aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--.mailmap1
-rw-r--r--Documentation/ABI/testing/sysfs-class-bdi46
-rw-r--r--Documentation/DocBook/Makefile2
-rw-r--r--Documentation/DocBook/debugobjects.tmpl391
-rw-r--r--Documentation/DocBook/kgdb.tmpl8
-rw-r--r--Documentation/DocBook/rapidio.tmpl1
-rw-r--r--Documentation/braille-console.txt34
-rw-r--r--Documentation/feature-removal-schedule.txt18
-rw-r--r--Documentation/filesystems/proc.txt21
-rw-r--r--Documentation/hwmon/w83l785ts3
-rw-r--r--Documentation/kbuild/kconfig-language.txt24
-rw-r--r--Documentation/kdump/kdump.txt5
-rw-r--r--Documentation/kernel-parameters.txt12
-rw-r--r--Documentation/laptops/thinkpad-acpi.txt139
-rw-r--r--Documentation/lguest/lguest.c62
-rw-r--r--Documentation/powerpc/mpc52xx-device-tree-bindings.txt23
-rw-r--r--Documentation/scheduler/sched-design.txt165
-rw-r--r--Documentation/scsi/ChangeLog.megaraid_sas22
-rw-r--r--Documentation/thermal/sysfs-api.txt33
-rw-r--r--Documentation/vm/slabinfo.c10
-rw-r--r--MAINTAINERS158
-rw-r--r--Makefile10
-rw-r--r--arch/alpha/kernel/osf_sys.c69
-rw-r--r--arch/arm/kernel/sys_arm.c17
-rw-r--r--arch/arm/mach-ixp4xx/ixp4xx_npe.c4
-rw-r--r--arch/arm/mach-ixp4xx/ixp4xx_qmgr.c2
-rw-r--r--arch/arm/mach-pxa/generic.c5
-rw-r--r--arch/arm/mach-pxa/littleton.c3
-rw-r--r--arch/arm/mach-pxa/lubbock.c4
-rw-r--r--arch/arm/mach-pxa/mainstone.c3
-rw-r--r--arch/arm/mach-pxa/zylonite.c6
-rw-r--r--arch/arm/mm/mmu.c1
-rw-r--r--arch/avr32/kernel/sys_avr32.c13
-rw-r--r--arch/blackfin/kernel/sys_bfin.c17
-rw-r--r--arch/frv/kernel/pm.c8
-rw-r--r--arch/frv/kernel/sys_frv.c17
-rw-r--r--arch/frv/mm/Makefile2
-rw-r--r--arch/h8300/kernel/sys_h8300.c17
-rw-r--r--arch/ia64/hp/sim/simserial.c11
-rw-r--r--arch/ia64/ia32/ia32_signal.c2
-rw-r--r--arch/ia64/kernel/acpi.c2
-rw-r--r--arch/ia64/kernel/irq.c4
-rw-r--r--arch/ia64/kernel/palinfo.c2
-rw-r--r--arch/ia64/kernel/perfmon.c199
-rw-r--r--arch/ia64/kernel/process.c2
-rw-r--r--arch/ia64/kernel/signal.c15
-rw-r--r--arch/ia64/kernel/smp.c68
-rw-r--r--arch/ia64/kernel/smpboot.c12
-rw-r--r--arch/ia64/kernel/time.c5
-rw-r--r--arch/ia64/kernel/topology.c25
-rw-r--r--arch/ia64/kernel/uncached.c23
-rw-r--r--arch/ia64/kvm/kvm-ia64.c3
-rw-r--r--arch/ia64/mm/tlb.c5
-rw-r--r--arch/m32r/Makefile2
-rw-r--r--arch/m32r/defconfig863
-rw-r--r--arch/m32r/kernel/vmlinux.lds.S3
-rw-r--r--arch/m68k/kernel/sys_m68k.c17
-rw-r--r--arch/m68k/kernel/traps.c17
-rw-r--r--arch/m68k/mac/config.c24
-rw-r--r--arch/m68k/mm/init.c1
-rw-r--r--arch/m68knommu/kernel/asm-offsets.c1
-rw-r--r--arch/m68knommu/kernel/entry.S9
-rw-r--r--arch/m68knommu/kernel/setup.c2
-rw-r--r--arch/m68knommu/kernel/signal.c21
-rw-r--r--arch/m68knommu/kernel/sys_m68k.c17
-rw-r--r--arch/m68knommu/kernel/traps.c88
-rw-r--r--arch/m68knommu/kernel/vmlinux.lds.S3
-rw-r--r--arch/m68knommu/platform/5206e/config.c2
-rw-r--r--arch/m68knommu/platform/5272/config.c4
-rw-r--r--arch/m68knommu/platform/528x/config.c266
-rw-r--r--arch/m68knommu/platform/5307/config.c3
-rw-r--r--arch/m68knommu/platform/coldfire/entry.S18
-rw-r--r--arch/mips/au1000/common/power.c35
-rw-r--r--arch/mips/kernel/binfmt_elfn32.c5
-rw-r--r--arch/mips/kernel/binfmt_elfo32.c5
-rw-r--r--arch/mips/kernel/irixioctl.c55
-rw-r--r--arch/mips/kernel/kspd.c1
-rw-r--r--arch/mn10300/kernel/sys_mn10300.c17
-rw-r--r--arch/parisc/kernel/sys_parisc.c13
-rw-r--r--arch/powerpc/boot/dts/cm5200.dts98
-rw-r--r--arch/powerpc/boot/dts/lite5200.dts132
-rw-r--r--arch/powerpc/boot/dts/lite5200b.dts146
-rw-r--r--arch/powerpc/boot/dts/motionpro.dts118
-rw-r--r--arch/powerpc/boot/dts/mpc8610_hpcd.dts23
-rw-r--r--arch/powerpc/boot/dts/pcm030.dts363
-rw-r--r--arch/powerpc/boot/dts/tqm5200.dts80
-rw-r--r--arch/powerpc/configs/52xx/cm5200_defconfig1099
-rw-r--r--arch/powerpc/configs/52xx/lite5200b_defconfig1049
-rw-r--r--arch/powerpc/configs/52xx/motionpro_defconfig1107
-rw-r--r--arch/powerpc/configs/52xx/pcm030_defconfig1115
-rw-r--r--arch/powerpc/configs/52xx/tqm5200_defconfig1214
-rw-r--r--arch/powerpc/configs/ps3_defconfig132
-rw-r--r--arch/powerpc/kernel/machine_kexec.c12
-rw-r--r--arch/powerpc/kernel/ppc_ksyms.c3
-rw-r--r--arch/powerpc/kernel/setup_64.c9
-rw-r--r--arch/powerpc/kernel/smp.c2
-rw-r--r--arch/powerpc/kernel/syscalls.c17
-rw-r--r--arch/powerpc/kernel/time.c4
-rw-r--r--arch/powerpc/kvm/booke_guest.c6
-rw-r--r--arch/powerpc/kvm/powerpc.c20
-rw-r--r--arch/powerpc/lib/Makefile1
-rw-r--r--arch/powerpc/lib/devres.c42
-rw-r--r--arch/powerpc/mm/slb.c27
-rw-r--r--arch/powerpc/platforms/52xx/Kconfig6
-rw-r--r--arch/powerpc/platforms/52xx/Makefile2
-rw-r--r--arch/powerpc/platforms/52xx/mpc5200_simple.c1
-rw-r--r--arch/powerpc/platforms/52xx/mpc52xx_gpio.c465
-rw-r--r--arch/powerpc/platforms/52xx/mpc52xx_pic.c38
-rw-r--r--arch/powerpc/platforms/cell/spufs/.gitignore2
-rw-r--r--arch/powerpc/platforms/cell/spufs/context.c4
-rw-r--r--arch/powerpc/platforms/cell/spufs/coredump.c1
-rw-r--r--arch/powerpc/platforms/cell/spufs/file.c166
-rw-r--r--arch/powerpc/platforms/cell/spufs/run.c2
-rw-r--r--arch/powerpc/platforms/cell/spufs/sched.c4
-rw-r--r--arch/powerpc/platforms/cell/spufs/spufs.h33
-rw-r--r--arch/powerpc/platforms/cell/spufs/sputrace.c36
-rw-r--r--arch/powerpc/platforms/ps3/interrupt.c6
-rw-r--r--arch/powerpc/platforms/pseries/scanlog.c19
-rw-r--r--arch/powerpc/sysdev/fsl_rio.c9
-rw-r--r--arch/powerpc/sysdev/fsl_soc.c4
-rw-r--r--arch/powerpc/sysdev/xilinx_intc.c2
-rw-r--r--arch/ppc/kernel/ppc_ksyms.c3
-rw-r--r--arch/s390/Kconfig8
-rw-r--r--arch/s390/defconfig141
-rw-r--r--arch/s390/kernel/Makefile2
-rw-r--r--arch/s390/kernel/early.c125
-rw-r--r--arch/s390/kernel/entry.S14
-rw-r--r--arch/s390/kernel/entry64.S12
-rw-r--r--arch/s390/kernel/head31.S61
-rw-r--r--arch/s390/kernel/head64.S64
-rw-r--r--arch/s390/kernel/process.c18
-rw-r--r--arch/s390/kernel/ptrace.c57
-rw-r--r--arch/s390/kernel/setup.c21
-rw-r--r--arch/s390/kernel/smp.c31
-rw-r--r--arch/s390/kernel/sys_s390.c17
-rw-r--r--arch/s390/kernel/topology.c35
-rw-r--r--arch/s390/kernel/traps.c26
-rw-r--r--arch/s390/kvm/priv.c11
-rw-r--r--arch/s390/lib/Makefile2
-rw-r--r--arch/s390/lib/uaccess_mvcos.c2
-rw-r--r--arch/s390/math-emu/Makefile1
-rw-r--r--arch/s390/mm/Makefile2
-rw-r--r--arch/s390/mm/extmem.c8
-rw-r--r--arch/s390/mm/fault.c3
-rw-r--r--arch/s390/mm/hugetlbpage.c134
-rw-r--r--arch/s390/mm/init.c25
-rw-r--r--arch/s390/mm/vmem.c135
-rw-r--r--arch/sh/kernel/sys_sh64.c17
-rw-r--r--arch/sparc/Kconfig1
-rw-r--r--arch/sparc/defconfig139
-rw-r--r--arch/sparc/kernel/Makefile1
-rw-r--r--arch/sparc/kernel/entry.S125
-rw-r--r--arch/sparc/kernel/head.S9
-rw-r--r--arch/sparc/kernel/kgdb.c164
-rw-r--r--arch/sparc/kernel/setup.c5
-rw-r--r--arch/sparc/kernel/sparc-stub.c724
-rw-r--r--arch/sparc/kernel/sparc_ksyms.c2
-rw-r--r--arch/sparc/kernel/sun4d_smp.c32
-rw-r--r--arch/sparc/kernel/sun4m_smp.c45
-rw-r--r--arch/sparc/mm/fault.c61
-rw-r--r--arch/sparc/prom/init.c7
-rw-r--r--arch/sparc/prom/memory.c235
-rw-r--r--arch/sparc64/Kconfig1
-rw-r--r--arch/sparc64/kernel/Makefile1
-rw-r--r--arch/sparc64/kernel/cherrs.S579
-rw-r--r--arch/sparc64/kernel/entry.S2575
-rw-r--r--arch/sparc64/kernel/fpu_traps.S384
-rw-r--r--arch/sparc64/kernel/getsetcc.S24
-rw-r--r--arch/sparc64/kernel/head.S15
-rw-r--r--arch/sparc64/kernel/helpers.S63
-rw-r--r--arch/sparc64/kernel/hvcalls.S886
-rw-r--r--arch/sparc64/kernel/ivec.S51
-rw-r--r--arch/sparc64/kernel/kgdb.c186
-rw-r--r--arch/sparc64/kernel/misctrap.S97
-rw-r--r--arch/sparc64/kernel/pci.c130
-rw-r--r--arch/sparc64/kernel/pci_common.c6
-rw-r--r--arch/sparc64/kernel/pci_impl.h9
-rw-r--r--arch/sparc64/kernel/process.c6
-rw-r--r--arch/sparc64/kernel/signal.c6
-rw-r--r--arch/sparc64/kernel/signal32.c6
-rw-r--r--arch/sparc64/kernel/smp.c11
-rw-r--r--arch/sparc64/kernel/spiterrs.S245
-rw-r--r--arch/sparc64/kernel/syscalls.S279
-rw-r--r--arch/sparc64/kernel/ttable.S2
-rw-r--r--arch/sparc64/kernel/utrap.S29
-rw-r--r--arch/sparc64/mm/init.c1
-rw-r--r--arch/sparc64/mm/ultra.S27
-rw-r--r--arch/um/Makefile5
-rw-r--r--arch/um/kernel/syscall.c17
-rw-r--r--arch/v850/kernel/syscalls.c17
-rw-r--r--arch/x86/Kconfig18
-rw-r--r--arch/x86/Kconfig.cpu10
-rw-r--r--arch/x86/Kconfig.debug8
-rw-r--r--arch/x86/boot/compressed/relocs.c2
-rw-r--r--arch/x86/ia32/ia32_signal.c2
-rw-r--r--arch/x86/kernel/Makefile1
-rw-r--r--arch/x86/kernel/acpi/Makefile2
-rw-r--r--arch/x86/kernel/acpi/realmode/Makefile5
-rw-r--r--arch/x86/kernel/apm_32.c16
-rw-r--r--arch/x86/kernel/genapic_64.c2
-rw-r--r--arch/x86/kernel/head_32.S19
-rw-r--r--arch/x86/kernel/hpet.c5
-rw-r--r--arch/x86/kernel/kvmclock.c4
-rw-r--r--arch/x86/kernel/mpparse.c7
-rw-r--r--arch/x86/kernel/pci-dma.c2
-rw-r--r--arch/x86/kernel/reboot.c2
-rw-r--r--arch/x86/kernel/setup.c2
-rw-r--r--arch/x86/kernel/signal_32.c17
-rw-r--r--arch/x86/kernel/signal_64.c16
-rw-r--r--arch/x86/kernel/smpboot.c4
-rw-r--r--arch/x86/kernel/sys_i386_32.c17
-rw-r--r--arch/x86/kernel/sys_x86_64.c17
-rw-r--r--arch/x86/kvm/i8254.c8
-rw-r--r--arch/x86/kvm/lapic.c6
-rw-r--r--arch/x86/kvm/mmu.c89
-rw-r--r--arch/x86/kvm/mmu.h37
-rw-r--r--arch/x86/kvm/svm.c10
-rw-r--r--arch/x86/kvm/vmx.c375
-rw-r--r--arch/x86/kvm/vmx.h38
-rw-r--r--arch/x86/kvm/x86.c22
-rw-r--r--arch/x86/kvm/x86_emulate.c1
-rw-r--r--arch/x86/mach-voyager/voyager_cat.c2
-rw-r--r--arch/x86/mm/discontig_32.c26
-rw-r--r--arch/x86/mm/highmem_32.c1
-rw-r--r--arch/x86/mm/ioremap.c23
-rw-r--r--arch/x86/mm/pageattr.c10
-rw-r--r--arch/x86/pci/Makefile_328
-rw-r--r--arch/x86/pci/acpi.c41
-rw-r--r--arch/x86/pci/common.c58
-rw-r--r--arch/x86/pci/fixup.c2
-rw-r--r--arch/x86/pci/i386.c12
-rw-r--r--arch/x86/pci/init.c4
-rw-r--r--arch/x86/pci/pci.h3
-rw-r--r--arch/x86/vdso/vdso32-setup.c4
-rw-r--r--arch/x86/video/fbdev.c2
-rw-r--r--block/blk-barrier.c3
-rw-r--r--block/blk-core.c5
-rw-r--r--block/blk-settings.c20
-rw-r--r--block/blk-tag.c8
-rw-r--r--block/bsg.c14
-rw-r--r--block/elevator.c5
-rw-r--r--block/genhd.c8
-rw-r--r--block/scsi_ioctl.c5
-rw-r--r--crypto/authenc.c5
-rw-r--r--crypto/cryptd.c4
-rw-r--r--crypto/eseqiv.c3
-rw-r--r--drivers/Kconfig2
-rw-r--r--drivers/Makefile1
-rw-r--r--drivers/accessibility/Kconfig23
-rw-r--r--drivers/accessibility/Makefile1
-rw-r--r--drivers/accessibility/braille/Makefile1
-rw-r--r--drivers/accessibility/braille/braille_console.c397
-rw-r--r--drivers/acpi/Kconfig3
-rw-r--r--drivers/acpi/bay.c2
-rw-r--r--drivers/acpi/dispatcher/dsfield.c173
-rw-r--r--drivers/acpi/dispatcher/dsinit.c2
-rw-r--r--drivers/acpi/dispatcher/dsmethod.c57
-rw-r--r--drivers/acpi/dispatcher/dsmthdat.c2
-rw-r--r--drivers/acpi/dispatcher/dsobject.c101
-rw-r--r--drivers/acpi/dispatcher/dsopcode.c260
-rw-r--r--drivers/acpi/dispatcher/dsutils.c167
-rw-r--r--drivers/acpi/dispatcher/dswexec.c78
-rw-r--r--drivers/acpi/dispatcher/dswload.c37
-rw-r--r--drivers/acpi/dispatcher/dswscope.c2
-rw-r--r--drivers/acpi/dispatcher/dswstate.c517
-rw-r--r--drivers/acpi/ec.c240
-rw-r--r--drivers/acpi/events/evevent.c2
-rw-r--r--drivers/acpi/events/evgpe.c6
-rw-r--r--drivers/acpi/events/evgpeblk.c2
-rw-r--r--drivers/acpi/events/evmisc.c92
-rw-r--r--drivers/acpi/events/evregion.c4
-rw-r--r--drivers/acpi/events/evrgnini.c2
-rw-r--r--drivers/acpi/events/evsci.c2
-rw-r--r--drivers/acpi/events/evxface.c23
-rw-r--r--drivers/acpi/events/evxfevnt.c2
-rw-r--r--drivers/acpi/events/evxfregn.c2
-rw-r--r--drivers/acpi/executer/exconfig.c105
-rw-r--r--drivers/acpi/executer/exconvrt.c2
-rw-r--r--drivers/acpi/executer/excreate.c117
-rw-r--r--drivers/acpi/executer/exdump.c69
-rw-r--r--drivers/acpi/executer/exfield.c63
-rw-r--r--drivers/acpi/executer/exfldio.c46
-rw-r--r--drivers/acpi/executer/exmisc.c2
-rw-r--r--drivers/acpi/executer/exmutex.c237
-rw-r--r--drivers/acpi/executer/exnames.c2
-rw-r--r--drivers/acpi/executer/exoparg1.c25
-rw-r--r--drivers/acpi/executer/exoparg2.c21
-rw-r--r--drivers/acpi/executer/exoparg3.c3
-rw-r--r--drivers/acpi/executer/exoparg6.c10
-rw-r--r--drivers/acpi/executer/exprep.c17
-rw-r--r--drivers/acpi/executer/exregion.c10
-rw-r--r--drivers/acpi/executer/exresnte.c12
-rw-r--r--drivers/acpi/executer/exresolv.c55
-rw-r--r--drivers/acpi/executer/exresop.c13
-rw-r--r--drivers/acpi/executer/exstore.c119
-rw-r--r--drivers/acpi/executer/exstoren.c2
-rw-r--r--drivers/acpi/executer/exstorob.c2
-rw-r--r--drivers/acpi/executer/exsystem.c3
-rw-r--r--drivers/acpi/executer/exutils.c67
-rw-r--r--drivers/acpi/fan.c35
-rw-r--r--drivers/acpi/glue.c20
-rw-r--r--drivers/acpi/hardware/hwacpi.c2
-rw-r--r--drivers/acpi/hardware/hwgpe.c2
-rw-r--r--drivers/acpi/hardware/hwregs.c2
-rw-r--r--drivers/acpi/hardware/hwsleep.c16
-rw-r--r--drivers/acpi/hardware/hwtimer.c2
-rw-r--r--drivers/acpi/namespace/nsaccess.c101
-rw-r--r--drivers/acpi/namespace/nsalloc.c2
-rw-r--r--drivers/acpi/namespace/nsdump.c11
-rw-r--r--drivers/acpi/namespace/nsdumpdv.c2
-rw-r--r--drivers/acpi/namespace/nseval.c2
-rw-r--r--drivers/acpi/namespace/nsinit.c12
-rw-r--r--drivers/acpi/namespace/nsload.c6
-rw-r--r--drivers/acpi/namespace/nsnames.c8
-rw-r--r--drivers/acpi/namespace/nsobject.c2
-rw-r--r--drivers/acpi/namespace/nsparse.c33
-rw-r--r--drivers/acpi/namespace/nssearch.c2
-rw-r--r--drivers/acpi/namespace/nsutils.c2
-rw-r--r--drivers/acpi/namespace/nswalk.c6
-rw-r--r--drivers/acpi/namespace/nsxfeval.c15
-rw-r--r--drivers/acpi/namespace/nsxfname.c2
-rw-r--r--drivers/acpi/namespace/nsxfobj.c2
-rw-r--r--drivers/acpi/osl.c1
-rw-r--r--drivers/acpi/parser/psargs.c63
-rw-r--r--drivers/acpi/parser/psloop.c61
-rw-r--r--drivers/acpi/parser/psopcode.c38
-rw-r--r--drivers/acpi/parser/psparse.c45
-rw-r--r--drivers/acpi/parser/psscope.c2
-rw-r--r--drivers/acpi/parser/pstree.c4
-rw-r--r--drivers/acpi/parser/psutils.c2
-rw-r--r--drivers/acpi/parser/pswalk.c2
-rw-r--r--drivers/acpi/parser/psxface.c2
-rw-r--r--drivers/acpi/power.c2
-rw-r--r--drivers/acpi/processor_core.c40
-rw-r--r--drivers/acpi/processor_idle.c18
-rw-r--r--drivers/acpi/resources/rsaddr.c2
-rw-r--r--drivers/acpi/resources/rscalc.c26
-rw-r--r--drivers/acpi/resources/rscreate.c2
-rw-r--r--drivers/acpi/resources/rsdump.c10
-rw-r--r--drivers/acpi/resources/rsinfo.c2
-rw-r--r--drivers/acpi/resources/rsio.c41
-rw-r--r--drivers/acpi/resources/rsirq.c45
-rw-r--r--drivers/acpi/resources/rslist.c2
-rw-r--r--drivers/acpi/resources/rsmemory.c2
-rw-r--r--drivers/acpi/resources/rsmisc.c13
-rw-r--r--drivers/acpi/resources/rsutils.c8
-rw-r--r--drivers/acpi/resources/rsxface.c2
-rw-r--r--drivers/acpi/scan.c63
-rw-r--r--drivers/acpi/sleep/main.c42
-rw-r--r--drivers/acpi/tables/tbfadt.c2
-rw-r--r--drivers/acpi/tables/tbfind.c34
-rw-r--r--drivers/acpi/tables/tbinstal.c24
-rw-r--r--drivers/acpi/tables/tbutils.c4
-rw-r--r--drivers/acpi/tables/tbxface.c91
-rw-r--r--drivers/acpi/tables/tbxfroot.c2
-rw-r--r--drivers/acpi/thermal.c20
-rw-r--r--drivers/acpi/utilities/utalloc.c4
-rw-r--r--drivers/acpi/utilities/utcache.c2
-rw-r--r--drivers/acpi/utilities/utcopy.c61
-rw-r--r--drivers/acpi/utilities/utdebug.c19
-rw-r--r--drivers/acpi/utilities/utdelete.c23
-rw-r--r--drivers/acpi/utilities/uteval.c2
-rw-r--r--drivers/acpi/utilities/utglobal.c49
-rw-r--r--drivers/acpi/utilities/utinit.c5
-rw-r--r--drivers/acpi/utilities/utmath.c4
-rw-r--r--drivers/acpi/utilities/utmisc.c6
-rw-r--r--drivers/acpi/utilities/utmutex.c2
-rw-r--r--drivers/acpi/utilities/utobject.c8
-rw-r--r--drivers/acpi/utilities/utresrc.c2
-rw-r--r--drivers/acpi/utilities/utstate.c2
-rw-r--r--drivers/acpi/utilities/utxface.c41
-rw-r--r--drivers/acpi/utils.c2
-rw-r--r--drivers/acpi/video.c219
-rw-r--r--drivers/atm/ambassador.c19
-rw-r--r--drivers/atm/ambassador.h2
-rw-r--r--drivers/base/base.h11
-rw-r--r--drivers/base/class.c638
-rw-r--r--drivers/base/cpu.c10
-rw-r--r--drivers/base/driver.c10
-rw-r--r--drivers/base/node.c2
-rw-r--r--drivers/block/brd.c19
-rw-r--r--drivers/block/cciss.c8
-rw-r--r--drivers/block/ub.c63
-rw-r--r--drivers/block/virtio_blk.c44
-rw-r--r--drivers/bluetooth/hci_ldisc.c13
-rw-r--r--drivers/bluetooth/hci_usb.h21
-rw-r--r--drivers/char/agp/agp.h2
-rw-r--r--drivers/char/amiserial.c30
-rw-r--r--drivers/char/applicom.c4
-rw-r--r--drivers/char/consolemap.c1
-rw-r--r--drivers/char/cyclades.c432
-rw-r--r--drivers/char/drm/drmP.h8
-rw-r--r--drivers/char/drm/drm_sysfs.c2
-rw-r--r--drivers/char/drm/i830_dma.c18
-rw-r--r--drivers/char/drm/i830_drv.h2
-rw-r--r--drivers/char/drm/i830_irq.c8
-rw-r--r--drivers/char/drm/i915_dma.c4
-rw-r--r--drivers/char/drm/i915_drv.h2
-rw-r--r--drivers/char/drm/radeon_cp.c2
-rw-r--r--drivers/char/ds1286.c3
-rw-r--r--drivers/char/epca.c315
-rw-r--r--drivers/char/esp.c611
-rw-r--r--drivers/char/generic_serial.c18
-rw-r--r--drivers/char/hpet.c10
-rw-r--r--drivers/char/hvsi.c52
-rw-r--r--drivers/char/i8k.c6
-rw-r--r--drivers/char/ip2/i2ellis.c194
-rw-r--r--drivers/char/ip2/i2ellis.h58
-rw-r--r--drivers/char/ip2/i2hw.h6
-rw-r--r--drivers/char/ip2/i2lib.c141
-rw-r--r--drivers/char/ip2/i2os.h127
-rw-r--r--drivers/char/ip2/ip2main.c89
-rw-r--r--drivers/char/isicom.c171
-rw-r--r--drivers/char/istallion.c22
-rw-r--r--drivers/char/keyboard.c4
-rw-r--r--drivers/char/mmtimer.c424
-rw-r--r--drivers/char/moxa.c2999
-rw-r--r--drivers/char/moxa.h304
-rw-r--r--drivers/char/mspec.c12
-rw-r--r--drivers/char/mxser.c346
-rw-r--r--drivers/char/mxser.h137
-rw-r--r--drivers/char/n_hdlc.c35
-rw-r--r--drivers/char/n_r3964.c33
-rw-r--r--drivers/char/n_tty.c160
-rw-r--r--drivers/char/nozomi.c17
-rw-r--r--drivers/char/pcmcia/cm4000_cs.c2
-rw-r--r--drivers/char/pcmcia/cm4040_cs.c2
-rw-r--r--drivers/char/pcmcia/synclink_cs.c23
-rw-r--r--drivers/char/pty.c32
-rw-r--r--drivers/char/rio/cirrus.h210
-rw-r--r--drivers/char/rio/rio_linux.c10
-rw-r--r--drivers/char/rio/rio_linux.h6
-rw-r--r--drivers/char/rio/riocmd.c19
-rw-r--r--drivers/char/rio/rioctrl.c37
-rw-r--r--drivers/char/rio/riointr.c5
-rw-r--r--drivers/char/rio/rioparam.c70
-rw-r--r--drivers/char/rio/riotty.c25
-rw-r--r--drivers/char/riscom8.c706
-rw-r--r--drivers/char/rocket.c43
-rw-r--r--drivers/char/serial167.c27
-rw-r--r--drivers/char/snsc.c18
-rw-r--r--drivers/char/snsc_event.c6
-rw-r--r--drivers/char/sonypi.c2
-rw-r--r--drivers/char/specialix.c111
-rw-r--r--drivers/char/stallion.c17
-rw-r--r--drivers/char/sx.c35
-rw-r--r--drivers/char/synclink.c45
-rw-r--r--drivers/char/synclink_gt.c80
-rw-r--r--drivers/char/synclinkmp.c41
-rw-r--r--drivers/char/toshiba.c2
-rw-r--r--drivers/char/tty_audit.c1
-rw-r--r--drivers/char/tty_io.c373
-rw-r--r--drivers/char/tty_ioctl.c126
-rw-r--r--drivers/char/viocons.c12
-rw-r--r--drivers/char/vt.c21
-rw-r--r--drivers/char/vt_ioctl.c452
-rw-r--r--drivers/char/xilinx_hwicap/xilinx_hwicap.c6
-rw-r--r--drivers/edac/edac_core.h2
-rw-r--r--drivers/edac/edac_device.c6
-rw-r--r--drivers/edac/edac_mc.c6
-rw-r--r--drivers/edac/edac_pci.c6
-rw-r--r--drivers/edac/pasemi_edac.c1
-rw-r--r--drivers/firewire/fw-sbp2.c4
-rw-r--r--drivers/gpio/gpiolib.c4
-rw-r--r--drivers/gpio/pca953x.c4
-rw-r--r--drivers/hwmon/ads7828.c2
-rw-r--r--drivers/hwmon/adt7473.c45
-rw-r--r--drivers/hwmon/asb100.c4
-rw-r--r--drivers/hwmon/lm75.c5
-rw-r--r--drivers/hwmon/smsc47b397.c17
-rw-r--r--drivers/hwmon/w83793.c26
-rw-r--r--drivers/hwmon/w83l785ts.c4
-rw-r--r--drivers/ide/ide-probe.c15
-rw-r--r--drivers/ide/legacy/falconide.c2
-rw-r--r--drivers/ieee1394/nodemgr.c5
-rw-r--r--drivers/input/serio/hp_sdc.c1
-rw-r--r--drivers/input/serio/serport.c2
-rw-r--r--drivers/isdn/capi/capi.c9
-rw-r--r--drivers/isdn/gigaset/ser-gigaset.c15
-rw-r--r--drivers/isdn/hysdn/hysdn_procconf.c3
-rw-r--r--drivers/isdn/i4l/isdn_tty.c30
-rw-r--r--drivers/lguest/lguest_device.c68
-rw-r--r--drivers/lguest/lguest_user.c4
-rw-r--r--drivers/macintosh/adb.c30
-rw-r--r--drivers/macintosh/therm_pm72.c31
-rw-r--r--drivers/macintosh/windfarm_smu_sat.c10
-rw-r--r--drivers/md/md.c112
-rw-r--r--drivers/md/raid1.c27
-rw-r--r--drivers/md/raid10.c29
-rw-r--r--drivers/md/raid5.c33
-rw-r--r--drivers/media/common/Makefile1
-rw-r--r--drivers/media/common/tuners/Kconfig9
-rw-r--r--drivers/media/video/bt8xx/bttvp.h2
-rw-r--r--drivers/media/video/cx18/Kconfig2
-rw-r--r--drivers/media/video/cx18/cx18-driver.c2
-rw-r--r--drivers/media/video/cx88/cx88-i2c.c1
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.c6
-rw-r--r--drivers/media/video/ivtv/ivtv-fileops.c4
-rw-r--r--drivers/media/video/tuner-core.c2
-rw-r--r--drivers/media/video/usbvideo/vicam.c6
-rw-r--r--drivers/mfd/asic3.c6
-rw-r--r--drivers/mfd/sm501.c4
-rw-r--r--drivers/misc/Kconfig21
-rw-r--r--drivers/misc/Makefile3
-rw-r--r--drivers/misc/eeepc-laptop.c666
-rw-r--r--drivers/misc/kgdbts.c77
-rw-r--r--drivers/misc/sgi-xp/xpc_partition.c4
-rw-r--r--drivers/misc/thinkpad_acpi.c765
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0001.c14
-rw-r--r--drivers/mtd/devices/mtdram.c11
-rw-r--r--drivers/mtd/devices/phram.c13
-rw-r--r--drivers/mtd/devices/pmc551.c27
-rw-r--r--drivers/mtd/devices/slram.c15
-rw-r--r--drivers/mtd/maps/uclinux.c6
-rw-r--r--drivers/mtd/mtdpart.c8
-rw-r--r--drivers/mtd/nand/at91_nand.c42
-rw-r--r--drivers/net/3c505.c30
-rw-r--r--drivers/net/3c505.h1
-rw-r--r--drivers/net/3c509.c47
-rw-r--r--drivers/net/3c515.c64
-rw-r--r--drivers/net/8390.c2
-rw-r--r--drivers/net/Kconfig1
-rw-r--r--drivers/net/Makefile2
-rw-r--r--drivers/net/arm/Kconfig8
-rw-r--r--drivers/net/arm/Makefile1
-rw-r--r--drivers/net/arm/ixp4xx_eth.c1265
-rw-r--r--drivers/net/bfin_mac.c296
-rw-r--r--drivers/net/bfin_mac.h2
-rw-r--r--drivers/net/bnx2.c43
-rw-r--r--drivers/net/bnx2_fw2.h502
-rw-r--r--drivers/net/eepro.c2
-rw-r--r--drivers/net/fec.c125
-rw-r--r--drivers/net/fec.h4
-rw-r--r--drivers/net/fec_mpc52xx.c120
-rw-r--r--drivers/net/fec_mpc52xx.h19
-rw-r--r--drivers/net/gianfar.c27
-rw-r--r--drivers/net/gianfar.h1
-rw-r--r--drivers/net/gianfar_mii.c38
-rw-r--r--drivers/net/gianfar_mii.h3
-rw-r--r--drivers/net/hamradio/6pack.c36
-rw-r--r--drivers/net/hamradio/mkiss.c15
-rw-r--r--drivers/net/irda/irtty-sir.c95
-rw-r--r--drivers/net/phy/Kconfig2
-rw-r--r--drivers/net/phy/phy_device.c2
-rw-r--r--drivers/net/phy/smsc.c83
-rw-r--r--drivers/net/ppp_async.c9
-rw-r--r--drivers/net/ppp_synctty.c9
-rw-r--r--drivers/net/r8169.c8
-rw-r--r--drivers/net/s2io.c337
-rw-r--r--drivers/net/s2io.h82
-rw-r--r--drivers/net/sfc/Kconfig12
-rw-r--r--drivers/net/sfc/Makefile5
-rw-r--r--drivers/net/sfc/bitfield.h508
-rw-r--r--drivers/net/sfc/boards.c167
-rw-r--r--drivers/net/sfc/boards.h26
-rw-r--r--drivers/net/sfc/efx.c2208
-rw-r--r--drivers/net/sfc/efx.h67
-rw-r--r--drivers/net/sfc/enum.h50
-rw-r--r--drivers/net/sfc/ethtool.c460
-rw-r--r--drivers/net/sfc/ethtool.h27
-rw-r--r--drivers/net/sfc/falcon.c2722
-rw-r--r--drivers/net/sfc/falcon.h130
-rw-r--r--drivers/net/sfc/falcon_hwdefs.h1135
-rw-r--r--drivers/net/sfc/falcon_io.h243
-rw-r--r--drivers/net/sfc/falcon_xmac.c585
-rw-r--r--drivers/net/sfc/gmii.h195
-rw-r--r--drivers/net/sfc/i2c-direct.c381
-rw-r--r--drivers/net/sfc/i2c-direct.h91
-rw-r--r--drivers/net/sfc/mac.h33
-rw-r--r--drivers/net/sfc/mdio_10g.c282
-rw-r--r--drivers/net/sfc/mdio_10g.h232
-rw-r--r--drivers/net/sfc/net_driver.h883
-rw-r--r--drivers/net/sfc/phy.h48
-rw-r--r--drivers/net/sfc/rx.c875
-rw-r--r--drivers/net/sfc/rx.h29
-rw-r--r--drivers/net/sfc/sfe4001.c252
-rw-r--r--drivers/net/sfc/spi.h71
-rw-r--r--drivers/net/sfc/tenxpress.c434
-rw-r--r--drivers/net/sfc/tx.c452
-rw-r--r--drivers/net/sfc/tx.h24
-rw-r--r--drivers/net/sfc/workarounds.h56
-rw-r--r--drivers/net/sfc/xenpack.h62
-rw-r--r--drivers/net/sfc/xfp_phy.c132
-rw-r--r--drivers/net/sis190.c136
-rw-r--r--drivers/net/slip.c13
-rw-r--r--drivers/net/tg3.c149
-rw-r--r--drivers/net/tg3.h15
-rw-r--r--drivers/net/virtio_net.c96
-rw-r--r--drivers/net/wan/pc300_tty.c24
-rw-r--r--drivers/net/wan/x25_asy.c279
-rw-r--r--drivers/net/wireless/b43/b43.h4
-rw-r--r--drivers/net/wireless/b43/main.c51
-rw-r--r--drivers/net/wireless/iwlwifi/Kconfig12
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.h1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965.h1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl3945-base.c29
-rw-r--r--drivers/net/wireless/iwlwifi/iwl4965-base.c26
-rw-r--r--drivers/net/wireless/libertas/scan.c3
-rw-r--r--drivers/net/wireless/rt2x00/rt2400pci.c4
-rw-r--r--drivers/net/wireless/rt2x00/rt2500pci.c4
-rw-r--r--drivers/net/wireless/rt2x00/rt2500usb.c2
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00dev.c2
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00leds.c15
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00lib.h6
-rw-r--r--drivers/net/wireless/rt2x00/rt61pci.c2
-rw-r--r--drivers/net/wireless/rt2x00/rt73usb.c2
-rw-r--r--drivers/net/wireless/strip.c66
-rw-r--r--drivers/net/xen-netfront.c2
-rw-r--r--drivers/parport/ieee1284.c4
-rw-r--r--drivers/parport/parport_gsc.c4
-rw-r--r--drivers/parport/parport_pc.c8
-rw-r--r--drivers/pci/probe.c33
-rw-r--r--drivers/pcmcia/au1000_db1x00.c6
-rw-r--r--drivers/pcmcia/au1000_generic.c11
-rw-r--r--drivers/pcmcia/au1000_pb1x00.c14
-rw-r--r--drivers/pcmcia/au1000_xxs1500.c2
-rw-r--r--drivers/pcmcia/cardbus.c2
-rw-r--r--drivers/pcmcia/cs.c13
-rw-r--r--drivers/pcmcia/cs_internal.h3
-rw-r--r--drivers/pcmcia/ds.c2
-rw-r--r--drivers/pcmcia/i82092.c6
-rw-r--r--drivers/pcmcia/omap_cf.c2
-rw-r--r--drivers/pcmcia/pd6729.c6
-rw-r--r--drivers/pcmcia/pxa2xx_lubbock.c8
-rw-r--r--drivers/pcmcia/pxa2xx_mainstone.c4
-rw-r--r--drivers/pcmcia/rsrc_nonstatic.c2
-rw-r--r--drivers/pcmcia/sa1100_assabet.c4
-rw-r--r--drivers/pcmcia/sa1100_badge4.c8
-rw-r--r--drivers/pcmcia/sa1100_cerf.c2
-rw-r--r--drivers/pcmcia/sa1100_jornada720.c4
-rw-r--r--drivers/pcmcia/sa1100_neponset.c4
-rw-r--r--drivers/pcmcia/sa1100_shannon.c8
-rw-r--r--drivers/pcmcia/sa1100_simpad.c2
-rw-r--r--drivers/pcmcia/soc_common.c17
-rw-r--r--drivers/pcmcia/soc_common.h1
-rw-r--r--drivers/pcmcia/socket_sysfs.c52
-rw-r--r--drivers/pnp/base.h74
-rw-r--r--drivers/pnp/card.c55
-rw-r--r--drivers/pnp/core.c46
-rw-r--r--drivers/pnp/driver.c28
-rw-r--r--drivers/pnp/interface.c111
-rw-r--r--drivers/pnp/isapnp/Makefile4
-rw-r--r--drivers/pnp/isapnp/core.c340
-rw-r--r--drivers/pnp/manager.c356
-rw-r--r--drivers/pnp/pnpacpi/Makefile4
-rw-r--r--drivers/pnp/pnpacpi/core.c92
-rw-r--r--drivers/pnp/pnpacpi/pnpacpi.h8
-rw-r--r--drivers/pnp/pnpacpi/rsparser.c589
-rw-r--r--drivers/pnp/pnpbios/Makefile4
-rw-r--r--drivers/pnp/pnpbios/bioscalls.c1
-rw-r--r--drivers/pnp/pnpbios/core.c31
-rw-r--r--drivers/pnp/pnpbios/pnpbios.h140
-rw-r--r--drivers/pnp/pnpbios/proc.c2
-rw-r--r--drivers/pnp/pnpbios/rsparser.c328
-rw-r--r--drivers/pnp/quirks.c15
-rw-r--r--drivers/pnp/resource.c361
-rw-r--r--drivers/pnp/support.c63
-rw-r--r--drivers/pnp/system.c21
-rw-r--r--drivers/power/pda_power.c11
-rw-r--r--drivers/power/pmu_battery.c2
-rw-r--r--drivers/ps3/ps3-lpm.c1
-rw-r--r--drivers/ps3/ps3-sys-manager.c7
-rw-r--r--drivers/rtc/rtc-cmos.c7
-rw-r--r--drivers/s390/char/con3215.c5
-rw-r--r--drivers/s390/char/sclp_config.c17
-rw-r--r--drivers/s390/char/sclp_tty.c4
-rw-r--r--drivers/s390/char/sclp_vt220.c6
-rw-r--r--drivers/s390/char/tty3270.c3
-rw-r--r--drivers/s390/cio/ccwgroup.c103
-rw-r--r--drivers/s390/cio/cio.c9
-rw-r--r--drivers/s390/cio/cio.h3
-rw-r--r--drivers/s390/cio/cmf.c11
-rw-r--r--drivers/s390/cio/css.c10
-rw-r--r--drivers/s390/cio/device.c17
-rw-r--r--drivers/s390/cio/device_fsm.c10
-rw-r--r--drivers/s390/cio/device_ops.c2
-rw-r--r--drivers/s390/cio/qdio.c8
-rw-r--r--drivers/s390/kvm/kvm_virtio.c23
-rw-r--r--drivers/s390/net/cu3088.c20
-rw-r--r--drivers/s390/net/lcs.c3
-rw-r--r--drivers/s390/net/netiucv.c3
-rw-r--r--drivers/s390/net/qeth_core.h50
-rw-r--r--drivers/s390/net/qeth_core_main.c200
-rw-r--r--drivers/s390/net/qeth_l2_main.c30
-rw-r--r--drivers/s390/net/qeth_l3.h3
-rw-r--r--drivers/s390/net/qeth_l3_main.c30
-rw-r--r--drivers/s390/scsi/zfcp_dbf.c2
-rw-r--r--drivers/s390/scsi/zfcp_fsf.c2
-rw-r--r--drivers/sbus/char/cpwatchdog.c2
-rw-r--r--drivers/sbus/char/uctrl.c4
-rw-r--r--drivers/scsi/53c700.c6
-rw-r--r--drivers/scsi/Kconfig4
-rw-r--r--drivers/scsi/a100u2w.c2
-rw-r--r--drivers/scsi/aacraid/aachba.c133
-rw-r--r--drivers/scsi/aacraid/aacraid.h28
-rw-r--r--drivers/scsi/aacraid/comminit.c2
-rw-r--r--drivers/scsi/aacraid/commsup.c34
-rw-r--r--drivers/scsi/aacraid/linit.c22
-rw-r--r--drivers/scsi/aic94xx/aic94xx_init.c6
-rw-r--r--drivers/scsi/constants.c10
-rw-r--r--drivers/scsi/dpt/dpti_ioctl.h16
-rw-r--r--drivers/scsi/dpt/dptsig.h8
-rw-r--r--drivers/scsi/dpt/sys_info.h4
-rw-r--r--drivers/scsi/dpt_i2o.c640
-rw-r--r--drivers/scsi/dpti.h15
-rw-r--r--drivers/scsi/gdth.c2
-rw-r--r--drivers/scsi/hptiop.c6
-rw-r--r--drivers/scsi/ibmvscsi/ibmvscsi.c7
-rw-r--r--drivers/scsi/ibmvscsi/viosrp.h9
-rw-r--r--drivers/scsi/initio.c2
-rw-r--r--drivers/scsi/ipr.c2
-rw-r--r--drivers/scsi/megaraid/megaraid_mbox.c17
-rw-r--r--drivers/scsi/megaraid/megaraid_mbox.h1
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.c13
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.h6
-rw-r--r--drivers/scsi/mvsas.c4
-rw-r--r--drivers/scsi/ncr53c8xx.c2
-rw-r--r--drivers/scsi/qla1280.c4
-rw-r--r--drivers/scsi/scsi.c23
-rw-r--r--drivers/scsi/scsi_error.c15
-rw-r--r--drivers/scsi/scsi_lib.c7
-rw-r--r--drivers/scsi/scsi_tgt_lib.c2
-rw-r--r--drivers/scsi/u14-34f.c6
-rw-r--r--drivers/serial/68328serial.c21
-rw-r--r--drivers/serial/68360serial.c28
-rw-r--r--drivers/serial/8250.c3
-rw-r--r--drivers/serial/8250_early.c4
-rw-r--r--drivers/serial/8250_pci.c14
-rw-r--r--drivers/serial/Kconfig43
-rw-r--r--drivers/serial/Makefile1
-rw-r--r--drivers/serial/bfin_5xx.c4
-rw-r--r--drivers/serial/bfin_sport_uart.c614
-rw-r--r--drivers/serial/bfin_sport_uart.h63
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_core.c2
-rw-r--r--drivers/serial/crisv10.c31
-rw-r--r--drivers/serial/ioc3_serial.c36
-rw-r--r--drivers/serial/ioc4_serial.c32
-rw-r--r--drivers/serial/jsm/jsm.h1
-rw-r--r--drivers/serial/jsm/jsm_driver.c6
-rw-r--r--drivers/serial/kgdboc.c6
-rw-r--r--drivers/serial/mcfserial.c22
-rw-r--r--drivers/serial/mpc52xx_uart.c4
-rw-r--r--drivers/serial/netx-serial.c1
-rw-r--r--drivers/serial/s3c2410.c6
-rw-r--r--drivers/serial/sa1100.c4
-rw-r--r--drivers/serial/serial_core.c54
-rw-r--r--drivers/serial/sh-sci.c2
-rw-r--r--drivers/serial/sn_console.c2
-rw-r--r--drivers/serial/sunhv.c2
-rw-r--r--drivers/serial/sunsab.c2
-rw-r--r--drivers/serial/sunsu.c2
-rw-r--r--drivers/serial/sunzilog.c2
-rw-r--r--drivers/serial/uartlite.c2
-rw-r--r--drivers/serial/ucc_uart.c4
-rw-r--r--drivers/spi/atmel_spi.c29
-rw-r--r--drivers/spi/spi_bfin5xx.c7
-rw-r--r--drivers/spi/spi_s3c24xx.c6
-rw-r--r--drivers/thermal/Kconfig4
-rw-r--r--drivers/thermal/Makefile2
-rw-r--r--drivers/thermal/thermal_sys.c (renamed from drivers/thermal/thermal.c)165
-rw-r--r--drivers/usb/Makefile2
-rw-r--r--drivers/usb/atm/Kconfig4
-rw-r--r--drivers/usb/c67x00/Makefile9
-rw-r--r--drivers/usb/c67x00/c67x00-drv.c243
-rw-r--r--drivers/usb/c67x00/c67x00-hcd.c412
-rw-r--r--drivers/usb/c67x00/c67x00-hcd.h133
-rw-r--r--drivers/usb/c67x00/c67x00-ll-hpi.c480
-rw-r--r--drivers/usb/c67x00/c67x00-sched.c1170
-rw-r--r--drivers/usb/c67x00/c67x00.h294
-rw-r--r--drivers/usb/core/message.c4
-rw-r--r--drivers/usb/gadget/Kconfig20
-rw-r--r--drivers/usb/gadget/Makefile1
-rw-r--r--drivers/usb/gadget/ether.c8
-rw-r--r--drivers/usb/gadget/file_storage.c25
-rw-r--r--drivers/usb/gadget/pxa27x_udc.c2404
-rw-r--r--drivers/usb/gadget/pxa27x_udc.h487
-rw-r--r--drivers/usb/gadget/serial.c100
-rw-r--r--drivers/usb/gadget/zero.c370
-rw-r--r--drivers/usb/host/Kconfig39
-rw-r--r--drivers/usb/host/Makefile4
-rw-r--r--drivers/usb/host/isp1760-hcd.c2231
-rw-r--r--drivers/usb/host/isp1760-hcd.h206
-rw-r--r--drivers/usb/host/isp1760-if.c298
-rw-r--r--drivers/usb/host/ohci-hub.c2
-rw-r--r--drivers/usb/host/uhci-hcd.c74
-rw-r--r--drivers/usb/host/uhci-hcd.h5
-rw-r--r--drivers/usb/misc/ldusb.c28
-rw-r--r--drivers/usb/misc/usbtest.c276
-rw-r--r--drivers/usb/serial/aircable.c98
-rw-r--r--drivers/usb/serial/airprime.c63
-rw-r--r--drivers/usb/serial/ark3116.c54
-rw-r--r--drivers/usb/serial/ch341.c2
-rw-r--r--drivers/usb/serial/digi_acceleport.c3
-rw-r--r--drivers/usb/serial/ftdi_sio.c8
-rw-r--r--drivers/usb/serial/ftdi_sio.h11
-rw-r--r--drivers/usb/serial/mos7840.c5
-rw-r--r--drivers/usb/serial/usb-serial.c129
-rw-r--r--drivers/usb/serial/whiteheat.c4
-rw-r--r--drivers/usb/storage/Kconfig3
-rw-r--r--drivers/usb/storage/cypress_atacb.c2
-rw-r--r--drivers/usb/storage/isd200.c2
-rw-r--r--drivers/usb/storage/libusual.c2
-rw-r--r--drivers/usb/storage/onetouch.c4
-rw-r--r--drivers/usb/storage/unusual_devs.h28
-rw-r--r--drivers/usb/storage/usb.c3
-rw-r--r--drivers/video/Kconfig5
-rw-r--r--drivers/video/pxafb.c1297
-rw-r--r--drivers/video/pxafb.h70
-rw-r--r--drivers/virtio/virtio.c38
-rw-r--r--drivers/virtio/virtio_balloon.c12
-rw-r--r--drivers/virtio/virtio_pci.c34
-rw-r--r--drivers/virtio/virtio_ring.c5
-rw-r--r--drivers/w1/w1_log.h2
-rw-r--r--fs/Kconfig3
-rw-r--r--fs/adfs/adfs.h2
-rw-r--r--fs/affs/file.c4
-rw-r--r--fs/afs/dir.c4
-rw-r--r--fs/afs/internal.h8
-rw-r--r--fs/aio.c5
-rw-r--r--fs/anon_inodes.c13
-rw-r--r--fs/autofs4/autofs_i.h2
-rw-r--r--fs/autofs4/expire.c26
-rw-r--r--fs/autofs4/root.c38
-rw-r--r--fs/autofs4/waitq.c2
-rw-r--r--fs/bfs/bfs.h2
-rw-r--r--fs/buffer.c2
-rw-r--r--fs/compat.c15
-rw-r--r--fs/compat_ioctl.c4
-rw-r--r--fs/configfs/file.c2
-rw-r--r--fs/configfs/inode.c2
-rw-r--r--fs/configfs/mount.c2
-rw-r--r--fs/configfs/symlink.c4
-rw-r--r--fs/debugfs/file.c2
-rw-r--r--fs/devpts/inode.c43
-rw-r--r--fs/dlm/lockspace.c2
-rw-r--r--fs/dnotify.c11
-rw-r--r--fs/eventfd.c15
-rw-r--r--fs/eventpoll.c30
-rw-r--r--fs/exec.c18
-rw-r--r--fs/exportfs/expfs.c10
-rw-r--r--fs/ext3/inode.c14
-rw-r--r--fs/ext4/acl.c12
-rw-r--r--fs/ext4/balloc.c33
-rw-r--r--fs/ext4/bitmap.c2
-rw-r--r--fs/ext4/dir.c4
-rw-r--r--fs/ext4/ext4.h (renamed from include/linux/ext4_fs.h)18
-rw-r--r--fs/ext4/ext4_extents.h (renamed from include/linux/ext4_fs_extents.h)8
-rw-r--r--fs/ext4/ext4_i.h (renamed from include/linux/ext4_fs_i.h)8
-rw-r--r--fs/ext4/ext4_jbd2.c14
-rw-r--r--fs/ext4/ext4_jbd2.h (renamed from include/linux/ext4_jbd2.h)10
-rw-r--r--fs/ext4/ext4_sb.h (renamed from include/linux/ext4_fs_sb.h)8
-rw-r--r--fs/ext4/extents.c354
-rw-r--r--fs/ext4/file.c6
-rw-r--r--fs/ext4/fsync.c7
-rw-r--r--fs/ext4/hash.c2
-rw-r--r--fs/ext4/ialloc.c44
-rw-r--r--fs/ext4/inode.c57
-rw-r--r--fs/ext4/ioctl.c16
-rw-r--r--fs/ext4/mballoc.c437
-rw-r--r--fs/ext4/mballoc.h304
-rw-r--r--fs/ext4/migrate.c43
-rw-r--r--fs/ext4/namei.c44
-rw-r--r--fs/ext4/resize.c83
-rw-r--r--fs/ext4/super.c66
-rw-r--r--fs/ext4/symlink.c2
-rw-r--r--fs/ext4/xattr.c40
-rw-r--r--fs/ext4/xattr.h7
-rw-r--r--fs/ext4/xattr_security.c4
-rw-r--r--fs/ext4/xattr_trusted.c4
-rw-r--r--fs/ext4/xattr_user.c4
-rw-r--r--fs/fat/cache.c6
-rw-r--r--fs/fat/fatent.c2
-rw-r--r--fs/fat/file.c2
-rw-r--r--fs/fcntl.c1
-rw-r--r--fs/file.c23
-rw-r--r--fs/file_table.c1
-rw-r--r--fs/fuse/control.c2
-rw-r--r--fs/fuse/dev.c23
-rw-r--r--fs/fuse/dir.c86
-rw-r--r--fs/fuse/file.c633
-rw-r--r--fs/fuse/fuse_i.h52
-rw-r--r--fs/fuse/inode.c90
-rw-r--r--fs/gfs2/locking/dlm/sysfs.c2
-rw-r--r--fs/gfs2/util.h18
-rw-r--r--fs/hfs/btree.c10
-rw-r--r--fs/hfs/mdb.c2
-rw-r--r--fs/hfsplus/btree.c10
-rw-r--r--fs/hfsplus/super.c2
-rw-r--r--fs/hugetlbfs/inode.c2
-rw-r--r--fs/isofs/dir.c8
-rw-r--r--fs/isofs/namei.c7
-rw-r--r--fs/jbd2/commit.c19
-rw-r--r--fs/jbd2/journal.c38
-rw-r--r--fs/jbd2/revoke.c165
-rw-r--r--fs/jbd2/transaction.c41
-rw-r--r--fs/jffs2/build.c31
-rw-r--r--fs/jffs2/debug.h8
-rw-r--r--fs/jffs2/dir.c42
-rw-r--r--fs/jffs2/erase.c9
-rw-r--r--fs/jffs2/fs.c14
-rw-r--r--fs/jffs2/gc.c8
-rw-r--r--fs/jffs2/nodelist.h5
-rw-r--r--fs/jffs2/nodemgmt.c2
-rw-r--r--fs/jffs2/os-linux.h2
-rw-r--r--fs/jffs2/readinode.c16
-rw-r--r--fs/jffs2/scan.c9
-rw-r--r--fs/jffs2/super.c15
-rw-r--r--fs/jffs2/wbuf.c2
-rw-r--r--fs/jffs2/write.c17
-rw-r--r--fs/jffs2/xattr.c8
-rw-r--r--fs/lockd/clntproc.c2
-rw-r--r--fs/lockd/svclock.c2
-rw-r--r--fs/locks.c1
-rw-r--r--fs/msdos/namei.c2
-rw-r--r--fs/namespace.c4
-rw-r--r--fs/nfs/super.c26
-rw-r--r--fs/nfsd/nfs4callback.c4
-rw-r--r--fs/ntfs/debug.h6
-rw-r--r--fs/ocfs2/cluster/sys.c2
-rw-r--r--fs/ocfs2/dlm/dlmdebug.c8
-rw-r--r--fs/ocfs2/dlm/dlmfs.c2
-rw-r--r--fs/ocfs2/file.c4
-rw-r--r--fs/ocfs2/localalloc.c4
-rw-r--r--fs/ocfs2/stack_o2cb.c2
-rw-r--r--fs/ocfs2/stack_user.c2
-rw-r--r--fs/ocfs2/symlink.c2
-rw-r--r--fs/open.c1
-rw-r--r--fs/partitions/ldm.c8
-rw-r--r--fs/pipe.c17
-rw-r--r--fs/proc/array.c7
-rw-r--r--fs/proc/base.c1
-rw-r--r--fs/proc/generic.c17
-rw-r--r--fs/proc/proc_misc.c2
-rw-r--r--fs/proc/proc_net.c11
-rw-r--r--fs/proc/proc_tty.c6
-rw-r--r--fs/proc/task_nommu.c1
-rw-r--r--fs/quota_v2.c4
-rw-r--r--fs/ramfs/inode.c2
-rw-r--r--fs/reiserfs/journal.c50
-rw-r--r--fs/select.c15
-rw-r--r--fs/signalfd.c17
-rw-r--r--fs/smbfs/smb_debug.h6
-rw-r--r--fs/sysfs/file.c2
-rw-r--r--fs/sysfs/inode.c4
-rw-r--r--fs/sysfs/mount.c2
-rw-r--r--fs/sysv/sysv.h8
-rw-r--r--fs/timerfd.c11
-rw-r--r--fs/udf/super.c4
-rw-r--r--fs/utimes.c17
-rw-r--r--fs/vfat/namei.c2
-rw-r--r--fs/xfs/Kconfig13
-rw-r--r--fs/xfs/linux-2.6/mrlock.h60
-rw-r--r--fs/xfs/linux-2.6/xfs_buf.c2
-rw-r--r--fs/xfs/linux-2.6/xfs_export.c2
-rw-r--r--fs/xfs/linux-2.6/xfs_file.c75
-rw-r--r--fs/xfs/linux-2.6/xfs_ioctl.c8
-rw-r--r--fs/xfs/linux-2.6/xfs_iops.c3
-rw-r--r--fs/xfs/linux-2.6/xfs_linux.h2
-rw-r--r--fs/xfs/linux-2.6/xfs_lrw.c21
-rw-r--r--fs/xfs/linux-2.6/xfs_lrw.h1
-rw-r--r--fs/xfs/linux-2.6/xfs_super.c2
-rw-r--r--fs/xfs/linux-2.6/xfs_vnode.h24
-rw-r--r--fs/xfs/quota/xfs_dquot.c4
-rw-r--r--fs/xfs/quota/xfs_qm.c27
-rw-r--r--fs/xfs/quota/xfs_qm_syscalls.c6
-rw-r--r--fs/xfs/quota/xfs_quota_priv.h5
-rw-r--r--fs/xfs/quota/xfs_trans_dquot.c2
-rw-r--r--fs/xfs/support/debug.h2
-rw-r--r--fs/xfs/xfs.h2
-rw-r--r--fs/xfs/xfs_acl.c53
-rw-r--r--fs/xfs/xfs_attr.c93
-rw-r--r--fs/xfs/xfs_attr.h6
-rw-r--r--fs/xfs/xfs_bmap.c1
-rw-r--r--fs/xfs/xfs_dfrag.c4
-rw-r--r--fs/xfs/xfs_fsops.c8
-rw-r--r--fs/xfs/xfs_ialloc.c10
-rw-r--r--fs/xfs/xfs_iget.c140
-rw-r--r--fs/xfs/xfs_inode.c25
-rw-r--r--fs/xfs/xfs_inode.h16
-rw-r--r--fs/xfs/xfs_inode_item.c12
-rw-r--r--fs/xfs/xfs_iomap.c19
-rw-r--r--fs/xfs/xfs_itable.c6
-rw-r--r--fs/xfs/xfs_mount.c83
-rw-r--r--fs/xfs/xfs_mount.h7
-rw-r--r--fs/xfs/xfs_rename.c252
-rw-r--r--fs/xfs/xfs_trans_inode.c12
-rw-r--r--fs/xfs/xfs_utils.c45
-rw-r--r--fs/xfs/xfs_utils.h2
-rw-r--r--fs/xfs/xfs_vfsops.c1
-rw-r--r--fs/xfs/xfs_vnodeops.c274
-rw-r--r--fs/xfs/xfs_vnodeops.h8
-rw-r--r--include/acpi/acconfig.h15
-rw-r--r--include/acpi/acdebug.h2
-rw-r--r--include/acpi/acdisasm.h38
-rw-r--r--include/acpi/acdispat.h31
-rw-r--r--include/acpi/acevents.h2
-rw-r--r--include/acpi/acexcep.h2
-rw-r--r--include/acpi/acglobal.h38
-rw-r--r--include/acpi/achware.h2
-rw-r--r--include/acpi/acinterp.h15
-rw-r--r--include/acpi/aclocal.h10
-rw-r--r--include/acpi/acmacros.h71
-rw-r--r--include/acpi/acnames.h2
-rw-r--r--include/acpi/acnamesp.h5
-rw-r--r--include/acpi/acobject.h5
-rw-r--r--include/acpi/acopcode.h6
-rw-r--r--include/acpi/acoutput.h2
-rw-r--r--include/acpi/acparser.h4
-rw-r--r--include/acpi/acpi.h2
-rw-r--r--include/acpi/acpiosxf.h2
-rw-r--r--include/acpi/acpixf.h7
-rw-r--r--include/acpi/acresrc.h3
-rw-r--r--include/acpi/acstruct.h5
-rw-r--r--include/acpi/actables.h2
-rw-r--r--include/acpi/actbl.h2
-rw-r--r--include/acpi/actbl1.h561
-rw-r--r--include/acpi/actypes.h93
-rw-r--r--include/acpi/acutils.h4
-rw-r--r--include/acpi/amlcode.h2
-rw-r--r--include/acpi/amlresrc.h2
-rw-r--r--include/acpi/platform/acenv.h2
-rw-r--r--include/acpi/platform/acgcc.h2
-rw-r--r--include/acpi/platform/aclinux.h2
-rw-r--r--include/asm-alpha/types.h30
-rw-r--r--include/asm-arm/arch-pxa/pxa-regs.h196
-rw-r--r--include/asm-arm/arch-pxa/pxafb.h71
-rw-r--r--include/asm-arm/arch-pxa/regs-lcd.h171
-rw-r--r--include/asm-arm/div64.h2
-rw-r--r--include/asm-arm/types.h33
-rw-r--r--include/asm-avr32/types.h32
-rw-r--r--include/asm-blackfin/types.h34
-rw-r--r--include/asm-cris/types.h33
-rw-r--r--include/asm-frv/types.h34
-rw-r--r--include/asm-frv/unaligned.h6
-rw-r--r--include/asm-generic/Kbuild2
-rw-r--r--include/asm-generic/bitops.h4
-rw-r--r--include/asm-generic/div64.h7
-rw-r--r--include/asm-generic/futex.h5
-rw-r--r--include/asm-generic/int-l64.h71
-rw-r--r--include/asm-generic/int-ll64.h76
-rw-r--r--include/asm-generic/memory_model.h2
-rw-r--r--include/asm-generic/page.h2
-rw-r--r--include/asm-generic/rtc.h3
-rw-r--r--include/asm-h8300/types.h33
-rw-r--r--include/asm-ia64/cpu.h2
-rw-r--r--include/asm-ia64/dmi.h5
-rw-r--r--include/asm-ia64/futex.h2
-rw-r--r--include/asm-ia64/io.h5
-rw-r--r--include/asm-ia64/thread_info.h16
-rw-r--r--include/asm-ia64/topology.h2
-rw-r--r--include/asm-ia64/types.h31
-rw-r--r--include/asm-ia64/uncached.h6
-rw-r--r--include/asm-m32r/types.h32
-rw-r--r--include/asm-m68k/div64.h1
-rw-r--r--include/asm-m68k/machw.h30
-rw-r--r--include/asm-m68k/types.h32
-rw-r--r--include/asm-m68knommu/dma.h3
-rw-r--r--include/asm-m68knommu/param.h7
-rw-r--r--include/asm-mips/div64.h6
-rw-r--r--include/asm-mips/futex.h2
-rw-r--r--include/asm-mips/types.h58
-rw-r--r--include/asm-mn10300/div64.h3
-rw-r--r--include/asm-mn10300/types.h33
-rw-r--r--include/asm-parisc/futex.h2
-rw-r--r--include/asm-parisc/types.h33
-rw-r--r--include/asm-powerpc/futex.h2
-rw-r--r--include/asm-powerpc/io.h8
-rw-r--r--include/asm-powerpc/kvm_host.h1
-rw-r--r--include/asm-powerpc/kvm_ppc.h5
-rw-r--r--include/asm-powerpc/ps3.h3
-rw-r--r--include/asm-powerpc/syscalls.h2
-rw-r--r--include/asm-powerpc/types.h48
-rw-r--r--include/asm-s390/ccwgroup.h7
-rw-r--r--include/asm-s390/hugetlb.h183
-rw-r--r--include/asm-s390/page.h49
-rw-r--r--include/asm-s390/pgtable.h21
-rw-r--r--include/asm-s390/processor.h9
-rw-r--r--include/asm-s390/ptrace.h2
-rw-r--r--include/asm-s390/qdio.h1
-rw-r--r--include/asm-s390/setup.h39
-rw-r--r--include/asm-s390/smp.h12
-rw-r--r--include/asm-s390/sparsemem.h18
-rw-r--r--include/asm-s390/sysinfo.h5
-rw-r--r--include/asm-s390/system.h18
-rw-r--r--include/asm-s390/thread_info.h2
-rw-r--r--include/asm-s390/tlbflush.h1
-rw-r--r--include/asm-s390/topology.h4
-rw-r--r--include/asm-s390/types.h48
-rw-r--r--include/asm-sh/futex.h2
-rw-r--r--include/asm-sh/types.h34
-rw-r--r--include/asm-sparc/head.h11
-rw-r--r--include/asm-sparc/kgdb.h116
-rw-r--r--include/asm-sparc/oplib.h17
-rw-r--r--include/asm-sparc/page.h5
-rw-r--r--include/asm-sparc/smp.h2
-rw-r--r--include/asm-sparc/system.h2
-rw-r--r--include/asm-sparc/types.h30
-rw-r--r--include/asm-sparc64/futex.h2
-rw-r--r--include/asm-sparc64/kgdb.h1
-rw-r--r--include/asm-sparc64/pil.h7
-rw-r--r--include/asm-sparc64/system.h5
-rw-r--r--include/asm-sparc64/ttable.h6
-rw-r--r--include/asm-sparc64/types.h30
-rw-r--r--include/asm-um/div64.h1
-rw-r--r--include/asm-v850/types.h32
-rw-r--r--include/asm-x86/bootparam.h8
-rw-r--r--include/asm-x86/div64.h34
-rw-r--r--include/asm-x86/dmi.h1
-rw-r--r--include/asm-x86/futex.h2
-rw-r--r--include/asm-x86/io_32.h5
-rw-r--r--include/asm-x86/kvm_host.h10
-rw-r--r--include/asm-x86/mach-default/mach_apic.h7
-rw-r--r--include/asm-x86/processor.h3
-rw-r--r--include/asm-x86/proto.h4
-rw-r--r--include/asm-x86/thread_info_32.h13
-rw-r--r--include/asm-x86/thread_info_64.h13
-rw-r--r--include/asm-x86/topology.h4
-rw-r--r--include/asm-x86/types.h38
-rw-r--r--include/asm-xtensa/types.h33
-rw-r--r--include/crypto/scatterwalk.h4
-rw-r--r--include/linux/Kbuild5
-rw-r--r--include/linux/agp_backend.h3
-rw-r--r--include/linux/anon_inodes.h3
-rw-r--r--include/linux/backing-dev.h100
-rw-r--r--include/linux/byteorder/Kbuild6
-rw-r--r--include/linux/byteorder/big_endian.h2
-rw-r--r--include/linux/byteorder/generic.h8
-rw-r--r--include/linux/byteorder/little_endian.h2
-rw-r--r--include/linux/calc64.h49
-rw-r--r--include/linux/cdev.h2
-rw-r--r--include/linux/clocksource.h2
-rw-r--r--include/linux/coda_fs_i.h2
-rw-r--r--include/linux/compat.h3
-rw-r--r--include/linux/compiler-gcc.h5
-rw-r--r--include/linux/concap.h3
-rw-r--r--include/linux/configfs.h4
-rw-r--r--include/linux/console.h4
-rw-r--r--include/linux/crc-ccitt.h2
-rw-r--r--include/linux/dcache.h4
-rw-r--r--include/linux/debugobjects.h90
-rw-r--r--include/linux/device-mapper.h3
-rw-r--r--include/linux/device.h105
-rw-r--r--include/linux/devpts_fs.h4
-rw-r--r--include/linux/eventfd.h5
-rw-r--r--include/linux/fdtable.h99
-rw-r--r--include/linux/file.h86
-rw-r--r--include/linux/fsl_devices.h2
-rw-r--r--include/linux/fsnotify.h4
-rw-r--r--include/linux/generic_serial.h2
-rw-r--r--include/linux/hrtimer.h24
-rw-r--r--include/linux/hw_random.h2
-rw-r--r--include/linux/i2o.h3
-rw-r--r--include/linux/ieee80211.h2
-rw-r--r--include/linux/if_bridge.h4
-rw-r--r--include/linux/if_macvlan.h3
-rw-r--r--include/linux/inet.h2
-rw-r--r--include/linux/init_task.h2
-rw-r--r--include/linux/io.h5
-rw-r--r--include/linux/irq.h1
-rw-r--r--include/linux/isapnp.h10
-rw-r--r--include/linux/isicom.h7
-rw-r--r--include/linux/jiffies.h2
-rw-r--r--include/linux/kernel.h91
-rw-r--r--include/linux/kfifo.h5
-rw-r--r--include/linux/kgdb.h4
-rw-r--r--include/linux/klist.h40
-rw-r--r--include/linux/kobj_map.h4
-rw-r--r--include/linux/kobject.h3
-rw-r--r--include/linux/kref.h3
-rw-r--r--include/linux/list.h5
-rw-r--r--include/linux/math64.h84
-rw-r--r--include/linux/mmzone.h3
-rw-r--r--include/linux/module.h19
-rw-r--r--include/linux/mount.h2
-rw-r--r--include/linux/mtd/jedec.h66
-rw-r--r--include/linux/mtd/mtd.h6
-rw-r--r--include/linux/mtd/pmc551.h5
-rw-r--r--include/linux/ncp_fs_i.h4
-rw-r--r--include/linux/of_device.h2
-rw-r--r--include/linux/pci.h5
-rw-r--r--include/linux/pci_ids.h1
-rw-r--r--include/linux/pda_power.h4
-rw-r--r--include/linux/pid.h8
-rw-r--r--include/linux/pid_namespace.h2
-rw-r--r--include/linux/pm.h4
-rw-r--r--include/linux/pnp.h212
-rw-r--r--include/linux/pnpbios.h151
-rw-r--r--include/linux/poison.h7
-rw-r--r--include/linux/poll.h2
-rw-r--r--include/linux/profile.h4
-rw-r--r--include/linux/proportions.h13
-rw-r--r--include/linux/ptrace.h4
-rw-r--r--include/linux/quota.h3
-rw-r--r--include/linux/raid/md.h1
-rw-r--r--include/linux/raid/md_k.h4
-rw-r--r--include/linux/rcuclassic.h3
-rw-r--r--include/linux/rcupdate.h3
-rw-r--r--include/linux/rcupreempt.h3
-rw-r--r--include/linux/rcupreempt_trace.h2
-rw-r--r--include/linux/reiserfs_fs_sb.h1
-rw-r--r--include/linux/rio.h5
-rw-r--r--include/linux/rio_drv.h3
-rw-r--r--include/linux/rwsem.h3
-rw-r--r--include/linux/sched.h56
-rw-r--r--include/linux/seq_file.h2
-rw-r--r--include/linux/serial_core.h6
-rw-r--r--include/linux/signal.h2
-rw-r--r--include/linux/slab.h10
-rw-r--r--include/linux/smb_fs_i.h2
-rw-r--r--include/linux/smb_fs_sb.h4
-rw-r--r--include/linux/string.h2
-rw-r--r--include/linux/svga.h3
-rw-r--r--include/linux/sysfs.h6
-rw-r--r--include/linux/textsearch.h4
-rw-r--r--include/linux/thermal.h39
-rw-r--r--include/linux/thread_info.h27
-rw-r--r--include/linux/timer.h23
-rw-r--r--include/linux/timex.h46
-rw-r--r--include/linux/tty.h25
-rw-r--r--include/linux/tty_driver.h106
-rw-r--r--include/linux/usb/c67x00.h48
-rw-r--r--include/linux/usb/ch9.h12
-rw-r--r--include/linux/usb/gadget.h21
-rw-r--r--include/linux/virtio.h7
-rw-r--r--include/linux/virtio_blk.h14
-rw-r--r--include/linux/virtio_config.h81
-rw-r--r--include/linux/virtio_net.h13
-rw-r--r--include/linux/wireless.h7
-rw-r--r--include/linux/writeback.h3
-rw-r--r--include/net/compat.h3
-rw-r--r--include/net/ip_vs.h3
-rw-r--r--include/net/netfilter/nf_conntrack_tuple.h10
-rw-r--r--include/net/route.h2
-rw-r--r--include/scsi/scsi.h40
-rw-r--r--include/scsi/scsi_cmnd.h23
-rw-r--r--include/scsi/scsi_eh.h4
-rw-r--r--include/scsi/scsi_host.h8
-rw-r--r--init/Kconfig22
-rw-r--r--init/main.c8
-rw-r--r--ipc/mqueue.c3
-rw-r--r--kernel/Makefile2
-rw-r--r--kernel/cgroup.c2
-rw-r--r--kernel/compat.c6
-rw-r--r--kernel/cpu.c4
-rw-r--r--kernel/exit.c67
-rw-r--r--kernel/fork.c3
-rw-r--r--kernel/futex.c193
-rw-r--r--kernel/hrtimer.c186
-rw-r--r--kernel/irq/manage.c49
-rw-r--r--kernel/irq/spurious.c4
-rw-r--r--kernel/kexec.c2
-rw-r--r--kernel/kgdb.c8
-rw-r--r--kernel/kmod.c1
-rw-r--r--kernel/kthread.c2
-rw-r--r--kernel/marker.c2
-rw-r--r--kernel/module.c363
-rw-r--r--kernel/pid.c41
-rw-r--r--kernel/pid_namespace.c2
-rw-r--r--kernel/posix-cpu-timers.c11
-rw-r--r--kernel/posix-timers.c6
-rw-r--r--kernel/power/Kconfig10
-rw-r--r--kernel/power/Makefile1
-rw-r--r--kernel/power/pm.c205
-rw-r--r--kernel/printk.c96
-rw-r--r--kernel/ptrace.c15
-rw-r--r--kernel/sched.c325
-rw-r--r--kernel/sched_clock.c236
-rw-r--r--kernel/sched_debug.c11
-rw-r--r--kernel/sched_fair.c39
-rw-r--r--kernel/sched_idletask.c2
-rw-r--r--kernel/sched_rt.c9
-rw-r--r--kernel/signal.c646
-rw-r--r--kernel/softirq.c20
-rw-r--r--kernel/sys.c79
-rw-r--r--kernel/taskstats.c6
-rw-r--r--kernel/time.c62
-rw-r--r--kernel/time/clocksource.c4
-rw-r--r--kernel/time/ntp.c398
-rw-r--r--kernel/time/timekeeping.c17
-rw-r--r--kernel/timeconst.pl120
-rw-r--r--kernel/timer.c153
-rw-r--r--kernel/user.c18
-rw-r--r--kernel/workqueue.c8
-rw-r--r--lib/Kconfig.debug31
-rw-r--r--lib/Kconfig.kgdb16
-rw-r--r--lib/Makefile1
-rw-r--r--lib/debugobjects.c890
-rw-r--r--lib/devres.c6
-rw-r--r--lib/div64.c35
-rw-r--r--lib/idr.c2
-rw-r--r--lib/klist.c235
-rw-r--r--lib/kobject.c44
-rw-r--r--lib/kobject_uevent.c10
-rw-r--r--lib/percpu_counter.c1
-rw-r--r--lib/proportions.c38
-rw-r--r--lib/string.c27
-rw-r--r--mm/backing-dev.c219
-rw-r--r--mm/memcontrol.c11
-rw-r--r--mm/migrate.c9
-rw-r--r--mm/page-writeback.c77
-rw-r--r--mm/page_alloc.c10
-rw-r--r--mm/readahead.c8
-rw-r--r--mm/shmem.c2
-rw-r--r--mm/slab.c14
-rw-r--r--mm/slub.c56
-rw-r--r--mm/sparse.c19
-rw-r--r--mm/swap_state.c2
-rw-r--r--mm/vmalloc.c3
-rw-r--r--mm/vmscan.c4
-rw-r--r--mm/vmstat.c5
-rw-r--r--net/8021q/vlanproc.c7
-rw-r--r--net/atm/proc.c6
-rw-r--r--net/bluetooth/bnep/core.c8
-rw-r--r--net/bluetooth/hci_event.c9
-rw-r--r--net/bluetooth/hci_sock.c2
-rw-r--r--net/bluetooth/l2cap.c2
-rw-r--r--net/bridge/br.c2
-rw-r--r--net/bridge/br_fdb.c4
-rw-r--r--net/bridge/br_if.c5
-rw-r--r--net/bridge/br_stp_bpdu.c4
-rw-r--r--net/can/bcm.c6
-rw-r--r--net/compat.c90
-rw-r--r--net/core/dev.c19
-rw-r--r--net/core/filter.c4
-rw-r--r--net/core/neighbour.c5
-rw-r--r--net/core/net-sysfs.c7
-rw-r--r--net/core/net-sysfs.h2
-rw-r--r--net/core/pktgen.c12
-rw-r--r--net/core/sock.c3
-rw-r--r--net/dccp/ccids/ccid2.c2
-rw-r--r--net/dccp/ccids/ccid3.c4
-rw-r--r--net/ipv4/cipso_ipv4.c18
-rw-r--r--net/ipv4/icmp.c3
-rw-r--r--net/ipv4/ip_output.c22
-rw-r--r--net/ipv4/ip_sockglue.c9
-rw-r--r--net/ipv4/ipconfig.c8
-rw-r--r--net/ipv4/ipvs/ip_vs_proto.c2
-rw-r--r--net/ipv4/ipvs/ip_vs_proto_ah.c1
-rw-r--r--net/ipv4/ipvs/ip_vs_proto_esp.c1
-rw-r--r--net/ipv4/ipvs/ip_vs_proto_tcp.c1
-rw-r--r--net/ipv4/ipvs/ip_vs_proto_udp.c1
-rw-r--r--net/ipv4/ipvs/ip_vs_sync.c80
-rw-r--r--net/ipv4/netfilter/ip_queue.c5
-rw-r--r--net/ipv4/netfilter/ipt_CLUSTERIP.c6
-rw-r--r--net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c2
-rw-r--r--net/ipv4/route.c38
-rw-r--r--net/ipv4/tcp_cong.c12
-rw-r--r--net/ipv4/tcp_cubic.c4
-rw-r--r--net/ipv4/tcp_hybla.c6
-rw-r--r--net/ipv4/tcp_input.c18
-rw-r--r--net/ipv4/tcp_ipv4.c10
-rw-r--r--net/ipv4/tcp_vegas.c16
-rw-r--r--net/ipv4/tcp_veno.c14
-rw-r--r--net/ipv4/udp.c7
-rw-r--r--net/ipv6/ipv6_sockglue.c4
-rw-r--r--net/ipv6/netfilter/ip6_queue.c5
-rw-r--r--net/ipv6/proc.c6
-rw-r--r--net/ipv6/reassembly.c4
-rw-r--r--net/irda/ircomm/ircomm_tty.c6
-rw-r--r--net/irda/iriap.c8
-rw-r--r--net/mac80211/ieee80211_i.h2
-rw-r--r--net/mac80211/main.c47
-rw-r--r--net/mac80211/mesh.c17
-rw-r--r--net/mac80211/mesh.h2
-rw-r--r--net/mac80211/tkip.c6
-rw-r--r--net/netfilter/nf_conntrack_core.c4
-rw-r--r--net/netfilter/nf_conntrack_standalone.c6
-rw-r--r--net/netfilter/nfnetlink_queue.c5
-rw-r--r--net/netfilter/x_tables.c15
-rw-r--r--net/netfilter/xt_TCPOPTSTRIP.c2
-rw-r--r--net/netfilter/xt_connbytes.c5
-rw-r--r--net/netfilter/xt_hashlimit.c12
-rw-r--r--net/rose/rose_route.c8
-rw-r--r--net/rxrpc/ar-transport.c3
-rw-r--r--net/sched/sch_generic.c1
-rw-r--r--net/sched/sch_sfq.c3
-rw-r--r--net/sunrpc/cache.c15
-rw-r--r--net/sunrpc/stats.c8
-rw-r--r--net/sysctl_net.c2
-rw-r--r--scripts/kallsyms.c6
-rw-r--r--scripts/kconfig/lkc.h6
-rw-r--r--scripts/kconfig/lxdialog/check-lxdialog.sh6
-rw-r--r--scripts/kconfig/mconf.c3
-rw-r--r--scripts/mod/file2alias.c35
-rw-r--r--security/selinux/hooks.c4
-rw-r--r--security/smack/smack_lsm.c164
-rw-r--r--sound/drivers/pcsp/pcsp.c4
-rw-r--r--sound/pci/Kconfig5
-rw-r--r--sound/pci/ac97/ac97_patch.c9
-rw-r--r--sound/pci/hda/patch_realtek.c5
-rw-r--r--sound/pci/hda/patch_sigmatel.c2
-rw-r--r--sound/soc/codecs/wm8753.c34
-rw-r--r--sound/soc/s3c24xx/ln2440sbc_alc650.c4
-rw-r--r--sound/soc/s3c24xx/neo1973_wm8753.c58
-rw-r--r--sound/soc/s3c24xx/s3c2443-ac97.c9
-rw-r--r--sound/soc/s3c24xx/s3c24xx-i2s.c2
-rw-r--r--sound/soc/s3c24xx/s3c24xx-pcm.c35
-rw-r--r--virt/kvm/kvm_main.c22
1399 files changed, 62160 insertions, 25743 deletions
diff --git a/.gitignore b/.gitignore
index 3016ed30526d..090b293b8779 100644
--- a/.gitignore
+++ b/.gitignore
@@ -41,6 +41,7 @@ include/linux/autoconf.h
41include/linux/compile.h 41include/linux/compile.h
42include/linux/version.h 42include/linux/version.h
43include/linux/utsrelease.h 43include/linux/utsrelease.h
44include/linux/bounds.h
44 45
45# stgit generated dirs 46# stgit generated dirs
46patches-* 47patches-*
diff --git a/.mailmap b/.mailmap
index ebf9bf84da0a..726084286d33 100644
--- a/.mailmap
+++ b/.mailmap
@@ -88,6 +88,7 @@ Rudolf Marek <R.Marek@sh.cvut.cz>
88Rui Saraiva <rmps@joel.ist.utl.pt> 88Rui Saraiva <rmps@joel.ist.utl.pt>
89Sachin P Sant <ssant@in.ibm.com> 89Sachin P Sant <ssant@in.ibm.com>
90Sam Ravnborg <sam@mars.ravnborg.org> 90Sam Ravnborg <sam@mars.ravnborg.org>
91S.Çağlar Onur <caglar@pardus.org.tr>
91Simon Kelley <simon@thekelleys.org.uk> 92Simon Kelley <simon@thekelleys.org.uk>
92Stéphane Witzmann <stephane.witzmann@ubpmes.univ-bpclermont.fr> 93Stéphane Witzmann <stephane.witzmann@ubpmes.univ-bpclermont.fr>
93Stephen Hemminger <shemminger@osdl.org> 94Stephen Hemminger <shemminger@osdl.org>
diff --git a/Documentation/ABI/testing/sysfs-class-bdi b/Documentation/ABI/testing/sysfs-class-bdi
new file mode 100644
index 000000000000..5ac1e01bbd48
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-class-bdi
@@ -0,0 +1,46 @@
1What: /sys/class/bdi/<bdi>/
2Date: January 2008
3Contact: Peter Zijlstra <a.p.zijlstra@chello.nl>
4Description:
5
6Provide a place in sysfs for the backing_dev_info object. This allows
7setting and retrieving various BDI specific variables.
8
9The <bdi> identifier can be either of the following:
10
11MAJOR:MINOR
12
13 Device number for block devices, or value of st_dev on
14 non-block filesystems which provide their own BDI, such as NFS
15 and FUSE.
16
17default
18
19 The default backing dev, used for non-block device backed
20 filesystems which do not provide their own BDI.
21
22Files under /sys/class/bdi/<bdi>/
23---------------------------------
24
25read_ahead_kb (read-write)
26
27 Size of the read-ahead window in kilobytes
28
29min_ratio (read-write)
30
31 Under normal circumstances each device is given a part of the
32 total write-back cache that relates to its current average
33 writeout speed in relation to the other devices.
34
35 The 'min_ratio' parameter allows assigning a minimum
36 percentage of the write-back cache to a particular device.
37 For example, this is useful for providing a minimum QoS.
38
39max_ratio (read-write)
40
41 Allows limiting a particular device to use not more than the
42 given percentage of the write-back cache. This is useful in
43 situations where we want to avoid one device taking all or
44 most of the write-back cache. For example in case of an NFS
45 mount that is prone to get stuck, or a FUSE mount which cannot
46 be trusted to play fair.
diff --git a/Documentation/DocBook/Makefile b/Documentation/DocBook/Makefile
index 83966e94cc32..0eb0d027eb32 100644
--- a/Documentation/DocBook/Makefile
+++ b/Documentation/DocBook/Makefile
@@ -12,7 +12,7 @@ DOCBOOKS := wanbook.xml z8530book.xml mcabook.xml videobook.xml \
12 kernel-api.xml filesystems.xml lsm.xml usb.xml kgdb.xml \ 12 kernel-api.xml filesystems.xml lsm.xml usb.xml kgdb.xml \
13 gadget.xml libata.xml mtdnand.xml librs.xml rapidio.xml \ 13 gadget.xml libata.xml mtdnand.xml librs.xml rapidio.xml \
14 genericirq.xml s390-drivers.xml uio-howto.xml scsi.xml \ 14 genericirq.xml s390-drivers.xml uio-howto.xml scsi.xml \
15 mac80211.xml 15 mac80211.xml debugobjects.xml
16 16
17### 17###
18# The build process is as follows (targets): 18# The build process is as follows (targets):
diff --git a/Documentation/DocBook/debugobjects.tmpl b/Documentation/DocBook/debugobjects.tmpl
new file mode 100644
index 000000000000..7f5f218015fe
--- /dev/null
+++ b/Documentation/DocBook/debugobjects.tmpl
@@ -0,0 +1,391 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>
4
5<book id="debug-objects-guide">
6 <bookinfo>
7 <title>Debug objects life time</title>
8
9 <authorgroup>
10 <author>
11 <firstname>Thomas</firstname>
12 <surname>Gleixner</surname>
13 <affiliation>
14 <address>
15 <email>tglx@linutronix.de</email>
16 </address>
17 </affiliation>
18 </author>
19 </authorgroup>
20
21 <copyright>
22 <year>2008</year>
23 <holder>Thomas Gleixner</holder>
24 </copyright>
25
26 <legalnotice>
27 <para>
28 This documentation is free software; you can redistribute
29 it and/or modify it under the terms of the GNU General Public
30 License version 2 as published by the Free Software Foundation.
31 </para>
32
33 <para>
34 This program is distributed in the hope that it will be
35 useful, but WITHOUT ANY WARRANTY; without even the implied
36 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
37 See the GNU General Public License for more details.
38 </para>
39
40 <para>
41 You should have received a copy of the GNU General Public
42 License along with this program; if not, write to the Free
43 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
44 MA 02111-1307 USA
45 </para>
46
47 <para>
48 For more details see the file COPYING in the source
49 distribution of Linux.
50 </para>
51 </legalnotice>
52 </bookinfo>
53
54<toc></toc>
55
56 <chapter id="intro">
57 <title>Introduction</title>
58 <para>
59 debugobjects is a generic infrastructure to track the life time
60 of kernel objects and validate the operations on those.
61 </para>
62 <para>
63 debugobjects is useful to check for the following error patterns:
64 <itemizedlist>
65 <listitem><para>Activation of uninitialized objects</para></listitem>
66 <listitem><para>Initialization of active objects</para></listitem>
67 <listitem><para>Usage of freed/destroyed objects</para></listitem>
68 </itemizedlist>
69 </para>
70 <para>
71 debugobjects is not changing the data structure of the real
72 object so it can be compiled in with a minimal runtime impact
73 and enabled on demand with a kernel command line option.
74 </para>
75 </chapter>
76
77 <chapter id="howto">
78 <title>Howto use debugobjects</title>
79 <para>
80 A kernel subsystem needs to provide a data structure which
81 describes the object type and add calls into the debug code at
82 appropriate places. The data structure to describe the object
83 type needs at minimum the name of the object type. Optional
84 functions can and should be provided to fixup detected problems
85 so the kernel can continue to work and the debug information can
86 be retrieved from a live system instead of hard core debugging
87 with serial consoles and stack trace transcripts from the
88 monitor.
89 </para>
90 <para>
91 The debug calls provided by debugobjects are:
92 <itemizedlist>
93 <listitem><para>debug_object_init</para></listitem>
94 <listitem><para>debug_object_init_on_stack</para></listitem>
95 <listitem><para>debug_object_activate</para></listitem>
96 <listitem><para>debug_object_deactivate</para></listitem>
97 <listitem><para>debug_object_destroy</para></listitem>
98 <listitem><para>debug_object_free</para></listitem>
99 </itemizedlist>
100 Each of these functions takes the address of the real object and
101 a pointer to the object type specific debug description
102 structure.
103 </para>
104 <para>
105 Each detected error is reported in the statistics and a limited
106 number of errors are printk'ed including a full stack trace.
107 </para>
108 <para>
109 The statistics are available via debugfs/debug_objects/stats.
110 They provide information about the number of warnings and the
111 number of successful fixups along with information about the
112 usage of the internal tracking objects and the state of the
113 internal tracking objects pool.
114 </para>
115 </chapter>
116 <chapter id="debugfunctions">
117 <title>Debug functions</title>
118 <sect1 id="prototypes">
119 <title>Debug object function reference</title>
120!Elib/debugobjects.c
121 </sect1>
122 <sect1 id="debug_object_init">
123 <title>debug_object_init</title>
124 <para>
125 This function is called whenever the initialization function
126 of a real object is called.
127 </para>
128 <para>
129 When the real object is already tracked by debugobjects it is
130 checked, whether the object can be initialized. Initializing
131 is not allowed for active and destroyed objects. When
132 debugobjects detects an error, then it calls the fixup_init
133 function of the object type description structure if provided
134 by the caller. The fixup function can correct the problem
135 before the real initialization of the object happens. E.g. it
136 can deactivate an active object in order to prevent damage to
137 the subsystem.
138 </para>
139 <para>
140 When the real object is not yet tracked by debugobjects,
141 debugobjects allocates a tracker object for the real object
142 and sets the tracker object state to ODEBUG_STATE_INIT. It
143 verifies that the object is not on the callers stack. If it is
144 on the callers stack then a limited number of warnings
145 including a full stack trace is printk'ed. The calling code
146 must use debug_object_init_on_stack() and remove the object
147 before leaving the function which allocated it. See next
148 section.
149 </para>
150 </sect1>
151
152 <sect1 id="debug_object_init_on_stack">
153 <title>debug_object_init_on_stack</title>
154 <para>
155 This function is called whenever the initialization function
156 of a real object which resides on the stack is called.
157 </para>
158 <para>
159 When the real object is already tracked by debugobjects it is
160 checked, whether the object can be initialized. Initializing
161 is not allowed for active and destroyed objects. When
162 debugobjects detects an error, then it calls the fixup_init
163 function of the object type description structure if provided
164 by the caller. The fixup function can correct the problem
165 before the real initialization of the object happens. E.g. it
166 can deactivate an active object in order to prevent damage to
167 the subsystem.
168 </para>
169 <para>
170 When the real object is not yet tracked by debugobjects
171 debugobjects allocates a tracker object for the real object
172 and sets the tracker object state to ODEBUG_STATE_INIT. It
173 verifies that the object is on the callers stack.
174 </para>
175 <para>
176 An object which is on the stack must be removed from the
177 tracker by calling debug_object_free() before the function
178 which allocates the object returns. Otherwise we keep track of
179 stale objects.
180 </para>
181 </sect1>
182
183 <sect1 id="debug_object_activate">
184 <title>debug_object_activate</title>
185 <para>
186 This function is called whenever the activation function of a
187 real object is called.
188 </para>
189 <para>
190 When the real object is already tracked by debugobjects it is
191 checked, whether the object can be activated. Activating is
192 not allowed for active and destroyed objects. When
193 debugobjects detects an error, then it calls the
194 fixup_activate function of the object type description
195 structure if provided by the caller. The fixup function can
196 correct the problem before the real activation of the object
197 happens. E.g. it can deactivate an active object in order to
198 prevent damage to the subsystem.
199 </para>
200 <para>
201 When the real object is not yet tracked by debugobjects then
202 the fixup_activate function is called if available. This is
203 necessary to allow the legitimate activation of statically
204 allocated and initialized objects. The fixup function checks
205 whether the object is valid and calls the debug_objects_init()
206 function to initialize the tracking of this object.
207 </para>
208 <para>
209 When the activation is legitimate, then the state of the
210 associated tracker object is set to ODEBUG_STATE_ACTIVE.
211 </para>
212 </sect1>
213
214 <sect1 id="debug_object_deactivate">
215 <title>debug_object_deactivate</title>
216 <para>
217 This function is called whenever the deactivation function of
218 a real object is called.
219 </para>
220 <para>
221 When the real object is tracked by debugobjects it is checked,
222 whether the object can be deactivated. Deactivating is not
223 allowed for untracked or destroyed objects.
224 </para>
225 <para>
226 When the deactivation is legitimate, then the state of the
227 associated tracker object is set to ODEBUG_STATE_INACTIVE.
228 </para>
229 </sect1>
230
231 <sect1 id="debug_object_destroy">
232 <title>debug_object_destroy</title>
233 <para>
234 This function is called to mark an object destroyed. This is
235 useful to prevent the usage of invalid objects, which are
236 still available in memory: either statically allocated objects
237 or objects which are freed later.
238 </para>
239 <para>
240 When the real object is tracked by debugobjects it is checked,
241 whether the object can be destroyed. Destruction is not
242 allowed for active and destroyed objects. When debugobjects
243 detects an error, then it calls the fixup_destroy function of
244 the object type description structure if provided by the
245 caller. The fixup function can correct the problem before the
246 real destruction of the object happens. E.g. it can deactivate
247 an active object in order to prevent damage to the subsystem.
248 </para>
249 <para>
250 When the destruction is legitimate, then the state of the
251 associated tracker object is set to ODEBUG_STATE_DESTROYED.
252 </para>
253 </sect1>
254
255 <sect1 id="debug_object_free">
256 <title>debug_object_free</title>
257 <para>
258 This function is called before an object is freed.
259 </para>
260 <para>
261 When the real object is tracked by debugobjects it is checked,
262 whether the object can be freed. Free is not allowed for
263 active objects. When debugobjects detects an error, then it
264 calls the fixup_free function of the object type description
265 structure if provided by the caller. The fixup function can
266 correct the problem before the real free of the object
267 happens. E.g. it can deactivate an active object in order to
268 prevent damage to the subsystem.
269 </para>
270 <para>
271 Note that debug_object_free removes the object from the
272 tracker. Later usage of the object is detected by the other
273 debug checks.
274 </para>
275 </sect1>
276 </chapter>
277 <chapter id="fixupfunctions">
278 <title>Fixup functions</title>
279 <sect1 id="debug_obj_descr">
280 <title>Debug object type description structure</title>
281!Iinclude/linux/debugobjects.h
282 </sect1>
283 <sect1 id="fixup_init">
284 <title>fixup_init</title>
285 <para>
286 This function is called from the debug code whenever a problem
287 in debug_object_init is detected. The function takes the
288 address of the object and the state which is currently
289 recorded in the tracker.
290 </para>
291 <para>
292 Called from debug_object_init when the object state is:
293 <itemizedlist>
294 <listitem><para>ODEBUG_STATE_ACTIVE</para></listitem>
295 </itemizedlist>
296 </para>
297 <para>
298 The function returns 1 when the fixup was successful,
299 otherwise 0. The return value is used to update the
300 statistics.
301 </para>
302 <para>
303 Note, that the function needs to call the debug_object_init()
304 function again, after the damage has been repaired in order to
305 keep the state consistent.
306 </para>
307 </sect1>
308
309 <sect1 id="fixup_activate">
310 <title>fixup_activate</title>
311 <para>
312 This function is called from the debug code whenever a problem
313 in debug_object_activate is detected.
314 </para>
315 <para>
316 Called from debug_object_activate when the object state is:
317 <itemizedlist>
318 <listitem><para>ODEBUG_STATE_NOTAVAILABLE</para></listitem>
319 <listitem><para>ODEBUG_STATE_ACTIVE</para></listitem>
320 </itemizedlist>
321 </para>
322 <para>
323 The function returns 1 when the fixup was successful,
324 otherwise 0. The return value is used to update the
325 statistics.
326 </para>
327 <para>
328 Note that the function needs to call the debug_object_activate()
329 function again after the damage has been repaired in order to
330 keep the state consistent.
331 </para>
332 <para>
333 The activation of statically initialized objects is a special
334 case. When debug_object_activate() has no tracked object for
335 this object address then fixup_activate() is called with
336 object state ODEBUG_STATE_NOTAVAILABLE. The fixup function
337 needs to check whether this is a legitimate case of a
338 statically initialized object or not. In case it is it calls
339 debug_object_init() and debug_object_activate() to make the
340 object known to the tracker and marked active. In this case
341 the function should return 0 because this is not a real fixup.
342 </para>
343 </sect1>
344
345 <sect1 id="fixup_destroy">
346 <title>fixup_destroy</title>
347 <para>
348 This function is called from the debug code whenever a problem
349 in debug_object_destroy is detected.
350 </para>
351 <para>
352 Called from debug_object_destroy when the object state is:
353 <itemizedlist>
354 <listitem><para>ODEBUG_STATE_ACTIVE</para></listitem>
355 </itemizedlist>
356 </para>
357 <para>
358 The function returns 1 when the fixup was successful,
359 otherwise 0. The return value is used to update the
360 statistics.
361 </para>
362 </sect1>
363 <sect1 id="fixup_free">
364 <title>fixup_free</title>
365 <para>
366 This function is called from the debug code whenever a problem
367 in debug_object_free is detected. Further it can be called
368 from the debug checks in kfree/vfree, when an active object is
369 detected from the debug_check_no_obj_freed() sanity checks.
370 </para>
371 <para>
372 Called from debug_object_free() or debug_check_no_obj_freed()
373 when the object state is:
374 <itemizedlist>
375 <listitem><para>ODEBUG_STATE_ACTIVE</para></listitem>
376 </itemizedlist>
377 </para>
378 <para>
379 The function returns 1 when the fixup was successful,
380 otherwise 0. The return value is used to update the
381 statistics.
382 </para>
383 </sect1>
384 </chapter>
385 <chapter id="bugs">
386 <title>Known Bugs And Assumptions</title>
387 <para>
388 None (knock on wood).
389 </para>
390 </chapter>
391</book>
diff --git a/Documentation/DocBook/kgdb.tmpl b/Documentation/DocBook/kgdb.tmpl
index 97618bed4d65..028a8444d95e 100644
--- a/Documentation/DocBook/kgdb.tmpl
+++ b/Documentation/DocBook/kgdb.tmpl
@@ -72,7 +72,7 @@
72 kgdb is a source level debugger for linux kernel. It is used along 72 kgdb is a source level debugger for linux kernel. It is used along
73 with gdb to debug a linux kernel. The expectation is that gdb can 73 with gdb to debug a linux kernel. The expectation is that gdb can
74 be used to "break in" to the kernel to inspect memory, variables 74 be used to "break in" to the kernel to inspect memory, variables
75 and look through a cal stack information similar to what an 75 and look through call stack information similar to what an
76 application developer would use gdb for. It is possible to place 76 application developer would use gdb for. It is possible to place
77 breakpoints in kernel code and perform some limited execution 77 breakpoints in kernel code and perform some limited execution
78 stepping. 78 stepping.
@@ -93,8 +93,10 @@
93 <chapter id="CompilingAKernel"> 93 <chapter id="CompilingAKernel">
94 <title>Compiling a kernel</title> 94 <title>Compiling a kernel</title>
95 <para> 95 <para>
96 To enable <symbol>CONFIG_KGDB</symbol>, look under the "Kernel debugging" 96 To enable <symbol>CONFIG_KGDB</symbol> you should first turn on
97 and then select "KGDB: kernel debugging with remote gdb". 97 "Prompt for development and/or incomplete code/drivers"
98 (CONFIG_EXPERIMENTAL) in "General setup", then under the
99 "Kernel debugging" select "KGDB: kernel debugging with remote gdb".
98 </para> 100 </para>
99 <para> 101 <para>
100 Next you should choose one of more I/O drivers to interconnect debugging 102 Next you should choose one of more I/O drivers to interconnect debugging
diff --git a/Documentation/DocBook/rapidio.tmpl b/Documentation/DocBook/rapidio.tmpl
index b9e143e28c64..54eb26b57372 100644
--- a/Documentation/DocBook/rapidio.tmpl
+++ b/Documentation/DocBook/rapidio.tmpl
@@ -133,7 +133,6 @@
133!Idrivers/rapidio/rio-sysfs.c 133!Idrivers/rapidio/rio-sysfs.c
134 </sect1> 134 </sect1>
135 <sect1 id="PPC32_support"><title>PPC32 support</title> 135 <sect1 id="PPC32_support"><title>PPC32 support</title>
136!Iarch/powerpc/kernel/rio.c
137!Earch/powerpc/sysdev/fsl_rio.c 136!Earch/powerpc/sysdev/fsl_rio.c
138!Iarch/powerpc/sysdev/fsl_rio.c 137!Iarch/powerpc/sysdev/fsl_rio.c
139 </sect1> 138 </sect1>
diff --git a/Documentation/braille-console.txt b/Documentation/braille-console.txt
new file mode 100644
index 000000000000..000b0fbdc105
--- /dev/null
+++ b/Documentation/braille-console.txt
@@ -0,0 +1,34 @@
1 Linux Braille Console
2
3To get early boot messages on a braille device (before userspace screen
4readers can start), you first need to compile the support for the usual serial
5console (see serial-console.txt), and for braille device (in Device Drivers -
6Accessibility).
7
8Then you need to specify a console=brl, option on the kernel command line, the
9format is:
10
11 console=brl,serial_options...
12
13where serial_options... are the same as described in serial-console.txt
14
15So for instance you can use console=brl,ttyS0 if the braille device is connected
16to the first serial port, and console=brl,ttyS0,115200 to override the baud rate
17to 115200, etc.
18
19By default, the braille device will just show the last kernel message (console
20mode). To review previous messages, press the Insert key to switch to the VT
21review mode. In review mode, the arrow keys permit to browse in the VT content,
22page up/down keys go at the top/bottom of the screen, and the home key goes back
23to the cursor, hence providing very basic screen reviewing facility.
24
25Sound feedback can be obtained by adding the braille_console.sound=1 kernel
26parameter.
27
28For simplicity, only one braille console can be enabled, other uses of
29console=brl,... will be discarded. Also note that it does not interfere with
30the console selection mecanism described in serial-console.txt
31
32For now, only the VisioBraille device is supported.
33
34Samuel Thibault <samuel.thibault@ens-lyon.org>
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index 599fe55bf297..3c35d452b1a9 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -138,6 +138,24 @@ Who: Kay Sievers <kay.sievers@suse.de>
138 138
139--------------------------- 139---------------------------
140 140
141What: find_task_by_pid
142When: 2.6.26
143Why: With pid namespaces, calling this funciton will return the
144 wrong task when called from inside a namespace.
145
146 The best way to save a task pid and find a task by this
147 pid later, is to find this task's struct pid pointer (or get
148 it directly from the task) and call pid_task() later.
149
150 If someone really needs to get a task by its pid_t, then
151 he most likely needs the find_task_by_vpid() to get the
152 task from the same namespace as the current task is in, but
153 this may be not so in general.
154
155Who: Pavel Emelyanov <xemul@openvz.org>
156
157---------------------------
158
141What: ACPI procfs interface 159What: ACPI procfs interface
142When: July 2008 160When: July 2008
143Why: ACPI sysfs conversion should be finished by January 2008. 161Why: ACPI sysfs conversion should be finished by January 2008.
diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesystems/proc.txt
index 2a99116edc47..dbc3c6a3650f 100644
--- a/Documentation/filesystems/proc.txt
+++ b/Documentation/filesystems/proc.txt
@@ -463,11 +463,17 @@ SwapTotal: 0 kB
463SwapFree: 0 kB 463SwapFree: 0 kB
464Dirty: 968 kB 464Dirty: 968 kB
465Writeback: 0 kB 465Writeback: 0 kB
466AnonPages: 861800 kB
466Mapped: 280372 kB 467Mapped: 280372 kB
467Slab: 684068 kB 468Slab: 284364 kB
469SReclaimable: 159856 kB
470SUnreclaim: 124508 kB
471PageTables: 24448 kB
472NFS_Unstable: 0 kB
473Bounce: 0 kB
474WritebackTmp: 0 kB
468CommitLimit: 7669796 kB 475CommitLimit: 7669796 kB
469Committed_AS: 100056 kB 476Committed_AS: 100056 kB
470PageTables: 24448 kB
471VmallocTotal: 112216 kB 477VmallocTotal: 112216 kB
472VmallocUsed: 428 kB 478VmallocUsed: 428 kB
473VmallocChunk: 111088 kB 479VmallocChunk: 111088 kB
@@ -503,8 +509,17 @@ VmallocChunk: 111088 kB
503 on the disk 509 on the disk
504 Dirty: Memory which is waiting to get written back to the disk 510 Dirty: Memory which is waiting to get written back to the disk
505 Writeback: Memory which is actively being written back to the disk 511 Writeback: Memory which is actively being written back to the disk
512 AnonPages: Non-file backed pages mapped into userspace page tables
506 Mapped: files which have been mmaped, such as libraries 513 Mapped: files which have been mmaped, such as libraries
507 Slab: in-kernel data structures cache 514 Slab: in-kernel data structures cache
515SReclaimable: Part of Slab, that might be reclaimed, such as caches
516 SUnreclaim: Part of Slab, that cannot be reclaimed on memory pressure
517 PageTables: amount of memory dedicated to the lowest level of page
518 tables.
519NFS_Unstable: NFS pages sent to the server, but not yet committed to stable
520 storage
521 Bounce: Memory used for block device "bounce buffers"
522WritebackTmp: Memory used by FUSE for temporary writeback buffers
508 CommitLimit: Based on the overcommit ratio ('vm.overcommit_ratio'), 523 CommitLimit: Based on the overcommit ratio ('vm.overcommit_ratio'),
509 this is the total amount of memory currently available to 524 this is the total amount of memory currently available to
510 be allocated on the system. This limit is only adhered to 525 be allocated on the system. This limit is only adhered to
@@ -531,8 +546,6 @@ Committed_AS: The amount of memory presently allocated on the system.
531 above) will not be permitted. This is useful if one needs 546 above) will not be permitted. This is useful if one needs
532 to guarantee that processes will not fail due to lack of 547 to guarantee that processes will not fail due to lack of
533 memory once that memory has been successfully allocated. 548 memory once that memory has been successfully allocated.
534 PageTables: amount of memory dedicated to the lowest level of page
535 tables.
536VmallocTotal: total size of vmalloc memory area 549VmallocTotal: total size of vmalloc memory area
537 VmallocUsed: amount of vmalloc area which is used 550 VmallocUsed: amount of vmalloc area which is used
538VmallocChunk: largest contigious block of vmalloc area which is free 551VmallocChunk: largest contigious block of vmalloc area which is free
diff --git a/Documentation/hwmon/w83l785ts b/Documentation/hwmon/w83l785ts
index 1841cedc25b2..bd1fa9d4468d 100644
--- a/Documentation/hwmon/w83l785ts
+++ b/Documentation/hwmon/w83l785ts
@@ -33,7 +33,8 @@ Known Issues
33------------ 33------------
34 34
35On some systems (Asus), the BIOS is known to interfere with the driver 35On some systems (Asus), the BIOS is known to interfere with the driver
36and cause read errors. The driver will retry a given number of times 36and cause read errors. Or maybe the W83L785TS-S chip is simply unreliable,
37we don't really know. The driver will retry a given number of times
37(5 by default) and then give up, returning the old value (or 0 if 38(5 by default) and then give up, returning the old value (or 0 if
38there is no old value). It seems to work well enough so that you should 39there is no old value). It seems to work well enough so that you should
39not notice anything. Thanks to James Bolt for helping test this feature. 40not notice anything. Thanks to James Bolt for helping test this feature.
diff --git a/Documentation/kbuild/kconfig-language.txt b/Documentation/kbuild/kconfig-language.txt
index 00b950d1c193..c412c245848f 100644
--- a/Documentation/kbuild/kconfig-language.txt
+++ b/Documentation/kbuild/kconfig-language.txt
@@ -377,27 +377,3 @@ config FOO
377 377
378limits FOO to module (=m) or disabled (=n). 378limits FOO to module (=m) or disabled (=n).
379 379
380
381Build limited by a third config symbol which may be =y or =m
382~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
383A common idiom that we see (and sometimes have problems with) is this:
384
385When option C in B (module or subsystem) uses interfaces from A (module
386or subsystem), and both A and B are tristate (could be =y or =m if they
387were independent of each other, but they aren't), then we need to limit
388C such that it cannot be built statically if A is built as a loadable
389module. (C already depends on B, so there is no dependency issue to
390take care of here.)
391
392If A is linked statically into the kernel image, C can be built
393statically or as loadable module(s). However, if A is built as loadable
394module(s), then C must be restricted to loadable module(s) also. This
395can be expressed in kconfig language as:
396
397config C
398 depends on A = y || A = B
399
400or for real examples, use this command in a kernel tree:
401
402$ find . -name Kconfig\* | xargs grep -ns "depends on.*=.*||.*=" | grep -v orig
403
diff --git a/Documentation/kdump/kdump.txt b/Documentation/kdump/kdump.txt
index d0ac72cc19ff..b8e52c0355d3 100644
--- a/Documentation/kdump/kdump.txt
+++ b/Documentation/kdump/kdump.txt
@@ -245,6 +245,8 @@ The syntax is:
245 crashkernel=<range1>:<size1>[,<range2>:<size2>,...][@offset] 245 crashkernel=<range1>:<size1>[,<range2>:<size2>,...][@offset]
246 range=start-[end] 246 range=start-[end]
247 247
248 'start' is inclusive and 'end' is exclusive.
249
248For example: 250For example:
249 251
250 crashkernel=512M-2G:64M,2G-:128M 252 crashkernel=512M-2G:64M,2G-:128M
@@ -253,10 +255,11 @@ This would mean:
253 255
254 1) if the RAM is smaller than 512M, then don't reserve anything 256 1) if the RAM is smaller than 512M, then don't reserve anything
255 (this is the "rescue" case) 257 (this is the "rescue" case)
256 2) if the RAM size is between 512M and 2G, then reserve 64M 258 2) if the RAM size is between 512M and 2G (exclusive), then reserve 64M
257 3) if the RAM size is larger than 2G, then reserve 128M 259 3) if the RAM size is larger than 2G, then reserve 128M
258 260
259 261
262
260Boot into System Kernel 263Boot into System Kernel
261======================= 264=======================
262 265
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 3ce193f86565..cdd5b934f43e 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -496,6 +496,11 @@ and is between 256 and 4096 characters. It is defined in the file
496 switching to the matching ttyS device later. The 496 switching to the matching ttyS device later. The
497 options are the same as for ttyS, above. 497 options are the same as for ttyS, above.
498 498
499 If the device connected to the port is not a TTY but a braille
500 device, prepend "brl," before the device type, for instance
501 console=brl,ttyS0
502 For now, only VisioBraille is supported.
503
499 earlycon= [KNL] Output early console device and options. 504 earlycon= [KNL] Output early console device and options.
500 uart[8250],io,<addr>[,options] 505 uart[8250],io,<addr>[,options]
501 uart[8250],mmio,<addr>[,options] 506 uart[8250],mmio,<addr>[,options]
@@ -556,6 +561,8 @@ and is between 256 and 4096 characters. It is defined in the file
556 1 will print _a lot_ more information - normally 561 1 will print _a lot_ more information - normally
557 only useful to kernel developers. 562 only useful to kernel developers.
558 563
564 debug_objects [KNL] Enable object debugging
565
559 decnet.addr= [HW,NET] 566 decnet.addr= [HW,NET]
560 Format: <area>[,<node>] 567 Format: <area>[,<node>]
561 See also Documentation/networking/decnet.txt. 568 See also Documentation/networking/decnet.txt.
@@ -1087,9 +1094,6 @@ and is between 256 and 4096 characters. It is defined in the file
1087 mac5380= [HW,SCSI] Format: 1094 mac5380= [HW,SCSI] Format:
1088 <can_queue>,<cmd_per_lun>,<sg_tablesize>,<hostid>,<use_tags> 1095 <can_queue>,<cmd_per_lun>,<sg_tablesize>,<hostid>,<use_tags>
1089 1096
1090 mac53c9x= [HW,SCSI] Format:
1091 <num_esps>,<disconnect>,<nosync>,<can_queue>,<cmd_per_lun>,<sg_tablesize>,<hostid>,<use_tags>
1092
1093 machvec= [IA64] Force the use of a particular machine-vector 1097 machvec= [IA64] Force the use of a particular machine-vector
1094 (machvec) in a generic kernel. 1098 (machvec) in a generic kernel.
1095 Example: machvec=hpzx1_swiotlb 1099 Example: machvec=hpzx1_swiotlb
@@ -1518,6 +1522,8 @@ and is between 256 and 4096 characters. It is defined in the file
1518 This is normally done in pci_enable_device(), 1522 This is normally done in pci_enable_device(),
1519 so this option is a temporary workaround 1523 so this option is a temporary workaround
1520 for broken drivers that don't call it. 1524 for broken drivers that don't call it.
1525 skip_isa_align [X86] do not align io start addr, so can
1526 handle more pci cards
1521 firmware [ARM] Do not re-enumerate the bus but instead 1527 firmware [ARM] Do not re-enumerate the bus but instead
1522 just use the configuration from the 1528 just use the configuration from the
1523 bootloader. This is currently used on 1529 bootloader. This is currently used on
diff --git a/Documentation/laptops/thinkpad-acpi.txt b/Documentation/laptops/thinkpad-acpi.txt
index 76cb428435da..01c6c3d8a7e3 100644
--- a/Documentation/laptops/thinkpad-acpi.txt
+++ b/Documentation/laptops/thinkpad-acpi.txt
@@ -1,7 +1,7 @@
1 ThinkPad ACPI Extras Driver 1 ThinkPad ACPI Extras Driver
2 2
3 Version 0.19 3 Version 0.20
4 January 06th, 2008 4 April 09th, 2008
5 5
6 Borislav Deianov <borislav@users.sf.net> 6 Borislav Deianov <borislav@users.sf.net>
7 Henrique de Moraes Holschuh <hmh@hmh.eng.br> 7 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
@@ -18,6 +18,11 @@ This driver used to be named ibm-acpi until kernel 2.6.21 and release
18moved to the drivers/misc tree and renamed to thinkpad-acpi for kernel 18moved to the drivers/misc tree and renamed to thinkpad-acpi for kernel
192.6.22, and release 0.14. 192.6.22, and release 0.14.
20 20
21The driver is named "thinkpad-acpi". In some places, like module
22names, "thinkpad_acpi" is used because of userspace issues.
23
24"tpacpi" is used as a shorthand where "thinkpad-acpi" would be too
25long due to length limitations on some Linux kernel versions.
21 26
22Status 27Status
23------ 28------
@@ -571,6 +576,47 @@ netlink interface and the input layer interface, and don't bother at all
571with hotkey_report_mode. 576with hotkey_report_mode.
572 577
573 578
579Brightness hotkey notes:
580
581These are the current sane choices for brightness key mapping in
582thinkpad-acpi:
583
584For IBM and Lenovo models *without* ACPI backlight control (the ones on
585which thinkpad-acpi will autoload its backlight interface by default,
586and on which ACPI video does not export a backlight interface):
587
5881. Don't enable or map the brightness hotkeys in thinkpad-acpi, as
589 these older firmware versions unfortunately won't respect the hotkey
590 mask for brightness keys anyway, and always reacts to them. This
591 usually work fine, unless X.org drivers are doing something to block
592 the BIOS. In that case, use (3) below. This is the default mode of
593 operation.
594
5952. Enable the hotkeys, but map them to something else that is NOT
596 KEY_BRIGHTNESS_UP/DOWN or any other keycode that would cause
597 userspace to try to change the backlight level, and use that as an
598 on-screen-display hint.
599
6003. IF AND ONLY IF X.org drivers find a way to block the firmware from
601 automatically changing the brightness, enable the hotkeys and map
602 them to KEY_BRIGHTNESS_UP and KEY_BRIGHTNESS_DOWN, and feed that to
603 something that calls xbacklight. thinkpad-acpi will not be able to
604 change brightness in that case either, so you should disable its
605 backlight interface.
606
607For Lenovo models *with* ACPI backlight control:
608
6091. Load up ACPI video and use that. ACPI video will report ACPI
610 events for brightness change keys. Do not mess with thinkpad-acpi
611 defaults in this case. thinkpad-acpi should not have anything to do
612 with backlight events in a scenario where ACPI video is loaded:
613 brightness hotkeys must be disabled, and the backlight interface is
614 to be kept disabled as well. This is the default mode of operation.
615
6162. Do *NOT* load up ACPI video, enable the hotkeys in thinkpad-acpi,
617 and map them to KEY_BRIGHTNESS_UP and KEY_BRIGHTNESS_DOWN. Process
618 these keys on userspace somehow (e.g. by calling xbacklight).
619
574Bluetooth 620Bluetooth
575--------- 621---------
576 622
@@ -647,16 +693,31 @@ while others are still having problems. For more information:
647 693
648https://bugs.freedesktop.org/show_bug.cgi?id=2000 694https://bugs.freedesktop.org/show_bug.cgi?id=2000
649 695
650ThinkLight control -- /proc/acpi/ibm/light 696ThinkLight control
651------------------------------------------ 697------------------
698
699procfs: /proc/acpi/ibm/light
700sysfs attributes: as per LED class, for the "tpacpi::thinklight" LED
652 701
653The current status of the ThinkLight can be found in this file. A few 702procfs notes:
654models which do not make the status available will show it as 703
655"unknown". The available commands are: 704The ThinkLight status can be read and set through the procfs interface. A
705few models which do not make the status available will show the ThinkLight
706status as "unknown". The available commands are:
656 707
657 echo on > /proc/acpi/ibm/light 708 echo on > /proc/acpi/ibm/light
658 echo off > /proc/acpi/ibm/light 709 echo off > /proc/acpi/ibm/light
659 710
711sysfs notes:
712
713The ThinkLight sysfs interface is documented by the LED class
714documentation, in Documentation/leds-class.txt. The ThinkLight LED name
715is "tpacpi::thinklight".
716
717Due to limitations in the sysfs LED class, if the status of the thinklight
718cannot be read or if it is unknown, thinkpad-acpi will report it as "off".
719It is impossible to know if the status returned through sysfs is valid.
720
660Docking / undocking -- /proc/acpi/ibm/dock 721Docking / undocking -- /proc/acpi/ibm/dock
661------------------------------------------ 722------------------------------------------
662 723
@@ -815,28 +876,63 @@ The cmos command interface is prone to firmware split-brain problems, as
815in newer ThinkPads it is just a compatibility layer. Do not use it, it is 876in newer ThinkPads it is just a compatibility layer. Do not use it, it is
816exported just as a debug tool. 877exported just as a debug tool.
817 878
818LED control -- /proc/acpi/ibm/led 879LED control
819--------------------------------- 880-----------
881
882procfs: /proc/acpi/ibm/led
883sysfs attributes: as per LED class, see below for names
884
885Some of the LED indicators can be controlled through this feature. On
886some older ThinkPad models, it is possible to query the status of the
887LED indicators as well. Newer ThinkPads cannot query the real status
888of the LED indicators.
820 889
821Some of the LED indicators can be controlled through this feature. The 890procfs notes:
822available commands are: 891
892The available commands are:
823 893
824 echo '<led number> on' >/proc/acpi/ibm/led 894 echo '<LED number> on' >/proc/acpi/ibm/led
825 echo '<led number> off' >/proc/acpi/ibm/led 895 echo '<LED number> off' >/proc/acpi/ibm/led
826 echo '<led number> blink' >/proc/acpi/ibm/led 896 echo '<LED number> blink' >/proc/acpi/ibm/led
827 897
828The <led number> range is 0 to 7. The set of LEDs that can be 898The <LED number> range is 0 to 7. The set of LEDs that can be
829controlled varies from model to model. Here is the mapping on the X40: 899controlled varies from model to model. Here is the common ThinkPad
900mapping:
830 901
831 0 - power 902 0 - power
832 1 - battery (orange) 903 1 - battery (orange)
833 2 - battery (green) 904 2 - battery (green)
834 3 - UltraBase 905 3 - UltraBase/dock
835 4 - UltraBay 906 4 - UltraBay
907 5 - UltraBase battery slot
908 6 - (unknown)
836 7 - standby 909 7 - standby
837 910
838All of the above can be turned on and off and can be made to blink. 911All of the above can be turned on and off and can be made to blink.
839 912
913sysfs notes:
914
915The ThinkPad LED sysfs interface is described in detail by the LED class
916documentation, in Documentation/leds-class.txt.
917
918The leds are named (in LED ID order, from 0 to 7):
919"tpacpi::power", "tpacpi:orange:batt", "tpacpi:green:batt",
920"tpacpi::dock_active", "tpacpi::bay_active", "tpacpi::dock_batt",
921"tpacpi::unknown_led", "tpacpi::standby".
922
923Due to limitations in the sysfs LED class, if the status of the LED
924indicators cannot be read due to an error, thinkpad-acpi will report it as
925a brightness of zero (same as LED off).
926
927If the thinkpad firmware doesn't support reading the current status,
928trying to read the current LED brightness will just return whatever
929brightness was last written to that attribute.
930
931These LEDs can blink using hardware acceleration. To request that a
932ThinkPad indicator LED should blink in hardware accelerated mode, use the
933"timer" trigger, and leave the delay_on and delay_off parameters set to
934zero (to request hardware acceleration autodetection).
935
840ACPI sounds -- /proc/acpi/ibm/beep 936ACPI sounds -- /proc/acpi/ibm/beep
841---------------------------------- 937----------------------------------
842 938
@@ -1090,6 +1186,15 @@ it there will be the following attributes:
1090 dim the display. 1186 dim the display.
1091 1187
1092 1188
1189WARNING:
1190
1191 Whatever you do, do NOT ever call thinkpad-acpi backlight-level change
1192 interface and the ACPI-based backlight level change interface
1193 (available on newer BIOSes, and driven by the Linux ACPI video driver)
1194 at the same time. The two will interact in bad ways, do funny things,
1195 and maybe reduce the life of the backlight lamps by needlessly kicking
1196 its level up and down at every change.
1197
1093Volume control -- /proc/acpi/ibm/volume 1198Volume control -- /proc/acpi/ibm/volume
1094--------------------------------------- 1199---------------------------------------
1095 1200
diff --git a/Documentation/lguest/lguest.c b/Documentation/lguest/lguest.c
index 4c1fc65a8b3d..3be8ab2a886a 100644
--- a/Documentation/lguest/lguest.c
+++ b/Documentation/lguest/lguest.c
@@ -131,6 +131,9 @@ struct device
131 /* Any queues attached to this device */ 131 /* Any queues attached to this device */
132 struct virtqueue *vq; 132 struct virtqueue *vq;
133 133
134 /* Handle status being finalized (ie. feature bits stable). */
135 void (*ready)(struct device *me);
136
134 /* Device-specific data. */ 137 /* Device-specific data. */
135 void *priv; 138 void *priv;
136}; 139};
@@ -925,24 +928,40 @@ static void enable_fd(int fd, struct virtqueue *vq)
925 write(waker_fd, &vq->dev->fd, sizeof(vq->dev->fd)); 928 write(waker_fd, &vq->dev->fd, sizeof(vq->dev->fd));
926} 929}
927 930
928/* When the Guest asks us to reset a device, it's is fairly easy. */ 931/* When the Guest tells us they updated the status field, we handle it. */
929static void reset_device(struct device *dev) 932static void update_device_status(struct device *dev)
930{ 933{
931 struct virtqueue *vq; 934 struct virtqueue *vq;
932 935
933 verbose("Resetting device %s\n", dev->name); 936 /* This is a reset. */
934 /* Clear the status. */ 937 if (dev->desc->status == 0) {
935 dev->desc->status = 0; 938 verbose("Resetting device %s\n", dev->name);
936 939
937 /* Clear any features they've acked. */ 940 /* Clear any features they've acked. */
938 memset(get_feature_bits(dev) + dev->desc->feature_len, 0, 941 memset(get_feature_bits(dev) + dev->desc->feature_len, 0,
939 dev->desc->feature_len); 942 dev->desc->feature_len);
940 943
941 /* Zero out the virtqueues. */ 944 /* Zero out the virtqueues. */
942 for (vq = dev->vq; vq; vq = vq->next) { 945 for (vq = dev->vq; vq; vq = vq->next) {
943 memset(vq->vring.desc, 0, 946 memset(vq->vring.desc, 0,
944 vring_size(vq->config.num, getpagesize())); 947 vring_size(vq->config.num, getpagesize()));
945 vq->last_avail_idx = 0; 948 vq->last_avail_idx = 0;
949 }
950 } else if (dev->desc->status & VIRTIO_CONFIG_S_FAILED) {
951 warnx("Device %s configuration FAILED", dev->name);
952 } else if (dev->desc->status & VIRTIO_CONFIG_S_DRIVER_OK) {
953 unsigned int i;
954
955 verbose("Device %s OK: offered", dev->name);
956 for (i = 0; i < dev->desc->feature_len; i++)
957 verbose(" %08x", get_feature_bits(dev)[i]);
958 verbose(", accepted");
959 for (i = 0; i < dev->desc->feature_len; i++)
960 verbose(" %08x", get_feature_bits(dev)
961 [dev->desc->feature_len+i]);
962
963 if (dev->ready)
964 dev->ready(dev);
946 } 965 }
947} 966}
948 967
@@ -954,9 +973,9 @@ static void handle_output(int fd, unsigned long addr)
954 973
955 /* Check each device and virtqueue. */ 974 /* Check each device and virtqueue. */
956 for (i = devices.dev; i; i = i->next) { 975 for (i = devices.dev; i; i = i->next) {
957 /* Notifications to device descriptors reset the device. */ 976 /* Notifications to device descriptors update device status. */
958 if (from_guest_phys(addr) == i->desc) { 977 if (from_guest_phys(addr) == i->desc) {
959 reset_device(i); 978 update_device_status(i);
960 return; 979 return;
961 } 980 }
962 981
@@ -1170,6 +1189,7 @@ static struct device *new_device(const char *name, u16 type, int fd,
1170 dev->handle_input = handle_input; 1189 dev->handle_input = handle_input;
1171 dev->name = name; 1190 dev->name = name;
1172 dev->vq = NULL; 1191 dev->vq = NULL;
1192 dev->ready = NULL;
1173 1193
1174 /* Append to device list. Prepending to a single-linked list is 1194 /* Append to device list. Prepending to a single-linked list is
1175 * easier, but the user expects the devices to be arranged on the bus 1195 * easier, but the user expects the devices to be arranged on the bus
@@ -1398,7 +1418,7 @@ static bool service_io(struct device *dev)
1398 struct vblk_info *vblk = dev->priv; 1418 struct vblk_info *vblk = dev->priv;
1399 unsigned int head, out_num, in_num, wlen; 1419 unsigned int head, out_num, in_num, wlen;
1400 int ret; 1420 int ret;
1401 struct virtio_blk_inhdr *in; 1421 u8 *in;
1402 struct virtio_blk_outhdr *out; 1422 struct virtio_blk_outhdr *out;
1403 struct iovec iov[dev->vq->vring.num]; 1423 struct iovec iov[dev->vq->vring.num];
1404 off64_t off; 1424 off64_t off;
@@ -1416,7 +1436,7 @@ static bool service_io(struct device *dev)
1416 head, out_num, in_num); 1436 head, out_num, in_num);
1417 1437
1418 out = convert(&iov[0], struct virtio_blk_outhdr); 1438 out = convert(&iov[0], struct virtio_blk_outhdr);
1419 in = convert(&iov[out_num+in_num-1], struct virtio_blk_inhdr); 1439 in = convert(&iov[out_num+in_num-1], u8);
1420 off = out->sector * 512; 1440 off = out->sector * 512;
1421 1441
1422 /* The block device implements "barriers", where the Guest indicates 1442 /* The block device implements "barriers", where the Guest indicates
@@ -1430,7 +1450,7 @@ static bool service_io(struct device *dev)
1430 * It'd be nice if we supported eject, for example, but we don't. */ 1450 * It'd be nice if we supported eject, for example, but we don't. */
1431 if (out->type & VIRTIO_BLK_T_SCSI_CMD) { 1451 if (out->type & VIRTIO_BLK_T_SCSI_CMD) {
1432 fprintf(stderr, "Scsi commands unsupported\n"); 1452 fprintf(stderr, "Scsi commands unsupported\n");
1433 in->status = VIRTIO_BLK_S_UNSUPP; 1453 *in = VIRTIO_BLK_S_UNSUPP;
1434 wlen = sizeof(*in); 1454 wlen = sizeof(*in);
1435 } else if (out->type & VIRTIO_BLK_T_OUT) { 1455 } else if (out->type & VIRTIO_BLK_T_OUT) {
1436 /* Write */ 1456 /* Write */
@@ -1453,7 +1473,7 @@ static bool service_io(struct device *dev)
1453 errx(1, "Write past end %llu+%u", off, ret); 1473 errx(1, "Write past end %llu+%u", off, ret);
1454 } 1474 }
1455 wlen = sizeof(*in); 1475 wlen = sizeof(*in);
1456 in->status = (ret >= 0 ? VIRTIO_BLK_S_OK : VIRTIO_BLK_S_IOERR); 1476 *in = (ret >= 0 ? VIRTIO_BLK_S_OK : VIRTIO_BLK_S_IOERR);
1457 } else { 1477 } else {
1458 /* Read */ 1478 /* Read */
1459 1479
@@ -1466,10 +1486,10 @@ static bool service_io(struct device *dev)
1466 verbose("READ from sector %llu: %i\n", out->sector, ret); 1486 verbose("READ from sector %llu: %i\n", out->sector, ret);
1467 if (ret >= 0) { 1487 if (ret >= 0) {
1468 wlen = sizeof(*in) + ret; 1488 wlen = sizeof(*in) + ret;
1469 in->status = VIRTIO_BLK_S_OK; 1489 *in = VIRTIO_BLK_S_OK;
1470 } else { 1490 } else {
1471 wlen = sizeof(*in); 1491 wlen = sizeof(*in);
1472 in->status = VIRTIO_BLK_S_IOERR; 1492 *in = VIRTIO_BLK_S_IOERR;
1473 } 1493 }
1474 } 1494 }
1475 1495
diff --git a/Documentation/powerpc/mpc52xx-device-tree-bindings.txt b/Documentation/powerpc/mpc52xx-device-tree-bindings.txt
index 5e03610e186f..6f12f1c79c0c 100644
--- a/Documentation/powerpc/mpc52xx-device-tree-bindings.txt
+++ b/Documentation/powerpc/mpc52xx-device-tree-bindings.txt
@@ -186,6 +186,12 @@ Recommended soc5200 child nodes; populate as needed for your board
186name device_type compatible Description 186name device_type compatible Description
187---- ----------- ---------- ----------- 187---- ----------- ---------- -----------
188gpt@<addr> gpt fsl,mpc5200-gpt General purpose timers 188gpt@<addr> gpt fsl,mpc5200-gpt General purpose timers
189gpt@<addr> gpt fsl,mpc5200-gpt-gpio General purpose
190 timers in GPIO mode
191gpio@<addr> fsl,mpc5200-gpio MPC5200 simple gpio
192 controller
193gpio@<addr> fsl,mpc5200-gpio-wkup MPC5200 wakeup gpio
194 controller
189rtc@<addr> rtc mpc5200-rtc Real time clock 195rtc@<addr> rtc mpc5200-rtc Real time clock
190mscan@<addr> mscan mpc5200-mscan CAN bus controller 196mscan@<addr> mscan mpc5200-mscan CAN bus controller
191pci@<addr> pci mpc5200-pci PCI bridge 197pci@<addr> pci mpc5200-pci PCI bridge
@@ -225,6 +231,23 @@ PSC in i2s mode: The mpc5200 and mpc5200b PSCs are not compatible when in
225i2s mode. An 'mpc5200b-psc-i2s' node cannot include 'mpc5200-psc-i2s' in the 231i2s mode. An 'mpc5200b-psc-i2s' node cannot include 'mpc5200-psc-i2s' in the
226compatible field. 232compatible field.
227 233
2347) GPIO controller nodes
235Each GPIO controller node should have the empty property gpio-controller and
236#gpio-cells set to 2. First cell is the GPIO number which is interpreted
237according to the bit numbers in the GPIO control registers. The second cell
238is for flags which is currently unsused.
239
2408) FEC nodes
241The FEC node can specify one of the following properties to configure
242the MII link:
243"fsl,7-wire-mode" - An empty property that specifies the link uses 7-wire
244 mode instead of MII
245"current-speed" - Specifies that the MII should be configured for a fixed
246 speed. This property should contain two cells. The
247 first cell specifies the speed in Mbps and the second
248 should be '0' for half duplex and '1' for full duplex
249"phy-handle" - Contains a phandle to an Ethernet PHY.
250
228IV - Extra Notes 251IV - Extra Notes
229================ 252================
230 253
diff --git a/Documentation/scheduler/sched-design.txt b/Documentation/scheduler/sched-design.txt
deleted file mode 100644
index 1605bf0cba8b..000000000000
--- a/Documentation/scheduler/sched-design.txt
+++ /dev/null
@@ -1,165 +0,0 @@
1 Goals, Design and Implementation of the
2 new ultra-scalable O(1) scheduler
3
4
5 This is an edited version of an email Ingo Molnar sent to
6 lkml on 4 Jan 2002. It describes the goals, design, and
7 implementation of Ingo's new ultra-scalable O(1) scheduler.
8 Last Updated: 18 April 2002.
9
10
11Goal
12====
13
14The main goal of the new scheduler is to keep all the good things we know
15and love about the current Linux scheduler:
16
17 - good interactive performance even during high load: if the user
18 types or clicks then the system must react instantly and must execute
19 the user tasks smoothly, even during considerable background load.
20
21 - good scheduling/wakeup performance with 1-2 runnable processes.
22
23 - fairness: no process should stay without any timeslice for any
24 unreasonable amount of time. No process should get an unjustly high
25 amount of CPU time.
26
27 - priorities: less important tasks can be started with lower priority,
28 more important tasks with higher priority.
29
30 - SMP efficiency: no CPU should stay idle if there is work to do.
31
32 - SMP affinity: processes which run on one CPU should stay affine to
33 that CPU. Processes should not bounce between CPUs too frequently.
34
35 - plus additional scheduler features: RT scheduling, CPU binding.
36
37and the goal is also to add a few new things:
38
39 - fully O(1) scheduling. Are you tired of the recalculation loop
40 blowing the L1 cache away every now and then? Do you think the goodness
41 loop is taking a bit too long to finish if there are lots of runnable
42 processes? This new scheduler takes no prisoners: wakeup(), schedule(),
43 the timer interrupt are all O(1) algorithms. There is no recalculation
44 loop. There is no goodness loop either.
45
46 - 'perfect' SMP scalability. With the new scheduler there is no 'big'
47 runqueue_lock anymore - it's all per-CPU runqueues and locks - two
48 tasks on two separate CPUs can wake up, schedule and context-switch
49 completely in parallel, without any interlocking. All
50 scheduling-relevant data is structured for maximum scalability.
51
52 - better SMP affinity. The old scheduler has a particular weakness that
53 causes the random bouncing of tasks between CPUs if/when higher
54 priority/interactive tasks, this was observed and reported by many
55 people. The reason is that the timeslice recalculation loop first needs
56 every currently running task to consume its timeslice. But when this
57 happens on eg. an 8-way system, then this property starves an
58 increasing number of CPUs from executing any process. Once the last
59 task that has a timeslice left has finished using up that timeslice,
60 the recalculation loop is triggered and other CPUs can start executing
61 tasks again - after having idled around for a number of timer ticks.
62 The more CPUs, the worse this effect.
63
64 Furthermore, this same effect causes the bouncing effect as well:
65 whenever there is such a 'timeslice squeeze' of the global runqueue,
66 idle processors start executing tasks which are not affine to that CPU.
67 (because the affine tasks have finished off their timeslices already.)
68
69 The new scheduler solves this problem by distributing timeslices on a
70 per-CPU basis, without having any global synchronization or
71 recalculation.
72
73 - batch scheduling. A significant proportion of computing-intensive tasks
74 benefit from batch-scheduling, where timeslices are long and processes
75 are roundrobin scheduled. The new scheduler does such batch-scheduling
76 of the lowest priority tasks - so nice +19 jobs will get
77 'batch-scheduled' automatically. With this scheduler, nice +19 jobs are
78 in essence SCHED_IDLE, from an interactiveness point of view.
79
80 - handle extreme loads more smoothly, without breakdown and scheduling
81 storms.
82
83 - O(1) RT scheduling. For those RT folks who are paranoid about the
84 O(nr_running) property of the goodness loop and the recalculation loop.
85
86 - run fork()ed children before the parent. Andrea has pointed out the
87 advantages of this a few months ago, but patches for this feature
88 do not work with the old scheduler as well as they should,
89 because idle processes often steal the new child before the fork()ing
90 CPU gets to execute it.
91
92
93Design
94======
95
96The core of the new scheduler contains the following mechanisms:
97
98 - *two* priority-ordered 'priority arrays' per CPU. There is an 'active'
99 array and an 'expired' array. The active array contains all tasks that
100 are affine to this CPU and have timeslices left. The expired array
101 contains all tasks which have used up their timeslices - but this array
102 is kept sorted as well. The active and expired array is not accessed
103 directly, it's accessed through two pointers in the per-CPU runqueue
104 structure. If all active tasks are used up then we 'switch' the two
105 pointers and from now on the ready-to-go (former-) expired array is the
106 active array - and the empty active array serves as the new collector
107 for expired tasks.
108
109 - there is a 64-bit bitmap cache for array indices. Finding the highest
110 priority task is thus a matter of two x86 BSFL bit-search instructions.
111
112the split-array solution enables us to have an arbitrary number of active
113and expired tasks, and the recalculation of timeslices can be done
114immediately when the timeslice expires. Because the arrays are always
115access through the pointers in the runqueue, switching the two arrays can
116be done very quickly.
117
118this is a hybride priority-list approach coupled with roundrobin
119scheduling and the array-switch method of distributing timeslices.
120
121 - there is a per-task 'load estimator'.
122
123one of the toughest things to get right is good interactive feel during
124heavy system load. While playing with various scheduler variants i found
125that the best interactive feel is achieved not by 'boosting' interactive
126tasks, but by 'punishing' tasks that want to use more CPU time than there
127is available. This method is also much easier to do in an O(1) fashion.
128
129to establish the actual 'load' the task contributes to the system, a
130complex-looking but pretty accurate method is used: there is a 4-entry
131'history' ringbuffer of the task's activities during the last 4 seconds.
132This ringbuffer is operated without much overhead. The entries tell the
133scheduler a pretty accurate load-history of the task: has it used up more
134CPU time or less during the past N seconds. [the size '4' and the interval
135of 4x 1 seconds was found by lots of experimentation - this part is
136flexible and can be changed in both directions.]
137
138the penalty a task gets for generating more load than the CPU can handle
139is a priority decrease - there is a maximum amount to this penalty
140relative to their static priority, so even fully CPU-bound tasks will
141observe each other's priorities, and will share the CPU accordingly.
142
143the SMP load-balancer can be extended/switched with additional parallel
144computing and cache hierarchy concepts: NUMA scheduling, multi-core CPUs
145can be supported easily by changing the load-balancer. Right now it's
146tuned for my SMP systems.
147
148i skipped the prev->mm == next->mm advantage - no workload i know of shows
149any sensitivity to this. It can be added back by sacrificing O(1)
150schedule() [the current and one-lower priority list can be searched for a
151that->mm == current->mm condition], but costs a fair number of cycles
152during a number of important workloads, so i wanted to avoid this as much
153as possible.
154
155- the SMP idle-task startup code was still racy and the new scheduler
156triggered this. So i streamlined the idle-setup code a bit. We do not call
157into schedule() before all processors have started up fully and all idle
158threads are in place.
159
160- the patch also cleans up a number of aspects of sched.c - moves code
161into other areas of the kernel where it's appropriate, and simplifies
162certain code paths and data constructs. As a result, the new scheduler's
163code is smaller than the old one.
164
165 Ingo
diff --git a/Documentation/scsi/ChangeLog.megaraid_sas b/Documentation/scsi/ChangeLog.megaraid_sas
index 91c81db0ba71..716fcc1cafb5 100644
--- a/Documentation/scsi/ChangeLog.megaraid_sas
+++ b/Documentation/scsi/ChangeLog.megaraid_sas
@@ -1,3 +1,25 @@
11 Release Date : Mon. March 10 11:02:31 PDT 2008 -
2 (emaild-id:megaraidlinux@lsi.com)
3 Sumant Patro
4 Bo Yang
5
62 Current Version : 00.00.03.20-RC1
73 Older Version : 00.00.03.16
8
91. Rollback the sense info implementation
10 Sense buffer ptr data type in the ioctl path is reverted back
11 to u32 * as in previous versions of driver.
12
132. Fixed the driver frame count.
14 When Driver sent wrong frame count to firmware. As this
15 particular command is sent to drive, FW is seeing continuous
16 chip resets and so the command will timeout.
17
183. Add the new controller(1078DE) support to the driver
19 and Increase the max_wait to 60 from 10 in the controller
20 operational status. With this max_wait increase, driver will
21 make sure the FW will finish the pending cmd for KDUMP case.
22
11 Release Date : Thur. Nov. 07 16:30:43 PST 2007 - 231 Release Date : Thur. Nov. 07 16:30:43 PST 2007 -
2 (emaild-id:megaraidlinux@lsi.com) 24 (emaild-id:megaraidlinux@lsi.com)
3 Sumant Patro 25 Sumant Patro
diff --git a/Documentation/thermal/sysfs-api.txt b/Documentation/thermal/sysfs-api.txt
index d9f28be75403..70d68ce8640a 100644
--- a/Documentation/thermal/sysfs-api.txt
+++ b/Documentation/thermal/sysfs-api.txt
@@ -108,10 +108,12 @@ and throttle appropriate devices.
108RO read only value 108RO read only value
109RW read/write value 109RW read/write value
110 110
111All thermal sysfs attributes will be represented under /sys/class/thermal 111Thermal sysfs attributes will be represented under /sys/class/thermal.
112Hwmon sysfs I/F extension is also available under /sys/class/hwmon
113if hwmon is compiled in or built as a module.
112 114
113Thermal zone device sys I/F, created once it's registered: 115Thermal zone device sys I/F, created once it's registered:
114|thermal_zone[0-*]: 116/sys/class/thermal/thermal_zone[0-*]:
115 |-----type: Type of the thermal zone 117 |-----type: Type of the thermal zone
116 |-----temp: Current temperature 118 |-----temp: Current temperature
117 |-----mode: Working mode of the thermal zone 119 |-----mode: Working mode of the thermal zone
@@ -119,7 +121,7 @@ Thermal zone device sys I/F, created once it's registered:
119 |-----trip_point_[0-*]_type: Trip point type 121 |-----trip_point_[0-*]_type: Trip point type
120 122
121Thermal cooling device sys I/F, created once it's registered: 123Thermal cooling device sys I/F, created once it's registered:
122|cooling_device[0-*]: 124/sys/class/thermal/cooling_device[0-*]:
123 |-----type : Type of the cooling device(processor/fan/...) 125 |-----type : Type of the cooling device(processor/fan/...)
124 |-----max_state: Maximum cooling state of the cooling device 126 |-----max_state: Maximum cooling state of the cooling device
125 |-----cur_state: Current cooling state of the cooling device 127 |-----cur_state: Current cooling state of the cooling device
@@ -130,10 +132,19 @@ They represent the relationship between a thermal zone and its associated coolin
130They are created/removed for each 132They are created/removed for each
131thermal_zone_bind_cooling_device/thermal_zone_unbind_cooling_device successful execution. 133thermal_zone_bind_cooling_device/thermal_zone_unbind_cooling_device successful execution.
132 134
133|thermal_zone[0-*] 135/sys/class/thermal/thermal_zone[0-*]
134 |-----cdev[0-*]: The [0-*]th cooling device in the current thermal zone 136 |-----cdev[0-*]: The [0-*]th cooling device in the current thermal zone
135 |-----cdev[0-*]_trip_point: Trip point that cdev[0-*] is associated with 137 |-----cdev[0-*]_trip_point: Trip point that cdev[0-*] is associated with
136 138
139Besides the thermal zone device sysfs I/F and cooling device sysfs I/F,
140the generic thermal driver also creates a hwmon sysfs I/F for each _type_ of
141thermal zone device. E.g. the generic thermal driver registers one hwmon class device
142and build the associated hwmon sysfs I/F for all the registered ACPI thermal zones.
143/sys/class/hwmon/hwmon[0-*]:
144 |-----name: The type of the thermal zone devices.
145 |-----temp[1-*]_input: The current temperature of thermal zone [1-*].
146 |-----temp[1-*]_critical: The critical trip point of thermal zone [1-*].
147Please read Documentation/hwmon/sysfs-interface for additional information.
137 148
138*************************** 149***************************
139* Thermal zone attributes * 150* Thermal zone attributes *
@@ -141,7 +152,10 @@ thermal_zone_bind_cooling_device/thermal_zone_unbind_cooling_device successful e
141 152
142type Strings which represent the thermal zone type. 153type Strings which represent the thermal zone type.
143 This is given by thermal zone driver as part of registration. 154 This is given by thermal zone driver as part of registration.
144 Eg: "ACPI thermal zone" indicates it's a ACPI thermal device 155 Eg: "acpitz" indicates it's an ACPI thermal device.
156 In order to keep it consistent with hwmon sys attribute,
157 this should be a short, lowercase string,
158 not containing spaces nor dashes.
145 RO 159 RO
146 Required 160 Required
147 161
@@ -218,7 +232,7 @@ the sys I/F structure will be built like this:
218/sys/class/thermal: 232/sys/class/thermal:
219 233
220|thermal_zone1: 234|thermal_zone1:
221 |-----type: ACPI thermal zone 235 |-----type: acpitz
222 |-----temp: 37000 236 |-----temp: 37000
223 |-----mode: kernel 237 |-----mode: kernel
224 |-----trip_point_0_temp: 100000 238 |-----trip_point_0_temp: 100000
@@ -243,3 +257,10 @@ the sys I/F structure will be built like this:
243 |-----type: Fan 257 |-----type: Fan
244 |-----max_state: 2 258 |-----max_state: 2
245 |-----cur_state: 0 259 |-----cur_state: 0
260
261/sys/class/hwmon:
262
263|hwmon0:
264 |-----name: acpitz
265 |-----temp1_input: 37000
266 |-----temp1_crit: 100000
diff --git a/Documentation/vm/slabinfo.c b/Documentation/vm/slabinfo.c
index d3ce295bffac..e4230ed16ee7 100644
--- a/Documentation/vm/slabinfo.c
+++ b/Documentation/vm/slabinfo.c
@@ -38,7 +38,7 @@ struct slabinfo {
38 unsigned long alloc_from_partial, alloc_slab, free_slab, alloc_refill; 38 unsigned long alloc_from_partial, alloc_slab, free_slab, alloc_refill;
39 unsigned long cpuslab_flush, deactivate_full, deactivate_empty; 39 unsigned long cpuslab_flush, deactivate_full, deactivate_empty;
40 unsigned long deactivate_to_head, deactivate_to_tail; 40 unsigned long deactivate_to_head, deactivate_to_tail;
41 unsigned long deactivate_remote_frees; 41 unsigned long deactivate_remote_frees, order_fallback;
42 int numa[MAX_NODES]; 42 int numa[MAX_NODES];
43 int numa_partial[MAX_NODES]; 43 int numa_partial[MAX_NODES];
44} slabinfo[MAX_SLABS]; 44} slabinfo[MAX_SLABS];
@@ -293,7 +293,7 @@ int line = 0;
293void first_line(void) 293void first_line(void)
294{ 294{
295 if (show_activity) 295 if (show_activity)
296 printf("Name Objects Alloc Free %%Fast\n"); 296 printf("Name Objects Alloc Free %%Fast Fallb O\n");
297 else 297 else
298 printf("Name Objects Objsize Space " 298 printf("Name Objects Objsize Space "
299 "Slabs/Part/Cpu O/S O %%Fr %%Ef Flg\n"); 299 "Slabs/Part/Cpu O/S O %%Fr %%Ef Flg\n");
@@ -573,11 +573,12 @@ void slabcache(struct slabinfo *s)
573 total_alloc = s->alloc_fastpath + s->alloc_slowpath; 573 total_alloc = s->alloc_fastpath + s->alloc_slowpath;
574 total_free = s->free_fastpath + s->free_slowpath; 574 total_free = s->free_fastpath + s->free_slowpath;
575 575
576 printf("%-21s %8ld %8ld %8ld %3ld %3ld \n", 576 printf("%-21s %8ld %10ld %10ld %3ld %3ld %5ld %1d\n",
577 s->name, s->objects, 577 s->name, s->objects,
578 total_alloc, total_free, 578 total_alloc, total_free,
579 total_alloc ? (s->alloc_fastpath * 100 / total_alloc) : 0, 579 total_alloc ? (s->alloc_fastpath * 100 / total_alloc) : 0,
580 total_free ? (s->free_fastpath * 100 / total_free) : 0); 580 total_free ? (s->free_fastpath * 100 / total_free) : 0,
581 s->order_fallback, s->order);
581 } 582 }
582 else 583 else
583 printf("%-21s %8ld %7d %8s %14s %4d %1d %3ld %3ld %s\n", 584 printf("%-21s %8ld %7d %8s %14s %4d %1d %3ld %3ld %s\n",
@@ -1188,6 +1189,7 @@ void read_slab_dir(void)
1188 slab->deactivate_to_head = get_obj("deactivate_to_head"); 1189 slab->deactivate_to_head = get_obj("deactivate_to_head");
1189 slab->deactivate_to_tail = get_obj("deactivate_to_tail"); 1190 slab->deactivate_to_tail = get_obj("deactivate_to_tail");
1190 slab->deactivate_remote_frees = get_obj("deactivate_remote_frees"); 1191 slab->deactivate_remote_frees = get_obj("deactivate_remote_frees");
1192 slab->order_fallback = get_obj("order_fallback");
1191 chdir(".."); 1193 chdir("..");
1192 if (slab->name[0] == ':') 1194 if (slab->name[0] == ':')
1193 alias_targets++; 1195 alias_targets++;
diff --git a/MAINTAINERS b/MAINTAINERS
index bca09ed77029..abe27871ad6a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1039,7 +1039,7 @@ P: Urs Thuermann
1039M: urs.thuermann@volkswagen.de 1039M: urs.thuermann@volkswagen.de
1040P: Oliver Hartkopp 1040P: Oliver Hartkopp
1041M: oliver.hartkopp@volkswagen.de 1041M: oliver.hartkopp@volkswagen.de
1042L: socketcan-core@lists.berlios.de 1042L: socketcan-core@lists.berlios.de (subscribers-only)
1043W: http://developer.berlios.de/projects/socketcan/ 1043W: http://developer.berlios.de/projects/socketcan/
1044S: Maintained 1044S: Maintained
1045 1045
@@ -1196,9 +1196,9 @@ S: Maintained
1196 1196
1197CPUSETS 1197CPUSETS
1198P: Paul Jackson 1198P: Paul Jackson
1199P: Simon Derr 1199P: Paul Menage
1200M: pj@sgi.com 1200M: pj@sgi.com
1201M: simon.derr@bull.net 1201M: menage@google.com
1202L: linux-kernel@vger.kernel.org 1202L: linux-kernel@vger.kernel.org
1203W: http://www.bullopensource.org/cpuset/ 1203W: http://www.bullopensource.org/cpuset/
1204S: Supported 1204S: Supported
@@ -1533,6 +1533,13 @@ L: bluesmoke-devel@lists.sourceforge.net
1533W: bluesmoke.sourceforge.net 1533W: bluesmoke.sourceforge.net
1534S: Maintained 1534S: Maintained
1535 1535
1536EEEPC LAPTOP EXTRAS DRIVER
1537P: Corentin Chary
1538M: corentincj@iksaif.net
1539L: acpi4asus-user@lists.sourceforge.net
1540W: http://sourceforge.net/projects/acpi4asus
1541S: Maintained
1542
1536EEPRO100 NETWORK DRIVER 1543EEPRO100 NETWORK DRIVER
1537P: Andrey V. Savochkin 1544P: Andrey V. Savochkin
1538M: saw@saw.sw.com.sg 1545M: saw@saw.sw.com.sg
@@ -1550,6 +1557,14 @@ M: raisch@de.ibm.com
1550L: general@lists.openfabrics.org 1557L: general@lists.openfabrics.org
1551S: Supported 1558S: Supported
1552 1559
1560EMBEDDED LINUX
1561P: Paul Gortmaker
1562M: paul.gortmaker@windriver.com
1563P David Woodhouse
1564M: dwmw2@infradead.org
1565L: linux-embedded@vger.kernel.org
1566S: Maintained
1567
1553EMULEX LPFC FC SCSI DRIVER 1568EMULEX LPFC FC SCSI DRIVER
1554P: James Smart 1569P: James Smart
1555M: james.smart@emulex.com 1570M: james.smart@emulex.com
@@ -2759,7 +2774,7 @@ M: rubini@ipvvis.unipv.it
2759L: linux-kernel@vger.kernel.org 2774L: linux-kernel@vger.kernel.org
2760S: Maintained 2775S: Maintained
2761 2776
2762MOXA SMARTIO/INDUSTIO SERIAL CARD (MXSER 2.0) 2777MOXA SMARTIO/INDUSTIO/INTELLIO SERIAL CARD
2763P: Jiri Slaby 2778P: Jiri Slaby
2764M: jirislaby@gmail.com 2779M: jirislaby@gmail.com
2765L: linux-kernel@vger.kernel.org 2780L: linux-kernel@vger.kernel.org
@@ -3115,7 +3130,7 @@ PCI SUBSYSTEM
3115P: Jesse Barnes 3130P: Jesse Barnes
3116M: jbarnes@virtuousgeek.org 3131M: jbarnes@virtuousgeek.org
3117L: linux-kernel@vger.kernel.org 3132L: linux-kernel@vger.kernel.org
3118L: linux-pci@atrey.karlin.mff.cuni.cz 3133L: linux-pci@vger.kernel.org
3119T: git kernel.org:/pub/scm/linux/kernel/git/jbarnes/pci-2.6.git 3134T: git kernel.org:/pub/scm/linux/kernel/git/jbarnes/pci-2.6.git
3120S: Supported 3135S: Supported
3121 3136
@@ -3577,6 +3592,13 @@ M: pfg@sgi.com
3577L: linux-ia64@vger.kernel.org 3592L: linux-ia64@vger.kernel.org
3578S: Supported 3593S: Supported
3579 3594
3595SFC NETWORK DRIVER
3596P: Steve Hodgson
3597P: Ben Hutchings
3598P: Robert Stonehouse
3599M: linux-net-drivers@solarflare.com
3600S: Supported
3601
3580SGI VISUAL WORKSTATION 320 AND 540 3602SGI VISUAL WORKSTATION 320 AND 540
3581P: Andrey Panin 3603P: Andrey Panin
3582M: pazke@donpac.ru 3604M: pazke@donpac.ru
@@ -3743,42 +3765,6 @@ M: chrisw@sous-sol.org
3743L: stable@kernel.org 3765L: stable@kernel.org
3744S: Maintained 3766S: Maintained
3745 3767
3746TPM DEVICE DRIVER
3747P: Kylene Hall
3748M: tpmdd-devel@lists.sourceforge.net
3749W: http://tpmdd.sourceforge.net
3750P: Marcel Selhorst
3751M: tpm@selhorst.net
3752W: http://www.prosec.rub.de/tpm/
3753L: tpmdd-devel@lists.sourceforge.net
3754S: Maintained
3755
3756Telecom Clock Driver for MCPL0010
3757P: Mark Gross
3758M: mark.gross@intel.com
3759S: Supported
3760
3761TENSILICA XTENSA PORT (xtensa):
3762P: Chris Zankel
3763M: chris@zankel.net
3764S: Maintained
3765
3766THINKPAD ACPI EXTRAS DRIVER
3767P: Henrique de Moraes Holschuh
3768M: ibm-acpi@hmh.eng.br
3769L: ibm-acpi-devel@lists.sourceforge.net
3770W: http://ibm-acpi.sourceforge.net
3771W: http://thinkwiki.org/wiki/Ibm-acpi
3772T: git repo.or.cz/linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git
3773S: Maintained
3774
3775UltraSPARC (sparc64):
3776P: David S. Miller
3777M: davem@davemloft.net
3778L: sparclinux@vger.kernel.org
3779T: git kernel.org:/pub/scm/linux/kernel/git/davem/sparc-2.6.git
3780S: Maintained
3781
3782SHARP LH SUPPORT (LH7952X & LH7A40X) 3768SHARP LH SUPPORT (LH7952X & LH7A40X)
3783P: Marc Singer 3769P: Marc Singer
3784M: elf@buici.com 3770M: elf@buici.com
@@ -3875,6 +3861,12 @@ P: Christoph Hellwig
3875M: hch@infradead.org 3861M: hch@infradead.org
3876S: Maintained 3862S: Maintained
3877 3863
3864TASKSTATS STATISTICS INTERFACE
3865P: Shailabh Nagar
3866M: nagar@watson.ibm.com
3867L: linux-kernel@vger.kernel.org
3868S: Maintained
3869
3878TC CLASSIFIER 3870TC CLASSIFIER
3879P: Jamal Hadi Salim 3871P: Jamal Hadi Salim
3880M: hadi@cyberus.ca 3872M: hadi@cyberus.ca
@@ -3897,6 +3889,25 @@ M: andy@greyhouse.net
3897L: netdev@vger.kernel.org 3889L: netdev@vger.kernel.org
3898S: Supported 3890S: Supported
3899 3891
3892Telecom Clock Driver for MCPL0010
3893P: Mark Gross
3894M: mark.gross@intel.com
3895S: Supported
3896
3897TENSILICA XTENSA PORT (xtensa):
3898P: Chris Zankel
3899M: chris@zankel.net
3900S: Maintained
3901
3902THINKPAD ACPI EXTRAS DRIVER
3903P: Henrique de Moraes Holschuh
3904M: ibm-acpi@hmh.eng.br
3905L: ibm-acpi-devel@lists.sourceforge.net
3906W: http://ibm-acpi.sourceforge.net
3907W: http://thinkwiki.org/wiki/Ibm-acpi
3908T: git repo.or.cz/linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git
3909S: Maintained
3910
3900TI FLASH MEDIA INTERFACE DRIVER 3911TI FLASH MEDIA INTERFACE DRIVER
3901P: Alex Dubov 3912P: Alex Dubov
3902M: oakad@yahoo.com 3913M: oakad@yahoo.com
@@ -3914,12 +3925,6 @@ P: Deepak Saxena
3914M: dsaxena@plexity.net 3925M: dsaxena@plexity.net
3915S: Maintained 3926S: Maintained
3916 3927
3917TASKSTATS STATISTICS INTERFACE
3918P: Shailabh Nagar
3919M: nagar@watson.ibm.com
3920L: linux-kernel@vger.kernel.org
3921S: Maintained
3922
3923TIPC NETWORK LAYER 3928TIPC NETWORK LAYER
3924P: Per Liden 3929P: Per Liden
3925M: per.liden@ericsson.com 3930M: per.liden@ericsson.com
@@ -3953,6 +3958,16 @@ L: tlinux-users@tce.toshiba-dme.co.jp
3953W: http://www.buzzard.org.uk/toshiba/ 3958W: http://www.buzzard.org.uk/toshiba/
3954S: Maintained 3959S: Maintained
3955 3960
3961TPM DEVICE DRIVER
3962P: Kylene Hall
3963M: tpmdd-devel@lists.sourceforge.net
3964W: http://tpmdd.sourceforge.net
3965P: Marcel Selhorst
3966M: tpm@selhorst.net
3967W: http://www.prosec.rub.de/tpm/
3968L: tpmdd-devel@lists.sourceforge.net
3969S: Maintained
3970
3956TRIDENT 4DWAVE/SIS 7018 PCI AUDIO CORE 3971TRIDENT 4DWAVE/SIS 7018 PCI AUDIO CORE
3957P: Muli Ben-Yehuda 3972P: Muli Ben-Yehuda
3958M: mulix@mulix.org 3973M: mulix@mulix.org
@@ -3965,6 +3980,12 @@ M: trivial@kernel.org
3965L: linux-kernel@vger.kernel.org 3980L: linux-kernel@vger.kernel.org
3966S: Maintained 3981S: Maintained
3967 3982
3983TTY LAYER
3984P: Alan Cox
3985M: alan@lxorguk.ukuu.org.uk
3986L: linux-kernel@vger.kernel.org
3987S: Maintained
3988
3968TULIP NETWORK DRIVERS 3989TULIP NETWORK DRIVERS
3969P: Grant Grundler 3990P: Grant Grundler
3970M: grundler@parisc-linux.org 3991M: grundler@parisc-linux.org
@@ -4030,6 +4051,12 @@ L: linux-usb@vger.kernel.org
4030S: Maintained 4051S: Maintained
4031W: http://www.kroah.com/linux-usb/ 4052W: http://www.kroah.com/linux-usb/
4032 4053
4054USB CYPRESS C67X00 DRIVER
4055P: Peter Korsgaard
4056M: jacmet@sunsite.dk
4057L: linux-usb@vger.kernel.org
4058S: Maintained
4059
4033USB DAVICOM DM9601 DRIVER 4060USB DAVICOM DM9601 DRIVER
4034P: Peter Korsgaard 4061P: Peter Korsgaard
4035M: jacmet@sunsite.dk 4062M: jacmet@sunsite.dk
@@ -4133,6 +4160,20 @@ L: linux-usb@vger.kernel.org
4133W: http://www.chello.nl/~j.vreeken/se401/ 4160W: http://www.chello.nl/~j.vreeken/se401/
4134S: Maintained 4161S: Maintained
4135 4162
4163USB SERIAL BELKIN F5U103 DRIVER
4164P: William Greathouse
4165M: wgreathouse@smva.com
4166L: linux-usb@vger.kernel.org
4167S: Maintained
4168
4169USB SERIAL CYPRESS M8 DRIVER
4170P: Lonnie Mendez
4171M: dignome@gmail.com
4172L: linux-usb@vger.kernel.org
4173S: Maintained
4174W: http://geocities.com/i0xox0i
4175W: http://firstlight.net/cvs
4176
4136USB SERIAL CYBERJACK DRIVER 4177USB SERIAL CYBERJACK DRIVER
4137P: Matthias Bruestle and Harald Welte 4178P: Matthias Bruestle and Harald Welte
4138M: support@reiner-sct.com 4179M: support@reiner-sct.com
@@ -4152,20 +4193,6 @@ M: gregkh@suse.de
4152L: linux-usb@vger.kernel.org 4193L: linux-usb@vger.kernel.org
4153S: Supported 4194S: Supported
4154 4195
4155USB SERIAL BELKIN F5U103 DRIVER
4156P: William Greathouse
4157M: wgreathouse@smva.com
4158L: linux-usb@vger.kernel.org
4159S: Maintained
4160
4161USB SERIAL CYPRESS M8 DRIVER
4162P: Lonnie Mendez
4163M: dignome@gmail.com
4164L: linux-usb@vger.kernel.org
4165S: Maintained
4166W: http://geocities.com/i0xox0i
4167W: http://firstlight.net/cvs
4168
4169USB SERIAL EMPEG EMPEG-CAR MARK I/II DRIVER 4196USB SERIAL EMPEG EMPEG-CAR MARK I/II DRIVER
4170P: Gary Brubaker 4197P: Gary Brubaker
4171M: xavyer@ix.netcom.com 4198M: xavyer@ix.netcom.com
@@ -4268,7 +4295,7 @@ M: gregkh@suse.de
4268L: linux-kernel@vger.kernel.org 4295L: linux-kernel@vger.kernel.org
4269S: Maintained 4296S: Maintained
4270 4297
4271FAT/VFAT/MSDOS FILESYSTEM: 4298VFAT/FAT/MSDOS FILESYSTEM:
4272P: OGAWA Hirofumi 4299P: OGAWA Hirofumi
4273M: hirofumi@mail.parknet.co.jp 4300M: hirofumi@mail.parknet.co.jp
4274L: linux-kernel@vger.kernel.org 4301L: linux-kernel@vger.kernel.org
@@ -4313,6 +4340,13 @@ M: dushistov@mail.ru
4313L: linux-kernel@vger.kernel.org 4340L: linux-kernel@vger.kernel.org
4314S: Maintained 4341S: Maintained
4315 4342
4343UltraSPARC (sparc64):
4344P: David S. Miller
4345M: davem@davemloft.net
4346L: sparclinux@vger.kernel.org
4347T: git kernel.org:/pub/scm/linux/kernel/git/davem/sparc-2.6.git
4348S: Maintained
4349
4316USB DIAMOND RIO500 DRIVER 4350USB DIAMOND RIO500 DRIVER
4317P: Cesar Miquel 4351P: Cesar Miquel
4318M: miquel@df.uba.ar 4352M: miquel@df.uba.ar
diff --git a/Makefile b/Makefile
index d3634cd6fe35..4492984efc09 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
1VERSION = 2 1VERSION = 2
2PATCHLEVEL = 6 2PATCHLEVEL = 6
3SUBLEVEL = 25 3SUBLEVEL = 26
4EXTRAVERSION = 4EXTRAVERSION = -rc1
5NAME = Funky Weasel is Jiggy wit it 5NAME = Funky Weasel is Jiggy wit it
6 6
7# *DOCUMENTATION* 7# *DOCUMENTATION*
@@ -794,7 +794,7 @@ endif # ifdef CONFIG_KALLSYMS
794quiet_cmd_vmlinux-modpost = LD $@ 794quiet_cmd_vmlinux-modpost = LD $@
795 cmd_vmlinux-modpost = $(LD) $(LDFLAGS) -r -o $@ \ 795 cmd_vmlinux-modpost = $(LD) $(LDFLAGS) -r -o $@ \
796 $(vmlinux-init) --start-group $(vmlinux-main) --end-group \ 796 $(vmlinux-init) --start-group $(vmlinux-main) --end-group \
797 $(filter-out $(vmlinux-init) $(vmlinux-main) $(vmlinux-lds) FORCE ,$^) 797 $(filter-out $(vmlinux-init) $(vmlinux-main) FORCE ,$^)
798define rule_vmlinux-modpost 798define rule_vmlinux-modpost
799 : 799 :
800 +$(call cmd,vmlinux-modpost) 800 +$(call cmd,vmlinux-modpost)
@@ -818,7 +818,9 @@ endif
818ifdef CONFIG_KALLSYMS 818ifdef CONFIG_KALLSYMS
819.tmp_vmlinux1: vmlinux.o 819.tmp_vmlinux1: vmlinux.o
820endif 820endif
821vmlinux.o: $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) FORCE 821
822modpost-init := $(filter-out init/built-in.o, $(vmlinux-init))
823vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
822 $(call if_changed_rule,vmlinux-modpost) 824 $(call if_changed_rule,vmlinux-modpost)
823 825
824# The actual objects are generated when descending, 826# The actual objects are generated when descending,
diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
index 9fee37e2596f..32ca1b927307 100644
--- a/arch/alpha/kernel/osf_sys.c
+++ b/arch/alpha/kernel/osf_sys.c
@@ -981,27 +981,18 @@ asmlinkage int
981osf_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp, 981osf_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp,
982 struct timeval32 __user *tvp) 982 struct timeval32 __user *tvp)
983{ 983{
984 fd_set_bits fds; 984 s64 timeout = MAX_SCHEDULE_TIMEOUT;
985 char *bits;
986 size_t size;
987 long timeout;
988 int ret = -EINVAL;
989 struct fdtable *fdt;
990 int max_fds;
991
992 timeout = MAX_SCHEDULE_TIMEOUT;
993 if (tvp) { 985 if (tvp) {
994 time_t sec, usec; 986 time_t sec, usec;
995 987
996 if (!access_ok(VERIFY_READ, tvp, sizeof(*tvp)) 988 if (!access_ok(VERIFY_READ, tvp, sizeof(*tvp))
997 || __get_user(sec, &tvp->tv_sec) 989 || __get_user(sec, &tvp->tv_sec)
998 || __get_user(usec, &tvp->tv_usec)) { 990 || __get_user(usec, &tvp->tv_usec)) {
999 ret = -EFAULT; 991 return -EFAULT;
1000 goto out_nofds;
1001 } 992 }
1002 993
1003 if (sec < 0 || usec < 0) 994 if (sec < 0 || usec < 0)
1004 goto out_nofds; 995 return -EINVAL;
1005 996
1006 if ((unsigned long) sec < MAX_SELECT_SECONDS) { 997 if ((unsigned long) sec < MAX_SELECT_SECONDS) {
1007 timeout = (usec + 1000000/HZ - 1) / (1000000/HZ); 998 timeout = (usec + 1000000/HZ - 1) / (1000000/HZ);
@@ -1009,60 +1000,8 @@ osf_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp,
1009 } 1000 }
1010 } 1001 }
1011 1002
1012 rcu_read_lock();
1013 fdt = files_fdtable(current->files);
1014 max_fds = fdt->max_fds;
1015 rcu_read_unlock();
1016 if (n < 0 || n > max_fds)
1017 goto out_nofds;
1018
1019 /*
1020 * We need 6 bitmaps (in/out/ex for both incoming and outgoing),
1021 * since we used fdset we need to allocate memory in units of
1022 * long-words.
1023 */
1024 ret = -ENOMEM;
1025 size = FDS_BYTES(n);
1026 bits = kmalloc(6 * size, GFP_KERNEL);
1027 if (!bits)
1028 goto out_nofds;
1029 fds.in = (unsigned long *) bits;
1030 fds.out = (unsigned long *) (bits + size);
1031 fds.ex = (unsigned long *) (bits + 2*size);
1032 fds.res_in = (unsigned long *) (bits + 3*size);
1033 fds.res_out = (unsigned long *) (bits + 4*size);
1034 fds.res_ex = (unsigned long *) (bits + 5*size);
1035
1036 if ((ret = get_fd_set(n, inp->fds_bits, fds.in)) ||
1037 (ret = get_fd_set(n, outp->fds_bits, fds.out)) ||
1038 (ret = get_fd_set(n, exp->fds_bits, fds.ex)))
1039 goto out;
1040 zero_fd_set(n, fds.res_in);
1041 zero_fd_set(n, fds.res_out);
1042 zero_fd_set(n, fds.res_ex);
1043
1044 ret = do_select(n, &fds, &timeout);
1045
1046 /* OSF does not copy back the remaining time. */ 1003 /* OSF does not copy back the remaining time. */
1047 1004 return core_sys_select(n, inp, outp, exp, &timeout);
1048 if (ret < 0)
1049 goto out;
1050 if (!ret) {
1051 ret = -ERESTARTNOHAND;
1052 if (signal_pending(current))
1053 goto out;
1054 ret = 0;
1055 }
1056
1057 if (set_fd_set(n, inp->fds_bits, fds.res_in) ||
1058 set_fd_set(n, outp->fds_bits, fds.res_out) ||
1059 set_fd_set(n, exp->fds_bits, fds.res_ex))
1060 ret = -EFAULT;
1061
1062 out:
1063 kfree(bits);
1064 out_nofds:
1065 return ret;
1066} 1005}
1067 1006
1068struct rusage32 { 1007struct rusage32 {
diff --git a/arch/arm/kernel/sys_arm.c b/arch/arm/kernel/sys_arm.c
index 9bd1870d980e..0128687ba0f7 100644
--- a/arch/arm/kernel/sys_arm.c
+++ b/arch/arm/kernel/sys_arm.c
@@ -34,23 +34,6 @@ extern unsigned long do_mremap(unsigned long addr, unsigned long old_len,
34 unsigned long new_len, unsigned long flags, 34 unsigned long new_len, unsigned long flags,
35 unsigned long new_addr); 35 unsigned long new_addr);
36 36
37/*
38 * sys_pipe() is the normal C calling standard for creating
39 * a pipe. It's not the way unix traditionally does this, though.
40 */
41asmlinkage int sys_pipe(unsigned long __user *fildes)
42{
43 int fd[2];
44 int error;
45
46 error = do_pipe(fd);
47 if (!error) {
48 if (copy_to_user(fildes, fd, 2*sizeof(int)))
49 error = -EFAULT;
50 }
51 return error;
52}
53
54/* common code for old and new mmaps */ 37/* common code for old and new mmaps */
55inline long do_mmap2( 38inline long do_mmap2(
56 unsigned long addr, unsigned long len, 39 unsigned long addr, unsigned long len,
diff --git a/arch/arm/mach-ixp4xx/ixp4xx_npe.c b/arch/arm/mach-ixp4xx/ixp4xx_npe.c
index 83c137ec582c..63a23fa4aab4 100644
--- a/arch/arm/mach-ixp4xx/ixp4xx_npe.c
+++ b/arch/arm/mach-ixp4xx/ixp4xx_npe.c
@@ -448,7 +448,9 @@ int npe_send_message(struct npe *npe, const void *msg, const char *what)
448 return -ETIMEDOUT; 448 return -ETIMEDOUT;
449 } 449 }
450 450
451#if DEBUG_MSG > 1
451 debug_msg(npe, "Sending a message took %i cycles\n", cycles); 452 debug_msg(npe, "Sending a message took %i cycles\n", cycles);
453#endif
452 return 0; 454 return 0;
453} 455}
454 456
@@ -484,7 +486,9 @@ int npe_recv_message(struct npe *npe, void *msg, const char *what)
484 return -ETIMEDOUT; 486 return -ETIMEDOUT;
485 } 487 }
486 488
489#if DEBUG_MSG > 1
487 debug_msg(npe, "Receiving a message took %i cycles\n", cycles); 490 debug_msg(npe, "Receiving a message took %i cycles\n", cycles);
491#endif
488 return 0; 492 return 0;
489} 493}
490 494
diff --git a/arch/arm/mach-ixp4xx/ixp4xx_qmgr.c b/arch/arm/mach-ixp4xx/ixp4xx_qmgr.c
index e83301325301..fab94eaecee7 100644
--- a/arch/arm/mach-ixp4xx/ixp4xx_qmgr.c
+++ b/arch/arm/mach-ixp4xx/ixp4xx_qmgr.c
@@ -184,6 +184,8 @@ void qmgr_release_queue(unsigned int queue)
184 case 3: mask[0] = 0xFF; break; 184 case 3: mask[0] = 0xFF; break;
185 } 185 }
186 186
187 mask[1] = mask[2] = mask[3] = 0;
188
187 while (addr--) 189 while (addr--)
188 shift_mask(mask); 190 shift_mask(mask);
189 191
diff --git a/arch/arm/mach-pxa/generic.c b/arch/arm/mach-pxa/generic.c
index 331f29b2d0cd..44617938f3f1 100644
--- a/arch/arm/mach-pxa/generic.c
+++ b/arch/arm/mach-pxa/generic.c
@@ -90,11 +90,6 @@ static struct map_desc standard_io_desc[] __initdata = {
90 .pfn = __phys_to_pfn(0x40000000), 90 .pfn = __phys_to_pfn(0x40000000),
91 .length = 0x02000000, 91 .length = 0x02000000,
92 .type = MT_DEVICE 92 .type = MT_DEVICE
93 }, { /* LCD */
94 .virtual = 0xf4000000,
95 .pfn = __phys_to_pfn(0x44000000),
96 .length = 0x00100000,
97 .type = MT_DEVICE
98 }, { /* Mem Ctl */ 93 }, { /* Mem Ctl */
99 .virtual = 0xf6000000, 94 .virtual = 0xf6000000,
100 .pfn = __phys_to_pfn(0x48000000), 95 .pfn = __phys_to_pfn(0x48000000),
diff --git a/arch/arm/mach-pxa/littleton.c b/arch/arm/mach-pxa/littleton.c
index 03396063b561..530654474bb2 100644
--- a/arch/arm/mach-pxa/littleton.c
+++ b/arch/arm/mach-pxa/littleton.c
@@ -301,8 +301,7 @@ static struct pxafb_mode_info tpo_tdo24mtea1_modes[] = {
301static struct pxafb_mach_info littleton_lcd_info = { 301static struct pxafb_mach_info littleton_lcd_info = {
302 .modes = tpo_tdo24mtea1_modes, 302 .modes = tpo_tdo24mtea1_modes,
303 .num_modes = 2, 303 .num_modes = 2,
304 .lccr0 = LCCR0_Act, 304 .lcd_conn = LCD_COLOR_TFT_16BPP,
305 .lccr3 = LCCR3_HSP | LCCR3_VSP,
306 .pxafb_lcd_power = littleton_lcd_power, 305 .pxafb_lcd_power = littleton_lcd_power,
307}; 306};
308 307
diff --git a/arch/arm/mach-pxa/lubbock.c b/arch/arm/mach-pxa/lubbock.c
index ca209c443f34..0993f4d1a0bc 100644
--- a/arch/arm/mach-pxa/lubbock.c
+++ b/arch/arm/mach-pxa/lubbock.c
@@ -395,8 +395,8 @@ static struct pxafb_mach_info sharp_lm8v31 = {
395 .num_modes = 1, 395 .num_modes = 1,
396 .cmap_inverse = 0, 396 .cmap_inverse = 0,
397 .cmap_static = 0, 397 .cmap_static = 0,
398 .lccr0 = LCCR0_SDS, 398 .lcd_conn = LCD_COLOR_DSTN_16BPP | LCD_PCLK_EDGE_FALL |
399 .lccr3 = LCCR3_PCP | LCCR3_Acb(255), 399 LCD_AC_BIAS_FREQ(255);
400}; 400};
401 401
402#define MMC_POLL_RATE msecs_to_jiffies(1000) 402#define MMC_POLL_RATE msecs_to_jiffies(1000)
diff --git a/arch/arm/mach-pxa/mainstone.c b/arch/arm/mach-pxa/mainstone.c
index 18d47cfa2a18..7399fb34da4e 100644
--- a/arch/arm/mach-pxa/mainstone.c
+++ b/arch/arm/mach-pxa/mainstone.c
@@ -434,8 +434,7 @@ static struct pxafb_mode_info toshiba_ltm035a776c_mode = {
434 434
435static struct pxafb_mach_info mainstone_pxafb_info = { 435static struct pxafb_mach_info mainstone_pxafb_info = {
436 .num_modes = 1, 436 .num_modes = 1,
437 .lccr0 = LCCR0_Act, 437 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
438 .lccr3 = LCCR3_PCP,
439}; 438};
440 439
441static int mainstone_mci_init(struct device *dev, irq_handler_t mstone_detect_int, void *data) 440static int mainstone_mci_init(struct device *dev, irq_handler_t mstone_detect_int, void *data)
diff --git a/arch/arm/mach-pxa/zylonite.c b/arch/arm/mach-pxa/zylonite.c
index dbb546216be1..4a0028087ea6 100644
--- a/arch/arm/mach-pxa/zylonite.c
+++ b/arch/arm/mach-pxa/zylonite.c
@@ -97,8 +97,7 @@ static struct pxafb_mode_info toshiba_ltm04c380k_mode = {
97 97
98static struct pxafb_mach_info zylonite_toshiba_lcd_info = { 98static struct pxafb_mach_info zylonite_toshiba_lcd_info = {
99 .num_modes = 1, 99 .num_modes = 1,
100 .lccr0 = LCCR0_Act, 100 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
101 .lccr3 = LCCR3_PCP,
102 .pxafb_backlight_power = zylonite_backlight_power, 101 .pxafb_backlight_power = zylonite_backlight_power,
103}; 102};
104 103
@@ -134,8 +133,7 @@ static struct pxafb_mode_info sharp_ls037_modes[] = {
134static struct pxafb_mach_info zylonite_sharp_lcd_info = { 133static struct pxafb_mach_info zylonite_sharp_lcd_info = {
135 .modes = sharp_ls037_modes, 134 .modes = sharp_ls037_modes,
136 .num_modes = 2, 135 .num_modes = 2,
137 .lccr0 = LCCR0_Act, 136 .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_PCLK_EDGE_FALL,
138 .lccr3 = LCCR3_PCP | LCCR3_HSP | LCCR3_VSP,
139 .pxafb_backlight_power = zylonite_backlight_power, 137 .pxafb_backlight_power = zylonite_backlight_power,
140}; 138};
141 139
diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
index d41a75ed3dce..2d6d682c206a 100644
--- a/arch/arm/mm/mmu.c
+++ b/arch/arm/mm/mmu.c
@@ -35,6 +35,7 @@ extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
35 * zero-initialized data and COW. 35 * zero-initialized data and COW.
36 */ 36 */
37struct page *empty_zero_page; 37struct page *empty_zero_page;
38EXPORT_SYMBOL(empty_zero_page);
38 39
39/* 40/*
40 * The pmd table for the upper-most set of pages. 41 * The pmd table for the upper-most set of pages.
diff --git a/arch/avr32/kernel/sys_avr32.c b/arch/avr32/kernel/sys_avr32.c
index 8deb6003ee62..8e8911e55c8f 100644
--- a/arch/avr32/kernel/sys_avr32.c
+++ b/arch/avr32/kernel/sys_avr32.c
@@ -14,19 +14,6 @@
14#include <asm/mman.h> 14#include <asm/mman.h>
15#include <asm/uaccess.h> 15#include <asm/uaccess.h>
16 16
17asmlinkage int sys_pipe(unsigned long __user *filedes)
18{
19 int fd[2];
20 int error;
21
22 error = do_pipe(fd);
23 if (!error) {
24 if (copy_to_user(filedes, fd, sizeof(fd)))
25 error = -EFAULT;
26 }
27 return error;
28}
29
30asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, 17asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
31 unsigned long prot, unsigned long flags, 18 unsigned long prot, unsigned long flags,
32 unsigned long fd, off_t offset) 19 unsigned long fd, off_t offset)
diff --git a/arch/blackfin/kernel/sys_bfin.c b/arch/blackfin/kernel/sys_bfin.c
index efb7b25a2633..fce49d7cf001 100644
--- a/arch/blackfin/kernel/sys_bfin.c
+++ b/arch/blackfin/kernel/sys_bfin.c
@@ -45,23 +45,6 @@
45#include <asm/cacheflush.h> 45#include <asm/cacheflush.h>
46#include <asm/dma.h> 46#include <asm/dma.h>
47 47
48/*
49 * sys_pipe() is the normal C calling standard for creating
50 * a pipe. It's not the way unix traditionally does this, though.
51 */
52asmlinkage int sys_pipe(unsigned long __user *fildes)
53{
54 int fd[2];
55 int error;
56
57 error = do_pipe(fd);
58 if (!error) {
59 if (copy_to_user(fildes, fd, 2 * sizeof(int)))
60 error = -EFAULT;
61 }
62 return error;
63}
64
65/* common code for old and new mmaps */ 48/* common code for old and new mmaps */
66static inline long 49static inline long
67do_mmap2(unsigned long addr, unsigned long len, 50do_mmap2(unsigned long addr, unsigned long len,
diff --git a/arch/frv/kernel/pm.c b/arch/frv/kernel/pm.c
index c57ce3f1f2e2..73f3aeefd203 100644
--- a/arch/frv/kernel/pm.c
+++ b/arch/frv/kernel/pm.c
@@ -163,14 +163,11 @@ static int sysctl_pm_do_suspend(ctl_table *ctl, int write, struct file *filp,
163 if ((mode != 1) && (mode != 5)) 163 if ((mode != 1) && (mode != 5))
164 return -EINVAL; 164 return -EINVAL;
165 165
166 retval = pm_send_all(PM_SUSPEND, (void *)3);
167
168 if (retval == 0) { 166 if (retval == 0) {
169 if (mode == 5) 167 if (mode == 5)
170 retval = pm_do_bus_sleep(); 168 retval = pm_do_bus_sleep();
171 else 169 else
172 retval = pm_do_suspend(); 170 retval = pm_do_suspend();
173 pm_send_all(PM_RESUME, (void *)0);
174 } 171 }
175 172
176 return retval; 173 return retval;
@@ -183,9 +180,6 @@ static int try_set_cmode(int new_cmode)
183 if (!(clock_cmodes_permitted & (1<<new_cmode))) 180 if (!(clock_cmodes_permitted & (1<<new_cmode)))
184 return -EINVAL; 181 return -EINVAL;
185 182
186 /* tell all the drivers we're suspending */
187 pm_send_all(PM_SUSPEND, (void *)3);
188
189 /* now change cmode */ 183 /* now change cmode */
190 local_irq_disable(); 184 local_irq_disable();
191 frv_dma_pause_all(); 185 frv_dma_pause_all();
@@ -201,8 +195,6 @@ static int try_set_cmode(int new_cmode)
201 frv_dma_resume_all(); 195 frv_dma_resume_all();
202 local_irq_enable(); 196 local_irq_enable();
203 197
204 /* tell all the drivers we're resuming */
205 pm_send_all(PM_RESUME, (void *)0);
206 return 0; 198 return 0;
207} 199}
208 200
diff --git a/arch/frv/kernel/sys_frv.c b/arch/frv/kernel/sys_frv.c
index 04c6b1677ccf..49b2cf2c38f3 100644
--- a/arch/frv/kernel/sys_frv.c
+++ b/arch/frv/kernel/sys_frv.c
@@ -28,23 +28,6 @@
28#include <asm/setup.h> 28#include <asm/setup.h>
29#include <asm/uaccess.h> 29#include <asm/uaccess.h>
30 30
31/*
32 * sys_pipe() is the normal C calling standard for creating
33 * a pipe. It's not the way unix traditionally does this, though.
34 */
35asmlinkage long sys_pipe(unsigned long __user * fildes)
36{
37 int fd[2];
38 int error;
39
40 error = do_pipe(fd);
41 if (!error) {
42 if (copy_to_user(fildes, fd, 2*sizeof(int)))
43 error = -EFAULT;
44 }
45 return error;
46}
47
48asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, 31asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
49 unsigned long prot, unsigned long flags, 32 unsigned long prot, unsigned long flags,
50 unsigned long fd, unsigned long pgoff) 33 unsigned long fd, unsigned long pgoff)
diff --git a/arch/frv/mm/Makefile b/arch/frv/mm/Makefile
index fb8b1d860f46..1bca5ab8a6ab 100644
--- a/arch/frv/mm/Makefile
+++ b/arch/frv/mm/Makefile
@@ -6,4 +6,4 @@ obj-y := init.o kmap.o
6 6
7obj-$(CONFIG_MMU) += \ 7obj-$(CONFIG_MMU) += \
8 pgalloc.o highmem.o fault.o extable.o cache-page.o tlb-flush.o tlb-miss.o \ 8 pgalloc.o highmem.o fault.o extable.o cache-page.o tlb-flush.o tlb-miss.o \
9 mmu-context.o dma-alloc.o unaligned.o elf-fdpic.o 9 mmu-context.o dma-alloc.o elf-fdpic.o
diff --git a/arch/h8300/kernel/sys_h8300.c b/arch/h8300/kernel/sys_h8300.c
index 00608be6d567..2745656dcc52 100644
--- a/arch/h8300/kernel/sys_h8300.c
+++ b/arch/h8300/kernel/sys_h8300.c
@@ -27,23 +27,6 @@
27#include <asm/traps.h> 27#include <asm/traps.h>
28#include <asm/unistd.h> 28#include <asm/unistd.h>
29 29
30/*
31 * sys_pipe() is the normal C calling standard for creating
32 * a pipe. It's not the way unix traditionally does this, though.
33 */
34asmlinkage int sys_pipe(unsigned long * fildes)
35{
36 int fd[2];
37 int error;
38
39 error = do_pipe(fd);
40 if (!error) {
41 if (copy_to_user(fildes, fd, 2*sizeof(int)))
42 error = -EFAULT;
43 }
44 return error;
45}
46
47/* common code for old and new mmaps */ 30/* common code for old and new mmaps */
48static inline long do_mmap2( 31static inline long do_mmap2(
49 unsigned long addr, unsigned long len, 32 unsigned long addr, unsigned long len,
diff --git a/arch/ia64/hp/sim/simserial.c b/arch/ia64/hp/sim/simserial.c
index eb0c32a85fd7..23cafc80d2a4 100644
--- a/arch/ia64/hp/sim/simserial.c
+++ b/arch/ia64/hp/sim/simserial.c
@@ -210,21 +210,23 @@ static void do_softint(struct work_struct *private_)
210 printk(KERN_ERR "simserial: do_softint called\n"); 210 printk(KERN_ERR "simserial: do_softint called\n");
211} 211}
212 212
213static void rs_put_char(struct tty_struct *tty, unsigned char ch) 213static int rs_put_char(struct tty_struct *tty, unsigned char ch)
214{ 214{
215 struct async_struct *info = (struct async_struct *)tty->driver_data; 215 struct async_struct *info = (struct async_struct *)tty->driver_data;
216 unsigned long flags; 216 unsigned long flags;
217 217
218 if (!tty || !info->xmit.buf) return; 218 if (!tty || !info->xmit.buf)
219 return 0;
219 220
220 local_irq_save(flags); 221 local_irq_save(flags);
221 if (CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE) == 0) { 222 if (CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE) == 0) {
222 local_irq_restore(flags); 223 local_irq_restore(flags);
223 return; 224 return 0;
224 } 225 }
225 info->xmit.buf[info->xmit.head] = ch; 226 info->xmit.buf[info->xmit.head] = ch;
226 info->xmit.head = (info->xmit.head + 1) & (SERIAL_XMIT_SIZE-1); 227 info->xmit.head = (info->xmit.head + 1) & (SERIAL_XMIT_SIZE-1);
227 local_irq_restore(flags); 228 local_irq_restore(flags);
229 return 1;
228} 230}
229 231
230static void transmit_chars(struct async_struct *info, int *intr_done) 232static void transmit_chars(struct async_struct *info, int *intr_done)
@@ -621,7 +623,8 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
621 * the line discipline to only process XON/XOFF characters. 623 * the line discipline to only process XON/XOFF characters.
622 */ 624 */
623 shutdown(info); 625 shutdown(info);
624 if (tty->driver->flush_buffer) tty->driver->flush_buffer(tty); 626 if (tty->ops->flush_buffer)
627 tty->ops->flush_buffer(tty);
625 if (tty->ldisc.flush_buffer) tty->ldisc.flush_buffer(tty); 628 if (tty->ldisc.flush_buffer) tty->ldisc.flush_buffer(tty);
626 info->event = 0; 629 info->event = 0;
627 info->tty = NULL; 630 info->tty = NULL;
diff --git a/arch/ia64/ia32/ia32_signal.c b/arch/ia64/ia32/ia32_signal.c
index 256a7faeda07..b763ca19ef17 100644
--- a/arch/ia64/ia32/ia32_signal.c
+++ b/arch/ia64/ia32/ia32_signal.c
@@ -463,7 +463,7 @@ sys32_sigsuspend (int history0, int history1, old_sigset_t mask)
463 463
464 current->state = TASK_INTERRUPTIBLE; 464 current->state = TASK_INTERRUPTIBLE;
465 schedule(); 465 schedule();
466 set_thread_flag(TIF_RESTORE_SIGMASK); 466 set_restore_sigmask();
467 return -ERESTARTNOHAND; 467 return -ERESTARTNOHAND;
468} 468}
469 469
diff --git a/arch/ia64/kernel/acpi.c b/arch/ia64/kernel/acpi.c
index c7467f863c7a..19709a079635 100644
--- a/arch/ia64/kernel/acpi.c
+++ b/arch/ia64/kernel/acpi.c
@@ -966,7 +966,7 @@ acpi_map_iosapics (void)
966fs_initcall(acpi_map_iosapics); 966fs_initcall(acpi_map_iosapics);
967#endif /* CONFIG_ACPI_NUMA */ 967#endif /* CONFIG_ACPI_NUMA */
968 968
969int acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base) 969int __ref acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
970{ 970{
971 int err; 971 int err;
972 972
diff --git a/arch/ia64/kernel/irq.c b/arch/ia64/kernel/irq.c
index 6dee579f205f..7fd18f54c056 100644
--- a/arch/ia64/kernel/irq.c
+++ b/arch/ia64/kernel/irq.c
@@ -183,10 +183,10 @@ void fixup_irqs(void)
183{ 183{
184 unsigned int irq; 184 unsigned int irq;
185 extern void ia64_process_pending_intr(void); 185 extern void ia64_process_pending_intr(void);
186 extern void ia64_disable_timer(void);
187 extern volatile int time_keeper_id; 186 extern volatile int time_keeper_id;
188 187
189 ia64_disable_timer(); 188 /* Mask ITV to disable timer */
189 ia64_set_itv(1 << 16);
190 190
191 /* 191 /*
192 * Find a new timesync master 192 * Find a new timesync master
diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
index 396004e8cd14..4547a2092af9 100644
--- a/arch/ia64/kernel/palinfo.c
+++ b/arch/ia64/kernel/palinfo.c
@@ -1053,7 +1053,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
1053 return NOTIFY_OK; 1053 return NOTIFY_OK;
1054} 1054}
1055 1055
1056static struct notifier_block palinfo_cpu_notifier __cpuinitdata = 1056static struct notifier_block __refdata palinfo_cpu_notifier =
1057{ 1057{
1058 .notifier_call = palinfo_cpu_callback, 1058 .notifier_call = palinfo_cpu_callback,
1059 .priority = 0, 1059 .priority = 0,
diff --git a/arch/ia64/kernel/perfmon.c b/arch/ia64/kernel/perfmon.c
index 7fbb51e10bbe..c1ad27de2dd2 100644
--- a/arch/ia64/kernel/perfmon.c
+++ b/arch/ia64/kernel/perfmon.c
@@ -867,7 +867,7 @@ pfm_rvfree(void *mem, unsigned long size)
867} 867}
868 868
869static pfm_context_t * 869static pfm_context_t *
870pfm_context_alloc(void) 870pfm_context_alloc(int ctx_flags)
871{ 871{
872 pfm_context_t *ctx; 872 pfm_context_t *ctx;
873 873
@@ -878,6 +878,46 @@ pfm_context_alloc(void)
878 ctx = kzalloc(sizeof(pfm_context_t), GFP_KERNEL); 878 ctx = kzalloc(sizeof(pfm_context_t), GFP_KERNEL);
879 if (ctx) { 879 if (ctx) {
880 DPRINT(("alloc ctx @%p\n", ctx)); 880 DPRINT(("alloc ctx @%p\n", ctx));
881
882 /*
883 * init context protection lock
884 */
885 spin_lock_init(&ctx->ctx_lock);
886
887 /*
888 * context is unloaded
889 */
890 ctx->ctx_state = PFM_CTX_UNLOADED;
891
892 /*
893 * initialization of context's flags
894 */
895 ctx->ctx_fl_block = (ctx_flags & PFM_FL_NOTIFY_BLOCK) ? 1 : 0;
896 ctx->ctx_fl_system = (ctx_flags & PFM_FL_SYSTEM_WIDE) ? 1: 0;
897 ctx->ctx_fl_no_msg = (ctx_flags & PFM_FL_OVFL_NO_MSG) ? 1: 0;
898 /*
899 * will move to set properties
900 * ctx->ctx_fl_excl_idle = (ctx_flags & PFM_FL_EXCL_IDLE) ? 1: 0;
901 */
902
903 /*
904 * init restart semaphore to locked
905 */
906 init_completion(&ctx->ctx_restart_done);
907
908 /*
909 * activation is used in SMP only
910 */
911 ctx->ctx_last_activation = PFM_INVALID_ACTIVATION;
912 SET_LAST_CPU(ctx, -1);
913
914 /*
915 * initialize notification message queue
916 */
917 ctx->ctx_msgq_head = ctx->ctx_msgq_tail = 0;
918 init_waitqueue_head(&ctx->ctx_msgq_wait);
919 init_waitqueue_head(&ctx->ctx_zombieq);
920
881 } 921 }
882 return ctx; 922 return ctx;
883} 923}
@@ -2165,28 +2205,21 @@ static struct dentry_operations pfmfs_dentry_operations = {
2165}; 2205};
2166 2206
2167 2207
2168static int 2208static struct file *
2169pfm_alloc_fd(struct file **cfile) 2209pfm_alloc_file(pfm_context_t *ctx)
2170{ 2210{
2171 int fd, ret = 0; 2211 struct file *file;
2172 struct file *file = NULL; 2212 struct inode *inode;
2173 struct inode * inode; 2213 struct dentry *dentry;
2174 char name[32]; 2214 char name[32];
2175 struct qstr this; 2215 struct qstr this;
2176 2216
2177 fd = get_unused_fd();
2178 if (fd < 0) return -ENFILE;
2179
2180 ret = -ENFILE;
2181
2182 file = get_empty_filp();
2183 if (!file) goto out;
2184
2185 /* 2217 /*
2186 * allocate a new inode 2218 * allocate a new inode
2187 */ 2219 */
2188 inode = new_inode(pfmfs_mnt->mnt_sb); 2220 inode = new_inode(pfmfs_mnt->mnt_sb);
2189 if (!inode) goto out; 2221 if (!inode)
2222 return ERR_PTR(-ENOMEM);
2190 2223
2191 DPRINT(("new inode ino=%ld @%p\n", inode->i_ino, inode)); 2224 DPRINT(("new inode ino=%ld @%p\n", inode->i_ino, inode));
2192 2225
@@ -2199,59 +2232,28 @@ pfm_alloc_fd(struct file **cfile)
2199 this.len = strlen(name); 2232 this.len = strlen(name);
2200 this.hash = inode->i_ino; 2233 this.hash = inode->i_ino;
2201 2234
2202 ret = -ENOMEM;
2203
2204 /* 2235 /*
2205 * allocate a new dcache entry 2236 * allocate a new dcache entry
2206 */ 2237 */
2207 file->f_path.dentry = d_alloc(pfmfs_mnt->mnt_sb->s_root, &this); 2238 dentry = d_alloc(pfmfs_mnt->mnt_sb->s_root, &this);
2208 if (!file->f_path.dentry) goto out; 2239 if (!dentry) {
2240 iput(inode);
2241 return ERR_PTR(-ENOMEM);
2242 }
2209 2243
2210 file->f_path.dentry->d_op = &pfmfs_dentry_operations; 2244 dentry->d_op = &pfmfs_dentry_operations;
2245 d_add(dentry, inode);
2211 2246
2212 d_add(file->f_path.dentry, inode); 2247 file = alloc_file(pfmfs_mnt, dentry, FMODE_READ, &pfm_file_ops);
2213 file->f_path.mnt = mntget(pfmfs_mnt); 2248 if (!file) {
2214 file->f_mapping = inode->i_mapping; 2249 dput(dentry);
2250 return ERR_PTR(-ENFILE);
2251 }
2215 2252
2216 file->f_op = &pfm_file_ops;
2217 file->f_mode = FMODE_READ;
2218 file->f_flags = O_RDONLY; 2253 file->f_flags = O_RDONLY;
2219 file->f_pos = 0; 2254 file->private_data = ctx;
2220
2221 /*
2222 * may have to delay until context is attached?
2223 */
2224 fd_install(fd, file);
2225
2226 /*
2227 * the file structure we will use
2228 */
2229 *cfile = file;
2230
2231 return fd;
2232out:
2233 if (file) put_filp(file);
2234 put_unused_fd(fd);
2235 return ret;
2236}
2237
2238static void
2239pfm_free_fd(int fd, struct file *file)
2240{
2241 struct files_struct *files = current->files;
2242 struct fdtable *fdt;
2243 2255
2244 /* 2256 return file;
2245 * there ie no fd_uninstall(), so we do it here
2246 */
2247 spin_lock(&files->file_lock);
2248 fdt = files_fdtable(files);
2249 rcu_assign_pointer(fdt->fd[fd], NULL);
2250 spin_unlock(&files->file_lock);
2251
2252 if (file)
2253 put_filp(file);
2254 put_unused_fd(fd);
2255} 2257}
2256 2258
2257static int 2259static int
@@ -2475,6 +2477,7 @@ pfm_setup_buffer_fmt(struct task_struct *task, struct file *filp, pfm_context_t
2475 2477
2476 /* link buffer format and context */ 2478 /* link buffer format and context */
2477 ctx->ctx_buf_fmt = fmt; 2479 ctx->ctx_buf_fmt = fmt;
2480 ctx->ctx_fl_is_sampling = 1; /* assume record() is defined */
2478 2481
2479 /* 2482 /*
2480 * check if buffer format wants to use perfmon buffer allocation/mapping service 2483 * check if buffer format wants to use perfmon buffer allocation/mapping service
@@ -2669,78 +2672,45 @@ pfm_context_create(pfm_context_t *ctx, void *arg, int count, struct pt_regs *reg
2669{ 2672{
2670 pfarg_context_t *req = (pfarg_context_t *)arg; 2673 pfarg_context_t *req = (pfarg_context_t *)arg;
2671 struct file *filp; 2674 struct file *filp;
2675 struct path path;
2672 int ctx_flags; 2676 int ctx_flags;
2677 int fd;
2673 int ret; 2678 int ret;
2674 2679
2675 /* let's check the arguments first */ 2680 /* let's check the arguments first */
2676 ret = pfarg_is_sane(current, req); 2681 ret = pfarg_is_sane(current, req);
2677 if (ret < 0) return ret; 2682 if (ret < 0)
2683 return ret;
2678 2684
2679 ctx_flags = req->ctx_flags; 2685 ctx_flags = req->ctx_flags;
2680 2686
2681 ret = -ENOMEM; 2687 ret = -ENOMEM;
2682 2688
2683 ctx = pfm_context_alloc(); 2689 fd = get_unused_fd();
2684 if (!ctx) goto error; 2690 if (fd < 0)
2691 return fd;
2685 2692
2686 ret = pfm_alloc_fd(&filp); 2693 ctx = pfm_context_alloc(ctx_flags);
2687 if (ret < 0) goto error_file; 2694 if (!ctx)
2695 goto error;
2688 2696
2689 req->ctx_fd = ctx->ctx_fd = ret; 2697 filp = pfm_alloc_file(ctx);
2698 if (IS_ERR(filp)) {
2699 ret = PTR_ERR(filp);
2700 goto error_file;
2701 }
2690 2702
2691 /* 2703 req->ctx_fd = ctx->ctx_fd = fd;
2692 * attach context to file
2693 */
2694 filp->private_data = ctx;
2695 2704
2696 /* 2705 /*
2697 * does the user want to sample? 2706 * does the user want to sample?
2698 */ 2707 */
2699 if (pfm_uuid_cmp(req->ctx_smpl_buf_id, pfm_null_uuid)) { 2708 if (pfm_uuid_cmp(req->ctx_smpl_buf_id, pfm_null_uuid)) {
2700 ret = pfm_setup_buffer_fmt(current, filp, ctx, ctx_flags, 0, req); 2709 ret = pfm_setup_buffer_fmt(current, filp, ctx, ctx_flags, 0, req);
2701 if (ret) goto buffer_error; 2710 if (ret)
2711 goto buffer_error;
2702 } 2712 }
2703 2713
2704 /*
2705 * init context protection lock
2706 */
2707 spin_lock_init(&ctx->ctx_lock);
2708
2709 /*
2710 * context is unloaded
2711 */
2712 ctx->ctx_state = PFM_CTX_UNLOADED;
2713
2714 /*
2715 * initialization of context's flags
2716 */
2717 ctx->ctx_fl_block = (ctx_flags & PFM_FL_NOTIFY_BLOCK) ? 1 : 0;
2718 ctx->ctx_fl_system = (ctx_flags & PFM_FL_SYSTEM_WIDE) ? 1: 0;
2719 ctx->ctx_fl_is_sampling = ctx->ctx_buf_fmt ? 1 : 0; /* assume record() is defined */
2720 ctx->ctx_fl_no_msg = (ctx_flags & PFM_FL_OVFL_NO_MSG) ? 1: 0;
2721 /*
2722 * will move to set properties
2723 * ctx->ctx_fl_excl_idle = (ctx_flags & PFM_FL_EXCL_IDLE) ? 1: 0;
2724 */
2725
2726 /*
2727 * init restart semaphore to locked
2728 */
2729 init_completion(&ctx->ctx_restart_done);
2730
2731 /*
2732 * activation is used in SMP only
2733 */
2734 ctx->ctx_last_activation = PFM_INVALID_ACTIVATION;
2735 SET_LAST_CPU(ctx, -1);
2736
2737 /*
2738 * initialize notification message queue
2739 */
2740 ctx->ctx_msgq_head = ctx->ctx_msgq_tail = 0;
2741 init_waitqueue_head(&ctx->ctx_msgq_wait);
2742 init_waitqueue_head(&ctx->ctx_zombieq);
2743
2744 DPRINT(("ctx=%p flags=0x%x system=%d notify_block=%d excl_idle=%d no_msg=%d ctx_fd=%d \n", 2714 DPRINT(("ctx=%p flags=0x%x system=%d notify_block=%d excl_idle=%d no_msg=%d ctx_fd=%d \n",
2745 ctx, 2715 ctx,
2746 ctx_flags, 2716 ctx_flags,
@@ -2755,10 +2725,14 @@ pfm_context_create(pfm_context_t *ctx, void *arg, int count, struct pt_regs *reg
2755 */ 2725 */
2756 pfm_reset_pmu_state(ctx); 2726 pfm_reset_pmu_state(ctx);
2757 2727
2728 fd_install(fd, filp);
2729
2758 return 0; 2730 return 0;
2759 2731
2760buffer_error: 2732buffer_error:
2761 pfm_free_fd(ctx->ctx_fd, filp); 2733 path = filp->f_path;
2734 put_filp(filp);
2735 path_put(&path);
2762 2736
2763 if (ctx->ctx_buf_fmt) { 2737 if (ctx->ctx_buf_fmt) {
2764 pfm_buf_fmt_exit(ctx->ctx_buf_fmt, current, NULL, regs); 2738 pfm_buf_fmt_exit(ctx->ctx_buf_fmt, current, NULL, regs);
@@ -2767,6 +2741,7 @@ error_file:
2767 pfm_context_free(ctx); 2741 pfm_context_free(ctx);
2768 2742
2769error: 2743error:
2744 put_unused_fd(fd);
2770 return ret; 2745 return ret;
2771} 2746}
2772 2747
diff --git a/arch/ia64/kernel/process.c b/arch/ia64/kernel/process.c
index a5ea817cbcbf..58dcfac5ea88 100644
--- a/arch/ia64/kernel/process.c
+++ b/arch/ia64/kernel/process.c
@@ -183,7 +183,7 @@ do_notify_resume_user (sigset_t *unused, struct sigscratch *scr, long in_syscall
183#endif 183#endif
184 184
185 /* deal with pending signal delivery */ 185 /* deal with pending signal delivery */
186 if (test_thread_flag(TIF_SIGPENDING)||test_thread_flag(TIF_RESTORE_SIGMASK)) 186 if (test_thread_flag(TIF_SIGPENDING))
187 ia64_do_signal(scr, in_syscall); 187 ia64_do_signal(scr, in_syscall);
188 188
189 /* copy user rbs to kernel rbs */ 189 /* copy user rbs to kernel rbs */
diff --git a/arch/ia64/kernel/signal.c b/arch/ia64/kernel/signal.c
index 5740296c35af..19c5a78636fc 100644
--- a/arch/ia64/kernel/signal.c
+++ b/arch/ia64/kernel/signal.c
@@ -464,7 +464,7 @@ ia64_do_signal (struct sigscratch *scr, long in_syscall)
464 if (!user_mode(&scr->pt)) 464 if (!user_mode(&scr->pt))
465 return; 465 return;
466 466
467 if (test_thread_flag(TIF_RESTORE_SIGMASK)) 467 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
468 oldset = &current->saved_sigmask; 468 oldset = &current->saved_sigmask;
469 else 469 else
470 oldset = &current->blocked; 470 oldset = &current->blocked;
@@ -530,12 +530,13 @@ ia64_do_signal (struct sigscratch *scr, long in_syscall)
530 * continue to iterate in this loop so we can deliver the SIGSEGV... 530 * continue to iterate in this loop so we can deliver the SIGSEGV...
531 */ 531 */
532 if (handle_signal(signr, &ka, &info, oldset, scr)) { 532 if (handle_signal(signr, &ka, &info, oldset, scr)) {
533 /* a signal was successfully delivered; the saved 533 /*
534 * A signal was successfully delivered; the saved
534 * sigmask will have been stored in the signal frame, 535 * sigmask will have been stored in the signal frame,
535 * and will be restored by sigreturn, so we can simply 536 * and will be restored by sigreturn, so we can simply
536 * clear the TIF_RESTORE_SIGMASK flag */ 537 * clear the TS_RESTORE_SIGMASK flag.
537 if (test_thread_flag(TIF_RESTORE_SIGMASK)) 538 */
538 clear_thread_flag(TIF_RESTORE_SIGMASK); 539 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
539 return; 540 return;
540 } 541 }
541 } 542 }
@@ -566,8 +567,8 @@ ia64_do_signal (struct sigscratch *scr, long in_syscall)
566 567
567 /* if there's no signal to deliver, we just put the saved sigmask 568 /* if there's no signal to deliver, we just put the saved sigmask
568 * back */ 569 * back */
569 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 570 if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
570 clear_thread_flag(TIF_RESTORE_SIGMASK); 571 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
571 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL); 572 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
572 } 573 }
573} 574}
diff --git a/arch/ia64/kernel/smp.c b/arch/ia64/kernel/smp.c
index 9a9d4c489330..983296f1c813 100644
--- a/arch/ia64/kernel/smp.c
+++ b/arch/ia64/kernel/smp.c
@@ -98,8 +98,33 @@ unlock_ipi_calllock(void)
98 spin_unlock_irq(&call_lock); 98 spin_unlock_irq(&call_lock);
99} 99}
100 100
101static inline void
102handle_call_data(void)
103{
104 struct call_data_struct *data;
105 void (*func)(void *info);
106 void *info;
107 int wait;
108
109 /* release the 'pointer lock' */
110 data = (struct call_data_struct *)call_data;
111 func = data->func;
112 info = data->info;
113 wait = data->wait;
114
115 mb();
116 atomic_inc(&data->started);
117 /* At this point the structure may be gone unless wait is true. */
118 (*func)(info);
119
120 /* Notify the sending CPU that the task is done. */
121 mb();
122 if (wait)
123 atomic_inc(&data->finished);
124}
125
101static void 126static void
102stop_this_cpu (void) 127stop_this_cpu(void)
103{ 128{
104 /* 129 /*
105 * Remove this CPU: 130 * Remove this CPU:
@@ -138,44 +163,21 @@ handle_IPI (int irq, void *dev_id)
138 ops &= ~(1 << which); 163 ops &= ~(1 << which);
139 164
140 switch (which) { 165 switch (which) {
141 case IPI_CALL_FUNC: 166 case IPI_CALL_FUNC:
142 { 167 handle_call_data();
143 struct call_data_struct *data; 168 break;
144 void (*func)(void *info); 169
145 void *info; 170 case IPI_CPU_STOP:
146 int wait;
147
148 /* release the 'pointer lock' */
149 data = (struct call_data_struct *) call_data;
150 func = data->func;
151 info = data->info;
152 wait = data->wait;
153
154 mb();
155 atomic_inc(&data->started);
156 /*
157 * At this point the structure may be gone unless
158 * wait is true.
159 */
160 (*func)(info);
161
162 /* Notify the sending CPU that the task is done. */
163 mb();
164 if (wait)
165 atomic_inc(&data->finished);
166 }
167 break;
168
169 case IPI_CPU_STOP:
170 stop_this_cpu(); 171 stop_this_cpu();
171 break; 172 break;
172#ifdef CONFIG_KEXEC 173#ifdef CONFIG_KEXEC
173 case IPI_KDUMP_CPU_STOP: 174 case IPI_KDUMP_CPU_STOP:
174 unw_init_running(kdump_cpu_freeze, NULL); 175 unw_init_running(kdump_cpu_freeze, NULL);
175 break; 176 break;
176#endif 177#endif
177 default: 178 default:
178 printk(KERN_CRIT "Unknown IPI on CPU %d: %lu\n", this_cpu, which); 179 printk(KERN_CRIT "Unknown IPI on CPU %d: %lu\n",
180 this_cpu, which);
179 break; 181 break;
180 } 182 }
181 } while (ops); 183 } while (ops);
diff --git a/arch/ia64/kernel/smpboot.c b/arch/ia64/kernel/smpboot.c
index 16483be18c0b..d7ad42b77d41 100644
--- a/arch/ia64/kernel/smpboot.c
+++ b/arch/ia64/kernel/smpboot.c
@@ -873,7 +873,8 @@ identify_siblings(struct cpuinfo_ia64 *c)
873 u16 pltid; 873 u16 pltid;
874 pal_logical_to_physical_t info; 874 pal_logical_to_physical_t info;
875 875
876 if ((status = ia64_pal_logical_to_phys(-1, &info)) != PAL_STATUS_SUCCESS) { 876 status = ia64_pal_logical_to_phys(-1, &info);
877 if (status != PAL_STATUS_SUCCESS) {
877 if (status != PAL_STATUS_UNIMPLEMENTED) { 878 if (status != PAL_STATUS_UNIMPLEMENTED) {
878 printk(KERN_ERR 879 printk(KERN_ERR
879 "ia64_pal_logical_to_phys failed with %ld\n", 880 "ia64_pal_logical_to_phys failed with %ld\n",
@@ -885,8 +886,13 @@ identify_siblings(struct cpuinfo_ia64 *c)
885 info.overview_cpp = 1; 886 info.overview_cpp = 1;
886 info.overview_tpc = 1; 887 info.overview_tpc = 1;
887 } 888 }
888 if ((status = ia64_sal_physical_id_info(&pltid)) != PAL_STATUS_SUCCESS) { 889
889 printk(KERN_ERR "ia64_sal_pltid failed with %ld\n", status); 890 status = ia64_sal_physical_id_info(&pltid);
891 if (status != PAL_STATUS_SUCCESS) {
892 if (status != PAL_STATUS_UNIMPLEMENTED)
893 printk(KERN_ERR
894 "ia64_sal_pltid failed with %ld\n",
895 status);
890 return; 896 return;
891 } 897 }
892 898
diff --git a/arch/ia64/kernel/time.c b/arch/ia64/kernel/time.c
index 48e15a51782f..8c73643f2d66 100644
--- a/arch/ia64/kernel/time.c
+++ b/arch/ia64/kernel/time.c
@@ -379,11 +379,6 @@ static struct irqaction timer_irqaction = {
379 .name = "timer" 379 .name = "timer"
380}; 380};
381 381
382void __devinit ia64_disable_timer(void)
383{
384 ia64_set_itv(1 << 16);
385}
386
387void __init 382void __init
388time_init (void) 383time_init (void)
389{ 384{
diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
index a2484fc1a06c..26228e2d01ae 100644
--- a/arch/ia64/kernel/topology.c
+++ b/arch/ia64/kernel/topology.c
@@ -27,9 +27,20 @@
27 27
28static struct ia64_cpu *sysfs_cpus; 28static struct ia64_cpu *sysfs_cpus;
29 29
30int arch_register_cpu(int num) 30void arch_fix_phys_package_id(int num, u32 slot)
31{ 31{
32#if defined (CONFIG_ACPI) && defined (CONFIG_HOTPLUG_CPU) 32#ifdef CONFIG_SMP
33 if (cpu_data(num)->socket_id == -1)
34 cpu_data(num)->socket_id = slot;
35#endif
36}
37EXPORT_SYMBOL_GPL(arch_fix_phys_package_id);
38
39
40#ifdef CONFIG_HOTPLUG_CPU
41int __ref arch_register_cpu(int num)
42{
43#ifdef CONFIG_ACPI
33 /* 44 /*
34 * If CPEI can be re-targetted or if this is not 45 * If CPEI can be re-targetted or if this is not
35 * CPEI target, then it is hotpluggable 46 * CPEI target, then it is hotpluggable
@@ -38,19 +49,21 @@ int arch_register_cpu(int num)
38 sysfs_cpus[num].cpu.hotpluggable = 1; 49 sysfs_cpus[num].cpu.hotpluggable = 1;
39 map_cpu_to_node(num, node_cpuid[num].nid); 50 map_cpu_to_node(num, node_cpuid[num].nid);
40#endif 51#endif
41
42 return register_cpu(&sysfs_cpus[num].cpu, num); 52 return register_cpu(&sysfs_cpus[num].cpu, num);
43} 53}
44 54EXPORT_SYMBOL(arch_register_cpu);
45#ifdef CONFIG_HOTPLUG_CPU
46 55
47void arch_unregister_cpu(int num) 56void arch_unregister_cpu(int num)
48{ 57{
49 unregister_cpu(&sysfs_cpus[num].cpu); 58 unregister_cpu(&sysfs_cpus[num].cpu);
50 unmap_cpu_from_node(num, cpu_to_node(num)); 59 unmap_cpu_from_node(num, cpu_to_node(num));
51} 60}
52EXPORT_SYMBOL(arch_register_cpu);
53EXPORT_SYMBOL(arch_unregister_cpu); 61EXPORT_SYMBOL(arch_unregister_cpu);
62#else
63static int __init arch_register_cpu(int num)
64{
65 return register_cpu(&sysfs_cpus[num].cpu, num);
66}
54#endif /*CONFIG_HOTPLUG_CPU*/ 67#endif /*CONFIG_HOTPLUG_CPU*/
55 68
56 69
diff --git a/arch/ia64/kernel/uncached.c b/arch/ia64/kernel/uncached.c
index 2a90c32024f4..e77995a6e3ed 100644
--- a/arch/ia64/kernel/uncached.c
+++ b/arch/ia64/kernel/uncached.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2001-2006 Silicon Graphics, Inc. All rights reserved. 2 * Copyright (C) 2001-2008 Silicon Graphics, Inc. All rights reserved.
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify it 4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License 5 * under the terms of version 2 of the GNU General Public License
@@ -177,12 +177,13 @@ failed:
177 * uncached_alloc_page 177 * uncached_alloc_page
178 * 178 *
179 * @starting_nid: node id of node to start with, or -1 179 * @starting_nid: node id of node to start with, or -1
180 * @n_pages: number of contiguous pages to allocate
180 * 181 *
181 * Allocate 1 uncached page. Allocates on the requested node. If no 182 * Allocate the specified number of contiguous uncached pages on the
182 * uncached pages are available on the requested node, roundrobin starting 183 * the requested node. If not enough contiguous uncached pages are available
183 * with the next higher node. 184 * on the requested node, roundrobin starting with the next higher node.
184 */ 185 */
185unsigned long uncached_alloc_page(int starting_nid) 186unsigned long uncached_alloc_page(int starting_nid, int n_pages)
186{ 187{
187 unsigned long uc_addr; 188 unsigned long uc_addr;
188 struct uncached_pool *uc_pool; 189 struct uncached_pool *uc_pool;
@@ -202,7 +203,8 @@ unsigned long uncached_alloc_page(int starting_nid)
202 if (uc_pool->pool == NULL) 203 if (uc_pool->pool == NULL)
203 continue; 204 continue;
204 do { 205 do {
205 uc_addr = gen_pool_alloc(uc_pool->pool, PAGE_SIZE); 206 uc_addr = gen_pool_alloc(uc_pool->pool,
207 n_pages * PAGE_SIZE);
206 if (uc_addr != 0) 208 if (uc_addr != 0)
207 return uc_addr; 209 return uc_addr;
208 } while (uncached_add_chunk(uc_pool, nid) == 0); 210 } while (uncached_add_chunk(uc_pool, nid) == 0);
@@ -217,11 +219,12 @@ EXPORT_SYMBOL(uncached_alloc_page);
217/* 219/*
218 * uncached_free_page 220 * uncached_free_page
219 * 221 *
220 * @uc_addr: uncached address of page to free 222 * @uc_addr: uncached address of first page to free
223 * @n_pages: number of contiguous pages to free
221 * 224 *
222 * Free a single uncached page. 225 * Free the specified number of uncached pages.
223 */ 226 */
224void uncached_free_page(unsigned long uc_addr) 227void uncached_free_page(unsigned long uc_addr, int n_pages)
225{ 228{
226 int nid = paddr_to_nid(uc_addr - __IA64_UNCACHED_OFFSET); 229 int nid = paddr_to_nid(uc_addr - __IA64_UNCACHED_OFFSET);
227 struct gen_pool *pool = uncached_pools[nid].pool; 230 struct gen_pool *pool = uncached_pools[nid].pool;
@@ -232,7 +235,7 @@ void uncached_free_page(unsigned long uc_addr)
232 if ((uc_addr & (0XFUL << 60)) != __IA64_UNCACHED_OFFSET) 235 if ((uc_addr & (0XFUL << 60)) != __IA64_UNCACHED_OFFSET)
233 panic("uncached_free_page invalid address %lx\n", uc_addr); 236 panic("uncached_free_page invalid address %lx\n", uc_addr);
234 237
235 gen_pool_free(pool, uc_addr, PAGE_SIZE); 238 gen_pool_free(pool, uc_addr, n_pages * PAGE_SIZE);
236} 239}
237EXPORT_SYMBOL(uncached_free_page); 240EXPORT_SYMBOL(uncached_free_page);
238 241
diff --git a/arch/ia64/kvm/kvm-ia64.c b/arch/ia64/kvm/kvm-ia64.c
index 6df073240135..318b81100623 100644
--- a/arch/ia64/kvm/kvm-ia64.c
+++ b/arch/ia64/kvm/kvm-ia64.c
@@ -1,4 +1,3 @@
1
2/* 1/*
3 * kvm_ia64.c: Basic KVM suppport On Itanium series processors 2 * kvm_ia64.c: Basic KVM suppport On Itanium series processors
4 * 3 *
@@ -431,7 +430,7 @@ int kvm_emulate_halt(struct kvm_vcpu *vcpu)
431 if (itc_diff < 0) 430 if (itc_diff < 0)
432 itc_diff = -itc_diff; 431 itc_diff = -itc_diff;
433 432
434 expires = div64_64(itc_diff, cyc_per_usec); 433 expires = div64_u64(itc_diff, cyc_per_usec);
435 kt = ktime_set(0, 1000 * expires); 434 kt = ktime_set(0, 1000 * expires);
436 vcpu->arch.ht_active = 1; 435 vcpu->arch.ht_active = 1;
437 hrtimer_start(p_ht, kt, HRTIMER_MODE_ABS); 436 hrtimer_start(p_ht, kt, HRTIMER_MODE_ABS);
diff --git a/arch/ia64/mm/tlb.c b/arch/ia64/mm/tlb.c
index d52ec4e83409..8caf42471f0d 100644
--- a/arch/ia64/mm/tlb.c
+++ b/arch/ia64/mm/tlb.c
@@ -168,7 +168,10 @@ setup_ptcg_sem(int max_purges, int nptcg_from)
168 static int firstcpu = 1; 168 static int firstcpu = 1;
169 169
170 if (toolatetochangeptcgsem) { 170 if (toolatetochangeptcgsem) {
171 BUG_ON(max_purges < nptcg); 171 if (nptcg_from == NPTCG_FROM_PAL && max_purges == 0)
172 BUG_ON(1 < nptcg);
173 else
174 BUG_ON(max_purges < nptcg);
172 return; 175 return;
173 } 176 }
174 177
diff --git a/arch/m32r/Makefile b/arch/m32r/Makefile
index 4072a07ebf8e..469766b24e22 100644
--- a/arch/m32r/Makefile
+++ b/arch/m32r/Makefile
@@ -5,6 +5,8 @@
5# architecture-specific flags and dependencies. 5# architecture-specific flags and dependencies.
6# 6#
7 7
8KBUILD_DEFCONFIG := m32700ut.smp_defconfig
9
8LDFLAGS := 10LDFLAGS :=
9OBJCOPYFLAGS := -O binary -R .note -R .comment -S 11OBJCOPYFLAGS := -O binary -R .note -R .comment -S
10LDFLAGS_vmlinux := 12LDFLAGS_vmlinux :=
diff --git a/arch/m32r/defconfig b/arch/m32r/defconfig
deleted file mode 100644
index af3b98179113..000000000000
--- a/arch/m32r/defconfig
+++ /dev/null
@@ -1,863 +0,0 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.23-rc1
4# Wed Aug 1 17:22:35 2007
5#
6CONFIG_M32R=y
7CONFIG_GENERIC_ISA_DMA=y
8CONFIG_ZONE_DMA=y
9CONFIG_GENERIC_HARDIRQS=y
10CONFIG_GENERIC_IRQ_PROBE=y
11CONFIG_NO_IOPORT=y
12CONFIG_NO_DMA=y
13CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
14
15#
16# Code maturity level options
17#
18CONFIG_EXPERIMENTAL=y
19CONFIG_LOCK_KERNEL=y
20CONFIG_INIT_ENV_ARG_LIMIT=32
21
22#
23# General setup
24#
25CONFIG_LOCALVERSION=""
26CONFIG_LOCALVERSION_AUTO=y
27CONFIG_SWAP=y
28CONFIG_SYSVIPC=y
29CONFIG_SYSVIPC_SYSCTL=y
30# CONFIG_POSIX_MQUEUE is not set
31CONFIG_BSD_PROCESS_ACCT=y
32# CONFIG_BSD_PROCESS_ACCT_V3 is not set
33# CONFIG_TASKSTATS is not set
34# CONFIG_USER_NS is not set
35# CONFIG_AUDIT is not set
36CONFIG_IKCONFIG=y
37CONFIG_IKCONFIG_PROC=y
38CONFIG_LOG_BUF_SHIFT=15
39# CONFIG_CPUSETS is not set
40CONFIG_SYSFS_DEPRECATED=y
41# CONFIG_RELAY is not set
42# CONFIG_BLK_DEV_INITRD is not set
43# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
44CONFIG_SYSCTL=y
45CONFIG_EMBEDDED=y
46CONFIG_SYSCTL_SYSCALL=y
47# CONFIG_KALLSYMS is not set
48CONFIG_HOTPLUG=y
49CONFIG_PRINTK=y
50CONFIG_BUG=y
51CONFIG_ELF_CORE=y
52CONFIG_BASE_FULL=y
53# CONFIG_FUTEX is not set
54CONFIG_ANON_INODES=y
55# CONFIG_EPOLL is not set
56CONFIG_SIGNALFD=y
57CONFIG_TIMERFD=y
58CONFIG_EVENTFD=y
59CONFIG_SHMEM=y
60CONFIG_VM_EVENT_COUNTERS=y
61CONFIG_SLAB=y
62# CONFIG_SLUB is not set
63# CONFIG_SLOB is not set
64# CONFIG_TINY_SHMEM is not set
65CONFIG_BASE_SMALL=0
66CONFIG_MODULES=y
67CONFIG_MODULE_UNLOAD=y
68# CONFIG_MODULE_FORCE_UNLOAD is not set
69# CONFIG_MODVERSIONS is not set
70# CONFIG_MODULE_SRCVERSION_ALL is not set
71CONFIG_KMOD=y
72CONFIG_STOP_MACHINE=y
73CONFIG_BLOCK=y
74# CONFIG_LBD is not set
75# CONFIG_BLK_DEV_IO_TRACE is not set
76# CONFIG_LSF is not set
77# CONFIG_BLK_DEV_BSG is not set
78
79#
80# IO Schedulers
81#
82CONFIG_IOSCHED_NOOP=y
83# CONFIG_IOSCHED_AS is not set
84CONFIG_IOSCHED_DEADLINE=y
85CONFIG_IOSCHED_CFQ=y
86# CONFIG_DEFAULT_AS is not set
87# CONFIG_DEFAULT_DEADLINE is not set
88CONFIG_DEFAULT_CFQ=y
89# CONFIG_DEFAULT_NOOP is not set
90CONFIG_DEFAULT_IOSCHED="cfq"
91
92#
93# Processor type and features
94#
95# CONFIG_PLAT_MAPPI is not set
96# CONFIG_PLAT_USRV is not set
97CONFIG_PLAT_M32700UT=y
98# CONFIG_PLAT_OPSPUT is not set
99# CONFIG_PLAT_OAKS32R is not set
100# CONFIG_PLAT_MAPPI2 is not set
101# CONFIG_PLAT_MAPPI3 is not set
102# CONFIG_PLAT_M32104UT is not set
103CONFIG_CHIP_M32700=y
104# CONFIG_CHIP_M32102 is not set
105# CONFIG_CHIP_M32104 is not set
106# CONFIG_CHIP_VDEC2 is not set
107# CONFIG_CHIP_OPSP is not set
108CONFIG_MMU=y
109CONFIG_TLB_ENTRIES=32
110CONFIG_ISA_M32R2=y
111CONFIG_ISA_DSP_LEVEL2=y
112CONFIG_ISA_DUAL_ISSUE=y
113CONFIG_BUS_CLOCK=50000000
114CONFIG_TIMER_DIVIDE=128
115# CONFIG_CPU_LITTLE_ENDIAN is not set
116CONFIG_MEMORY_START=0x08000000
117CONFIG_MEMORY_SIZE=0x01000000
118CONFIG_NOHIGHMEM=y
119CONFIG_ARCH_DISCONTIGMEM_ENABLE=y
120CONFIG_SELECT_MEMORY_MODEL=y
121# CONFIG_FLATMEM_MANUAL is not set
122CONFIG_DISCONTIGMEM_MANUAL=y
123# CONFIG_SPARSEMEM_MANUAL is not set
124CONFIG_DISCONTIGMEM=y
125CONFIG_FLAT_NODE_MEM_MAP=y
126CONFIG_NEED_MULTIPLE_NODES=y
127# CONFIG_SPARSEMEM_STATIC is not set
128CONFIG_SPLIT_PTLOCK_CPUS=4
129# CONFIG_RESOURCES_64BIT is not set
130CONFIG_ZONE_DMA_FLAG=1
131CONFIG_BOUNCE=y
132CONFIG_VIRT_TO_BUS=y
133CONFIG_IRAM_START=0x00f00000
134CONFIG_IRAM_SIZE=0x00080000
135CONFIG_RWSEM_GENERIC_SPINLOCK=y
136# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
137# CONFIG_ARCH_HAS_ILOG2_U32 is not set
138# CONFIG_ARCH_HAS_ILOG2_U64 is not set
139CONFIG_GENERIC_FIND_NEXT_BIT=y
140CONFIG_GENERIC_HWEIGHT=y
141CONFIG_GENERIC_CALIBRATE_DELAY=y
142CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
143CONFIG_PREEMPT=y
144CONFIG_SMP=y
145# CONFIG_CHIP_M32700_TS1 is not set
146CONFIG_NR_CPUS=2
147CONFIG_NODES_SHIFT=1
148
149#
150# Bus options (PCI, PCMCIA, EISA, MCA, ISA)
151#
152# CONFIG_ARCH_SUPPORTS_MSI is not set
153# CONFIG_ISA is not set
154
155#
156# PCCARD (PCMCIA/CardBus) support
157#
158# CONFIG_PCCARD is not set
159
160#
161# Executable file formats
162#
163CONFIG_BINFMT_ELF=y
164# CONFIG_BINFMT_MISC is not set
165
166#
167# Networking
168#
169CONFIG_NET=y
170
171#
172# Networking options
173#
174CONFIG_PACKET=y
175# CONFIG_PACKET_MMAP is not set
176CONFIG_UNIX=y
177CONFIG_XFRM=y
178# CONFIG_XFRM_USER is not set
179# CONFIG_XFRM_SUB_POLICY is not set
180# CONFIG_XFRM_MIGRATE is not set
181# CONFIG_NET_KEY is not set
182CONFIG_INET=y
183# CONFIG_IP_MULTICAST is not set
184# CONFIG_IP_ADVANCED_ROUTER is not set
185CONFIG_IP_FIB_HASH=y
186CONFIG_IP_PNP=y
187CONFIG_IP_PNP_DHCP=y
188# CONFIG_IP_PNP_BOOTP is not set
189# CONFIG_IP_PNP_RARP is not set
190# CONFIG_NET_IPIP is not set
191# CONFIG_NET_IPGRE is not set
192# CONFIG_ARPD is not set
193# CONFIG_SYN_COOKIES is not set
194# CONFIG_INET_AH is not set
195# CONFIG_INET_ESP is not set
196# CONFIG_INET_IPCOMP is not set
197# CONFIG_INET_XFRM_TUNNEL is not set
198# CONFIG_INET_TUNNEL is not set
199CONFIG_INET_XFRM_MODE_TRANSPORT=y
200CONFIG_INET_XFRM_MODE_TUNNEL=y
201CONFIG_INET_XFRM_MODE_BEET=y
202CONFIG_INET_DIAG=y
203CONFIG_INET_TCP_DIAG=y
204# CONFIG_TCP_CONG_ADVANCED is not set
205CONFIG_TCP_CONG_CUBIC=y
206CONFIG_DEFAULT_TCP_CONG="cubic"
207# CONFIG_TCP_MD5SIG is not set
208# CONFIG_IPV6 is not set
209# CONFIG_INET6_XFRM_TUNNEL is not set
210# CONFIG_INET6_TUNNEL is not set
211# CONFIG_NETWORK_SECMARK is not set
212# CONFIG_NETFILTER is not set
213# CONFIG_IP_DCCP is not set
214# CONFIG_IP_SCTP is not set
215# CONFIG_TIPC is not set
216# CONFIG_ATM is not set
217# CONFIG_BRIDGE is not set
218# CONFIG_VLAN_8021Q is not set
219# CONFIG_DECNET is not set
220# CONFIG_LLC2 is not set
221# CONFIG_IPX is not set
222# CONFIG_ATALK is not set
223# CONFIG_X25 is not set
224# CONFIG_LAPB is not set
225# CONFIG_ECONET is not set
226# CONFIG_WAN_ROUTER is not set
227
228#
229# QoS and/or fair queueing
230#
231# CONFIG_NET_SCHED is not set
232
233#
234# Network testing
235#
236# CONFIG_NET_PKTGEN is not set
237# CONFIG_HAMRADIO is not set
238# CONFIG_IRDA is not set
239# CONFIG_BT is not set
240# CONFIG_AF_RXRPC is not set
241
242#
243# Wireless
244#
245# CONFIG_CFG80211 is not set
246# CONFIG_WIRELESS_EXT is not set
247# CONFIG_MAC80211 is not set
248# CONFIG_IEEE80211 is not set
249# CONFIG_RFKILL is not set
250# CONFIG_NET_9P is not set
251
252#
253# Device Drivers
254#
255
256#
257# Generic Driver Options
258#
259CONFIG_STANDALONE=y
260CONFIG_PREVENT_FIRMWARE_BUILD=y
261CONFIG_FW_LOADER=y
262# CONFIG_SYS_HYPERVISOR is not set
263# CONFIG_CONNECTOR is not set
264CONFIG_MTD=y
265# CONFIG_MTD_DEBUG is not set
266# CONFIG_MTD_CONCAT is not set
267CONFIG_MTD_PARTITIONS=y
268CONFIG_MTD_REDBOOT_PARTS=y
269CONFIG_MTD_REDBOOT_DIRECTORY_BLOCK=-1
270# CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED is not set
271# CONFIG_MTD_REDBOOT_PARTS_READONLY is not set
272# CONFIG_MTD_CMDLINE_PARTS is not set
273
274#
275# User Modules And Translation Layers
276#
277# CONFIG_MTD_CHAR is not set
278CONFIG_MTD_BLKDEVS=y
279CONFIG_MTD_BLOCK=y
280# CONFIG_FTL is not set
281# CONFIG_NFTL is not set
282# CONFIG_INFTL is not set
283# CONFIG_RFD_FTL is not set
284# CONFIG_SSFDC is not set
285
286#
287# RAM/ROM/Flash chip drivers
288#
289CONFIG_MTD_CFI=m
290CONFIG_MTD_JEDECPROBE=m
291CONFIG_MTD_GEN_PROBE=m
292CONFIG_MTD_CFI_ADV_OPTIONS=y
293# CONFIG_MTD_CFI_NOSWAP is not set
294CONFIG_MTD_CFI_BE_BYTE_SWAP=y
295# CONFIG_MTD_CFI_LE_BYTE_SWAP is not set
296CONFIG_MTD_CFI_GEOMETRY=y
297CONFIG_MTD_MAP_BANK_WIDTH_1=y
298CONFIG_MTD_MAP_BANK_WIDTH_2=y
299CONFIG_MTD_MAP_BANK_WIDTH_4=y
300# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
301# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
302# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
303CONFIG_MTD_CFI_I1=y
304# CONFIG_MTD_CFI_I2 is not set
305# CONFIG_MTD_CFI_I4 is not set
306# CONFIG_MTD_CFI_I8 is not set
307# CONFIG_MTD_OTP is not set
308# CONFIG_MTD_CFI_INTELEXT is not set
309CONFIG_MTD_CFI_AMDSTD=m
310# CONFIG_MTD_CFI_STAA is not set
311CONFIG_MTD_CFI_UTIL=m
312# CONFIG_MTD_RAM is not set
313# CONFIG_MTD_ROM is not set
314# CONFIG_MTD_ABSENT is not set
315
316#
317# Mapping drivers for chip access
318#
319# CONFIG_MTD_COMPLEX_MAPPINGS is not set
320# CONFIG_MTD_PHYSMAP is not set
321# CONFIG_MTD_PLATRAM is not set
322
323#
324# Self-contained MTD device drivers
325#
326# CONFIG_MTD_SLRAM is not set
327# CONFIG_MTD_PHRAM is not set
328# CONFIG_MTD_MTDRAM is not set
329# CONFIG_MTD_BLOCK2MTD is not set
330
331#
332# Disk-On-Chip Device Drivers
333#
334# CONFIG_MTD_DOC2000 is not set
335# CONFIG_MTD_DOC2001 is not set
336# CONFIG_MTD_DOC2001PLUS is not set
337# CONFIG_MTD_NAND is not set
338# CONFIG_MTD_ONENAND is not set
339
340#
341# UBI - Unsorted block images
342#
343# CONFIG_MTD_UBI is not set
344# CONFIG_PARPORT is not set
345CONFIG_BLK_DEV=y
346# CONFIG_BLK_DEV_COW_COMMON is not set
347CONFIG_BLK_DEV_LOOP=y
348# CONFIG_BLK_DEV_CRYPTOLOOP is not set
349CONFIG_BLK_DEV_NBD=y
350CONFIG_BLK_DEV_RAM=y
351CONFIG_BLK_DEV_RAM_COUNT=16
352CONFIG_BLK_DEV_RAM_SIZE=4096
353CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
354# CONFIG_CDROM_PKTCDVD is not set
355CONFIG_ATA_OVER_ETH=m
356CONFIG_MISC_DEVICES=y
357# CONFIG_EEPROM_93CX6 is not set
358CONFIG_IDE=y
359CONFIG_IDE_MAX_HWIFS=4
360CONFIG_BLK_DEV_IDE=y
361
362#
363# Please see Documentation/ide.txt for help/info on IDE drives
364#
365# CONFIG_BLK_DEV_IDE_SATA is not set
366CONFIG_BLK_DEV_IDEDISK=y
367# CONFIG_IDEDISK_MULTI_MODE is not set
368CONFIG_BLK_DEV_IDECD=m
369# CONFIG_BLK_DEV_IDETAPE is not set
370# CONFIG_BLK_DEV_IDEFLOPPY is not set
371# CONFIG_BLK_DEV_IDESCSI is not set
372# CONFIG_IDE_TASK_IOCTL is not set
373CONFIG_IDE_PROC_FS=y
374
375#
376# IDE chipset support/bugfixes
377#
378CONFIG_IDE_GENERIC=y
379# CONFIG_IDEPCI_PCIBUS_ORDER is not set
380# CONFIG_IDE_ARM is not set
381# CONFIG_BLK_DEV_IDEDMA is not set
382# CONFIG_BLK_DEV_HD is not set
383
384#
385# SCSI device support
386#
387# CONFIG_RAID_ATTRS is not set
388CONFIG_SCSI=m
389# CONFIG_SCSI_DMA is not set
390# CONFIG_SCSI_TGT is not set
391# CONFIG_SCSI_NETLINK is not set
392CONFIG_SCSI_PROC_FS=y
393
394#
395# SCSI support type (disk, tape, CD-ROM)
396#
397CONFIG_BLK_DEV_SD=m
398# CONFIG_CHR_DEV_ST is not set
399# CONFIG_CHR_DEV_OSST is not set
400CONFIG_BLK_DEV_SR=m
401# CONFIG_BLK_DEV_SR_VENDOR is not set
402CONFIG_CHR_DEV_SG=m
403# CONFIG_CHR_DEV_SCH is not set
404
405#
406# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
407#
408CONFIG_SCSI_MULTI_LUN=y
409# CONFIG_SCSI_CONSTANTS is not set
410# CONFIG_SCSI_LOGGING is not set
411# CONFIG_SCSI_SCAN_ASYNC is not set
412CONFIG_SCSI_WAIT_SCAN=m
413
414#
415# SCSI Transports
416#
417# CONFIG_SCSI_SPI_ATTRS is not set
418# CONFIG_SCSI_FC_ATTRS is not set
419# CONFIG_SCSI_ISCSI_ATTRS is not set
420# CONFIG_SCSI_SAS_LIBSAS is not set
421CONFIG_SCSI_LOWLEVEL=y
422# CONFIG_ISCSI_TCP is not set
423# CONFIG_SCSI_DEBUG is not set
424# CONFIG_MD is not set
425CONFIG_NETDEVICES=y
426# CONFIG_NETDEVICES_MULTIQUEUE is not set
427# CONFIG_DUMMY is not set
428# CONFIG_BONDING is not set
429# CONFIG_MACVLAN is not set
430# CONFIG_EQUALIZER is not set
431# CONFIG_TUN is not set
432# CONFIG_PHYLIB is not set
433CONFIG_NET_ETHERNET=y
434CONFIG_MII=y
435CONFIG_SMC91X=y
436# CONFIG_NE2000 is not set
437CONFIG_NETDEV_1000=y
438CONFIG_NETDEV_10000=y
439
440#
441# Wireless LAN
442#
443# CONFIG_WLAN_PRE80211 is not set
444# CONFIG_WLAN_80211 is not set
445# CONFIG_WAN is not set
446# CONFIG_PPP is not set
447# CONFIG_SLIP is not set
448# CONFIG_SHAPER is not set
449# CONFIG_NETCONSOLE is not set
450# CONFIG_NETPOLL is not set
451# CONFIG_NET_POLL_CONTROLLER is not set
452# CONFIG_ISDN is not set
453# CONFIG_PHONE is not set
454
455#
456# Input device support
457#
458CONFIG_INPUT=y
459# CONFIG_INPUT_FF_MEMLESS is not set
460# CONFIG_INPUT_POLLDEV is not set
461
462#
463# Userland interfaces
464#
465# CONFIG_INPUT_MOUSEDEV is not set
466# CONFIG_INPUT_JOYDEV is not set
467# CONFIG_INPUT_TSDEV is not set
468# CONFIG_INPUT_EVDEV is not set
469# CONFIG_INPUT_EVBUG is not set
470
471#
472# Input Device Drivers
473#
474# CONFIG_INPUT_KEYBOARD is not set
475# CONFIG_INPUT_MOUSE is not set
476# CONFIG_INPUT_JOYSTICK is not set
477# CONFIG_INPUT_TABLET is not set
478# CONFIG_INPUT_TOUCHSCREEN is not set
479# CONFIG_INPUT_MISC is not set
480
481#
482# Hardware I/O ports
483#
484CONFIG_SERIO=y
485# CONFIG_SERIO_I8042 is not set
486CONFIG_SERIO_SERPORT=y
487# CONFIG_SERIO_LIBPS2 is not set
488# CONFIG_SERIO_RAW is not set
489# CONFIG_GAMEPORT is not set
490
491#
492# Character devices
493#
494CONFIG_VT=y
495CONFIG_VT_CONSOLE=y
496CONFIG_HW_CONSOLE=y
497# CONFIG_VT_HW_CONSOLE_BINDING is not set
498# CONFIG_SERIAL_NONSTANDARD is not set
499
500#
501# Serial drivers
502#
503# CONFIG_SERIAL_8250 is not set
504
505#
506# Non-8250 serial port support
507#
508CONFIG_SERIAL_CORE=y
509CONFIG_SERIAL_CORE_CONSOLE=y
510CONFIG_SERIAL_M32R_SIO=y
511CONFIG_SERIAL_M32R_SIO_CONSOLE=y
512CONFIG_SERIAL_M32R_PLDSIO=y
513CONFIG_UNIX98_PTYS=y
514CONFIG_LEGACY_PTYS=y
515CONFIG_LEGACY_PTY_COUNT=256
516# CONFIG_IPMI_HANDLER is not set
517# CONFIG_WATCHDOG is not set
518CONFIG_HW_RANDOM=y
519# CONFIG_RTC is not set
520CONFIG_DS1302=y
521# CONFIG_R3964 is not set
522# CONFIG_RAW_DRIVER is not set
523# CONFIG_TCG_TPM is not set
524# CONFIG_I2C is not set
525
526#
527# SPI support
528#
529# CONFIG_SPI is not set
530# CONFIG_SPI_MASTER is not set
531# CONFIG_W1 is not set
532# CONFIG_POWER_SUPPLY is not set
533CONFIG_HWMON=y
534# CONFIG_HWMON_VID is not set
535# CONFIG_SENSORS_ABITUGURU is not set
536# CONFIG_SENSORS_ABITUGURU3 is not set
537# CONFIG_SENSORS_F71805F is not set
538# CONFIG_SENSORS_IT87 is not set
539# CONFIG_SENSORS_PC87360 is not set
540# CONFIG_SENSORS_PC87427 is not set
541# CONFIG_SENSORS_SMSC47M1 is not set
542# CONFIG_SENSORS_SMSC47B397 is not set
543# CONFIG_SENSORS_VT1211 is not set
544# CONFIG_SENSORS_W83627HF is not set
545# CONFIG_SENSORS_W83627EHF is not set
546# CONFIG_HWMON_DEBUG_CHIP is not set
547
548#
549# Multifunction device drivers
550#
551# CONFIG_MFD_SM501 is not set
552
553#
554# Multimedia devices
555#
556CONFIG_VIDEO_DEV=m
557CONFIG_VIDEO_V4L1=y
558CONFIG_VIDEO_V4L1_COMPAT=y
559CONFIG_VIDEO_V4L2=y
560CONFIG_VIDEO_CAPTURE_DRIVERS=y
561# CONFIG_VIDEO_ADV_DEBUG is not set
562CONFIG_VIDEO_HELPER_CHIPS_AUTO=y
563# CONFIG_VIDEO_CPIA is not set
564CONFIG_VIDEO_M32R_AR=m
565CONFIG_VIDEO_M32R_AR_M64278=m
566CONFIG_RADIO_ADAPTERS=y
567# CONFIG_DVB_CORE is not set
568CONFIG_DAB=y
569
570#
571# Graphics support
572#
573# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
574
575#
576# Display device support
577#
578# CONFIG_DISPLAY_SUPPORT is not set
579# CONFIG_VGASTATE is not set
580CONFIG_VIDEO_OUTPUT_CONTROL=m
581CONFIG_FB=y
582CONFIG_FIRMWARE_EDID=y
583# CONFIG_FB_DDC is not set
584CONFIG_FB_CFB_FILLRECT=y
585CONFIG_FB_CFB_COPYAREA=y
586CONFIG_FB_CFB_IMAGEBLIT=y
587# CONFIG_FB_SYS_FILLRECT is not set
588# CONFIG_FB_SYS_COPYAREA is not set
589# CONFIG_FB_SYS_IMAGEBLIT is not set
590# CONFIG_FB_SYS_FOPS is not set
591CONFIG_FB_DEFERRED_IO=y
592# CONFIG_FB_SVGALIB is not set
593# CONFIG_FB_MACMODES is not set
594# CONFIG_FB_BACKLIGHT is not set
595# CONFIG_FB_MODE_HELPERS is not set
596# CONFIG_FB_TILEBLITTING is not set
597
598#
599# Frame buffer hardware drivers
600#
601CONFIG_FB_S1D13XXX=y
602# CONFIG_FB_VIRTUAL is not set
603
604#
605# Console display driver support
606#
607# CONFIG_VGA_CONSOLE is not set
608CONFIG_DUMMY_CONSOLE=y
609CONFIG_FRAMEBUFFER_CONSOLE=y
610# CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY is not set
611# CONFIG_FRAMEBUFFER_CONSOLE_ROTATION is not set
612# CONFIG_FONTS is not set
613CONFIG_FONT_8x8=y
614CONFIG_FONT_8x16=y
615CONFIG_LOGO=y
616CONFIG_LOGO_LINUX_MONO=y
617CONFIG_LOGO_LINUX_VGA16=y
618CONFIG_LOGO_LINUX_CLUT224=y
619CONFIG_LOGO_M32R_CLUT224=y
620
621#
622# Sound
623#
624# CONFIG_SOUND is not set
625CONFIG_HID_SUPPORT=y
626CONFIG_HID=y
627# CONFIG_HID_DEBUG is not set
628CONFIG_USB_SUPPORT=y
629# CONFIG_USB_ARCH_HAS_HCD is not set
630# CONFIG_USB_ARCH_HAS_OHCI is not set
631# CONFIG_USB_ARCH_HAS_EHCI is not set
632
633#
634# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
635#
636
637#
638# USB Gadget Support
639#
640# CONFIG_USB_GADGET is not set
641CONFIG_MMC=y
642CONFIG_MMC_DEBUG=y
643# CONFIG_MMC_UNSAFE_RESUME is not set
644
645#
646# MMC/SD Card Drivers
647#
648CONFIG_MMC_BLOCK=y
649CONFIG_MMC_BLOCK_BOUNCE=y
650
651#
652# MMC/SD Host Controller Drivers
653#
654# CONFIG_NEW_LEDS is not set
655
656#
657# Real Time Clock
658#
659# CONFIG_RTC_CLASS is not set
660
661#
662# Userspace I/O
663#
664# CONFIG_UIO is not set
665
666#
667# File systems
668#
669CONFIG_EXT2_FS=y
670# CONFIG_EXT2_FS_XATTR is not set
671# CONFIG_EXT2_FS_XIP is not set
672CONFIG_EXT3_FS=y
673CONFIG_EXT3_FS_XATTR=y
674# CONFIG_EXT3_FS_POSIX_ACL is not set
675# CONFIG_EXT3_FS_SECURITY is not set
676# CONFIG_EXT4DEV_FS is not set
677CONFIG_JBD=y
678CONFIG_JBD_DEBUG=y
679CONFIG_FS_MBCACHE=y
680CONFIG_REISERFS_FS=m
681# CONFIG_REISERFS_CHECK is not set
682# CONFIG_REISERFS_PROC_INFO is not set
683# CONFIG_REISERFS_FS_XATTR is not set
684# CONFIG_JFS_FS is not set
685# CONFIG_FS_POSIX_ACL is not set
686# CONFIG_XFS_FS is not set
687# CONFIG_GFS2_FS is not set
688# CONFIG_OCFS2_FS is not set
689# CONFIG_MINIX_FS is not set
690# CONFIG_ROMFS_FS is not set
691CONFIG_INOTIFY=y
692CONFIG_INOTIFY_USER=y
693# CONFIG_QUOTA is not set
694CONFIG_DNOTIFY=y
695# CONFIG_AUTOFS_FS is not set
696# CONFIG_AUTOFS4_FS is not set
697# CONFIG_FUSE_FS is not set
698
699#
700# CD-ROM/DVD Filesystems
701#
702CONFIG_ISO9660_FS=m
703CONFIG_JOLIET=y
704# CONFIG_ZISOFS is not set
705CONFIG_UDF_FS=m
706CONFIG_UDF_NLS=y
707
708#
709# DOS/FAT/NT Filesystems
710#
711CONFIG_FAT_FS=m
712CONFIG_MSDOS_FS=m
713CONFIG_VFAT_FS=m
714CONFIG_FAT_DEFAULT_CODEPAGE=437
715CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
716# CONFIG_NTFS_FS is not set
717
718#
719# Pseudo filesystems
720#
721CONFIG_PROC_FS=y
722CONFIG_PROC_KCORE=y
723CONFIG_PROC_SYSCTL=y
724CONFIG_SYSFS=y
725CONFIG_TMPFS=y
726# CONFIG_TMPFS_POSIX_ACL is not set
727# CONFIG_HUGETLB_PAGE is not set
728CONFIG_RAMFS=y
729# CONFIG_CONFIGFS_FS is not set
730
731#
732# Miscellaneous filesystems
733#
734# CONFIG_ADFS_FS is not set
735# CONFIG_AFFS_FS is not set
736# CONFIG_HFS_FS is not set
737# CONFIG_HFSPLUS_FS is not set
738# CONFIG_BEFS_FS is not set
739# CONFIG_BFS_FS is not set
740# CONFIG_EFS_FS is not set
741# CONFIG_JFFS2_FS is not set
742# CONFIG_CRAMFS is not set
743# CONFIG_VXFS_FS is not set
744# CONFIG_HPFS_FS is not set
745# CONFIG_QNX4FS_FS is not set
746# CONFIG_SYSV_FS is not set
747# CONFIG_UFS_FS is not set
748
749#
750# Network File Systems
751#
752CONFIG_NFS_FS=y
753CONFIG_NFS_V3=y
754# CONFIG_NFS_V3_ACL is not set
755# CONFIG_NFS_V4 is not set
756# CONFIG_NFS_DIRECTIO is not set
757# CONFIG_NFSD is not set
758CONFIG_ROOT_NFS=y
759CONFIG_LOCKD=y
760CONFIG_LOCKD_V4=y
761CONFIG_NFS_COMMON=y
762CONFIG_SUNRPC=y
763# CONFIG_SUNRPC_BIND34 is not set
764# CONFIG_RPCSEC_GSS_KRB5 is not set
765# CONFIG_RPCSEC_GSS_SPKM3 is not set
766# CONFIG_SMB_FS is not set
767# CONFIG_CIFS is not set
768# CONFIG_NCP_FS is not set
769# CONFIG_CODA_FS is not set
770# CONFIG_AFS_FS is not set
771
772#
773# Partition Types
774#
775# CONFIG_PARTITION_ADVANCED is not set
776CONFIG_MSDOS_PARTITION=y
777
778#
779# Native Language Support
780#
781CONFIG_NLS=y
782CONFIG_NLS_DEFAULT="iso8859-1"
783# CONFIG_NLS_CODEPAGE_437 is not set
784# CONFIG_NLS_CODEPAGE_737 is not set
785# CONFIG_NLS_CODEPAGE_775 is not set
786# CONFIG_NLS_CODEPAGE_850 is not set
787# CONFIG_NLS_CODEPAGE_852 is not set
788# CONFIG_NLS_CODEPAGE_855 is not set
789# CONFIG_NLS_CODEPAGE_857 is not set
790# CONFIG_NLS_CODEPAGE_860 is not set
791# CONFIG_NLS_CODEPAGE_861 is not set
792# CONFIG_NLS_CODEPAGE_862 is not set
793# CONFIG_NLS_CODEPAGE_863 is not set
794# CONFIG_NLS_CODEPAGE_864 is not set
795# CONFIG_NLS_CODEPAGE_865 is not set
796# CONFIG_NLS_CODEPAGE_866 is not set
797# CONFIG_NLS_CODEPAGE_869 is not set
798# CONFIG_NLS_CODEPAGE_936 is not set
799# CONFIG_NLS_CODEPAGE_950 is not set
800# CONFIG_NLS_CODEPAGE_932 is not set
801# CONFIG_NLS_CODEPAGE_949 is not set
802# CONFIG_NLS_CODEPAGE_874 is not set
803# CONFIG_NLS_ISO8859_8 is not set
804# CONFIG_NLS_CODEPAGE_1250 is not set
805# CONFIG_NLS_CODEPAGE_1251 is not set
806# CONFIG_NLS_ASCII is not set
807# CONFIG_NLS_ISO8859_1 is not set
808# CONFIG_NLS_ISO8859_2 is not set
809# CONFIG_NLS_ISO8859_3 is not set
810# CONFIG_NLS_ISO8859_4 is not set
811# CONFIG_NLS_ISO8859_5 is not set
812# CONFIG_NLS_ISO8859_6 is not set
813# CONFIG_NLS_ISO8859_7 is not set
814# CONFIG_NLS_ISO8859_9 is not set
815# CONFIG_NLS_ISO8859_13 is not set
816# CONFIG_NLS_ISO8859_14 is not set
817# CONFIG_NLS_ISO8859_15 is not set
818# CONFIG_NLS_KOI8_R is not set
819# CONFIG_NLS_KOI8_U is not set
820# CONFIG_NLS_UTF8 is not set
821
822#
823# Distributed Lock Manager
824#
825# CONFIG_DLM is not set
826
827#
828# Profiling support
829#
830CONFIG_PROFILING=y
831CONFIG_OPROFILE=y
832
833#
834# Kernel hacking
835#
836# CONFIG_PRINTK_TIME is not set
837CONFIG_ENABLE_MUST_CHECK=y
838# CONFIG_MAGIC_SYSRQ is not set
839# CONFIG_UNUSED_SYMBOLS is not set
840# CONFIG_DEBUG_FS is not set
841# CONFIG_HEADERS_CHECK is not set
842# CONFIG_DEBUG_KERNEL is not set
843# CONFIG_DEBUG_BUGVERBOSE is not set
844# CONFIG_FRAME_POINTER is not set
845
846#
847# Security options
848#
849# CONFIG_KEYS is not set
850# CONFIG_SECURITY is not set
851# CONFIG_CRYPTO is not set
852
853#
854# Library routines
855#
856CONFIG_BITREVERSE=y
857# CONFIG_CRC_CCITT is not set
858# CONFIG_CRC16 is not set
859# CONFIG_CRC_ITU_T is not set
860CONFIG_CRC32=y
861# CONFIG_CRC7 is not set
862# CONFIG_LIBCRC32C is not set
863CONFIG_HAS_IOMEM=y
diff --git a/arch/m32r/kernel/vmlinux.lds.S b/arch/m32r/kernel/vmlinux.lds.S
index 41b07854fcc6..15a6f36c06db 100644
--- a/arch/m32r/kernel/vmlinux.lds.S
+++ b/arch/m32r/kernel/vmlinux.lds.S
@@ -60,9 +60,6 @@ SECTIONS
60 . = ALIGN(4096); 60 . = ALIGN(4096);
61 __nosave_end = .; 61 __nosave_end = .;
62 62
63 . = ALIGN(4096);
64 .data.page_aligned : { *(.data.idt) }
65
66 . = ALIGN(32); 63 . = ALIGN(32);
67 .data.cacheline_aligned : { *(.data.cacheline_aligned) } 64 .data.cacheline_aligned : { *(.data.cacheline_aligned) }
68 65
diff --git a/arch/m68k/kernel/sys_m68k.c b/arch/m68k/kernel/sys_m68k.c
index e892f17ba3fa..7f54efaf60bb 100644
--- a/arch/m68k/kernel/sys_m68k.c
+++ b/arch/m68k/kernel/sys_m68k.c
@@ -30,23 +30,6 @@
30#include <asm/page.h> 30#include <asm/page.h>
31#include <asm/unistd.h> 31#include <asm/unistd.h>
32 32
33/*
34 * sys_pipe() is the normal C calling standard for creating
35 * a pipe. It's not the way unix traditionally does this, though.
36 */
37asmlinkage int sys_pipe(unsigned long __user * fildes)
38{
39 int fd[2];
40 int error;
41
42 error = do_pipe(fd);
43 if (!error) {
44 if (copy_to_user(fildes, fd, 2*sizeof(int)))
45 error = -EFAULT;
46 }
47 return error;
48}
49
50/* common code for old and new mmaps */ 33/* common code for old and new mmaps */
51static inline long do_mmap2( 34static inline long do_mmap2(
52 unsigned long addr, unsigned long len, 35 unsigned long addr, unsigned long len,
diff --git a/arch/m68k/kernel/traps.c b/arch/m68k/kernel/traps.c
index fd4858e2dd63..75b8340b254b 100644
--- a/arch/m68k/kernel/traps.c
+++ b/arch/m68k/kernel/traps.c
@@ -468,15 +468,26 @@ static inline void access_error040(struct frame *fp)
468 * (if do_page_fault didn't fix the mapping, 468 * (if do_page_fault didn't fix the mapping,
469 * the writeback won't do good) 469 * the writeback won't do good)
470 */ 470 */
471disable_wb:
471#ifdef DEBUG 472#ifdef DEBUG
472 printk(".. disabling wb2\n"); 473 printk(".. disabling wb2\n");
473#endif 474#endif
474 if (fp->un.fmt7.wb2a == fp->un.fmt7.faddr) 475 if (fp->un.fmt7.wb2a == fp->un.fmt7.faddr)
475 fp->un.fmt7.wb2s &= ~WBV_040; 476 fp->un.fmt7.wb2s &= ~WBV_040;
477 if (fp->un.fmt7.wb3a == fp->un.fmt7.faddr)
478 fp->un.fmt7.wb3s &= ~WBV_040;
476 } 479 }
477 } else if (send_fault_sig(&fp->ptregs) > 0) { 480 } else {
478 printk("68040 access error, ssw=%x\n", ssw); 481 /* In case of a bus error we either kill the process or expect
479 trap_c(fp); 482 * the kernel to catch the fault, which then is also responsible
483 * for cleaning up the mess.
484 */
485 current->thread.signo = SIGBUS;
486 current->thread.faddr = fp->un.fmt7.faddr;
487 if (send_fault_sig(&fp->ptregs) >= 0)
488 printk("68040 bus error (ssw=%x, faddr=%lx)\n", ssw,
489 fp->un.fmt7.faddr);
490 goto disable_wb;
480 } 491 }
481 492
482 do_040writebacks(fp); 493 do_040writebacks(fp);
diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
index 735a49b4b936..ad3e3bacae39 100644
--- a/arch/m68k/mac/config.c
+++ b/arch/m68k/mac/config.c
@@ -48,9 +48,6 @@
48struct mac_booter_data mac_bi_data; 48struct mac_booter_data mac_bi_data;
49int mac_bisize = sizeof mac_bi_data; 49int mac_bisize = sizeof mac_bi_data;
50 50
51struct mac_hw_present mac_hw_present;
52EXPORT_SYMBOL(mac_hw_present);
53
54/* New m68k bootinfo stuff and videobase */ 51/* New m68k bootinfo stuff and videobase */
55 52
56extern int m68k_num_memory; 53extern int m68k_num_memory;
@@ -817,27 +814,6 @@ void __init mac_identify(void)
817 m68k_ramdisk.addr, m68k_ramdisk.size); 814 m68k_ramdisk.addr, m68k_ramdisk.size);
818#endif 815#endif
819 816
820 /*
821 * TODO: set the various fields in macintosh_config->hw_present here!
822 */
823 switch (macintosh_config->scsi_type) {
824 case MAC_SCSI_OLD:
825 MACHW_SET(MAC_SCSI_80);
826 break;
827 case MAC_SCSI_QUADRA:
828 case MAC_SCSI_QUADRA2:
829 case MAC_SCSI_QUADRA3:
830 MACHW_SET(MAC_SCSI_96);
831 if ((macintosh_config->ident == MAC_MODEL_Q900) ||
832 (macintosh_config->ident == MAC_MODEL_Q950))
833 MACHW_SET(MAC_SCSI_96_2);
834 break;
835 default:
836 printk(KERN_WARNING "config.c: wtf: unknown scsi, using 53c80\n");
837 MACHW_SET(MAC_SCSI_80);
838 break;
839 }
840
841 iop_init(); 817 iop_init();
842 via_init(); 818 via_init();
843 oss_init(); 819 oss_init();
diff --git a/arch/m68k/mm/init.c b/arch/m68k/mm/init.c
index a2bb01f59642..d8fb9c5303cc 100644
--- a/arch/m68k/mm/init.c
+++ b/arch/m68k/mm/init.c
@@ -69,6 +69,7 @@ void __init m68k_setup_node(int node)
69 */ 69 */
70 70
71void *empty_zero_page; 71void *empty_zero_page;
72EXPORT_SYMBOL(empty_zero_page);
72 73
73void show_mem(void) 74void show_mem(void)
74{ 75{
diff --git a/arch/m68knommu/kernel/asm-offsets.c b/arch/m68knommu/kernel/asm-offsets.c
index fd0c685a7f11..c785d07c02cc 100644
--- a/arch/m68knommu/kernel/asm-offsets.c
+++ b/arch/m68knommu/kernel/asm-offsets.c
@@ -87,6 +87,7 @@ int main(void)
87 DEFINE(TI_TASK, offsetof(struct thread_info, task)); 87 DEFINE(TI_TASK, offsetof(struct thread_info, task));
88 DEFINE(TI_EXECDOMAIN, offsetof(struct thread_info, exec_domain)); 88 DEFINE(TI_EXECDOMAIN, offsetof(struct thread_info, exec_domain));
89 DEFINE(TI_FLAGS, offsetof(struct thread_info, flags)); 89 DEFINE(TI_FLAGS, offsetof(struct thread_info, flags));
90 DEFINE(TI_PREEMPTCOUNT, offsetof(struct thread_info, preempt_count));
90 DEFINE(TI_CPU, offsetof(struct thread_info, cpu)); 91 DEFINE(TI_CPU, offsetof(struct thread_info, cpu));
91 92
92 return 0; 93 return 0;
diff --git a/arch/m68knommu/kernel/entry.S b/arch/m68knommu/kernel/entry.S
index 1e7ea6a3e1a1..f4782d2dce8f 100644
--- a/arch/m68knommu/kernel/entry.S
+++ b/arch/m68knommu/kernel/entry.S
@@ -32,6 +32,7 @@
32#include <asm/segment.h> 32#include <asm/segment.h>
33#include <asm/asm-offsets.h> 33#include <asm/asm-offsets.h>
34#include <asm/entry.h> 34#include <asm/entry.h>
35#include <asm/unistd.h>
35 36
36.text 37.text
37 38
@@ -140,3 +141,11 @@ ENTRY(sys_rt_sigreturn)
140 RESTORE_SWITCH_STACK 141 RESTORE_SWITCH_STACK
141 rts 142 rts
142 143
144ENTRY(ret_from_user_signal)
145 moveq #__NR_sigreturn,%d0
146 trap #0
147
148ENTRY(ret_from_user_rt_signal)
149 move #__NR_rt_sigreturn,%d0
150 trap #0
151
diff --git a/arch/m68knommu/kernel/setup.c b/arch/m68knommu/kernel/setup.c
index d6f0200316fe..03f4fe6a2fc0 100644
--- a/arch/m68knommu/kernel/setup.c
+++ b/arch/m68knommu/kernel/setup.c
@@ -162,7 +162,7 @@ void __init setup_arch(char **cmdline_p)
162 printk(KERN_INFO "DragonEngine II board support by Georges Menie\n"); 162 printk(KERN_INFO "DragonEngine II board support by Georges Menie\n");
163#endif 163#endif
164#ifdef CONFIG_M5235EVB 164#ifdef CONFIG_M5235EVB
165 printk(KERN_INFO "Motorola M5235EVB support (C)2005 Syn-tech Systems, Inc. (Jate Sujjavanich)"); 165 printk(KERN_INFO "Motorola M5235EVB support (C)2005 Syn-tech Systems, Inc. (Jate Sujjavanich)\n");
166#endif 166#endif
167 167
168#ifdef DEBUG 168#ifdef DEBUG
diff --git a/arch/m68knommu/kernel/signal.c b/arch/m68knommu/kernel/signal.c
index 70371378db86..bbfcae9e52b4 100644
--- a/arch/m68knommu/kernel/signal.c
+++ b/arch/m68knommu/kernel/signal.c
@@ -51,6 +51,8 @@
51 51
52#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) 52#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
53 53
54void ret_from_user_signal(void);
55void ret_from_user_rt_signal(void);
54asmlinkage int do_signal(sigset_t *oldset, struct pt_regs *regs); 56asmlinkage int do_signal(sigset_t *oldset, struct pt_regs *regs);
55 57
56/* 58/*
@@ -539,10 +541,6 @@ static inline int rt_setup_ucontext(struct ucontext *uc, struct pt_regs *regs)
539 return err; 541 return err;
540} 542}
541 543
542static inline void push_cache (unsigned long vaddr)
543{
544}
545
546static inline void * 544static inline void *
547get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size) 545get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size)
548{ 546{
@@ -586,16 +584,11 @@ static void setup_frame (int sig, struct k_sigaction *ka,
586 err |= copy_to_user (&frame->sc, &context, sizeof(context)); 584 err |= copy_to_user (&frame->sc, &context, sizeof(context));
587 585
588 /* Set up to return from userspace. */ 586 /* Set up to return from userspace. */
589 err |= __put_user(frame->retcode, &frame->pretcode); 587 err |= __put_user((void *) ret_from_user_signal, &frame->pretcode);
590 /* moveq #,d0; trap #0 */
591 err |= __put_user(0x70004e40 + (__NR_sigreturn << 16),
592 (long *)(frame->retcode));
593 588
594 if (err) 589 if (err)
595 goto give_sigsegv; 590 goto give_sigsegv;
596 591
597 push_cache ((unsigned long) &frame->retcode);
598
599 /* Set up registers for signal handler */ 592 /* Set up registers for signal handler */
600 wrusp ((unsigned long) frame); 593 wrusp ((unsigned long) frame);
601 regs->pc = (unsigned long) ka->sa.sa_handler; 594 regs->pc = (unsigned long) ka->sa.sa_handler;
@@ -655,17 +648,11 @@ static void setup_rt_frame (int sig, struct k_sigaction *ka, siginfo_t *info,
655 err |= copy_to_user (&frame->uc.uc_sigmask, set, sizeof(*set)); 648 err |= copy_to_user (&frame->uc.uc_sigmask, set, sizeof(*set));
656 649
657 /* Set up to return from userspace. */ 650 /* Set up to return from userspace. */
658 err |= __put_user(frame->retcode, &frame->pretcode); 651 err |= __put_user((void *) ret_from_user_rt_signal, &frame->pretcode);
659 /* moveq #,d0; notb d0; trap #0 */
660 err |= __put_user(0x70004600 + ((__NR_rt_sigreturn ^ 0xff) << 16),
661 (long *)(frame->retcode + 0));
662 err |= __put_user(0x4e40, (short *)(frame->retcode + 4));
663 652
664 if (err) 653 if (err)
665 goto give_sigsegv; 654 goto give_sigsegv;
666 655
667 push_cache ((unsigned long) &frame->retcode);
668
669 /* Set up registers for signal handler */ 656 /* Set up registers for signal handler */
670 wrusp ((unsigned long) frame); 657 wrusp ((unsigned long) frame);
671 regs->pc = (unsigned long) ka->sa.sa_handler; 658 regs->pc = (unsigned long) ka->sa.sa_handler;
diff --git a/arch/m68knommu/kernel/sys_m68k.c b/arch/m68knommu/kernel/sys_m68k.c
index 65f7a95f056e..700281638629 100644
--- a/arch/m68knommu/kernel/sys_m68k.c
+++ b/arch/m68knommu/kernel/sys_m68k.c
@@ -28,23 +28,6 @@
28#include <asm/cacheflush.h> 28#include <asm/cacheflush.h>
29#include <asm/unistd.h> 29#include <asm/unistd.h>
30 30
31/*
32 * sys_pipe() is the normal C calling standard for creating
33 * a pipe. It's not the way unix traditionally does this, though.
34 */
35asmlinkage int sys_pipe(unsigned long * fildes)
36{
37 int fd[2];
38 int error;
39
40 error = do_pipe(fd);
41 if (!error) {
42 if (copy_to_user(fildes, fd, 2*sizeof(int)))
43 error = -EFAULT;
44 }
45 return error;
46}
47
48/* common code for old and new mmaps */ 31/* common code for old and new mmaps */
49static inline long do_mmap2( 32static inline long do_mmap2(
50 unsigned long addr, unsigned long len, 33 unsigned long addr, unsigned long len,
diff --git a/arch/m68knommu/kernel/traps.c b/arch/m68knommu/kernel/traps.c
index 437a061d8b94..ec9aea652e79 100644
--- a/arch/m68knommu/kernel/traps.c
+++ b/arch/m68knommu/kernel/traps.c
@@ -28,6 +28,7 @@
28#include <linux/linkage.h> 28#include <linux/linkage.h>
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/ptrace.h> 30#include <linux/ptrace.h>
31#include <linux/kallsyms.h>
31 32
32#include <asm/setup.h> 33#include <asm/setup.h>
33#include <asm/fpu.h> 34#include <asm/fpu.h>
@@ -102,56 +103,47 @@ asmlinkage void buserr_c(struct frame *fp)
102 force_sig(SIGSEGV, current); 103 force_sig(SIGSEGV, current);
103} 104}
104 105
105
106int kstack_depth_to_print = 48; 106int kstack_depth_to_print = 48;
107 107
108void show_stack(struct task_struct *task, unsigned long *stack) 108static void __show_stack(struct task_struct *task, unsigned long *stack)
109{ 109{
110 unsigned long *endstack, addr; 110 unsigned long *endstack, addr;
111 extern char _start, _etext; 111 unsigned long *last_stack;
112 int i; 112 int i;
113 113
114 if (!stack) { 114 if (!stack)
115 if (task) 115 stack = (unsigned long *)task->thread.ksp;
116 stack = (unsigned long *)task->thread.ksp;
117 else
118 stack = (unsigned long *)&stack;
119 }
120 116
121 addr = (unsigned long) stack; 117 addr = (unsigned long) stack;
122 endstack = (unsigned long *) PAGE_ALIGN(addr); 118 endstack = (unsigned long *) PAGE_ALIGN(addr);
123 119
124 printk(KERN_EMERG "Stack from %08lx:", (unsigned long)stack); 120 printk(KERN_EMERG "Stack from %08lx:", (unsigned long)stack);
125 for (i = 0; i < kstack_depth_to_print; i++) { 121 for (i = 0; i < kstack_depth_to_print; i++) {
126 if (stack + 1 > endstack) 122 if (stack + 1 + i > endstack)
127 break; 123 break;
128 if (i % 8 == 0) 124 if (i % 8 == 0)
129 printk("\n" KERN_EMERG " "); 125 printk("\n" KERN_EMERG " ");
130 printk(" %08lx", *stack++); 126 printk(" %08lx", *(stack + i));
131 } 127 }
132 printk("\n"); 128 printk("\n");
133 129
134 printk(KERN_EMERG "Call Trace:"); 130#ifdef CONFIG_FRAME_POINTER
135 i = 0; 131 printk(KERN_EMERG "Call Trace:\n");
136 while (stack + 1 <= endstack) { 132
137 addr = *stack++; 133 last_stack = stack - 1;
138 /* 134 while (stack <= endstack && stack > last_stack) {
139 * If the address is either in the text segment of the 135
140 * kernel, or in the region which contains vmalloc'ed 136 addr = *(stack + 1);
141 * memory, it *may* be the address of a calling 137 printk(KERN_EMERG " [%08lx] ", addr);
142 * routine; if so, print it so that someone tracing 138 print_symbol(KERN_CONT "%s\n", addr);
143 * down the cause of the crash will be able to figure 139
144 * out the call path that was taken. 140 last_stack = stack;
145 */ 141 stack = (unsigned long *)*stack;
146 if (((addr >= (unsigned long) &_start) &&
147 (addr <= (unsigned long) &_etext))) {
148 if (i % 4 == 0)
149 printk("\n" KERN_EMERG " ");
150 printk(" [<%08lx>]", addr);
151 i++;
152 }
153 } 142 }
154 printk("\n"); 143 printk("\n");
144#else
145 printk(KERN_EMERG "CONFIG_FRAME_POINTER disabled, no symbolic call trace\n");
146#endif
155} 147}
156 148
157void bad_super_trap(struct frame *fp) 149void bad_super_trap(struct frame *fp)
@@ -298,19 +290,47 @@ asmlinkage void set_esp0(unsigned long ssp)
298 current->thread.esp0 = ssp; 290 current->thread.esp0 = ssp;
299} 291}
300 292
301
302/* 293/*
303 * The architecture-independent backtrace generator 294 * The architecture-independent backtrace generator
304 */ 295 */
305void dump_stack(void) 296void dump_stack(void)
306{ 297{
307 unsigned long stack; 298 /*
299 * We need frame pointers for this little trick, which works as follows:
300 *
301 * +------------+ 0x00
302 * | Next SP | -> 0x0c
303 * +------------+ 0x04
304 * | Caller |
305 * +------------+ 0x08
306 * | Local vars | -> our stack var
307 * +------------+ 0x0c
308 * | Next SP | -> 0x18, that is what we pass to show_stack()
309 * +------------+ 0x10
310 * | Caller |
311 * +------------+ 0x14
312 * | Local vars |
313 * +------------+ 0x18
314 * | ... |
315 * +------------+
316 */
308 317
309 show_stack(current, &stack); 318 unsigned long *stack;
310}
311 319
320 stack = (unsigned long *)&stack;
321 stack++;
322 __show_stack(current, stack);
323}
312EXPORT_SYMBOL(dump_stack); 324EXPORT_SYMBOL(dump_stack);
313 325
326void show_stack(struct task_struct *task, unsigned long *stack)
327{
328 if (!stack && !task)
329 dump_stack();
330 else
331 __show_stack(task, stack);
332}
333
314#ifdef CONFIG_M68KFPU_EMU 334#ifdef CONFIG_M68KFPU_EMU
315asmlinkage void fpemu_signal(int signal, int code, void *addr) 335asmlinkage void fpemu_signal(int signal, int code, void *addr)
316{ 336{
diff --git a/arch/m68knommu/kernel/vmlinux.lds.S b/arch/m68knommu/kernel/vmlinux.lds.S
index b44edb08e212..5592e0bf951f 100644
--- a/arch/m68knommu/kernel/vmlinux.lds.S
+++ b/arch/m68knommu/kernel/vmlinux.lds.S
@@ -64,6 +64,7 @@ SECTIONS {
64 _stext = . ; 64 _stext = . ;
65 TEXT_TEXT 65 TEXT_TEXT
66 SCHED_TEXT 66 SCHED_TEXT
67 LOCK_TEXT
67 *(.text.lock) 68 *(.text.lock)
68 69
69 . = ALIGN(16); /* Exception table */ 70 . = ALIGN(16); /* Exception table */
@@ -73,6 +74,7 @@ SECTIONS {
73 74
74 *(.rodata) *(.rodata.*) 75 *(.rodata) *(.rodata.*)
75 *(__vermagic) /* Kernel version magic */ 76 *(__vermagic) /* Kernel version magic */
77 *(__markers_strings)
76 *(.rodata1) 78 *(.rodata1)
77 *(.rodata.str1.1) 79 *(.rodata.str1.1)
78 80
@@ -182,6 +184,7 @@ SECTIONS {
182 *(COMMON) 184 *(COMMON)
183 . = ALIGN(4) ; 185 . = ALIGN(4) ;
184 _ebss = . ; 186 _ebss = . ;
187 _end = . ;
185 } > BSS 188 } > BSS
186 189
187} 190}
diff --git a/arch/m68knommu/platform/5206e/config.c b/arch/m68knommu/platform/5206e/config.c
index a6692e958f6b..d01a5d2b7557 100644
--- a/arch/m68knommu/platform/5206e/config.c
+++ b/arch/m68knommu/platform/5206e/config.c
@@ -48,7 +48,7 @@ static struct platform_device *m5206e_devices[] __initdata = {
48 48
49/***************************************************************************/ 49/***************************************************************************/
50 50
51static void __init m5206_uart_init_line(int line, int irq) 51static void __init m5206e_uart_init_line(int line, int irq)
52{ 52{
53 if (line == 0) { 53 if (line == 0) {
54 writel(MCFSIM_ICR_LEVEL6 | MCFSIM_ICR_PRI1, MCF_MBAR + MCFSIM_UART1ICR); 54 writel(MCFSIM_ICR_LEVEL6 | MCFSIM_ICR_PRI1, MCF_MBAR + MCFSIM_UART1ICR);
diff --git a/arch/m68knommu/platform/5272/config.c b/arch/m68knommu/platform/5272/config.c
index 2aca599a1ca7..230bae691a7f 100644
--- a/arch/m68knommu/platform/5272/config.c
+++ b/arch/m68knommu/platform/5272/config.c
@@ -139,10 +139,6 @@ void __init config_BSP(char *commandp, int size)
139 /* Copy command line from FLASH to local buffer... */ 139 /* Copy command line from FLASH to local buffer... */
140 memcpy(commandp, (char *) 0xf0004000, size); 140 memcpy(commandp, (char *) 0xf0004000, size);
141 commandp[size-1] = 0; 141 commandp[size-1] = 0;
142#elif defined(CONFIG_MTD_KeyTechnology)
143 /* Copy command line from FLASH to local buffer... */
144 memcpy(commandp, (char *) 0xffe06000, size);
145 commandp[size-1] = 0;
146#elif defined(CONFIG_CANCam) 142#elif defined(CONFIG_CANCam)
147 /* Copy command line from FLASH to local buffer... */ 143 /* Copy command line from FLASH to local buffer... */
148 memcpy(commandp, (char *) 0xf0010000, size); 144 memcpy(commandp, (char *) 0xf0010000, size);
diff --git a/arch/m68knommu/platform/528x/config.c b/arch/m68knommu/platform/528x/config.c
index 036e1b73d944..dfdb5c2ed8e6 100644
--- a/arch/m68knommu/platform/528x/config.c
+++ b/arch/m68knommu/platform/528x/config.c
@@ -26,9 +26,240 @@
26#include <asm/mcfuart.h> 26#include <asm/mcfuart.h>
27#include <asm/mcfqspi.h> 27#include <asm/mcfqspi.h>
28 28
29#ifdef CONFIG_MTD_PARTITIONS
30#include <linux/mtd/partitions.h>
31#endif
32
29/***************************************************************************/ 33/***************************************************************************/
30 34
31void coldfire_reset(void); 35void coldfire_reset(void);
36static void coldfire_qspi_cs_control(u8 cs, u8 command);
37
38/***************************************************************************/
39
40#if defined(CONFIG_SPI)
41
42#if defined(CONFIG_WILDFIRE)
43#define SPI_NUM_CHIPSELECTS 0x02
44#define SPI_PAR_VAL 0x07 /* Enable DIN, DOUT, CLK */
45#define SPI_CS_MASK 0x18
46
47#define FLASH_BLOCKSIZE (1024*64)
48#define FLASH_NUMBLOCKS 16
49#define FLASH_TYPE "m25p80"
50
51#define M25P80_CS 0
52#define MMC_CS 1
53
54#ifdef CONFIG_MTD_PARTITIONS
55static struct mtd_partition stm25p_partitions[] = {
56 /* sflash */
57 [0] = {
58 .name = "stm25p80",
59 .offset = 0x00000000,
60 .size = FLASH_BLOCKSIZE * FLASH_NUMBLOCKS,
61 .mask_flags = 0
62 }
63};
64
65#endif
66
67#elif defined(CONFIG_WILDFIREMOD)
68
69#define SPI_NUM_CHIPSELECTS 0x08
70#define SPI_PAR_VAL 0x07 /* Enable DIN, DOUT, CLK */
71#define SPI_CS_MASK 0x78
72
73#define FLASH_BLOCKSIZE (1024*64)
74#define FLASH_NUMBLOCKS 64
75#define FLASH_TYPE "m25p32"
76/* Reserve 1M for the kernel parition */
77#define FLASH_KERNEL_SIZE (1024 * 1024)
78
79#define M25P80_CS 5
80#define MMC_CS 6
81
82#ifdef CONFIG_MTD_PARTITIONS
83static struct mtd_partition stm25p_partitions[] = {
84 /* sflash */
85 [0] = {
86 .name = "kernel",
87 .offset = FLASH_BLOCKSIZE * FLASH_NUMBLOCKS - FLASH_KERNEL_SIZE,
88 .size = FLASH_KERNEL_SIZE,
89 .mask_flags = 0
90 },
91 [1] = {
92 .name = "image",
93 .offset = 0x00000000,
94 .size = FLASH_BLOCKSIZE * FLASH_NUMBLOCKS - FLASH_KERNEL_SIZE,
95 .mask_flags = 0
96 },
97 [2] = {
98 .name = "all",
99 .offset = 0x00000000,
100 .size = FLASH_BLOCKSIZE * FLASH_NUMBLOCKS,
101 .mask_flags = 0
102 }
103};
104#endif
105
106#else
107#define SPI_NUM_CHIPSELECTS 0x04
108#define SPI_PAR_VAL 0x7F /* Enable DIN, DOUT, CLK, CS0 - CS4 */
109#endif
110
111#ifdef MMC_CS
112static struct coldfire_spi_chip flash_chip_info = {
113 .mode = SPI_MODE_0,
114 .bits_per_word = 16,
115 .del_cs_to_clk = 17,
116 .del_after_trans = 1,
117 .void_write_data = 0
118};
119
120static struct coldfire_spi_chip mmc_chip_info = {
121 .mode = SPI_MODE_0,
122 .bits_per_word = 16,
123 .del_cs_to_clk = 17,
124 .del_after_trans = 1,
125 .void_write_data = 0xFFFF
126};
127#endif
128
129#ifdef M25P80_CS
130static struct flash_platform_data stm25p80_platform_data = {
131 .name = "ST M25P80 SPI Flash chip",
132#ifdef CONFIG_MTD_PARTITIONS
133 .parts = stm25p_partitions,
134 .nr_parts = sizeof(stm25p_partitions) / sizeof(*stm25p_partitions),
135#endif
136 .type = FLASH_TYPE
137};
138#endif
139
140static struct spi_board_info spi_board_info[] __initdata = {
141#ifdef M25P80_CS
142 {
143 .modalias = "m25p80",
144 .max_speed_hz = 16000000,
145 .bus_num = 1,
146 .chip_select = M25P80_CS,
147 .platform_data = &stm25p80_platform_data,
148 .controller_data = &flash_chip_info
149 },
150#endif
151#ifdef MMC_CS
152 {
153 .modalias = "mmc_spi",
154 .max_speed_hz = 16000000,
155 .bus_num = 1,
156 .chip_select = MMC_CS,
157 .controller_data = &mmc_chip_info
158 }
159#endif
160};
161
162static struct coldfire_spi_master coldfire_master_info = {
163 .bus_num = 1,
164 .num_chipselect = SPI_NUM_CHIPSELECTS,
165 .irq_source = MCF5282_QSPI_IRQ_SOURCE,
166 .irq_vector = MCF5282_QSPI_IRQ_VECTOR,
167 .irq_mask = ((0x01 << MCF5282_QSPI_IRQ_SOURCE) | 0x01),
168 .irq_lp = 0x2B, /* Level 5 and Priority 3 */
169 .par_val = SPI_PAR_VAL,
170 .cs_control = coldfire_qspi_cs_control,
171};
172
173static struct resource coldfire_spi_resources[] = {
174 [0] = {
175 .name = "qspi-par",
176 .start = MCF5282_QSPI_PAR,
177 .end = MCF5282_QSPI_PAR,
178 .flags = IORESOURCE_MEM
179 },
180
181 [1] = {
182 .name = "qspi-module",
183 .start = MCF5282_QSPI_QMR,
184 .end = MCF5282_QSPI_QMR + 0x18,
185 .flags = IORESOURCE_MEM
186 },
187
188 [2] = {
189 .name = "qspi-int-level",
190 .start = MCF5282_INTC0 + MCFINTC_ICR0 + MCF5282_QSPI_IRQ_SOURCE,
191 .end = MCF5282_INTC0 + MCFINTC_ICR0 + MCF5282_QSPI_IRQ_SOURCE,
192 .flags = IORESOURCE_MEM
193 },
194
195 [3] = {
196 .name = "qspi-int-mask",
197 .start = MCF5282_INTC0 + MCFINTC_IMRL,
198 .end = MCF5282_INTC0 + MCFINTC_IMRL,
199 .flags = IORESOURCE_MEM
200 }
201};
202
203static struct platform_device coldfire_spi = {
204 .name = "spi_coldfire",
205 .id = -1,
206 .resource = coldfire_spi_resources,
207 .num_resources = ARRAY_SIZE(coldfire_spi_resources),
208 .dev = {
209 .platform_data = &coldfire_master_info,
210 }
211};
212
213static void coldfire_qspi_cs_control(u8 cs, u8 command)
214{
215 u8 cs_bit = ((0x01 << cs) << 3) & SPI_CS_MASK;
216
217#if defined(CONFIG_WILDFIRE)
218 u8 cs_mask = ~(((0x01 << cs) << 3) & SPI_CS_MASK);
219#endif
220#if defined(CONFIG_WILDFIREMOD)
221 u8 cs_mask = (cs << 3) & SPI_CS_MASK;
222#endif
223
224 /*
225 * Don't do anything if the chip select is not
226 * one of the port qs pins.
227 */
228 if (command & QSPI_CS_INIT) {
229#if defined(CONFIG_WILDFIRE)
230 MCF5282_GPIO_DDRQS |= cs_bit;
231 MCF5282_GPIO_PQSPAR &= ~cs_bit;
232#endif
233
234#if defined(CONFIG_WILDFIREMOD)
235 MCF5282_GPIO_DDRQS |= SPI_CS_MASK;
236 MCF5282_GPIO_PQSPAR &= ~SPI_CS_MASK;
237#endif
238 }
239
240 if (command & QSPI_CS_ASSERT) {
241 MCF5282_GPIO_PORTQS &= ~SPI_CS_MASK;
242 MCF5282_GPIO_PORTQS |= cs_mask;
243 } else if (command & QSPI_CS_DROP) {
244 MCF5282_GPIO_PORTQS |= SPI_CS_MASK;
245 }
246}
247
248static int __init spi_dev_init(void)
249{
250 int retval;
251
252 retval = platform_device_register(&coldfire_spi);
253 if (retval < 0)
254 return retval;
255
256 if (ARRAY_SIZE(spi_board_info))
257 retval = spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
258
259 return retval;
260}
261
262#endif /* CONFIG_SPI */
32 263
33/***************************************************************************/ 264/***************************************************************************/
34 265
@@ -111,10 +342,43 @@ void mcf_autovector(unsigned int vec)
111 342
112/***************************************************************************/ 343/***************************************************************************/
113 344
345#ifdef CONFIG_WILDFIRE
346void wildfire_halt(void)
347{
348 writeb(0, 0x30000007);
349 writeb(0x2, 0x30000007);
350}
351#endif
352
353#ifdef CONFIG_WILDFIREMOD
354void wildfiremod_halt(void)
355{
356 printk(KERN_INFO "WildFireMod hibernating...\n");
357
358 /* Set portE.5 to Digital IO */
359 MCF5282_GPIO_PEPAR &= ~(1 << (5 * 2));
360
361 /* Make portE.5 an output */
362 MCF5282_GPIO_DDRE |= (1 << 5);
363
364 /* Now toggle portE.5 from low to high */
365 MCF5282_GPIO_PORTE &= ~(1 << 5);
366 MCF5282_GPIO_PORTE |= (1 << 5);
367
368 printk(KERN_EMERG "Failed to hibernate. Halting!\n");
369}
370#endif
371
114void __init config_BSP(char *commandp, int size) 372void __init config_BSP(char *commandp, int size)
115{ 373{
116 mcf_disableall(); 374 mcf_disableall();
117 mach_reset = coldfire_reset; 375
376#ifdef CONFIG_WILDFIRE
377 mach_halt = wildfire_halt;
378#endif
379#ifdef CONFIG_WILDFIREMOD
380 mach_halt = wildfiremod_halt;
381#endif
118} 382}
119 383
120/***************************************************************************/ 384/***************************************************************************/
diff --git a/arch/m68knommu/platform/5307/config.c b/arch/m68knommu/platform/5307/config.c
index 92dc862fa826..11cff6625dcc 100644
--- a/arch/m68knommu/platform/5307/config.c
+++ b/arch/m68knommu/platform/5307/config.c
@@ -124,8 +124,7 @@ void __init config_BSP(char *commandp, int size)
124 mcf_setimr(MCFSIM_IMR_MASKALL); 124 mcf_setimr(MCFSIM_IMR_MASKALL);
125 125
126#if defined(CONFIG_NETtel) || defined(CONFIG_eLIA) || \ 126#if defined(CONFIG_NETtel) || defined(CONFIG_eLIA) || \
127 defined(CONFIG_DISKtel) || defined(CONFIG_SECUREEDGEMP3) || \ 127 defined(CONFIG_SECUREEDGEMP3) || defined(CONFIG_CLEOPATRA)
128 defined(CONFIG_CLEOPATRA)
129 /* Copy command line from FLASH to local buffer... */ 128 /* Copy command line from FLASH to local buffer... */
130 memcpy(commandp, (char *) 0xf0004000, size); 129 memcpy(commandp, (char *) 0xf0004000, size);
131 commandp[size-1] = 0; 130 commandp[size-1] = 0;
diff --git a/arch/m68knommu/platform/coldfire/entry.S b/arch/m68knommu/platform/coldfire/entry.S
index 111b66dc737b..1e3c0dcbd7ac 100644
--- a/arch/m68knommu/platform/coldfire/entry.S
+++ b/arch/m68knommu/platform/coldfire/entry.S
@@ -103,9 +103,26 @@ ret_from_signal:
103 addql #4,%sp 103 addql #4,%sp
104 104
105ret_from_exception: 105ret_from_exception:
106 move #0x2700,%sr /* disable intrs */
106 btst #5,%sp@(PT_SR) /* check if returning to kernel */ 107 btst #5,%sp@(PT_SR) /* check if returning to kernel */
107 jeq Luser_return /* if so, skip resched, signals */ 108 jeq Luser_return /* if so, skip resched, signals */
108 109
110#ifdef CONFIG_PREEMPT
111 movel %sp,%d1 /* get thread_info pointer */
112 andl #-THREAD_SIZE,%d1 /* at base of kernel stack */
113 movel %d1,%a0
114 movel %a0@(TI_FLAGS),%d1 /* get thread_info->flags */
115 andl #_TIF_NEED_RESCHED,%d1
116 jeq Lkernel_return
117
118 movel %a0@(TI_PREEMPTCOUNT),%d1
119 cmpl #0,%d1
120 jne Lkernel_return
121
122 pea Lkernel_return
123 jmp preempt_schedule_irq /* preempt the kernel */
124#endif
125
109Lkernel_return: 126Lkernel_return:
110 moveml %sp@,%d1-%d5/%a0-%a2 127 moveml %sp@,%d1-%d5/%a0-%a2
111 lea %sp@(32),%sp /* space for 8 regs */ 128 lea %sp@(32),%sp /* space for 8 regs */
@@ -140,6 +157,7 @@ Lreturn:
140 157
141Lwork_to_do: 158Lwork_to_do:
142 movel %a0@(TI_FLAGS),%d1 /* get thread_info->flags */ 159 movel %a0@(TI_FLAGS),%d1 /* get thread_info->flags */
160 move #0x2000,%sr /* enable intrs again */
143 btst #TIF_NEED_RESCHED,%d1 161 btst #TIF_NEED_RESCHED,%d1
144 jne reschedule 162 jne reschedule
145 163
diff --git a/arch/mips/au1000/common/power.c b/arch/mips/au1000/common/power.c
index 812a5f8b7d26..a8cd2c1b9e1b 100644
--- a/arch/mips/au1000/common/power.c
+++ b/arch/mips/au1000/common/power.c
@@ -251,7 +251,6 @@ int au_sleep(void)
251static int pm_do_sleep(ctl_table * ctl, int write, struct file *file, 251static int pm_do_sleep(ctl_table * ctl, int write, struct file *file,
252 void __user *buffer, size_t * len, loff_t *ppos) 252 void __user *buffer, size_t * len, loff_t *ppos)
253{ 253{
254 int retval = 0;
255#ifdef SLEEP_TEST_TIMEOUT 254#ifdef SLEEP_TEST_TIMEOUT
256#define TMPBUFLEN2 16 255#define TMPBUFLEN2 16
257 char buf[TMPBUFLEN2], *p; 256 char buf[TMPBUFLEN2], *p;
@@ -271,36 +270,12 @@ static int pm_do_sleep(ctl_table * ctl, int write, struct file *file,
271 p = buf; 270 p = buf;
272 sleep_ticks = simple_strtoul(p, &p, 0); 271 sleep_ticks = simple_strtoul(p, &p, 0);
273#endif 272#endif
274 retval = pm_send_all(PM_SUSPEND, (void *) 2);
275
276 if (retval)
277 return retval;
278 273
279 au_sleep(); 274 au_sleep();
280 retval = pm_send_all(PM_RESUME, (void *) 0);
281 } 275 }
282 return retval; 276 return 0;
283}
284
285static int pm_do_suspend(ctl_table * ctl, int write, struct file *file,
286 void __user *buffer, size_t * len, loff_t *ppos)
287{
288 int retval = 0;
289
290 if (!write) {
291 *len = 0;
292 } else {
293 retval = pm_send_all(PM_SUSPEND, (void *) 2);
294 if (retval)
295 return retval;
296 suspend_mode = 1;
297
298 retval = pm_send_all(PM_RESUME, (void *) 0);
299 }
300 return retval;
301} 277}
302 278
303
304static int pm_do_freq(ctl_table * ctl, int write, struct file *file, 279static int pm_do_freq(ctl_table * ctl, int write, struct file *file,
305 void __user *buffer, size_t * len, loff_t *ppos) 280 void __user *buffer, size_t * len, loff_t *ppos)
306{ 281{
@@ -414,14 +389,6 @@ static int pm_do_freq(ctl_table * ctl, int write, struct file *file,
414 389
415static struct ctl_table pm_table[] = { 390static struct ctl_table pm_table[] = {
416 { 391 {
417 .ctl_name = CTL_UNNUMBERED,
418 .procname = "suspend",
419 .data = NULL,
420 .maxlen = 0,
421 .mode = 0600,
422 .proc_handler = &pm_do_suspend
423 },
424 {
425 .ctl_name = CTL_UNNUMBERED, 392 .ctl_name = CTL_UNNUMBERED,
426 .procname = "sleep", 393 .procname = "sleep",
427 .data = NULL, 394 .data = NULL,
diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
index 77db3473deab..9fdd8bcdd21e 100644
--- a/arch/mips/kernel/binfmt_elfn32.c
+++ b/arch/mips/kernel/binfmt_elfn32.c
@@ -54,6 +54,7 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
54#include <linux/module.h> 54#include <linux/module.h>
55#include <linux/elfcore.h> 55#include <linux/elfcore.h>
56#include <linux/compat.h> 56#include <linux/compat.h>
57#include <linux/math64.h>
57 58
58#define elf_prstatus elf_prstatus32 59#define elf_prstatus elf_prstatus32
59struct elf_prstatus32 60struct elf_prstatus32
@@ -102,8 +103,8 @@ jiffies_to_compat_timeval(unsigned long jiffies, struct compat_timeval *value)
102 * one divide. 103 * one divide.
103 */ 104 */
104 u64 nsec = (u64)jiffies * TICK_NSEC; 105 u64 nsec = (u64)jiffies * TICK_NSEC;
105 long rem; 106 u32 rem;
106 value->tv_sec = div_long_long_rem(nsec, NSEC_PER_SEC, &rem); 107 value->tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
107 value->tv_usec = rem / NSEC_PER_USEC; 108 value->tv_usec = rem / NSEC_PER_USEC;
108} 109}
109 110
diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
index 08f4cd781ee3..e1333d7319e2 100644
--- a/arch/mips/kernel/binfmt_elfo32.c
+++ b/arch/mips/kernel/binfmt_elfo32.c
@@ -56,6 +56,7 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
56#include <linux/module.h> 56#include <linux/module.h>
57#include <linux/elfcore.h> 57#include <linux/elfcore.h>
58#include <linux/compat.h> 58#include <linux/compat.h>
59#include <linux/math64.h>
59 60
60#define elf_prstatus elf_prstatus32 61#define elf_prstatus elf_prstatus32
61struct elf_prstatus32 62struct elf_prstatus32
@@ -104,8 +105,8 @@ jiffies_to_compat_timeval(unsigned long jiffies, struct compat_timeval *value)
104 * one divide. 105 * one divide.
105 */ 106 */
106 u64 nsec = (u64)jiffies * TICK_NSEC; 107 u64 nsec = (u64)jiffies * TICK_NSEC;
107 long rem; 108 u32 rem;
108 value->tv_sec = div_long_long_rem(nsec, NSEC_PER_SEC, &rem); 109 value->tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
109 value->tv_usec = rem / NSEC_PER_USEC; 110 value->tv_usec = rem / NSEC_PER_USEC;
110} 111}
111 112
diff --git a/arch/mips/kernel/irixioctl.c b/arch/mips/kernel/irixioctl.c
index 2bde200d5ad0..b39bdba82e02 100644
--- a/arch/mips/kernel/irixioctl.c
+++ b/arch/mips/kernel/irixioctl.c
@@ -27,33 +27,6 @@ struct irix_termios {
27 cc_t c_cc[NCCS]; 27 cc_t c_cc[NCCS];
28}; 28};
29 29
30extern void start_tty(struct tty_struct *tty);
31static struct tty_struct *get_tty(int fd)
32{
33 struct file *filp;
34 struct tty_struct *ttyp = NULL;
35
36 rcu_read_lock();
37 filp = fcheck(fd);
38 if(filp && filp->private_data) {
39 ttyp = (struct tty_struct *) filp->private_data;
40
41 if(ttyp->magic != TTY_MAGIC)
42 ttyp =NULL;
43 }
44 rcu_read_unlock();
45 return ttyp;
46}
47
48static struct tty_struct *get_real_tty(struct tty_struct *tp)
49{
50 if (tp->driver->type == TTY_DRIVER_TYPE_PTY &&
51 tp->driver->subtype == PTY_TYPE_MASTER)
52 return tp->link;
53 else
54 return tp;
55}
56
57asmlinkage int irix_ioctl(int fd, unsigned long cmd, unsigned long arg) 30asmlinkage int irix_ioctl(int fd, unsigned long cmd, unsigned long arg)
58{ 31{
59 struct tty_struct *tp, *rtp; 32 struct tty_struct *tp, *rtp;
@@ -146,34 +119,24 @@ asmlinkage int irix_ioctl(int fd, unsigned long cmd, unsigned long arg)
146 error = sys_ioctl(fd, TIOCNOTTY, arg); 119 error = sys_ioctl(fd, TIOCNOTTY, arg);
147 break; 120 break;
148 121
149 case 0x00007416: 122 case 0x00007416: {
123 pid_t pid;
150#ifdef DEBUG_IOCTLS 124#ifdef DEBUG_IOCTLS
151 printk("TIOCGSID, %08lx) ", arg); 125 printk("TIOCGSID, %08lx) ", arg);
152#endif 126#endif
153 tp = get_tty(fd); 127 old_fs = get_fs(); set_fs(get_ds());
154 if(!tp) { 128 error = sys_ioctl(fd, TIOCGSID, (unsigned long)&pid);
155 error = -EINVAL; 129 set_fs(old_fs);
156 break; 130 if (!error)
157 } 131 error = put_user(pid, (unsigned long __user *) arg);
158 rtp = get_real_tty(tp);
159#ifdef DEBUG_IOCTLS
160 printk("rtp->session=%d ", rtp->session);
161#endif
162 error = put_user(rtp->session, (unsigned long __user *) arg);
163 break; 132 break;
164 133 }
165 case 0x746e: 134 case 0x746e:
166 /* TIOCSTART, same effect as hitting ^Q */ 135 /* TIOCSTART, same effect as hitting ^Q */
167#ifdef DEBUG_IOCTLS 136#ifdef DEBUG_IOCTLS
168 printk("TIOCSTART, %08lx) ", arg); 137 printk("TIOCSTART, %08lx) ", arg);
169#endif 138#endif
170 tp = get_tty(fd); 139 error = sys_ioctl(fd, TCXONC, TCOON);
171 if(!tp) {
172 error = -EINVAL;
173 break;
174 }
175 rtp = get_real_tty(tp);
176 start_tty(rtp);
177 break; 140 break;
178 141
179 case 0x20006968: 142 case 0x20006968:
diff --git a/arch/mips/kernel/kspd.c b/arch/mips/kernel/kspd.c
index 998c4efcce88..ceb62dce1c9c 100644
--- a/arch/mips/kernel/kspd.c
+++ b/arch/mips/kernel/kspd.c
@@ -20,6 +20,7 @@
20#include <linux/sched.h> 20#include <linux/sched.h>
21#include <linux/unistd.h> 21#include <linux/unistd.h>
22#include <linux/file.h> 22#include <linux/file.h>
23#include <linux/fdtable.h>
23#include <linux/fs.h> 24#include <linux/fs.h>
24#include <linux/syscalls.h> 25#include <linux/syscalls.h>
25#include <linux/workqueue.h> 26#include <linux/workqueue.h>
diff --git a/arch/mn10300/kernel/sys_mn10300.c b/arch/mn10300/kernel/sys_mn10300.c
index 5f17a1ebc825..bca5a84dc72c 100644
--- a/arch/mn10300/kernel/sys_mn10300.c
+++ b/arch/mn10300/kernel/sys_mn10300.c
@@ -29,23 +29,6 @@
29#define MIN_MAP_ADDR PAGE_SIZE /* minimum fixed mmap address */ 29#define MIN_MAP_ADDR PAGE_SIZE /* minimum fixed mmap address */
30 30
31/* 31/*
32 * sys_pipe() is the normal C calling standard for creating
33 * a pipe. It's not the way Unix traditionally does this, though.
34 */
35asmlinkage long sys_pipe(unsigned long __user *fildes)
36{
37 int fd[2];
38 int error;
39
40 error = do_pipe(fd);
41 if (!error) {
42 if (copy_to_user(fildes, fd, 2 * sizeof(int)))
43 error = -EFAULT;
44 }
45 return error;
46}
47
48/*
49 * memory mapping syscall 32 * memory mapping syscall
50 */ 33 */
51asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, 34asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
index 4f589216b39e..71b31957c8f1 100644
--- a/arch/parisc/kernel/sys_parisc.c
+++ b/arch/parisc/kernel/sys_parisc.c
@@ -33,19 +33,6 @@
33#include <linux/utsname.h> 33#include <linux/utsname.h>
34#include <linux/personality.h> 34#include <linux/personality.h>
35 35
36int sys_pipe(int __user *fildes)
37{
38 int fd[2];
39 int error;
40
41 error = do_pipe(fd);
42 if (!error) {
43 if (copy_to_user(fildes, fd, 2*sizeof(int)))
44 error = -EFAULT;
45 }
46 return error;
47}
48
49static unsigned long get_unshared_area(unsigned long addr, unsigned long len) 36static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
50{ 37{
51 struct vm_area_struct *vma; 38 struct vm_area_struct *vma;
diff --git a/arch/powerpc/boot/dts/cm5200.dts b/arch/powerpc/boot/dts/cm5200.dts
index c6ca6319e4f7..2f74cc4e093e 100644
--- a/arch/powerpc/boot/dts/cm5200.dts
+++ b/arch/powerpc/boot/dts/cm5200.dts
@@ -10,11 +10,7 @@
10 * option) any later version. 10 * option) any later version.
11 */ 11 */
12 12
13/* 13/dts-v1/;
14 * WARNING: Do not depend on this tree layout remaining static just yet.
15 * The MPC5200 device tree conventions are still in flux
16 * Keep an eye on the linuxppc-dev mailing list for more details
17 */
18 14
19/ { 15/ {
20 model = "schindler,cm5200"; 16 model = "schindler,cm5200";
@@ -29,10 +25,10 @@
29 PowerPC,5200@0 { 25 PowerPC,5200@0 {
30 device_type = "cpu"; 26 device_type = "cpu";
31 reg = <0>; 27 reg = <0>;
32 d-cache-line-size = <20>; 28 d-cache-line-size = <32>;
33 i-cache-line-size = <20>; 29 i-cache-line-size = <32>;
34 d-cache-size = <4000>; // L1, 16K 30 d-cache-size = <0x4000>; // L1, 16K
35 i-cache-size = <4000>; // L1, 16K 31 i-cache-size = <0x4000>; // L1, 16K
36 timebase-frequency = <0>; // from bootloader 32 timebase-frequency = <0>; // from bootloader
37 bus-frequency = <0>; // from bootloader 33 bus-frequency = <0>; // from bootloader
38 clock-frequency = <0>; // from bootloader 34 clock-frequency = <0>; // from bootloader
@@ -41,34 +37,34 @@
41 37
42 memory { 38 memory {
43 device_type = "memory"; 39 device_type = "memory";
44 reg = <00000000 04000000>; // 64MB 40 reg = <0x00000000 0x04000000>; // 64MB
45 }; 41 };
46 42
47 soc5200@f0000000 { 43 soc5200@f0000000 {
48 #address-cells = <1>; 44 #address-cells = <1>;
49 #size-cells = <1>; 45 #size-cells = <1>;
50 compatible = "fsl,mpc5200b-immr"; 46 compatible = "fsl,mpc5200b-immr";
51 ranges = <0 f0000000 0000c000>; 47 ranges = <0 0xf0000000 0x0000c000>;
52 reg = <f0000000 00000100>; 48 reg = <0xf0000000 0x00000100>;
53 bus-frequency = <0>; // from bootloader 49 bus-frequency = <0>; // from bootloader
54 system-frequency = <0>; // from bootloader 50 system-frequency = <0>; // from bootloader
55 51
56 cdm@200 { 52 cdm@200 {
57 compatible = "fsl,mpc5200b-cdm","fsl,mpc5200-cdm"; 53 compatible = "fsl,mpc5200b-cdm","fsl,mpc5200-cdm";
58 reg = <200 38>; 54 reg = <0x200 0x38>;
59 }; 55 };
60 56
61 mpc5200_pic: pic@500 { 57 mpc5200_pic: interrupt-controller@500 {
62 // 5200 interrupts are encoded into two levels; 58 // 5200 interrupts are encoded into two levels;
63 interrupt-controller; 59 interrupt-controller;
64 #interrupt-cells = <3>; 60 #interrupt-cells = <3>;
65 compatible = "fsl,mpc5200b-pic","fsl,mpc5200-pic"; 61 compatible = "fsl,mpc5200b-pic","fsl,mpc5200-pic";
66 reg = <500 80>; 62 reg = <0x500 0x80>;
67 }; 63 };
68 64
69 timer@600 { // General Purpose Timer 65 timer@600 { // General Purpose Timer
70 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 66 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
71 reg = <600 10>; 67 reg = <0x600 0x10>;
72 interrupts = <1 9 0>; 68 interrupts = <1 9 0>;
73 interrupt-parent = <&mpc5200_pic>; 69 interrupt-parent = <&mpc5200_pic>;
74 fsl,has-wdt; 70 fsl,has-wdt;
@@ -76,108 +72,108 @@
76 72
77 timer@610 { // General Purpose Timer 73 timer@610 { // General Purpose Timer
78 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 74 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
79 reg = <610 10>; 75 reg = <0x610 0x10>;
80 interrupts = <1 a 0>; 76 interrupts = <1 10 0>;
81 interrupt-parent = <&mpc5200_pic>; 77 interrupt-parent = <&mpc5200_pic>;
82 }; 78 };
83 79
84 timer@620 { // General Purpose Timer 80 timer@620 { // General Purpose Timer
85 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 81 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
86 reg = <620 10>; 82 reg = <0x620 0x10>;
87 interrupts = <1 b 0>; 83 interrupts = <1 11 0>;
88 interrupt-parent = <&mpc5200_pic>; 84 interrupt-parent = <&mpc5200_pic>;
89 }; 85 };
90 86
91 timer@630 { // General Purpose Timer 87 timer@630 { // General Purpose Timer
92 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 88 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
93 reg = <630 10>; 89 reg = <0x630 0x10>;
94 interrupts = <1 c 0>; 90 interrupts = <1 12 0>;
95 interrupt-parent = <&mpc5200_pic>; 91 interrupt-parent = <&mpc5200_pic>;
96 }; 92 };
97 93
98 timer@640 { // General Purpose Timer 94 timer@640 { // General Purpose Timer
99 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 95 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
100 reg = <640 10>; 96 reg = <0x640 0x10>;
101 interrupts = <1 d 0>; 97 interrupts = <1 13 0>;
102 interrupt-parent = <&mpc5200_pic>; 98 interrupt-parent = <&mpc5200_pic>;
103 }; 99 };
104 100
105 timer@650 { // General Purpose Timer 101 timer@650 { // General Purpose Timer
106 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 102 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
107 reg = <650 10>; 103 reg = <0x650 0x10>;
108 interrupts = <1 e 0>; 104 interrupts = <1 14 0>;
109 interrupt-parent = <&mpc5200_pic>; 105 interrupt-parent = <&mpc5200_pic>;
110 }; 106 };
111 107
112 timer@660 { // General Purpose Timer 108 timer@660 { // General Purpose Timer
113 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 109 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
114 reg = <660 10>; 110 reg = <0x660 0x10>;
115 interrupts = <1 f 0>; 111 interrupts = <1 15 0>;
116 interrupt-parent = <&mpc5200_pic>; 112 interrupt-parent = <&mpc5200_pic>;
117 }; 113 };
118 114
119 timer@670 { // General Purpose Timer 115 timer@670 { // General Purpose Timer
120 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 116 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
121 reg = <670 10>; 117 reg = <0x670 0x10>;
122 interrupts = <1 10 0>; 118 interrupts = <1 16 0>;
123 interrupt-parent = <&mpc5200_pic>; 119 interrupt-parent = <&mpc5200_pic>;
124 }; 120 };
125 121
126 rtc@800 { // Real time clock 122 rtc@800 { // Real time clock
127 compatible = "fsl,mpc5200b-rtc","fsl,mpc5200-rtc"; 123 compatible = "fsl,mpc5200b-rtc","fsl,mpc5200-rtc";
128 reg = <800 100>; 124 reg = <0x800 0x100>;
129 interrupts = <1 5 0 1 6 0>; 125 interrupts = <1 5 0 1 6 0>;
130 interrupt-parent = <&mpc5200_pic>; 126 interrupt-parent = <&mpc5200_pic>;
131 }; 127 };
132 128
133 gpio@b00 { 129 gpio@b00 {
134 compatible = "fsl,mpc5200b-gpio","fsl,mpc5200-gpio"; 130 compatible = "fsl,mpc5200b-gpio","fsl,mpc5200-gpio";
135 reg = <b00 40>; 131 reg = <0xb00 0x40>;
136 interrupts = <1 7 0>; 132 interrupts = <1 7 0>;
137 interrupt-parent = <&mpc5200_pic>; 133 interrupt-parent = <&mpc5200_pic>;
138 }; 134 };
139 135
140 gpio@c00 { 136 gpio@c00 {
141 compatible = "fsl,mpc5200b-gpio-wkup","fsl,mpc5200-gpio-wkup"; 137 compatible = "fsl,mpc5200b-gpio-wkup","fsl,mpc5200-gpio-wkup";
142 reg = <c00 40>; 138 reg = <0xc00 0x40>;
143 interrupts = <1 8 0 0 3 0>; 139 interrupts = <1 8 0 0 3 0>;
144 interrupt-parent = <&mpc5200_pic>; 140 interrupt-parent = <&mpc5200_pic>;
145 }; 141 };
146 142
147 spi@f00 { 143 spi@f00 {
148 compatible = "fsl,mpc5200b-spi","fsl,mpc5200-spi"; 144 compatible = "fsl,mpc5200b-spi","fsl,mpc5200-spi";
149 reg = <f00 20>; 145 reg = <0xf00 0x20>;
150 interrupts = <2 d 0 2 e 0>; 146 interrupts = <2 13 0 2 14 0>;
151 interrupt-parent = <&mpc5200_pic>; 147 interrupt-parent = <&mpc5200_pic>;
152 }; 148 };
153 149
154 usb@1000 { 150 usb@1000 {
155 compatible = "fsl,mpc5200b-ohci","fsl,mpc5200-ohci","ohci-be"; 151 compatible = "fsl,mpc5200b-ohci","fsl,mpc5200-ohci","ohci-be";
156 reg = <1000 ff>; 152 reg = <0x1000 0xff>;
157 interrupts = <2 6 0>; 153 interrupts = <2 6 0>;
158 interrupt-parent = <&mpc5200_pic>; 154 interrupt-parent = <&mpc5200_pic>;
159 }; 155 };
160 156
161 dma-controller@1200 { 157 dma-controller@1200 {
162 compatible = "fsl,mpc5200b-bestcomm","fsl,mpc5200-bestcomm"; 158 compatible = "fsl,mpc5200b-bestcomm","fsl,mpc5200-bestcomm";
163 reg = <1200 80>; 159 reg = <0x1200 0x80>;
164 interrupts = <3 0 0 3 1 0 3 2 0 3 3 0 160 interrupts = <3 0 0 3 1 0 3 2 0 3 3 0
165 3 4 0 3 5 0 3 6 0 3 7 0 161 3 4 0 3 5 0 3 6 0 3 7 0
166 3 8 0 3 9 0 3 a 0 3 b 0 162 3 8 0 3 9 0 3 10 0 3 11 0
167 3 c 0 3 d 0 3 e 0 3 f 0>; 163 3 12 0 3 13 0 3 14 0 3 15 0>;
168 interrupt-parent = <&mpc5200_pic>; 164 interrupt-parent = <&mpc5200_pic>;
169 }; 165 };
170 166
171 xlb@1f00 { 167 xlb@1f00 {
172 compatible = "fsl,mpc5200b-xlb","fsl,mpc5200-xlb"; 168 compatible = "fsl,mpc5200b-xlb","fsl,mpc5200-xlb";
173 reg = <1f00 100>; 169 reg = <0x1f00 0x100>;
174 }; 170 };
175 171
176 serial@2000 { // PSC1 172 serial@2000 { // PSC1
177 device_type = "serial"; 173 device_type = "serial";
178 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 174 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
179 port-number = <0>; // Logical port assignment 175 port-number = <0>; // Logical port assignment
180 reg = <2000 100>; 176 reg = <0x2000 0x100>;
181 interrupts = <2 1 0>; 177 interrupts = <2 1 0>;
182 interrupt-parent = <&mpc5200_pic>; 178 interrupt-parent = <&mpc5200_pic>;
183 }; 179 };
@@ -186,7 +182,7 @@
186 device_type = "serial"; 182 device_type = "serial";
187 compatible = "fsl,mpc5200-psc-uart"; 183 compatible = "fsl,mpc5200-psc-uart";
188 port-number = <1>; // Logical port assignment 184 port-number = <1>; // Logical port assignment
189 reg = <2200 100>; 185 reg = <0x2200 0x100>;
190 interrupts = <2 2 0>; 186 interrupts = <2 2 0>;
191 interrupt-parent = <&mpc5200_pic>; 187 interrupt-parent = <&mpc5200_pic>;
192 }; 188 };
@@ -195,7 +191,7 @@
195 device_type = "serial"; 191 device_type = "serial";
196 compatible = "fsl,mpc5200-psc-uart"; 192 compatible = "fsl,mpc5200-psc-uart";
197 port-number = <2>; // Logical port assignment 193 port-number = <2>; // Logical port assignment
198 reg = <2400 100>; 194 reg = <0x2400 0x100>;
199 interrupts = <2 3 0>; 195 interrupts = <2 3 0>;
200 interrupt-parent = <&mpc5200_pic>; 196 interrupt-parent = <&mpc5200_pic>;
201 }; 197 };
@@ -204,7 +200,7 @@
204 device_type = "serial"; 200 device_type = "serial";
205 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 201 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
206 port-number = <5>; // Logical port assignment 202 port-number = <5>; // Logical port assignment
207 reg = <2c00 100>; 203 reg = <0x2c00 0x100>;
208 interrupts = <2 4 0>; 204 interrupts = <2 4 0>;
209 interrupt-parent = <&mpc5200_pic>; 205 interrupt-parent = <&mpc5200_pic>;
210 }; 206 };
@@ -212,7 +208,7 @@
212 ethernet@3000 { 208 ethernet@3000 {
213 device_type = "network"; 209 device_type = "network";
214 compatible = "fsl,mpc5200b-fec","fsl,mpc5200-fec"; 210 compatible = "fsl,mpc5200b-fec","fsl,mpc5200-fec";
215 reg = <3000 400>; 211 reg = <0x3000 0x400>;
216 local-mac-address = [ 00 00 00 00 00 00 ]; 212 local-mac-address = [ 00 00 00 00 00 00 ];
217 interrupts = <2 5 0>; 213 interrupts = <2 5 0>;
218 interrupt-parent = <&mpc5200_pic>; 214 interrupt-parent = <&mpc5200_pic>;
@@ -223,7 +219,7 @@
223 #address-cells = <1>; 219 #address-cells = <1>;
224 #size-cells = <0>; 220 #size-cells = <0>;
225 compatible = "fsl,mpc5200b-mdio","fsl,mpc5200-mdio"; 221 compatible = "fsl,mpc5200b-mdio","fsl,mpc5200-mdio";
226 reg = <3000 400>; // fec range, since we need to setup fec interrupts 222 reg = <0x3000 0x400>; // fec range, since we need to setup fec interrupts
227 interrupts = <2 5 0>; // these are for "mii command finished", not link changes & co. 223 interrupts = <2 5 0>; // these are for "mii command finished", not link changes & co.
228 interrupt-parent = <&mpc5200_pic>; 224 interrupt-parent = <&mpc5200_pic>;
229 225
@@ -237,15 +233,15 @@
237 #address-cells = <1>; 233 #address-cells = <1>;
238 #size-cells = <0>; 234 #size-cells = <0>;
239 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c"; 235 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
240 reg = <3d40 40>; 236 reg = <0x3d40 0x40>;
241 interrupts = <2 10 0>; 237 interrupts = <2 16 0>;
242 interrupt-parent = <&mpc5200_pic>; 238 interrupt-parent = <&mpc5200_pic>;
243 fsl5200-clocking; 239 fsl5200-clocking;
244 }; 240 };
245 241
246 sram@8000 { 242 sram@8000 {
247 compatible = "fsl,mpc5200b-sram","fsl,mpc5200-sram"; 243 compatible = "fsl,mpc5200b-sram","fsl,mpc5200-sram";
248 reg = <8000 4000>; 244 reg = <0x8000 0x4000>;
249 }; 245 };
250 }; 246 };
251 247
@@ -254,12 +250,12 @@
254 compatible = "fsl,lpb"; 250 compatible = "fsl,lpb";
255 #address-cells = <2>; 251 #address-cells = <2>;
256 #size-cells = <1>; 252 #size-cells = <1>;
257 ranges = <0 0 fc000000 2000000>; 253 ranges = <0 0 0xfc000000 0x2000000>;
258 254
259 // 16-bit flash device at LocalPlus Bus CS0 255 // 16-bit flash device at LocalPlus Bus CS0
260 flash@0,0 { 256 flash@0,0 {
261 compatible = "cfi-flash"; 257 compatible = "cfi-flash";
262 reg = <0 0 2000000>; 258 reg = <0 0 0x2000000>;
263 bank-width = <2>; 259 bank-width = <2>;
264 device-width = <2>; 260 device-width = <2>;
265 #size-cells = <1>; 261 #size-cells = <1>;
diff --git a/arch/powerpc/boot/dts/lite5200.dts b/arch/powerpc/boot/dts/lite5200.dts
index 09b4e16154d6..2cf9a8768f44 100644
--- a/arch/powerpc/boot/dts/lite5200.dts
+++ b/arch/powerpc/boot/dts/lite5200.dts
@@ -10,6 +10,8 @@
10 * option) any later version. 10 * option) any later version.
11 */ 11 */
12 12
13/dts-v1/;
14
13/ { 15/ {
14 model = "fsl,lite5200"; 16 model = "fsl,lite5200";
15 compatible = "fsl,lite5200"; 17 compatible = "fsl,lite5200";
@@ -23,10 +25,10 @@
23 PowerPC,5200@0 { 25 PowerPC,5200@0 {
24 device_type = "cpu"; 26 device_type = "cpu";
25 reg = <0>; 27 reg = <0>;
26 d-cache-line-size = <20>; 28 d-cache-line-size = <32>;
27 i-cache-line-size = <20>; 29 i-cache-line-size = <32>;
28 d-cache-size = <4000>; // L1, 16K 30 d-cache-size = <0x4000>; // L1, 16K
29 i-cache-size = <4000>; // L1, 16K 31 i-cache-size = <0x4000>; // L1, 16K
30 timebase-frequency = <0>; // from bootloader 32 timebase-frequency = <0>; // from bootloader
31 bus-frequency = <0>; // from bootloader 33 bus-frequency = <0>; // from bootloader
32 clock-frequency = <0>; // from bootloader 34 clock-frequency = <0>; // from bootloader
@@ -35,21 +37,21 @@
35 37
36 memory { 38 memory {
37 device_type = "memory"; 39 device_type = "memory";
38 reg = <00000000 04000000>; // 64MB 40 reg = <0x00000000 0x04000000>; // 64MB
39 }; 41 };
40 42
41 soc5200@f0000000 { 43 soc5200@f0000000 {
42 #address-cells = <1>; 44 #address-cells = <1>;
43 #size-cells = <1>; 45 #size-cells = <1>;
44 compatible = "fsl,mpc5200-immr"; 46 compatible = "fsl,mpc5200-immr";
45 ranges = <0 f0000000 0000c000>; 47 ranges = <0 0xf0000000 0x0000c000>;
46 reg = <f0000000 00000100>; 48 reg = <0xf0000000 0x00000100>;
47 bus-frequency = <0>; // from bootloader 49 bus-frequency = <0>; // from bootloader
48 system-frequency = <0>; // from bootloader 50 system-frequency = <0>; // from bootloader
49 51
50 cdm@200 { 52 cdm@200 {
51 compatible = "fsl,mpc5200-cdm"; 53 compatible = "fsl,mpc5200-cdm";
52 reg = <200 38>; 54 reg = <0x200 0x38>;
53 }; 55 };
54 56
55 mpc5200_pic: interrupt-controller@500 { 57 mpc5200_pic: interrupt-controller@500 {
@@ -58,13 +60,13 @@
58 #interrupt-cells = <3>; 60 #interrupt-cells = <3>;
59 device_type = "interrupt-controller"; 61 device_type = "interrupt-controller";
60 compatible = "fsl,mpc5200-pic"; 62 compatible = "fsl,mpc5200-pic";
61 reg = <500 80>; 63 reg = <0x500 0x80>;
62 }; 64 };
63 65
64 timer@600 { // General Purpose Timer 66 timer@600 { // General Purpose Timer
65 compatible = "fsl,mpc5200-gpt"; 67 compatible = "fsl,mpc5200-gpt";
66 cell-index = <0>; 68 cell-index = <0>;
67 reg = <600 10>; 69 reg = <0x600 0x10>;
68 interrupts = <1 9 0>; 70 interrupts = <1 9 0>;
69 interrupt-parent = <&mpc5200_pic>; 71 interrupt-parent = <&mpc5200_pic>;
70 fsl,has-wdt; 72 fsl,has-wdt;
@@ -73,63 +75,63 @@
73 timer@610 { // General Purpose Timer 75 timer@610 { // General Purpose Timer
74 compatible = "fsl,mpc5200-gpt"; 76 compatible = "fsl,mpc5200-gpt";
75 cell-index = <1>; 77 cell-index = <1>;
76 reg = <610 10>; 78 reg = <0x610 0x10>;
77 interrupts = <1 a 0>; 79 interrupts = <1 10 0>;
78 interrupt-parent = <&mpc5200_pic>; 80 interrupt-parent = <&mpc5200_pic>;
79 }; 81 };
80 82
81 timer@620 { // General Purpose Timer 83 timer@620 { // General Purpose Timer
82 compatible = "fsl,mpc5200-gpt"; 84 compatible = "fsl,mpc5200-gpt";
83 cell-index = <2>; 85 cell-index = <2>;
84 reg = <620 10>; 86 reg = <0x620 0x10>;
85 interrupts = <1 b 0>; 87 interrupts = <1 11 0>;
86 interrupt-parent = <&mpc5200_pic>; 88 interrupt-parent = <&mpc5200_pic>;
87 }; 89 };
88 90
89 timer@630 { // General Purpose Timer 91 timer@630 { // General Purpose Timer
90 compatible = "fsl,mpc5200-gpt"; 92 compatible = "fsl,mpc5200-gpt";
91 cell-index = <3>; 93 cell-index = <3>;
92 reg = <630 10>; 94 reg = <0x630 0x10>;
93 interrupts = <1 c 0>; 95 interrupts = <1 12 0>;
94 interrupt-parent = <&mpc5200_pic>; 96 interrupt-parent = <&mpc5200_pic>;
95 }; 97 };
96 98
97 timer@640 { // General Purpose Timer 99 timer@640 { // General Purpose Timer
98 compatible = "fsl,mpc5200-gpt"; 100 compatible = "fsl,mpc5200-gpt";
99 cell-index = <4>; 101 cell-index = <4>;
100 reg = <640 10>; 102 reg = <0x640 0x10>;
101 interrupts = <1 d 0>; 103 interrupts = <1 13 0>;
102 interrupt-parent = <&mpc5200_pic>; 104 interrupt-parent = <&mpc5200_pic>;
103 }; 105 };
104 106
105 timer@650 { // General Purpose Timer 107 timer@650 { // General Purpose Timer
106 compatible = "fsl,mpc5200-gpt"; 108 compatible = "fsl,mpc5200-gpt";
107 cell-index = <5>; 109 cell-index = <5>;
108 reg = <650 10>; 110 reg = <0x650 0x10>;
109 interrupts = <1 e 0>; 111 interrupts = <1 14 0>;
110 interrupt-parent = <&mpc5200_pic>; 112 interrupt-parent = <&mpc5200_pic>;
111 }; 113 };
112 114
113 timer@660 { // General Purpose Timer 115 timer@660 { // General Purpose Timer
114 compatible = "fsl,mpc5200-gpt"; 116 compatible = "fsl,mpc5200-gpt";
115 cell-index = <6>; 117 cell-index = <6>;
116 reg = <660 10>; 118 reg = <0x660 0x10>;
117 interrupts = <1 f 0>; 119 interrupts = <1 15 0>;
118 interrupt-parent = <&mpc5200_pic>; 120 interrupt-parent = <&mpc5200_pic>;
119 }; 121 };
120 122
121 timer@670 { // General Purpose Timer 123 timer@670 { // General Purpose Timer
122 compatible = "fsl,mpc5200-gpt"; 124 compatible = "fsl,mpc5200-gpt";
123 cell-index = <7>; 125 cell-index = <7>;
124 reg = <670 10>; 126 reg = <0x670 0x10>;
125 interrupts = <1 10 0>; 127 interrupts = <1 16 0>;
126 interrupt-parent = <&mpc5200_pic>; 128 interrupt-parent = <&mpc5200_pic>;
127 }; 129 };
128 130
129 rtc@800 { // Real time clock 131 rtc@800 { // Real time clock
130 compatible = "fsl,mpc5200-rtc"; 132 compatible = "fsl,mpc5200-rtc";
131 device_type = "rtc"; 133 device_type = "rtc";
132 reg = <800 100>; 134 reg = <0x800 0x100>;
133 interrupts = <1 5 0 1 6 0>; 135 interrupts = <1 5 0 1 6 0>;
134 interrupt-parent = <&mpc5200_pic>; 136 interrupt-parent = <&mpc5200_pic>;
135 }; 137 };
@@ -137,43 +139,43 @@
137 can@900 { 139 can@900 {
138 compatible = "fsl,mpc5200-mscan"; 140 compatible = "fsl,mpc5200-mscan";
139 cell-index = <0>; 141 cell-index = <0>;
140 interrupts = <2 11 0>; 142 interrupts = <2 17 0>;
141 interrupt-parent = <&mpc5200_pic>; 143 interrupt-parent = <&mpc5200_pic>;
142 reg = <900 80>; 144 reg = <0x900 0x80>;
143 }; 145 };
144 146
145 can@980 { 147 can@980 {
146 compatible = "fsl,mpc5200-mscan"; 148 compatible = "fsl,mpc5200-mscan";
147 cell-index = <1>; 149 cell-index = <1>;
148 interrupts = <2 12 0>; 150 interrupts = <2 18 0>;
149 interrupt-parent = <&mpc5200_pic>; 151 interrupt-parent = <&mpc5200_pic>;
150 reg = <980 80>; 152 reg = <0x980 0x80>;
151 }; 153 };
152 154
153 gpio@b00 { 155 gpio@b00 {
154 compatible = "fsl,mpc5200-gpio"; 156 compatible = "fsl,mpc5200-gpio";
155 reg = <b00 40>; 157 reg = <0xb00 0x40>;
156 interrupts = <1 7 0>; 158 interrupts = <1 7 0>;
157 interrupt-parent = <&mpc5200_pic>; 159 interrupt-parent = <&mpc5200_pic>;
158 }; 160 };
159 161
160 gpio@c00 { 162 gpio@c00 {
161 compatible = "fsl,mpc5200-gpio-wkup"; 163 compatible = "fsl,mpc5200-gpio-wkup";
162 reg = <c00 40>; 164 reg = <0xc00 0x40>;
163 interrupts = <1 8 0 0 3 0>; 165 interrupts = <1 8 0 0 3 0>;
164 interrupt-parent = <&mpc5200_pic>; 166 interrupt-parent = <&mpc5200_pic>;
165 }; 167 };
166 168
167 spi@f00 { 169 spi@f00 {
168 compatible = "fsl,mpc5200-spi"; 170 compatible = "fsl,mpc5200-spi";
169 reg = <f00 20>; 171 reg = <0xf00 0x20>;
170 interrupts = <2 d 0 2 e 0>; 172 interrupts = <2 13 0 2 14 0>;
171 interrupt-parent = <&mpc5200_pic>; 173 interrupt-parent = <&mpc5200_pic>;
172 }; 174 };
173 175
174 usb@1000 { 176 usb@1000 {
175 compatible = "fsl,mpc5200-ohci","ohci-be"; 177 compatible = "fsl,mpc5200-ohci","ohci-be";
176 reg = <1000 ff>; 178 reg = <0x1000 0xff>;
177 interrupts = <2 6 0>; 179 interrupts = <2 6 0>;
178 interrupt-parent = <&mpc5200_pic>; 180 interrupt-parent = <&mpc5200_pic>;
179 }; 181 };
@@ -181,17 +183,17 @@
181 dma-controller@1200 { 183 dma-controller@1200 {
182 device_type = "dma-controller"; 184 device_type = "dma-controller";
183 compatible = "fsl,mpc5200-bestcomm"; 185 compatible = "fsl,mpc5200-bestcomm";
184 reg = <1200 80>; 186 reg = <0x1200 0x80>;
185 interrupts = <3 0 0 3 1 0 3 2 0 3 3 0 187 interrupts = <3 0 0 3 1 0 3 2 0 3 3 0
186 3 4 0 3 5 0 3 6 0 3 7 0 188 3 4 0 3 5 0 3 6 0 3 7 0
187 3 8 0 3 9 0 3 a 0 3 b 0 189 3 8 0 3 9 0 3 10 0 3 11 0
188 3 c 0 3 d 0 3 e 0 3 f 0>; 190 3 12 0 3 13 0 3 14 0 3 15 0>;
189 interrupt-parent = <&mpc5200_pic>; 191 interrupt-parent = <&mpc5200_pic>;
190 }; 192 };
191 193
192 xlb@1f00 { 194 xlb@1f00 {
193 compatible = "fsl,mpc5200-xlb"; 195 compatible = "fsl,mpc5200-xlb";
194 reg = <1f00 100>; 196 reg = <0x1f00 0x100>;
195 }; 197 };
196 198
197 serial@2000 { // PSC1 199 serial@2000 { // PSC1
@@ -199,7 +201,7 @@
199 compatible = "fsl,mpc5200-psc-uart"; 201 compatible = "fsl,mpc5200-psc-uart";
200 port-number = <0>; // Logical port assignment 202 port-number = <0>; // Logical port assignment
201 cell-index = <0>; 203 cell-index = <0>;
202 reg = <2000 100>; 204 reg = <0x2000 0x100>;
203 interrupts = <2 1 0>; 205 interrupts = <2 1 0>;
204 interrupt-parent = <&mpc5200_pic>; 206 interrupt-parent = <&mpc5200_pic>;
205 }; 207 };
@@ -208,7 +210,7 @@
208 //ac97@2200 { // PSC2 210 //ac97@2200 { // PSC2
209 // compatible = "fsl,mpc5200-psc-ac97"; 211 // compatible = "fsl,mpc5200-psc-ac97";
210 // cell-index = <1>; 212 // cell-index = <1>;
211 // reg = <2200 100>; 213 // reg = <0x2200 0x100>;
212 // interrupts = <2 2 0>; 214 // interrupts = <2 2 0>;
213 // interrupt-parent = <&mpc5200_pic>; 215 // interrupt-parent = <&mpc5200_pic>;
214 //}; 216 //};
@@ -217,7 +219,7 @@
217 //i2s@2400 { // PSC3 219 //i2s@2400 { // PSC3
218 // compatible = "fsl,mpc5200-psc-i2s"; 220 // compatible = "fsl,mpc5200-psc-i2s";
219 // cell-index = <2>; 221 // cell-index = <2>;
220 // reg = <2400 100>; 222 // reg = <0x2400 0x100>;
221 // interrupts = <2 3 0>; 223 // interrupts = <2 3 0>;
222 // interrupt-parent = <&mpc5200_pic>; 224 // interrupt-parent = <&mpc5200_pic>;
223 //}; 225 //};
@@ -227,8 +229,8 @@
227 // device_type = "serial"; 229 // device_type = "serial";
228 // compatible = "fsl,mpc5200-psc-uart"; 230 // compatible = "fsl,mpc5200-psc-uart";
229 // cell-index = <3>; 231 // cell-index = <3>;
230 // reg = <2600 100>; 232 // reg = <0x2600 0x100>;
231 // interrupts = <2 b 0>; 233 // interrupts = <2 11 0>;
232 // interrupt-parent = <&mpc5200_pic>; 234 // interrupt-parent = <&mpc5200_pic>;
233 //}; 235 //};
234 236
@@ -237,8 +239,8 @@
237 // device_type = "serial"; 239 // device_type = "serial";
238 // compatible = "fsl,mpc5200-psc-uart"; 240 // compatible = "fsl,mpc5200-psc-uart";
239 // cell-index = <4>; 241 // cell-index = <4>;
240 // reg = <2800 100>; 242 // reg = <0x2800 0x100>;
241 // interrupts = <2 c 0>; 243 // interrupts = <2 12 0>;
242 // interrupt-parent = <&mpc5200_pic>; 244 // interrupt-parent = <&mpc5200_pic>;
243 //}; 245 //};
244 246
@@ -246,7 +248,7 @@
246 //spi@2c00 { // PSC6 248 //spi@2c00 { // PSC6
247 // compatible = "fsl,mpc5200-psc-spi"; 249 // compatible = "fsl,mpc5200-psc-spi";
248 // cell-index = <5>; 250 // cell-index = <5>;
249 // reg = <2c00 100>; 251 // reg = <0x2c00 0x100>;
250 // interrupts = <2 4 0>; 252 // interrupts = <2 4 0>;
251 // interrupt-parent = <&mpc5200_pic>; 253 // interrupt-parent = <&mpc5200_pic>;
252 //}; 254 //};
@@ -254,7 +256,7 @@
254 ethernet@3000 { 256 ethernet@3000 {
255 device_type = "network"; 257 device_type = "network";
256 compatible = "fsl,mpc5200-fec"; 258 compatible = "fsl,mpc5200-fec";
257 reg = <3000 800>; 259 reg = <0x3000 0x400>;
258 local-mac-address = [ 00 00 00 00 00 00 ]; 260 local-mac-address = [ 00 00 00 00 00 00 ];
259 interrupts = <2 5 0>; 261 interrupts = <2 5 0>;
260 interrupt-parent = <&mpc5200_pic>; 262 interrupt-parent = <&mpc5200_pic>;
@@ -265,11 +267,11 @@
265 #address-cells = <1>; 267 #address-cells = <1>;
266 #size-cells = <0>; 268 #size-cells = <0>;
267 compatible = "fsl,mpc5200-mdio"; 269 compatible = "fsl,mpc5200-mdio";
268 reg = <3000 400>; // fec range, since we need to setup fec interrupts 270 reg = <0x3000 0x400>; // fec range, since we need to setup fec interrupts
269 interrupts = <2 5 0>; // these are for "mii command finished", not link changes & co. 271 interrupts = <2 5 0>; // these are for "mii command finished", not link changes & co.
270 interrupt-parent = <&mpc5200_pic>; 272 interrupt-parent = <&mpc5200_pic>;
271 273
272 phy0:ethernet-phy@1 { 274 phy0: ethernet-phy@1 {
273 device_type = "ethernet-phy"; 275 device_type = "ethernet-phy";
274 reg = <1>; 276 reg = <1>;
275 }; 277 };
@@ -278,7 +280,7 @@
278 ata@3a00 { 280 ata@3a00 {
279 device_type = "ata"; 281 device_type = "ata";
280 compatible = "fsl,mpc5200-ata"; 282 compatible = "fsl,mpc5200-ata";
281 reg = <3a00 100>; 283 reg = <0x3a00 0x100>;
282 interrupts = <2 7 0>; 284 interrupts = <2 7 0>;
283 interrupt-parent = <&mpc5200_pic>; 285 interrupt-parent = <&mpc5200_pic>;
284 }; 286 };
@@ -288,8 +290,8 @@
288 #size-cells = <0>; 290 #size-cells = <0>;
289 compatible = "fsl,mpc5200-i2c","fsl-i2c"; 291 compatible = "fsl,mpc5200-i2c","fsl-i2c";
290 cell-index = <0>; 292 cell-index = <0>;
291 reg = <3d00 40>; 293 reg = <0x3d00 0x40>;
292 interrupts = <2 f 0>; 294 interrupts = <2 15 0>;
293 interrupt-parent = <&mpc5200_pic>; 295 interrupt-parent = <&mpc5200_pic>;
294 fsl5200-clocking; 296 fsl5200-clocking;
295 }; 297 };
@@ -299,14 +301,14 @@
299 #size-cells = <0>; 301 #size-cells = <0>;
300 compatible = "fsl,mpc5200-i2c","fsl-i2c"; 302 compatible = "fsl,mpc5200-i2c","fsl-i2c";
301 cell-index = <1>; 303 cell-index = <1>;
302 reg = <3d40 40>; 304 reg = <0x3d40 0x40>;
303 interrupts = <2 10 0>; 305 interrupts = <2 16 0>;
304 interrupt-parent = <&mpc5200_pic>; 306 interrupt-parent = <&mpc5200_pic>;
305 fsl5200-clocking; 307 fsl5200-clocking;
306 }; 308 };
307 sram@8000 { 309 sram@8000 {
308 compatible = "fsl,mpc5200-sram","sram"; 310 compatible = "fsl,mpc5200-sram","sram";
309 reg = <8000 4000>; 311 reg = <0x8000 0x4000>;
310 }; 312 };
311 }; 313 };
312 314
@@ -316,18 +318,18 @@
316 #address-cells = <3>; 318 #address-cells = <3>;
317 device_type = "pci"; 319 device_type = "pci";
318 compatible = "fsl,mpc5200-pci"; 320 compatible = "fsl,mpc5200-pci";
319 reg = <f0000d00 100>; 321 reg = <0xf0000d00 0x100>;
320 interrupt-map-mask = <f800 0 0 7>; 322 interrupt-map-mask = <0xf800 0 0 7>;
321 interrupt-map = <c000 0 0 1 &mpc5200_pic 0 0 3 323 interrupt-map = <0xc000 0 0 1 &mpc5200_pic 0 0 3
322 c000 0 0 2 &mpc5200_pic 0 0 3 324 0xc000 0 0 2 &mpc5200_pic 0 0 3
323 c000 0 0 3 &mpc5200_pic 0 0 3 325 0xc000 0 0 3 &mpc5200_pic 0 0 3
324 c000 0 0 4 &mpc5200_pic 0 0 3>; 326 0xc000 0 0 4 &mpc5200_pic 0 0 3>;
325 clock-frequency = <0>; // From boot loader 327 clock-frequency = <0>; // From boot loader
326 interrupts = <2 8 0 2 9 0 2 a 0>; 328 interrupts = <2 8 0 2 9 0 2 10 0>;
327 interrupt-parent = <&mpc5200_pic>; 329 interrupt-parent = <&mpc5200_pic>;
328 bus-range = <0 0>; 330 bus-range = <0 0>;
329 ranges = <42000000 0 80000000 80000000 0 20000000 331 ranges = <0x42000000 0 0x80000000 0x80000000 0 0x20000000
330 02000000 0 a0000000 a0000000 0 10000000 332 0x02000000 0 0xa0000000 0xa0000000 0 0x10000000
331 01000000 0 00000000 b0000000 0 01000000>; 333 0x01000000 0 0x00000000 0xb0000000 0 0x01000000>;
332 }; 334 };
333}; 335};
diff --git a/arch/powerpc/boot/dts/lite5200b.dts b/arch/powerpc/boot/dts/lite5200b.dts
index 2e9bc397ae9a..7bd5b9c399b8 100644
--- a/arch/powerpc/boot/dts/lite5200b.dts
+++ b/arch/powerpc/boot/dts/lite5200b.dts
@@ -10,11 +10,7 @@
10 * option) any later version. 10 * option) any later version.
11 */ 11 */
12 12
13/* 13/dts-v1/;
14 * WARNING: Do not depend on this tree layout remaining static just yet.
15 * The MPC5200 device tree conventions are still in flux
16 * Keep an eye on the linuxppc-dev mailing list for more details
17 */
18 14
19/ { 15/ {
20 model = "fsl,lite5200b"; 16 model = "fsl,lite5200b";
@@ -29,10 +25,10 @@
29 PowerPC,5200@0 { 25 PowerPC,5200@0 {
30 device_type = "cpu"; 26 device_type = "cpu";
31 reg = <0>; 27 reg = <0>;
32 d-cache-line-size = <20>; 28 d-cache-line-size = <32>;
33 i-cache-line-size = <20>; 29 i-cache-line-size = <32>;
34 d-cache-size = <4000>; // L1, 16K 30 d-cache-size = <0x4000>; // L1, 16K
35 i-cache-size = <4000>; // L1, 16K 31 i-cache-size = <0x4000>; // L1, 16K
36 timebase-frequency = <0>; // from bootloader 32 timebase-frequency = <0>; // from bootloader
37 bus-frequency = <0>; // from bootloader 33 bus-frequency = <0>; // from bootloader
38 clock-frequency = <0>; // from bootloader 34 clock-frequency = <0>; // from bootloader
@@ -41,21 +37,21 @@
41 37
42 memory { 38 memory {
43 device_type = "memory"; 39 device_type = "memory";
44 reg = <00000000 10000000>; // 256MB 40 reg = <0x00000000 0x10000000>; // 256MB
45 }; 41 };
46 42
47 soc5200@f0000000 { 43 soc5200@f0000000 {
48 #address-cells = <1>; 44 #address-cells = <1>;
49 #size-cells = <1>; 45 #size-cells = <1>;
50 compatible = "fsl,mpc5200b-immr"; 46 compatible = "fsl,mpc5200b-immr";
51 ranges = <0 f0000000 0000c000>; 47 ranges = <0 0xf0000000 0x0000c000>;
52 reg = <f0000000 00000100>; 48 reg = <0xf0000000 0x00000100>;
53 bus-frequency = <0>; // from bootloader 49 bus-frequency = <0>; // from bootloader
54 system-frequency = <0>; // from bootloader 50 system-frequency = <0>; // from bootloader
55 51
56 cdm@200 { 52 cdm@200 {
57 compatible = "fsl,mpc5200b-cdm","fsl,mpc5200-cdm"; 53 compatible = "fsl,mpc5200b-cdm","fsl,mpc5200-cdm";
58 reg = <200 38>; 54 reg = <0x200 0x38>;
59 }; 55 };
60 56
61 mpc5200_pic: interrupt-controller@500 { 57 mpc5200_pic: interrupt-controller@500 {
@@ -64,13 +60,13 @@
64 #interrupt-cells = <3>; 60 #interrupt-cells = <3>;
65 device_type = "interrupt-controller"; 61 device_type = "interrupt-controller";
66 compatible = "fsl,mpc5200b-pic","fsl,mpc5200-pic"; 62 compatible = "fsl,mpc5200b-pic","fsl,mpc5200-pic";
67 reg = <500 80>; 63 reg = <0x500 0x80>;
68 }; 64 };
69 65
70 timer@600 { // General Purpose Timer 66 timer@600 { // General Purpose Timer
71 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 67 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
72 cell-index = <0>; 68 cell-index = <0>;
73 reg = <600 10>; 69 reg = <0x600 0x10>;
74 interrupts = <1 9 0>; 70 interrupts = <1 9 0>;
75 interrupt-parent = <&mpc5200_pic>; 71 interrupt-parent = <&mpc5200_pic>;
76 fsl,has-wdt; 72 fsl,has-wdt;
@@ -79,63 +75,63 @@
79 timer@610 { // General Purpose Timer 75 timer@610 { // General Purpose Timer
80 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 76 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
81 cell-index = <1>; 77 cell-index = <1>;
82 reg = <610 10>; 78 reg = <0x610 0x10>;
83 interrupts = <1 a 0>; 79 interrupts = <1 10 0>;
84 interrupt-parent = <&mpc5200_pic>; 80 interrupt-parent = <&mpc5200_pic>;
85 }; 81 };
86 82
87 timer@620 { // General Purpose Timer 83 timer@620 { // General Purpose Timer
88 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 84 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
89 cell-index = <2>; 85 cell-index = <2>;
90 reg = <620 10>; 86 reg = <0x620 0x10>;
91 interrupts = <1 b 0>; 87 interrupts = <1 11 0>;
92 interrupt-parent = <&mpc5200_pic>; 88 interrupt-parent = <&mpc5200_pic>;
93 }; 89 };
94 90
95 timer@630 { // General Purpose Timer 91 timer@630 { // General Purpose Timer
96 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 92 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
97 cell-index = <3>; 93 cell-index = <3>;
98 reg = <630 10>; 94 reg = <0x630 0x10>;
99 interrupts = <1 c 0>; 95 interrupts = <1 12 0>;
100 interrupt-parent = <&mpc5200_pic>; 96 interrupt-parent = <&mpc5200_pic>;
101 }; 97 };
102 98
103 timer@640 { // General Purpose Timer 99 timer@640 { // General Purpose Timer
104 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 100 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
105 cell-index = <4>; 101 cell-index = <4>;
106 reg = <640 10>; 102 reg = <0x640 0x10>;
107 interrupts = <1 d 0>; 103 interrupts = <1 13 0>;
108 interrupt-parent = <&mpc5200_pic>; 104 interrupt-parent = <&mpc5200_pic>;
109 }; 105 };
110 106
111 timer@650 { // General Purpose Timer 107 timer@650 { // General Purpose Timer
112 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 108 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
113 cell-index = <5>; 109 cell-index = <5>;
114 reg = <650 10>; 110 reg = <0x650 0x10>;
115 interrupts = <1 e 0>; 111 interrupts = <1 14 0>;
116 interrupt-parent = <&mpc5200_pic>; 112 interrupt-parent = <&mpc5200_pic>;
117 }; 113 };
118 114
119 timer@660 { // General Purpose Timer 115 timer@660 { // General Purpose Timer
120 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 116 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
121 cell-index = <6>; 117 cell-index = <6>;
122 reg = <660 10>; 118 reg = <0x660 0x10>;
123 interrupts = <1 f 0>; 119 interrupts = <1 15 0>;
124 interrupt-parent = <&mpc5200_pic>; 120 interrupt-parent = <&mpc5200_pic>;
125 }; 121 };
126 122
127 timer@670 { // General Purpose Timer 123 timer@670 { // General Purpose Timer
128 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 124 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
129 cell-index = <7>; 125 cell-index = <7>;
130 reg = <670 10>; 126 reg = <0x670 0x10>;
131 interrupts = <1 10 0>; 127 interrupts = <1 16 0>;
132 interrupt-parent = <&mpc5200_pic>; 128 interrupt-parent = <&mpc5200_pic>;
133 }; 129 };
134 130
135 rtc@800 { // Real time clock 131 rtc@800 { // Real time clock
136 compatible = "fsl,mpc5200b-rtc","fsl,mpc5200-rtc"; 132 compatible = "fsl,mpc5200b-rtc","fsl,mpc5200-rtc";
137 device_type = "rtc"; 133 device_type = "rtc";
138 reg = <800 100>; 134 reg = <0x800 0x100>;
139 interrupts = <1 5 0 1 6 0>; 135 interrupts = <1 5 0 1 6 0>;
140 interrupt-parent = <&mpc5200_pic>; 136 interrupt-parent = <&mpc5200_pic>;
141 }; 137 };
@@ -143,43 +139,43 @@
143 can@900 { 139 can@900 {
144 compatible = "fsl,mpc5200b-mscan","fsl,mpc5200-mscan"; 140 compatible = "fsl,mpc5200b-mscan","fsl,mpc5200-mscan";
145 cell-index = <0>; 141 cell-index = <0>;
146 interrupts = <2 11 0>; 142 interrupts = <2 17 0>;
147 interrupt-parent = <&mpc5200_pic>; 143 interrupt-parent = <&mpc5200_pic>;
148 reg = <900 80>; 144 reg = <0x900 0x80>;
149 }; 145 };
150 146
151 can@980 { 147 can@980 {
152 compatible = "fsl,mpc5200b-mscan","fsl,mpc5200-mscan"; 148 compatible = "fsl,mpc5200b-mscan","fsl,mpc5200-mscan";
153 cell-index = <1>; 149 cell-index = <1>;
154 interrupts = <2 12 0>; 150 interrupts = <2 18 0>;
155 interrupt-parent = <&mpc5200_pic>; 151 interrupt-parent = <&mpc5200_pic>;
156 reg = <980 80>; 152 reg = <0x980 0x80>;
157 }; 153 };
158 154
159 gpio@b00 { 155 gpio@b00 {
160 compatible = "fsl,mpc5200b-gpio","fsl,mpc5200-gpio"; 156 compatible = "fsl,mpc5200b-gpio","fsl,mpc5200-gpio";
161 reg = <b00 40>; 157 reg = <0xb00 0x40>;
162 interrupts = <1 7 0>; 158 interrupts = <1 7 0>;
163 interrupt-parent = <&mpc5200_pic>; 159 interrupt-parent = <&mpc5200_pic>;
164 }; 160 };
165 161
166 gpio@c00 { 162 gpio@c00 {
167 compatible = "fsl,mpc5200b-gpio-wkup","fsl,mpc5200-gpio-wkup"; 163 compatible = "fsl,mpc5200b-gpio-wkup","fsl,mpc5200-gpio-wkup";
168 reg = <c00 40>; 164 reg = <0xc00 0x40>;
169 interrupts = <1 8 0 0 3 0>; 165 interrupts = <1 8 0 0 3 0>;
170 interrupt-parent = <&mpc5200_pic>; 166 interrupt-parent = <&mpc5200_pic>;
171 }; 167 };
172 168
173 spi@f00 { 169 spi@f00 {
174 compatible = "fsl,mpc5200b-spi","fsl,mpc5200-spi"; 170 compatible = "fsl,mpc5200b-spi","fsl,mpc5200-spi";
175 reg = <f00 20>; 171 reg = <0xf00 0x20>;
176 interrupts = <2 d 0 2 e 0>; 172 interrupts = <2 13 0 2 14 0>;
177 interrupt-parent = <&mpc5200_pic>; 173 interrupt-parent = <&mpc5200_pic>;
178 }; 174 };
179 175
180 usb@1000 { 176 usb@1000 {
181 compatible = "fsl,mpc5200b-ohci","fsl,mpc5200-ohci","ohci-be"; 177 compatible = "fsl,mpc5200b-ohci","fsl,mpc5200-ohci","ohci-be";
182 reg = <1000 ff>; 178 reg = <0x1000 0xff>;
183 interrupts = <2 6 0>; 179 interrupts = <2 6 0>;
184 interrupt-parent = <&mpc5200_pic>; 180 interrupt-parent = <&mpc5200_pic>;
185 }; 181 };
@@ -187,17 +183,17 @@
187 dma-controller@1200 { 183 dma-controller@1200 {
188 device_type = "dma-controller"; 184 device_type = "dma-controller";
189 compatible = "fsl,mpc5200b-bestcomm","fsl,mpc5200-bestcomm"; 185 compatible = "fsl,mpc5200b-bestcomm","fsl,mpc5200-bestcomm";
190 reg = <1200 80>; 186 reg = <0x1200 0x80>;
191 interrupts = <3 0 0 3 1 0 3 2 0 3 3 0 187 interrupts = <3 0 0 3 1 0 3 2 0 3 3 0
192 3 4 0 3 5 0 3 6 0 3 7 0 188 3 4 0 3 5 0 3 6 0 3 7 0
193 3 8 0 3 9 0 3 a 0 3 b 0 189 3 8 0 3 9 0 3 10 0 3 11 0
194 3 c 0 3 d 0 3 e 0 3 f 0>; 190 3 12 0 3 13 0 3 14 0 3 15 0>;
195 interrupt-parent = <&mpc5200_pic>; 191 interrupt-parent = <&mpc5200_pic>;
196 }; 192 };
197 193
198 xlb@1f00 { 194 xlb@1f00 {
199 compatible = "fsl,mpc5200b-xlb","fsl,mpc5200-xlb"; 195 compatible = "fsl,mpc5200b-xlb","fsl,mpc5200-xlb";
200 reg = <1f00 100>; 196 reg = <0x1f00 0x100>;
201 }; 197 };
202 198
203 serial@2000 { // PSC1 199 serial@2000 { // PSC1
@@ -205,7 +201,7 @@
205 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 201 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
206 port-number = <0>; // Logical port assignment 202 port-number = <0>; // Logical port assignment
207 cell-index = <0>; 203 cell-index = <0>;
208 reg = <2000 100>; 204 reg = <0x2000 0x100>;
209 interrupts = <2 1 0>; 205 interrupts = <2 1 0>;
210 interrupt-parent = <&mpc5200_pic>; 206 interrupt-parent = <&mpc5200_pic>;
211 }; 207 };
@@ -214,7 +210,7 @@
214 //ac97@2200 { // PSC2 210 //ac97@2200 { // PSC2
215 // compatible = "fsl,mpc5200b-psc-ac97","fsl,mpc5200-psc-ac97"; 211 // compatible = "fsl,mpc5200b-psc-ac97","fsl,mpc5200-psc-ac97";
216 // cell-index = <1>; 212 // cell-index = <1>;
217 // reg = <2200 100>; 213 // reg = <0x2200 0x100>;
218 // interrupts = <2 2 0>; 214 // interrupts = <2 2 0>;
219 // interrupt-parent = <&mpc5200_pic>; 215 // interrupt-parent = <&mpc5200_pic>;
220 //}; 216 //};
@@ -223,7 +219,7 @@
223 //i2s@2400 { // PSC3 219 //i2s@2400 { // PSC3
224 // compatible = "fsl,mpc5200b-psc-i2s"; //not 5200 compatible 220 // compatible = "fsl,mpc5200b-psc-i2s"; //not 5200 compatible
225 // cell-index = <2>; 221 // cell-index = <2>;
226 // reg = <2400 100>; 222 // reg = <0x2400 0x100>;
227 // interrupts = <2 3 0>; 223 // interrupts = <2 3 0>;
228 // interrupt-parent = <&mpc5200_pic>; 224 // interrupt-parent = <&mpc5200_pic>;
229 //}; 225 //};
@@ -233,8 +229,8 @@
233 // device_type = "serial"; 229 // device_type = "serial";
234 // compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 230 // compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
235 // cell-index = <3>; 231 // cell-index = <3>;
236 // reg = <2600 100>; 232 // reg = <0x2600 0x100>;
237 // interrupts = <2 b 0>; 233 // interrupts = <2 11 0>;
238 // interrupt-parent = <&mpc5200_pic>; 234 // interrupt-parent = <&mpc5200_pic>;
239 //}; 235 //};
240 236
@@ -243,8 +239,8 @@
243 // device_type = "serial"; 239 // device_type = "serial";
244 // compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 240 // compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
245 // cell-index = <4>; 241 // cell-index = <4>;
246 // reg = <2800 100>; 242 // reg = <0x2800 0x100>;
247 // interrupts = <2 c 0>; 243 // interrupts = <2 12 0>;
248 // interrupt-parent = <&mpc5200_pic>; 244 // interrupt-parent = <&mpc5200_pic>;
249 //}; 245 //};
250 246
@@ -252,7 +248,7 @@
252 //spi@2c00 { // PSC6 248 //spi@2c00 { // PSC6
253 // compatible = "fsl,mpc5200b-psc-spi","fsl,mpc5200-psc-spi"; 249 // compatible = "fsl,mpc5200b-psc-spi","fsl,mpc5200-psc-spi";
254 // cell-index = <5>; 250 // cell-index = <5>;
255 // reg = <2c00 100>; 251 // reg = <0x2c00 0x100>;
256 // interrupts = <2 4 0>; 252 // interrupts = <2 4 0>;
257 // interrupt-parent = <&mpc5200_pic>; 253 // interrupt-parent = <&mpc5200_pic>;
258 //}; 254 //};
@@ -260,7 +256,7 @@
260 ethernet@3000 { 256 ethernet@3000 {
261 device_type = "network"; 257 device_type = "network";
262 compatible = "fsl,mpc5200b-fec","fsl,mpc5200-fec"; 258 compatible = "fsl,mpc5200b-fec","fsl,mpc5200-fec";
263 reg = <3000 400>; 259 reg = <0x3000 0x400>;
264 local-mac-address = [ 00 00 00 00 00 00 ]; 260 local-mac-address = [ 00 00 00 00 00 00 ];
265 interrupts = <2 5 0>; 261 interrupts = <2 5 0>;
266 interrupt-parent = <&mpc5200_pic>; 262 interrupt-parent = <&mpc5200_pic>;
@@ -271,11 +267,11 @@
271 #address-cells = <1>; 267 #address-cells = <1>;
272 #size-cells = <0>; 268 #size-cells = <0>;
273 compatible = "fsl,mpc5200b-mdio", "fsl,mpc5200-mdio"; 269 compatible = "fsl,mpc5200b-mdio", "fsl,mpc5200-mdio";
274 reg = <3000 400>; // fec range, since we need to setup fec interrupts 270 reg = <0x3000 0x400>; // fec range, since we need to setup fec interrupts
275 interrupts = <2 5 0>; // these are for "mii command finished", not link changes & co. 271 interrupts = <2 5 0>; // these are for "mii command finished", not link changes & co.
276 interrupt-parent = <&mpc5200_pic>; 272 interrupt-parent = <&mpc5200_pic>;
277 273
278 phy0:ethernet-phy@0 { 274 phy0: ethernet-phy@0 {
279 device_type = "ethernet-phy"; 275 device_type = "ethernet-phy";
280 reg = <0>; 276 reg = <0>;
281 }; 277 };
@@ -284,7 +280,7 @@
284 ata@3a00 { 280 ata@3a00 {
285 device_type = "ata"; 281 device_type = "ata";
286 compatible = "fsl,mpc5200b-ata","fsl,mpc5200-ata"; 282 compatible = "fsl,mpc5200b-ata","fsl,mpc5200-ata";
287 reg = <3a00 100>; 283 reg = <0x3a00 0x100>;
288 interrupts = <2 7 0>; 284 interrupts = <2 7 0>;
289 interrupt-parent = <&mpc5200_pic>; 285 interrupt-parent = <&mpc5200_pic>;
290 }; 286 };
@@ -294,8 +290,8 @@
294 #size-cells = <0>; 290 #size-cells = <0>;
295 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c"; 291 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
296 cell-index = <0>; 292 cell-index = <0>;
297 reg = <3d00 40>; 293 reg = <0x3d00 0x40>;
298 interrupts = <2 f 0>; 294 interrupts = <2 15 0>;
299 interrupt-parent = <&mpc5200_pic>; 295 interrupt-parent = <&mpc5200_pic>;
300 fsl5200-clocking; 296 fsl5200-clocking;
301 }; 297 };
@@ -305,14 +301,14 @@
305 #size-cells = <0>; 301 #size-cells = <0>;
306 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c"; 302 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
307 cell-index = <1>; 303 cell-index = <1>;
308 reg = <3d40 40>; 304 reg = <0x3d40 0x40>;
309 interrupts = <2 10 0>; 305 interrupts = <2 16 0>;
310 interrupt-parent = <&mpc5200_pic>; 306 interrupt-parent = <&mpc5200_pic>;
311 fsl5200-clocking; 307 fsl5200-clocking;
312 }; 308 };
313 sram@8000 { 309 sram@8000 {
314 compatible = "fsl,mpc5200b-sram","fsl,mpc5200-sram","sram"; 310 compatible = "fsl,mpc5200b-sram","fsl,mpc5200-sram","sram";
315 reg = <8000 4000>; 311 reg = <0x8000 0x4000>;
316 }; 312 };
317 }; 313 };
318 314
@@ -322,23 +318,23 @@
322 #address-cells = <3>; 318 #address-cells = <3>;
323 device_type = "pci"; 319 device_type = "pci";
324 compatible = "fsl,mpc5200b-pci","fsl,mpc5200-pci"; 320 compatible = "fsl,mpc5200b-pci","fsl,mpc5200-pci";
325 reg = <f0000d00 100>; 321 reg = <0xf0000d00 0x100>;
326 interrupt-map-mask = <f800 0 0 7>; 322 interrupt-map-mask = <0xf800 0 0 7>;
327 interrupt-map = <c000 0 0 1 &mpc5200_pic 0 0 3 // 1st slot 323 interrupt-map = <0xc000 0 0 1 &mpc5200_pic 0 0 3 // 1st slot
328 c000 0 0 2 &mpc5200_pic 1 1 3 324 0xc000 0 0 2 &mpc5200_pic 1 1 3
329 c000 0 0 3 &mpc5200_pic 1 2 3 325 0xc000 0 0 3 &mpc5200_pic 1 2 3
330 c000 0 0 4 &mpc5200_pic 1 3 3 326 0xc000 0 0 4 &mpc5200_pic 1 3 3
331 327
332 c800 0 0 1 &mpc5200_pic 1 1 3 // 2nd slot 328 0xc800 0 0 1 &mpc5200_pic 1 1 3 // 2nd slot
333 c800 0 0 2 &mpc5200_pic 1 2 3 329 0xc800 0 0 2 &mpc5200_pic 1 2 3
334 c800 0 0 3 &mpc5200_pic 1 3 3 330 0xc800 0 0 3 &mpc5200_pic 1 3 3
335 c800 0 0 4 &mpc5200_pic 0 0 3>; 331 0xc800 0 0 4 &mpc5200_pic 0 0 3>;
336 clock-frequency = <0>; // From boot loader 332 clock-frequency = <0>; // From boot loader
337 interrupts = <2 8 0 2 9 0 2 a 0>; 333 interrupts = <2 8 0 2 9 0 2 10 0>;
338 interrupt-parent = <&mpc5200_pic>; 334 interrupt-parent = <&mpc5200_pic>;
339 bus-range = <0 0>; 335 bus-range = <0 0>;
340 ranges = <42000000 0 80000000 80000000 0 20000000 336 ranges = <0x42000000 0 0x80000000 0x80000000 0 0x20000000
341 02000000 0 a0000000 a0000000 0 10000000 337 0x02000000 0 0xa0000000 0xa0000000 0 0x10000000
342 01000000 0 00000000 b0000000 0 01000000>; 338 0x01000000 0 0x00000000 0xb0000000 0 0x01000000>;
343 }; 339 };
344}; 340};
diff --git a/arch/powerpc/boot/dts/motionpro.dts b/arch/powerpc/boot/dts/motionpro.dts
index 2b0dde058f8e..9e3c921be164 100644
--- a/arch/powerpc/boot/dts/motionpro.dts
+++ b/arch/powerpc/boot/dts/motionpro.dts
@@ -10,6 +10,8 @@
10 * option) any later version. 10 * option) any later version.
11 */ 11 */
12 12
13/dts-v1/;
14
13/ { 15/ {
14 model = "promess,motionpro"; 16 model = "promess,motionpro";
15 compatible = "promess,motionpro"; 17 compatible = "promess,motionpro";
@@ -23,10 +25,10 @@
23 PowerPC,5200@0 { 25 PowerPC,5200@0 {
24 device_type = "cpu"; 26 device_type = "cpu";
25 reg = <0>; 27 reg = <0>;
26 d-cache-line-size = <20>; 28 d-cache-line-size = <32>;
27 i-cache-line-size = <20>; 29 i-cache-line-size = <32>;
28 d-cache-size = <4000>; // L1, 16K 30 d-cache-size = <0x4000>; // L1, 16K
29 i-cache-size = <4000>; // L1, 16K 31 i-cache-size = <0x4000>; // L1, 16K
30 timebase-frequency = <0>; // from bootloader 32 timebase-frequency = <0>; // from bootloader
31 bus-frequency = <0>; // from bootloader 33 bus-frequency = <0>; // from bootloader
32 clock-frequency = <0>; // from bootloader 34 clock-frequency = <0>; // from bootloader
@@ -35,21 +37,21 @@
35 37
36 memory { 38 memory {
37 device_type = "memory"; 39 device_type = "memory";
38 reg = <00000000 04000000>; // 64MB 40 reg = <0x00000000 0x04000000>; // 64MB
39 }; 41 };
40 42
41 soc5200@f0000000 { 43 soc5200@f0000000 {
42 #address-cells = <1>; 44 #address-cells = <1>;
43 #size-cells = <1>; 45 #size-cells = <1>;
44 compatible = "fsl,mpc5200b-immr"; 46 compatible = "fsl,mpc5200b-immr";
45 ranges = <0 f0000000 0000c000>; 47 ranges = <0 0xf0000000 0x0000c000>;
46 reg = <f0000000 00000100>; 48 reg = <0xf0000000 0x00000100>;
47 bus-frequency = <0>; // from bootloader 49 bus-frequency = <0>; // from bootloader
48 system-frequency = <0>; // from bootloader 50 system-frequency = <0>; // from bootloader
49 51
50 cdm@200 { 52 cdm@200 {
51 compatible = "fsl,mpc5200b-cdm","fsl,mpc5200-cdm"; 53 compatible = "fsl,mpc5200b-cdm","fsl,mpc5200-cdm";
52 reg = <200 38>; 54 reg = <0x200 0x38>;
53 }; 55 };
54 56
55 mpc5200_pic: interrupt-controller@500 { 57 mpc5200_pic: interrupt-controller@500 {
@@ -57,12 +59,12 @@
57 interrupt-controller; 59 interrupt-controller;
58 #interrupt-cells = <3>; 60 #interrupt-cells = <3>;
59 compatible = "fsl,mpc5200b-pic","fsl,mpc5200-pic"; 61 compatible = "fsl,mpc5200b-pic","fsl,mpc5200-pic";
60 reg = <500 80>; 62 reg = <0x500 0x80>;
61 }; 63 };
62 64
63 timer@600 { // General Purpose Timer 65 timer@600 { // General Purpose Timer
64 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 66 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
65 reg = <600 10>; 67 reg = <0x600 0x10>;
66 interrupts = <1 9 0>; 68 interrupts = <1 9 0>;
67 interrupt-parent = <&mpc5200_pic>; 69 interrupt-parent = <&mpc5200_pic>;
68 fsl,has-wdt; 70 fsl,has-wdt;
@@ -70,118 +72,118 @@
70 72
71 timer@610 { // General Purpose Timer 73 timer@610 { // General Purpose Timer
72 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 74 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
73 reg = <610 10>; 75 reg = <0x610 0x10>;
74 interrupts = <1 a 0>; 76 interrupts = <1 10 0>;
75 interrupt-parent = <&mpc5200_pic>; 77 interrupt-parent = <&mpc5200_pic>;
76 }; 78 };
77 79
78 timer@620 { // General Purpose Timer 80 timer@620 { // General Purpose Timer
79 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 81 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
80 reg = <620 10>; 82 reg = <0x620 0x10>;
81 interrupts = <1 b 0>; 83 interrupts = <1 11 0>;
82 interrupt-parent = <&mpc5200_pic>; 84 interrupt-parent = <&mpc5200_pic>;
83 }; 85 };
84 86
85 timer@630 { // General Purpose Timer 87 timer@630 { // General Purpose Timer
86 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 88 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
87 reg = <630 10>; 89 reg = <0x630 0x10>;
88 interrupts = <1 c 0>; 90 interrupts = <1 12 0>;
89 interrupt-parent = <&mpc5200_pic>; 91 interrupt-parent = <&mpc5200_pic>;
90 }; 92 };
91 93
92 timer@640 { // General Purpose Timer 94 timer@640 { // General Purpose Timer
93 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 95 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
94 reg = <640 10>; 96 reg = <0x640 0x10>;
95 interrupts = <1 d 0>; 97 interrupts = <1 13 0>;
96 interrupt-parent = <&mpc5200_pic>; 98 interrupt-parent = <&mpc5200_pic>;
97 }; 99 };
98 100
99 timer@650 { // General Purpose Timer 101 timer@650 { // General Purpose Timer
100 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt"; 102 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
101 reg = <650 10>; 103 reg = <0x650 0x10>;
102 interrupts = <1 e 0>; 104 interrupts = <1 14 0>;
103 interrupt-parent = <&mpc5200_pic>; 105 interrupt-parent = <&mpc5200_pic>;
104 }; 106 };
105 107
106 motionpro-led@660 { // Motion-PRO status LED 108 motionpro-led@660 { // Motion-PRO status LED
107 compatible = "promess,motionpro-led"; 109 compatible = "promess,motionpro-led";
108 label = "motionpro-statusled"; 110 label = "motionpro-statusled";
109 reg = <660 10>; 111 reg = <0x660 0x10>;
110 interrupts = <1 f 0>; 112 interrupts = <1 15 0>;
111 interrupt-parent = <&mpc5200_pic>; 113 interrupt-parent = <&mpc5200_pic>;
112 blink-delay = <64>; // 100 msec 114 blink-delay = <100>; // 100 msec
113 }; 115 };
114 116
115 motionpro-led@670 { // Motion-PRO ready LED 117 motionpro-led@670 { // Motion-PRO ready LED
116 compatible = "promess,motionpro-led"; 118 compatible = "promess,motionpro-led";
117 label = "motionpro-readyled"; 119 label = "motionpro-readyled";
118 reg = <670 10>; 120 reg = <0x670 0x10>;
119 interrupts = <1 10 0>; 121 interrupts = <1 16 0>;
120 interrupt-parent = <&mpc5200_pic>; 122 interrupt-parent = <&mpc5200_pic>;
121 }; 123 };
122 124
123 rtc@800 { // Real time clock 125 rtc@800 { // Real time clock
124 compatible = "fsl,mpc5200b-rtc","fsl,mpc5200-rtc"; 126 compatible = "fsl,mpc5200b-rtc","fsl,mpc5200-rtc";
125 reg = <800 100>; 127 reg = <0x800 0x100>;
126 interrupts = <1 5 0 1 6 0>; 128 interrupts = <1 5 0 1 6 0>;
127 interrupt-parent = <&mpc5200_pic>; 129 interrupt-parent = <&mpc5200_pic>;
128 }; 130 };
129 131
130 mscan@980 { 132 can@980 {
131 compatible = "fsl,mpc5200b-mscan","fsl,mpc5200-mscan"; 133 compatible = "fsl,mpc5200b-mscan","fsl,mpc5200-mscan";
132 interrupts = <2 12 0>; 134 interrupts = <2 18 0>;
133 interrupt-parent = <&mpc5200_pic>; 135 interrupt-parent = <&mpc5200_pic>;
134 reg = <980 80>; 136 reg = <0x980 0x80>;
135 }; 137 };
136 138
137 gpio@b00 { 139 gpio@b00 {
138 compatible = "fsl,mpc5200b-gpio","fsl,mpc5200-gpio"; 140 compatible = "fsl,mpc5200b-gpio","fsl,mpc5200-gpio";
139 reg = <b00 40>; 141 reg = <0xb00 0x40>;
140 interrupts = <1 7 0>; 142 interrupts = <1 7 0>;
141 interrupt-parent = <&mpc5200_pic>; 143 interrupt-parent = <&mpc5200_pic>;
142 }; 144 };
143 145
144 gpio@c00 { 146 gpio@c00 {
145 compatible = "fsl,mpc5200b-gpio-wkup","fsl,mpc5200-gpio-wkup"; 147 compatible = "fsl,mpc5200b-gpio-wkup","fsl,mpc5200-gpio-wkup";
146 reg = <c00 40>; 148 reg = <0xc00 0x40>;
147 interrupts = <1 8 0 0 3 0>; 149 interrupts = <1 8 0 0 3 0>;
148 interrupt-parent = <&mpc5200_pic>; 150 interrupt-parent = <&mpc5200_pic>;
149 }; 151 };
150 152
151 spi@f00 { 153 spi@f00 {
152 compatible = "fsl,mpc5200b-spi","fsl,mpc5200-spi"; 154 compatible = "fsl,mpc5200b-spi","fsl,mpc5200-spi";
153 reg = <f00 20>; 155 reg = <0xf00 0x20>;
154 interrupts = <2 d 0 2 e 0>; 156 interrupts = <2 13 0 2 14 0>;
155 interrupt-parent = <&mpc5200_pic>; 157 interrupt-parent = <&mpc5200_pic>;
156 }; 158 };
157 159
158 usb@1000 { 160 usb@1000 {
159 compatible = "fsl,mpc5200b-ohci","fsl,mpc5200-ohci","ohci-be"; 161 compatible = "fsl,mpc5200b-ohci","fsl,mpc5200-ohci","ohci-be";
160 reg = <1000 ff>; 162 reg = <0x1000 0xff>;
161 interrupts = <2 6 0>; 163 interrupts = <2 6 0>;
162 interrupt-parent = <&mpc5200_pic>; 164 interrupt-parent = <&mpc5200_pic>;
163 }; 165 };
164 166
165 dma-controller@1200 { 167 dma-controller@1200 {
166 compatible = "fsl,mpc5200b-bestcomm","fsl,mpc5200-bestcomm"; 168 compatible = "fsl,mpc5200b-bestcomm","fsl,mpc5200-bestcomm";
167 reg = <1200 80>; 169 reg = <0x1200 0x80>;
168 interrupts = <3 0 0 3 1 0 3 2 0 3 3 0 170 interrupts = <3 0 0 3 1 0 3 2 0 3 3 0
169 3 4 0 3 5 0 3 6 0 3 7 0 171 3 4 0 3 5 0 3 6 0 3 7 0
170 3 8 0 3 9 0 3 a 0 3 b 0 172 3 8 0 3 9 0 3 10 0 3 11 0
171 3 c 0 3 d 0 3 e 0 3 f 0>; 173 3 12 0 3 13 0 3 14 0 3 15 0>;
172 interrupt-parent = <&mpc5200_pic>; 174 interrupt-parent = <&mpc5200_pic>;
173 }; 175 };
174 176
175 xlb@1f00 { 177 xlb@1f00 {
176 compatible = "fsl,mpc5200b-xlb","fsl,mpc5200-xlb"; 178 compatible = "fsl,mpc5200b-xlb","fsl,mpc5200-xlb";
177 reg = <1f00 100>; 179 reg = <0x1f00 0x100>;
178 }; 180 };
179 181
180 serial@2000 { // PSC1 182 serial@2000 { // PSC1
181 device_type = "serial"; 183 device_type = "serial";
182 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 184 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
183 port-number = <0>; // Logical port assignment 185 port-number = <0>; // Logical port assignment
184 reg = <2000 100>; 186 reg = <0x2000 0x100>;
185 interrupts = <2 1 0>; 187 interrupts = <2 1 0>;
186 interrupt-parent = <&mpc5200_pic>; 188 interrupt-parent = <&mpc5200_pic>;
187 }; 189 };
@@ -190,7 +192,7 @@
190 spi@2200 { // PSC2 192 spi@2200 { // PSC2
191 compatible = "fsl,mpc5200b-psc-spi","fsl,mpc5200-psc-spi"; 193 compatible = "fsl,mpc5200b-psc-spi","fsl,mpc5200-psc-spi";
192 cell-index = <1>; 194 cell-index = <1>;
193 reg = <2200 100>; 195 reg = <0x2200 0x100>;
194 interrupts = <2 2 0>; 196 interrupts = <2 2 0>;
195 interrupt-parent = <&mpc5200_pic>; 197 interrupt-parent = <&mpc5200_pic>;
196 }; 198 };
@@ -200,15 +202,15 @@
200 device_type = "serial"; 202 device_type = "serial";
201 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart"; 203 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
202 port-number = <4>; // Logical port assignment 204 port-number = <4>; // Logical port assignment
203 reg = <2800 100>; 205 reg = <0x2800 0x100>;
204 interrupts = <2 c 0>; 206 interrupts = <2 12 0>;
205 interrupt-parent = <&mpc5200_pic>; 207 interrupt-parent = <&mpc5200_pic>;
206 }; 208 };
207 209
208 ethernet@3000 { 210 ethernet@3000 {
209 device_type = "network"; 211 device_type = "network";
210 compatible = "fsl,mpc5200b-fec","fsl,mpc5200-fec"; 212 compatible = "fsl,mpc5200b-fec","fsl,mpc5200-fec";
211 reg = <3000 400>; 213 reg = <0x3000 0x400>;
212 local-mac-address = [ 00 00 00 00 00 00 ]; 214 local-mac-address = [ 00 00 00 00 00 00 ];
213 interrupts = <2 5 0>; 215 interrupts = <2 5 0>;
214 interrupt-parent = <&mpc5200_pic>; 216 interrupt-parent = <&mpc5200_pic>;
@@ -219,7 +221,7 @@
219 #address-cells = <1>; 221 #address-cells = <1>;
220 #size-cells = <0>; 222 #size-cells = <0>;
221 compatible = "fsl,mpc5200b-mdio","fsl,mpc5200-mdio"; 223 compatible = "fsl,mpc5200b-mdio","fsl,mpc5200-mdio";
222 reg = <3000 400>; // fec range, since we need to setup fec interrupts 224 reg = <0x3000 0x400>; // fec range, since we need to setup fec interrupts
223 interrupts = <2 5 0>; // these are for "mii command finished", not link changes & co. 225 interrupts = <2 5 0>; // these are for "mii command finished", not link changes & co.
224 interrupt-parent = <&mpc5200_pic>; 226 interrupt-parent = <&mpc5200_pic>;
225 227
@@ -231,7 +233,7 @@
231 233
232 ata@3a00 { 234 ata@3a00 {
233 compatible = "fsl,mpc5200b-ata","fsl,mpc5200-ata"; 235 compatible = "fsl,mpc5200b-ata","fsl,mpc5200-ata";
234 reg = <3a00 100>; 236 reg = <0x3a00 0x100>;
235 interrupts = <2 7 0>; 237 interrupts = <2 7 0>;
236 interrupt-parent = <&mpc5200_pic>; 238 interrupt-parent = <&mpc5200_pic>;
237 }; 239 };
@@ -240,21 +242,21 @@
240 #address-cells = <1>; 242 #address-cells = <1>;
241 #size-cells = <0>; 243 #size-cells = <0>;
242 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c"; 244 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
243 reg = <3d40 40>; 245 reg = <0x3d40 0x40>;
244 interrupts = <2 10 0>; 246 interrupts = <2 16 0>;
245 interrupt-parent = <&mpc5200_pic>; 247 interrupt-parent = <&mpc5200_pic>;
246 fsl5200-clocking; 248 fsl5200-clocking;
247 249
248 rtc@68 { 250 rtc@68 {
249 device_type = "rtc"; 251 device_type = "rtc";
250 compatible = "dallas,ds1339"; 252 compatible = "dallas,ds1339";
251 reg = <68>; 253 reg = <0x68>;
252 }; 254 };
253 }; 255 };
254 256
255 sram@8000 { 257 sram@8000 {
256 compatible = "fsl,mpc5200b-sram","fsl,mpc5200-sram"; 258 compatible = "fsl,mpc5200b-sram","fsl,mpc5200-sram";
257 reg = <8000 4000>; 259 reg = <0x8000 0x4000>;
258 }; 260 };
259 }; 261 };
260 262
@@ -262,15 +264,15 @@
262 compatible = "fsl,lpb"; 264 compatible = "fsl,lpb";
263 #address-cells = <2>; 265 #address-cells = <2>;
264 #size-cells = <1>; 266 #size-cells = <1>;
265 ranges = <0 0 ff000000 01000000 267 ranges = <0 0 0xff000000 0x01000000
266 1 0 50000000 00010000 268 1 0 0x50000000 0x00010000
267 2 0 50010000 00010000 269 2 0 0x50010000 0x00010000
268 3 0 50020000 00010000>; 270 3 0 0x50020000 0x00010000>;
269 271
270 // 8-bit DualPort SRAM on LocalPlus Bus CS1 272 // 8-bit DualPort SRAM on LocalPlus Bus CS1
271 kollmorgen@1,0 { 273 kollmorgen@1,0 {
272 compatible = "promess,motionpro-kollmorgen"; 274 compatible = "promess,motionpro-kollmorgen";
273 reg = <1 0 10000>; 275 reg = <1 0 0x10000>;
274 interrupts = <1 1 0>; 276 interrupts = <1 1 0>;
275 interrupt-parent = <&mpc5200_pic>; 277 interrupt-parent = <&mpc5200_pic>;
276 }; 278 };
@@ -278,13 +280,13 @@
278 // 8-bit board CPLD on LocalPlus Bus CS2 280 // 8-bit board CPLD on LocalPlus Bus CS2
279 cpld@2,0 { 281 cpld@2,0 {
280 compatible = "promess,motionpro-cpld"; 282 compatible = "promess,motionpro-cpld";
281 reg = <2 0 10000>; 283 reg = <2 0 0x10000>;
282 }; 284 };
283 285
284 // 8-bit custom Anybus Module on LocalPlus Bus CS3 286 // 8-bit custom Anybus Module on LocalPlus Bus CS3
285 anybus@3,0 { 287 anybus@3,0 {
286 compatible = "promess,motionpro-anybus"; 288 compatible = "promess,motionpro-anybus";
287 reg = <3 0 10000>; 289 reg = <3 0 0x10000>;
288 }; 290 };
289 pro_module_general@3,0 { 291 pro_module_general@3,0 {
290 compatible = "promess,pro_module_general"; 292 compatible = "promess,pro_module_general";
@@ -292,13 +294,13 @@
292 }; 294 };
293 pro_module_dio@3,800 { 295 pro_module_dio@3,800 {
294 compatible = "promess,pro_module_dio"; 296 compatible = "promess,pro_module_dio";
295 reg = <3 800 2>; 297 reg = <3 0x800 2>;
296 }; 298 };
297 299
298 // 16-bit flash device at LocalPlus Bus CS0 300 // 16-bit flash device at LocalPlus Bus CS0
299 flash@0,0 { 301 flash@0,0 {
300 compatible = "cfi-flash"; 302 compatible = "cfi-flash";
301 reg = <0 0 01000000>; 303 reg = <0 0 0x01000000>;
302 bank-width = <2>; 304 bank-width = <2>;
303 device-width = <2>; 305 device-width = <2>;
304 #size-cells = <1>; 306 #size-cells = <1>;
diff --git a/arch/powerpc/boot/dts/mpc8610_hpcd.dts b/arch/powerpc/boot/dts/mpc8610_hpcd.dts
index 1f2f1e0a5571..bba234eb14a9 100644
--- a/arch/powerpc/boot/dts/mpc8610_hpcd.dts
+++ b/arch/powerpc/boot/dts/mpc8610_hpcd.dts
@@ -21,6 +21,7 @@
21 serial1 = &serial1; 21 serial1 = &serial1;
22 pci0 = &pci0; 22 pci0 = &pci0;
23 pci1 = &pci1; 23 pci1 = &pci1;
24 pci2 = &pci2;
24 }; 25 };
25 26
26 cpus { 27 cpus {
@@ -105,7 +106,7 @@
105 compatible = "ns16550"; 106 compatible = "ns16550";
106 reg = <0x4600 0x100>; 107 reg = <0x4600 0x100>;
107 clock-frequency = <0>; 108 clock-frequency = <0>;
108 interrupts = <28 2>; 109 interrupts = <42 2>;
109 interrupt-parent = <&mpic>; 110 interrupt-parent = <&mpic>;
110 }; 111 };
111 112
@@ -322,4 +323,24 @@
322 }; 323 };
323 }; 324 };
324 }; 325 };
326
327 pci2: pcie@e0009000 {
328 #address-cells = <3>;
329 #size-cells = <2>;
330 #interrupt-cells = <1>;
331 device_type = "pci";
332 compatible = "fsl,mpc8641-pcie";
333 reg = <0xe0009000 0x00001000>;
334 ranges = <0x02000000 0 0x90000000 0x90000000 0 0x10000000
335 0x01000000 0 0x00000000 0xe2000000 0 0x00100000>;
336 bus-range = <0 255>;
337 interrupt-map-mask = <0xf800 0 0 7>;
338 interrupt-map = <0x0000 0 0 1 &mpic 4 1
339 0x0000 0 0 2 &mpic 5 1
340 0x0000 0 0 3 &mpic 6 1
341 0x0000 0 0 4 &mpic 7 1>;
342 interrupt-parent = <&mpic>;
343 interrupts = <25 2>;
344 clock-frequency = <33333333>;
345 };
325}; 346};
diff --git a/arch/powerpc/boot/dts/pcm030.dts b/arch/powerpc/boot/dts/pcm030.dts
new file mode 100644
index 000000000000..7c1bb952360c
--- /dev/null
+++ b/arch/powerpc/boot/dts/pcm030.dts
@@ -0,0 +1,363 @@
1/*
2 * phyCORE-MPC5200B-tiny (pcm030) board Device Tree Source
3 *
4 * Copyright 2006 Pengutronix
5 * Sascha Hauer <s.hauer@pengutronix.de>
6 * Copyright 2007 Pengutronix
7 * Juergen Beisert <j.beisert@pengutronix.de>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 */
14
15/dts-v1/;
16
17/ {
18 model = "phytec,pcm030";
19 compatible = "phytec,pcm030";
20 #address-cells = <1>;
21 #size-cells = <1>;
22
23 cpus {
24 #address-cells = <1>;
25 #size-cells = <0>;
26
27 PowerPC,5200@0 {
28 device_type = "cpu";
29 reg = <0>;
30 d-cache-line-size = <32>;
31 i-cache-line-size = <32>;
32 d-cache-size = <0x4000>; /* L1, 16K */
33 i-cache-size = <0x4000>; /* L1, 16K */
34 timebase-frequency = <0>; /* From Bootloader */
35 bus-frequency = <0>; /* From Bootloader */
36 clock-frequency = <0>; /* From Bootloader */
37 };
38 };
39
40 memory {
41 device_type = "memory";
42 reg = <0x00000000 0x04000000>; /* 64MB */
43 };
44
45 soc5200@f0000000 {
46 #address-cells = <1>;
47 #size-cells = <1>;
48 compatible = "fsl,mpc5200b-immr";
49 ranges = <0x0 0xf0000000 0x0000c000>;
50 bus-frequency = <0>; /* From bootloader */
51 system-frequency = <0>; /* From bootloader */
52
53 cdm@200 {
54 compatible = "fsl,mpc5200b-cdm","fsl,mpc5200-cdm";
55 reg = <0x200 0x38>;
56 };
57
58 mpc5200_pic: interrupt-controller@500 {
59 /* 5200 interrupts are encoded into two levels; */
60 interrupt-controller;
61 #interrupt-cells = <3>;
62 device_type = "interrupt-controller";
63 compatible = "fsl,mpc5200b-pic","fsl,mpc5200-pic";
64 reg = <0x500 0x80>;
65 };
66
67 timer@600 { /* General Purpose Timer */
68 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
69 cell-index = <0>;
70 reg = <0x600 0x10>;
71 interrupts = <0x1 0x9 0x0>;
72 interrupt-parent = <&mpc5200_pic>;
73 fsl,has-wdt;
74 };
75
76 timer@610 { /* General Purpose Timer */
77 compatible = "fsl,mpc5200b-gpt","fsl,mpc5200-gpt";
78 cell-index = <1>;
79 reg = <0x610 0x10>;
80 interrupts = <0x1 0xa 0x0>;
81 interrupt-parent = <&mpc5200_pic>;
82 };
83
84 gpt2: timer@620 { /* General Purpose Timer in GPIO mode */
85 compatible = "fsl,mpc5200b-gpt-gpio","fsl,mpc5200-gpt-gpio";
86 cell-index = <2>;
87 reg = <0x620 0x10>;
88 interrupts = <0x1 0xb 0x0>;
89 interrupt-parent = <&mpc5200_pic>;
90 gpio-controller;
91 #gpio-cells = <2>;
92 };
93
94 gpt3: timer@630 { /* General Purpose Timer in GPIO mode */
95 compatible = "fsl,mpc5200b-gpt-gpio","fsl,mpc5200-gpt-gpio";
96 cell-index = <3>;
97 reg = <0x630 0x10>;
98 interrupts = <0x1 0xc 0x0>;
99 interrupt-parent = <&mpc5200_pic>;
100 gpio-controller;
101 #gpio-cells = <2>;
102 };
103
104 gpt4: timer@640 { /* General Purpose Timer in GPIO mode */
105 compatible = "fsl,mpc5200b-gpt-gpio","fsl,mpc5200-gpt-gpio";
106 cell-index = <4>;
107 reg = <0x640 0x10>;
108 interrupts = <0x1 0xd 0x0>;
109 interrupt-parent = <&mpc5200_pic>;
110 gpio-controller;
111 #gpio-cells = <2>;
112 };
113
114 gpt5: timer@650 { /* General Purpose Timer in GPIO mode */
115 compatible = "fsl,mpc5200b-gpt-gpio","fsl,mpc5200-gpt-gpio";
116 cell-index = <5>;
117 reg = <0x650 0x10>;
118 interrupts = <0x1 0xe 0x0>;
119 interrupt-parent = <&mpc5200_pic>;
120 gpio-controller;
121 #gpio-cells = <2>;
122 };
123
124 gpt6: timer@660 { /* General Purpose Timer in GPIO mode */
125 compatible = "fsl,mpc5200b-gpt-gpio","fsl,mpc5200-gpt-gpio";
126 cell-index = <6>;
127 reg = <0x660 0x10>;
128 interrupts = <0x1 0xf 0x0>;
129 interrupt-parent = <&mpc5200_pic>;
130 gpio-controller;
131 #gpio-cells = <2>;
132 };
133
134 gpt7: timer@670 { /* General Purpose Timer in GPIO mode */
135 compatible = "fsl,mpc5200b-gpt-gpio","fsl,mpc5200-gpt-gpio";
136 cell-index = <7>;
137 reg = <0x670 0x10>;
138 interrupts = <0x1 0x10 0x0>;
139 interrupt-parent = <&mpc5200_pic>;
140 gpio-controller;
141 #gpio-cells = <2>;
142 };
143
144 rtc@800 { // Real time clock
145 compatible = "fsl,mpc5200b-rtc","fsl,mpc5200-rtc";
146 device_type = "rtc";
147 reg = <0x800 0x100>;
148 interrupts = <0x1 0x5 0x0 0x1 0x6 0x0>;
149 interrupt-parent = <&mpc5200_pic>;
150 };
151
152 can@900 {
153 compatible = "fsl,mpc5200b-mscan","fsl,mpc5200-mscan";
154 cell-index = <0>;
155 interrupts = <0x2 0x11 0x0>;
156 interrupt-parent = <&mpc5200_pic>;
157 reg = <0x900 0x80>;
158 };
159
160 can@980 {
161 compatible = "fsl,mpc5200b-mscan","fsl,mpc5200-mscan";
162 cell-index = <1>;
163 interrupts = <0x2 0x12 0x0>;
164 interrupt-parent = <&mpc5200_pic>;
165 reg = <0x980 0x80>;
166 };
167
168 gpio_simple: gpio@b00 {
169 compatible = "fsl,mpc5200b-gpio","fsl,mpc5200-gpio";
170 reg = <0xb00 0x40>;
171 interrupts = <0x1 0x7 0x0>;
172 interrupt-parent = <&mpc5200_pic>;
173 gpio-controller;
174 #gpio-cells = <2>;
175 };
176
177 gpio_wkup: gpio-wkup@c00 {
178 compatible = "fsl,mpc5200b-gpio-wkup","fsl,mpc5200-gpio-wkup";
179 reg = <0xc00 0x40>;
180 interrupts = <0x1 0x8 0x0 0x0 0x3 0x0>;
181 interrupt-parent = <&mpc5200_pic>;
182 gpio-controller;
183 #gpio-cells = <2>;
184 };
185
186 spi@f00 {
187 compatible = "fsl,mpc5200b-spi","fsl,mpc5200-spi";
188 reg = <0xf00 0x20>;
189 interrupts = <0x2 0xd 0x0 0x2 0xe 0x0>;
190 interrupt-parent = <&mpc5200_pic>;
191 };
192
193 usb@1000 {
194 compatible = "fsl,mpc5200b-ohci","fsl,mpc5200-ohci","ohci-be";
195 reg = <0x1000 0xff>;
196 interrupts = <0x2 0x6 0x0>;
197 interrupt-parent = <&mpc5200_pic>;
198 };
199
200 dma-controller@1200 {
201 device_type = "dma-controller";
202 compatible = "fsl,mpc5200b-bestcomm","fsl,mpc5200-bestcomm";
203 reg = <0x1200 0x80>;
204 interrupts = <0x3 0x0 0x0 0x3 0x1 0x0 0x3 0x2 0x0 0x3 0x3 0x0
205 0x3 0x4 0x0 0x3 0x5 0x0 0x3 0x6 0x0 0x3 0x7 0x0
206 0x3 0x8 0x0 0x3 0x9 0x0 0x3 0xa 0x0 0x3 0xb 0x0
207 0x3 0xc 0x0 0x3 0xd 0x0 0x3 0xe 0x0 0x3 0xf 0x0>;
208 interrupt-parent = <&mpc5200_pic>;
209 };
210
211 xlb@1f00 {
212 compatible = "fsl,mpc5200b-xlb","fsl,mpc5200-xlb";
213 reg = <0x1f00 0x100>;
214 };
215
216 ac97@2000 { /* PSC1 in ac97 mode */
217 device_type = "sound";
218 compatible = "mpc5200b-psc-ac97","fsl,mpc5200b-psc-ac97";
219 cell-index = <0>;
220 reg = <0x2000 0x100>;
221 interrupts = <0x2 0x2 0x0>;
222 interrupt-parent = <&mpc5200_pic>;
223 };
224
225 /* PSC2 port is used by CAN1/2 */
226
227 serial@2400 { /* PSC3 in UART mode */
228 device_type = "serial";
229 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
230 port-number = <0>;
231 cell-index = <2>;
232 reg = <0x2400 0x100>;
233 interrupts = <0x2 0x3 0x0>;
234 interrupt-parent = <&mpc5200_pic>;
235 };
236
237 /* PSC4 is ??? */
238
239 /* PSC5 is ??? */
240
241 serial@2c00 { /* PSC6 in UART mode */
242 device_type = "serial";
243 compatible = "fsl,mpc5200b-psc-uart","fsl,mpc5200-psc-uart";
244 port-number = <1>;
245 cell-index = <5>;
246 reg = <0x2c00 0x100>;
247 interrupts = <0x2 0x4 0x0>;
248 interrupt-parent = <&mpc5200_pic>;
249 };
250
251 ethernet@3000 {
252 device_type = "network";
253 compatible = "fsl,mpc5200b-fec","fsl,mpc5200-fec";
254 reg = <0x3000 0x400>;
255 local-mac-address = [00 00 00 00 00 00];
256 interrupts = <0x2 0x5 0x0>;
257 interrupt-parent = <&mpc5200_pic>;
258 phy-handle = <&phy0>;
259 };
260
261 mdio@3000 {
262 #address-cells = <1>;
263 #size-cells = <0>;
264 compatible = "fsl,mpc5200b-mdio", "fsl,mpc5200-mdio";
265 reg = <0x3000 0x400>; /* fec range, since we need to setup fec interrupts */
266 interrupts = <0x2 0x5 0x0>; /* these are for "mii command finished", not link changes & co. */
267 interrupt-parent = <&mpc5200_pic>;
268
269 phy0:ethernet-phy@0 {
270 device_type = "ethernet-phy";
271 reg = <0x0>;
272 };
273 };
274
275 ata@3a00 {
276 device_type = "ata";
277 compatible = "fsl,mpc5200b-ata","fsl,mpc5200-ata";
278 reg = <0x3a00 0x100>;
279 interrupts = <0x2 0x7 0x0>;
280 interrupt-parent = <&mpc5200_pic>;
281 };
282
283 i2c@3d00 {
284 #address-cells = <1>;
285 #size-cells = <0>;
286 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
287 cell-index = <0>;
288 reg = <0x3d00 0x40>;
289 interrupts = <0x2 0xf 0x0>;
290 interrupt-parent = <&mpc5200_pic>;
291 fsl5200-clocking;
292 };
293
294 i2c@3d40 {
295 #address-cells = <1>;
296 #size-cells = <0>;
297 compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
298 cell-index = <1>;
299 reg = <0x3d40 0x40>;
300 interrupts = <0x2 0x10 0x0>;
301 interrupt-parent = <&mpc5200_pic>;
302 fsl5200-clocking;
303 rtc@51 {
304 device_type = "rtc";
305 compatible = "nxp,pcf8563";
306 reg = <0x51>;
307 };
308 /* FIXME: EEPROM */
309 };
310
311 sram@8000 {
312 compatible = "fsl,mpc5200b-sram","fsl,mpc5200-sram","sram";
313 reg = <0x8000 0x4000>;
314 };
315
316 /* This is only an example device to show the usage of gpios. It maps all available
317 * gpios to the "gpio-provider" device.
318 */
319 gpio {
320 compatible = "gpio-provider";
321
322 /* mpc52xx exp.con patchfield */
323 gpios = <&gpio_wkup 0 0 /* GPIO_WKUP_7 11d jp13-3 */
324 &gpio_wkup 1 0 /* GPIO_WKUP_6 14c */
325 &gpio_wkup 6 0 /* PSC2_4 43c x5-11 */
326 &gpio_simple 2 0 /* IRDA_1 24c x7-6 set GPS_PORT_CONFIG[IRDA] = 0 */
327 &gpio_simple 3 0 /* IRDA_0 x8-5 set GPS_PORT_CONFIG[IRDA] = 0 */
328 &gpt2 0 0 /* timer2 12d x4-4 */
329 &gpt3 0 0 /* timer3 13d x6-4 */
330 &gpt4 0 0 /* timer4 61c x2-16 */
331 &gpt5 0 0 /* timer5 44c x7-11 */
332 &gpt6 0 0 /* timer6 60c x8-15 */
333 &gpt7 0 0 /* timer7 36a x17-9 */
334 >;
335 };
336 };
337
338 pci@f0000d00 {
339 #interrupt-cells = <1>;
340 #size-cells = <2>;
341 #address-cells = <3>;
342 device_type = "pci";
343 compatible = "fsl,mpc5200b-pci","fsl,mpc5200-pci";
344 reg = <0xf0000d00 0x100>;
345 interrupt-map-mask = <0xf800 0x0 0x0 0x7>;
346 interrupt-map = <0xc000 0x0 0x0 0x1 &mpc5200_pic 0x0 0x0 0x3 /* 1st slot */
347 0xc000 0x0 0x0 0x2 &mpc5200_pic 0x1 0x1 0x3
348 0xc000 0x0 0x0 0x3 &mpc5200_pic 0x1 0x2 0x3
349 0xc000 0x0 0x0 0x4 &mpc5200_pic 0x1 0x3 0x3
350
351 0xc800 0x0 0x0 0x1 &mpc5200_pic 0x1 0x1 0x3 /* 2nd slot */
352 0xc800 0x0 0x0 0x2 &mpc5200_pic 0x1 0x2 0x3
353 0xc800 0x0 0x0 0x3 &mpc5200_pic 0x1 0x3 0x3
354 0xc800 0x0 0x0 0x4 &mpc5200_pic 0x0 0x0 0x3>;
355 clock-frequency = <0>; // From boot loader
356 interrupts = <0x2 0x8 0x0 0x2 0x9 0x0 0x2 0xa 0x0>;
357 interrupt-parent = <&mpc5200_pic>;
358 bus-range = <0 0>;
359 ranges = <0x42000000 0x0 0x80000000 0x80000000 0x0 0x20000000
360 0x02000000 0x0 0xa0000000 0xa0000000 0x0 0x10000000
361 0x01000000 0x0 0x00000000 0xb0000000 0x0 0x01000000>;
362 };
363};
diff --git a/arch/powerpc/boot/dts/tqm5200.dts b/arch/powerpc/boot/dts/tqm5200.dts
index 65bcea6a0173..773a68e00058 100644
--- a/arch/powerpc/boot/dts/tqm5200.dts
+++ b/arch/powerpc/boot/dts/tqm5200.dts
@@ -10,6 +10,8 @@
10 * option) any later version. 10 * option) any later version.
11 */ 11 */
12 12
13/dts-v1/;
14
13/ { 15/ {
14 model = "tqc,tqm5200"; 16 model = "tqc,tqm5200";
15 compatible = "tqc,tqm5200"; 17 compatible = "tqc,tqm5200";
@@ -23,10 +25,10 @@
23 PowerPC,5200@0 { 25 PowerPC,5200@0 {
24 device_type = "cpu"; 26 device_type = "cpu";
25 reg = <0>; 27 reg = <0>;
26 d-cache-line-size = <20>; 28 d-cache-line-size = <32>;
27 i-cache-line-size = <20>; 29 i-cache-line-size = <32>;
28 d-cache-size = <4000>; // L1, 16K 30 d-cache-size = <0x4000>; // L1, 16K
29 i-cache-size = <4000>; // L1, 16K 31 i-cache-size = <0x4000>; // L1, 16K
30 timebase-frequency = <0>; // from bootloader 32 timebase-frequency = <0>; // from bootloader
31 bus-frequency = <0>; // from bootloader 33 bus-frequency = <0>; // from bootloader
32 clock-frequency = <0>; // from bootloader 34 clock-frequency = <0>; // from bootloader
@@ -35,21 +37,21 @@
35 37
36 memory { 38 memory {
37 device_type = "memory"; 39 device_type = "memory";
38 reg = <00000000 04000000>; // 64MB 40 reg = <0x00000000 0x04000000>; // 64MB
39 }; 41 };
40 42
41 soc5200@f0000000 { 43 soc5200@f0000000 {
42 #address-cells = <1>; 44 #address-cells = <1>;
43 #size-cells = <1>; 45 #size-cells = <1>;
44 compatible = "fsl,mpc5200-immr"; 46 compatible = "fsl,mpc5200-immr";
45 ranges = <0 f0000000 0000c000>; 47 ranges = <0 0xf0000000 0x0000c000>;
46 reg = <f0000000 00000100>; 48 reg = <0xf0000000 0x00000100>;
47 bus-frequency = <0>; // from bootloader 49 bus-frequency = <0>; // from bootloader
48 system-frequency = <0>; // from bootloader 50 system-frequency = <0>; // from bootloader
49 51
50 cdm@200 { 52 cdm@200 {
51 compatible = "fsl,mpc5200-cdm"; 53 compatible = "fsl,mpc5200-cdm";
52 reg = <200 38>; 54 reg = <0x200 0x38>;
53 }; 55 };
54 56
55 mpc5200_pic: interrupt-controller@500 { 57 mpc5200_pic: interrupt-controller@500 {
@@ -57,12 +59,12 @@
57 interrupt-controller; 59 interrupt-controller;
58 #interrupt-cells = <3>; 60 #interrupt-cells = <3>;
59 compatible = "fsl,mpc5200-pic"; 61 compatible = "fsl,mpc5200-pic";
60 reg = <500 80>; 62 reg = <0x500 0x80>;
61 }; 63 };
62 64
63 timer@600 { // General Purpose Timer 65 timer@600 { // General Purpose Timer
64 compatible = "fsl,mpc5200-gpt"; 66 compatible = "fsl,mpc5200-gpt";
65 reg = <600 10>; 67 reg = <0x600 0x10>;
66 interrupts = <1 9 0>; 68 interrupts = <1 9 0>;
67 interrupt-parent = <&mpc5200_pic>; 69 interrupt-parent = <&mpc5200_pic>;
68 fsl,has-wdt; 70 fsl,has-wdt;
@@ -70,38 +72,38 @@
70 72
71 gpio@b00 { 73 gpio@b00 {
72 compatible = "fsl,mpc5200-gpio"; 74 compatible = "fsl,mpc5200-gpio";
73 reg = <b00 40>; 75 reg = <0xb00 0x40>;
74 interrupts = <1 7 0>; 76 interrupts = <1 7 0>;
75 interrupt-parent = <&mpc5200_pic>; 77 interrupt-parent = <&mpc5200_pic>;
76 }; 78 };
77 79
78 usb@1000 { 80 usb@1000 {
79 compatible = "fsl,mpc5200-ohci","ohci-be"; 81 compatible = "fsl,mpc5200-ohci","ohci-be";
80 reg = <1000 ff>; 82 reg = <0x1000 0xff>;
81 interrupts = <2 6 0>; 83 interrupts = <2 6 0>;
82 interrupt-parent = <&mpc5200_pic>; 84 interrupt-parent = <&mpc5200_pic>;
83 }; 85 };
84 86
85 dma-controller@1200 { 87 dma-controller@1200 {
86 compatible = "fsl,mpc5200-bestcomm"; 88 compatible = "fsl,mpc5200-bestcomm";
87 reg = <1200 80>; 89 reg = <0x1200 0x80>;
88 interrupts = <3 0 0 3 1 0 3 2 0 3 3 0 90 interrupts = <3 0 0 3 1 0 3 2 0 3 3 0
89 3 4 0 3 5 0 3 6 0 3 7 0 91 3 4 0 3 5 0 3 6 0 3 7 0
90 3 8 0 3 9 0 3 a 0 3 b 0 92 3 8 0 3 9 0 3 10 0 3 11 0
91 3 c 0 3 d 0 3 e 0 3 f 0>; 93 3 12 0 3 13 0 3 14 0 3 15 0>;
92 interrupt-parent = <&mpc5200_pic>; 94 interrupt-parent = <&mpc5200_pic>;
93 }; 95 };
94 96
95 xlb@1f00 { 97 xlb@1f00 {
96 compatible = "fsl,mpc5200-xlb"; 98 compatible = "fsl,mpc5200-xlb";
97 reg = <1f00 100>; 99 reg = <0x1f00 0x100>;
98 }; 100 };
99 101
100 serial@2000 { // PSC1 102 serial@2000 { // PSC1
101 device_type = "serial"; 103 device_type = "serial";
102 compatible = "fsl,mpc5200-psc-uart"; 104 compatible = "fsl,mpc5200-psc-uart";
103 port-number = <0>; // Logical port assignment 105 port-number = <0>; // Logical port assignment
104 reg = <2000 100>; 106 reg = <0x2000 0x100>;
105 interrupts = <2 1 0>; 107 interrupts = <2 1 0>;
106 interrupt-parent = <&mpc5200_pic>; 108 interrupt-parent = <&mpc5200_pic>;
107 }; 109 };
@@ -110,7 +112,7 @@
110 device_type = "serial"; 112 device_type = "serial";
111 compatible = "fsl,mpc5200-psc-uart"; 113 compatible = "fsl,mpc5200-psc-uart";
112 port-number = <1>; // Logical port assignment 114 port-number = <1>; // Logical port assignment
113 reg = <2200 100>; 115 reg = <0x2200 0x100>;
114 interrupts = <2 2 0>; 116 interrupts = <2 2 0>;
115 interrupt-parent = <&mpc5200_pic>; 117 interrupt-parent = <&mpc5200_pic>;
116 }; 118 };
@@ -119,7 +121,7 @@
119 device_type = "serial"; 121 device_type = "serial";
120 compatible = "fsl,mpc5200-psc-uart"; 122 compatible = "fsl,mpc5200-psc-uart";
121 port-number = <2>; // Logical port assignment 123 port-number = <2>; // Logical port assignment
122 reg = <2400 100>; 124 reg = <0x2400 0x100>;
123 interrupts = <2 3 0>; 125 interrupts = <2 3 0>;
124 interrupt-parent = <&mpc5200_pic>; 126 interrupt-parent = <&mpc5200_pic>;
125 }; 127 };
@@ -127,7 +129,7 @@
127 ethernet@3000 { 129 ethernet@3000 {
128 device_type = "network"; 130 device_type = "network";
129 compatible = "fsl,mpc5200-fec"; 131 compatible = "fsl,mpc5200-fec";
130 reg = <3000 400>; 132 reg = <0x3000 0x400>;
131 local-mac-address = [ 00 00 00 00 00 00 ]; 133 local-mac-address = [ 00 00 00 00 00 00 ];
132 interrupts = <2 5 0>; 134 interrupts = <2 5 0>;
133 interrupt-parent = <&mpc5200_pic>; 135 interrupt-parent = <&mpc5200_pic>;
@@ -137,8 +139,8 @@
137 mdio@3000 { 139 mdio@3000 {
138 #address-cells = <1>; 140 #address-cells = <1>;
139 #size-cells = <0>; 141 #size-cells = <0>;
140 compatible = "fsl,mpc5200b-mdio","fsl,mpc5200-mdio"; 142 compatible = "fsl,mpc5200-mdio";
141 reg = <3000 400>; // fec range, since we need to setup fec interrupts 143 reg = <0x3000 0x400>; // fec range, since we need to setup fec interrupts
142 interrupts = <2 5 0>; // these are for "mii command finished", not link changes & co. 144 interrupts = <2 5 0>; // these are for "mii command finished", not link changes & co.
143 interrupt-parent = <&mpc5200_pic>; 145 interrupt-parent = <&mpc5200_pic>;
144 146
@@ -150,7 +152,7 @@
150 152
151 ata@3a00 { 153 ata@3a00 {
152 compatible = "fsl,mpc5200-ata"; 154 compatible = "fsl,mpc5200-ata";
153 reg = <3a00 100>; 155 reg = <0x3a00 0x100>;
154 interrupts = <2 7 0>; 156 interrupts = <2 7 0>;
155 interrupt-parent = <&mpc5200_pic>; 157 interrupt-parent = <&mpc5200_pic>;
156 }; 158 };
@@ -159,21 +161,21 @@
159 #address-cells = <1>; 161 #address-cells = <1>;
160 #size-cells = <0>; 162 #size-cells = <0>;
161 compatible = "fsl,mpc5200-i2c","fsl-i2c"; 163 compatible = "fsl,mpc5200-i2c","fsl-i2c";
162 reg = <3d40 40>; 164 reg = <0x3d40 0x40>;
163 interrupts = <2 10 0>; 165 interrupts = <2 16 0>;
164 interrupt-parent = <&mpc5200_pic>; 166 interrupt-parent = <&mpc5200_pic>;
165 fsl5200-clocking; 167 fsl5200-clocking;
166 168
167 rtc@68 { 169 rtc@68 {
168 device_type = "rtc"; 170 device_type = "rtc";
169 compatible = "dallas,ds1307"; 171 compatible = "dallas,ds1307";
170 reg = <68>; 172 reg = <0x68>;
171 }; 173 };
172 }; 174 };
173 175
174 sram@8000 { 176 sram@8000 {
175 compatible = "fsl,mpc5200-sram"; 177 compatible = "fsl,mpc5200-sram";
176 reg = <8000 4000>; 178 reg = <0x8000 0x4000>;
177 }; 179 };
178 }; 180 };
179 181
@@ -182,11 +184,11 @@
182 compatible = "fsl,lpb"; 184 compatible = "fsl,lpb";
183 #address-cells = <2>; 185 #address-cells = <2>;
184 #size-cells = <1>; 186 #size-cells = <1>;
185 ranges = <0 0 fc000000 02000000>; 187 ranges = <0 0 0xfc000000 0x02000000>;
186 188
187 flash@0,0 { 189 flash@0,0 {
188 compatible = "cfi-flash"; 190 compatible = "cfi-flash";
189 reg = <0 0 02000000>; 191 reg = <0 0 0x02000000>;
190 bank-width = <4>; 192 bank-width = <4>;
191 device-width = <2>; 193 device-width = <2>;
192 #size-cells = <1>; 194 #size-cells = <1>;
@@ -200,18 +202,18 @@
200 #address-cells = <3>; 202 #address-cells = <3>;
201 device_type = "pci"; 203 device_type = "pci";
202 compatible = "fsl,mpc5200-pci"; 204 compatible = "fsl,mpc5200-pci";
203 reg = <f0000d00 100>; 205 reg = <0xf0000d00 0x100>;
204 interrupt-map-mask = <f800 0 0 7>; 206 interrupt-map-mask = <0xf800 0 0 7>;
205 interrupt-map = <c000 0 0 1 &mpc5200_pic 0 0 3 207 interrupt-map = <0xc000 0 0 1 &mpc5200_pic 0 0 3
206 c000 0 0 2 &mpc5200_pic 0 0 3 208 0xc000 0 0 2 &mpc5200_pic 0 0 3
207 c000 0 0 3 &mpc5200_pic 0 0 3 209 0xc000 0 0 3 &mpc5200_pic 0 0 3
208 c000 0 0 4 &mpc5200_pic 0 0 3>; 210 0xc000 0 0 4 &mpc5200_pic 0 0 3>;
209 clock-frequency = <0>; // From boot loader 211 clock-frequency = <0>; // From boot loader
210 interrupts = <2 8 0 2 9 0 2 a 0>; 212 interrupts = <2 8 0 2 9 0 2 10 0>;
211 interrupt-parent = <&mpc5200_pic>; 213 interrupt-parent = <&mpc5200_pic>;
212 bus-range = <0 0>; 214 bus-range = <0 0>;
213 ranges = <42000000 0 80000000 80000000 0 10000000 215 ranges = <0x42000000 0 0x80000000 0x80000000 0 0x10000000
214 02000000 0 90000000 90000000 0 10000000 216 0x02000000 0 0x90000000 0x90000000 0 0x10000000
215 01000000 0 00000000 a0000000 0 01000000>; 217 0x01000000 0 0x00000000 0xa0000000 0 0x01000000>;
216 }; 218 };
217}; 219};
diff --git a/arch/powerpc/configs/52xx/cm5200_defconfig b/arch/powerpc/configs/52xx/cm5200_defconfig
new file mode 100644
index 000000000000..c10f7395aa1b
--- /dev/null
+++ b/arch/powerpc/configs/52xx/cm5200_defconfig
@@ -0,0 +1,1099 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.25
4# Tue Apr 29 07:11:37 2008
5#
6# CONFIG_PPC64 is not set
7
8#
9# Processor support
10#
11CONFIG_6xx=y
12# CONFIG_PPC_85xx is not set
13# CONFIG_PPC_8xx is not set
14# CONFIG_40x is not set
15# CONFIG_44x is not set
16# CONFIG_E200 is not set
17CONFIG_PPC_FPU=y
18# CONFIG_ALTIVEC is not set
19CONFIG_PPC_STD_MMU=y
20CONFIG_PPC_STD_MMU_32=y
21# CONFIG_PPC_MM_SLICES is not set
22# CONFIG_SMP is not set
23CONFIG_PPC32=y
24CONFIG_WORD_SIZE=32
25CONFIG_PPC_MERGE=y
26CONFIG_MMU=y
27CONFIG_GENERIC_CMOS_UPDATE=y
28CONFIG_GENERIC_TIME=y
29CONFIG_GENERIC_TIME_VSYSCALL=y
30CONFIG_GENERIC_CLOCKEVENTS=y
31CONFIG_GENERIC_HARDIRQS=y
32# CONFIG_HAVE_SETUP_PER_CPU_AREA is not set
33CONFIG_IRQ_PER_CPU=y
34CONFIG_STACKTRACE_SUPPORT=y
35CONFIG_LOCKDEP_SUPPORT=y
36CONFIG_RWSEM_XCHGADD_ALGORITHM=y
37CONFIG_ARCH_HAS_ILOG2_U32=y
38CONFIG_GENERIC_HWEIGHT=y
39CONFIG_GENERIC_CALIBRATE_DELAY=y
40CONFIG_GENERIC_FIND_NEXT_BIT=y
41# CONFIG_ARCH_NO_VIRT_TO_BUS is not set
42CONFIG_PPC=y
43CONFIG_EARLY_PRINTK=y
44CONFIG_GENERIC_NVRAM=y
45CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
46CONFIG_ARCH_MAY_HAVE_PC_FDC=y
47CONFIG_PPC_OF=y
48CONFIG_OF=y
49# CONFIG_PPC_UDBG_16550 is not set
50# CONFIG_GENERIC_TBSYNC is not set
51CONFIG_AUDIT_ARCH=y
52CONFIG_GENERIC_BUG=y
53CONFIG_DEFAULT_UIMAGE=y
54# CONFIG_PPC_DCR_NATIVE is not set
55# CONFIG_PPC_DCR_MMIO is not set
56CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
57
58#
59# General setup
60#
61CONFIG_EXPERIMENTAL=y
62CONFIG_BROKEN_ON_SMP=y
63CONFIG_INIT_ENV_ARG_LIMIT=32
64CONFIG_LOCALVERSION=""
65CONFIG_LOCALVERSION_AUTO=y
66CONFIG_SWAP=y
67CONFIG_SYSVIPC=y
68CONFIG_SYSVIPC_SYSCTL=y
69# CONFIG_POSIX_MQUEUE is not set
70# CONFIG_BSD_PROCESS_ACCT is not set
71# CONFIG_TASKSTATS is not set
72# CONFIG_AUDIT is not set
73# CONFIG_IKCONFIG is not set
74CONFIG_LOG_BUF_SHIFT=14
75# CONFIG_CGROUPS is not set
76CONFIG_GROUP_SCHED=y
77CONFIG_FAIR_GROUP_SCHED=y
78# CONFIG_RT_GROUP_SCHED is not set
79CONFIG_USER_SCHED=y
80# CONFIG_CGROUP_SCHED is not set
81CONFIG_SYSFS_DEPRECATED=y
82CONFIG_SYSFS_DEPRECATED_V2=y
83# CONFIG_RELAY is not set
84# CONFIG_NAMESPACES is not set
85CONFIG_BLK_DEV_INITRD=y
86CONFIG_INITRAMFS_SOURCE=""
87# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
88CONFIG_SYSCTL=y
89CONFIG_EMBEDDED=y
90# CONFIG_SYSCTL_SYSCALL is not set
91# CONFIG_KALLSYMS is not set
92CONFIG_HOTPLUG=y
93CONFIG_PRINTK=y
94CONFIG_BUG=y
95CONFIG_ELF_CORE=y
96CONFIG_COMPAT_BRK=y
97CONFIG_BASE_FULL=y
98CONFIG_FUTEX=y
99CONFIG_ANON_INODES=y
100# CONFIG_EPOLL is not set
101CONFIG_SIGNALFD=y
102CONFIG_TIMERFD=y
103CONFIG_EVENTFD=y
104CONFIG_SHMEM=y
105CONFIG_VM_EVENT_COUNTERS=y
106CONFIG_SLUB_DEBUG=y
107# CONFIG_SLAB is not set
108CONFIG_SLUB=y
109# CONFIG_SLOB is not set
110# CONFIG_PROFILING is not set
111# CONFIG_MARKERS is not set
112CONFIG_HAVE_OPROFILE=y
113CONFIG_HAVE_KPROBES=y
114CONFIG_HAVE_KRETPROBES=y
115CONFIG_PROC_PAGE_MONITOR=y
116CONFIG_SLABINFO=y
117CONFIG_RT_MUTEXES=y
118# CONFIG_TINY_SHMEM is not set
119CONFIG_BASE_SMALL=0
120# CONFIG_MODULES is not set
121CONFIG_BLOCK=y
122# CONFIG_LBD is not set
123# CONFIG_BLK_DEV_IO_TRACE is not set
124# CONFIG_LSF is not set
125# CONFIG_BLK_DEV_BSG is not set
126
127#
128# IO Schedulers
129#
130CONFIG_IOSCHED_NOOP=y
131CONFIG_IOSCHED_AS=y
132CONFIG_IOSCHED_DEADLINE=y
133CONFIG_IOSCHED_CFQ=y
134CONFIG_DEFAULT_AS=y
135# CONFIG_DEFAULT_DEADLINE is not set
136# CONFIG_DEFAULT_CFQ is not set
137# CONFIG_DEFAULT_NOOP is not set
138CONFIG_DEFAULT_IOSCHED="anticipatory"
139CONFIG_CLASSIC_RCU=y
140
141#
142# Platform support
143#
144CONFIG_PPC_MULTIPLATFORM=y
145# CONFIG_PPC_82xx is not set
146# CONFIG_PPC_83xx is not set
147# CONFIG_PPC_86xx is not set
148CONFIG_CLASSIC32=y
149# CONFIG_PPC_CHRP is not set
150# CONFIG_PPC_MPC512x is not set
151# CONFIG_PPC_MPC5121 is not set
152# CONFIG_MPC5121_ADS is not set
153CONFIG_PPC_MPC52xx=y
154CONFIG_PPC_MPC5200_SIMPLE=y
155# CONFIG_PPC_EFIKA is not set
156# CONFIG_PPC_LITE5200 is not set
157# CONFIG_PPC_MPC5200_BUGFIX is not set
158# CONFIG_PPC_MPC5200_GPIO is not set
159# CONFIG_PPC_PMAC is not set
160# CONFIG_PPC_CELL is not set
161# CONFIG_PPC_CELL_NATIVE is not set
162# CONFIG_PQ2ADS is not set
163# CONFIG_EMBEDDED6xx is not set
164# CONFIG_IPIC is not set
165# CONFIG_MPIC is not set
166# CONFIG_MPIC_WEIRD is not set
167# CONFIG_PPC_I8259 is not set
168# CONFIG_PPC_RTAS is not set
169# CONFIG_MMIO_NVRAM is not set
170# CONFIG_PPC_MPC106 is not set
171# CONFIG_PPC_970_NAP is not set
172# CONFIG_PPC_INDIRECT_IO is not set
173# CONFIG_GENERIC_IOMAP is not set
174# CONFIG_CPU_FREQ is not set
175# CONFIG_TAU is not set
176# CONFIG_FSL_ULI1575 is not set
177CONFIG_PPC_BESTCOMM=y
178# CONFIG_PPC_BESTCOMM_ATA is not set
179CONFIG_PPC_BESTCOMM_FEC=y
180# CONFIG_PPC_BESTCOMM_GEN_BD is not set
181
182#
183# Kernel options
184#
185# CONFIG_HIGHMEM is not set
186# CONFIG_TICK_ONESHOT is not set
187# CONFIG_NO_HZ is not set
188# CONFIG_HIGH_RES_TIMERS is not set
189CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
190# CONFIG_HZ_100 is not set
191CONFIG_HZ_250=y
192# CONFIG_HZ_300 is not set
193# CONFIG_HZ_1000 is not set
194CONFIG_HZ=250
195# CONFIG_SCHED_HRTICK is not set
196CONFIG_PREEMPT_NONE=y
197# CONFIG_PREEMPT_VOLUNTARY is not set
198# CONFIG_PREEMPT is not set
199CONFIG_BINFMT_ELF=y
200# CONFIG_BINFMT_MISC is not set
201# CONFIG_IOMMU_HELPER is not set
202CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
203CONFIG_ARCH_HAS_WALK_MEMORY=y
204CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
205# CONFIG_KEXEC is not set
206CONFIG_ARCH_FLATMEM_ENABLE=y
207CONFIG_ARCH_POPULATES_NODE_MAP=y
208CONFIG_SELECT_MEMORY_MODEL=y
209CONFIG_FLATMEM_MANUAL=y
210# CONFIG_DISCONTIGMEM_MANUAL is not set
211# CONFIG_SPARSEMEM_MANUAL is not set
212CONFIG_FLATMEM=y
213CONFIG_FLAT_NODE_MEM_MAP=y
214# CONFIG_SPARSEMEM_STATIC is not set
215# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
216CONFIG_PAGEFLAGS_EXTENDED=y
217CONFIG_SPLIT_PTLOCK_CPUS=4
218# CONFIG_RESOURCES_64BIT is not set
219CONFIG_ZONE_DMA_FLAG=1
220CONFIG_BOUNCE=y
221CONFIG_VIRT_TO_BUS=y
222CONFIG_FORCE_MAX_ZONEORDER=11
223CONFIG_PROC_DEVICETREE=y
224# CONFIG_CMDLINE_BOOL is not set
225CONFIG_PM=y
226# CONFIG_PM_LEGACY is not set
227# CONFIG_PM_DEBUG is not set
228CONFIG_SECCOMP=y
229CONFIG_ISA_DMA_API=y
230
231#
232# Bus options
233#
234CONFIG_ZONE_DMA=y
235CONFIG_GENERIC_ISA_DMA=y
236CONFIG_FSL_SOC=y
237# CONFIG_PCI is not set
238# CONFIG_PCI_DOMAINS is not set
239# CONFIG_PCI_SYSCALL is not set
240# CONFIG_ARCH_SUPPORTS_MSI is not set
241# CONFIG_PCCARD is not set
242# CONFIG_HAS_RAPIDIO is not set
243
244#
245# Advanced setup
246#
247# CONFIG_ADVANCED_OPTIONS is not set
248
249#
250# Default settings for advanced configuration options are used
251#
252CONFIG_LOWMEM_SIZE=0x30000000
253CONFIG_PAGE_OFFSET=0xc0000000
254CONFIG_KERNEL_START=0xc0000000
255CONFIG_PHYSICAL_START=0x00000000
256CONFIG_TASK_SIZE=0xc0000000
257
258#
259# Networking
260#
261CONFIG_NET=y
262
263#
264# Networking options
265#
266CONFIG_PACKET=y
267# CONFIG_PACKET_MMAP is not set
268CONFIG_UNIX=y
269CONFIG_XFRM=y
270CONFIG_XFRM_USER=y
271# CONFIG_XFRM_SUB_POLICY is not set
272# CONFIG_XFRM_MIGRATE is not set
273# CONFIG_XFRM_STATISTICS is not set
274# CONFIG_NET_KEY is not set
275CONFIG_INET=y
276CONFIG_IP_MULTICAST=y
277# CONFIG_IP_ADVANCED_ROUTER is not set
278CONFIG_IP_FIB_HASH=y
279CONFIG_IP_PNP=y
280CONFIG_IP_PNP_DHCP=y
281CONFIG_IP_PNP_BOOTP=y
282# CONFIG_IP_PNP_RARP is not set
283# CONFIG_NET_IPIP is not set
284# CONFIG_NET_IPGRE is not set
285# CONFIG_IP_MROUTE is not set
286# CONFIG_ARPD is not set
287CONFIG_SYN_COOKIES=y
288# CONFIG_INET_AH is not set
289# CONFIG_INET_ESP is not set
290# CONFIG_INET_IPCOMP is not set
291# CONFIG_INET_XFRM_TUNNEL is not set
292# CONFIG_INET_TUNNEL is not set
293CONFIG_INET_XFRM_MODE_TRANSPORT=y
294CONFIG_INET_XFRM_MODE_TUNNEL=y
295CONFIG_INET_XFRM_MODE_BEET=y
296# CONFIG_INET_LRO is not set
297CONFIG_INET_DIAG=y
298CONFIG_INET_TCP_DIAG=y
299# CONFIG_TCP_CONG_ADVANCED is not set
300CONFIG_TCP_CONG_CUBIC=y
301CONFIG_DEFAULT_TCP_CONG="cubic"
302# CONFIG_TCP_MD5SIG is not set
303# CONFIG_IPV6 is not set
304# CONFIG_NETWORK_SECMARK is not set
305# CONFIG_NETFILTER is not set
306# CONFIG_IP_DCCP is not set
307# CONFIG_IP_SCTP is not set
308# CONFIG_TIPC is not set
309# CONFIG_ATM is not set
310# CONFIG_BRIDGE is not set
311# CONFIG_VLAN_8021Q is not set
312# CONFIG_DECNET is not set
313# CONFIG_LLC2 is not set
314# CONFIG_IPX is not set
315# CONFIG_ATALK is not set
316# CONFIG_X25 is not set
317# CONFIG_LAPB is not set
318# CONFIG_ECONET is not set
319# CONFIG_WAN_ROUTER is not set
320# CONFIG_NET_SCHED is not set
321
322#
323# Network testing
324#
325# CONFIG_NET_PKTGEN is not set
326# CONFIG_HAMRADIO is not set
327# CONFIG_CAN is not set
328# CONFIG_IRDA is not set
329# CONFIG_BT is not set
330# CONFIG_AF_RXRPC is not set
331
332#
333# Wireless
334#
335# CONFIG_CFG80211 is not set
336# CONFIG_WIRELESS_EXT is not set
337# CONFIG_MAC80211 is not set
338# CONFIG_IEEE80211 is not set
339# CONFIG_RFKILL is not set
340# CONFIG_NET_9P is not set
341
342#
343# Device Drivers
344#
345
346#
347# Generic Driver Options
348#
349CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
350CONFIG_STANDALONE=y
351CONFIG_PREVENT_FIRMWARE_BUILD=y
352# CONFIG_FW_LOADER is not set
353# CONFIG_DEBUG_DRIVER is not set
354# CONFIG_DEBUG_DEVRES is not set
355# CONFIG_SYS_HYPERVISOR is not set
356# CONFIG_CONNECTOR is not set
357CONFIG_MTD=y
358# CONFIG_MTD_DEBUG is not set
359# CONFIG_MTD_CONCAT is not set
360CONFIG_MTD_PARTITIONS=y
361# CONFIG_MTD_REDBOOT_PARTS is not set
362CONFIG_MTD_CMDLINE_PARTS=y
363# CONFIG_MTD_OF_PARTS is not set
364# CONFIG_MTD_AR7_PARTS is not set
365
366#
367# User Modules And Translation Layers
368#
369CONFIG_MTD_CHAR=y
370CONFIG_MTD_BLKDEVS=y
371CONFIG_MTD_BLOCK=y
372# CONFIG_FTL is not set
373# CONFIG_NFTL is not set
374# CONFIG_INFTL is not set
375# CONFIG_RFD_FTL is not set
376# CONFIG_SSFDC is not set
377# CONFIG_MTD_OOPS is not set
378
379#
380# RAM/ROM/Flash chip drivers
381#
382CONFIG_MTD_CFI=y
383# CONFIG_MTD_JEDECPROBE is not set
384CONFIG_MTD_GEN_PROBE=y
385# CONFIG_MTD_CFI_ADV_OPTIONS is not set
386CONFIG_MTD_MAP_BANK_WIDTH_1=y
387CONFIG_MTD_MAP_BANK_WIDTH_2=y
388CONFIG_MTD_MAP_BANK_WIDTH_4=y
389# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
390# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
391# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
392CONFIG_MTD_CFI_I1=y
393CONFIG_MTD_CFI_I2=y
394# CONFIG_MTD_CFI_I4 is not set
395# CONFIG_MTD_CFI_I8 is not set
396# CONFIG_MTD_CFI_INTELEXT is not set
397CONFIG_MTD_CFI_AMDSTD=y
398# CONFIG_MTD_CFI_STAA is not set
399CONFIG_MTD_CFI_UTIL=y
400# CONFIG_MTD_RAM is not set
401# CONFIG_MTD_ROM is not set
402# CONFIG_MTD_ABSENT is not set
403
404#
405# Mapping drivers for chip access
406#
407# CONFIG_MTD_COMPLEX_MAPPINGS is not set
408# CONFIG_MTD_PHYSMAP is not set
409CONFIG_MTD_PHYSMAP_OF=y
410# CONFIG_MTD_PLATRAM is not set
411
412#
413# Self-contained MTD device drivers
414#
415# CONFIG_MTD_SLRAM is not set
416# CONFIG_MTD_PHRAM is not set
417# CONFIG_MTD_MTDRAM is not set
418# CONFIG_MTD_BLOCK2MTD is not set
419
420#
421# Disk-On-Chip Device Drivers
422#
423# CONFIG_MTD_DOC2000 is not set
424# CONFIG_MTD_DOC2001 is not set
425# CONFIG_MTD_DOC2001PLUS is not set
426# CONFIG_MTD_NAND is not set
427# CONFIG_MTD_ONENAND is not set
428
429#
430# UBI - Unsorted block images
431#
432# CONFIG_MTD_UBI is not set
433CONFIG_OF_DEVICE=y
434CONFIG_OF_I2C=y
435# CONFIG_PARPORT is not set
436CONFIG_BLK_DEV=y
437# CONFIG_BLK_DEV_FD is not set
438# CONFIG_BLK_DEV_COW_COMMON is not set
439CONFIG_BLK_DEV_LOOP=y
440# CONFIG_BLK_DEV_CRYPTOLOOP is not set
441# CONFIG_BLK_DEV_NBD is not set
442# CONFIG_BLK_DEV_UB is not set
443CONFIG_BLK_DEV_RAM=y
444CONFIG_BLK_DEV_RAM_COUNT=16
445CONFIG_BLK_DEV_RAM_SIZE=32768
446# CONFIG_BLK_DEV_XIP is not set
447# CONFIG_CDROM_PKTCDVD is not set
448# CONFIG_ATA_OVER_ETH is not set
449# CONFIG_MISC_DEVICES is not set
450CONFIG_HAVE_IDE=y
451# CONFIG_IDE is not set
452
453#
454# SCSI device support
455#
456# CONFIG_RAID_ATTRS is not set
457CONFIG_SCSI=y
458CONFIG_SCSI_DMA=y
459# CONFIG_SCSI_TGT is not set
460# CONFIG_SCSI_NETLINK is not set
461CONFIG_SCSI_PROC_FS=y
462
463#
464# SCSI support type (disk, tape, CD-ROM)
465#
466CONFIG_BLK_DEV_SD=y
467# CONFIG_CHR_DEV_ST is not set
468# CONFIG_CHR_DEV_OSST is not set
469# CONFIG_BLK_DEV_SR is not set
470CONFIG_CHR_DEV_SG=y
471# CONFIG_CHR_DEV_SCH is not set
472
473#
474# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
475#
476# CONFIG_SCSI_MULTI_LUN is not set
477# CONFIG_SCSI_CONSTANTS is not set
478# CONFIG_SCSI_LOGGING is not set
479# CONFIG_SCSI_SCAN_ASYNC is not set
480
481#
482# SCSI Transports
483#
484# CONFIG_SCSI_SPI_ATTRS is not set
485# CONFIG_SCSI_FC_ATTRS is not set
486# CONFIG_SCSI_ISCSI_ATTRS is not set
487# CONFIG_SCSI_SAS_LIBSAS is not set
488# CONFIG_SCSI_SRP_ATTRS is not set
489# CONFIG_SCSI_LOWLEVEL is not set
490# CONFIG_ATA is not set
491# CONFIG_MD is not set
492# CONFIG_MACINTOSH_DRIVERS is not set
493CONFIG_NETDEVICES=y
494# CONFIG_NETDEVICES_MULTIQUEUE is not set
495# CONFIG_DUMMY is not set
496# CONFIG_BONDING is not set
497# CONFIG_MACVLAN is not set
498# CONFIG_EQUALIZER is not set
499# CONFIG_TUN is not set
500# CONFIG_VETH is not set
501CONFIG_PHYLIB=y
502
503#
504# MII PHY device drivers
505#
506# CONFIG_MARVELL_PHY is not set
507# CONFIG_DAVICOM_PHY is not set
508# CONFIG_QSEMI_PHY is not set
509CONFIG_LXT_PHY=y
510# CONFIG_CICADA_PHY is not set
511# CONFIG_VITESSE_PHY is not set
512# CONFIG_SMSC_PHY is not set
513# CONFIG_BROADCOM_PHY is not set
514# CONFIG_ICPLUS_PHY is not set
515# CONFIG_REALTEK_PHY is not set
516# CONFIG_FIXED_PHY is not set
517# CONFIG_MDIO_BITBANG is not set
518CONFIG_NET_ETHERNET=y
519# CONFIG_MII is not set
520# CONFIG_IBM_NEW_EMAC_ZMII is not set
521# CONFIG_IBM_NEW_EMAC_RGMII is not set
522# CONFIG_IBM_NEW_EMAC_TAH is not set
523# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
524# CONFIG_B44 is not set
525CONFIG_FEC_MPC52xx=y
526CONFIG_FEC_MPC52xx_MDIO=y
527# CONFIG_NETDEV_1000 is not set
528# CONFIG_NETDEV_10000 is not set
529
530#
531# Wireless LAN
532#
533# CONFIG_WLAN_PRE80211 is not set
534# CONFIG_WLAN_80211 is not set
535# CONFIG_IWLWIFI is not set
536# CONFIG_IWLWIFI_LEDS is not set
537
538#
539# USB Network Adapters
540#
541# CONFIG_USB_CATC is not set
542# CONFIG_USB_KAWETH is not set
543# CONFIG_USB_PEGASUS is not set
544# CONFIG_USB_RTL8150 is not set
545# CONFIG_USB_USBNET is not set
546# CONFIG_WAN is not set
547# CONFIG_PPP is not set
548# CONFIG_SLIP is not set
549# CONFIG_NETCONSOLE is not set
550# CONFIG_NETPOLL is not set
551# CONFIG_NET_POLL_CONTROLLER is not set
552# CONFIG_ISDN is not set
553# CONFIG_PHONE is not set
554
555#
556# Input device support
557#
558# CONFIG_INPUT is not set
559
560#
561# Hardware I/O ports
562#
563# CONFIG_SERIO is not set
564# CONFIG_GAMEPORT is not set
565
566#
567# Character devices
568#
569# CONFIG_VT is not set
570# CONFIG_SERIAL_NONSTANDARD is not set
571
572#
573# Serial drivers
574#
575# CONFIG_SERIAL_8250 is not set
576
577#
578# Non-8250 serial port support
579#
580# CONFIG_SERIAL_UARTLITE is not set
581CONFIG_SERIAL_CORE=y
582CONFIG_SERIAL_CORE_CONSOLE=y
583CONFIG_SERIAL_MPC52xx=y
584CONFIG_SERIAL_MPC52xx_CONSOLE=y
585CONFIG_SERIAL_MPC52xx_CONSOLE_BAUD=57600
586CONFIG_UNIX98_PTYS=y
587CONFIG_LEGACY_PTYS=y
588CONFIG_LEGACY_PTY_COUNT=256
589# CONFIG_IPMI_HANDLER is not set
590# CONFIG_HW_RANDOM is not set
591# CONFIG_NVRAM is not set
592# CONFIG_GEN_RTC is not set
593# CONFIG_R3964 is not set
594# CONFIG_RAW_DRIVER is not set
595# CONFIG_TCG_TPM is not set
596CONFIG_I2C=y
597CONFIG_I2C_BOARDINFO=y
598CONFIG_I2C_CHARDEV=y
599
600#
601# I2C Hardware Bus support
602#
603CONFIG_I2C_MPC=y
604# CONFIG_I2C_OCORES is not set
605# CONFIG_I2C_PARPORT_LIGHT is not set
606# CONFIG_I2C_SIMTEC is not set
607# CONFIG_I2C_TAOS_EVM is not set
608# CONFIG_I2C_TINY_USB is not set
609# CONFIG_I2C_PCA_PLATFORM is not set
610
611#
612# Miscellaneous I2C Chip support
613#
614# CONFIG_DS1682 is not set
615# CONFIG_SENSORS_EEPROM is not set
616# CONFIG_SENSORS_PCF8574 is not set
617# CONFIG_PCF8575 is not set
618# CONFIG_SENSORS_PCF8591 is not set
619# CONFIG_SENSORS_MAX6875 is not set
620# CONFIG_SENSORS_TSL2550 is not set
621# CONFIG_I2C_DEBUG_CORE is not set
622# CONFIG_I2C_DEBUG_ALGO is not set
623# CONFIG_I2C_DEBUG_BUS is not set
624# CONFIG_I2C_DEBUG_CHIP is not set
625# CONFIG_SPI is not set
626# CONFIG_W1 is not set
627# CONFIG_POWER_SUPPLY is not set
628# CONFIG_HWMON is not set
629# CONFIG_THERMAL is not set
630CONFIG_WATCHDOG=y
631# CONFIG_WATCHDOG_NOWAYOUT is not set
632
633#
634# Watchdog Device Drivers
635#
636# CONFIG_SOFT_WATCHDOG is not set
637# CONFIG_MPC5200_WDT is not set
638
639#
640# USB-based Watchdog Cards
641#
642# CONFIG_USBPCWATCHDOG is not set
643
644#
645# Sonics Silicon Backplane
646#
647CONFIG_SSB_POSSIBLE=y
648# CONFIG_SSB is not set
649
650#
651# Multifunction device drivers
652#
653# CONFIG_MFD_SM501 is not set
654# CONFIG_HTC_PASIC3 is not set
655
656#
657# Multimedia devices
658#
659# CONFIG_VIDEO_DEV is not set
660# CONFIG_DVB_CORE is not set
661# CONFIG_DAB is not set
662
663#
664# Graphics support
665#
666# CONFIG_VGASTATE is not set
667# CONFIG_VIDEO_OUTPUT_CONTROL is not set
668# CONFIG_FB is not set
669# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
670
671#
672# Display device support
673#
674# CONFIG_DISPLAY_SUPPORT is not set
675
676#
677# Sound
678#
679# CONFIG_SOUND is not set
680CONFIG_USB_SUPPORT=y
681CONFIG_USB_ARCH_HAS_HCD=y
682CONFIG_USB_ARCH_HAS_OHCI=y
683# CONFIG_USB_ARCH_HAS_EHCI is not set
684CONFIG_USB=y
685# CONFIG_USB_DEBUG is not set
686# CONFIG_USB_ANNOUNCE_NEW_DEVICES is not set
687
688#
689# Miscellaneous USB options
690#
691CONFIG_USB_DEVICEFS=y
692# CONFIG_USB_DEVICE_CLASS is not set
693# CONFIG_USB_DYNAMIC_MINORS is not set
694# CONFIG_USB_SUSPEND is not set
695# CONFIG_USB_OTG is not set
696# CONFIG_USB_OTG_WHITELIST is not set
697# CONFIG_USB_OTG_BLACKLIST_HUB is not set
698
699#
700# USB Host Controller Drivers
701#
702# CONFIG_USB_ISP116X_HCD is not set
703CONFIG_USB_OHCI_HCD=y
704CONFIG_USB_OHCI_HCD_PPC_SOC=y
705CONFIG_USB_OHCI_HCD_PPC_OF=y
706CONFIG_USB_OHCI_HCD_PPC_OF_BE=y
707# CONFIG_USB_OHCI_HCD_PPC_OF_LE is not set
708CONFIG_USB_OHCI_BIG_ENDIAN_DESC=y
709CONFIG_USB_OHCI_BIG_ENDIAN_MMIO=y
710# CONFIG_USB_OHCI_LITTLE_ENDIAN is not set
711# CONFIG_USB_SL811_HCD is not set
712# CONFIG_USB_R8A66597_HCD is not set
713
714#
715# USB Device Class drivers
716#
717# CONFIG_USB_ACM is not set
718# CONFIG_USB_PRINTER is not set
719
720#
721# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
722#
723
724#
725# may also be needed; see USB_STORAGE Help for more information
726#
727CONFIG_USB_STORAGE=y
728# CONFIG_USB_STORAGE_DEBUG is not set
729# CONFIG_USB_STORAGE_DATAFAB is not set
730# CONFIG_USB_STORAGE_FREECOM is not set
731# CONFIG_USB_STORAGE_ISD200 is not set
732# CONFIG_USB_STORAGE_DPCM is not set
733# CONFIG_USB_STORAGE_USBAT is not set
734# CONFIG_USB_STORAGE_SDDR09 is not set
735# CONFIG_USB_STORAGE_SDDR55 is not set
736# CONFIG_USB_STORAGE_JUMPSHOT is not set
737# CONFIG_USB_STORAGE_ALAUDA is not set
738# CONFIG_USB_STORAGE_KARMA is not set
739# CONFIG_USB_STORAGE_CYPRESS_ATACB is not set
740# CONFIG_USB_LIBUSUAL is not set
741
742#
743# USB Imaging devices
744#
745# CONFIG_USB_MDC800 is not set
746# CONFIG_USB_MICROTEK is not set
747# CONFIG_USB_MON is not set
748
749#
750# USB port drivers
751#
752# CONFIG_USB_SERIAL is not set
753
754#
755# USB Miscellaneous drivers
756#
757# CONFIG_USB_EMI62 is not set
758# CONFIG_USB_EMI26 is not set
759# CONFIG_USB_ADUTUX is not set
760# CONFIG_USB_AUERSWALD is not set
761# CONFIG_USB_RIO500 is not set
762# CONFIG_USB_LEGOTOWER is not set
763# CONFIG_USB_LCD is not set
764# CONFIG_USB_BERRY_CHARGE is not set
765# CONFIG_USB_LED is not set
766# CONFIG_USB_CYPRESS_CY7C63 is not set
767# CONFIG_USB_CYTHERM is not set
768# CONFIG_USB_PHIDGET is not set
769# CONFIG_USB_IDMOUSE is not set
770# CONFIG_USB_FTDI_ELAN is not set
771# CONFIG_USB_APPLEDISPLAY is not set
772# CONFIG_USB_LD is not set
773# CONFIG_USB_TRANCEVIBRATOR is not set
774# CONFIG_USB_IOWARRIOR is not set
775# CONFIG_USB_TEST is not set
776# CONFIG_USB_GADGET is not set
777# CONFIG_MMC is not set
778# CONFIG_MEMSTICK is not set
779# CONFIG_NEW_LEDS is not set
780# CONFIG_EDAC is not set
781# CONFIG_RTC_CLASS is not set
782# CONFIG_DMADEVICES is not set
783# CONFIG_UIO is not set
784
785#
786# File systems
787#
788CONFIG_EXT2_FS=y
789# CONFIG_EXT2_FS_XATTR is not set
790# CONFIG_EXT2_FS_XIP is not set
791CONFIG_EXT3_FS=y
792CONFIG_EXT3_FS_XATTR=y
793# CONFIG_EXT3_FS_POSIX_ACL is not set
794# CONFIG_EXT3_FS_SECURITY is not set
795# CONFIG_EXT4DEV_FS is not set
796CONFIG_JBD=y
797CONFIG_FS_MBCACHE=y
798# CONFIG_REISERFS_FS is not set
799# CONFIG_JFS_FS is not set
800# CONFIG_FS_POSIX_ACL is not set
801# CONFIG_XFS_FS is not set
802# CONFIG_OCFS2_FS is not set
803CONFIG_DNOTIFY=y
804CONFIG_INOTIFY=y
805CONFIG_INOTIFY_USER=y
806# CONFIG_QUOTA is not set
807# CONFIG_AUTOFS_FS is not set
808# CONFIG_AUTOFS4_FS is not set
809# CONFIG_FUSE_FS is not set
810
811#
812# CD-ROM/DVD Filesystems
813#
814# CONFIG_ISO9660_FS is not set
815# CONFIG_UDF_FS is not set
816
817#
818# DOS/FAT/NT Filesystems
819#
820CONFIG_FAT_FS=y
821CONFIG_MSDOS_FS=y
822CONFIG_VFAT_FS=y
823CONFIG_FAT_DEFAULT_CODEPAGE=437
824CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
825# CONFIG_NTFS_FS is not set
826
827#
828# Pseudo filesystems
829#
830CONFIG_PROC_FS=y
831CONFIG_PROC_KCORE=y
832CONFIG_PROC_SYSCTL=y
833CONFIG_SYSFS=y
834CONFIG_TMPFS=y
835# CONFIG_TMPFS_POSIX_ACL is not set
836# CONFIG_HUGETLB_PAGE is not set
837# CONFIG_CONFIGFS_FS is not set
838
839#
840# Miscellaneous filesystems
841#
842# CONFIG_ADFS_FS is not set
843# CONFIG_AFFS_FS is not set
844# CONFIG_HFS_FS is not set
845# CONFIG_HFSPLUS_FS is not set
846# CONFIG_BEFS_FS is not set
847# CONFIG_BFS_FS is not set
848# CONFIG_EFS_FS is not set
849CONFIG_JFFS2_FS=y
850CONFIG_JFFS2_FS_DEBUG=0
851CONFIG_JFFS2_FS_WRITEBUFFER=y
852# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
853# CONFIG_JFFS2_SUMMARY is not set
854# CONFIG_JFFS2_FS_XATTR is not set
855# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
856CONFIG_JFFS2_ZLIB=y
857# CONFIG_JFFS2_LZO is not set
858CONFIG_JFFS2_RTIME=y
859# CONFIG_JFFS2_RUBIN is not set
860CONFIG_CRAMFS=y
861# CONFIG_VXFS_FS is not set
862# CONFIG_MINIX_FS is not set
863# CONFIG_HPFS_FS is not set
864# CONFIG_QNX4FS_FS is not set
865# CONFIG_ROMFS_FS is not set
866# CONFIG_SYSV_FS is not set
867# CONFIG_UFS_FS is not set
868CONFIG_NETWORK_FILESYSTEMS=y
869CONFIG_NFS_FS=y
870CONFIG_NFS_V3=y
871# CONFIG_NFS_V3_ACL is not set
872CONFIG_NFS_V4=y
873# CONFIG_NFSD is not set
874CONFIG_ROOT_NFS=y
875CONFIG_LOCKD=y
876CONFIG_LOCKD_V4=y
877CONFIG_NFS_COMMON=y
878CONFIG_SUNRPC=y
879CONFIG_SUNRPC_GSS=y
880# CONFIG_SUNRPC_BIND34 is not set
881CONFIG_RPCSEC_GSS_KRB5=y
882# CONFIG_RPCSEC_GSS_SPKM3 is not set
883# CONFIG_SMB_FS is not set
884# CONFIG_CIFS is not set
885# CONFIG_NCP_FS is not set
886# CONFIG_CODA_FS is not set
887# CONFIG_AFS_FS is not set
888
889#
890# Partition Types
891#
892CONFIG_PARTITION_ADVANCED=y
893# CONFIG_ACORN_PARTITION is not set
894# CONFIG_OSF_PARTITION is not set
895# CONFIG_AMIGA_PARTITION is not set
896# CONFIG_ATARI_PARTITION is not set
897# CONFIG_MAC_PARTITION is not set
898CONFIG_MSDOS_PARTITION=y
899# CONFIG_BSD_DISKLABEL is not set
900# CONFIG_MINIX_SUBPARTITION is not set
901# CONFIG_SOLARIS_X86_PARTITION is not set
902# CONFIG_UNIXWARE_DISKLABEL is not set
903# CONFIG_LDM_PARTITION is not set
904# CONFIG_SGI_PARTITION is not set
905# CONFIG_ULTRIX_PARTITION is not set
906# CONFIG_SUN_PARTITION is not set
907# CONFIG_KARMA_PARTITION is not set
908# CONFIG_EFI_PARTITION is not set
909# CONFIG_SYSV68_PARTITION is not set
910CONFIG_NLS=y
911CONFIG_NLS_DEFAULT="iso8859-1"
912CONFIG_NLS_CODEPAGE_437=y
913# CONFIG_NLS_CODEPAGE_737 is not set
914# CONFIG_NLS_CODEPAGE_775 is not set
915# CONFIG_NLS_CODEPAGE_850 is not set
916# CONFIG_NLS_CODEPAGE_852 is not set
917# CONFIG_NLS_CODEPAGE_855 is not set
918# CONFIG_NLS_CODEPAGE_857 is not set
919# CONFIG_NLS_CODEPAGE_860 is not set
920# CONFIG_NLS_CODEPAGE_861 is not set
921# CONFIG_NLS_CODEPAGE_862 is not set
922# CONFIG_NLS_CODEPAGE_863 is not set
923# CONFIG_NLS_CODEPAGE_864 is not set
924# CONFIG_NLS_CODEPAGE_865 is not set
925# CONFIG_NLS_CODEPAGE_866 is not set
926# CONFIG_NLS_CODEPAGE_869 is not set
927# CONFIG_NLS_CODEPAGE_936 is not set
928# CONFIG_NLS_CODEPAGE_950 is not set
929# CONFIG_NLS_CODEPAGE_932 is not set
930# CONFIG_NLS_CODEPAGE_949 is not set
931# CONFIG_NLS_CODEPAGE_874 is not set
932# CONFIG_NLS_ISO8859_8 is not set
933# CONFIG_NLS_CODEPAGE_1250 is not set
934# CONFIG_NLS_CODEPAGE_1251 is not set
935# CONFIG_NLS_ASCII is not set
936CONFIG_NLS_ISO8859_1=y
937# CONFIG_NLS_ISO8859_2 is not set
938# CONFIG_NLS_ISO8859_3 is not set
939# CONFIG_NLS_ISO8859_4 is not set
940# CONFIG_NLS_ISO8859_5 is not set
941# CONFIG_NLS_ISO8859_6 is not set
942# CONFIG_NLS_ISO8859_7 is not set
943# CONFIG_NLS_ISO8859_9 is not set
944# CONFIG_NLS_ISO8859_13 is not set
945# CONFIG_NLS_ISO8859_14 is not set
946# CONFIG_NLS_ISO8859_15 is not set
947# CONFIG_NLS_KOI8_R is not set
948# CONFIG_NLS_KOI8_U is not set
949# CONFIG_NLS_UTF8 is not set
950# CONFIG_DLM is not set
951
952#
953# Library routines
954#
955CONFIG_BITREVERSE=y
956# CONFIG_GENERIC_FIND_FIRST_BIT is not set
957# CONFIG_CRC_CCITT is not set
958# CONFIG_CRC16 is not set
959# CONFIG_CRC_ITU_T is not set
960CONFIG_CRC32=y
961# CONFIG_CRC7 is not set
962# CONFIG_LIBCRC32C is not set
963CONFIG_ZLIB_INFLATE=y
964CONFIG_ZLIB_DEFLATE=y
965CONFIG_PLIST=y
966CONFIG_HAS_IOMEM=y
967CONFIG_HAS_IOPORT=y
968CONFIG_HAS_DMA=y
969CONFIG_HAVE_LMB=y
970
971#
972# Kernel hacking
973#
974CONFIG_PRINTK_TIME=y
975CONFIG_ENABLE_WARN_DEPRECATED=y
976CONFIG_ENABLE_MUST_CHECK=y
977CONFIG_FRAME_WARN=1024
978# CONFIG_MAGIC_SYSRQ is not set
979# CONFIG_UNUSED_SYMBOLS is not set
980# CONFIG_DEBUG_FS is not set
981# CONFIG_HEADERS_CHECK is not set
982CONFIG_DEBUG_KERNEL=y
983# CONFIG_DEBUG_SHIRQ is not set
984CONFIG_DETECT_SOFTLOCKUP=y
985CONFIG_SCHED_DEBUG=y
986# CONFIG_SCHEDSTATS is not set
987# CONFIG_TIMER_STATS is not set
988# CONFIG_SLUB_DEBUG_ON is not set
989# CONFIG_SLUB_STATS is not set
990# CONFIG_DEBUG_RT_MUTEXES is not set
991# CONFIG_RT_MUTEX_TESTER is not set
992# CONFIG_DEBUG_SPINLOCK is not set
993# CONFIG_DEBUG_MUTEXES is not set
994# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
995# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
996# CONFIG_DEBUG_KOBJECT is not set
997# CONFIG_DEBUG_BUGVERBOSE is not set
998# CONFIG_DEBUG_INFO is not set
999# CONFIG_DEBUG_VM is not set
1000# CONFIG_DEBUG_WRITECOUNT is not set
1001# CONFIG_DEBUG_LIST is not set
1002# CONFIG_DEBUG_SG is not set
1003# CONFIG_BOOT_PRINTK_DELAY is not set
1004# CONFIG_BACKTRACE_SELF_TEST is not set
1005# CONFIG_FAULT_INJECTION is not set
1006# CONFIG_SAMPLES is not set
1007# CONFIG_DEBUG_STACKOVERFLOW is not set
1008# CONFIG_DEBUG_STACK_USAGE is not set
1009# CONFIG_DEBUG_PAGEALLOC is not set
1010# CONFIG_DEBUGGER is not set
1011# CONFIG_IRQSTACKS is not set
1012# CONFIG_BDI_SWITCH is not set
1013# CONFIG_BOOTX_TEXT is not set
1014# CONFIG_PPC_EARLY_DEBUG is not set
1015
1016#
1017# Security options
1018#
1019# CONFIG_KEYS is not set
1020# CONFIG_SECURITY is not set
1021# CONFIG_SECURITY_FILE_CAPABILITIES is not set
1022CONFIG_CRYPTO=y
1023
1024#
1025# Crypto core or helper
1026#
1027CONFIG_CRYPTO_ALGAPI=y
1028CONFIG_CRYPTO_BLKCIPHER=y
1029CONFIG_CRYPTO_MANAGER=y
1030# CONFIG_CRYPTO_GF128MUL is not set
1031# CONFIG_CRYPTO_NULL is not set
1032# CONFIG_CRYPTO_CRYPTD is not set
1033# CONFIG_CRYPTO_AUTHENC is not set
1034
1035#
1036# Authenticated Encryption with Associated Data
1037#
1038# CONFIG_CRYPTO_CCM is not set
1039# CONFIG_CRYPTO_GCM is not set
1040# CONFIG_CRYPTO_SEQIV is not set
1041
1042#
1043# Block modes
1044#
1045CONFIG_CRYPTO_CBC=y
1046# CONFIG_CRYPTO_CTR is not set
1047# CONFIG_CRYPTO_CTS is not set
1048CONFIG_CRYPTO_ECB=y
1049# CONFIG_CRYPTO_LRW is not set
1050CONFIG_CRYPTO_PCBC=y
1051# CONFIG_CRYPTO_XTS is not set
1052
1053#
1054# Hash modes
1055#
1056# CONFIG_CRYPTO_HMAC is not set
1057# CONFIG_CRYPTO_XCBC is not set
1058
1059#
1060# Digest
1061#
1062# CONFIG_CRYPTO_CRC32C is not set
1063# CONFIG_CRYPTO_MD4 is not set
1064CONFIG_CRYPTO_MD5=y
1065# CONFIG_CRYPTO_MICHAEL_MIC is not set
1066# CONFIG_CRYPTO_SHA1 is not set
1067# CONFIG_CRYPTO_SHA256 is not set
1068# CONFIG_CRYPTO_SHA512 is not set
1069# CONFIG_CRYPTO_TGR192 is not set
1070# CONFIG_CRYPTO_WP512 is not set
1071
1072#
1073# Ciphers
1074#
1075# CONFIG_CRYPTO_AES is not set
1076# CONFIG_CRYPTO_ANUBIS is not set
1077# CONFIG_CRYPTO_ARC4 is not set
1078# CONFIG_CRYPTO_BLOWFISH is not set
1079# CONFIG_CRYPTO_CAMELLIA is not set
1080# CONFIG_CRYPTO_CAST5 is not set
1081# CONFIG_CRYPTO_CAST6 is not set
1082CONFIG_CRYPTO_DES=y
1083# CONFIG_CRYPTO_FCRYPT is not set
1084# CONFIG_CRYPTO_KHAZAD is not set
1085# CONFIG_CRYPTO_SALSA20 is not set
1086# CONFIG_CRYPTO_SEED is not set
1087# CONFIG_CRYPTO_SERPENT is not set
1088# CONFIG_CRYPTO_TEA is not set
1089# CONFIG_CRYPTO_TWOFISH is not set
1090
1091#
1092# Compression
1093#
1094# CONFIG_CRYPTO_DEFLATE is not set
1095# CONFIG_CRYPTO_LZO is not set
1096CONFIG_CRYPTO_HW=y
1097CONFIG_PPC_CLOCK=y
1098CONFIG_PPC_LIB_RHEAP=y
1099# CONFIG_VIRTUALIZATION is not set
diff --git a/arch/powerpc/configs/52xx/lite5200b_defconfig b/arch/powerpc/configs/52xx/lite5200b_defconfig
new file mode 100644
index 000000000000..1a8a250fa11b
--- /dev/null
+++ b/arch/powerpc/configs/52xx/lite5200b_defconfig
@@ -0,0 +1,1049 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.25
4# Tue Apr 29 07:12:56 2008
5#
6# CONFIG_PPC64 is not set
7
8#
9# Processor support
10#
11CONFIG_6xx=y
12# CONFIG_PPC_85xx is not set
13# CONFIG_PPC_8xx is not set
14# CONFIG_40x is not set
15# CONFIG_44x is not set
16# CONFIG_E200 is not set
17CONFIG_PPC_FPU=y
18# CONFIG_ALTIVEC is not set
19CONFIG_PPC_STD_MMU=y
20CONFIG_PPC_STD_MMU_32=y
21# CONFIG_PPC_MM_SLICES is not set
22# CONFIG_SMP is not set
23CONFIG_PPC32=y
24CONFIG_WORD_SIZE=32
25CONFIG_PPC_MERGE=y
26CONFIG_MMU=y
27CONFIG_GENERIC_CMOS_UPDATE=y
28CONFIG_GENERIC_TIME=y
29CONFIG_GENERIC_TIME_VSYSCALL=y
30CONFIG_GENERIC_CLOCKEVENTS=y
31CONFIG_GENERIC_HARDIRQS=y
32# CONFIG_HAVE_SETUP_PER_CPU_AREA is not set
33CONFIG_IRQ_PER_CPU=y
34CONFIG_STACKTRACE_SUPPORT=y
35CONFIG_LOCKDEP_SUPPORT=y
36CONFIG_RWSEM_XCHGADD_ALGORITHM=y
37CONFIG_ARCH_HAS_ILOG2_U32=y
38CONFIG_GENERIC_HWEIGHT=y
39CONFIG_GENERIC_CALIBRATE_DELAY=y
40CONFIG_GENERIC_FIND_NEXT_BIT=y
41# CONFIG_ARCH_NO_VIRT_TO_BUS is not set
42CONFIG_PPC=y
43CONFIG_EARLY_PRINTK=y
44CONFIG_GENERIC_NVRAM=y
45CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
46CONFIG_ARCH_MAY_HAVE_PC_FDC=y
47CONFIG_PPC_OF=y
48CONFIG_OF=y
49# CONFIG_PPC_UDBG_16550 is not set
50# CONFIG_GENERIC_TBSYNC is not set
51CONFIG_AUDIT_ARCH=y
52CONFIG_GENERIC_BUG=y
53CONFIG_DEFAULT_UIMAGE=y
54CONFIG_ARCH_SUSPEND_POSSIBLE=y
55# CONFIG_PPC_DCR_NATIVE is not set
56# CONFIG_PPC_DCR_MMIO is not set
57CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
58
59#
60# General setup
61#
62CONFIG_EXPERIMENTAL=y
63CONFIG_BROKEN_ON_SMP=y
64CONFIG_INIT_ENV_ARG_LIMIT=32
65CONFIG_LOCALVERSION=""
66CONFIG_LOCALVERSION_AUTO=y
67CONFIG_SWAP=y
68CONFIG_SYSVIPC=y
69CONFIG_SYSVIPC_SYSCTL=y
70# CONFIG_POSIX_MQUEUE is not set
71# CONFIG_BSD_PROCESS_ACCT is not set
72# CONFIG_TASKSTATS is not set
73# CONFIG_AUDIT is not set
74# CONFIG_IKCONFIG is not set
75CONFIG_LOG_BUF_SHIFT=14
76# CONFIG_CGROUPS is not set
77CONFIG_GROUP_SCHED=y
78# CONFIG_FAIR_GROUP_SCHED is not set
79# CONFIG_RT_GROUP_SCHED is not set
80CONFIG_USER_SCHED=y
81# CONFIG_CGROUP_SCHED is not set
82CONFIG_SYSFS_DEPRECATED=y
83CONFIG_SYSFS_DEPRECATED_V2=y
84# CONFIG_RELAY is not set
85# CONFIG_NAMESPACES is not set
86CONFIG_BLK_DEV_INITRD=y
87CONFIG_INITRAMFS_SOURCE=""
88# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
89CONFIG_SYSCTL=y
90CONFIG_EMBEDDED=y
91# CONFIG_SYSCTL_SYSCALL is not set
92# CONFIG_KALLSYMS is not set
93CONFIG_HOTPLUG=y
94CONFIG_PRINTK=y
95CONFIG_BUG=y
96CONFIG_ELF_CORE=y
97CONFIG_COMPAT_BRK=y
98CONFIG_BASE_FULL=y
99CONFIG_FUTEX=y
100CONFIG_ANON_INODES=y
101# CONFIG_EPOLL is not set
102CONFIG_SIGNALFD=y
103CONFIG_TIMERFD=y
104CONFIG_EVENTFD=y
105CONFIG_SHMEM=y
106CONFIG_VM_EVENT_COUNTERS=y
107CONFIG_SLUB_DEBUG=y
108# CONFIG_SLAB is not set
109CONFIG_SLUB=y
110# CONFIG_SLOB is not set
111# CONFIG_PROFILING is not set
112# CONFIG_MARKERS is not set
113CONFIG_HAVE_OPROFILE=y
114CONFIG_HAVE_KPROBES=y
115CONFIG_HAVE_KRETPROBES=y
116CONFIG_PROC_PAGE_MONITOR=y
117CONFIG_SLABINFO=y
118CONFIG_RT_MUTEXES=y
119# CONFIG_TINY_SHMEM is not set
120CONFIG_BASE_SMALL=0
121CONFIG_MODULES=y
122CONFIG_MODULE_UNLOAD=y
123# CONFIG_MODULE_FORCE_UNLOAD is not set
124# CONFIG_MODVERSIONS is not set
125# CONFIG_MODULE_SRCVERSION_ALL is not set
126# CONFIG_KMOD is not set
127CONFIG_BLOCK=y
128# CONFIG_LBD is not set
129# CONFIG_BLK_DEV_IO_TRACE is not set
130# CONFIG_LSF is not set
131# CONFIG_BLK_DEV_BSG is not set
132
133#
134# IO Schedulers
135#
136CONFIG_IOSCHED_NOOP=y
137CONFIG_IOSCHED_AS=y
138CONFIG_IOSCHED_DEADLINE=y
139CONFIG_IOSCHED_CFQ=y
140CONFIG_DEFAULT_AS=y
141# CONFIG_DEFAULT_DEADLINE is not set
142# CONFIG_DEFAULT_CFQ is not set
143# CONFIG_DEFAULT_NOOP is not set
144CONFIG_DEFAULT_IOSCHED="anticipatory"
145CONFIG_CLASSIC_RCU=y
146
147#
148# Platform support
149#
150CONFIG_PPC_MULTIPLATFORM=y
151# CONFIG_PPC_82xx is not set
152# CONFIG_PPC_83xx is not set
153# CONFIG_PPC_86xx is not set
154CONFIG_CLASSIC32=y
155# CONFIG_PPC_CHRP is not set
156# CONFIG_PPC_MPC512x is not set
157# CONFIG_PPC_MPC5121 is not set
158# CONFIG_MPC5121_ADS is not set
159CONFIG_PPC_MPC52xx=y
160CONFIG_PPC_MPC5200_SIMPLE=y
161# CONFIG_PPC_EFIKA is not set
162CONFIG_PPC_LITE5200=y
163# CONFIG_PPC_MPC5200_BUGFIX is not set
164# CONFIG_PPC_MPC5200_GPIO is not set
165# CONFIG_PPC_PMAC is not set
166# CONFIG_PPC_CELL is not set
167# CONFIG_PPC_CELL_NATIVE is not set
168# CONFIG_PQ2ADS is not set
169# CONFIG_EMBEDDED6xx is not set
170# CONFIG_IPIC is not set
171# CONFIG_MPIC is not set
172# CONFIG_MPIC_WEIRD is not set
173# CONFIG_PPC_I8259 is not set
174# CONFIG_PPC_RTAS is not set
175# CONFIG_MMIO_NVRAM is not set
176# CONFIG_PPC_MPC106 is not set
177# CONFIG_PPC_970_NAP is not set
178# CONFIG_PPC_INDIRECT_IO is not set
179# CONFIG_GENERIC_IOMAP is not set
180# CONFIG_CPU_FREQ is not set
181# CONFIG_TAU is not set
182# CONFIG_FSL_ULI1575 is not set
183CONFIG_PPC_BESTCOMM=y
184CONFIG_PPC_BESTCOMM_ATA=y
185CONFIG_PPC_BESTCOMM_FEC=y
186CONFIG_PPC_BESTCOMM_GEN_BD=y
187
188#
189# Kernel options
190#
191# CONFIG_HIGHMEM is not set
192CONFIG_TICK_ONESHOT=y
193CONFIG_NO_HZ=y
194CONFIG_HIGH_RES_TIMERS=y
195CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
196# CONFIG_HZ_100 is not set
197CONFIG_HZ_250=y
198# CONFIG_HZ_300 is not set
199# CONFIG_HZ_1000 is not set
200CONFIG_HZ=250
201# CONFIG_SCHED_HRTICK is not set
202CONFIG_PREEMPT_NONE=y
203# CONFIG_PREEMPT_VOLUNTARY is not set
204# CONFIG_PREEMPT is not set
205CONFIG_BINFMT_ELF=y
206# CONFIG_BINFMT_MISC is not set
207# CONFIG_IOMMU_HELPER is not set
208CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
209CONFIG_ARCH_HAS_WALK_MEMORY=y
210CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
211# CONFIG_KEXEC is not set
212CONFIG_ARCH_FLATMEM_ENABLE=y
213CONFIG_ARCH_POPULATES_NODE_MAP=y
214CONFIG_SELECT_MEMORY_MODEL=y
215CONFIG_FLATMEM_MANUAL=y
216# CONFIG_DISCONTIGMEM_MANUAL is not set
217# CONFIG_SPARSEMEM_MANUAL is not set
218CONFIG_FLATMEM=y
219CONFIG_FLAT_NODE_MEM_MAP=y
220# CONFIG_SPARSEMEM_STATIC is not set
221# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
222CONFIG_PAGEFLAGS_EXTENDED=y
223CONFIG_SPLIT_PTLOCK_CPUS=4
224# CONFIG_RESOURCES_64BIT is not set
225CONFIG_ZONE_DMA_FLAG=1
226CONFIG_BOUNCE=y
227CONFIG_VIRT_TO_BUS=y
228CONFIG_FORCE_MAX_ZONEORDER=11
229CONFIG_PROC_DEVICETREE=y
230# CONFIG_CMDLINE_BOOL is not set
231CONFIG_PM=y
232# CONFIG_PM_LEGACY is not set
233# CONFIG_PM_DEBUG is not set
234CONFIG_PM_SLEEP=y
235CONFIG_SUSPEND=y
236CONFIG_SUSPEND_FREEZER=y
237CONFIG_SECCOMP=y
238CONFIG_ISA_DMA_API=y
239
240#
241# Bus options
242#
243CONFIG_ZONE_DMA=y
244CONFIG_GENERIC_ISA_DMA=y
245# CONFIG_PPC_INDIRECT_PCI is not set
246CONFIG_FSL_SOC=y
247CONFIG_PCI=y
248CONFIG_PCI_DOMAINS=y
249CONFIG_PCI_SYSCALL=y
250# CONFIG_PCIEPORTBUS is not set
251CONFIG_ARCH_SUPPORTS_MSI=y
252# CONFIG_PCI_MSI is not set
253CONFIG_PCI_LEGACY=y
254# CONFIG_PCI_DEBUG is not set
255# CONFIG_PCCARD is not set
256# CONFIG_HOTPLUG_PCI is not set
257# CONFIG_HAS_RAPIDIO is not set
258
259#
260# Advanced setup
261#
262# CONFIG_ADVANCED_OPTIONS is not set
263
264#
265# Default settings for advanced configuration options are used
266#
267CONFIG_LOWMEM_SIZE=0x30000000
268CONFIG_PAGE_OFFSET=0xc0000000
269CONFIG_KERNEL_START=0xc0000000
270CONFIG_PHYSICAL_START=0x00000000
271CONFIG_TASK_SIZE=0xc0000000
272
273#
274# Networking
275#
276CONFIG_NET=y
277
278#
279# Networking options
280#
281CONFIG_PACKET=y
282# CONFIG_PACKET_MMAP is not set
283CONFIG_UNIX=y
284CONFIG_XFRM=y
285CONFIG_XFRM_USER=m
286# CONFIG_XFRM_SUB_POLICY is not set
287# CONFIG_XFRM_MIGRATE is not set
288# CONFIG_XFRM_STATISTICS is not set
289# CONFIG_NET_KEY is not set
290CONFIG_INET=y
291CONFIG_IP_MULTICAST=y
292# CONFIG_IP_ADVANCED_ROUTER is not set
293CONFIG_IP_FIB_HASH=y
294CONFIG_IP_PNP=y
295CONFIG_IP_PNP_DHCP=y
296CONFIG_IP_PNP_BOOTP=y
297# CONFIG_IP_PNP_RARP is not set
298# CONFIG_NET_IPIP is not set
299# CONFIG_NET_IPGRE is not set
300# CONFIG_IP_MROUTE is not set
301# CONFIG_ARPD is not set
302CONFIG_SYN_COOKIES=y
303# CONFIG_INET_AH is not set
304# CONFIG_INET_ESP is not set
305# CONFIG_INET_IPCOMP is not set
306# CONFIG_INET_XFRM_TUNNEL is not set
307# CONFIG_INET_TUNNEL is not set
308CONFIG_INET_XFRM_MODE_TRANSPORT=y
309CONFIG_INET_XFRM_MODE_TUNNEL=y
310CONFIG_INET_XFRM_MODE_BEET=y
311# CONFIG_INET_LRO is not set
312CONFIG_INET_DIAG=y
313CONFIG_INET_TCP_DIAG=y
314# CONFIG_TCP_CONG_ADVANCED is not set
315CONFIG_TCP_CONG_CUBIC=y
316CONFIG_DEFAULT_TCP_CONG="cubic"
317# CONFIG_TCP_MD5SIG is not set
318# CONFIG_IPV6 is not set
319# CONFIG_NETWORK_SECMARK is not set
320# CONFIG_NETFILTER is not set
321# CONFIG_IP_DCCP is not set
322# CONFIG_IP_SCTP is not set
323# CONFIG_TIPC is not set
324# CONFIG_ATM is not set
325# CONFIG_BRIDGE is not set
326# CONFIG_VLAN_8021Q is not set
327# CONFIG_DECNET is not set
328# CONFIG_LLC2 is not set
329# CONFIG_IPX is not set
330# CONFIG_ATALK is not set
331# CONFIG_X25 is not set
332# CONFIG_LAPB is not set
333# CONFIG_ECONET is not set
334# CONFIG_WAN_ROUTER is not set
335# CONFIG_NET_SCHED is not set
336
337#
338# Network testing
339#
340# CONFIG_NET_PKTGEN is not set
341# CONFIG_HAMRADIO is not set
342# CONFIG_CAN is not set
343# CONFIG_IRDA is not set
344# CONFIG_BT is not set
345# CONFIG_AF_RXRPC is not set
346
347#
348# Wireless
349#
350# CONFIG_CFG80211 is not set
351# CONFIG_WIRELESS_EXT is not set
352# CONFIG_MAC80211 is not set
353# CONFIG_IEEE80211 is not set
354# CONFIG_RFKILL is not set
355# CONFIG_NET_9P is not set
356
357#
358# Device Drivers
359#
360
361#
362# Generic Driver Options
363#
364CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
365CONFIG_STANDALONE=y
366CONFIG_PREVENT_FIRMWARE_BUILD=y
367# CONFIG_FW_LOADER is not set
368# CONFIG_DEBUG_DRIVER is not set
369# CONFIG_DEBUG_DEVRES is not set
370# CONFIG_SYS_HYPERVISOR is not set
371# CONFIG_CONNECTOR is not set
372# CONFIG_MTD is not set
373CONFIG_OF_DEVICE=y
374CONFIG_OF_I2C=y
375# CONFIG_PARPORT is not set
376CONFIG_BLK_DEV=y
377# CONFIG_BLK_DEV_FD is not set
378# CONFIG_BLK_CPQ_DA is not set
379# CONFIG_BLK_CPQ_CISS_DA is not set
380# CONFIG_BLK_DEV_DAC960 is not set
381# CONFIG_BLK_DEV_UMEM is not set
382# CONFIG_BLK_DEV_COW_COMMON is not set
383CONFIG_BLK_DEV_LOOP=y
384# CONFIG_BLK_DEV_CRYPTOLOOP is not set
385# CONFIG_BLK_DEV_NBD is not set
386# CONFIG_BLK_DEV_SX8 is not set
387CONFIG_BLK_DEV_RAM=y
388CONFIG_BLK_DEV_RAM_COUNT=16
389CONFIG_BLK_DEV_RAM_SIZE=32768
390# CONFIG_BLK_DEV_XIP is not set
391# CONFIG_CDROM_PKTCDVD is not set
392# CONFIG_ATA_OVER_ETH is not set
393CONFIG_MISC_DEVICES=y
394# CONFIG_PHANTOM is not set
395# CONFIG_EEPROM_93CX6 is not set
396# CONFIG_SGI_IOC4 is not set
397# CONFIG_TIFM_CORE is not set
398# CONFIG_ENCLOSURE_SERVICES is not set
399CONFIG_HAVE_IDE=y
400# CONFIG_IDE is not set
401
402#
403# SCSI device support
404#
405# CONFIG_RAID_ATTRS is not set
406CONFIG_SCSI=y
407CONFIG_SCSI_DMA=y
408# CONFIG_SCSI_TGT is not set
409# CONFIG_SCSI_NETLINK is not set
410# CONFIG_SCSI_PROC_FS is not set
411
412#
413# SCSI support type (disk, tape, CD-ROM)
414#
415# CONFIG_BLK_DEV_SD is not set
416# CONFIG_CHR_DEV_ST is not set
417# CONFIG_CHR_DEV_OSST is not set
418# CONFIG_BLK_DEV_SR is not set
419# CONFIG_CHR_DEV_SG is not set
420# CONFIG_CHR_DEV_SCH is not set
421
422#
423# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
424#
425# CONFIG_SCSI_MULTI_LUN is not set
426# CONFIG_SCSI_CONSTANTS is not set
427# CONFIG_SCSI_LOGGING is not set
428# CONFIG_SCSI_SCAN_ASYNC is not set
429CONFIG_SCSI_WAIT_SCAN=m
430
431#
432# SCSI Transports
433#
434# CONFIG_SCSI_SPI_ATTRS is not set
435# CONFIG_SCSI_FC_ATTRS is not set
436# CONFIG_SCSI_ISCSI_ATTRS is not set
437# CONFIG_SCSI_SAS_LIBSAS is not set
438# CONFIG_SCSI_SRP_ATTRS is not set
439CONFIG_SCSI_LOWLEVEL=y
440# CONFIG_ISCSI_TCP is not set
441# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
442# CONFIG_SCSI_3W_9XXX is not set
443# CONFIG_SCSI_ACARD is not set
444# CONFIG_SCSI_AACRAID is not set
445# CONFIG_SCSI_AIC7XXX is not set
446# CONFIG_SCSI_AIC7XXX_OLD is not set
447# CONFIG_SCSI_AIC79XX is not set
448# CONFIG_SCSI_AIC94XX is not set
449# CONFIG_SCSI_DPT_I2O is not set
450# CONFIG_SCSI_ADVANSYS is not set
451# CONFIG_SCSI_ARCMSR is not set
452# CONFIG_MEGARAID_NEWGEN is not set
453# CONFIG_MEGARAID_LEGACY is not set
454# CONFIG_MEGARAID_SAS is not set
455# CONFIG_SCSI_HPTIOP is not set
456# CONFIG_SCSI_BUSLOGIC is not set
457# CONFIG_SCSI_DMX3191D is not set
458# CONFIG_SCSI_EATA is not set
459# CONFIG_SCSI_FUTURE_DOMAIN is not set
460# CONFIG_SCSI_GDTH is not set
461# CONFIG_SCSI_IPS is not set
462# CONFIG_SCSI_INITIO is not set
463# CONFIG_SCSI_INIA100 is not set
464# CONFIG_SCSI_MVSAS is not set
465# CONFIG_SCSI_STEX is not set
466# CONFIG_SCSI_SYM53C8XX_2 is not set
467# CONFIG_SCSI_IPR is not set
468# CONFIG_SCSI_QLOGIC_1280 is not set
469# CONFIG_SCSI_QLA_FC is not set
470# CONFIG_SCSI_QLA_ISCSI is not set
471# CONFIG_SCSI_LPFC is not set
472# CONFIG_SCSI_DC395x is not set
473# CONFIG_SCSI_DC390T is not set
474# CONFIG_SCSI_NSP32 is not set
475# CONFIG_SCSI_DEBUG is not set
476# CONFIG_SCSI_SRP is not set
477CONFIG_ATA=y
478# CONFIG_ATA_NONSTANDARD is not set
479CONFIG_SATA_PMP=y
480# CONFIG_SATA_AHCI is not set
481# CONFIG_SATA_SIL24 is not set
482# CONFIG_SATA_FSL is not set
483CONFIG_ATA_SFF=y
484# CONFIG_SATA_SVW is not set
485# CONFIG_ATA_PIIX is not set
486# CONFIG_SATA_MV is not set
487# CONFIG_SATA_NV is not set
488# CONFIG_PDC_ADMA is not set
489# CONFIG_SATA_QSTOR is not set
490# CONFIG_SATA_PROMISE is not set
491# CONFIG_SATA_SX4 is not set
492# CONFIG_SATA_SIL is not set
493# CONFIG_SATA_SIS is not set
494# CONFIG_SATA_ULI is not set
495# CONFIG_SATA_VIA is not set
496# CONFIG_SATA_VITESSE is not set
497# CONFIG_SATA_INIC162X is not set
498# CONFIG_PATA_ALI is not set
499# CONFIG_PATA_AMD is not set
500# CONFIG_PATA_ARTOP is not set
501# CONFIG_PATA_ATIIXP is not set
502# CONFIG_PATA_CMD640_PCI is not set
503# CONFIG_PATA_CMD64X is not set
504# CONFIG_PATA_CS5520 is not set
505# CONFIG_PATA_CS5530 is not set
506# CONFIG_PATA_CYPRESS is not set
507# CONFIG_PATA_EFAR is not set
508# CONFIG_ATA_GENERIC is not set
509# CONFIG_PATA_HPT366 is not set
510# CONFIG_PATA_HPT37X is not set
511# CONFIG_PATA_HPT3X2N is not set
512# CONFIG_PATA_HPT3X3 is not set
513# CONFIG_PATA_IT821X is not set
514# CONFIG_PATA_IT8213 is not set
515# CONFIG_PATA_JMICRON is not set
516# CONFIG_PATA_TRIFLEX is not set
517# CONFIG_PATA_MARVELL is not set
518CONFIG_PATA_MPC52xx=y
519# CONFIG_PATA_MPIIX is not set
520# CONFIG_PATA_OLDPIIX is not set
521# CONFIG_PATA_NETCELL is not set
522# CONFIG_PATA_NINJA32 is not set
523# CONFIG_PATA_NS87410 is not set
524# CONFIG_PATA_NS87415 is not set
525# CONFIG_PATA_OPTI is not set
526# CONFIG_PATA_OPTIDMA is not set
527# CONFIG_PATA_PDC_OLD is not set
528# CONFIG_PATA_RADISYS is not set
529# CONFIG_PATA_RZ1000 is not set
530# CONFIG_PATA_SC1200 is not set
531# CONFIG_PATA_SERVERWORKS is not set
532# CONFIG_PATA_PDC2027X is not set
533# CONFIG_PATA_SIL680 is not set
534# CONFIG_PATA_SIS is not set
535# CONFIG_PATA_VIA is not set
536# CONFIG_PATA_WINBOND is not set
537# CONFIG_PATA_PLATFORM is not set
538# CONFIG_MD is not set
539# CONFIG_FUSION is not set
540
541#
542# IEEE 1394 (FireWire) support
543#
544# CONFIG_FIREWIRE is not set
545# CONFIG_IEEE1394 is not set
546# CONFIG_I2O is not set
547# CONFIG_MACINTOSH_DRIVERS is not set
548CONFIG_NETDEVICES=y
549# CONFIG_NETDEVICES_MULTIQUEUE is not set
550# CONFIG_DUMMY is not set
551# CONFIG_BONDING is not set
552# CONFIG_MACVLAN is not set
553# CONFIG_EQUALIZER is not set
554# CONFIG_TUN is not set
555# CONFIG_VETH is not set
556# CONFIG_ARCNET is not set
557CONFIG_PHYLIB=y
558
559#
560# MII PHY device drivers
561#
562# CONFIG_MARVELL_PHY is not set
563# CONFIG_DAVICOM_PHY is not set
564# CONFIG_QSEMI_PHY is not set
565CONFIG_LXT_PHY=y
566# CONFIG_CICADA_PHY is not set
567# CONFIG_VITESSE_PHY is not set
568# CONFIG_SMSC_PHY is not set
569# CONFIG_BROADCOM_PHY is not set
570# CONFIG_ICPLUS_PHY is not set
571# CONFIG_REALTEK_PHY is not set
572# CONFIG_FIXED_PHY is not set
573# CONFIG_MDIO_BITBANG is not set
574CONFIG_NET_ETHERNET=y
575# CONFIG_MII is not set
576# CONFIG_HAPPYMEAL is not set
577# CONFIG_SUNGEM is not set
578# CONFIG_CASSINI is not set
579# CONFIG_NET_VENDOR_3COM is not set
580# CONFIG_NET_TULIP is not set
581# CONFIG_HP100 is not set
582# CONFIG_IBM_NEW_EMAC_ZMII is not set
583# CONFIG_IBM_NEW_EMAC_RGMII is not set
584# CONFIG_IBM_NEW_EMAC_TAH is not set
585# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
586# CONFIG_NET_PCI is not set
587# CONFIG_B44 is not set
588CONFIG_FEC_MPC52xx=y
589CONFIG_FEC_MPC52xx_MDIO=y
590CONFIG_NETDEV_1000=y
591# CONFIG_ACENIC is not set
592# CONFIG_DL2K is not set
593# CONFIG_E1000 is not set
594# CONFIG_E1000E is not set
595# CONFIG_E1000E_ENABLED is not set
596# CONFIG_IP1000 is not set
597# CONFIG_IGB is not set
598# CONFIG_NS83820 is not set
599# CONFIG_HAMACHI is not set
600# CONFIG_YELLOWFIN is not set
601# CONFIG_R8169 is not set
602# CONFIG_SIS190 is not set
603# CONFIG_SKGE is not set
604# CONFIG_SKY2 is not set
605# CONFIG_VIA_VELOCITY is not set
606# CONFIG_TIGON3 is not set
607# CONFIG_BNX2 is not set
608# CONFIG_GIANFAR is not set
609# CONFIG_MV643XX_ETH is not set
610# CONFIG_QLA3XXX is not set
611# CONFIG_ATL1 is not set
612CONFIG_NETDEV_10000=y
613# CONFIG_CHELSIO_T1 is not set
614# CONFIG_CHELSIO_T3 is not set
615# CONFIG_IXGBE is not set
616# CONFIG_IXGB is not set
617# CONFIG_S2IO is not set
618# CONFIG_MYRI10GE is not set
619# CONFIG_NETXEN_NIC is not set
620# CONFIG_NIU is not set
621# CONFIG_MLX4_CORE is not set
622# CONFIG_TEHUTI is not set
623# CONFIG_BNX2X is not set
624# CONFIG_TR is not set
625
626#
627# Wireless LAN
628#
629# CONFIG_WLAN_PRE80211 is not set
630# CONFIG_WLAN_80211 is not set
631# CONFIG_IWLWIFI is not set
632# CONFIG_IWLWIFI_LEDS is not set
633# CONFIG_WAN is not set
634# CONFIG_FDDI is not set
635# CONFIG_HIPPI is not set
636# CONFIG_PPP is not set
637# CONFIG_SLIP is not set
638# CONFIG_NET_FC is not set
639# CONFIG_NETCONSOLE is not set
640# CONFIG_NETPOLL is not set
641# CONFIG_NET_POLL_CONTROLLER is not set
642# CONFIG_ISDN is not set
643# CONFIG_PHONE is not set
644
645#
646# Input device support
647#
648# CONFIG_INPUT is not set
649
650#
651# Hardware I/O ports
652#
653# CONFIG_SERIO is not set
654# CONFIG_GAMEPORT is not set
655
656#
657# Character devices
658#
659# CONFIG_VT is not set
660# CONFIG_SERIAL_NONSTANDARD is not set
661# CONFIG_NOZOMI is not set
662
663#
664# Serial drivers
665#
666# CONFIG_SERIAL_8250 is not set
667
668#
669# Non-8250 serial port support
670#
671# CONFIG_SERIAL_UARTLITE is not set
672CONFIG_SERIAL_CORE=y
673CONFIG_SERIAL_CORE_CONSOLE=y
674CONFIG_SERIAL_MPC52xx=y
675CONFIG_SERIAL_MPC52xx_CONSOLE=y
676CONFIG_SERIAL_MPC52xx_CONSOLE_BAUD=115200
677# CONFIG_SERIAL_JSM is not set
678CONFIG_UNIX98_PTYS=y
679CONFIG_LEGACY_PTYS=y
680CONFIG_LEGACY_PTY_COUNT=256
681# CONFIG_IPMI_HANDLER is not set
682# CONFIG_HW_RANDOM is not set
683# CONFIG_NVRAM is not set
684CONFIG_GEN_RTC=y
685# CONFIG_GEN_RTC_X is not set
686# CONFIG_R3964 is not set
687# CONFIG_APPLICOM is not set
688# CONFIG_RAW_DRIVER is not set
689# CONFIG_TCG_TPM is not set
690CONFIG_DEVPORT=y
691CONFIG_I2C=y
692CONFIG_I2C_BOARDINFO=y
693CONFIG_I2C_CHARDEV=y
694
695#
696# I2C Hardware Bus support
697#
698# CONFIG_I2C_ALI1535 is not set
699# CONFIG_I2C_ALI1563 is not set
700# CONFIG_I2C_ALI15X3 is not set
701# CONFIG_I2C_AMD756 is not set
702# CONFIG_I2C_AMD8111 is not set
703# CONFIG_I2C_I801 is not set
704# CONFIG_I2C_I810 is not set
705# CONFIG_I2C_PIIX4 is not set
706CONFIG_I2C_MPC=y
707# CONFIG_I2C_NFORCE2 is not set
708# CONFIG_I2C_OCORES is not set
709# CONFIG_I2C_PARPORT_LIGHT is not set
710# CONFIG_I2C_PROSAVAGE is not set
711# CONFIG_I2C_SAVAGE4 is not set
712# CONFIG_I2C_SIMTEC is not set
713# CONFIG_I2C_SIS5595 is not set
714# CONFIG_I2C_SIS630 is not set
715# CONFIG_I2C_SIS96X is not set
716# CONFIG_I2C_TAOS_EVM is not set
717# CONFIG_I2C_STUB is not set
718# CONFIG_I2C_VIA is not set
719# CONFIG_I2C_VIAPRO is not set
720# CONFIG_I2C_VOODOO3 is not set
721# CONFIG_I2C_PCA_PLATFORM is not set
722
723#
724# Miscellaneous I2C Chip support
725#
726# CONFIG_DS1682 is not set
727# CONFIG_SENSORS_EEPROM is not set
728# CONFIG_SENSORS_PCF8574 is not set
729# CONFIG_PCF8575 is not set
730# CONFIG_SENSORS_PCF8591 is not set
731# CONFIG_SENSORS_MAX6875 is not set
732# CONFIG_SENSORS_TSL2550 is not set
733# CONFIG_I2C_DEBUG_CORE is not set
734# CONFIG_I2C_DEBUG_ALGO is not set
735# CONFIG_I2C_DEBUG_BUS is not set
736# CONFIG_I2C_DEBUG_CHIP is not set
737# CONFIG_SPI is not set
738# CONFIG_W1 is not set
739# CONFIG_POWER_SUPPLY is not set
740# CONFIG_HWMON is not set
741# CONFIG_THERMAL is not set
742# CONFIG_WATCHDOG is not set
743
744#
745# Sonics Silicon Backplane
746#
747CONFIG_SSB_POSSIBLE=y
748# CONFIG_SSB is not set
749
750#
751# Multifunction device drivers
752#
753# CONFIG_MFD_SM501 is not set
754# CONFIG_HTC_PASIC3 is not set
755
756#
757# Multimedia devices
758#
759# CONFIG_VIDEO_DEV is not set
760# CONFIG_DVB_CORE is not set
761# CONFIG_DAB is not set
762
763#
764# Graphics support
765#
766# CONFIG_AGP is not set
767# CONFIG_DRM is not set
768# CONFIG_VGASTATE is not set
769CONFIG_VIDEO_OUTPUT_CONTROL=m
770# CONFIG_FB is not set
771# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
772
773#
774# Display device support
775#
776# CONFIG_DISPLAY_SUPPORT is not set
777
778#
779# Sound
780#
781# CONFIG_SOUND is not set
782CONFIG_USB_SUPPORT=y
783CONFIG_USB_ARCH_HAS_HCD=y
784CONFIG_USB_ARCH_HAS_OHCI=y
785CONFIG_USB_ARCH_HAS_EHCI=y
786# CONFIG_USB is not set
787# CONFIG_USB_OTG_WHITELIST is not set
788# CONFIG_USB_OTG_BLACKLIST_HUB is not set
789
790#
791# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
792#
793# CONFIG_USB_GADGET is not set
794# CONFIG_MMC is not set
795# CONFIG_MEMSTICK is not set
796# CONFIG_NEW_LEDS is not set
797# CONFIG_INFINIBAND is not set
798# CONFIG_EDAC is not set
799# CONFIG_RTC_CLASS is not set
800# CONFIG_DMADEVICES is not set
801# CONFIG_UIO is not set
802
803#
804# File systems
805#
806CONFIG_EXT2_FS=y
807# CONFIG_EXT2_FS_XATTR is not set
808# CONFIG_EXT2_FS_XIP is not set
809CONFIG_EXT3_FS=y
810CONFIG_EXT3_FS_XATTR=y
811# CONFIG_EXT3_FS_POSIX_ACL is not set
812# CONFIG_EXT3_FS_SECURITY is not set
813# CONFIG_EXT4DEV_FS is not set
814CONFIG_JBD=y
815CONFIG_FS_MBCACHE=y
816# CONFIG_REISERFS_FS is not set
817# CONFIG_JFS_FS is not set
818# CONFIG_FS_POSIX_ACL is not set
819# CONFIG_XFS_FS is not set
820# CONFIG_OCFS2_FS is not set
821CONFIG_DNOTIFY=y
822CONFIG_INOTIFY=y
823CONFIG_INOTIFY_USER=y
824# CONFIG_QUOTA is not set
825# CONFIG_AUTOFS_FS is not set
826# CONFIG_AUTOFS4_FS is not set
827# CONFIG_FUSE_FS is not set
828
829#
830# CD-ROM/DVD Filesystems
831#
832# CONFIG_ISO9660_FS is not set
833# CONFIG_UDF_FS is not set
834
835#
836# DOS/FAT/NT Filesystems
837#
838# CONFIG_MSDOS_FS is not set
839# CONFIG_VFAT_FS is not set
840# CONFIG_NTFS_FS is not set
841
842#
843# Pseudo filesystems
844#
845CONFIG_PROC_FS=y
846CONFIG_PROC_KCORE=y
847CONFIG_PROC_SYSCTL=y
848CONFIG_SYSFS=y
849CONFIG_TMPFS=y
850# CONFIG_TMPFS_POSIX_ACL is not set
851# CONFIG_HUGETLB_PAGE is not set
852# CONFIG_CONFIGFS_FS is not set
853
854#
855# Miscellaneous filesystems
856#
857# CONFIG_ADFS_FS is not set
858# CONFIG_AFFS_FS is not set
859# CONFIG_HFS_FS is not set
860# CONFIG_HFSPLUS_FS is not set
861# CONFIG_BEFS_FS is not set
862# CONFIG_BFS_FS is not set
863# CONFIG_EFS_FS is not set
864# CONFIG_CRAMFS is not set
865# CONFIG_VXFS_FS is not set
866# CONFIG_MINIX_FS is not set
867# CONFIG_HPFS_FS is not set
868# CONFIG_QNX4FS_FS is not set
869# CONFIG_ROMFS_FS is not set
870# CONFIG_SYSV_FS is not set
871# CONFIG_UFS_FS is not set
872CONFIG_NETWORK_FILESYSTEMS=y
873CONFIG_NFS_FS=y
874CONFIG_NFS_V3=y
875# CONFIG_NFS_V3_ACL is not set
876CONFIG_NFS_V4=y
877# CONFIG_NFSD is not set
878CONFIG_ROOT_NFS=y
879CONFIG_LOCKD=y
880CONFIG_LOCKD_V4=y
881CONFIG_NFS_COMMON=y
882CONFIG_SUNRPC=y
883CONFIG_SUNRPC_GSS=y
884# CONFIG_SUNRPC_BIND34 is not set
885CONFIG_RPCSEC_GSS_KRB5=y
886# CONFIG_RPCSEC_GSS_SPKM3 is not set
887# CONFIG_SMB_FS is not set
888# CONFIG_CIFS is not set
889# CONFIG_NCP_FS is not set
890# CONFIG_CODA_FS is not set
891# CONFIG_AFS_FS is not set
892
893#
894# Partition Types
895#
896# CONFIG_PARTITION_ADVANCED is not set
897CONFIG_MSDOS_PARTITION=y
898# CONFIG_NLS is not set
899# CONFIG_DLM is not set
900
901#
902# Library routines
903#
904CONFIG_BITREVERSE=y
905# CONFIG_GENERIC_FIND_FIRST_BIT is not set
906# CONFIG_CRC_CCITT is not set
907# CONFIG_CRC16 is not set
908# CONFIG_CRC_ITU_T is not set
909CONFIG_CRC32=y
910# CONFIG_CRC7 is not set
911# CONFIG_LIBCRC32C is not set
912CONFIG_PLIST=y
913CONFIG_HAS_IOMEM=y
914CONFIG_HAS_IOPORT=y
915CONFIG_HAS_DMA=y
916CONFIG_HAVE_LMB=y
917
918#
919# Kernel hacking
920#
921CONFIG_PRINTK_TIME=y
922CONFIG_ENABLE_WARN_DEPRECATED=y
923CONFIG_ENABLE_MUST_CHECK=y
924CONFIG_FRAME_WARN=1024
925# CONFIG_MAGIC_SYSRQ is not set
926# CONFIG_UNUSED_SYMBOLS is not set
927# CONFIG_DEBUG_FS is not set
928# CONFIG_HEADERS_CHECK is not set
929CONFIG_DEBUG_KERNEL=y
930# CONFIG_DEBUG_SHIRQ is not set
931CONFIG_DETECT_SOFTLOCKUP=y
932CONFIG_SCHED_DEBUG=y
933# CONFIG_SCHEDSTATS is not set
934# CONFIG_TIMER_STATS is not set
935# CONFIG_SLUB_DEBUG_ON is not set
936# CONFIG_SLUB_STATS is not set
937# CONFIG_DEBUG_RT_MUTEXES is not set
938# CONFIG_RT_MUTEX_TESTER is not set
939# CONFIG_DEBUG_SPINLOCK is not set
940# CONFIG_DEBUG_MUTEXES is not set
941# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
942# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
943# CONFIG_DEBUG_KOBJECT is not set
944# CONFIG_DEBUG_BUGVERBOSE is not set
945CONFIG_DEBUG_INFO=y
946# CONFIG_DEBUG_VM is not set
947# CONFIG_DEBUG_WRITECOUNT is not set
948# CONFIG_DEBUG_LIST is not set
949# CONFIG_DEBUG_SG is not set
950# CONFIG_BOOT_PRINTK_DELAY is not set
951# CONFIG_RCU_TORTURE_TEST is not set
952# CONFIG_BACKTRACE_SELF_TEST is not set
953# CONFIG_FAULT_INJECTION is not set
954# CONFIG_SAMPLES is not set
955# CONFIG_DEBUG_STACKOVERFLOW is not set
956# CONFIG_DEBUG_STACK_USAGE is not set
957# CONFIG_DEBUG_PAGEALLOC is not set
958# CONFIG_DEBUGGER is not set
959# CONFIG_IRQSTACKS is not set
960# CONFIG_BDI_SWITCH is not set
961# CONFIG_BOOTX_TEXT is not set
962# CONFIG_PPC_EARLY_DEBUG is not set
963
964#
965# Security options
966#
967# CONFIG_KEYS is not set
968# CONFIG_SECURITY is not set
969# CONFIG_SECURITY_FILE_CAPABILITIES is not set
970CONFIG_CRYPTO=y
971
972#
973# Crypto core or helper
974#
975CONFIG_CRYPTO_ALGAPI=y
976CONFIG_CRYPTO_BLKCIPHER=y
977CONFIG_CRYPTO_MANAGER=y
978# CONFIG_CRYPTO_GF128MUL is not set
979# CONFIG_CRYPTO_NULL is not set
980# CONFIG_CRYPTO_CRYPTD is not set
981# CONFIG_CRYPTO_AUTHENC is not set
982# CONFIG_CRYPTO_TEST is not set
983
984#
985# Authenticated Encryption with Associated Data
986#
987# CONFIG_CRYPTO_CCM is not set
988# CONFIG_CRYPTO_GCM is not set
989# CONFIG_CRYPTO_SEQIV is not set
990
991#
992# Block modes
993#
994CONFIG_CRYPTO_CBC=y
995# CONFIG_CRYPTO_CTR is not set
996# CONFIG_CRYPTO_CTS is not set
997# CONFIG_CRYPTO_ECB is not set
998# CONFIG_CRYPTO_LRW is not set
999# CONFIG_CRYPTO_PCBC is not set
1000# CONFIG_CRYPTO_XTS is not set
1001
1002#
1003# Hash modes
1004#
1005# CONFIG_CRYPTO_HMAC is not set
1006# CONFIG_CRYPTO_XCBC is not set
1007
1008#
1009# Digest
1010#
1011# CONFIG_CRYPTO_CRC32C is not set
1012# CONFIG_CRYPTO_MD4 is not set
1013CONFIG_CRYPTO_MD5=y
1014# CONFIG_CRYPTO_MICHAEL_MIC is not set
1015# CONFIG_CRYPTO_SHA1 is not set
1016# CONFIG_CRYPTO_SHA256 is not set
1017# CONFIG_CRYPTO_SHA512 is not set
1018# CONFIG_CRYPTO_TGR192 is not set
1019# CONFIG_CRYPTO_WP512 is not set
1020
1021#
1022# Ciphers
1023#
1024# CONFIG_CRYPTO_AES is not set
1025# CONFIG_CRYPTO_ANUBIS is not set
1026# CONFIG_CRYPTO_ARC4 is not set
1027# CONFIG_CRYPTO_BLOWFISH is not set
1028# CONFIG_CRYPTO_CAMELLIA is not set
1029# CONFIG_CRYPTO_CAST5 is not set
1030# CONFIG_CRYPTO_CAST6 is not set
1031CONFIG_CRYPTO_DES=y
1032# CONFIG_CRYPTO_FCRYPT is not set
1033# CONFIG_CRYPTO_KHAZAD is not set
1034# CONFIG_CRYPTO_SALSA20 is not set
1035# CONFIG_CRYPTO_SEED is not set
1036# CONFIG_CRYPTO_SERPENT is not set
1037# CONFIG_CRYPTO_TEA is not set
1038# CONFIG_CRYPTO_TWOFISH is not set
1039
1040#
1041# Compression
1042#
1043# CONFIG_CRYPTO_DEFLATE is not set
1044# CONFIG_CRYPTO_LZO is not set
1045CONFIG_CRYPTO_HW=y
1046# CONFIG_CRYPTO_DEV_HIFN_795X is not set
1047CONFIG_PPC_CLOCK=y
1048CONFIG_PPC_LIB_RHEAP=y
1049# CONFIG_VIRTUALIZATION is not set
diff --git a/arch/powerpc/configs/52xx/motionpro_defconfig b/arch/powerpc/configs/52xx/motionpro_defconfig
new file mode 100644
index 000000000000..8c7ba7c6ba49
--- /dev/null
+++ b/arch/powerpc/configs/52xx/motionpro_defconfig
@@ -0,0 +1,1107 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.25
4# Tue Apr 29 07:12:22 2008
5#
6# CONFIG_PPC64 is not set
7
8#
9# Processor support
10#
11CONFIG_6xx=y
12# CONFIG_PPC_85xx is not set
13# CONFIG_PPC_8xx is not set
14# CONFIG_40x is not set
15# CONFIG_44x is not set
16# CONFIG_E200 is not set
17CONFIG_PPC_FPU=y
18# CONFIG_ALTIVEC is not set
19CONFIG_PPC_STD_MMU=y
20CONFIG_PPC_STD_MMU_32=y
21# CONFIG_PPC_MM_SLICES is not set
22# CONFIG_SMP is not set
23CONFIG_PPC32=y
24CONFIG_WORD_SIZE=32
25CONFIG_PPC_MERGE=y
26CONFIG_MMU=y
27CONFIG_GENERIC_CMOS_UPDATE=y
28CONFIG_GENERIC_TIME=y
29CONFIG_GENERIC_TIME_VSYSCALL=y
30CONFIG_GENERIC_CLOCKEVENTS=y
31CONFIG_GENERIC_HARDIRQS=y
32# CONFIG_HAVE_SETUP_PER_CPU_AREA is not set
33CONFIG_IRQ_PER_CPU=y
34CONFIG_STACKTRACE_SUPPORT=y
35CONFIG_LOCKDEP_SUPPORT=y
36CONFIG_RWSEM_XCHGADD_ALGORITHM=y
37CONFIG_ARCH_HAS_ILOG2_U32=y
38CONFIG_GENERIC_HWEIGHT=y
39CONFIG_GENERIC_CALIBRATE_DELAY=y
40CONFIG_GENERIC_FIND_NEXT_BIT=y
41# CONFIG_ARCH_NO_VIRT_TO_BUS is not set
42CONFIG_PPC=y
43CONFIG_EARLY_PRINTK=y
44CONFIG_GENERIC_NVRAM=y
45CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
46CONFIG_ARCH_MAY_HAVE_PC_FDC=y
47CONFIG_PPC_OF=y
48CONFIG_OF=y
49# CONFIG_PPC_UDBG_16550 is not set
50# CONFIG_GENERIC_TBSYNC is not set
51CONFIG_AUDIT_ARCH=y
52CONFIG_GENERIC_BUG=y
53CONFIG_DEFAULT_UIMAGE=y
54# CONFIG_PPC_DCR_NATIVE is not set
55# CONFIG_PPC_DCR_MMIO is not set
56CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
57
58#
59# General setup
60#
61CONFIG_EXPERIMENTAL=y
62CONFIG_BROKEN_ON_SMP=y
63CONFIG_INIT_ENV_ARG_LIMIT=32
64CONFIG_LOCALVERSION=""
65CONFIG_LOCALVERSION_AUTO=y
66CONFIG_SWAP=y
67CONFIG_SYSVIPC=y
68CONFIG_SYSVIPC_SYSCTL=y
69# CONFIG_POSIX_MQUEUE is not set
70# CONFIG_BSD_PROCESS_ACCT is not set
71# CONFIG_TASKSTATS is not set
72# CONFIG_AUDIT is not set
73# CONFIG_IKCONFIG is not set
74CONFIG_LOG_BUF_SHIFT=14
75# CONFIG_CGROUPS is not set
76CONFIG_GROUP_SCHED=y
77CONFIG_FAIR_GROUP_SCHED=y
78# CONFIG_RT_GROUP_SCHED is not set
79CONFIG_USER_SCHED=y
80# CONFIG_CGROUP_SCHED is not set
81CONFIG_SYSFS_DEPRECATED=y
82CONFIG_SYSFS_DEPRECATED_V2=y
83# CONFIG_RELAY is not set
84# CONFIG_NAMESPACES is not set
85CONFIG_BLK_DEV_INITRD=y
86CONFIG_INITRAMFS_SOURCE=""
87# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
88CONFIG_SYSCTL=y
89CONFIG_EMBEDDED=y
90# CONFIG_SYSCTL_SYSCALL is not set
91# CONFIG_KALLSYMS is not set
92CONFIG_HOTPLUG=y
93CONFIG_PRINTK=y
94CONFIG_BUG=y
95CONFIG_ELF_CORE=y
96CONFIG_COMPAT_BRK=y
97CONFIG_BASE_FULL=y
98CONFIG_FUTEX=y
99CONFIG_ANON_INODES=y
100# CONFIG_EPOLL is not set
101CONFIG_SIGNALFD=y
102CONFIG_TIMERFD=y
103CONFIG_EVENTFD=y
104CONFIG_SHMEM=y
105CONFIG_VM_EVENT_COUNTERS=y
106CONFIG_SLUB_DEBUG=y
107# CONFIG_SLAB is not set
108CONFIG_SLUB=y
109# CONFIG_SLOB is not set
110# CONFIG_PROFILING is not set
111# CONFIG_MARKERS is not set
112CONFIG_HAVE_OPROFILE=y
113CONFIG_HAVE_KPROBES=y
114CONFIG_HAVE_KRETPROBES=y
115CONFIG_PROC_PAGE_MONITOR=y
116CONFIG_SLABINFO=y
117CONFIG_RT_MUTEXES=y
118# CONFIG_TINY_SHMEM is not set
119CONFIG_BASE_SMALL=0
120# CONFIG_MODULES is not set
121CONFIG_BLOCK=y
122# CONFIG_LBD is not set
123# CONFIG_BLK_DEV_IO_TRACE is not set
124# CONFIG_LSF is not set
125# CONFIG_BLK_DEV_BSG is not set
126
127#
128# IO Schedulers
129#
130CONFIG_IOSCHED_NOOP=y
131CONFIG_IOSCHED_AS=y
132CONFIG_IOSCHED_DEADLINE=y
133CONFIG_IOSCHED_CFQ=y
134CONFIG_DEFAULT_AS=y
135# CONFIG_DEFAULT_DEADLINE is not set
136# CONFIG_DEFAULT_CFQ is not set
137# CONFIG_DEFAULT_NOOP is not set
138CONFIG_DEFAULT_IOSCHED="anticipatory"
139CONFIG_CLASSIC_RCU=y
140
141#
142# Platform support
143#
144CONFIG_PPC_MULTIPLATFORM=y
145# CONFIG_PPC_82xx is not set
146# CONFIG_PPC_83xx is not set
147# CONFIG_PPC_86xx is not set
148CONFIG_CLASSIC32=y
149# CONFIG_PPC_CHRP is not set
150# CONFIG_PPC_MPC512x is not set
151# CONFIG_PPC_MPC5121 is not set
152# CONFIG_MPC5121_ADS is not set
153CONFIG_PPC_MPC52xx=y
154CONFIG_PPC_MPC5200_SIMPLE=y
155# CONFIG_PPC_EFIKA is not set
156# CONFIG_PPC_LITE5200 is not set
157# CONFIG_PPC_MPC5200_BUGFIX is not set
158# CONFIG_PPC_MPC5200_GPIO is not set
159# CONFIG_PPC_PMAC is not set
160# CONFIG_PPC_CELL is not set
161# CONFIG_PPC_CELL_NATIVE is not set
162# CONFIG_PQ2ADS is not set
163# CONFIG_EMBEDDED6xx is not set
164# CONFIG_IPIC is not set
165# CONFIG_MPIC is not set
166# CONFIG_MPIC_WEIRD is not set
167# CONFIG_PPC_I8259 is not set
168# CONFIG_PPC_RTAS is not set
169# CONFIG_MMIO_NVRAM is not set
170# CONFIG_PPC_MPC106 is not set
171# CONFIG_PPC_970_NAP is not set
172# CONFIG_PPC_INDIRECT_IO is not set
173# CONFIG_GENERIC_IOMAP is not set
174# CONFIG_CPU_FREQ is not set
175# CONFIG_TAU is not set
176# CONFIG_FSL_ULI1575 is not set
177CONFIG_PPC_BESTCOMM=y
178# CONFIG_PPC_BESTCOMM_ATA is not set
179CONFIG_PPC_BESTCOMM_FEC=y
180# CONFIG_PPC_BESTCOMM_GEN_BD is not set
181
182#
183# Kernel options
184#
185# CONFIG_HIGHMEM is not set
186# CONFIG_TICK_ONESHOT is not set
187# CONFIG_NO_HZ is not set
188# CONFIG_HIGH_RES_TIMERS is not set
189CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
190# CONFIG_HZ_100 is not set
191CONFIG_HZ_250=y
192# CONFIG_HZ_300 is not set
193# CONFIG_HZ_1000 is not set
194CONFIG_HZ=250
195# CONFIG_SCHED_HRTICK is not set
196CONFIG_PREEMPT_NONE=y
197# CONFIG_PREEMPT_VOLUNTARY is not set
198# CONFIG_PREEMPT is not set
199CONFIG_BINFMT_ELF=y
200# CONFIG_BINFMT_MISC is not set
201# CONFIG_IOMMU_HELPER is not set
202CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
203CONFIG_ARCH_HAS_WALK_MEMORY=y
204CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
205# CONFIG_KEXEC is not set
206CONFIG_ARCH_FLATMEM_ENABLE=y
207CONFIG_ARCH_POPULATES_NODE_MAP=y
208CONFIG_SELECT_MEMORY_MODEL=y
209CONFIG_FLATMEM_MANUAL=y
210# CONFIG_DISCONTIGMEM_MANUAL is not set
211# CONFIG_SPARSEMEM_MANUAL is not set
212CONFIG_FLATMEM=y
213CONFIG_FLAT_NODE_MEM_MAP=y
214# CONFIG_SPARSEMEM_STATIC is not set
215# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
216CONFIG_PAGEFLAGS_EXTENDED=y
217CONFIG_SPLIT_PTLOCK_CPUS=4
218# CONFIG_RESOURCES_64BIT is not set
219CONFIG_ZONE_DMA_FLAG=1
220CONFIG_BOUNCE=y
221CONFIG_VIRT_TO_BUS=y
222CONFIG_FORCE_MAX_ZONEORDER=11
223CONFIG_PROC_DEVICETREE=y
224# CONFIG_CMDLINE_BOOL is not set
225CONFIG_PM=y
226# CONFIG_PM_LEGACY is not set
227# CONFIG_PM_DEBUG is not set
228CONFIG_SECCOMP=y
229CONFIG_ISA_DMA_API=y
230
231#
232# Bus options
233#
234CONFIG_ZONE_DMA=y
235CONFIG_GENERIC_ISA_DMA=y
236CONFIG_FSL_SOC=y
237# CONFIG_PCI is not set
238# CONFIG_PCI_DOMAINS is not set
239# CONFIG_PCI_SYSCALL is not set
240# CONFIG_ARCH_SUPPORTS_MSI is not set
241# CONFIG_PCCARD is not set
242# CONFIG_HAS_RAPIDIO is not set
243
244#
245# Advanced setup
246#
247# CONFIG_ADVANCED_OPTIONS is not set
248
249#
250# Default settings for advanced configuration options are used
251#
252CONFIG_LOWMEM_SIZE=0x30000000
253CONFIG_PAGE_OFFSET=0xc0000000
254CONFIG_KERNEL_START=0xc0000000
255CONFIG_PHYSICAL_START=0x00000000
256CONFIG_TASK_SIZE=0xc0000000
257
258#
259# Networking
260#
261CONFIG_NET=y
262
263#
264# Networking options
265#
266CONFIG_PACKET=y
267# CONFIG_PACKET_MMAP is not set
268CONFIG_UNIX=y
269CONFIG_XFRM=y
270CONFIG_XFRM_USER=y
271# CONFIG_XFRM_SUB_POLICY is not set
272# CONFIG_XFRM_MIGRATE is not set
273# CONFIG_XFRM_STATISTICS is not set
274# CONFIG_NET_KEY is not set
275CONFIG_INET=y
276CONFIG_IP_MULTICAST=y
277# CONFIG_IP_ADVANCED_ROUTER is not set
278CONFIG_IP_FIB_HASH=y
279CONFIG_IP_PNP=y
280CONFIG_IP_PNP_DHCP=y
281CONFIG_IP_PNP_BOOTP=y
282# CONFIG_IP_PNP_RARP is not set
283# CONFIG_NET_IPIP is not set
284# CONFIG_NET_IPGRE is not set
285# CONFIG_IP_MROUTE is not set
286# CONFIG_ARPD is not set
287CONFIG_SYN_COOKIES=y
288# CONFIG_INET_AH is not set
289# CONFIG_INET_ESP is not set
290# CONFIG_INET_IPCOMP is not set
291# CONFIG_INET_XFRM_TUNNEL is not set
292# CONFIG_INET_TUNNEL is not set
293CONFIG_INET_XFRM_MODE_TRANSPORT=y
294CONFIG_INET_XFRM_MODE_TUNNEL=y
295CONFIG_INET_XFRM_MODE_BEET=y
296# CONFIG_INET_LRO is not set
297CONFIG_INET_DIAG=y
298CONFIG_INET_TCP_DIAG=y
299# CONFIG_TCP_CONG_ADVANCED is not set
300CONFIG_TCP_CONG_CUBIC=y
301CONFIG_DEFAULT_TCP_CONG="cubic"
302# CONFIG_TCP_MD5SIG is not set
303# CONFIG_IPV6 is not set
304# CONFIG_NETWORK_SECMARK is not set
305# CONFIG_NETFILTER is not set
306# CONFIG_IP_DCCP is not set
307# CONFIG_IP_SCTP is not set
308# CONFIG_TIPC is not set
309# CONFIG_ATM is not set
310# CONFIG_BRIDGE is not set
311# CONFIG_VLAN_8021Q is not set
312# CONFIG_DECNET is not set
313# CONFIG_LLC2 is not set
314# CONFIG_IPX is not set
315# CONFIG_ATALK is not set
316# CONFIG_X25 is not set
317# CONFIG_LAPB is not set
318# CONFIG_ECONET is not set
319# CONFIG_WAN_ROUTER is not set
320# CONFIG_NET_SCHED is not set
321
322#
323# Network testing
324#
325# CONFIG_NET_PKTGEN is not set
326# CONFIG_HAMRADIO is not set
327# CONFIG_CAN is not set
328# CONFIG_IRDA is not set
329# CONFIG_BT is not set
330# CONFIG_AF_RXRPC is not set
331
332#
333# Wireless
334#
335# CONFIG_CFG80211 is not set
336# CONFIG_WIRELESS_EXT is not set
337# CONFIG_MAC80211 is not set
338# CONFIG_IEEE80211 is not set
339# CONFIG_RFKILL is not set
340# CONFIG_NET_9P is not set
341
342#
343# Device Drivers
344#
345
346#
347# Generic Driver Options
348#
349CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
350CONFIG_STANDALONE=y
351CONFIG_PREVENT_FIRMWARE_BUILD=y
352# CONFIG_FW_LOADER is not set
353# CONFIG_DEBUG_DRIVER is not set
354# CONFIG_DEBUG_DEVRES is not set
355# CONFIG_SYS_HYPERVISOR is not set
356# CONFIG_CONNECTOR is not set
357CONFIG_MTD=y
358# CONFIG_MTD_DEBUG is not set
359CONFIG_MTD_CONCAT=y
360CONFIG_MTD_PARTITIONS=y
361# CONFIG_MTD_REDBOOT_PARTS is not set
362CONFIG_MTD_CMDLINE_PARTS=y
363# CONFIG_MTD_OF_PARTS is not set
364# CONFIG_MTD_AR7_PARTS is not set
365
366#
367# User Modules And Translation Layers
368#
369CONFIG_MTD_CHAR=y
370CONFIG_MTD_BLKDEVS=y
371CONFIG_MTD_BLOCK=y
372# CONFIG_FTL is not set
373# CONFIG_NFTL is not set
374# CONFIG_INFTL is not set
375# CONFIG_RFD_FTL is not set
376# CONFIG_SSFDC is not set
377# CONFIG_MTD_OOPS is not set
378
379#
380# RAM/ROM/Flash chip drivers
381#
382CONFIG_MTD_CFI=y
383# CONFIG_MTD_JEDECPROBE is not set
384CONFIG_MTD_GEN_PROBE=y
385# CONFIG_MTD_CFI_ADV_OPTIONS is not set
386CONFIG_MTD_MAP_BANK_WIDTH_1=y
387CONFIG_MTD_MAP_BANK_WIDTH_2=y
388CONFIG_MTD_MAP_BANK_WIDTH_4=y
389# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
390# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
391# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
392CONFIG_MTD_CFI_I1=y
393CONFIG_MTD_CFI_I2=y
394# CONFIG_MTD_CFI_I4 is not set
395# CONFIG_MTD_CFI_I8 is not set
396# CONFIG_MTD_CFI_INTELEXT is not set
397CONFIG_MTD_CFI_AMDSTD=y
398# CONFIG_MTD_CFI_STAA is not set
399CONFIG_MTD_CFI_UTIL=y
400# CONFIG_MTD_RAM is not set
401CONFIG_MTD_ROM=y
402# CONFIG_MTD_ABSENT is not set
403
404#
405# Mapping drivers for chip access
406#
407# CONFIG_MTD_COMPLEX_MAPPINGS is not set
408# CONFIG_MTD_PHYSMAP is not set
409# CONFIG_MTD_PHYSMAP_OF is not set
410# CONFIG_MTD_PLATRAM is not set
411
412#
413# Self-contained MTD device drivers
414#
415# CONFIG_MTD_SLRAM is not set
416# CONFIG_MTD_PHRAM is not set
417# CONFIG_MTD_MTDRAM is not set
418# CONFIG_MTD_BLOCK2MTD is not set
419
420#
421# Disk-On-Chip Device Drivers
422#
423# CONFIG_MTD_DOC2000 is not set
424# CONFIG_MTD_DOC2001 is not set
425# CONFIG_MTD_DOC2001PLUS is not set
426# CONFIG_MTD_NAND is not set
427# CONFIG_MTD_ONENAND is not set
428
429#
430# UBI - Unsorted block images
431#
432# CONFIG_MTD_UBI is not set
433CONFIG_OF_DEVICE=y
434CONFIG_OF_I2C=y
435# CONFIG_PARPORT is not set
436CONFIG_BLK_DEV=y
437# CONFIG_BLK_DEV_FD is not set
438# CONFIG_BLK_DEV_COW_COMMON is not set
439CONFIG_BLK_DEV_LOOP=y
440# CONFIG_BLK_DEV_CRYPTOLOOP is not set
441# CONFIG_BLK_DEV_NBD is not set
442CONFIG_BLK_DEV_RAM=y
443CONFIG_BLK_DEV_RAM_COUNT=16
444CONFIG_BLK_DEV_RAM_SIZE=32768
445# CONFIG_BLK_DEV_XIP is not set
446# CONFIG_CDROM_PKTCDVD is not set
447# CONFIG_ATA_OVER_ETH is not set
448CONFIG_MISC_DEVICES=y
449# CONFIG_EEPROM_93CX6 is not set
450# CONFIG_ENCLOSURE_SERVICES is not set
451CONFIG_HAVE_IDE=y
452# CONFIG_IDE is not set
453
454#
455# SCSI device support
456#
457# CONFIG_RAID_ATTRS is not set
458CONFIG_SCSI=y
459CONFIG_SCSI_DMA=y
460CONFIG_SCSI_TGT=y
461# CONFIG_SCSI_NETLINK is not set
462CONFIG_SCSI_PROC_FS=y
463
464#
465# SCSI support type (disk, tape, CD-ROM)
466#
467CONFIG_BLK_DEV_SD=y
468# CONFIG_CHR_DEV_ST is not set
469# CONFIG_CHR_DEV_OSST is not set
470# CONFIG_BLK_DEV_SR is not set
471CONFIG_CHR_DEV_SG=y
472# CONFIG_CHR_DEV_SCH is not set
473
474#
475# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
476#
477# CONFIG_SCSI_MULTI_LUN is not set
478# CONFIG_SCSI_CONSTANTS is not set
479# CONFIG_SCSI_LOGGING is not set
480# CONFIG_SCSI_SCAN_ASYNC is not set
481
482#
483# SCSI Transports
484#
485# CONFIG_SCSI_SPI_ATTRS is not set
486# CONFIG_SCSI_FC_ATTRS is not set
487# CONFIG_SCSI_ISCSI_ATTRS is not set
488# CONFIG_SCSI_SAS_LIBSAS is not set
489# CONFIG_SCSI_SRP_ATTRS is not set
490CONFIG_SCSI_LOWLEVEL=y
491# CONFIG_ISCSI_TCP is not set
492# CONFIG_SCSI_DEBUG is not set
493CONFIG_ATA=y
494# CONFIG_ATA_NONSTANDARD is not set
495CONFIG_SATA_PMP=y
496# CONFIG_SATA_FSL is not set
497CONFIG_ATA_SFF=y
498# CONFIG_SATA_MV is not set
499CONFIG_PATA_MPC52xx=y
500# CONFIG_PATA_PLATFORM is not set
501# CONFIG_MD is not set
502# CONFIG_MACINTOSH_DRIVERS is not set
503CONFIG_NETDEVICES=y
504# CONFIG_NETDEVICES_MULTIQUEUE is not set
505# CONFIG_DUMMY is not set
506# CONFIG_BONDING is not set
507# CONFIG_MACVLAN is not set
508# CONFIG_EQUALIZER is not set
509# CONFIG_TUN is not set
510# CONFIG_VETH is not set
511CONFIG_PHYLIB=y
512
513#
514# MII PHY device drivers
515#
516CONFIG_MARVELL_PHY=y
517CONFIG_DAVICOM_PHY=y
518CONFIG_QSEMI_PHY=y
519CONFIG_LXT_PHY=y
520CONFIG_CICADA_PHY=y
521CONFIG_VITESSE_PHY=y
522CONFIG_SMSC_PHY=y
523CONFIG_BROADCOM_PHY=y
524CONFIG_ICPLUS_PHY=y
525# CONFIG_REALTEK_PHY is not set
526# CONFIG_FIXED_PHY is not set
527CONFIG_MDIO_BITBANG=y
528CONFIG_NET_ETHERNET=y
529CONFIG_MII=y
530# CONFIG_IBM_NEW_EMAC_ZMII is not set
531# CONFIG_IBM_NEW_EMAC_RGMII is not set
532# CONFIG_IBM_NEW_EMAC_TAH is not set
533# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
534# CONFIG_B44 is not set
535CONFIG_FEC_MPC52xx=y
536CONFIG_FEC_MPC52xx_MDIO=y
537# CONFIG_NETDEV_1000 is not set
538# CONFIG_NETDEV_10000 is not set
539
540#
541# Wireless LAN
542#
543# CONFIG_WLAN_PRE80211 is not set
544# CONFIG_WLAN_80211 is not set
545# CONFIG_IWLWIFI is not set
546# CONFIG_IWLWIFI_LEDS is not set
547# CONFIG_WAN is not set
548# CONFIG_PPP is not set
549# CONFIG_SLIP is not set
550# CONFIG_NETCONSOLE is not set
551# CONFIG_NETPOLL is not set
552# CONFIG_NET_POLL_CONTROLLER is not set
553# CONFIG_ISDN is not set
554# CONFIG_PHONE is not set
555
556#
557# Input device support
558#
559# CONFIG_INPUT is not set
560
561#
562# Hardware I/O ports
563#
564# CONFIG_SERIO is not set
565# CONFIG_GAMEPORT is not set
566
567#
568# Character devices
569#
570# CONFIG_VT is not set
571# CONFIG_SERIAL_NONSTANDARD is not set
572
573#
574# Serial drivers
575#
576# CONFIG_SERIAL_8250 is not set
577
578#
579# Non-8250 serial port support
580#
581# CONFIG_SERIAL_UARTLITE is not set
582CONFIG_SERIAL_CORE=y
583CONFIG_SERIAL_CORE_CONSOLE=y
584CONFIG_SERIAL_MPC52xx=y
585CONFIG_SERIAL_MPC52xx_CONSOLE=y
586CONFIG_SERIAL_MPC52xx_CONSOLE_BAUD=115200
587CONFIG_UNIX98_PTYS=y
588CONFIG_LEGACY_PTYS=y
589CONFIG_LEGACY_PTY_COUNT=256
590# CONFIG_IPMI_HANDLER is not set
591# CONFIG_HW_RANDOM is not set
592# CONFIG_NVRAM is not set
593# CONFIG_R3964 is not set
594# CONFIG_RAW_DRIVER is not set
595# CONFIG_TCG_TPM is not set
596CONFIG_I2C=y
597CONFIG_I2C_BOARDINFO=y
598CONFIG_I2C_CHARDEV=y
599
600#
601# I2C Hardware Bus support
602#
603CONFIG_I2C_MPC=y
604# CONFIG_I2C_OCORES is not set
605# CONFIG_I2C_PARPORT_LIGHT is not set
606# CONFIG_I2C_SIMTEC is not set
607# CONFIG_I2C_TAOS_EVM is not set
608# CONFIG_I2C_PCA_PLATFORM is not set
609
610#
611# Miscellaneous I2C Chip support
612#
613# CONFIG_DS1682 is not set
614CONFIG_SENSORS_EEPROM=y
615# CONFIG_SENSORS_PCF8574 is not set
616# CONFIG_PCF8575 is not set
617# CONFIG_SENSORS_PCF8591 is not set
618# CONFIG_SENSORS_MAX6875 is not set
619# CONFIG_SENSORS_TSL2550 is not set
620# CONFIG_I2C_DEBUG_CORE is not set
621# CONFIG_I2C_DEBUG_ALGO is not set
622# CONFIG_I2C_DEBUG_BUS is not set
623# CONFIG_I2C_DEBUG_CHIP is not set
624# CONFIG_SPI is not set
625# CONFIG_W1 is not set
626# CONFIG_POWER_SUPPLY is not set
627CONFIG_HWMON=y
628# CONFIG_HWMON_VID is not set
629# CONFIG_SENSORS_AD7418 is not set
630# CONFIG_SENSORS_ADM1021 is not set
631# CONFIG_SENSORS_ADM1025 is not set
632# CONFIG_SENSORS_ADM1026 is not set
633# CONFIG_SENSORS_ADM1029 is not set
634# CONFIG_SENSORS_ADM1031 is not set
635# CONFIG_SENSORS_ADM9240 is not set
636# CONFIG_SENSORS_ADT7470 is not set
637# CONFIG_SENSORS_ADT7473 is not set
638# CONFIG_SENSORS_ATXP1 is not set
639# CONFIG_SENSORS_DS1621 is not set
640# CONFIG_SENSORS_F71805F is not set
641# CONFIG_SENSORS_F71882FG is not set
642# CONFIG_SENSORS_F75375S is not set
643# CONFIG_SENSORS_GL518SM is not set
644# CONFIG_SENSORS_GL520SM is not set
645# CONFIG_SENSORS_IT87 is not set
646# CONFIG_SENSORS_LM63 is not set
647# CONFIG_SENSORS_LM75 is not set
648# CONFIG_SENSORS_LM77 is not set
649# CONFIG_SENSORS_LM78 is not set
650# CONFIG_SENSORS_LM80 is not set
651# CONFIG_SENSORS_LM83 is not set
652# CONFIG_SENSORS_LM85 is not set
653# CONFIG_SENSORS_LM87 is not set
654# CONFIG_SENSORS_LM90 is not set
655# CONFIG_SENSORS_LM92 is not set
656# CONFIG_SENSORS_LM93 is not set
657# CONFIG_SENSORS_MAX1619 is not set
658# CONFIG_SENSORS_MAX6650 is not set
659# CONFIG_SENSORS_PC87360 is not set
660# CONFIG_SENSORS_PC87427 is not set
661# CONFIG_SENSORS_DME1737 is not set
662# CONFIG_SENSORS_SMSC47M1 is not set
663# CONFIG_SENSORS_SMSC47M192 is not set
664# CONFIG_SENSORS_SMSC47B397 is not set
665# CONFIG_SENSORS_ADS7828 is not set
666# CONFIG_SENSORS_THMC50 is not set
667# CONFIG_SENSORS_VT1211 is not set
668# CONFIG_SENSORS_W83781D is not set
669# CONFIG_SENSORS_W83791D is not set
670# CONFIG_SENSORS_W83792D is not set
671# CONFIG_SENSORS_W83793 is not set
672# CONFIG_SENSORS_W83L785TS is not set
673# CONFIG_SENSORS_W83L786NG is not set
674# CONFIG_SENSORS_W83627HF is not set
675# CONFIG_SENSORS_W83627EHF is not set
676# CONFIG_HWMON_DEBUG_CHIP is not set
677# CONFIG_THERMAL is not set
678CONFIG_WATCHDOG=y
679# CONFIG_WATCHDOG_NOWAYOUT is not set
680
681#
682# Watchdog Device Drivers
683#
684# CONFIG_SOFT_WATCHDOG is not set
685# CONFIG_MPC5200_WDT is not set
686
687#
688# Sonics Silicon Backplane
689#
690CONFIG_SSB_POSSIBLE=y
691# CONFIG_SSB is not set
692
693#
694# Multifunction device drivers
695#
696# CONFIG_MFD_SM501 is not set
697# CONFIG_HTC_PASIC3 is not set
698
699#
700# Multimedia devices
701#
702# CONFIG_VIDEO_DEV is not set
703# CONFIG_DVB_CORE is not set
704CONFIG_DAB=y
705
706#
707# Graphics support
708#
709# CONFIG_VGASTATE is not set
710# CONFIG_VIDEO_OUTPUT_CONTROL is not set
711# CONFIG_FB is not set
712# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
713
714#
715# Display device support
716#
717# CONFIG_DISPLAY_SUPPORT is not set
718
719#
720# Sound
721#
722# CONFIG_SOUND is not set
723# CONFIG_USB_SUPPORT is not set
724# CONFIG_MMC is not set
725# CONFIG_MEMSTICK is not set
726CONFIG_NEW_LEDS=y
727CONFIG_LEDS_CLASS=y
728
729#
730# LED drivers
731#
732
733#
734# LED Triggers
735#
736CONFIG_LEDS_TRIGGERS=y
737CONFIG_LEDS_TRIGGER_TIMER=y
738# CONFIG_LEDS_TRIGGER_HEARTBEAT is not set
739# CONFIG_LEDS_TRIGGER_DEFAULT_ON is not set
740# CONFIG_EDAC is not set
741CONFIG_RTC_LIB=y
742CONFIG_RTC_CLASS=y
743CONFIG_RTC_HCTOSYS=y
744CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
745# CONFIG_RTC_DEBUG is not set
746
747#
748# RTC interfaces
749#
750CONFIG_RTC_INTF_SYSFS=y
751CONFIG_RTC_INTF_PROC=y
752CONFIG_RTC_INTF_DEV=y
753# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
754# CONFIG_RTC_DRV_TEST is not set
755
756#
757# I2C RTC drivers
758#
759CONFIG_RTC_DRV_DS1307=y
760# CONFIG_RTC_DRV_DS1374 is not set
761# CONFIG_RTC_DRV_DS1672 is not set
762# CONFIG_RTC_DRV_MAX6900 is not set
763# CONFIG_RTC_DRV_RS5C372 is not set
764# CONFIG_RTC_DRV_ISL1208 is not set
765# CONFIG_RTC_DRV_X1205 is not set
766# CONFIG_RTC_DRV_PCF8563 is not set
767# CONFIG_RTC_DRV_PCF8583 is not set
768# CONFIG_RTC_DRV_M41T80 is not set
769# CONFIG_RTC_DRV_S35390A is not set
770
771#
772# SPI RTC drivers
773#
774
775#
776# Platform RTC drivers
777#
778# CONFIG_RTC_DRV_CMOS is not set
779# CONFIG_RTC_DRV_DS1511 is not set
780# CONFIG_RTC_DRV_DS1553 is not set
781# CONFIG_RTC_DRV_DS1742 is not set
782# CONFIG_RTC_DRV_STK17TA8 is not set
783# CONFIG_RTC_DRV_M48T86 is not set
784# CONFIG_RTC_DRV_M48T59 is not set
785# CONFIG_RTC_DRV_V3020 is not set
786
787#
788# on-CPU RTC drivers
789#
790# CONFIG_DMADEVICES is not set
791# CONFIG_UIO is not set
792
793#
794# File systems
795#
796CONFIG_EXT2_FS=y
797# CONFIG_EXT2_FS_XATTR is not set
798# CONFIG_EXT2_FS_XIP is not set
799CONFIG_EXT3_FS=y
800CONFIG_EXT3_FS_XATTR=y
801# CONFIG_EXT3_FS_POSIX_ACL is not set
802# CONFIG_EXT3_FS_SECURITY is not set
803# CONFIG_EXT4DEV_FS is not set
804CONFIG_JBD=y
805CONFIG_FS_MBCACHE=y
806# CONFIG_REISERFS_FS is not set
807# CONFIG_JFS_FS is not set
808# CONFIG_FS_POSIX_ACL is not set
809# CONFIG_XFS_FS is not set
810# CONFIG_OCFS2_FS is not set
811CONFIG_DNOTIFY=y
812CONFIG_INOTIFY=y
813CONFIG_INOTIFY_USER=y
814# CONFIG_QUOTA is not set
815# CONFIG_AUTOFS_FS is not set
816# CONFIG_AUTOFS4_FS is not set
817# CONFIG_FUSE_FS is not set
818
819#
820# CD-ROM/DVD Filesystems
821#
822# CONFIG_ISO9660_FS is not set
823# CONFIG_UDF_FS is not set
824
825#
826# DOS/FAT/NT Filesystems
827#
828CONFIG_FAT_FS=y
829CONFIG_MSDOS_FS=y
830CONFIG_VFAT_FS=y
831CONFIG_FAT_DEFAULT_CODEPAGE=437
832CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
833# CONFIG_NTFS_FS is not set
834
835#
836# Pseudo filesystems
837#
838CONFIG_PROC_FS=y
839CONFIG_PROC_KCORE=y
840CONFIG_PROC_SYSCTL=y
841CONFIG_SYSFS=y
842CONFIG_TMPFS=y
843# CONFIG_TMPFS_POSIX_ACL is not set
844# CONFIG_HUGETLB_PAGE is not set
845# CONFIG_CONFIGFS_FS is not set
846
847#
848# Miscellaneous filesystems
849#
850# CONFIG_ADFS_FS is not set
851# CONFIG_AFFS_FS is not set
852# CONFIG_HFS_FS is not set
853# CONFIG_HFSPLUS_FS is not set
854# CONFIG_BEFS_FS is not set
855# CONFIG_BFS_FS is not set
856# CONFIG_EFS_FS is not set
857CONFIG_JFFS2_FS=y
858CONFIG_JFFS2_FS_DEBUG=0
859CONFIG_JFFS2_FS_WRITEBUFFER=y
860# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
861# CONFIG_JFFS2_SUMMARY is not set
862# CONFIG_JFFS2_FS_XATTR is not set
863# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
864CONFIG_JFFS2_ZLIB=y
865# CONFIG_JFFS2_LZO is not set
866CONFIG_JFFS2_RTIME=y
867# CONFIG_JFFS2_RUBIN is not set
868CONFIG_CRAMFS=y
869# CONFIG_VXFS_FS is not set
870# CONFIG_MINIX_FS is not set
871# CONFIG_HPFS_FS is not set
872# CONFIG_QNX4FS_FS is not set
873# CONFIG_ROMFS_FS is not set
874# CONFIG_SYSV_FS is not set
875# CONFIG_UFS_FS is not set
876CONFIG_NETWORK_FILESYSTEMS=y
877CONFIG_NFS_FS=y
878CONFIG_NFS_V3=y
879# CONFIG_NFS_V3_ACL is not set
880CONFIG_NFS_V4=y
881# CONFIG_NFSD is not set
882CONFIG_ROOT_NFS=y
883CONFIG_LOCKD=y
884CONFIG_LOCKD_V4=y
885CONFIG_NFS_COMMON=y
886CONFIG_SUNRPC=y
887CONFIG_SUNRPC_GSS=y
888# CONFIG_SUNRPC_BIND34 is not set
889CONFIG_RPCSEC_GSS_KRB5=y
890# CONFIG_RPCSEC_GSS_SPKM3 is not set
891# CONFIG_SMB_FS is not set
892# CONFIG_CIFS is not set
893# CONFIG_NCP_FS is not set
894# CONFIG_CODA_FS is not set
895# CONFIG_AFS_FS is not set
896
897#
898# Partition Types
899#
900CONFIG_PARTITION_ADVANCED=y
901# CONFIG_ACORN_PARTITION is not set
902# CONFIG_OSF_PARTITION is not set
903# CONFIG_AMIGA_PARTITION is not set
904# CONFIG_ATARI_PARTITION is not set
905# CONFIG_MAC_PARTITION is not set
906CONFIG_MSDOS_PARTITION=y
907# CONFIG_BSD_DISKLABEL is not set
908# CONFIG_MINIX_SUBPARTITION is not set
909# CONFIG_SOLARIS_X86_PARTITION is not set
910# CONFIG_UNIXWARE_DISKLABEL is not set
911# CONFIG_LDM_PARTITION is not set
912# CONFIG_SGI_PARTITION is not set
913# CONFIG_ULTRIX_PARTITION is not set
914# CONFIG_SUN_PARTITION is not set
915# CONFIG_KARMA_PARTITION is not set
916# CONFIG_EFI_PARTITION is not set
917# CONFIG_SYSV68_PARTITION is not set
918CONFIG_NLS=y
919CONFIG_NLS_DEFAULT="iso8859-1"
920CONFIG_NLS_CODEPAGE_437=y
921# CONFIG_NLS_CODEPAGE_737 is not set
922# CONFIG_NLS_CODEPAGE_775 is not set
923# CONFIG_NLS_CODEPAGE_850 is not set
924# CONFIG_NLS_CODEPAGE_852 is not set
925# CONFIG_NLS_CODEPAGE_855 is not set
926# CONFIG_NLS_CODEPAGE_857 is not set
927# CONFIG_NLS_CODEPAGE_860 is not set
928# CONFIG_NLS_CODEPAGE_861 is not set
929# CONFIG_NLS_CODEPAGE_862 is not set
930# CONFIG_NLS_CODEPAGE_863 is not set
931# CONFIG_NLS_CODEPAGE_864 is not set
932# CONFIG_NLS_CODEPAGE_865 is not set
933# CONFIG_NLS_CODEPAGE_866 is not set
934# CONFIG_NLS_CODEPAGE_869 is not set
935# CONFIG_NLS_CODEPAGE_936 is not set
936# CONFIG_NLS_CODEPAGE_950 is not set
937# CONFIG_NLS_CODEPAGE_932 is not set
938# CONFIG_NLS_CODEPAGE_949 is not set
939# CONFIG_NLS_CODEPAGE_874 is not set
940# CONFIG_NLS_ISO8859_8 is not set
941# CONFIG_NLS_CODEPAGE_1250 is not set
942# CONFIG_NLS_CODEPAGE_1251 is not set
943# CONFIG_NLS_ASCII is not set
944CONFIG_NLS_ISO8859_1=y
945# CONFIG_NLS_ISO8859_2 is not set
946# CONFIG_NLS_ISO8859_3 is not set
947# CONFIG_NLS_ISO8859_4 is not set
948# CONFIG_NLS_ISO8859_5 is not set
949# CONFIG_NLS_ISO8859_6 is not set
950# CONFIG_NLS_ISO8859_7 is not set
951# CONFIG_NLS_ISO8859_9 is not set
952# CONFIG_NLS_ISO8859_13 is not set
953# CONFIG_NLS_ISO8859_14 is not set
954# CONFIG_NLS_ISO8859_15 is not set
955# CONFIG_NLS_KOI8_R is not set
956# CONFIG_NLS_KOI8_U is not set
957# CONFIG_NLS_UTF8 is not set
958# CONFIG_DLM is not set
959
960#
961# Library routines
962#
963CONFIG_BITREVERSE=y
964# CONFIG_GENERIC_FIND_FIRST_BIT is not set
965# CONFIG_CRC_CCITT is not set
966# CONFIG_CRC16 is not set
967# CONFIG_CRC_ITU_T is not set
968CONFIG_CRC32=y
969# CONFIG_CRC7 is not set
970# CONFIG_LIBCRC32C is not set
971CONFIG_ZLIB_INFLATE=y
972CONFIG_ZLIB_DEFLATE=y
973CONFIG_PLIST=y
974CONFIG_HAS_IOMEM=y
975CONFIG_HAS_IOPORT=y
976CONFIG_HAS_DMA=y
977CONFIG_HAVE_LMB=y
978
979#
980# Kernel hacking
981#
982CONFIG_PRINTK_TIME=y
983CONFIG_ENABLE_WARN_DEPRECATED=y
984CONFIG_ENABLE_MUST_CHECK=y
985CONFIG_FRAME_WARN=1024
986# CONFIG_MAGIC_SYSRQ is not set
987# CONFIG_UNUSED_SYMBOLS is not set
988# CONFIG_DEBUG_FS is not set
989# CONFIG_HEADERS_CHECK is not set
990CONFIG_DEBUG_KERNEL=y
991# CONFIG_DEBUG_SHIRQ is not set
992CONFIG_DETECT_SOFTLOCKUP=y
993CONFIG_SCHED_DEBUG=y
994# CONFIG_SCHEDSTATS is not set
995# CONFIG_TIMER_STATS is not set
996# CONFIG_SLUB_DEBUG_ON is not set
997# CONFIG_SLUB_STATS is not set
998# CONFIG_DEBUG_RT_MUTEXES is not set
999# CONFIG_RT_MUTEX_TESTER is not set
1000# CONFIG_DEBUG_SPINLOCK is not set
1001# CONFIG_DEBUG_MUTEXES is not set
1002# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
1003# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
1004# CONFIG_DEBUG_KOBJECT is not set
1005# CONFIG_DEBUG_BUGVERBOSE is not set
1006CONFIG_DEBUG_INFO=y
1007# CONFIG_DEBUG_VM is not set
1008# CONFIG_DEBUG_WRITECOUNT is not set
1009# CONFIG_DEBUG_LIST is not set
1010# CONFIG_DEBUG_SG is not set
1011# CONFIG_BOOT_PRINTK_DELAY is not set
1012# CONFIG_BACKTRACE_SELF_TEST is not set
1013# CONFIG_FAULT_INJECTION is not set
1014# CONFIG_SAMPLES is not set
1015# CONFIG_DEBUG_STACKOVERFLOW is not set
1016# CONFIG_DEBUG_STACK_USAGE is not set
1017# CONFIG_DEBUG_PAGEALLOC is not set
1018# CONFIG_DEBUGGER is not set
1019# CONFIG_IRQSTACKS is not set
1020# CONFIG_BDI_SWITCH is not set
1021# CONFIG_BOOTX_TEXT is not set
1022# CONFIG_PPC_EARLY_DEBUG is not set
1023
1024#
1025# Security options
1026#
1027# CONFIG_KEYS is not set
1028# CONFIG_SECURITY is not set
1029# CONFIG_SECURITY_FILE_CAPABILITIES is not set
1030CONFIG_CRYPTO=y
1031
1032#
1033# Crypto core or helper
1034#
1035CONFIG_CRYPTO_ALGAPI=y
1036CONFIG_CRYPTO_BLKCIPHER=y
1037CONFIG_CRYPTO_MANAGER=y
1038# CONFIG_CRYPTO_GF128MUL is not set
1039# CONFIG_CRYPTO_NULL is not set
1040# CONFIG_CRYPTO_CRYPTD is not set
1041# CONFIG_CRYPTO_AUTHENC is not set
1042
1043#
1044# Authenticated Encryption with Associated Data
1045#
1046# CONFIG_CRYPTO_CCM is not set
1047# CONFIG_CRYPTO_GCM is not set
1048# CONFIG_CRYPTO_SEQIV is not set
1049
1050#
1051# Block modes
1052#
1053CONFIG_CRYPTO_CBC=y
1054# CONFIG_CRYPTO_CTR is not set
1055# CONFIG_CRYPTO_CTS is not set
1056CONFIG_CRYPTO_ECB=y
1057# CONFIG_CRYPTO_LRW is not set
1058CONFIG_CRYPTO_PCBC=y
1059# CONFIG_CRYPTO_XTS is not set
1060
1061#
1062# Hash modes
1063#
1064# CONFIG_CRYPTO_HMAC is not set
1065# CONFIG_CRYPTO_XCBC is not set
1066
1067#
1068# Digest
1069#
1070# CONFIG_CRYPTO_CRC32C is not set
1071# CONFIG_CRYPTO_MD4 is not set
1072CONFIG_CRYPTO_MD5=y
1073# CONFIG_CRYPTO_MICHAEL_MIC is not set
1074# CONFIG_CRYPTO_SHA1 is not set
1075# CONFIG_CRYPTO_SHA256 is not set
1076# CONFIG_CRYPTO_SHA512 is not set
1077# CONFIG_CRYPTO_TGR192 is not set
1078# CONFIG_CRYPTO_WP512 is not set
1079
1080#
1081# Ciphers
1082#
1083# CONFIG_CRYPTO_AES is not set
1084# CONFIG_CRYPTO_ANUBIS is not set
1085# CONFIG_CRYPTO_ARC4 is not set
1086# CONFIG_CRYPTO_BLOWFISH is not set
1087# CONFIG_CRYPTO_CAMELLIA is not set
1088# CONFIG_CRYPTO_CAST5 is not set
1089# CONFIG_CRYPTO_CAST6 is not set
1090CONFIG_CRYPTO_DES=y
1091# CONFIG_CRYPTO_FCRYPT is not set
1092# CONFIG_CRYPTO_KHAZAD is not set
1093# CONFIG_CRYPTO_SALSA20 is not set
1094# CONFIG_CRYPTO_SEED is not set
1095# CONFIG_CRYPTO_SERPENT is not set
1096# CONFIG_CRYPTO_TEA is not set
1097# CONFIG_CRYPTO_TWOFISH is not set
1098
1099#
1100# Compression
1101#
1102# CONFIG_CRYPTO_DEFLATE is not set
1103# CONFIG_CRYPTO_LZO is not set
1104CONFIG_CRYPTO_HW=y
1105CONFIG_PPC_CLOCK=y
1106CONFIG_PPC_LIB_RHEAP=y
1107# CONFIG_VIRTUALIZATION is not set
diff --git a/arch/powerpc/configs/52xx/pcm030_defconfig b/arch/powerpc/configs/52xx/pcm030_defconfig
new file mode 100644
index 000000000000..9c0caa488b2e
--- /dev/null
+++ b/arch/powerpc/configs/52xx/pcm030_defconfig
@@ -0,0 +1,1115 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.25
4# Tue Apr 29 07:13:19 2008
5#
6# CONFIG_PPC64 is not set
7
8#
9# Processor support
10#
11CONFIG_6xx=y
12# CONFIG_PPC_85xx is not set
13# CONFIG_PPC_8xx is not set
14# CONFIG_40x is not set
15# CONFIG_44x is not set
16# CONFIG_E200 is not set
17CONFIG_PPC_FPU=y
18# CONFIG_ALTIVEC is not set
19CONFIG_PPC_STD_MMU=y
20CONFIG_PPC_STD_MMU_32=y
21# CONFIG_PPC_MM_SLICES is not set
22# CONFIG_SMP is not set
23CONFIG_PPC32=y
24CONFIG_WORD_SIZE=32
25CONFIG_PPC_MERGE=y
26CONFIG_MMU=y
27CONFIG_GENERIC_CMOS_UPDATE=y
28CONFIG_GENERIC_TIME=y
29CONFIG_GENERIC_TIME_VSYSCALL=y
30CONFIG_GENERIC_CLOCKEVENTS=y
31CONFIG_GENERIC_HARDIRQS=y
32# CONFIG_HAVE_SETUP_PER_CPU_AREA is not set
33CONFIG_IRQ_PER_CPU=y
34CONFIG_STACKTRACE_SUPPORT=y
35CONFIG_LOCKDEP_SUPPORT=y
36CONFIG_RWSEM_XCHGADD_ALGORITHM=y
37CONFIG_ARCH_HAS_ILOG2_U32=y
38CONFIG_GENERIC_HWEIGHT=y
39CONFIG_GENERIC_CALIBRATE_DELAY=y
40CONFIG_GENERIC_FIND_NEXT_BIT=y
41# CONFIG_ARCH_NO_VIRT_TO_BUS is not set
42CONFIG_PPC=y
43CONFIG_EARLY_PRINTK=y
44CONFIG_GENERIC_NVRAM=y
45CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
46CONFIG_ARCH_MAY_HAVE_PC_FDC=y
47CONFIG_PPC_OF=y
48CONFIG_OF=y
49# CONFIG_PPC_UDBG_16550 is not set
50# CONFIG_GENERIC_TBSYNC is not set
51CONFIG_AUDIT_ARCH=y
52CONFIG_GENERIC_BUG=y
53CONFIG_DEFAULT_UIMAGE=y
54# CONFIG_PPC_DCR_NATIVE is not set
55# CONFIG_PPC_DCR_MMIO is not set
56CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
57
58#
59# General setup
60#
61CONFIG_EXPERIMENTAL=y
62CONFIG_BROKEN_ON_SMP=y
63CONFIG_LOCK_KERNEL=y
64CONFIG_INIT_ENV_ARG_LIMIT=32
65CONFIG_LOCALVERSION="trunk"
66# CONFIG_LOCALVERSION_AUTO is not set
67# CONFIG_SWAP is not set
68CONFIG_SYSVIPC=y
69CONFIG_SYSVIPC_SYSCTL=y
70CONFIG_POSIX_MQUEUE=y
71# CONFIG_BSD_PROCESS_ACCT is not set
72# CONFIG_TASKSTATS is not set
73# CONFIG_AUDIT is not set
74CONFIG_IKCONFIG=y
75CONFIG_IKCONFIG_PROC=y
76CONFIG_LOG_BUF_SHIFT=14
77# CONFIG_CGROUPS is not set
78CONFIG_GROUP_SCHED=y
79CONFIG_FAIR_GROUP_SCHED=y
80# CONFIG_RT_GROUP_SCHED is not set
81CONFIG_USER_SCHED=y
82# CONFIG_CGROUP_SCHED is not set
83CONFIG_SYSFS_DEPRECATED=y
84CONFIG_SYSFS_DEPRECATED_V2=y
85# CONFIG_RELAY is not set
86# CONFIG_NAMESPACES is not set
87# CONFIG_BLK_DEV_INITRD is not set
88# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
89CONFIG_SYSCTL=y
90CONFIG_EMBEDDED=y
91# CONFIG_SYSCTL_SYSCALL is not set
92CONFIG_KALLSYMS=y
93# CONFIG_KALLSYMS_EXTRA_PASS is not set
94CONFIG_HOTPLUG=y
95CONFIG_PRINTK=y
96CONFIG_BUG=y
97CONFIG_ELF_CORE=y
98CONFIG_COMPAT_BRK=y
99CONFIG_BASE_FULL=y
100CONFIG_FUTEX=y
101CONFIG_ANON_INODES=y
102CONFIG_EPOLL=y
103CONFIG_SIGNALFD=y
104CONFIG_TIMERFD=y
105CONFIG_EVENTFD=y
106CONFIG_SHMEM=y
107# CONFIG_VM_EVENT_COUNTERS is not set
108CONFIG_SLAB=y
109# CONFIG_SLUB is not set
110# CONFIG_SLOB is not set
111# CONFIG_PROFILING is not set
112# CONFIG_MARKERS is not set
113CONFIG_HAVE_OPROFILE=y
114# CONFIG_KPROBES is not set
115CONFIG_HAVE_KPROBES=y
116CONFIG_HAVE_KRETPROBES=y
117CONFIG_PROC_PAGE_MONITOR=y
118CONFIG_SLABINFO=y
119CONFIG_RT_MUTEXES=y
120# CONFIG_TINY_SHMEM is not set
121CONFIG_BASE_SMALL=0
122CONFIG_MODULES=y
123CONFIG_MODULE_UNLOAD=y
124# CONFIG_MODULE_FORCE_UNLOAD is not set
125# CONFIG_MODVERSIONS is not set
126# CONFIG_MODULE_SRCVERSION_ALL is not set
127# CONFIG_KMOD is not set
128CONFIG_BLOCK=y
129# CONFIG_LBD is not set
130# CONFIG_BLK_DEV_IO_TRACE is not set
131# CONFIG_LSF is not set
132# CONFIG_BLK_DEV_BSG is not set
133
134#
135# IO Schedulers
136#
137CONFIG_IOSCHED_NOOP=y
138# CONFIG_IOSCHED_AS is not set
139# CONFIG_IOSCHED_DEADLINE is not set
140# CONFIG_IOSCHED_CFQ is not set
141# CONFIG_DEFAULT_AS is not set
142# CONFIG_DEFAULT_DEADLINE is not set
143# CONFIG_DEFAULT_CFQ is not set
144CONFIG_DEFAULT_NOOP=y
145CONFIG_DEFAULT_IOSCHED="noop"
146CONFIG_CLASSIC_RCU=y
147
148#
149# Platform support
150#
151CONFIG_PPC_MULTIPLATFORM=y
152# CONFIG_PPC_82xx is not set
153# CONFIG_PPC_83xx is not set
154# CONFIG_PPC_86xx is not set
155CONFIG_CLASSIC32=y
156# CONFIG_PPC_CHRP is not set
157# CONFIG_PPC_MPC512x is not set
158# CONFIG_PPC_MPC5121 is not set
159# CONFIG_MPC5121_ADS is not set
160CONFIG_PPC_MPC52xx=y
161CONFIG_PPC_MPC5200_SIMPLE=y
162# CONFIG_PPC_EFIKA is not set
163# CONFIG_PPC_LITE5200 is not set
164# CONFIG_PPC_MPC5200_BUGFIX is not set
165# CONFIG_PPC_MPC5200_GPIO is not set
166# CONFIG_PPC_PMAC is not set
167# CONFIG_PPC_CELL is not set
168# CONFIG_PPC_CELL_NATIVE is not set
169# CONFIG_PQ2ADS is not set
170# CONFIG_EMBEDDED6xx is not set
171# CONFIG_IPIC is not set
172# CONFIG_MPIC is not set
173# CONFIG_MPIC_WEIRD is not set
174# CONFIG_PPC_I8259 is not set
175# CONFIG_PPC_RTAS is not set
176# CONFIG_MMIO_NVRAM is not set
177# CONFIG_PPC_MPC106 is not set
178# CONFIG_PPC_970_NAP is not set
179# CONFIG_PPC_INDIRECT_IO is not set
180# CONFIG_GENERIC_IOMAP is not set
181# CONFIG_CPU_FREQ is not set
182# CONFIG_TAU is not set
183# CONFIG_FSL_ULI1575 is not set
184CONFIG_PPC_BESTCOMM=y
185CONFIG_PPC_BESTCOMM_ATA=y
186CONFIG_PPC_BESTCOMM_FEC=y
187CONFIG_PPC_BESTCOMM_GEN_BD=y
188
189#
190# Kernel options
191#
192# CONFIG_HIGHMEM is not set
193CONFIG_TICK_ONESHOT=y
194CONFIG_NO_HZ=y
195CONFIG_HIGH_RES_TIMERS=y
196CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
197CONFIG_HZ_100=y
198# CONFIG_HZ_250 is not set
199# CONFIG_HZ_300 is not set
200# CONFIG_HZ_1000 is not set
201CONFIG_HZ=100
202# CONFIG_SCHED_HRTICK is not set
203# CONFIG_PREEMPT_NONE is not set
204# CONFIG_PREEMPT_VOLUNTARY is not set
205CONFIG_PREEMPT=y
206# CONFIG_PREEMPT_RCU is not set
207CONFIG_BINFMT_ELF=y
208# CONFIG_BINFMT_MISC is not set
209# CONFIG_IOMMU_HELPER is not set
210CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
211CONFIG_ARCH_HAS_WALK_MEMORY=y
212CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
213# CONFIG_KEXEC is not set
214CONFIG_ARCH_FLATMEM_ENABLE=y
215CONFIG_ARCH_POPULATES_NODE_MAP=y
216CONFIG_SELECT_MEMORY_MODEL=y
217CONFIG_FLATMEM_MANUAL=y
218# CONFIG_DISCONTIGMEM_MANUAL is not set
219# CONFIG_SPARSEMEM_MANUAL is not set
220CONFIG_FLATMEM=y
221CONFIG_FLAT_NODE_MEM_MAP=y
222# CONFIG_SPARSEMEM_STATIC is not set
223# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
224CONFIG_PAGEFLAGS_EXTENDED=y
225CONFIG_SPLIT_PTLOCK_CPUS=4
226# CONFIG_RESOURCES_64BIT is not set
227CONFIG_ZONE_DMA_FLAG=1
228CONFIG_BOUNCE=y
229CONFIG_VIRT_TO_BUS=y
230CONFIG_FORCE_MAX_ZONEORDER=11
231CONFIG_PROC_DEVICETREE=y
232# CONFIG_CMDLINE_BOOL is not set
233# CONFIG_PM is not set
234# CONFIG_SECCOMP is not set
235CONFIG_ISA_DMA_API=y
236
237#
238# Bus options
239#
240CONFIG_ZONE_DMA=y
241CONFIG_GENERIC_ISA_DMA=y
242# CONFIG_PPC_INDIRECT_PCI is not set
243CONFIG_FSL_SOC=y
244CONFIG_PCI=y
245CONFIG_PCI_DOMAINS=y
246CONFIG_PCI_SYSCALL=y
247# CONFIG_PCIEPORTBUS is not set
248CONFIG_ARCH_SUPPORTS_MSI=y
249# CONFIG_PCI_MSI is not set
250CONFIG_PCI_LEGACY=y
251# CONFIG_PCCARD is not set
252# CONFIG_HOTPLUG_PCI is not set
253# CONFIG_HAS_RAPIDIO is not set
254
255#
256# Advanced setup
257#
258# CONFIG_ADVANCED_OPTIONS is not set
259
260#
261# Default settings for advanced configuration options are used
262#
263CONFIG_LOWMEM_SIZE=0x30000000
264CONFIG_PAGE_OFFSET=0xc0000000
265CONFIG_KERNEL_START=0xc0000000
266CONFIG_PHYSICAL_START=0x00000000
267CONFIG_TASK_SIZE=0xc0000000
268
269#
270# Networking
271#
272CONFIG_NET=y
273
274#
275# Networking options
276#
277CONFIG_PACKET=y
278# CONFIG_PACKET_MMAP is not set
279CONFIG_UNIX=y
280# CONFIG_NET_KEY is not set
281CONFIG_INET=y
282CONFIG_IP_MULTICAST=y
283# CONFIG_IP_ADVANCED_ROUTER is not set
284CONFIG_IP_FIB_HASH=y
285CONFIG_IP_PNP=y
286CONFIG_IP_PNP_DHCP=y
287CONFIG_IP_PNP_BOOTP=y
288# CONFIG_IP_PNP_RARP is not set
289# CONFIG_NET_IPIP is not set
290# CONFIG_NET_IPGRE is not set
291# CONFIG_IP_MROUTE is not set
292# CONFIG_ARPD is not set
293# CONFIG_SYN_COOKIES is not set
294# CONFIG_INET_AH is not set
295# CONFIG_INET_ESP is not set
296# CONFIG_INET_IPCOMP is not set
297# CONFIG_INET_XFRM_TUNNEL is not set
298# CONFIG_INET_TUNNEL is not set
299# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
300# CONFIG_INET_XFRM_MODE_TUNNEL is not set
301# CONFIG_INET_XFRM_MODE_BEET is not set
302# CONFIG_INET_LRO is not set
303# CONFIG_INET_DIAG is not set
304# CONFIG_TCP_CONG_ADVANCED is not set
305CONFIG_TCP_CONG_CUBIC=y
306CONFIG_DEFAULT_TCP_CONG="cubic"
307# CONFIG_TCP_MD5SIG is not set
308# CONFIG_IPV6 is not set
309# CONFIG_NETWORK_SECMARK is not set
310# CONFIG_NETFILTER is not set
311# CONFIG_IP_DCCP is not set
312# CONFIG_IP_SCTP is not set
313# CONFIG_TIPC is not set
314# CONFIG_ATM is not set
315# CONFIG_BRIDGE is not set
316# CONFIG_VLAN_8021Q is not set
317# CONFIG_DECNET is not set
318# CONFIG_LLC2 is not set
319# CONFIG_IPX is not set
320# CONFIG_ATALK is not set
321# CONFIG_X25 is not set
322# CONFIG_LAPB is not set
323# CONFIG_ECONET is not set
324# CONFIG_WAN_ROUTER is not set
325# CONFIG_NET_SCHED is not set
326
327#
328# Network testing
329#
330# CONFIG_NET_PKTGEN is not set
331# CONFIG_HAMRADIO is not set
332# CONFIG_CAN is not set
333# CONFIG_IRDA is not set
334# CONFIG_BT is not set
335# CONFIG_AF_RXRPC is not set
336
337#
338# Wireless
339#
340# CONFIG_CFG80211 is not set
341# CONFIG_WIRELESS_EXT is not set
342# CONFIG_MAC80211 is not set
343# CONFIG_IEEE80211 is not set
344# CONFIG_RFKILL is not set
345# CONFIG_NET_9P is not set
346
347#
348# Device Drivers
349#
350
351#
352# Generic Driver Options
353#
354CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
355CONFIG_STANDALONE=y
356CONFIG_PREVENT_FIRMWARE_BUILD=y
357# CONFIG_FW_LOADER is not set
358# CONFIG_SYS_HYPERVISOR is not set
359# CONFIG_CONNECTOR is not set
360CONFIG_MTD=y
361# CONFIG_MTD_DEBUG is not set
362# CONFIG_MTD_CONCAT is not set
363CONFIG_MTD_PARTITIONS=y
364# CONFIG_MTD_REDBOOT_PARTS is not set
365CONFIG_MTD_CMDLINE_PARTS=y
366# CONFIG_MTD_OF_PARTS is not set
367# CONFIG_MTD_AR7_PARTS is not set
368
369#
370# User Modules And Translation Layers
371#
372CONFIG_MTD_CHAR=y
373CONFIG_MTD_BLKDEVS=y
374CONFIG_MTD_BLOCK=y
375# CONFIG_FTL is not set
376# CONFIG_NFTL is not set
377# CONFIG_INFTL is not set
378# CONFIG_RFD_FTL is not set
379# CONFIG_SSFDC is not set
380# CONFIG_MTD_OOPS is not set
381
382#
383# RAM/ROM/Flash chip drivers
384#
385CONFIG_MTD_CFI=y
386# CONFIG_MTD_JEDECPROBE is not set
387CONFIG_MTD_GEN_PROBE=y
388# CONFIG_MTD_CFI_ADV_OPTIONS is not set
389CONFIG_MTD_MAP_BANK_WIDTH_1=y
390CONFIG_MTD_MAP_BANK_WIDTH_2=y
391CONFIG_MTD_MAP_BANK_WIDTH_4=y
392# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
393# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
394# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
395CONFIG_MTD_CFI_I1=y
396CONFIG_MTD_CFI_I2=y
397# CONFIG_MTD_CFI_I4 is not set
398# CONFIG_MTD_CFI_I8 is not set
399CONFIG_MTD_CFI_INTELEXT=y
400# CONFIG_MTD_CFI_AMDSTD is not set
401# CONFIG_MTD_CFI_STAA is not set
402CONFIG_MTD_CFI_UTIL=y
403# CONFIG_MTD_RAM is not set
404# CONFIG_MTD_ROM is not set
405# CONFIG_MTD_ABSENT is not set
406
407#
408# Mapping drivers for chip access
409#
410# CONFIG_MTD_COMPLEX_MAPPINGS is not set
411CONFIG_MTD_PHYSMAP=y
412CONFIG_MTD_PHYSMAP_START=0x0
413CONFIG_MTD_PHYSMAP_LEN=0x0
414CONFIG_MTD_PHYSMAP_BANKWIDTH=1
415# CONFIG_MTD_PHYSMAP_OF is not set
416# CONFIG_MTD_INTEL_VR_NOR is not set
417# CONFIG_MTD_PLATRAM is not set
418
419#
420# Self-contained MTD device drivers
421#
422# CONFIG_MTD_PMC551 is not set
423# CONFIG_MTD_SLRAM is not set
424# CONFIG_MTD_PHRAM is not set
425# CONFIG_MTD_MTDRAM is not set
426# CONFIG_MTD_BLOCK2MTD is not set
427
428#
429# Disk-On-Chip Device Drivers
430#
431# CONFIG_MTD_DOC2000 is not set
432# CONFIG_MTD_DOC2001 is not set
433# CONFIG_MTD_DOC2001PLUS is not set
434# CONFIG_MTD_NAND is not set
435# CONFIG_MTD_ONENAND is not set
436
437#
438# UBI - Unsorted block images
439#
440# CONFIG_MTD_UBI is not set
441CONFIG_OF_DEVICE=y
442CONFIG_OF_I2C=y
443# CONFIG_PARPORT is not set
444# CONFIG_BLK_DEV is not set
445# CONFIG_MISC_DEVICES is not set
446CONFIG_HAVE_IDE=y
447# CONFIG_IDE is not set
448
449#
450# SCSI device support
451#
452# CONFIG_RAID_ATTRS is not set
453CONFIG_SCSI=m
454CONFIG_SCSI_DMA=y
455# CONFIG_SCSI_TGT is not set
456# CONFIG_SCSI_NETLINK is not set
457# CONFIG_SCSI_PROC_FS is not set
458
459#
460# SCSI support type (disk, tape, CD-ROM)
461#
462CONFIG_BLK_DEV_SD=m
463# CONFIG_CHR_DEV_ST is not set
464# CONFIG_CHR_DEV_OSST is not set
465# CONFIG_BLK_DEV_SR is not set
466# CONFIG_CHR_DEV_SG is not set
467# CONFIG_CHR_DEV_SCH is not set
468
469#
470# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
471#
472# CONFIG_SCSI_MULTI_LUN is not set
473# CONFIG_SCSI_CONSTANTS is not set
474# CONFIG_SCSI_LOGGING is not set
475# CONFIG_SCSI_SCAN_ASYNC is not set
476CONFIG_SCSI_WAIT_SCAN=m
477
478#
479# SCSI Transports
480#
481# CONFIG_SCSI_SPI_ATTRS is not set
482# CONFIG_SCSI_FC_ATTRS is not set
483# CONFIG_SCSI_ISCSI_ATTRS is not set
484# CONFIG_SCSI_SAS_LIBSAS is not set
485# CONFIG_SCSI_SRP_ATTRS is not set
486# CONFIG_SCSI_LOWLEVEL is not set
487CONFIG_ATA=m
488# CONFIG_ATA_NONSTANDARD is not set
489CONFIG_SATA_PMP=y
490# CONFIG_SATA_AHCI is not set
491# CONFIG_SATA_SIL24 is not set
492# CONFIG_SATA_FSL is not set
493CONFIG_ATA_SFF=y
494# CONFIG_SATA_SVW is not set
495# CONFIG_ATA_PIIX is not set
496# CONFIG_SATA_MV is not set
497# CONFIG_SATA_NV is not set
498# CONFIG_PDC_ADMA is not set
499# CONFIG_SATA_QSTOR is not set
500# CONFIG_SATA_PROMISE is not set
501# CONFIG_SATA_SX4 is not set
502# CONFIG_SATA_SIL is not set
503# CONFIG_SATA_SIS is not set
504# CONFIG_SATA_ULI is not set
505# CONFIG_SATA_VIA is not set
506# CONFIG_SATA_VITESSE is not set
507# CONFIG_SATA_INIC162X is not set
508# CONFIG_PATA_ALI is not set
509# CONFIG_PATA_AMD is not set
510# CONFIG_PATA_ARTOP is not set
511# CONFIG_PATA_ATIIXP is not set
512# CONFIG_PATA_CMD640_PCI is not set
513# CONFIG_PATA_CMD64X is not set
514# CONFIG_PATA_CS5520 is not set
515# CONFIG_PATA_CS5530 is not set
516# CONFIG_PATA_CYPRESS is not set
517# CONFIG_PATA_EFAR is not set
518# CONFIG_ATA_GENERIC is not set
519# CONFIG_PATA_HPT366 is not set
520# CONFIG_PATA_HPT37X is not set
521# CONFIG_PATA_HPT3X2N is not set
522# CONFIG_PATA_HPT3X3 is not set
523# CONFIG_PATA_IT821X is not set
524# CONFIG_PATA_IT8213 is not set
525# CONFIG_PATA_JMICRON is not set
526# CONFIG_PATA_TRIFLEX is not set
527# CONFIG_PATA_MARVELL is not set
528CONFIG_PATA_MPC52xx=m
529# CONFIG_PATA_MPIIX is not set
530# CONFIG_PATA_OLDPIIX is not set
531# CONFIG_PATA_NETCELL is not set
532# CONFIG_PATA_NINJA32 is not set
533# CONFIG_PATA_NS87410 is not set
534# CONFIG_PATA_NS87415 is not set
535# CONFIG_PATA_OPTI is not set
536# CONFIG_PATA_OPTIDMA is not set
537# CONFIG_PATA_PDC_OLD is not set
538# CONFIG_PATA_RADISYS is not set
539# CONFIG_PATA_RZ1000 is not set
540# CONFIG_PATA_SC1200 is not set
541# CONFIG_PATA_SERVERWORKS is not set
542# CONFIG_PATA_PDC2027X is not set
543# CONFIG_PATA_SIL680 is not set
544# CONFIG_PATA_SIS is not set
545# CONFIG_PATA_VIA is not set
546# CONFIG_PATA_WINBOND is not set
547# CONFIG_PATA_PLATFORM is not set
548# CONFIG_MD is not set
549# CONFIG_FUSION is not set
550
551#
552# IEEE 1394 (FireWire) support
553#
554# CONFIG_FIREWIRE is not set
555# CONFIG_IEEE1394 is not set
556# CONFIG_I2O is not set
557# CONFIG_MACINTOSH_DRIVERS is not set
558CONFIG_NETDEVICES=y
559# CONFIG_NETDEVICES_MULTIQUEUE is not set
560# CONFIG_DUMMY is not set
561# CONFIG_BONDING is not set
562# CONFIG_MACVLAN is not set
563# CONFIG_EQUALIZER is not set
564# CONFIG_TUN is not set
565# CONFIG_VETH is not set
566# CONFIG_ARCNET is not set
567CONFIG_PHYLIB=y
568
569#
570# MII PHY device drivers
571#
572# CONFIG_MARVELL_PHY is not set
573# CONFIG_DAVICOM_PHY is not set
574# CONFIG_QSEMI_PHY is not set
575# CONFIG_LXT_PHY is not set
576# CONFIG_CICADA_PHY is not set
577# CONFIG_VITESSE_PHY is not set
578# CONFIG_SMSC_PHY is not set
579# CONFIG_BROADCOM_PHY is not set
580# CONFIG_ICPLUS_PHY is not set
581# CONFIG_REALTEK_PHY is not set
582# CONFIG_FIXED_PHY is not set
583# CONFIG_MDIO_BITBANG is not set
584CONFIG_NET_ETHERNET=y
585CONFIG_MII=y
586# CONFIG_HAPPYMEAL is not set
587# CONFIG_SUNGEM is not set
588# CONFIG_CASSINI is not set
589# CONFIG_NET_VENDOR_3COM is not set
590# CONFIG_NET_TULIP is not set
591# CONFIG_HP100 is not set
592# CONFIG_IBM_NEW_EMAC_ZMII is not set
593# CONFIG_IBM_NEW_EMAC_RGMII is not set
594# CONFIG_IBM_NEW_EMAC_TAH is not set
595# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
596# CONFIG_NET_PCI is not set
597# CONFIG_B44 is not set
598CONFIG_FEC_MPC52xx=y
599CONFIG_FEC_MPC52xx_MDIO=y
600# CONFIG_NETDEV_1000 is not set
601# CONFIG_NETDEV_10000 is not set
602# CONFIG_TR is not set
603
604#
605# Wireless LAN
606#
607# CONFIG_WLAN_PRE80211 is not set
608# CONFIG_WLAN_80211 is not set
609# CONFIG_IWLWIFI is not set
610# CONFIG_IWLWIFI_LEDS is not set
611
612#
613# USB Network Adapters
614#
615# CONFIG_USB_CATC is not set
616# CONFIG_USB_KAWETH is not set
617# CONFIG_USB_PEGASUS is not set
618# CONFIG_USB_RTL8150 is not set
619# CONFIG_USB_USBNET is not set
620# CONFIG_WAN is not set
621# CONFIG_FDDI is not set
622# CONFIG_HIPPI is not set
623# CONFIG_PPP is not set
624# CONFIG_SLIP is not set
625# CONFIG_NET_FC is not set
626# CONFIG_NETCONSOLE is not set
627# CONFIG_NETPOLL is not set
628# CONFIG_NET_POLL_CONTROLLER is not set
629# CONFIG_ISDN is not set
630# CONFIG_PHONE is not set
631
632#
633# Input device support
634#
635# CONFIG_INPUT is not set
636
637#
638# Hardware I/O ports
639#
640# CONFIG_SERIO is not set
641# CONFIG_GAMEPORT is not set
642
643#
644# Character devices
645#
646# CONFIG_VT is not set
647# CONFIG_SERIAL_NONSTANDARD is not set
648# CONFIG_NOZOMI is not set
649
650#
651# Serial drivers
652#
653# CONFIG_SERIAL_8250 is not set
654
655#
656# Non-8250 serial port support
657#
658# CONFIG_SERIAL_UARTLITE is not set
659CONFIG_SERIAL_CORE=y
660CONFIG_SERIAL_CORE_CONSOLE=y
661CONFIG_SERIAL_MPC52xx=y
662CONFIG_SERIAL_MPC52xx_CONSOLE=y
663CONFIG_SERIAL_MPC52xx_CONSOLE_BAUD=9600
664# CONFIG_SERIAL_JSM is not set
665CONFIG_UNIX98_PTYS=y
666# CONFIG_LEGACY_PTYS is not set
667# CONFIG_IPMI_HANDLER is not set
668CONFIG_HW_RANDOM=y
669# CONFIG_NVRAM is not set
670# CONFIG_R3964 is not set
671# CONFIG_APPLICOM is not set
672# CONFIG_RAW_DRIVER is not set
673# CONFIG_TCG_TPM is not set
674CONFIG_DEVPORT=y
675CONFIG_I2C=y
676CONFIG_I2C_BOARDINFO=y
677CONFIG_I2C_CHARDEV=y
678
679#
680# I2C Hardware Bus support
681#
682# CONFIG_I2C_ALI1535 is not set
683# CONFIG_I2C_ALI1563 is not set
684# CONFIG_I2C_ALI15X3 is not set
685# CONFIG_I2C_AMD756 is not set
686# CONFIG_I2C_AMD8111 is not set
687# CONFIG_I2C_I801 is not set
688# CONFIG_I2C_I810 is not set
689# CONFIG_I2C_PIIX4 is not set
690CONFIG_I2C_MPC=y
691# CONFIG_I2C_NFORCE2 is not set
692# CONFIG_I2C_OCORES is not set
693# CONFIG_I2C_PARPORT_LIGHT is not set
694# CONFIG_I2C_PROSAVAGE is not set
695# CONFIG_I2C_SAVAGE4 is not set
696# CONFIG_I2C_SIMTEC is not set
697# CONFIG_I2C_SIS5595 is not set
698# CONFIG_I2C_SIS630 is not set
699# CONFIG_I2C_SIS96X is not set
700# CONFIG_I2C_TAOS_EVM is not set
701# CONFIG_I2C_STUB is not set
702# CONFIG_I2C_TINY_USB is not set
703# CONFIG_I2C_VIA is not set
704# CONFIG_I2C_VIAPRO is not set
705# CONFIG_I2C_VOODOO3 is not set
706# CONFIG_I2C_PCA_PLATFORM is not set
707
708#
709# Miscellaneous I2C Chip support
710#
711# CONFIG_DS1682 is not set
712CONFIG_SENSORS_EEPROM=m
713# CONFIG_SENSORS_PCF8574 is not set
714# CONFIG_PCF8575 is not set
715# CONFIG_SENSORS_PCF8591 is not set
716# CONFIG_SENSORS_MAX6875 is not set
717# CONFIG_SENSORS_TSL2550 is not set
718# CONFIG_I2C_DEBUG_CORE is not set
719# CONFIG_I2C_DEBUG_ALGO is not set
720# CONFIG_I2C_DEBUG_BUS is not set
721# CONFIG_I2C_DEBUG_CHIP is not set
722# CONFIG_SPI is not set
723# CONFIG_W1 is not set
724# CONFIG_POWER_SUPPLY is not set
725# CONFIG_HWMON is not set
726# CONFIG_THERMAL is not set
727# CONFIG_WATCHDOG is not set
728
729#
730# Sonics Silicon Backplane
731#
732CONFIG_SSB_POSSIBLE=y
733# CONFIG_SSB is not set
734
735#
736# Multifunction device drivers
737#
738# CONFIG_MFD_SM501 is not set
739# CONFIG_HTC_PASIC3 is not set
740
741#
742# Multimedia devices
743#
744# CONFIG_VIDEO_DEV is not set
745# CONFIG_DVB_CORE is not set
746# CONFIG_DAB is not set
747
748#
749# Graphics support
750#
751# CONFIG_AGP is not set
752# CONFIG_DRM is not set
753# CONFIG_VGASTATE is not set
754# CONFIG_VIDEO_OUTPUT_CONTROL is not set
755# CONFIG_FB is not set
756# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
757
758#
759# Display device support
760#
761# CONFIG_DISPLAY_SUPPORT is not set
762
763#
764# Sound
765#
766# CONFIG_SOUND is not set
767CONFIG_USB_SUPPORT=y
768CONFIG_USB_ARCH_HAS_HCD=y
769CONFIG_USB_ARCH_HAS_OHCI=y
770CONFIG_USB_ARCH_HAS_EHCI=y
771CONFIG_USB=y
772# CONFIG_USB_DEBUG is not set
773# CONFIG_USB_ANNOUNCE_NEW_DEVICES is not set
774
775#
776# Miscellaneous USB options
777#
778CONFIG_USB_DEVICEFS=y
779# CONFIG_USB_DEVICE_CLASS is not set
780# CONFIG_USB_DYNAMIC_MINORS is not set
781# CONFIG_USB_OTG is not set
782# CONFIG_USB_OTG_WHITELIST is not set
783# CONFIG_USB_OTG_BLACKLIST_HUB is not set
784
785#
786# USB Host Controller Drivers
787#
788# CONFIG_USB_EHCI_HCD is not set
789# CONFIG_USB_ISP116X_HCD is not set
790CONFIG_USB_OHCI_HCD=m
791# CONFIG_USB_OHCI_HCD_PPC_SOC is not set
792CONFIG_USB_OHCI_HCD_PPC_OF=y
793CONFIG_USB_OHCI_HCD_PPC_OF_BE=y
794# CONFIG_USB_OHCI_HCD_PPC_OF_LE is not set
795# CONFIG_USB_OHCI_HCD_PCI is not set
796CONFIG_USB_OHCI_BIG_ENDIAN_DESC=y
797CONFIG_USB_OHCI_BIG_ENDIAN_MMIO=y
798# CONFIG_USB_OHCI_LITTLE_ENDIAN is not set
799# CONFIG_USB_UHCI_HCD is not set
800# CONFIG_USB_SL811_HCD is not set
801# CONFIG_USB_R8A66597_HCD is not set
802
803#
804# USB Device Class drivers
805#
806# CONFIG_USB_ACM is not set
807# CONFIG_USB_PRINTER is not set
808
809#
810# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
811#
812
813#
814# may also be needed; see USB_STORAGE Help for more information
815#
816CONFIG_USB_STORAGE=m
817# CONFIG_USB_STORAGE_DEBUG is not set
818# CONFIG_USB_STORAGE_DATAFAB is not set
819# CONFIG_USB_STORAGE_FREECOM is not set
820# CONFIG_USB_STORAGE_ISD200 is not set
821# CONFIG_USB_STORAGE_DPCM is not set
822# CONFIG_USB_STORAGE_USBAT is not set
823# CONFIG_USB_STORAGE_SDDR09 is not set
824# CONFIG_USB_STORAGE_SDDR55 is not set
825# CONFIG_USB_STORAGE_JUMPSHOT is not set
826# CONFIG_USB_STORAGE_ALAUDA is not set
827# CONFIG_USB_STORAGE_KARMA is not set
828# CONFIG_USB_STORAGE_CYPRESS_ATACB is not set
829# CONFIG_USB_LIBUSUAL is not set
830
831#
832# USB Imaging devices
833#
834# CONFIG_USB_MDC800 is not set
835# CONFIG_USB_MICROTEK is not set
836# CONFIG_USB_MON is not set
837
838#
839# USB port drivers
840#
841# CONFIG_USB_SERIAL is not set
842
843#
844# USB Miscellaneous drivers
845#
846# CONFIG_USB_EMI62 is not set
847# CONFIG_USB_EMI26 is not set
848# CONFIG_USB_ADUTUX is not set
849# CONFIG_USB_AUERSWALD is not set
850# CONFIG_USB_RIO500 is not set
851# CONFIG_USB_LEGOTOWER is not set
852# CONFIG_USB_LCD is not set
853# CONFIG_USB_BERRY_CHARGE is not set
854# CONFIG_USB_LED is not set
855# CONFIG_USB_CYPRESS_CY7C63 is not set
856# CONFIG_USB_CYTHERM is not set
857# CONFIG_USB_PHIDGET is not set
858# CONFIG_USB_IDMOUSE is not set
859# CONFIG_USB_FTDI_ELAN is not set
860# CONFIG_USB_APPLEDISPLAY is not set
861# CONFIG_USB_LD is not set
862# CONFIG_USB_TRANCEVIBRATOR is not set
863# CONFIG_USB_IOWARRIOR is not set
864# CONFIG_USB_TEST is not set
865# CONFIG_USB_GADGET is not set
866# CONFIG_MMC is not set
867# CONFIG_MEMSTICK is not set
868# CONFIG_NEW_LEDS is not set
869# CONFIG_INFINIBAND is not set
870# CONFIG_EDAC is not set
871CONFIG_RTC_LIB=m
872CONFIG_RTC_CLASS=m
873
874#
875# RTC interfaces
876#
877CONFIG_RTC_INTF_SYSFS=y
878CONFIG_RTC_INTF_PROC=y
879CONFIG_RTC_INTF_DEV=y
880# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
881# CONFIG_RTC_DRV_TEST is not set
882
883#
884# I2C RTC drivers
885#
886# CONFIG_RTC_DRV_DS1307 is not set
887# CONFIG_RTC_DRV_DS1374 is not set
888# CONFIG_RTC_DRV_DS1672 is not set
889# CONFIG_RTC_DRV_MAX6900 is not set
890# CONFIG_RTC_DRV_RS5C372 is not set
891# CONFIG_RTC_DRV_ISL1208 is not set
892# CONFIG_RTC_DRV_X1205 is not set
893CONFIG_RTC_DRV_PCF8563=m
894# CONFIG_RTC_DRV_PCF8583 is not set
895# CONFIG_RTC_DRV_M41T80 is not set
896# CONFIG_RTC_DRV_S35390A is not set
897
898#
899# SPI RTC drivers
900#
901
902#
903# Platform RTC drivers
904#
905# CONFIG_RTC_DRV_CMOS is not set
906# CONFIG_RTC_DRV_DS1511 is not set
907# CONFIG_RTC_DRV_DS1553 is not set
908# CONFIG_RTC_DRV_DS1742 is not set
909# CONFIG_RTC_DRV_STK17TA8 is not set
910# CONFIG_RTC_DRV_M48T86 is not set
911# CONFIG_RTC_DRV_M48T59 is not set
912# CONFIG_RTC_DRV_V3020 is not set
913
914#
915# on-CPU RTC drivers
916#
917# CONFIG_DMADEVICES is not set
918# CONFIG_UIO is not set
919
920#
921# File systems
922#
923CONFIG_EXT2_FS=m
924# CONFIG_EXT2_FS_XATTR is not set
925# CONFIG_EXT2_FS_XIP is not set
926CONFIG_EXT3_FS=m
927CONFIG_EXT3_FS_XATTR=y
928# CONFIG_EXT3_FS_POSIX_ACL is not set
929# CONFIG_EXT3_FS_SECURITY is not set
930# CONFIG_EXT4DEV_FS is not set
931CONFIG_JBD=m
932CONFIG_FS_MBCACHE=m
933# CONFIG_REISERFS_FS is not set
934# CONFIG_JFS_FS is not set
935# CONFIG_FS_POSIX_ACL is not set
936# CONFIG_XFS_FS is not set
937# CONFIG_OCFS2_FS is not set
938# CONFIG_DNOTIFY is not set
939# CONFIG_INOTIFY is not set
940# CONFIG_QUOTA is not set
941# CONFIG_AUTOFS_FS is not set
942# CONFIG_AUTOFS4_FS is not set
943# CONFIG_FUSE_FS is not set
944
945#
946# CD-ROM/DVD Filesystems
947#
948# CONFIG_ISO9660_FS is not set
949# CONFIG_UDF_FS is not set
950
951#
952# DOS/FAT/NT Filesystems
953#
954CONFIG_FAT_FS=m
955# CONFIG_MSDOS_FS is not set
956CONFIG_VFAT_FS=m
957CONFIG_FAT_DEFAULT_CODEPAGE=850
958CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
959# CONFIG_NTFS_FS is not set
960
961#
962# Pseudo filesystems
963#
964CONFIG_PROC_FS=y
965# CONFIG_PROC_KCORE is not set
966CONFIG_PROC_SYSCTL=y
967CONFIG_SYSFS=y
968CONFIG_TMPFS=y
969# CONFIG_TMPFS_POSIX_ACL is not set
970# CONFIG_HUGETLB_PAGE is not set
971# CONFIG_CONFIGFS_FS is not set
972
973#
974# Miscellaneous filesystems
975#
976# CONFIG_ADFS_FS is not set
977# CONFIG_AFFS_FS is not set
978# CONFIG_HFS_FS is not set
979# CONFIG_HFSPLUS_FS is not set
980# CONFIG_BEFS_FS is not set
981# CONFIG_BFS_FS is not set
982# CONFIG_EFS_FS is not set
983CONFIG_JFFS2_FS=y
984CONFIG_JFFS2_FS_DEBUG=0
985CONFIG_JFFS2_FS_WRITEBUFFER=y
986# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
987# CONFIG_JFFS2_SUMMARY is not set
988# CONFIG_JFFS2_FS_XATTR is not set
989# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
990CONFIG_JFFS2_ZLIB=y
991# CONFIG_JFFS2_LZO is not set
992CONFIG_JFFS2_RTIME=y
993# CONFIG_JFFS2_RUBIN is not set
994# CONFIG_CRAMFS is not set
995# CONFIG_VXFS_FS is not set
996# CONFIG_MINIX_FS is not set
997# CONFIG_HPFS_FS is not set
998# CONFIG_QNX4FS_FS is not set
999# CONFIG_ROMFS_FS is not set
1000# CONFIG_SYSV_FS is not set
1001# CONFIG_UFS_FS is not set
1002CONFIG_NETWORK_FILESYSTEMS=y
1003CONFIG_NFS_FS=y
1004CONFIG_NFS_V3=y
1005# CONFIG_NFS_V3_ACL is not set
1006# CONFIG_NFS_V4 is not set
1007# CONFIG_NFSD is not set
1008CONFIG_ROOT_NFS=y
1009CONFIG_LOCKD=y
1010CONFIG_LOCKD_V4=y
1011CONFIG_NFS_COMMON=y
1012CONFIG_SUNRPC=y
1013# CONFIG_SUNRPC_BIND34 is not set
1014# CONFIG_RPCSEC_GSS_KRB5 is not set
1015# CONFIG_RPCSEC_GSS_SPKM3 is not set
1016# CONFIG_SMB_FS is not set
1017# CONFIG_CIFS is not set
1018# CONFIG_NCP_FS is not set
1019# CONFIG_CODA_FS is not set
1020# CONFIG_AFS_FS is not set
1021
1022#
1023# Partition Types
1024#
1025# CONFIG_PARTITION_ADVANCED is not set
1026CONFIG_MSDOS_PARTITION=y
1027CONFIG_NLS=y
1028CONFIG_NLS_DEFAULT="iso8859-1"
1029# CONFIG_NLS_CODEPAGE_437 is not set
1030# CONFIG_NLS_CODEPAGE_737 is not set
1031# CONFIG_NLS_CODEPAGE_775 is not set
1032CONFIG_NLS_CODEPAGE_850=y
1033# CONFIG_NLS_CODEPAGE_852 is not set
1034# CONFIG_NLS_CODEPAGE_855 is not set
1035# CONFIG_NLS_CODEPAGE_857 is not set
1036# CONFIG_NLS_CODEPAGE_860 is not set
1037# CONFIG_NLS_CODEPAGE_861 is not set
1038# CONFIG_NLS_CODEPAGE_862 is not set
1039# CONFIG_NLS_CODEPAGE_863 is not set
1040# CONFIG_NLS_CODEPAGE_864 is not set
1041# CONFIG_NLS_CODEPAGE_865 is not set
1042# CONFIG_NLS_CODEPAGE_866 is not set
1043# CONFIG_NLS_CODEPAGE_869 is not set
1044# CONFIG_NLS_CODEPAGE_936 is not set
1045# CONFIG_NLS_CODEPAGE_950 is not set
1046# CONFIG_NLS_CODEPAGE_932 is not set
1047# CONFIG_NLS_CODEPAGE_949 is not set
1048# CONFIG_NLS_CODEPAGE_874 is not set
1049# CONFIG_NLS_ISO8859_8 is not set
1050# CONFIG_NLS_CODEPAGE_1250 is not set
1051# CONFIG_NLS_CODEPAGE_1251 is not set
1052# CONFIG_NLS_ASCII is not set
1053CONFIG_NLS_ISO8859_1=y
1054# CONFIG_NLS_ISO8859_2 is not set
1055# CONFIG_NLS_ISO8859_3 is not set
1056# CONFIG_NLS_ISO8859_4 is not set
1057# CONFIG_NLS_ISO8859_5 is not set
1058# CONFIG_NLS_ISO8859_6 is not set
1059# CONFIG_NLS_ISO8859_7 is not set
1060# CONFIG_NLS_ISO8859_9 is not set
1061# CONFIG_NLS_ISO8859_13 is not set
1062# CONFIG_NLS_ISO8859_14 is not set
1063# CONFIG_NLS_ISO8859_15 is not set
1064# CONFIG_NLS_KOI8_R is not set
1065# CONFIG_NLS_KOI8_U is not set
1066# CONFIG_NLS_UTF8 is not set
1067# CONFIG_DLM is not set
1068
1069#
1070# Library routines
1071#
1072CONFIG_BITREVERSE=y
1073# CONFIG_GENERIC_FIND_FIRST_BIT is not set
1074# CONFIG_CRC_CCITT is not set
1075# CONFIG_CRC16 is not set
1076# CONFIG_CRC_ITU_T is not set
1077CONFIG_CRC32=y
1078# CONFIG_CRC7 is not set
1079# CONFIG_LIBCRC32C is not set
1080CONFIG_ZLIB_INFLATE=y
1081CONFIG_ZLIB_DEFLATE=y
1082CONFIG_PLIST=y
1083CONFIG_HAS_IOMEM=y
1084CONFIG_HAS_IOPORT=y
1085CONFIG_HAS_DMA=y
1086CONFIG_HAVE_LMB=y
1087
1088#
1089# Kernel hacking
1090#
1091# CONFIG_PRINTK_TIME is not set
1092CONFIG_ENABLE_WARN_DEPRECATED=y
1093CONFIG_ENABLE_MUST_CHECK=y
1094CONFIG_FRAME_WARN=1024
1095# CONFIG_MAGIC_SYSRQ is not set
1096# CONFIG_UNUSED_SYMBOLS is not set
1097# CONFIG_DEBUG_FS is not set
1098# CONFIG_HEADERS_CHECK is not set
1099# CONFIG_DEBUG_KERNEL is not set
1100# CONFIG_DEBUG_BUGVERBOSE is not set
1101# CONFIG_SAMPLES is not set
1102# CONFIG_IRQSTACKS is not set
1103# CONFIG_BOOTX_TEXT is not set
1104# CONFIG_PPC_EARLY_DEBUG is not set
1105
1106#
1107# Security options
1108#
1109# CONFIG_KEYS is not set
1110# CONFIG_SECURITY is not set
1111# CONFIG_SECURITY_FILE_CAPABILITIES is not set
1112# CONFIG_CRYPTO is not set
1113CONFIG_PPC_CLOCK=y
1114CONFIG_PPC_LIB_RHEAP=y
1115# CONFIG_VIRTUALIZATION is not set
diff --git a/arch/powerpc/configs/52xx/tqm5200_defconfig b/arch/powerpc/configs/52xx/tqm5200_defconfig
new file mode 100644
index 000000000000..7672bfba3566
--- /dev/null
+++ b/arch/powerpc/configs/52xx/tqm5200_defconfig
@@ -0,0 +1,1214 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.25
4# Tue Apr 29 07:12:39 2008
5#
6# CONFIG_PPC64 is not set
7
8#
9# Processor support
10#
11CONFIG_6xx=y
12# CONFIG_PPC_85xx is not set
13# CONFIG_PPC_8xx is not set
14# CONFIG_40x is not set
15# CONFIG_44x is not set
16# CONFIG_E200 is not set
17CONFIG_PPC_FPU=y
18# CONFIG_ALTIVEC is not set
19CONFIG_PPC_STD_MMU=y
20CONFIG_PPC_STD_MMU_32=y
21# CONFIG_PPC_MM_SLICES is not set
22# CONFIG_SMP is not set
23CONFIG_PPC32=y
24CONFIG_WORD_SIZE=32
25CONFIG_PPC_MERGE=y
26CONFIG_MMU=y
27CONFIG_GENERIC_CMOS_UPDATE=y
28CONFIG_GENERIC_TIME=y
29CONFIG_GENERIC_TIME_VSYSCALL=y
30CONFIG_GENERIC_CLOCKEVENTS=y
31CONFIG_GENERIC_HARDIRQS=y
32# CONFIG_HAVE_SETUP_PER_CPU_AREA is not set
33CONFIG_IRQ_PER_CPU=y
34CONFIG_STACKTRACE_SUPPORT=y
35CONFIG_LOCKDEP_SUPPORT=y
36CONFIG_RWSEM_XCHGADD_ALGORITHM=y
37CONFIG_ARCH_HAS_ILOG2_U32=y
38CONFIG_GENERIC_HWEIGHT=y
39CONFIG_GENERIC_CALIBRATE_DELAY=y
40CONFIG_GENERIC_FIND_NEXT_BIT=y
41# CONFIG_ARCH_NO_VIRT_TO_BUS is not set
42CONFIG_PPC=y
43CONFIG_EARLY_PRINTK=y
44CONFIG_GENERIC_NVRAM=y
45CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
46CONFIG_ARCH_MAY_HAVE_PC_FDC=y
47CONFIG_PPC_OF=y
48CONFIG_OF=y
49# CONFIG_PPC_UDBG_16550 is not set
50# CONFIG_GENERIC_TBSYNC is not set
51CONFIG_AUDIT_ARCH=y
52CONFIG_GENERIC_BUG=y
53CONFIG_DEFAULT_UIMAGE=y
54# CONFIG_PPC_DCR_NATIVE is not set
55# CONFIG_PPC_DCR_MMIO is not set
56CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
57
58#
59# General setup
60#
61CONFIG_EXPERIMENTAL=y
62CONFIG_BROKEN_ON_SMP=y
63CONFIG_INIT_ENV_ARG_LIMIT=32
64CONFIG_LOCALVERSION=""
65CONFIG_LOCALVERSION_AUTO=y
66CONFIG_SWAP=y
67CONFIG_SYSVIPC=y
68CONFIG_SYSVIPC_SYSCTL=y
69# CONFIG_POSIX_MQUEUE is not set
70# CONFIG_BSD_PROCESS_ACCT is not set
71# CONFIG_TASKSTATS is not set
72# CONFIG_AUDIT is not set
73# CONFIG_IKCONFIG is not set
74CONFIG_LOG_BUF_SHIFT=14
75# CONFIG_CGROUPS is not set
76CONFIG_GROUP_SCHED=y
77CONFIG_FAIR_GROUP_SCHED=y
78# CONFIG_RT_GROUP_SCHED is not set
79CONFIG_USER_SCHED=y
80# CONFIG_CGROUP_SCHED is not set
81CONFIG_SYSFS_DEPRECATED=y
82CONFIG_SYSFS_DEPRECATED_V2=y
83# CONFIG_RELAY is not set
84# CONFIG_NAMESPACES is not set
85CONFIG_BLK_DEV_INITRD=y
86CONFIG_INITRAMFS_SOURCE=""
87# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
88CONFIG_SYSCTL=y
89CONFIG_EMBEDDED=y
90# CONFIG_SYSCTL_SYSCALL is not set
91# CONFIG_KALLSYMS is not set
92CONFIG_HOTPLUG=y
93CONFIG_PRINTK=y
94CONFIG_BUG=y
95CONFIG_ELF_CORE=y
96CONFIG_COMPAT_BRK=y
97CONFIG_BASE_FULL=y
98CONFIG_FUTEX=y
99CONFIG_ANON_INODES=y
100# CONFIG_EPOLL is not set
101CONFIG_SIGNALFD=y
102CONFIG_TIMERFD=y
103CONFIG_EVENTFD=y
104CONFIG_SHMEM=y
105CONFIG_VM_EVENT_COUNTERS=y
106CONFIG_SLUB_DEBUG=y
107# CONFIG_SLAB is not set
108CONFIG_SLUB=y
109# CONFIG_SLOB is not set
110# CONFIG_PROFILING is not set
111# CONFIG_MARKERS is not set
112CONFIG_HAVE_OPROFILE=y
113CONFIG_HAVE_KPROBES=y
114CONFIG_HAVE_KRETPROBES=y
115CONFIG_PROC_PAGE_MONITOR=y
116CONFIG_SLABINFO=y
117CONFIG_RT_MUTEXES=y
118# CONFIG_TINY_SHMEM is not set
119CONFIG_BASE_SMALL=0
120CONFIG_MODULES=y
121CONFIG_MODULE_UNLOAD=y
122# CONFIG_MODULE_FORCE_UNLOAD is not set
123CONFIG_MODVERSIONS=y
124# CONFIG_MODULE_SRCVERSION_ALL is not set
125CONFIG_KMOD=y
126CONFIG_BLOCK=y
127# CONFIG_LBD is not set
128# CONFIG_BLK_DEV_IO_TRACE is not set
129# CONFIG_LSF is not set
130# CONFIG_BLK_DEV_BSG is not set
131
132#
133# IO Schedulers
134#
135CONFIG_IOSCHED_NOOP=y
136CONFIG_IOSCHED_AS=y
137CONFIG_IOSCHED_DEADLINE=y
138CONFIG_IOSCHED_CFQ=y
139CONFIG_DEFAULT_AS=y
140# CONFIG_DEFAULT_DEADLINE is not set
141# CONFIG_DEFAULT_CFQ is not set
142# CONFIG_DEFAULT_NOOP is not set
143CONFIG_DEFAULT_IOSCHED="anticipatory"
144CONFIG_CLASSIC_RCU=y
145
146#
147# Platform support
148#
149CONFIG_PPC_MULTIPLATFORM=y
150# CONFIG_PPC_82xx is not set
151# CONFIG_PPC_83xx is not set
152# CONFIG_PPC_86xx is not set
153CONFIG_CLASSIC32=y
154# CONFIG_PPC_CHRP is not set
155# CONFIG_PPC_MPC512x is not set
156# CONFIG_PPC_MPC5121 is not set
157# CONFIG_MPC5121_ADS is not set
158CONFIG_PPC_MPC52xx=y
159CONFIG_PPC_MPC5200_SIMPLE=y
160# CONFIG_PPC_EFIKA is not set
161# CONFIG_PPC_LITE5200 is not set
162CONFIG_PPC_MPC5200_BUGFIX=y
163# CONFIG_PPC_MPC5200_GPIO is not set
164# CONFIG_PPC_PMAC is not set
165# CONFIG_PPC_CELL is not set
166# CONFIG_PPC_CELL_NATIVE is not set
167# CONFIG_PQ2ADS is not set
168# CONFIG_EMBEDDED6xx is not set
169# CONFIG_IPIC is not set
170# CONFIG_MPIC is not set
171# CONFIG_MPIC_WEIRD is not set
172# CONFIG_PPC_I8259 is not set
173# CONFIG_PPC_RTAS is not set
174# CONFIG_MMIO_NVRAM is not set
175# CONFIG_PPC_MPC106 is not set
176# CONFIG_PPC_970_NAP is not set
177# CONFIG_PPC_INDIRECT_IO is not set
178# CONFIG_GENERIC_IOMAP is not set
179# CONFIG_CPU_FREQ is not set
180# CONFIG_TAU is not set
181# CONFIG_FSL_ULI1575 is not set
182CONFIG_PPC_BESTCOMM=y
183# CONFIG_PPC_BESTCOMM_ATA is not set
184CONFIG_PPC_BESTCOMM_FEC=y
185# CONFIG_PPC_BESTCOMM_GEN_BD is not set
186
187#
188# Kernel options
189#
190# CONFIG_HIGHMEM is not set
191# CONFIG_TICK_ONESHOT is not set
192# CONFIG_NO_HZ is not set
193# CONFIG_HIGH_RES_TIMERS is not set
194CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
195# CONFIG_HZ_100 is not set
196CONFIG_HZ_250=y
197# CONFIG_HZ_300 is not set
198# CONFIG_HZ_1000 is not set
199CONFIG_HZ=250
200# CONFIG_SCHED_HRTICK is not set
201CONFIG_PREEMPT_NONE=y
202# CONFIG_PREEMPT_VOLUNTARY is not set
203# CONFIG_PREEMPT is not set
204CONFIG_BINFMT_ELF=y
205# CONFIG_BINFMT_MISC is not set
206# CONFIG_IOMMU_HELPER is not set
207CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
208CONFIG_ARCH_HAS_WALK_MEMORY=y
209CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
210# CONFIG_KEXEC is not set
211CONFIG_ARCH_FLATMEM_ENABLE=y
212CONFIG_ARCH_POPULATES_NODE_MAP=y
213CONFIG_SELECT_MEMORY_MODEL=y
214CONFIG_FLATMEM_MANUAL=y
215# CONFIG_DISCONTIGMEM_MANUAL is not set
216# CONFIG_SPARSEMEM_MANUAL is not set
217CONFIG_FLATMEM=y
218CONFIG_FLAT_NODE_MEM_MAP=y
219# CONFIG_SPARSEMEM_STATIC is not set
220# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
221CONFIG_PAGEFLAGS_EXTENDED=y
222CONFIG_SPLIT_PTLOCK_CPUS=4
223# CONFIG_RESOURCES_64BIT is not set
224CONFIG_ZONE_DMA_FLAG=1
225CONFIG_BOUNCE=y
226CONFIG_VIRT_TO_BUS=y
227CONFIG_FORCE_MAX_ZONEORDER=11
228CONFIG_PROC_DEVICETREE=y
229# CONFIG_CMDLINE_BOOL is not set
230CONFIG_PM=y
231# CONFIG_PM_LEGACY is not set
232# CONFIG_PM_DEBUG is not set
233CONFIG_SECCOMP=y
234CONFIG_ISA_DMA_API=y
235
236#
237# Bus options
238#
239CONFIG_ZONE_DMA=y
240CONFIG_GENERIC_ISA_DMA=y
241CONFIG_FSL_SOC=y
242# CONFIG_PCI is not set
243# CONFIG_PCI_DOMAINS is not set
244# CONFIG_PCI_SYSCALL is not set
245# CONFIG_ARCH_SUPPORTS_MSI is not set
246# CONFIG_PCCARD is not set
247# CONFIG_HAS_RAPIDIO is not set
248
249#
250# Advanced setup
251#
252# CONFIG_ADVANCED_OPTIONS is not set
253
254#
255# Default settings for advanced configuration options are used
256#
257CONFIG_LOWMEM_SIZE=0x30000000
258CONFIG_PAGE_OFFSET=0xc0000000
259CONFIG_KERNEL_START=0xc0000000
260CONFIG_PHYSICAL_START=0x00000000
261CONFIG_TASK_SIZE=0xc0000000
262
263#
264# Networking
265#
266CONFIG_NET=y
267
268#
269# Networking options
270#
271CONFIG_PACKET=y
272# CONFIG_PACKET_MMAP is not set
273CONFIG_UNIX=y
274CONFIG_XFRM=y
275CONFIG_XFRM_USER=y
276# CONFIG_XFRM_SUB_POLICY is not set
277# CONFIG_XFRM_MIGRATE is not set
278# CONFIG_XFRM_STATISTICS is not set
279# CONFIG_NET_KEY is not set
280CONFIG_INET=y
281CONFIG_IP_MULTICAST=y
282# CONFIG_IP_ADVANCED_ROUTER is not set
283CONFIG_IP_FIB_HASH=y
284CONFIG_IP_PNP=y
285CONFIG_IP_PNP_DHCP=y
286CONFIG_IP_PNP_BOOTP=y
287# CONFIG_IP_PNP_RARP is not set
288# CONFIG_NET_IPIP is not set
289# CONFIG_NET_IPGRE is not set
290# CONFIG_IP_MROUTE is not set
291# CONFIG_ARPD is not set
292CONFIG_SYN_COOKIES=y
293# CONFIG_INET_AH is not set
294# CONFIG_INET_ESP is not set
295# CONFIG_INET_IPCOMP is not set
296# CONFIG_INET_XFRM_TUNNEL is not set
297# CONFIG_INET_TUNNEL is not set
298CONFIG_INET_XFRM_MODE_TRANSPORT=y
299CONFIG_INET_XFRM_MODE_TUNNEL=y
300CONFIG_INET_XFRM_MODE_BEET=y
301# CONFIG_INET_LRO is not set
302CONFIG_INET_DIAG=y
303CONFIG_INET_TCP_DIAG=y
304# CONFIG_TCP_CONG_ADVANCED is not set
305CONFIG_TCP_CONG_CUBIC=y
306CONFIG_DEFAULT_TCP_CONG="cubic"
307# CONFIG_TCP_MD5SIG is not set
308# CONFIG_IPV6 is not set
309# CONFIG_NETWORK_SECMARK is not set
310# CONFIG_NETFILTER is not set
311# CONFIG_IP_DCCP is not set
312# CONFIG_IP_SCTP is not set
313# CONFIG_TIPC is not set
314# CONFIG_ATM is not set
315# CONFIG_BRIDGE is not set
316# CONFIG_VLAN_8021Q is not set
317# CONFIG_DECNET is not set
318# CONFIG_LLC2 is not set
319# CONFIG_IPX is not set
320# CONFIG_ATALK is not set
321# CONFIG_X25 is not set
322# CONFIG_LAPB is not set
323# CONFIG_ECONET is not set
324# CONFIG_WAN_ROUTER is not set
325# CONFIG_NET_SCHED is not set
326
327#
328# Network testing
329#
330# CONFIG_NET_PKTGEN is not set
331# CONFIG_HAMRADIO is not set
332# CONFIG_CAN is not set
333# CONFIG_IRDA is not set
334# CONFIG_BT is not set
335# CONFIG_AF_RXRPC is not set
336
337#
338# Wireless
339#
340# CONFIG_CFG80211 is not set
341# CONFIG_WIRELESS_EXT is not set
342# CONFIG_MAC80211 is not set
343# CONFIG_IEEE80211 is not set
344# CONFIG_RFKILL is not set
345# CONFIG_NET_9P is not set
346
347#
348# Device Drivers
349#
350
351#
352# Generic Driver Options
353#
354CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
355CONFIG_STANDALONE=y
356CONFIG_PREVENT_FIRMWARE_BUILD=y
357# CONFIG_FW_LOADER is not set
358# CONFIG_DEBUG_DRIVER is not set
359# CONFIG_DEBUG_DEVRES is not set
360# CONFIG_SYS_HYPERVISOR is not set
361# CONFIG_CONNECTOR is not set
362CONFIG_MTD=y
363# CONFIG_MTD_DEBUG is not set
364CONFIG_MTD_CONCAT=y
365CONFIG_MTD_PARTITIONS=y
366# CONFIG_MTD_REDBOOT_PARTS is not set
367CONFIG_MTD_CMDLINE_PARTS=y
368# CONFIG_MTD_OF_PARTS is not set
369# CONFIG_MTD_AR7_PARTS is not set
370
371#
372# User Modules And Translation Layers
373#
374CONFIG_MTD_CHAR=y
375CONFIG_MTD_BLKDEVS=y
376CONFIG_MTD_BLOCK=y
377# CONFIG_FTL is not set
378# CONFIG_NFTL is not set
379# CONFIG_INFTL is not set
380# CONFIG_RFD_FTL is not set
381# CONFIG_SSFDC is not set
382# CONFIG_MTD_OOPS is not set
383
384#
385# RAM/ROM/Flash chip drivers
386#
387CONFIG_MTD_CFI=y
388# CONFIG_MTD_JEDECPROBE is not set
389CONFIG_MTD_GEN_PROBE=y
390# CONFIG_MTD_CFI_ADV_OPTIONS is not set
391CONFIG_MTD_MAP_BANK_WIDTH_1=y
392CONFIG_MTD_MAP_BANK_WIDTH_2=y
393CONFIG_MTD_MAP_BANK_WIDTH_4=y
394# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
395# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
396# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
397CONFIG_MTD_CFI_I1=y
398CONFIG_MTD_CFI_I2=y
399# CONFIG_MTD_CFI_I4 is not set
400# CONFIG_MTD_CFI_I8 is not set
401# CONFIG_MTD_CFI_INTELEXT is not set
402CONFIG_MTD_CFI_AMDSTD=y
403# CONFIG_MTD_CFI_STAA is not set
404CONFIG_MTD_CFI_UTIL=y
405# CONFIG_MTD_RAM is not set
406CONFIG_MTD_ROM=y
407# CONFIG_MTD_ABSENT is not set
408
409#
410# Mapping drivers for chip access
411#
412# CONFIG_MTD_COMPLEX_MAPPINGS is not set
413# CONFIG_MTD_PHYSMAP is not set
414CONFIG_MTD_PHYSMAP_OF=y
415# CONFIG_MTD_PLATRAM is not set
416
417#
418# Self-contained MTD device drivers
419#
420# CONFIG_MTD_SLRAM is not set
421# CONFIG_MTD_PHRAM is not set
422# CONFIG_MTD_MTDRAM is not set
423# CONFIG_MTD_BLOCK2MTD is not set
424
425#
426# Disk-On-Chip Device Drivers
427#
428# CONFIG_MTD_DOC2000 is not set
429# CONFIG_MTD_DOC2001 is not set
430# CONFIG_MTD_DOC2001PLUS is not set
431# CONFIG_MTD_NAND is not set
432# CONFIG_MTD_ONENAND is not set
433
434#
435# UBI - Unsorted block images
436#
437# CONFIG_MTD_UBI is not set
438CONFIG_OF_DEVICE=y
439CONFIG_OF_I2C=y
440# CONFIG_PARPORT is not set
441CONFIG_BLK_DEV=y
442# CONFIG_BLK_DEV_FD is not set
443# CONFIG_BLK_DEV_COW_COMMON is not set
444CONFIG_BLK_DEV_LOOP=y
445# CONFIG_BLK_DEV_CRYPTOLOOP is not set
446# CONFIG_BLK_DEV_NBD is not set
447# CONFIG_BLK_DEV_UB is not set
448CONFIG_BLK_DEV_RAM=y
449CONFIG_BLK_DEV_RAM_COUNT=16
450CONFIG_BLK_DEV_RAM_SIZE=32768
451# CONFIG_BLK_DEV_XIP is not set
452# CONFIG_CDROM_PKTCDVD is not set
453# CONFIG_ATA_OVER_ETH is not set
454# CONFIG_MISC_DEVICES is not set
455CONFIG_HAVE_IDE=y
456# CONFIG_IDE is not set
457
458#
459# SCSI device support
460#
461# CONFIG_RAID_ATTRS is not set
462CONFIG_SCSI=y
463CONFIG_SCSI_DMA=y
464# CONFIG_SCSI_TGT is not set
465# CONFIG_SCSI_NETLINK is not set
466CONFIG_SCSI_PROC_FS=y
467
468#
469# SCSI support type (disk, tape, CD-ROM)
470#
471CONFIG_BLK_DEV_SD=y
472# CONFIG_CHR_DEV_ST is not set
473# CONFIG_CHR_DEV_OSST is not set
474# CONFIG_BLK_DEV_SR is not set
475CONFIG_CHR_DEV_SG=y
476# CONFIG_CHR_DEV_SCH is not set
477
478#
479# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
480#
481# CONFIG_SCSI_MULTI_LUN is not set
482# CONFIG_SCSI_CONSTANTS is not set
483# CONFIG_SCSI_LOGGING is not set
484# CONFIG_SCSI_SCAN_ASYNC is not set
485CONFIG_SCSI_WAIT_SCAN=m
486
487#
488# SCSI Transports
489#
490# CONFIG_SCSI_SPI_ATTRS is not set
491# CONFIG_SCSI_FC_ATTRS is not set
492# CONFIG_SCSI_ISCSI_ATTRS is not set
493# CONFIG_SCSI_SAS_LIBSAS is not set
494# CONFIG_SCSI_SRP_ATTRS is not set
495CONFIG_SCSI_LOWLEVEL=y
496# CONFIG_ISCSI_TCP is not set
497# CONFIG_SCSI_DEBUG is not set
498CONFIG_ATA=y
499# CONFIG_ATA_NONSTANDARD is not set
500CONFIG_SATA_PMP=y
501# CONFIG_SATA_FSL is not set
502CONFIG_ATA_SFF=y
503# CONFIG_SATA_MV is not set
504CONFIG_PATA_MPC52xx=y
505CONFIG_PATA_PLATFORM=y
506# CONFIG_PATA_OF_PLATFORM is not set
507# CONFIG_MD is not set
508# CONFIG_MACINTOSH_DRIVERS is not set
509CONFIG_NETDEVICES=y
510# CONFIG_NETDEVICES_MULTIQUEUE is not set
511# CONFIG_DUMMY is not set
512# CONFIG_BONDING is not set
513# CONFIG_MACVLAN is not set
514# CONFIG_EQUALIZER is not set
515# CONFIG_TUN is not set
516# CONFIG_VETH is not set
517CONFIG_PHYLIB=y
518
519#
520# MII PHY device drivers
521#
522# CONFIG_MARVELL_PHY is not set
523# CONFIG_DAVICOM_PHY is not set
524# CONFIG_QSEMI_PHY is not set
525CONFIG_LXT_PHY=y
526# CONFIG_CICADA_PHY is not set
527# CONFIG_VITESSE_PHY is not set
528# CONFIG_SMSC_PHY is not set
529# CONFIG_BROADCOM_PHY is not set
530# CONFIG_ICPLUS_PHY is not set
531# CONFIG_REALTEK_PHY is not set
532# CONFIG_FIXED_PHY is not set
533# CONFIG_MDIO_BITBANG is not set
534CONFIG_NET_ETHERNET=y
535# CONFIG_MII is not set
536# CONFIG_IBM_NEW_EMAC_ZMII is not set
537# CONFIG_IBM_NEW_EMAC_RGMII is not set
538# CONFIG_IBM_NEW_EMAC_TAH is not set
539# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
540# CONFIG_B44 is not set
541CONFIG_FEC_MPC52xx=y
542CONFIG_FEC_MPC52xx_MDIO=y
543# CONFIG_NETDEV_1000 is not set
544# CONFIG_NETDEV_10000 is not set
545
546#
547# Wireless LAN
548#
549# CONFIG_WLAN_PRE80211 is not set
550# CONFIG_WLAN_80211 is not set
551# CONFIG_IWLWIFI is not set
552# CONFIG_IWLWIFI_LEDS is not set
553
554#
555# USB Network Adapters
556#
557# CONFIG_USB_CATC is not set
558# CONFIG_USB_KAWETH is not set
559# CONFIG_USB_PEGASUS is not set
560# CONFIG_USB_RTL8150 is not set
561# CONFIG_USB_USBNET is not set
562# CONFIG_WAN is not set
563# CONFIG_PPP is not set
564# CONFIG_SLIP is not set
565# CONFIG_NETCONSOLE is not set
566# CONFIG_NETPOLL is not set
567# CONFIG_NET_POLL_CONTROLLER is not set
568# CONFIG_ISDN is not set
569# CONFIG_PHONE is not set
570
571#
572# Input device support
573#
574# CONFIG_INPUT is not set
575
576#
577# Hardware I/O ports
578#
579# CONFIG_SERIO is not set
580# CONFIG_GAMEPORT is not set
581
582#
583# Character devices
584#
585# CONFIG_VT is not set
586# CONFIG_SERIAL_NONSTANDARD is not set
587
588#
589# Serial drivers
590#
591# CONFIG_SERIAL_8250 is not set
592
593#
594# Non-8250 serial port support
595#
596# CONFIG_SERIAL_UARTLITE is not set
597CONFIG_SERIAL_CORE=y
598CONFIG_SERIAL_CORE_CONSOLE=y
599CONFIG_SERIAL_MPC52xx=y
600CONFIG_SERIAL_MPC52xx_CONSOLE=y
601CONFIG_SERIAL_MPC52xx_CONSOLE_BAUD=115200
602CONFIG_UNIX98_PTYS=y
603CONFIG_LEGACY_PTYS=y
604CONFIG_LEGACY_PTY_COUNT=256
605# CONFIG_IPMI_HANDLER is not set
606# CONFIG_HW_RANDOM is not set
607# CONFIG_NVRAM is not set
608# CONFIG_R3964 is not set
609# CONFIG_RAW_DRIVER is not set
610# CONFIG_TCG_TPM is not set
611CONFIG_I2C=y
612CONFIG_I2C_BOARDINFO=y
613CONFIG_I2C_CHARDEV=y
614
615#
616# I2C Hardware Bus support
617#
618CONFIG_I2C_MPC=y
619# CONFIG_I2C_OCORES is not set
620# CONFIG_I2C_PARPORT_LIGHT is not set
621# CONFIG_I2C_SIMTEC is not set
622# CONFIG_I2C_TAOS_EVM is not set
623# CONFIG_I2C_STUB is not set
624# CONFIG_I2C_TINY_USB is not set
625# CONFIG_I2C_PCA_PLATFORM is not set
626
627#
628# Miscellaneous I2C Chip support
629#
630# CONFIG_DS1682 is not set
631# CONFIG_SENSORS_EEPROM is not set
632# CONFIG_SENSORS_PCF8574 is not set
633# CONFIG_PCF8575 is not set
634# CONFIG_SENSORS_PCF8591 is not set
635# CONFIG_SENSORS_MAX6875 is not set
636# CONFIG_SENSORS_TSL2550 is not set
637# CONFIG_I2C_DEBUG_CORE is not set
638# CONFIG_I2C_DEBUG_ALGO is not set
639# CONFIG_I2C_DEBUG_BUS is not set
640# CONFIG_I2C_DEBUG_CHIP is not set
641# CONFIG_SPI is not set
642# CONFIG_W1 is not set
643# CONFIG_POWER_SUPPLY is not set
644CONFIG_HWMON=y
645# CONFIG_HWMON_VID is not set
646# CONFIG_SENSORS_AD7418 is not set
647# CONFIG_SENSORS_ADM1021 is not set
648# CONFIG_SENSORS_ADM1025 is not set
649# CONFIG_SENSORS_ADM1026 is not set
650# CONFIG_SENSORS_ADM1029 is not set
651# CONFIG_SENSORS_ADM1031 is not set
652# CONFIG_SENSORS_ADM9240 is not set
653# CONFIG_SENSORS_ADT7470 is not set
654# CONFIG_SENSORS_ADT7473 is not set
655# CONFIG_SENSORS_ATXP1 is not set
656# CONFIG_SENSORS_DS1621 is not set
657# CONFIG_SENSORS_F71805F is not set
658# CONFIG_SENSORS_F71882FG is not set
659# CONFIG_SENSORS_F75375S is not set
660# CONFIG_SENSORS_GL518SM is not set
661# CONFIG_SENSORS_GL520SM is not set
662# CONFIG_SENSORS_IT87 is not set
663# CONFIG_SENSORS_LM63 is not set
664# CONFIG_SENSORS_LM75 is not set
665# CONFIG_SENSORS_LM77 is not set
666# CONFIG_SENSORS_LM78 is not set
667# CONFIG_SENSORS_LM80 is not set
668# CONFIG_SENSORS_LM83 is not set
669# CONFIG_SENSORS_LM85 is not set
670# CONFIG_SENSORS_LM87 is not set
671# CONFIG_SENSORS_LM90 is not set
672# CONFIG_SENSORS_LM92 is not set
673# CONFIG_SENSORS_LM93 is not set
674# CONFIG_SENSORS_MAX1619 is not set
675# CONFIG_SENSORS_MAX6650 is not set
676# CONFIG_SENSORS_PC87360 is not set
677# CONFIG_SENSORS_PC87427 is not set
678# CONFIG_SENSORS_DME1737 is not set
679# CONFIG_SENSORS_SMSC47M1 is not set
680# CONFIG_SENSORS_SMSC47M192 is not set
681# CONFIG_SENSORS_SMSC47B397 is not set
682# CONFIG_SENSORS_ADS7828 is not set
683# CONFIG_SENSORS_THMC50 is not set
684# CONFIG_SENSORS_VT1211 is not set
685# CONFIG_SENSORS_W83781D is not set
686# CONFIG_SENSORS_W83791D is not set
687# CONFIG_SENSORS_W83792D is not set
688# CONFIG_SENSORS_W83793 is not set
689# CONFIG_SENSORS_W83L785TS is not set
690# CONFIG_SENSORS_W83L786NG is not set
691# CONFIG_SENSORS_W83627HF is not set
692# CONFIG_SENSORS_W83627EHF is not set
693# CONFIG_HWMON_DEBUG_CHIP is not set
694# CONFIG_THERMAL is not set
695CONFIG_WATCHDOG=y
696# CONFIG_WATCHDOG_NOWAYOUT is not set
697
698#
699# Watchdog Device Drivers
700#
701# CONFIG_SOFT_WATCHDOG is not set
702# CONFIG_MPC5200_WDT is not set
703
704#
705# USB-based Watchdog Cards
706#
707# CONFIG_USBPCWATCHDOG is not set
708
709#
710# Sonics Silicon Backplane
711#
712CONFIG_SSB_POSSIBLE=y
713# CONFIG_SSB is not set
714
715#
716# Multifunction device drivers
717#
718# CONFIG_MFD_SM501 is not set
719# CONFIG_HTC_PASIC3 is not set
720
721#
722# Multimedia devices
723#
724# CONFIG_VIDEO_DEV is not set
725# CONFIG_DVB_CORE is not set
726# CONFIG_DAB is not set
727
728#
729# Graphics support
730#
731# CONFIG_VGASTATE is not set
732# CONFIG_VIDEO_OUTPUT_CONTROL is not set
733# CONFIG_FB is not set
734# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
735
736#
737# Display device support
738#
739# CONFIG_DISPLAY_SUPPORT is not set
740
741#
742# Sound
743#
744# CONFIG_SOUND is not set
745CONFIG_USB_SUPPORT=y
746CONFIG_USB_ARCH_HAS_HCD=y
747CONFIG_USB_ARCH_HAS_OHCI=y
748# CONFIG_USB_ARCH_HAS_EHCI is not set
749CONFIG_USB=y
750# CONFIG_USB_DEBUG is not set
751# CONFIG_USB_ANNOUNCE_NEW_DEVICES is not set
752
753#
754# Miscellaneous USB options
755#
756CONFIG_USB_DEVICEFS=y
757# CONFIG_USB_DEVICE_CLASS is not set
758# CONFIG_USB_DYNAMIC_MINORS is not set
759# CONFIG_USB_SUSPEND is not set
760# CONFIG_USB_OTG is not set
761# CONFIG_USB_OTG_WHITELIST is not set
762# CONFIG_USB_OTG_BLACKLIST_HUB is not set
763
764#
765# USB Host Controller Drivers
766#
767# CONFIG_USB_ISP116X_HCD is not set
768CONFIG_USB_OHCI_HCD=y
769CONFIG_USB_OHCI_HCD_PPC_SOC=y
770CONFIG_USB_OHCI_HCD_PPC_OF=y
771CONFIG_USB_OHCI_HCD_PPC_OF_BE=y
772# CONFIG_USB_OHCI_HCD_PPC_OF_LE is not set
773CONFIG_USB_OHCI_BIG_ENDIAN_DESC=y
774CONFIG_USB_OHCI_BIG_ENDIAN_MMIO=y
775# CONFIG_USB_OHCI_LITTLE_ENDIAN is not set
776# CONFIG_USB_SL811_HCD is not set
777# CONFIG_USB_R8A66597_HCD is not set
778
779#
780# USB Device Class drivers
781#
782# CONFIG_USB_ACM is not set
783# CONFIG_USB_PRINTER is not set
784
785#
786# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
787#
788
789#
790# may also be needed; see USB_STORAGE Help for more information
791#
792CONFIG_USB_STORAGE=y
793# CONFIG_USB_STORAGE_DEBUG is not set
794# CONFIG_USB_STORAGE_DATAFAB is not set
795# CONFIG_USB_STORAGE_FREECOM is not set
796# CONFIG_USB_STORAGE_ISD200 is not set
797# CONFIG_USB_STORAGE_DPCM is not set
798# CONFIG_USB_STORAGE_USBAT is not set
799# CONFIG_USB_STORAGE_SDDR09 is not set
800# CONFIG_USB_STORAGE_SDDR55 is not set
801# CONFIG_USB_STORAGE_JUMPSHOT is not set
802# CONFIG_USB_STORAGE_ALAUDA is not set
803# CONFIG_USB_STORAGE_KARMA is not set
804# CONFIG_USB_STORAGE_CYPRESS_ATACB is not set
805# CONFIG_USB_LIBUSUAL is not set
806
807#
808# USB Imaging devices
809#
810# CONFIG_USB_MDC800 is not set
811# CONFIG_USB_MICROTEK is not set
812CONFIG_USB_MON=y
813
814#
815# USB port drivers
816#
817# CONFIG_USB_SERIAL is not set
818
819#
820# USB Miscellaneous drivers
821#
822# CONFIG_USB_EMI62 is not set
823# CONFIG_USB_EMI26 is not set
824# CONFIG_USB_ADUTUX is not set
825# CONFIG_USB_AUERSWALD is not set
826# CONFIG_USB_RIO500 is not set
827# CONFIG_USB_LEGOTOWER is not set
828# CONFIG_USB_LCD is not set
829# CONFIG_USB_BERRY_CHARGE is not set
830# CONFIG_USB_LED is not set
831# CONFIG_USB_CYPRESS_CY7C63 is not set
832# CONFIG_USB_CYTHERM is not set
833# CONFIG_USB_PHIDGET is not set
834# CONFIG_USB_IDMOUSE is not set
835# CONFIG_USB_FTDI_ELAN is not set
836# CONFIG_USB_APPLEDISPLAY is not set
837# CONFIG_USB_LD is not set
838# CONFIG_USB_TRANCEVIBRATOR is not set
839# CONFIG_USB_IOWARRIOR is not set
840# CONFIG_USB_TEST is not set
841# CONFIG_USB_GADGET is not set
842# CONFIG_MMC is not set
843# CONFIG_MEMSTICK is not set
844# CONFIG_NEW_LEDS is not set
845# CONFIG_EDAC is not set
846CONFIG_RTC_LIB=y
847CONFIG_RTC_CLASS=y
848CONFIG_RTC_HCTOSYS=y
849CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
850# CONFIG_RTC_DEBUG is not set
851
852#
853# RTC interfaces
854#
855CONFIG_RTC_INTF_SYSFS=y
856CONFIG_RTC_INTF_PROC=y
857CONFIG_RTC_INTF_DEV=y
858# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
859# CONFIG_RTC_DRV_TEST is not set
860
861#
862# I2C RTC drivers
863#
864CONFIG_RTC_DRV_DS1307=y
865# CONFIG_RTC_DRV_DS1374 is not set
866# CONFIG_RTC_DRV_DS1672 is not set
867# CONFIG_RTC_DRV_MAX6900 is not set
868# CONFIG_RTC_DRV_RS5C372 is not set
869# CONFIG_RTC_DRV_ISL1208 is not set
870# CONFIG_RTC_DRV_X1205 is not set
871# CONFIG_RTC_DRV_PCF8563 is not set
872# CONFIG_RTC_DRV_PCF8583 is not set
873# CONFIG_RTC_DRV_M41T80 is not set
874# CONFIG_RTC_DRV_S35390A is not set
875
876#
877# SPI RTC drivers
878#
879
880#
881# Platform RTC drivers
882#
883# CONFIG_RTC_DRV_CMOS is not set
884# CONFIG_RTC_DRV_DS1511 is not set
885# CONFIG_RTC_DRV_DS1553 is not set
886# CONFIG_RTC_DRV_DS1742 is not set
887# CONFIG_RTC_DRV_STK17TA8 is not set
888# CONFIG_RTC_DRV_M48T86 is not set
889# CONFIG_RTC_DRV_M48T59 is not set
890# CONFIG_RTC_DRV_V3020 is not set
891
892#
893# on-CPU RTC drivers
894#
895# CONFIG_DMADEVICES is not set
896# CONFIG_UIO is not set
897
898#
899# File systems
900#
901CONFIG_EXT2_FS=y
902# CONFIG_EXT2_FS_XATTR is not set
903# CONFIG_EXT2_FS_XIP is not set
904CONFIG_EXT3_FS=y
905CONFIG_EXT3_FS_XATTR=y
906# CONFIG_EXT3_FS_POSIX_ACL is not set
907# CONFIG_EXT3_FS_SECURITY is not set
908# CONFIG_EXT4DEV_FS is not set
909CONFIG_JBD=y
910CONFIG_FS_MBCACHE=y
911# CONFIG_REISERFS_FS is not set
912# CONFIG_JFS_FS is not set
913# CONFIG_FS_POSIX_ACL is not set
914# CONFIG_XFS_FS is not set
915# CONFIG_OCFS2_FS is not set
916CONFIG_DNOTIFY=y
917CONFIG_INOTIFY=y
918CONFIG_INOTIFY_USER=y
919# CONFIG_QUOTA is not set
920# CONFIG_AUTOFS_FS is not set
921# CONFIG_AUTOFS4_FS is not set
922# CONFIG_FUSE_FS is not set
923
924#
925# CD-ROM/DVD Filesystems
926#
927# CONFIG_ISO9660_FS is not set
928# CONFIG_UDF_FS is not set
929
930#
931# DOS/FAT/NT Filesystems
932#
933CONFIG_FAT_FS=y
934CONFIG_MSDOS_FS=y
935CONFIG_VFAT_FS=y
936CONFIG_FAT_DEFAULT_CODEPAGE=437
937CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
938# CONFIG_NTFS_FS is not set
939
940#
941# Pseudo filesystems
942#
943CONFIG_PROC_FS=y
944CONFIG_PROC_KCORE=y
945CONFIG_PROC_SYSCTL=y
946CONFIG_SYSFS=y
947CONFIG_TMPFS=y
948# CONFIG_TMPFS_POSIX_ACL is not set
949# CONFIG_HUGETLB_PAGE is not set
950# CONFIG_CONFIGFS_FS is not set
951
952#
953# Miscellaneous filesystems
954#
955# CONFIG_ADFS_FS is not set
956# CONFIG_AFFS_FS is not set
957# CONFIG_HFS_FS is not set
958# CONFIG_HFSPLUS_FS is not set
959# CONFIG_BEFS_FS is not set
960# CONFIG_BFS_FS is not set
961# CONFIG_EFS_FS is not set
962CONFIG_JFFS2_FS=y
963CONFIG_JFFS2_FS_DEBUG=0
964CONFIG_JFFS2_FS_WRITEBUFFER=y
965# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
966# CONFIG_JFFS2_SUMMARY is not set
967# CONFIG_JFFS2_FS_XATTR is not set
968# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
969CONFIG_JFFS2_ZLIB=y
970# CONFIG_JFFS2_LZO is not set
971CONFIG_JFFS2_RTIME=y
972# CONFIG_JFFS2_RUBIN is not set
973CONFIG_CRAMFS=y
974# CONFIG_VXFS_FS is not set
975# CONFIG_MINIX_FS is not set
976# CONFIG_HPFS_FS is not set
977# CONFIG_QNX4FS_FS is not set
978# CONFIG_ROMFS_FS is not set
979# CONFIG_SYSV_FS is not set
980# CONFIG_UFS_FS is not set
981CONFIG_NETWORK_FILESYSTEMS=y
982CONFIG_NFS_FS=y
983CONFIG_NFS_V3=y
984# CONFIG_NFS_V3_ACL is not set
985CONFIG_NFS_V4=y
986# CONFIG_NFSD is not set
987CONFIG_ROOT_NFS=y
988CONFIG_LOCKD=y
989CONFIG_LOCKD_V4=y
990CONFIG_NFS_COMMON=y
991CONFIG_SUNRPC=y
992CONFIG_SUNRPC_GSS=y
993# CONFIG_SUNRPC_BIND34 is not set
994CONFIG_RPCSEC_GSS_KRB5=y
995# CONFIG_RPCSEC_GSS_SPKM3 is not set
996# CONFIG_SMB_FS is not set
997# CONFIG_CIFS is not set
998# CONFIG_NCP_FS is not set
999# CONFIG_CODA_FS is not set
1000# CONFIG_AFS_FS is not set
1001
1002#
1003# Partition Types
1004#
1005CONFIG_PARTITION_ADVANCED=y
1006# CONFIG_ACORN_PARTITION is not set
1007# CONFIG_OSF_PARTITION is not set
1008# CONFIG_AMIGA_PARTITION is not set
1009# CONFIG_ATARI_PARTITION is not set
1010# CONFIG_MAC_PARTITION is not set
1011CONFIG_MSDOS_PARTITION=y
1012# CONFIG_BSD_DISKLABEL is not set
1013# CONFIG_MINIX_SUBPARTITION is not set
1014# CONFIG_SOLARIS_X86_PARTITION is not set
1015# CONFIG_UNIXWARE_DISKLABEL is not set
1016# CONFIG_LDM_PARTITION is not set
1017# CONFIG_SGI_PARTITION is not set
1018# CONFIG_ULTRIX_PARTITION is not set
1019# CONFIG_SUN_PARTITION is not set
1020# CONFIG_KARMA_PARTITION is not set
1021# CONFIG_EFI_PARTITION is not set
1022# CONFIG_SYSV68_PARTITION is not set
1023CONFIG_NLS=y
1024CONFIG_NLS_DEFAULT="iso8859-1"
1025CONFIG_NLS_CODEPAGE_437=y
1026# CONFIG_NLS_CODEPAGE_737 is not set
1027# CONFIG_NLS_CODEPAGE_775 is not set
1028# CONFIG_NLS_CODEPAGE_850 is not set
1029# CONFIG_NLS_CODEPAGE_852 is not set
1030# CONFIG_NLS_CODEPAGE_855 is not set
1031# CONFIG_NLS_CODEPAGE_857 is not set
1032# CONFIG_NLS_CODEPAGE_860 is not set
1033# CONFIG_NLS_CODEPAGE_861 is not set
1034# CONFIG_NLS_CODEPAGE_862 is not set
1035# CONFIG_NLS_CODEPAGE_863 is not set
1036# CONFIG_NLS_CODEPAGE_864 is not set
1037# CONFIG_NLS_CODEPAGE_865 is not set
1038# CONFIG_NLS_CODEPAGE_866 is not set
1039# CONFIG_NLS_CODEPAGE_869 is not set
1040# CONFIG_NLS_CODEPAGE_936 is not set
1041# CONFIG_NLS_CODEPAGE_950 is not set
1042# CONFIG_NLS_CODEPAGE_932 is not set
1043# CONFIG_NLS_CODEPAGE_949 is not set
1044# CONFIG_NLS_CODEPAGE_874 is not set
1045# CONFIG_NLS_ISO8859_8 is not set
1046# CONFIG_NLS_CODEPAGE_1250 is not set
1047# CONFIG_NLS_CODEPAGE_1251 is not set
1048# CONFIG_NLS_ASCII is not set
1049CONFIG_NLS_ISO8859_1=y
1050# CONFIG_NLS_ISO8859_2 is not set
1051# CONFIG_NLS_ISO8859_3 is not set
1052# CONFIG_NLS_ISO8859_4 is not set
1053# CONFIG_NLS_ISO8859_5 is not set
1054# CONFIG_NLS_ISO8859_6 is not set
1055# CONFIG_NLS_ISO8859_7 is not set
1056# CONFIG_NLS_ISO8859_9 is not set
1057# CONFIG_NLS_ISO8859_13 is not set
1058# CONFIG_NLS_ISO8859_14 is not set
1059# CONFIG_NLS_ISO8859_15 is not set
1060# CONFIG_NLS_KOI8_R is not set
1061# CONFIG_NLS_KOI8_U is not set
1062# CONFIG_NLS_UTF8 is not set
1063# CONFIG_DLM is not set
1064
1065#
1066# Library routines
1067#
1068CONFIG_BITREVERSE=y
1069# CONFIG_GENERIC_FIND_FIRST_BIT is not set
1070# CONFIG_CRC_CCITT is not set
1071# CONFIG_CRC16 is not set
1072# CONFIG_CRC_ITU_T is not set
1073CONFIG_CRC32=y
1074# CONFIG_CRC7 is not set
1075# CONFIG_LIBCRC32C is not set
1076CONFIG_ZLIB_INFLATE=y
1077CONFIG_ZLIB_DEFLATE=y
1078CONFIG_PLIST=y
1079CONFIG_HAS_IOMEM=y
1080CONFIG_HAS_IOPORT=y
1081CONFIG_HAS_DMA=y
1082CONFIG_HAVE_LMB=y
1083
1084#
1085# Kernel hacking
1086#
1087CONFIG_PRINTK_TIME=y
1088CONFIG_ENABLE_WARN_DEPRECATED=y
1089CONFIG_ENABLE_MUST_CHECK=y
1090CONFIG_FRAME_WARN=1024
1091# CONFIG_MAGIC_SYSRQ is not set
1092# CONFIG_UNUSED_SYMBOLS is not set
1093# CONFIG_DEBUG_FS is not set
1094# CONFIG_HEADERS_CHECK is not set
1095CONFIG_DEBUG_KERNEL=y
1096# CONFIG_DEBUG_SHIRQ is not set
1097CONFIG_DETECT_SOFTLOCKUP=y
1098CONFIG_SCHED_DEBUG=y
1099# CONFIG_SCHEDSTATS is not set
1100# CONFIG_TIMER_STATS is not set
1101# CONFIG_SLUB_DEBUG_ON is not set
1102# CONFIG_SLUB_STATS is not set
1103# CONFIG_DEBUG_RT_MUTEXES is not set
1104# CONFIG_RT_MUTEX_TESTER is not set
1105# CONFIG_DEBUG_SPINLOCK is not set
1106# CONFIG_DEBUG_MUTEXES is not set
1107# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
1108# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
1109# CONFIG_DEBUG_KOBJECT is not set
1110# CONFIG_DEBUG_BUGVERBOSE is not set
1111CONFIG_DEBUG_INFO=y
1112# CONFIG_DEBUG_VM is not set
1113# CONFIG_DEBUG_WRITECOUNT is not set
1114# CONFIG_DEBUG_LIST is not set
1115# CONFIG_DEBUG_SG is not set
1116# CONFIG_BOOT_PRINTK_DELAY is not set
1117# CONFIG_RCU_TORTURE_TEST is not set
1118# CONFIG_BACKTRACE_SELF_TEST is not set
1119# CONFIG_FAULT_INJECTION is not set
1120# CONFIG_SAMPLES is not set
1121# CONFIG_DEBUG_STACKOVERFLOW is not set
1122# CONFIG_DEBUG_STACK_USAGE is not set
1123# CONFIG_DEBUG_PAGEALLOC is not set
1124# CONFIG_DEBUGGER is not set
1125# CONFIG_IRQSTACKS is not set
1126# CONFIG_BDI_SWITCH is not set
1127# CONFIG_BOOTX_TEXT is not set
1128# CONFIG_PPC_EARLY_DEBUG is not set
1129
1130#
1131# Security options
1132#
1133# CONFIG_KEYS is not set
1134# CONFIG_SECURITY is not set
1135# CONFIG_SECURITY_FILE_CAPABILITIES is not set
1136CONFIG_CRYPTO=y
1137
1138#
1139# Crypto core or helper
1140#
1141CONFIG_CRYPTO_ALGAPI=y
1142CONFIG_CRYPTO_BLKCIPHER=y
1143CONFIG_CRYPTO_MANAGER=y
1144# CONFIG_CRYPTO_GF128MUL is not set
1145# CONFIG_CRYPTO_NULL is not set
1146# CONFIG_CRYPTO_CRYPTD is not set
1147# CONFIG_CRYPTO_AUTHENC is not set
1148# CONFIG_CRYPTO_TEST is not set
1149
1150#
1151# Authenticated Encryption with Associated Data
1152#
1153# CONFIG_CRYPTO_CCM is not set
1154# CONFIG_CRYPTO_GCM is not set
1155# CONFIG_CRYPTO_SEQIV is not set
1156
1157#
1158# Block modes
1159#
1160CONFIG_CRYPTO_CBC=y
1161# CONFIG_CRYPTO_CTR is not set
1162# CONFIG_CRYPTO_CTS is not set
1163CONFIG_CRYPTO_ECB=y
1164# CONFIG_CRYPTO_LRW is not set
1165CONFIG_CRYPTO_PCBC=y
1166# CONFIG_CRYPTO_XTS is not set
1167
1168#
1169# Hash modes
1170#
1171# CONFIG_CRYPTO_HMAC is not set
1172# CONFIG_CRYPTO_XCBC is not set
1173
1174#
1175# Digest
1176#
1177# CONFIG_CRYPTO_CRC32C is not set
1178# CONFIG_CRYPTO_MD4 is not set
1179CONFIG_CRYPTO_MD5=y
1180# CONFIG_CRYPTO_MICHAEL_MIC is not set
1181# CONFIG_CRYPTO_SHA1 is not set
1182# CONFIG_CRYPTO_SHA256 is not set
1183# CONFIG_CRYPTO_SHA512 is not set
1184# CONFIG_CRYPTO_TGR192 is not set
1185# CONFIG_CRYPTO_WP512 is not set
1186
1187#
1188# Ciphers
1189#
1190# CONFIG_CRYPTO_AES is not set
1191# CONFIG_CRYPTO_ANUBIS is not set
1192# CONFIG_CRYPTO_ARC4 is not set
1193# CONFIG_CRYPTO_BLOWFISH is not set
1194# CONFIG_CRYPTO_CAMELLIA is not set
1195# CONFIG_CRYPTO_CAST5 is not set
1196# CONFIG_CRYPTO_CAST6 is not set
1197CONFIG_CRYPTO_DES=y
1198# CONFIG_CRYPTO_FCRYPT is not set
1199# CONFIG_CRYPTO_KHAZAD is not set
1200# CONFIG_CRYPTO_SALSA20 is not set
1201# CONFIG_CRYPTO_SEED is not set
1202# CONFIG_CRYPTO_SERPENT is not set
1203# CONFIG_CRYPTO_TEA is not set
1204# CONFIG_CRYPTO_TWOFISH is not set
1205
1206#
1207# Compression
1208#
1209# CONFIG_CRYPTO_DEFLATE is not set
1210# CONFIG_CRYPTO_LZO is not set
1211CONFIG_CRYPTO_HW=y
1212CONFIG_PPC_CLOCK=y
1213CONFIG_PPC_LIB_RHEAP=y
1214# CONFIG_VIRTUALIZATION is not set
diff --git a/arch/powerpc/configs/ps3_defconfig b/arch/powerpc/configs/ps3_defconfig
index 7a64c564f6e6..71d79e428d20 100644
--- a/arch/powerpc/configs/ps3_defconfig
+++ b/arch/powerpc/configs/ps3_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.25-rc6 3# Linux kernel version: 2.6.25
4# Thu Mar 20 11:07:04 2008 4# Mon Apr 28 12:39:10 2008
5# 5#
6CONFIG_PPC64=y 6CONFIG_PPC64=y
7 7
@@ -30,6 +30,9 @@ CONFIG_GENERIC_CLOCKEVENTS=y
30CONFIG_GENERIC_HARDIRQS=y 30CONFIG_GENERIC_HARDIRQS=y
31CONFIG_HAVE_SETUP_PER_CPU_AREA=y 31CONFIG_HAVE_SETUP_PER_CPU_AREA=y
32CONFIG_IRQ_PER_CPU=y 32CONFIG_IRQ_PER_CPU=y
33CONFIG_STACKTRACE_SUPPORT=y
34CONFIG_TRACE_IRQFLAGS_SUPPORT=y
35CONFIG_LOCKDEP_SUPPORT=y
33CONFIG_RWSEM_XCHGADD_ALGORITHM=y 36CONFIG_RWSEM_XCHGADD_ALGORITHM=y
34CONFIG_ARCH_HAS_ILOG2_U32=y 37CONFIG_ARCH_HAS_ILOG2_U32=y
35CONFIG_ARCH_HAS_ILOG2_U64=y 38CONFIG_ARCH_HAS_ILOG2_U64=y
@@ -73,8 +76,6 @@ CONFIG_POSIX_MQUEUE=y
73CONFIG_LOG_BUF_SHIFT=17 76CONFIG_LOG_BUF_SHIFT=17
74# CONFIG_CGROUPS is not set 77# CONFIG_CGROUPS is not set
75# CONFIG_GROUP_SCHED is not set 78# CONFIG_GROUP_SCHED is not set
76# CONFIG_USER_SCHED is not set
77# CONFIG_CGROUP_SCHED is not set
78CONFIG_SYSFS_DEPRECATED=y 79CONFIG_SYSFS_DEPRECATED=y
79CONFIG_SYSFS_DEPRECATED_V2=y 80CONFIG_SYSFS_DEPRECATED_V2=y
80# CONFIG_RELAY is not set 81# CONFIG_RELAY is not set
@@ -161,7 +162,6 @@ CONFIG_PPC_MULTIPLATFORM=y
161# CONFIG_PPC_PMAC is not set 162# CONFIG_PPC_PMAC is not set
162# CONFIG_PPC_MAPLE is not set 163# CONFIG_PPC_MAPLE is not set
163# CONFIG_PPC_PASEMI is not set 164# CONFIG_PPC_PASEMI is not set
164# CONFIG_PPC_CELLEB is not set
165CONFIG_PPC_PS3=y 165CONFIG_PPC_PS3=y
166 166
167# 167#
@@ -181,6 +181,7 @@ CONFIG_PS3_LPM=m
181CONFIG_PPC_CELL=y 181CONFIG_PPC_CELL=y
182# CONFIG_PPC_CELL_NATIVE is not set 182# CONFIG_PPC_CELL_NATIVE is not set
183# CONFIG_PPC_IBM_CELL_BLADE is not set 183# CONFIG_PPC_IBM_CELL_BLADE is not set
184# CONFIG_PPC_CELLEB is not set
184 185
185# 186#
186# Cell Broadband Engine options 187# Cell Broadband Engine options
@@ -205,9 +206,9 @@ CONFIG_SPU_BASE=y
205# 206#
206# Kernel options 207# Kernel options
207# 208#
208# CONFIG_TICK_ONESHOT is not set 209CONFIG_TICK_ONESHOT=y
209# CONFIG_NO_HZ is not set 210# CONFIG_NO_HZ is not set
210# CONFIG_HIGH_RES_TIMERS is not set 211CONFIG_HIGH_RES_TIMERS=y
211CONFIG_GENERIC_CLOCKEVENTS_BUILD=y 212CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
212# CONFIG_HZ_100 is not set 213# CONFIG_HZ_100 is not set
213CONFIG_HZ_250=y 214CONFIG_HZ_250=y
@@ -221,7 +222,6 @@ CONFIG_PREEMPT_NONE=y
221CONFIG_BINFMT_ELF=y 222CONFIG_BINFMT_ELF=y
222CONFIG_COMPAT_BINFMT_ELF=y 223CONFIG_COMPAT_BINFMT_ELF=y
223CONFIG_BINFMT_MISC=y 224CONFIG_BINFMT_MISC=y
224CONFIG_FORCE_MAX_ZONEORDER=13
225# CONFIG_IOMMU_VMERGE is not set 225# CONFIG_IOMMU_VMERGE is not set
226CONFIG_IOMMU_HELPER=y 226CONFIG_IOMMU_HELPER=y
227CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y 227CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
@@ -255,6 +255,7 @@ CONFIG_BOUNCE=y
255CONFIG_ARCH_MEMORY_PROBE=y 255CONFIG_ARCH_MEMORY_PROBE=y
256# CONFIG_PPC_HAS_HASH_64K is not set 256# CONFIG_PPC_HAS_HASH_64K is not set
257# CONFIG_PPC_64K_PAGES is not set 257# CONFIG_PPC_64K_PAGES is not set
258CONFIG_FORCE_MAX_ZONEORDER=13
258# CONFIG_SCHED_SMT is not set 259# CONFIG_SCHED_SMT is not set
259CONFIG_PROC_DEVICETREE=y 260CONFIG_PROC_DEVICETREE=y
260# CONFIG_CMDLINE_BOOL is not set 261# CONFIG_CMDLINE_BOOL is not set
@@ -272,7 +273,9 @@ CONFIG_GENERIC_ISA_DMA=y
272# CONFIG_PCI_SYSCALL is not set 273# CONFIG_PCI_SYSCALL is not set
273# CONFIG_ARCH_SUPPORTS_MSI is not set 274# CONFIG_ARCH_SUPPORTS_MSI is not set
274# CONFIG_PCCARD is not set 275# CONFIG_PCCARD is not set
276CONFIG_PAGE_OFFSET=0xc000000000000000
275CONFIG_KERNEL_START=0xc000000000000000 277CONFIG_KERNEL_START=0xc000000000000000
278CONFIG_PHYSICAL_START=0x00000000
276 279
277# 280#
278# Networking 281# Networking
@@ -292,7 +295,7 @@ CONFIG_XFRM=y
292# CONFIG_XFRM_STATISTICS is not set 295# CONFIG_XFRM_STATISTICS is not set
293# CONFIG_NET_KEY is not set 296# CONFIG_NET_KEY is not set
294CONFIG_INET=y 297CONFIG_INET=y
295# CONFIG_IP_MULTICAST is not set 298CONFIG_IP_MULTICAST=y
296# CONFIG_IP_ADVANCED_ROUTER is not set 299# CONFIG_IP_ADVANCED_ROUTER is not set
297CONFIG_IP_FIB_HASH=y 300CONFIG_IP_FIB_HASH=y
298CONFIG_IP_PNP=y 301CONFIG_IP_PNP=y
@@ -301,6 +304,7 @@ CONFIG_IP_PNP_DHCP=y
301# CONFIG_IP_PNP_RARP is not set 304# CONFIG_IP_PNP_RARP is not set
302# CONFIG_NET_IPIP is not set 305# CONFIG_NET_IPIP is not set
303# CONFIG_NET_IPGRE is not set 306# CONFIG_NET_IPGRE is not set
307# CONFIG_IP_MROUTE is not set
304# CONFIG_ARPD is not set 308# CONFIG_ARPD is not set
305# CONFIG_SYN_COOKIES is not set 309# CONFIG_SYN_COOKIES is not set
306# CONFIG_INET_AH is not set 310# CONFIG_INET_AH is not set
@@ -332,8 +336,10 @@ CONFIG_INET6_XFRM_MODE_TUNNEL=y
332CONFIG_INET6_XFRM_MODE_BEET=y 336CONFIG_INET6_XFRM_MODE_BEET=y
333# CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION is not set 337# CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION is not set
334CONFIG_IPV6_SIT=y 338CONFIG_IPV6_SIT=y
339CONFIG_IPV6_NDISC_NODETYPE=y
335# CONFIG_IPV6_TUNNEL is not set 340# CONFIG_IPV6_TUNNEL is not set
336# CONFIG_IPV6_MULTIPLE_TABLES is not set 341# CONFIG_IPV6_MULTIPLE_TABLES is not set
342# CONFIG_IPV6_MROUTE is not set
337# CONFIG_NETWORK_SECMARK is not set 343# CONFIG_NETWORK_SECMARK is not set
338# CONFIG_NETFILTER is not set 344# CONFIG_NETFILTER is not set
339# CONFIG_IP_DCCP is not set 345# CONFIG_IP_DCCP is not set
@@ -392,8 +398,6 @@ CONFIG_IEEE80211=m
392CONFIG_IEEE80211_CRYPT_WEP=m 398CONFIG_IEEE80211_CRYPT_WEP=m
393CONFIG_IEEE80211_CRYPT_CCMP=m 399CONFIG_IEEE80211_CRYPT_CCMP=m
394CONFIG_IEEE80211_CRYPT_TKIP=m 400CONFIG_IEEE80211_CRYPT_TKIP=m
395CONFIG_IEEE80211_SOFTMAC=m
396# CONFIG_IEEE80211_SOFTMAC_DEBUG is not set
397# CONFIG_RFKILL is not set 401# CONFIG_RFKILL is not set
398# CONFIG_NET_9P is not set 402# CONFIG_NET_9P is not set
399 403
@@ -507,6 +511,7 @@ CONFIG_WLAN_80211=y
507# CONFIG_LIBERTAS is not set 511# CONFIG_LIBERTAS is not set
508# CONFIG_USB_ZD1201 is not set 512# CONFIG_USB_ZD1201 is not set
509# CONFIG_USB_NET_RNDIS_WLAN is not set 513# CONFIG_USB_NET_RNDIS_WLAN is not set
514# CONFIG_IWLWIFI_LEDS is not set
510# CONFIG_HOSTAP is not set 515# CONFIG_HOSTAP is not set
511 516
512# 517#
@@ -578,6 +583,7 @@ CONFIG_INPUT_JOYSTICK=y
578# CONFIG_JOYSTICK_SPACEBALL is not set 583# CONFIG_JOYSTICK_SPACEBALL is not set
579# CONFIG_JOYSTICK_STINGER is not set 584# CONFIG_JOYSTICK_STINGER is not set
580# CONFIG_JOYSTICK_TWIDJOY is not set 585# CONFIG_JOYSTICK_TWIDJOY is not set
586# CONFIG_JOYSTICK_ZHENHUA is not set
581# CONFIG_JOYSTICK_JOYDUMP is not set 587# CONFIG_JOYSTICK_JOYDUMP is not set
582# CONFIG_JOYSTICK_XPAD is not set 588# CONFIG_JOYSTICK_XPAD is not set
583# CONFIG_INPUT_TABLET is not set 589# CONFIG_INPUT_TABLET is not set
@@ -641,6 +647,7 @@ CONFIG_SSB_POSSIBLE=y
641# Multifunction device drivers 647# Multifunction device drivers
642# 648#
643# CONFIG_MFD_SM501 is not set 649# CONFIG_MFD_SM501 is not set
650# CONFIG_HTC_PASIC3 is not set
644 651
645# 652#
646# Multimedia devices 653# Multimedia devices
@@ -761,10 +768,6 @@ CONFIG_SND_PS3_DEFAULT_START_DELAY=2000
761# CONFIG_SND_SOC is not set 768# CONFIG_SND_SOC is not set
762 769
763# 770#
764# SoC Audio support for SuperH
765#
766
767#
768# ALSA SoC audio for Freescale SOCs 771# ALSA SoC audio for Freescale SOCs
769# 772#
770 773
@@ -849,6 +852,7 @@ CONFIG_USB_STORAGE=m
849# CONFIG_USB_STORAGE_ALAUDA is not set 852# CONFIG_USB_STORAGE_ALAUDA is not set
850# CONFIG_USB_STORAGE_ONETOUCH is not set 853# CONFIG_USB_STORAGE_ONETOUCH is not set
851# CONFIG_USB_STORAGE_KARMA is not set 854# CONFIG_USB_STORAGE_KARMA is not set
855# CONFIG_USB_STORAGE_CYPRESS_ATACB is not set
852# CONFIG_USB_LIBUSUAL is not set 856# CONFIG_USB_LIBUSUAL is not set
853 857
854# 858#
@@ -893,10 +897,6 @@ CONFIG_USB_MON=y
893# CONFIG_EDAC is not set 897# CONFIG_EDAC is not set
894# CONFIG_RTC_CLASS is not set 898# CONFIG_RTC_CLASS is not set
895# CONFIG_DMADEVICES is not set 899# CONFIG_DMADEVICES is not set
896
897#
898# Userspace I/O
899#
900# CONFIG_UIO is not set 900# CONFIG_UIO is not set
901 901
902# 902#
@@ -986,7 +986,6 @@ CONFIG_NFS_FS=y
986CONFIG_NFS_V3=y 986CONFIG_NFS_V3=y
987# CONFIG_NFS_V3_ACL is not set 987# CONFIG_NFS_V3_ACL is not set
988CONFIG_NFS_V4=y 988CONFIG_NFS_V4=y
989# CONFIG_NFS_DIRECTIO is not set
990# CONFIG_NFSD is not set 989# CONFIG_NFSD is not set
991CONFIG_ROOT_NFS=y 990CONFIG_ROOT_NFS=y
992CONFIG_LOCKD=y 991CONFIG_LOCKD=y
@@ -1059,9 +1058,10 @@ CONFIG_NLS_ISO8859_1=y
1059# Library routines 1058# Library routines
1060# 1059#
1061CONFIG_BITREVERSE=y 1060CONFIG_BITREVERSE=y
1061# CONFIG_GENERIC_FIND_FIRST_BIT is not set
1062# CONFIG_CRC_CCITT is not set 1062# CONFIG_CRC_CCITT is not set
1063# CONFIG_CRC16 is not set 1063# CONFIG_CRC16 is not set
1064# CONFIG_CRC_ITU_T is not set 1064CONFIG_CRC_ITU_T=m
1065CONFIG_CRC32=y 1065CONFIG_CRC32=y
1066# CONFIG_CRC7 is not set 1066# CONFIG_CRC7 is not set
1067# CONFIG_LIBCRC32C is not set 1067# CONFIG_LIBCRC32C is not set
@@ -1071,6 +1071,7 @@ CONFIG_PLIST=y
1071CONFIG_HAS_IOMEM=y 1071CONFIG_HAS_IOMEM=y
1072CONFIG_HAS_IOPORT=y 1072CONFIG_HAS_IOPORT=y
1073CONFIG_HAS_DMA=y 1073CONFIG_HAS_DMA=y
1074CONFIG_HAVE_LMB=y
1074 1075
1075# 1076#
1076# Kernel hacking 1077# Kernel hacking
@@ -1078,6 +1079,7 @@ CONFIG_HAS_DMA=y
1078# CONFIG_PRINTK_TIME is not set 1079# CONFIG_PRINTK_TIME is not set
1079CONFIG_ENABLE_WARN_DEPRECATED=y 1080CONFIG_ENABLE_WARN_DEPRECATED=y
1080CONFIG_ENABLE_MUST_CHECK=y 1081CONFIG_ENABLE_MUST_CHECK=y
1082CONFIG_FRAME_WARN=2048
1081CONFIG_MAGIC_SYSRQ=y 1083CONFIG_MAGIC_SYSRQ=y
1082# CONFIG_UNUSED_SYMBOLS is not set 1084# CONFIG_UNUSED_SYMBOLS is not set
1083# CONFIG_DEBUG_FS is not set 1085# CONFIG_DEBUG_FS is not set
@@ -1093,12 +1095,16 @@ CONFIG_SCHED_DEBUG=y
1093# CONFIG_RT_MUTEX_TESTER is not set 1095# CONFIG_RT_MUTEX_TESTER is not set
1094CONFIG_DEBUG_SPINLOCK=y 1096CONFIG_DEBUG_SPINLOCK=y
1095CONFIG_DEBUG_MUTEXES=y 1097CONFIG_DEBUG_MUTEXES=y
1098# CONFIG_DEBUG_LOCK_ALLOC is not set
1099# CONFIG_PROVE_LOCKING is not set
1100# CONFIG_LOCK_STAT is not set
1096CONFIG_DEBUG_SPINLOCK_SLEEP=y 1101CONFIG_DEBUG_SPINLOCK_SLEEP=y
1097# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set 1102# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
1098# CONFIG_DEBUG_KOBJECT is not set 1103# CONFIG_DEBUG_KOBJECT is not set
1099CONFIG_DEBUG_BUGVERBOSE=y 1104CONFIG_DEBUG_BUGVERBOSE=y
1100CONFIG_DEBUG_INFO=y 1105CONFIG_DEBUG_INFO=y
1101# CONFIG_DEBUG_VM is not set 1106# CONFIG_DEBUG_VM is not set
1107# CONFIG_DEBUG_WRITECOUNT is not set
1102CONFIG_DEBUG_LIST=y 1108CONFIG_DEBUG_LIST=y
1103# CONFIG_DEBUG_SG is not set 1109# CONFIG_DEBUG_SG is not set
1104# CONFIG_BOOT_PRINTK_DELAY is not set 1110# CONFIG_BOOT_PRINTK_DELAY is not set
@@ -1121,51 +1127,81 @@ CONFIG_IRQSTACKS=y
1121# CONFIG_SECURITY is not set 1127# CONFIG_SECURITY is not set
1122# CONFIG_SECURITY_FILE_CAPABILITIES is not set 1128# CONFIG_SECURITY_FILE_CAPABILITIES is not set
1123CONFIG_CRYPTO=y 1129CONFIG_CRYPTO=y
1130
1131#
1132# Crypto core or helper
1133#
1124CONFIG_CRYPTO_ALGAPI=y 1134CONFIG_CRYPTO_ALGAPI=y
1125CONFIG_CRYPTO_AEAD=m 1135CONFIG_CRYPTO_AEAD=m
1126CONFIG_CRYPTO_BLKCIPHER=y 1136CONFIG_CRYPTO_BLKCIPHER=y
1127CONFIG_CRYPTO_SEQIV=m
1128CONFIG_CRYPTO_MANAGER=y 1137CONFIG_CRYPTO_MANAGER=y
1138CONFIG_CRYPTO_GF128MUL=m
1139# CONFIG_CRYPTO_NULL is not set
1140# CONFIG_CRYPTO_CRYPTD is not set
1141# CONFIG_CRYPTO_AUTHENC is not set
1142# CONFIG_CRYPTO_TEST is not set
1143
1144#
1145# Authenticated Encryption with Associated Data
1146#
1147CONFIG_CRYPTO_CCM=m
1148CONFIG_CRYPTO_GCM=m
1149CONFIG_CRYPTO_SEQIV=m
1150
1151#
1152# Block modes
1153#
1154CONFIG_CRYPTO_CBC=y
1155CONFIG_CRYPTO_CTR=m
1156# CONFIG_CRYPTO_CTS is not set
1157CONFIG_CRYPTO_ECB=m
1158# CONFIG_CRYPTO_LRW is not set
1159CONFIG_CRYPTO_PCBC=m
1160# CONFIG_CRYPTO_XTS is not set
1161
1162#
1163# Hash modes
1164#
1129# CONFIG_CRYPTO_HMAC is not set 1165# CONFIG_CRYPTO_HMAC is not set
1130# CONFIG_CRYPTO_XCBC is not set 1166# CONFIG_CRYPTO_XCBC is not set
1131# CONFIG_CRYPTO_NULL is not set 1167
1168#
1169# Digest
1170#
1171# CONFIG_CRYPTO_CRC32C is not set
1132# CONFIG_CRYPTO_MD4 is not set 1172# CONFIG_CRYPTO_MD4 is not set
1133CONFIG_CRYPTO_MD5=y 1173CONFIG_CRYPTO_MD5=y
1174CONFIG_CRYPTO_MICHAEL_MIC=m
1134# CONFIG_CRYPTO_SHA1 is not set 1175# CONFIG_CRYPTO_SHA1 is not set
1135# CONFIG_CRYPTO_SHA256 is not set 1176# CONFIG_CRYPTO_SHA256 is not set
1136# CONFIG_CRYPTO_SHA512 is not set 1177# CONFIG_CRYPTO_SHA512 is not set
1137# CONFIG_CRYPTO_WP512 is not set
1138# CONFIG_CRYPTO_TGR192 is not set 1178# CONFIG_CRYPTO_TGR192 is not set
1139CONFIG_CRYPTO_GF128MUL=m 1179# CONFIG_CRYPTO_WP512 is not set
1140CONFIG_CRYPTO_ECB=m 1180
1141CONFIG_CRYPTO_CBC=y 1181#
1142CONFIG_CRYPTO_PCBC=m 1182# Ciphers
1143# CONFIG_CRYPTO_LRW is not set 1183#
1144# CONFIG_CRYPTO_XTS is not set
1145CONFIG_CRYPTO_CTR=m
1146CONFIG_CRYPTO_GCM=m
1147CONFIG_CRYPTO_CCM=m
1148# CONFIG_CRYPTO_CRYPTD is not set
1149CONFIG_CRYPTO_DES=y
1150# CONFIG_CRYPTO_FCRYPT is not set
1151# CONFIG_CRYPTO_BLOWFISH is not set
1152# CONFIG_CRYPTO_TWOFISH is not set
1153# CONFIG_CRYPTO_SERPENT is not set
1154CONFIG_CRYPTO_AES=m 1184CONFIG_CRYPTO_AES=m
1185# CONFIG_CRYPTO_ANUBIS is not set
1186CONFIG_CRYPTO_ARC4=m
1187# CONFIG_CRYPTO_BLOWFISH is not set
1188# CONFIG_CRYPTO_CAMELLIA is not set
1155# CONFIG_CRYPTO_CAST5 is not set 1189# CONFIG_CRYPTO_CAST5 is not set
1156# CONFIG_CRYPTO_CAST6 is not set 1190# CONFIG_CRYPTO_CAST6 is not set
1157# CONFIG_CRYPTO_TEA is not set 1191CONFIG_CRYPTO_DES=y
1158CONFIG_CRYPTO_ARC4=m 1192# CONFIG_CRYPTO_FCRYPT is not set
1159# CONFIG_CRYPTO_KHAZAD is not set 1193# CONFIG_CRYPTO_KHAZAD is not set
1160# CONFIG_CRYPTO_ANUBIS is not set
1161# CONFIG_CRYPTO_SEED is not set
1162CONFIG_CRYPTO_SALSA20=m 1194CONFIG_CRYPTO_SALSA20=m
1195# CONFIG_CRYPTO_SEED is not set
1196# CONFIG_CRYPTO_SERPENT is not set
1197# CONFIG_CRYPTO_TEA is not set
1198# CONFIG_CRYPTO_TWOFISH is not set
1199
1200#
1201# Compression
1202#
1163# CONFIG_CRYPTO_DEFLATE is not set 1203# CONFIG_CRYPTO_DEFLATE is not set
1164CONFIG_CRYPTO_MICHAEL_MIC=m
1165# CONFIG_CRYPTO_CRC32C is not set
1166# CONFIG_CRYPTO_CAMELLIA is not set
1167# CONFIG_CRYPTO_TEST is not set
1168# CONFIG_CRYPTO_AUTHENC is not set
1169CONFIG_CRYPTO_LZO=m 1204CONFIG_CRYPTO_LZO=m
1170CONFIG_CRYPTO_HW=y 1205CONFIG_CRYPTO_HW=y
1171# CONFIG_PPC_CLOCK is not set 1206# CONFIG_PPC_CLOCK is not set
1207# CONFIG_VIRTUALIZATION is not set
diff --git a/arch/powerpc/kernel/machine_kexec.c b/arch/powerpc/kernel/machine_kexec.c
index 2d202f274e73..29a0e039d436 100644
--- a/arch/powerpc/kernel/machine_kexec.c
+++ b/arch/powerpc/kernel/machine_kexec.c
@@ -74,20 +74,20 @@ void __init reserve_crashkernel(void)
74 ret = parse_crashkernel(boot_command_line, lmb_phys_mem_size(), 74 ret = parse_crashkernel(boot_command_line, lmb_phys_mem_size(),
75 &crash_size, &crash_base); 75 &crash_size, &crash_base);
76 if (ret == 0 && crash_size > 0) { 76 if (ret == 0 && crash_size > 0) {
77 if (crash_base == 0)
78 crash_base = KDUMP_KERNELBASE;
79 crashk_res.start = crash_base; 77 crashk_res.start = crash_base;
80 } else { 78 crashk_res.end = crash_base + crash_size - 1;
81 /* handle the device tree */
82 crash_size = crashk_res.end - crashk_res.start + 1;
83 } 79 }
84 80
85 if (crash_size == 0) 81 if (crashk_res.end == crashk_res.start) {
82 crashk_res.start = crashk_res.end = 0;
86 return; 83 return;
84 }
87 85
88 /* We might have got these values via the command line or the 86 /* We might have got these values via the command line or the
89 * device tree, either way sanitise them now. */ 87 * device tree, either way sanitise them now. */
90 88
89 crash_size = crashk_res.end - crashk_res.start + 1;
90
91 if (crashk_res.start != KDUMP_KERNELBASE) 91 if (crashk_res.start != KDUMP_KERNELBASE)
92 printk("Crash kernel location must be 0x%x\n", 92 printk("Crash kernel location must be 0x%x\n",
93 KDUMP_KERNELBASE); 93 KDUMP_KERNELBASE);
diff --git a/arch/powerpc/kernel/ppc_ksyms.c b/arch/powerpc/kernel/ppc_ksyms.c
index 09fcb50c45ae..cf6b5a7d8b3f 100644
--- a/arch/powerpc/kernel/ppc_ksyms.c
+++ b/arch/powerpc/kernel/ppc_ksyms.c
@@ -133,9 +133,6 @@ EXPORT_SYMBOL(adb_try_handler_change);
133EXPORT_SYMBOL(cuda_request); 133EXPORT_SYMBOL(cuda_request);
134EXPORT_SYMBOL(cuda_poll); 134EXPORT_SYMBOL(cuda_poll);
135#endif /* CONFIG_ADB_CUDA */ 135#endif /* CONFIG_ADB_CUDA */
136#ifdef CONFIG_VT
137EXPORT_SYMBOL(kd_mksound);
138#endif
139EXPORT_SYMBOL(to_tm); 136EXPORT_SYMBOL(to_tm);
140 137
141#ifdef CONFIG_PPC32 138#ifdef CONFIG_PPC32
diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index dff6308d1b5e..25e3fd8606ab 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -487,9 +487,12 @@ static void __init emergency_stack_init(void)
487 */ 487 */
488 limit = min(0x10000000UL, lmb.rmo_size); 488 limit = min(0x10000000UL, lmb.rmo_size);
489 489
490 for_each_possible_cpu(i) 490 for_each_possible_cpu(i) {
491 paca[i].emergency_sp = 491 unsigned long sp;
492 __va(lmb_alloc_base(HW_PAGE_SIZE, 128, limit)) + HW_PAGE_SIZE; 492 sp = lmb_alloc_base(THREAD_SIZE, THREAD_SIZE, limit);
493 sp += THREAD_SIZE;
494 paca[i].emergency_sp = __va(sp);
495 }
493} 496}
494 497
495/* 498/*
diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index be35ffae10f0..1457aa0a08f1 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -386,6 +386,8 @@ static void __init smp_create_idle(unsigned int cpu)
386 panic("failed fork for CPU %u: %li", cpu, PTR_ERR(p)); 386 panic("failed fork for CPU %u: %li", cpu, PTR_ERR(p));
387#ifdef CONFIG_PPC64 387#ifdef CONFIG_PPC64
388 paca[cpu].__current = p; 388 paca[cpu].__current = p;
389 paca[cpu].kstack = (unsigned long) task_thread_info(p)
390 + THREAD_SIZE - STACK_FRAME_OVERHEAD;
389#endif 391#endif
390 current_set[cpu] = task_thread_info(p); 392 current_set[cpu] = task_thread_info(p);
391 task_thread_info(p)->cpu = cpu; 393 task_thread_info(p)->cpu = cpu;
diff --git a/arch/powerpc/kernel/syscalls.c b/arch/powerpc/kernel/syscalls.c
index e722a4eeb5d0..4fe69ca24481 100644
--- a/arch/powerpc/kernel/syscalls.c
+++ b/arch/powerpc/kernel/syscalls.c
@@ -136,23 +136,6 @@ int sys_ipc(uint call, int first, unsigned long second, long third,
136 return ret; 136 return ret;
137} 137}
138 138
139/*
140 * sys_pipe() is the normal C calling standard for creating
141 * a pipe. It's not the way unix traditionally does this, though.
142 */
143int sys_pipe(int __user *fildes)
144{
145 int fd[2];
146 int error;
147
148 error = do_pipe(fd);
149 if (!error) {
150 if (copy_to_user(fildes, fd, 2*sizeof(int)))
151 error = -EFAULT;
152 }
153 return error;
154}
155
156static inline unsigned long do_mmap2(unsigned long addr, size_t len, 139static inline unsigned long do_mmap2(unsigned long addr, size_t len,
157 unsigned long prot, unsigned long flags, 140 unsigned long prot, unsigned long flags,
158 unsigned long fd, unsigned long off, int shift) 141 unsigned long fd, unsigned long off, int shift)
diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 3b26fbd6bec9..73401e83739a 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -149,7 +149,7 @@ EXPORT_SYMBOL(tb_ticks_per_sec); /* for cputime_t conversions */
149u64 tb_to_xs; 149u64 tb_to_xs;
150unsigned tb_to_us; 150unsigned tb_to_us;
151 151
152#define TICKLEN_SCALE TICK_LENGTH_SHIFT 152#define TICKLEN_SCALE NTP_SCALE_SHIFT
153u64 last_tick_len; /* units are ns / 2^TICKLEN_SCALE */ 153u64 last_tick_len; /* units are ns / 2^TICKLEN_SCALE */
154u64 ticklen_to_xs; /* 0.64 fraction */ 154u64 ticklen_to_xs; /* 0.64 fraction */
155 155
@@ -1007,8 +1007,6 @@ void __init time_init(void)
1007 vdso_data->stamp_xsec = (u64) xtime.tv_sec * XSEC_PER_SEC; 1007 vdso_data->stamp_xsec = (u64) xtime.tv_sec * XSEC_PER_SEC;
1008 vdso_data->tb_to_xs = tb_to_xs; 1008 vdso_data->tb_to_xs = tb_to_xs;
1009 1009
1010 time_freq = 0;
1011
1012 write_sequnlock_irqrestore(&xtime_lock, flags); 1010 write_sequnlock_irqrestore(&xtime_lock, flags);
1013 1011
1014 /* Register the clocksource, if we're not running on iSeries */ 1012 /* Register the clocksource, if we're not running on iSeries */
diff --git a/arch/powerpc/kvm/booke_guest.c b/arch/powerpc/kvm/booke_guest.c
index 6d9884a6884a..712d89a28c46 100644
--- a/arch/powerpc/kvm/booke_guest.c
+++ b/arch/powerpc/kvm/booke_guest.c
@@ -49,6 +49,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
49 { "inst_emu", VCPU_STAT(emulated_inst_exits) }, 49 { "inst_emu", VCPU_STAT(emulated_inst_exits) },
50 { "dec", VCPU_STAT(dec_exits) }, 50 { "dec", VCPU_STAT(dec_exits) },
51 { "ext_intr", VCPU_STAT(ext_intr_exits) }, 51 { "ext_intr", VCPU_STAT(ext_intr_exits) },
52 { "halt_wakeup", VCPU_STAT(halt_wakeup) },
52 { NULL } 53 { NULL }
53}; 54};
54 55
@@ -338,6 +339,11 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
338 } 339 }
339 break; 340 break;
340 341
342 case BOOKE_INTERRUPT_FP_UNAVAIL:
343 kvmppc_queue_exception(vcpu, exit_nr);
344 r = RESUME_GUEST;
345 break;
346
341 case BOOKE_INTERRUPT_DATA_STORAGE: 347 case BOOKE_INTERRUPT_DATA_STORAGE:
342 vcpu->arch.dear = vcpu->arch.fault_dear; 348 vcpu->arch.dear = vcpu->arch.fault_dear;
343 vcpu->arch.esr = vcpu->arch.fault_esr; 349 vcpu->arch.esr = vcpu->arch.fault_esr;
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index bad40bd2d3ac..777e0f34e0ea 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -36,13 +36,12 @@ gfn_t unalias_gfn(struct kvm *kvm, gfn_t gfn)
36 36
37int kvm_cpu_has_interrupt(struct kvm_vcpu *v) 37int kvm_cpu_has_interrupt(struct kvm_vcpu *v)
38{ 38{
39 /* XXX implement me */ 39 return !!(v->arch.pending_exceptions);
40 return 0;
41} 40}
42 41
43int kvm_arch_vcpu_runnable(struct kvm_vcpu *v) 42int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
44{ 43{
45 return 1; 44 return !(v->arch.msr & MSR_WE);
46} 45}
47 46
48 47
@@ -214,6 +213,11 @@ static void kvmppc_decrementer_func(unsigned long data)
214 struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data; 213 struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data;
215 214
216 kvmppc_queue_exception(vcpu, BOOKE_INTERRUPT_DECREMENTER); 215 kvmppc_queue_exception(vcpu, BOOKE_INTERRUPT_DECREMENTER);
216
217 if (waitqueue_active(&vcpu->wq)) {
218 wake_up_interruptible(&vcpu->wq);
219 vcpu->stat.halt_wakeup++;
220 }
217} 221}
218 222
219int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu) 223int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
@@ -339,6 +343,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
339 int r; 343 int r;
340 sigset_t sigsaved; 344 sigset_t sigsaved;
341 345
346 vcpu_load(vcpu);
347
342 if (vcpu->sigset_active) 348 if (vcpu->sigset_active)
343 sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved); 349 sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved);
344 350
@@ -363,12 +369,20 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
363 if (vcpu->sigset_active) 369 if (vcpu->sigset_active)
364 sigprocmask(SIG_SETMASK, &sigsaved, NULL); 370 sigprocmask(SIG_SETMASK, &sigsaved, NULL);
365 371
372 vcpu_put(vcpu);
373
366 return r; 374 return r;
367} 375}
368 376
369int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, struct kvm_interrupt *irq) 377int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu, struct kvm_interrupt *irq)
370{ 378{
371 kvmppc_queue_exception(vcpu, BOOKE_INTERRUPT_EXTERNAL); 379 kvmppc_queue_exception(vcpu, BOOKE_INTERRUPT_EXTERNAL);
380
381 if (waitqueue_active(&vcpu->wq)) {
382 wake_up_interruptible(&vcpu->wq);
383 vcpu->stat.halt_wakeup++;
384 }
385
372 return 0; 386 return 0;
373} 387}
374 388
diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
index 4bb023f4c869..f1d2cdc5331b 100644
--- a/arch/powerpc/lib/Makefile
+++ b/arch/powerpc/lib/Makefile
@@ -23,3 +23,4 @@ obj-$(CONFIG_SMP) += locks.o
23endif 23endif
24 24
25obj-$(CONFIG_PPC_LIB_RHEAP) += rheap.o 25obj-$(CONFIG_PPC_LIB_RHEAP) += rheap.o
26obj-$(CONFIG_HAS_IOMEM) += devres.o
diff --git a/arch/powerpc/lib/devres.c b/arch/powerpc/lib/devres.c
new file mode 100644
index 000000000000..292115d98ea9
--- /dev/null
+++ b/arch/powerpc/lib/devres.c
@@ -0,0 +1,42 @@
1/*
2 * Copyright (C) 2008 Freescale Semiconductor, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 */
9
10#include <linux/device.h> /* devres_*(), devm_ioremap_release() */
11#include <linux/io.h> /* ioremap_flags() */
12#include <linux/module.h> /* EXPORT_SYMBOL() */
13
14/**
15 * devm_ioremap_prot - Managed ioremap_flags()
16 * @dev: Generic device to remap IO address for
17 * @offset: BUS offset to map
18 * @size: Size of map
19 * @flags: Page flags
20 *
21 * Managed ioremap_prot(). Map is automatically unmapped on driver
22 * detach.
23 */
24void __iomem *devm_ioremap_prot(struct device *dev, resource_size_t offset,
25 size_t size, unsigned long flags)
26{
27 void __iomem **ptr, *addr;
28
29 ptr = devres_alloc(devm_ioremap_release, sizeof(*ptr), GFP_KERNEL);
30 if (!ptr)
31 return NULL;
32
33 addr = ioremap_flags(offset, size, flags);
34 if (addr) {
35 *ptr = addr;
36 devres_add(dev, ptr);
37 } else
38 devres_free(ptr);
39
40 return addr;
41}
42EXPORT_SYMBOL(devm_ioremap_prot);
diff --git a/arch/powerpc/mm/slb.c b/arch/powerpc/mm/slb.c
index 906daeda59a8..cf8705e32d60 100644
--- a/arch/powerpc/mm/slb.c
+++ b/arch/powerpc/mm/slb.c
@@ -30,7 +30,7 @@
30#ifdef DEBUG 30#ifdef DEBUG
31#define DBG(fmt...) udbg_printf(fmt) 31#define DBG(fmt...) udbg_printf(fmt)
32#else 32#else
33#define DBG(fmt...) 33#define DBG pr_debug
34#endif 34#endif
35 35
36extern void slb_allocate_realmode(unsigned long ea); 36extern void slb_allocate_realmode(unsigned long ea);
@@ -44,13 +44,13 @@ static void slb_allocate(unsigned long ea)
44 slb_allocate_realmode(ea); 44 slb_allocate_realmode(ea);
45} 45}
46 46
47#define slb_esid_mask(ssize) \
48 (((ssize) == MMU_SEGSIZE_256M)? ESID_MASK: ESID_MASK_1T)
49
47static inline unsigned long mk_esid_data(unsigned long ea, int ssize, 50static inline unsigned long mk_esid_data(unsigned long ea, int ssize,
48 unsigned long slot) 51 unsigned long slot)
49{ 52{
50 unsigned long mask; 53 return (ea & slb_esid_mask(ssize)) | SLB_ESID_V | slot;
51
52 mask = (ssize == MMU_SEGSIZE_256M)? ESID_MASK: ESID_MASK_1T;
53 return (ea & mask) | SLB_ESID_V | slot;
54} 54}
55 55
56#define slb_vsid_shift(ssize) \ 56#define slb_vsid_shift(ssize) \
@@ -279,8 +279,8 @@ void slb_initialize(void)
279 patch_slb_encoding(slb_compare_rr_to_size, 279 patch_slb_encoding(slb_compare_rr_to_size,
280 mmu_slb_size); 280 mmu_slb_size);
281 281
282 DBG("SLB: linear LLP = %04x\n", linear_llp); 282 DBG("SLB: linear LLP = %04lx\n", linear_llp);
283 DBG("SLB: io LLP = %04x\n", io_llp); 283 DBG("SLB: io LLP = %04lx\n", io_llp);
284 } 284 }
285 285
286 get_paca()->stab_rr = SLB_NUM_BOLTED; 286 get_paca()->stab_rr = SLB_NUM_BOLTED;
@@ -301,11 +301,16 @@ void slb_initialize(void)
301 301
302 create_shadowed_slbe(VMALLOC_START, mmu_kernel_ssize, vflags, 1); 302 create_shadowed_slbe(VMALLOC_START, mmu_kernel_ssize, vflags, 1);
303 303
304 /* For the boot cpu, we're running on the stack in init_thread_union,
305 * which is in the first segment of the linear mapping, and also
306 * get_paca()->kstack hasn't been initialized yet.
307 * For secondary cpus, we need to bolt the kernel stack entry now.
308 */
304 slb_shadow_clear(2); 309 slb_shadow_clear(2);
310 if (raw_smp_processor_id() != boot_cpuid &&
311 (get_paca()->kstack & slb_esid_mask(mmu_kernel_ssize)) > PAGE_OFFSET)
312 create_shadowed_slbe(get_paca()->kstack,
313 mmu_kernel_ssize, lflags, 2);
305 314
306 /* We don't bolt the stack for the time being - we're in boot,
307 * so the stack is in the bolted segment. By the time it goes
308 * elsewhere, we'll call _switch() which will bolt in the new
309 * one. */
310 asm volatile("isync":::"memory"); 315 asm volatile("isync":::"memory");
311} 316}
diff --git a/arch/powerpc/platforms/52xx/Kconfig b/arch/powerpc/platforms/52xx/Kconfig
index cf945d55c276..acd2fc8cf492 100644
--- a/arch/powerpc/platforms/52xx/Kconfig
+++ b/arch/powerpc/platforms/52xx/Kconfig
@@ -44,3 +44,9 @@ config PPC_MPC5200_BUGFIX
44 44
45 It is safe to say 'Y' here 45 It is safe to say 'Y' here
46 46
47config PPC_MPC5200_GPIO
48 bool "MPC5200 GPIO support"
49 depends on PPC_MPC52xx
50 select HAVE_GPIO_LIB
51 help
52 Enable gpiolib support for mpc5200 based boards
diff --git a/arch/powerpc/platforms/52xx/Makefile b/arch/powerpc/platforms/52xx/Makefile
index fe1b81bb5224..daf0e1568d6d 100644
--- a/arch/powerpc/platforms/52xx/Makefile
+++ b/arch/powerpc/platforms/52xx/Makefile
@@ -14,3 +14,5 @@ obj-$(CONFIG_PM) += mpc52xx_sleep.o mpc52xx_pm.o
14ifeq ($(CONFIG_PPC_LITE5200),y) 14ifeq ($(CONFIG_PPC_LITE5200),y)
15 obj-$(CONFIG_PM) += lite5200_sleep.o lite5200_pm.o 15 obj-$(CONFIG_PM) += lite5200_sleep.o lite5200_pm.o
16endif 16endif
17
18obj-$(CONFIG_PPC_MPC5200_GPIO) += mpc52xx_gpio.o \ No newline at end of file
diff --git a/arch/powerpc/platforms/52xx/mpc5200_simple.c b/arch/powerpc/platforms/52xx/mpc5200_simple.c
index c48b82bc2aad..a3bda0b9f1ff 100644
--- a/arch/powerpc/platforms/52xx/mpc5200_simple.c
+++ b/arch/powerpc/platforms/52xx/mpc5200_simple.c
@@ -51,6 +51,7 @@ static void __init mpc5200_simple_setup_arch(void)
51/* list of the supported boards */ 51/* list of the supported boards */
52static char *board[] __initdata = { 52static char *board[] __initdata = {
53 "promess,motionpro", 53 "promess,motionpro",
54 "phytec,pcm030",
54 "schindler,cm5200", 55 "schindler,cm5200",
55 "tqc,tqm5200", 56 "tqc,tqm5200",
56 NULL 57 NULL
diff --git a/arch/powerpc/platforms/52xx/mpc52xx_gpio.c b/arch/powerpc/platforms/52xx/mpc52xx_gpio.c
new file mode 100644
index 000000000000..48da5dfe4856
--- /dev/null
+++ b/arch/powerpc/platforms/52xx/mpc52xx_gpio.c
@@ -0,0 +1,465 @@
1/*
2 * MPC52xx gpio driver
3 *
4 * Copyright (c) 2008 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation.
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/of.h>
21#include <linux/kernel.h>
22#include <linux/of_gpio.h>
23#include <linux/io.h>
24#include <linux/of_platform.h>
25
26#include <asm/gpio.h>
27#include <asm/mpc52xx.h>
28#include <sysdev/fsl_soc.h>
29
30static DEFINE_SPINLOCK(gpio_lock);
31
32struct mpc52xx_gpiochip {
33 struct of_mm_gpio_chip mmchip;
34 unsigned int shadow_dvo;
35 unsigned int shadow_gpioe;
36 unsigned int shadow_ddr;
37};
38
39/*
40 * GPIO LIB API implementation for wakeup GPIOs.
41 *
42 * There's a maximum of 8 wakeup GPIOs. Which of these are available
43 * for use depends on your board setup.
44 *
45 * 0 -> GPIO_WKUP_7
46 * 1 -> GPIO_WKUP_6
47 * 2 -> PSC6_1
48 * 3 -> PSC6_0
49 * 4 -> ETH_17
50 * 5 -> PSC3_9
51 * 6 -> PSC2_4
52 * 7 -> PSC1_4
53 *
54 */
55static int mpc52xx_wkup_gpio_get(struct gpio_chip *gc, unsigned int gpio)
56{
57 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
58 struct mpc52xx_gpio_wkup __iomem *regs = mm_gc->regs;
59 unsigned int ret;
60
61 ret = (in_8(&regs->wkup_ival) >> (7 - gpio)) & 1;
62
63 pr_debug("%s: gpio: %d ret: %d\n", __func__, gpio, ret);
64
65 return ret;
66}
67
68static inline void
69__mpc52xx_wkup_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
70{
71 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
72 struct mpc52xx_gpiochip *chip = container_of(mm_gc,
73 struct mpc52xx_gpiochip, mmchip);
74 struct mpc52xx_gpio_wkup __iomem *regs = mm_gc->regs;
75
76 if (val)
77 chip->shadow_dvo |= 1 << (7 - gpio);
78 else
79 chip->shadow_dvo &= ~(1 << (7 - gpio));
80
81 out_8(&regs->wkup_dvo, chip->shadow_dvo);
82}
83
84static void
85mpc52xx_wkup_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
86{
87 unsigned long flags;
88
89 spin_lock_irqsave(&gpio_lock, flags);
90
91 __mpc52xx_wkup_gpio_set(gc, gpio, val);
92
93 spin_unlock_irqrestore(&gpio_lock, flags);
94
95 pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val);
96}
97
98static int mpc52xx_wkup_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
99{
100 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
101 struct mpc52xx_gpiochip *chip = container_of(mm_gc,
102 struct mpc52xx_gpiochip, mmchip);
103 struct mpc52xx_gpio_wkup *regs = mm_gc->regs;
104 unsigned long flags;
105
106 spin_lock_irqsave(&gpio_lock, flags);
107
108 /* set the direction */
109 chip->shadow_ddr &= ~(1 << (7 - gpio));
110 out_8(&regs->wkup_ddr, chip->shadow_ddr);
111
112 /* and enable the pin */
113 chip->shadow_gpioe |= 1 << (7 - gpio);
114 out_8(&regs->wkup_gpioe, chip->shadow_gpioe);
115
116 spin_unlock_irqrestore(&gpio_lock, flags);
117
118 return 0;
119}
120
121static int
122mpc52xx_wkup_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
123{
124 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
125 struct mpc52xx_gpio_wkup *regs = mm_gc->regs;
126 struct mpc52xx_gpiochip *chip = container_of(mm_gc,
127 struct mpc52xx_gpiochip, mmchip);
128 unsigned long flags;
129
130 spin_lock_irqsave(&gpio_lock, flags);
131
132 __mpc52xx_wkup_gpio_set(gc, gpio, val);
133
134 /* Then set direction */
135 chip->shadow_ddr |= 1 << (7 - gpio);
136 out_8(&regs->wkup_ddr, chip->shadow_ddr);
137
138 /* Finally enable the pin */
139 chip->shadow_gpioe |= 1 << (7 - gpio);
140 out_8(&regs->wkup_gpioe, chip->shadow_gpioe);
141
142 spin_unlock_irqrestore(&gpio_lock, flags);
143
144 pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val);
145
146 return 0;
147}
148
149static int __devinit mpc52xx_wkup_gpiochip_probe(struct of_device *ofdev,
150 const struct of_device_id *match)
151{
152 struct mpc52xx_gpiochip *chip;
153 struct mpc52xx_gpio_wkup *regs;
154 struct of_gpio_chip *ofchip;
155 int ret;
156
157 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
158 if (!chip)
159 return -ENOMEM;
160
161 ofchip = &chip->mmchip.of_gc;
162
163 ofchip->gpio_cells = 2;
164 ofchip->gc.ngpio = 8;
165 ofchip->gc.direction_input = mpc52xx_wkup_gpio_dir_in;
166 ofchip->gc.direction_output = mpc52xx_wkup_gpio_dir_out;
167 ofchip->gc.get = mpc52xx_wkup_gpio_get;
168 ofchip->gc.set = mpc52xx_wkup_gpio_set;
169
170 ret = of_mm_gpiochip_add(ofdev->node, &chip->mmchip);
171 if (ret)
172 return ret;
173
174 regs = chip->mmchip.regs;
175 chip->shadow_gpioe = in_8(&regs->wkup_gpioe);
176 chip->shadow_ddr = in_8(&regs->wkup_ddr);
177 chip->shadow_dvo = in_8(&regs->wkup_dvo);
178
179 return 0;
180}
181
182static int mpc52xx_gpiochip_remove(struct of_device *ofdev)
183{
184 return -EBUSY;
185}
186
187static const struct of_device_id mpc52xx_wkup_gpiochip_match[] = {
188 {
189 .compatible = "fsl,mpc5200-gpio-wkup",
190 },
191 {}
192};
193
194static struct of_platform_driver mpc52xx_wkup_gpiochip_driver = {
195 .name = "gpio_wkup",
196 .match_table = mpc52xx_wkup_gpiochip_match,
197 .probe = mpc52xx_wkup_gpiochip_probe,
198 .remove = mpc52xx_gpiochip_remove,
199};
200
201/*
202 * GPIO LIB API implementation for simple GPIOs
203 *
204 * There's a maximum of 32 simple GPIOs. Which of these are available
205 * for use depends on your board setup.
206 * The numbering reflects the bit numbering in the port registers:
207 *
208 * 0..1 > reserved
209 * 2..3 > IRDA
210 * 4..7 > ETHR
211 * 8..11 > reserved
212 * 12..15 > USB
213 * 16..17 > reserved
214 * 18..23 > PSC3
215 * 24..27 > PSC2
216 * 28..31 > PSC1
217 */
218static int mpc52xx_simple_gpio_get(struct gpio_chip *gc, unsigned int gpio)
219{
220 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
221 struct mpc52xx_gpio __iomem *regs = mm_gc->regs;
222 unsigned int ret;
223
224 ret = (in_be32(&regs->simple_ival) >> (31 - gpio)) & 1;
225
226 return ret;
227}
228
229static inline void
230__mpc52xx_simple_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
231{
232 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
233 struct mpc52xx_gpiochip *chip = container_of(mm_gc,
234 struct mpc52xx_gpiochip, mmchip);
235 struct mpc52xx_gpio __iomem *regs = mm_gc->regs;
236
237 if (val)
238 chip->shadow_dvo |= 1 << (31 - gpio);
239 else
240 chip->shadow_dvo &= ~(1 << (31 - gpio));
241 out_be32(&regs->simple_dvo, chip->shadow_dvo);
242}
243
244static void
245mpc52xx_simple_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
246{
247 unsigned long flags;
248
249 spin_lock_irqsave(&gpio_lock, flags);
250
251 __mpc52xx_simple_gpio_set(gc, gpio, val);
252
253 spin_unlock_irqrestore(&gpio_lock, flags);
254
255 pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val);
256}
257
258static int mpc52xx_simple_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
259{
260 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
261 struct mpc52xx_gpiochip *chip = container_of(mm_gc,
262 struct mpc52xx_gpiochip, mmchip);
263 struct mpc52xx_gpio *regs = mm_gc->regs;
264 unsigned long flags;
265
266 spin_lock_irqsave(&gpio_lock, flags);
267
268 /* set the direction */
269 chip->shadow_ddr &= ~(1 << (31 - gpio));
270 out_be32(&regs->simple_ddr, chip->shadow_ddr);
271
272 /* and enable the pin */
273 chip->shadow_gpioe |= 1 << (31 - gpio);
274 out_be32(&regs->simple_gpioe, chip->shadow_gpioe);
275
276 spin_unlock_irqrestore(&gpio_lock, flags);
277
278 return 0;
279}
280
281static int
282mpc52xx_simple_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
283{
284 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
285 struct mpc52xx_gpiochip *chip = container_of(mm_gc,
286 struct mpc52xx_gpiochip, mmchip);
287 struct mpc52xx_gpio *regs = mm_gc->regs;
288 unsigned long flags;
289
290 spin_lock_irqsave(&gpio_lock, flags);
291
292 /* First set initial value */
293 __mpc52xx_simple_gpio_set(gc, gpio, val);
294
295 /* Then set direction */
296 chip->shadow_ddr |= 1 << (31 - gpio);
297 out_be32(&regs->simple_ddr, chip->shadow_ddr);
298
299 /* Finally enable the pin */
300 chip->shadow_gpioe |= 1 << (31 - gpio);
301 out_be32(&regs->simple_gpioe, chip->shadow_gpioe);
302
303 spin_unlock_irqrestore(&gpio_lock, flags);
304
305 pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val);
306
307 return 0;
308}
309
310static int __devinit mpc52xx_simple_gpiochip_probe(struct of_device *ofdev,
311 const struct of_device_id *match)
312{
313 struct mpc52xx_gpiochip *chip;
314 struct of_gpio_chip *ofchip;
315 struct mpc52xx_gpio *regs;
316 int ret;
317
318 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
319 if (!chip)
320 return -ENOMEM;
321
322 ofchip = &chip->mmchip.of_gc;
323
324 ofchip->gpio_cells = 2;
325 ofchip->gc.ngpio = 32;
326 ofchip->gc.direction_input = mpc52xx_simple_gpio_dir_in;
327 ofchip->gc.direction_output = mpc52xx_simple_gpio_dir_out;
328 ofchip->gc.get = mpc52xx_simple_gpio_get;
329 ofchip->gc.set = mpc52xx_simple_gpio_set;
330
331 ret = of_mm_gpiochip_add(ofdev->node, &chip->mmchip);
332 if (ret)
333 return ret;
334
335 regs = chip->mmchip.regs;
336 chip->shadow_gpioe = in_be32(&regs->simple_gpioe);
337 chip->shadow_ddr = in_be32(&regs->simple_ddr);
338 chip->shadow_dvo = in_be32(&regs->simple_dvo);
339
340 return 0;
341}
342
343static const struct of_device_id mpc52xx_simple_gpiochip_match[] = {
344 {
345 .compatible = "fsl,mpc5200-gpio",
346 },
347 {}
348};
349
350static struct of_platform_driver mpc52xx_simple_gpiochip_driver = {
351 .name = "gpio",
352 .match_table = mpc52xx_simple_gpiochip_match,
353 .probe = mpc52xx_simple_gpiochip_probe,
354 .remove = mpc52xx_gpiochip_remove,
355};
356
357/*
358 * GPIO LIB API implementation for gpt GPIOs.
359 *
360 * Each gpt only has a single GPIO.
361 */
362static int mpc52xx_gpt_gpio_get(struct gpio_chip *gc, unsigned int gpio)
363{
364 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
365 struct mpc52xx_gpt __iomem *regs = mm_gc->regs;
366 unsigned int ret;
367
368 return (in_be32(&regs->status) & (1 << (31 - 23))) ? 1 : 0;
369
370 return ret;
371}
372
373static void
374mpc52xx_gpt_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
375{
376 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
377 struct mpc52xx_gpt __iomem *regs = mm_gc->regs;
378
379 if (val)
380 out_be32(&regs->mode, 0x34);
381 else
382 out_be32(&regs->mode, 0x24);
383
384 pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val);
385}
386
387static int mpc52xx_gpt_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
388{
389 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
390 struct mpc52xx_gpt *regs = mm_gc->regs;
391
392 out_be32(&regs->mode, 0x04);
393
394 return 0;
395}
396
397static int
398mpc52xx_gpt_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
399{
400 mpc52xx_gpt_gpio_set(gc, gpio, val);
401 pr_debug("%s: gpio: %d val: %d\n", __func__, gpio, val);
402
403 return 0;
404}
405
406static int __devinit mpc52xx_gpt_gpiochip_probe(struct of_device *ofdev,
407 const struct of_device_id *match)
408{
409 struct of_mm_gpio_chip *mmchip;
410 struct of_gpio_chip *chip;
411
412 mmchip = kzalloc(sizeof(*mmchip), GFP_KERNEL);
413 if (!mmchip)
414 return -ENOMEM;
415
416 chip = &mmchip->of_gc;
417
418 chip->gpio_cells = 2;
419 chip->gc.ngpio = 1;
420 chip->gc.direction_input = mpc52xx_gpt_gpio_dir_in;
421 chip->gc.direction_output = mpc52xx_gpt_gpio_dir_out;
422 chip->gc.get = mpc52xx_gpt_gpio_get;
423 chip->gc.set = mpc52xx_gpt_gpio_set;
424
425 return of_mm_gpiochip_add(ofdev->node, mmchip);
426}
427
428static const struct of_device_id mpc52xx_gpt_gpiochip_match[] = {
429 {
430 .compatible = "fsl,mpc5200-gpt-gpio",
431 },
432 {}
433};
434
435static struct of_platform_driver mpc52xx_gpt_gpiochip_driver = {
436 .name = "gpio_gpt",
437 .match_table = mpc52xx_gpt_gpiochip_match,
438 .probe = mpc52xx_gpt_gpiochip_probe,
439 .remove = mpc52xx_gpiochip_remove,
440};
441
442static int __init mpc52xx_gpio_init(void)
443{
444 if (of_register_platform_driver(&mpc52xx_wkup_gpiochip_driver))
445 printk(KERN_ERR "Unable to register wakeup GPIO driver\n");
446
447 if (of_register_platform_driver(&mpc52xx_simple_gpiochip_driver))
448 printk(KERN_ERR "Unable to register simple GPIO driver\n");
449
450 if (of_register_platform_driver(&mpc52xx_gpt_gpiochip_driver))
451 printk(KERN_ERR "Unable to register gpt GPIO driver\n");
452
453 return 0;
454}
455
456
457/* Make sure we get initialised before anyone else tries to use us */
458subsys_initcall(mpc52xx_gpio_init);
459
460/* No exit call at the moment as we cannot unregister of gpio chips */
461
462MODULE_DESCRIPTION("Freescale MPC52xx gpio driver");
463MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de");
464MODULE_LICENSE("GPL v2");
465
diff --git a/arch/powerpc/platforms/52xx/mpc52xx_pic.c b/arch/powerpc/platforms/52xx/mpc52xx_pic.c
index d0dead8b9a95..8479394e9ab4 100644
--- a/arch/powerpc/platforms/52xx/mpc52xx_pic.c
+++ b/arch/powerpc/platforms/52xx/mpc52xx_pic.c
@@ -18,6 +18,7 @@
18 18
19#undef DEBUG 19#undef DEBUG
20 20
21#include <linux/interrupt.h>
21#include <linux/irq.h> 22#include <linux/irq.h>
22#include <linux/of.h> 23#include <linux/of.h>
23#include <asm/io.h> 24#include <asm/io.h>
@@ -109,11 +110,48 @@ static void mpc52xx_extirq_ack(unsigned int virq)
109 io_be_setbit(&intr->ctrl, 27-l2irq); 110 io_be_setbit(&intr->ctrl, 27-l2irq);
110} 111}
111 112
113static int mpc52xx_extirq_set_type(unsigned int virq, unsigned int flow_type)
114{
115 u32 ctrl_reg, type;
116 int irq;
117 int l2irq;
118
119 irq = irq_map[virq].hwirq;
120 l2irq = (irq & MPC52xx_IRQ_L2_MASK) >> MPC52xx_IRQ_L2_OFFSET;
121
122 pr_debug("%s: irq=%x. l2=%d flow_type=%d\n", __func__, irq, l2irq, flow_type);
123
124 switch (flow_type) {
125 case IRQF_TRIGGER_HIGH:
126 type = 0;
127 break;
128 case IRQF_TRIGGER_RISING:
129 type = 1;
130 break;
131 case IRQF_TRIGGER_FALLING:
132 type = 2;
133 break;
134 case IRQF_TRIGGER_LOW:
135 type = 3;
136 break;
137 default:
138 type = 0;
139 }
140
141 ctrl_reg = in_be32(&intr->ctrl);
142 ctrl_reg &= ~(0x3 << (22 - (l2irq * 2)));
143 ctrl_reg |= (type << (22 - (l2irq * 2)));
144 out_be32(&intr->ctrl, ctrl_reg);
145
146 return 0;
147}
148
112static struct irq_chip mpc52xx_extirq_irqchip = { 149static struct irq_chip mpc52xx_extirq_irqchip = {
113 .typename = " MPC52xx IRQ[0-3] ", 150 .typename = " MPC52xx IRQ[0-3] ",
114 .mask = mpc52xx_extirq_mask, 151 .mask = mpc52xx_extirq_mask,
115 .unmask = mpc52xx_extirq_unmask, 152 .unmask = mpc52xx_extirq_unmask,
116 .ack = mpc52xx_extirq_ack, 153 .ack = mpc52xx_extirq_ack,
154 .set_type = mpc52xx_extirq_set_type,
117}; 155};
118 156
119/* 157/*
diff --git a/arch/powerpc/platforms/cell/spufs/.gitignore b/arch/powerpc/platforms/cell/spufs/.gitignore
new file mode 100644
index 000000000000..a09ee8d84d6c
--- /dev/null
+++ b/arch/powerpc/platforms/cell/spufs/.gitignore
@@ -0,0 +1,2 @@
1spu_save_dump.h
2spu_restore_dump.h
diff --git a/arch/powerpc/platforms/cell/spufs/context.c b/arch/powerpc/platforms/cell/spufs/context.c
index 0ad83aeb70b1..177735f79317 100644
--- a/arch/powerpc/platforms/cell/spufs/context.c
+++ b/arch/powerpc/platforms/cell/spufs/context.c
@@ -78,6 +78,7 @@ void destroy_spu_context(struct kref *kref)
78{ 78{
79 struct spu_context *ctx; 79 struct spu_context *ctx;
80 ctx = container_of(kref, struct spu_context, kref); 80 ctx = container_of(kref, struct spu_context, kref);
81 spu_context_nospu_trace(destroy_spu_context__enter, ctx);
81 mutex_lock(&ctx->state_mutex); 82 mutex_lock(&ctx->state_mutex);
82 spu_deactivate(ctx); 83 spu_deactivate(ctx);
83 mutex_unlock(&ctx->state_mutex); 84 mutex_unlock(&ctx->state_mutex);
@@ -88,6 +89,7 @@ void destroy_spu_context(struct kref *kref)
88 kref_put(ctx->prof_priv_kref, ctx->prof_priv_release); 89 kref_put(ctx->prof_priv_kref, ctx->prof_priv_release);
89 BUG_ON(!list_empty(&ctx->rq)); 90 BUG_ON(!list_empty(&ctx->rq));
90 atomic_dec(&nr_spu_contexts); 91 atomic_dec(&nr_spu_contexts);
92 kfree(ctx->switch_log);
91 kfree(ctx); 93 kfree(ctx);
92} 94}
93 95
@@ -150,6 +152,8 @@ int spu_acquire_saved(struct spu_context *ctx)
150{ 152{
151 int ret; 153 int ret;
152 154
155 spu_context_nospu_trace(spu_acquire_saved__enter, ctx);
156
153 ret = spu_acquire(ctx); 157 ret = spu_acquire(ctx);
154 if (ret) 158 if (ret)
155 return ret; 159 return ret;
diff --git a/arch/powerpc/platforms/cell/spufs/coredump.c b/arch/powerpc/platforms/cell/spufs/coredump.c
index b962c3ab470c..af116aadba10 100644
--- a/arch/powerpc/platforms/cell/spufs/coredump.c
+++ b/arch/powerpc/platforms/cell/spufs/coredump.c
@@ -22,6 +22,7 @@
22 22
23#include <linux/elf.h> 23#include <linux/elf.h>
24#include <linux/file.h> 24#include <linux/file.h>
25#include <linux/fdtable.h>
25#include <linux/fs.h> 26#include <linux/fs.h>
26#include <linux/list.h> 27#include <linux/list.h>
27#include <linux/module.h> 28#include <linux/module.h>
diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
index 08f44d1971ac..80911a373400 100644
--- a/arch/powerpc/platforms/cell/spufs/file.c
+++ b/arch/powerpc/platforms/cell/spufs/file.c
@@ -2386,6 +2386,171 @@ static const struct file_operations spufs_stat_fops = {
2386 .release = single_release, 2386 .release = single_release,
2387}; 2387};
2388 2388
2389static inline int spufs_switch_log_used(struct spu_context *ctx)
2390{
2391 return (ctx->switch_log->head - ctx->switch_log->tail) %
2392 SWITCH_LOG_BUFSIZE;
2393}
2394
2395static inline int spufs_switch_log_avail(struct spu_context *ctx)
2396{
2397 return SWITCH_LOG_BUFSIZE - spufs_switch_log_used(ctx);
2398}
2399
2400static int spufs_switch_log_open(struct inode *inode, struct file *file)
2401{
2402 struct spu_context *ctx = SPUFS_I(inode)->i_ctx;
2403
2404 /*
2405 * We (ab-)use the mapping_lock here because it serves the similar
2406 * purpose for synchronizing open/close elsewhere. Maybe it should
2407 * be renamed eventually.
2408 */
2409 mutex_lock(&ctx->mapping_lock);
2410 if (ctx->switch_log) {
2411 spin_lock(&ctx->switch_log->lock);
2412 ctx->switch_log->head = 0;
2413 ctx->switch_log->tail = 0;
2414 spin_unlock(&ctx->switch_log->lock);
2415 } else {
2416 /*
2417 * We allocate the switch log data structures on first open.
2418 * They will never be free because we assume a context will
2419 * be traced until it goes away.
2420 */
2421 ctx->switch_log = kzalloc(sizeof(struct switch_log) +
2422 SWITCH_LOG_BUFSIZE * sizeof(struct switch_log_entry),
2423 GFP_KERNEL);
2424 if (!ctx->switch_log)
2425 goto out;
2426 spin_lock_init(&ctx->switch_log->lock);
2427 init_waitqueue_head(&ctx->switch_log->wait);
2428 }
2429 mutex_unlock(&ctx->mapping_lock);
2430
2431 return 0;
2432 out:
2433 mutex_unlock(&ctx->mapping_lock);
2434 return -ENOMEM;
2435}
2436
2437static int switch_log_sprint(struct spu_context *ctx, char *tbuf, int n)
2438{
2439 struct switch_log_entry *p;
2440
2441 p = ctx->switch_log->log + ctx->switch_log->tail % SWITCH_LOG_BUFSIZE;
2442
2443 return snprintf(tbuf, n, "%u.%09u %d %u %u %llu\n",
2444 (unsigned int) p->tstamp.tv_sec,
2445 (unsigned int) p->tstamp.tv_nsec,
2446 p->spu_id,
2447 (unsigned int) p->type,
2448 (unsigned int) p->val,
2449 (unsigned long long) p->timebase);
2450}
2451
2452static ssize_t spufs_switch_log_read(struct file *file, char __user *buf,
2453 size_t len, loff_t *ppos)
2454{
2455 struct inode *inode = file->f_path.dentry->d_inode;
2456 struct spu_context *ctx = SPUFS_I(inode)->i_ctx;
2457 int error = 0, cnt = 0;
2458
2459 if (!buf || len < 0)
2460 return -EINVAL;
2461
2462 while (cnt < len) {
2463 char tbuf[128];
2464 int width;
2465
2466 if (file->f_flags & O_NONBLOCK) {
2467 if (spufs_switch_log_used(ctx) <= 0)
2468 return cnt ? cnt : -EAGAIN;
2469 } else {
2470 /* Wait for data in buffer */
2471 error = wait_event_interruptible(ctx->switch_log->wait,
2472 spufs_switch_log_used(ctx) > 0);
2473 if (error)
2474 break;
2475 }
2476
2477 spin_lock(&ctx->switch_log->lock);
2478 if (ctx->switch_log->head == ctx->switch_log->tail) {
2479 /* multiple readers race? */
2480 spin_unlock(&ctx->switch_log->lock);
2481 continue;
2482 }
2483
2484 width = switch_log_sprint(ctx, tbuf, sizeof(tbuf));
2485 if (width < len) {
2486 ctx->switch_log->tail =
2487 (ctx->switch_log->tail + 1) %
2488 SWITCH_LOG_BUFSIZE;
2489 }
2490
2491 spin_unlock(&ctx->switch_log->lock);
2492
2493 /*
2494 * If the record is greater than space available return
2495 * partial buffer (so far)
2496 */
2497 if (width >= len)
2498 break;
2499
2500 error = copy_to_user(buf + cnt, tbuf, width);
2501 if (error)
2502 break;
2503 cnt += width;
2504 }
2505
2506 return cnt == 0 ? error : cnt;
2507}
2508
2509static unsigned int spufs_switch_log_poll(struct file *file, poll_table *wait)
2510{
2511 struct inode *inode = file->f_path.dentry->d_inode;
2512 struct spu_context *ctx = SPUFS_I(inode)->i_ctx;
2513 unsigned int mask = 0;
2514
2515 poll_wait(file, &ctx->switch_log->wait, wait);
2516
2517 if (spufs_switch_log_used(ctx) > 0)
2518 mask |= POLLIN;
2519
2520 return mask;
2521}
2522
2523static const struct file_operations spufs_switch_log_fops = {
2524 .owner = THIS_MODULE,
2525 .open = spufs_switch_log_open,
2526 .read = spufs_switch_log_read,
2527 .poll = spufs_switch_log_poll,
2528};
2529
2530void spu_switch_log_notify(struct spu *spu, struct spu_context *ctx,
2531 u32 type, u32 val)
2532{
2533 if (!ctx->switch_log)
2534 return;
2535
2536 spin_lock(&ctx->switch_log->lock);
2537 if (spufs_switch_log_avail(ctx) > 1) {
2538 struct switch_log_entry *p;
2539
2540 p = ctx->switch_log->log + ctx->switch_log->head;
2541 ktime_get_ts(&p->tstamp);
2542 p->timebase = get_tb();
2543 p->spu_id = spu ? spu->number : -1;
2544 p->type = type;
2545 p->val = val;
2546
2547 ctx->switch_log->head =
2548 (ctx->switch_log->head + 1) % SWITCH_LOG_BUFSIZE;
2549 }
2550 spin_unlock(&ctx->switch_log->lock);
2551
2552 wake_up(&ctx->switch_log->wait);
2553}
2389 2554
2390struct tree_descr spufs_dir_contents[] = { 2555struct tree_descr spufs_dir_contents[] = {
2391 { "capabilities", &spufs_caps_fops, 0444, }, 2556 { "capabilities", &spufs_caps_fops, 0444, },
@@ -2422,6 +2587,7 @@ struct tree_descr spufs_dir_contents[] = {
2422 { "proxydma_info", &spufs_proxydma_info_fops, 0444, }, 2587 { "proxydma_info", &spufs_proxydma_info_fops, 0444, },
2423 { "tid", &spufs_tid_fops, 0444, }, 2588 { "tid", &spufs_tid_fops, 0444, },
2424 { "stat", &spufs_stat_fops, 0444, }, 2589 { "stat", &spufs_stat_fops, 0444, },
2590 { "switch_log", &spufs_switch_log_fops, 0444 },
2425 {}, 2591 {},
2426}; 2592};
2427 2593
diff --git a/arch/powerpc/platforms/cell/spufs/run.c b/arch/powerpc/platforms/cell/spufs/run.c
index 96bf7c2b86fc..a9c35b7b719f 100644
--- a/arch/powerpc/platforms/cell/spufs/run.c
+++ b/arch/powerpc/platforms/cell/spufs/run.c
@@ -405,6 +405,8 @@ long spufs_run_spu(struct spu_context *ctx, u32 *npc, u32 *event)
405 ret = spu_run_fini(ctx, npc, &status); 405 ret = spu_run_fini(ctx, npc, &status);
406 spu_yield(ctx); 406 spu_yield(ctx);
407 407
408 spu_switch_log_notify(NULL, ctx, SWITCH_LOG_EXIT, status);
409
408 if ((status & SPU_STATUS_STOPPED_BY_STOP) && 410 if ((status & SPU_STATUS_STOPPED_BY_STOP) &&
409 (((status >> SPU_STOP_STATUS_SHIFT) & 0x3f00) == 0x2100)) 411 (((status >> SPU_STOP_STATUS_SHIFT) & 0x3f00) == 0x2100))
410 ctx->stats.libassist++; 412 ctx->stats.libassist++;
diff --git a/arch/powerpc/platforms/cell/spufs/sched.c b/arch/powerpc/platforms/cell/spufs/sched.c
index 45dcd2693502..7298e7db2c83 100644
--- a/arch/powerpc/platforms/cell/spufs/sched.c
+++ b/arch/powerpc/platforms/cell/spufs/sched.c
@@ -240,6 +240,7 @@ static void spu_bind_context(struct spu *spu, struct spu_context *ctx)
240 spu->mfc_callback = spufs_mfc_callback; 240 spu->mfc_callback = spufs_mfc_callback;
241 mb(); 241 mb();
242 spu_unmap_mappings(ctx); 242 spu_unmap_mappings(ctx);
243 spu_switch_log_notify(spu, ctx, SWITCH_LOG_START, 0);
243 spu_restore(&ctx->csa, spu); 244 spu_restore(&ctx->csa, spu);
244 spu->timestamp = jiffies; 245 spu->timestamp = jiffies;
245 spu_cpu_affinity_set(spu, raw_smp_processor_id()); 246 spu_cpu_affinity_set(spu, raw_smp_processor_id());
@@ -419,6 +420,7 @@ static void spu_unbind_context(struct spu *spu, struct spu_context *ctx)
419 spu_switch_notify(spu, NULL); 420 spu_switch_notify(spu, NULL);
420 spu_unmap_mappings(ctx); 421 spu_unmap_mappings(ctx);
421 spu_save(&ctx->csa, spu); 422 spu_save(&ctx->csa, spu);
423 spu_switch_log_notify(spu, ctx, SWITCH_LOG_STOP, 0);
422 spu->timestamp = jiffies; 424 spu->timestamp = jiffies;
423 ctx->state = SPU_STATE_SAVED; 425 ctx->state = SPU_STATE_SAVED;
424 spu->ibox_callback = NULL; 426 spu->ibox_callback = NULL;
@@ -591,7 +593,7 @@ static struct spu *find_victim(struct spu_context *ctx)
591 struct spu *spu; 593 struct spu *spu;
592 int node, n; 594 int node, n;
593 595
594 spu_context_nospu_trace(spu_find_vitim__enter, ctx); 596 spu_context_nospu_trace(spu_find_victim__enter, ctx);
595 597
596 /* 598 /*
597 * Look for a possible preemption candidate on the local node first. 599 * Look for a possible preemption candidate on the local node first.
diff --git a/arch/powerpc/platforms/cell/spufs/spufs.h b/arch/powerpc/platforms/cell/spufs/spufs.h
index cdc515182f82..7312745b7540 100644
--- a/arch/powerpc/platforms/cell/spufs/spufs.h
+++ b/arch/powerpc/platforms/cell/spufs/spufs.h
@@ -47,6 +47,30 @@ enum {
47 SPU_SCHED_SPU_RUN, /* context is within spu_run */ 47 SPU_SCHED_SPU_RUN, /* context is within spu_run */
48}; 48};
49 49
50enum {
51 SWITCH_LOG_BUFSIZE = 4096,
52};
53
54enum {
55 SWITCH_LOG_START,
56 SWITCH_LOG_STOP,
57 SWITCH_LOG_EXIT,
58};
59
60struct switch_log {
61 spinlock_t lock;
62 wait_queue_head_t wait;
63 unsigned long head;
64 unsigned long tail;
65 struct switch_log_entry {
66 struct timespec tstamp;
67 s32 spu_id;
68 u32 type;
69 u32 val;
70 u64 timebase;
71 } log[];
72};
73
50struct spu_context { 74struct spu_context {
51 struct spu *spu; /* pointer to a physical SPU */ 75 struct spu *spu; /* pointer to a physical SPU */
52 struct spu_state csa; /* SPU context save area. */ 76 struct spu_state csa; /* SPU context save area. */
@@ -116,6 +140,9 @@ struct spu_context {
116 unsigned long long libassist; 140 unsigned long long libassist;
117 } stats; 141 } stats;
118 142
143 /* context switch log */
144 struct switch_log *switch_log;
145
119 struct list_head aff_list; 146 struct list_head aff_list;
120 int aff_head; 147 int aff_head;
121 int aff_offset; 148 int aff_offset;
@@ -256,6 +283,8 @@ int spu_activate(struct spu_context *ctx, unsigned long flags);
256void spu_deactivate(struct spu_context *ctx); 283void spu_deactivate(struct spu_context *ctx);
257void spu_yield(struct spu_context *ctx); 284void spu_yield(struct spu_context *ctx);
258void spu_switch_notify(struct spu *spu, struct spu_context *ctx); 285void spu_switch_notify(struct spu *spu, struct spu_context *ctx);
286void spu_switch_log_notify(struct spu *spu, struct spu_context *ctx,
287 u32 type, u32 val);
259void spu_set_timeslice(struct spu_context *ctx); 288void spu_set_timeslice(struct spu_context *ctx);
260void spu_update_sched_info(struct spu_context *ctx); 289void spu_update_sched_info(struct spu_context *ctx);
261void __spu_update_sched_info(struct spu_context *ctx); 290void __spu_update_sched_info(struct spu_context *ctx);
@@ -330,8 +359,8 @@ extern void spuctx_switch_state(struct spu_context *ctx,
330 enum spu_utilization_state new_state); 359 enum spu_utilization_state new_state);
331 360
332#define spu_context_trace(name, ctx, spu) \ 361#define spu_context_trace(name, ctx, spu) \
333 trace_mark(name, "%p %p", ctx, spu); 362 trace_mark(name, "ctx %p spu %p", ctx, spu);
334#define spu_context_nospu_trace(name, ctx) \ 363#define spu_context_nospu_trace(name, ctx) \
335 trace_mark(name, "%p", ctx); 364 trace_mark(name, "ctx %p", ctx);
336 365
337#endif 366#endif
diff --git a/arch/powerpc/platforms/cell/spufs/sputrace.c b/arch/powerpc/platforms/cell/spufs/sputrace.c
index aea5286f1245..53202422ba72 100644
--- a/arch/powerpc/platforms/cell/spufs/sputrace.c
+++ b/arch/powerpc/platforms/cell/spufs/sputrace.c
@@ -171,24 +171,24 @@ static void spu_context_nospu_event(void *probe_private, void *call_data,
171} 171}
172 172
173struct spu_probe spu_probes[] = { 173struct spu_probe spu_probes[] = {
174 { "spu_bind_context__enter", "%p %p", spu_context_event }, 174 { "spu_bind_context__enter", "ctx %p spu %p", spu_context_event },
175 { "spu_unbind_context__enter", "%p %p", spu_context_event }, 175 { "spu_unbind_context__enter", "ctx %p spu %p", spu_context_event },
176 { "spu_get_idle__enter", "%p", spu_context_nospu_event }, 176 { "spu_get_idle__enter", "ctx %p", spu_context_nospu_event },
177 { "spu_get_idle__found", "%p %p", spu_context_event }, 177 { "spu_get_idle__found", "ctx %p spu %p", spu_context_event },
178 { "spu_get_idle__not_found", "%p", spu_context_nospu_event }, 178 { "spu_get_idle__not_found", "ctx %p", spu_context_nospu_event },
179 { "spu_find_victim__enter", "%p", spu_context_nospu_event }, 179 { "spu_find_victim__enter", "ctx %p", spu_context_nospu_event },
180 { "spusched_tick__preempt", "%p %p", spu_context_event }, 180 { "spusched_tick__preempt", "ctx %p spu %p", spu_context_event },
181 { "spusched_tick__newslice", "%p", spu_context_nospu_event }, 181 { "spusched_tick__newslice", "ctx %p", spu_context_nospu_event },
182 { "spu_yield__enter", "%p", spu_context_nospu_event }, 182 { "spu_yield__enter", "ctx %p", spu_context_nospu_event },
183 { "spu_deactivate__enter", "%p", spu_context_nospu_event }, 183 { "spu_deactivate__enter", "ctx %p", spu_context_nospu_event },
184 { "__spu_deactivate__unload", "%p %p", spu_context_event }, 184 { "__spu_deactivate__unload", "ctx %p spu %p", spu_context_event },
185 { "spufs_ps_nopfn__enter", "%p", spu_context_nospu_event }, 185 { "spufs_ps_nopfn__enter", "ctx %p", spu_context_nospu_event },
186 { "spufs_ps_nopfn__sleep", "%p", spu_context_nospu_event }, 186 { "spufs_ps_nopfn__sleep", "ctx %p", spu_context_nospu_event },
187 { "spufs_ps_nopfn__wake", "%p %p", spu_context_event }, 187 { "spufs_ps_nopfn__wake", "ctx %p spu %p", spu_context_event },
188 { "spufs_ps_nopfn__insert", "%p %p", spu_context_event }, 188 { "spufs_ps_nopfn__insert", "ctx %p spu %p", spu_context_event },
189 { "spu_acquire_saved__enter", "%p", spu_context_nospu_event }, 189 { "spu_acquire_saved__enter", "ctx %p", spu_context_nospu_event },
190 { "destroy_spu_context__enter", "%p", spu_context_nospu_event }, 190 { "destroy_spu_context__enter", "ctx %p", spu_context_nospu_event },
191 { "spufs_stop_callback__enter", "%p %p", spu_context_event }, 191 { "spufs_stop_callback__enter", "ctx %p spu %p", spu_context_event },
192}; 192};
193 193
194static int __init sputrace_init(void) 194static int __init sputrace_init(void)
diff --git a/arch/powerpc/platforms/ps3/interrupt.c b/arch/powerpc/platforms/ps3/interrupt.c
index a14e5cdc2fed..e59634f7af96 100644
--- a/arch/powerpc/platforms/ps3/interrupt.c
+++ b/arch/powerpc/platforms/ps3/interrupt.c
@@ -167,8 +167,8 @@ static struct irq_chip ps3_irq_chip = {
167 * ps3_private data. 167 * ps3_private data.
168 */ 168 */
169 169
170int ps3_virq_setup(enum ps3_cpu_binding cpu, unsigned long outlet, 170static int ps3_virq_setup(enum ps3_cpu_binding cpu, unsigned long outlet,
171 unsigned int *virq) 171 unsigned int *virq)
172{ 172{
173 int result; 173 int result;
174 struct ps3_private *pd; 174 struct ps3_private *pd;
@@ -217,7 +217,7 @@ fail_create:
217 * Clears chip data and calls irq_dispose_mapping() for the virq. 217 * Clears chip data and calls irq_dispose_mapping() for the virq.
218 */ 218 */
219 219
220int ps3_virq_destroy(unsigned int virq) 220static int ps3_virq_destroy(unsigned int virq)
221{ 221{
222 const struct ps3_private *pd = get_irq_chip_data(virq); 222 const struct ps3_private *pd = get_irq_chip_data(virq);
223 223
diff --git a/arch/powerpc/platforms/pseries/scanlog.c b/arch/powerpc/platforms/pseries/scanlog.c
index bec3803f0618..417eca79df69 100644
--- a/arch/powerpc/platforms/pseries/scanlog.c
+++ b/arch/powerpc/platforms/pseries/scanlog.c
@@ -55,11 +55,6 @@ static ssize_t scanlog_read(struct file *file, char __user *buf,
55 dp = PDE(inode); 55 dp = PDE(inode);
56 data = (unsigned int *)dp->data; 56 data = (unsigned int *)dp->data;
57 57
58 if (!data) {
59 printk(KERN_ERR "scanlog: read failed no data\n");
60 return -EIO;
61 }
62
63 if (count > RTAS_DATA_BUF_SIZE) 58 if (count > RTAS_DATA_BUF_SIZE)
64 count = RTAS_DATA_BUF_SIZE; 59 count = RTAS_DATA_BUF_SIZE;
65 60
@@ -146,11 +141,6 @@ static int scanlog_open(struct inode * inode, struct file * file)
146 struct proc_dir_entry *dp = PDE(inode); 141 struct proc_dir_entry *dp = PDE(inode);
147 unsigned int *data = (unsigned int *)dp->data; 142 unsigned int *data = (unsigned int *)dp->data;
148 143
149 if (!data) {
150 printk(KERN_ERR "scanlog: open failed no data\n");
151 return -EIO;
152 }
153
154 if (data[0] != 0) { 144 if (data[0] != 0) {
155 /* This imperfect test stops a second copy of the 145 /* This imperfect test stops a second copy of the
156 * data (or a reset while data is being copied) 146 * data (or a reset while data is being copied)
@@ -168,10 +158,6 @@ static int scanlog_release(struct inode * inode, struct file * file)
168 struct proc_dir_entry *dp = PDE(inode); 158 struct proc_dir_entry *dp = PDE(inode);
169 unsigned int *data = (unsigned int *)dp->data; 159 unsigned int *data = (unsigned int *)dp->data;
170 160
171 if (!data) {
172 printk(KERN_ERR "scanlog: release failed no data\n");
173 return -EIO;
174 }
175 data[0] = 0; 161 data[0] = 0;
176 162
177 return 0; 163 return 0;
@@ -200,12 +186,11 @@ static int __init scanlog_init(void)
200 if (!data) 186 if (!data)
201 goto err; 187 goto err;
202 188
203 ent = proc_create("ppc64/rtas/scan-log-dump", S_IRUSR, NULL, 189 ent = proc_create_data("ppc64/rtas/scan-log-dump", S_IRUSR, NULL,
204 &scanlog_fops); 190 &scanlog_fops, data);
205 if (!ent) 191 if (!ent)
206 goto err; 192 goto err;
207 193
208 ent->data = data;
209 proc_ppc64_scan_log_dump = ent; 194 proc_ppc64_scan_log_dump = ent;
210 195
211 return 0; 196 return 0;
diff --git a/arch/powerpc/sysdev/fsl_rio.c b/arch/powerpc/sysdev/fsl_rio.c
index 3d920376f58e..a0fa4ebb39c6 100644
--- a/arch/powerpc/sysdev/fsl_rio.c
+++ b/arch/powerpc/sysdev/fsl_rio.c
@@ -176,6 +176,7 @@ struct rio_priv {
176 176
177/** 177/**
178 * fsl_rio_doorbell_send - Send a MPC85xx doorbell message 178 * fsl_rio_doorbell_send - Send a MPC85xx doorbell message
179 * @mport: RapidIO master port info
179 * @index: ID of RapidIO interface 180 * @index: ID of RapidIO interface
180 * @destid: Destination ID of target device 181 * @destid: Destination ID of target device
181 * @data: 16-bit info field of RapidIO doorbell message 182 * @data: 16-bit info field of RapidIO doorbell message
@@ -211,6 +212,7 @@ static int fsl_rio_doorbell_send(struct rio_mport *mport,
211 212
212/** 213/**
213 * fsl_local_config_read - Generate a MPC85xx local config space read 214 * fsl_local_config_read - Generate a MPC85xx local config space read
215 * @mport: RapidIO master port info
214 * @index: ID of RapdiIO interface 216 * @index: ID of RapdiIO interface
215 * @offset: Offset into configuration space 217 * @offset: Offset into configuration space
216 * @len: Length (in bytes) of the maintenance transaction 218 * @len: Length (in bytes) of the maintenance transaction
@@ -232,6 +234,7 @@ static int fsl_local_config_read(struct rio_mport *mport,
232 234
233/** 235/**
234 * fsl_local_config_write - Generate a MPC85xx local config space write 236 * fsl_local_config_write - Generate a MPC85xx local config space write
237 * @mport: RapidIO master port info
235 * @index: ID of RapdiIO interface 238 * @index: ID of RapdiIO interface
236 * @offset: Offset into configuration space 239 * @offset: Offset into configuration space
237 * @len: Length (in bytes) of the maintenance transaction 240 * @len: Length (in bytes) of the maintenance transaction
@@ -254,6 +257,7 @@ static int fsl_local_config_write(struct rio_mport *mport,
254 257
255/** 258/**
256 * fsl_rio_config_read - Generate a MPC85xx read maintenance transaction 259 * fsl_rio_config_read - Generate a MPC85xx read maintenance transaction
260 * @mport: RapidIO master port info
257 * @index: ID of RapdiIO interface 261 * @index: ID of RapdiIO interface
258 * @destid: Destination ID of transaction 262 * @destid: Destination ID of transaction
259 * @hopcount: Number of hops to target device 263 * @hopcount: Number of hops to target device
@@ -295,6 +299,7 @@ fsl_rio_config_read(struct rio_mport *mport, int index, u16 destid,
295 299
296/** 300/**
297 * fsl_rio_config_write - Generate a MPC85xx write maintenance transaction 301 * fsl_rio_config_write - Generate a MPC85xx write maintenance transaction
302 * @mport: RapidIO master port info
298 * @index: ID of RapdiIO interface 303 * @index: ID of RapdiIO interface
299 * @destid: Destination ID of transaction 304 * @destid: Destination ID of transaction
300 * @hopcount: Number of hops to target device 305 * @hopcount: Number of hops to target device
@@ -985,8 +990,8 @@ static inline void fsl_rio_info(struct device *dev, u32 ccsr)
985} 990}
986 991
987/** 992/**
988 * fsl_rio_setup - Setup MPC85xx RapidIO interface 993 * fsl_rio_setup - Setup Freescale PowerPC RapidIO interface
989 * @fsl_rio_setup - Setup Freescale PowerPC RapidIO interface 994 * @dev: of_device pointer
990 * 995 *
991 * Initializes MPC85xx RapidIO hardware interface, configures 996 * Initializes MPC85xx RapidIO hardware interface, configures
992 * master port with system-specific info, and registers the 997 * master port with system-specific info, and registers the
diff --git a/arch/powerpc/sysdev/fsl_soc.c b/arch/powerpc/sysdev/fsl_soc.c
index 324c01b70ddd..3a7054e2bb75 100644
--- a/arch/powerpc/sysdev/fsl_soc.c
+++ b/arch/powerpc/sysdev/fsl_soc.c
@@ -389,8 +389,8 @@ static int __init gfar_of_init(void)
389 } 389 }
390 390
391 gfar_data.phy_id = *id; 391 gfar_data.phy_id = *id;
392 snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "%x", 392 snprintf(gfar_data.bus_id, MII_BUS_ID_SIZE, "%llx",
393 res.start); 393 (unsigned long long)res.start);
394 394
395 of_node_put(phy); 395 of_node_put(phy);
396 of_node_put(mdio); 396 of_node_put(mdio);
diff --git a/arch/powerpc/sysdev/xilinx_intc.c b/arch/powerpc/sysdev/xilinx_intc.c
index ba8eea2bcce0..b7aefd0d45cb 100644
--- a/arch/powerpc/sysdev/xilinx_intc.c
+++ b/arch/powerpc/sysdev/xilinx_intc.c
@@ -107,7 +107,7 @@ xilinx_intc_init(struct device_node *np)
107 } 107 }
108 regs = ioremap(res.start, 32); 108 regs = ioremap(res.start, 32);
109 109
110 printk(KERN_INFO "Xilinx intc at 0x%08X mapped to 0x%p\n", 110 printk(KERN_INFO "Xilinx intc at 0x%08LX mapped to 0x%p\n",
111 res.start, regs); 111 res.start, regs);
112 112
113 /* Setup interrupt controller */ 113 /* Setup interrupt controller */
diff --git a/arch/ppc/kernel/ppc_ksyms.c b/arch/ppc/kernel/ppc_ksyms.c
index d9036ef0b658..16ac11ca7ba0 100644
--- a/arch/ppc/kernel/ppc_ksyms.c
+++ b/arch/ppc/kernel/ppc_ksyms.c
@@ -183,9 +183,6 @@ EXPORT_SYMBOL(cuda_poll);
183#if defined(CONFIG_BOOTX_TEXT) 183#if defined(CONFIG_BOOTX_TEXT)
184EXPORT_SYMBOL(btext_update_display); 184EXPORT_SYMBOL(btext_update_display);
185#endif 185#endif
186#ifdef CONFIG_VT
187EXPORT_SYMBOL(kd_mksound);
188#endif
189EXPORT_SYMBOL(to_tm); 186EXPORT_SYMBOL(to_tm);
190 187
191EXPORT_SYMBOL(pm_power_off); 188EXPORT_SYMBOL(pm_power_off);
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 8f5f02160ffc..29a7940f284f 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -300,6 +300,14 @@ comment "Kernel preemption"
300 300
301source "kernel/Kconfig.preempt" 301source "kernel/Kconfig.preempt"
302 302
303config ARCH_SPARSEMEM_ENABLE
304 def_bool y
305 select SPARSEMEM_VMEMMAP_ENABLE
306 select SPARSEMEM_VMEMMAP
307
308config ARCH_SPARSEMEM_DEFAULT
309 def_bool y
310
303source "mm/Kconfig" 311source "mm/Kconfig"
304 312
305comment "I/O subsystem configuration" 313comment "I/O subsystem configuration"
diff --git a/arch/s390/defconfig b/arch/s390/defconfig
index a72f208e62d0..aa341d0ea1e6 100644
--- a/arch/s390/defconfig
+++ b/arch/s390/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.25-rc4 3# Linux kernel version: 2.6.25
4# Wed Mar 5 11:22:59 2008 4# Wed Apr 30 11:07:45 2008
5# 5#
6CONFIG_SCHED_MC=y 6CONFIG_SCHED_MC=y
7CONFIG_MMU=y 7CONFIG_MMU=y
@@ -14,10 +14,12 @@ CONFIG_RWSEM_XCHGADD_ALGORITHM=y
14# CONFIG_ARCH_HAS_ILOG2_U64 is not set 14# CONFIG_ARCH_HAS_ILOG2_U64 is not set
15CONFIG_GENERIC_HWEIGHT=y 15CONFIG_GENERIC_HWEIGHT=y
16CONFIG_GENERIC_TIME=y 16CONFIG_GENERIC_TIME=y
17CONFIG_GENERIC_CLOCKEVENTS=y
17CONFIG_GENERIC_BUG=y 18CONFIG_GENERIC_BUG=y
18CONFIG_NO_IOMEM=y 19CONFIG_NO_IOMEM=y
19CONFIG_NO_DMA=y 20CONFIG_NO_DMA=y
20CONFIG_GENERIC_LOCKBREAK=y 21CONFIG_GENERIC_LOCKBREAK=y
22CONFIG_PGSTE=y
21CONFIG_S390=y 23CONFIG_S390=y
22CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config" 24CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
23 25
@@ -43,6 +45,7 @@ CONFIG_LOG_BUF_SHIFT=17
43CONFIG_CGROUPS=y 45CONFIG_CGROUPS=y
44# CONFIG_CGROUP_DEBUG is not set 46# CONFIG_CGROUP_DEBUG is not set
45CONFIG_CGROUP_NS=y 47CONFIG_CGROUP_NS=y
48# CONFIG_CGROUP_DEVICE is not set
46# CONFIG_CPUSETS is not set 49# CONFIG_CPUSETS is not set
47CONFIG_GROUP_SCHED=y 50CONFIG_GROUP_SCHED=y
48CONFIG_FAIR_GROUP_SCHED=y 51CONFIG_FAIR_GROUP_SCHED=y
@@ -65,6 +68,7 @@ CONFIG_INITRAMFS_SOURCE=""
65CONFIG_SYSCTL=y 68CONFIG_SYSCTL=y
66# CONFIG_EMBEDDED is not set 69# CONFIG_EMBEDDED is not set
67CONFIG_SYSCTL_SYSCALL=y 70CONFIG_SYSCTL_SYSCALL=y
71CONFIG_SYSCTL_SYSCALL_CHECK=y
68CONFIG_KALLSYMS=y 72CONFIG_KALLSYMS=y
69# CONFIG_KALLSYMS_ALL is not set 73# CONFIG_KALLSYMS_ALL is not set
70# CONFIG_KALLSYMS_EXTRA_PASS is not set 74# CONFIG_KALLSYMS_EXTRA_PASS is not set
@@ -92,6 +96,7 @@ CONFIG_KPROBES=y
92CONFIG_KRETPROBES=y 96CONFIG_KRETPROBES=y
93CONFIG_HAVE_KPROBES=y 97CONFIG_HAVE_KPROBES=y
94CONFIG_HAVE_KRETPROBES=y 98CONFIG_HAVE_KRETPROBES=y
99# CONFIG_HAVE_DMA_ATTRS is not set
95CONFIG_PROC_PAGE_MONITOR=y 100CONFIG_PROC_PAGE_MONITOR=y
96CONFIG_SLABINFO=y 101CONFIG_SLABINFO=y
97CONFIG_RT_MUTEXES=y 102CONFIG_RT_MUTEXES=y
@@ -121,8 +126,8 @@ CONFIG_DEFAULT_DEADLINE=y
121# CONFIG_DEFAULT_CFQ is not set 126# CONFIG_DEFAULT_CFQ is not set
122# CONFIG_DEFAULT_NOOP is not set 127# CONFIG_DEFAULT_NOOP is not set
123CONFIG_DEFAULT_IOSCHED="deadline" 128CONFIG_DEFAULT_IOSCHED="deadline"
129CONFIG_PREEMPT_NOTIFIERS=y
124CONFIG_CLASSIC_RCU=y 130CONFIG_CLASSIC_RCU=y
125# CONFIG_PREEMPT_RCU is not set
126 131
127# 132#
128# Base setup 133# Base setup
@@ -131,6 +136,10 @@ CONFIG_CLASSIC_RCU=y
131# 136#
132# Processor type and features 137# Processor type and features
133# 138#
139CONFIG_TICK_ONESHOT=y
140CONFIG_NO_HZ=y
141CONFIG_HIGH_RES_TIMERS=y
142CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
134CONFIG_64BIT=y 143CONFIG_64BIT=y
135CONFIG_SMP=y 144CONFIG_SMP=y
136CONFIG_NR_CPUS=32 145CONFIG_NR_CPUS=32
@@ -161,15 +170,20 @@ CONFIG_ARCH_POPULATES_NODE_MAP=y
161# CONFIG_PREEMPT_NONE is not set 170# CONFIG_PREEMPT_NONE is not set
162# CONFIG_PREEMPT_VOLUNTARY is not set 171# CONFIG_PREEMPT_VOLUNTARY is not set
163CONFIG_PREEMPT=y 172CONFIG_PREEMPT=y
164# CONFIG_RCU_TRACE is not set 173# CONFIG_PREEMPT_RCU is not set
174CONFIG_ARCH_SPARSEMEM_ENABLE=y
175CONFIG_ARCH_SPARSEMEM_DEFAULT=y
165CONFIG_SELECT_MEMORY_MODEL=y 176CONFIG_SELECT_MEMORY_MODEL=y
166CONFIG_FLATMEM_MANUAL=y 177# CONFIG_FLATMEM_MANUAL is not set
167# CONFIG_DISCONTIGMEM_MANUAL is not set 178# CONFIG_DISCONTIGMEM_MANUAL is not set
168# CONFIG_SPARSEMEM_MANUAL is not set 179CONFIG_SPARSEMEM_MANUAL=y
169CONFIG_FLATMEM=y 180CONFIG_SPARSEMEM=y
170CONFIG_FLAT_NODE_MEM_MAP=y 181CONFIG_HAVE_MEMORY_PRESENT=y
171# CONFIG_SPARSEMEM_STATIC is not set 182# CONFIG_SPARSEMEM_STATIC is not set
172# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set 183CONFIG_SPARSEMEM_EXTREME=y
184CONFIG_SPARSEMEM_VMEMMAP_ENABLE=y
185CONFIG_SPARSEMEM_VMEMMAP=y
186CONFIG_PAGEFLAGS_EXTENDED=y
173CONFIG_SPLIT_PTLOCK_CPUS=4 187CONFIG_SPLIT_PTLOCK_CPUS=4
174CONFIG_RESOURCES_64BIT=y 188CONFIG_RESOURCES_64BIT=y
175CONFIG_ZONE_DMA_FLAG=1 189CONFIG_ZONE_DMA_FLAG=1
@@ -205,11 +219,10 @@ CONFIG_HZ_100=y
205# CONFIG_HZ_1000 is not set 219# CONFIG_HZ_1000 is not set
206CONFIG_HZ=100 220CONFIG_HZ=100
207# CONFIG_SCHED_HRTICK is not set 221# CONFIG_SCHED_HRTICK is not set
208CONFIG_NO_IDLE_HZ=y
209CONFIG_NO_IDLE_HZ_INIT=y
210CONFIG_S390_HYPFS_FS=y 222CONFIG_S390_HYPFS_FS=y
211CONFIG_KEXEC=y 223CONFIG_KEXEC=y
212# CONFIG_ZFCPDUMP is not set 224# CONFIG_ZFCPDUMP is not set
225CONFIG_S390_GUEST=y
213 226
214# 227#
215# Networking 228# Networking
@@ -272,8 +285,10 @@ CONFIG_INET6_XFRM_MODE_TUNNEL=y
272CONFIG_INET6_XFRM_MODE_BEET=y 285CONFIG_INET6_XFRM_MODE_BEET=y
273# CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION is not set 286# CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION is not set
274CONFIG_IPV6_SIT=y 287CONFIG_IPV6_SIT=y
288CONFIG_IPV6_NDISC_NODETYPE=y
275# CONFIG_IPV6_TUNNEL is not set 289# CONFIG_IPV6_TUNNEL is not set
276# CONFIG_IPV6_MULTIPLE_TABLES is not set 290# CONFIG_IPV6_MULTIPLE_TABLES is not set
291# CONFIG_IPV6_MROUTE is not set
277# CONFIG_NETWORK_SECMARK is not set 292# CONFIG_NETWORK_SECMARK is not set
278CONFIG_NETFILTER=y 293CONFIG_NETFILTER=y
279# CONFIG_NETFILTER_DEBUG is not set 294# CONFIG_NETFILTER_DEBUG is not set
@@ -289,6 +304,7 @@ CONFIG_NF_CONNTRACK=m
289# CONFIG_NF_CT_ACCT is not set 304# CONFIG_NF_CT_ACCT is not set
290# CONFIG_NF_CONNTRACK_MARK is not set 305# CONFIG_NF_CONNTRACK_MARK is not set
291# CONFIG_NF_CONNTRACK_EVENTS is not set 306# CONFIG_NF_CONNTRACK_EVENTS is not set
307# CONFIG_NF_CT_PROTO_DCCP is not set
292# CONFIG_NF_CT_PROTO_SCTP is not set 308# CONFIG_NF_CT_PROTO_SCTP is not set
293# CONFIG_NF_CT_PROTO_UDPLITE is not set 309# CONFIG_NF_CT_PROTO_UDPLITE is not set
294# CONFIG_NF_CONNTRACK_AMANDA is not set 310# CONFIG_NF_CONNTRACK_AMANDA is not set
@@ -439,6 +455,7 @@ CONFIG_DASD_ECKD=y
439CONFIG_DASD_FBA=y 455CONFIG_DASD_FBA=y
440CONFIG_DASD_DIAG=y 456CONFIG_DASD_DIAG=y
441CONFIG_DASD_EER=y 457CONFIG_DASD_EER=y
458CONFIG_VIRTIO_BLK=m
442CONFIG_MISC_DEVICES=y 459CONFIG_MISC_DEVICES=y
443# CONFIG_EEPROM_93CX6 is not set 460# CONFIG_EEPROM_93CX6 is not set
444# CONFIG_ENCLOSURE_SERVICES is not set 461# CONFIG_ENCLOSURE_SERVICES is not set
@@ -533,7 +550,7 @@ CONFIG_NETDEV_10000=y
533# S/390 network device drivers 550# S/390 network device drivers
534# 551#
535CONFIG_LCS=m 552CONFIG_LCS=m
536CONFIG_CTC=m 553CONFIG_CTCM=m
537# CONFIG_NETIUCV is not set 554# CONFIG_NETIUCV is not set
538# CONFIG_SMSGIUCV is not set 555# CONFIG_SMSGIUCV is not set
539# CONFIG_CLAW is not set 556# CONFIG_CLAW is not set
@@ -547,10 +564,12 @@ CONFIG_CCWGROUP=y
547# CONFIG_NETCONSOLE is not set 564# CONFIG_NETCONSOLE is not set
548# CONFIG_NETPOLL is not set 565# CONFIG_NETPOLL is not set
549# CONFIG_NET_POLL_CONTROLLER is not set 566# CONFIG_NET_POLL_CONTROLLER is not set
567CONFIG_VIRTIO_NET=m
550 568
551# 569#
552# Character devices 570# Character devices
553# 571#
572CONFIG_DEVKMEM=y
554CONFIG_UNIX98_PTYS=y 573CONFIG_UNIX98_PTYS=y
555CONFIG_LEGACY_PTYS=y 574CONFIG_LEGACY_PTYS=y
556CONFIG_LEGACY_PTY_COUNT=256 575CONFIG_LEGACY_PTY_COUNT=256
@@ -600,6 +619,7 @@ CONFIG_S390_VMUR=m
600# Sonics Silicon Backplane 619# Sonics Silicon Backplane
601# 620#
602# CONFIG_MEMSTICK is not set 621# CONFIG_MEMSTICK is not set
622# CONFIG_NEW_LEDS is not set
603 623
604# 624#
605# File systems 625# File systems
@@ -652,6 +672,7 @@ CONFIG_PROC_SYSCTL=y
652CONFIG_SYSFS=y 672CONFIG_SYSFS=y
653CONFIG_TMPFS=y 673CONFIG_TMPFS=y
654CONFIG_TMPFS_POSIX_ACL=y 674CONFIG_TMPFS_POSIX_ACL=y
675# CONFIG_HUGETLBFS is not set
655# CONFIG_HUGETLB_PAGE is not set 676# CONFIG_HUGETLB_PAGE is not set
656CONFIG_CONFIGFS_FS=m 677CONFIG_CONFIGFS_FS=m
657 678
@@ -678,12 +699,10 @@ CONFIG_NFS_FS=y
678CONFIG_NFS_V3=y 699CONFIG_NFS_V3=y
679# CONFIG_NFS_V3_ACL is not set 700# CONFIG_NFS_V3_ACL is not set
680# CONFIG_NFS_V4 is not set 701# CONFIG_NFS_V4 is not set
681# CONFIG_NFS_DIRECTIO is not set
682CONFIG_NFSD=y 702CONFIG_NFSD=y
683CONFIG_NFSD_V3=y 703CONFIG_NFSD_V3=y
684# CONFIG_NFSD_V3_ACL is not set 704# CONFIG_NFSD_V3_ACL is not set
685# CONFIG_NFSD_V4 is not set 705# CONFIG_NFSD_V4 is not set
686CONFIG_NFSD_TCP=y
687CONFIG_LOCKD=y 706CONFIG_LOCKD=y
688CONFIG_LOCKD_V4=y 707CONFIG_LOCKD_V4=y
689CONFIG_EXPORTFS=y 708CONFIG_EXPORTFS=y
@@ -731,6 +750,7 @@ CONFIG_TRACE_IRQFLAGS_SUPPORT=y
731# CONFIG_PRINTK_TIME is not set 750# CONFIG_PRINTK_TIME is not set
732CONFIG_ENABLE_WARN_DEPRECATED=y 751CONFIG_ENABLE_WARN_DEPRECATED=y
733CONFIG_ENABLE_MUST_CHECK=y 752CONFIG_ENABLE_MUST_CHECK=y
753CONFIG_FRAME_WARN=2048
734CONFIG_MAGIC_SYSRQ=y 754CONFIG_MAGIC_SYSRQ=y
735# CONFIG_UNUSED_SYMBOLS is not set 755# CONFIG_UNUSED_SYMBOLS is not set
736CONFIG_DEBUG_FS=y 756CONFIG_DEBUG_FS=y
@@ -754,6 +774,7 @@ CONFIG_DEBUG_SPINLOCK_SLEEP=y
754CONFIG_DEBUG_BUGVERBOSE=y 774CONFIG_DEBUG_BUGVERBOSE=y
755# CONFIG_DEBUG_INFO is not set 775# CONFIG_DEBUG_INFO is not set
756# CONFIG_DEBUG_VM is not set 776# CONFIG_DEBUG_VM is not set
777# CONFIG_DEBUG_WRITECOUNT is not set
757# CONFIG_DEBUG_LIST is not set 778# CONFIG_DEBUG_LIST is not set
758# CONFIG_DEBUG_SG is not set 779# CONFIG_DEBUG_SG is not set
759# CONFIG_FRAME_POINTER is not set 780# CONFIG_FRAME_POINTER is not set
@@ -775,58 +796,88 @@ CONFIG_SAMPLES=y
775# CONFIG_SECURITY is not set 796# CONFIG_SECURITY is not set
776# CONFIG_SECURITY_FILE_CAPABILITIES is not set 797# CONFIG_SECURITY_FILE_CAPABILITIES is not set
777CONFIG_CRYPTO=y 798CONFIG_CRYPTO=y
799
800#
801# Crypto core or helper
802#
778CONFIG_CRYPTO_ALGAPI=y 803CONFIG_CRYPTO_ALGAPI=y
779CONFIG_CRYPTO_AEAD=m 804CONFIG_CRYPTO_AEAD=m
780CONFIG_CRYPTO_BLKCIPHER=y 805CONFIG_CRYPTO_BLKCIPHER=y
781CONFIG_CRYPTO_SEQIV=m
782CONFIG_CRYPTO_HASH=m 806CONFIG_CRYPTO_HASH=m
783CONFIG_CRYPTO_MANAGER=y 807CONFIG_CRYPTO_MANAGER=y
808CONFIG_CRYPTO_GF128MUL=m
809# CONFIG_CRYPTO_NULL is not set
810# CONFIG_CRYPTO_CRYPTD is not set
811CONFIG_CRYPTO_AUTHENC=m
812# CONFIG_CRYPTO_TEST is not set
813
814#
815# Authenticated Encryption with Associated Data
816#
817CONFIG_CRYPTO_CCM=m
818CONFIG_CRYPTO_GCM=m
819CONFIG_CRYPTO_SEQIV=m
820
821#
822# Block modes
823#
824CONFIG_CRYPTO_CBC=y
825CONFIG_CRYPTO_CTR=m
826CONFIG_CRYPTO_CTS=m
827CONFIG_CRYPTO_ECB=m
828# CONFIG_CRYPTO_LRW is not set
829CONFIG_CRYPTO_PCBC=m
830# CONFIG_CRYPTO_XTS is not set
831
832#
833# Hash modes
834#
784CONFIG_CRYPTO_HMAC=m 835CONFIG_CRYPTO_HMAC=m
785# CONFIG_CRYPTO_XCBC is not set 836# CONFIG_CRYPTO_XCBC is not set
786# CONFIG_CRYPTO_NULL is not set 837
838#
839# Digest
840#
841# CONFIG_CRYPTO_CRC32C is not set
787# CONFIG_CRYPTO_MD4 is not set 842# CONFIG_CRYPTO_MD4 is not set
788CONFIG_CRYPTO_MD5=m 843CONFIG_CRYPTO_MD5=m
844# CONFIG_CRYPTO_MICHAEL_MIC is not set
789CONFIG_CRYPTO_SHA1=m 845CONFIG_CRYPTO_SHA1=m
790# CONFIG_CRYPTO_SHA256 is not set 846# CONFIG_CRYPTO_SHA256 is not set
791# CONFIG_CRYPTO_SHA512 is not set 847# CONFIG_CRYPTO_SHA512 is not set
792# CONFIG_CRYPTO_WP512 is not set
793# CONFIG_CRYPTO_TGR192 is not set 848# CONFIG_CRYPTO_TGR192 is not set
794CONFIG_CRYPTO_GF128MUL=m 849# CONFIG_CRYPTO_WP512 is not set
795CONFIG_CRYPTO_ECB=m 850
796CONFIG_CRYPTO_CBC=y 851#
797CONFIG_CRYPTO_PCBC=m 852# Ciphers
798# CONFIG_CRYPTO_LRW is not set 853#
799# CONFIG_CRYPTO_XTS is not set
800CONFIG_CRYPTO_CTR=m
801CONFIG_CRYPTO_GCM=m
802CONFIG_CRYPTO_CCM=m
803# CONFIG_CRYPTO_CRYPTD is not set
804# CONFIG_CRYPTO_DES is not set
805CONFIG_CRYPTO_FCRYPT=m
806# CONFIG_CRYPTO_BLOWFISH is not set
807# CONFIG_CRYPTO_TWOFISH is not set
808# CONFIG_CRYPTO_SERPENT is not set
809# CONFIG_CRYPTO_AES is not set 854# CONFIG_CRYPTO_AES is not set
855# CONFIG_CRYPTO_ANUBIS is not set
856# CONFIG_CRYPTO_ARC4 is not set
857# CONFIG_CRYPTO_BLOWFISH is not set
858CONFIG_CRYPTO_CAMELLIA=m
810# CONFIG_CRYPTO_CAST5 is not set 859# CONFIG_CRYPTO_CAST5 is not set
811# CONFIG_CRYPTO_CAST6 is not set 860# CONFIG_CRYPTO_CAST6 is not set
812# CONFIG_CRYPTO_TEA is not set 861# CONFIG_CRYPTO_DES is not set
813# CONFIG_CRYPTO_ARC4 is not set 862CONFIG_CRYPTO_FCRYPT=m
814# CONFIG_CRYPTO_KHAZAD is not set 863# CONFIG_CRYPTO_KHAZAD is not set
815# CONFIG_CRYPTO_ANUBIS is not set
816CONFIG_CRYPTO_SEED=m
817CONFIG_CRYPTO_SALSA20=m 864CONFIG_CRYPTO_SALSA20=m
865CONFIG_CRYPTO_SEED=m
866# CONFIG_CRYPTO_SERPENT is not set
867# CONFIG_CRYPTO_TEA is not set
868# CONFIG_CRYPTO_TWOFISH is not set
869
870#
871# Compression
872#
818# CONFIG_CRYPTO_DEFLATE is not set 873# CONFIG_CRYPTO_DEFLATE is not set
819# CONFIG_CRYPTO_MICHAEL_MIC is not set
820# CONFIG_CRYPTO_CRC32C is not set
821CONFIG_CRYPTO_CAMELLIA=m
822# CONFIG_CRYPTO_TEST is not set
823CONFIG_CRYPTO_AUTHENC=m
824CONFIG_CRYPTO_LZO=m 874CONFIG_CRYPTO_LZO=m
825CONFIG_CRYPTO_HW=y 875CONFIG_CRYPTO_HW=y
826CONFIG_ZCRYPT=m 876CONFIG_ZCRYPT=m
827# CONFIG_ZCRYPT_MONOLITHIC is not set 877# CONFIG_ZCRYPT_MONOLITHIC is not set
828# CONFIG_CRYPTO_SHA1_S390 is not set 878# CONFIG_CRYPTO_SHA1_S390 is not set
829# CONFIG_CRYPTO_SHA256_S390 is not set 879# CONFIG_CRYPTO_SHA256_S390 is not set
880CONFIG_CRYPTO_SHA512_S390=m
830# CONFIG_CRYPTO_DES_S390 is not set 881# CONFIG_CRYPTO_DES_S390 is not set
831# CONFIG_CRYPTO_AES_S390 is not set 882# CONFIG_CRYPTO_AES_S390 is not set
832CONFIG_S390_PRNG=m 883CONFIG_S390_PRNG=m
@@ -835,6 +886,8 @@ CONFIG_S390_PRNG=m
835# Library routines 886# Library routines
836# 887#
837CONFIG_BITREVERSE=m 888CONFIG_BITREVERSE=m
889# CONFIG_GENERIC_FIND_FIRST_BIT is not set
890# CONFIG_GENERIC_FIND_NEXT_BIT is not set
838# CONFIG_CRC_CCITT is not set 891# CONFIG_CRC_CCITT is not set
839# CONFIG_CRC16 is not set 892# CONFIG_CRC16 is not set
840# CONFIG_CRC_ITU_T is not set 893# CONFIG_CRC_ITU_T is not set
@@ -844,3 +897,9 @@ CONFIG_LIBCRC32C=m
844CONFIG_LZO_COMPRESS=m 897CONFIG_LZO_COMPRESS=m
845CONFIG_LZO_DECOMPRESS=m 898CONFIG_LZO_DECOMPRESS=m
846CONFIG_PLIST=y 899CONFIG_PLIST=y
900CONFIG_HAVE_KVM=y
901CONFIG_VIRTUALIZATION=y
902CONFIG_KVM=m
903CONFIG_VIRTIO=y
904CONFIG_VIRTIO_RING=y
905CONFIG_VIRTIO_BALLOON=m
diff --git a/arch/s390/kernel/Makefile b/arch/s390/kernel/Makefile
index 77051cd27925..6302f5082588 100644
--- a/arch/s390/kernel/Makefile
+++ b/arch/s390/kernel/Makefile
@@ -2,8 +2,6 @@
2# Makefile for the linux kernel. 2# Makefile for the linux kernel.
3# 3#
4 4
5EXTRA_AFLAGS := -traditional
6
7# 5#
8# Passing null pointers is ok for smp code, since we access the lowcore here. 6# Passing null pointers is ok for smp code, since we access the lowcore here.
9# 7#
diff --git a/arch/s390/kernel/early.c b/arch/s390/kernel/early.c
index 68ec4083bf73..d0e09684b9ce 100644
--- a/arch/s390/kernel/early.c
+++ b/arch/s390/kernel/early.c
@@ -139,15 +139,15 @@ static noinline __init void detect_machine_type(void)
139 139
140 /* Running under z/VM ? */ 140 /* Running under z/VM ? */
141 if (cpuinfo->cpu_id.version == 0xff) 141 if (cpuinfo->cpu_id.version == 0xff)
142 machine_flags |= 1; 142 machine_flags |= MACHINE_FLAG_VM;
143 143
144 /* Running on a P/390 ? */ 144 /* Running on a P/390 ? */
145 if (cpuinfo->cpu_id.machine == 0x7490) 145 if (cpuinfo->cpu_id.machine == 0x7490)
146 machine_flags |= 4; 146 machine_flags |= MACHINE_FLAG_P390;
147 147
148 /* Running under KVM ? */ 148 /* Running under KVM ? */
149 if (cpuinfo->cpu_id.version == 0xfe) 149 if (cpuinfo->cpu_id.version == 0xfe)
150 machine_flags |= 64; 150 machine_flags |= MACHINE_FLAG_KVM;
151} 151}
152 152
153#ifdef CONFIG_64BIT 153#ifdef CONFIG_64BIT
@@ -268,6 +268,118 @@ static noinline __init void setup_lowcore_early(void)
268 s390_base_pgm_handler_fn = early_pgm_check_handler; 268 s390_base_pgm_handler_fn = early_pgm_check_handler;
269} 269}
270 270
271static noinline __init void setup_hpage(void)
272{
273#ifndef CONFIG_DEBUG_PAGEALLOC
274 unsigned int facilities;
275
276 facilities = stfl();
277 if (!(facilities & (1UL << 23)) || !(facilities & (1UL << 29)))
278 return;
279 machine_flags |= MACHINE_FLAG_HPAGE;
280 __ctl_set_bit(0, 23);
281#endif
282}
283
284static __init void detect_mvpg(void)
285{
286#ifndef CONFIG_64BIT
287 int rc;
288
289 asm volatile(
290 " la 0,0\n"
291 " mvpg %2,%2\n"
292 "0: la %0,0\n"
293 "1:\n"
294 EX_TABLE(0b,1b)
295 : "=d" (rc) : "0" (-EOPNOTSUPP), "a" (0) : "memory", "cc", "0");
296 if (!rc)
297 machine_flags |= MACHINE_FLAG_MVPG;
298#endif
299}
300
301static __init void detect_ieee(void)
302{
303#ifndef CONFIG_64BIT
304 int rc, tmp;
305
306 asm volatile(
307 " efpc %1,0\n"
308 "0: la %0,0\n"
309 "1:\n"
310 EX_TABLE(0b,1b)
311 : "=d" (rc), "=d" (tmp): "0" (-EOPNOTSUPP) : "cc");
312 if (!rc)
313 machine_flags |= MACHINE_FLAG_IEEE;
314#endif
315}
316
317static __init void detect_csp(void)
318{
319#ifndef CONFIG_64BIT
320 int rc;
321
322 asm volatile(
323 " la 0,0\n"
324 " la 1,0\n"
325 " la 2,4\n"
326 " csp 0,2\n"
327 "0: la %0,0\n"
328 "1:\n"
329 EX_TABLE(0b,1b)
330 : "=d" (rc) : "0" (-EOPNOTSUPP) : "cc", "0", "1", "2");
331 if (!rc)
332 machine_flags |= MACHINE_FLAG_CSP;
333#endif
334}
335
336static __init void detect_diag9c(void)
337{
338 unsigned int cpu_address;
339 int rc;
340
341 cpu_address = stap();
342 asm volatile(
343 " diag %2,0,0x9c\n"
344 "0: la %0,0\n"
345 "1:\n"
346 EX_TABLE(0b,1b)
347 : "=d" (rc) : "0" (-EOPNOTSUPP), "d" (cpu_address) : "cc");
348 if (!rc)
349 machine_flags |= MACHINE_FLAG_DIAG9C;
350}
351
352static __init void detect_diag44(void)
353{
354#ifdef CONFIG_64BIT
355 int rc;
356
357 asm volatile(
358 " diag 0,0,0x44\n"
359 "0: la %0,0\n"
360 "1:\n"
361 EX_TABLE(0b,1b)
362 : "=d" (rc) : "0" (-EOPNOTSUPP) : "cc");
363 if (!rc)
364 machine_flags |= MACHINE_FLAG_DIAG44;
365#endif
366}
367
368static __init void detect_machine_facilities(void)
369{
370#ifdef CONFIG_64BIT
371 unsigned int facilities;
372
373 facilities = stfl();
374 if (facilities & (1 << 28))
375 machine_flags |= MACHINE_FLAG_IDTE;
376 if (facilities & (1 << 23))
377 machine_flags |= MACHINE_FLAG_PFMF;
378 if (facilities & (1 << 4))
379 machine_flags |= MACHINE_FLAG_MVCOS;
380#endif
381}
382
271/* 383/*
272 * Save ipl parameters, clear bss memory, initialize storage keys 384 * Save ipl parameters, clear bss memory, initialize storage keys
273 * and create a kernel NSS at startup if the SAVESYS= parm is defined 385 * and create a kernel NSS at startup if the SAVESYS= parm is defined
@@ -285,6 +397,13 @@ void __init startup_init(void)
285 create_kernel_nss(); 397 create_kernel_nss();
286 sort_main_extable(); 398 sort_main_extable();
287 setup_lowcore_early(); 399 setup_lowcore_early();
400 detect_mvpg();
401 detect_ieee();
402 detect_csp();
403 detect_diag9c();
404 detect_diag44();
405 detect_machine_facilities();
406 setup_hpage();
288 sclp_read_info_early(); 407 sclp_read_info_early();
289 sclp_facilities_detect(); 408 sclp_facilities_detect();
290 memsize = sclp_memory_detect(); 409 memsize = sclp_memory_detect();
diff --git a/arch/s390/kernel/entry.S b/arch/s390/kernel/entry.S
index 6766e37fe8ea..bdbb3bcd78a5 100644
--- a/arch/s390/kernel/entry.S
+++ b/arch/s390/kernel/entry.S
@@ -49,9 +49,9 @@ SP_ILC = STACK_FRAME_OVERHEAD + __PT_ILC
49SP_TRAP = STACK_FRAME_OVERHEAD + __PT_TRAP 49SP_TRAP = STACK_FRAME_OVERHEAD + __PT_TRAP
50SP_SIZE = STACK_FRAME_OVERHEAD + __PT_SIZE 50SP_SIZE = STACK_FRAME_OVERHEAD + __PT_SIZE
51 51
52_TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK | _TIF_NEED_RESCHED | \ 52_TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
53 _TIF_MCCK_PENDING | _TIF_RESTART_SVC | _TIF_SINGLE_STEP ) 53 _TIF_MCCK_PENDING | _TIF_RESTART_SVC | _TIF_SINGLE_STEP )
54_TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK | _TIF_NEED_RESCHED | \ 54_TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
55 _TIF_MCCK_PENDING) 55 _TIF_MCCK_PENDING)
56 56
57STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER 57STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER
@@ -316,7 +316,7 @@ sysc_work:
316 bo BASED(sysc_mcck_pending) 316 bo BASED(sysc_mcck_pending)
317 tm __TI_flags+3(%r9),_TIF_NEED_RESCHED 317 tm __TI_flags+3(%r9),_TIF_NEED_RESCHED
318 bo BASED(sysc_reschedule) 318 bo BASED(sysc_reschedule)
319 tm __TI_flags+3(%r9),(_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK) 319 tm __TI_flags+3(%r9),_TIF_SIGPENDING
320 bnz BASED(sysc_sigpending) 320 bnz BASED(sysc_sigpending)
321 tm __TI_flags+3(%r9),_TIF_RESTART_SVC 321 tm __TI_flags+3(%r9),_TIF_RESTART_SVC
322 bo BASED(sysc_restart) 322 bo BASED(sysc_restart)
@@ -342,7 +342,7 @@ sysc_mcck_pending:
342 br %r1 # TIF bit will be cleared by handler 342 br %r1 # TIF bit will be cleared by handler
343 343
344# 344#
345# _TIF_SIGPENDING or _TIF_RESTORE_SIGMASK is set, call do_signal 345# _TIF_SIGPENDING is set, call do_signal
346# 346#
347sysc_sigpending: 347sysc_sigpending:
348 ni __TI_flags+3(%r9),255-_TIF_SINGLE_STEP # clear TIF_SINGLE_STEP 348 ni __TI_flags+3(%r9),255-_TIF_SINGLE_STEP # clear TIF_SINGLE_STEP
@@ -657,7 +657,7 @@ io_work:
657 lr %r15,%r1 657 lr %r15,%r1
658# 658#
659# One of the work bits is on. Find out which one. 659# One of the work bits is on. Find out which one.
660# Checked are: _TIF_SIGPENDING, _TIF_RESTORE_SIGMASK, _TIF_NEED_RESCHED 660# Checked are: _TIF_SIGPENDING, _TIF_NEED_RESCHED
661# and _TIF_MCCK_PENDING 661# and _TIF_MCCK_PENDING
662# 662#
663io_work_loop: 663io_work_loop:
@@ -665,7 +665,7 @@ io_work_loop:
665 bo BASED(io_mcck_pending) 665 bo BASED(io_mcck_pending)
666 tm __TI_flags+3(%r9),_TIF_NEED_RESCHED 666 tm __TI_flags+3(%r9),_TIF_NEED_RESCHED
667 bo BASED(io_reschedule) 667 bo BASED(io_reschedule)
668 tm __TI_flags+3(%r9),(_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK) 668 tm __TI_flags+3(%r9),_TIF_SIGPENDING
669 bnz BASED(io_sigpending) 669 bnz BASED(io_sigpending)
670 b BASED(io_restore) 670 b BASED(io_restore)
671io_work_done: 671io_work_done:
@@ -693,7 +693,7 @@ io_reschedule:
693 b BASED(io_work_loop) 693 b BASED(io_work_loop)
694 694
695# 695#
696# _TIF_SIGPENDING or _TIF_RESTORE_SIGMASK is set, call do_signal 696# _TIF_SIGPENDING is set, call do_signal
697# 697#
698io_sigpending: 698io_sigpending:
699 TRACE_IRQS_ON 699 TRACE_IRQS_ON
diff --git a/arch/s390/kernel/entry64.S b/arch/s390/kernel/entry64.S
index cd959c0b2e16..5a4a7bcd2bba 100644
--- a/arch/s390/kernel/entry64.S
+++ b/arch/s390/kernel/entry64.S
@@ -52,9 +52,9 @@ SP_SIZE = STACK_FRAME_OVERHEAD + __PT_SIZE
52STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER 52STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER
53STACK_SIZE = 1 << STACK_SHIFT 53STACK_SIZE = 1 << STACK_SHIFT
54 54
55_TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK | _TIF_NEED_RESCHED | \ 55_TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
56 _TIF_MCCK_PENDING | _TIF_RESTART_SVC | _TIF_SINGLE_STEP ) 56 _TIF_MCCK_PENDING | _TIF_RESTART_SVC | _TIF_SINGLE_STEP )
57_TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK | _TIF_NEED_RESCHED | \ 57_TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
58 _TIF_MCCK_PENDING) 58 _TIF_MCCK_PENDING)
59 59
60#define BASED(name) name-system_call(%r13) 60#define BASED(name) name-system_call(%r13)
@@ -308,7 +308,7 @@ sysc_work:
308 jo sysc_mcck_pending 308 jo sysc_mcck_pending
309 tm __TI_flags+7(%r9),_TIF_NEED_RESCHED 309 tm __TI_flags+7(%r9),_TIF_NEED_RESCHED
310 jo sysc_reschedule 310 jo sysc_reschedule
311 tm __TI_flags+7(%r9),(_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK) 311 tm __TI_flags+7(%r9),_TIF_SIGPENDING
312 jnz sysc_sigpending 312 jnz sysc_sigpending
313 tm __TI_flags+7(%r9),_TIF_RESTART_SVC 313 tm __TI_flags+7(%r9),_TIF_RESTART_SVC
314 jo sysc_restart 314 jo sysc_restart
@@ -332,7 +332,7 @@ sysc_mcck_pending:
332 jg s390_handle_mcck # TIF bit will be cleared by handler 332 jg s390_handle_mcck # TIF bit will be cleared by handler
333 333
334# 334#
335# _TIF_SIGPENDING or _TIF_RESTORE_SIGMASK is set, call do_signal 335# _TIF_SIGPENDING is set, call do_signal
336# 336#
337sysc_sigpending: 337sysc_sigpending:
338 ni __TI_flags+7(%r9),255-_TIF_SINGLE_STEP # clear TIF_SINGLE_STEP 338 ni __TI_flags+7(%r9),255-_TIF_SINGLE_STEP # clear TIF_SINGLE_STEP
@@ -648,7 +648,7 @@ io_work_loop:
648 jo io_mcck_pending 648 jo io_mcck_pending
649 tm __TI_flags+7(%r9),_TIF_NEED_RESCHED 649 tm __TI_flags+7(%r9),_TIF_NEED_RESCHED
650 jo io_reschedule 650 jo io_reschedule
651 tm __TI_flags+7(%r9),(_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK) 651 tm __TI_flags+7(%r9),_TIF_SIGPENDING
652 jnz io_sigpending 652 jnz io_sigpending
653 j io_restore 653 j io_restore
654io_work_done: 654io_work_done:
@@ -674,7 +674,7 @@ io_reschedule:
674 j io_work_loop 674 j io_work_loop
675 675
676# 676#
677# _TIF_SIGPENDING or _TIF_RESTORE_SIGMASK is set, call do_signal 677# _TIF_SIGPENDING or is set, call do_signal
678# 678#
679io_sigpending: 679io_sigpending:
680 TRACE_IRQS_ON 680 TRACE_IRQS_ON
diff --git a/arch/s390/kernel/head31.S b/arch/s390/kernel/head31.S
index dc364c1419af..a816e2de32b9 100644
--- a/arch/s390/kernel/head31.S
+++ b/arch/s390/kernel/head31.S
@@ -57,61 +57,6 @@ startup_continue:
57# 57#
58 l %r14,.Lstartup_init-.LPG1(%r13) 58 l %r14,.Lstartup_init-.LPG1(%r13)
59 basr %r14,%r14 59 basr %r14,%r14
60
61 l %r12,.Lmflags-.LPG1(%r13) # get address of machine_flags
62#
63# find out if we have an IEEE fpu
64#
65 mvc __LC_PGM_NEW_PSW(8),.Lpcfpu-.LPG1(%r13)
66 efpc %r0,0 # test IEEE extract fpc instruction
67 oi 3(%r12),2 # set IEEE fpu flag
68.Lchkfpu:
69
70#
71# find out if we have the CSP instruction
72#
73 mvc __LC_PGM_NEW_PSW(8),.Lpccsp-.LPG1(%r13)
74 la %r0,0
75 lr %r1,%r0
76 la %r2,4
77 csp %r0,%r2 # Test CSP instruction
78 oi 3(%r12),8 # set CSP flag
79.Lchkcsp:
80
81#
82# find out if we have the MVPG instruction
83#
84 mvc __LC_PGM_NEW_PSW(8),.Lpcmvpg-.LPG1(%r13)
85 sr %r0,%r0
86 la %r1,0
87 la %r2,0
88 mvpg %r1,%r2 # Test CSP instruction
89 oi 3(%r12),16 # set MVPG flag
90.Lchkmvpg:
91
92#
93# find out if we have the IDTE instruction
94#
95 mvc __LC_PGM_NEW_PSW(8),.Lpcidte-.LPG1(%r13)
96 .long 0xb2b10000 # store facility list
97 tm 0xc8,0x08 # check bit for clearing-by-ASCE
98 bno .Lchkidte-.LPG1(%r13)
99 lhi %r1,2094
100 lhi %r2,0
101 .long 0xb98e2001
102 oi 3(%r12),0x80 # set IDTE flag
103.Lchkidte:
104
105#
106# find out if the diag 0x9c is available
107#
108 mvc __LC_PGM_NEW_PSW(8),.Lpcdiag9c-.LPG1(%r13)
109 stap __LC_CPUID+4 # store cpu address
110 lh %r1,__LC_CPUID+4
111 diag %r1,0,0x9c # test diag 0x9c
112 oi 2(%r12),1 # set diag9c flag
113.Lchkdiag9c:
114
115 lpsw .Lentry-.LPG1(13) # jump to _stext in primary-space, 60 lpsw .Lentry-.LPG1(13) # jump to _stext in primary-space,
116 # virtual and never return ... 61 # virtual and never return ...
117 .align 8 62 .align 8
@@ -132,13 +77,7 @@ startup_continue:
132 .long 0 # cr13: home space segment table 77 .long 0 # cr13: home space segment table
133 .long 0xc0000000 # cr14: machine check handling off 78 .long 0xc0000000 # cr14: machine check handling off
134 .long 0 # cr15: linkage stack operations 79 .long 0 # cr15: linkage stack operations
135.Lpcfpu:.long 0x00080000,0x80000000 + .Lchkfpu
136.Lpccsp:.long 0x00080000,0x80000000 + .Lchkcsp
137.Lpcmvpg:.long 0x00080000,0x80000000 + .Lchkmvpg
138.Lpcidte:.long 0x00080000,0x80000000 + .Lchkidte
139.Lpcdiag9c:.long 0x00080000,0x80000000 + .Lchkdiag9c
140.Lmchunk:.long memory_chunk 80.Lmchunk:.long memory_chunk
141.Lmflags:.long machine_flags
142.Lbss_bgn: .long __bss_start 81.Lbss_bgn: .long __bss_start
143.Lbss_end: .long _end 82.Lbss_end: .long _end
144.Lparmaddr: .long PARMAREA 83.Lparmaddr: .long PARMAREA
diff --git a/arch/s390/kernel/head64.S b/arch/s390/kernel/head64.S
index 79dccd206a6e..1d06961e87b3 100644
--- a/arch/s390/kernel/head64.S
+++ b/arch/s390/kernel/head64.S
@@ -125,73 +125,11 @@ startup_continue:
125# and create a kernel NSS if the SAVESYS= parm is defined 125# and create a kernel NSS if the SAVESYS= parm is defined
126# 126#
127 brasl %r14,startup_init 127 brasl %r14,startup_init
128 # set program check new psw mask
129 mvc __LC_PGM_NEW_PSW(8),.Lpcmsk-.LPG1(%r13)
130 larl %r12,machine_flags
131#
132# find out if we have the MVPG instruction
133#
134 la %r1,0f-.LPG1(%r13) # set program check address
135 stg %r1,__LC_PGM_NEW_PSW+8
136 sgr %r0,%r0
137 lghi %r1,0
138 lghi %r2,0
139 mvpg %r1,%r2 # test MVPG instruction
140 oi 7(%r12),16 # set MVPG flag
1410:
142
143#
144# find out if the diag 0x44 works in 64 bit mode
145#
146 la %r1,0f-.LPG1(%r13) # set program check address
147 stg %r1,__LC_PGM_NEW_PSW+8
148 diag 0,0,0x44 # test diag 0x44
149 oi 7(%r12),32 # set diag44 flag
1500:
151
152#
153# find out if we have the IDTE instruction
154#
155 la %r1,0f-.LPG1(%r13) # set program check address
156 stg %r1,__LC_PGM_NEW_PSW+8
157 .long 0xb2b10000 # store facility list
158 tm 0xc8,0x08 # check bit for clearing-by-ASCE
159 bno 0f-.LPG1(%r13)
160 lhi %r1,2048
161 lhi %r2,0
162 .long 0xb98e2001
163 oi 7(%r12),0x80 # set IDTE flag
1640:
165
166#
167# find out if the diag 0x9c is available
168#
169 la %r1,0f-.LPG1(%r13) # set program check address
170 stg %r1,__LC_PGM_NEW_PSW+8
171 stap __LC_CPUID+4 # store cpu address
172 lh %r1,__LC_CPUID+4
173 diag %r1,0,0x9c # test diag 0x9c
174 oi 6(%r12),1 # set diag9c flag
1750:
176
177#
178# find out if we have the MVCOS instruction
179#
180 la %r1,0f-.LPG1(%r13) # set program check address
181 stg %r1,__LC_PGM_NEW_PSW+8
182 .short 0xc800 # mvcos 0(%r0),0(%r0),%r0
183 .short 0x0000
184 .short 0x0000
1850: tm 0x8f,0x13 # special-operation exception?
186 bno 1f-.LPG1(%r13) # if yes, MVCOS is present
187 oi 6(%r12),2 # set MVCOS flag
1881:
189
190 lpswe .Lentry-.LPG1(13) # jump to _stext in primary-space, 128 lpswe .Lentry-.LPG1(13) # jump to _stext in primary-space,
191 # virtual and never return ... 129 # virtual and never return ...
192 .align 16 130 .align 16
193.Lentry:.quad 0x0000000180000000,_stext 131.Lentry:.quad 0x0000000180000000,_stext
194.Lctl: .quad 0x04b50002 # cr0: various things 132.Lctl: .quad 0x04350002 # cr0: various things
195 .quad 0 # cr1: primary space segment table 133 .quad 0 # cr1: primary space segment table
196 .quad .Lduct # cr2: dispatchable unit control table 134 .quad .Lduct # cr2: dispatchable unit control table
197 .quad 0 # cr3: instruction authorization 135 .quad 0 # cr3: instruction authorization
diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
index c1aff194141d..7920861109d2 100644
--- a/arch/s390/kernel/process.c
+++ b/arch/s390/kernel/process.c
@@ -180,24 +180,6 @@ void cpu_idle(void)
180 } 180 }
181} 181}
182 182
183void show_regs(struct pt_regs *regs)
184{
185 print_modules();
186 printk("CPU: %d %s %s %.*s\n",
187 task_thread_info(current)->cpu, print_tainted(),
188 init_utsname()->release,
189 (int)strcspn(init_utsname()->version, " "),
190 init_utsname()->version);
191 printk("Process %s (pid: %d, task: %p, ksp: %p)\n",
192 current->comm, current->pid, current,
193 (void *) current->thread.ksp);
194 show_registers(regs);
195 /* Show stack backtrace if pt_regs is from kernel mode */
196 if (!(regs->psw.mask & PSW_MASK_PSTATE))
197 show_trace(NULL, (unsigned long *) regs->gprs[15]);
198 show_last_breaking_event(regs);
199}
200
201extern void kernel_thread_starter(void); 183extern void kernel_thread_starter(void);
202 184
203asm( 185asm(
diff --git a/arch/s390/kernel/ptrace.c b/arch/s390/kernel/ptrace.c
index 58a064296987..7f4270163744 100644
--- a/arch/s390/kernel/ptrace.c
+++ b/arch/s390/kernel/ptrace.c
@@ -607,38 +607,8 @@ do_ptrace_emu31(struct task_struct *child, long request, long addr, long data)
607} 607}
608#endif 608#endif
609 609
610#define PT32_IEEE_IP 0x13c 610long arch_ptrace(struct task_struct *child, long request, long addr, long data)
611
612static int
613do_ptrace(struct task_struct *child, long request, long addr, long data)
614{ 611{
615 int ret;
616
617 if (request == PTRACE_ATTACH)
618 return ptrace_attach(child);
619
620 /*
621 * Special cases to get/store the ieee instructions pointer.
622 */
623 if (child == current) {
624 if (request == PTRACE_PEEKUSR && addr == PT_IEEE_IP)
625 return peek_user(child, addr, data);
626 if (request == PTRACE_POKEUSR && addr == PT_IEEE_IP)
627 return poke_user(child, addr, data);
628#ifdef CONFIG_COMPAT
629 if (request == PTRACE_PEEKUSR &&
630 addr == PT32_IEEE_IP && test_thread_flag(TIF_31BIT))
631 return peek_user_emu31(child, addr, data);
632 if (request == PTRACE_POKEUSR &&
633 addr == PT32_IEEE_IP && test_thread_flag(TIF_31BIT))
634 return poke_user_emu31(child, addr, data);
635#endif
636 }
637
638 ret = ptrace_check_attach(child, request == PTRACE_KILL);
639 if (ret < 0)
640 return ret;
641
642 switch (request) { 612 switch (request) {
643 case PTRACE_SYSCALL: 613 case PTRACE_SYSCALL:
644 /* continue and stop at next (return from) syscall */ 614 /* continue and stop at next (return from) syscall */
@@ -693,31 +663,6 @@ do_ptrace(struct task_struct *child, long request, long addr, long data)
693 return -EIO; 663 return -EIO;
694} 664}
695 665
696asmlinkage long
697sys_ptrace(long request, long pid, long addr, long data)
698{
699 struct task_struct *child;
700 int ret;
701
702 lock_kernel();
703 if (request == PTRACE_TRACEME) {
704 ret = ptrace_traceme();
705 goto out;
706 }
707
708 child = ptrace_get_task_struct(pid);
709 if (IS_ERR(child)) {
710 ret = PTR_ERR(child);
711 goto out;
712 }
713
714 ret = do_ptrace(child, request, addr, data);
715 put_task_struct(child);
716out:
717 unlock_kernel();
718 return ret;
719}
720
721asmlinkage void 666asmlinkage void
722syscall_trace(struct pt_regs *regs, int entryexit) 667syscall_trace(struct pt_regs *regs, int entryexit)
723{ 668{
diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
index a9d18aafa5f4..2bc70b6e876a 100644
--- a/arch/s390/kernel/setup.c
+++ b/arch/s390/kernel/setup.c
@@ -73,7 +73,7 @@ EXPORT_SYMBOL(uaccess);
73unsigned int console_mode = 0; 73unsigned int console_mode = 0;
74unsigned int console_devno = -1; 74unsigned int console_devno = -1;
75unsigned int console_irq = -1; 75unsigned int console_irq = -1;
76unsigned long machine_flags = 0; 76unsigned long machine_flags;
77unsigned long elf_hwcap = 0; 77unsigned long elf_hwcap = 0;
78char elf_platform[ELF_PLATFORM_SIZE]; 78char elf_platform[ELF_PLATFORM_SIZE];
79 79
@@ -683,15 +683,6 @@ setup_memory(void)
683#endif 683#endif
684} 684}
685 685
686static __init unsigned int stfl(void)
687{
688 asm volatile(
689 " .insn s,0xb2b10000,0(0)\n" /* stfl */
690 "0:\n"
691 EX_TABLE(0b,0b));
692 return S390_lowcore.stfl_fac_list;
693}
694
695static int __init __stfle(unsigned long long *list, int doublewords) 686static int __init __stfle(unsigned long long *list, int doublewords)
696{ 687{
697 typedef struct { unsigned long long _[doublewords]; } addrtype; 688 typedef struct { unsigned long long _[doublewords]; } addrtype;
@@ -758,6 +749,9 @@ static void __init setup_hwcaps(void)
758 elf_hwcap |= 1UL << 6; 749 elf_hwcap |= 1UL << 6;
759 } 750 }
760 751
752 if (MACHINE_HAS_HPAGE)
753 elf_hwcap |= 1UL << 7;
754
761 switch (cpuinfo->cpu_id.machine) { 755 switch (cpuinfo->cpu_id.machine) {
762 case 0x9672: 756 case 0x9672:
763#if !defined(CONFIG_64BIT) 757#if !defined(CONFIG_64BIT)
@@ -881,8 +875,9 @@ void __cpuinit print_cpu_info(struct cpuinfo_S390 *cpuinfo)
881 875
882static int show_cpuinfo(struct seq_file *m, void *v) 876static int show_cpuinfo(struct seq_file *m, void *v)
883{ 877{
884 static const char *hwcap_str[7] = { 878 static const char *hwcap_str[8] = {
885 "esan3", "zarch", "stfle", "msa", "ldisp", "eimm", "dfp" 879 "esan3", "zarch", "stfle", "msa", "ldisp", "eimm", "dfp",
880 "edat"
886 }; 881 };
887 struct cpuinfo_S390 *cpuinfo; 882 struct cpuinfo_S390 *cpuinfo;
888 unsigned long n = (unsigned long) v - 1; 883 unsigned long n = (unsigned long) v - 1;
@@ -897,7 +892,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)
897 num_online_cpus(), loops_per_jiffy/(500000/HZ), 892 num_online_cpus(), loops_per_jiffy/(500000/HZ),
898 (loops_per_jiffy/(5000/HZ))%100); 893 (loops_per_jiffy/(5000/HZ))%100);
899 seq_puts(m, "features\t: "); 894 seq_puts(m, "features\t: ");
900 for (i = 0; i < 7; i++) 895 for (i = 0; i < 8; i++)
901 if (hwcap_str[i] && (elf_hwcap & (1UL << i))) 896 if (hwcap_str[i] && (elf_hwcap & (1UL << i)))
902 seq_printf(m, "%s ", hwcap_str[i]); 897 seq_printf(m, "%s ", hwcap_str[i]);
903 seq_puts(m, "\n"); 898 seq_puts(m, "\n");
diff --git a/arch/s390/kernel/smp.c b/arch/s390/kernel/smp.c
index 0dfa988c1b26..0aeb290060d9 100644
--- a/arch/s390/kernel/smp.c
+++ b/arch/s390/kernel/smp.c
@@ -505,7 +505,7 @@ out:
505 return rc; 505 return rc;
506} 506}
507 507
508static int smp_rescan_cpus(void) 508static int __smp_rescan_cpus(void)
509{ 509{
510 cpumask_t avail; 510 cpumask_t avail;
511 511
@@ -570,7 +570,7 @@ out:
570 kfree(info); 570 kfree(info);
571 printk(KERN_INFO "CPUs: %d configured, %d standby\n", c_cpus, s_cpus); 571 printk(KERN_INFO "CPUs: %d configured, %d standby\n", c_cpus, s_cpus);
572 get_online_cpus(); 572 get_online_cpus();
573 smp_rescan_cpus(); 573 __smp_rescan_cpus();
574 put_online_cpus(); 574 put_online_cpus();
575} 575}
576 576
@@ -890,8 +890,8 @@ static ssize_t cpu_configure_store(struct sys_device *dev, const char *buf,
890 if (val != 0 && val != 1) 890 if (val != 0 && val != 1)
891 return -EINVAL; 891 return -EINVAL;
892 892
893 mutex_lock(&smp_cpu_state_mutex);
894 get_online_cpus(); 893 get_online_cpus();
894 mutex_lock(&smp_cpu_state_mutex);
895 rc = -EBUSY; 895 rc = -EBUSY;
896 if (cpu_online(cpu)) 896 if (cpu_online(cpu))
897 goto out; 897 goto out;
@@ -919,8 +919,8 @@ static ssize_t cpu_configure_store(struct sys_device *dev, const char *buf,
919 break; 919 break;
920 } 920 }
921out: 921out:
922 put_online_cpus();
923 mutex_unlock(&smp_cpu_state_mutex); 922 mutex_unlock(&smp_cpu_state_mutex);
923 put_online_cpus();
924 return rc ? rc : count; 924 return rc ? rc : count;
925} 925}
926static SYSDEV_ATTR(configure, 0644, cpu_configure_show, cpu_configure_store); 926static SYSDEV_ATTR(configure, 0644, cpu_configure_show, cpu_configure_store);
@@ -1088,17 +1088,17 @@ out:
1088} 1088}
1089 1089
1090#ifdef CONFIG_HOTPLUG_CPU 1090#ifdef CONFIG_HOTPLUG_CPU
1091static ssize_t __ref rescan_store(struct sys_device *dev, 1091
1092 const char *buf, size_t count) 1092int smp_rescan_cpus(void)
1093{ 1093{
1094 cpumask_t newcpus; 1094 cpumask_t newcpus;
1095 int cpu; 1095 int cpu;
1096 int rc; 1096 int rc;
1097 1097
1098 mutex_lock(&smp_cpu_state_mutex);
1099 get_online_cpus(); 1098 get_online_cpus();
1099 mutex_lock(&smp_cpu_state_mutex);
1100 newcpus = cpu_present_map; 1100 newcpus = cpu_present_map;
1101 rc = smp_rescan_cpus(); 1101 rc = __smp_rescan_cpus();
1102 if (rc) 1102 if (rc)
1103 goto out; 1103 goto out;
1104 cpus_andnot(newcpus, cpu_present_map, newcpus); 1104 cpus_andnot(newcpus, cpu_present_map, newcpus);
@@ -1109,10 +1109,19 @@ static ssize_t __ref rescan_store(struct sys_device *dev,
1109 } 1109 }
1110 rc = 0; 1110 rc = 0;
1111out: 1111out:
1112 put_online_cpus();
1113 mutex_unlock(&smp_cpu_state_mutex); 1112 mutex_unlock(&smp_cpu_state_mutex);
1113 put_online_cpus();
1114 if (!cpus_empty(newcpus)) 1114 if (!cpus_empty(newcpus))
1115 topology_schedule_update(); 1115 topology_schedule_update();
1116 return rc;
1117}
1118
1119static ssize_t __ref rescan_store(struct sys_device *dev, const char *buf,
1120 size_t count)
1121{
1122 int rc;
1123
1124 rc = smp_rescan_cpus();
1116 return rc ? rc : count; 1125 return rc ? rc : count;
1117} 1126}
1118static SYSDEV_ATTR(rescan, 0200, NULL, rescan_store); 1127static SYSDEV_ATTR(rescan, 0200, NULL, rescan_store);
@@ -1139,16 +1148,16 @@ static ssize_t dispatching_store(struct sys_device *dev, const char *buf,
1139 if (val != 0 && val != 1) 1148 if (val != 0 && val != 1)
1140 return -EINVAL; 1149 return -EINVAL;
1141 rc = 0; 1150 rc = 0;
1142 mutex_lock(&smp_cpu_state_mutex);
1143 get_online_cpus(); 1151 get_online_cpus();
1152 mutex_lock(&smp_cpu_state_mutex);
1144 if (cpu_management == val) 1153 if (cpu_management == val)
1145 goto out; 1154 goto out;
1146 rc = topology_set_cpu_management(val); 1155 rc = topology_set_cpu_management(val);
1147 if (!rc) 1156 if (!rc)
1148 cpu_management = val; 1157 cpu_management = val;
1149out: 1158out:
1150 put_online_cpus();
1151 mutex_unlock(&smp_cpu_state_mutex); 1159 mutex_unlock(&smp_cpu_state_mutex);
1160 put_online_cpus();
1152 return rc ? rc : count; 1161 return rc ? rc : count;
1153} 1162}
1154static SYSDEV_ATTR(dispatching, 0644, dispatching_show, dispatching_store); 1163static SYSDEV_ATTR(dispatching, 0644, dispatching_show, dispatching_store);
diff --git a/arch/s390/kernel/sys_s390.c b/arch/s390/kernel/sys_s390.c
index 988d0d64c2c8..5fdb799062b7 100644
--- a/arch/s390/kernel/sys_s390.c
+++ b/arch/s390/kernel/sys_s390.c
@@ -32,23 +32,6 @@
32#include <asm/uaccess.h> 32#include <asm/uaccess.h>
33#include "entry.h" 33#include "entry.h"
34 34
35/*
36 * sys_pipe() is the normal C calling standard for creating
37 * a pipe. It's not the way Unix traditionally does this, though.
38 */
39asmlinkage long sys_pipe(unsigned long __user *fildes)
40{
41 int fd[2];
42 int error;
43
44 error = do_pipe(fd);
45 if (!error) {
46 if (copy_to_user(fildes, fd, 2*sizeof(int)))
47 error = -EFAULT;
48 }
49 return error;
50}
51
52/* common code for old and new mmaps */ 35/* common code for old and new mmaps */
53static inline long do_mmap2( 36static inline long do_mmap2(
54 unsigned long addr, unsigned long len, 37 unsigned long addr, unsigned long len,
diff --git a/arch/s390/kernel/topology.c b/arch/s390/kernel/topology.c
index 12b39b3d9c38..661a07217057 100644
--- a/arch/s390/kernel/topology.c
+++ b/arch/s390/kernel/topology.c
@@ -9,6 +9,7 @@
9#include <linux/device.h> 9#include <linux/device.h>
10#include <linux/bootmem.h> 10#include <linux/bootmem.h>
11#include <linux/sched.h> 11#include <linux/sched.h>
12#include <linux/kthread.h>
12#include <linux/workqueue.h> 13#include <linux/workqueue.h>
13#include <linux/cpu.h> 14#include <linux/cpu.h>
14#include <linux/smp.h> 15#include <linux/smp.h>
@@ -66,6 +67,8 @@ static struct timer_list topology_timer;
66static void set_topology_timer(void); 67static void set_topology_timer(void);
67static DECLARE_WORK(topology_work, topology_work_fn); 68static DECLARE_WORK(topology_work, topology_work_fn);
68 69
70cpumask_t cpu_core_map[NR_CPUS];
71
69cpumask_t cpu_coregroup_map(unsigned int cpu) 72cpumask_t cpu_coregroup_map(unsigned int cpu)
70{ 73{
71 struct core_info *core = &core_info; 74 struct core_info *core = &core_info;
@@ -199,6 +202,14 @@ int topology_set_cpu_management(int fc)
199 return rc; 202 return rc;
200} 203}
201 204
205static void update_cpu_core_map(void)
206{
207 int cpu;
208
209 for_each_present_cpu(cpu)
210 cpu_core_map[cpu] = cpu_coregroup_map(cpu);
211}
212
202void arch_update_cpu_topology(void) 213void arch_update_cpu_topology(void)
203{ 214{
204 struct tl_info *info = tl_info; 215 struct tl_info *info = tl_info;
@@ -206,20 +217,33 @@ void arch_update_cpu_topology(void)
206 int cpu; 217 int cpu;
207 218
208 if (!machine_has_topology) { 219 if (!machine_has_topology) {
220 update_cpu_core_map();
209 topology_update_polarization_simple(); 221 topology_update_polarization_simple();
210 return; 222 return;
211 } 223 }
212 stsi(info, 15, 1, 2); 224 stsi(info, 15, 1, 2);
213 tl_to_cores(info); 225 tl_to_cores(info);
226 update_cpu_core_map();
214 for_each_online_cpu(cpu) { 227 for_each_online_cpu(cpu) {
215 sysdev = get_cpu_sysdev(cpu); 228 sysdev = get_cpu_sysdev(cpu);
216 kobject_uevent(&sysdev->kobj, KOBJ_CHANGE); 229 kobject_uevent(&sysdev->kobj, KOBJ_CHANGE);
217 } 230 }
218} 231}
219 232
220static void topology_work_fn(struct work_struct *work) 233static int topology_kthread(void *data)
221{ 234{
222 arch_reinit_sched_domains(); 235 arch_reinit_sched_domains();
236 return 0;
237}
238
239static void topology_work_fn(struct work_struct *work)
240{
241 /* We can't call arch_reinit_sched_domains() from a multi-threaded
242 * workqueue context since it may deadlock in case of cpu hotplug.
243 * So we have to create a kernel thread in order to call
244 * arch_reinit_sched_domains().
245 */
246 kthread_run(topology_kthread, NULL, "topology_update");
223} 247}
224 248
225void topology_schedule_update(void) 249void topology_schedule_update(void)
@@ -251,20 +275,23 @@ static int __init init_topology_update(void)
251{ 275{
252 int rc; 276 int rc;
253 277
278 rc = 0;
254 if (!machine_has_topology) { 279 if (!machine_has_topology) {
255 topology_update_polarization_simple(); 280 topology_update_polarization_simple();
256 return 0; 281 goto out;
257 } 282 }
258 init_timer_deferrable(&topology_timer); 283 init_timer_deferrable(&topology_timer);
259 if (machine_has_topology_irq) { 284 if (machine_has_topology_irq) {
260 rc = register_external_interrupt(0x2005, topology_interrupt); 285 rc = register_external_interrupt(0x2005, topology_interrupt);
261 if (rc) 286 if (rc)
262 return rc; 287 goto out;
263 ctl_set_bit(0, 8); 288 ctl_set_bit(0, 8);
264 } 289 }
265 else 290 else
266 set_topology_timer(); 291 set_topology_timer();
267 return 0; 292out:
293 update_cpu_core_map();
294 return rc;
268} 295}
269__initcall(init_topology_update); 296__initcall(init_topology_update);
270 297
diff --git a/arch/s390/kernel/traps.c b/arch/s390/kernel/traps.c
index 57b607b61100..4584d81984c0 100644
--- a/arch/s390/kernel/traps.c
+++ b/arch/s390/kernel/traps.c
@@ -113,7 +113,7 @@ __show_trace(unsigned long sp, unsigned long low, unsigned long high)
113 } 113 }
114} 114}
115 115
116void show_trace(struct task_struct *task, unsigned long *stack) 116static void show_trace(struct task_struct *task, unsigned long *stack)
117{ 117{
118 register unsigned long __r15 asm ("15"); 118 register unsigned long __r15 asm ("15");
119 unsigned long sp; 119 unsigned long sp;
@@ -161,14 +161,14 @@ void show_stack(struct task_struct *task, unsigned long *sp)
161 show_trace(task, sp); 161 show_trace(task, sp);
162} 162}
163 163
164#ifdef CONFIG_64BIT 164static void show_last_breaking_event(struct pt_regs *regs)
165void show_last_breaking_event(struct pt_regs *regs)
166{ 165{
166#ifdef CONFIG_64BIT
167 printk("Last Breaking-Event-Address:\n"); 167 printk("Last Breaking-Event-Address:\n");
168 printk(" [<%016lx>] ", regs->args[0] & PSW_ADDR_INSN); 168 printk(" [<%016lx>] ", regs->args[0] & PSW_ADDR_INSN);
169 print_symbol("%s\n", regs->args[0] & PSW_ADDR_INSN); 169 print_symbol("%s\n", regs->args[0] & PSW_ADDR_INSN);
170}
171#endif 170#endif
171}
172 172
173/* 173/*
174 * The architecture-independent dump_stack generator 174 * The architecture-independent dump_stack generator
@@ -223,6 +223,24 @@ void show_registers(struct pt_regs *regs)
223 show_code(regs); 223 show_code(regs);
224} 224}
225 225
226void show_regs(struct pt_regs *regs)
227{
228 print_modules();
229 printk("CPU: %d %s %s %.*s\n",
230 task_thread_info(current)->cpu, print_tainted(),
231 init_utsname()->release,
232 (int)strcspn(init_utsname()->version, " "),
233 init_utsname()->version);
234 printk("Process %s (pid: %d, task: %p, ksp: %p)\n",
235 current->comm, current->pid, current,
236 (void *) current->thread.ksp);
237 show_registers(regs);
238 /* Show stack backtrace if pt_regs is from kernel mode */
239 if (!(regs->psw.mask & PSW_MASK_PSTATE))
240 show_trace(NULL, (unsigned long *) regs->gprs[15]);
241 show_last_breaking_event(regs);
242}
243
226/* This is called from fs/proc/array.c */ 244/* This is called from fs/proc/array.c */
227void task_show_regs(struct seq_file *m, struct task_struct *task) 245void task_show_regs(struct seq_file *m, struct task_struct *task)
228{ 246{
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index 1465946325c5..c02286c6a931 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -151,18 +151,9 @@ static int handle_chsc(struct kvm_vcpu *vcpu)
151 return 0; 151 return 0;
152} 152}
153 153
154static unsigned int kvm_stfl(void)
155{
156 asm volatile(
157 " .insn s,0xb2b10000,0(0)\n" /* stfl */
158 "0:\n"
159 EX_TABLE(0b, 0b));
160 return S390_lowcore.stfl_fac_list;
161}
162
163static int handle_stfl(struct kvm_vcpu *vcpu) 154static int handle_stfl(struct kvm_vcpu *vcpu)
164{ 155{
165 unsigned int facility_list = kvm_stfl(); 156 unsigned int facility_list = stfl();
166 int rc; 157 int rc;
167 158
168 vcpu->stat.instruction_stfl++; 159 vcpu->stat.instruction_stfl++;
diff --git a/arch/s390/lib/Makefile b/arch/s390/lib/Makefile
index 52084436ab69..ab6735df2d21 100644
--- a/arch/s390/lib/Makefile
+++ b/arch/s390/lib/Makefile
@@ -2,8 +2,6 @@
2# Makefile for s390-specific library files.. 2# Makefile for s390-specific library files..
3# 3#
4 4
5EXTRA_AFLAGS := -traditional
6
7lib-y += delay.o string.o uaccess_std.o uaccess_pt.o 5lib-y += delay.o string.o uaccess_std.o uaccess_pt.o
8obj-$(CONFIG_32BIT) += div64.o qrnnd.o 6obj-$(CONFIG_32BIT) += div64.o qrnnd.o
9lib-$(CONFIG_64BIT) += uaccess_mvcos.o 7lib-$(CONFIG_64BIT) += uaccess_mvcos.o
diff --git a/arch/s390/lib/uaccess_mvcos.c b/arch/s390/lib/uaccess_mvcos.c
index 6d8772339d76..3f15aaf54855 100644
--- a/arch/s390/lib/uaccess_mvcos.c
+++ b/arch/s390/lib/uaccess_mvcos.c
@@ -162,6 +162,7 @@ static size_t clear_user_mvcos(size_t size, void __user *to)
162 return size; 162 return size;
163} 163}
164 164
165#ifdef CONFIG_S390_SWITCH_AMODE
165static size_t strnlen_user_mvcos(size_t count, const char __user *src) 166static size_t strnlen_user_mvcos(size_t count, const char __user *src)
166{ 167{
167 char buf[256]; 168 char buf[256];
@@ -199,6 +200,7 @@ static size_t strncpy_from_user_mvcos(size_t count, const char __user *src,
199 } while ((len_str == len) && (done < count)); 200 } while ((len_str == len) && (done < count));
200 return done; 201 return done;
201} 202}
203#endif /* CONFIG_S390_SWITCH_AMODE */
202 204
203struct uaccess_ops uaccess_mvcos = { 205struct uaccess_ops uaccess_mvcos = {
204 .copy_from_user = copy_from_user_mvcos_check, 206 .copy_from_user = copy_from_user_mvcos_check,
diff --git a/arch/s390/math-emu/Makefile b/arch/s390/math-emu/Makefile
index 73b3e72efc46..c84890341052 100644
--- a/arch/s390/math-emu/Makefile
+++ b/arch/s390/math-emu/Makefile
@@ -5,4 +5,3 @@
5obj-$(CONFIG_MATHEMU) := math.o 5obj-$(CONFIG_MATHEMU) := math.o
6 6
7EXTRA_CFLAGS := -I$(src) -Iinclude/math-emu -w 7EXTRA_CFLAGS := -I$(src) -Iinclude/math-emu -w
8EXTRA_AFLAGS := -traditional
diff --git a/arch/s390/mm/Makefile b/arch/s390/mm/Makefile
index 66401930f83e..fb988a48a754 100644
--- a/arch/s390/mm/Makefile
+++ b/arch/s390/mm/Makefile
@@ -4,4 +4,4 @@
4 4
5obj-y := init.o fault.o extmem.o mmap.o vmem.o pgtable.o 5obj-y := init.o fault.o extmem.o mmap.o vmem.o pgtable.o
6obj-$(CONFIG_CMM) += cmm.o 6obj-$(CONFIG_CMM) += cmm.o
7 7obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
diff --git a/arch/s390/mm/extmem.c b/arch/s390/mm/extmem.c
index ed2af0a3303b..f231f5ec74b6 100644
--- a/arch/s390/mm/extmem.c
+++ b/arch/s390/mm/extmem.c
@@ -287,7 +287,7 @@ __segment_load (char *name, int do_nonshared, unsigned long *addr, unsigned long
287 if (rc < 0) 287 if (rc < 0)
288 goto out_free; 288 goto out_free;
289 289
290 rc = add_shared_memory(seg->start_addr, seg->end - seg->start_addr + 1); 290 rc = vmem_add_mapping(seg->start_addr, seg->end - seg->start_addr + 1);
291 291
292 if (rc) 292 if (rc)
293 goto out_free; 293 goto out_free;
@@ -351,7 +351,7 @@ __segment_load (char *name, int do_nonshared, unsigned long *addr, unsigned long
351 release_resource(seg->res); 351 release_resource(seg->res);
352 kfree(seg->res); 352 kfree(seg->res);
353 out_shared: 353 out_shared:
354 remove_shared_memory(seg->start_addr, seg->end - seg->start_addr + 1); 354 vmem_remove_mapping(seg->start_addr, seg->end - seg->start_addr + 1);
355 out_free: 355 out_free:
356 kfree(seg); 356 kfree(seg);
357 out: 357 out:
@@ -474,7 +474,7 @@ segment_modify_shared (char *name, int do_nonshared)
474 rc = 0; 474 rc = 0;
475 goto out_unlock; 475 goto out_unlock;
476 out_del: 476 out_del:
477 remove_shared_memory(seg->start_addr, seg->end - seg->start_addr + 1); 477 vmem_remove_mapping(seg->start_addr, seg->end - seg->start_addr + 1);
478 list_del(&seg->list); 478 list_del(&seg->list);
479 dcss_diag(DCSS_PURGESEG, seg->dcss_name, &dummy, &dummy); 479 dcss_diag(DCSS_PURGESEG, seg->dcss_name, &dummy, &dummy);
480 kfree(seg); 480 kfree(seg);
@@ -508,7 +508,7 @@ segment_unload(char *name)
508 goto out_unlock; 508 goto out_unlock;
509 release_resource(seg->res); 509 release_resource(seg->res);
510 kfree(seg->res); 510 kfree(seg->res);
511 remove_shared_memory(seg->start_addr, seg->end - seg->start_addr + 1); 511 vmem_remove_mapping(seg->start_addr, seg->end - seg->start_addr + 1);
512 list_del(&seg->list); 512 list_del(&seg->list);
513 dcss_diag(DCSS_PURGESEG, seg->dcss_name, &dummy, &dummy); 513 dcss_diag(DCSS_PURGESEG, seg->dcss_name, &dummy, &dummy);
514 kfree(seg); 514 kfree(seg);
diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c
index 2650f46001d0..4d537205e83c 100644
--- a/arch/s390/mm/fault.c
+++ b/arch/s390/mm/fault.c
@@ -28,6 +28,7 @@
28#include <linux/hardirq.h> 28#include <linux/hardirq.h>
29#include <linux/kprobes.h> 29#include <linux/kprobes.h>
30#include <linux/uaccess.h> 30#include <linux/uaccess.h>
31#include <linux/hugetlb.h>
31#include <asm/system.h> 32#include <asm/system.h>
32#include <asm/pgtable.h> 33#include <asm/pgtable.h>
33#include <asm/s390_ext.h> 34#include <asm/s390_ext.h>
@@ -367,6 +368,8 @@ good_area:
367 } 368 }
368 369
369survive: 370survive:
371 if (is_vm_hugetlb_page(vma))
372 address &= HPAGE_MASK;
370 /* 373 /*
371 * If for any reason at all we couldn't handle the fault, 374 * If for any reason at all we couldn't handle the fault,
372 * make sure we exit gracefully rather than endlessly redo 375 * make sure we exit gracefully rather than endlessly redo
diff --git a/arch/s390/mm/hugetlbpage.c b/arch/s390/mm/hugetlbpage.c
new file mode 100644
index 000000000000..f4b6124fdb75
--- /dev/null
+++ b/arch/s390/mm/hugetlbpage.c
@@ -0,0 +1,134 @@
1/*
2 * IBM System z Huge TLB Page Support for Kernel.
3 *
4 * Copyright 2007 IBM Corp.
5 * Author(s): Gerald Schaefer <gerald.schaefer@de.ibm.com>
6 */
7
8#include <linux/mm.h>
9#include <linux/hugetlb.h>
10
11
12void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
13 pte_t *pteptr, pte_t pteval)
14{
15 pmd_t *pmdp = (pmd_t *) pteptr;
16 pte_t shadow_pteval = pteval;
17 unsigned long mask;
18
19 if (!MACHINE_HAS_HPAGE) {
20 pteptr = (pte_t *) pte_page(pteval)[1].index;
21 mask = pte_val(pteval) &
22 (_SEGMENT_ENTRY_INV | _SEGMENT_ENTRY_RO);
23 pte_val(pteval) = (_SEGMENT_ENTRY + __pa(pteptr)) | mask;
24 if (mm->context.noexec) {
25 pteptr += PTRS_PER_PTE;
26 pte_val(shadow_pteval) =
27 (_SEGMENT_ENTRY + __pa(pteptr)) | mask;
28 }
29 }
30
31 pmd_val(*pmdp) = pte_val(pteval);
32 if (mm->context.noexec) {
33 pmdp = get_shadow_table(pmdp);
34 pmd_val(*pmdp) = pte_val(shadow_pteval);
35 }
36}
37
38int arch_prepare_hugepage(struct page *page)
39{
40 unsigned long addr = page_to_phys(page);
41 pte_t pte;
42 pte_t *ptep;
43 int i;
44
45 if (MACHINE_HAS_HPAGE)
46 return 0;
47
48 ptep = (pte_t *) pte_alloc_one(&init_mm, address);
49 if (!ptep)
50 return -ENOMEM;
51
52 pte = mk_pte(page, PAGE_RW);
53 for (i = 0; i < PTRS_PER_PTE; i++) {
54 set_pte_at(&init_mm, addr + i * PAGE_SIZE, ptep + i, pte);
55 pte_val(pte) += PAGE_SIZE;
56 }
57 page[1].index = (unsigned long) ptep;
58 return 0;
59}
60
61void arch_release_hugepage(struct page *page)
62{
63 pte_t *ptep;
64
65 if (MACHINE_HAS_HPAGE)
66 return;
67
68 ptep = (pte_t *) page[1].index;
69 if (!ptep)
70 return;
71 pte_free(&init_mm, ptep);
72 page[1].index = 0;
73}
74
75pte_t *huge_pte_alloc(struct mm_struct *mm, unsigned long addr)
76{
77 pgd_t *pgdp;
78 pud_t *pudp;
79 pmd_t *pmdp = NULL;
80
81 pgdp = pgd_offset(mm, addr);
82 pudp = pud_alloc(mm, pgdp, addr);
83 if (pudp)
84 pmdp = pmd_alloc(mm, pudp, addr);
85 return (pte_t *) pmdp;
86}
87
88pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)
89{
90 pgd_t *pgdp;
91 pud_t *pudp;
92 pmd_t *pmdp = NULL;
93
94 pgdp = pgd_offset(mm, addr);
95 if (pgd_present(*pgdp)) {
96 pudp = pud_offset(pgdp, addr);
97 if (pud_present(*pudp))
98 pmdp = pmd_offset(pudp, addr);
99 }
100 return (pte_t *) pmdp;
101}
102
103int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
104{
105 return 0;
106}
107
108struct page *follow_huge_addr(struct mm_struct *mm, unsigned long address,
109 int write)
110{
111 return ERR_PTR(-EINVAL);
112}
113
114int pmd_huge(pmd_t pmd)
115{
116 if (!MACHINE_HAS_HPAGE)
117 return 0;
118
119 return !!(pmd_val(pmd) & _SEGMENT_ENTRY_LARGE);
120}
121
122struct page *follow_huge_pmd(struct mm_struct *mm, unsigned long address,
123 pmd_t *pmdp, int write)
124{
125 struct page *page;
126
127 if (!MACHINE_HAS_HPAGE)
128 return NULL;
129
130 page = pmd_page(*pmdp);
131 if (page)
132 page += ((address & ~HPAGE_MASK) >> PAGE_SHIFT);
133 return page;
134}
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index 202c952a29b4..fa31de6ae97a 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -77,28 +77,6 @@ void show_mem(void)
77 printk("%lu pages pagetables\n", global_page_state(NR_PAGETABLE)); 77 printk("%lu pages pagetables\n", global_page_state(NR_PAGETABLE));
78} 78}
79 79
80static void __init setup_ro_region(void)
81{
82 pgd_t *pgd;
83 pud_t *pud;
84 pmd_t *pmd;
85 pte_t *pte;
86 pte_t new_pte;
87 unsigned long address, end;
88
89 address = ((unsigned long)&_stext) & PAGE_MASK;
90 end = PFN_ALIGN((unsigned long)&_eshared);
91
92 for (; address < end; address += PAGE_SIZE) {
93 pgd = pgd_offset_k(address);
94 pud = pud_offset(pgd, address);
95 pmd = pmd_offset(pud, address);
96 pte = pte_offset_kernel(pmd, address);
97 new_pte = mk_pte_phys(address, __pgprot(_PAGE_RO));
98 *pte = new_pte;
99 }
100}
101
102/* 80/*
103 * paging_init() sets up the page tables 81 * paging_init() sets up the page tables
104 */ 82 */
@@ -121,7 +99,6 @@ void __init paging_init(void)
121 clear_table((unsigned long *) init_mm.pgd, pgd_type, 99 clear_table((unsigned long *) init_mm.pgd, pgd_type,
122 sizeof(unsigned long)*2048); 100 sizeof(unsigned long)*2048);
123 vmem_map_init(); 101 vmem_map_init();
124 setup_ro_region();
125 102
126 /* enable virtual mapping in kernel mode */ 103 /* enable virtual mapping in kernel mode */
127 __ctl_load(S390_lowcore.kernel_asce, 1, 1); 104 __ctl_load(S390_lowcore.kernel_asce, 1, 1);
@@ -129,6 +106,8 @@ void __init paging_init(void)
129 __ctl_load(S390_lowcore.kernel_asce, 13, 13); 106 __ctl_load(S390_lowcore.kernel_asce, 13, 13);
130 __raw_local_irq_ssm(ssm_mask); 107 __raw_local_irq_ssm(ssm_mask);
131 108
109 sparse_memory_present_with_active_regions(MAX_NUMNODES);
110 sparse_init();
132 memset(max_zone_pfns, 0, sizeof(max_zone_pfns)); 111 memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
133#ifdef CONFIG_ZONE_DMA 112#ifdef CONFIG_ZONE_DMA
134 max_zone_pfns[ZONE_DMA] = PFN_DOWN(MAX_DMA_ADDRESS); 113 max_zone_pfns[ZONE_DMA] = PFN_DOWN(MAX_DMA_ADDRESS);
diff --git a/arch/s390/mm/vmem.c b/arch/s390/mm/vmem.c
index 35d90a4720fd..beccacf907f3 100644
--- a/arch/s390/mm/vmem.c
+++ b/arch/s390/mm/vmem.c
@@ -10,10 +10,12 @@
10#include <linux/mm.h> 10#include <linux/mm.h>
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/list.h> 12#include <linux/list.h>
13#include <linux/hugetlb.h>
13#include <asm/pgalloc.h> 14#include <asm/pgalloc.h>
14#include <asm/pgtable.h> 15#include <asm/pgtable.h>
15#include <asm/setup.h> 16#include <asm/setup.h>
16#include <asm/tlbflush.h> 17#include <asm/tlbflush.h>
18#include <asm/sections.h>
17 19
18static DEFINE_MUTEX(vmem_mutex); 20static DEFINE_MUTEX(vmem_mutex);
19 21
@@ -25,43 +27,6 @@ struct memory_segment {
25 27
26static LIST_HEAD(mem_segs); 28static LIST_HEAD(mem_segs);
27 29
28void __meminit memmap_init(unsigned long size, int nid, unsigned long zone,
29 unsigned long start_pfn)
30{
31 struct page *start, *end;
32 struct page *map_start, *map_end;
33 int i;
34
35 start = pfn_to_page(start_pfn);
36 end = start + size;
37
38 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
39 unsigned long cstart, cend;
40
41 cstart = PFN_DOWN(memory_chunk[i].addr);
42 cend = cstart + PFN_DOWN(memory_chunk[i].size);
43
44 map_start = mem_map + cstart;
45 map_end = mem_map + cend;
46
47 if (map_start < start)
48 map_start = start;
49 if (map_end > end)
50 map_end = end;
51
52 map_start -= ((unsigned long) map_start & (PAGE_SIZE - 1))
53 / sizeof(struct page);
54 map_end += ((PFN_ALIGN((unsigned long) map_end)
55 - (unsigned long) map_end)
56 / sizeof(struct page));
57
58 if (map_start < map_end)
59 memmap_init_zone((unsigned long)(map_end - map_start),
60 nid, zone, page_to_pfn(map_start),
61 MEMMAP_EARLY);
62 }
63}
64
65static void __ref *vmem_alloc_pages(unsigned int order) 30static void __ref *vmem_alloc_pages(unsigned int order)
66{ 31{
67 if (slab_is_available()) 32 if (slab_is_available())
@@ -77,8 +42,7 @@ static inline pud_t *vmem_pud_alloc(void)
77 pud = vmem_alloc_pages(2); 42 pud = vmem_alloc_pages(2);
78 if (!pud) 43 if (!pud)
79 return NULL; 44 return NULL;
80 pud_val(*pud) = _REGION3_ENTRY_EMPTY; 45 clear_table((unsigned long *) pud, _REGION3_ENTRY_EMPTY, PAGE_SIZE * 4);
81 memcpy(pud + 1, pud, (PTRS_PER_PUD - 1)*sizeof(pud_t));
82#endif 46#endif
83 return pud; 47 return pud;
84} 48}
@@ -91,7 +55,7 @@ static inline pmd_t *vmem_pmd_alloc(void)
91 pmd = vmem_alloc_pages(2); 55 pmd = vmem_alloc_pages(2);
92 if (!pmd) 56 if (!pmd)
93 return NULL; 57 return NULL;
94 clear_table((unsigned long *) pmd, _SEGMENT_ENTRY_EMPTY, PAGE_SIZE*4); 58 clear_table((unsigned long *) pmd, _SEGMENT_ENTRY_EMPTY, PAGE_SIZE * 4);
95#endif 59#endif
96 return pmd; 60 return pmd;
97} 61}
@@ -114,7 +78,7 @@ static pte_t __init_refok *vmem_pte_alloc(void)
114/* 78/*
115 * Add a physical memory range to the 1:1 mapping. 79 * Add a physical memory range to the 1:1 mapping.
116 */ 80 */
117static int vmem_add_range(unsigned long start, unsigned long size) 81static int vmem_add_mem(unsigned long start, unsigned long size, int ro)
118{ 82{
119 unsigned long address; 83 unsigned long address;
120 pgd_t *pg_dir; 84 pgd_t *pg_dir;
@@ -141,7 +105,19 @@ static int vmem_add_range(unsigned long start, unsigned long size)
141 pud_populate_kernel(&init_mm, pu_dir, pm_dir); 105 pud_populate_kernel(&init_mm, pu_dir, pm_dir);
142 } 106 }
143 107
108 pte = mk_pte_phys(address, __pgprot(ro ? _PAGE_RO : 0));
144 pm_dir = pmd_offset(pu_dir, address); 109 pm_dir = pmd_offset(pu_dir, address);
110
111#ifdef __s390x__
112 if (MACHINE_HAS_HPAGE && !(address & ~HPAGE_MASK) &&
113 (address + HPAGE_SIZE <= start + size) &&
114 (address >= HPAGE_SIZE)) {
115 pte_val(pte) |= _SEGMENT_ENTRY_LARGE;
116 pmd_val(*pm_dir) = pte_val(pte);
117 address += HPAGE_SIZE - PAGE_SIZE;
118 continue;
119 }
120#endif
145 if (pmd_none(*pm_dir)) { 121 if (pmd_none(*pm_dir)) {
146 pt_dir = vmem_pte_alloc(); 122 pt_dir = vmem_pte_alloc();
147 if (!pt_dir) 123 if (!pt_dir)
@@ -150,7 +126,6 @@ static int vmem_add_range(unsigned long start, unsigned long size)
150 } 126 }
151 127
152 pt_dir = pte_offset_kernel(pm_dir, address); 128 pt_dir = pte_offset_kernel(pm_dir, address);
153 pte = pfn_pte(address >> PAGE_SHIFT, PAGE_KERNEL);
154 *pt_dir = pte; 129 *pt_dir = pte;
155 } 130 }
156 ret = 0; 131 ret = 0;
@@ -181,6 +156,13 @@ static void vmem_remove_range(unsigned long start, unsigned long size)
181 pm_dir = pmd_offset(pu_dir, address); 156 pm_dir = pmd_offset(pu_dir, address);
182 if (pmd_none(*pm_dir)) 157 if (pmd_none(*pm_dir))
183 continue; 158 continue;
159
160 if (pmd_huge(*pm_dir)) {
161 pmd_clear_kernel(pm_dir);
162 address += HPAGE_SIZE - PAGE_SIZE;
163 continue;
164 }
165
184 pt_dir = pte_offset_kernel(pm_dir, address); 166 pt_dir = pte_offset_kernel(pm_dir, address);
185 *pt_dir = pte; 167 *pt_dir = pte;
186 } 168 }
@@ -190,10 +172,9 @@ static void vmem_remove_range(unsigned long start, unsigned long size)
190/* 172/*
191 * Add a backed mem_map array to the virtual mem_map array. 173 * Add a backed mem_map array to the virtual mem_map array.
192 */ 174 */
193static int vmem_add_mem_map(unsigned long start, unsigned long size) 175int __meminit vmemmap_populate(struct page *start, unsigned long nr, int node)
194{ 176{
195 unsigned long address, start_addr, end_addr; 177 unsigned long address, start_addr, end_addr;
196 struct page *map_start, *map_end;
197 pgd_t *pg_dir; 178 pgd_t *pg_dir;
198 pud_t *pu_dir; 179 pud_t *pu_dir;
199 pmd_t *pm_dir; 180 pmd_t *pm_dir;
@@ -201,11 +182,8 @@ static int vmem_add_mem_map(unsigned long start, unsigned long size)
201 pte_t pte; 182 pte_t pte;
202 int ret = -ENOMEM; 183 int ret = -ENOMEM;
203 184
204 map_start = VMEM_MAP + PFN_DOWN(start); 185 start_addr = (unsigned long) start;
205 map_end = VMEM_MAP + PFN_DOWN(start + size); 186 end_addr = (unsigned long) (start + nr);
206
207 start_addr = (unsigned long) map_start & PAGE_MASK;
208 end_addr = PFN_ALIGN((unsigned long) map_end);
209 187
210 for (address = start_addr; address < end_addr; address += PAGE_SIZE) { 188 for (address = start_addr; address < end_addr; address += PAGE_SIZE) {
211 pg_dir = pgd_offset_k(address); 189 pg_dir = pgd_offset_k(address);
@@ -249,16 +227,6 @@ out:
249 return ret; 227 return ret;
250} 228}
251 229
252static int vmem_add_mem(unsigned long start, unsigned long size)
253{
254 int ret;
255
256 ret = vmem_add_mem_map(start, size);
257 if (ret)
258 return ret;
259 return vmem_add_range(start, size);
260}
261
262/* 230/*
263 * Add memory segment to the segment list if it doesn't overlap with 231 * Add memory segment to the segment list if it doesn't overlap with
264 * an already present segment. 232 * an already present segment.
@@ -296,7 +264,7 @@ static void __remove_shared_memory(struct memory_segment *seg)
296 vmem_remove_range(seg->start, seg->size); 264 vmem_remove_range(seg->start, seg->size);
297} 265}
298 266
299int remove_shared_memory(unsigned long start, unsigned long size) 267int vmem_remove_mapping(unsigned long start, unsigned long size)
300{ 268{
301 struct memory_segment *seg; 269 struct memory_segment *seg;
302 int ret; 270 int ret;
@@ -320,11 +288,9 @@ out:
320 return ret; 288 return ret;
321} 289}
322 290
323int add_shared_memory(unsigned long start, unsigned long size) 291int vmem_add_mapping(unsigned long start, unsigned long size)
324{ 292{
325 struct memory_segment *seg; 293 struct memory_segment *seg;
326 struct page *page;
327 unsigned long pfn, num_pfn, end_pfn;
328 int ret; 294 int ret;
329 295
330 mutex_lock(&vmem_mutex); 296 mutex_lock(&vmem_mutex);
@@ -339,24 +305,9 @@ int add_shared_memory(unsigned long start, unsigned long size)
339 if (ret) 305 if (ret)
340 goto out_free; 306 goto out_free;
341 307
342 ret = vmem_add_mem(start, size); 308 ret = vmem_add_mem(start, size, 0);
343 if (ret) 309 if (ret)
344 goto out_remove; 310 goto out_remove;
345
346 pfn = PFN_DOWN(start);
347 num_pfn = PFN_DOWN(size);
348 end_pfn = pfn + num_pfn;
349
350 page = pfn_to_page(pfn);
351 memset(page, 0, num_pfn * sizeof(struct page));
352
353 for (; pfn < end_pfn; pfn++) {
354 page = pfn_to_page(pfn);
355 init_page_count(page);
356 reset_page_mapcount(page);
357 SetPageReserved(page);
358 INIT_LIST_HEAD(&page->lru);
359 }
360 goto out; 311 goto out;
361 312
362out_remove: 313out_remove:
@@ -375,14 +326,34 @@ out:
375 */ 326 */
376void __init vmem_map_init(void) 327void __init vmem_map_init(void)
377{ 328{
329 unsigned long ro_start, ro_end;
330 unsigned long start, end;
378 int i; 331 int i;
379 332
380 INIT_LIST_HEAD(&init_mm.context.crst_list); 333 INIT_LIST_HEAD(&init_mm.context.crst_list);
381 INIT_LIST_HEAD(&init_mm.context.pgtable_list); 334 INIT_LIST_HEAD(&init_mm.context.pgtable_list);
382 init_mm.context.noexec = 0; 335 init_mm.context.noexec = 0;
383 NODE_DATA(0)->node_mem_map = VMEM_MAP; 336 ro_start = ((unsigned long)&_stext) & PAGE_MASK;
384 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) 337 ro_end = PFN_ALIGN((unsigned long)&_eshared);
385 vmem_add_mem(memory_chunk[i].addr, memory_chunk[i].size); 338 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
339 start = memory_chunk[i].addr;
340 end = memory_chunk[i].addr + memory_chunk[i].size;
341 if (start >= ro_end || end <= ro_start)
342 vmem_add_mem(start, end - start, 0);
343 else if (start >= ro_start && end <= ro_end)
344 vmem_add_mem(start, end - start, 1);
345 else if (start >= ro_start) {
346 vmem_add_mem(start, ro_end - start, 1);
347 vmem_add_mem(ro_end, end - ro_end, 0);
348 } else if (end < ro_end) {
349 vmem_add_mem(start, ro_start - start, 0);
350 vmem_add_mem(ro_start, end - ro_start, 1);
351 } else {
352 vmem_add_mem(start, ro_start - start, 0);
353 vmem_add_mem(ro_start, ro_end - ro_start, 1);
354 vmem_add_mem(ro_end, end - ro_end, 0);
355 }
356 }
386} 357}
387 358
388/* 359/*
diff --git a/arch/sh/kernel/sys_sh64.c b/arch/sh/kernel/sys_sh64.c
index 578004d71e02..91fb8445a5a0 100644
--- a/arch/sh/kernel/sys_sh64.c
+++ b/arch/sh/kernel/sys_sh64.c
@@ -31,23 +31,6 @@
31#include <asm/unistd.h> 31#include <asm/unistd.h>
32 32
33/* 33/*
34 * sys_pipe() is the normal C calling standard for creating
35 * a pipe. It's not the way Unix traditionally does this, though.
36 */
37asmlinkage int sys_pipe(unsigned long * fildes)
38{
39 int fd[2];
40 int error;
41
42 error = do_pipe(fd);
43 if (!error) {
44 if (copy_to_user(fildes, fd, 2*sizeof(int)))
45 error = -EFAULT;
46 }
47 return error;
48}
49
50/*
51 * Do a system call from kernel instead of calling sys_execve so we 34 * Do a system call from kernel instead of calling sys_execve so we
52 * end up with proper pt_regs. 35 * end up with proper pt_regs.
53 */ 36 */
diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index 49590f8fe98c..d211fdb24584 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -68,6 +68,7 @@ config SPARC
68 default y 68 default y
69 select HAVE_IDE 69 select HAVE_IDE
70 select HAVE_OPROFILE 70 select HAVE_OPROFILE
71 select HAVE_ARCH_KGDB if !SMP
71 72
72# Identify this as a Sparc32 build 73# Identify this as a Sparc32 build
73config SPARC32 74config SPARC32
diff --git a/arch/sparc/defconfig b/arch/sparc/defconfig
index 6a2c57a2fe71..2e3a149ea0e7 100644
--- a/arch/sparc/defconfig
+++ b/arch/sparc/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.25 3# Linux kernel version: 2.6.25
4# Sun Apr 20 01:49:51 2008 4# Tue Apr 29 01:28:58 2008
5# 5#
6CONFIG_MMU=y 6CONFIG_MMU=y
7CONFIG_HIGHMEM=y 7CONFIG_HIGHMEM=y
@@ -217,12 +217,7 @@ CONFIG_IPV6_TUNNEL=m
217# CONFIG_NETWORK_SECMARK is not set 217# CONFIG_NETWORK_SECMARK is not set
218# CONFIG_NETFILTER is not set 218# CONFIG_NETFILTER is not set
219# CONFIG_IP_DCCP is not set 219# CONFIG_IP_DCCP is not set
220CONFIG_IP_SCTP=m 220# CONFIG_IP_SCTP is not set
221# CONFIG_SCTP_DBG_MSG is not set
222CONFIG_SCTP_DBG_OBJCNT=y
223# CONFIG_SCTP_HMAC_NONE is not set
224# CONFIG_SCTP_HMAC_SHA1 is not set
225CONFIG_SCTP_HMAC_MD5=y
226# CONFIG_TIPC is not set 221# CONFIG_TIPC is not set
227# CONFIG_ATM is not set 222# CONFIG_ATM is not set
228# CONFIG_BRIDGE is not set 223# CONFIG_BRIDGE is not set
@@ -245,9 +240,7 @@ CONFIG_NET_PKTGEN=m
245# CONFIG_CAN is not set 240# CONFIG_CAN is not set
246# CONFIG_IRDA is not set 241# CONFIG_IRDA is not set
247# CONFIG_BT is not set 242# CONFIG_BT is not set
248CONFIG_AF_RXRPC=m 243# CONFIG_AF_RXRPC is not set
249# CONFIG_AF_RXRPC_DEBUG is not set
250# CONFIG_RXKAD is not set
251 244
252# 245#
253# Wireless 246# Wireless
@@ -390,7 +383,7 @@ CONFIG_DUMMY=m
390# CONFIG_BONDING is not set 383# CONFIG_BONDING is not set
391# CONFIG_MACVLAN is not set 384# CONFIG_MACVLAN is not set
392# CONFIG_EQUALIZER is not set 385# CONFIG_EQUALIZER is not set
393CONFIG_TUN=m 386# CONFIG_TUN is not set
394# CONFIG_VETH is not set 387# CONFIG_VETH is not set
395# CONFIG_ARCNET is not set 388# CONFIG_ARCNET is not set
396# CONFIG_PHYLIB is not set 389# CONFIG_PHYLIB is not set
@@ -544,6 +537,7 @@ CONFIG_SERIAL_SUNSU_CONSOLE=y
544# CONFIG_SERIAL_SUNSAB is not set 537# CONFIG_SERIAL_SUNSAB is not set
545CONFIG_SERIAL_CORE=y 538CONFIG_SERIAL_CORE=y
546CONFIG_SERIAL_CORE_CONSOLE=y 539CONFIG_SERIAL_CORE_CONSOLE=y
540CONFIG_CONSOLE_POLL=y
547# CONFIG_SERIAL_JSM is not set 541# CONFIG_SERIAL_JSM is not set
548CONFIG_UNIX98_PTYS=y 542CONFIG_UNIX98_PTYS=y
549CONFIG_LEGACY_PTYS=y 543CONFIG_LEGACY_PTYS=y
@@ -595,6 +589,7 @@ CONFIG_SSB_POSSIBLE=y
595# Multifunction device drivers 589# Multifunction device drivers
596# 590#
597# CONFIG_MFD_SM501 is not set 591# CONFIG_MFD_SM501 is not set
592# CONFIG_HTC_PASIC3 is not set
598 593
599# 594#
600# Multimedia devices 595# Multimedia devices
@@ -645,10 +640,6 @@ CONFIG_USB_ARCH_HAS_EHCI=y
645# CONFIG_NEW_LEDS is not set 640# CONFIG_NEW_LEDS is not set
646# CONFIG_INFINIBAND is not set 641# CONFIG_INFINIBAND is not set
647# CONFIG_RTC_CLASS is not set 642# CONFIG_RTC_CLASS is not set
648
649#
650# Userspace I/O
651#
652# CONFIG_UIO is not set 643# CONFIG_UIO is not set
653 644
654# 645#
@@ -680,16 +671,12 @@ CONFIG_FS_MBCACHE=y
680# CONFIG_REISERFS_FS is not set 671# CONFIG_REISERFS_FS is not set
681# CONFIG_JFS_FS is not set 672# CONFIG_JFS_FS is not set
682CONFIG_FS_POSIX_ACL=y 673CONFIG_FS_POSIX_ACL=y
683CONFIG_XFS_FS=m 674# CONFIG_XFS_FS is not set
684CONFIG_XFS_QUOTA=y
685CONFIG_XFS_POSIX_ACL=y
686CONFIG_XFS_RT=y
687# CONFIG_OCFS2_FS is not set 675# CONFIG_OCFS2_FS is not set
688CONFIG_DNOTIFY=y 676CONFIG_DNOTIFY=y
689CONFIG_INOTIFY=y 677CONFIG_INOTIFY=y
690CONFIG_INOTIFY_USER=y 678CONFIG_INOTIFY_USER=y
691# CONFIG_QUOTA is not set 679# CONFIG_QUOTA is not set
692CONFIG_QUOTACTL=y
693CONFIG_AUTOFS_FS=m 680CONFIG_AUTOFS_FS=m
694CONFIG_AUTOFS4_FS=m 681CONFIG_AUTOFS4_FS=m
695# CONFIG_FUSE_FS is not set 682# CONFIG_FUSE_FS is not set
@@ -725,11 +712,9 @@ CONFIG_SYSFS=y
725# 712#
726# CONFIG_ADFS_FS is not set 713# CONFIG_ADFS_FS is not set
727# CONFIG_AFFS_FS is not set 714# CONFIG_AFFS_FS is not set
728# CONFIG_ECRYPT_FS is not set
729# CONFIG_HFS_FS is not set 715# CONFIG_HFS_FS is not set
730# CONFIG_HFSPLUS_FS is not set 716# CONFIG_HFSPLUS_FS is not set
731CONFIG_BEFS_FS=m 717# CONFIG_BEFS_FS is not set
732# CONFIG_BEFS_DEBUG is not set
733# CONFIG_BFS_FS is not set 718# CONFIG_BFS_FS is not set
734# CONFIG_EFS_FS is not set 719# CONFIG_EFS_FS is not set
735# CONFIG_CRAMFS is not set 720# CONFIG_CRAMFS is not set
@@ -744,7 +729,6 @@ CONFIG_NETWORK_FILESYSTEMS=y
744CONFIG_NFS_FS=y 729CONFIG_NFS_FS=y
745# CONFIG_NFS_V3 is not set 730# CONFIG_NFS_V3 is not set
746# CONFIG_NFS_V4 is not set 731# CONFIG_NFS_V4 is not set
747# CONFIG_NFS_DIRECTIO is not set
748# CONFIG_NFSD is not set 732# CONFIG_NFSD is not set
749CONFIG_ROOT_NFS=y 733CONFIG_ROOT_NFS=y
750CONFIG_LOCKD=y 734CONFIG_LOCKD=y
@@ -755,16 +739,10 @@ CONFIG_SUNRPC_GSS=m
755CONFIG_RPCSEC_GSS_KRB5=m 739CONFIG_RPCSEC_GSS_KRB5=m
756# CONFIG_RPCSEC_GSS_SPKM3 is not set 740# CONFIG_RPCSEC_GSS_SPKM3 is not set
757# CONFIG_SMB_FS is not set 741# CONFIG_SMB_FS is not set
758CONFIG_CIFS=m 742# CONFIG_CIFS is not set
759# CONFIG_CIFS_STATS is not set
760# CONFIG_CIFS_WEAK_PW_HASH is not set
761# CONFIG_CIFS_XATTR is not set
762# CONFIG_CIFS_DEBUG2 is not set
763# CONFIG_CIFS_EXPERIMENTAL is not set
764# CONFIG_NCP_FS is not set 743# CONFIG_NCP_FS is not set
765# CONFIG_CODA_FS is not set 744# CONFIG_CODA_FS is not set
766CONFIG_AFS_FS=m 745# CONFIG_AFS_FS is not set
767# CONFIG_AFS_DEBUG is not set
768 746
769# 747#
770# Partition Types 748# Partition Types
@@ -821,6 +799,7 @@ CONFIG_TRACE_IRQFLAGS_SUPPORT=y
821# CONFIG_PRINTK_TIME is not set 799# CONFIG_PRINTK_TIME is not set
822# CONFIG_ENABLE_WARN_DEPRECATED is not set 800# CONFIG_ENABLE_WARN_DEPRECATED is not set
823CONFIG_ENABLE_MUST_CHECK=y 801CONFIG_ENABLE_MUST_CHECK=y
802CONFIG_FRAME_WARN=1024
824CONFIG_MAGIC_SYSRQ=y 803CONFIG_MAGIC_SYSRQ=y
825# CONFIG_UNUSED_SYMBOLS is not set 804# CONFIG_UNUSED_SYMBOLS is not set
826# CONFIG_DEBUG_FS is not set 805# CONFIG_DEBUG_FS is not set
@@ -842,70 +821,105 @@ CONFIG_DETECT_SOFTLOCKUP=y
842CONFIG_DEBUG_BUGVERBOSE=y 821CONFIG_DEBUG_BUGVERBOSE=y
843# CONFIG_DEBUG_INFO is not set 822# CONFIG_DEBUG_INFO is not set
844# CONFIG_DEBUG_VM is not set 823# CONFIG_DEBUG_VM is not set
824# CONFIG_DEBUG_WRITECOUNT is not set
845# CONFIG_DEBUG_LIST is not set 825# CONFIG_DEBUG_LIST is not set
846# CONFIG_DEBUG_SG is not set 826# CONFIG_DEBUG_SG is not set
827CONFIG_FRAME_POINTER=y
847# CONFIG_BOOT_PRINTK_DELAY is not set 828# CONFIG_BOOT_PRINTK_DELAY is not set
848# CONFIG_RCU_TORTURE_TEST is not set 829# CONFIG_RCU_TORTURE_TEST is not set
849# CONFIG_BACKTRACE_SELF_TEST is not set 830# CONFIG_BACKTRACE_SELF_TEST is not set
850# CONFIG_FAULT_INJECTION is not set 831# CONFIG_FAULT_INJECTION is not set
851# CONFIG_SAMPLES is not set 832# CONFIG_SAMPLES is not set
833CONFIG_KGDB=y
834CONFIG_HAVE_ARCH_KGDB=y
835CONFIG_KGDB_SERIAL_CONSOLE=y
836CONFIG_KGDB_TESTS=y
837# CONFIG_KGDB_TESTS_ON_BOOT is not set
852# CONFIG_DEBUG_STACK_USAGE is not set 838# CONFIG_DEBUG_STACK_USAGE is not set
853 839
854# 840#
855# Security options 841# Security options
856# 842#
857CONFIG_KEYS=y 843# CONFIG_KEYS is not set
858# CONFIG_KEYS_DEBUG_PROC_KEYS is not set
859# CONFIG_SECURITY is not set 844# CONFIG_SECURITY is not set
860# CONFIG_SECURITY_FILE_CAPABILITIES is not set 845# CONFIG_SECURITY_FILE_CAPABILITIES is not set
861CONFIG_CRYPTO=y 846CONFIG_CRYPTO=y
847
848#
849# Crypto core or helper
850#
862CONFIG_CRYPTO_ALGAPI=y 851CONFIG_CRYPTO_ALGAPI=y
863CONFIG_CRYPTO_AEAD=y 852CONFIG_CRYPTO_AEAD=y
864CONFIG_CRYPTO_BLKCIPHER=y 853CONFIG_CRYPTO_BLKCIPHER=y
865# CONFIG_CRYPTO_SEQIV is not set
866CONFIG_CRYPTO_HASH=y 854CONFIG_CRYPTO_HASH=y
867CONFIG_CRYPTO_MANAGER=y 855CONFIG_CRYPTO_MANAGER=y
856# CONFIG_CRYPTO_GF128MUL is not set
857CONFIG_CRYPTO_NULL=m
858# CONFIG_CRYPTO_CRYPTD is not set
859CONFIG_CRYPTO_AUTHENC=y
860# CONFIG_CRYPTO_TEST is not set
861
862#
863# Authenticated Encryption with Associated Data
864#
865# CONFIG_CRYPTO_CCM is not set
866# CONFIG_CRYPTO_GCM is not set
867# CONFIG_CRYPTO_SEQIV is not set
868
869#
870# Block modes
871#
872CONFIG_CRYPTO_CBC=y
873# CONFIG_CRYPTO_CTR is not set
874# CONFIG_CRYPTO_CTS is not set
875CONFIG_CRYPTO_ECB=m
876# CONFIG_CRYPTO_LRW is not set
877CONFIG_CRYPTO_PCBC=m
878# CONFIG_CRYPTO_XTS is not set
879
880#
881# Hash modes
882#
868CONFIG_CRYPTO_HMAC=y 883CONFIG_CRYPTO_HMAC=y
869# CONFIG_CRYPTO_XCBC is not set 884# CONFIG_CRYPTO_XCBC is not set
870CONFIG_CRYPTO_NULL=m 885
886#
887# Digest
888#
889CONFIG_CRYPTO_CRC32C=m
871CONFIG_CRYPTO_MD4=y 890CONFIG_CRYPTO_MD4=y
872CONFIG_CRYPTO_MD5=y 891CONFIG_CRYPTO_MD5=y
892CONFIG_CRYPTO_MICHAEL_MIC=m
873CONFIG_CRYPTO_SHA1=y 893CONFIG_CRYPTO_SHA1=y
874CONFIG_CRYPTO_SHA256=m 894CONFIG_CRYPTO_SHA256=m
875CONFIG_CRYPTO_SHA512=m 895CONFIG_CRYPTO_SHA512=m
876# CONFIG_CRYPTO_WP512 is not set
877# CONFIG_CRYPTO_TGR192 is not set 896# CONFIG_CRYPTO_TGR192 is not set
878# CONFIG_CRYPTO_GF128MUL is not set 897# CONFIG_CRYPTO_WP512 is not set
879CONFIG_CRYPTO_ECB=m 898
880CONFIG_CRYPTO_CBC=y 899#
881CONFIG_CRYPTO_PCBC=m 900# Ciphers
882# CONFIG_CRYPTO_LRW is not set 901#
883# CONFIG_CRYPTO_XTS is not set
884# CONFIG_CRYPTO_CTR is not set
885# CONFIG_CRYPTO_GCM is not set
886# CONFIG_CRYPTO_CCM is not set
887# CONFIG_CRYPTO_CRYPTD is not set
888CONFIG_CRYPTO_DES=y
889# CONFIG_CRYPTO_FCRYPT is not set
890CONFIG_CRYPTO_BLOWFISH=m
891CONFIG_CRYPTO_TWOFISH=m
892CONFIG_CRYPTO_TWOFISH_COMMON=m
893CONFIG_CRYPTO_SERPENT=m
894CONFIG_CRYPTO_AES=m 902CONFIG_CRYPTO_AES=m
903# CONFIG_CRYPTO_ANUBIS is not set
904CONFIG_CRYPTO_ARC4=m
905CONFIG_CRYPTO_BLOWFISH=m
906# CONFIG_CRYPTO_CAMELLIA is not set
895CONFIG_CRYPTO_CAST5=m 907CONFIG_CRYPTO_CAST5=m
896CONFIG_CRYPTO_CAST6=m 908CONFIG_CRYPTO_CAST6=m
897# CONFIG_CRYPTO_TEA is not set 909CONFIG_CRYPTO_DES=y
898CONFIG_CRYPTO_ARC4=m 910# CONFIG_CRYPTO_FCRYPT is not set
899# CONFIG_CRYPTO_KHAZAD is not set 911# CONFIG_CRYPTO_KHAZAD is not set
900# CONFIG_CRYPTO_ANUBIS is not set
901# CONFIG_CRYPTO_SEED is not set
902# CONFIG_CRYPTO_SALSA20 is not set 912# CONFIG_CRYPTO_SALSA20 is not set
913# CONFIG_CRYPTO_SEED is not set
914CONFIG_CRYPTO_SERPENT=m
915# CONFIG_CRYPTO_TEA is not set
916CONFIG_CRYPTO_TWOFISH=m
917CONFIG_CRYPTO_TWOFISH_COMMON=m
918
919#
920# Compression
921#
903CONFIG_CRYPTO_DEFLATE=y 922CONFIG_CRYPTO_DEFLATE=y
904CONFIG_CRYPTO_MICHAEL_MIC=m
905CONFIG_CRYPTO_CRC32C=m
906# CONFIG_CRYPTO_CAMELLIA is not set
907# CONFIG_CRYPTO_TEST is not set
908CONFIG_CRYPTO_AUTHENC=y
909# CONFIG_CRYPTO_LZO is not set 923# CONFIG_CRYPTO_LZO is not set
910# CONFIG_CRYPTO_HW is not set 924# CONFIG_CRYPTO_HW is not set
911 925
@@ -913,6 +927,7 @@ CONFIG_CRYPTO_AUTHENC=y
913# Library routines 927# Library routines
914# 928#
915CONFIG_BITREVERSE=y 929CONFIG_BITREVERSE=y
930# CONFIG_GENERIC_FIND_FIRST_BIT is not set
916# CONFIG_CRC_CCITT is not set 931# CONFIG_CRC_CCITT is not set
917# CONFIG_CRC16 is not set 932# CONFIG_CRC16 is not set
918# CONFIG_CRC_ITU_T is not set 933# CONFIG_CRC_ITU_T is not set
diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
index 59700aaaae93..6e03a2a7863c 100644
--- a/arch/sparc/kernel/Makefile
+++ b/arch/sparc/kernel/Makefile
@@ -25,3 +25,4 @@ obj-$(CONFIG_PCI) += ebus.o
25obj-$(CONFIG_SUN_PM) += apc.o pmc.o 25obj-$(CONFIG_SUN_PM) += apc.o pmc.o
26obj-$(CONFIG_MODULES) += module.o sparc_ksyms.o 26obj-$(CONFIG_MODULES) += module.o sparc_ksyms.o
27obj-$(CONFIG_SPARC_LED) += led.o 27obj-$(CONFIG_SPARC_LED) += led.o
28obj-$(CONFIG_KGDB) += kgdb.o
diff --git a/arch/sparc/kernel/entry.S b/arch/sparc/kernel/entry.S
index 484c83d23eef..57d1bbdd0bd2 100644
--- a/arch/sparc/kernel/entry.S
+++ b/arch/sparc/kernel/entry.S
@@ -12,7 +12,6 @@
12#include <asm/head.h> 12#include <asm/head.h>
13#include <asm/asi.h> 13#include <asm/asi.h>
14#include <asm/smp.h> 14#include <asm/smp.h>
15#include <asm/kgdb.h>
16#include <asm/contregs.h> 15#include <asm/contregs.h>
17#include <asm/ptrace.h> 16#include <asm/ptrace.h>
18#include <asm/asm-offsets.h> 17#include <asm/asm-offsets.h>
@@ -45,91 +44,20 @@
45 _SV; _SV; _SV; _SV; _SV; _SV; _SV; \ 44 _SV; _SV; _SV; _SV; _SV; _SV; _SV; \
46 _RS; _RS; _RS; _RS; _RS; _RS; _RS; 45 _RS; _RS; _RS; _RS; _RS; _RS; _RS;
47 46
48/* First, KGDB low level things. This is a rewrite
49 * of the routines found in the sparc-stub.c asm() statement
50 * from the gdb distribution. This is also dual-purpose
51 * as a software trap for userlevel programs.
52 */
53 .data
54 .align 4
55
56in_trap_handler:
57 .word 0
58
59 .text 47 .text
60 .align 4
61 48
62#if 0 /* kgdb is dropped from 2.5.33 */ 49#ifdef CONFIG_KGDB
63! This function is called when any SPARC trap (except window overflow or 50 .align 4
64! underflow) occurs. It makes sure that the invalid register window is still 51 .globl arch_kgdb_breakpoint
65! available before jumping into C code. It will also restore the world if you 52 .type arch_kgdb_breakpoint,#function
66! return from handle_exception. 53arch_kgdb_breakpoint:
67 54 ta 0x7d
68 .globl trap_low 55 retl
69trap_low: 56 nop
70 rd %wim, %l3 57 .size arch_kgdb_breakpoint,.-arch_kgdb_breakpoint
71 SAVE_ALL
72
73 sethi %hi(in_trap_handler), %l4
74 ld [%lo(in_trap_handler) + %l4], %l5
75 inc %l5
76 st %l5, [%lo(in_trap_handler) + %l4]
77
78 /* Make sure kgdb sees the same state we just saved. */
79 LOAD_PT_GLOBALS(sp)
80 LOAD_PT_INS(sp)
81 ld [%sp + STACKFRAME_SZ + PT_Y], %l4
82 ld [%sp + STACKFRAME_SZ + PT_WIM], %l3
83 ld [%sp + STACKFRAME_SZ + PT_PSR], %l0
84 ld [%sp + STACKFRAME_SZ + PT_PC], %l1
85 ld [%sp + STACKFRAME_SZ + PT_NPC], %l2
86 rd %tbr, %l5 /* Never changes... */
87
88 /* Make kgdb exception frame. */
89 sub %sp,(16+1+6+1+72)*4,%sp ! Make room for input & locals
90 ! + hidden arg + arg spill
91 ! + doubleword alignment
92 ! + registers[72] local var
93 SAVE_KGDB_GLOBALS(sp)
94 SAVE_KGDB_INS(sp)
95 SAVE_KGDB_SREGS(sp, l4, l0, l3, l5, l1, l2)
96
97 /* We are increasing PIL, so two writes. */
98 or %l0, PSR_PIL, %l0
99 wr %l0, 0, %psr
100 WRITE_PAUSE
101 wr %l0, PSR_ET, %psr
102 WRITE_PAUSE
103
104 call handle_exception
105 add %sp, STACKFRAME_SZ, %o0 ! Pass address of registers
106
107 /* Load new kgdb register set. */
108 LOAD_KGDB_GLOBALS(sp)
109 LOAD_KGDB_INS(sp)
110 LOAD_KGDB_SREGS(sp, l4, l0, l3, l5, l1, l2)
111 wr %l4, 0x0, %y
112
113 sethi %hi(in_trap_handler), %l4
114 ld [%lo(in_trap_handler) + %l4], %l5
115 dec %l5
116 st %l5, [%lo(in_trap_handler) + %l4]
117
118 add %sp,(16+1+6+1+72)*4,%sp ! Undo the kgdb trap frame.
119
120 /* Now take what kgdb did and place it into the pt_regs
121 * frame which SparcLinux RESTORE_ALL understands.,
122 */
123 STORE_PT_INS(sp)
124 STORE_PT_GLOBALS(sp)
125 STORE_PT_YREG(sp, g2)
126 STORE_PT_PRIV(sp, l0, l1, l2)
127
128 RESTORE_ALL
129#endif 58#endif
130 59
131#if defined(CONFIG_BLK_DEV_FD) || defined(CONFIG_BLK_DEV_FD_MODULE) 60#if defined(CONFIG_BLK_DEV_FD) || defined(CONFIG_BLK_DEV_FD_MODULE)
132 .text
133 .align 4 61 .align 4
134 .globl floppy_hardint 62 .globl floppy_hardint
135floppy_hardint: 63floppy_hardint:
@@ -1596,6 +1524,23 @@ breakpoint_trap:
1596 1524
1597 RESTORE_ALL 1525 RESTORE_ALL
1598 1526
1527#ifdef CONFIG_KGDB
1528 .align 4
1529 .globl kgdb_trap_low
1530 .type kgdb_trap_low,#function
1531kgdb_trap_low:
1532 rd %wim,%l3
1533 SAVE_ALL
1534 wr %l0, PSR_ET, %psr
1535 WRITE_PAUSE
1536
1537 call kgdb_trap
1538 add %sp, STACKFRAME_SZ, %o0
1539
1540 RESTORE_ALL
1541 .size kgdb_trap_low,.-kgdb_trap_low
1542#endif
1543
1599 .align 4 1544 .align 4
1600 .globl __handle_exception, flush_patch_exception 1545 .globl __handle_exception, flush_patch_exception
1601__handle_exception: 1546__handle_exception:
@@ -1698,4 +1643,22 @@ pcic_nmi_trap_patch:
1698 1643
1699#endif /* CONFIG_PCI */ 1644#endif /* CONFIG_PCI */
1700 1645
1646 .globl flushw_all
1647flushw_all:
1648 save %sp, -0x40, %sp
1649 save %sp, -0x40, %sp
1650 save %sp, -0x40, %sp
1651 save %sp, -0x40, %sp
1652 save %sp, -0x40, %sp
1653 save %sp, -0x40, %sp
1654 save %sp, -0x40, %sp
1655 restore
1656 restore
1657 restore
1658 restore
1659 restore
1660 restore
1661 ret
1662 restore
1663
1701/* End of entry.S */ 1664/* End of entry.S */
diff --git a/arch/sparc/kernel/head.S b/arch/sparc/kernel/head.S
index b7f1e81c8ff2..8bec05fa5795 100644
--- a/arch/sparc/kernel/head.S
+++ b/arch/sparc/kernel/head.S
@@ -191,7 +191,8 @@ t_bade8:BAD_TRAP(0xe8) BAD_TRAP(0xe9) BAD_TRAP(0xea) BAD_TRAP(0xeb) BAD_TRAP(0xe
191t_baded:BAD_TRAP(0xed) BAD_TRAP(0xee) BAD_TRAP(0xef) BAD_TRAP(0xf0) BAD_TRAP(0xf1) 191t_baded:BAD_TRAP(0xed) BAD_TRAP(0xee) BAD_TRAP(0xef) BAD_TRAP(0xf0) BAD_TRAP(0xf1)
192t_badf2:BAD_TRAP(0xf2) BAD_TRAP(0xf3) BAD_TRAP(0xf4) BAD_TRAP(0xf5) BAD_TRAP(0xf6) 192t_badf2:BAD_TRAP(0xf2) BAD_TRAP(0xf3) BAD_TRAP(0xf4) BAD_TRAP(0xf5) BAD_TRAP(0xf6)
193t_badf7:BAD_TRAP(0xf7) BAD_TRAP(0xf8) BAD_TRAP(0xf9) BAD_TRAP(0xfa) BAD_TRAP(0xfb) 193t_badf7:BAD_TRAP(0xf7) BAD_TRAP(0xf8) BAD_TRAP(0xf9) BAD_TRAP(0xfa) BAD_TRAP(0xfb)
194t_badfc:BAD_TRAP(0xfc) BAD_TRAP(0xfd) 194t_badfc:BAD_TRAP(0xfc)
195t_kgdb: KGDB_TRAP(0xfd)
195dbtrap: BAD_TRAP(0xfe) /* Debugger/PROM breakpoint #1 */ 196dbtrap: BAD_TRAP(0xfe) /* Debugger/PROM breakpoint #1 */
196dbtrap2:BAD_TRAP(0xff) /* Debugger/PROM breakpoint #2 */ 197dbtrap2:BAD_TRAP(0xff) /* Debugger/PROM breakpoint #2 */
197 198
@@ -267,7 +268,7 @@ trapbase_cpu1:
267 BAD_TRAP(0xed) BAD_TRAP(0xee) BAD_TRAP(0xef) BAD_TRAP(0xf0) BAD_TRAP(0xf1) 268 BAD_TRAP(0xed) BAD_TRAP(0xee) BAD_TRAP(0xef) BAD_TRAP(0xf0) BAD_TRAP(0xf1)
268 BAD_TRAP(0xf2) BAD_TRAP(0xf3) BAD_TRAP(0xf4) BAD_TRAP(0xf5) BAD_TRAP(0xf6) 269 BAD_TRAP(0xf2) BAD_TRAP(0xf3) BAD_TRAP(0xf4) BAD_TRAP(0xf5) BAD_TRAP(0xf6)
269 BAD_TRAP(0xf7) BAD_TRAP(0xf8) BAD_TRAP(0xf9) BAD_TRAP(0xfa) BAD_TRAP(0xfb) 270 BAD_TRAP(0xf7) BAD_TRAP(0xf8) BAD_TRAP(0xf9) BAD_TRAP(0xfa) BAD_TRAP(0xfb)
270 BAD_TRAP(0xfc) BAD_TRAP(0xfd) BAD_TRAP(0xfe) BAD_TRAP(0xff) 271 BAD_TRAP(0xfc) KGDB_TRAP(0xfd) BAD_TRAP(0xfe) BAD_TRAP(0xff)
271 272
272trapbase_cpu2: 273trapbase_cpu2:
273 BAD_TRAP(0x0) SRMMU_TFAULT TRAP_ENTRY(0x2, bad_instruction) 274 BAD_TRAP(0x0) SRMMU_TFAULT TRAP_ENTRY(0x2, bad_instruction)
@@ -335,7 +336,7 @@ trapbase_cpu2:
335 BAD_TRAP(0xed) BAD_TRAP(0xee) BAD_TRAP(0xef) BAD_TRAP(0xf0) BAD_TRAP(0xf1) 336 BAD_TRAP(0xed) BAD_TRAP(0xee) BAD_TRAP(0xef) BAD_TRAP(0xf0) BAD_TRAP(0xf1)
336 BAD_TRAP(0xf2) BAD_TRAP(0xf3) BAD_TRAP(0xf4) BAD_TRAP(0xf5) BAD_TRAP(0xf6) 337 BAD_TRAP(0xf2) BAD_TRAP(0xf3) BAD_TRAP(0xf4) BAD_TRAP(0xf5) BAD_TRAP(0xf6)
337 BAD_TRAP(0xf7) BAD_TRAP(0xf8) BAD_TRAP(0xf9) BAD_TRAP(0xfa) BAD_TRAP(0xfb) 338 BAD_TRAP(0xf7) BAD_TRAP(0xf8) BAD_TRAP(0xf9) BAD_TRAP(0xfa) BAD_TRAP(0xfb)
338 BAD_TRAP(0xfc) BAD_TRAP(0xfd) BAD_TRAP(0xfe) BAD_TRAP(0xff) 339 BAD_TRAP(0xfc) KGDB_TRAP(0xfd) BAD_TRAP(0xfe) BAD_TRAP(0xff)
339 340
340trapbase_cpu3: 341trapbase_cpu3:
341 BAD_TRAP(0x0) SRMMU_TFAULT TRAP_ENTRY(0x2, bad_instruction) 342 BAD_TRAP(0x0) SRMMU_TFAULT TRAP_ENTRY(0x2, bad_instruction)
@@ -403,7 +404,7 @@ trapbase_cpu3:
403 BAD_TRAP(0xed) BAD_TRAP(0xee) BAD_TRAP(0xef) BAD_TRAP(0xf0) BAD_TRAP(0xf1) 404 BAD_TRAP(0xed) BAD_TRAP(0xee) BAD_TRAP(0xef) BAD_TRAP(0xf0) BAD_TRAP(0xf1)
404 BAD_TRAP(0xf2) BAD_TRAP(0xf3) BAD_TRAP(0xf4) BAD_TRAP(0xf5) BAD_TRAP(0xf6) 405 BAD_TRAP(0xf2) BAD_TRAP(0xf3) BAD_TRAP(0xf4) BAD_TRAP(0xf5) BAD_TRAP(0xf6)
405 BAD_TRAP(0xf7) BAD_TRAP(0xf8) BAD_TRAP(0xf9) BAD_TRAP(0xfa) BAD_TRAP(0xfb) 406 BAD_TRAP(0xf7) BAD_TRAP(0xf8) BAD_TRAP(0xf9) BAD_TRAP(0xfa) BAD_TRAP(0xfb)
406 BAD_TRAP(0xfc) BAD_TRAP(0xfd) BAD_TRAP(0xfe) BAD_TRAP(0xff) 407 BAD_TRAP(0xfc) KGDB_TRAP(0xfd) BAD_TRAP(0xfe) BAD_TRAP(0xff)
407 408
408#endif 409#endif
409 .align PAGE_SIZE 410 .align PAGE_SIZE
diff --git a/arch/sparc/kernel/kgdb.c b/arch/sparc/kernel/kgdb.c
new file mode 100644
index 000000000000..757805ce02ee
--- /dev/null
+++ b/arch/sparc/kernel/kgdb.c
@@ -0,0 +1,164 @@
1/* kgdb.c: KGDB support for 32-bit sparc.
2 *
3 * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
4 */
5
6#include <linux/kgdb.h>
7#include <linux/kdebug.h>
8
9#include <asm/kdebug.h>
10#include <asm/ptrace.h>
11#include <asm/irq.h>
12
13extern unsigned long trapbase;
14
15void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)
16{
17 struct reg_window *win;
18 int i;
19
20 gdb_regs[GDB_G0] = 0;
21 for (i = 0; i < 15; i++)
22 gdb_regs[GDB_G1 + i] = regs->u_regs[UREG_G1 + i];
23
24 win = (struct reg_window *) regs->u_regs[UREG_FP];
25 for (i = 0; i < 8; i++)
26 gdb_regs[GDB_L0 + i] = win->locals[i];
27 for (i = 0; i < 8; i++)
28 gdb_regs[GDB_I0 + i] = win->ins[i];
29
30 for (i = GDB_F0; i <= GDB_F31; i++)
31 gdb_regs[i] = 0;
32
33 gdb_regs[GDB_Y] = regs->y;
34 gdb_regs[GDB_PSR] = regs->psr;
35 gdb_regs[GDB_WIM] = 0;
36 gdb_regs[GDB_TBR] = (unsigned long) &trapbase;
37 gdb_regs[GDB_PC] = regs->pc;
38 gdb_regs[GDB_NPC] = regs->npc;
39 gdb_regs[GDB_FSR] = 0;
40 gdb_regs[GDB_CSR] = 0;
41}
42
43void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
44{
45 struct thread_info *t = task_thread_info(p);
46 struct reg_window *win;
47 int i;
48
49 for (i = GDB_G0; i < GDB_G6; i++)
50 gdb_regs[i] = 0;
51 gdb_regs[GDB_G6] = (unsigned long) t;
52 gdb_regs[GDB_G7] = 0;
53 for (i = GDB_O0; i < GDB_SP; i++)
54 gdb_regs[i] = 0;
55 gdb_regs[GDB_SP] = t->ksp;
56 gdb_regs[GDB_O7] = 0;
57
58 win = (struct reg_window *) t->ksp;
59 for (i = 0; i < 8; i++)
60 gdb_regs[GDB_L0 + i] = win->locals[i];
61 for (i = 0; i < 8; i++)
62 gdb_regs[GDB_I0 + i] = win->ins[i];
63
64 for (i = GDB_F0; i <= GDB_F31; i++)
65 gdb_regs[i] = 0;
66
67 gdb_regs[GDB_Y] = 0;
68
69 gdb_regs[GDB_PSR] = t->kpsr;
70 gdb_regs[GDB_WIM] = t->kwim;
71 gdb_regs[GDB_TBR] = (unsigned long) &trapbase;
72 gdb_regs[GDB_PC] = t->kpc;
73 gdb_regs[GDB_NPC] = t->kpc + 4;
74 gdb_regs[GDB_FSR] = 0;
75 gdb_regs[GDB_CSR] = 0;
76}
77
78void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs)
79{
80 struct reg_window *win;
81 int i;
82
83 for (i = 0; i < 15; i++)
84 regs->u_regs[UREG_G1 + i] = gdb_regs[GDB_G1 + i];
85
86 /* If the PSR register is changing, we have to preserve
87 * the CWP field, otherwise window save/restore explodes.
88 */
89 if (regs->psr != gdb_regs[GDB_PSR]) {
90 unsigned long cwp = regs->psr & PSR_CWP;
91
92 regs->psr = (gdb_regs[GDB_PSR] & ~PSR_CWP) | cwp;
93 }
94
95 regs->pc = gdb_regs[GDB_PC];
96 regs->npc = gdb_regs[GDB_NPC];
97 regs->y = gdb_regs[GDB_Y];
98
99 win = (struct reg_window *) regs->u_regs[UREG_FP];
100 for (i = 0; i < 8; i++)
101 win->locals[i] = gdb_regs[GDB_L0 + i];
102 for (i = 0; i < 8; i++)
103 win->ins[i] = gdb_regs[GDB_I0 + i];
104}
105
106int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
107 char *remcomInBuffer, char *remcomOutBuffer,
108 struct pt_regs *linux_regs)
109{
110 unsigned long addr;
111 char *ptr;
112
113 switch (remcomInBuffer[0]) {
114 case 'c':
115 /* try to read optional parameter, pc unchanged if no parm */
116 ptr = &remcomInBuffer[1];
117 if (kgdb_hex2long(&ptr, &addr)) {
118 linux_regs->pc = addr;
119 linux_regs->npc = addr + 4;
120 }
121 /* fallthru */
122
123 case 'D':
124 case 'k':
125 if (linux_regs->pc == (unsigned long) arch_kgdb_breakpoint) {
126 linux_regs->pc = linux_regs->npc;
127 linux_regs->npc += 4;
128 }
129 return 0;
130 }
131 return -1;
132}
133
134extern void do_hw_interrupt(struct pt_regs *regs, unsigned long type);
135
136asmlinkage void kgdb_trap(struct pt_regs *regs)
137{
138 unsigned long flags;
139
140 if (user_mode(regs)) {
141 do_hw_interrupt(regs, 0xfd);
142 return;
143 }
144
145 flushw_all();
146
147 local_irq_save(flags);
148 kgdb_handle_exception(0x172, SIGTRAP, 0, regs);
149 local_irq_restore(flags);
150}
151
152int kgdb_arch_init(void)
153{
154 return 0;
155}
156
157void kgdb_arch_exit(void)
158{
159}
160
161struct kgdb_arch arch_kgdb_ops = {
162 /* Breakpoint instruction: ta 0x7d */
163 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x7d },
164};
diff --git a/arch/sparc/kernel/setup.c b/arch/sparc/kernel/setup.c
index 3c13137685da..8a55c4f0df84 100644
--- a/arch/sparc/kernel/setup.c
+++ b/arch/sparc/kernel/setup.c
@@ -180,11 +180,9 @@ static void __init boot_flags_init(char *commands)
180 180
181/* This routine will in the future do all the nasty prom stuff 181/* This routine will in the future do all the nasty prom stuff
182 * to probe for the mmu type and its parameters, etc. This will 182 * to probe for the mmu type and its parameters, etc. This will
183 * also be where SMP things happen plus the Sparc specific memory 183 * also be where SMP things happen.
184 * physical memory probe as on the alpha.
185 */ 184 */
186 185
187extern int prom_probe_memory(void);
188extern void sun4c_probe_vac(void); 186extern void sun4c_probe_vac(void);
189extern char cputypval; 187extern char cputypval;
190extern unsigned long start, end; 188extern unsigned long start, end;
@@ -268,7 +266,6 @@ void __init setup_arch(char **cmdline_p)
268 if (ARCH_SUN4C_SUN4) 266 if (ARCH_SUN4C_SUN4)
269 sun4c_probe_vac(); 267 sun4c_probe_vac();
270 load_mmu(); 268 load_mmu();
271 (void) prom_probe_memory();
272 269
273 phys_base = 0xffffffffUL; 270 phys_base = 0xffffffffUL;
274 highest_paddr = 0UL; 271 highest_paddr = 0UL;
diff --git a/arch/sparc/kernel/sparc-stub.c b/arch/sparc/kernel/sparc-stub.c
deleted file mode 100644
index e84f815e6903..000000000000
--- a/arch/sparc/kernel/sparc-stub.c
+++ /dev/null
@@ -1,724 +0,0 @@
1/* $Id: sparc-stub.c,v 1.28 2001/10/30 04:54:21 davem Exp $
2 * sparc-stub.c: KGDB support for the Linux kernel.
3 *
4 * Modifications to run under Linux
5 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
6 *
7 * This file originally came from the gdb sources, and the
8 * copyright notices have been retained below.
9 */
10
11/****************************************************************************
12
13 THIS SOFTWARE IS NOT COPYRIGHTED
14
15 HP offers the following for use in the public domain. HP makes no
16 warranty with regard to the software or its performance and the
17 user accepts the software "AS IS" with all faults.
18
19 HP DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD
20 TO THIS SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22
23****************************************************************************/
24
25/****************************************************************************
26 * Header: remcom.c,v 1.34 91/03/09 12:29:49 glenne Exp $
27 *
28 * Module name: remcom.c $
29 * Revision: 1.34 $
30 * Date: 91/03/09 12:29:49 $
31 * Contributor: Lake Stevens Instrument Division$
32 *
33 * Description: low level support for gdb debugger. $
34 *
35 * Considerations: only works on target hardware $
36 *
37 * Written by: Glenn Engel $
38 * ModuleState: Experimental $
39 *
40 * NOTES: See Below $
41 *
42 * Modified for SPARC by Stu Grossman, Cygnus Support.
43 *
44 * This code has been extensively tested on the Fujitsu SPARClite demo board.
45 *
46 * To enable debugger support, two things need to happen. One, a
47 * call to set_debug_traps() is necessary in order to allow any breakpoints
48 * or error conditions to be properly intercepted and reported to gdb.
49 * Two, a breakpoint needs to be generated to begin communication. This
50 * is most easily accomplished by a call to breakpoint(). Breakpoint()
51 * simulates a breakpoint by executing a trap #1.
52 *
53 *************
54 *
55 * The following gdb commands are supported:
56 *
57 * command function Return value
58 *
59 * g return the value of the CPU registers hex data or ENN
60 * G set the value of the CPU registers OK or ENN
61 *
62 * mAA..AA,LLLL Read LLLL bytes at address AA..AA hex data or ENN
63 * MAA..AA,LLLL: Write LLLL bytes at address AA.AA OK or ENN
64 *
65 * c Resume at current address SNN ( signal NN)
66 * cAA..AA Continue at address AA..AA SNN
67 *
68 * s Step one instruction SNN
69 * sAA..AA Step one instruction from AA..AA SNN
70 *
71 * k kill
72 *
73 * ? What was the last sigval ? SNN (signal NN)
74 *
75 * bBB..BB Set baud rate to BB..BB OK or BNN, then sets
76 * baud rate
77 *
78 * All commands and responses are sent with a packet which includes a
79 * checksum. A packet consists of
80 *
81 * $<packet info>#<checksum>.
82 *
83 * where
84 * <packet info> :: <characters representing the command or response>
85 * <checksum> :: < two hex digits computed as modulo 256 sum of <packetinfo>>
86 *
87 * When a packet is received, it is first acknowledged with either '+' or '-'.
88 * '+' indicates a successful transfer. '-' indicates a failed transfer.
89 *
90 * Example:
91 *
92 * Host: Reply:
93 * $m0,10#2a +$00010203040506070809101112131415#42
94 *
95 ****************************************************************************/
96
97#include <linux/kernel.h>
98#include <linux/string.h>
99#include <linux/mm.h>
100#include <linux/smp.h>
101#include <linux/smp_lock.h>
102
103#include <asm/system.h>
104#include <asm/signal.h>
105#include <asm/oplib.h>
106#include <asm/head.h>
107#include <asm/traps.h>
108#include <asm/vac-ops.h>
109#include <asm/kgdb.h>
110#include <asm/pgalloc.h>
111#include <asm/pgtable.h>
112#include <asm/cacheflush.h>
113
114/*
115 *
116 * external low-level support routines
117 */
118
119extern void putDebugChar(char); /* write a single character */
120extern char getDebugChar(void); /* read and return a single char */
121
122/*
123 * BUFMAX defines the maximum number of characters in inbound/outbound buffers
124 * at least NUMREGBYTES*2 are needed for register packets
125 */
126#define BUFMAX 2048
127
128static int initialized; /* !0 means we've been initialized */
129
130static const char hexchars[]="0123456789abcdef";
131
132#define NUMREGS 72
133
134/* Number of bytes of registers. */
135#define NUMREGBYTES (NUMREGS * 4)
136enum regnames {G0, G1, G2, G3, G4, G5, G6, G7,
137 O0, O1, O2, O3, O4, O5, SP, O7,
138 L0, L1, L2, L3, L4, L5, L6, L7,
139 I0, I1, I2, I3, I4, I5, FP, I7,
140
141 F0, F1, F2, F3, F4, F5, F6, F7,
142 F8, F9, F10, F11, F12, F13, F14, F15,
143 F16, F17, F18, F19, F20, F21, F22, F23,
144 F24, F25, F26, F27, F28, F29, F30, F31,
145 Y, PSR, WIM, TBR, PC, NPC, FPSR, CPSR };
146
147
148extern void trap_low(void); /* In arch/sparc/kernel/entry.S */
149
150unsigned long get_sun4cpte(unsigned long addr)
151{
152 unsigned long entry;
153
154 __asm__ __volatile__("\n\tlda [%1] %2, %0\n\t" :
155 "=r" (entry) :
156 "r" (addr), "i" (ASI_PTE));
157 return entry;
158}
159
160unsigned long get_sun4csegmap(unsigned long addr)
161{
162 unsigned long entry;
163
164 __asm__ __volatile__("\n\tlduba [%1] %2, %0\n\t" :
165 "=r" (entry) :
166 "r" (addr), "i" (ASI_SEGMAP));
167 return entry;
168}
169
170#if 0
171/* Have to sort this out. This cannot be done after initialization. */
172static void flush_cache_all_nop(void) {}
173#endif
174
175/* Place where we save old trap entries for restoration */
176struct tt_entry kgdb_savettable[256];
177typedef void (*trapfunc_t)(void);
178
179/* Helper routine for manipulation of kgdb_savettable */
180static inline void copy_ttentry(struct tt_entry *src, struct tt_entry *dest)
181{
182 dest->inst_one = src->inst_one;
183 dest->inst_two = src->inst_two;
184 dest->inst_three = src->inst_three;
185 dest->inst_four = src->inst_four;
186}
187
188/* Initialize the kgdb_savettable so that debugging can commence */
189static void eh_init(void)
190{
191 int i;
192
193 for(i=0; i < 256; i++)
194 copy_ttentry(&sparc_ttable[i], &kgdb_savettable[i]);
195}
196
197/* Install an exception handler for kgdb */
198static void exceptionHandler(int tnum, trapfunc_t trap_entry)
199{
200 unsigned long te_addr = (unsigned long) trap_entry;
201
202 /* Make new vector */
203 sparc_ttable[tnum].inst_one =
204 SPARC_BRANCH((unsigned long) te_addr,
205 (unsigned long) &sparc_ttable[tnum].inst_one);
206 sparc_ttable[tnum].inst_two = SPARC_RD_PSR_L0;
207 sparc_ttable[tnum].inst_three = SPARC_NOP;
208 sparc_ttable[tnum].inst_four = SPARC_NOP;
209}
210
211/* Convert ch from a hex digit to an int */
212static int
213hex(unsigned char ch)
214{
215 if (ch >= 'a' && ch <= 'f')
216 return ch-'a'+10;
217 if (ch >= '0' && ch <= '9')
218 return ch-'0';
219 if (ch >= 'A' && ch <= 'F')
220 return ch-'A'+10;
221 return -1;
222}
223
224/* scan for the sequence $<data>#<checksum> */
225static void
226getpacket(char *buffer)
227{
228 unsigned char checksum;
229 unsigned char xmitcsum;
230 int i;
231 int count;
232 unsigned char ch;
233
234 do {
235 /* wait around for the start character, ignore all other characters */
236 while ((ch = (getDebugChar() & 0x7f)) != '$') ;
237
238 checksum = 0;
239 xmitcsum = -1;
240
241 count = 0;
242
243 /* now, read until a # or end of buffer is found */
244 while (count < BUFMAX) {
245 ch = getDebugChar() & 0x7f;
246 if (ch == '#')
247 break;
248 checksum = checksum + ch;
249 buffer[count] = ch;
250 count = count + 1;
251 }
252
253 if (count >= BUFMAX)
254 continue;
255
256 buffer[count] = 0;
257
258 if (ch == '#') {
259 xmitcsum = hex(getDebugChar() & 0x7f) << 4;
260 xmitcsum |= hex(getDebugChar() & 0x7f);
261 if (checksum != xmitcsum)
262 putDebugChar('-'); /* failed checksum */
263 else {
264 putDebugChar('+'); /* successful transfer */
265 /* if a sequence char is present, reply the ID */
266 if (buffer[2] == ':') {
267 putDebugChar(buffer[0]);
268 putDebugChar(buffer[1]);
269 /* remove sequence chars from buffer */
270 count = strlen(buffer);
271 for (i=3; i <= count; i++)
272 buffer[i-3] = buffer[i];
273 }
274 }
275 }
276 } while (checksum != xmitcsum);
277}
278
279/* send the packet in buffer. */
280
281static void
282putpacket(unsigned char *buffer)
283{
284 unsigned char checksum;
285 int count;
286 unsigned char ch, recv;
287
288 /* $<packet info>#<checksum>. */
289 do {
290 putDebugChar('$');
291 checksum = 0;
292 count = 0;
293
294 while ((ch = buffer[count])) {
295 putDebugChar(ch);
296 checksum += ch;
297 count += 1;
298 }
299
300 putDebugChar('#');
301 putDebugChar(hexchars[checksum >> 4]);
302 putDebugChar(hexchars[checksum & 0xf]);
303 recv = getDebugChar();
304 } while ((recv & 0x7f) != '+');
305}
306
307static char remcomInBuffer[BUFMAX];
308static char remcomOutBuffer[BUFMAX];
309
310/* Convert the memory pointed to by mem into hex, placing result in buf.
311 * Return a pointer to the last char put in buf (null), in case of mem fault,
312 * return 0.
313 */
314
315static unsigned char *
316mem2hex(char *mem, char *buf, int count)
317{
318 unsigned char ch;
319
320 while (count-- > 0) {
321 /* This assembler code is basically: ch = *mem++;
322 * except that we use the SPARC/Linux exception table
323 * mechanism (see how "fixup" works in kernel_mna_trap_fault)
324 * to arrange for a "return 0" upon a memory fault
325 */
326 __asm__(
327 "\n1:\n\t"
328 "ldub [%0], %1\n\t"
329 "inc %0\n\t"
330 ".section .fixup,#alloc,#execinstr\n\t"
331 ".align 4\n"
332 "2:\n\t"
333 "retl\n\t"
334 " mov 0, %%o0\n\t"
335 ".section __ex_table, #alloc\n\t"
336 ".align 4\n\t"
337 ".word 1b, 2b\n\t"
338 ".text\n"
339 : "=r" (mem), "=r" (ch) : "0" (mem));
340 *buf++ = hexchars[ch >> 4];
341 *buf++ = hexchars[ch & 0xf];
342 }
343
344 *buf = 0;
345 return buf;
346}
347
348/* convert the hex array pointed to by buf into binary to be placed in mem
349 * return a pointer to the character AFTER the last byte written.
350*/
351static char *
352hex2mem(char *buf, char *mem, int count)
353{
354 int i;
355 unsigned char ch;
356
357 for (i=0; i<count; i++) {
358
359 ch = hex(*buf++) << 4;
360 ch |= hex(*buf++);
361 /* Assembler code is *mem++ = ch; with return 0 on fault */
362 __asm__(
363 "\n1:\n\t"
364 "stb %1, [%0]\n\t"
365 "inc %0\n\t"
366 ".section .fixup,#alloc,#execinstr\n\t"
367 ".align 4\n"
368 "2:\n\t"
369 "retl\n\t"
370 " mov 0, %%o0\n\t"
371 ".section __ex_table, #alloc\n\t"
372 ".align 4\n\t"
373 ".word 1b, 2b\n\t"
374 ".text\n"
375 : "=r" (mem) : "r" (ch) , "0" (mem));
376 }
377 return mem;
378}
379
380/* This table contains the mapping between SPARC hardware trap types, and
381 signals, which are primarily what GDB understands. It also indicates
382 which hardware traps we need to commandeer when initializing the stub. */
383
384static struct hard_trap_info
385{
386 unsigned char tt; /* Trap type code for SPARC */
387 unsigned char signo; /* Signal that we map this trap into */
388} hard_trap_info[] = {
389 {SP_TRAP_SBPT, SIGTRAP}, /* ta 1 - Linux/KGDB software breakpoint */
390 {0, 0} /* Must be last */
391};
392
393/* Set up exception handlers for tracing and breakpoints */
394
395void
396set_debug_traps(void)
397{
398 struct hard_trap_info *ht;
399 unsigned long flags;
400
401 local_irq_save(flags);
402#if 0
403/* Have to sort this out. This cannot be done after initialization. */
404 BTFIXUPSET_CALL(flush_cache_all, flush_cache_all_nop, BTFIXUPCALL_NOP);
405#endif
406
407 /* Initialize our copy of the Linux Sparc trap table */
408 eh_init();
409
410 for (ht = hard_trap_info; ht->tt && ht->signo; ht++) {
411 /* Only if it doesn't destroy our fault handlers */
412 if((ht->tt != SP_TRAP_TFLT) &&
413 (ht->tt != SP_TRAP_DFLT))
414 exceptionHandler(ht->tt, trap_low);
415 }
416
417 /* In case GDB is started before us, ack any packets (presumably
418 * "$?#xx") sitting there.
419 *
420 * I've found this code causes more problems than it solves,
421 * so that's why it's commented out. GDB seems to work fine
422 * now starting either before or after the kernel -bwb
423 */
424#if 0
425 while((c = getDebugChar()) != '$');
426 while((c = getDebugChar()) != '#');
427 c = getDebugChar(); /* eat first csum byte */
428 c = getDebugChar(); /* eat second csum byte */
429 putDebugChar('+'); /* ack it */
430#endif
431
432 initialized = 1; /* connect! */
433 local_irq_restore(flags);
434}
435
436/* Convert the SPARC hardware trap type code to a unix signal number. */
437
438static int
439computeSignal(int tt)
440{
441 struct hard_trap_info *ht;
442
443 for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
444 if (ht->tt == tt)
445 return ht->signo;
446
447 return SIGHUP; /* default for things we don't know about */
448}
449
450/*
451 * While we find nice hex chars, build an int.
452 * Return number of chars processed.
453 */
454
455static int
456hexToInt(char **ptr, int *intValue)
457{
458 int numChars = 0;
459 int hexValue;
460
461 *intValue = 0;
462
463 while (**ptr) {
464 hexValue = hex(**ptr);
465 if (hexValue < 0)
466 break;
467
468 *intValue = (*intValue << 4) | hexValue;
469 numChars ++;
470
471 (*ptr)++;
472 }
473
474 return (numChars);
475}
476
477/*
478 * This function does all command processing for interfacing to gdb. It
479 * returns 1 if you should skip the instruction at the trap address, 0
480 * otherwise.
481 */
482
483extern void breakinst(void);
484
485void
486handle_exception (unsigned long *registers)
487{
488 int tt; /* Trap type */
489 int sigval;
490 int addr;
491 int length;
492 char *ptr;
493 unsigned long *sp;
494
495 /* First, we must force all of the windows to be spilled out */
496
497 asm("save %sp, -64, %sp\n\t"
498 "save %sp, -64, %sp\n\t"
499 "save %sp, -64, %sp\n\t"
500 "save %sp, -64, %sp\n\t"
501 "save %sp, -64, %sp\n\t"
502 "save %sp, -64, %sp\n\t"
503 "save %sp, -64, %sp\n\t"
504 "save %sp, -64, %sp\n\t"
505 "restore\n\t"
506 "restore\n\t"
507 "restore\n\t"
508 "restore\n\t"
509 "restore\n\t"
510 "restore\n\t"
511 "restore\n\t"
512 "restore\n\t");
513
514 lock_kernel();
515 if (registers[PC] == (unsigned long)breakinst) {
516 /* Skip over breakpoint trap insn */
517 registers[PC] = registers[NPC];
518 registers[NPC] += 4;
519 }
520
521 sp = (unsigned long *)registers[SP];
522
523 tt = (registers[TBR] >> 4) & 0xff;
524
525 /* reply to host that an exception has occurred */
526 sigval = computeSignal(tt);
527 ptr = remcomOutBuffer;
528
529 *ptr++ = 'T';
530 *ptr++ = hexchars[sigval >> 4];
531 *ptr++ = hexchars[sigval & 0xf];
532
533 *ptr++ = hexchars[PC >> 4];
534 *ptr++ = hexchars[PC & 0xf];
535 *ptr++ = ':';
536 ptr = mem2hex((char *)&registers[PC], ptr, 4);
537 *ptr++ = ';';
538
539 *ptr++ = hexchars[FP >> 4];
540 *ptr++ = hexchars[FP & 0xf];
541 *ptr++ = ':';
542 ptr = mem2hex((char *) (sp + 8 + 6), ptr, 4); /* FP */
543 *ptr++ = ';';
544
545 *ptr++ = hexchars[SP >> 4];
546 *ptr++ = hexchars[SP & 0xf];
547 *ptr++ = ':';
548 ptr = mem2hex((char *)&sp, ptr, 4);
549 *ptr++ = ';';
550
551 *ptr++ = hexchars[NPC >> 4];
552 *ptr++ = hexchars[NPC & 0xf];
553 *ptr++ = ':';
554 ptr = mem2hex((char *)&registers[NPC], ptr, 4);
555 *ptr++ = ';';
556
557 *ptr++ = hexchars[O7 >> 4];
558 *ptr++ = hexchars[O7 & 0xf];
559 *ptr++ = ':';
560 ptr = mem2hex((char *)&registers[O7], ptr, 4);
561 *ptr++ = ';';
562
563 *ptr++ = 0;
564
565 putpacket(remcomOutBuffer);
566
567 /* XXX We may want to add some features dealing with poking the
568 * XXX page tables, the real ones on the srmmu, and what is currently
569 * XXX loaded in the sun4/sun4c tlb at this point in time. But this
570 * XXX also required hacking to the gdb sources directly...
571 */
572
573 while (1) {
574 remcomOutBuffer[0] = 0;
575
576 getpacket(remcomInBuffer);
577 switch (remcomInBuffer[0]) {
578 case '?':
579 remcomOutBuffer[0] = 'S';
580 remcomOutBuffer[1] = hexchars[sigval >> 4];
581 remcomOutBuffer[2] = hexchars[sigval & 0xf];
582 remcomOutBuffer[3] = 0;
583 break;
584
585 case 'd':
586 /* toggle debug flag */
587 break;
588
589 case 'g': /* return the value of the CPU registers */
590 {
591 ptr = remcomOutBuffer;
592 /* G & O regs */
593 ptr = mem2hex((char *)registers, ptr, 16 * 4);
594 /* L & I regs */
595 ptr = mem2hex((char *) (sp + 0), ptr, 16 * 4);
596 /* Floating point */
597 memset(ptr, '0', 32 * 8);
598 /* Y, PSR, WIM, TBR, PC, NPC, FPSR, CPSR */
599 mem2hex((char *)&registers[Y], (ptr + 32 * 4 * 2), (8 * 4));
600 }
601 break;
602
603 case 'G': /* set the value of the CPU registers - return OK */
604 {
605 unsigned long *newsp, psr;
606
607 psr = registers[PSR];
608
609 ptr = &remcomInBuffer[1];
610 /* G & O regs */
611 hex2mem(ptr, (char *)registers, 16 * 4);
612 /* L & I regs */
613 hex2mem(ptr + 16 * 4 * 2, (char *) (sp + 0), 16 * 4);
614 /* Y, PSR, WIM, TBR, PC, NPC, FPSR, CPSR */
615 hex2mem(ptr + 64 * 4 * 2, (char *)&registers[Y], 8 * 4);
616
617 /* See if the stack pointer has moved. If so,
618 * then copy the saved locals and ins to the
619 * new location. This keeps the window
620 * overflow and underflow routines happy.
621 */
622
623 newsp = (unsigned long *)registers[SP];
624 if (sp != newsp)
625 sp = memcpy(newsp, sp, 16 * 4);
626
627 /* Don't allow CWP to be modified. */
628
629 if (psr != registers[PSR])
630 registers[PSR] = (psr & 0x1f) | (registers[PSR] & ~0x1f);
631
632 strcpy(remcomOutBuffer,"OK");
633 }
634 break;
635
636 case 'm': /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */
637 /* Try to read %x,%x. */
638
639 ptr = &remcomInBuffer[1];
640
641 if (hexToInt(&ptr, &addr)
642 && *ptr++ == ','
643 && hexToInt(&ptr, &length)) {
644 if (mem2hex((char *)addr, remcomOutBuffer, length))
645 break;
646
647 strcpy (remcomOutBuffer, "E03");
648 } else {
649 strcpy(remcomOutBuffer,"E01");
650 }
651 break;
652
653 case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA.AA return OK */
654 /* Try to read '%x,%x:'. */
655
656 ptr = &remcomInBuffer[1];
657
658 if (hexToInt(&ptr, &addr)
659 && *ptr++ == ','
660 && hexToInt(&ptr, &length)
661 && *ptr++ == ':') {
662 if (hex2mem(ptr, (char *)addr, length)) {
663 strcpy(remcomOutBuffer, "OK");
664 } else {
665 strcpy(remcomOutBuffer, "E03");
666 }
667 } else {
668 strcpy(remcomOutBuffer, "E02");
669 }
670 break;
671
672 case 'c': /* cAA..AA Continue at address AA..AA(optional) */
673 /* try to read optional parameter, pc unchanged if no parm */
674
675 ptr = &remcomInBuffer[1];
676 if (hexToInt(&ptr, &addr)) {
677 registers[PC] = addr;
678 registers[NPC] = addr + 4;
679 }
680
681/* Need to flush the instruction cache here, as we may have deposited a
682 * breakpoint, and the icache probably has no way of knowing that a data ref to
683 * some location may have changed something that is in the instruction cache.
684 */
685 flush_cache_all();
686 unlock_kernel();
687 return;
688
689 /* kill the program */
690 case 'k' : /* do nothing */
691 break;
692 case 'r': /* Reset */
693 asm ("call 0\n\t"
694 "nop\n\t");
695 break;
696 } /* switch */
697
698 /* reply to the request */
699 putpacket(remcomOutBuffer);
700 } /* while(1) */
701}
702
703/* This function will generate a breakpoint exception. It is used at the
704 beginning of a program to sync up with a debugger and can be used
705 otherwise as a quick means to stop program execution and "break" into
706 the debugger. */
707
708void
709breakpoint(void)
710{
711 if (!initialized)
712 return;
713
714 /* Again, watch those c-prefixes for ELF kernels */
715#if defined(__svr4__) || defined(__ELF__)
716 asm(".globl breakinst\n"
717 "breakinst:\n\t"
718 "ta 1\n");
719#else
720 asm(".globl _breakinst\n"
721 "_breakinst:\n\t"
722 "ta 1\n");
723#endif
724}
diff --git a/arch/sparc/kernel/sparc_ksyms.c b/arch/sparc/kernel/sparc_ksyms.c
index 0bcf98a7ef38..aa8ee06cf488 100644
--- a/arch/sparc/kernel/sparc_ksyms.c
+++ b/arch/sparc/kernel/sparc_ksyms.c
@@ -282,3 +282,5 @@ EXPORT_SYMBOL(do_BUG);
282 282
283/* Sun Power Management Idle Handler */ 283/* Sun Power Management Idle Handler */
284EXPORT_SYMBOL(pm_idle); 284EXPORT_SYMBOL(pm_idle);
285
286EXPORT_SYMBOL(empty_zero_page);
diff --git a/arch/sparc/kernel/sun4d_smp.c b/arch/sparc/kernel/sun4d_smp.c
index 0def48158c7d..dfde77ff0848 100644
--- a/arch/sparc/kernel/sun4d_smp.c
+++ b/arch/sparc/kernel/sun4d_smp.c
@@ -335,37 +335,6 @@ void smp4d_cross_call_irq(void)
335 ccall_info.processors_out[i] = 1; 335 ccall_info.processors_out[i] = 1;
336} 336}
337 337
338static int smp4d_stop_cpu_sender;
339
340static void smp4d_stop_cpu(void)
341{
342 int me = hard_smp4d_processor_id();
343
344 if (me != smp4d_stop_cpu_sender)
345 while(1) barrier();
346}
347
348/* Cross calls, in order to work efficiently and atomically do all
349 * the message passing work themselves, only stopcpu and reschedule
350 * messages come through here.
351 */
352void smp4d_message_pass(int target, int msg, unsigned long data, int wait)
353{
354 int me = hard_smp4d_processor_id();
355
356 SMP_PRINTK(("smp4d_message_pass %d %d %08lx %d\n", target, msg, data, wait));
357 if (msg == MSG_STOP_CPU && target == MSG_ALL_BUT_SELF) {
358 unsigned long flags;
359 static DEFINE_SPINLOCK(stop_cpu_lock);
360 spin_lock_irqsave(&stop_cpu_lock, flags);
361 smp4d_stop_cpu_sender = me;
362 smp4d_cross_call((smpfunc_t)smp4d_stop_cpu, 0, 0, 0, 0, 0);
363 spin_unlock_irqrestore(&stop_cpu_lock, flags);
364 }
365 printk("Yeeee, trying to send SMP msg(%d) to %d on cpu %d\n", msg, target, me);
366 panic("Bogon SMP message pass.");
367}
368
369void smp4d_percpu_timer_interrupt(struct pt_regs *regs) 338void smp4d_percpu_timer_interrupt(struct pt_regs *regs)
370{ 339{
371 struct pt_regs *old_regs; 340 struct pt_regs *old_regs;
@@ -439,7 +408,6 @@ void __init sun4d_init_smp(void)
439 BTFIXUPSET_BLACKBOX(hard_smp_processor_id, smp4d_blackbox_id); 408 BTFIXUPSET_BLACKBOX(hard_smp_processor_id, smp4d_blackbox_id);
440 BTFIXUPSET_BLACKBOX(load_current, smp4d_blackbox_current); 409 BTFIXUPSET_BLACKBOX(load_current, smp4d_blackbox_current);
441 BTFIXUPSET_CALL(smp_cross_call, smp4d_cross_call, BTFIXUPCALL_NORM); 410 BTFIXUPSET_CALL(smp_cross_call, smp4d_cross_call, BTFIXUPCALL_NORM);
442 BTFIXUPSET_CALL(smp_message_pass, smp4d_message_pass, BTFIXUPCALL_NORM);
443 BTFIXUPSET_CALL(__hard_smp_processor_id, __smp4d_processor_id, BTFIXUPCALL_NORM); 411 BTFIXUPSET_CALL(__hard_smp_processor_id, __smp4d_processor_id, BTFIXUPCALL_NORM);
444 412
445 for (i = 0; i < NR_CPUS; i++) { 413 for (i = 0; i < NR_CPUS; i++) {
diff --git a/arch/sparc/kernel/sun4m_smp.c b/arch/sparc/kernel/sun4m_smp.c
index 0b9407267162..ffb875aacb7e 100644
--- a/arch/sparc/kernel/sun4m_smp.c
+++ b/arch/sparc/kernel/sun4m_smp.c
@@ -34,8 +34,6 @@
34 34
35#include "irq.h" 35#include "irq.h"
36 36
37#define IRQ_RESCHEDULE 13
38#define IRQ_STOP_CPU 14
39#define IRQ_CROSS_CALL 15 37#define IRQ_CROSS_CALL 15
40 38
41extern ctxd_t *srmmu_ctx_table_phys; 39extern ctxd_t *srmmu_ctx_table_phys;
@@ -232,48 +230,6 @@ void smp4m_irq_rotate(int cpu)
232 set_irq_udt(next); 230 set_irq_udt(next);
233} 231}
234 232
235/* Cross calls, in order to work efficiently and atomically do all
236 * the message passing work themselves, only stopcpu and reschedule
237 * messages come through here.
238 */
239void smp4m_message_pass(int target, int msg, unsigned long data, int wait)
240{
241 static unsigned long smp_cpu_in_msg[NR_CPUS];
242 cpumask_t mask;
243 int me = smp_processor_id();
244 int irq, i;
245
246 if(msg == MSG_RESCHEDULE) {
247 irq = IRQ_RESCHEDULE;
248
249 if(smp_cpu_in_msg[me])
250 return;
251 } else if(msg == MSG_STOP_CPU) {
252 irq = IRQ_STOP_CPU;
253 } else {
254 goto barf;
255 }
256
257 smp_cpu_in_msg[me]++;
258 if(target == MSG_ALL_BUT_SELF || target == MSG_ALL) {
259 mask = cpu_online_map;
260 if(target == MSG_ALL_BUT_SELF)
261 cpu_clear(me, mask);
262 for(i = 0; i < 4; i++) {
263 if (cpu_isset(i, mask))
264 set_cpu_int(i, irq);
265 }
266 } else {
267 set_cpu_int(target, irq);
268 }
269 smp_cpu_in_msg[me]--;
270
271 return;
272barf:
273 printk("Yeeee, trying to send SMP msg(%d) on cpu %d\n", msg, me);
274 panic("Bogon SMP message pass.");
275}
276
277static struct smp_funcall { 233static struct smp_funcall {
278 smpfunc_t func; 234 smpfunc_t func;
279 unsigned long arg1; 235 unsigned long arg1;
@@ -413,6 +369,5 @@ void __init sun4m_init_smp(void)
413 BTFIXUPSET_BLACKBOX(hard_smp_processor_id, smp4m_blackbox_id); 369 BTFIXUPSET_BLACKBOX(hard_smp_processor_id, smp4m_blackbox_id);
414 BTFIXUPSET_BLACKBOX(load_current, smp4m_blackbox_current); 370 BTFIXUPSET_BLACKBOX(load_current, smp4m_blackbox_current);
415 BTFIXUPSET_CALL(smp_cross_call, smp4m_cross_call, BTFIXUPCALL_NORM); 371 BTFIXUPSET_CALL(smp_cross_call, smp4m_cross_call, BTFIXUPCALL_NORM);
416 BTFIXUPSET_CALL(smp_message_pass, smp4m_message_pass, BTFIXUPCALL_NORM);
417 BTFIXUPSET_CALL(__hard_smp_processor_id, __smp4m_processor_id, BTFIXUPCALL_NORM); 372 BTFIXUPSET_CALL(__hard_smp_processor_id, __smp4m_processor_id, BTFIXUPCALL_NORM);
418} 373}
diff --git a/arch/sparc/mm/fault.c b/arch/sparc/mm/fault.c
index e4d9c8e19df5..abd50795a7b6 100644
--- a/arch/sparc/mm/fault.c
+++ b/arch/sparc/mm/fault.c
@@ -47,64 +47,15 @@ int vac_size, vac_linesize, vac_do_hw_vac_flushes;
47int vac_entries_per_context, vac_entries_per_segment; 47int vac_entries_per_context, vac_entries_per_segment;
48int vac_entries_per_page; 48int vac_entries_per_page;
49 49
50/* Nice, simple, prom library does all the sweating for us. ;) */ 50/* Return how much physical memory we have. */
51int prom_probe_memory (void) 51unsigned long probe_memory(void)
52{ 52{
53 register struct linux_mlist_v0 *mlist; 53 unsigned long total = 0;
54 register unsigned long bytes, base_paddr, tally; 54 int i;
55 register int i;
56
57 i = 0;
58 mlist= *prom_meminfo()->v0_available;
59 bytes = tally = mlist->num_bytes;
60 base_paddr = (unsigned long) mlist->start_adr;
61
62 sp_banks[0].base_addr = base_paddr;
63 sp_banks[0].num_bytes = bytes;
64
65 while (mlist->theres_more != (void *) 0){
66 i++;
67 mlist = mlist->theres_more;
68 bytes = mlist->num_bytes;
69 tally += bytes;
70 if (i > SPARC_PHYS_BANKS-1) {
71 printk ("The machine has more banks than "
72 "this kernel can support\n"
73 "Increase the SPARC_PHYS_BANKS "
74 "setting (currently %d)\n",
75 SPARC_PHYS_BANKS);
76 i = SPARC_PHYS_BANKS-1;
77 break;
78 }
79
80 sp_banks[i].base_addr = (unsigned long) mlist->start_adr;
81 sp_banks[i].num_bytes = mlist->num_bytes;
82 }
83
84 i++;
85 sp_banks[i].base_addr = 0xdeadbeef;
86 sp_banks[i].num_bytes = 0;
87
88 /* Now mask all bank sizes on a page boundary, it is all we can
89 * use anyways.
90 */
91 for(i=0; sp_banks[i].num_bytes != 0; i++)
92 sp_banks[i].num_bytes &= PAGE_MASK;
93
94 return tally;
95}
96
97/* Traverse the memory lists in the prom to see how much physical we
98 * have.
99 */
100unsigned long
101probe_memory(void)
102{
103 int total;
104 55
105 total = prom_probe_memory(); 56 for (i = 0; sp_banks[i].num_bytes; i++)
57 total += sp_banks[i].num_bytes;
106 58
107 /* Oh man, much nicer, keep the dirt in promlib. */
108 return total; 59 return total;
109} 60}
110 61
diff --git a/arch/sparc/prom/init.c b/arch/sparc/prom/init.c
index 50abfb1b880e..2fa3a474e3a2 100644
--- a/arch/sparc/prom/init.c
+++ b/arch/sparc/prom/init.c
@@ -21,8 +21,6 @@ linux_sun4_romvec *sun4_romvec;
21/* The root node of the prom device tree. */ 21/* The root node of the prom device tree. */
22int prom_root_node; 22int prom_root_node;
23 23
24int prom_stdin, prom_stdout;
25
26/* Pointer to the device tree operations structure. */ 24/* Pointer to the device tree operations structure. */
27struct linux_nodeops *prom_nodeops; 25struct linux_nodeops *prom_nodeops;
28 26
@@ -74,11 +72,6 @@ void __init prom_init(struct linux_romvec *rp)
74 (((unsigned long) prom_nodeops) == -1)) 72 (((unsigned long) prom_nodeops) == -1))
75 prom_halt(); 73 prom_halt();
76 74
77 if(prom_vers == PROM_V2 || prom_vers == PROM_V3) {
78 prom_stdout = *romvec->pv_v2bootargs.fd_stdout;
79 prom_stdin = *romvec->pv_v2bootargs.fd_stdin;
80 }
81
82 prom_meminit(); 75 prom_meminit();
83 76
84 prom_ranges_init(); 77 prom_ranges_init();
diff --git a/arch/sparc/prom/memory.c b/arch/sparc/prom/memory.c
index b0c0f9c4fc14..947f047dc95a 100644
--- a/arch/sparc/prom/memory.c
+++ b/arch/sparc/prom/memory.c
@@ -1,215 +1,100 @@
1/* $Id: memory.c,v 1.15 2000/01/29 01:09:12 anton Exp $ 1/* memory.c: Prom routine for acquiring various bits of information
2 * memory.c: Prom routine for acquiring various bits of information
3 * about RAM on the machine, both virtual and physical. 2 * about RAM on the machine, both virtual and physical.
4 * 3 *
5 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) 4 * Copyright (C) 1995, 2008 David S. Miller (davem@davemloft.net)
6 * Copyright (C) 1997 Michael A. Griffith (grif@acm.org) 5 * Copyright (C) 1997 Michael A. Griffith (grif@acm.org)
7 */ 6 */
8 7
9#include <linux/kernel.h> 8#include <linux/kernel.h>
9#include <linux/sort.h>
10#include <linux/init.h> 10#include <linux/init.h>
11 11
12#include <asm/openprom.h> 12#include <asm/openprom.h>
13#include <asm/sun4prom.h> 13#include <asm/sun4prom.h>
14#include <asm/oplib.h> 14#include <asm/oplib.h>
15#include <asm/page.h>
15 16
16/* This routine, for consistency, returns the ram parameters in the 17static int __init prom_meminit_v0(void)
17 * V0 prom memory descriptor format. I choose this format because I 18{
18 * think it was the easiest to work with. I feel the religious 19 struct linux_mlist_v0 *p;
19 * arguments now... ;) Also, I return the linked lists sorted to 20 int index;
20 * prevent paging_init() upset stomach as I have not yet written 21
21 * the pepto-bismol kernel module yet. 22 index = 0;
22 */ 23 for (p = *(romvec->pv_v0mem.v0_available); p; p = p->theres_more) {
24 sp_banks[index].base_addr = (unsigned long) p->start_adr;
25 sp_banks[index].num_bytes = p->num_bytes;
26 index++;
27 }
23 28
24struct linux_prom_registers prom_reg_memlist[64]; 29 return index;
25struct linux_prom_registers prom_reg_tmp[64]; 30}
26 31
27struct linux_mlist_v0 prom_phys_total[64]; 32static int __init prom_meminit_v2(void)
28struct linux_mlist_v0 prom_prom_taken[64]; 33{
29struct linux_mlist_v0 prom_phys_avail[64]; 34 struct linux_prom_registers reg[64];
35 int node, size, num_ents, i;
30 36
31struct linux_mlist_v0 *prom_ptot_ptr = prom_phys_total; 37 node = prom_searchsiblings(prom_getchild(prom_root_node), "memory");
32struct linux_mlist_v0 *prom_ptak_ptr = prom_prom_taken; 38 size = prom_getproperty(node, "available", (char *) reg, sizeof(reg));
33struct linux_mlist_v0 *prom_pavl_ptr = prom_phys_avail; 39 num_ents = size / sizeof(struct linux_prom_registers);
34 40
35struct linux_mem_v0 prom_memlist; 41 for (i = 0; i < num_ents; i++) {
42 sp_banks[i].base_addr = reg[i].phys_addr;
43 sp_banks[i].num_bytes = reg[i].reg_size;
44 }
36 45
46 return num_ents;
47}
37 48
38/* Internal Prom library routine to sort a linux_mlist_v0 memory 49static int __init prom_meminit_sun4(void)
39 * list. Used below in initialization.
40 */
41static void __init
42prom_sortmemlist(struct linux_mlist_v0 *thislist)
43{ 50{
44 int swapi = 0; 51#ifdef CONFIG_SUN4
45 int i, mitr, tmpsize; 52 sp_banks[0].base_addr = 0;
46 char *tmpaddr; 53 sp_banks[0].num_bytes = *(sun4_romvec->memoryavail);
47 char *lowest; 54#endif
48 55 return 1;
49 for(i=0; thislist[i].theres_more; i++) { 56}
50 lowest = thislist[i].start_adr; 57
51 for(mitr = i+1; thislist[mitr-1].theres_more; mitr++) 58static int sp_banks_cmp(const void *a, const void *b)
52 if(thislist[mitr].start_adr < lowest) { 59{
53 lowest = thislist[mitr].start_adr; 60 const struct sparc_phys_banks *x = a, *y = b;
54 swapi = mitr;
55 }
56 if(lowest == thislist[i].start_adr) continue;
57 tmpaddr = thislist[swapi].start_adr;
58 tmpsize = thislist[swapi].num_bytes;
59 for(mitr = swapi; mitr > i; mitr--) {
60 thislist[mitr].start_adr = thislist[mitr-1].start_adr;
61 thislist[mitr].num_bytes = thislist[mitr-1].num_bytes;
62 }
63 thislist[i].start_adr = tmpaddr;
64 thislist[i].num_bytes = tmpsize;
65 }
66 61
67 return; 62 if (x->base_addr > y->base_addr)
63 return 1;
64 if (x->base_addr < y->base_addr)
65 return -1;
66 return 0;
68} 67}
69 68
70/* Initialize the memory lists based upon the prom version. */ 69/* Initialize the memory lists based upon the prom version. */
71void __init prom_meminit(void) 70void __init prom_meminit(void)
72{ 71{
73 int node = 0; 72 int i, num_ents = 0;
74 unsigned int iter, num_regs;
75 struct linux_mlist_v0 *mptr; /* ptr for traversal */
76 73
77 switch(prom_vers) { 74 switch (prom_vers) {
78 case PROM_V0: 75 case PROM_V0:
79 /* Nice, kind of easier to do in this case. */ 76 num_ents = prom_meminit_v0();
80 /* First, the total physical descriptors. */
81 for(mptr = (*(romvec->pv_v0mem.v0_totphys)), iter=0;
82 mptr; mptr=mptr->theres_more, iter++) {
83 prom_phys_total[iter].start_adr = mptr->start_adr;
84 prom_phys_total[iter].num_bytes = mptr->num_bytes;
85 prom_phys_total[iter].theres_more = &prom_phys_total[iter+1];
86 }
87 prom_phys_total[iter-1].theres_more = NULL;
88 /* Second, the total prom taken descriptors. */
89 for(mptr = (*(romvec->pv_v0mem.v0_prommap)), iter=0;
90 mptr; mptr=mptr->theres_more, iter++) {
91 prom_prom_taken[iter].start_adr = mptr->start_adr;
92 prom_prom_taken[iter].num_bytes = mptr->num_bytes;
93 prom_prom_taken[iter].theres_more = &prom_prom_taken[iter+1];
94 }
95 prom_prom_taken[iter-1].theres_more = NULL;
96 /* Last, the available physical descriptors. */
97 for(mptr = (*(romvec->pv_v0mem.v0_available)), iter=0;
98 mptr; mptr=mptr->theres_more, iter++) {
99 prom_phys_avail[iter].start_adr = mptr->start_adr;
100 prom_phys_avail[iter].num_bytes = mptr->num_bytes;
101 prom_phys_avail[iter].theres_more = &prom_phys_avail[iter+1];
102 }
103 prom_phys_avail[iter-1].theres_more = NULL;
104 /* Sort all the lists. */
105 prom_sortmemlist(prom_phys_total);
106 prom_sortmemlist(prom_prom_taken);
107 prom_sortmemlist(prom_phys_avail);
108 break; 77 break;
78
109 case PROM_V2: 79 case PROM_V2:
110 case PROM_V3: 80 case PROM_V3:
111 /* Grrr, have to traverse the prom device tree ;( */ 81 num_ents = prom_meminit_v2();
112 node = prom_getchild(prom_root_node);
113 node = prom_searchsiblings(node, "memory");
114 num_regs = prom_getproperty(node, "available",
115 (char *) prom_reg_memlist,
116 sizeof(prom_reg_memlist));
117 num_regs = (num_regs/sizeof(struct linux_prom_registers));
118 for(iter=0; iter<num_regs; iter++) {
119 prom_phys_avail[iter].start_adr =
120 (char *) prom_reg_memlist[iter].phys_addr;
121 prom_phys_avail[iter].num_bytes =
122 (unsigned long) prom_reg_memlist[iter].reg_size;
123 prom_phys_avail[iter].theres_more =
124 &prom_phys_avail[iter+1];
125 }
126 prom_phys_avail[iter-1].theres_more = NULL;
127
128 num_regs = prom_getproperty(node, "reg",
129 (char *) prom_reg_memlist,
130 sizeof(prom_reg_memlist));
131 num_regs = (num_regs/sizeof(struct linux_prom_registers));
132 for(iter=0; iter<num_regs; iter++) {
133 prom_phys_total[iter].start_adr =
134 (char *) prom_reg_memlist[iter].phys_addr;
135 prom_phys_total[iter].num_bytes =
136 (unsigned long) prom_reg_memlist[iter].reg_size;
137 prom_phys_total[iter].theres_more =
138 &prom_phys_total[iter+1];
139 }
140 prom_phys_total[iter-1].theres_more = NULL;
141
142 node = prom_getchild(prom_root_node);
143 node = prom_searchsiblings(node, "virtual-memory");
144 num_regs = prom_getproperty(node, "available",
145 (char *) prom_reg_memlist,
146 sizeof(prom_reg_memlist));
147 num_regs = (num_regs/sizeof(struct linux_prom_registers));
148
149 /* Convert available virtual areas to taken virtual
150 * areas. First sort, then convert.
151 */
152 for(iter=0; iter<num_regs; iter++) {
153 prom_prom_taken[iter].start_adr =
154 (char *) prom_reg_memlist[iter].phys_addr;
155 prom_prom_taken[iter].num_bytes =
156 (unsigned long) prom_reg_memlist[iter].reg_size;
157 prom_prom_taken[iter].theres_more =
158 &prom_prom_taken[iter+1];
159 }
160 prom_prom_taken[iter-1].theres_more = NULL;
161
162 prom_sortmemlist(prom_prom_taken);
163
164 /* Finally, convert. */
165 for(iter=0; iter<num_regs; iter++) {
166 prom_prom_taken[iter].start_adr =
167 prom_prom_taken[iter].start_adr +
168 prom_prom_taken[iter].num_bytes;
169 prom_prom_taken[iter].num_bytes =
170 prom_prom_taken[iter+1].start_adr -
171 prom_prom_taken[iter].start_adr;
172 }
173 prom_prom_taken[iter-1].num_bytes =
174 0xffffffff - (unsigned long) prom_prom_taken[iter-1].start_adr;
175
176 /* Sort the other two lists. */
177 prom_sortmemlist(prom_phys_total);
178 prom_sortmemlist(prom_phys_avail);
179 break; 82 break;
180 83
181 case PROM_SUN4: 84 case PROM_SUN4:
182#ifdef CONFIG_SUN4 85 num_ents = prom_meminit_sun4();
183 /* how simple :) */
184 prom_phys_total[0].start_adr = NULL;
185 prom_phys_total[0].num_bytes = *(sun4_romvec->memorysize);
186 prom_phys_total[0].theres_more = NULL;
187 prom_prom_taken[0].start_adr = NULL;
188 prom_prom_taken[0].num_bytes = 0x0;
189 prom_prom_taken[0].theres_more = NULL;
190 prom_phys_avail[0].start_adr = NULL;
191 prom_phys_avail[0].num_bytes = *(sun4_romvec->memoryavail);
192 prom_phys_avail[0].theres_more = NULL;
193#endif
194 break; 86 break;
195 87
196 default: 88 default:
197 break; 89 break;
198 }; 90 }
199 91 sort(sp_banks, num_ents, sizeof(struct sparc_phys_banks),
200 /* Link all the lists into the top-level descriptor. */ 92 sp_banks_cmp, NULL);
201 prom_memlist.v0_totphys=&prom_ptot_ptr;
202 prom_memlist.v0_prommap=&prom_ptak_ptr;
203 prom_memlist.v0_available=&prom_pavl_ptr;
204 93
205 return; 94 /* Sentinel. */
206} 95 sp_banks[num_ents].base_addr = 0xdeadbeef;
96 sp_banks[num_ents].num_bytes = 0;
207 97
208/* This returns a pointer to our libraries internal v0 format 98 for (i = 0; i < num_ents; i++)
209 * memory descriptor. 99 sp_banks[i].num_bytes &= PAGE_MASK;
210 */
211struct linux_mem_v0 *
212prom_meminfo(void)
213{
214 return &prom_memlist;
215} 100}
diff --git a/arch/sparc64/Kconfig b/arch/sparc64/Kconfig
index edbe71e3fab9..eb36f3b746b8 100644
--- a/arch/sparc64/Kconfig
+++ b/arch/sparc64/Kconfig
@@ -13,6 +13,7 @@ config SPARC64
13 default y 13 default y
14 select HAVE_IDE 14 select HAVE_IDE
15 select HAVE_LMB 15 select HAVE_LMB
16 select HAVE_ARCH_KGDB
16 17
17config GENERIC_TIME 18config GENERIC_TIME
18 bool 19 bool
diff --git a/arch/sparc64/kernel/Makefile b/arch/sparc64/kernel/Makefile
index 2bd0340b743d..ec4f5ebb1ca6 100644
--- a/arch/sparc64/kernel/Makefile
+++ b/arch/sparc64/kernel/Makefile
@@ -29,3 +29,4 @@ obj-$(CONFIG_SUN_LDOMS) += ldc.o vio.o viohs.o ds.o
29obj-$(CONFIG_AUDIT) += audit.o 29obj-$(CONFIG_AUDIT) += audit.o
30obj-$(CONFIG_AUDIT)$(CONFIG_COMPAT) += compat_audit.o 30obj-$(CONFIG_AUDIT)$(CONFIG_COMPAT) += compat_audit.o
31obj-y += $(obj-yy) 31obj-y += $(obj-yy)
32obj-$(CONFIG_KGDB) += kgdb.o
diff --git a/arch/sparc64/kernel/cherrs.S b/arch/sparc64/kernel/cherrs.S
new file mode 100644
index 000000000000..89afebd7eca0
--- /dev/null
+++ b/arch/sparc64/kernel/cherrs.S
@@ -0,0 +1,579 @@
1 /* These get patched into the trap table at boot time
2 * once we know we have a cheetah processor.
3 */
4 .globl cheetah_fecc_trap_vector
5 .type cheetah_fecc_trap_vector,#function
6cheetah_fecc_trap_vector:
7 membar #Sync
8 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
9 andn %g1, DCU_DC | DCU_IC, %g1
10 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
11 membar #Sync
12 sethi %hi(cheetah_fast_ecc), %g2
13 jmpl %g2 + %lo(cheetah_fast_ecc), %g0
14 mov 0, %g1
15 .size cheetah_fecc_trap_vector,.-cheetah_fecc_trap_vector
16
17 .globl cheetah_fecc_trap_vector_tl1
18 .type cheetah_fecc_trap_vector_tl1,#function
19cheetah_fecc_trap_vector_tl1:
20 membar #Sync
21 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
22 andn %g1, DCU_DC | DCU_IC, %g1
23 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
24 membar #Sync
25 sethi %hi(cheetah_fast_ecc), %g2
26 jmpl %g2 + %lo(cheetah_fast_ecc), %g0
27 mov 1, %g1
28 .size cheetah_fecc_trap_vector_tl1,.-cheetah_fecc_trap_vector_tl1
29
30 .globl cheetah_cee_trap_vector
31 .type cheetah_cee_trap_vector,#function
32cheetah_cee_trap_vector:
33 membar #Sync
34 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
35 andn %g1, DCU_IC, %g1
36 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
37 membar #Sync
38 sethi %hi(cheetah_cee), %g2
39 jmpl %g2 + %lo(cheetah_cee), %g0
40 mov 0, %g1
41 .size cheetah_cee_trap_vector,.-cheetah_cee_trap_vector
42
43 .globl cheetah_cee_trap_vector_tl1
44 .type cheetah_cee_trap_vector_tl1,#function
45cheetah_cee_trap_vector_tl1:
46 membar #Sync
47 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
48 andn %g1, DCU_IC, %g1
49 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
50 membar #Sync
51 sethi %hi(cheetah_cee), %g2
52 jmpl %g2 + %lo(cheetah_cee), %g0
53 mov 1, %g1
54 .size cheetah_cee_trap_vector_tl1,.-cheetah_cee_trap_vector_tl1
55
56 .globl cheetah_deferred_trap_vector
57 .type cheetah_deferred_trap_vector,#function
58cheetah_deferred_trap_vector:
59 membar #Sync
60 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1;
61 andn %g1, DCU_DC | DCU_IC, %g1;
62 stxa %g1, [%g0] ASI_DCU_CONTROL_REG;
63 membar #Sync;
64 sethi %hi(cheetah_deferred_trap), %g2
65 jmpl %g2 + %lo(cheetah_deferred_trap), %g0
66 mov 0, %g1
67 .size cheetah_deferred_trap_vector,.-cheetah_deferred_trap_vector
68
69 .globl cheetah_deferred_trap_vector_tl1
70 .type cheetah_deferred_trap_vector_tl1,#function
71cheetah_deferred_trap_vector_tl1:
72 membar #Sync;
73 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1;
74 andn %g1, DCU_DC | DCU_IC, %g1;
75 stxa %g1, [%g0] ASI_DCU_CONTROL_REG;
76 membar #Sync;
77 sethi %hi(cheetah_deferred_trap), %g2
78 jmpl %g2 + %lo(cheetah_deferred_trap), %g0
79 mov 1, %g1
80 .size cheetah_deferred_trap_vector_tl1,.-cheetah_deferred_trap_vector_tl1
81
82 /* Cheetah+ specific traps. These are for the new I/D cache parity
83 * error traps. The first argument to cheetah_plus_parity_handler
84 * is encoded as follows:
85 *
86 * Bit0: 0=dcache,1=icache
87 * Bit1: 0=recoverable,1=unrecoverable
88 */
89 .globl cheetah_plus_dcpe_trap_vector
90 .type cheetah_plus_dcpe_trap_vector,#function
91cheetah_plus_dcpe_trap_vector:
92 membar #Sync
93 sethi %hi(do_cheetah_plus_data_parity), %g7
94 jmpl %g7 + %lo(do_cheetah_plus_data_parity), %g0
95 nop
96 nop
97 nop
98 nop
99 nop
100 .size cheetah_plus_dcpe_trap_vector,.-cheetah_plus_dcpe_trap_vector
101
102 .type do_cheetah_plus_data_parity,#function
103do_cheetah_plus_data_parity:
104 rdpr %pil, %g2
105 wrpr %g0, 15, %pil
106 ba,pt %xcc, etrap_irq
107 rd %pc, %g7
108#ifdef CONFIG_TRACE_IRQFLAGS
109 call trace_hardirqs_off
110 nop
111#endif
112 mov 0x0, %o0
113 call cheetah_plus_parity_error
114 add %sp, PTREGS_OFF, %o1
115 ba,a,pt %xcc, rtrap_irq
116 .size do_cheetah_plus_data_parity,.-do_cheetah_plus_data_parity
117
118 .globl cheetah_plus_dcpe_trap_vector_tl1
119 .type cheetah_plus_dcpe_trap_vector_tl1,#function
120cheetah_plus_dcpe_trap_vector_tl1:
121 membar #Sync
122 wrpr PSTATE_IG | PSTATE_PEF | PSTATE_PRIV, %pstate
123 sethi %hi(do_dcpe_tl1), %g3
124 jmpl %g3 + %lo(do_dcpe_tl1), %g0
125 nop
126 nop
127 nop
128 nop
129 .size cheetah_plus_dcpe_trap_vector_tl1,.-cheetah_plus_dcpe_trap_vector_tl1
130
131 .globl cheetah_plus_icpe_trap_vector
132 .type cheetah_plus_icpe_trap_vector,#function
133cheetah_plus_icpe_trap_vector:
134 membar #Sync
135 sethi %hi(do_cheetah_plus_insn_parity), %g7
136 jmpl %g7 + %lo(do_cheetah_plus_insn_parity), %g0
137 nop
138 nop
139 nop
140 nop
141 nop
142 .size cheetah_plus_icpe_trap_vector,.-cheetah_plus_icpe_trap_vector
143
144 .type do_cheetah_plus_insn_parity,#function
145do_cheetah_plus_insn_parity:
146 rdpr %pil, %g2
147 wrpr %g0, 15, %pil
148 ba,pt %xcc, etrap_irq
149 rd %pc, %g7
150#ifdef CONFIG_TRACE_IRQFLAGS
151 call trace_hardirqs_off
152 nop
153#endif
154 mov 0x1, %o0
155 call cheetah_plus_parity_error
156 add %sp, PTREGS_OFF, %o1
157 ba,a,pt %xcc, rtrap_irq
158 .size do_cheetah_plus_insn_parity,.-do_cheetah_plus_insn_parity
159
160 .globl cheetah_plus_icpe_trap_vector_tl1
161 .type cheetah_plus_icpe_trap_vector_tl1,#function
162cheetah_plus_icpe_trap_vector_tl1:
163 membar #Sync
164 wrpr PSTATE_IG | PSTATE_PEF | PSTATE_PRIV, %pstate
165 sethi %hi(do_icpe_tl1), %g3
166 jmpl %g3 + %lo(do_icpe_tl1), %g0
167 nop
168 nop
169 nop
170 nop
171 .size cheetah_plus_icpe_trap_vector_tl1,.-cheetah_plus_icpe_trap_vector_tl1
172
173 /* If we take one of these traps when tl >= 1, then we
174 * jump to interrupt globals. If some trap level above us
175 * was also using interrupt globals, we cannot recover.
176 * We may use all interrupt global registers except %g6.
177 */
178 .globl do_dcpe_tl1
179 .type do_dcpe_tl1,#function
180do_dcpe_tl1:
181 rdpr %tl, %g1 ! Save original trap level
182 mov 1, %g2 ! Setup TSTATE checking loop
183 sethi %hi(TSTATE_IG), %g3 ! TSTATE mask bit
1841: wrpr %g2, %tl ! Set trap level to check
185 rdpr %tstate, %g4 ! Read TSTATE for this level
186 andcc %g4, %g3, %g0 ! Interrupt globals in use?
187 bne,a,pn %xcc, do_dcpe_tl1_fatal ! Yep, irrecoverable
188 wrpr %g1, %tl ! Restore original trap level
189 add %g2, 1, %g2 ! Next trap level
190 cmp %g2, %g1 ! Hit them all yet?
191 ble,pt %icc, 1b ! Not yet
192 nop
193 wrpr %g1, %tl ! Restore original trap level
194do_dcpe_tl1_nonfatal: /* Ok we may use interrupt globals safely. */
195 sethi %hi(dcache_parity_tl1_occurred), %g2
196 lduw [%g2 + %lo(dcache_parity_tl1_occurred)], %g1
197 add %g1, 1, %g1
198 stw %g1, [%g2 + %lo(dcache_parity_tl1_occurred)]
199 /* Reset D-cache parity */
200 sethi %hi(1 << 16), %g1 ! D-cache size
201 mov (1 << 5), %g2 ! D-cache line size
202 sub %g1, %g2, %g1 ! Move down 1 cacheline
2031: srl %g1, 14, %g3 ! Compute UTAG
204 membar #Sync
205 stxa %g3, [%g1] ASI_DCACHE_UTAG
206 membar #Sync
207 sub %g2, 8, %g3 ! 64-bit data word within line
2082: membar #Sync
209 stxa %g0, [%g1 + %g3] ASI_DCACHE_DATA
210 membar #Sync
211 subcc %g3, 8, %g3 ! Next 64-bit data word
212 bge,pt %icc, 2b
213 nop
214 subcc %g1, %g2, %g1 ! Next cacheline
215 bge,pt %icc, 1b
216 nop
217 ba,pt %xcc, dcpe_icpe_tl1_common
218 nop
219
220do_dcpe_tl1_fatal:
221 sethi %hi(1f), %g7
222 ba,pt %xcc, etraptl1
2231: or %g7, %lo(1b), %g7
224 mov 0x2, %o0
225 call cheetah_plus_parity_error
226 add %sp, PTREGS_OFF, %o1
227 ba,pt %xcc, rtrap
228 nop
229 .size do_dcpe_tl1,.-do_dcpe_tl1
230
231 .globl do_icpe_tl1
232 .type do_icpe_tl1,#function
233do_icpe_tl1:
234 rdpr %tl, %g1 ! Save original trap level
235 mov 1, %g2 ! Setup TSTATE checking loop
236 sethi %hi(TSTATE_IG), %g3 ! TSTATE mask bit
2371: wrpr %g2, %tl ! Set trap level to check
238 rdpr %tstate, %g4 ! Read TSTATE for this level
239 andcc %g4, %g3, %g0 ! Interrupt globals in use?
240 bne,a,pn %xcc, do_icpe_tl1_fatal ! Yep, irrecoverable
241 wrpr %g1, %tl ! Restore original trap level
242 add %g2, 1, %g2 ! Next trap level
243 cmp %g2, %g1 ! Hit them all yet?
244 ble,pt %icc, 1b ! Not yet
245 nop
246 wrpr %g1, %tl ! Restore original trap level
247do_icpe_tl1_nonfatal: /* Ok we may use interrupt globals safely. */
248 sethi %hi(icache_parity_tl1_occurred), %g2
249 lduw [%g2 + %lo(icache_parity_tl1_occurred)], %g1
250 add %g1, 1, %g1
251 stw %g1, [%g2 + %lo(icache_parity_tl1_occurred)]
252 /* Flush I-cache */
253 sethi %hi(1 << 15), %g1 ! I-cache size
254 mov (1 << 5), %g2 ! I-cache line size
255 sub %g1, %g2, %g1
2561: or %g1, (2 << 3), %g3
257 stxa %g0, [%g3] ASI_IC_TAG
258 membar #Sync
259 subcc %g1, %g2, %g1
260 bge,pt %icc, 1b
261 nop
262 ba,pt %xcc, dcpe_icpe_tl1_common
263 nop
264
265do_icpe_tl1_fatal:
266 sethi %hi(1f), %g7
267 ba,pt %xcc, etraptl1
2681: or %g7, %lo(1b), %g7
269 mov 0x3, %o0
270 call cheetah_plus_parity_error
271 add %sp, PTREGS_OFF, %o1
272 ba,pt %xcc, rtrap
273 nop
274 .size do_icpe_tl1,.-do_icpe_tl1
275
276 .type dcpe_icpe_tl1_common,#function
277dcpe_icpe_tl1_common:
278 /* Flush D-cache, re-enable D/I caches in DCU and finally
279 * retry the trapping instruction.
280 */
281 sethi %hi(1 << 16), %g1 ! D-cache size
282 mov (1 << 5), %g2 ! D-cache line size
283 sub %g1, %g2, %g1
2841: stxa %g0, [%g1] ASI_DCACHE_TAG
285 membar #Sync
286 subcc %g1, %g2, %g1
287 bge,pt %icc, 1b
288 nop
289 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
290 or %g1, (DCU_DC | DCU_IC), %g1
291 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
292 membar #Sync
293 retry
294 .size dcpe_icpe_tl1_common,.-dcpe_icpe_tl1_common
295
296 /* Capture I/D/E-cache state into per-cpu error scoreboard.
297 *
298 * %g1: (TL>=0) ? 1 : 0
299 * %g2: scratch
300 * %g3: scratch
301 * %g4: AFSR
302 * %g5: AFAR
303 * %g6: unused, will have current thread ptr after etrap
304 * %g7: scratch
305 */
306 .type __cheetah_log_error,#function
307__cheetah_log_error:
308 /* Put "TL1" software bit into AFSR. */
309 and %g1, 0x1, %g1
310 sllx %g1, 63, %g2
311 or %g4, %g2, %g4
312
313 /* Get log entry pointer for this cpu at this trap level. */
314 BRANCH_IF_JALAPENO(g2,g3,50f)
315 ldxa [%g0] ASI_SAFARI_CONFIG, %g2
316 srlx %g2, 17, %g2
317 ba,pt %xcc, 60f
318 and %g2, 0x3ff, %g2
319
32050: ldxa [%g0] ASI_JBUS_CONFIG, %g2
321 srlx %g2, 17, %g2
322 and %g2, 0x1f, %g2
323
32460: sllx %g2, 9, %g2
325 sethi %hi(cheetah_error_log), %g3
326 ldx [%g3 + %lo(cheetah_error_log)], %g3
327 brz,pn %g3, 80f
328 nop
329
330 add %g3, %g2, %g3
331 sllx %g1, 8, %g1
332 add %g3, %g1, %g1
333
334 /* %g1 holds pointer to the top of the logging scoreboard */
335 ldx [%g1 + 0x0], %g7
336 cmp %g7, -1
337 bne,pn %xcc, 80f
338 nop
339
340 stx %g4, [%g1 + 0x0]
341 stx %g5, [%g1 + 0x8]
342 add %g1, 0x10, %g1
343
344 /* %g1 now points to D-cache logging area */
345 set 0x3ff8, %g2 /* DC_addr mask */
346 and %g5, %g2, %g2 /* DC_addr bits of AFAR */
347 srlx %g5, 12, %g3
348 or %g3, 1, %g3 /* PHYS tag + valid */
349
35010: ldxa [%g2] ASI_DCACHE_TAG, %g7
351 cmp %g3, %g7 /* TAG match? */
352 bne,pt %xcc, 13f
353 nop
354
355 /* Yep, what we want, capture state. */
356 stx %g2, [%g1 + 0x20]
357 stx %g7, [%g1 + 0x28]
358
359 /* A membar Sync is required before and after utag access. */
360 membar #Sync
361 ldxa [%g2] ASI_DCACHE_UTAG, %g7
362 membar #Sync
363 stx %g7, [%g1 + 0x30]
364 ldxa [%g2] ASI_DCACHE_SNOOP_TAG, %g7
365 stx %g7, [%g1 + 0x38]
366 clr %g3
367
36812: ldxa [%g2 + %g3] ASI_DCACHE_DATA, %g7
369 stx %g7, [%g1]
370 add %g3, (1 << 5), %g3
371 cmp %g3, (4 << 5)
372 bl,pt %xcc, 12b
373 add %g1, 0x8, %g1
374
375 ba,pt %xcc, 20f
376 add %g1, 0x20, %g1
377
37813: sethi %hi(1 << 14), %g7
379 add %g2, %g7, %g2
380 srlx %g2, 14, %g7
381 cmp %g7, 4
382 bl,pt %xcc, 10b
383 nop
384
385 add %g1, 0x40, %g1
386
387 /* %g1 now points to I-cache logging area */
38820: set 0x1fe0, %g2 /* IC_addr mask */
389 and %g5, %g2, %g2 /* IC_addr bits of AFAR */
390 sllx %g2, 1, %g2 /* IC_addr[13:6]==VA[12:5] */
391 srlx %g5, (13 - 8), %g3 /* Make PTAG */
392 andn %g3, 0xff, %g3 /* Mask off undefined bits */
393
39421: ldxa [%g2] ASI_IC_TAG, %g7
395 andn %g7, 0xff, %g7
396 cmp %g3, %g7
397 bne,pt %xcc, 23f
398 nop
399
400 /* Yep, what we want, capture state. */
401 stx %g2, [%g1 + 0x40]
402 stx %g7, [%g1 + 0x48]
403 add %g2, (1 << 3), %g2
404 ldxa [%g2] ASI_IC_TAG, %g7
405 add %g2, (1 << 3), %g2
406 stx %g7, [%g1 + 0x50]
407 ldxa [%g2] ASI_IC_TAG, %g7
408 add %g2, (1 << 3), %g2
409 stx %g7, [%g1 + 0x60]
410 ldxa [%g2] ASI_IC_TAG, %g7
411 stx %g7, [%g1 + 0x68]
412 sub %g2, (3 << 3), %g2
413 ldxa [%g2] ASI_IC_STAG, %g7
414 stx %g7, [%g1 + 0x58]
415 clr %g3
416 srlx %g2, 2, %g2
417
41822: ldxa [%g2 + %g3] ASI_IC_INSTR, %g7
419 stx %g7, [%g1]
420 add %g3, (1 << 3), %g3
421 cmp %g3, (8 << 3)
422 bl,pt %xcc, 22b
423 add %g1, 0x8, %g1
424
425 ba,pt %xcc, 30f
426 add %g1, 0x30, %g1
427
42823: sethi %hi(1 << 14), %g7
429 add %g2, %g7, %g2
430 srlx %g2, 14, %g7
431 cmp %g7, 4
432 bl,pt %xcc, 21b
433 nop
434
435 add %g1, 0x70, %g1
436
437 /* %g1 now points to E-cache logging area */
43830: andn %g5, (32 - 1), %g2
439 stx %g2, [%g1 + 0x20]
440 ldxa [%g2] ASI_EC_TAG_DATA, %g7
441 stx %g7, [%g1 + 0x28]
442 ldxa [%g2] ASI_EC_R, %g0
443 clr %g3
444
44531: ldxa [%g3] ASI_EC_DATA, %g7
446 stx %g7, [%g1 + %g3]
447 add %g3, 0x8, %g3
448 cmp %g3, 0x20
449
450 bl,pt %xcc, 31b
451 nop
45280:
453 rdpr %tt, %g2
454 cmp %g2, 0x70
455 be c_fast_ecc
456 cmp %g2, 0x63
457 be c_cee
458 nop
459 ba,pt %xcc, c_deferred
460 .size __cheetah_log_error,.-__cheetah_log_error
461
462 /* Cheetah FECC trap handling, we get here from tl{0,1}_fecc
463 * in the trap table. That code has done a memory barrier
464 * and has disabled both the I-cache and D-cache in the DCU
465 * control register. The I-cache is disabled so that we may
466 * capture the corrupted cache line, and the D-cache is disabled
467 * because corrupt data may have been placed there and we don't
468 * want to reference it.
469 *
470 * %g1 is one if this trap occurred at %tl >= 1.
471 *
472 * Next, we turn off error reporting so that we don't recurse.
473 */
474 .globl cheetah_fast_ecc
475 .type cheetah_fast_ecc,#function
476cheetah_fast_ecc:
477 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
478 andn %g2, ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN, %g2
479 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
480 membar #Sync
481
482 /* Fetch and clear AFSR/AFAR */
483 ldxa [%g0] ASI_AFSR, %g4
484 ldxa [%g0] ASI_AFAR, %g5
485 stxa %g4, [%g0] ASI_AFSR
486 membar #Sync
487
488 ba,pt %xcc, __cheetah_log_error
489 nop
490 .size cheetah_fast_ecc,.-cheetah_fast_ecc
491
492 .type c_fast_ecc,#function
493c_fast_ecc:
494 rdpr %pil, %g2
495 wrpr %g0, 15, %pil
496 ba,pt %xcc, etrap_irq
497 rd %pc, %g7
498#ifdef CONFIG_TRACE_IRQFLAGS
499 call trace_hardirqs_off
500 nop
501#endif
502 mov %l4, %o1
503 mov %l5, %o2
504 call cheetah_fecc_handler
505 add %sp, PTREGS_OFF, %o0
506 ba,a,pt %xcc, rtrap_irq
507 .size c_fast_ecc,.-c_fast_ecc
508
509 /* Our caller has disabled I-cache and performed membar Sync. */
510 .globl cheetah_cee
511 .type cheetah_cee,#function
512cheetah_cee:
513 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
514 andn %g2, ESTATE_ERROR_CEEN, %g2
515 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
516 membar #Sync
517
518 /* Fetch and clear AFSR/AFAR */
519 ldxa [%g0] ASI_AFSR, %g4
520 ldxa [%g0] ASI_AFAR, %g5
521 stxa %g4, [%g0] ASI_AFSR
522 membar #Sync
523
524 ba,pt %xcc, __cheetah_log_error
525 nop
526 .size cheetah_cee,.-cheetah_cee
527
528 .type c_cee,#function
529c_cee:
530 rdpr %pil, %g2
531 wrpr %g0, 15, %pil
532 ba,pt %xcc, etrap_irq
533 rd %pc, %g7
534#ifdef CONFIG_TRACE_IRQFLAGS
535 call trace_hardirqs_off
536 nop
537#endif
538 mov %l4, %o1
539 mov %l5, %o2
540 call cheetah_cee_handler
541 add %sp, PTREGS_OFF, %o0
542 ba,a,pt %xcc, rtrap_irq
543 .size c_cee,.-c_cee
544
545 /* Our caller has disabled I-cache+D-cache and performed membar Sync. */
546 .globl cheetah_deferred_trap
547 .type cheetah_deferred_trap,#function
548cheetah_deferred_trap:
549 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
550 andn %g2, ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN, %g2
551 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
552 membar #Sync
553
554 /* Fetch and clear AFSR/AFAR */
555 ldxa [%g0] ASI_AFSR, %g4
556 ldxa [%g0] ASI_AFAR, %g5
557 stxa %g4, [%g0] ASI_AFSR
558 membar #Sync
559
560 ba,pt %xcc, __cheetah_log_error
561 nop
562 .size cheetah_deferred_trap,.-cheetah_deferred_trap
563
564 .type c_deferred,#function
565c_deferred:
566 rdpr %pil, %g2
567 wrpr %g0, 15, %pil
568 ba,pt %xcc, etrap_irq
569 rd %pc, %g7
570#ifdef CONFIG_TRACE_IRQFLAGS
571 call trace_hardirqs_off
572 nop
573#endif
574 mov %l4, %o1
575 mov %l5, %o2
576 call cheetah_deferred_handler
577 add %sp, PTREGS_OFF, %o0
578 ba,a,pt %xcc, rtrap_irq
579 .size c_deferred,.-c_deferred
diff --git a/arch/sparc64/kernel/entry.S b/arch/sparc64/kernel/entry.S
deleted file mode 100644
index fd06e937ae1e..000000000000
--- a/arch/sparc64/kernel/entry.S
+++ /dev/null
@@ -1,2575 +0,0 @@
1/* $Id: entry.S,v 1.144 2002/02/09 19:49:30 davem Exp $
2 * arch/sparc64/kernel/entry.S: Sparc64 trap low-level entry points.
3 *
4 * Copyright (C) 1995,1997 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
6 * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
7 * Copyright (C) 1996,98,99 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
8 */
9
10#include <linux/errno.h>
11
12#include <asm/head.h>
13#include <asm/asi.h>
14#include <asm/smp.h>
15#include <asm/ptrace.h>
16#include <asm/page.h>
17#include <asm/signal.h>
18#include <asm/pgtable.h>
19#include <asm/processor.h>
20#include <asm/visasm.h>
21#include <asm/estate.h>
22#include <asm/auxio.h>
23#include <asm/sfafsr.h>
24#include <asm/pil.h>
25#include <asm/unistd.h>
26
27#define curptr g6
28
29 .text
30 .align 32
31
32 /* This is trivial with the new code... */
33 .globl do_fpdis
34do_fpdis:
35 sethi %hi(TSTATE_PEF), %g4
36 rdpr %tstate, %g5
37 andcc %g5, %g4, %g0
38 be,pt %xcc, 1f
39 nop
40 rd %fprs, %g5
41 andcc %g5, FPRS_FEF, %g0
42 be,pt %xcc, 1f
43 nop
44
45 /* Legal state when DCR_IFPOE is set in Cheetah %dcr. */
46 sethi %hi(109f), %g7
47 ba,pt %xcc, etrap
48109: or %g7, %lo(109b), %g7
49 add %g0, %g0, %g0
50 ba,a,pt %xcc, rtrap
51
521: TRAP_LOAD_THREAD_REG(%g6, %g1)
53 ldub [%g6 + TI_FPSAVED], %g5
54 wr %g0, FPRS_FEF, %fprs
55 andcc %g5, FPRS_FEF, %g0
56 be,a,pt %icc, 1f
57 clr %g7
58 ldx [%g6 + TI_GSR], %g7
591: andcc %g5, FPRS_DL, %g0
60 bne,pn %icc, 2f
61 fzero %f0
62 andcc %g5, FPRS_DU, %g0
63 bne,pn %icc, 1f
64 fzero %f2
65 faddd %f0, %f2, %f4
66 fmuld %f0, %f2, %f6
67 faddd %f0, %f2, %f8
68 fmuld %f0, %f2, %f10
69 faddd %f0, %f2, %f12
70 fmuld %f0, %f2, %f14
71 faddd %f0, %f2, %f16
72 fmuld %f0, %f2, %f18
73 faddd %f0, %f2, %f20
74 fmuld %f0, %f2, %f22
75 faddd %f0, %f2, %f24
76 fmuld %f0, %f2, %f26
77 faddd %f0, %f2, %f28
78 fmuld %f0, %f2, %f30
79 faddd %f0, %f2, %f32
80 fmuld %f0, %f2, %f34
81 faddd %f0, %f2, %f36
82 fmuld %f0, %f2, %f38
83 faddd %f0, %f2, %f40
84 fmuld %f0, %f2, %f42
85 faddd %f0, %f2, %f44
86 fmuld %f0, %f2, %f46
87 faddd %f0, %f2, %f48
88 fmuld %f0, %f2, %f50
89 faddd %f0, %f2, %f52
90 fmuld %f0, %f2, %f54
91 faddd %f0, %f2, %f56
92 fmuld %f0, %f2, %f58
93 b,pt %xcc, fpdis_exit2
94 faddd %f0, %f2, %f60
951: mov SECONDARY_CONTEXT, %g3
96 add %g6, TI_FPREGS + 0x80, %g1
97 faddd %f0, %f2, %f4
98 fmuld %f0, %f2, %f6
99
100661: ldxa [%g3] ASI_DMMU, %g5
101 .section .sun4v_1insn_patch, "ax"
102 .word 661b
103 ldxa [%g3] ASI_MMU, %g5
104 .previous
105
106 sethi %hi(sparc64_kern_sec_context), %g2
107 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
108
109661: stxa %g2, [%g3] ASI_DMMU
110 .section .sun4v_1insn_patch, "ax"
111 .word 661b
112 stxa %g2, [%g3] ASI_MMU
113 .previous
114
115 membar #Sync
116 add %g6, TI_FPREGS + 0xc0, %g2
117 faddd %f0, %f2, %f8
118 fmuld %f0, %f2, %f10
119 membar #Sync
120 ldda [%g1] ASI_BLK_S, %f32
121 ldda [%g2] ASI_BLK_S, %f48
122 membar #Sync
123 faddd %f0, %f2, %f12
124 fmuld %f0, %f2, %f14
125 faddd %f0, %f2, %f16
126 fmuld %f0, %f2, %f18
127 faddd %f0, %f2, %f20
128 fmuld %f0, %f2, %f22
129 faddd %f0, %f2, %f24
130 fmuld %f0, %f2, %f26
131 faddd %f0, %f2, %f28
132 fmuld %f0, %f2, %f30
133 b,pt %xcc, fpdis_exit
134 nop
1352: andcc %g5, FPRS_DU, %g0
136 bne,pt %icc, 3f
137 fzero %f32
138 mov SECONDARY_CONTEXT, %g3
139 fzero %f34
140
141661: ldxa [%g3] ASI_DMMU, %g5
142 .section .sun4v_1insn_patch, "ax"
143 .word 661b
144 ldxa [%g3] ASI_MMU, %g5
145 .previous
146
147 add %g6, TI_FPREGS, %g1
148 sethi %hi(sparc64_kern_sec_context), %g2
149 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
150
151661: stxa %g2, [%g3] ASI_DMMU
152 .section .sun4v_1insn_patch, "ax"
153 .word 661b
154 stxa %g2, [%g3] ASI_MMU
155 .previous
156
157 membar #Sync
158 add %g6, TI_FPREGS + 0x40, %g2
159 faddd %f32, %f34, %f36
160 fmuld %f32, %f34, %f38
161 membar #Sync
162 ldda [%g1] ASI_BLK_S, %f0
163 ldda [%g2] ASI_BLK_S, %f16
164 membar #Sync
165 faddd %f32, %f34, %f40
166 fmuld %f32, %f34, %f42
167 faddd %f32, %f34, %f44
168 fmuld %f32, %f34, %f46
169 faddd %f32, %f34, %f48
170 fmuld %f32, %f34, %f50
171 faddd %f32, %f34, %f52
172 fmuld %f32, %f34, %f54
173 faddd %f32, %f34, %f56
174 fmuld %f32, %f34, %f58
175 faddd %f32, %f34, %f60
176 fmuld %f32, %f34, %f62
177 ba,pt %xcc, fpdis_exit
178 nop
1793: mov SECONDARY_CONTEXT, %g3
180 add %g6, TI_FPREGS, %g1
181
182661: ldxa [%g3] ASI_DMMU, %g5
183 .section .sun4v_1insn_patch, "ax"
184 .word 661b
185 ldxa [%g3] ASI_MMU, %g5
186 .previous
187
188 sethi %hi(sparc64_kern_sec_context), %g2
189 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
190
191661: stxa %g2, [%g3] ASI_DMMU
192 .section .sun4v_1insn_patch, "ax"
193 .word 661b
194 stxa %g2, [%g3] ASI_MMU
195 .previous
196
197 membar #Sync
198 mov 0x40, %g2
199 membar #Sync
200 ldda [%g1] ASI_BLK_S, %f0
201 ldda [%g1 + %g2] ASI_BLK_S, %f16
202 add %g1, 0x80, %g1
203 ldda [%g1] ASI_BLK_S, %f32
204 ldda [%g1 + %g2] ASI_BLK_S, %f48
205 membar #Sync
206fpdis_exit:
207
208661: stxa %g5, [%g3] ASI_DMMU
209 .section .sun4v_1insn_patch, "ax"
210 .word 661b
211 stxa %g5, [%g3] ASI_MMU
212 .previous
213
214 membar #Sync
215fpdis_exit2:
216 wr %g7, 0, %gsr
217 ldx [%g6 + TI_XFSR], %fsr
218 rdpr %tstate, %g3
219 or %g3, %g4, %g3 ! anal...
220 wrpr %g3, %tstate
221 wr %g0, FPRS_FEF, %fprs ! clean DU/DL bits
222 retry
223
224 .align 32
225fp_other_bounce:
226 call do_fpother
227 add %sp, PTREGS_OFF, %o0
228 ba,pt %xcc, rtrap
229 nop
230
231 .globl do_fpother_check_fitos
232 .align 32
233do_fpother_check_fitos:
234 TRAP_LOAD_THREAD_REG(%g6, %g1)
235 sethi %hi(fp_other_bounce - 4), %g7
236 or %g7, %lo(fp_other_bounce - 4), %g7
237
238 /* NOTE: Need to preserve %g7 until we fully commit
239 * to the fitos fixup.
240 */
241 stx %fsr, [%g6 + TI_XFSR]
242 rdpr %tstate, %g3
243 andcc %g3, TSTATE_PRIV, %g0
244 bne,pn %xcc, do_fptrap_after_fsr
245 nop
246 ldx [%g6 + TI_XFSR], %g3
247 srlx %g3, 14, %g1
248 and %g1, 7, %g1
249 cmp %g1, 2 ! Unfinished FP-OP
250 bne,pn %xcc, do_fptrap_after_fsr
251 sethi %hi(1 << 23), %g1 ! Inexact
252 andcc %g3, %g1, %g0
253 bne,pn %xcc, do_fptrap_after_fsr
254 rdpr %tpc, %g1
255 lduwa [%g1] ASI_AIUP, %g3 ! This cannot ever fail
256#define FITOS_MASK 0xc1f83fe0
257#define FITOS_COMPARE 0x81a01880
258 sethi %hi(FITOS_MASK), %g1
259 or %g1, %lo(FITOS_MASK), %g1
260 and %g3, %g1, %g1
261 sethi %hi(FITOS_COMPARE), %g2
262 or %g2, %lo(FITOS_COMPARE), %g2
263 cmp %g1, %g2
264 bne,pn %xcc, do_fptrap_after_fsr
265 nop
266 std %f62, [%g6 + TI_FPREGS + (62 * 4)]
267 sethi %hi(fitos_table_1), %g1
268 and %g3, 0x1f, %g2
269 or %g1, %lo(fitos_table_1), %g1
270 sllx %g2, 2, %g2
271 jmpl %g1 + %g2, %g0
272 ba,pt %xcc, fitos_emul_continue
273
274fitos_table_1:
275 fitod %f0, %f62
276 fitod %f1, %f62
277 fitod %f2, %f62
278 fitod %f3, %f62
279 fitod %f4, %f62
280 fitod %f5, %f62
281 fitod %f6, %f62
282 fitod %f7, %f62
283 fitod %f8, %f62
284 fitod %f9, %f62
285 fitod %f10, %f62
286 fitod %f11, %f62
287 fitod %f12, %f62
288 fitod %f13, %f62
289 fitod %f14, %f62
290 fitod %f15, %f62
291 fitod %f16, %f62
292 fitod %f17, %f62
293 fitod %f18, %f62
294 fitod %f19, %f62
295 fitod %f20, %f62
296 fitod %f21, %f62
297 fitod %f22, %f62
298 fitod %f23, %f62
299 fitod %f24, %f62
300 fitod %f25, %f62
301 fitod %f26, %f62
302 fitod %f27, %f62
303 fitod %f28, %f62
304 fitod %f29, %f62
305 fitod %f30, %f62
306 fitod %f31, %f62
307
308fitos_emul_continue:
309 sethi %hi(fitos_table_2), %g1
310 srl %g3, 25, %g2
311 or %g1, %lo(fitos_table_2), %g1
312 and %g2, 0x1f, %g2
313 sllx %g2, 2, %g2
314 jmpl %g1 + %g2, %g0
315 ba,pt %xcc, fitos_emul_fini
316
317fitos_table_2:
318 fdtos %f62, %f0
319 fdtos %f62, %f1
320 fdtos %f62, %f2
321 fdtos %f62, %f3
322 fdtos %f62, %f4
323 fdtos %f62, %f5
324 fdtos %f62, %f6
325 fdtos %f62, %f7
326 fdtos %f62, %f8
327 fdtos %f62, %f9
328 fdtos %f62, %f10
329 fdtos %f62, %f11
330 fdtos %f62, %f12
331 fdtos %f62, %f13
332 fdtos %f62, %f14
333 fdtos %f62, %f15
334 fdtos %f62, %f16
335 fdtos %f62, %f17
336 fdtos %f62, %f18
337 fdtos %f62, %f19
338 fdtos %f62, %f20
339 fdtos %f62, %f21
340 fdtos %f62, %f22
341 fdtos %f62, %f23
342 fdtos %f62, %f24
343 fdtos %f62, %f25
344 fdtos %f62, %f26
345 fdtos %f62, %f27
346 fdtos %f62, %f28
347 fdtos %f62, %f29
348 fdtos %f62, %f30
349 fdtos %f62, %f31
350
351fitos_emul_fini:
352 ldd [%g6 + TI_FPREGS + (62 * 4)], %f62
353 done
354
355 .globl do_fptrap
356 .align 32
357do_fptrap:
358 TRAP_LOAD_THREAD_REG(%g6, %g1)
359 stx %fsr, [%g6 + TI_XFSR]
360do_fptrap_after_fsr:
361 ldub [%g6 + TI_FPSAVED], %g3
362 rd %fprs, %g1
363 or %g3, %g1, %g3
364 stb %g3, [%g6 + TI_FPSAVED]
365 rd %gsr, %g3
366 stx %g3, [%g6 + TI_GSR]
367 mov SECONDARY_CONTEXT, %g3
368
369661: ldxa [%g3] ASI_DMMU, %g5
370 .section .sun4v_1insn_patch, "ax"
371 .word 661b
372 ldxa [%g3] ASI_MMU, %g5
373 .previous
374
375 sethi %hi(sparc64_kern_sec_context), %g2
376 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
377
378661: stxa %g2, [%g3] ASI_DMMU
379 .section .sun4v_1insn_patch, "ax"
380 .word 661b
381 stxa %g2, [%g3] ASI_MMU
382 .previous
383
384 membar #Sync
385 add %g6, TI_FPREGS, %g2
386 andcc %g1, FPRS_DL, %g0
387 be,pn %icc, 4f
388 mov 0x40, %g3
389 stda %f0, [%g2] ASI_BLK_S
390 stda %f16, [%g2 + %g3] ASI_BLK_S
391 andcc %g1, FPRS_DU, %g0
392 be,pn %icc, 5f
3934: add %g2, 128, %g2
394 stda %f32, [%g2] ASI_BLK_S
395 stda %f48, [%g2 + %g3] ASI_BLK_S
3965: mov SECONDARY_CONTEXT, %g1
397 membar #Sync
398
399661: stxa %g5, [%g1] ASI_DMMU
400 .section .sun4v_1insn_patch, "ax"
401 .word 661b
402 stxa %g5, [%g1] ASI_MMU
403 .previous
404
405 membar #Sync
406 ba,pt %xcc, etrap
407 wr %g0, 0, %fprs
408
409 /* The registers for cross calls will be:
410 *
411 * DATA 0: [low 32-bits] Address of function to call, jmp to this
412 * [high 32-bits] MMU Context Argument 0, place in %g5
413 * DATA 1: Address Argument 1, place in %g1
414 * DATA 2: Address Argument 2, place in %g7
415 *
416 * With this method we can do most of the cross-call tlb/cache
417 * flushing very quickly.
418 */
419 .text
420 .align 32
421 .globl do_ivec
422do_ivec:
423 mov 0x40, %g3
424 ldxa [%g3 + %g0] ASI_INTR_R, %g3
425 sethi %hi(KERNBASE), %g4
426 cmp %g3, %g4
427 bgeu,pn %xcc, do_ivec_xcall
428 srlx %g3, 32, %g5
429 stxa %g0, [%g0] ASI_INTR_RECEIVE
430 membar #Sync
431
432 sethi %hi(ivector_table_pa), %g2
433 ldx [%g2 + %lo(ivector_table_pa)], %g2
434 sllx %g3, 4, %g3
435 add %g2, %g3, %g3
436
437 TRAP_LOAD_IRQ_WORK_PA(%g6, %g1)
438
439 ldx [%g6], %g5
440 stxa %g5, [%g3] ASI_PHYS_USE_EC
441 stx %g3, [%g6]
442 wr %g0, 1 << PIL_DEVICE_IRQ, %set_softint
443 retry
444do_ivec_xcall:
445 mov 0x50, %g1
446 ldxa [%g1 + %g0] ASI_INTR_R, %g1
447 srl %g3, 0, %g3
448
449 mov 0x60, %g7
450 ldxa [%g7 + %g0] ASI_INTR_R, %g7
451 stxa %g0, [%g0] ASI_INTR_RECEIVE
452 membar #Sync
453 ba,pt %xcc, 1f
454 nop
455
456 .align 32
4571: jmpl %g3, %g0
458 nop
459
460 .globl getcc, setcc
461getcc:
462 ldx [%o0 + PT_V9_TSTATE], %o1
463 srlx %o1, 32, %o1
464 and %o1, 0xf, %o1
465 retl
466 stx %o1, [%o0 + PT_V9_G1]
467setcc:
468 ldx [%o0 + PT_V9_TSTATE], %o1
469 ldx [%o0 + PT_V9_G1], %o2
470 or %g0, %ulo(TSTATE_ICC), %o3
471 sllx %o3, 32, %o3
472 andn %o1, %o3, %o1
473 sllx %o2, 32, %o2
474 and %o2, %o3, %o2
475 or %o1, %o2, %o1
476 retl
477 stx %o1, [%o0 + PT_V9_TSTATE]
478
479 .globl utrap_trap
480utrap_trap: /* %g3=handler,%g4=level */
481 TRAP_LOAD_THREAD_REG(%g6, %g1)
482 ldx [%g6 + TI_UTRAPS], %g1
483 brnz,pt %g1, invoke_utrap
484 nop
485
486 ba,pt %xcc, etrap
487 rd %pc, %g7
488 mov %l4, %o1
489 call bad_trap
490 add %sp, PTREGS_OFF, %o0
491 ba,pt %xcc, rtrap
492 nop
493
494invoke_utrap:
495 sllx %g3, 3, %g3
496 ldx [%g1 + %g3], %g1
497 save %sp, -128, %sp
498 rdpr %tstate, %l6
499 rdpr %cwp, %l7
500 andn %l6, TSTATE_CWP, %l6
501 wrpr %l6, %l7, %tstate
502 rdpr %tpc, %l6
503 rdpr %tnpc, %l7
504 wrpr %g1, 0, %tnpc
505 done
506
507 /* We need to carefully read the error status, ACK
508 * the errors, prevent recursive traps, and pass the
509 * information on to C code for logging.
510 *
511 * We pass the AFAR in as-is, and we encode the status
512 * information as described in asm-sparc64/sfafsr.h
513 */
514 .globl __spitfire_access_error
515__spitfire_access_error:
516 /* Disable ESTATE error reporting so that we do not
517 * take recursive traps and RED state the processor.
518 */
519 stxa %g0, [%g0] ASI_ESTATE_ERROR_EN
520 membar #Sync
521
522 mov UDBE_UE, %g1
523 ldxa [%g0] ASI_AFSR, %g4 ! Get AFSR
524
525 /* __spitfire_cee_trap branches here with AFSR in %g4 and
526 * UDBE_CE in %g1. It only clears ESTATE_ERR_CE in the
527 * ESTATE Error Enable register.
528 */
529__spitfire_cee_trap_continue:
530 ldxa [%g0] ASI_AFAR, %g5 ! Get AFAR
531
532 rdpr %tt, %g3
533 and %g3, 0x1ff, %g3 ! Paranoia
534 sllx %g3, SFSTAT_TRAP_TYPE_SHIFT, %g3
535 or %g4, %g3, %g4
536 rdpr %tl, %g3
537 cmp %g3, 1
538 mov 1, %g3
539 bleu %xcc, 1f
540 sllx %g3, SFSTAT_TL_GT_ONE_SHIFT, %g3
541
542 or %g4, %g3, %g4
543
544 /* Read in the UDB error register state, clearing the
545 * sticky error bits as-needed. We only clear them if
546 * the UE bit is set. Likewise, __spitfire_cee_trap
547 * below will only do so if the CE bit is set.
548 *
549 * NOTE: UltraSparc-I/II have high and low UDB error
550 * registers, corresponding to the two UDB units
551 * present on those chips. UltraSparc-IIi only
552 * has a single UDB, called "SDB" in the manual.
553 * For IIi the upper UDB register always reads
554 * as zero so for our purposes things will just
555 * work with the checks below.
556 */
5571: ldxa [%g0] ASI_UDBH_ERROR_R, %g3
558 and %g3, 0x3ff, %g7 ! Paranoia
559 sllx %g7, SFSTAT_UDBH_SHIFT, %g7
560 or %g4, %g7, %g4
561 andcc %g3, %g1, %g3 ! UDBE_UE or UDBE_CE
562 be,pn %xcc, 1f
563 nop
564 stxa %g3, [%g0] ASI_UDB_ERROR_W
565 membar #Sync
566
5671: mov 0x18, %g3
568 ldxa [%g3] ASI_UDBL_ERROR_R, %g3
569 and %g3, 0x3ff, %g7 ! Paranoia
570 sllx %g7, SFSTAT_UDBL_SHIFT, %g7
571 or %g4, %g7, %g4
572 andcc %g3, %g1, %g3 ! UDBE_UE or UDBE_CE
573 be,pn %xcc, 1f
574 nop
575 mov 0x18, %g7
576 stxa %g3, [%g7] ASI_UDB_ERROR_W
577 membar #Sync
578
5791: /* Ok, now that we've latched the error state,
580 * clear the sticky bits in the AFSR.
581 */
582 stxa %g4, [%g0] ASI_AFSR
583 membar #Sync
584
585 rdpr %tl, %g2
586 cmp %g2, 1
587 rdpr %pil, %g2
588 bleu,pt %xcc, 1f
589 wrpr %g0, 15, %pil
590
591 ba,pt %xcc, etraptl1
592 rd %pc, %g7
593
594 ba,pt %xcc, 2f
595 nop
596
5971: ba,pt %xcc, etrap_irq
598 rd %pc, %g7
599
6002:
601#ifdef CONFIG_TRACE_IRQFLAGS
602 call trace_hardirqs_off
603 nop
604#endif
605 mov %l4, %o1
606 mov %l5, %o2
607 call spitfire_access_error
608 add %sp, PTREGS_OFF, %o0
609 ba,pt %xcc, rtrap
610 nop
611
612 /* This is the trap handler entry point for ECC correctable
613 * errors. They are corrected, but we listen for the trap
614 * so that the event can be logged.
615 *
616 * Disrupting errors are either:
617 * 1) single-bit ECC errors during UDB reads to system
618 * memory
619 * 2) data parity errors during write-back events
620 *
621 * As far as I can make out from the manual, the CEE trap
622 * is only for correctable errors during memory read
623 * accesses by the front-end of the processor.
624 *
625 * The code below is only for trap level 1 CEE events,
626 * as it is the only situation where we can safely record
627 * and log. For trap level >1 we just clear the CE bit
628 * in the AFSR and return.
629 *
630 * This is just like __spiftire_access_error above, but it
631 * specifically handles correctable errors. If an
632 * uncorrectable error is indicated in the AFSR we
633 * will branch directly above to __spitfire_access_error
634 * to handle it instead. Uncorrectable therefore takes
635 * priority over correctable, and the error logging
636 * C code will notice this case by inspecting the
637 * trap type.
638 */
639 .globl __spitfire_cee_trap
640__spitfire_cee_trap:
641 ldxa [%g0] ASI_AFSR, %g4 ! Get AFSR
642 mov 1, %g3
643 sllx %g3, SFAFSR_UE_SHIFT, %g3
644 andcc %g4, %g3, %g0 ! Check for UE
645 bne,pn %xcc, __spitfire_access_error
646 nop
647
648 /* Ok, in this case we only have a correctable error.
649 * Indicate we only wish to capture that state in register
650 * %g1, and we only disable CE error reporting unlike UE
651 * handling which disables all errors.
652 */
653 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g3
654 andn %g3, ESTATE_ERR_CE, %g3
655 stxa %g3, [%g0] ASI_ESTATE_ERROR_EN
656 membar #Sync
657
658 /* Preserve AFSR in %g4, indicate UDB state to capture in %g1 */
659 ba,pt %xcc, __spitfire_cee_trap_continue
660 mov UDBE_CE, %g1
661
662 .globl __spitfire_data_access_exception
663 .globl __spitfire_data_access_exception_tl1
664__spitfire_data_access_exception_tl1:
665 rdpr %pstate, %g4
666 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
667 mov TLB_SFSR, %g3
668 mov DMMU_SFAR, %g5
669 ldxa [%g3] ASI_DMMU, %g4 ! Get SFSR
670 ldxa [%g5] ASI_DMMU, %g5 ! Get SFAR
671 stxa %g0, [%g3] ASI_DMMU ! Clear SFSR.FaultValid bit
672 membar #Sync
673 rdpr %tt, %g3
674 cmp %g3, 0x80 ! first win spill/fill trap
675 blu,pn %xcc, 1f
676 cmp %g3, 0xff ! last win spill/fill trap
677 bgu,pn %xcc, 1f
678 nop
679 ba,pt %xcc, winfix_dax
680 rdpr %tpc, %g3
6811: sethi %hi(109f), %g7
682 ba,pt %xcc, etraptl1
683109: or %g7, %lo(109b), %g7
684 mov %l4, %o1
685 mov %l5, %o2
686 call spitfire_data_access_exception_tl1
687 add %sp, PTREGS_OFF, %o0
688 ba,pt %xcc, rtrap
689 nop
690
691__spitfire_data_access_exception:
692 rdpr %pstate, %g4
693 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
694 mov TLB_SFSR, %g3
695 mov DMMU_SFAR, %g5
696 ldxa [%g3] ASI_DMMU, %g4 ! Get SFSR
697 ldxa [%g5] ASI_DMMU, %g5 ! Get SFAR
698 stxa %g0, [%g3] ASI_DMMU ! Clear SFSR.FaultValid bit
699 membar #Sync
700 sethi %hi(109f), %g7
701 ba,pt %xcc, etrap
702109: or %g7, %lo(109b), %g7
703 mov %l4, %o1
704 mov %l5, %o2
705 call spitfire_data_access_exception
706 add %sp, PTREGS_OFF, %o0
707 ba,pt %xcc, rtrap
708 nop
709
710 .globl __spitfire_insn_access_exception
711 .globl __spitfire_insn_access_exception_tl1
712__spitfire_insn_access_exception_tl1:
713 rdpr %pstate, %g4
714 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
715 mov TLB_SFSR, %g3
716 ldxa [%g3] ASI_IMMU, %g4 ! Get SFSR
717 rdpr %tpc, %g5 ! IMMU has no SFAR, use TPC
718 stxa %g0, [%g3] ASI_IMMU ! Clear FaultValid bit
719 membar #Sync
720 sethi %hi(109f), %g7
721 ba,pt %xcc, etraptl1
722109: or %g7, %lo(109b), %g7
723 mov %l4, %o1
724 mov %l5, %o2
725 call spitfire_insn_access_exception_tl1
726 add %sp, PTREGS_OFF, %o0
727 ba,pt %xcc, rtrap
728 nop
729
730__spitfire_insn_access_exception:
731 rdpr %pstate, %g4
732 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
733 mov TLB_SFSR, %g3
734 ldxa [%g3] ASI_IMMU, %g4 ! Get SFSR
735 rdpr %tpc, %g5 ! IMMU has no SFAR, use TPC
736 stxa %g0, [%g3] ASI_IMMU ! Clear FaultValid bit
737 membar #Sync
738 sethi %hi(109f), %g7
739 ba,pt %xcc, etrap
740109: or %g7, %lo(109b), %g7
741 mov %l4, %o1
742 mov %l5, %o2
743 call spitfire_insn_access_exception
744 add %sp, PTREGS_OFF, %o0
745 ba,pt %xcc, rtrap
746 nop
747
748 /* These get patched into the trap table at boot time
749 * once we know we have a cheetah processor.
750 */
751 .globl cheetah_fecc_trap_vector, cheetah_fecc_trap_vector_tl1
752cheetah_fecc_trap_vector:
753 membar #Sync
754 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
755 andn %g1, DCU_DC | DCU_IC, %g1
756 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
757 membar #Sync
758 sethi %hi(cheetah_fast_ecc), %g2
759 jmpl %g2 + %lo(cheetah_fast_ecc), %g0
760 mov 0, %g1
761cheetah_fecc_trap_vector_tl1:
762 membar #Sync
763 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
764 andn %g1, DCU_DC | DCU_IC, %g1
765 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
766 membar #Sync
767 sethi %hi(cheetah_fast_ecc), %g2
768 jmpl %g2 + %lo(cheetah_fast_ecc), %g0
769 mov 1, %g1
770 .globl cheetah_cee_trap_vector, cheetah_cee_trap_vector_tl1
771cheetah_cee_trap_vector:
772 membar #Sync
773 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
774 andn %g1, DCU_IC, %g1
775 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
776 membar #Sync
777 sethi %hi(cheetah_cee), %g2
778 jmpl %g2 + %lo(cheetah_cee), %g0
779 mov 0, %g1
780cheetah_cee_trap_vector_tl1:
781 membar #Sync
782 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
783 andn %g1, DCU_IC, %g1
784 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
785 membar #Sync
786 sethi %hi(cheetah_cee), %g2
787 jmpl %g2 + %lo(cheetah_cee), %g0
788 mov 1, %g1
789 .globl cheetah_deferred_trap_vector, cheetah_deferred_trap_vector_tl1
790cheetah_deferred_trap_vector:
791 membar #Sync
792 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1;
793 andn %g1, DCU_DC | DCU_IC, %g1;
794 stxa %g1, [%g0] ASI_DCU_CONTROL_REG;
795 membar #Sync;
796 sethi %hi(cheetah_deferred_trap), %g2
797 jmpl %g2 + %lo(cheetah_deferred_trap), %g0
798 mov 0, %g1
799cheetah_deferred_trap_vector_tl1:
800 membar #Sync;
801 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1;
802 andn %g1, DCU_DC | DCU_IC, %g1;
803 stxa %g1, [%g0] ASI_DCU_CONTROL_REG;
804 membar #Sync;
805 sethi %hi(cheetah_deferred_trap), %g2
806 jmpl %g2 + %lo(cheetah_deferred_trap), %g0
807 mov 1, %g1
808
809 /* Cheetah+ specific traps. These are for the new I/D cache parity
810 * error traps. The first argument to cheetah_plus_parity_handler
811 * is encoded as follows:
812 *
813 * Bit0: 0=dcache,1=icache
814 * Bit1: 0=recoverable,1=unrecoverable
815 */
816 .globl cheetah_plus_dcpe_trap_vector, cheetah_plus_dcpe_trap_vector_tl1
817cheetah_plus_dcpe_trap_vector:
818 membar #Sync
819 sethi %hi(do_cheetah_plus_data_parity), %g7
820 jmpl %g7 + %lo(do_cheetah_plus_data_parity), %g0
821 nop
822 nop
823 nop
824 nop
825 nop
826
827do_cheetah_plus_data_parity:
828 rdpr %pil, %g2
829 wrpr %g0, 15, %pil
830 ba,pt %xcc, etrap_irq
831 rd %pc, %g7
832#ifdef CONFIG_TRACE_IRQFLAGS
833 call trace_hardirqs_off
834 nop
835#endif
836 mov 0x0, %o0
837 call cheetah_plus_parity_error
838 add %sp, PTREGS_OFF, %o1
839 ba,a,pt %xcc, rtrap_irq
840
841cheetah_plus_dcpe_trap_vector_tl1:
842 membar #Sync
843 wrpr PSTATE_IG | PSTATE_PEF | PSTATE_PRIV, %pstate
844 sethi %hi(do_dcpe_tl1), %g3
845 jmpl %g3 + %lo(do_dcpe_tl1), %g0
846 nop
847 nop
848 nop
849 nop
850
851 .globl cheetah_plus_icpe_trap_vector, cheetah_plus_icpe_trap_vector_tl1
852cheetah_plus_icpe_trap_vector:
853 membar #Sync
854 sethi %hi(do_cheetah_plus_insn_parity), %g7
855 jmpl %g7 + %lo(do_cheetah_plus_insn_parity), %g0
856 nop
857 nop
858 nop
859 nop
860 nop
861
862do_cheetah_plus_insn_parity:
863 rdpr %pil, %g2
864 wrpr %g0, 15, %pil
865 ba,pt %xcc, etrap_irq
866 rd %pc, %g7
867#ifdef CONFIG_TRACE_IRQFLAGS
868 call trace_hardirqs_off
869 nop
870#endif
871 mov 0x1, %o0
872 call cheetah_plus_parity_error
873 add %sp, PTREGS_OFF, %o1
874 ba,a,pt %xcc, rtrap_irq
875
876cheetah_plus_icpe_trap_vector_tl1:
877 membar #Sync
878 wrpr PSTATE_IG | PSTATE_PEF | PSTATE_PRIV, %pstate
879 sethi %hi(do_icpe_tl1), %g3
880 jmpl %g3 + %lo(do_icpe_tl1), %g0
881 nop
882 nop
883 nop
884 nop
885
886 /* If we take one of these traps when tl >= 1, then we
887 * jump to interrupt globals. If some trap level above us
888 * was also using interrupt globals, we cannot recover.
889 * We may use all interrupt global registers except %g6.
890 */
891 .globl do_dcpe_tl1, do_icpe_tl1
892do_dcpe_tl1:
893 rdpr %tl, %g1 ! Save original trap level
894 mov 1, %g2 ! Setup TSTATE checking loop
895 sethi %hi(TSTATE_IG), %g3 ! TSTATE mask bit
8961: wrpr %g2, %tl ! Set trap level to check
897 rdpr %tstate, %g4 ! Read TSTATE for this level
898 andcc %g4, %g3, %g0 ! Interrupt globals in use?
899 bne,a,pn %xcc, do_dcpe_tl1_fatal ! Yep, irrecoverable
900 wrpr %g1, %tl ! Restore original trap level
901 add %g2, 1, %g2 ! Next trap level
902 cmp %g2, %g1 ! Hit them all yet?
903 ble,pt %icc, 1b ! Not yet
904 nop
905 wrpr %g1, %tl ! Restore original trap level
906do_dcpe_tl1_nonfatal: /* Ok we may use interrupt globals safely. */
907 sethi %hi(dcache_parity_tl1_occurred), %g2
908 lduw [%g2 + %lo(dcache_parity_tl1_occurred)], %g1
909 add %g1, 1, %g1
910 stw %g1, [%g2 + %lo(dcache_parity_tl1_occurred)]
911 /* Reset D-cache parity */
912 sethi %hi(1 << 16), %g1 ! D-cache size
913 mov (1 << 5), %g2 ! D-cache line size
914 sub %g1, %g2, %g1 ! Move down 1 cacheline
9151: srl %g1, 14, %g3 ! Compute UTAG
916 membar #Sync
917 stxa %g3, [%g1] ASI_DCACHE_UTAG
918 membar #Sync
919 sub %g2, 8, %g3 ! 64-bit data word within line
9202: membar #Sync
921 stxa %g0, [%g1 + %g3] ASI_DCACHE_DATA
922 membar #Sync
923 subcc %g3, 8, %g3 ! Next 64-bit data word
924 bge,pt %icc, 2b
925 nop
926 subcc %g1, %g2, %g1 ! Next cacheline
927 bge,pt %icc, 1b
928 nop
929 ba,pt %xcc, dcpe_icpe_tl1_common
930 nop
931
932do_dcpe_tl1_fatal:
933 sethi %hi(1f), %g7
934 ba,pt %xcc, etraptl1
9351: or %g7, %lo(1b), %g7
936 mov 0x2, %o0
937 call cheetah_plus_parity_error
938 add %sp, PTREGS_OFF, %o1
939 ba,pt %xcc, rtrap
940 nop
941
942do_icpe_tl1:
943 rdpr %tl, %g1 ! Save original trap level
944 mov 1, %g2 ! Setup TSTATE checking loop
945 sethi %hi(TSTATE_IG), %g3 ! TSTATE mask bit
9461: wrpr %g2, %tl ! Set trap level to check
947 rdpr %tstate, %g4 ! Read TSTATE for this level
948 andcc %g4, %g3, %g0 ! Interrupt globals in use?
949 bne,a,pn %xcc, do_icpe_tl1_fatal ! Yep, irrecoverable
950 wrpr %g1, %tl ! Restore original trap level
951 add %g2, 1, %g2 ! Next trap level
952 cmp %g2, %g1 ! Hit them all yet?
953 ble,pt %icc, 1b ! Not yet
954 nop
955 wrpr %g1, %tl ! Restore original trap level
956do_icpe_tl1_nonfatal: /* Ok we may use interrupt globals safely. */
957 sethi %hi(icache_parity_tl1_occurred), %g2
958 lduw [%g2 + %lo(icache_parity_tl1_occurred)], %g1
959 add %g1, 1, %g1
960 stw %g1, [%g2 + %lo(icache_parity_tl1_occurred)]
961 /* Flush I-cache */
962 sethi %hi(1 << 15), %g1 ! I-cache size
963 mov (1 << 5), %g2 ! I-cache line size
964 sub %g1, %g2, %g1
9651: or %g1, (2 << 3), %g3
966 stxa %g0, [%g3] ASI_IC_TAG
967 membar #Sync
968 subcc %g1, %g2, %g1
969 bge,pt %icc, 1b
970 nop
971 ba,pt %xcc, dcpe_icpe_tl1_common
972 nop
973
974do_icpe_tl1_fatal:
975 sethi %hi(1f), %g7
976 ba,pt %xcc, etraptl1
9771: or %g7, %lo(1b), %g7
978 mov 0x3, %o0
979 call cheetah_plus_parity_error
980 add %sp, PTREGS_OFF, %o1
981 ba,pt %xcc, rtrap
982 nop
983
984dcpe_icpe_tl1_common:
985 /* Flush D-cache, re-enable D/I caches in DCU and finally
986 * retry the trapping instruction.
987 */
988 sethi %hi(1 << 16), %g1 ! D-cache size
989 mov (1 << 5), %g2 ! D-cache line size
990 sub %g1, %g2, %g1
9911: stxa %g0, [%g1] ASI_DCACHE_TAG
992 membar #Sync
993 subcc %g1, %g2, %g1
994 bge,pt %icc, 1b
995 nop
996 ldxa [%g0] ASI_DCU_CONTROL_REG, %g1
997 or %g1, (DCU_DC | DCU_IC), %g1
998 stxa %g1, [%g0] ASI_DCU_CONTROL_REG
999 membar #Sync
1000 retry
1001
1002 /* Capture I/D/E-cache state into per-cpu error scoreboard.
1003 *
1004 * %g1: (TL>=0) ? 1 : 0
1005 * %g2: scratch
1006 * %g3: scratch
1007 * %g4: AFSR
1008 * %g5: AFAR
1009 * %g6: unused, will have current thread ptr after etrap
1010 * %g7: scratch
1011 */
1012__cheetah_log_error:
1013 /* Put "TL1" software bit into AFSR. */
1014 and %g1, 0x1, %g1
1015 sllx %g1, 63, %g2
1016 or %g4, %g2, %g4
1017
1018 /* Get log entry pointer for this cpu at this trap level. */
1019 BRANCH_IF_JALAPENO(g2,g3,50f)
1020 ldxa [%g0] ASI_SAFARI_CONFIG, %g2
1021 srlx %g2, 17, %g2
1022 ba,pt %xcc, 60f
1023 and %g2, 0x3ff, %g2
1024
102550: ldxa [%g0] ASI_JBUS_CONFIG, %g2
1026 srlx %g2, 17, %g2
1027 and %g2, 0x1f, %g2
1028
102960: sllx %g2, 9, %g2
1030 sethi %hi(cheetah_error_log), %g3
1031 ldx [%g3 + %lo(cheetah_error_log)], %g3
1032 brz,pn %g3, 80f
1033 nop
1034
1035 add %g3, %g2, %g3
1036 sllx %g1, 8, %g1
1037 add %g3, %g1, %g1
1038
1039 /* %g1 holds pointer to the top of the logging scoreboard */
1040 ldx [%g1 + 0x0], %g7
1041 cmp %g7, -1
1042 bne,pn %xcc, 80f
1043 nop
1044
1045 stx %g4, [%g1 + 0x0]
1046 stx %g5, [%g1 + 0x8]
1047 add %g1, 0x10, %g1
1048
1049 /* %g1 now points to D-cache logging area */
1050 set 0x3ff8, %g2 /* DC_addr mask */
1051 and %g5, %g2, %g2 /* DC_addr bits of AFAR */
1052 srlx %g5, 12, %g3
1053 or %g3, 1, %g3 /* PHYS tag + valid */
1054
105510: ldxa [%g2] ASI_DCACHE_TAG, %g7
1056 cmp %g3, %g7 /* TAG match? */
1057 bne,pt %xcc, 13f
1058 nop
1059
1060 /* Yep, what we want, capture state. */
1061 stx %g2, [%g1 + 0x20]
1062 stx %g7, [%g1 + 0x28]
1063
1064 /* A membar Sync is required before and after utag access. */
1065 membar #Sync
1066 ldxa [%g2] ASI_DCACHE_UTAG, %g7
1067 membar #Sync
1068 stx %g7, [%g1 + 0x30]
1069 ldxa [%g2] ASI_DCACHE_SNOOP_TAG, %g7
1070 stx %g7, [%g1 + 0x38]
1071 clr %g3
1072
107312: ldxa [%g2 + %g3] ASI_DCACHE_DATA, %g7
1074 stx %g7, [%g1]
1075 add %g3, (1 << 5), %g3
1076 cmp %g3, (4 << 5)
1077 bl,pt %xcc, 12b
1078 add %g1, 0x8, %g1
1079
1080 ba,pt %xcc, 20f
1081 add %g1, 0x20, %g1
1082
108313: sethi %hi(1 << 14), %g7
1084 add %g2, %g7, %g2
1085 srlx %g2, 14, %g7
1086 cmp %g7, 4
1087 bl,pt %xcc, 10b
1088 nop
1089
1090 add %g1, 0x40, %g1
1091
1092 /* %g1 now points to I-cache logging area */
109320: set 0x1fe0, %g2 /* IC_addr mask */
1094 and %g5, %g2, %g2 /* IC_addr bits of AFAR */
1095 sllx %g2, 1, %g2 /* IC_addr[13:6]==VA[12:5] */
1096 srlx %g5, (13 - 8), %g3 /* Make PTAG */
1097 andn %g3, 0xff, %g3 /* Mask off undefined bits */
1098
109921: ldxa [%g2] ASI_IC_TAG, %g7
1100 andn %g7, 0xff, %g7
1101 cmp %g3, %g7
1102 bne,pt %xcc, 23f
1103 nop
1104
1105 /* Yep, what we want, capture state. */
1106 stx %g2, [%g1 + 0x40]
1107 stx %g7, [%g1 + 0x48]
1108 add %g2, (1 << 3), %g2
1109 ldxa [%g2] ASI_IC_TAG, %g7
1110 add %g2, (1 << 3), %g2
1111 stx %g7, [%g1 + 0x50]
1112 ldxa [%g2] ASI_IC_TAG, %g7
1113 add %g2, (1 << 3), %g2
1114 stx %g7, [%g1 + 0x60]
1115 ldxa [%g2] ASI_IC_TAG, %g7
1116 stx %g7, [%g1 + 0x68]
1117 sub %g2, (3 << 3), %g2
1118 ldxa [%g2] ASI_IC_STAG, %g7
1119 stx %g7, [%g1 + 0x58]
1120 clr %g3
1121 srlx %g2, 2, %g2
1122
112322: ldxa [%g2 + %g3] ASI_IC_INSTR, %g7
1124 stx %g7, [%g1]
1125 add %g3, (1 << 3), %g3
1126 cmp %g3, (8 << 3)
1127 bl,pt %xcc, 22b
1128 add %g1, 0x8, %g1
1129
1130 ba,pt %xcc, 30f
1131 add %g1, 0x30, %g1
1132
113323: sethi %hi(1 << 14), %g7
1134 add %g2, %g7, %g2
1135 srlx %g2, 14, %g7
1136 cmp %g7, 4
1137 bl,pt %xcc, 21b
1138 nop
1139
1140 add %g1, 0x70, %g1
1141
1142 /* %g1 now points to E-cache logging area */
114330: andn %g5, (32 - 1), %g2
1144 stx %g2, [%g1 + 0x20]
1145 ldxa [%g2] ASI_EC_TAG_DATA, %g7
1146 stx %g7, [%g1 + 0x28]
1147 ldxa [%g2] ASI_EC_R, %g0
1148 clr %g3
1149
115031: ldxa [%g3] ASI_EC_DATA, %g7
1151 stx %g7, [%g1 + %g3]
1152 add %g3, 0x8, %g3
1153 cmp %g3, 0x20
1154
1155 bl,pt %xcc, 31b
1156 nop
115780:
1158 rdpr %tt, %g2
1159 cmp %g2, 0x70
1160 be c_fast_ecc
1161 cmp %g2, 0x63
1162 be c_cee
1163 nop
1164 ba,pt %xcc, c_deferred
1165
1166 /* Cheetah FECC trap handling, we get here from tl{0,1}_fecc
1167 * in the trap table. That code has done a memory barrier
1168 * and has disabled both the I-cache and D-cache in the DCU
1169 * control register. The I-cache is disabled so that we may
1170 * capture the corrupted cache line, and the D-cache is disabled
1171 * because corrupt data may have been placed there and we don't
1172 * want to reference it.
1173 *
1174 * %g1 is one if this trap occurred at %tl >= 1.
1175 *
1176 * Next, we turn off error reporting so that we don't recurse.
1177 */
1178 .globl cheetah_fast_ecc
1179cheetah_fast_ecc:
1180 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
1181 andn %g2, ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN, %g2
1182 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
1183 membar #Sync
1184
1185 /* Fetch and clear AFSR/AFAR */
1186 ldxa [%g0] ASI_AFSR, %g4
1187 ldxa [%g0] ASI_AFAR, %g5
1188 stxa %g4, [%g0] ASI_AFSR
1189 membar #Sync
1190
1191 ba,pt %xcc, __cheetah_log_error
1192 nop
1193
1194c_fast_ecc:
1195 rdpr %pil, %g2
1196 wrpr %g0, 15, %pil
1197 ba,pt %xcc, etrap_irq
1198 rd %pc, %g7
1199#ifdef CONFIG_TRACE_IRQFLAGS
1200 call trace_hardirqs_off
1201 nop
1202#endif
1203 mov %l4, %o1
1204 mov %l5, %o2
1205 call cheetah_fecc_handler
1206 add %sp, PTREGS_OFF, %o0
1207 ba,a,pt %xcc, rtrap_irq
1208
1209 /* Our caller has disabled I-cache and performed membar Sync. */
1210 .globl cheetah_cee
1211cheetah_cee:
1212 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
1213 andn %g2, ESTATE_ERROR_CEEN, %g2
1214 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
1215 membar #Sync
1216
1217 /* Fetch and clear AFSR/AFAR */
1218 ldxa [%g0] ASI_AFSR, %g4
1219 ldxa [%g0] ASI_AFAR, %g5
1220 stxa %g4, [%g0] ASI_AFSR
1221 membar #Sync
1222
1223 ba,pt %xcc, __cheetah_log_error
1224 nop
1225
1226c_cee:
1227 rdpr %pil, %g2
1228 wrpr %g0, 15, %pil
1229 ba,pt %xcc, etrap_irq
1230 rd %pc, %g7
1231#ifdef CONFIG_TRACE_IRQFLAGS
1232 call trace_hardirqs_off
1233 nop
1234#endif
1235 mov %l4, %o1
1236 mov %l5, %o2
1237 call cheetah_cee_handler
1238 add %sp, PTREGS_OFF, %o0
1239 ba,a,pt %xcc, rtrap_irq
1240
1241 /* Our caller has disabled I-cache+D-cache and performed membar Sync. */
1242 .globl cheetah_deferred_trap
1243cheetah_deferred_trap:
1244 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g2
1245 andn %g2, ESTATE_ERROR_NCEEN | ESTATE_ERROR_CEEN, %g2
1246 stxa %g2, [%g0] ASI_ESTATE_ERROR_EN
1247 membar #Sync
1248
1249 /* Fetch and clear AFSR/AFAR */
1250 ldxa [%g0] ASI_AFSR, %g4
1251 ldxa [%g0] ASI_AFAR, %g5
1252 stxa %g4, [%g0] ASI_AFSR
1253 membar #Sync
1254
1255 ba,pt %xcc, __cheetah_log_error
1256 nop
1257
1258c_deferred:
1259 rdpr %pil, %g2
1260 wrpr %g0, 15, %pil
1261 ba,pt %xcc, etrap_irq
1262 rd %pc, %g7
1263#ifdef CONFIG_TRACE_IRQFLAGS
1264 call trace_hardirqs_off
1265 nop
1266#endif
1267 mov %l4, %o1
1268 mov %l5, %o2
1269 call cheetah_deferred_handler
1270 add %sp, PTREGS_OFF, %o0
1271 ba,a,pt %xcc, rtrap_irq
1272
1273 .globl __do_privact
1274__do_privact:
1275 mov TLB_SFSR, %g3
1276 stxa %g0, [%g3] ASI_DMMU ! Clear FaultValid bit
1277 membar #Sync
1278 sethi %hi(109f), %g7
1279 ba,pt %xcc, etrap
1280109: or %g7, %lo(109b), %g7
1281 call do_privact
1282 add %sp, PTREGS_OFF, %o0
1283 ba,pt %xcc, rtrap
1284 nop
1285
1286 .globl do_mna
1287do_mna:
1288 rdpr %tl, %g3
1289 cmp %g3, 1
1290
1291 /* Setup %g4/%g5 now as they are used in the
1292 * winfixup code.
1293 */
1294 mov TLB_SFSR, %g3
1295 mov DMMU_SFAR, %g4
1296 ldxa [%g4] ASI_DMMU, %g4
1297 ldxa [%g3] ASI_DMMU, %g5
1298 stxa %g0, [%g3] ASI_DMMU ! Clear FaultValid bit
1299 membar #Sync
1300 bgu,pn %icc, winfix_mna
1301 rdpr %tpc, %g3
1302
13031: sethi %hi(109f), %g7
1304 ba,pt %xcc, etrap
1305109: or %g7, %lo(109b), %g7
1306 mov %l4, %o1
1307 mov %l5, %o2
1308 call mem_address_unaligned
1309 add %sp, PTREGS_OFF, %o0
1310 ba,pt %xcc, rtrap
1311 nop
1312
1313 .globl do_lddfmna
1314do_lddfmna:
1315 sethi %hi(109f), %g7
1316 mov TLB_SFSR, %g4
1317 ldxa [%g4] ASI_DMMU, %g5
1318 stxa %g0, [%g4] ASI_DMMU ! Clear FaultValid bit
1319 membar #Sync
1320 mov DMMU_SFAR, %g4
1321 ldxa [%g4] ASI_DMMU, %g4
1322 ba,pt %xcc, etrap
1323109: or %g7, %lo(109b), %g7
1324 mov %l4, %o1
1325 mov %l5, %o2
1326 call handle_lddfmna
1327 add %sp, PTREGS_OFF, %o0
1328 ba,pt %xcc, rtrap
1329 nop
1330
1331 .globl do_stdfmna
1332do_stdfmna:
1333 sethi %hi(109f), %g7
1334 mov TLB_SFSR, %g4
1335 ldxa [%g4] ASI_DMMU, %g5
1336 stxa %g0, [%g4] ASI_DMMU ! Clear FaultValid bit
1337 membar #Sync
1338 mov DMMU_SFAR, %g4
1339 ldxa [%g4] ASI_DMMU, %g4
1340 ba,pt %xcc, etrap
1341109: or %g7, %lo(109b), %g7
1342 mov %l4, %o1
1343 mov %l5, %o2
1344 call handle_stdfmna
1345 add %sp, PTREGS_OFF, %o0
1346 ba,pt %xcc, rtrap
1347 nop
1348
1349 .globl breakpoint_trap
1350breakpoint_trap:
1351 call sparc_breakpoint
1352 add %sp, PTREGS_OFF, %o0
1353 ba,pt %xcc, rtrap
1354 nop
1355
1356 /* SunOS's execv() call only specifies the argv argument, the
1357 * environment settings are the same as the calling processes.
1358 */
1359 .globl sunos_execv
1360sys_execve:
1361 sethi %hi(sparc_execve), %g1
1362 ba,pt %xcc, execve_merge
1363 or %g1, %lo(sparc_execve), %g1
1364#ifdef CONFIG_COMPAT
1365 .globl sys_execve
1366sunos_execv:
1367 stx %g0, [%sp + PTREGS_OFF + PT_V9_I2]
1368 .globl sys32_execve
1369sys32_execve:
1370 sethi %hi(sparc32_execve), %g1
1371 or %g1, %lo(sparc32_execve), %g1
1372#endif
1373execve_merge:
1374 flushw
1375 jmpl %g1, %g0
1376 add %sp, PTREGS_OFF, %o0
1377
1378 .globl sys_pipe, sys_sigpause, sys_nis_syscall
1379 .globl sys_rt_sigreturn
1380 .globl sys_ptrace
1381 .globl sys_sigaltstack
1382 .align 32
1383sys_pipe: ba,pt %xcc, sparc_pipe
1384 add %sp, PTREGS_OFF, %o0
1385sys_nis_syscall:ba,pt %xcc, c_sys_nis_syscall
1386 add %sp, PTREGS_OFF, %o0
1387sys_memory_ordering:
1388 ba,pt %xcc, sparc_memory_ordering
1389 add %sp, PTREGS_OFF, %o1
1390sys_sigaltstack:ba,pt %xcc, do_sigaltstack
1391 add %i6, STACK_BIAS, %o2
1392#ifdef CONFIG_COMPAT
1393 .globl sys32_sigstack
1394sys32_sigstack: ba,pt %xcc, do_sys32_sigstack
1395 mov %i6, %o2
1396 .globl sys32_sigaltstack
1397sys32_sigaltstack:
1398 ba,pt %xcc, do_sys32_sigaltstack
1399 mov %i6, %o2
1400#endif
1401 .align 32
1402#ifdef CONFIG_COMPAT
1403 .globl sys32_sigreturn
1404sys32_sigreturn:
1405 add %sp, PTREGS_OFF, %o0
1406 call do_sigreturn32
1407 add %o7, 1f-.-4, %o7
1408 nop
1409#endif
1410sys_rt_sigreturn:
1411 add %sp, PTREGS_OFF, %o0
1412 call do_rt_sigreturn
1413 add %o7, 1f-.-4, %o7
1414 nop
1415#ifdef CONFIG_COMPAT
1416 .globl sys32_rt_sigreturn
1417sys32_rt_sigreturn:
1418 add %sp, PTREGS_OFF, %o0
1419 call do_rt_sigreturn32
1420 add %o7, 1f-.-4, %o7
1421 nop
1422#endif
1423 .align 32
14241: ldx [%curptr + TI_FLAGS], %l5
1425 andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
1426 be,pt %icc, rtrap
1427 nop
1428 add %sp, PTREGS_OFF, %o0
1429 call syscall_trace
1430 mov 1, %o1
1431
1432 ba,pt %xcc, rtrap
1433 nop
1434
1435 /* This is how fork() was meant to be done, 8 instruction entry.
1436 *
1437 * I questioned the following code briefly, let me clear things
1438 * up so you must not reason on it like I did.
1439 *
1440 * Know the fork_kpsr etc. we use in the sparc32 port? We don't
1441 * need it here because the only piece of window state we copy to
1442 * the child is the CWP register. Even if the parent sleeps,
1443 * we are safe because we stuck it into pt_regs of the parent
1444 * so it will not change.
1445 *
1446 * XXX This raises the question, whether we can do the same on
1447 * XXX sparc32 to get rid of fork_kpsr _and_ fork_kwim. The
1448 * XXX answer is yes. We stick fork_kpsr in UREG_G0 and
1449 * XXX fork_kwim in UREG_G1 (global registers are considered
1450 * XXX volatile across a system call in the sparc ABI I think
1451 * XXX if it isn't we can use regs->y instead, anyone who depends
1452 * XXX upon the Y register being preserved across a fork deserves
1453 * XXX to lose).
1454 *
1455 * In fact we should take advantage of that fact for other things
1456 * during system calls...
1457 */
1458 .globl sys_fork, sys_vfork, sys_clone, sparc_exit
1459 .globl ret_from_syscall
1460 .align 32
1461sys_vfork: /* Under Linux, vfork and fork are just special cases of clone. */
1462 sethi %hi(0x4000 | 0x0100 | SIGCHLD), %o0
1463 or %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
1464 ba,pt %xcc, sys_clone
1465sys_fork: clr %o1
1466 mov SIGCHLD, %o0
1467sys_clone: flushw
1468 movrz %o1, %fp, %o1
1469 mov 0, %o3
1470 ba,pt %xcc, sparc_do_fork
1471 add %sp, PTREGS_OFF, %o2
1472ret_from_syscall:
1473 /* Clear current_thread_info()->new_child, and
1474 * check performance counter stuff too.
1475 */
1476 stb %g0, [%g6 + TI_NEW_CHILD]
1477 ldx [%g6 + TI_FLAGS], %l0
1478 call schedule_tail
1479 mov %g7, %o0
1480 andcc %l0, _TIF_PERFCTR, %g0
1481 be,pt %icc, 1f
1482 nop
1483 ldx [%g6 + TI_PCR], %o7
1484 wr %g0, %o7, %pcr
1485
1486 /* Blackbird errata workaround. See commentary in
1487 * smp.c:smp_percpu_timer_interrupt() for more
1488 * information.
1489 */
1490 ba,pt %xcc, 99f
1491 nop
1492 .align 64
149399: wr %g0, %g0, %pic
1494 rd %pic, %g0
1495
14961: b,pt %xcc, ret_sys_call
1497 ldx [%sp + PTREGS_OFF + PT_V9_I0], %o0
1498sparc_exit: rdpr %pstate, %g2
1499 wrpr %g2, PSTATE_IE, %pstate
1500 rdpr %otherwin, %g1
1501 rdpr %cansave, %g3
1502 add %g3, %g1, %g3
1503 wrpr %g3, 0x0, %cansave
1504 wrpr %g0, 0x0, %otherwin
1505 wrpr %g2, 0x0, %pstate
1506 ba,pt %xcc, sys_exit
1507 stb %g0, [%g6 + TI_WSAVED]
1508
1509linux_sparc_ni_syscall:
1510 sethi %hi(sys_ni_syscall), %l7
1511 b,pt %xcc, 4f
1512 or %l7, %lo(sys_ni_syscall), %l7
1513
1514linux_syscall_trace32:
1515 add %sp, PTREGS_OFF, %o0
1516 call syscall_trace
1517 clr %o1
1518 srl %i0, 0, %o0
1519 srl %i4, 0, %o4
1520 srl %i1, 0, %o1
1521 srl %i2, 0, %o2
1522 b,pt %xcc, 2f
1523 srl %i3, 0, %o3
1524
1525linux_syscall_trace:
1526 add %sp, PTREGS_OFF, %o0
1527 call syscall_trace
1528 clr %o1
1529 mov %i0, %o0
1530 mov %i1, %o1
1531 mov %i2, %o2
1532 mov %i3, %o3
1533 b,pt %xcc, 2f
1534 mov %i4, %o4
1535
1536
1537 /* Linux 32-bit system calls enter here... */
1538 .align 32
1539 .globl linux_sparc_syscall32
1540linux_sparc_syscall32:
1541 /* Direct access to user regs, much faster. */
1542 cmp %g1, NR_SYSCALLS ! IEU1 Group
1543 bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
1544 srl %i0, 0, %o0 ! IEU0
1545 sll %g1, 2, %l4 ! IEU0 Group
1546 srl %i4, 0, %o4 ! IEU1
1547 lduw [%l7 + %l4], %l7 ! Load
1548 srl %i1, 0, %o1 ! IEU0 Group
1549 ldx [%curptr + TI_FLAGS], %l0 ! Load
1550
1551 srl %i5, 0, %o5 ! IEU1
1552 srl %i2, 0, %o2 ! IEU0 Group
1553 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
1554 bne,pn %icc, linux_syscall_trace32 ! CTI
1555 mov %i0, %l5 ! IEU1
1556 call %l7 ! CTI Group brk forced
1557 srl %i3, 0, %o3 ! IEU0
1558 ba,a,pt %xcc, 3f
1559
1560 /* Linux native system calls enter here... */
1561 .align 32
1562 .globl linux_sparc_syscall
1563linux_sparc_syscall:
1564 /* Direct access to user regs, much faster. */
1565 cmp %g1, NR_SYSCALLS ! IEU1 Group
1566 bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
1567 mov %i0, %o0 ! IEU0
1568 sll %g1, 2, %l4 ! IEU0 Group
1569 mov %i1, %o1 ! IEU1
1570 lduw [%l7 + %l4], %l7 ! Load
15714: mov %i2, %o2 ! IEU0 Group
1572 ldx [%curptr + TI_FLAGS], %l0 ! Load
1573
1574 mov %i3, %o3 ! IEU1
1575 mov %i4, %o4 ! IEU0 Group
1576 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
1577 bne,pn %icc, linux_syscall_trace ! CTI Group
1578 mov %i0, %l5 ! IEU0
15792: call %l7 ! CTI Group brk forced
1580 mov %i5, %o5 ! IEU0
1581 nop
1582
15833: stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1584ret_sys_call:
1585 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
1586 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
1587 sra %o0, 0, %o0
1588 mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
1589 sllx %g2, 32, %g2
1590
1591 /* Check if force_successful_syscall_return()
1592 * was invoked.
1593 */
1594 ldub [%curptr + TI_SYS_NOERROR], %l2
1595 brnz,a,pn %l2, 80f
1596 stb %g0, [%curptr + TI_SYS_NOERROR]
1597
1598 cmp %o0, -ERESTART_RESTARTBLOCK
1599 bgeu,pn %xcc, 1f
1600 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
160180:
1602 /* System call success, clear Carry condition code. */
1603 andn %g3, %g2, %g3
1604 stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
1605 bne,pn %icc, linux_syscall_trace2
1606 add %l1, 0x4, %l2 ! npc = npc+4
1607 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
1608 ba,pt %xcc, rtrap
1609 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
1610
16111:
1612 /* System call failure, set Carry condition code.
1613 * Also, get abs(errno) to return to the process.
1614 */
1615 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
1616 sub %g0, %o0, %o0
1617 or %g3, %g2, %g3
1618 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1619 stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
1620 bne,pn %icc, linux_syscall_trace2
1621 add %l1, 0x4, %l2 ! npc = npc+4
1622 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
1623
1624 b,pt %xcc, rtrap
1625 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
1626linux_syscall_trace2:
1627 add %sp, PTREGS_OFF, %o0
1628 call syscall_trace
1629 mov 1, %o1
1630 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
1631 ba,pt %xcc, rtrap
1632 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
1633
1634 .align 32
1635 .globl __flushw_user
1636__flushw_user:
1637 rdpr %otherwin, %g1
1638 brz,pn %g1, 2f
1639 clr %g2
16401: save %sp, -128, %sp
1641 rdpr %otherwin, %g1
1642 brnz,pt %g1, 1b
1643 add %g2, 1, %g2
16441: sub %g2, 1, %g2
1645 brnz,pt %g2, 1b
1646 restore %g0, %g0, %g0
16472: retl
1648 nop
1649
1650 /* Flush %fp and %i7 to the stack for all register
1651 * windows active inside of the cpu. This allows
1652 * show_stack_trace() to avoid using an expensive
1653 * 'flushw'.
1654 */
1655 .globl stack_trace_flush
1656 .type stack_trace_flush,#function
1657stack_trace_flush:
1658 rdpr %pstate, %o0
1659 wrpr %o0, PSTATE_IE, %pstate
1660
1661 rdpr %cwp, %g1
1662 rdpr %canrestore, %g2
1663 sub %g1, 1, %g3
1664
16651: brz,pn %g2, 2f
1666 sub %g2, 1, %g2
1667 wrpr %g3, %cwp
1668 stx %fp, [%sp + STACK_BIAS + RW_V9_I6]
1669 stx %i7, [%sp + STACK_BIAS + RW_V9_I7]
1670 ba,pt %xcc, 1b
1671 sub %g3, 1, %g3
1672
16732: wrpr %g1, %cwp
1674 wrpr %o0, %pstate
1675
1676 retl
1677 nop
1678 .size stack_trace_flush,.-stack_trace_flush
1679
1680#ifdef CONFIG_SMP
1681 .globl hard_smp_processor_id
1682hard_smp_processor_id:
1683#endif
1684 .globl real_hard_smp_processor_id
1685real_hard_smp_processor_id:
1686 __GET_CPUID(%o0)
1687 retl
1688 nop
1689
1690 /* %o0: devhandle
1691 * %o1: devino
1692 *
1693 * returns %o0: sysino
1694 */
1695 .globl sun4v_devino_to_sysino
1696 .type sun4v_devino_to_sysino,#function
1697sun4v_devino_to_sysino:
1698 mov HV_FAST_INTR_DEVINO2SYSINO, %o5
1699 ta HV_FAST_TRAP
1700 retl
1701 mov %o1, %o0
1702 .size sun4v_devino_to_sysino, .-sun4v_devino_to_sysino
1703
1704 /* %o0: sysino
1705 *
1706 * returns %o0: intr_enabled (HV_INTR_{DISABLED,ENABLED})
1707 */
1708 .globl sun4v_intr_getenabled
1709 .type sun4v_intr_getenabled,#function
1710sun4v_intr_getenabled:
1711 mov HV_FAST_INTR_GETENABLED, %o5
1712 ta HV_FAST_TRAP
1713 retl
1714 mov %o1, %o0
1715 .size sun4v_intr_getenabled, .-sun4v_intr_getenabled
1716
1717 /* %o0: sysino
1718 * %o1: intr_enabled (HV_INTR_{DISABLED,ENABLED})
1719 */
1720 .globl sun4v_intr_setenabled
1721 .type sun4v_intr_setenabled,#function
1722sun4v_intr_setenabled:
1723 mov HV_FAST_INTR_SETENABLED, %o5
1724 ta HV_FAST_TRAP
1725 retl
1726 nop
1727 .size sun4v_intr_setenabled, .-sun4v_intr_setenabled
1728
1729 /* %o0: sysino
1730 *
1731 * returns %o0: intr_state (HV_INTR_STATE_*)
1732 */
1733 .globl sun4v_intr_getstate
1734 .type sun4v_intr_getstate,#function
1735sun4v_intr_getstate:
1736 mov HV_FAST_INTR_GETSTATE, %o5
1737 ta HV_FAST_TRAP
1738 retl
1739 mov %o1, %o0
1740 .size sun4v_intr_getstate, .-sun4v_intr_getstate
1741
1742 /* %o0: sysino
1743 * %o1: intr_state (HV_INTR_STATE_*)
1744 */
1745 .globl sun4v_intr_setstate
1746 .type sun4v_intr_setstate,#function
1747sun4v_intr_setstate:
1748 mov HV_FAST_INTR_SETSTATE, %o5
1749 ta HV_FAST_TRAP
1750 retl
1751 nop
1752 .size sun4v_intr_setstate, .-sun4v_intr_setstate
1753
1754 /* %o0: sysino
1755 *
1756 * returns %o0: cpuid
1757 */
1758 .globl sun4v_intr_gettarget
1759 .type sun4v_intr_gettarget,#function
1760sun4v_intr_gettarget:
1761 mov HV_FAST_INTR_GETTARGET, %o5
1762 ta HV_FAST_TRAP
1763 retl
1764 mov %o1, %o0
1765 .size sun4v_intr_gettarget, .-sun4v_intr_gettarget
1766
1767 /* %o0: sysino
1768 * %o1: cpuid
1769 */
1770 .globl sun4v_intr_settarget
1771 .type sun4v_intr_settarget,#function
1772sun4v_intr_settarget:
1773 mov HV_FAST_INTR_SETTARGET, %o5
1774 ta HV_FAST_TRAP
1775 retl
1776 nop
1777 .size sun4v_intr_settarget, .-sun4v_intr_settarget
1778
1779 /* %o0: cpuid
1780 * %o1: pc
1781 * %o2: rtba
1782 * %o3: arg0
1783 *
1784 * returns %o0: status
1785 */
1786 .globl sun4v_cpu_start
1787 .type sun4v_cpu_start,#function
1788sun4v_cpu_start:
1789 mov HV_FAST_CPU_START, %o5
1790 ta HV_FAST_TRAP
1791 retl
1792 nop
1793 .size sun4v_cpu_start, .-sun4v_cpu_start
1794
1795 /* %o0: cpuid
1796 *
1797 * returns %o0: status
1798 */
1799 .globl sun4v_cpu_stop
1800 .type sun4v_cpu_stop,#function
1801sun4v_cpu_stop:
1802 mov HV_FAST_CPU_STOP, %o5
1803 ta HV_FAST_TRAP
1804 retl
1805 nop
1806 .size sun4v_cpu_stop, .-sun4v_cpu_stop
1807
1808 /* returns %o0: status */
1809 .globl sun4v_cpu_yield
1810 .type sun4v_cpu_yield, #function
1811sun4v_cpu_yield:
1812 mov HV_FAST_CPU_YIELD, %o5
1813 ta HV_FAST_TRAP
1814 retl
1815 nop
1816 .size sun4v_cpu_yield, .-sun4v_cpu_yield
1817
1818 /* %o0: type
1819 * %o1: queue paddr
1820 * %o2: num queue entries
1821 *
1822 * returns %o0: status
1823 */
1824 .globl sun4v_cpu_qconf
1825 .type sun4v_cpu_qconf,#function
1826sun4v_cpu_qconf:
1827 mov HV_FAST_CPU_QCONF, %o5
1828 ta HV_FAST_TRAP
1829 retl
1830 nop
1831 .size sun4v_cpu_qconf, .-sun4v_cpu_qconf
1832
1833 /* %o0: num cpus in cpu list
1834 * %o1: cpu list paddr
1835 * %o2: mondo block paddr
1836 *
1837 * returns %o0: status
1838 */
1839 .globl sun4v_cpu_mondo_send
1840 .type sun4v_cpu_mondo_send,#function
1841sun4v_cpu_mondo_send:
1842 mov HV_FAST_CPU_MONDO_SEND, %o5
1843 ta HV_FAST_TRAP
1844 retl
1845 nop
1846 .size sun4v_cpu_mondo_send, .-sun4v_cpu_mondo_send
1847
1848 /* %o0: CPU ID
1849 *
1850 * returns %o0: -status if status non-zero, else
1851 * %o0: cpu state as HV_CPU_STATE_*
1852 */
1853 .globl sun4v_cpu_state
1854 .type sun4v_cpu_state,#function
1855sun4v_cpu_state:
1856 mov HV_FAST_CPU_STATE, %o5
1857 ta HV_FAST_TRAP
1858 brnz,pn %o0, 1f
1859 sub %g0, %o0, %o0
1860 mov %o1, %o0
18611: retl
1862 nop
1863 .size sun4v_cpu_state, .-sun4v_cpu_state
1864
1865 /* %o0: virtual address
1866 * %o1: must be zero
1867 * %o2: TTE
1868 * %o3: HV_MMU_* flags
1869 *
1870 * returns %o0: status
1871 */
1872 .globl sun4v_mmu_map_perm_addr
1873 .type sun4v_mmu_map_perm_addr,#function
1874sun4v_mmu_map_perm_addr:
1875 mov HV_FAST_MMU_MAP_PERM_ADDR, %o5
1876 ta HV_FAST_TRAP
1877 retl
1878 nop
1879 .size sun4v_mmu_map_perm_addr, .-sun4v_mmu_map_perm_addr
1880
1881 /* %o0: number of TSB descriptions
1882 * %o1: TSB descriptions real address
1883 *
1884 * returns %o0: status
1885 */
1886 .globl sun4v_mmu_tsb_ctx0
1887 .type sun4v_mmu_tsb_ctx0,#function
1888sun4v_mmu_tsb_ctx0:
1889 mov HV_FAST_MMU_TSB_CTX0, %o5
1890 ta HV_FAST_TRAP
1891 retl
1892 nop
1893 .size sun4v_mmu_tsb_ctx0, .-sun4v_mmu_tsb_ctx0
1894
1895 /* %o0: API group number
1896 * %o1: pointer to unsigned long major number storage
1897 * %o2: pointer to unsigned long minor number storage
1898 *
1899 * returns %o0: status
1900 */
1901 .globl sun4v_get_version
1902 .type sun4v_get_version,#function
1903sun4v_get_version:
1904 mov HV_CORE_GET_VER, %o5
1905 mov %o1, %o3
1906 mov %o2, %o4
1907 ta HV_CORE_TRAP
1908 stx %o1, [%o3]
1909 retl
1910 stx %o2, [%o4]
1911 .size sun4v_get_version, .-sun4v_get_version
1912
1913 /* %o0: API group number
1914 * %o1: desired major number
1915 * %o2: desired minor number
1916 * %o3: pointer to unsigned long actual minor number storage
1917 *
1918 * returns %o0: status
1919 */
1920 .globl sun4v_set_version
1921 .type sun4v_set_version,#function
1922sun4v_set_version:
1923 mov HV_CORE_SET_VER, %o5
1924 mov %o3, %o4
1925 ta HV_CORE_TRAP
1926 retl
1927 stx %o1, [%o4]
1928 .size sun4v_set_version, .-sun4v_set_version
1929
1930 /* %o0: pointer to unsigned long time
1931 *
1932 * returns %o0: status
1933 */
1934 .globl sun4v_tod_get
1935 .type sun4v_tod_get,#function
1936sun4v_tod_get:
1937 mov %o0, %o4
1938 mov HV_FAST_TOD_GET, %o5
1939 ta HV_FAST_TRAP
1940 stx %o1, [%o4]
1941 retl
1942 nop
1943 .size sun4v_tod_get, .-sun4v_tod_get
1944
1945 /* %o0: time
1946 *
1947 * returns %o0: status
1948 */
1949 .globl sun4v_tod_set
1950 .type sun4v_tod_set,#function
1951sun4v_tod_set:
1952 mov HV_FAST_TOD_SET, %o5
1953 ta HV_FAST_TRAP
1954 retl
1955 nop
1956 .size sun4v_tod_set, .-sun4v_tod_set
1957
1958 /* %o0: pointer to unsigned long status
1959 *
1960 * returns %o0: signed character
1961 */
1962 .globl sun4v_con_getchar
1963 .type sun4v_con_getchar,#function
1964sun4v_con_getchar:
1965 mov %o0, %o4
1966 mov HV_FAST_CONS_GETCHAR, %o5
1967 clr %o0
1968 clr %o1
1969 ta HV_FAST_TRAP
1970 stx %o0, [%o4]
1971 retl
1972 sra %o1, 0, %o0
1973 .size sun4v_con_getchar, .-sun4v_con_getchar
1974
1975 /* %o0: signed long character
1976 *
1977 * returns %o0: status
1978 */
1979 .globl sun4v_con_putchar
1980 .type sun4v_con_putchar,#function
1981sun4v_con_putchar:
1982 mov HV_FAST_CONS_PUTCHAR, %o5
1983 ta HV_FAST_TRAP
1984 retl
1985 sra %o0, 0, %o0
1986 .size sun4v_con_putchar, .-sun4v_con_putchar
1987
1988 /* %o0: buffer real address
1989 * %o1: buffer size
1990 * %o2: pointer to unsigned long bytes_read
1991 *
1992 * returns %o0: status
1993 */
1994 .globl sun4v_con_read
1995 .type sun4v_con_read,#function
1996sun4v_con_read:
1997 mov %o2, %o4
1998 mov HV_FAST_CONS_READ, %o5
1999 ta HV_FAST_TRAP
2000 brnz %o0, 1f
2001 cmp %o1, -1 /* break */
2002 be,a,pn %icc, 1f
2003 mov %o1, %o0
2004 cmp %o1, -2 /* hup */
2005 be,a,pn %icc, 1f
2006 mov %o1, %o0
2007 stx %o1, [%o4]
20081: retl
2009 nop
2010 .size sun4v_con_read, .-sun4v_con_read
2011
2012 /* %o0: buffer real address
2013 * %o1: buffer size
2014 * %o2: pointer to unsigned long bytes_written
2015 *
2016 * returns %o0: status
2017 */
2018 .globl sun4v_con_write
2019 .type sun4v_con_write,#function
2020sun4v_con_write:
2021 mov %o2, %o4
2022 mov HV_FAST_CONS_WRITE, %o5
2023 ta HV_FAST_TRAP
2024 stx %o1, [%o4]
2025 retl
2026 nop
2027 .size sun4v_con_write, .-sun4v_con_write
2028
2029 /* %o0: soft state
2030 * %o1: address of description string
2031 *
2032 * returns %o0: status
2033 */
2034 .globl sun4v_mach_set_soft_state
2035 .type sun4v_mach_set_soft_state,#function
2036sun4v_mach_set_soft_state:
2037 mov HV_FAST_MACH_SET_SOFT_STATE, %o5
2038 ta HV_FAST_TRAP
2039 retl
2040 nop
2041 .size sun4v_mach_set_soft_state, .-sun4v_mach_set_soft_state
2042
2043 /* %o0: exit code
2044 *
2045 * Does not return.
2046 */
2047 .globl sun4v_mach_exit
2048 .type sun4v_mach_exit,#function
2049sun4v_mach_exit:
2050 mov HV_FAST_MACH_EXIT, %o5
2051 ta HV_FAST_TRAP
2052 retl
2053 nop
2054 .size sun4v_mach_exit, .-sun4v_mach_exit
2055
2056 /* %o0: buffer real address
2057 * %o1: buffer length
2058 * %o2: pointer to unsigned long real_buf_len
2059 *
2060 * returns %o0: status
2061 */
2062 .globl sun4v_mach_desc
2063 .type sun4v_mach_desc,#function
2064sun4v_mach_desc:
2065 mov %o2, %o4
2066 mov HV_FAST_MACH_DESC, %o5
2067 ta HV_FAST_TRAP
2068 stx %o1, [%o4]
2069 retl
2070 nop
2071 .size sun4v_mach_desc, .-sun4v_mach_desc
2072
2073 /* %o0: new timeout in milliseconds
2074 * %o1: pointer to unsigned long orig_timeout
2075 *
2076 * returns %o0: status
2077 */
2078 .globl sun4v_mach_set_watchdog
2079 .type sun4v_mach_set_watchdog,#function
2080sun4v_mach_set_watchdog:
2081 mov %o1, %o4
2082 mov HV_FAST_MACH_SET_WATCHDOG, %o5
2083 ta HV_FAST_TRAP
2084 stx %o1, [%o4]
2085 retl
2086 nop
2087 .size sun4v_mach_set_watchdog, .-sun4v_mach_set_watchdog
2088
2089 /* No inputs and does not return. */
2090 .globl sun4v_mach_sir
2091 .type sun4v_mach_sir,#function
2092sun4v_mach_sir:
2093 mov %o1, %o4
2094 mov HV_FAST_MACH_SIR, %o5
2095 ta HV_FAST_TRAP
2096 stx %o1, [%o4]
2097 retl
2098 nop
2099 .size sun4v_mach_sir, .-sun4v_mach_sir
2100
2101 /* %o0: channel
2102 * %o1: ra
2103 * %o2: num_entries
2104 *
2105 * returns %o0: status
2106 */
2107 .globl sun4v_ldc_tx_qconf
2108 .type sun4v_ldc_tx_qconf,#function
2109sun4v_ldc_tx_qconf:
2110 mov HV_FAST_LDC_TX_QCONF, %o5
2111 ta HV_FAST_TRAP
2112 retl
2113 nop
2114 .size sun4v_ldc_tx_qconf, .-sun4v_ldc_tx_qconf
2115
2116 /* %o0: channel
2117 * %o1: pointer to unsigned long ra
2118 * %o2: pointer to unsigned long num_entries
2119 *
2120 * returns %o0: status
2121 */
2122 .globl sun4v_ldc_tx_qinfo
2123 .type sun4v_ldc_tx_qinfo,#function
2124sun4v_ldc_tx_qinfo:
2125 mov %o1, %g1
2126 mov %o2, %g2
2127 mov HV_FAST_LDC_TX_QINFO, %o5
2128 ta HV_FAST_TRAP
2129 stx %o1, [%g1]
2130 stx %o2, [%g2]
2131 retl
2132 nop
2133 .size sun4v_ldc_tx_qinfo, .-sun4v_ldc_tx_qinfo
2134
2135 /* %o0: channel
2136 * %o1: pointer to unsigned long head_off
2137 * %o2: pointer to unsigned long tail_off
2138 * %o2: pointer to unsigned long chan_state
2139 *
2140 * returns %o0: status
2141 */
2142 .globl sun4v_ldc_tx_get_state
2143 .type sun4v_ldc_tx_get_state,#function
2144sun4v_ldc_tx_get_state:
2145 mov %o1, %g1
2146 mov %o2, %g2
2147 mov %o3, %g3
2148 mov HV_FAST_LDC_TX_GET_STATE, %o5
2149 ta HV_FAST_TRAP
2150 stx %o1, [%g1]
2151 stx %o2, [%g2]
2152 stx %o3, [%g3]
2153 retl
2154 nop
2155 .size sun4v_ldc_tx_get_state, .-sun4v_ldc_tx_get_state
2156
2157 /* %o0: channel
2158 * %o1: tail_off
2159 *
2160 * returns %o0: status
2161 */
2162 .globl sun4v_ldc_tx_set_qtail
2163 .type sun4v_ldc_tx_set_qtail,#function
2164sun4v_ldc_tx_set_qtail:
2165 mov HV_FAST_LDC_TX_SET_QTAIL, %o5
2166 ta HV_FAST_TRAP
2167 retl
2168 nop
2169 .size sun4v_ldc_tx_set_qtail, .-sun4v_ldc_tx_set_qtail
2170
2171 /* %o0: channel
2172 * %o1: ra
2173 * %o2: num_entries
2174 *
2175 * returns %o0: status
2176 */
2177 .globl sun4v_ldc_rx_qconf
2178 .type sun4v_ldc_rx_qconf,#function
2179sun4v_ldc_rx_qconf:
2180 mov HV_FAST_LDC_RX_QCONF, %o5
2181 ta HV_FAST_TRAP
2182 retl
2183 nop
2184 .size sun4v_ldc_rx_qconf, .-sun4v_ldc_rx_qconf
2185
2186 /* %o0: channel
2187 * %o1: pointer to unsigned long ra
2188 * %o2: pointer to unsigned long num_entries
2189 *
2190 * returns %o0: status
2191 */
2192 .globl sun4v_ldc_rx_qinfo
2193 .type sun4v_ldc_rx_qinfo,#function
2194sun4v_ldc_rx_qinfo:
2195 mov %o1, %g1
2196 mov %o2, %g2
2197 mov HV_FAST_LDC_RX_QINFO, %o5
2198 ta HV_FAST_TRAP
2199 stx %o1, [%g1]
2200 stx %o2, [%g2]
2201 retl
2202 nop
2203 .size sun4v_ldc_rx_qinfo, .-sun4v_ldc_rx_qinfo
2204
2205 /* %o0: channel
2206 * %o1: pointer to unsigned long head_off
2207 * %o2: pointer to unsigned long tail_off
2208 * %o2: pointer to unsigned long chan_state
2209 *
2210 * returns %o0: status
2211 */
2212 .globl sun4v_ldc_rx_get_state
2213 .type sun4v_ldc_rx_get_state,#function
2214sun4v_ldc_rx_get_state:
2215 mov %o1, %g1
2216 mov %o2, %g2
2217 mov %o3, %g3
2218 mov HV_FAST_LDC_RX_GET_STATE, %o5
2219 ta HV_FAST_TRAP
2220 stx %o1, [%g1]
2221 stx %o2, [%g2]
2222 stx %o3, [%g3]
2223 retl
2224 nop
2225 .size sun4v_ldc_rx_get_state, .-sun4v_ldc_rx_get_state
2226
2227 /* %o0: channel
2228 * %o1: head_off
2229 *
2230 * returns %o0: status
2231 */
2232 .globl sun4v_ldc_rx_set_qhead
2233 .type sun4v_ldc_rx_set_qhead,#function
2234sun4v_ldc_rx_set_qhead:
2235 mov HV_FAST_LDC_RX_SET_QHEAD, %o5
2236 ta HV_FAST_TRAP
2237 retl
2238 nop
2239 .size sun4v_ldc_rx_set_qhead, .-sun4v_ldc_rx_set_qhead
2240
2241 /* %o0: channel
2242 * %o1: ra
2243 * %o2: num_entries
2244 *
2245 * returns %o0: status
2246 */
2247 .globl sun4v_ldc_set_map_table
2248 .type sun4v_ldc_set_map_table,#function
2249sun4v_ldc_set_map_table:
2250 mov HV_FAST_LDC_SET_MAP_TABLE, %o5
2251 ta HV_FAST_TRAP
2252 retl
2253 nop
2254 .size sun4v_ldc_set_map_table, .-sun4v_ldc_set_map_table
2255
2256 /* %o0: channel
2257 * %o1: pointer to unsigned long ra
2258 * %o2: pointer to unsigned long num_entries
2259 *
2260 * returns %o0: status
2261 */
2262 .globl sun4v_ldc_get_map_table
2263 .type sun4v_ldc_get_map_table,#function
2264sun4v_ldc_get_map_table:
2265 mov %o1, %g1
2266 mov %o2, %g2
2267 mov HV_FAST_LDC_GET_MAP_TABLE, %o5
2268 ta HV_FAST_TRAP
2269 stx %o1, [%g1]
2270 stx %o2, [%g2]
2271 retl
2272 nop
2273 .size sun4v_ldc_get_map_table, .-sun4v_ldc_get_map_table
2274
2275 /* %o0: channel
2276 * %o1: dir_code
2277 * %o2: tgt_raddr
2278 * %o3: lcl_raddr
2279 * %o4: len
2280 * %o5: pointer to unsigned long actual_len
2281 *
2282 * returns %o0: status
2283 */
2284 .globl sun4v_ldc_copy
2285 .type sun4v_ldc_copy,#function
2286sun4v_ldc_copy:
2287 mov %o5, %g1
2288 mov HV_FAST_LDC_COPY, %o5
2289 ta HV_FAST_TRAP
2290 stx %o1, [%g1]
2291 retl
2292 nop
2293 .size sun4v_ldc_copy, .-sun4v_ldc_copy
2294
2295 /* %o0: channel
2296 * %o1: cookie
2297 * %o2: pointer to unsigned long ra
2298 * %o3: pointer to unsigned long perm
2299 *
2300 * returns %o0: status
2301 */
2302 .globl sun4v_ldc_mapin
2303 .type sun4v_ldc_mapin,#function
2304sun4v_ldc_mapin:
2305 mov %o2, %g1
2306 mov %o3, %g2
2307 mov HV_FAST_LDC_MAPIN, %o5
2308 ta HV_FAST_TRAP
2309 stx %o1, [%g1]
2310 stx %o2, [%g2]
2311 retl
2312 nop
2313 .size sun4v_ldc_mapin, .-sun4v_ldc_mapin
2314
2315 /* %o0: ra
2316 *
2317 * returns %o0: status
2318 */
2319 .globl sun4v_ldc_unmap
2320 .type sun4v_ldc_unmap,#function
2321sun4v_ldc_unmap:
2322 mov HV_FAST_LDC_UNMAP, %o5
2323 ta HV_FAST_TRAP
2324 retl
2325 nop
2326 .size sun4v_ldc_unmap, .-sun4v_ldc_unmap
2327
2328 /* %o0: channel
2329 * %o1: cookie
2330 * %o2: mte_cookie
2331 *
2332 * returns %o0: status
2333 */
2334 .globl sun4v_ldc_revoke
2335 .type sun4v_ldc_revoke,#function
2336sun4v_ldc_revoke:
2337 mov HV_FAST_LDC_REVOKE, %o5
2338 ta HV_FAST_TRAP
2339 retl
2340 nop
2341 .size sun4v_ldc_revoke, .-sun4v_ldc_revoke
2342
2343 /* %o0: device handle
2344 * %o1: device INO
2345 * %o2: pointer to unsigned long cookie
2346 *
2347 * returns %o0: status
2348 */
2349 .globl sun4v_vintr_get_cookie
2350 .type sun4v_vintr_get_cookie,#function
2351sun4v_vintr_get_cookie:
2352 mov %o2, %g1
2353 mov HV_FAST_VINTR_GET_COOKIE, %o5
2354 ta HV_FAST_TRAP
2355 stx %o1, [%g1]
2356 retl
2357 nop
2358 .size sun4v_vintr_get_cookie, .-sun4v_vintr_get_cookie
2359
2360 /* %o0: device handle
2361 * %o1: device INO
2362 * %o2: cookie
2363 *
2364 * returns %o0: status
2365 */
2366 .globl sun4v_vintr_set_cookie
2367 .type sun4v_vintr_set_cookie,#function
2368sun4v_vintr_set_cookie:
2369 mov HV_FAST_VINTR_SET_COOKIE, %o5
2370 ta HV_FAST_TRAP
2371 retl
2372 nop
2373 .size sun4v_vintr_set_cookie, .-sun4v_vintr_set_cookie
2374
2375 /* %o0: device handle
2376 * %o1: device INO
2377 * %o2: pointer to unsigned long valid_state
2378 *
2379 * returns %o0: status
2380 */
2381 .globl sun4v_vintr_get_valid
2382 .type sun4v_vintr_get_valid,#function
2383sun4v_vintr_get_valid:
2384 mov %o2, %g1
2385 mov HV_FAST_VINTR_GET_VALID, %o5
2386 ta HV_FAST_TRAP
2387 stx %o1, [%g1]
2388 retl
2389 nop
2390 .size sun4v_vintr_get_valid, .-sun4v_vintr_get_valid
2391
2392 /* %o0: device handle
2393 * %o1: device INO
2394 * %o2: valid_state
2395 *
2396 * returns %o0: status
2397 */
2398 .globl sun4v_vintr_set_valid
2399 .type sun4v_vintr_set_valid,#function
2400sun4v_vintr_set_valid:
2401 mov HV_FAST_VINTR_SET_VALID, %o5
2402 ta HV_FAST_TRAP
2403 retl
2404 nop
2405 .size sun4v_vintr_set_valid, .-sun4v_vintr_set_valid
2406
2407 /* %o0: device handle
2408 * %o1: device INO
2409 * %o2: pointer to unsigned long state
2410 *
2411 * returns %o0: status
2412 */
2413 .globl sun4v_vintr_get_state
2414 .type sun4v_vintr_get_state,#function
2415sun4v_vintr_get_state:
2416 mov %o2, %g1
2417 mov HV_FAST_VINTR_GET_STATE, %o5
2418 ta HV_FAST_TRAP
2419 stx %o1, [%g1]
2420 retl
2421 nop
2422 .size sun4v_vintr_get_state, .-sun4v_vintr_get_state
2423
2424 /* %o0: device handle
2425 * %o1: device INO
2426 * %o2: state
2427 *
2428 * returns %o0: status
2429 */
2430 .globl sun4v_vintr_set_state
2431 .type sun4v_vintr_set_state,#function
2432sun4v_vintr_set_state:
2433 mov HV_FAST_VINTR_SET_STATE, %o5
2434 ta HV_FAST_TRAP
2435 retl
2436 nop
2437 .size sun4v_vintr_set_state, .-sun4v_vintr_set_state
2438
2439 /* %o0: device handle
2440 * %o1: device INO
2441 * %o2: pointer to unsigned long cpuid
2442 *
2443 * returns %o0: status
2444 */
2445 .globl sun4v_vintr_get_target
2446 .type sun4v_vintr_get_target,#function
2447sun4v_vintr_get_target:
2448 mov %o2, %g1
2449 mov HV_FAST_VINTR_GET_TARGET, %o5
2450 ta HV_FAST_TRAP
2451 stx %o1, [%g1]
2452 retl
2453 nop
2454 .size sun4v_vintr_get_target, .-sun4v_vintr_get_target
2455
2456 /* %o0: device handle
2457 * %o1: device INO
2458 * %o2: cpuid
2459 *
2460 * returns %o0: status
2461 */
2462 .globl sun4v_vintr_set_target
2463 .type sun4v_vintr_set_target,#function
2464sun4v_vintr_set_target:
2465 mov HV_FAST_VINTR_SET_TARGET, %o5
2466 ta HV_FAST_TRAP
2467 retl
2468 nop
2469 .size sun4v_vintr_set_target, .-sun4v_vintr_set_target
2470
2471 /* %o0: NCS sub-function
2472 * %o1: sub-function arg real-address
2473 * %o2: sub-function arg size
2474 *
2475 * returns %o0: status
2476 */
2477 .globl sun4v_ncs_request
2478 .type sun4v_ncs_request,#function
2479sun4v_ncs_request:
2480 mov HV_FAST_NCS_REQUEST, %o5
2481 ta HV_FAST_TRAP
2482 retl
2483 nop
2484 .size sun4v_ncs_request, .-sun4v_ncs_request
2485
2486 .globl sun4v_svc_send
2487 .type sun4v_svc_send,#function
2488sun4v_svc_send:
2489 save %sp, -192, %sp
2490 mov %i0, %o0
2491 mov %i1, %o1
2492 mov %i2, %o2
2493 mov HV_FAST_SVC_SEND, %o5
2494 ta HV_FAST_TRAP
2495 stx %o1, [%i3]
2496 ret
2497 restore
2498 .size sun4v_svc_send, .-sun4v_svc_send
2499
2500 .globl sun4v_svc_recv
2501 .type sun4v_svc_recv,#function
2502sun4v_svc_recv:
2503 save %sp, -192, %sp
2504 mov %i0, %o0
2505 mov %i1, %o1
2506 mov %i2, %o2
2507 mov HV_FAST_SVC_RECV, %o5
2508 ta HV_FAST_TRAP
2509 stx %o1, [%i3]
2510 ret
2511 restore
2512 .size sun4v_svc_recv, .-sun4v_svc_recv
2513
2514 .globl sun4v_svc_getstatus
2515 .type sun4v_svc_getstatus,#function
2516sun4v_svc_getstatus:
2517 mov HV_FAST_SVC_GETSTATUS, %o5
2518 mov %o1, %o4
2519 ta HV_FAST_TRAP
2520 stx %o1, [%o4]
2521 retl
2522 nop
2523 .size sun4v_svc_getstatus, .-sun4v_svc_getstatus
2524
2525 .globl sun4v_svc_setstatus
2526 .type sun4v_svc_setstatus,#function
2527sun4v_svc_setstatus:
2528 mov HV_FAST_SVC_SETSTATUS, %o5
2529 ta HV_FAST_TRAP
2530 retl
2531 nop
2532 .size sun4v_svc_setstatus, .-sun4v_svc_setstatus
2533
2534 .globl sun4v_svc_clrstatus
2535 .type sun4v_svc_clrstatus,#function
2536sun4v_svc_clrstatus:
2537 mov HV_FAST_SVC_CLRSTATUS, %o5
2538 ta HV_FAST_TRAP
2539 retl
2540 nop
2541 .size sun4v_svc_clrstatus, .-sun4v_svc_clrstatus
2542
2543 .globl sun4v_mmustat_conf
2544 .type sun4v_mmustat_conf,#function
2545sun4v_mmustat_conf:
2546 mov %o1, %o4
2547 mov HV_FAST_MMUSTAT_CONF, %o5
2548 ta HV_FAST_TRAP
2549 stx %o1, [%o4]
2550 retl
2551 nop
2552 .size sun4v_mmustat_conf, .-sun4v_mmustat_conf
2553
2554 .globl sun4v_mmustat_info
2555 .type sun4v_mmustat_info,#function
2556sun4v_mmustat_info:
2557 mov %o0, %o4
2558 mov HV_FAST_MMUSTAT_INFO, %o5
2559 ta HV_FAST_TRAP
2560 stx %o1, [%o4]
2561 retl
2562 nop
2563 .size sun4v_mmustat_info, .-sun4v_mmustat_info
2564
2565 .globl sun4v_mmu_demap_all
2566 .type sun4v_mmu_demap_all,#function
2567sun4v_mmu_demap_all:
2568 clr %o0
2569 clr %o1
2570 mov HV_MMU_ALL, %o2
2571 mov HV_FAST_MMU_DEMAP_ALL, %o5
2572 ta HV_FAST_TRAP
2573 retl
2574 nop
2575 .size sun4v_mmu_demap_all, .-sun4v_mmu_demap_all
diff --git a/arch/sparc64/kernel/fpu_traps.S b/arch/sparc64/kernel/fpu_traps.S
new file mode 100644
index 000000000000..a6864826a4bd
--- /dev/null
+++ b/arch/sparc64/kernel/fpu_traps.S
@@ -0,0 +1,384 @@
1 /* This is trivial with the new code... */
2 .globl do_fpdis
3 .type do_fpdis,#function
4do_fpdis:
5 sethi %hi(TSTATE_PEF), %g4
6 rdpr %tstate, %g5
7 andcc %g5, %g4, %g0
8 be,pt %xcc, 1f
9 nop
10 rd %fprs, %g5
11 andcc %g5, FPRS_FEF, %g0
12 be,pt %xcc, 1f
13 nop
14
15 /* Legal state when DCR_IFPOE is set in Cheetah %dcr. */
16 sethi %hi(109f), %g7
17 ba,pt %xcc, etrap
18109: or %g7, %lo(109b), %g7
19 add %g0, %g0, %g0
20 ba,a,pt %xcc, rtrap
21
221: TRAP_LOAD_THREAD_REG(%g6, %g1)
23 ldub [%g6 + TI_FPSAVED], %g5
24 wr %g0, FPRS_FEF, %fprs
25 andcc %g5, FPRS_FEF, %g0
26 be,a,pt %icc, 1f
27 clr %g7
28 ldx [%g6 + TI_GSR], %g7
291: andcc %g5, FPRS_DL, %g0
30 bne,pn %icc, 2f
31 fzero %f0
32 andcc %g5, FPRS_DU, %g0
33 bne,pn %icc, 1f
34 fzero %f2
35 faddd %f0, %f2, %f4
36 fmuld %f0, %f2, %f6
37 faddd %f0, %f2, %f8
38 fmuld %f0, %f2, %f10
39 faddd %f0, %f2, %f12
40 fmuld %f0, %f2, %f14
41 faddd %f0, %f2, %f16
42 fmuld %f0, %f2, %f18
43 faddd %f0, %f2, %f20
44 fmuld %f0, %f2, %f22
45 faddd %f0, %f2, %f24
46 fmuld %f0, %f2, %f26
47 faddd %f0, %f2, %f28
48 fmuld %f0, %f2, %f30
49 faddd %f0, %f2, %f32
50 fmuld %f0, %f2, %f34
51 faddd %f0, %f2, %f36
52 fmuld %f0, %f2, %f38
53 faddd %f0, %f2, %f40
54 fmuld %f0, %f2, %f42
55 faddd %f0, %f2, %f44
56 fmuld %f0, %f2, %f46
57 faddd %f0, %f2, %f48
58 fmuld %f0, %f2, %f50
59 faddd %f0, %f2, %f52
60 fmuld %f0, %f2, %f54
61 faddd %f0, %f2, %f56
62 fmuld %f0, %f2, %f58
63 b,pt %xcc, fpdis_exit2
64 faddd %f0, %f2, %f60
651: mov SECONDARY_CONTEXT, %g3
66 add %g6, TI_FPREGS + 0x80, %g1
67 faddd %f0, %f2, %f4
68 fmuld %f0, %f2, %f6
69
70661: ldxa [%g3] ASI_DMMU, %g5
71 .section .sun4v_1insn_patch, "ax"
72 .word 661b
73 ldxa [%g3] ASI_MMU, %g5
74 .previous
75
76 sethi %hi(sparc64_kern_sec_context), %g2
77 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
78
79661: stxa %g2, [%g3] ASI_DMMU
80 .section .sun4v_1insn_patch, "ax"
81 .word 661b
82 stxa %g2, [%g3] ASI_MMU
83 .previous
84
85 membar #Sync
86 add %g6, TI_FPREGS + 0xc0, %g2
87 faddd %f0, %f2, %f8
88 fmuld %f0, %f2, %f10
89 membar #Sync
90 ldda [%g1] ASI_BLK_S, %f32
91 ldda [%g2] ASI_BLK_S, %f48
92 membar #Sync
93 faddd %f0, %f2, %f12
94 fmuld %f0, %f2, %f14
95 faddd %f0, %f2, %f16
96 fmuld %f0, %f2, %f18
97 faddd %f0, %f2, %f20
98 fmuld %f0, %f2, %f22
99 faddd %f0, %f2, %f24
100 fmuld %f0, %f2, %f26
101 faddd %f0, %f2, %f28
102 fmuld %f0, %f2, %f30
103 b,pt %xcc, fpdis_exit
104 nop
1052: andcc %g5, FPRS_DU, %g0
106 bne,pt %icc, 3f
107 fzero %f32
108 mov SECONDARY_CONTEXT, %g3
109 fzero %f34
110
111661: ldxa [%g3] ASI_DMMU, %g5
112 .section .sun4v_1insn_patch, "ax"
113 .word 661b
114 ldxa [%g3] ASI_MMU, %g5
115 .previous
116
117 add %g6, TI_FPREGS, %g1
118 sethi %hi(sparc64_kern_sec_context), %g2
119 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
120
121661: stxa %g2, [%g3] ASI_DMMU
122 .section .sun4v_1insn_patch, "ax"
123 .word 661b
124 stxa %g2, [%g3] ASI_MMU
125 .previous
126
127 membar #Sync
128 add %g6, TI_FPREGS + 0x40, %g2
129 faddd %f32, %f34, %f36
130 fmuld %f32, %f34, %f38
131 membar #Sync
132 ldda [%g1] ASI_BLK_S, %f0
133 ldda [%g2] ASI_BLK_S, %f16
134 membar #Sync
135 faddd %f32, %f34, %f40
136 fmuld %f32, %f34, %f42
137 faddd %f32, %f34, %f44
138 fmuld %f32, %f34, %f46
139 faddd %f32, %f34, %f48
140 fmuld %f32, %f34, %f50
141 faddd %f32, %f34, %f52
142 fmuld %f32, %f34, %f54
143 faddd %f32, %f34, %f56
144 fmuld %f32, %f34, %f58
145 faddd %f32, %f34, %f60
146 fmuld %f32, %f34, %f62
147 ba,pt %xcc, fpdis_exit
148 nop
1493: mov SECONDARY_CONTEXT, %g3
150 add %g6, TI_FPREGS, %g1
151
152661: ldxa [%g3] ASI_DMMU, %g5
153 .section .sun4v_1insn_patch, "ax"
154 .word 661b
155 ldxa [%g3] ASI_MMU, %g5
156 .previous
157
158 sethi %hi(sparc64_kern_sec_context), %g2
159 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
160
161661: stxa %g2, [%g3] ASI_DMMU
162 .section .sun4v_1insn_patch, "ax"
163 .word 661b
164 stxa %g2, [%g3] ASI_MMU
165 .previous
166
167 membar #Sync
168 mov 0x40, %g2
169 membar #Sync
170 ldda [%g1] ASI_BLK_S, %f0
171 ldda [%g1 + %g2] ASI_BLK_S, %f16
172 add %g1, 0x80, %g1
173 ldda [%g1] ASI_BLK_S, %f32
174 ldda [%g1 + %g2] ASI_BLK_S, %f48
175 membar #Sync
176fpdis_exit:
177
178661: stxa %g5, [%g3] ASI_DMMU
179 .section .sun4v_1insn_patch, "ax"
180 .word 661b
181 stxa %g5, [%g3] ASI_MMU
182 .previous
183
184 membar #Sync
185fpdis_exit2:
186 wr %g7, 0, %gsr
187 ldx [%g6 + TI_XFSR], %fsr
188 rdpr %tstate, %g3
189 or %g3, %g4, %g3 ! anal...
190 wrpr %g3, %tstate
191 wr %g0, FPRS_FEF, %fprs ! clean DU/DL bits
192 retry
193 .size do_fpdis,.-do_fpdis
194
195 .align 32
196 .type fp_other_bounce,#function
197fp_other_bounce:
198 call do_fpother
199 add %sp, PTREGS_OFF, %o0
200 ba,pt %xcc, rtrap
201 nop
202 .size fp_other_bounce,.-fp_other_bounce
203
204 .align 32
205 .globl do_fpother_check_fitos
206 .type do_fpother_check_fitos,#function
207do_fpother_check_fitos:
208 TRAP_LOAD_THREAD_REG(%g6, %g1)
209 sethi %hi(fp_other_bounce - 4), %g7
210 or %g7, %lo(fp_other_bounce - 4), %g7
211
212 /* NOTE: Need to preserve %g7 until we fully commit
213 * to the fitos fixup.
214 */
215 stx %fsr, [%g6 + TI_XFSR]
216 rdpr %tstate, %g3
217 andcc %g3, TSTATE_PRIV, %g0
218 bne,pn %xcc, do_fptrap_after_fsr
219 nop
220 ldx [%g6 + TI_XFSR], %g3
221 srlx %g3, 14, %g1
222 and %g1, 7, %g1
223 cmp %g1, 2 ! Unfinished FP-OP
224 bne,pn %xcc, do_fptrap_after_fsr
225 sethi %hi(1 << 23), %g1 ! Inexact
226 andcc %g3, %g1, %g0
227 bne,pn %xcc, do_fptrap_after_fsr
228 rdpr %tpc, %g1
229 lduwa [%g1] ASI_AIUP, %g3 ! This cannot ever fail
230#define FITOS_MASK 0xc1f83fe0
231#define FITOS_COMPARE 0x81a01880
232 sethi %hi(FITOS_MASK), %g1
233 or %g1, %lo(FITOS_MASK), %g1
234 and %g3, %g1, %g1
235 sethi %hi(FITOS_COMPARE), %g2
236 or %g2, %lo(FITOS_COMPARE), %g2
237 cmp %g1, %g2
238 bne,pn %xcc, do_fptrap_after_fsr
239 nop
240 std %f62, [%g6 + TI_FPREGS + (62 * 4)]
241 sethi %hi(fitos_table_1), %g1
242 and %g3, 0x1f, %g2
243 or %g1, %lo(fitos_table_1), %g1
244 sllx %g2, 2, %g2
245 jmpl %g1 + %g2, %g0
246 ba,pt %xcc, fitos_emul_continue
247
248fitos_table_1:
249 fitod %f0, %f62
250 fitod %f1, %f62
251 fitod %f2, %f62
252 fitod %f3, %f62
253 fitod %f4, %f62
254 fitod %f5, %f62
255 fitod %f6, %f62
256 fitod %f7, %f62
257 fitod %f8, %f62
258 fitod %f9, %f62
259 fitod %f10, %f62
260 fitod %f11, %f62
261 fitod %f12, %f62
262 fitod %f13, %f62
263 fitod %f14, %f62
264 fitod %f15, %f62
265 fitod %f16, %f62
266 fitod %f17, %f62
267 fitod %f18, %f62
268 fitod %f19, %f62
269 fitod %f20, %f62
270 fitod %f21, %f62
271 fitod %f22, %f62
272 fitod %f23, %f62
273 fitod %f24, %f62
274 fitod %f25, %f62
275 fitod %f26, %f62
276 fitod %f27, %f62
277 fitod %f28, %f62
278 fitod %f29, %f62
279 fitod %f30, %f62
280 fitod %f31, %f62
281
282fitos_emul_continue:
283 sethi %hi(fitos_table_2), %g1
284 srl %g3, 25, %g2
285 or %g1, %lo(fitos_table_2), %g1
286 and %g2, 0x1f, %g2
287 sllx %g2, 2, %g2
288 jmpl %g1 + %g2, %g0
289 ba,pt %xcc, fitos_emul_fini
290
291fitos_table_2:
292 fdtos %f62, %f0
293 fdtos %f62, %f1
294 fdtos %f62, %f2
295 fdtos %f62, %f3
296 fdtos %f62, %f4
297 fdtos %f62, %f5
298 fdtos %f62, %f6
299 fdtos %f62, %f7
300 fdtos %f62, %f8
301 fdtos %f62, %f9
302 fdtos %f62, %f10
303 fdtos %f62, %f11
304 fdtos %f62, %f12
305 fdtos %f62, %f13
306 fdtos %f62, %f14
307 fdtos %f62, %f15
308 fdtos %f62, %f16
309 fdtos %f62, %f17
310 fdtos %f62, %f18
311 fdtos %f62, %f19
312 fdtos %f62, %f20
313 fdtos %f62, %f21
314 fdtos %f62, %f22
315 fdtos %f62, %f23
316 fdtos %f62, %f24
317 fdtos %f62, %f25
318 fdtos %f62, %f26
319 fdtos %f62, %f27
320 fdtos %f62, %f28
321 fdtos %f62, %f29
322 fdtos %f62, %f30
323 fdtos %f62, %f31
324
325fitos_emul_fini:
326 ldd [%g6 + TI_FPREGS + (62 * 4)], %f62
327 done
328 .size do_fpother_check_fitos,.-do_fpother_check_fitos
329
330 .align 32
331 .globl do_fptrap
332 .type do_fptrap,#function
333do_fptrap:
334 TRAP_LOAD_THREAD_REG(%g6, %g1)
335 stx %fsr, [%g6 + TI_XFSR]
336do_fptrap_after_fsr:
337 ldub [%g6 + TI_FPSAVED], %g3
338 rd %fprs, %g1
339 or %g3, %g1, %g3
340 stb %g3, [%g6 + TI_FPSAVED]
341 rd %gsr, %g3
342 stx %g3, [%g6 + TI_GSR]
343 mov SECONDARY_CONTEXT, %g3
344
345661: ldxa [%g3] ASI_DMMU, %g5
346 .section .sun4v_1insn_patch, "ax"
347 .word 661b
348 ldxa [%g3] ASI_MMU, %g5
349 .previous
350
351 sethi %hi(sparc64_kern_sec_context), %g2
352 ldx [%g2 + %lo(sparc64_kern_sec_context)], %g2
353
354661: stxa %g2, [%g3] ASI_DMMU
355 .section .sun4v_1insn_patch, "ax"
356 .word 661b
357 stxa %g2, [%g3] ASI_MMU
358 .previous
359
360 membar #Sync
361 add %g6, TI_FPREGS, %g2
362 andcc %g1, FPRS_DL, %g0
363 be,pn %icc, 4f
364 mov 0x40, %g3
365 stda %f0, [%g2] ASI_BLK_S
366 stda %f16, [%g2 + %g3] ASI_BLK_S
367 andcc %g1, FPRS_DU, %g0
368 be,pn %icc, 5f
3694: add %g2, 128, %g2
370 stda %f32, [%g2] ASI_BLK_S
371 stda %f48, [%g2 + %g3] ASI_BLK_S
3725: mov SECONDARY_CONTEXT, %g1
373 membar #Sync
374
375661: stxa %g5, [%g1] ASI_DMMU
376 .section .sun4v_1insn_patch, "ax"
377 .word 661b
378 stxa %g5, [%g1] ASI_MMU
379 .previous
380
381 membar #Sync
382 ba,pt %xcc, etrap
383 wr %g0, 0, %fprs
384 .size do_fptrap,.-do_fptrap
diff --git a/arch/sparc64/kernel/getsetcc.S b/arch/sparc64/kernel/getsetcc.S
new file mode 100644
index 000000000000..a14d272d2061
--- /dev/null
+++ b/arch/sparc64/kernel/getsetcc.S
@@ -0,0 +1,24 @@
1 .globl getcc
2 .type getcc,#function
3getcc:
4 ldx [%o0 + PT_V9_TSTATE], %o1
5 srlx %o1, 32, %o1
6 and %o1, 0xf, %o1
7 retl
8 stx %o1, [%o0 + PT_V9_G1]
9 .size getcc,.-getcc
10
11 .globl setcc
12 .type setcc,#function
13setcc:
14 ldx [%o0 + PT_V9_TSTATE], %o1
15 ldx [%o0 + PT_V9_G1], %o2
16 or %g0, %ulo(TSTATE_ICC), %o3
17 sllx %o3, 32, %o3
18 andn %o1, %o3, %o1
19 sllx %o2, 32, %o2
20 and %o2, %o3, %o2
21 or %o1, %o2, %o1
22 retl
23 stx %o1, [%o0 + PT_V9_TSTATE]
24 .size setcc,.-setcc
diff --git a/arch/sparc64/kernel/head.S b/arch/sparc64/kernel/head.S
index 34f8ff57c56b..c9afef093d51 100644
--- a/arch/sparc64/kernel/head.S
+++ b/arch/sparc64/kernel/head.S
@@ -27,6 +27,10 @@
27#include <asm/ttable.h> 27#include <asm/ttable.h>
28#include <asm/mmu.h> 28#include <asm/mmu.h>
29#include <asm/cpudata.h> 29#include <asm/cpudata.h>
30#include <asm/pil.h>
31#include <asm/estate.h>
32#include <asm/sfafsr.h>
33#include <asm/unistd.h>
30 34
31/* This section from from _start to sparc64_boot_end should fit into 35/* This section from from _start to sparc64_boot_end should fit into
32 * 0x0000000000404000 to 0x0000000000408000. 36 * 0x0000000000404000 to 0x0000000000408000.
@@ -823,7 +827,16 @@ sparc64_boot_end:
823#include "etrap.S" 827#include "etrap.S"
824#include "rtrap.S" 828#include "rtrap.S"
825#include "winfixup.S" 829#include "winfixup.S"
826#include "entry.S" 830#include "fpu_traps.S"
831#include "ivec.S"
832#include "getsetcc.S"
833#include "utrap.S"
834#include "spiterrs.S"
835#include "cherrs.S"
836#include "misctrap.S"
837#include "syscalls.S"
838#include "helpers.S"
839#include "hvcalls.S"
827#include "sun4v_tlb_miss.S" 840#include "sun4v_tlb_miss.S"
828#include "sun4v_ivec.S" 841#include "sun4v_ivec.S"
829#include "ktlb.S" 842#include "ktlb.S"
diff --git a/arch/sparc64/kernel/helpers.S b/arch/sparc64/kernel/helpers.S
new file mode 100644
index 000000000000..314dd0c9fc5b
--- /dev/null
+++ b/arch/sparc64/kernel/helpers.S
@@ -0,0 +1,63 @@
1 .align 32
2 .globl __flushw_user
3 .type __flushw_user,#function
4__flushw_user:
5 rdpr %otherwin, %g1
6 brz,pn %g1, 2f
7 clr %g2
81: save %sp, -128, %sp
9 rdpr %otherwin, %g1
10 brnz,pt %g1, 1b
11 add %g2, 1, %g2
121: sub %g2, 1, %g2
13 brnz,pt %g2, 1b
14 restore %g0, %g0, %g0
152: retl
16 nop
17 .size __flushw_user,.-__flushw_user
18
19 /* Flush %fp and %i7 to the stack for all register
20 * windows active inside of the cpu. This allows
21 * show_stack_trace() to avoid using an expensive
22 * 'flushw'.
23 */
24 .globl stack_trace_flush
25 .type stack_trace_flush,#function
26stack_trace_flush:
27 rdpr %pstate, %o0
28 wrpr %o0, PSTATE_IE, %pstate
29
30 rdpr %cwp, %g1
31 rdpr %canrestore, %g2
32 sub %g1, 1, %g3
33
341: brz,pn %g2, 2f
35 sub %g2, 1, %g2
36 wrpr %g3, %cwp
37 stx %fp, [%sp + STACK_BIAS + RW_V9_I6]
38 stx %i7, [%sp + STACK_BIAS + RW_V9_I7]
39 ba,pt %xcc, 1b
40 sub %g3, 1, %g3
41
422: wrpr %g1, %cwp
43 wrpr %o0, %pstate
44
45 retl
46 nop
47 .size stack_trace_flush,.-stack_trace_flush
48
49#ifdef CONFIG_SMP
50 .globl hard_smp_processor_id
51 .type hard_smp_processor_id,#function
52hard_smp_processor_id:
53#endif
54 .globl real_hard_smp_processor_id
55 .type real_hard_smp_processor_id,#function
56real_hard_smp_processor_id:
57 __GET_CPUID(%o0)
58 retl
59 nop
60#ifdef CONFIG_SMP
61 .size hard_smp_processor_id,.-hard_smp_processor_id
62#endif
63 .size real_hard_smp_processor_id,.-real_hard_smp_processor_id
diff --git a/arch/sparc64/kernel/hvcalls.S b/arch/sparc64/kernel/hvcalls.S
new file mode 100644
index 000000000000..a2810f3ac70f
--- /dev/null
+++ b/arch/sparc64/kernel/hvcalls.S
@@ -0,0 +1,886 @@
1 /* %o0: devhandle
2 * %o1: devino
3 *
4 * returns %o0: sysino
5 */
6 .globl sun4v_devino_to_sysino
7 .type sun4v_devino_to_sysino,#function
8sun4v_devino_to_sysino:
9 mov HV_FAST_INTR_DEVINO2SYSINO, %o5
10 ta HV_FAST_TRAP
11 retl
12 mov %o1, %o0
13 .size sun4v_devino_to_sysino, .-sun4v_devino_to_sysino
14
15 /* %o0: sysino
16 *
17 * returns %o0: intr_enabled (HV_INTR_{DISABLED,ENABLED})
18 */
19 .globl sun4v_intr_getenabled
20 .type sun4v_intr_getenabled,#function
21sun4v_intr_getenabled:
22 mov HV_FAST_INTR_GETENABLED, %o5
23 ta HV_FAST_TRAP
24 retl
25 mov %o1, %o0
26 .size sun4v_intr_getenabled, .-sun4v_intr_getenabled
27
28 /* %o0: sysino
29 * %o1: intr_enabled (HV_INTR_{DISABLED,ENABLED})
30 */
31 .globl sun4v_intr_setenabled
32 .type sun4v_intr_setenabled,#function
33sun4v_intr_setenabled:
34 mov HV_FAST_INTR_SETENABLED, %o5
35 ta HV_FAST_TRAP
36 retl
37 nop
38 .size sun4v_intr_setenabled, .-sun4v_intr_setenabled
39
40 /* %o0: sysino
41 *
42 * returns %o0: intr_state (HV_INTR_STATE_*)
43 */
44 .globl sun4v_intr_getstate
45 .type sun4v_intr_getstate,#function
46sun4v_intr_getstate:
47 mov HV_FAST_INTR_GETSTATE, %o5
48 ta HV_FAST_TRAP
49 retl
50 mov %o1, %o0
51 .size sun4v_intr_getstate, .-sun4v_intr_getstate
52
53 /* %o0: sysino
54 * %o1: intr_state (HV_INTR_STATE_*)
55 */
56 .globl sun4v_intr_setstate
57 .type sun4v_intr_setstate,#function
58sun4v_intr_setstate:
59 mov HV_FAST_INTR_SETSTATE, %o5
60 ta HV_FAST_TRAP
61 retl
62 nop
63 .size sun4v_intr_setstate, .-sun4v_intr_setstate
64
65 /* %o0: sysino
66 *
67 * returns %o0: cpuid
68 */
69 .globl sun4v_intr_gettarget
70 .type sun4v_intr_gettarget,#function
71sun4v_intr_gettarget:
72 mov HV_FAST_INTR_GETTARGET, %o5
73 ta HV_FAST_TRAP
74 retl
75 mov %o1, %o0
76 .size sun4v_intr_gettarget, .-sun4v_intr_gettarget
77
78 /* %o0: sysino
79 * %o1: cpuid
80 */
81 .globl sun4v_intr_settarget
82 .type sun4v_intr_settarget,#function
83sun4v_intr_settarget:
84 mov HV_FAST_INTR_SETTARGET, %o5
85 ta HV_FAST_TRAP
86 retl
87 nop
88 .size sun4v_intr_settarget, .-sun4v_intr_settarget
89
90 /* %o0: cpuid
91 * %o1: pc
92 * %o2: rtba
93 * %o3: arg0
94 *
95 * returns %o0: status
96 */
97 .globl sun4v_cpu_start
98 .type sun4v_cpu_start,#function
99sun4v_cpu_start:
100 mov HV_FAST_CPU_START, %o5
101 ta HV_FAST_TRAP
102 retl
103 nop
104 .size sun4v_cpu_start, .-sun4v_cpu_start
105
106 /* %o0: cpuid
107 *
108 * returns %o0: status
109 */
110 .globl sun4v_cpu_stop
111 .type sun4v_cpu_stop,#function
112sun4v_cpu_stop:
113 mov HV_FAST_CPU_STOP, %o5
114 ta HV_FAST_TRAP
115 retl
116 nop
117 .size sun4v_cpu_stop, .-sun4v_cpu_stop
118
119 /* returns %o0: status */
120 .globl sun4v_cpu_yield
121 .type sun4v_cpu_yield, #function
122sun4v_cpu_yield:
123 mov HV_FAST_CPU_YIELD, %o5
124 ta HV_FAST_TRAP
125 retl
126 nop
127 .size sun4v_cpu_yield, .-sun4v_cpu_yield
128
129 /* %o0: type
130 * %o1: queue paddr
131 * %o2: num queue entries
132 *
133 * returns %o0: status
134 */
135 .globl sun4v_cpu_qconf
136 .type sun4v_cpu_qconf,#function
137sun4v_cpu_qconf:
138 mov HV_FAST_CPU_QCONF, %o5
139 ta HV_FAST_TRAP
140 retl
141 nop
142 .size sun4v_cpu_qconf, .-sun4v_cpu_qconf
143
144 /* %o0: num cpus in cpu list
145 * %o1: cpu list paddr
146 * %o2: mondo block paddr
147 *
148 * returns %o0: status
149 */
150 .globl sun4v_cpu_mondo_send
151 .type sun4v_cpu_mondo_send,#function
152sun4v_cpu_mondo_send:
153 mov HV_FAST_CPU_MONDO_SEND, %o5
154 ta HV_FAST_TRAP
155 retl
156 nop
157 .size sun4v_cpu_mondo_send, .-sun4v_cpu_mondo_send
158
159 /* %o0: CPU ID
160 *
161 * returns %o0: -status if status non-zero, else
162 * %o0: cpu state as HV_CPU_STATE_*
163 */
164 .globl sun4v_cpu_state
165 .type sun4v_cpu_state,#function
166sun4v_cpu_state:
167 mov HV_FAST_CPU_STATE, %o5
168 ta HV_FAST_TRAP
169 brnz,pn %o0, 1f
170 sub %g0, %o0, %o0
171 mov %o1, %o0
1721: retl
173 nop
174 .size sun4v_cpu_state, .-sun4v_cpu_state
175
176 /* %o0: virtual address
177 * %o1: must be zero
178 * %o2: TTE
179 * %o3: HV_MMU_* flags
180 *
181 * returns %o0: status
182 */
183 .globl sun4v_mmu_map_perm_addr
184 .type sun4v_mmu_map_perm_addr,#function
185sun4v_mmu_map_perm_addr:
186 mov HV_FAST_MMU_MAP_PERM_ADDR, %o5
187 ta HV_FAST_TRAP
188 retl
189 nop
190 .size sun4v_mmu_map_perm_addr, .-sun4v_mmu_map_perm_addr
191
192 /* %o0: number of TSB descriptions
193 * %o1: TSB descriptions real address
194 *
195 * returns %o0: status
196 */
197 .globl sun4v_mmu_tsb_ctx0
198 .type sun4v_mmu_tsb_ctx0,#function
199sun4v_mmu_tsb_ctx0:
200 mov HV_FAST_MMU_TSB_CTX0, %o5
201 ta HV_FAST_TRAP
202 retl
203 nop
204 .size sun4v_mmu_tsb_ctx0, .-sun4v_mmu_tsb_ctx0
205
206 /* %o0: API group number
207 * %o1: pointer to unsigned long major number storage
208 * %o2: pointer to unsigned long minor number storage
209 *
210 * returns %o0: status
211 */
212 .globl sun4v_get_version
213 .type sun4v_get_version,#function
214sun4v_get_version:
215 mov HV_CORE_GET_VER, %o5
216 mov %o1, %o3
217 mov %o2, %o4
218 ta HV_CORE_TRAP
219 stx %o1, [%o3]
220 retl
221 stx %o2, [%o4]
222 .size sun4v_get_version, .-sun4v_get_version
223
224 /* %o0: API group number
225 * %o1: desired major number
226 * %o2: desired minor number
227 * %o3: pointer to unsigned long actual minor number storage
228 *
229 * returns %o0: status
230 */
231 .globl sun4v_set_version
232 .type sun4v_set_version,#function
233sun4v_set_version:
234 mov HV_CORE_SET_VER, %o5
235 mov %o3, %o4
236 ta HV_CORE_TRAP
237 retl
238 stx %o1, [%o4]
239 .size sun4v_set_version, .-sun4v_set_version
240
241 /* %o0: pointer to unsigned long time
242 *
243 * returns %o0: status
244 */
245 .globl sun4v_tod_get
246 .type sun4v_tod_get,#function
247sun4v_tod_get:
248 mov %o0, %o4
249 mov HV_FAST_TOD_GET, %o5
250 ta HV_FAST_TRAP
251 stx %o1, [%o4]
252 retl
253 nop
254 .size sun4v_tod_get, .-sun4v_tod_get
255
256 /* %o0: time
257 *
258 * returns %o0: status
259 */
260 .globl sun4v_tod_set
261 .type sun4v_tod_set,#function
262sun4v_tod_set:
263 mov HV_FAST_TOD_SET, %o5
264 ta HV_FAST_TRAP
265 retl
266 nop
267 .size sun4v_tod_set, .-sun4v_tod_set
268
269 /* %o0: pointer to unsigned long status
270 *
271 * returns %o0: signed character
272 */
273 .globl sun4v_con_getchar
274 .type sun4v_con_getchar,#function
275sun4v_con_getchar:
276 mov %o0, %o4
277 mov HV_FAST_CONS_GETCHAR, %o5
278 clr %o0
279 clr %o1
280 ta HV_FAST_TRAP
281 stx %o0, [%o4]
282 retl
283 sra %o1, 0, %o0
284 .size sun4v_con_getchar, .-sun4v_con_getchar
285
286 /* %o0: signed long character
287 *
288 * returns %o0: status
289 */
290 .globl sun4v_con_putchar
291 .type sun4v_con_putchar,#function
292sun4v_con_putchar:
293 mov HV_FAST_CONS_PUTCHAR, %o5
294 ta HV_FAST_TRAP
295 retl
296 sra %o0, 0, %o0
297 .size sun4v_con_putchar, .-sun4v_con_putchar
298
299 /* %o0: buffer real address
300 * %o1: buffer size
301 * %o2: pointer to unsigned long bytes_read
302 *
303 * returns %o0: status
304 */
305 .globl sun4v_con_read
306 .type sun4v_con_read,#function
307sun4v_con_read:
308 mov %o2, %o4
309 mov HV_FAST_CONS_READ, %o5
310 ta HV_FAST_TRAP
311 brnz %o0, 1f
312 cmp %o1, -1 /* break */
313 be,a,pn %icc, 1f
314 mov %o1, %o0
315 cmp %o1, -2 /* hup */
316 be,a,pn %icc, 1f
317 mov %o1, %o0
318 stx %o1, [%o4]
3191: retl
320 nop
321 .size sun4v_con_read, .-sun4v_con_read
322
323 /* %o0: buffer real address
324 * %o1: buffer size
325 * %o2: pointer to unsigned long bytes_written
326 *
327 * returns %o0: status
328 */
329 .globl sun4v_con_write
330 .type sun4v_con_write,#function
331sun4v_con_write:
332 mov %o2, %o4
333 mov HV_FAST_CONS_WRITE, %o5
334 ta HV_FAST_TRAP
335 stx %o1, [%o4]
336 retl
337 nop
338 .size sun4v_con_write, .-sun4v_con_write
339
340 /* %o0: soft state
341 * %o1: address of description string
342 *
343 * returns %o0: status
344 */
345 .globl sun4v_mach_set_soft_state
346 .type sun4v_mach_set_soft_state,#function
347sun4v_mach_set_soft_state:
348 mov HV_FAST_MACH_SET_SOFT_STATE, %o5
349 ta HV_FAST_TRAP
350 retl
351 nop
352 .size sun4v_mach_set_soft_state, .-sun4v_mach_set_soft_state
353
354 /* %o0: exit code
355 *
356 * Does not return.
357 */
358 .globl sun4v_mach_exit
359 .type sun4v_mach_exit,#function
360sun4v_mach_exit:
361 mov HV_FAST_MACH_EXIT, %o5
362 ta HV_FAST_TRAP
363 retl
364 nop
365 .size sun4v_mach_exit, .-sun4v_mach_exit
366
367 /* %o0: buffer real address
368 * %o1: buffer length
369 * %o2: pointer to unsigned long real_buf_len
370 *
371 * returns %o0: status
372 */
373 .globl sun4v_mach_desc
374 .type sun4v_mach_desc,#function
375sun4v_mach_desc:
376 mov %o2, %o4
377 mov HV_FAST_MACH_DESC, %o5
378 ta HV_FAST_TRAP
379 stx %o1, [%o4]
380 retl
381 nop
382 .size sun4v_mach_desc, .-sun4v_mach_desc
383
384 /* %o0: new timeout in milliseconds
385 * %o1: pointer to unsigned long orig_timeout
386 *
387 * returns %o0: status
388 */
389 .globl sun4v_mach_set_watchdog
390 .type sun4v_mach_set_watchdog,#function
391sun4v_mach_set_watchdog:
392 mov %o1, %o4
393 mov HV_FAST_MACH_SET_WATCHDOG, %o5
394 ta HV_FAST_TRAP
395 stx %o1, [%o4]
396 retl
397 nop
398 .size sun4v_mach_set_watchdog, .-sun4v_mach_set_watchdog
399
400 /* No inputs and does not return. */
401 .globl sun4v_mach_sir
402 .type sun4v_mach_sir,#function
403sun4v_mach_sir:
404 mov %o1, %o4
405 mov HV_FAST_MACH_SIR, %o5
406 ta HV_FAST_TRAP
407 stx %o1, [%o4]
408 retl
409 nop
410 .size sun4v_mach_sir, .-sun4v_mach_sir
411
412 /* %o0: channel
413 * %o1: ra
414 * %o2: num_entries
415 *
416 * returns %o0: status
417 */
418 .globl sun4v_ldc_tx_qconf
419 .type sun4v_ldc_tx_qconf,#function
420sun4v_ldc_tx_qconf:
421 mov HV_FAST_LDC_TX_QCONF, %o5
422 ta HV_FAST_TRAP
423 retl
424 nop
425 .size sun4v_ldc_tx_qconf, .-sun4v_ldc_tx_qconf
426
427 /* %o0: channel
428 * %o1: pointer to unsigned long ra
429 * %o2: pointer to unsigned long num_entries
430 *
431 * returns %o0: status
432 */
433 .globl sun4v_ldc_tx_qinfo
434 .type sun4v_ldc_tx_qinfo,#function
435sun4v_ldc_tx_qinfo:
436 mov %o1, %g1
437 mov %o2, %g2
438 mov HV_FAST_LDC_TX_QINFO, %o5
439 ta HV_FAST_TRAP
440 stx %o1, [%g1]
441 stx %o2, [%g2]
442 retl
443 nop
444 .size sun4v_ldc_tx_qinfo, .-sun4v_ldc_tx_qinfo
445
446 /* %o0: channel
447 * %o1: pointer to unsigned long head_off
448 * %o2: pointer to unsigned long tail_off
449 * %o2: pointer to unsigned long chan_state
450 *
451 * returns %o0: status
452 */
453 .globl sun4v_ldc_tx_get_state
454 .type sun4v_ldc_tx_get_state,#function
455sun4v_ldc_tx_get_state:
456 mov %o1, %g1
457 mov %o2, %g2
458 mov %o3, %g3
459 mov HV_FAST_LDC_TX_GET_STATE, %o5
460 ta HV_FAST_TRAP
461 stx %o1, [%g1]
462 stx %o2, [%g2]
463 stx %o3, [%g3]
464 retl
465 nop
466 .size sun4v_ldc_tx_get_state, .-sun4v_ldc_tx_get_state
467
468 /* %o0: channel
469 * %o1: tail_off
470 *
471 * returns %o0: status
472 */
473 .globl sun4v_ldc_tx_set_qtail
474 .type sun4v_ldc_tx_set_qtail,#function
475sun4v_ldc_tx_set_qtail:
476 mov HV_FAST_LDC_TX_SET_QTAIL, %o5
477 ta HV_FAST_TRAP
478 retl
479 nop
480 .size sun4v_ldc_tx_set_qtail, .-sun4v_ldc_tx_set_qtail
481
482 /* %o0: channel
483 * %o1: ra
484 * %o2: num_entries
485 *
486 * returns %o0: status
487 */
488 .globl sun4v_ldc_rx_qconf
489 .type sun4v_ldc_rx_qconf,#function
490sun4v_ldc_rx_qconf:
491 mov HV_FAST_LDC_RX_QCONF, %o5
492 ta HV_FAST_TRAP
493 retl
494 nop
495 .size sun4v_ldc_rx_qconf, .-sun4v_ldc_rx_qconf
496
497 /* %o0: channel
498 * %o1: pointer to unsigned long ra
499 * %o2: pointer to unsigned long num_entries
500 *
501 * returns %o0: status
502 */
503 .globl sun4v_ldc_rx_qinfo
504 .type sun4v_ldc_rx_qinfo,#function
505sun4v_ldc_rx_qinfo:
506 mov %o1, %g1
507 mov %o2, %g2
508 mov HV_FAST_LDC_RX_QINFO, %o5
509 ta HV_FAST_TRAP
510 stx %o1, [%g1]
511 stx %o2, [%g2]
512 retl
513 nop
514 .size sun4v_ldc_rx_qinfo, .-sun4v_ldc_rx_qinfo
515
516 /* %o0: channel
517 * %o1: pointer to unsigned long head_off
518 * %o2: pointer to unsigned long tail_off
519 * %o2: pointer to unsigned long chan_state
520 *
521 * returns %o0: status
522 */
523 .globl sun4v_ldc_rx_get_state
524 .type sun4v_ldc_rx_get_state,#function
525sun4v_ldc_rx_get_state:
526 mov %o1, %g1
527 mov %o2, %g2
528 mov %o3, %g3
529 mov HV_FAST_LDC_RX_GET_STATE, %o5
530 ta HV_FAST_TRAP
531 stx %o1, [%g1]
532 stx %o2, [%g2]
533 stx %o3, [%g3]
534 retl
535 nop
536 .size sun4v_ldc_rx_get_state, .-sun4v_ldc_rx_get_state
537
538 /* %o0: channel
539 * %o1: head_off
540 *
541 * returns %o0: status
542 */
543 .globl sun4v_ldc_rx_set_qhead
544 .type sun4v_ldc_rx_set_qhead,#function
545sun4v_ldc_rx_set_qhead:
546 mov HV_FAST_LDC_RX_SET_QHEAD, %o5
547 ta HV_FAST_TRAP
548 retl
549 nop
550 .size sun4v_ldc_rx_set_qhead, .-sun4v_ldc_rx_set_qhead
551
552 /* %o0: channel
553 * %o1: ra
554 * %o2: num_entries
555 *
556 * returns %o0: status
557 */
558 .globl sun4v_ldc_set_map_table
559 .type sun4v_ldc_set_map_table,#function
560sun4v_ldc_set_map_table:
561 mov HV_FAST_LDC_SET_MAP_TABLE, %o5
562 ta HV_FAST_TRAP
563 retl
564 nop
565 .size sun4v_ldc_set_map_table, .-sun4v_ldc_set_map_table
566
567 /* %o0: channel
568 * %o1: pointer to unsigned long ra
569 * %o2: pointer to unsigned long num_entries
570 *
571 * returns %o0: status
572 */
573 .globl sun4v_ldc_get_map_table
574 .type sun4v_ldc_get_map_table,#function
575sun4v_ldc_get_map_table:
576 mov %o1, %g1
577 mov %o2, %g2
578 mov HV_FAST_LDC_GET_MAP_TABLE, %o5
579 ta HV_FAST_TRAP
580 stx %o1, [%g1]
581 stx %o2, [%g2]
582 retl
583 nop
584 .size sun4v_ldc_get_map_table, .-sun4v_ldc_get_map_table
585
586 /* %o0: channel
587 * %o1: dir_code
588 * %o2: tgt_raddr
589 * %o3: lcl_raddr
590 * %o4: len
591 * %o5: pointer to unsigned long actual_len
592 *
593 * returns %o0: status
594 */
595 .globl sun4v_ldc_copy
596 .type sun4v_ldc_copy,#function
597sun4v_ldc_copy:
598 mov %o5, %g1
599 mov HV_FAST_LDC_COPY, %o5
600 ta HV_FAST_TRAP
601 stx %o1, [%g1]
602 retl
603 nop
604 .size sun4v_ldc_copy, .-sun4v_ldc_copy
605
606 /* %o0: channel
607 * %o1: cookie
608 * %o2: pointer to unsigned long ra
609 * %o3: pointer to unsigned long perm
610 *
611 * returns %o0: status
612 */
613 .globl sun4v_ldc_mapin
614 .type sun4v_ldc_mapin,#function
615sun4v_ldc_mapin:
616 mov %o2, %g1
617 mov %o3, %g2
618 mov HV_FAST_LDC_MAPIN, %o5
619 ta HV_FAST_TRAP
620 stx %o1, [%g1]
621 stx %o2, [%g2]
622 retl
623 nop
624 .size sun4v_ldc_mapin, .-sun4v_ldc_mapin
625
626 /* %o0: ra
627 *
628 * returns %o0: status
629 */
630 .globl sun4v_ldc_unmap
631 .type sun4v_ldc_unmap,#function
632sun4v_ldc_unmap:
633 mov HV_FAST_LDC_UNMAP, %o5
634 ta HV_FAST_TRAP
635 retl
636 nop
637 .size sun4v_ldc_unmap, .-sun4v_ldc_unmap
638
639 /* %o0: channel
640 * %o1: cookie
641 * %o2: mte_cookie
642 *
643 * returns %o0: status
644 */
645 .globl sun4v_ldc_revoke
646 .type sun4v_ldc_revoke,#function
647sun4v_ldc_revoke:
648 mov HV_FAST_LDC_REVOKE, %o5
649 ta HV_FAST_TRAP
650 retl
651 nop
652 .size sun4v_ldc_revoke, .-sun4v_ldc_revoke
653
654 /* %o0: device handle
655 * %o1: device INO
656 * %o2: pointer to unsigned long cookie
657 *
658 * returns %o0: status
659 */
660 .globl sun4v_vintr_get_cookie
661 .type sun4v_vintr_get_cookie,#function
662sun4v_vintr_get_cookie:
663 mov %o2, %g1
664 mov HV_FAST_VINTR_GET_COOKIE, %o5
665 ta HV_FAST_TRAP
666 stx %o1, [%g1]
667 retl
668 nop
669 .size sun4v_vintr_get_cookie, .-sun4v_vintr_get_cookie
670
671 /* %o0: device handle
672 * %o1: device INO
673 * %o2: cookie
674 *
675 * returns %o0: status
676 */
677 .globl sun4v_vintr_set_cookie
678 .type sun4v_vintr_set_cookie,#function
679sun4v_vintr_set_cookie:
680 mov HV_FAST_VINTR_SET_COOKIE, %o5
681 ta HV_FAST_TRAP
682 retl
683 nop
684 .size sun4v_vintr_set_cookie, .-sun4v_vintr_set_cookie
685
686 /* %o0: device handle
687 * %o1: device INO
688 * %o2: pointer to unsigned long valid_state
689 *
690 * returns %o0: status
691 */
692 .globl sun4v_vintr_get_valid
693 .type sun4v_vintr_get_valid,#function
694sun4v_vintr_get_valid:
695 mov %o2, %g1
696 mov HV_FAST_VINTR_GET_VALID, %o5
697 ta HV_FAST_TRAP
698 stx %o1, [%g1]
699 retl
700 nop
701 .size sun4v_vintr_get_valid, .-sun4v_vintr_get_valid
702
703 /* %o0: device handle
704 * %o1: device INO
705 * %o2: valid_state
706 *
707 * returns %o0: status
708 */
709 .globl sun4v_vintr_set_valid
710 .type sun4v_vintr_set_valid,#function
711sun4v_vintr_set_valid:
712 mov HV_FAST_VINTR_SET_VALID, %o5
713 ta HV_FAST_TRAP
714 retl
715 nop
716 .size sun4v_vintr_set_valid, .-sun4v_vintr_set_valid
717
718 /* %o0: device handle
719 * %o1: device INO
720 * %o2: pointer to unsigned long state
721 *
722 * returns %o0: status
723 */
724 .globl sun4v_vintr_get_state
725 .type sun4v_vintr_get_state,#function
726sun4v_vintr_get_state:
727 mov %o2, %g1
728 mov HV_FAST_VINTR_GET_STATE, %o5
729 ta HV_FAST_TRAP
730 stx %o1, [%g1]
731 retl
732 nop
733 .size sun4v_vintr_get_state, .-sun4v_vintr_get_state
734
735 /* %o0: device handle
736 * %o1: device INO
737 * %o2: state
738 *
739 * returns %o0: status
740 */
741 .globl sun4v_vintr_set_state
742 .type sun4v_vintr_set_state,#function
743sun4v_vintr_set_state:
744 mov HV_FAST_VINTR_SET_STATE, %o5
745 ta HV_FAST_TRAP
746 retl
747 nop
748 .size sun4v_vintr_set_state, .-sun4v_vintr_set_state
749
750 /* %o0: device handle
751 * %o1: device INO
752 * %o2: pointer to unsigned long cpuid
753 *
754 * returns %o0: status
755 */
756 .globl sun4v_vintr_get_target
757 .type sun4v_vintr_get_target,#function
758sun4v_vintr_get_target:
759 mov %o2, %g1
760 mov HV_FAST_VINTR_GET_TARGET, %o5
761 ta HV_FAST_TRAP
762 stx %o1, [%g1]
763 retl
764 nop
765 .size sun4v_vintr_get_target, .-sun4v_vintr_get_target
766
767 /* %o0: device handle
768 * %o1: device INO
769 * %o2: cpuid
770 *
771 * returns %o0: status
772 */
773 .globl sun4v_vintr_set_target
774 .type sun4v_vintr_set_target,#function
775sun4v_vintr_set_target:
776 mov HV_FAST_VINTR_SET_TARGET, %o5
777 ta HV_FAST_TRAP
778 retl
779 nop
780 .size sun4v_vintr_set_target, .-sun4v_vintr_set_target
781
782 /* %o0: NCS sub-function
783 * %o1: sub-function arg real-address
784 * %o2: sub-function arg size
785 *
786 * returns %o0: status
787 */
788 .globl sun4v_ncs_request
789 .type sun4v_ncs_request,#function
790sun4v_ncs_request:
791 mov HV_FAST_NCS_REQUEST, %o5
792 ta HV_FAST_TRAP
793 retl
794 nop
795 .size sun4v_ncs_request, .-sun4v_ncs_request
796
797 .globl sun4v_svc_send
798 .type sun4v_svc_send,#function
799sun4v_svc_send:
800 save %sp, -192, %sp
801 mov %i0, %o0
802 mov %i1, %o1
803 mov %i2, %o2
804 mov HV_FAST_SVC_SEND, %o5
805 ta HV_FAST_TRAP
806 stx %o1, [%i3]
807 ret
808 restore
809 .size sun4v_svc_send, .-sun4v_svc_send
810
811 .globl sun4v_svc_recv
812 .type sun4v_svc_recv,#function
813sun4v_svc_recv:
814 save %sp, -192, %sp
815 mov %i0, %o0
816 mov %i1, %o1
817 mov %i2, %o2
818 mov HV_FAST_SVC_RECV, %o5
819 ta HV_FAST_TRAP
820 stx %o1, [%i3]
821 ret
822 restore
823 .size sun4v_svc_recv, .-sun4v_svc_recv
824
825 .globl sun4v_svc_getstatus
826 .type sun4v_svc_getstatus,#function
827sun4v_svc_getstatus:
828 mov HV_FAST_SVC_GETSTATUS, %o5
829 mov %o1, %o4
830 ta HV_FAST_TRAP
831 stx %o1, [%o4]
832 retl
833 nop
834 .size sun4v_svc_getstatus, .-sun4v_svc_getstatus
835
836 .globl sun4v_svc_setstatus
837 .type sun4v_svc_setstatus,#function
838sun4v_svc_setstatus:
839 mov HV_FAST_SVC_SETSTATUS, %o5
840 ta HV_FAST_TRAP
841 retl
842 nop
843 .size sun4v_svc_setstatus, .-sun4v_svc_setstatus
844
845 .globl sun4v_svc_clrstatus
846 .type sun4v_svc_clrstatus,#function
847sun4v_svc_clrstatus:
848 mov HV_FAST_SVC_CLRSTATUS, %o5
849 ta HV_FAST_TRAP
850 retl
851 nop
852 .size sun4v_svc_clrstatus, .-sun4v_svc_clrstatus
853
854 .globl sun4v_mmustat_conf
855 .type sun4v_mmustat_conf,#function
856sun4v_mmustat_conf:
857 mov %o1, %o4
858 mov HV_FAST_MMUSTAT_CONF, %o5
859 ta HV_FAST_TRAP
860 stx %o1, [%o4]
861 retl
862 nop
863 .size sun4v_mmustat_conf, .-sun4v_mmustat_conf
864
865 .globl sun4v_mmustat_info
866 .type sun4v_mmustat_info,#function
867sun4v_mmustat_info:
868 mov %o0, %o4
869 mov HV_FAST_MMUSTAT_INFO, %o5
870 ta HV_FAST_TRAP
871 stx %o1, [%o4]
872 retl
873 nop
874 .size sun4v_mmustat_info, .-sun4v_mmustat_info
875
876 .globl sun4v_mmu_demap_all
877 .type sun4v_mmu_demap_all,#function
878sun4v_mmu_demap_all:
879 clr %o0
880 clr %o1
881 mov HV_MMU_ALL, %o2
882 mov HV_FAST_MMU_DEMAP_ALL, %o5
883 ta HV_FAST_TRAP
884 retl
885 nop
886 .size sun4v_mmu_demap_all, .-sun4v_mmu_demap_all
diff --git a/arch/sparc64/kernel/ivec.S b/arch/sparc64/kernel/ivec.S
new file mode 100644
index 000000000000..d29f92ebca5e
--- /dev/null
+++ b/arch/sparc64/kernel/ivec.S
@@ -0,0 +1,51 @@
1 /* The registers for cross calls will be:
2 *
3 * DATA 0: [low 32-bits] Address of function to call, jmp to this
4 * [high 32-bits] MMU Context Argument 0, place in %g5
5 * DATA 1: Address Argument 1, place in %g1
6 * DATA 2: Address Argument 2, place in %g7
7 *
8 * With this method we can do most of the cross-call tlb/cache
9 * flushing very quickly.
10 */
11 .align 32
12 .globl do_ivec
13 .type do_ivec,#function
14do_ivec:
15 mov 0x40, %g3
16 ldxa [%g3 + %g0] ASI_INTR_R, %g3
17 sethi %hi(KERNBASE), %g4
18 cmp %g3, %g4
19 bgeu,pn %xcc, do_ivec_xcall
20 srlx %g3, 32, %g5
21 stxa %g0, [%g0] ASI_INTR_RECEIVE
22 membar #Sync
23
24 sethi %hi(ivector_table_pa), %g2
25 ldx [%g2 + %lo(ivector_table_pa)], %g2
26 sllx %g3, 4, %g3
27 add %g2, %g3, %g3
28
29 TRAP_LOAD_IRQ_WORK_PA(%g6, %g1)
30
31 ldx [%g6], %g5
32 stxa %g5, [%g3] ASI_PHYS_USE_EC
33 stx %g3, [%g6]
34 wr %g0, 1 << PIL_DEVICE_IRQ, %set_softint
35 retry
36do_ivec_xcall:
37 mov 0x50, %g1
38 ldxa [%g1 + %g0] ASI_INTR_R, %g1
39 srl %g3, 0, %g3
40
41 mov 0x60, %g7
42 ldxa [%g7 + %g0] ASI_INTR_R, %g7
43 stxa %g0, [%g0] ASI_INTR_RECEIVE
44 membar #Sync
45 ba,pt %xcc, 1f
46 nop
47
48 .align 32
491: jmpl %g3, %g0
50 nop
51 .size do_ivec,.-do_ivec
diff --git a/arch/sparc64/kernel/kgdb.c b/arch/sparc64/kernel/kgdb.c
new file mode 100644
index 000000000000..fefbe6dc51be
--- /dev/null
+++ b/arch/sparc64/kernel/kgdb.c
@@ -0,0 +1,186 @@
1/* kgdb.c: KGDB support for 64-bit sparc.
2 *
3 * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
4 */
5
6#include <linux/kgdb.h>
7#include <linux/kdebug.h>
8
9#include <asm/kdebug.h>
10#include <asm/ptrace.h>
11#include <asm/irq.h>
12
13void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)
14{
15 struct reg_window *win;
16 int i;
17
18 gdb_regs[GDB_G0] = 0;
19 for (i = 0; i < 15; i++)
20 gdb_regs[GDB_G1 + i] = regs->u_regs[UREG_G1 + i];
21
22 win = (struct reg_window *) (regs->u_regs[UREG_FP] + STACK_BIAS);
23 for (i = 0; i < 8; i++)
24 gdb_regs[GDB_L0 + i] = win->locals[i];
25 for (i = 0; i < 8; i++)
26 gdb_regs[GDB_I0 + i] = win->ins[i];
27
28 for (i = GDB_F0; i <= GDB_F62; i++)
29 gdb_regs[i] = 0;
30
31 gdb_regs[GDB_PC] = regs->tpc;
32 gdb_regs[GDB_NPC] = regs->tnpc;
33 gdb_regs[GDB_STATE] = regs->tstate;
34 gdb_regs[GDB_FSR] = 0;
35 gdb_regs[GDB_FPRS] = 0;
36 gdb_regs[GDB_Y] = regs->y;
37}
38
39void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p)
40{
41 struct thread_info *t = task_thread_info(p);
42 extern unsigned int switch_to_pc;
43 extern unsigned int ret_from_syscall;
44 struct reg_window *win;
45 unsigned long pc, cwp;
46 int i;
47
48 for (i = GDB_G0; i < GDB_G6; i++)
49 gdb_regs[i] = 0;
50 gdb_regs[GDB_G6] = (unsigned long) t;
51 gdb_regs[GDB_G7] = (unsigned long) p;
52 for (i = GDB_O0; i < GDB_SP; i++)
53 gdb_regs[i] = 0;
54 gdb_regs[GDB_SP] = t->ksp;
55 gdb_regs[GDB_O7] = 0;
56
57 win = (struct reg_window *) (t->ksp + STACK_BIAS);
58 for (i = 0; i < 8; i++)
59 gdb_regs[GDB_L0 + i] = win->locals[i];
60 for (i = 0; i < 8; i++)
61 gdb_regs[GDB_I0 + i] = win->ins[i];
62
63 for (i = GDB_F0; i <= GDB_F62; i++)
64 gdb_regs[i] = 0;
65
66 if (t->new_child)
67 pc = (unsigned long) &ret_from_syscall;
68 else
69 pc = (unsigned long) &switch_to_pc;
70
71 gdb_regs[GDB_PC] = pc;
72 gdb_regs[GDB_NPC] = pc + 4;
73
74 cwp = __thread_flag_byte_ptr(t)[TI_FLAG_BYTE_CWP];
75
76 gdb_regs[GDB_STATE] = (TSTATE_PRIV | TSTATE_IE | cwp);
77 gdb_regs[GDB_FSR] = 0;
78 gdb_regs[GDB_FPRS] = 0;
79 gdb_regs[GDB_Y] = 0;
80}
81
82void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs)
83{
84 struct reg_window *win;
85 int i;
86
87 for (i = 0; i < 15; i++)
88 regs->u_regs[UREG_G1 + i] = gdb_regs[GDB_G1 + i];
89
90 /* If the TSTATE register is changing, we have to preserve
91 * the CWP field, otherwise window save/restore explodes.
92 */
93 if (regs->tstate != gdb_regs[GDB_STATE]) {
94 unsigned long cwp = regs->tstate & TSTATE_CWP;
95
96 regs->tstate = (gdb_regs[GDB_STATE] & ~TSTATE_CWP) | cwp;
97 }
98
99 regs->tpc = gdb_regs[GDB_PC];
100 regs->tnpc = gdb_regs[GDB_NPC];
101 regs->y = gdb_regs[GDB_Y];
102
103 win = (struct reg_window *) (regs->u_regs[UREG_FP] + STACK_BIAS);
104 for (i = 0; i < 8; i++)
105 win->locals[i] = gdb_regs[GDB_L0 + i];
106 for (i = 0; i < 8; i++)
107 win->ins[i] = gdb_regs[GDB_I0 + i];
108}
109
110#ifdef CONFIG_SMP
111void smp_kgdb_capture_client(struct pt_regs *regs)
112{
113 unsigned long flags;
114
115 __asm__ __volatile__("rdpr %%pstate, %0\n\t"
116 "wrpr %0, %1, %%pstate"
117 : "=r" (flags)
118 : "i" (PSTATE_IE));
119
120 flushw_all();
121
122 if (atomic_read(&kgdb_active) != -1)
123 kgdb_nmicallback(raw_smp_processor_id(), regs);
124
125 __asm__ __volatile__("wrpr %0, 0, %%pstate"
126 : : "r" (flags));
127}
128#endif
129
130int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
131 char *remcomInBuffer, char *remcomOutBuffer,
132 struct pt_regs *linux_regs)
133{
134 unsigned long addr;
135 char *ptr;
136
137 switch (remcomInBuffer[0]) {
138 case 'c':
139 /* try to read optional parameter, pc unchanged if no parm */
140 ptr = &remcomInBuffer[1];
141 if (kgdb_hex2long(&ptr, &addr)) {
142 linux_regs->tpc = addr;
143 linux_regs->tnpc = addr + 4;
144 }
145 /* fallthru */
146
147 case 'D':
148 case 'k':
149 if (linux_regs->tpc == (unsigned long) arch_kgdb_breakpoint) {
150 linux_regs->tpc = linux_regs->tnpc;
151 linux_regs->tnpc += 4;
152 }
153 return 0;
154 }
155 return -1;
156}
157
158asmlinkage void kgdb_trap(unsigned long trap_level, struct pt_regs *regs)
159{
160 unsigned long flags;
161
162 if (user_mode(regs)) {
163 bad_trap(regs, trap_level);
164 return;
165 }
166
167 flushw_all();
168
169 local_irq_save(flags);
170 kgdb_handle_exception(0x172, SIGTRAP, 0, regs);
171 local_irq_restore(flags);
172}
173
174int kgdb_arch_init(void)
175{
176 return 0;
177}
178
179void kgdb_arch_exit(void)
180{
181}
182
183struct kgdb_arch arch_kgdb_ops = {
184 /* Breakpoint instruction: ta 0x72 */
185 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x72 },
186};
diff --git a/arch/sparc64/kernel/misctrap.S b/arch/sparc64/kernel/misctrap.S
new file mode 100644
index 000000000000..753b4f031bfb
--- /dev/null
+++ b/arch/sparc64/kernel/misctrap.S
@@ -0,0 +1,97 @@
1#ifdef CONFIG_KGDB
2 .globl arch_kgdb_breakpoint
3 .type arch_kgdb_breakpoint,#function
4arch_kgdb_breakpoint:
5 ta 0x72
6 retl
7 nop
8 .size arch_kgdb_breakpoint,.-arch_kgdb_breakpoint
9#endif
10
11 .type __do_privact,#function
12__do_privact:
13 mov TLB_SFSR, %g3
14 stxa %g0, [%g3] ASI_DMMU ! Clear FaultValid bit
15 membar #Sync
16 sethi %hi(109f), %g7
17 ba,pt %xcc, etrap
18109: or %g7, %lo(109b), %g7
19 call do_privact
20 add %sp, PTREGS_OFF, %o0
21 ba,pt %xcc, rtrap
22 nop
23 .size __do_privact,.-__do_privact
24
25 .type do_mna,#function
26do_mna:
27 rdpr %tl, %g3
28 cmp %g3, 1
29
30 /* Setup %g4/%g5 now as they are used in the
31 * winfixup code.
32 */
33 mov TLB_SFSR, %g3
34 mov DMMU_SFAR, %g4
35 ldxa [%g4] ASI_DMMU, %g4
36 ldxa [%g3] ASI_DMMU, %g5
37 stxa %g0, [%g3] ASI_DMMU ! Clear FaultValid bit
38 membar #Sync
39 bgu,pn %icc, winfix_mna
40 rdpr %tpc, %g3
41
421: sethi %hi(109f), %g7
43 ba,pt %xcc, etrap
44109: or %g7, %lo(109b), %g7
45 mov %l4, %o1
46 mov %l5, %o2
47 call mem_address_unaligned
48 add %sp, PTREGS_OFF, %o0
49 ba,pt %xcc, rtrap
50 nop
51 .size do_mna,.-do_mna
52
53 .type do_lddfmna,#function
54do_lddfmna:
55 sethi %hi(109f), %g7
56 mov TLB_SFSR, %g4
57 ldxa [%g4] ASI_DMMU, %g5
58 stxa %g0, [%g4] ASI_DMMU ! Clear FaultValid bit
59 membar #Sync
60 mov DMMU_SFAR, %g4
61 ldxa [%g4] ASI_DMMU, %g4
62 ba,pt %xcc, etrap
63109: or %g7, %lo(109b), %g7
64 mov %l4, %o1
65 mov %l5, %o2
66 call handle_lddfmna
67 add %sp, PTREGS_OFF, %o0
68 ba,pt %xcc, rtrap
69 nop
70 .size do_lddfmna,.-do_lddfmna
71
72 .type do_stdfmna,#function
73do_stdfmna:
74 sethi %hi(109f), %g7
75 mov TLB_SFSR, %g4
76 ldxa [%g4] ASI_DMMU, %g5
77 stxa %g0, [%g4] ASI_DMMU ! Clear FaultValid bit
78 membar #Sync
79 mov DMMU_SFAR, %g4
80 ldxa [%g4] ASI_DMMU, %g4
81 ba,pt %xcc, etrap
82109: or %g7, %lo(109b), %g7
83 mov %l4, %o1
84 mov %l5, %o2
85 call handle_stdfmna
86 add %sp, PTREGS_OFF, %o0
87 ba,pt %xcc, rtrap
88 nop
89 .size do_stdfmna,.-do_stdfmna
90
91 .type breakpoint_trap,#function
92breakpoint_trap:
93 call sparc_breakpoint
94 add %sp, PTREGS_OFF, %o0
95 ba,pt %xcc, rtrap
96 nop
97 .size breakpoint_trap,.-breakpoint_trap
diff --git a/arch/sparc64/kernel/pci.c b/arch/sparc64/kernel/pci.c
index dbf2fc2f4d87..112b09f16f36 100644
--- a/arch/sparc64/kernel/pci.c
+++ b/arch/sparc64/kernel/pci.c
@@ -350,8 +350,7 @@ static void pci_parse_of_addrs(struct of_device *op,
350 350
351struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm, 351struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,
352 struct device_node *node, 352 struct device_node *node,
353 struct pci_bus *bus, int devfn, 353 struct pci_bus *bus, int devfn)
354 int host_controller)
355{ 354{
356 struct dev_archdata *sd; 355 struct dev_archdata *sd;
357 struct pci_dev *dev; 356 struct pci_dev *dev;
@@ -390,43 +389,28 @@ struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,
390 dev->devfn = devfn; 389 dev->devfn = devfn;
391 dev->multifunction = 0; /* maybe a lie? */ 390 dev->multifunction = 0; /* maybe a lie? */
392 391
393 if (host_controller) { 392 dev->vendor = of_getintprop_default(node, "vendor-id", 0xffff);
394 if (tlb_type != hypervisor) { 393 dev->device = of_getintprop_default(node, "device-id", 0xffff);
395 pci_read_config_word(dev, PCI_VENDOR_ID, 394 dev->subsystem_vendor =
396 &dev->vendor); 395 of_getintprop_default(node, "subsystem-vendor-id", 0);
397 pci_read_config_word(dev, PCI_DEVICE_ID, 396 dev->subsystem_device =
398 &dev->device); 397 of_getintprop_default(node, "subsystem-id", 0);
399 } else { 398
400 dev->vendor = PCI_VENDOR_ID_SUN; 399 dev->cfg_size = pci_cfg_space_size(dev);
401 dev->device = 0x80f0; 400
402 } 401 /* We can't actually use the firmware value, we have
403 dev->cfg_size = 256; 402 * to read what is in the register right now. One
404 dev->class = PCI_CLASS_BRIDGE_HOST << 8; 403 * reason is that in the case of IDE interfaces the
405 sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(bus), 404 * firmware can sample the value before the the IDE
406 0x00, PCI_SLOT(devfn), PCI_FUNC(devfn)); 405 * interface is programmed into native mode.
407 } else { 406 */
408 dev->vendor = of_getintprop_default(node, "vendor-id", 0xffff); 407 pci_read_config_dword(dev, PCI_CLASS_REVISION, &class);
409 dev->device = of_getintprop_default(node, "device-id", 0xffff); 408 dev->class = class >> 8;
410 dev->subsystem_vendor = 409 dev->revision = class & 0xff;
411 of_getintprop_default(node, "subsystem-vendor-id", 0); 410
412 dev->subsystem_device = 411 sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(bus),
413 of_getintprop_default(node, "subsystem-id", 0); 412 dev->bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn));
414
415 dev->cfg_size = pci_cfg_space_size(dev);
416
417 /* We can't actually use the firmware value, we have
418 * to read what is in the register right now. One
419 * reason is that in the case of IDE interfaces the
420 * firmware can sample the value before the the IDE
421 * interface is programmed into native mode.
422 */
423 pci_read_config_dword(dev, PCI_CLASS_REVISION, &class);
424 dev->class = class >> 8;
425 dev->revision = class & 0xff;
426 413
427 sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(bus),
428 dev->bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn));
429 }
430 if (ofpci_verbose) 414 if (ofpci_verbose)
431 printk(" class: 0x%x device name: %s\n", 415 printk(" class: 0x%x device name: %s\n",
432 dev->class, pci_name(dev)); 416 dev->class, pci_name(dev));
@@ -441,26 +425,21 @@ struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,
441 dev->current_state = 4; /* unknown power state */ 425 dev->current_state = 4; /* unknown power state */
442 dev->error_state = pci_channel_io_normal; 426 dev->error_state = pci_channel_io_normal;
443 427
444 if (host_controller) { 428 if (!strcmp(type, "pci") || !strcmp(type, "pciex")) {
429 /* a PCI-PCI bridge */
445 dev->hdr_type = PCI_HEADER_TYPE_BRIDGE; 430 dev->hdr_type = PCI_HEADER_TYPE_BRIDGE;
446 dev->rom_base_reg = PCI_ROM_ADDRESS1; 431 dev->rom_base_reg = PCI_ROM_ADDRESS1;
447 dev->irq = PCI_IRQ_NONE; 432 } else if (!strcmp(type, "cardbus")) {
433 dev->hdr_type = PCI_HEADER_TYPE_CARDBUS;
448 } else { 434 } else {
449 if (!strcmp(type, "pci") || !strcmp(type, "pciex")) { 435 dev->hdr_type = PCI_HEADER_TYPE_NORMAL;
450 /* a PCI-PCI bridge */ 436 dev->rom_base_reg = PCI_ROM_ADDRESS;
451 dev->hdr_type = PCI_HEADER_TYPE_BRIDGE;
452 dev->rom_base_reg = PCI_ROM_ADDRESS1;
453 } else if (!strcmp(type, "cardbus")) {
454 dev->hdr_type = PCI_HEADER_TYPE_CARDBUS;
455 } else {
456 dev->hdr_type = PCI_HEADER_TYPE_NORMAL;
457 dev->rom_base_reg = PCI_ROM_ADDRESS;
458 437
459 dev->irq = sd->op->irqs[0]; 438 dev->irq = sd->op->irqs[0];
460 if (dev->irq == 0xffffffff) 439 if (dev->irq == 0xffffffff)
461 dev->irq = PCI_IRQ_NONE; 440 dev->irq = PCI_IRQ_NONE;
462 }
463 } 441 }
442
464 pci_parse_of_addrs(sd->op, node, dev); 443 pci_parse_of_addrs(sd->op, node, dev);
465 444
466 if (ofpci_verbose) 445 if (ofpci_verbose)
@@ -749,7 +728,7 @@ static void __devinit pci_of_scan_bus(struct pci_pbm_info *pbm,
749 prev_devfn = devfn; 728 prev_devfn = devfn;
750 729
751 /* create a new pci_dev for this device */ 730 /* create a new pci_dev for this device */
752 dev = of_create_pci_dev(pbm, child, bus, devfn, 0); 731 dev = of_create_pci_dev(pbm, child, bus, devfn);
753 if (!dev) 732 if (!dev)
754 continue; 733 continue;
755 if (ofpci_verbose) 734 if (ofpci_verbose)
@@ -796,48 +775,9 @@ static void __devinit pci_bus_register_of_sysfs(struct pci_bus *bus)
796 pci_bus_register_of_sysfs(child_bus); 775 pci_bus_register_of_sysfs(child_bus);
797} 776}
798 777
799int pci_host_bridge_read_pci_cfg(struct pci_bus *bus_dev,
800 unsigned int devfn,
801 int where, int size,
802 u32 *value)
803{
804 static u8 fake_pci_config[] = {
805 0x8e, 0x10, /* Vendor: 0x108e (Sun) */
806 0xf0, 0x80, /* Device: 0x80f0 (Fire) */
807 0x46, 0x01, /* Command: 0x0146 (SERR, PARITY, MASTER, MEM) */
808 0xa0, 0x22, /* Status: 0x02a0 (DEVSEL_MED, FB2B, 66MHZ) */
809 0x00, 0x00, 0x00, 0x06, /* Class: 0x06000000 host bridge */
810 0x00, /* Cacheline: 0x00 */
811 0x40, /* Latency: 0x40 */
812 0x00, /* Header-Type: 0x00 normal */
813 };
814
815 *value = 0;
816 if (where >= 0 && where < sizeof(fake_pci_config) &&
817 (where + size) >= 0 &&
818 (where + size) < sizeof(fake_pci_config) &&
819 size <= sizeof(u32)) {
820 while (size--) {
821 *value <<= 8;
822 *value |= fake_pci_config[where + size];
823 }
824 }
825
826 return PCIBIOS_SUCCESSFUL;
827}
828
829int pci_host_bridge_write_pci_cfg(struct pci_bus *bus_dev,
830 unsigned int devfn,
831 int where, int size,
832 u32 value)
833{
834 return PCIBIOS_SUCCESSFUL;
835}
836
837struct pci_bus * __devinit pci_scan_one_pbm(struct pci_pbm_info *pbm) 778struct pci_bus * __devinit pci_scan_one_pbm(struct pci_pbm_info *pbm)
838{ 779{
839 struct device_node *node = pbm->prom_node; 780 struct device_node *node = pbm->prom_node;
840 struct pci_dev *host_pdev;
841 struct pci_bus *bus; 781 struct pci_bus *bus;
842 782
843 printk("PCI: Scanning PBM %s\n", node->full_name); 783 printk("PCI: Scanning PBM %s\n", node->full_name);
@@ -855,10 +795,6 @@ struct pci_bus * __devinit pci_scan_one_pbm(struct pci_pbm_info *pbm)
855 bus->resource[0] = &pbm->io_space; 795 bus->resource[0] = &pbm->io_space;
856 bus->resource[1] = &pbm->mem_space; 796 bus->resource[1] = &pbm->mem_space;
857 797
858 /* Create the dummy host bridge and link it in. */
859 host_pdev = of_create_pci_dev(pbm, node, bus, 0x00, 1);
860 bus->self = host_pdev;
861
862 pci_of_scan_bus(pbm, node, bus); 798 pci_of_scan_bus(pbm, node, bus);
863 pci_bus_add_devices(bus); 799 pci_bus_add_devices(bus);
864 pci_bus_register_of_sysfs(bus); 800 pci_bus_register_of_sysfs(bus);
diff --git a/arch/sparc64/kernel/pci_common.c b/arch/sparc64/kernel/pci_common.c
index 923e0bcc3bfd..19fa621d6a60 100644
--- a/arch/sparc64/kernel/pci_common.c
+++ b/arch/sparc64/kernel/pci_common.c
@@ -264,9 +264,6 @@ static int sun4v_read_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
264 unsigned int func = PCI_FUNC(devfn); 264 unsigned int func = PCI_FUNC(devfn);
265 unsigned long ret; 265 unsigned long ret;
266 266
267 if (!bus && devfn == 0x00)
268 return pci_host_bridge_read_pci_cfg(bus_dev, devfn, where,
269 size, value);
270 if (config_out_of_range(pbm, bus, devfn, where)) { 267 if (config_out_of_range(pbm, bus, devfn, where)) {
271 ret = ~0UL; 268 ret = ~0UL;
272 } else { 269 } else {
@@ -300,9 +297,6 @@ static int sun4v_write_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
300 unsigned int func = PCI_FUNC(devfn); 297 unsigned int func = PCI_FUNC(devfn);
301 unsigned long ret; 298 unsigned long ret;
302 299
303 if (!bus && devfn == 0x00)
304 return pci_host_bridge_write_pci_cfg(bus_dev, devfn, where,
305 size, value);
306 if (config_out_of_range(pbm, bus, devfn, where)) { 300 if (config_out_of_range(pbm, bus, devfn, where)) {
307 /* Do nothing. */ 301 /* Do nothing. */
308 } else { 302 } else {
diff --git a/arch/sparc64/kernel/pci_impl.h b/arch/sparc64/kernel/pci_impl.h
index 218bac4ff79b..c385d126be11 100644
--- a/arch/sparc64/kernel/pci_impl.h
+++ b/arch/sparc64/kernel/pci_impl.h
@@ -167,15 +167,6 @@ extern void pci_get_pbm_props(struct pci_pbm_info *pbm);
167extern struct pci_bus *pci_scan_one_pbm(struct pci_pbm_info *pbm); 167extern struct pci_bus *pci_scan_one_pbm(struct pci_pbm_info *pbm);
168extern void pci_determine_mem_io_space(struct pci_pbm_info *pbm); 168extern void pci_determine_mem_io_space(struct pci_pbm_info *pbm);
169 169
170extern int pci_host_bridge_read_pci_cfg(struct pci_bus *bus_dev,
171 unsigned int devfn,
172 int where, int size,
173 u32 *value);
174extern int pci_host_bridge_write_pci_cfg(struct pci_bus *bus_dev,
175 unsigned int devfn,
176 int where, int size,
177 u32 value);
178
179/* Error reporting support. */ 170/* Error reporting support. */
180extern void pci_scan_for_target_abort(struct pci_pbm_info *, struct pci_bus *); 171extern void pci_scan_for_target_abort(struct pci_pbm_info *, struct pci_bus *);
181extern void pci_scan_for_master_abort(struct pci_pbm_info *, struct pci_bus *); 172extern void pci_scan_for_master_abort(struct pci_pbm_info *, struct pci_bus *);
diff --git a/arch/sparc64/kernel/process.c b/arch/sparc64/kernel/process.c
index 056013749157..500ac6d483a0 100644
--- a/arch/sparc64/kernel/process.c
+++ b/arch/sparc64/kernel/process.c
@@ -591,12 +591,6 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
591 if (clone_flags & CLONE_SETTLS) 591 if (clone_flags & CLONE_SETTLS)
592 t->kregs->u_regs[UREG_G7] = regs->u_regs[UREG_I3]; 592 t->kregs->u_regs[UREG_G7] = regs->u_regs[UREG_I3];
593 593
594 /* We do not want to accidently trigger system call restart
595 * handling in the new thread. Therefore, clear out the trap
596 * type, which will make pt_regs_regs_is_syscall() return false.
597 */
598 pt_regs_clear_trap_type(t->kregs);
599
600 return 0; 594 return 0;
601} 595}
602 596
diff --git a/arch/sparc64/kernel/signal.c b/arch/sparc64/kernel/signal.c
index f2d88d8f7a42..45d6bf632daa 100644
--- a/arch/sparc64/kernel/signal.c
+++ b/arch/sparc64/kernel/signal.c
@@ -332,6 +332,9 @@ void do_rt_sigreturn(struct pt_regs *regs)
332 regs->tpc = tpc; 332 regs->tpc = tpc;
333 regs->tnpc = tnpc; 333 regs->tnpc = tnpc;
334 334
335 /* Prevent syscall restart. */
336 pt_regs_clear_trap_type(regs);
337
335 sigdelsetmask(&set, ~_BLOCKABLE); 338 sigdelsetmask(&set, ~_BLOCKABLE);
336 spin_lock_irq(&current->sighand->siglock); 339 spin_lock_irq(&current->sighand->siglock);
337 current->blocked = set; 340 current->blocked = set;
@@ -515,7 +518,8 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
515 siginfo_t info; 518 siginfo_t info;
516 int signr; 519 int signr;
517 520
518 if (pt_regs_is_syscall(regs)) { 521 if (pt_regs_is_syscall(regs) &&
522 (regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY))) {
519 pt_regs_clear_trap_type(regs); 523 pt_regs_clear_trap_type(regs);
520 cookie.restart_syscall = 1; 524 cookie.restart_syscall = 1;
521 } else 525 } else
diff --git a/arch/sparc64/kernel/signal32.c b/arch/sparc64/kernel/signal32.c
index 91f8d0826db1..9415d2c918c5 100644
--- a/arch/sparc64/kernel/signal32.c
+++ b/arch/sparc64/kernel/signal32.c
@@ -268,6 +268,9 @@ void do_sigreturn32(struct pt_regs *regs)
268 regs->tstate &= ~(TSTATE_ICC|TSTATE_XCC); 268 regs->tstate &= ~(TSTATE_ICC|TSTATE_XCC);
269 regs->tstate |= psr_to_tstate_icc(psr); 269 regs->tstate |= psr_to_tstate_icc(psr);
270 270
271 /* Prevent syscall restart. */
272 pt_regs_clear_trap_type(regs);
273
271 err |= __get_user(fpu_save, &sf->fpu_save); 274 err |= __get_user(fpu_save, &sf->fpu_save);
272 if (fpu_save) 275 if (fpu_save)
273 err |= restore_fpu_state32(regs, &sf->fpu_state); 276 err |= restore_fpu_state32(regs, &sf->fpu_state);
@@ -351,6 +354,9 @@ asmlinkage void do_rt_sigreturn32(struct pt_regs *regs)
351 regs->tstate &= ~(TSTATE_ICC|TSTATE_XCC); 354 regs->tstate &= ~(TSTATE_ICC|TSTATE_XCC);
352 regs->tstate |= psr_to_tstate_icc(psr); 355 regs->tstate |= psr_to_tstate_icc(psr);
353 356
357 /* Prevent syscall restart. */
358 pt_regs_clear_trap_type(regs);
359
354 err |= __get_user(fpu_save, &sf->fpu_save); 360 err |= __get_user(fpu_save, &sf->fpu_save);
355 if (fpu_save) 361 if (fpu_save)
356 err |= restore_fpu_state32(regs, &sf->fpu_state); 362 err |= restore_fpu_state32(regs, &sf->fpu_state);
diff --git a/arch/sparc64/kernel/smp.c b/arch/sparc64/kernel/smp.c
index 409dd71f2738..3aba47624df4 100644
--- a/arch/sparc64/kernel/smp.c
+++ b/arch/sparc64/kernel/smp.c
@@ -38,7 +38,6 @@
38#include <asm/pgtable.h> 38#include <asm/pgtable.h>
39#include <asm/oplib.h> 39#include <asm/oplib.h>
40#include <asm/uaccess.h> 40#include <asm/uaccess.h>
41#include <asm/timer.h>
42#include <asm/starfire.h> 41#include <asm/starfire.h>
43#include <asm/tlb.h> 42#include <asm/tlb.h>
44#include <asm/sections.h> 43#include <asm/sections.h>
@@ -910,6 +909,9 @@ extern unsigned long xcall_flush_tlb_kernel_range;
910extern unsigned long xcall_report_regs; 909extern unsigned long xcall_report_regs;
911extern unsigned long xcall_receive_signal; 910extern unsigned long xcall_receive_signal;
912extern unsigned long xcall_new_mmu_context_version; 911extern unsigned long xcall_new_mmu_context_version;
912#ifdef CONFIG_KGDB
913extern unsigned long xcall_kgdb_capture;
914#endif
913 915
914#ifdef DCACHE_ALIASING_POSSIBLE 916#ifdef DCACHE_ALIASING_POSSIBLE
915extern unsigned long xcall_flush_dcache_page_cheetah; 917extern unsigned long xcall_flush_dcache_page_cheetah;
@@ -1079,6 +1081,13 @@ void smp_new_mmu_context_version(void)
1079 smp_cross_call(&xcall_new_mmu_context_version, 0, 0, 0); 1081 smp_cross_call(&xcall_new_mmu_context_version, 0, 0, 0);
1080} 1082}
1081 1083
1084#ifdef CONFIG_KGDB
1085void kgdb_roundup_cpus(unsigned long flags)
1086{
1087 smp_cross_call(&xcall_kgdb_capture, 0, 0, 0);
1088}
1089#endif
1090
1082void smp_report_regs(void) 1091void smp_report_regs(void)
1083{ 1092{
1084 smp_cross_call(&xcall_report_regs, 0, 0, 0); 1093 smp_cross_call(&xcall_report_regs, 0, 0, 0);
diff --git a/arch/sparc64/kernel/spiterrs.S b/arch/sparc64/kernel/spiterrs.S
new file mode 100644
index 000000000000..ef902c6f8e3c
--- /dev/null
+++ b/arch/sparc64/kernel/spiterrs.S
@@ -0,0 +1,245 @@
1 /* We need to carefully read the error status, ACK the errors,
2 * prevent recursive traps, and pass the information on to C
3 * code for logging.
4 *
5 * We pass the AFAR in as-is, and we encode the status
6 * information as described in asm-sparc64/sfafsr.h
7 */
8 .type __spitfire_access_error,#function
9__spitfire_access_error:
10 /* Disable ESTATE error reporting so that we do not take
11 * recursive traps and RED state the processor.
12 */
13 stxa %g0, [%g0] ASI_ESTATE_ERROR_EN
14 membar #Sync
15
16 mov UDBE_UE, %g1
17 ldxa [%g0] ASI_AFSR, %g4 ! Get AFSR
18
19 /* __spitfire_cee_trap branches here with AFSR in %g4 and
20 * UDBE_CE in %g1. It only clears ESTATE_ERR_CE in the ESTATE
21 * Error Enable register.
22 */
23__spitfire_cee_trap_continue:
24 ldxa [%g0] ASI_AFAR, %g5 ! Get AFAR
25
26 rdpr %tt, %g3
27 and %g3, 0x1ff, %g3 ! Paranoia
28 sllx %g3, SFSTAT_TRAP_TYPE_SHIFT, %g3
29 or %g4, %g3, %g4
30 rdpr %tl, %g3
31 cmp %g3, 1
32 mov 1, %g3
33 bleu %xcc, 1f
34 sllx %g3, SFSTAT_TL_GT_ONE_SHIFT, %g3
35
36 or %g4, %g3, %g4
37
38 /* Read in the UDB error register state, clearing the sticky
39 * error bits as-needed. We only clear them if the UE bit is
40 * set. Likewise, __spitfire_cee_trap below will only do so
41 * if the CE bit is set.
42 *
43 * NOTE: UltraSparc-I/II have high and low UDB error
44 * registers, corresponding to the two UDB units
45 * present on those chips. UltraSparc-IIi only
46 * has a single UDB, called "SDB" in the manual.
47 * For IIi the upper UDB register always reads
48 * as zero so for our purposes things will just
49 * work with the checks below.
50 */
511: ldxa [%g0] ASI_UDBH_ERROR_R, %g3
52 and %g3, 0x3ff, %g7 ! Paranoia
53 sllx %g7, SFSTAT_UDBH_SHIFT, %g7
54 or %g4, %g7, %g4
55 andcc %g3, %g1, %g3 ! UDBE_UE or UDBE_CE
56 be,pn %xcc, 1f
57 nop
58 stxa %g3, [%g0] ASI_UDB_ERROR_W
59 membar #Sync
60
611: mov 0x18, %g3
62 ldxa [%g3] ASI_UDBL_ERROR_R, %g3
63 and %g3, 0x3ff, %g7 ! Paranoia
64 sllx %g7, SFSTAT_UDBL_SHIFT, %g7
65 or %g4, %g7, %g4
66 andcc %g3, %g1, %g3 ! UDBE_UE or UDBE_CE
67 be,pn %xcc, 1f
68 nop
69 mov 0x18, %g7
70 stxa %g3, [%g7] ASI_UDB_ERROR_W
71 membar #Sync
72
731: /* Ok, now that we've latched the error state, clear the
74 * sticky bits in the AFSR.
75 */
76 stxa %g4, [%g0] ASI_AFSR
77 membar #Sync
78
79 rdpr %tl, %g2
80 cmp %g2, 1
81 rdpr %pil, %g2
82 bleu,pt %xcc, 1f
83 wrpr %g0, 15, %pil
84
85 ba,pt %xcc, etraptl1
86 rd %pc, %g7
87
88 ba,pt %xcc, 2f
89 nop
90
911: ba,pt %xcc, etrap_irq
92 rd %pc, %g7
93
942:
95#ifdef CONFIG_TRACE_IRQFLAGS
96 call trace_hardirqs_off
97 nop
98#endif
99 mov %l4, %o1
100 mov %l5, %o2
101 call spitfire_access_error
102 add %sp, PTREGS_OFF, %o0
103 ba,pt %xcc, rtrap
104 nop
105 .size __spitfire_access_error,.-__spitfire_access_error
106
107 /* This is the trap handler entry point for ECC correctable
108 * errors. They are corrected, but we listen for the trap so
109 * that the event can be logged.
110 *
111 * Disrupting errors are either:
112 * 1) single-bit ECC errors during UDB reads to system
113 * memory
114 * 2) data parity errors during write-back events
115 *
116 * As far as I can make out from the manual, the CEE trap is
117 * only for correctable errors during memory read accesses by
118 * the front-end of the processor.
119 *
120 * The code below is only for trap level 1 CEE events, as it
121 * is the only situation where we can safely record and log.
122 * For trap level >1 we just clear the CE bit in the AFSR and
123 * return.
124 *
125 * This is just like __spiftire_access_error above, but it
126 * specifically handles correctable errors. If an
127 * uncorrectable error is indicated in the AFSR we will branch
128 * directly above to __spitfire_access_error to handle it
129 * instead. Uncorrectable therefore takes priority over
130 * correctable, and the error logging C code will notice this
131 * case by inspecting the trap type.
132 */
133 .type __spitfire_cee_trap,#function
134__spitfire_cee_trap:
135 ldxa [%g0] ASI_AFSR, %g4 ! Get AFSR
136 mov 1, %g3
137 sllx %g3, SFAFSR_UE_SHIFT, %g3
138 andcc %g4, %g3, %g0 ! Check for UE
139 bne,pn %xcc, __spitfire_access_error
140 nop
141
142 /* Ok, in this case we only have a correctable error.
143 * Indicate we only wish to capture that state in register
144 * %g1, and we only disable CE error reporting unlike UE
145 * handling which disables all errors.
146 */
147 ldxa [%g0] ASI_ESTATE_ERROR_EN, %g3
148 andn %g3, ESTATE_ERR_CE, %g3
149 stxa %g3, [%g0] ASI_ESTATE_ERROR_EN
150 membar #Sync
151
152 /* Preserve AFSR in %g4, indicate UDB state to capture in %g1 */
153 ba,pt %xcc, __spitfire_cee_trap_continue
154 mov UDBE_CE, %g1
155 .size __spitfire_cee_trap,.-__spitfire_cee_trap
156
157 .type __spitfire_data_access_exception_tl1,#function
158__spitfire_data_access_exception_tl1:
159 rdpr %pstate, %g4
160 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
161 mov TLB_SFSR, %g3
162 mov DMMU_SFAR, %g5
163 ldxa [%g3] ASI_DMMU, %g4 ! Get SFSR
164 ldxa [%g5] ASI_DMMU, %g5 ! Get SFAR
165 stxa %g0, [%g3] ASI_DMMU ! Clear SFSR.FaultValid bit
166 membar #Sync
167 rdpr %tt, %g3
168 cmp %g3, 0x80 ! first win spill/fill trap
169 blu,pn %xcc, 1f
170 cmp %g3, 0xff ! last win spill/fill trap
171 bgu,pn %xcc, 1f
172 nop
173 ba,pt %xcc, winfix_dax
174 rdpr %tpc, %g3
1751: sethi %hi(109f), %g7
176 ba,pt %xcc, etraptl1
177109: or %g7, %lo(109b), %g7
178 mov %l4, %o1
179 mov %l5, %o2
180 call spitfire_data_access_exception_tl1
181 add %sp, PTREGS_OFF, %o0
182 ba,pt %xcc, rtrap
183 nop
184 .size __spitfire_data_access_exception_tl1,.-__spitfire_data_access_exception_tl1
185
186 .type __spitfire_data_access_exception,#function
187__spitfire_data_access_exception:
188 rdpr %pstate, %g4
189 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
190 mov TLB_SFSR, %g3
191 mov DMMU_SFAR, %g5
192 ldxa [%g3] ASI_DMMU, %g4 ! Get SFSR
193 ldxa [%g5] ASI_DMMU, %g5 ! Get SFAR
194 stxa %g0, [%g3] ASI_DMMU ! Clear SFSR.FaultValid bit
195 membar #Sync
196 sethi %hi(109f), %g7
197 ba,pt %xcc, etrap
198109: or %g7, %lo(109b), %g7
199 mov %l4, %o1
200 mov %l5, %o2
201 call spitfire_data_access_exception
202 add %sp, PTREGS_OFF, %o0
203 ba,pt %xcc, rtrap
204 nop
205 .size __spitfire_data_access_exception,.-__spitfire_data_access_exception
206
207 .type __spitfire_insn_access_exception_tl1,#function
208__spitfire_insn_access_exception_tl1:
209 rdpr %pstate, %g4
210 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
211 mov TLB_SFSR, %g3
212 ldxa [%g3] ASI_IMMU, %g4 ! Get SFSR
213 rdpr %tpc, %g5 ! IMMU has no SFAR, use TPC
214 stxa %g0, [%g3] ASI_IMMU ! Clear FaultValid bit
215 membar #Sync
216 sethi %hi(109f), %g7
217 ba,pt %xcc, etraptl1
218109: or %g7, %lo(109b), %g7
219 mov %l4, %o1
220 mov %l5, %o2
221 call spitfire_insn_access_exception_tl1
222 add %sp, PTREGS_OFF, %o0
223 ba,pt %xcc, rtrap
224 nop
225 .size __spitfire_insn_access_exception_tl1,.-__spitfire_insn_access_exception_tl1
226
227 .type __spitfire_insn_access_exception,#function
228__spitfire_insn_access_exception:
229 rdpr %pstate, %g4
230 wrpr %g4, PSTATE_MG|PSTATE_AG, %pstate
231 mov TLB_SFSR, %g3
232 ldxa [%g3] ASI_IMMU, %g4 ! Get SFSR
233 rdpr %tpc, %g5 ! IMMU has no SFAR, use TPC
234 stxa %g0, [%g3] ASI_IMMU ! Clear FaultValid bit
235 membar #Sync
236 sethi %hi(109f), %g7
237 ba,pt %xcc, etrap
238109: or %g7, %lo(109b), %g7
239 mov %l4, %o1
240 mov %l5, %o2
241 call spitfire_insn_access_exception
242 add %sp, PTREGS_OFF, %o0
243 ba,pt %xcc, rtrap
244 nop
245 .size __spitfire_insn_access_exception,.-__spitfire_insn_access_exception
diff --git a/arch/sparc64/kernel/syscalls.S b/arch/sparc64/kernel/syscalls.S
new file mode 100644
index 000000000000..db19ed67acf6
--- /dev/null
+++ b/arch/sparc64/kernel/syscalls.S
@@ -0,0 +1,279 @@
1 /* SunOS's execv() call only specifies the argv argument, the
2 * environment settings are the same as the calling processes.
3 */
4sys_execve:
5 sethi %hi(sparc_execve), %g1
6 ba,pt %xcc, execve_merge
7 or %g1, %lo(sparc_execve), %g1
8
9#ifdef CONFIG_COMPAT
10sunos_execv:
11 stx %g0, [%sp + PTREGS_OFF + PT_V9_I2]
12sys32_execve:
13 sethi %hi(sparc32_execve), %g1
14 or %g1, %lo(sparc32_execve), %g1
15#endif
16
17execve_merge:
18 flushw
19 jmpl %g1, %g0
20 add %sp, PTREGS_OFF, %o0
21
22 .align 32
23sys_pipe:
24 ba,pt %xcc, sparc_pipe
25 add %sp, PTREGS_OFF, %o0
26sys_nis_syscall:
27 ba,pt %xcc, c_sys_nis_syscall
28 add %sp, PTREGS_OFF, %o0
29sys_memory_ordering:
30 ba,pt %xcc, sparc_memory_ordering
31 add %sp, PTREGS_OFF, %o1
32sys_sigaltstack:
33 ba,pt %xcc, do_sigaltstack
34 add %i6, STACK_BIAS, %o2
35#ifdef CONFIG_COMPAT
36sys32_sigstack:
37 ba,pt %xcc, do_sys32_sigstack
38 mov %i6, %o2
39sys32_sigaltstack:
40 ba,pt %xcc, do_sys32_sigaltstack
41 mov %i6, %o2
42#endif
43 .align 32
44#ifdef CONFIG_COMPAT
45sys32_sigreturn:
46 add %sp, PTREGS_OFF, %o0
47 call do_sigreturn32
48 add %o7, 1f-.-4, %o7
49 nop
50#endif
51sys_rt_sigreturn:
52 add %sp, PTREGS_OFF, %o0
53 call do_rt_sigreturn
54 add %o7, 1f-.-4, %o7
55 nop
56#ifdef CONFIG_COMPAT
57sys32_rt_sigreturn:
58 add %sp, PTREGS_OFF, %o0
59 call do_rt_sigreturn32
60 add %o7, 1f-.-4, %o7
61 nop
62#endif
63 .align 32
641: ldx [%g6 + TI_FLAGS], %l5
65 andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
66 be,pt %icc, rtrap
67 nop
68 add %sp, PTREGS_OFF, %o0
69 call syscall_trace
70 mov 1, %o1
71 ba,pt %xcc, rtrap
72 nop
73
74 /* This is how fork() was meant to be done, 8 instruction entry.
75 *
76 * I questioned the following code briefly, let me clear things
77 * up so you must not reason on it like I did.
78 *
79 * Know the fork_kpsr etc. we use in the sparc32 port? We don't
80 * need it here because the only piece of window state we copy to
81 * the child is the CWP register. Even if the parent sleeps,
82 * we are safe because we stuck it into pt_regs of the parent
83 * so it will not change.
84 *
85 * XXX This raises the question, whether we can do the same on
86 * XXX sparc32 to get rid of fork_kpsr _and_ fork_kwim. The
87 * XXX answer is yes. We stick fork_kpsr in UREG_G0 and
88 * XXX fork_kwim in UREG_G1 (global registers are considered
89 * XXX volatile across a system call in the sparc ABI I think
90 * XXX if it isn't we can use regs->y instead, anyone who depends
91 * XXX upon the Y register being preserved across a fork deserves
92 * XXX to lose).
93 *
94 * In fact we should take advantage of that fact for other things
95 * during system calls...
96 */
97 .align 32
98sys_vfork: /* Under Linux, vfork and fork are just special cases of clone. */
99 sethi %hi(0x4000 | 0x0100 | SIGCHLD), %o0
100 or %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
101 ba,pt %xcc, sys_clone
102sys_fork:
103 clr %o1
104 mov SIGCHLD, %o0
105sys_clone:
106 flushw
107 movrz %o1, %fp, %o1
108 mov 0, %o3
109 ba,pt %xcc, sparc_do_fork
110 add %sp, PTREGS_OFF, %o2
111
112 .globl ret_from_syscall
113ret_from_syscall:
114 /* Clear current_thread_info()->new_child, and
115 * check performance counter stuff too.
116 */
117 stb %g0, [%g6 + TI_NEW_CHILD]
118 ldx [%g6 + TI_FLAGS], %l0
119 call schedule_tail
120 mov %g7, %o0
121 andcc %l0, _TIF_PERFCTR, %g0
122 be,pt %icc, 1f
123 nop
124 ldx [%g6 + TI_PCR], %o7
125 wr %g0, %o7, %pcr
126
127 /* Blackbird errata workaround. See commentary in
128 * smp.c:smp_percpu_timer_interrupt() for more
129 * information.
130 */
131 ba,pt %xcc, 99f
132 nop
133
134 .align 64
13599: wr %g0, %g0, %pic
136 rd %pic, %g0
137
1381: ba,pt %xcc, ret_sys_call
139 ldx [%sp + PTREGS_OFF + PT_V9_I0], %o0
140
141 .globl sparc_exit
142 .type sparc_exit,#function
143sparc_exit:
144 rdpr %pstate, %g2
145 wrpr %g2, PSTATE_IE, %pstate
146 rdpr %otherwin, %g1
147 rdpr %cansave, %g3
148 add %g3, %g1, %g3
149 wrpr %g3, 0x0, %cansave
150 wrpr %g0, 0x0, %otherwin
151 wrpr %g2, 0x0, %pstate
152 ba,pt %xcc, sys_exit
153 stb %g0, [%g6 + TI_WSAVED]
154 .size sparc_exit,.-sparc_exit
155
156linux_sparc_ni_syscall:
157 sethi %hi(sys_ni_syscall), %l7
158 ba,pt %xcc, 4f
159 or %l7, %lo(sys_ni_syscall), %l7
160
161linux_syscall_trace32:
162 add %sp, PTREGS_OFF, %o0
163 call syscall_trace
164 clr %o1
165 srl %i0, 0, %o0
166 srl %i4, 0, %o4
167 srl %i1, 0, %o1
168 srl %i2, 0, %o2
169 ba,pt %xcc, 2f
170 srl %i3, 0, %o3
171
172linux_syscall_trace:
173 add %sp, PTREGS_OFF, %o0
174 call syscall_trace
175 clr %o1
176 mov %i0, %o0
177 mov %i1, %o1
178 mov %i2, %o2
179 mov %i3, %o3
180 b,pt %xcc, 2f
181 mov %i4, %o4
182
183
184 /* Linux 32-bit system calls enter here... */
185 .align 32
186 .globl linux_sparc_syscall32
187linux_sparc_syscall32:
188 /* Direct access to user regs, much faster. */
189 cmp %g1, NR_SYSCALLS ! IEU1 Group
190 bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
191 srl %i0, 0, %o0 ! IEU0
192 sll %g1, 2, %l4 ! IEU0 Group
193 srl %i4, 0, %o4 ! IEU1
194 lduw [%l7 + %l4], %l7 ! Load
195 srl %i1, 0, %o1 ! IEU0 Group
196 ldx [%g6 + TI_FLAGS], %l0 ! Load
197
198 srl %i5, 0, %o5 ! IEU1
199 srl %i2, 0, %o2 ! IEU0 Group
200 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
201 bne,pn %icc, linux_syscall_trace32 ! CTI
202 mov %i0, %l5 ! IEU1
203 call %l7 ! CTI Group brk forced
204 srl %i3, 0, %o3 ! IEU0
205 ba,a,pt %xcc, 3f
206
207 /* Linux native system calls enter here... */
208 .align 32
209 .globl linux_sparc_syscall
210linux_sparc_syscall:
211 /* Direct access to user regs, much faster. */
212 cmp %g1, NR_SYSCALLS ! IEU1 Group
213 bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
214 mov %i0, %o0 ! IEU0
215 sll %g1, 2, %l4 ! IEU0 Group
216 mov %i1, %o1 ! IEU1
217 lduw [%l7 + %l4], %l7 ! Load
2184: mov %i2, %o2 ! IEU0 Group
219 ldx [%g6 + TI_FLAGS], %l0 ! Load
220
221 mov %i3, %o3 ! IEU1
222 mov %i4, %o4 ! IEU0 Group
223 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
224 bne,pn %icc, linux_syscall_trace ! CTI Group
225 mov %i0, %l5 ! IEU0
2262: call %l7 ! CTI Group brk forced
227 mov %i5, %o5 ! IEU0
228 nop
229
2303: stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
231ret_sys_call:
232 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
233 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
234 sra %o0, 0, %o0
235 mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
236 sllx %g2, 32, %g2
237
238 /* Check if force_successful_syscall_return()
239 * was invoked.
240 */
241 ldub [%g6 + TI_SYS_NOERROR], %l2
242 brnz,a,pn %l2, 80f
243 stb %g0, [%g6 + TI_SYS_NOERROR]
244
245 cmp %o0, -ERESTART_RESTARTBLOCK
246 bgeu,pn %xcc, 1f
247 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
24880:
249 /* System call success, clear Carry condition code. */
250 andn %g3, %g2, %g3
251 stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
252 bne,pn %icc, linux_syscall_trace2
253 add %l1, 0x4, %l2 ! npc = npc+4
254 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
255 ba,pt %xcc, rtrap
256 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
257
2581:
259 /* System call failure, set Carry condition code.
260 * Also, get abs(errno) to return to the process.
261 */
262 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
263 sub %g0, %o0, %o0
264 or %g3, %g2, %g3
265 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
266 stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
267 bne,pn %icc, linux_syscall_trace2
268 add %l1, 0x4, %l2 ! npc = npc+4
269 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
270
271 b,pt %xcc, rtrap
272 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
273linux_syscall_trace2:
274 add %sp, PTREGS_OFF, %o0
275 call syscall_trace
276 mov 1, %o1
277 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
278 ba,pt %xcc, rtrap
279 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
diff --git a/arch/sparc64/kernel/ttable.S b/arch/sparc64/kernel/ttable.S
index b0de4c00b11a..450053af039e 100644
--- a/arch/sparc64/kernel/ttable.S
+++ b/arch/sparc64/kernel/ttable.S
@@ -153,7 +153,7 @@ tl0_resv164: BTRAP(0x164) BTRAP(0x165) BTRAP(0x166) BTRAP(0x167) BTRAP(0x168)
153tl0_resv169: BTRAP(0x169) BTRAP(0x16a) BTRAP(0x16b) BTRAP(0x16c) 153tl0_resv169: BTRAP(0x169) BTRAP(0x16a) BTRAP(0x16b) BTRAP(0x16c)
154tl0_linux64: LINUX_64BIT_SYSCALL_TRAP 154tl0_linux64: LINUX_64BIT_SYSCALL_TRAP
155tl0_gsctx: TRAP(sparc64_get_context) TRAP(sparc64_set_context) 155tl0_gsctx: TRAP(sparc64_get_context) TRAP(sparc64_set_context)
156tl0_resv170: KPROBES_TRAP(0x170) KPROBES_TRAP(0x171) BTRAP(0x172) 156tl0_resv170: KPROBES_TRAP(0x170) KPROBES_TRAP(0x171) KGDB_TRAP(0x172)
157tl0_resv173: BTRAP(0x173) BTRAP(0x174) BTRAP(0x175) BTRAP(0x176) BTRAP(0x177) 157tl0_resv173: BTRAP(0x173) BTRAP(0x174) BTRAP(0x175) BTRAP(0x176) BTRAP(0x177)
158tl0_resv178: BTRAP(0x178) BTRAP(0x179) BTRAP(0x17a) BTRAP(0x17b) BTRAP(0x17c) 158tl0_resv178: BTRAP(0x178) BTRAP(0x179) BTRAP(0x17a) BTRAP(0x17b) BTRAP(0x17c)
159tl0_resv17d: BTRAP(0x17d) BTRAP(0x17e) BTRAP(0x17f) 159tl0_resv17d: BTRAP(0x17d) BTRAP(0x17e) BTRAP(0x17f)
diff --git a/arch/sparc64/kernel/utrap.S b/arch/sparc64/kernel/utrap.S
new file mode 100644
index 000000000000..b7f0f3f3a909
--- /dev/null
+++ b/arch/sparc64/kernel/utrap.S
@@ -0,0 +1,29 @@
1 .globl utrap_trap
2 .type utrap_trap,#function
3utrap_trap: /* %g3=handler,%g4=level */
4 TRAP_LOAD_THREAD_REG(%g6, %g1)
5 ldx [%g6 + TI_UTRAPS], %g1
6 brnz,pt %g1, invoke_utrap
7 nop
8
9 ba,pt %xcc, etrap
10 rd %pc, %g7
11 mov %l4, %o1
12 call bad_trap
13 add %sp, PTREGS_OFF, %o0
14 ba,pt %xcc, rtrap
15 nop
16
17invoke_utrap:
18 sllx %g3, 3, %g3
19 ldx [%g1 + %g3], %g1
20 save %sp, -128, %sp
21 rdpr %tstate, %l6
22 rdpr %cwp, %l7
23 andn %l6, TSTATE_CWP, %l6
24 wrpr %l6, %l7, %tstate
25 rdpr %tpc, %l6
26 rdpr %tnpc, %l7
27 wrpr %g1, 0, %tnpc
28 done
29 .size utrap_trap,.-utrap_trap
diff --git a/arch/sparc64/mm/init.c b/arch/sparc64/mm/init.c
index 8c2b50e8abc6..4cad0b32b0af 100644
--- a/arch/sparc64/mm/init.c
+++ b/arch/sparc64/mm/init.c
@@ -160,6 +160,7 @@ extern unsigned int sparc_ramdisk_image;
160extern unsigned int sparc_ramdisk_size; 160extern unsigned int sparc_ramdisk_size;
161 161
162struct page *mem_map_zero __read_mostly; 162struct page *mem_map_zero __read_mostly;
163EXPORT_SYMBOL(mem_map_zero);
163 164
164unsigned int sparc64_highest_unlocked_tlb_ent __read_mostly; 165unsigned int sparc64_highest_unlocked_tlb_ent __read_mostly;
165 166
diff --git a/arch/sparc64/mm/ultra.S b/arch/sparc64/mm/ultra.S
index e686a67561af..796e005dad8b 100644
--- a/arch/sparc64/mm/ultra.S
+++ b/arch/sparc64/mm/ultra.S
@@ -676,6 +676,33 @@ xcall_new_mmu_context_version:
676 wr %g0, (1 << PIL_SMP_CTX_NEW_VERSION), %set_softint 676 wr %g0, (1 << PIL_SMP_CTX_NEW_VERSION), %set_softint
677 retry 677 retry
678 678
679#ifdef CONFIG_KGDB
680 .globl xcall_kgdb_capture
681xcall_kgdb_capture:
682661: rdpr %pstate, %g2
683 wrpr %g2, PSTATE_IG | PSTATE_AG, %pstate
684 .section .sun4v_2insn_patch, "ax"
685 .word 661b
686 nop
687 nop
688 .previous
689
690 rdpr %pil, %g2
691 wrpr %g0, 15, %pil
692 sethi %hi(109f), %g7
693 ba,pt %xcc, etrap_irq
694109: or %g7, %lo(109b), %g7
695#ifdef CONFIG_TRACE_IRQFLAGS
696 call trace_hardirqs_off
697 nop
698#endif
699 call smp_kgdb_capture_client
700 add %sp, PTREGS_OFF, %o0
701 /* Has to be a non-v9 branch due to the large distance. */
702 ba rtrap_xcall
703 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
704#endif
705
679#endif /* CONFIG_SMP */ 706#endif /* CONFIG_SMP */
680 707
681 708
diff --git a/arch/um/Makefile b/arch/um/Makefile
index dbeab15e7bb7..01b97c19a8ba 100644
--- a/arch/um/Makefile
+++ b/arch/um/Makefile
@@ -77,7 +77,10 @@ include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
77KERNEL_DEFINES = $(strip -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask \ 77KERNEL_DEFINES = $(strip -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask \
78 -Dmktime=kernel_mktime $(ARCH_KERNEL_DEFINES)) 78 -Dmktime=kernel_mktime $(ARCH_KERNEL_DEFINES))
79KBUILD_CFLAGS += $(KERNEL_DEFINES) 79KBUILD_CFLAGS += $(KERNEL_DEFINES)
80KBUILD_CFLAGS += $(call cc-option,-fno-unit-at-a-time,) 80# Disable unit-at-a-time mode on pre-gcc-4.0 compilers, it makes gcc use
81# a lot more stack due to the lack of sharing of stacklots:
82KBUILD_CFLAGS += $(shell if [ $(call cc-version) -lt 0400 ] ; then \
83 echo $(call cc-option,-fno-unit-at-a-time); fi ;)
81 84
82PHONY += linux 85PHONY += linux
83 86
diff --git a/arch/um/kernel/syscall.c b/arch/um/kernel/syscall.c
index 9cffc628a37e..128ee85bc8d9 100644
--- a/arch/um/kernel/syscall.c
+++ b/arch/um/kernel/syscall.c
@@ -73,23 +73,6 @@ long old_mmap(unsigned long addr, unsigned long len,
73 out: 73 out:
74 return err; 74 return err;
75} 75}
76/*
77 * sys_pipe() is the normal C calling standard for creating
78 * a pipe. It's not the way unix traditionally does this, though.
79 */
80long sys_pipe(unsigned long __user * fildes)
81{
82 int fd[2];
83 long error;
84
85 error = do_pipe(fd);
86 if (!error) {
87 if (copy_to_user(fildes, fd, sizeof(fd)))
88 error = -EFAULT;
89 }
90 return error;
91}
92
93 76
94long sys_uname(struct old_utsname __user * name) 77long sys_uname(struct old_utsname __user * name)
95{ 78{
diff --git a/arch/v850/kernel/syscalls.c b/arch/v850/kernel/syscalls.c
index 003db9c8c44a..1a83daf8e24f 100644
--- a/arch/v850/kernel/syscalls.c
+++ b/arch/v850/kernel/syscalls.c
@@ -132,23 +132,6 @@ sys_ipc (uint call, int first, int second, int third, void *ptr, long fifth)
132 return ret; 132 return ret;
133} 133}
134 134
135/*
136 * sys_pipe() is the normal C calling standard for creating
137 * a pipe. It's not the way unix traditionally does this, though.
138 */
139int sys_pipe (int *fildes)
140{
141 int fd[2];
142 int error;
143
144 error = do_pipe (fd);
145 if (!error) {
146 if (copy_to_user (fildes, fd, 2*sizeof (int)))
147 error = -EFAULT;
148 }
149 return error;
150}
151
152static inline unsigned long 135static inline unsigned long
153do_mmap2 (unsigned long addr, size_t len, 136do_mmap2 (unsigned long addr, size_t len,
154 unsigned long prot, unsigned long flags, 137 unsigned long prot, unsigned long flags,
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index f70e3e3a9fa7..bbcafaa160c0 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -18,6 +18,7 @@ config X86_64
18### Arch settings 18### Arch settings
19config X86 19config X86
20 def_bool y 20 def_bool y
21 select HAVE_UNSTABLE_SCHED_CLOCK
21 select HAVE_IDE 22 select HAVE_IDE
22 select HAVE_OPROFILE 23 select HAVE_OPROFILE
23 select HAVE_KPROBES 24 select HAVE_KPROBES
@@ -25,6 +26,18 @@ config X86
25 select HAVE_KVM if ((X86_32 && !X86_VOYAGER && !X86_VISWS && !X86_NUMAQ) || X86_64) 26 select HAVE_KVM if ((X86_32 && !X86_VOYAGER && !X86_VISWS && !X86_NUMAQ) || X86_64)
26 select HAVE_ARCH_KGDB if !X86_VOYAGER 27 select HAVE_ARCH_KGDB if !X86_VOYAGER
27 28
29config DEFCONFIG_LIST
30 string
31 depends on X86_32
32 option defconfig_list
33 default "arch/x86/configs/i386_defconfig"
34
35config DEFCONFIG_LIST
36 string
37 depends on X86_64
38 option defconfig_list
39 default "arch/x86/configs/x86_64_defconfig"
40
28 41
29config GENERIC_LOCKBREAK 42config GENERIC_LOCKBREAK
30 def_bool n 43 def_bool n
@@ -180,7 +193,7 @@ config X86_HT
180 193
181config X86_BIOS_REBOOT 194config X86_BIOS_REBOOT
182 bool 195 bool
183 depends on X86_32 && !(X86_VISWS || X86_VOYAGER) 196 depends on !X86_VISWS && !X86_VOYAGER
184 default y 197 default y
185 198
186config X86_TRAMPOLINE 199config X86_TRAMPOLINE
@@ -1161,7 +1174,7 @@ source kernel/Kconfig.hz
1161 1174
1162config KEXEC 1175config KEXEC
1163 bool "kexec system call" 1176 bool "kexec system call"
1164 depends on X86_64 || X86_BIOS_REBOOT 1177 depends on X86_BIOS_REBOOT
1165 help 1178 help
1166 kexec is a system call that implements the ability to shutdown your 1179 kexec is a system call that implements the ability to shutdown your
1167 current kernel, and to start another kernel. It is like a reboot 1180 current kernel, and to start another kernel. It is like a reboot
@@ -1649,6 +1662,7 @@ config GEODE_MFGPT_TIMER
1649 1662
1650config OLPC 1663config OLPC
1651 bool "One Laptop Per Child support" 1664 bool "One Laptop Per Child support"
1665 depends on MGEODE_LX
1652 default n 1666 default n
1653 help 1667 help
1654 Add support for detecting the unique features of the OLPC 1668 Add support for detecting the unique features of the OLPC
diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
index 7ef18b01f0bc..2ad6301849a1 100644
--- a/arch/x86/Kconfig.cpu
+++ b/arch/x86/Kconfig.cpu
@@ -278,11 +278,6 @@ config GENERIC_CPU
278 278
279endchoice 279endchoice
280 280
281config X86_CPU
282 def_bool y
283 select GENERIC_FIND_FIRST_BIT
284 select GENERIC_FIND_NEXT_BIT
285
286config X86_GENERIC 281config X86_GENERIC
287 bool "Generic x86 support" 282 bool "Generic x86 support"
288 depends on X86_32 283 depends on X86_32
@@ -297,6 +292,11 @@ config X86_GENERIC
297 292
298endif 293endif
299 294
295config X86_CPU
296 def_bool y
297 select GENERIC_FIND_FIRST_BIT
298 select GENERIC_FIND_NEXT_BIT
299
300# 300#
301# Define implied options from the CPU selection here 301# Define implied options from the CPU selection here
302config X86_L1_CACHE_BYTES 302config X86_L1_CACHE_BYTES
diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
index 5b1979a45a1e..ac1e31ba4795 100644
--- a/arch/x86/Kconfig.debug
+++ b/arch/x86/Kconfig.debug
@@ -118,7 +118,6 @@ config DEBUG_NX_TEST
118config 4KSTACKS 118config 4KSTACKS
119 bool "Use 4Kb for kernel stacks instead of 8Kb" 119 bool "Use 4Kb for kernel stacks instead of 8Kb"
120 depends on X86_32 120 depends on X86_32
121 default y
122 help 121 help
123 If you say Y here the kernel will use a 4Kb stacksize for the 122 If you say Y here the kernel will use a 4Kb stacksize for the
124 kernel stack attached to each process/thread. This facilitates 123 kernel stack attached to each process/thread. This facilitates
@@ -256,11 +255,9 @@ config CPA_DEBUG
256 help 255 help
257 Do change_page_attr() self-tests every 30 seconds. 256 Do change_page_attr() self-tests every 30 seconds.
258 257
259endmenu
260
261config OPTIMIZE_INLINING 258config OPTIMIZE_INLINING
262 bool "Allow gcc to uninline functions marked 'inline'" 259 bool "Allow gcc to uninline functions marked 'inline'"
263 default y 260 depends on BROKEN
264 help 261 help
265 This option determines if the kernel forces gcc to inline the functions 262 This option determines if the kernel forces gcc to inline the functions
266 developers have marked 'inline'. Doing so takes away freedom from gcc to 263 developers have marked 'inline'. Doing so takes away freedom from gcc to
@@ -270,3 +267,6 @@ config OPTIMIZE_INLINING
270 this algorithm is so good that allowing gcc4 to make the decision can 267 this algorithm is so good that allowing gcc4 to make the decision can
271 become the default in the future, until then this option is there to 268 become the default in the future, until then this option is there to
272 test gcc for this. 269 test gcc for this.
270
271endmenu
272
diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
index d01ea42187e6..edaadea90aaf 100644
--- a/arch/x86/boot/compressed/relocs.c
+++ b/arch/x86/boot/compressed/relocs.c
@@ -191,7 +191,7 @@ static void read_ehdr(FILE *fp)
191 die("Cannot read ELF header: %s\n", 191 die("Cannot read ELF header: %s\n",
192 strerror(errno)); 192 strerror(errno));
193 } 193 }
194 if (memcmp(ehdr.e_ident, ELFMAG, 4) != 0) { 194 if (memcmp(ehdr.e_ident, ELFMAG, SELFMAG) != 0) {
195 die("No ELF magic\n"); 195 die("No ELF magic\n");
196 } 196 }
197 if (ehdr.e_ident[EI_CLASS] != ELFCLASS32) { 197 if (ehdr.e_ident[EI_CLASS] != ELFCLASS32) {
diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
index bbed3a26ce55..cb3856a18c85 100644
--- a/arch/x86/ia32/ia32_signal.c
+++ b/arch/x86/ia32/ia32_signal.c
@@ -128,7 +128,7 @@ asmlinkage long sys32_sigsuspend(int history0, int history1, old_sigset_t mask)
128 128
129 current->state = TASK_INTERRUPTIBLE; 129 current->state = TASK_INTERRUPTIBLE;
130 schedule(); 130 schedule();
131 set_thread_flag(TIF_RESTORE_SIGMASK); 131 set_restore_sigmask();
132 return -ERESTARTNOHAND; 132 return -ERESTARTNOHAND;
133} 133}
134 134
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index 30d54ed27e55..bbdacb398d48 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -40,7 +40,6 @@ obj-$(CONFIG_STACKTRACE) += stacktrace.o
40obj-y += cpu/ 40obj-y += cpu/
41obj-y += acpi/ 41obj-y += acpi/
42obj-$(CONFIG_X86_BIOS_REBOOT) += reboot.o 42obj-$(CONFIG_X86_BIOS_REBOOT) += reboot.o
43obj-$(CONFIG_X86_64) += reboot.o
44obj-$(CONFIG_MCA) += mca_32.o 43obj-$(CONFIG_MCA) += mca_32.o
45obj-$(CONFIG_X86_MSR) += msr.o 44obj-$(CONFIG_X86_MSR) += msr.o
46obj-$(CONFIG_X86_CPUID) += cpuid.o 45obj-$(CONFIG_X86_CPUID) += cpuid.o
diff --git a/arch/x86/kernel/acpi/Makefile b/arch/x86/kernel/acpi/Makefile
index 7335959b6aff..fd5ca97a2ad5 100644
--- a/arch/x86/kernel/acpi/Makefile
+++ b/arch/x86/kernel/acpi/Makefile
@@ -10,5 +10,5 @@ endif
10$(obj)/wakeup_rm.o: $(obj)/realmode/wakeup.bin 10$(obj)/wakeup_rm.o: $(obj)/realmode/wakeup.bin
11 11
12$(obj)/realmode/wakeup.bin: FORCE 12$(obj)/realmode/wakeup.bin: FORCE
13 $(Q)$(MAKE) $(build)=$(obj)/realmode $@ 13 $(Q)$(MAKE) $(build)=$(obj)/realmode
14 14
diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
index 092900854acc..1c31cc0e9def 100644
--- a/arch/x86/kernel/acpi/realmode/Makefile
+++ b/arch/x86/kernel/acpi/realmode/Makefile
@@ -6,7 +6,8 @@
6# for more details. 6# for more details.
7# 7#
8 8
9targets := wakeup.bin wakeup.elf 9always := wakeup.bin
10targets := wakeup.elf wakeup.lds
10 11
11wakeup-y += wakeup.o wakemain.o video-mode.o copy.o 12wakeup-y += wakeup.o wakemain.o video-mode.o copy.o
12 13
@@ -48,7 +49,7 @@ LDFLAGS_wakeup.elf := -T
48 49
49CPPFLAGS_wakeup.lds += -P -C 50CPPFLAGS_wakeup.lds += -P -C
50 51
51$(obj)/wakeup.elf: $(src)/wakeup.lds $(WAKEUP_OBJS) FORCE 52$(obj)/wakeup.elf: $(obj)/wakeup.lds $(WAKEUP_OBJS) FORCE
52 $(call if_changed,ld) 53 $(call if_changed,ld)
53 54
54OBJCOPYFLAGS_wakeup.bin := -O binary 55OBJCOPYFLAGS_wakeup.bin := -O binary
diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
index e4ea362e8480..bf9290e29013 100644
--- a/arch/x86/kernel/apm_32.c
+++ b/arch/x86/kernel/apm_32.c
@@ -1192,19 +1192,6 @@ static int suspend(int vetoable)
1192 int err; 1192 int err;
1193 struct apm_user *as; 1193 struct apm_user *as;
1194 1194
1195 if (pm_send_all(PM_SUSPEND, (void *)3)) {
1196 /* Vetoed */
1197 if (vetoable) {
1198 if (apm_info.connection_version > 0x100)
1199 set_system_power_state(APM_STATE_REJECT);
1200 err = -EBUSY;
1201 ignore_sys_suspend = 0;
1202 printk(KERN_WARNING "apm: suspend was vetoed.\n");
1203 goto out;
1204 }
1205 printk(KERN_CRIT "apm: suspend was vetoed, but suspending anyway.\n");
1206 }
1207
1208 device_suspend(PMSG_SUSPEND); 1195 device_suspend(PMSG_SUSPEND);
1209 local_irq_disable(); 1196 local_irq_disable();
1210 device_power_down(PMSG_SUSPEND); 1197 device_power_down(PMSG_SUSPEND);
@@ -1227,9 +1214,7 @@ static int suspend(int vetoable)
1227 device_power_up(); 1214 device_power_up();
1228 local_irq_enable(); 1215 local_irq_enable();
1229 device_resume(); 1216 device_resume();
1230 pm_send_all(PM_RESUME, (void *)0);
1231 queue_event(APM_NORMAL_RESUME, NULL); 1217 queue_event(APM_NORMAL_RESUME, NULL);
1232 out:
1233 spin_lock(&user_list_lock); 1218 spin_lock(&user_list_lock);
1234 for (as = user_list; as != NULL; as = as->next) { 1219 for (as = user_list; as != NULL; as = as->next) {
1235 as->suspend_wait = 0; 1220 as->suspend_wait = 0;
@@ -1340,7 +1325,6 @@ static void check_events(void)
1340 if ((event != APM_NORMAL_RESUME) 1325 if ((event != APM_NORMAL_RESUME)
1341 || (ignore_normal_resume == 0)) { 1326 || (ignore_normal_resume == 0)) {
1342 device_resume(); 1327 device_resume();
1343 pm_send_all(PM_RESUME, (void *)0);
1344 queue_event(event, NULL); 1328 queue_event(event, NULL);
1345 } 1329 }
1346 ignore_normal_resume = 0; 1330 ignore_normal_resume = 0;
diff --git a/arch/x86/kernel/genapic_64.c b/arch/x86/kernel/genapic_64.c
index 021624c83583..cbaaf69bedb2 100644
--- a/arch/x86/kernel/genapic_64.c
+++ b/arch/x86/kernel/genapic_64.c
@@ -83,7 +83,7 @@ unsigned int read_apic_id(void)
83{ 83{
84 unsigned int id; 84 unsigned int id;
85 85
86 WARN_ON(preemptible()); 86 WARN_ON(preemptible() && num_online_cpus() > 1);
87 id = apic_read(APIC_ID); 87 id = apic_read(APIC_ID);
88 if (uv_system_type >= UV_X2APIC) 88 if (uv_system_type >= UV_X2APIC)
89 id |= __get_cpu_var(x2apic_extra_bits); 89 id |= __get_cpu_var(x2apic_extra_bits);
diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index 90f038af3adc..b2cc73768a9d 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -656,15 +656,16 @@ int_msg:
656 .asciz "Unknown interrupt or fault at EIP %p %p %p\n" 656 .asciz "Unknown interrupt or fault at EIP %p %p %p\n"
657 657
658fault_msg: 658fault_msg:
659 .asciz \ 659/* fault info: */
660/* fault info: */ "BUG: Int %d: CR2 %p\n" \ 660 .ascii "BUG: Int %d: CR2 %p\n"
661/* pusha regs: */ " EDI %p ESI %p EBP %p ESP %p\n" \ 661/* pusha regs: */
662 " EBX %p EDX %p ECX %p EAX %p\n" \ 662 .ascii " EDI %p ESI %p EBP %p ESP %p\n"
663/* fault frame: */ " err %p EIP %p CS %p flg %p\n" \ 663 .ascii " EBX %p EDX %p ECX %p EAX %p\n"
664 \ 664/* fault frame: */
665 "Stack: %p %p %p %p %p %p %p %p\n" \ 665 .ascii " err %p EIP %p CS %p flg %p\n"
666 " %p %p %p %p %p %p %p %p\n" \ 666 .ascii "Stack: %p %p %p %p %p %p %p %p\n"
667 " %p %p %p %p %p %p %p %p\n" 667 .ascii " %p %p %p %p %p %p %p %p\n"
668 .asciz " %p %p %p %p %p %p %p %p\n"
668 669
669#include "../../x86/xen/xen-head.S" 670#include "../../x86/xen/xen-head.S"
670 671
diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c
index 9007f9ea64ee..9b5cfcdfc426 100644
--- a/arch/x86/kernel/hpet.c
+++ b/arch/x86/kernel/hpet.c
@@ -137,9 +137,10 @@ static void hpet_reserve_platform_timers(unsigned long id)
137 hd.hd_irq[0] = HPET_LEGACY_8254; 137 hd.hd_irq[0] = HPET_LEGACY_8254;
138 hd.hd_irq[1] = HPET_LEGACY_RTC; 138 hd.hd_irq[1] = HPET_LEGACY_RTC;
139 139
140 for (i = 2; i < nrtimers; timer++, i++) 140 for (i = 2; i < nrtimers; timer++, i++) {
141 hd.hd_irq[i] = (timer->hpet_config & Tn_INT_ROUTE_CNF_MASK) >> 141 hd.hd_irq[i] = (readl(&timer->hpet_config) & Tn_INT_ROUTE_CNF_MASK) >>
142 Tn_INT_ROUTE_CNF_SHIFT; 142 Tn_INT_ROUTE_CNF_SHIFT;
143 }
143 144
144 hpet_alloc(&hd); 145 hpet_alloc(&hd);
145 146
diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
index ddee04043aeb..4bc1be5d5472 100644
--- a/arch/x86/kernel/kvmclock.c
+++ b/arch/x86/kernel/kvmclock.c
@@ -133,6 +133,7 @@ static int kvm_register_clock(void)
133 return native_write_msr_safe(MSR_KVM_SYSTEM_TIME, low, high); 133 return native_write_msr_safe(MSR_KVM_SYSTEM_TIME, low, high);
134} 134}
135 135
136#ifdef CONFIG_X86_LOCAL_APIC
136static void kvm_setup_secondary_clock(void) 137static void kvm_setup_secondary_clock(void)
137{ 138{
138 /* 139 /*
@@ -143,6 +144,7 @@ static void kvm_setup_secondary_clock(void)
143 /* ok, done with our trickery, call native */ 144 /* ok, done with our trickery, call native */
144 setup_secondary_APIC_clock(); 145 setup_secondary_APIC_clock();
145} 146}
147#endif
146 148
147/* 149/*
148 * After the clock is registered, the host will keep writing to the 150 * After the clock is registered, the host will keep writing to the
@@ -177,7 +179,9 @@ void __init kvmclock_init(void)
177 pv_time_ops.get_wallclock = kvm_get_wallclock; 179 pv_time_ops.get_wallclock = kvm_get_wallclock;
178 pv_time_ops.set_wallclock = kvm_set_wallclock; 180 pv_time_ops.set_wallclock = kvm_set_wallclock;
179 pv_time_ops.sched_clock = kvm_clock_read; 181 pv_time_ops.sched_clock = kvm_clock_read;
182#ifdef CONFIG_X86_LOCAL_APIC
180 pv_apic_ops.setup_secondary_clock = kvm_setup_secondary_clock; 183 pv_apic_ops.setup_secondary_clock = kvm_setup_secondary_clock;
184#endif
181 machine_ops.shutdown = kvm_shutdown; 185 machine_ops.shutdown = kvm_shutdown;
182#ifdef CONFIG_KEXEC 186#ifdef CONFIG_KEXEC
183 machine_ops.crash_shutdown = kvm_crash_shutdown; 187 machine_ops.crash_shutdown = kvm_crash_shutdown;
diff --git a/arch/x86/kernel/mpparse.c b/arch/x86/kernel/mpparse.c
index 3e2c54dc8b29..404683b94e79 100644
--- a/arch/x86/kernel/mpparse.c
+++ b/arch/x86/kernel/mpparse.c
@@ -794,6 +794,11 @@ void __init find_smp_config(void)
794 ACPI-based MP Configuration 794 ACPI-based MP Configuration
795 -------------------------------------------------------------------------- */ 795 -------------------------------------------------------------------------- */
796 796
797/*
798 * Keep this outside and initialized to 0, for !CONFIG_ACPI builds:
799 */
800int es7000_plat;
801
797#ifdef CONFIG_ACPI 802#ifdef CONFIG_ACPI
798 803
799#ifdef CONFIG_X86_IO_APIC 804#ifdef CONFIG_X86_IO_APIC
@@ -909,8 +914,6 @@ void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
909 MP_intsrc_info(&intsrc); 914 MP_intsrc_info(&intsrc);
910} 915}
911 916
912int es7000_plat;
913
914void __init mp_config_acpi_legacy_irqs(void) 917void __init mp_config_acpi_legacy_irqs(void)
915{ 918{
916 struct mpc_config_intsrc intsrc; 919 struct mpc_config_intsrc intsrc;
diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index 388b113a7d88..0c37f16b6950 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -14,7 +14,7 @@ EXPORT_SYMBOL(forbid_dac);
14const struct dma_mapping_ops *dma_ops; 14const struct dma_mapping_ops *dma_ops;
15EXPORT_SYMBOL(dma_ops); 15EXPORT_SYMBOL(dma_ops);
16 16
17int iommu_sac_force __read_mostly = 0; 17static int iommu_sac_force __read_mostly;
18 18
19#ifdef CONFIG_IOMMU_DEBUG 19#ifdef CONFIG_IOMMU_DEBUG
20int panic_on_overflow __read_mostly = 1; 20int panic_on_overflow __read_mostly = 1;
diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
index a4a838306b2c..f6be7d5f82f8 100644
--- a/arch/x86/kernel/reboot.c
+++ b/arch/x86/kernel/reboot.c
@@ -9,6 +9,7 @@
9#include <asm/desc.h> 9#include <asm/desc.h>
10#include <asm/hpet.h> 10#include <asm/hpet.h>
11#include <asm/pgtable.h> 11#include <asm/pgtable.h>
12#include <asm/proto.h>
12#include <asm/reboot_fixups.h> 13#include <asm/reboot_fixups.h>
13#include <asm/reboot.h> 14#include <asm/reboot.h>
14 15
@@ -148,7 +149,6 @@ static struct dmi_system_id __initdata reboot_dmi_table[] = {
148 .matches = { 149 .matches = {
149 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 150 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
150 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 745"), 151 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 745"),
151 DMI_MATCH(DMI_BOARD_NAME, "0WF810"),
152 }, 152 },
153 }, 153 },
154 { /* Handle problems with rebooting on Dell Optiplex 745's DFF*/ 154 { /* Handle problems with rebooting on Dell Optiplex 745's DFF*/
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index c0c68c18a788..cc6f5eb20b24 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -95,7 +95,7 @@ void __init setup_per_cpu_areas(void)
95 95
96 /* Copy section for each CPU (we discard the original) */ 96 /* Copy section for each CPU (we discard the original) */
97 size = PERCPU_ENOUGH_ROOM; 97 size = PERCPU_ENOUGH_ROOM;
98 printk(KERN_INFO "PERCPU: Allocating %lu bytes of per cpu data\n", 98 printk(KERN_INFO "PERCPU: Allocating %zd bytes of per cpu data\n",
99 size); 99 size);
100 100
101 for_each_possible_cpu(i) { 101 for_each_possible_cpu(i) {
diff --git a/arch/x86/kernel/signal_32.c b/arch/x86/kernel/signal_32.c
index 8e05e7f7bd40..d92373630963 100644
--- a/arch/x86/kernel/signal_32.c
+++ b/arch/x86/kernel/signal_32.c
@@ -57,7 +57,7 @@ sys_sigsuspend(int history0, int history1, old_sigset_t mask)
57 57
58 current->state = TASK_INTERRUPTIBLE; 58 current->state = TASK_INTERRUPTIBLE;
59 schedule(); 59 schedule();
60 set_thread_flag(TIF_RESTORE_SIGMASK); 60 set_restore_sigmask();
61 61
62 return -ERESTARTNOHAND; 62 return -ERESTARTNOHAND;
63} 63}
@@ -593,7 +593,7 @@ static void do_signal(struct pt_regs *regs)
593 if (!user_mode(regs)) 593 if (!user_mode(regs))
594 return; 594 return;
595 595
596 if (test_thread_flag(TIF_RESTORE_SIGMASK)) 596 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
597 oldset = &current->saved_sigmask; 597 oldset = &current->saved_sigmask;
598 else 598 else
599 oldset = &current->blocked; 599 oldset = &current->blocked;
@@ -612,13 +612,12 @@ static void do_signal(struct pt_regs *regs)
612 /* Whee! Actually deliver the signal. */ 612 /* Whee! Actually deliver the signal. */
613 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) { 613 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
614 /* 614 /*
615 * a signal was successfully delivered; the saved 615 * A signal was successfully delivered; the saved
616 * sigmask will have been stored in the signal frame, 616 * sigmask will have been stored in the signal frame,
617 * and will be restored by sigreturn, so we can simply 617 * and will be restored by sigreturn, so we can simply
618 * clear the TIF_RESTORE_SIGMASK flag 618 * clear the TS_RESTORE_SIGMASK flag.
619 */ 619 */
620 if (test_thread_flag(TIF_RESTORE_SIGMASK)) 620 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
621 clear_thread_flag(TIF_RESTORE_SIGMASK);
622 } 621 }
623 return; 622 return;
624 } 623 }
@@ -645,8 +644,8 @@ static void do_signal(struct pt_regs *regs)
645 * If there's no signal to deliver, we just put the saved sigmask 644 * If there's no signal to deliver, we just put the saved sigmask
646 * back. 645 * back.
647 */ 646 */
648 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 647 if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
649 clear_thread_flag(TIF_RESTORE_SIGMASK); 648 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
650 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL); 649 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
651 } 650 }
652} 651}
@@ -665,7 +664,7 @@ do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
665 } 664 }
666 665
667 /* deal with pending signal delivery */ 666 /* deal with pending signal delivery */
668 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)) 667 if (thread_info_flags & _TIF_SIGPENDING)
669 do_signal(regs); 668 do_signal(regs);
670 669
671 if (thread_info_flags & _TIF_HRTICK_RESCHED) 670 if (thread_info_flags & _TIF_HRTICK_RESCHED)
diff --git a/arch/x86/kernel/signal_64.c b/arch/x86/kernel/signal_64.c
index ccb2a4560c2d..e53b267662e7 100644
--- a/arch/x86/kernel/signal_64.c
+++ b/arch/x86/kernel/signal_64.c
@@ -427,7 +427,7 @@ static void do_signal(struct pt_regs *regs)
427 if (!user_mode(regs)) 427 if (!user_mode(regs))
428 return; 428 return;
429 429
430 if (test_thread_flag(TIF_RESTORE_SIGMASK)) 430 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
431 oldset = &current->saved_sigmask; 431 oldset = &current->saved_sigmask;
432 else 432 else
433 oldset = &current->blocked; 433 oldset = &current->blocked;
@@ -444,11 +444,13 @@ static void do_signal(struct pt_regs *regs)
444 444
445 /* Whee! Actually deliver the signal. */ 445 /* Whee! Actually deliver the signal. */
446 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) { 446 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
447 /* a signal was successfully delivered; the saved 447 /*
448 * A signal was successfully delivered; the saved
448 * sigmask will have been stored in the signal frame, 449 * sigmask will have been stored in the signal frame,
449 * and will be restored by sigreturn, so we can simply 450 * and will be restored by sigreturn, so we can simply
450 * clear the TIF_RESTORE_SIGMASK flag */ 451 * clear the TS_RESTORE_SIGMASK flag.
451 clear_thread_flag(TIF_RESTORE_SIGMASK); 452 */
453 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
452 } 454 }
453 return; 455 return;
454 } 456 }
@@ -476,8 +478,8 @@ static void do_signal(struct pt_regs *regs)
476 * If there's no signal to deliver, we just put the saved sigmask 478 * If there's no signal to deliver, we just put the saved sigmask
477 * back. 479 * back.
478 */ 480 */
479 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 481 if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
480 clear_thread_flag(TIF_RESTORE_SIGMASK); 482 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
481 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL); 483 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
482 } 484 }
483} 485}
@@ -498,7 +500,7 @@ void do_notify_resume(struct pt_regs *regs, void *unused,
498#endif /* CONFIG_X86_MCE */ 500#endif /* CONFIG_X86_MCE */
499 501
500 /* deal with pending signal delivery */ 502 /* deal with pending signal delivery */
501 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)) 503 if (thread_info_flags & _TIF_SIGPENDING)
502 do_signal(regs); 504 do_signal(regs);
503 505
504 if (thread_info_flags & _TIF_HRTICK_RESCHED) 506 if (thread_info_flags & _TIF_HRTICK_RESCHED)
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 84241a256dc8..6b087ab6cd8f 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -299,7 +299,7 @@ static void __cpuinit smp_callin(void)
299/* 299/*
300 * Activate a secondary processor. 300 * Activate a secondary processor.
301 */ 301 */
302void __cpuinit start_secondary(void *unused) 302static void __cpuinit start_secondary(void *unused)
303{ 303{
304 /* 304 /*
305 * Don't put *anything* before cpu_init(), SMP booting is too 305 * Don't put *anything* before cpu_init(), SMP booting is too
@@ -1306,7 +1306,7 @@ static void remove_siblinginfo(int cpu)
1306 cpu_clear(cpu, cpu_sibling_setup_map); 1306 cpu_clear(cpu, cpu_sibling_setup_map);
1307} 1307}
1308 1308
1309int additional_cpus __initdata = -1; 1309static int additional_cpus __initdata = -1;
1310 1310
1311static __init int setup_additional_cpus(char *s) 1311static __init int setup_additional_cpus(char *s)
1312{ 1312{
diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
index a86d26f036e1..d2ab52cc1d6b 100644
--- a/arch/x86/kernel/sys_i386_32.c
+++ b/arch/x86/kernel/sys_i386_32.c
@@ -22,23 +22,6 @@
22#include <asm/uaccess.h> 22#include <asm/uaccess.h>
23#include <asm/unistd.h> 23#include <asm/unistd.h>
24 24
25/*
26 * sys_pipe() is the normal C calling standard for creating
27 * a pipe. It's not the way Unix traditionally does this, though.
28 */
29asmlinkage int sys_pipe(unsigned long __user * fildes)
30{
31 int fd[2];
32 int error;
33
34 error = do_pipe(fd);
35 if (!error) {
36 if (copy_to_user(fildes, fd, 2*sizeof(int)))
37 error = -EFAULT;
38 }
39 return error;
40}
41
42asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, 25asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
43 unsigned long prot, unsigned long flags, 26 unsigned long prot, unsigned long flags,
44 unsigned long fd, unsigned long pgoff) 27 unsigned long fd, unsigned long pgoff)
diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
index bd802a5e1aa3..3b360ef33817 100644
--- a/arch/x86/kernel/sys_x86_64.c
+++ b/arch/x86/kernel/sys_x86_64.c
@@ -17,23 +17,6 @@
17#include <asm/uaccess.h> 17#include <asm/uaccess.h>
18#include <asm/ia32.h> 18#include <asm/ia32.h>
19 19
20/*
21 * sys_pipe() is the normal C calling standard for creating
22 * a pipe. It's not the way Unix traditionally does this, though.
23 */
24asmlinkage long sys_pipe(int __user *fildes)
25{
26 int fd[2];
27 int error;
28
29 error = do_pipe(fd);
30 if (!error) {
31 if (copy_to_user(fildes, fd, 2*sizeof(int)))
32 error = -EFAULT;
33 }
34 return error;
35}
36
37asmlinkage long sys_mmap(unsigned long addr, unsigned long len, unsigned long prot, unsigned long flags, 20asmlinkage long sys_mmap(unsigned long addr, unsigned long len, unsigned long prot, unsigned long flags,
38 unsigned long fd, unsigned long off) 21 unsigned long fd, unsigned long off)
39{ 22{
diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
index 361e31611276..3324d90038e4 100644
--- a/arch/x86/kvm/i8254.c
+++ b/arch/x86/kvm/i8254.c
@@ -35,7 +35,7 @@
35#include "i8254.h" 35#include "i8254.h"
36 36
37#ifndef CONFIG_X86_64 37#ifndef CONFIG_X86_64
38#define mod_64(x, y) ((x) - (y) * div64_64(x, y)) 38#define mod_64(x, y) ((x) - (y) * div64_u64(x, y))
39#else 39#else
40#define mod_64(x, y) ((x) % (y)) 40#define mod_64(x, y) ((x) % (y))
41#endif 41#endif
@@ -60,8 +60,8 @@ static u64 muldiv64(u64 a, u32 b, u32 c)
60 rl = (u64)u.l.low * (u64)b; 60 rl = (u64)u.l.low * (u64)b;
61 rh = (u64)u.l.high * (u64)b; 61 rh = (u64)u.l.high * (u64)b;
62 rh += (rl >> 32); 62 rh += (rl >> 32);
63 res.l.high = div64_64(rh, c); 63 res.l.high = div64_u64(rh, c);
64 res.l.low = div64_64(((mod_64(rh, c) << 32) + (rl & 0xffffffff)), c); 64 res.l.low = div64_u64(((mod_64(rh, c) << 32) + (rl & 0xffffffff)), c);
65 return res.ll; 65 return res.ll;
66} 66}
67 67
@@ -288,6 +288,8 @@ static void pit_load_count(struct kvm *kvm, int channel, u32 val)
288 * mode 1 is one shot, mode 2 is period, otherwise del timer */ 288 * mode 1 is one shot, mode 2 is period, otherwise del timer */
289 switch (ps->channels[0].mode) { 289 switch (ps->channels[0].mode) {
290 case 1: 290 case 1:
291 /* FIXME: enhance mode 4 precision */
292 case 4:
291 create_pit_timer(&ps->pit_timer, val, 0); 293 create_pit_timer(&ps->pit_timer, val, 0);
292 break; 294 break;
293 case 2: 295 case 2:
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 57ac4e4c556a..36809d79788b 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -25,13 +25,13 @@
25#include <linux/hrtimer.h> 25#include <linux/hrtimer.h>
26#include <linux/io.h> 26#include <linux/io.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/math64.h>
28#include <asm/processor.h> 29#include <asm/processor.h>
29#include <asm/msr.h> 30#include <asm/msr.h>
30#include <asm/page.h> 31#include <asm/page.h>
31#include <asm/current.h> 32#include <asm/current.h>
32#include <asm/apicdef.h> 33#include <asm/apicdef.h>
33#include <asm/atomic.h> 34#include <asm/atomic.h>
34#include <asm/div64.h>
35#include "irq.h" 35#include "irq.h"
36 36
37#define PRId64 "d" 37#define PRId64 "d"
@@ -526,8 +526,8 @@ static u32 apic_get_tmcct(struct kvm_lapic *apic)
526 } else 526 } else
527 passed = ktime_sub(now, apic->timer.last_update); 527 passed = ktime_sub(now, apic->timer.last_update);
528 528
529 counter_passed = div64_64(ktime_to_ns(passed), 529 counter_passed = div64_u64(ktime_to_ns(passed),
530 (APIC_BUS_CYCLE_NS * apic->timer.divide_count)); 530 (APIC_BUS_CYCLE_NS * apic->timer.divide_count));
531 531
532 if (counter_passed > tmcct) { 532 if (counter_passed > tmcct) {
533 if (unlikely(!apic_lvtt_period(apic))) { 533 if (unlikely(!apic_lvtt_period(apic))) {
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 2ad6f5481671..36c5406b1813 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -79,36 +79,6 @@ static int dbg = 1;
79 } 79 }
80#endif 80#endif
81 81
82#define PT64_PT_BITS 9
83#define PT64_ENT_PER_PAGE (1 << PT64_PT_BITS)
84#define PT32_PT_BITS 10
85#define PT32_ENT_PER_PAGE (1 << PT32_PT_BITS)
86
87#define PT_WRITABLE_SHIFT 1
88
89#define PT_PRESENT_MASK (1ULL << 0)
90#define PT_WRITABLE_MASK (1ULL << PT_WRITABLE_SHIFT)
91#define PT_USER_MASK (1ULL << 2)
92#define PT_PWT_MASK (1ULL << 3)
93#define PT_PCD_MASK (1ULL << 4)
94#define PT_ACCESSED_MASK (1ULL << 5)
95#define PT_DIRTY_MASK (1ULL << 6)
96#define PT_PAGE_SIZE_MASK (1ULL << 7)
97#define PT_PAT_MASK (1ULL << 7)
98#define PT_GLOBAL_MASK (1ULL << 8)
99#define PT64_NX_SHIFT 63
100#define PT64_NX_MASK (1ULL << PT64_NX_SHIFT)
101
102#define PT_PAT_SHIFT 7
103#define PT_DIR_PAT_SHIFT 12
104#define PT_DIR_PAT_MASK (1ULL << PT_DIR_PAT_SHIFT)
105
106#define PT32_DIR_PSE36_SIZE 4
107#define PT32_DIR_PSE36_SHIFT 13
108#define PT32_DIR_PSE36_MASK \
109 (((1ULL << PT32_DIR_PSE36_SIZE) - 1) << PT32_DIR_PSE36_SHIFT)
110
111
112#define PT_FIRST_AVAIL_BITS_SHIFT 9 82#define PT_FIRST_AVAIL_BITS_SHIFT 9
113#define PT64_SECOND_AVAIL_BITS_SHIFT 52 83#define PT64_SECOND_AVAIL_BITS_SHIFT 52
114 84
@@ -154,10 +124,6 @@ static int dbg = 1;
154#define PFERR_USER_MASK (1U << 2) 124#define PFERR_USER_MASK (1U << 2)
155#define PFERR_FETCH_MASK (1U << 4) 125#define PFERR_FETCH_MASK (1U << 4)
156 126
157#define PT64_ROOT_LEVEL 4
158#define PT32_ROOT_LEVEL 2
159#define PT32E_ROOT_LEVEL 3
160
161#define PT_DIRECTORY_LEVEL 2 127#define PT_DIRECTORY_LEVEL 2
162#define PT_PAGE_TABLE_LEVEL 1 128#define PT_PAGE_TABLE_LEVEL 1
163 129
@@ -186,6 +152,12 @@ static struct kmem_cache *mmu_page_header_cache;
186 152
187static u64 __read_mostly shadow_trap_nonpresent_pte; 153static u64 __read_mostly shadow_trap_nonpresent_pte;
188static u64 __read_mostly shadow_notrap_nonpresent_pte; 154static u64 __read_mostly shadow_notrap_nonpresent_pte;
155static u64 __read_mostly shadow_base_present_pte;
156static u64 __read_mostly shadow_nx_mask;
157static u64 __read_mostly shadow_x_mask; /* mutual exclusive with nx_mask */
158static u64 __read_mostly shadow_user_mask;
159static u64 __read_mostly shadow_accessed_mask;
160static u64 __read_mostly shadow_dirty_mask;
189 161
190void kvm_mmu_set_nonpresent_ptes(u64 trap_pte, u64 notrap_pte) 162void kvm_mmu_set_nonpresent_ptes(u64 trap_pte, u64 notrap_pte)
191{ 163{
@@ -194,6 +166,23 @@ void kvm_mmu_set_nonpresent_ptes(u64 trap_pte, u64 notrap_pte)
194} 166}
195EXPORT_SYMBOL_GPL(kvm_mmu_set_nonpresent_ptes); 167EXPORT_SYMBOL_GPL(kvm_mmu_set_nonpresent_ptes);
196 168
169void kvm_mmu_set_base_ptes(u64 base_pte)
170{
171 shadow_base_present_pte = base_pte;
172}
173EXPORT_SYMBOL_GPL(kvm_mmu_set_base_ptes);
174
175void kvm_mmu_set_mask_ptes(u64 user_mask, u64 accessed_mask,
176 u64 dirty_mask, u64 nx_mask, u64 x_mask)
177{
178 shadow_user_mask = user_mask;
179 shadow_accessed_mask = accessed_mask;
180 shadow_dirty_mask = dirty_mask;
181 shadow_nx_mask = nx_mask;
182 shadow_x_mask = x_mask;
183}
184EXPORT_SYMBOL_GPL(kvm_mmu_set_mask_ptes);
185
197static int is_write_protection(struct kvm_vcpu *vcpu) 186static int is_write_protection(struct kvm_vcpu *vcpu)
198{ 187{
199 return vcpu->arch.cr0 & X86_CR0_WP; 188 return vcpu->arch.cr0 & X86_CR0_WP;
@@ -232,7 +221,7 @@ static int is_writeble_pte(unsigned long pte)
232 221
233static int is_dirty_pte(unsigned long pte) 222static int is_dirty_pte(unsigned long pte)
234{ 223{
235 return pte & PT_DIRTY_MASK; 224 return pte & shadow_dirty_mask;
236} 225}
237 226
238static int is_rmap_pte(u64 pte) 227static int is_rmap_pte(u64 pte)
@@ -387,7 +376,6 @@ static void account_shadowed(struct kvm *kvm, gfn_t gfn)
387 376
388 write_count = slot_largepage_idx(gfn, gfn_to_memslot(kvm, gfn)); 377 write_count = slot_largepage_idx(gfn, gfn_to_memslot(kvm, gfn));
389 *write_count += 1; 378 *write_count += 1;
390 WARN_ON(*write_count > KVM_PAGES_PER_HPAGE);
391} 379}
392 380
393static void unaccount_shadowed(struct kvm *kvm, gfn_t gfn) 381static void unaccount_shadowed(struct kvm *kvm, gfn_t gfn)
@@ -547,7 +535,7 @@ static void rmap_remove(struct kvm *kvm, u64 *spte)
547 return; 535 return;
548 sp = page_header(__pa(spte)); 536 sp = page_header(__pa(spte));
549 pfn = spte_to_pfn(*spte); 537 pfn = spte_to_pfn(*spte);
550 if (*spte & PT_ACCESSED_MASK) 538 if (*spte & shadow_accessed_mask)
551 kvm_set_pfn_accessed(pfn); 539 kvm_set_pfn_accessed(pfn);
552 if (is_writeble_pte(*spte)) 540 if (is_writeble_pte(*spte))
553 kvm_release_pfn_dirty(pfn); 541 kvm_release_pfn_dirty(pfn);
@@ -1073,17 +1061,17 @@ static void mmu_set_spte(struct kvm_vcpu *vcpu, u64 *shadow_pte,
1073 * whether the guest actually used the pte (in order to detect 1061 * whether the guest actually used the pte (in order to detect
1074 * demand paging). 1062 * demand paging).
1075 */ 1063 */
1076 spte = PT_PRESENT_MASK | PT_DIRTY_MASK; 1064 spte = shadow_base_present_pte | shadow_dirty_mask;
1077 if (!speculative) 1065 if (!speculative)
1078 pte_access |= PT_ACCESSED_MASK; 1066 pte_access |= PT_ACCESSED_MASK;
1079 if (!dirty) 1067 if (!dirty)
1080 pte_access &= ~ACC_WRITE_MASK; 1068 pte_access &= ~ACC_WRITE_MASK;
1081 if (!(pte_access & ACC_EXEC_MASK)) 1069 if (pte_access & ACC_EXEC_MASK)
1082 spte |= PT64_NX_MASK; 1070 spte |= shadow_x_mask;
1083 1071 else
1084 spte |= PT_PRESENT_MASK; 1072 spte |= shadow_nx_mask;
1085 if (pte_access & ACC_USER_MASK) 1073 if (pte_access & ACC_USER_MASK)
1086 spte |= PT_USER_MASK; 1074 spte |= shadow_user_mask;
1087 if (largepage) 1075 if (largepage)
1088 spte |= PT_PAGE_SIZE_MASK; 1076 spte |= PT_PAGE_SIZE_MASK;
1089 1077
@@ -1188,8 +1176,9 @@ static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, int write,
1188 return -ENOMEM; 1176 return -ENOMEM;
1189 } 1177 }
1190 1178
1191 table[index] = __pa(new_table->spt) | PT_PRESENT_MASK 1179 table[index] = __pa(new_table->spt)
1192 | PT_WRITABLE_MASK | PT_USER_MASK; 1180 | PT_PRESENT_MASK | PT_WRITABLE_MASK
1181 | shadow_user_mask | shadow_x_mask;
1193 } 1182 }
1194 table_addr = table[index] & PT64_BASE_ADDR_MASK; 1183 table_addr = table[index] & PT64_BASE_ADDR_MASK;
1195 } 1184 }
@@ -1244,7 +1233,6 @@ static void mmu_free_roots(struct kvm_vcpu *vcpu)
1244 if (!VALID_PAGE(vcpu->arch.mmu.root_hpa)) 1233 if (!VALID_PAGE(vcpu->arch.mmu.root_hpa))
1245 return; 1234 return;
1246 spin_lock(&vcpu->kvm->mmu_lock); 1235 spin_lock(&vcpu->kvm->mmu_lock);
1247#ifdef CONFIG_X86_64
1248 if (vcpu->arch.mmu.shadow_root_level == PT64_ROOT_LEVEL) { 1236 if (vcpu->arch.mmu.shadow_root_level == PT64_ROOT_LEVEL) {
1249 hpa_t root = vcpu->arch.mmu.root_hpa; 1237 hpa_t root = vcpu->arch.mmu.root_hpa;
1250 1238
@@ -1256,7 +1244,6 @@ static void mmu_free_roots(struct kvm_vcpu *vcpu)
1256 spin_unlock(&vcpu->kvm->mmu_lock); 1244 spin_unlock(&vcpu->kvm->mmu_lock);
1257 return; 1245 return;
1258 } 1246 }
1259#endif
1260 for (i = 0; i < 4; ++i) { 1247 for (i = 0; i < 4; ++i) {
1261 hpa_t root = vcpu->arch.mmu.pae_root[i]; 1248 hpa_t root = vcpu->arch.mmu.pae_root[i];
1262 1249
@@ -1282,7 +1269,6 @@ static void mmu_alloc_roots(struct kvm_vcpu *vcpu)
1282 1269
1283 root_gfn = vcpu->arch.cr3 >> PAGE_SHIFT; 1270 root_gfn = vcpu->arch.cr3 >> PAGE_SHIFT;
1284 1271
1285#ifdef CONFIG_X86_64
1286 if (vcpu->arch.mmu.shadow_root_level == PT64_ROOT_LEVEL) { 1272 if (vcpu->arch.mmu.shadow_root_level == PT64_ROOT_LEVEL) {
1287 hpa_t root = vcpu->arch.mmu.root_hpa; 1273 hpa_t root = vcpu->arch.mmu.root_hpa;
1288 1274
@@ -1297,7 +1283,6 @@ static void mmu_alloc_roots(struct kvm_vcpu *vcpu)
1297 vcpu->arch.mmu.root_hpa = root; 1283 vcpu->arch.mmu.root_hpa = root;
1298 return; 1284 return;
1299 } 1285 }
1300#endif
1301 metaphysical = !is_paging(vcpu); 1286 metaphysical = !is_paging(vcpu);
1302 if (tdp_enabled) 1287 if (tdp_enabled)
1303 metaphysical = 1; 1288 metaphysical = 1;
@@ -1377,7 +1362,7 @@ static int tdp_page_fault(struct kvm_vcpu *vcpu, gva_t gpa,
1377 spin_lock(&vcpu->kvm->mmu_lock); 1362 spin_lock(&vcpu->kvm->mmu_lock);
1378 kvm_mmu_free_some_pages(vcpu); 1363 kvm_mmu_free_some_pages(vcpu);
1379 r = __direct_map(vcpu, gpa, error_code & PFERR_WRITE_MASK, 1364 r = __direct_map(vcpu, gpa, error_code & PFERR_WRITE_MASK,
1380 largepage, gfn, pfn, TDP_ROOT_LEVEL); 1365 largepage, gfn, pfn, kvm_x86_ops->get_tdp_level());
1381 spin_unlock(&vcpu->kvm->mmu_lock); 1366 spin_unlock(&vcpu->kvm->mmu_lock);
1382 1367
1383 return r; 1368 return r;
@@ -1484,7 +1469,7 @@ static int init_kvm_tdp_mmu(struct kvm_vcpu *vcpu)
1484 context->page_fault = tdp_page_fault; 1469 context->page_fault = tdp_page_fault;
1485 context->free = nonpaging_free; 1470 context->free = nonpaging_free;
1486 context->prefetch_page = nonpaging_prefetch_page; 1471 context->prefetch_page = nonpaging_prefetch_page;
1487 context->shadow_root_level = TDP_ROOT_LEVEL; 1472 context->shadow_root_level = kvm_x86_ops->get_tdp_level();
1488 context->root_hpa = INVALID_PAGE; 1473 context->root_hpa = INVALID_PAGE;
1489 1474
1490 if (!is_paging(vcpu)) { 1475 if (!is_paging(vcpu)) {
@@ -1633,7 +1618,7 @@ static bool last_updated_pte_accessed(struct kvm_vcpu *vcpu)
1633{ 1618{
1634 u64 *spte = vcpu->arch.last_pte_updated; 1619 u64 *spte = vcpu->arch.last_pte_updated;
1635 1620
1636 return !!(spte && (*spte & PT_ACCESSED_MASK)); 1621 return !!(spte && (*spte & shadow_accessed_mask));
1637} 1622}
1638 1623
1639static void mmu_guess_page_from_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa, 1624static void mmu_guess_page_from_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
index e64e9f56a65e..1730757bbc7a 100644
--- a/arch/x86/kvm/mmu.h
+++ b/arch/x86/kvm/mmu.h
@@ -3,11 +3,38 @@
3 3
4#include <linux/kvm_host.h> 4#include <linux/kvm_host.h>
5 5
6#ifdef CONFIG_X86_64 6#define PT64_PT_BITS 9
7#define TDP_ROOT_LEVEL PT64_ROOT_LEVEL 7#define PT64_ENT_PER_PAGE (1 << PT64_PT_BITS)
8#else 8#define PT32_PT_BITS 10
9#define TDP_ROOT_LEVEL PT32E_ROOT_LEVEL 9#define PT32_ENT_PER_PAGE (1 << PT32_PT_BITS)
10#endif 10
11#define PT_WRITABLE_SHIFT 1
12
13#define PT_PRESENT_MASK (1ULL << 0)
14#define PT_WRITABLE_MASK (1ULL << PT_WRITABLE_SHIFT)
15#define PT_USER_MASK (1ULL << 2)
16#define PT_PWT_MASK (1ULL << 3)
17#define PT_PCD_MASK (1ULL << 4)
18#define PT_ACCESSED_MASK (1ULL << 5)
19#define PT_DIRTY_MASK (1ULL << 6)
20#define PT_PAGE_SIZE_MASK (1ULL << 7)
21#define PT_PAT_MASK (1ULL << 7)
22#define PT_GLOBAL_MASK (1ULL << 8)
23#define PT64_NX_SHIFT 63
24#define PT64_NX_MASK (1ULL << PT64_NX_SHIFT)
25
26#define PT_PAT_SHIFT 7
27#define PT_DIR_PAT_SHIFT 12
28#define PT_DIR_PAT_MASK (1ULL << PT_DIR_PAT_SHIFT)
29
30#define PT32_DIR_PSE36_SIZE 4
31#define PT32_DIR_PSE36_SHIFT 13
32#define PT32_DIR_PSE36_MASK \
33 (((1ULL << PT32_DIR_PSE36_SIZE) - 1) << PT32_DIR_PSE36_SHIFT)
34
35#define PT64_ROOT_LEVEL 4
36#define PT32_ROOT_LEVEL 2
37#define PT32E_ROOT_LEVEL 3
11 38
12static inline void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu) 39static inline void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu)
13{ 40{
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 89e0be2c10d0..ab22615eee89 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -1863,6 +1863,15 @@ static bool svm_cpu_has_accelerated_tpr(void)
1863 return false; 1863 return false;
1864} 1864}
1865 1865
1866static int get_npt_level(void)
1867{
1868#ifdef CONFIG_X86_64
1869 return PT64_ROOT_LEVEL;
1870#else
1871 return PT32E_ROOT_LEVEL;
1872#endif
1873}
1874
1866static struct kvm_x86_ops svm_x86_ops = { 1875static struct kvm_x86_ops svm_x86_ops = {
1867 .cpu_has_kvm_support = has_svm, 1876 .cpu_has_kvm_support = has_svm,
1868 .disabled_by_bios = is_disabled, 1877 .disabled_by_bios = is_disabled,
@@ -1920,6 +1929,7 @@ static struct kvm_x86_ops svm_x86_ops = {
1920 .inject_pending_vectors = do_interrupt_requests, 1929 .inject_pending_vectors = do_interrupt_requests,
1921 1930
1922 .set_tss_addr = svm_set_tss_addr, 1931 .set_tss_addr = svm_set_tss_addr,
1932 .get_tdp_level = get_npt_level,
1923}; 1933};
1924 1934
1925static int __init svm_init(void) 1935static int __init svm_init(void)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 8e5d6645b90d..bfe4db11989c 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -42,6 +42,9 @@ module_param(enable_vpid, bool, 0);
42static int flexpriority_enabled = 1; 42static int flexpriority_enabled = 1;
43module_param(flexpriority_enabled, bool, 0); 43module_param(flexpriority_enabled, bool, 0);
44 44
45static int enable_ept = 1;
46module_param(enable_ept, bool, 0);
47
45struct vmcs { 48struct vmcs {
46 u32 revision_id; 49 u32 revision_id;
47 u32 abort; 50 u32 abort;
@@ -84,7 +87,7 @@ static inline struct vcpu_vmx *to_vmx(struct kvm_vcpu *vcpu)
84 return container_of(vcpu, struct vcpu_vmx, vcpu); 87 return container_of(vcpu, struct vcpu_vmx, vcpu);
85} 88}
86 89
87static int init_rmode_tss(struct kvm *kvm); 90static int init_rmode(struct kvm *kvm);
88 91
89static DEFINE_PER_CPU(struct vmcs *, vmxarea); 92static DEFINE_PER_CPU(struct vmcs *, vmxarea);
90static DEFINE_PER_CPU(struct vmcs *, current_vmcs); 93static DEFINE_PER_CPU(struct vmcs *, current_vmcs);
@@ -107,6 +110,11 @@ static struct vmcs_config {
107 u32 vmentry_ctrl; 110 u32 vmentry_ctrl;
108} vmcs_config; 111} vmcs_config;
109 112
113struct vmx_capability {
114 u32 ept;
115 u32 vpid;
116} vmx_capability;
117
110#define VMX_SEGMENT_FIELD(seg) \ 118#define VMX_SEGMENT_FIELD(seg) \
111 [VCPU_SREG_##seg] = { \ 119 [VCPU_SREG_##seg] = { \
112 .selector = GUEST_##seg##_SELECTOR, \ 120 .selector = GUEST_##seg##_SELECTOR, \
@@ -214,6 +222,32 @@ static inline bool cpu_has_vmx_virtualize_apic_accesses(void)
214 SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES); 222 SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES);
215} 223}
216 224
225static inline int cpu_has_vmx_invept_individual_addr(void)
226{
227 return (!!(vmx_capability.ept & VMX_EPT_EXTENT_INDIVIDUAL_BIT));
228}
229
230static inline int cpu_has_vmx_invept_context(void)
231{
232 return (!!(vmx_capability.ept & VMX_EPT_EXTENT_CONTEXT_BIT));
233}
234
235static inline int cpu_has_vmx_invept_global(void)
236{
237 return (!!(vmx_capability.ept & VMX_EPT_EXTENT_GLOBAL_BIT));
238}
239
240static inline int cpu_has_vmx_ept(void)
241{
242 return (vmcs_config.cpu_based_2nd_exec_ctrl &
243 SECONDARY_EXEC_ENABLE_EPT);
244}
245
246static inline int vm_need_ept(void)
247{
248 return (cpu_has_vmx_ept() && enable_ept);
249}
250
217static inline int vm_need_virtualize_apic_accesses(struct kvm *kvm) 251static inline int vm_need_virtualize_apic_accesses(struct kvm *kvm)
218{ 252{
219 return ((cpu_has_vmx_virtualize_apic_accesses()) && 253 return ((cpu_has_vmx_virtualize_apic_accesses()) &&
@@ -250,6 +284,18 @@ static inline void __invvpid(int ext, u16 vpid, gva_t gva)
250 : : "a"(&operand), "c"(ext) : "cc", "memory"); 284 : : "a"(&operand), "c"(ext) : "cc", "memory");
251} 285}
252 286
287static inline void __invept(int ext, u64 eptp, gpa_t gpa)
288{
289 struct {
290 u64 eptp, gpa;
291 } operand = {eptp, gpa};
292
293 asm volatile (ASM_VMX_INVEPT
294 /* CF==1 or ZF==1 --> rc = -1 */
295 "; ja 1f ; ud2 ; 1:\n"
296 : : "a" (&operand), "c" (ext) : "cc", "memory");
297}
298
253static struct kvm_msr_entry *find_msr_entry(struct vcpu_vmx *vmx, u32 msr) 299static struct kvm_msr_entry *find_msr_entry(struct vcpu_vmx *vmx, u32 msr)
254{ 300{
255 int i; 301 int i;
@@ -301,6 +347,33 @@ static inline void vpid_sync_vcpu_all(struct vcpu_vmx *vmx)
301 __invvpid(VMX_VPID_EXTENT_SINGLE_CONTEXT, vmx->vpid, 0); 347 __invvpid(VMX_VPID_EXTENT_SINGLE_CONTEXT, vmx->vpid, 0);
302} 348}
303 349
350static inline void ept_sync_global(void)
351{
352 if (cpu_has_vmx_invept_global())
353 __invept(VMX_EPT_EXTENT_GLOBAL, 0, 0);
354}
355
356static inline void ept_sync_context(u64 eptp)
357{
358 if (vm_need_ept()) {
359 if (cpu_has_vmx_invept_context())
360 __invept(VMX_EPT_EXTENT_CONTEXT, eptp, 0);
361 else
362 ept_sync_global();
363 }
364}
365
366static inline void ept_sync_individual_addr(u64 eptp, gpa_t gpa)
367{
368 if (vm_need_ept()) {
369 if (cpu_has_vmx_invept_individual_addr())
370 __invept(VMX_EPT_EXTENT_INDIVIDUAL_ADDR,
371 eptp, gpa);
372 else
373 ept_sync_context(eptp);
374 }
375}
376
304static unsigned long vmcs_readl(unsigned long field) 377static unsigned long vmcs_readl(unsigned long field)
305{ 378{
306 unsigned long value; 379 unsigned long value;
@@ -388,6 +461,8 @@ static void update_exception_bitmap(struct kvm_vcpu *vcpu)
388 eb |= 1u << 1; 461 eb |= 1u << 1;
389 if (vcpu->arch.rmode.active) 462 if (vcpu->arch.rmode.active)
390 eb = ~0; 463 eb = ~0;
464 if (vm_need_ept())
465 eb &= ~(1u << PF_VECTOR); /* bypass_guest_pf = 0 */
391 vmcs_write32(EXCEPTION_BITMAP, eb); 466 vmcs_write32(EXCEPTION_BITMAP, eb);
392} 467}
393 468
@@ -985,7 +1060,7 @@ static __init int adjust_vmx_controls(u32 ctl_min, u32 ctl_opt,
985static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf) 1060static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf)
986{ 1061{
987 u32 vmx_msr_low, vmx_msr_high; 1062 u32 vmx_msr_low, vmx_msr_high;
988 u32 min, opt; 1063 u32 min, opt, min2, opt2;
989 u32 _pin_based_exec_control = 0; 1064 u32 _pin_based_exec_control = 0;
990 u32 _cpu_based_exec_control = 0; 1065 u32 _cpu_based_exec_control = 0;
991 u32 _cpu_based_2nd_exec_control = 0; 1066 u32 _cpu_based_2nd_exec_control = 0;
@@ -1003,6 +1078,8 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf)
1003 CPU_BASED_CR8_LOAD_EXITING | 1078 CPU_BASED_CR8_LOAD_EXITING |
1004 CPU_BASED_CR8_STORE_EXITING | 1079 CPU_BASED_CR8_STORE_EXITING |
1005#endif 1080#endif
1081 CPU_BASED_CR3_LOAD_EXITING |
1082 CPU_BASED_CR3_STORE_EXITING |
1006 CPU_BASED_USE_IO_BITMAPS | 1083 CPU_BASED_USE_IO_BITMAPS |
1007 CPU_BASED_MOV_DR_EXITING | 1084 CPU_BASED_MOV_DR_EXITING |
1008 CPU_BASED_USE_TSC_OFFSETING; 1085 CPU_BASED_USE_TSC_OFFSETING;
@@ -1018,11 +1095,13 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf)
1018 ~CPU_BASED_CR8_STORE_EXITING; 1095 ~CPU_BASED_CR8_STORE_EXITING;
1019#endif 1096#endif
1020 if (_cpu_based_exec_control & CPU_BASED_ACTIVATE_SECONDARY_CONTROLS) { 1097 if (_cpu_based_exec_control & CPU_BASED_ACTIVATE_SECONDARY_CONTROLS) {
1021 min = 0; 1098 min2 = 0;
1022 opt = SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES | 1099 opt2 = SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES |
1023 SECONDARY_EXEC_WBINVD_EXITING | 1100 SECONDARY_EXEC_WBINVD_EXITING |
1024 SECONDARY_EXEC_ENABLE_VPID; 1101 SECONDARY_EXEC_ENABLE_VPID |
1025 if (adjust_vmx_controls(min, opt, MSR_IA32_VMX_PROCBASED_CTLS2, 1102 SECONDARY_EXEC_ENABLE_EPT;
1103 if (adjust_vmx_controls(min2, opt2,
1104 MSR_IA32_VMX_PROCBASED_CTLS2,
1026 &_cpu_based_2nd_exec_control) < 0) 1105 &_cpu_based_2nd_exec_control) < 0)
1027 return -EIO; 1106 return -EIO;
1028 } 1107 }
@@ -1031,6 +1110,16 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf)
1031 SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES)) 1110 SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES))
1032 _cpu_based_exec_control &= ~CPU_BASED_TPR_SHADOW; 1111 _cpu_based_exec_control &= ~CPU_BASED_TPR_SHADOW;
1033#endif 1112#endif
1113 if (_cpu_based_2nd_exec_control & SECONDARY_EXEC_ENABLE_EPT) {
1114 /* CR3 accesses don't need to cause VM Exits when EPT enabled */
1115 min &= ~(CPU_BASED_CR3_LOAD_EXITING |
1116 CPU_BASED_CR3_STORE_EXITING);
1117 if (adjust_vmx_controls(min, opt, MSR_IA32_VMX_PROCBASED_CTLS,
1118 &_cpu_based_exec_control) < 0)
1119 return -EIO;
1120 rdmsr(MSR_IA32_VMX_EPT_VPID_CAP,
1121 vmx_capability.ept, vmx_capability.vpid);
1122 }
1034 1123
1035 min = 0; 1124 min = 0;
1036#ifdef CONFIG_X86_64 1125#ifdef CONFIG_X86_64
@@ -1256,7 +1345,7 @@ static void enter_rmode(struct kvm_vcpu *vcpu)
1256 fix_rmode_seg(VCPU_SREG_FS, &vcpu->arch.rmode.fs); 1345 fix_rmode_seg(VCPU_SREG_FS, &vcpu->arch.rmode.fs);
1257 1346
1258 kvm_mmu_reset_context(vcpu); 1347 kvm_mmu_reset_context(vcpu);
1259 init_rmode_tss(vcpu->kvm); 1348 init_rmode(vcpu->kvm);
1260} 1349}
1261 1350
1262#ifdef CONFIG_X86_64 1351#ifdef CONFIG_X86_64
@@ -1304,8 +1393,64 @@ static void vmx_decache_cr4_guest_bits(struct kvm_vcpu *vcpu)
1304 vcpu->arch.cr4 |= vmcs_readl(GUEST_CR4) & ~KVM_GUEST_CR4_MASK; 1393 vcpu->arch.cr4 |= vmcs_readl(GUEST_CR4) & ~KVM_GUEST_CR4_MASK;
1305} 1394}
1306 1395
1396static void ept_load_pdptrs(struct kvm_vcpu *vcpu)
1397{
1398 if (is_paging(vcpu) && is_pae(vcpu) && !is_long_mode(vcpu)) {
1399 if (!load_pdptrs(vcpu, vcpu->arch.cr3)) {
1400 printk(KERN_ERR "EPT: Fail to load pdptrs!\n");
1401 return;
1402 }
1403 vmcs_write64(GUEST_PDPTR0, vcpu->arch.pdptrs[0]);
1404 vmcs_write64(GUEST_PDPTR1, vcpu->arch.pdptrs[1]);
1405 vmcs_write64(GUEST_PDPTR2, vcpu->arch.pdptrs[2]);
1406 vmcs_write64(GUEST_PDPTR3, vcpu->arch.pdptrs[3]);
1407 }
1408}
1409
1410static void vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4);
1411
1412static void ept_update_paging_mode_cr0(unsigned long *hw_cr0,
1413 unsigned long cr0,
1414 struct kvm_vcpu *vcpu)
1415{
1416 if (!(cr0 & X86_CR0_PG)) {
1417 /* From paging/starting to nonpaging */
1418 vmcs_write32(CPU_BASED_VM_EXEC_CONTROL,
1419 vmcs_config.cpu_based_exec_ctrl |
1420 (CPU_BASED_CR3_LOAD_EXITING |
1421 CPU_BASED_CR3_STORE_EXITING));
1422 vcpu->arch.cr0 = cr0;
1423 vmx_set_cr4(vcpu, vcpu->arch.cr4);
1424 *hw_cr0 |= X86_CR0_PE | X86_CR0_PG;
1425 *hw_cr0 &= ~X86_CR0_WP;
1426 } else if (!is_paging(vcpu)) {
1427 /* From nonpaging to paging */
1428 vmcs_write32(CPU_BASED_VM_EXEC_CONTROL,
1429 vmcs_config.cpu_based_exec_ctrl &
1430 ~(CPU_BASED_CR3_LOAD_EXITING |
1431 CPU_BASED_CR3_STORE_EXITING));
1432 vcpu->arch.cr0 = cr0;
1433 vmx_set_cr4(vcpu, vcpu->arch.cr4);
1434 if (!(vcpu->arch.cr0 & X86_CR0_WP))
1435 *hw_cr0 &= ~X86_CR0_WP;
1436 }
1437}
1438
1439static void ept_update_paging_mode_cr4(unsigned long *hw_cr4,
1440 struct kvm_vcpu *vcpu)
1441{
1442 if (!is_paging(vcpu)) {
1443 *hw_cr4 &= ~X86_CR4_PAE;
1444 *hw_cr4 |= X86_CR4_PSE;
1445 } else if (!(vcpu->arch.cr4 & X86_CR4_PAE))
1446 *hw_cr4 &= ~X86_CR4_PAE;
1447}
1448
1307static void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0) 1449static void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
1308{ 1450{
1451 unsigned long hw_cr0 = (cr0 & ~KVM_GUEST_CR0_MASK) |
1452 KVM_VM_CR0_ALWAYS_ON;
1453
1309 vmx_fpu_deactivate(vcpu); 1454 vmx_fpu_deactivate(vcpu);
1310 1455
1311 if (vcpu->arch.rmode.active && (cr0 & X86_CR0_PE)) 1456 if (vcpu->arch.rmode.active && (cr0 & X86_CR0_PE))
@@ -1323,29 +1468,61 @@ static void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
1323 } 1468 }
1324#endif 1469#endif
1325 1470
1471 if (vm_need_ept())
1472 ept_update_paging_mode_cr0(&hw_cr0, cr0, vcpu);
1473
1326 vmcs_writel(CR0_READ_SHADOW, cr0); 1474 vmcs_writel(CR0_READ_SHADOW, cr0);
1327 vmcs_writel(GUEST_CR0, 1475 vmcs_writel(GUEST_CR0, hw_cr0);
1328 (cr0 & ~KVM_GUEST_CR0_MASK) | KVM_VM_CR0_ALWAYS_ON);
1329 vcpu->arch.cr0 = cr0; 1476 vcpu->arch.cr0 = cr0;
1330 1477
1331 if (!(cr0 & X86_CR0_TS) || !(cr0 & X86_CR0_PE)) 1478 if (!(cr0 & X86_CR0_TS) || !(cr0 & X86_CR0_PE))
1332 vmx_fpu_activate(vcpu); 1479 vmx_fpu_activate(vcpu);
1333} 1480}
1334 1481
1482static u64 construct_eptp(unsigned long root_hpa)
1483{
1484 u64 eptp;
1485
1486 /* TODO write the value reading from MSR */
1487 eptp = VMX_EPT_DEFAULT_MT |
1488 VMX_EPT_DEFAULT_GAW << VMX_EPT_GAW_EPTP_SHIFT;
1489 eptp |= (root_hpa & PAGE_MASK);
1490
1491 return eptp;
1492}
1493
1335static void vmx_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3) 1494static void vmx_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
1336{ 1495{
1496 unsigned long guest_cr3;
1497 u64 eptp;
1498
1499 guest_cr3 = cr3;
1500 if (vm_need_ept()) {
1501 eptp = construct_eptp(cr3);
1502 vmcs_write64(EPT_POINTER, eptp);
1503 ept_sync_context(eptp);
1504 ept_load_pdptrs(vcpu);
1505 guest_cr3 = is_paging(vcpu) ? vcpu->arch.cr3 :
1506 VMX_EPT_IDENTITY_PAGETABLE_ADDR;
1507 }
1508
1337 vmx_flush_tlb(vcpu); 1509 vmx_flush_tlb(vcpu);
1338 vmcs_writel(GUEST_CR3, cr3); 1510 vmcs_writel(GUEST_CR3, guest_cr3);
1339 if (vcpu->arch.cr0 & X86_CR0_PE) 1511 if (vcpu->arch.cr0 & X86_CR0_PE)
1340 vmx_fpu_deactivate(vcpu); 1512 vmx_fpu_deactivate(vcpu);
1341} 1513}
1342 1514
1343static void vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) 1515static void vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
1344{ 1516{
1345 vmcs_writel(CR4_READ_SHADOW, cr4); 1517 unsigned long hw_cr4 = cr4 | (vcpu->arch.rmode.active ?
1346 vmcs_writel(GUEST_CR4, cr4 | (vcpu->arch.rmode.active ? 1518 KVM_RMODE_VM_CR4_ALWAYS_ON : KVM_PMODE_VM_CR4_ALWAYS_ON);
1347 KVM_RMODE_VM_CR4_ALWAYS_ON : KVM_PMODE_VM_CR4_ALWAYS_ON)); 1519
1348 vcpu->arch.cr4 = cr4; 1520 vcpu->arch.cr4 = cr4;
1521 if (vm_need_ept())
1522 ept_update_paging_mode_cr4(&hw_cr4, vcpu);
1523
1524 vmcs_writel(CR4_READ_SHADOW, cr4);
1525 vmcs_writel(GUEST_CR4, hw_cr4);
1349} 1526}
1350 1527
1351static void vmx_set_efer(struct kvm_vcpu *vcpu, u64 efer) 1528static void vmx_set_efer(struct kvm_vcpu *vcpu, u64 efer)
@@ -1530,6 +1707,41 @@ out:
1530 return ret; 1707 return ret;
1531} 1708}
1532 1709
1710static int init_rmode_identity_map(struct kvm *kvm)
1711{
1712 int i, r, ret;
1713 pfn_t identity_map_pfn;
1714 u32 tmp;
1715
1716 if (!vm_need_ept())
1717 return 1;
1718 if (unlikely(!kvm->arch.ept_identity_pagetable)) {
1719 printk(KERN_ERR "EPT: identity-mapping pagetable "
1720 "haven't been allocated!\n");
1721 return 0;
1722 }
1723 if (likely(kvm->arch.ept_identity_pagetable_done))
1724 return 1;
1725 ret = 0;
1726 identity_map_pfn = VMX_EPT_IDENTITY_PAGETABLE_ADDR >> PAGE_SHIFT;
1727 r = kvm_clear_guest_page(kvm, identity_map_pfn, 0, PAGE_SIZE);
1728 if (r < 0)
1729 goto out;
1730 /* Set up identity-mapping pagetable for EPT in real mode */
1731 for (i = 0; i < PT32_ENT_PER_PAGE; i++) {
1732 tmp = (i << 22) + (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER |
1733 _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_PSE);
1734 r = kvm_write_guest_page(kvm, identity_map_pfn,
1735 &tmp, i * sizeof(tmp), sizeof(tmp));
1736 if (r < 0)
1737 goto out;
1738 }
1739 kvm->arch.ept_identity_pagetable_done = true;
1740 ret = 1;
1741out:
1742 return ret;
1743}
1744
1533static void seg_setup(int seg) 1745static void seg_setup(int seg)
1534{ 1746{
1535 struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg]; 1747 struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg];
@@ -1564,6 +1776,31 @@ out:
1564 return r; 1776 return r;
1565} 1777}
1566 1778
1779static int alloc_identity_pagetable(struct kvm *kvm)
1780{
1781 struct kvm_userspace_memory_region kvm_userspace_mem;
1782 int r = 0;
1783
1784 down_write(&kvm->slots_lock);
1785 if (kvm->arch.ept_identity_pagetable)
1786 goto out;
1787 kvm_userspace_mem.slot = IDENTITY_PAGETABLE_PRIVATE_MEMSLOT;
1788 kvm_userspace_mem.flags = 0;
1789 kvm_userspace_mem.guest_phys_addr = VMX_EPT_IDENTITY_PAGETABLE_ADDR;
1790 kvm_userspace_mem.memory_size = PAGE_SIZE;
1791 r = __kvm_set_memory_region(kvm, &kvm_userspace_mem, 0);
1792 if (r)
1793 goto out;
1794
1795 down_read(&current->mm->mmap_sem);
1796 kvm->arch.ept_identity_pagetable = gfn_to_page(kvm,
1797 VMX_EPT_IDENTITY_PAGETABLE_ADDR >> PAGE_SHIFT);
1798 up_read(&current->mm->mmap_sem);
1799out:
1800 up_write(&kvm->slots_lock);
1801 return r;
1802}
1803
1567static void allocate_vpid(struct vcpu_vmx *vmx) 1804static void allocate_vpid(struct vcpu_vmx *vmx)
1568{ 1805{
1569 int vpid; 1806 int vpid;
@@ -1638,6 +1875,9 @@ static int vmx_vcpu_setup(struct vcpu_vmx *vmx)
1638 CPU_BASED_CR8_LOAD_EXITING; 1875 CPU_BASED_CR8_LOAD_EXITING;
1639#endif 1876#endif
1640 } 1877 }
1878 if (!vm_need_ept())
1879 exec_control |= CPU_BASED_CR3_STORE_EXITING |
1880 CPU_BASED_CR3_LOAD_EXITING;
1641 vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, exec_control); 1881 vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, exec_control);
1642 1882
1643 if (cpu_has_secondary_exec_ctrls()) { 1883 if (cpu_has_secondary_exec_ctrls()) {
@@ -1647,6 +1887,8 @@ static int vmx_vcpu_setup(struct vcpu_vmx *vmx)
1647 ~SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES; 1887 ~SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES;
1648 if (vmx->vpid == 0) 1888 if (vmx->vpid == 0)
1649 exec_control &= ~SECONDARY_EXEC_ENABLE_VPID; 1889 exec_control &= ~SECONDARY_EXEC_ENABLE_VPID;
1890 if (!vm_need_ept())
1891 exec_control &= ~SECONDARY_EXEC_ENABLE_EPT;
1650 vmcs_write32(SECONDARY_VM_EXEC_CONTROL, exec_control); 1892 vmcs_write32(SECONDARY_VM_EXEC_CONTROL, exec_control);
1651 } 1893 }
1652 1894
@@ -1722,6 +1964,15 @@ static int vmx_vcpu_setup(struct vcpu_vmx *vmx)
1722 return 0; 1964 return 0;
1723} 1965}
1724 1966
1967static int init_rmode(struct kvm *kvm)
1968{
1969 if (!init_rmode_tss(kvm))
1970 return 0;
1971 if (!init_rmode_identity_map(kvm))
1972 return 0;
1973 return 1;
1974}
1975
1725static int vmx_vcpu_reset(struct kvm_vcpu *vcpu) 1976static int vmx_vcpu_reset(struct kvm_vcpu *vcpu)
1726{ 1977{
1727 struct vcpu_vmx *vmx = to_vmx(vcpu); 1978 struct vcpu_vmx *vmx = to_vmx(vcpu);
@@ -1729,7 +1980,7 @@ static int vmx_vcpu_reset(struct kvm_vcpu *vcpu)
1729 int ret; 1980 int ret;
1730 1981
1731 down_read(&vcpu->kvm->slots_lock); 1982 down_read(&vcpu->kvm->slots_lock);
1732 if (!init_rmode_tss(vmx->vcpu.kvm)) { 1983 if (!init_rmode(vmx->vcpu.kvm)) {
1733 ret = -ENOMEM; 1984 ret = -ENOMEM;
1734 goto out; 1985 goto out;
1735 } 1986 }
@@ -1994,6 +2245,9 @@ static int handle_exception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1994 if (intr_info & INTR_INFO_DELIVER_CODE_MASK) 2245 if (intr_info & INTR_INFO_DELIVER_CODE_MASK)
1995 error_code = vmcs_read32(VM_EXIT_INTR_ERROR_CODE); 2246 error_code = vmcs_read32(VM_EXIT_INTR_ERROR_CODE);
1996 if (is_page_fault(intr_info)) { 2247 if (is_page_fault(intr_info)) {
2248 /* EPT won't cause page fault directly */
2249 if (vm_need_ept())
2250 BUG();
1997 cr2 = vmcs_readl(EXIT_QUALIFICATION); 2251 cr2 = vmcs_readl(EXIT_QUALIFICATION);
1998 KVMTRACE_3D(PAGE_FAULT, vcpu, error_code, (u32)cr2, 2252 KVMTRACE_3D(PAGE_FAULT, vcpu, error_code, (u32)cr2,
1999 (u32)((u64)cr2 >> 32), handler); 2253 (u32)((u64)cr2 >> 32), handler);
@@ -2323,6 +2577,64 @@ static int handle_task_switch(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
2323 return kvm_task_switch(vcpu, tss_selector, reason); 2577 return kvm_task_switch(vcpu, tss_selector, reason);
2324} 2578}
2325 2579
2580static int handle_ept_violation(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
2581{
2582 u64 exit_qualification;
2583 enum emulation_result er;
2584 gpa_t gpa;
2585 unsigned long hva;
2586 int gla_validity;
2587 int r;
2588
2589 exit_qualification = vmcs_read64(EXIT_QUALIFICATION);
2590
2591 if (exit_qualification & (1 << 6)) {
2592 printk(KERN_ERR "EPT: GPA exceeds GAW!\n");
2593 return -ENOTSUPP;
2594 }
2595
2596 gla_validity = (exit_qualification >> 7) & 0x3;
2597 if (gla_validity != 0x3 && gla_validity != 0x1 && gla_validity != 0) {
2598 printk(KERN_ERR "EPT: Handling EPT violation failed!\n");
2599 printk(KERN_ERR "EPT: GPA: 0x%lx, GVA: 0x%lx\n",
2600 (long unsigned int)vmcs_read64(GUEST_PHYSICAL_ADDRESS),
2601 (long unsigned int)vmcs_read64(GUEST_LINEAR_ADDRESS));
2602 printk(KERN_ERR "EPT: Exit qualification is 0x%lx\n",
2603 (long unsigned int)exit_qualification);
2604 kvm_run->exit_reason = KVM_EXIT_UNKNOWN;
2605 kvm_run->hw.hardware_exit_reason = 0;
2606 return -ENOTSUPP;
2607 }
2608
2609 gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS);
2610 hva = gfn_to_hva(vcpu->kvm, gpa >> PAGE_SHIFT);
2611 if (!kvm_is_error_hva(hva)) {
2612 r = kvm_mmu_page_fault(vcpu, gpa & PAGE_MASK, 0);
2613 if (r < 0) {
2614 printk(KERN_ERR "EPT: Not enough memory!\n");
2615 return -ENOMEM;
2616 }
2617 return 1;
2618 } else {
2619 /* must be MMIO */
2620 er = emulate_instruction(vcpu, kvm_run, 0, 0, 0);
2621
2622 if (er == EMULATE_FAIL) {
2623 printk(KERN_ERR
2624 "EPT: Fail to handle EPT violation vmexit!er is %d\n",
2625 er);
2626 printk(KERN_ERR "EPT: GPA: 0x%lx, GVA: 0x%lx\n",
2627 (long unsigned int)vmcs_read64(GUEST_PHYSICAL_ADDRESS),
2628 (long unsigned int)vmcs_read64(GUEST_LINEAR_ADDRESS));
2629 printk(KERN_ERR "EPT: Exit qualification is 0x%lx\n",
2630 (long unsigned int)exit_qualification);
2631 return -ENOTSUPP;
2632 } else if (er == EMULATE_DO_MMIO)
2633 return 0;
2634 }
2635 return 1;
2636}
2637
2326/* 2638/*
2327 * The exit handlers return 1 if the exit was handled fully and guest execution 2639 * The exit handlers return 1 if the exit was handled fully and guest execution
2328 * may resume. Otherwise they set the kvm_run parameter to indicate what needs 2640 * may resume. Otherwise they set the kvm_run parameter to indicate what needs
@@ -2346,6 +2658,7 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu,
2346 [EXIT_REASON_APIC_ACCESS] = handle_apic_access, 2658 [EXIT_REASON_APIC_ACCESS] = handle_apic_access,
2347 [EXIT_REASON_WBINVD] = handle_wbinvd, 2659 [EXIT_REASON_WBINVD] = handle_wbinvd,
2348 [EXIT_REASON_TASK_SWITCH] = handle_task_switch, 2660 [EXIT_REASON_TASK_SWITCH] = handle_task_switch,
2661 [EXIT_REASON_EPT_VIOLATION] = handle_ept_violation,
2349}; 2662};
2350 2663
2351static const int kvm_vmx_max_exit_handlers = 2664static const int kvm_vmx_max_exit_handlers =
@@ -2364,6 +2677,13 @@ static int kvm_handle_exit(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
2364 KVMTRACE_3D(VMEXIT, vcpu, exit_reason, (u32)vmcs_readl(GUEST_RIP), 2677 KVMTRACE_3D(VMEXIT, vcpu, exit_reason, (u32)vmcs_readl(GUEST_RIP),
2365 (u32)((u64)vmcs_readl(GUEST_RIP) >> 32), entryexit); 2678 (u32)((u64)vmcs_readl(GUEST_RIP) >> 32), entryexit);
2366 2679
2680 /* Access CR3 don't cause VMExit in paging mode, so we need
2681 * to sync with guest real CR3. */
2682 if (vm_need_ept() && is_paging(vcpu)) {
2683 vcpu->arch.cr3 = vmcs_readl(GUEST_CR3);
2684 ept_load_pdptrs(vcpu);
2685 }
2686
2367 if (unlikely(vmx->fail)) { 2687 if (unlikely(vmx->fail)) {
2368 kvm_run->exit_reason = KVM_EXIT_FAIL_ENTRY; 2688 kvm_run->exit_reason = KVM_EXIT_FAIL_ENTRY;
2369 kvm_run->fail_entry.hardware_entry_failure_reason 2689 kvm_run->fail_entry.hardware_entry_failure_reason
@@ -2372,7 +2692,8 @@ static int kvm_handle_exit(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
2372 } 2692 }
2373 2693
2374 if ((vectoring_info & VECTORING_INFO_VALID_MASK) && 2694 if ((vectoring_info & VECTORING_INFO_VALID_MASK) &&
2375 exit_reason != EXIT_REASON_EXCEPTION_NMI) 2695 (exit_reason != EXIT_REASON_EXCEPTION_NMI &&
2696 exit_reason != EXIT_REASON_EPT_VIOLATION))
2376 printk(KERN_WARNING "%s: unexpected, valid vectoring info and " 2697 printk(KERN_WARNING "%s: unexpected, valid vectoring info and "
2377 "exit reason is 0x%x\n", __func__, exit_reason); 2698 "exit reason is 0x%x\n", __func__, exit_reason);
2378 if (exit_reason < kvm_vmx_max_exit_handlers 2699 if (exit_reason < kvm_vmx_max_exit_handlers
@@ -2674,6 +2995,15 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
2674 return ERR_PTR(-ENOMEM); 2995 return ERR_PTR(-ENOMEM);
2675 2996
2676 allocate_vpid(vmx); 2997 allocate_vpid(vmx);
2998 if (id == 0 && vm_need_ept()) {
2999 kvm_mmu_set_base_ptes(VMX_EPT_READABLE_MASK |
3000 VMX_EPT_WRITABLE_MASK |
3001 VMX_EPT_DEFAULT_MT << VMX_EPT_MT_EPTE_SHIFT);
3002 kvm_mmu_set_mask_ptes(0ull, VMX_EPT_FAKE_ACCESSED_MASK,
3003 VMX_EPT_FAKE_DIRTY_MASK, 0ull,
3004 VMX_EPT_EXECUTABLE_MASK);
3005 kvm_enable_tdp();
3006 }
2677 3007
2678 err = kvm_vcpu_init(&vmx->vcpu, kvm, id); 3008 err = kvm_vcpu_init(&vmx->vcpu, kvm, id);
2679 if (err) 3009 if (err)
@@ -2706,6 +3036,10 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
2706 if (alloc_apic_access_page(kvm) != 0) 3036 if (alloc_apic_access_page(kvm) != 0)
2707 goto free_vmcs; 3037 goto free_vmcs;
2708 3038
3039 if (vm_need_ept())
3040 if (alloc_identity_pagetable(kvm) != 0)
3041 goto free_vmcs;
3042
2709 return &vmx->vcpu; 3043 return &vmx->vcpu;
2710 3044
2711free_vmcs: 3045free_vmcs:
@@ -2735,6 +3069,11 @@ static void __init vmx_check_processor_compat(void *rtn)
2735 } 3069 }
2736} 3070}
2737 3071
3072static int get_ept_level(void)
3073{
3074 return VMX_EPT_DEFAULT_GAW + 1;
3075}
3076
2738static struct kvm_x86_ops vmx_x86_ops = { 3077static struct kvm_x86_ops vmx_x86_ops = {
2739 .cpu_has_kvm_support = cpu_has_kvm_support, 3078 .cpu_has_kvm_support = cpu_has_kvm_support,
2740 .disabled_by_bios = vmx_disabled_by_bios, 3079 .disabled_by_bios = vmx_disabled_by_bios,
@@ -2791,6 +3130,7 @@ static struct kvm_x86_ops vmx_x86_ops = {
2791 .inject_pending_vectors = do_interrupt_requests, 3130 .inject_pending_vectors = do_interrupt_requests,
2792 3131
2793 .set_tss_addr = vmx_set_tss_addr, 3132 .set_tss_addr = vmx_set_tss_addr,
3133 .get_tdp_level = get_ept_level,
2794}; 3134};
2795 3135
2796static int __init vmx_init(void) 3136static int __init vmx_init(void)
@@ -2843,9 +3183,14 @@ static int __init vmx_init(void)
2843 vmx_disable_intercept_for_msr(vmx_msr_bitmap, MSR_IA32_SYSENTER_ESP); 3183 vmx_disable_intercept_for_msr(vmx_msr_bitmap, MSR_IA32_SYSENTER_ESP);
2844 vmx_disable_intercept_for_msr(vmx_msr_bitmap, MSR_IA32_SYSENTER_EIP); 3184 vmx_disable_intercept_for_msr(vmx_msr_bitmap, MSR_IA32_SYSENTER_EIP);
2845 3185
3186 if (cpu_has_vmx_ept())
3187 bypass_guest_pf = 0;
3188
2846 if (bypass_guest_pf) 3189 if (bypass_guest_pf)
2847 kvm_mmu_set_nonpresent_ptes(~0xffeull, 0ull); 3190 kvm_mmu_set_nonpresent_ptes(~0xffeull, 0ull);
2848 3191
3192 ept_sync_global();
3193
2849 return 0; 3194 return 0;
2850 3195
2851out2: 3196out2:
diff --git a/arch/x86/kvm/vmx.h b/arch/x86/kvm/vmx.h
index 5dff4606b988..79d94c610dfe 100644
--- a/arch/x86/kvm/vmx.h
+++ b/arch/x86/kvm/vmx.h
@@ -35,6 +35,8 @@
35#define CPU_BASED_MWAIT_EXITING 0x00000400 35#define CPU_BASED_MWAIT_EXITING 0x00000400
36#define CPU_BASED_RDPMC_EXITING 0x00000800 36#define CPU_BASED_RDPMC_EXITING 0x00000800
37#define CPU_BASED_RDTSC_EXITING 0x00001000 37#define CPU_BASED_RDTSC_EXITING 0x00001000
38#define CPU_BASED_CR3_LOAD_EXITING 0x00008000
39#define CPU_BASED_CR3_STORE_EXITING 0x00010000
38#define CPU_BASED_CR8_LOAD_EXITING 0x00080000 40#define CPU_BASED_CR8_LOAD_EXITING 0x00080000
39#define CPU_BASED_CR8_STORE_EXITING 0x00100000 41#define CPU_BASED_CR8_STORE_EXITING 0x00100000
40#define CPU_BASED_TPR_SHADOW 0x00200000 42#define CPU_BASED_TPR_SHADOW 0x00200000
@@ -49,6 +51,7 @@
49 * Definitions of Secondary Processor-Based VM-Execution Controls. 51 * Definitions of Secondary Processor-Based VM-Execution Controls.
50 */ 52 */
51#define SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES 0x00000001 53#define SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES 0x00000001
54#define SECONDARY_EXEC_ENABLE_EPT 0x00000002
52#define SECONDARY_EXEC_ENABLE_VPID 0x00000020 55#define SECONDARY_EXEC_ENABLE_VPID 0x00000020
53#define SECONDARY_EXEC_WBINVD_EXITING 0x00000040 56#define SECONDARY_EXEC_WBINVD_EXITING 0x00000040
54 57
@@ -100,10 +103,22 @@ enum vmcs_field {
100 VIRTUAL_APIC_PAGE_ADDR_HIGH = 0x00002013, 103 VIRTUAL_APIC_PAGE_ADDR_HIGH = 0x00002013,
101 APIC_ACCESS_ADDR = 0x00002014, 104 APIC_ACCESS_ADDR = 0x00002014,
102 APIC_ACCESS_ADDR_HIGH = 0x00002015, 105 APIC_ACCESS_ADDR_HIGH = 0x00002015,
106 EPT_POINTER = 0x0000201a,
107 EPT_POINTER_HIGH = 0x0000201b,
108 GUEST_PHYSICAL_ADDRESS = 0x00002400,
109 GUEST_PHYSICAL_ADDRESS_HIGH = 0x00002401,
103 VMCS_LINK_POINTER = 0x00002800, 110 VMCS_LINK_POINTER = 0x00002800,
104 VMCS_LINK_POINTER_HIGH = 0x00002801, 111 VMCS_LINK_POINTER_HIGH = 0x00002801,
105 GUEST_IA32_DEBUGCTL = 0x00002802, 112 GUEST_IA32_DEBUGCTL = 0x00002802,
106 GUEST_IA32_DEBUGCTL_HIGH = 0x00002803, 113 GUEST_IA32_DEBUGCTL_HIGH = 0x00002803,
114 GUEST_PDPTR0 = 0x0000280a,
115 GUEST_PDPTR0_HIGH = 0x0000280b,
116 GUEST_PDPTR1 = 0x0000280c,
117 GUEST_PDPTR1_HIGH = 0x0000280d,
118 GUEST_PDPTR2 = 0x0000280e,
119 GUEST_PDPTR2_HIGH = 0x0000280f,
120 GUEST_PDPTR3 = 0x00002810,
121 GUEST_PDPTR3_HIGH = 0x00002811,
107 PIN_BASED_VM_EXEC_CONTROL = 0x00004000, 122 PIN_BASED_VM_EXEC_CONTROL = 0x00004000,
108 CPU_BASED_VM_EXEC_CONTROL = 0x00004002, 123 CPU_BASED_VM_EXEC_CONTROL = 0x00004002,
109 EXCEPTION_BITMAP = 0x00004004, 124 EXCEPTION_BITMAP = 0x00004004,
@@ -226,6 +241,8 @@ enum vmcs_field {
226#define EXIT_REASON_MWAIT_INSTRUCTION 36 241#define EXIT_REASON_MWAIT_INSTRUCTION 36
227#define EXIT_REASON_TPR_BELOW_THRESHOLD 43 242#define EXIT_REASON_TPR_BELOW_THRESHOLD 43
228#define EXIT_REASON_APIC_ACCESS 44 243#define EXIT_REASON_APIC_ACCESS 44
244#define EXIT_REASON_EPT_VIOLATION 48
245#define EXIT_REASON_EPT_MISCONFIG 49
229#define EXIT_REASON_WBINVD 54 246#define EXIT_REASON_WBINVD 54
230 247
231/* 248/*
@@ -316,15 +333,36 @@ enum vmcs_field {
316#define MSR_IA32_VMX_CR4_FIXED1 0x489 333#define MSR_IA32_VMX_CR4_FIXED1 0x489
317#define MSR_IA32_VMX_VMCS_ENUM 0x48a 334#define MSR_IA32_VMX_VMCS_ENUM 0x48a
318#define MSR_IA32_VMX_PROCBASED_CTLS2 0x48b 335#define MSR_IA32_VMX_PROCBASED_CTLS2 0x48b
336#define MSR_IA32_VMX_EPT_VPID_CAP 0x48c
319 337
320#define MSR_IA32_FEATURE_CONTROL 0x3a 338#define MSR_IA32_FEATURE_CONTROL 0x3a
321#define MSR_IA32_FEATURE_CONTROL_LOCKED 0x1 339#define MSR_IA32_FEATURE_CONTROL_LOCKED 0x1
322#define MSR_IA32_FEATURE_CONTROL_VMXON_ENABLED 0x4 340#define MSR_IA32_FEATURE_CONTROL_VMXON_ENABLED 0x4
323 341
324#define APIC_ACCESS_PAGE_PRIVATE_MEMSLOT 9 342#define APIC_ACCESS_PAGE_PRIVATE_MEMSLOT 9
343#define IDENTITY_PAGETABLE_PRIVATE_MEMSLOT 10
325 344
326#define VMX_NR_VPIDS (1 << 16) 345#define VMX_NR_VPIDS (1 << 16)
327#define VMX_VPID_EXTENT_SINGLE_CONTEXT 1 346#define VMX_VPID_EXTENT_SINGLE_CONTEXT 1
328#define VMX_VPID_EXTENT_ALL_CONTEXT 2 347#define VMX_VPID_EXTENT_ALL_CONTEXT 2
329 348
349#define VMX_EPT_EXTENT_INDIVIDUAL_ADDR 0
350#define VMX_EPT_EXTENT_CONTEXT 1
351#define VMX_EPT_EXTENT_GLOBAL 2
352#define VMX_EPT_EXTENT_INDIVIDUAL_BIT (1ull << 24)
353#define VMX_EPT_EXTENT_CONTEXT_BIT (1ull << 25)
354#define VMX_EPT_EXTENT_GLOBAL_BIT (1ull << 26)
355#define VMX_EPT_DEFAULT_GAW 3
356#define VMX_EPT_MAX_GAW 0x4
357#define VMX_EPT_MT_EPTE_SHIFT 3
358#define VMX_EPT_GAW_EPTP_SHIFT 3
359#define VMX_EPT_DEFAULT_MT 0x6ull
360#define VMX_EPT_READABLE_MASK 0x1ull
361#define VMX_EPT_WRITABLE_MASK 0x2ull
362#define VMX_EPT_EXECUTABLE_MASK 0x4ull
363#define VMX_EPT_FAKE_ACCESSED_MASK (1ull << 62)
364#define VMX_EPT_FAKE_DIRTY_MASK (1ull << 63)
365
366#define VMX_EPT_IDENTITY_PAGETABLE_ADDR 0xfffbc000ul
367
330#endif 368#endif
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 0ce556372a4d..21338bdb28ff 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2417,6 +2417,9 @@ int kvm_arch_init(void *opaque)
2417 2417
2418 kvm_x86_ops = ops; 2418 kvm_x86_ops = ops;
2419 kvm_mmu_set_nonpresent_ptes(0ull, 0ull); 2419 kvm_mmu_set_nonpresent_ptes(0ull, 0ull);
2420 kvm_mmu_set_base_ptes(PT_PRESENT_MASK);
2421 kvm_mmu_set_mask_ptes(PT_USER_MASK, PT_ACCESSED_MASK,
2422 PT_DIRTY_MASK, PT64_NX_MASK, 0);
2420 return 0; 2423 return 0;
2421 2424
2422out: 2425out:
@@ -3019,6 +3022,8 @@ int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
3019 3022
3020 kvm_x86_ops->decache_regs(vcpu); 3023 kvm_x86_ops->decache_regs(vcpu);
3021 3024
3025 vcpu->arch.exception.pending = false;
3026
3022 vcpu_put(vcpu); 3027 vcpu_put(vcpu);
3023 3028
3024 return 0; 3029 return 0;
@@ -3481,7 +3486,7 @@ int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int reason)
3481 } 3486 }
3482 3487
3483 if (reason == TASK_SWITCH_IRET || reason == TASK_SWITCH_JMP) { 3488 if (reason == TASK_SWITCH_IRET || reason == TASK_SWITCH_JMP) {
3484 cseg_desc.type &= ~(1 << 8); //clear the B flag 3489 cseg_desc.type &= ~(1 << 1); //clear the B flag
3485 save_guest_segment_descriptor(vcpu, tr_seg.selector, 3490 save_guest_segment_descriptor(vcpu, tr_seg.selector,
3486 &cseg_desc); 3491 &cseg_desc);
3487 } 3492 }
@@ -3507,7 +3512,7 @@ int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int reason)
3507 } 3512 }
3508 3513
3509 if (reason != TASK_SWITCH_IRET) { 3514 if (reason != TASK_SWITCH_IRET) {
3510 nseg_desc.type |= (1 << 8); 3515 nseg_desc.type |= (1 << 1);
3511 save_guest_segment_descriptor(vcpu, tss_selector, 3516 save_guest_segment_descriptor(vcpu, tss_selector,
3512 &nseg_desc); 3517 &nseg_desc);
3513 } 3518 }
@@ -3698,10 +3703,19 @@ void fx_init(struct kvm_vcpu *vcpu)
3698{ 3703{
3699 unsigned after_mxcsr_mask; 3704 unsigned after_mxcsr_mask;
3700 3705
3706 /*
3707 * Touch the fpu the first time in non atomic context as if
3708 * this is the first fpu instruction the exception handler
3709 * will fire before the instruction returns and it'll have to
3710 * allocate ram with GFP_KERNEL.
3711 */
3712 if (!used_math())
3713 fx_save(&vcpu->arch.host_fx_image);
3714
3701 /* Initialize guest FPU by resetting ours and saving into guest's */ 3715 /* Initialize guest FPU by resetting ours and saving into guest's */
3702 preempt_disable(); 3716 preempt_disable();
3703 fx_save(&vcpu->arch.host_fx_image); 3717 fx_save(&vcpu->arch.host_fx_image);
3704 fpu_init(); 3718 fx_finit();
3705 fx_save(&vcpu->arch.guest_fx_image); 3719 fx_save(&vcpu->arch.guest_fx_image);
3706 fx_restore(&vcpu->arch.host_fx_image); 3720 fx_restore(&vcpu->arch.host_fx_image);
3707 preempt_enable(); 3721 preempt_enable();
@@ -3906,6 +3920,8 @@ void kvm_arch_destroy_vm(struct kvm *kvm)
3906 kvm_free_physmem(kvm); 3920 kvm_free_physmem(kvm);
3907 if (kvm->arch.apic_access_page) 3921 if (kvm->arch.apic_access_page)
3908 put_page(kvm->arch.apic_access_page); 3922 put_page(kvm->arch.apic_access_page);
3923 if (kvm->arch.ept_identity_pagetable)
3924 put_page(kvm->arch.ept_identity_pagetable);
3909 kfree(kvm); 3925 kfree(kvm);
3910} 3926}
3911 3927
diff --git a/arch/x86/kvm/x86_emulate.c b/arch/x86/kvm/x86_emulate.c
index 2ca08386f993..f2a696d6a243 100644
--- a/arch/x86/kvm/x86_emulate.c
+++ b/arch/x86/kvm/x86_emulate.c
@@ -1761,6 +1761,7 @@ twobyte_insn:
1761 case 6: /* lmsw */ 1761 case 6: /* lmsw */
1762 realmode_lmsw(ctxt->vcpu, (u16)c->src.val, 1762 realmode_lmsw(ctxt->vcpu, (u16)c->src.val,
1763 &ctxt->eflags); 1763 &ctxt->eflags);
1764 c->dst.type = OP_NONE;
1764 break; 1765 break;
1765 case 7: /* invlpg*/ 1766 case 7: /* invlpg*/
1766 emulate_invlpg(ctxt->vcpu, memop); 1767 emulate_invlpg(ctxt->vcpu, memop);
diff --git a/arch/x86/mach-voyager/voyager_cat.c b/arch/x86/mach-voyager/voyager_cat.c
index ecab9fff0fd1..2ad598c104af 100644
--- a/arch/x86/mach-voyager/voyager_cat.c
+++ b/arch/x86/mach-voyager/voyager_cat.c
@@ -877,7 +877,7 @@ void __init voyager_cat_init(void)
877 request_resource(&iomem_resource, res); 877 request_resource(&iomem_resource, res);
878 } 878 }
879 879
880 qic_addr = (unsigned long)ioremap(qic_addr, 0x400); 880 qic_addr = (unsigned long)ioremap_cache(qic_addr, 0x400);
881 881
882 for (j = 0; j < 4; j++) { 882 for (j = 0; j < 4; j++) {
883 __u8 cpu; 883 __u8 cpu;
diff --git a/arch/x86/mm/discontig_32.c b/arch/x86/mm/discontig_32.c
index 18378850e25a..914ccf983687 100644
--- a/arch/x86/mm/discontig_32.c
+++ b/arch/x86/mm/discontig_32.c
@@ -476,29 +476,3 @@ int memory_add_physaddr_to_nid(u64 addr)
476 476
477EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid); 477EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
478#endif 478#endif
479
480#ifndef CONFIG_HAVE_ARCH_PARSE_SRAT
481/*
482 * XXX FIXME: Make SLIT table parsing available to 32-bit NUMA
483 *
484 * These stub functions are needed to compile 32-bit NUMA when SRAT is
485 * not set. There are functions in srat_64.c for parsing this table
486 * and it may be possible to make them common functions.
487 */
488void acpi_numa_slit_init (struct acpi_table_slit *slit)
489{
490 printk(KERN_INFO "ACPI: No support for parsing SLIT table\n");
491}
492
493void acpi_numa_processor_affinity_init (struct acpi_srat_cpu_affinity *pa)
494{
495}
496
497void acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma)
498{
499}
500
501void acpi_numa_arch_fixup(void)
502{
503}
504#endif /* CONFIG_HAVE_ARCH_PARSE_SRAT */
diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
index 9cf33d3ee5bc..165c871ba9af 100644
--- a/arch/x86/mm/highmem_32.c
+++ b/arch/x86/mm/highmem_32.c
@@ -155,4 +155,3 @@ EXPORT_SYMBOL(kmap);
155EXPORT_SYMBOL(kunmap); 155EXPORT_SYMBOL(kunmap);
156EXPORT_SYMBOL(kmap_atomic); 156EXPORT_SYMBOL(kmap_atomic);
157EXPORT_SYMBOL(kunmap_atomic); 157EXPORT_SYMBOL(kunmap_atomic);
158EXPORT_SYMBOL(kmap_atomic_to_page);
diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index 804de18abcc2..71bb3159031a 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -149,7 +149,8 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
149 * Don't allow anybody to remap normal RAM that we're using.. 149 * Don't allow anybody to remap normal RAM that we're using..
150 */ 150 */
151 for (pfn = phys_addr >> PAGE_SHIFT; 151 for (pfn = phys_addr >> PAGE_SHIFT;
152 (pfn << PAGE_SHIFT) < last_addr; pfn++) { 152 (pfn << PAGE_SHIFT) < (last_addr & PAGE_MASK);
153 pfn++) {
153 154
154 int is_ram = page_is_ram(pfn); 155 int is_ram = page_is_ram(pfn);
155 156
@@ -176,11 +177,11 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
176 /* 177 /*
177 * Do not fallback to certain memory types with certain 178 * Do not fallback to certain memory types with certain
178 * requested type: 179 * requested type:
179 * - request is uncached, return cannot be write-back 180 * - request is uc-, return cannot be write-back
180 * - request is uncached, return cannot be write-combine 181 * - request is uc-, return cannot be write-combine
181 * - request is write-combine, return cannot be write-back 182 * - request is write-combine, return cannot be write-back
182 */ 183 */
183 if ((prot_val == _PAGE_CACHE_UC && 184 if ((prot_val == _PAGE_CACHE_UC_MINUS &&
184 (new_prot_val == _PAGE_CACHE_WB || 185 (new_prot_val == _PAGE_CACHE_WB ||
185 new_prot_val == _PAGE_CACHE_WC)) || 186 new_prot_val == _PAGE_CACHE_WC)) ||
186 (prot_val == _PAGE_CACHE_WC && 187 (prot_val == _PAGE_CACHE_WC &&
@@ -201,6 +202,9 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
201 default: 202 default:
202 prot = PAGE_KERNEL_NOCACHE; 203 prot = PAGE_KERNEL_NOCACHE;
203 break; 204 break;
205 case _PAGE_CACHE_UC_MINUS:
206 prot = PAGE_KERNEL_UC_MINUS;
207 break;
204 case _PAGE_CACHE_WC: 208 case _PAGE_CACHE_WC:
205 prot = PAGE_KERNEL_WC; 209 prot = PAGE_KERNEL_WC;
206 break; 210 break;
@@ -255,7 +259,16 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
255 */ 259 */
256void __iomem *ioremap_nocache(resource_size_t phys_addr, unsigned long size) 260void __iomem *ioremap_nocache(resource_size_t phys_addr, unsigned long size)
257{ 261{
258 return __ioremap_caller(phys_addr, size, _PAGE_CACHE_UC, 262 /*
263 * Ideally, this should be:
264 * pat_wc_enabled ? _PAGE_CACHE_UC : _PAGE_CACHE_UC_MINUS;
265 *
266 * Till we fix all X drivers to use ioremap_wc(), we will use
267 * UC MINUS.
268 */
269 unsigned long val = _PAGE_CACHE_UC_MINUS;
270
271 return __ioremap_caller(phys_addr, size, val,
259 __builtin_return_address(0)); 272 __builtin_return_address(0));
260} 273}
261EXPORT_SYMBOL(ioremap_nocache); 274EXPORT_SYMBOL(ioremap_nocache);
diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
index bd5e05c654dc..60bcb5b6a37e 100644
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -777,14 +777,20 @@ static inline int change_page_attr_clear(unsigned long addr, int numpages,
777 777
778int _set_memory_uc(unsigned long addr, int numpages) 778int _set_memory_uc(unsigned long addr, int numpages)
779{ 779{
780 /*
781 * for now UC MINUS. see comments in ioremap_nocache()
782 */
780 return change_page_attr_set(addr, numpages, 783 return change_page_attr_set(addr, numpages,
781 __pgprot(_PAGE_CACHE_UC)); 784 __pgprot(_PAGE_CACHE_UC_MINUS));
782} 785}
783 786
784int set_memory_uc(unsigned long addr, int numpages) 787int set_memory_uc(unsigned long addr, int numpages)
785{ 788{
789 /*
790 * for now UC MINUS. see comments in ioremap_nocache()
791 */
786 if (reserve_memtype(addr, addr + numpages * PAGE_SIZE, 792 if (reserve_memtype(addr, addr + numpages * PAGE_SIZE,
787 _PAGE_CACHE_UC, NULL)) 793 _PAGE_CACHE_UC_MINUS, NULL))
788 return -EINVAL; 794 return -EINVAL;
789 795
790 return _set_memory_uc(addr, numpages); 796 return _set_memory_uc(addr, numpages);
diff --git a/arch/x86/pci/Makefile_32 b/arch/x86/pci/Makefile_32
index 2a1516efb542..89ec35d00efd 100644
--- a/arch/x86/pci/Makefile_32
+++ b/arch/x86/pci/Makefile_32
@@ -6,11 +6,19 @@ obj-$(CONFIG_PCI_DIRECT) += direct.o
6obj-$(CONFIG_PCI_OLPC) += olpc.o 6obj-$(CONFIG_PCI_OLPC) += olpc.o
7 7
8pci-y := fixup.o 8pci-y := fixup.o
9
10# Do not change the ordering here. There is a nasty init function
11# ordering dependency which breaks when you move acpi.o below
12# legacy/irq.o
9pci-$(CONFIG_ACPI) += acpi.o 13pci-$(CONFIG_ACPI) += acpi.o
10pci-y += legacy.o irq.o 14pci-y += legacy.o irq.o
11 15
16# Careful: VISWS and NUMAQ overrule the pci-y above. The colons are
17# therefor correct. This needs a proper fix by distangling the code.
12pci-$(CONFIG_X86_VISWS) := visws.o fixup.o 18pci-$(CONFIG_X86_VISWS) := visws.o fixup.o
13pci-$(CONFIG_X86_NUMAQ) := numa.o irq.o 19pci-$(CONFIG_X86_NUMAQ) := numa.o irq.o
20
21# Necessary for NUMAQ as well
14pci-$(CONFIG_NUMA) += mp_bus_to_node.o 22pci-$(CONFIG_NUMA) += mp_bus_to_node.o
15 23
16obj-y += $(pci-y) common.o early.o 24obj-y += $(pci-y) common.o early.o
diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
index 1a9c0c6a1a18..d95de2f199cd 100644
--- a/arch/x86/pci/acpi.c
+++ b/arch/x86/pci/acpi.c
@@ -6,45 +6,6 @@
6#include <asm/numa.h> 6#include <asm/numa.h>
7#include "pci.h" 7#include "pci.h"
8 8
9static int __devinit can_skip_ioresource_align(const struct dmi_system_id *d)
10{
11 pci_probe |= PCI_CAN_SKIP_ISA_ALIGN;
12 printk(KERN_INFO "PCI: %s detected, can skip ISA alignment\n", d->ident);
13 return 0;
14}
15
16static struct dmi_system_id acpi_pciprobe_dmi_table[] __devinitdata = {
17/*
18 * Systems where PCI IO resource ISA alignment can be skipped
19 * when the ISA enable bit in the bridge control is not set
20 */
21 {
22 .callback = can_skip_ioresource_align,
23 .ident = "IBM System x3800",
24 .matches = {
25 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
26 DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
27 },
28 },
29 {
30 .callback = can_skip_ioresource_align,
31 .ident = "IBM System x3850",
32 .matches = {
33 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
34 DMI_MATCH(DMI_PRODUCT_NAME, "x3850"),
35 },
36 },
37 {
38 .callback = can_skip_ioresource_align,
39 .ident = "IBM System x3950",
40 .matches = {
41 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
42 DMI_MATCH(DMI_PRODUCT_NAME, "x3950"),
43 },
44 },
45 {}
46};
47
48struct pci_root_info { 9struct pci_root_info {
49 char *name; 10 char *name;
50 unsigned int res_num; 11 unsigned int res_num;
@@ -196,8 +157,6 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int do
196 int pxm; 157 int pxm;
197#endif 158#endif
198 159
199 dmi_check_system(acpi_pciprobe_dmi_table);
200
201 if (domain && !pci_domains_supported) { 160 if (domain && !pci_domains_supported) {
202 printk(KERN_WARNING "PCI: Multiple domains not supported " 161 printk(KERN_WARNING "PCI: Multiple domains not supported "
203 "(dom %d, bus %d)\n", domain, busnum); 162 "(dom %d, bus %d)\n", domain, busnum);
diff --git a/arch/x86/pci/common.c b/arch/x86/pci/common.c
index 2a4d751818b7..bfa72a9475b3 100644
--- a/arch/x86/pci/common.c
+++ b/arch/x86/pci/common.c
@@ -90,6 +90,50 @@ static void __devinit pcibios_fixup_device_resources(struct pci_dev *dev)
90 rom_r->start = rom_r->end = rom_r->flags = 0; 90 rom_r->start = rom_r->end = rom_r->flags = 0;
91} 91}
92 92
93static int __devinit can_skip_ioresource_align(const struct dmi_system_id *d)
94{
95 pci_probe |= PCI_CAN_SKIP_ISA_ALIGN;
96 printk(KERN_INFO "PCI: %s detected, can skip ISA alignment\n", d->ident);
97 return 0;
98}
99
100static struct dmi_system_id can_skip_pciprobe_dmi_table[] __devinitdata = {
101/*
102 * Systems where PCI IO resource ISA alignment can be skipped
103 * when the ISA enable bit in the bridge control is not set
104 */
105 {
106 .callback = can_skip_ioresource_align,
107 .ident = "IBM System x3800",
108 .matches = {
109 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
110 DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
111 },
112 },
113 {
114 .callback = can_skip_ioresource_align,
115 .ident = "IBM System x3850",
116 .matches = {
117 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
118 DMI_MATCH(DMI_PRODUCT_NAME, "x3850"),
119 },
120 },
121 {
122 .callback = can_skip_ioresource_align,
123 .ident = "IBM System x3950",
124 .matches = {
125 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
126 DMI_MATCH(DMI_PRODUCT_NAME, "x3950"),
127 },
128 },
129 {}
130};
131
132void __init dmi_check_skip_isa_align(void)
133{
134 dmi_check_system(can_skip_pciprobe_dmi_table);
135}
136
93/* 137/*
94 * Called after each bus is probed, but before its children 138 * Called after each bus is probed, but before its children
95 * are examined. 139 * are examined.
@@ -318,13 +362,16 @@ static struct dmi_system_id __devinitdata pciprobe_dmi_table[] = {
318 {} 362 {}
319}; 363};
320 364
365void __init dmi_check_pciprobe(void)
366{
367 dmi_check_system(pciprobe_dmi_table);
368}
369
321struct pci_bus * __devinit pcibios_scan_root(int busnum) 370struct pci_bus * __devinit pcibios_scan_root(int busnum)
322{ 371{
323 struct pci_bus *bus = NULL; 372 struct pci_bus *bus = NULL;
324 struct pci_sysdata *sd; 373 struct pci_sysdata *sd;
325 374
326 dmi_check_system(pciprobe_dmi_table);
327
328 while ((bus = pci_find_next_bus(bus)) != NULL) { 375 while ((bus = pci_find_next_bus(bus)) != NULL) {
329 if (bus->number == busnum) { 376 if (bus->number == busnum) {
330 /* Already scanned */ 377 /* Already scanned */
@@ -462,6 +509,9 @@ char * __devinit pcibios_setup(char *str)
462 } else if (!strcmp(str, "routeirq")) { 509 } else if (!strcmp(str, "routeirq")) {
463 pci_routeirq = 1; 510 pci_routeirq = 1;
464 return NULL; 511 return NULL;
512 } else if (!strcmp(str, "skip_isa_align")) {
513 pci_probe |= PCI_CAN_SKIP_ISA_ALIGN;
514 return NULL;
465 } 515 }
466 return str; 516 return str;
467} 517}
@@ -489,7 +539,7 @@ void pcibios_disable_device (struct pci_dev *dev)
489 pcibios_disable_irq(dev); 539 pcibios_disable_irq(dev);
490} 540}
491 541
492struct pci_bus *pci_scan_bus_on_node(int busno, struct pci_ops *ops, int node) 542struct pci_bus * __devinit pci_scan_bus_on_node(int busno, struct pci_ops *ops, int node)
493{ 543{
494 struct pci_bus *bus = NULL; 544 struct pci_bus *bus = NULL;
495 struct pci_sysdata *sd; 545 struct pci_sysdata *sd;
@@ -512,7 +562,7 @@ struct pci_bus *pci_scan_bus_on_node(int busno, struct pci_ops *ops, int node)
512 return bus; 562 return bus;
513} 563}
514 564
515struct pci_bus *pci_scan_bus_with_sysdata(int busno) 565struct pci_bus * __devinit pci_scan_bus_with_sysdata(int busno)
516{ 566{
517 return pci_scan_bus_on_node(busno, &pci_root_ops, -1); 567 return pci_scan_bus_on_node(busno, &pci_root_ops, -1);
518} 568}
diff --git a/arch/x86/pci/fixup.c b/arch/x86/pci/fixup.c
index b60b2abd480c..ff3a6a336342 100644
--- a/arch/x86/pci/fixup.c
+++ b/arch/x86/pci/fixup.c
@@ -502,7 +502,7 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SIEMENS, 0x0015,
502 */ 502 */
503static void fam10h_pci_cfg_space_size(struct pci_dev *dev) 503static void fam10h_pci_cfg_space_size(struct pci_dev *dev)
504{ 504{
505 dev->cfg_size = pci_cfg_space_size_ext(dev, 0); 505 dev->cfg_size = pci_cfg_space_size_ext(dev);
506} 506}
507 507
508DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, 0x1200, fam10h_pci_cfg_space_size); 508DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, 0x1200, fam10h_pci_cfg_space_size);
diff --git a/arch/x86/pci/i386.c b/arch/x86/pci/i386.c
index 94f6c73a53d0..8af0f0bae2af 100644
--- a/arch/x86/pci/i386.c
+++ b/arch/x86/pci/i386.c
@@ -301,6 +301,13 @@ int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
301 prot = pgprot_val(vma->vm_page_prot); 301 prot = pgprot_val(vma->vm_page_prot);
302 if (pat_wc_enabled && write_combine) 302 if (pat_wc_enabled && write_combine)
303 prot |= _PAGE_CACHE_WC; 303 prot |= _PAGE_CACHE_WC;
304 else if (pat_wc_enabled)
305 /*
306 * ioremap() and ioremap_nocache() defaults to UC MINUS for now.
307 * To avoid attribute conflicts, request UC MINUS here
308 * aswell.
309 */
310 prot |= _PAGE_CACHE_UC_MINUS;
304 else if (boot_cpu_data.x86 > 3) 311 else if (boot_cpu_data.x86 > 3)
305 prot |= _PAGE_CACHE_UC; 312 prot |= _PAGE_CACHE_UC;
306 313
@@ -319,9 +326,8 @@ int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
319 * - request is uncached, return cannot be write-combine 326 * - request is uncached, return cannot be write-combine
320 * - request is write-combine, return cannot be write-back 327 * - request is write-combine, return cannot be write-back
321 */ 328 */
322 if ((flags == _PAGE_CACHE_UC && 329 if ((flags == _PAGE_CACHE_UC_MINUS &&
323 (new_flags == _PAGE_CACHE_WB || 330 (new_flags == _PAGE_CACHE_WB)) ||
324 new_flags == _PAGE_CACHE_WC)) ||
325 (flags == _PAGE_CACHE_WC && 331 (flags == _PAGE_CACHE_WC &&
326 new_flags == _PAGE_CACHE_WB)) { 332 new_flags == _PAGE_CACHE_WB)) {
327 free_memtype(addr, addr+len); 333 free_memtype(addr, addr+len);
diff --git a/arch/x86/pci/init.c b/arch/x86/pci/init.c
index dd30c6076b5d..e70b9c57b88e 100644
--- a/arch/x86/pci/init.c
+++ b/arch/x86/pci/init.c
@@ -33,6 +33,10 @@ static __init int pci_access_init(void)
33 printk(KERN_ERR 33 printk(KERN_ERR
34 "PCI: Fatal: No config space access function found\n"); 34 "PCI: Fatal: No config space access function found\n");
35 35
36 dmi_check_pciprobe();
37
38 dmi_check_skip_isa_align();
39
36 return 0; 40 return 0;
37} 41}
38arch_initcall(pci_access_init); 42arch_initcall(pci_access_init);
diff --git a/arch/x86/pci/pci.h b/arch/x86/pci/pci.h
index c58805a92db5..f3972b12c60a 100644
--- a/arch/x86/pci/pci.h
+++ b/arch/x86/pci/pci.h
@@ -38,6 +38,9 @@ enum pci_bf_sort_state {
38 pci_dmi_bf, 38 pci_dmi_bf,
39}; 39};
40 40
41extern void __init dmi_check_pciprobe(void);
42extern void __init dmi_check_skip_isa_align(void);
43
41/* pci-i386.c */ 44/* pci-i386.c */
42 45
43extern unsigned int pcibios_max_latency; 46extern unsigned int pcibios_max_latency;
diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
index e2af8eee80e3..cf058fecfcee 100644
--- a/arch/x86/vdso/vdso32-setup.c
+++ b/arch/x86/vdso/vdso32-setup.c
@@ -162,7 +162,7 @@ static __init void relocate_vdso(Elf32_Ehdr *ehdr)
162 Elf32_Shdr *shdr; 162 Elf32_Shdr *shdr;
163 int i; 163 int i;
164 164
165 BUG_ON(memcmp(ehdr->e_ident, ELFMAG, 4) != 0 || 165 BUG_ON(memcmp(ehdr->e_ident, ELFMAG, SELFMAG) != 0 ||
166 !elf_check_arch_ia32(ehdr) || 166 !elf_check_arch_ia32(ehdr) ||
167 ehdr->e_type != ET_DYN); 167 ehdr->e_type != ET_DYN);
168 168
@@ -303,8 +303,6 @@ int __init sysenter_setup(void)
303 303
304#ifdef CONFIG_X86_32 304#ifdef CONFIG_X86_32
305 gate_vma_init(); 305 gate_vma_init();
306
307 printk("Compat vDSO mapped to %08lx.\n", __fix_to_virt(FIX_VDSO));
308#endif 306#endif
309 307
310 if (!vdso32_sysenter()) { 308 if (!vdso32_sysenter()) {
diff --git a/arch/x86/video/fbdev.c b/arch/x86/video/fbdev.c
index 4db42bff8c60..69527688f794 100644
--- a/arch/x86/video/fbdev.c
+++ b/arch/x86/video/fbdev.c
@@ -1,5 +1,4 @@
1/* 1/*
2 *
3 * Copyright (C) 2007 Antonino Daplas <adaplas@gmail.com> 2 * Copyright (C) 2007 Antonino Daplas <adaplas@gmail.com>
4 * 3 *
5 * This file is subject to the terms and conditions of the GNU General Public 4 * This file is subject to the terms and conditions of the GNU General Public
@@ -29,3 +28,4 @@ int fb_is_primary_device(struct fb_info *info)
29 return retval; 28 return retval;
30} 29}
31EXPORT_SYMBOL(fb_is_primary_device); 30EXPORT_SYMBOL(fb_is_primary_device);
31MODULE_LICENSE("GPL");
diff --git a/block/blk-barrier.c b/block/blk-barrier.c
index 66e55288178c..a09ead19f9c5 100644
--- a/block/blk-barrier.c
+++ b/block/blk-barrier.c
@@ -26,8 +26,7 @@ int blk_queue_ordered(struct request_queue *q, unsigned ordered,
26{ 26{
27 if (ordered & (QUEUE_ORDERED_PREFLUSH | QUEUE_ORDERED_POSTFLUSH) && 27 if (ordered & (QUEUE_ORDERED_PREFLUSH | QUEUE_ORDERED_POSTFLUSH) &&
28 prepare_flush_fn == NULL) { 28 prepare_flush_fn == NULL) {
29 printk(KERN_ERR "%s: prepare_flush_fn required\n", 29 printk(KERN_ERR "%s: prepare_flush_fn required\n", __func__);
30 __FUNCTION__);
31 return -EINVAL; 30 return -EINVAL;
32 } 31 }
33 32
diff --git a/block/blk-core.c b/block/blk-core.c
index 5d09f8c56024..b754a4a2f9bd 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -136,7 +136,7 @@ static void req_bio_endio(struct request *rq, struct bio *bio,
136 136
137 if (unlikely(nbytes > bio->bi_size)) { 137 if (unlikely(nbytes > bio->bi_size)) {
138 printk(KERN_ERR "%s: want %u bytes done, %u left\n", 138 printk(KERN_ERR "%s: want %u bytes done, %u left\n",
139 __FUNCTION__, nbytes, bio->bi_size); 139 __func__, nbytes, bio->bi_size);
140 nbytes = bio->bi_size; 140 nbytes = bio->bi_size;
141 } 141 }
142 142
@@ -1566,8 +1566,7 @@ static int __end_that_request_first(struct request *req, int error,
1566 if (unlikely(bio->bi_idx >= bio->bi_vcnt)) { 1566 if (unlikely(bio->bi_idx >= bio->bi_vcnt)) {
1567 blk_dump_rq_flags(req, "__end_that"); 1567 blk_dump_rq_flags(req, "__end_that");
1568 printk(KERN_ERR "%s: bio idx %d >= vcnt %d\n", 1568 printk(KERN_ERR "%s: bio idx %d >= vcnt %d\n",
1569 __FUNCTION__, bio->bi_idx, 1569 __func__, bio->bi_idx, bio->bi_vcnt);
1570 bio->bi_vcnt);
1571 break; 1570 break;
1572 } 1571 }
1573 1572
diff --git a/block/blk-settings.c b/block/blk-settings.c
index 6089384ab064..bb93d4c32775 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -168,8 +168,8 @@ void blk_queue_max_sectors(struct request_queue *q, unsigned int max_sectors)
168{ 168{
169 if ((max_sectors << 9) < PAGE_CACHE_SIZE) { 169 if ((max_sectors << 9) < PAGE_CACHE_SIZE) {
170 max_sectors = 1 << (PAGE_CACHE_SHIFT - 9); 170 max_sectors = 1 << (PAGE_CACHE_SHIFT - 9);
171 printk(KERN_INFO "%s: set to minimum %d\n", __FUNCTION__, 171 printk(KERN_INFO "%s: set to minimum %d\n",
172 max_sectors); 172 __func__, max_sectors);
173 } 173 }
174 174
175 if (BLK_DEF_MAX_SECTORS > max_sectors) 175 if (BLK_DEF_MAX_SECTORS > max_sectors)
@@ -196,8 +196,8 @@ void blk_queue_max_phys_segments(struct request_queue *q,
196{ 196{
197 if (!max_segments) { 197 if (!max_segments) {
198 max_segments = 1; 198 max_segments = 1;
199 printk(KERN_INFO "%s: set to minimum %d\n", __FUNCTION__, 199 printk(KERN_INFO "%s: set to minimum %d\n",
200 max_segments); 200 __func__, max_segments);
201 } 201 }
202 202
203 q->max_phys_segments = max_segments; 203 q->max_phys_segments = max_segments;
@@ -220,8 +220,8 @@ void blk_queue_max_hw_segments(struct request_queue *q,
220{ 220{
221 if (!max_segments) { 221 if (!max_segments) {
222 max_segments = 1; 222 max_segments = 1;
223 printk(KERN_INFO "%s: set to minimum %d\n", __FUNCTION__, 223 printk(KERN_INFO "%s: set to minimum %d\n",
224 max_segments); 224 __func__, max_segments);
225 } 225 }
226 226
227 q->max_hw_segments = max_segments; 227 q->max_hw_segments = max_segments;
@@ -241,8 +241,8 @@ void blk_queue_max_segment_size(struct request_queue *q, unsigned int max_size)
241{ 241{
242 if (max_size < PAGE_CACHE_SIZE) { 242 if (max_size < PAGE_CACHE_SIZE) {
243 max_size = PAGE_CACHE_SIZE; 243 max_size = PAGE_CACHE_SIZE;
244 printk(KERN_INFO "%s: set to minimum %d\n", __FUNCTION__, 244 printk(KERN_INFO "%s: set to minimum %d\n",
245 max_size); 245 __func__, max_size);
246 } 246 }
247 247
248 q->max_segment_size = max_size; 248 q->max_segment_size = max_size;
@@ -357,8 +357,8 @@ void blk_queue_segment_boundary(struct request_queue *q, unsigned long mask)
357{ 357{
358 if (mask < PAGE_CACHE_SIZE - 1) { 358 if (mask < PAGE_CACHE_SIZE - 1) {
359 mask = PAGE_CACHE_SIZE - 1; 359 mask = PAGE_CACHE_SIZE - 1;
360 printk(KERN_INFO "%s: set to minimum %lx\n", __FUNCTION__, 360 printk(KERN_INFO "%s: set to minimum %lx\n",
361 mask); 361 __func__, mask);
362 } 362 }
363 363
364 q->seg_boundary_mask = mask; 364 q->seg_boundary_mask = mask;
diff --git a/block/blk-tag.c b/block/blk-tag.c
index e176ddbe599e..de64e0429977 100644
--- a/block/blk-tag.c
+++ b/block/blk-tag.c
@@ -112,7 +112,7 @@ init_tag_map(struct request_queue *q, struct blk_queue_tag *tags, int depth)
112 if (q && depth > q->nr_requests * 2) { 112 if (q && depth > q->nr_requests * 2) {
113 depth = q->nr_requests * 2; 113 depth = q->nr_requests * 2;
114 printk(KERN_ERR "%s: adjusted depth to %d\n", 114 printk(KERN_ERR "%s: adjusted depth to %d\n",
115 __FUNCTION__, depth); 115 __func__, depth);
116 } 116 }
117 117
118 tag_index = kzalloc(depth * sizeof(struct request *), GFP_ATOMIC); 118 tag_index = kzalloc(depth * sizeof(struct request *), GFP_ATOMIC);
@@ -296,13 +296,13 @@ void blk_queue_end_tag(struct request_queue *q, struct request *rq)
296 296
297 if (unlikely(bqt->tag_index[tag] == NULL)) 297 if (unlikely(bqt->tag_index[tag] == NULL))
298 printk(KERN_ERR "%s: tag %d is missing\n", 298 printk(KERN_ERR "%s: tag %d is missing\n",
299 __FUNCTION__, tag); 299 __func__, tag);
300 300
301 bqt->tag_index[tag] = NULL; 301 bqt->tag_index[tag] = NULL;
302 302
303 if (unlikely(!test_bit(tag, bqt->tag_map))) { 303 if (unlikely(!test_bit(tag, bqt->tag_map))) {
304 printk(KERN_ERR "%s: attempt to clear non-busy tag (%d)\n", 304 printk(KERN_ERR "%s: attempt to clear non-busy tag (%d)\n",
305 __FUNCTION__, tag); 305 __func__, tag);
306 return; 306 return;
307 } 307 }
308 /* 308 /*
@@ -340,7 +340,7 @@ int blk_queue_start_tag(struct request_queue *q, struct request *rq)
340 if (unlikely((rq->cmd_flags & REQ_QUEUED))) { 340 if (unlikely((rq->cmd_flags & REQ_QUEUED))) {
341 printk(KERN_ERR 341 printk(KERN_ERR
342 "%s: request %p for device [%s] already tagged %d", 342 "%s: request %p for device [%s] already tagged %d",
343 __FUNCTION__, rq, 343 __func__, rq,
344 rq->rq_disk ? rq->rq_disk->disk_name : "?", rq->tag); 344 rq->rq_disk ? rq->rq_disk->disk_name : "?", rq->tag);
345 BUG(); 345 BUG();
346 } 346 }
diff --git a/block/bsg.c b/block/bsg.c
index 23ea4fd1a66d..f0b7cd343216 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -57,7 +57,7 @@ enum {
57#undef BSG_DEBUG 57#undef BSG_DEBUG
58 58
59#ifdef BSG_DEBUG 59#ifdef BSG_DEBUG
60#define dprintk(fmt, args...) printk(KERN_ERR "%s: " fmt, __FUNCTION__, ##args) 60#define dprintk(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ##args)
61#else 61#else
62#define dprintk(fmt, args...) 62#define dprintk(fmt, args...)
63#endif 63#endif
@@ -174,7 +174,11 @@ unlock:
174static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq, 174static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
175 struct sg_io_v4 *hdr, int has_write_perm) 175 struct sg_io_v4 *hdr, int has_write_perm)
176{ 176{
177 memset(rq->cmd, 0, BLK_MAX_CDB); /* ATAPI hates garbage after CDB */ 177 if (hdr->request_len > BLK_MAX_CDB) {
178 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
179 if (!rq->cmd)
180 return -ENOMEM;
181 }
178 182
179 if (copy_from_user(rq->cmd, (void *)(unsigned long)hdr->request, 183 if (copy_from_user(rq->cmd, (void *)(unsigned long)hdr->request,
180 hdr->request_len)) 184 hdr->request_len))
@@ -211,8 +215,6 @@ bsg_validate_sgv4_hdr(struct request_queue *q, struct sg_io_v4 *hdr, int *rw)
211 215
212 if (hdr->guard != 'Q') 216 if (hdr->guard != 'Q')
213 return -EINVAL; 217 return -EINVAL;
214 if (hdr->request_len > BLK_MAX_CDB)
215 return -EINVAL;
216 if (hdr->dout_xfer_len > (q->max_sectors << 9) || 218 if (hdr->dout_xfer_len > (q->max_sectors << 9) ||
217 hdr->din_xfer_len > (q->max_sectors << 9)) 219 hdr->din_xfer_len > (q->max_sectors << 9))
218 return -EIO; 220 return -EIO;
@@ -302,6 +304,8 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr)
302 } 304 }
303 return rq; 305 return rq;
304out: 306out:
307 if (rq->cmd != rq->__cmd)
308 kfree(rq->cmd);
305 blk_put_request(rq); 309 blk_put_request(rq);
306 if (next_rq) { 310 if (next_rq) {
307 blk_rq_unmap_user(next_rq->bio); 311 blk_rq_unmap_user(next_rq->bio);
@@ -455,6 +459,8 @@ static int blk_complete_sgv4_hdr_rq(struct request *rq, struct sg_io_v4 *hdr,
455 ret = rq->errors; 459 ret = rq->errors;
456 460
457 blk_rq_unmap_user(bio); 461 blk_rq_unmap_user(bio);
462 if (rq->cmd != rq->__cmd)
463 kfree(rq->cmd);
458 blk_put_request(rq); 464 blk_put_request(rq);
459 465
460 return ret; 466 return ret;
diff --git a/block/elevator.c b/block/elevator.c
index ac5310ef8270..980f8ae147b4 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -650,7 +650,7 @@ void elv_insert(struct request_queue *q, struct request *rq, int where)
650 650
651 default: 651 default:
652 printk(KERN_ERR "%s: bad insertion point %d\n", 652 printk(KERN_ERR "%s: bad insertion point %d\n",
653 __FUNCTION__, where); 653 __func__, where);
654 BUG(); 654 BUG();
655 } 655 }
656 656
@@ -808,8 +808,7 @@ struct request *elv_next_request(struct request_queue *q)
808 rq->cmd_flags |= REQ_QUIET; 808 rq->cmd_flags |= REQ_QUIET;
809 end_queued_request(rq, 0); 809 end_queued_request(rq, 0);
810 } else { 810 } else {
811 printk(KERN_ERR "%s: bad return=%d\n", __FUNCTION__, 811 printk(KERN_ERR "%s: bad return=%d\n", __func__, ret);
812 ret);
813 break; 812 break;
814 } 813 }
815 } 814 }
diff --git a/block/genhd.c b/block/genhd.c
index 00da5219ee37..fda9c7a63c29 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -182,11 +182,17 @@ static int exact_lock(dev_t devt, void *data)
182 */ 182 */
183void add_disk(struct gendisk *disk) 183void add_disk(struct gendisk *disk)
184{ 184{
185 struct backing_dev_info *bdi;
186
185 disk->flags |= GENHD_FL_UP; 187 disk->flags |= GENHD_FL_UP;
186 blk_register_region(MKDEV(disk->major, disk->first_minor), 188 blk_register_region(MKDEV(disk->major, disk->first_minor),
187 disk->minors, NULL, exact_match, exact_lock, disk); 189 disk->minors, NULL, exact_match, exact_lock, disk);
188 register_disk(disk); 190 register_disk(disk);
189 blk_register_queue(disk); 191 blk_register_queue(disk);
192
193 bdi = &disk->queue->backing_dev_info;
194 bdi_register_dev(bdi, MKDEV(disk->major, disk->first_minor));
195 sysfs_create_link(&disk->dev.kobj, &bdi->dev->kobj, "bdi");
190} 196}
191 197
192EXPORT_SYMBOL(add_disk); 198EXPORT_SYMBOL(add_disk);
@@ -194,6 +200,8 @@ EXPORT_SYMBOL(del_gendisk); /* in partitions/check.c */
194 200
195void unlink_gendisk(struct gendisk *disk) 201void unlink_gendisk(struct gendisk *disk)
196{ 202{
203 sysfs_remove_link(&disk->dev.kobj, "bdi");
204 bdi_unregister(&disk->queue->backing_dev_info);
197 blk_unregister_queue(disk); 205 blk_unregister_queue(disk);
198 blk_unregister_region(MKDEV(disk->major, disk->first_minor), 206 blk_unregister_region(MKDEV(disk->major, disk->first_minor),
199 disk->minors); 207 disk->minors);
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index ffa3720e6ca0..78199c08ec92 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -33,13 +33,12 @@
33#include <scsi/scsi_cmnd.h> 33#include <scsi/scsi_cmnd.h>
34 34
35/* Command group 3 is reserved and should never be used. */ 35/* Command group 3 is reserved and should never be used. */
36const unsigned char scsi_command_size[8] = 36const unsigned char scsi_command_size_tbl[8] =
37{ 37{
38 6, 10, 10, 12, 38 6, 10, 10, 12,
39 16, 12, 10, 10 39 16, 12, 10, 10
40}; 40};
41 41EXPORT_SYMBOL(scsi_command_size_tbl);
42EXPORT_SYMBOL(scsi_command_size);
43 42
44#include <scsi/sg.h> 43#include <scsi/sg.h>
45 44
diff --git a/crypto/authenc.c b/crypto/authenc.c
index ed8ac5a6fa5f..4b226768752a 100644
--- a/crypto/authenc.c
+++ b/crypto/authenc.c
@@ -217,9 +217,10 @@ static void crypto_authenc_givencrypt_done(struct crypto_async_request *req,
217 int err) 217 int err)
218{ 218{
219 if (!err) { 219 if (!err) {
220 struct aead_givcrypt_request *greq = req->data; 220 struct aead_request *areq = req->data;
221 struct skcipher_givcrypt_request *greq = aead_request_ctx(areq);
221 222
222 err = crypto_authenc_genicv(&greq->areq, greq->giv, 0); 223 err = crypto_authenc_genicv(areq, greq->giv, 0);
223 } 224 }
224 225
225 aead_request_complete(req->data, err); 226 aead_request_complete(req->data, err);
diff --git a/crypto/cryptd.c b/crypto/cryptd.c
index 250425263e00..b150de562057 100644
--- a/crypto/cryptd.c
+++ b/crypto/cryptd.c
@@ -190,8 +190,10 @@ static struct crypto_instance *cryptd_alloc_instance(struct crypto_alg *alg,
190 int err; 190 int err;
191 191
192 inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL); 192 inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL);
193 if (IS_ERR(inst)) 193 if (!inst) {
194 inst = ERR_PTR(-ENOMEM);
194 goto out; 195 goto out;
196 }
195 197
196 err = -ENAMETOOLONG; 198 err = -ENAMETOOLONG;
197 if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, 199 if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME,
diff --git a/crypto/eseqiv.c b/crypto/eseqiv.c
index b14f14e314b6..881d30910434 100644
--- a/crypto/eseqiv.c
+++ b/crypto/eseqiv.c
@@ -136,7 +136,8 @@ static int eseqiv_givencrypt(struct skcipher_givcrypt_request *req)
136 } 136 }
137 137
138 ablkcipher_request_set_crypt(subreq, reqctx->src, dst, 138 ablkcipher_request_set_crypt(subreq, reqctx->src, dst,
139 req->creq.nbytes, req->creq.info); 139 req->creq.nbytes + ivsize,
140 req->creq.info);
140 141
141 memcpy(req->creq.info, ctx->salt, ivsize); 142 memcpy(req->creq.info, ctx->salt, ivsize);
142 143
diff --git a/drivers/Kconfig b/drivers/Kconfig
index 80f0ec91e2cf..59f33fa6af3e 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -84,6 +84,8 @@ source "drivers/memstick/Kconfig"
84 84
85source "drivers/leds/Kconfig" 85source "drivers/leds/Kconfig"
86 86
87source "drivers/accessibility/Kconfig"
88
87source "drivers/infiniband/Kconfig" 89source "drivers/infiniband/Kconfig"
88 90
89source "drivers/edac/Kconfig" 91source "drivers/edac/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index e5e394a7e6c0..f65deda72d61 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -70,6 +70,7 @@ obj-$(CONFIG_WATCHDOG) += watchdog/
70obj-$(CONFIG_PHONE) += telephony/ 70obj-$(CONFIG_PHONE) += telephony/
71obj-$(CONFIG_MD) += md/ 71obj-$(CONFIG_MD) += md/
72obj-$(CONFIG_BT) += bluetooth/ 72obj-$(CONFIG_BT) += bluetooth/
73obj-$(CONFIG_ACCESSIBILITY) += accessibility/
73obj-$(CONFIG_ISDN) += isdn/ 74obj-$(CONFIG_ISDN) += isdn/
74obj-$(CONFIG_EDAC) += edac/ 75obj-$(CONFIG_EDAC) += edac/
75obj-$(CONFIG_MCA) += mca/ 76obj-$(CONFIG_MCA) += mca/
diff --git a/drivers/accessibility/Kconfig b/drivers/accessibility/Kconfig
new file mode 100644
index 000000000000..1264c4b98094
--- /dev/null
+++ b/drivers/accessibility/Kconfig
@@ -0,0 +1,23 @@
1menuconfig ACCESSIBILITY
2 bool "Accessibility support"
3 ---help---
4 Enable a submenu where accessibility items may be enabled.
5
6 If unsure, say N.
7
8if ACCESSIBILITY
9config A11Y_BRAILLE_CONSOLE
10 bool "Console on braille device"
11 depends on VT
12 depends on SERIAL_CORE_CONSOLE
13 ---help---
14 Enables console output on a braille device connected to a 8250
15 serial port. For now only the VisioBraille device is supported.
16
17 To actually enable it, you need to pass option
18 console=brl,ttyS0
19 to the kernel. Options are the same as for serial console.
20
21 If unsure, say N.
22
23endif # ACCESSIBILITY
diff --git a/drivers/accessibility/Makefile b/drivers/accessibility/Makefile
new file mode 100644
index 000000000000..72b01a46546f
--- /dev/null
+++ b/drivers/accessibility/Makefile
@@ -0,0 +1 @@
obj-y += braille/
diff --git a/drivers/accessibility/braille/Makefile b/drivers/accessibility/braille/Makefile
new file mode 100644
index 000000000000..2e9f16c91347
--- /dev/null
+++ b/drivers/accessibility/braille/Makefile
@@ -0,0 +1 @@
obj-$(CONFIG_A11Y_BRAILLE_CONSOLE) += braille_console.o
diff --git a/drivers/accessibility/braille/braille_console.c b/drivers/accessibility/braille/braille_console.c
new file mode 100644
index 000000000000..0a5f6b2114c5
--- /dev/null
+++ b/drivers/accessibility/braille/braille_console.c
@@ -0,0 +1,397 @@
1/*
2 * Minimalistic braille device kernel support.
3 *
4 * By default, shows console messages on the braille device.
5 * Pressing Insert switches to VC browsing.
6 *
7 * Copyright (C) Samuel Thibault <samuel.thibault@ens-lyon.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 as published by
11 * the Free Software Foundation ; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY ; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with the program ; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24#include <linux/autoconf.h>
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/moduleparam.h>
28#include <linux/console.h>
29#include <linux/notifier.h>
30
31#include <linux/selection.h>
32#include <linux/vt_kern.h>
33#include <linux/consolemap.h>
34
35#include <linux/keyboard.h>
36#include <linux/kbd_kern.h>
37#include <linux/input.h>
38
39MODULE_AUTHOR("samuel.thibault@ens-lyon.org");
40MODULE_DESCRIPTION("braille device");
41MODULE_LICENSE("GPL");
42
43/*
44 * Braille device support part.
45 */
46
47/* Emit various sounds */
48static int sound;
49module_param(sound, bool, 0);
50MODULE_PARM_DESC(sound, "emit sounds");
51
52static void beep(unsigned int freq)
53{
54 if (sound)
55 kd_mksound(freq, HZ/10);
56}
57
58/* mini console */
59#define WIDTH 40
60#define BRAILLE_KEY KEY_INSERT
61static u16 console_buf[WIDTH];
62static int console_cursor;
63
64/* mini view of VC */
65static int vc_x, vc_y, lastvc_x, lastvc_y;
66
67/* show console ? (or show VC) */
68static int console_show = 1;
69/* pending newline ? */
70static int console_newline = 1;
71static int lastVC = -1;
72
73static struct console *braille_co;
74
75/* Very VisioBraille-specific */
76static void braille_write(u16 *buf)
77{
78 static u16 lastwrite[WIDTH];
79 unsigned char data[1 + 1 + 2*WIDTH + 2 + 1], csum = 0, *c;
80 u16 out;
81 int i;
82
83 if (!braille_co)
84 return;
85
86 if (!memcmp(lastwrite, buf, WIDTH * sizeof(*buf)))
87 return;
88 memcpy(lastwrite, buf, WIDTH * sizeof(*buf));
89
90#define SOH 1
91#define STX 2
92#define ETX 2
93#define EOT 4
94#define ENQ 5
95 data[0] = STX;
96 data[1] = '>';
97 csum ^= '>';
98 c = &data[2];
99 for (i = 0; i < WIDTH; i++) {
100 out = buf[i];
101 if (out >= 0x100)
102 out = '?';
103 else if (out == 0x00)
104 out = ' ';
105 csum ^= out;
106 if (out <= 0x05) {
107 *c++ = SOH;
108 out |= 0x40;
109 }
110 *c++ = out;
111 }
112
113 if (csum <= 0x05) {
114 *c++ = SOH;
115 csum |= 0x40;
116 }
117 *c++ = csum;
118 *c++ = ETX;
119
120 braille_co->write(braille_co, data, c - data);
121}
122
123/* Follow the VC cursor*/
124static void vc_follow_cursor(struct vc_data *vc)
125{
126 vc_x = vc->vc_x - (vc->vc_x % WIDTH);
127 vc_y = vc->vc_y;
128 lastvc_x = vc->vc_x;
129 lastvc_y = vc->vc_y;
130}
131
132/* Maybe the VC cursor moved, if so follow it */
133static void vc_maybe_cursor_moved(struct vc_data *vc)
134{
135 if (vc->vc_x != lastvc_x || vc->vc_y != lastvc_y)
136 vc_follow_cursor(vc);
137}
138
139/* Show portion of VC at vc_x, vc_y */
140static void vc_refresh(struct vc_data *vc)
141{
142 u16 buf[WIDTH];
143 int i;
144
145 for (i = 0; i < WIDTH; i++) {
146 u16 glyph = screen_glyph(vc,
147 2 * (vc_x + i) + vc_y * vc->vc_size_row);
148 buf[i] = inverse_translate(vc, glyph, 1);
149 }
150 braille_write(buf);
151}
152
153/*
154 * Link to keyboard
155 */
156
157static int keyboard_notifier_call(struct notifier_block *blk,
158 unsigned long code, void *_param)
159{
160 struct keyboard_notifier_param *param = _param;
161 struct vc_data *vc = param->vc;
162 int ret = NOTIFY_OK;
163
164 if (!param->down)
165 return ret;
166
167 switch (code) {
168 case KBD_KEYCODE:
169 if (console_show) {
170 if (param->value == BRAILLE_KEY) {
171 console_show = 0;
172 beep(880);
173 vc_maybe_cursor_moved(vc);
174 vc_refresh(vc);
175 ret = NOTIFY_STOP;
176 }
177 } else {
178 ret = NOTIFY_STOP;
179 switch (param->value) {
180 case KEY_INSERT:
181 beep(440);
182 console_show = 1;
183 lastVC = -1;
184 braille_write(console_buf);
185 break;
186 case KEY_LEFT:
187 if (vc_x > 0) {
188 vc_x -= WIDTH;
189 if (vc_x < 0)
190 vc_x = 0;
191 } else if (vc_y >= 1) {
192 beep(880);
193 vc_y--;
194 vc_x = vc->vc_cols-WIDTH;
195 } else
196 beep(220);
197 break;
198 case KEY_RIGHT:
199 if (vc_x + WIDTH < vc->vc_cols) {
200 vc_x += WIDTH;
201 } else if (vc_y + 1 < vc->vc_rows) {
202 beep(880);
203 vc_y++;
204 vc_x = 0;
205 } else
206 beep(220);
207 break;
208 case KEY_DOWN:
209 if (vc_y + 1 < vc->vc_rows)
210 vc_y++;
211 else
212 beep(220);
213 break;
214 case KEY_UP:
215 if (vc_y >= 1)
216 vc_y--;
217 else
218 beep(220);
219 break;
220 case KEY_HOME:
221 vc_follow_cursor(vc);
222 break;
223 case KEY_PAGEUP:
224 vc_x = 0;
225 vc_y = 0;
226 break;
227 case KEY_PAGEDOWN:
228 vc_x = 0;
229 vc_y = vc->vc_rows-1;
230 break;
231 default:
232 ret = NOTIFY_OK;
233 break;
234 }
235 if (ret == NOTIFY_STOP)
236 vc_refresh(vc);
237 }
238 break;
239 case KBD_POST_KEYSYM:
240 {
241 unsigned char type = KTYP(param->value) - 0xf0;
242 if (type == KT_SPEC) {
243 unsigned char val = KVAL(param->value);
244 int on_off = -1;
245
246 switch (val) {
247 case KVAL(K_CAPS):
248 on_off = vc_kbd_led(kbd_table + fg_console,
249 VC_CAPSLOCK);
250 break;
251 case KVAL(K_NUM):
252 on_off = vc_kbd_led(kbd_table + fg_console,
253 VC_NUMLOCK);
254 break;
255 case KVAL(K_HOLD):
256 on_off = vc_kbd_led(kbd_table + fg_console,
257 VC_SCROLLOCK);
258 break;
259 }
260 if (on_off == 1)
261 beep(880);
262 else if (on_off == 0)
263 beep(440);
264 }
265 }
266 case KBD_UNBOUND_KEYCODE:
267 case KBD_UNICODE:
268 case KBD_KEYSYM:
269 /* Unused */
270 break;
271 }
272 return ret;
273}
274
275static struct notifier_block keyboard_notifier_block = {
276 .notifier_call = keyboard_notifier_call,
277};
278
279static int vt_notifier_call(struct notifier_block *blk,
280 unsigned long code, void *_param)
281{
282 struct vt_notifier_param *param = _param;
283 struct vc_data *vc = param->vc;
284 switch (code) {
285 case VT_ALLOCATE:
286 break;
287 case VT_DEALLOCATE:
288 break;
289 case VT_WRITE:
290 {
291 unsigned char c = param->c;
292 if (vc->vc_num != fg_console)
293 break;
294 switch (c) {
295 case '\b':
296 case 127:
297 if (console_cursor > 0) {
298 console_cursor--;
299 console_buf[console_cursor] = ' ';
300 }
301 break;
302 case '\n':
303 case '\v':
304 case '\f':
305 case '\r':
306 console_newline = 1;
307 break;
308 case '\t':
309 c = ' ';
310 /* Fallthrough */
311 default:
312 if (c < 32)
313 /* Ignore other control sequences */
314 break;
315 if (console_newline) {
316 memset(console_buf, 0, sizeof(console_buf));
317 console_cursor = 0;
318 console_newline = 0;
319 }
320 if (console_cursor == WIDTH)
321 memmove(console_buf, &console_buf[1],
322 (WIDTH-1) * sizeof(*console_buf));
323 else
324 console_cursor++;
325 console_buf[console_cursor-1] = c;
326 break;
327 }
328 if (console_show)
329 braille_write(console_buf);
330 else {
331 vc_maybe_cursor_moved(vc);
332 vc_refresh(vc);
333 }
334 break;
335 }
336 case VT_UPDATE:
337 /* Maybe a VT switch, flush */
338 if (console_show) {
339 if (vc->vc_num != lastVC) {
340 lastVC = vc->vc_num;
341 memset(console_buf, 0, sizeof(console_buf));
342 console_cursor = 0;
343 braille_write(console_buf);
344 }
345 } else {
346 vc_maybe_cursor_moved(vc);
347 vc_refresh(vc);
348 }
349 break;
350 }
351 return NOTIFY_OK;
352}
353
354static struct notifier_block vt_notifier_block = {
355 .notifier_call = vt_notifier_call,
356};
357
358/*
359 * Called from printk.c when console=brl is given
360 */
361
362int braille_register_console(struct console *console, int index,
363 char *console_options, char *braille_options)
364{
365 int ret;
366 if (!console_options)
367 /* Only support VisioBraille for now */
368 console_options = "57600o8";
369 if (braille_co)
370 return -ENODEV;
371 if (console->setup) {
372 ret = console->setup(console, console_options);
373 if (ret != 0)
374 return ret;
375 }
376 console->flags |= CON_ENABLED;
377 console->index = index;
378 braille_co = console;
379 return 0;
380}
381
382int braille_unregister_console(struct console *console)
383{
384 if (braille_co != console)
385 return -EINVAL;
386 braille_co = NULL;
387 return 0;
388}
389
390static int __init braille_init(void)
391{
392 register_keyboard_notifier(&keyboard_notifier_block);
393 register_vt_notifier(&vt_notifier_block);
394 return 0;
395}
396
397console_initcall(braille_init);
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index b4f5e8542829..c52fca833268 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -140,6 +140,7 @@ config ACPI_VIDEO
140 tristate "Video" 140 tristate "Video"
141 depends on X86 && BACKLIGHT_CLASS_DEVICE && VIDEO_OUTPUT_CONTROL 141 depends on X86 && BACKLIGHT_CLASS_DEVICE && VIDEO_OUTPUT_CONTROL
142 depends on INPUT 142 depends on INPUT
143 select THERMAL
143 help 144 help
144 This driver implement the ACPI Extensions For Display Adapters 145 This driver implement the ACPI Extensions For Display Adapters
145 for integrated graphics devices on motherboard, as specified in 146 for integrated graphics devices on motherboard, as specified in
@@ -151,6 +152,7 @@ config ACPI_VIDEO
151 152
152config ACPI_FAN 153config ACPI_FAN
153 tristate "Fan" 154 tristate "Fan"
155 select THERMAL
154 default y 156 default y
155 help 157 help
156 This driver adds support for ACPI fan devices, allowing user-mode 158 This driver adds support for ACPI fan devices, allowing user-mode
@@ -172,6 +174,7 @@ config ACPI_BAY
172 174
173config ACPI_PROCESSOR 175config ACPI_PROCESSOR
174 tristate "Processor" 176 tristate "Processor"
177 select THERMAL
175 default y 178 default y
176 help 179 help
177 This driver installs ACPI as the idle handler for Linux, and uses 180 This driver installs ACPI as the idle handler for Linux, and uses
diff --git a/drivers/acpi/bay.c b/drivers/acpi/bay.c
index 1fa86811b8ee..d2fc94161848 100644
--- a/drivers/acpi/bay.c
+++ b/drivers/acpi/bay.c
@@ -201,6 +201,7 @@ static int is_ejectable_bay(acpi_handle handle)
201 return 0; 201 return 0;
202} 202}
203 203
204#if 0
204/** 205/**
205 * eject_removable_drive - try to eject this drive 206 * eject_removable_drive - try to eject this drive
206 * @dev : the device structure of the drive 207 * @dev : the device structure of the drive
@@ -225,6 +226,7 @@ int eject_removable_drive(struct device *dev)
225 return 0; 226 return 0;
226} 227}
227EXPORT_SYMBOL_GPL(eject_removable_drive); 228EXPORT_SYMBOL_GPL(eject_removable_drive);
229#endif /* 0 */
228 230
229static int acpi_bay_add_fs(struct bay *bay) 231static int acpi_bay_add_fs(struct bay *bay)
230{ 232{
diff --git a/drivers/acpi/dispatcher/dsfield.c b/drivers/acpi/dispatcher/dsfield.c
index f049639bac35..c78078315be9 100644
--- a/drivers/acpi/dispatcher/dsfield.c
+++ b/drivers/acpi/dispatcher/dsfield.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -89,12 +89,16 @@ acpi_ds_create_buffer_field(union acpi_parse_object *op,
89 89
90 ACPI_FUNCTION_TRACE(ds_create_buffer_field); 90 ACPI_FUNCTION_TRACE(ds_create_buffer_field);
91 91
92 /* Get the name_string argument */ 92 /*
93 93 * Get the name_string argument (name of the new buffer_field)
94 */
94 if (op->common.aml_opcode == AML_CREATE_FIELD_OP) { 95 if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
96
97 /* For create_field, name is the 4th argument */
98
95 arg = acpi_ps_get_arg(op, 3); 99 arg = acpi_ps_get_arg(op, 3);
96 } else { 100 } else {
97 /* Create Bit/Byte/Word/Dword field */ 101 /* For all other create_xXXField operators, name is the 3rd argument */
98 102
99 arg = acpi_ps_get_arg(op, 2); 103 arg = acpi_ps_get_arg(op, 2);
100 } 104 }
@@ -107,26 +111,30 @@ acpi_ds_create_buffer_field(union acpi_parse_object *op,
107 node = walk_state->deferred_node; 111 node = walk_state->deferred_node;
108 status = AE_OK; 112 status = AE_OK;
109 } else { 113 } else {
110 /* 114 /* Execute flag should always be set when this function is entered */
111 * During the load phase, we want to enter the name of the field into 115
112 * the namespace. During the execute phase (when we evaluate the size 116 if (!(walk_state->parse_flags & ACPI_PARSE_EXECUTE)) {
113 * operand), we want to lookup the name 117 return_ACPI_STATUS(AE_AML_INTERNAL);
114 */
115 if (walk_state->parse_flags & ACPI_PARSE_EXECUTE) {
116 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE;
117 } else {
118 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
119 ACPI_NS_ERROR_IF_FOUND;
120 } 118 }
121 119
122 /* 120 /* Creating new namespace node, should not already exist */
123 * Enter the name_string into the namespace 121
124 */ 122 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
123 ACPI_NS_ERROR_IF_FOUND;
124
125 /* Mark node temporary if we are executing a method */
126
127 if (walk_state->method_node) {
128 flags |= ACPI_NS_TEMPORARY;
129 }
130
131 /* Enter the name_string into the namespace */
132
125 status = 133 status =
126 acpi_ns_lookup(walk_state->scope_info, 134 acpi_ns_lookup(walk_state->scope_info,
127 arg->common.value.string, ACPI_TYPE_ANY, 135 arg->common.value.string, ACPI_TYPE_ANY,
128 ACPI_IMODE_LOAD_PASS1, flags, walk_state, 136 ACPI_IMODE_LOAD_PASS1, flags, walk_state,
129 &(node)); 137 &node);
130 if (ACPI_FAILURE(status)) { 138 if (ACPI_FAILURE(status)) {
131 ACPI_ERROR_NAMESPACE(arg->common.value.string, status); 139 ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
132 return_ACPI_STATUS(status); 140 return_ACPI_STATUS(status);
@@ -136,13 +144,13 @@ acpi_ds_create_buffer_field(union acpi_parse_object *op,
136 /* 144 /*
137 * We could put the returned object (Node) on the object stack for later, 145 * We could put the returned object (Node) on the object stack for later,
138 * but for now, we will put it in the "op" object that the parser uses, 146 * but for now, we will put it in the "op" object that the parser uses,
139 * so we can get it again at the end of this scope 147 * so we can get it again at the end of this scope.
140 */ 148 */
141 op->common.node = node; 149 op->common.node = node;
142 150
143 /* 151 /*
144 * If there is no object attached to the node, this node was just created 152 * If there is no object attached to the node, this node was just created
145 * and we need to create the field object. Otherwise, this was a lookup 153 * and we need to create the field object. Otherwise, this was a lookup
146 * of an existing node and we don't want to create the field object again. 154 * of an existing node and we don't want to create the field object again.
147 */ 155 */
148 obj_desc = acpi_ns_get_attached_object(node); 156 obj_desc = acpi_ns_get_attached_object(node);
@@ -164,9 +172,8 @@ acpi_ds_create_buffer_field(union acpi_parse_object *op,
164 } 172 }
165 173
166 /* 174 /*
167 * Remember location in AML stream of the field unit 175 * Remember location in AML stream of the field unit opcode and operands --
168 * opcode and operands -- since the buffer and index 176 * since the buffer and index operands must be evaluated.
169 * operands must be evaluated.
170 */ 177 */
171 second_desc = obj_desc->common.next_object; 178 second_desc = obj_desc->common.next_object;
172 second_desc->extra.aml_start = op->named.data; 179 second_desc->extra.aml_start = op->named.data;
@@ -261,7 +268,7 @@ acpi_ds_get_field_names(struct acpi_create_field_info *info,
261 268
262 case AML_INT_NAMEDFIELD_OP: 269 case AML_INT_NAMEDFIELD_OP:
263 270
264 /* Lookup the name */ 271 /* Lookup the name, it should already exist */
265 272
266 status = acpi_ns_lookup(walk_state->scope_info, 273 status = acpi_ns_lookup(walk_state->scope_info,
267 (char *)&arg->named.name, 274 (char *)&arg->named.name,
@@ -272,20 +279,23 @@ acpi_ds_get_field_names(struct acpi_create_field_info *info,
272 if (ACPI_FAILURE(status)) { 279 if (ACPI_FAILURE(status)) {
273 ACPI_ERROR_NAMESPACE((char *)&arg->named.name, 280 ACPI_ERROR_NAMESPACE((char *)&arg->named.name,
274 status); 281 status);
275 if (status != AE_ALREADY_EXISTS) { 282 return_ACPI_STATUS(status);
276 return_ACPI_STATUS(status);
277 }
278
279 /* Already exists, ignore error */
280 } else { 283 } else {
281 arg->common.node = info->field_node; 284 arg->common.node = info->field_node;
282 info->field_bit_length = arg->common.value.size; 285 info->field_bit_length = arg->common.value.size;
283 286
284 /* Create and initialize an object for the new Field Node */ 287 /*
285 288 * If there is no object attached to the node, this node was
286 status = acpi_ex_prep_field_value(info); 289 * just created and we need to create the field object.
287 if (ACPI_FAILURE(status)) { 290 * Otherwise, this was a lookup of an existing node and we
288 return_ACPI_STATUS(status); 291 * don't want to create the field object again.
292 */
293 if (!acpi_ns_get_attached_object
294 (info->field_node)) {
295 status = acpi_ex_prep_field_value(info);
296 if (ACPI_FAILURE(status)) {
297 return_ACPI_STATUS(status);
298 }
289 } 299 }
290 } 300 }
291 301
@@ -399,9 +409,27 @@ acpi_ds_init_field_objects(union acpi_parse_object *op,
399 union acpi_parse_object *arg = NULL; 409 union acpi_parse_object *arg = NULL;
400 struct acpi_namespace_node *node; 410 struct acpi_namespace_node *node;
401 u8 type = 0; 411 u8 type = 0;
412 u32 flags;
402 413
403 ACPI_FUNCTION_TRACE_PTR(ds_init_field_objects, op); 414 ACPI_FUNCTION_TRACE_PTR(ds_init_field_objects, op);
404 415
416 /* Execute flag should always be set when this function is entered */
417
418 if (!(walk_state->parse_flags & ACPI_PARSE_EXECUTE)) {
419 if (walk_state->parse_flags & ACPI_PARSE_DEFERRED_OP) {
420
421 /* bank_field Op is deferred, just return OK */
422
423 return_ACPI_STATUS(AE_OK);
424 }
425
426 return_ACPI_STATUS(AE_AML_INTERNAL);
427 }
428
429 /*
430 * Get the field_list argument for this opcode. This is the start of the
431 * list of field elements.
432 */
405 switch (walk_state->opcode) { 433 switch (walk_state->opcode) {
406 case AML_FIELD_OP: 434 case AML_FIELD_OP:
407 arg = acpi_ps_get_arg(op, 2); 435 arg = acpi_ps_get_arg(op, 2);
@@ -422,20 +450,33 @@ acpi_ds_init_field_objects(union acpi_parse_object *op,
422 return_ACPI_STATUS(AE_BAD_PARAMETER); 450 return_ACPI_STATUS(AE_BAD_PARAMETER);
423 } 451 }
424 452
453 if (!arg) {
454 return_ACPI_STATUS(AE_AML_NO_OPERAND);
455 }
456
457 /* Creating new namespace node(s), should not already exist */
458
459 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
460 ACPI_NS_ERROR_IF_FOUND;
461
462 /* Mark node(s) temporary if we are executing a method */
463
464 if (walk_state->method_node) {
465 flags |= ACPI_NS_TEMPORARY;
466 }
467
425 /* 468 /*
426 * Walk the list of entries in the field_list 469 * Walk the list of entries in the field_list
427 */ 470 */
428 while (arg) { 471 while (arg) {
429 472 /*
430 /* Ignore OFFSET and ACCESSAS terms here */ 473 * Ignore OFFSET and ACCESSAS terms here; we are only interested in the
431 474 * field names in order to enter them into the namespace.
475 */
432 if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) { 476 if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) {
433 status = acpi_ns_lookup(walk_state->scope_info, 477 status = acpi_ns_lookup(walk_state->scope_info,
434 (char *)&arg->named.name, 478 (char *)&arg->named.name, type,
435 type, ACPI_IMODE_LOAD_PASS1, 479 ACPI_IMODE_LOAD_PASS1, flags,
436 ACPI_NS_NO_UPSEARCH |
437 ACPI_NS_DONT_OPEN_SCOPE |
438 ACPI_NS_ERROR_IF_FOUND,
439 walk_state, &node); 480 walk_state, &node);
440 if (ACPI_FAILURE(status)) { 481 if (ACPI_FAILURE(status)) {
441 ACPI_ERROR_NAMESPACE((char *)&arg->named.name, 482 ACPI_ERROR_NAMESPACE((char *)&arg->named.name,
@@ -452,7 +493,7 @@ acpi_ds_init_field_objects(union acpi_parse_object *op,
452 arg->common.node = node; 493 arg->common.node = node;
453 } 494 }
454 495
455 /* Move to next field in the list */ 496 /* Get the next field element in the list */
456 497
457 arg = arg->common.next; 498 arg = arg->common.next;
458 } 499 }
@@ -466,7 +507,7 @@ acpi_ds_init_field_objects(union acpi_parse_object *op,
466 * 507 *
467 * PARAMETERS: Op - Op containing the Field definition and args 508 * PARAMETERS: Op - Op containing the Field definition and args
468 * region_node - Object for the containing Operation Region 509 * region_node - Object for the containing Operation Region
469 * ` walk_state - Current method state 510 * walk_state - Current method state
470 * 511 *
471 * RETURN: Status 512 * RETURN: Status
472 * 513 *
@@ -513,36 +554,13 @@ acpi_ds_create_bank_field(union acpi_parse_object *op,
513 return_ACPI_STATUS(status); 554 return_ACPI_STATUS(status);
514 } 555 }
515 556
516 /* Third arg is the bank_value */ 557 /*
517 558 * Third arg is the bank_value
518 /* TBD: This arg is a term_arg, not a constant, and must be evaluated */ 559 * This arg is a term_arg, not a constant
519 560 * It will be evaluated later, by acpi_ds_eval_bank_field_operands
561 */
520 arg = arg->common.next; 562 arg = arg->common.next;
521 563
522 /* Currently, only the following constants are supported */
523
524 switch (arg->common.aml_opcode) {
525 case AML_ZERO_OP:
526 info.bank_value = 0;
527 break;
528
529 case AML_ONE_OP:
530 info.bank_value = 1;
531 break;
532
533 case AML_BYTE_OP:
534 case AML_WORD_OP:
535 case AML_DWORD_OP:
536 case AML_QWORD_OP:
537 info.bank_value = (u32) arg->common.value.integer;
538 break;
539
540 default:
541 info.bank_value = 0;
542 ACPI_ERROR((AE_INFO,
543 "Non-constant BankValue for BankField is not implemented"));
544 }
545
546 /* Fourth arg is the field flags */ 564 /* Fourth arg is the field flags */
547 565
548 arg = arg->common.next; 566 arg = arg->common.next;
@@ -553,8 +571,17 @@ acpi_ds_create_bank_field(union acpi_parse_object *op,
553 info.field_type = ACPI_TYPE_LOCAL_BANK_FIELD; 571 info.field_type = ACPI_TYPE_LOCAL_BANK_FIELD;
554 info.region_node = region_node; 572 info.region_node = region_node;
555 573
556 status = acpi_ds_get_field_names(&info, walk_state, arg->common.next); 574 /*
575 * Use Info.data_register_node to store bank_field Op
576 * It's safe because data_register_node will never be used when create bank field
577 * We store aml_start and aml_length in the bank_field Op for late evaluation
578 * Used in acpi_ex_prep_field_value(Info)
579 *
580 * TBD: Or, should we add a field in struct acpi_create_field_info, like "void *ParentOp"?
581 */
582 info.data_register_node = (struct acpi_namespace_node *)op;
557 583
584 status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
558 return_ACPI_STATUS(status); 585 return_ACPI_STATUS(status);
559} 586}
560 587
diff --git a/drivers/acpi/dispatcher/dsinit.c b/drivers/acpi/dispatcher/dsinit.c
index af923c388520..610b1ee102b0 100644
--- a/drivers/acpi/dispatcher/dsinit.c
+++ b/drivers/acpi/dispatcher/dsinit.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/dispatcher/dsmethod.c b/drivers/acpi/dispatcher/dsmethod.c
index 1cbe61905824..e48a3ea03117 100644
--- a/drivers/acpi/dispatcher/dsmethod.c
+++ b/drivers/acpi/dispatcher/dsmethod.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -42,7 +42,6 @@
42 */ 42 */
43 43
44#include <acpi/acpi.h> 44#include <acpi/acpi.h>
45#include <acpi/acparser.h>
46#include <acpi/amlcode.h> 45#include <acpi/amlcode.h>
47#include <acpi/acdispat.h> 46#include <acpi/acdispat.h>
48#include <acpi/acinterp.h> 47#include <acpi/acinterp.h>
@@ -102,7 +101,7 @@ acpi_ds_method_error(acpi_status status, struct acpi_walk_state *walk_state)
102 walk_state->opcode, 101 walk_state->opcode,
103 walk_state->aml_offset, 102 walk_state->aml_offset,
104 NULL); 103 NULL);
105 (void)acpi_ex_enter_interpreter(); 104 acpi_ex_enter_interpreter();
106 } 105 }
107#ifdef ACPI_DISASSEMBLER 106#ifdef ACPI_DISASSEMBLER
108 if (ACPI_FAILURE(status)) { 107 if (ACPI_FAILURE(status)) {
@@ -232,9 +231,9 @@ acpi_ds_begin_method_execution(struct acpi_namespace_node *method_node,
232 * recursive call. 231 * recursive call.
233 */ 232 */
234 if (!walk_state || 233 if (!walk_state ||
235 !obj_desc->method.mutex->mutex.owner_thread || 234 !obj_desc->method.mutex->mutex.thread_id ||
236 (walk_state->thread != 235 (walk_state->thread->thread_id !=
237 obj_desc->method.mutex->mutex.owner_thread)) { 236 obj_desc->method.mutex->mutex.thread_id)) {
238 /* 237 /*
239 * Acquire the method mutex. This releases the interpreter if we 238 * Acquire the method mutex. This releases the interpreter if we
240 * block (and reacquires it before it returns) 239 * block (and reacquires it before it returns)
@@ -254,8 +253,8 @@ acpi_ds_begin_method_execution(struct acpi_namespace_node *method_node,
254 original_sync_level = 253 original_sync_level =
255 walk_state->thread->current_sync_level; 254 walk_state->thread->current_sync_level;
256 255
257 obj_desc->method.mutex->mutex.owner_thread = 256 obj_desc->method.mutex->mutex.thread_id =
258 walk_state->thread; 257 walk_state->thread->thread_id;
259 walk_state->thread->current_sync_level = 258 walk_state->thread->current_sync_level =
260 obj_desc->method.sync_level; 259 obj_desc->method.sync_level;
261 } else { 260 } else {
@@ -535,8 +534,6 @@ void
535acpi_ds_terminate_control_method(union acpi_operand_object *method_desc, 534acpi_ds_terminate_control_method(union acpi_operand_object *method_desc,
536 struct acpi_walk_state *walk_state) 535 struct acpi_walk_state *walk_state)
537{ 536{
538 struct acpi_namespace_node *method_node;
539 acpi_status status;
540 537
541 ACPI_FUNCTION_TRACE_PTR(ds_terminate_control_method, walk_state); 538 ACPI_FUNCTION_TRACE_PTR(ds_terminate_control_method, walk_state);
542 539
@@ -551,34 +548,26 @@ acpi_ds_terminate_control_method(union acpi_operand_object *method_desc,
551 /* Delete all arguments and locals */ 548 /* Delete all arguments and locals */
552 549
553 acpi_ds_method_data_delete_all(walk_state); 550 acpi_ds_method_data_delete_all(walk_state);
554 }
555 551
556 /* 552 /*
557 * If method is serialized, release the mutex and restore the 553 * If method is serialized, release the mutex and restore the
558 * current sync level for this thread 554 * current sync level for this thread
559 */ 555 */
560 if (method_desc->method.mutex) { 556 if (method_desc->method.mutex) {
561 557
562 /* Acquisition Depth handles recursive calls */ 558 /* Acquisition Depth handles recursive calls */
563 559
564 method_desc->method.mutex->mutex.acquisition_depth--; 560 method_desc->method.mutex->mutex.acquisition_depth--;
565 if (!method_desc->method.mutex->mutex.acquisition_depth) { 561 if (!method_desc->method.mutex->mutex.acquisition_depth) {
566 walk_state->thread->current_sync_level = 562 walk_state->thread->current_sync_level =
567 method_desc->method.mutex->mutex. 563 method_desc->method.mutex->mutex.
568 original_sync_level; 564 original_sync_level;
569 565
570 acpi_os_release_mutex(method_desc->method.mutex->mutex. 566 acpi_os_release_mutex(method_desc->method.
571 os_mutex); 567 mutex->mutex.os_mutex);
572 method_desc->method.mutex->mutex.owner_thread = NULL; 568 method_desc->method.mutex->mutex.thread_id = 0;
569 }
573 } 570 }
574 }
575
576 if (walk_state) {
577 /*
578 * Delete any objects created by this method during execution.
579 * The method Node is stored in the walk state
580 */
581 method_node = walk_state->method_node;
582 571
583 /* 572 /*
584 * Delete any namespace objects created anywhere within 573 * Delete any namespace objects created anywhere within
@@ -620,7 +609,7 @@ acpi_ds_terminate_control_method(union acpi_operand_object *method_desc,
620 */ 609 */
621 if ((method_desc->method.method_flags & AML_METHOD_SERIALIZED) 610 if ((method_desc->method.method_flags & AML_METHOD_SERIALIZED)
622 && (!method_desc->method.mutex)) { 611 && (!method_desc->method.mutex)) {
623 status = acpi_ds_create_method_mutex(method_desc); 612 (void)acpi_ds_create_method_mutex(method_desc);
624 } 613 }
625 614
626 /* No more threads, we can free the owner_id */ 615 /* No more threads, we can free the owner_id */
diff --git a/drivers/acpi/dispatcher/dsmthdat.c b/drivers/acpi/dispatcher/dsmthdat.c
index ba4626e06a5e..13c43eac35db 100644
--- a/drivers/acpi/dispatcher/dsmthdat.c
+++ b/drivers/acpi/dispatcher/dsmthdat.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/dispatcher/dsobject.c b/drivers/acpi/dispatcher/dsobject.c
index 954ac8ce958a..1022e38994c2 100644
--- a/drivers/acpi/dispatcher/dsobject.c
+++ b/drivers/acpi/dispatcher/dsobject.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -157,7 +157,9 @@ acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
157 * will remain as named references. This behavior is not described 157 * will remain as named references. This behavior is not described
158 * in the ACPI spec, but it appears to be an oversight. 158 * in the ACPI spec, but it appears to be an oversight.
159 */ 159 */
160 obj_desc = (union acpi_operand_object *)op->common.node; 160 obj_desc =
161 ACPI_CAST_PTR(union acpi_operand_object,
162 op->common.node);
161 163
162 status = 164 status =
163 acpi_ex_resolve_node_to_value(ACPI_CAST_INDIRECT_PTR 165 acpi_ex_resolve_node_to_value(ACPI_CAST_INDIRECT_PTR
@@ -172,7 +174,19 @@ acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
172 switch (op->common.node->type) { 174 switch (op->common.node->type) {
173 /* 175 /*
174 * For these types, we need the actual node, not the subobject. 176 * For these types, we need the actual node, not the subobject.
175 * However, the subobject got an extra reference count above. 177 * However, the subobject did not get an extra reference count above.
178 *
179 * TBD: should ex_resolve_node_to_value be changed to fix this?
180 */
181 case ACPI_TYPE_DEVICE:
182 case ACPI_TYPE_THERMAL:
183
184 acpi_ut_add_reference(op->common.node->object);
185
186 /*lint -fallthrough */
187 /*
188 * For these types, we need the actual node, not the subobject.
189 * The subobject got an extra reference count in ex_resolve_node_to_value.
176 */ 190 */
177 case ACPI_TYPE_MUTEX: 191 case ACPI_TYPE_MUTEX:
178 case ACPI_TYPE_METHOD: 192 case ACPI_TYPE_METHOD:
@@ -180,25 +194,15 @@ acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
180 case ACPI_TYPE_PROCESSOR: 194 case ACPI_TYPE_PROCESSOR:
181 case ACPI_TYPE_EVENT: 195 case ACPI_TYPE_EVENT:
182 case ACPI_TYPE_REGION: 196 case ACPI_TYPE_REGION:
183 case ACPI_TYPE_DEVICE:
184 case ACPI_TYPE_THERMAL:
185 197
186 obj_desc = 198 /* We will create a reference object for these types below */
187 (union acpi_operand_object *)op->common.
188 node;
189 break; 199 break;
190 200
191 default: 201 default:
192 break; 202 /*
193 } 203 * All other types - the node was resolved to an actual
194 204 * object, we are done.
195 /* 205 */
196 * If above resolved to an operand object, we are done. Otherwise,
197 * we have a NS node, we must create the package entry as a named
198 * reference.
199 */
200 if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) !=
201 ACPI_DESC_TYPE_NAMED) {
202 goto exit; 206 goto exit;
203 } 207 }
204 } 208 }
@@ -223,7 +227,7 @@ acpi_ds_build_internal_object(struct acpi_walk_state *walk_state,
223 227
224 exit: 228 exit:
225 *obj_desc_ptr = obj_desc; 229 *obj_desc_ptr = obj_desc;
226 return_ACPI_STATUS(AE_OK); 230 return_ACPI_STATUS(status);
227} 231}
228 232
229/******************************************************************************* 233/*******************************************************************************
@@ -369,7 +373,9 @@ acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
369 union acpi_parse_object *parent; 373 union acpi_parse_object *parent;
370 union acpi_operand_object *obj_desc = NULL; 374 union acpi_operand_object *obj_desc = NULL;
371 acpi_status status = AE_OK; 375 acpi_status status = AE_OK;
372 acpi_native_uint i; 376 unsigned i;
377 u16 index;
378 u16 reference_count;
373 379
374 ACPI_FUNCTION_TRACE(ds_build_internal_package_obj); 380 ACPI_FUNCTION_TRACE(ds_build_internal_package_obj);
375 381
@@ -447,13 +453,60 @@ acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
447 package. 453 package.
448 elements[i]); 454 elements[i]);
449 } 455 }
456
457 if (*obj_desc_ptr) {
458
459 /* Existing package, get existing reference count */
460
461 reference_count =
462 (*obj_desc_ptr)->common.reference_count;
463 if (reference_count > 1) {
464
465 /* Make new element ref count match original ref count */
466
467 for (index = 0; index < (reference_count - 1);
468 index++) {
469 acpi_ut_add_reference((obj_desc->
470 package.
471 elements[i]));
472 }
473 }
474 }
475
450 arg = arg->common.next; 476 arg = arg->common.next;
451 } 477 }
452 478
453 if (!arg) { 479 /* Check for match between num_elements and actual length of package_list */
480
481 if (arg) {
482 /*
483 * num_elements was exhausted, but there are remaining elements in the
484 * package_list.
485 *
486 * Note: technically, this is an error, from ACPI spec: "It is an error
487 * for NumElements to be less than the number of elements in the
488 * PackageList". However, for now, we just print an error message and
489 * no exception is returned.
490 */
491 while (arg) {
492
493 /* Find out how many elements there really are */
494
495 i++;
496 arg = arg->common.next;
497 }
498
499 ACPI_ERROR((AE_INFO,
500 "Package List length (%X) larger than NumElements count (%X), truncated\n",
501 i, element_count));
502 } else if (i < element_count) {
503 /*
504 * Arg list (elements) was exhausted, but we did not reach num_elements count.
505 * Note: this is not an error, the package is padded out with NULLs.
506 */
454 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 507 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
455 "Package List length larger than NumElements count (%X), truncated\n", 508 "Package List length (%X) smaller than NumElements count (%X), padded with null elements\n",
456 element_count)); 509 i, element_count));
457 } 510 }
458 511
459 obj_desc->package.flags |= AOPOBJ_DATA_VALID; 512 obj_desc->package.flags |= AOPOBJ_DATA_VALID;
@@ -721,6 +774,8 @@ acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
721 /* Node was saved in Op */ 774 /* Node was saved in Op */
722 775
723 obj_desc->reference.node = op->common.node; 776 obj_desc->reference.node = op->common.node;
777 obj_desc->reference.object =
778 op->common.node->object;
724 } 779 }
725 780
726 obj_desc->reference.opcode = opcode; 781 obj_desc->reference.opcode = opcode;
diff --git a/drivers/acpi/dispatcher/dsopcode.c b/drivers/acpi/dispatcher/dsopcode.c
index f501e083aac7..a818e0ddb996 100644
--- a/drivers/acpi/dispatcher/dsopcode.c
+++ b/drivers/acpi/dispatcher/dsopcode.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -49,6 +49,7 @@
49#include <acpi/acinterp.h> 49#include <acpi/acinterp.h>
50#include <acpi/acnamesp.h> 50#include <acpi/acnamesp.h>
51#include <acpi/acevents.h> 51#include <acpi/acevents.h>
52#include <acpi/actables.h>
52 53
53#define _COMPONENT ACPI_DISPATCHER 54#define _COMPONENT ACPI_DISPATCHER
54ACPI_MODULE_NAME("dsopcode") 55ACPI_MODULE_NAME("dsopcode")
@@ -219,6 +220,50 @@ acpi_ds_get_buffer_field_arguments(union acpi_operand_object *obj_desc)
219 220
220/******************************************************************************* 221/*******************************************************************************
221 * 222 *
223 * FUNCTION: acpi_ds_get_bank_field_arguments
224 *
225 * PARAMETERS: obj_desc - A valid bank_field object
226 *
227 * RETURN: Status.
228 *
229 * DESCRIPTION: Get bank_field bank_value. This implements the late
230 * evaluation of these field attributes.
231 *
232 ******************************************************************************/
233
234acpi_status
235acpi_ds_get_bank_field_arguments(union acpi_operand_object *obj_desc)
236{
237 union acpi_operand_object *extra_desc;
238 struct acpi_namespace_node *node;
239 acpi_status status;
240
241 ACPI_FUNCTION_TRACE_PTR(ds_get_bank_field_arguments, obj_desc);
242
243 if (obj_desc->common.flags & AOPOBJ_DATA_VALID) {
244 return_ACPI_STATUS(AE_OK);
245 }
246
247 /* Get the AML pointer (method object) and bank_field node */
248
249 extra_desc = acpi_ns_get_secondary_object(obj_desc);
250 node = obj_desc->bank_field.node;
251
252 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
253 (ACPI_TYPE_LOCAL_BANK_FIELD, node, NULL));
254 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "[%4.4s] BankField Arg Init\n",
255 acpi_ut_get_node_name(node)));
256
257 /* Execute the AML code for the term_arg arguments */
258
259 status = acpi_ds_execute_arguments(node, acpi_ns_get_parent_node(node),
260 extra_desc->extra.aml_length,
261 extra_desc->extra.aml_start);
262 return_ACPI_STATUS(status);
263}
264
265/*******************************************************************************
266 *
222 * FUNCTION: acpi_ds_get_buffer_arguments 267 * FUNCTION: acpi_ds_get_buffer_arguments
223 * 268 *
224 * PARAMETERS: obj_desc - A valid Buffer object 269 * PARAMETERS: obj_desc - A valid Buffer object
@@ -770,7 +815,109 @@ acpi_ds_eval_region_operands(struct acpi_walk_state *walk_state,
770 815
771 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n", 816 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
772 obj_desc, 817 obj_desc,
773 ACPI_FORMAT_UINT64(obj_desc->region.address), 818 ACPI_FORMAT_NATIVE_UINT(obj_desc->region.address),
819 obj_desc->region.length));
820
821 /* Now the address and length are valid for this opregion */
822
823 obj_desc->region.flags |= AOPOBJ_DATA_VALID;
824
825 return_ACPI_STATUS(status);
826}
827
828/*******************************************************************************
829 *
830 * FUNCTION: acpi_ds_eval_table_region_operands
831 *
832 * PARAMETERS: walk_state - Current walk
833 * Op - A valid region Op object
834 *
835 * RETURN: Status
836 *
837 * DESCRIPTION: Get region address and length
838 * Called from acpi_ds_exec_end_op during data_table_region parse tree walk
839 *
840 ******************************************************************************/
841
842acpi_status
843acpi_ds_eval_table_region_operands(struct acpi_walk_state *walk_state,
844 union acpi_parse_object *op)
845{
846 acpi_status status;
847 union acpi_operand_object *obj_desc;
848 union acpi_operand_object **operand;
849 struct acpi_namespace_node *node;
850 union acpi_parse_object *next_op;
851 acpi_native_uint table_index;
852 struct acpi_table_header *table;
853
854 ACPI_FUNCTION_TRACE_PTR(ds_eval_table_region_operands, op);
855
856 /*
857 * This is where we evaluate the signature_string and oem_iDString
858 * and oem_table_iDString of the data_table_region declaration
859 */
860 node = op->common.node;
861
862 /* next_op points to signature_string op */
863
864 next_op = op->common.value.arg;
865
866 /*
867 * Evaluate/create the signature_string and oem_iDString
868 * and oem_table_iDString operands
869 */
870 status = acpi_ds_create_operands(walk_state, next_op);
871 if (ACPI_FAILURE(status)) {
872 return_ACPI_STATUS(status);
873 }
874
875 /*
876 * Resolve the signature_string and oem_iDString
877 * and oem_table_iDString operands
878 */
879 status = acpi_ex_resolve_operands(op->common.aml_opcode,
880 ACPI_WALK_OPERANDS, walk_state);
881 if (ACPI_FAILURE(status)) {
882 return_ACPI_STATUS(status);
883 }
884
885 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
886 acpi_ps_get_opcode_name(op->common.aml_opcode),
887 1, "after AcpiExResolveOperands");
888
889 operand = &walk_state->operands[0];
890
891 /* Find the ACPI table */
892
893 status = acpi_tb_find_table(operand[0]->string.pointer,
894 operand[1]->string.pointer,
895 operand[2]->string.pointer, &table_index);
896 if (ACPI_FAILURE(status)) {
897 return_ACPI_STATUS(status);
898 }
899
900 acpi_ut_remove_reference(operand[0]);
901 acpi_ut_remove_reference(operand[1]);
902 acpi_ut_remove_reference(operand[2]);
903
904 status = acpi_get_table_by_index(table_index, &table);
905 if (ACPI_FAILURE(status)) {
906 return_ACPI_STATUS(status);
907 }
908
909 obj_desc = acpi_ns_get_attached_object(node);
910 if (!obj_desc) {
911 return_ACPI_STATUS(AE_NOT_EXIST);
912 }
913
914 obj_desc->region.address =
915 (acpi_physical_address) ACPI_TO_INTEGER(table);
916 obj_desc->region.length = table->length;
917
918 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
919 obj_desc,
920 ACPI_FORMAT_NATIVE_UINT(obj_desc->region.address),
774 obj_desc->region.length)); 921 obj_desc->region.length));
775 922
776 /* Now the address and length are valid for this opregion */ 923 /* Now the address and length are valid for this opregion */
@@ -808,6 +955,12 @@ acpi_ds_eval_data_object_operands(struct acpi_walk_state *walk_state,
808 955
809 /* The first operand (for all of these data objects) is the length */ 956 /* The first operand (for all of these data objects) is the length */
810 957
958 /*
959 * Set proper index into operand stack for acpi_ds_obj_stack_push
960 * invoked inside acpi_ds_create_operand.
961 */
962 walk_state->operand_index = walk_state->num_operands;
963
811 status = acpi_ds_create_operand(walk_state, op->common.value.arg, 1); 964 status = acpi_ds_create_operand(walk_state, op->common.value.arg, 1);
812 if (ACPI_FAILURE(status)) { 965 if (ACPI_FAILURE(status)) {
813 return_ACPI_STATUS(status); 966 return_ACPI_STATUS(status);
@@ -878,6 +1031,106 @@ acpi_ds_eval_data_object_operands(struct acpi_walk_state *walk_state,
878 1031
879/******************************************************************************* 1032/*******************************************************************************
880 * 1033 *
1034 * FUNCTION: acpi_ds_eval_bank_field_operands
1035 *
1036 * PARAMETERS: walk_state - Current walk
1037 * Op - A valid bank_field Op object
1038 *
1039 * RETURN: Status
1040 *
1041 * DESCRIPTION: Get bank_field bank_value
1042 * Called from acpi_ds_exec_end_op during bank_field parse tree walk
1043 *
1044 ******************************************************************************/
1045
1046acpi_status
1047acpi_ds_eval_bank_field_operands(struct acpi_walk_state *walk_state,
1048 union acpi_parse_object *op)
1049{
1050 acpi_status status;
1051 union acpi_operand_object *obj_desc;
1052 union acpi_operand_object *operand_desc;
1053 struct acpi_namespace_node *node;
1054 union acpi_parse_object *next_op;
1055 union acpi_parse_object *arg;
1056
1057 ACPI_FUNCTION_TRACE_PTR(ds_eval_bank_field_operands, op);
1058
1059 /*
1060 * This is where we evaluate the bank_value field of the
1061 * bank_field declaration
1062 */
1063
1064 /* next_op points to the op that holds the Region */
1065
1066 next_op = op->common.value.arg;
1067
1068 /* next_op points to the op that holds the Bank Register */
1069
1070 next_op = next_op->common.next;
1071
1072 /* next_op points to the op that holds the Bank Value */
1073
1074 next_op = next_op->common.next;
1075
1076 /*
1077 * Set proper index into operand stack for acpi_ds_obj_stack_push
1078 * invoked inside acpi_ds_create_operand.
1079 *
1080 * We use walk_state->Operands[0] to store the evaluated bank_value
1081 */
1082 walk_state->operand_index = 0;
1083
1084 status = acpi_ds_create_operand(walk_state, next_op, 0);
1085 if (ACPI_FAILURE(status)) {
1086 return_ACPI_STATUS(status);
1087 }
1088
1089 status = acpi_ex_resolve_to_value(&walk_state->operands[0], walk_state);
1090 if (ACPI_FAILURE(status)) {
1091 return_ACPI_STATUS(status);
1092 }
1093
1094 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE,
1095 acpi_ps_get_opcode_name(op->common.aml_opcode),
1096 1, "after AcpiExResolveOperands");
1097
1098 /*
1099 * Get the bank_value operand and save it
1100 * (at Top of stack)
1101 */
1102 operand_desc = walk_state->operands[0];
1103
1104 /* Arg points to the start Bank Field */
1105
1106 arg = acpi_ps_get_arg(op, 4);
1107 while (arg) {
1108
1109 /* Ignore OFFSET and ACCESSAS terms here */
1110
1111 if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) {
1112 node = arg->common.node;
1113
1114 obj_desc = acpi_ns_get_attached_object(node);
1115 if (!obj_desc) {
1116 return_ACPI_STATUS(AE_NOT_EXIST);
1117 }
1118
1119 obj_desc->bank_field.value =
1120 (u32) operand_desc->integer.value;
1121 }
1122
1123 /* Move to next field in the list */
1124
1125 arg = arg->common.next;
1126 }
1127
1128 acpi_ut_remove_reference(operand_desc);
1129 return_ACPI_STATUS(status);
1130}
1131
1132/*******************************************************************************
1133 *
881 * FUNCTION: acpi_ds_exec_begin_control_op 1134 * FUNCTION: acpi_ds_exec_begin_control_op
882 * 1135 *
883 * PARAMETERS: walk_list - The list that owns the walk stack 1136 * PARAMETERS: walk_list - The list that owns the walk stack
@@ -1070,8 +1323,7 @@ acpi_ds_exec_end_control_op(struct acpi_walk_state * walk_state,
1070 * is set to anything other than zero! 1323 * is set to anything other than zero!
1071 */ 1324 */
1072 walk_state->return_desc = walk_state->operands[0]; 1325 walk_state->return_desc = walk_state->operands[0];
1073 } else if ((walk_state->results) && 1326 } else if (walk_state->result_count) {
1074 (walk_state->results->results.num_results > 0)) {
1075 1327
1076 /* Since we have a real Return(), delete any implicit return */ 1328 /* Since we have a real Return(), delete any implicit return */
1077 1329
diff --git a/drivers/acpi/dispatcher/dsutils.c b/drivers/acpi/dispatcher/dsutils.c
index 71503c036f7c..b398982f0d8b 100644
--- a/drivers/acpi/dispatcher/dsutils.c
+++ b/drivers/acpi/dispatcher/dsutils.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -278,7 +278,9 @@ acpi_ds_is_result_used(union acpi_parse_object * op,
278 AML_VAR_PACKAGE_OP) 278 AML_VAR_PACKAGE_OP)
279 || (op->common.parent->common.aml_opcode == AML_BUFFER_OP) 279 || (op->common.parent->common.aml_opcode == AML_BUFFER_OP)
280 || (op->common.parent->common.aml_opcode == 280 || (op->common.parent->common.aml_opcode ==
281 AML_INT_EVAL_SUBTREE_OP)) { 281 AML_INT_EVAL_SUBTREE_OP)
282 || (op->common.parent->common.aml_opcode ==
283 AML_BANK_FIELD_OP)) {
282 /* 284 /*
283 * These opcodes allow term_arg(s) as operands and therefore 285 * These opcodes allow term_arg(s) as operands and therefore
284 * the operands can be method calls. The result is used. 286 * the operands can be method calls. The result is used.
@@ -472,7 +474,8 @@ acpi_ds_create_operand(struct acpi_walk_state *walk_state,
472 /* A valid name must be looked up in the namespace */ 474 /* A valid name must be looked up in the namespace */
473 475
474 if ((arg->common.aml_opcode == AML_INT_NAMEPATH_OP) && 476 if ((arg->common.aml_opcode == AML_INT_NAMEPATH_OP) &&
475 (arg->common.value.string)) { 477 (arg->common.value.string) &&
478 !(arg->common.flags & ACPI_PARSEOP_IN_STACK)) {
476 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Getting a name: Arg=%p\n", 479 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Getting a name: Arg=%p\n",
477 arg)); 480 arg));
478 481
@@ -595,7 +598,8 @@ acpi_ds_create_operand(struct acpi_walk_state *walk_state,
595 } else { 598 } else {
596 /* Check for null name case */ 599 /* Check for null name case */
597 600
598 if (arg->common.aml_opcode == AML_INT_NAMEPATH_OP) { 601 if ((arg->common.aml_opcode == AML_INT_NAMEPATH_OP) &&
602 !(arg->common.flags & ACPI_PARSEOP_IN_STACK)) {
599 /* 603 /*
600 * If the name is null, this means that this is an 604 * If the name is null, this means that this is an
601 * optional result parameter that was not specified 605 * optional result parameter that was not specified
@@ -617,7 +621,8 @@ acpi_ds_create_operand(struct acpi_walk_state *walk_state,
617 return_ACPI_STATUS(AE_NOT_IMPLEMENTED); 621 return_ACPI_STATUS(AE_NOT_IMPLEMENTED);
618 } 622 }
619 623
620 if (op_info->flags & AML_HAS_RETVAL) { 624 if ((op_info->flags & AML_HAS_RETVAL)
625 || (arg->common.flags & ACPI_PARSEOP_IN_STACK)) {
621 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, 626 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
622 "Argument previously created, already stacked\n")); 627 "Argument previously created, already stacked\n"));
623 628
@@ -630,9 +635,7 @@ acpi_ds_create_operand(struct acpi_walk_state *walk_state,
630 * Use value that was already previously returned 635 * Use value that was already previously returned
631 * by the evaluation of this argument 636 * by the evaluation of this argument
632 */ 637 */
633 status = 638 status = acpi_ds_result_pop(&obj_desc, walk_state);
634 acpi_ds_result_pop_from_bottom(&obj_desc,
635 walk_state);
636 if (ACPI_FAILURE(status)) { 639 if (ACPI_FAILURE(status)) {
637 /* 640 /*
638 * Only error is underflow, and this indicates 641 * Only error is underflow, and this indicates
@@ -698,27 +701,52 @@ acpi_ds_create_operands(struct acpi_walk_state *walk_state,
698{ 701{
699 acpi_status status = AE_OK; 702 acpi_status status = AE_OK;
700 union acpi_parse_object *arg; 703 union acpi_parse_object *arg;
704 union acpi_parse_object *arguments[ACPI_OBJ_NUM_OPERANDS];
701 u32 arg_count = 0; 705 u32 arg_count = 0;
706 u32 index = walk_state->num_operands;
707 u32 i;
702 708
703 ACPI_FUNCTION_TRACE_PTR(ds_create_operands, first_arg); 709 ACPI_FUNCTION_TRACE_PTR(ds_create_operands, first_arg);
704 710
705 /* For all arguments in the list... */ 711 /* Get all arguments in the list */
706 712
707 arg = first_arg; 713 arg = first_arg;
708 while (arg) { 714 while (arg) {
709 status = acpi_ds_create_operand(walk_state, arg, arg_count); 715 if (index >= ACPI_OBJ_NUM_OPERANDS) {
710 if (ACPI_FAILURE(status)) { 716 return_ACPI_STATUS(AE_BAD_DATA);
711 goto cleanup;
712 } 717 }
713 718
714 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, 719 arguments[index] = arg;
715 "Arg #%d (%p) done, Arg1=%p\n", arg_count, 720 walk_state->operands[index] = NULL;
716 arg, first_arg));
717 721
718 /* Move on to next argument, if any */ 722 /* Move on to next argument, if any */
719 723
720 arg = arg->common.next; 724 arg = arg->common.next;
721 arg_count++; 725 arg_count++;
726 index++;
727 }
728
729 index--;
730
731 /* It is the appropriate order to get objects from the Result stack */
732
733 for (i = 0; i < arg_count; i++) {
734 arg = arguments[index];
735
736 /* Force the filling of the operand stack in inverse order */
737
738 walk_state->operand_index = (u8) index;
739
740 status = acpi_ds_create_operand(walk_state, arg, index);
741 if (ACPI_FAILURE(status)) {
742 goto cleanup;
743 }
744
745 index--;
746
747 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
748 "Arg #%d (%p) done, Arg1=%p\n", index, arg,
749 first_arg));
722 } 750 }
723 751
724 return_ACPI_STATUS(status); 752 return_ACPI_STATUS(status);
@@ -729,9 +757,112 @@ acpi_ds_create_operands(struct acpi_walk_state *walk_state,
729 * pop everything off of the operand stack and delete those 757 * pop everything off of the operand stack and delete those
730 * objects 758 * objects
731 */ 759 */
732 (void)acpi_ds_obj_stack_pop_and_delete(arg_count, walk_state); 760 acpi_ds_obj_stack_pop_and_delete(arg_count, walk_state);
761
762 ACPI_EXCEPTION((AE_INFO, status, "While creating Arg %d", index));
763 return_ACPI_STATUS(status);
764}
765
766/*****************************************************************************
767 *
768 * FUNCTION: acpi_ds_evaluate_name_path
769 *
770 * PARAMETERS: walk_state - Current state of the parse tree walk,
771 * the opcode of current operation should be
772 * AML_INT_NAMEPATH_OP
773 *
774 * RETURN: Status
775 *
776 * DESCRIPTION: Translate the -name_path- parse tree object to the equivalent
777 * interpreter object, convert it to value, if needed, duplicate
778 * it, if needed, and push it onto the current result stack.
779 *
780 ****************************************************************************/
781
782acpi_status acpi_ds_evaluate_name_path(struct acpi_walk_state *walk_state)
783{
784 acpi_status status = AE_OK;
785 union acpi_parse_object *op = walk_state->op;
786 union acpi_operand_object **operand = &walk_state->operands[0];
787 union acpi_operand_object *new_obj_desc;
788 u8 type;
789
790 ACPI_FUNCTION_TRACE_PTR(ds_evaluate_name_path, walk_state);
791
792 if (!op->common.parent) {
793
794 /* This happens after certain exception processing */
795
796 goto exit;
797 }
798
799 if ((op->common.parent->common.aml_opcode == AML_PACKAGE_OP) ||
800 (op->common.parent->common.aml_opcode == AML_VAR_PACKAGE_OP) ||
801 (op->common.parent->common.aml_opcode == AML_REF_OF_OP)) {
802
803 /* TBD: Should we specify this feature as a bit of op_info->Flags of these opcodes? */
804
805 goto exit;
806 }
807
808 status = acpi_ds_create_operand(walk_state, op, 0);
809 if (ACPI_FAILURE(status)) {
810 goto exit;
811 }
812
813 if (op->common.flags & ACPI_PARSEOP_TARGET) {
814 new_obj_desc = *operand;
815 goto push_result;
816 }
817
818 type = ACPI_GET_OBJECT_TYPE(*operand);
819
820 status = acpi_ex_resolve_to_value(operand, walk_state);
821 if (ACPI_FAILURE(status)) {
822 goto exit;
823 }
824
825 if (type == ACPI_TYPE_INTEGER) {
826
827 /* It was incremented by acpi_ex_resolve_to_value */
828
829 acpi_ut_remove_reference(*operand);
830
831 status =
832 acpi_ut_copy_iobject_to_iobject(*operand, &new_obj_desc,
833 walk_state);
834 if (ACPI_FAILURE(status)) {
835 goto exit;
836 }
837 } else {
838 /*
839 * The object either was anew created or is
840 * a Namespace node - don't decrement it.
841 */
842 new_obj_desc = *operand;
843 }
844
845 /* Cleanup for name-path operand */
846
847 status = acpi_ds_obj_stack_pop(1, walk_state);
848 if (ACPI_FAILURE(status)) {
849 walk_state->result_obj = new_obj_desc;
850 goto exit;
851 }
852
853 push_result:
854
855 walk_state->result_obj = new_obj_desc;
856
857 status = acpi_ds_result_push(walk_state->result_obj, walk_state);
858 if (ACPI_SUCCESS(status)) {
859
860 /* Force to take it from stack */
861
862 op->common.flags |= ACPI_PARSEOP_IN_STACK;
863 }
864
865 exit:
733 866
734 ACPI_EXCEPTION((AE_INFO, status, "While creating Arg %d",
735 (arg_count + 1)));
736 return_ACPI_STATUS(status); 867 return_ACPI_STATUS(status);
737} 868}
diff --git a/drivers/acpi/dispatcher/dswexec.c b/drivers/acpi/dispatcher/dswexec.c
index 69693fa07224..b246b9657ead 100644
--- a/drivers/acpi/dispatcher/dswexec.c
+++ b/drivers/acpi/dispatcher/dswexec.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -285,11 +285,6 @@ acpi_ds_exec_begin_op(struct acpi_walk_state *walk_state,
285 switch (opcode_class) { 285 switch (opcode_class) {
286 case AML_CLASS_CONTROL: 286 case AML_CLASS_CONTROL:
287 287
288 status = acpi_ds_result_stack_push(walk_state);
289 if (ACPI_FAILURE(status)) {
290 goto error_exit;
291 }
292
293 status = acpi_ds_exec_begin_control_op(walk_state, op); 288 status = acpi_ds_exec_begin_control_op(walk_state, op);
294 break; 289 break;
295 290
@@ -305,20 +300,11 @@ acpi_ds_exec_begin_op(struct acpi_walk_state *walk_state,
305 status = acpi_ds_load2_begin_op(walk_state, NULL); 300 status = acpi_ds_load2_begin_op(walk_state, NULL);
306 } 301 }
307 302
308 if (op->common.aml_opcode == AML_REGION_OP) {
309 status = acpi_ds_result_stack_push(walk_state);
310 }
311 break; 303 break;
312 304
313 case AML_CLASS_EXECUTE: 305 case AML_CLASS_EXECUTE:
314 case AML_CLASS_CREATE: 306 case AML_CLASS_CREATE:
315 /* 307
316 * Most operators with arguments (except create_xxx_field operators)
317 * Start a new result/operand state
318 */
319 if (walk_state->op_info->object_type != ACPI_TYPE_BUFFER_FIELD) {
320 status = acpi_ds_result_stack_push(walk_state);
321 }
322 break; 308 break;
323 309
324 default: 310 default:
@@ -374,6 +360,7 @@ acpi_status acpi_ds_exec_end_op(struct acpi_walk_state *walk_state)
374 /* Init the walk state */ 360 /* Init the walk state */
375 361
376 walk_state->num_operands = 0; 362 walk_state->num_operands = 0;
363 walk_state->operand_index = 0;
377 walk_state->return_desc = NULL; 364 walk_state->return_desc = NULL;
378 walk_state->result_obj = NULL; 365 walk_state->result_obj = NULL;
379 366
@@ -388,10 +375,17 @@ acpi_status acpi_ds_exec_end_op(struct acpi_walk_state *walk_state)
388 /* Decode the Opcode Class */ 375 /* Decode the Opcode Class */
389 376
390 switch (op_class) { 377 switch (op_class) {
391 case AML_CLASS_ARGUMENT: /* constants, literals, etc. - do nothing */ 378 case AML_CLASS_ARGUMENT: /* Constants, literals, etc. */
379
380 if (walk_state->opcode == AML_INT_NAMEPATH_OP) {
381 status = acpi_ds_evaluate_name_path(walk_state);
382 if (ACPI_FAILURE(status)) {
383 goto cleanup;
384 }
385 }
392 break; 386 break;
393 387
394 case AML_CLASS_EXECUTE: /* most operators with arguments */ 388 case AML_CLASS_EXECUTE: /* Most operators with arguments */
395 389
396 /* Build resolved operand stack */ 390 /* Build resolved operand stack */
397 391
@@ -400,13 +394,6 @@ acpi_status acpi_ds_exec_end_op(struct acpi_walk_state *walk_state)
400 goto cleanup; 394 goto cleanup;
401 } 395 }
402 396
403 /* Done with this result state (Now that operand stack is built) */
404
405 status = acpi_ds_result_stack_pop(walk_state);
406 if (ACPI_FAILURE(status)) {
407 goto cleanup;
408 }
409
410 /* 397 /*
411 * All opcodes require operand resolution, with the only exceptions 398 * All opcodes require operand resolution, with the only exceptions
412 * being the object_type and size_of operators. 399 * being the object_type and size_of operators.
@@ -487,16 +474,6 @@ acpi_status acpi_ds_exec_end_op(struct acpi_walk_state *walk_state)
487 474
488 status = acpi_ds_exec_end_control_op(walk_state, op); 475 status = acpi_ds_exec_end_control_op(walk_state, op);
489 476
490 /* Make sure to properly pop the result stack */
491
492 if (ACPI_SUCCESS(status)) {
493 status = acpi_ds_result_stack_pop(walk_state);
494 } else if (status == AE_CTRL_PENDING) {
495 status = acpi_ds_result_stack_pop(walk_state);
496 if (ACPI_SUCCESS(status)) {
497 status = AE_CTRL_PENDING;
498 }
499 }
500 break; 477 break;
501 478
502 case AML_TYPE_METHOD_CALL: 479 case AML_TYPE_METHOD_CALL:
@@ -516,7 +493,7 @@ acpi_status acpi_ds_exec_end_op(struct acpi_walk_state *walk_state)
516 493
517 op->common.node = 494 op->common.node =
518 (struct acpi_namespace_node *)op->asl.value. 495 (struct acpi_namespace_node *)op->asl.value.
519 arg->asl.node->object; 496 arg->asl.node;
520 acpi_ut_add_reference(op->asl.value.arg->asl. 497 acpi_ut_add_reference(op->asl.value.arg->asl.
521 node->object); 498 node->object);
522 return_ACPI_STATUS(AE_OK); 499 return_ACPI_STATUS(AE_OK);
@@ -632,13 +609,6 @@ acpi_status acpi_ds_exec_end_op(struct acpi_walk_state *walk_state)
632 break; 609 break;
633 } 610 }
634 611
635 /* Done with result state (Now that operand stack is built) */
636
637 status = acpi_ds_result_stack_pop(walk_state);
638 if (ACPI_FAILURE(status)) {
639 goto cleanup;
640 }
641
642 /* 612 /*
643 * If a result object was returned from above, push it on the 613 * If a result object was returned from above, push it on the
644 * current result stack 614 * current result stack
@@ -671,8 +641,28 @@ acpi_status acpi_ds_exec_end_op(struct acpi_walk_state *walk_state)
671 if (ACPI_FAILURE(status)) { 641 if (ACPI_FAILURE(status)) {
672 break; 642 break;
673 } 643 }
644 } else if (op->common.aml_opcode == AML_DATA_REGION_OP) {
645 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
646 "Executing DataTableRegion Strings Op=%p\n",
647 op));
648
649 status =
650 acpi_ds_eval_table_region_operands
651 (walk_state, op);
652 if (ACPI_FAILURE(status)) {
653 break;
654 }
655 } else if (op->common.aml_opcode == AML_BANK_FIELD_OP) {
656 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
657 "Executing BankField Op=%p\n",
658 op));
674 659
675 status = acpi_ds_result_stack_pop(walk_state); 660 status =
661 acpi_ds_eval_bank_field_operands(walk_state,
662 op);
663 if (ACPI_FAILURE(status)) {
664 break;
665 }
676 } 666 }
677 break; 667 break;
678 668
diff --git a/drivers/acpi/dispatcher/dswload.c b/drivers/acpi/dispatcher/dswload.c
index 8ab9d1b29a4c..dff7a3e445a8 100644
--- a/drivers/acpi/dispatcher/dswload.c
+++ b/drivers/acpi/dispatcher/dswload.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -443,6 +443,15 @@ acpi_status acpi_ds_load1_end_op(struct acpi_walk_state *walk_state)
443 if (ACPI_FAILURE(status)) { 443 if (ACPI_FAILURE(status)) {
444 return_ACPI_STATUS(status); 444 return_ACPI_STATUS(status);
445 } 445 }
446 } else if (op->common.aml_opcode == AML_DATA_REGION_OP) {
447 status =
448 acpi_ex_create_region(op->named.data,
449 op->named.length,
450 REGION_DATA_TABLE,
451 walk_state);
452 if (ACPI_FAILURE(status)) {
453 return_ACPI_STATUS(status);
454 }
446 } 455 }
447 } 456 }
448#endif 457#endif
@@ -767,6 +776,12 @@ acpi_ds_load2_begin_op(struct acpi_walk_state *walk_state,
767 acpi_ns_lookup(walk_state->scope_info, buffer_ptr, 776 acpi_ns_lookup(walk_state->scope_info, buffer_ptr,
768 object_type, ACPI_IMODE_LOAD_PASS2, flags, 777 object_type, ACPI_IMODE_LOAD_PASS2, flags,
769 walk_state, &node); 778 walk_state, &node);
779
780 if (ACPI_SUCCESS(status) && (flags & ACPI_NS_TEMPORARY)) {
781 ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
782 "***New Node [%4.4s] %p is temporary\n",
783 acpi_ut_get_node_name(node), node));
784 }
770 break; 785 break;
771 } 786 }
772 787
@@ -823,6 +838,7 @@ acpi_status acpi_ds_load2_end_op(struct acpi_walk_state *walk_state)
823 struct acpi_namespace_node *new_node; 838 struct acpi_namespace_node *new_node;
824#ifndef ACPI_NO_METHOD_EXECUTION 839#ifndef ACPI_NO_METHOD_EXECUTION
825 u32 i; 840 u32 i;
841 u8 region_space;
826#endif 842#endif
827 843
828 ACPI_FUNCTION_TRACE(ds_load2_end_op); 844 ACPI_FUNCTION_TRACE(ds_load2_end_op);
@@ -1003,11 +1019,6 @@ acpi_status acpi_ds_load2_end_op(struct acpi_walk_state *walk_state)
1003 status = acpi_ex_create_event(walk_state); 1019 status = acpi_ex_create_event(walk_state);
1004 break; 1020 break;
1005 1021
1006 case AML_DATA_REGION_OP:
1007
1008 status = acpi_ex_create_table_region(walk_state);
1009 break;
1010
1011 case AML_ALIAS_OP: 1022 case AML_ALIAS_OP:
1012 1023
1013 status = acpi_ex_create_alias(walk_state); 1024 status = acpi_ex_create_alias(walk_state);
@@ -1035,6 +1046,15 @@ acpi_status acpi_ds_load2_end_op(struct acpi_walk_state *walk_state)
1035 switch (op->common.aml_opcode) { 1046 switch (op->common.aml_opcode) {
1036#ifndef ACPI_NO_METHOD_EXECUTION 1047#ifndef ACPI_NO_METHOD_EXECUTION
1037 case AML_REGION_OP: 1048 case AML_REGION_OP:
1049 case AML_DATA_REGION_OP:
1050
1051 if (op->common.aml_opcode == AML_REGION_OP) {
1052 region_space = (acpi_adr_space_type)
1053 ((op->common.value.arg)->common.value.
1054 integer);
1055 } else {
1056 region_space = REGION_DATA_TABLE;
1057 }
1038 1058
1039 /* 1059 /*
1040 * If we are executing a method, initialize the region 1060 * If we are executing a method, initialize the region
@@ -1043,10 +1063,7 @@ acpi_status acpi_ds_load2_end_op(struct acpi_walk_state *walk_state)
1043 status = 1063 status =
1044 acpi_ex_create_region(op->named.data, 1064 acpi_ex_create_region(op->named.data,
1045 op->named.length, 1065 op->named.length,
1046 (acpi_adr_space_type) 1066 region_space,
1047 ((op->common.value.
1048 arg)->common.value.
1049 integer),
1050 walk_state); 1067 walk_state);
1051 if (ACPI_FAILURE(status)) { 1068 if (ACPI_FAILURE(status)) {
1052 return (status); 1069 return (status);
diff --git a/drivers/acpi/dispatcher/dswscope.c b/drivers/acpi/dispatcher/dswscope.c
index 3927c495e4bf..9e6073265873 100644
--- a/drivers/acpi/dispatcher/dswscope.c
+++ b/drivers/acpi/dispatcher/dswscope.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/dispatcher/dswstate.c b/drivers/acpi/dispatcher/dswstate.c
index 5afcdd9c7449..1386ced332ec 100644
--- a/drivers/acpi/dispatcher/dswstate.c
+++ b/drivers/acpi/dispatcher/dswstate.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -49,85 +49,9 @@
49#define _COMPONENT ACPI_DISPATCHER 49#define _COMPONENT ACPI_DISPATCHER
50ACPI_MODULE_NAME("dswstate") 50ACPI_MODULE_NAME("dswstate")
51 51
52/* Local prototypes */ 52 /* Local prototypes */
53#ifdef ACPI_OBSOLETE_FUNCTIONS 53static acpi_status acpi_ds_result_stack_push(struct acpi_walk_state *ws);
54acpi_status 54static acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state *ws);
55acpi_ds_result_insert(void *object,
56 u32 index, struct acpi_walk_state *walk_state);
57
58acpi_status acpi_ds_obj_stack_delete_all(struct acpi_walk_state *walk_state);
59
60acpi_status
61acpi_ds_obj_stack_pop_object(union acpi_operand_object **object,
62 struct acpi_walk_state *walk_state);
63
64void *acpi_ds_obj_stack_get_value(u32 index,
65 struct acpi_walk_state *walk_state);
66#endif
67
68#ifdef ACPI_FUTURE_USAGE
69/*******************************************************************************
70 *
71 * FUNCTION: acpi_ds_result_remove
72 *
73 * PARAMETERS: Object - Where to return the popped object
74 * Index - Where to extract the object
75 * walk_state - Current Walk state
76 *
77 * RETURN: Status
78 *
79 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
80 * other words, this is a FIFO.
81 *
82 ******************************************************************************/
83
84acpi_status
85acpi_ds_result_remove(union acpi_operand_object **object,
86 u32 index, struct acpi_walk_state *walk_state)
87{
88 union acpi_generic_state *state;
89
90 ACPI_FUNCTION_NAME(ds_result_remove);
91
92 state = walk_state->results;
93 if (!state) {
94 ACPI_ERROR((AE_INFO, "No result object pushed! State=%p",
95 walk_state));
96 return (AE_NOT_EXIST);
97 }
98
99 if (index >= ACPI_OBJ_MAX_OPERAND) {
100 ACPI_ERROR((AE_INFO,
101 "Index out of range: %X State=%p Num=%X",
102 index, walk_state, state->results.num_results));
103 }
104
105 /* Check for a valid result object */
106
107 if (!state->results.obj_desc[index]) {
108 ACPI_ERROR((AE_INFO,
109 "Null operand! State=%p #Ops=%X, Index=%X",
110 walk_state, state->results.num_results, index));
111 return (AE_AML_NO_RETURN_VALUE);
112 }
113
114 /* Remove the object */
115
116 state->results.num_results--;
117
118 *object = state->results.obj_desc[index];
119 state->results.obj_desc[index] = NULL;
120
121 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
122 "Obj=%p [%s] Index=%X State=%p Num=%X\n",
123 *object,
124 (*object) ? acpi_ut_get_object_type_name(*object) :
125 "NULL", index, walk_state,
126 state->results.num_results));
127
128 return (AE_OK);
129}
130#endif /* ACPI_FUTURE_USAGE */
131 55
132/******************************************************************************* 56/*******************************************************************************
133 * 57 *
@@ -138,122 +62,67 @@ acpi_ds_result_remove(union acpi_operand_object **object,
138 * 62 *
139 * RETURN: Status 63 * RETURN: Status
140 * 64 *
141 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In 65 * DESCRIPTION: Pop an object off the top of this walk's result stack
142 * other words, this is a FIFO.
143 * 66 *
144 ******************************************************************************/ 67 ******************************************************************************/
145 68
146acpi_status 69acpi_status
147acpi_ds_result_pop(union acpi_operand_object ** object, 70acpi_ds_result_pop(union acpi_operand_object **object,
148 struct acpi_walk_state * walk_state) 71 struct acpi_walk_state *walk_state)
149{ 72{
150 acpi_native_uint index; 73 acpi_native_uint index;
151 union acpi_generic_state *state; 74 union acpi_generic_state *state;
75 acpi_status status;
152 76
153 ACPI_FUNCTION_NAME(ds_result_pop); 77 ACPI_FUNCTION_NAME(ds_result_pop);
154 78
155 state = walk_state->results; 79 state = walk_state->results;
156 if (!state) {
157 return (AE_OK);
158 }
159
160 if (!state->results.num_results) {
161 ACPI_ERROR((AE_INFO, "Result stack is empty! State=%p",
162 walk_state));
163 return (AE_AML_NO_RETURN_VALUE);
164 }
165 80
166 /* Remove top element */ 81 /* Incorrect state of result stack */
167 82
168 state->results.num_results--; 83 if (state && !walk_state->result_count) {
169 84 ACPI_ERROR((AE_INFO, "No results on result stack"));
170 for (index = ACPI_OBJ_NUM_OPERANDS; index; index--) { 85 return (AE_AML_INTERNAL);
171
172 /* Check for a valid result object */
173
174 if (state->results.obj_desc[index - 1]) {
175 *object = state->results.obj_desc[index - 1];
176 state->results.obj_desc[index - 1] = NULL;
177
178 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
179 "Obj=%p [%s] Index=%X State=%p Num=%X\n",
180 *object,
181 (*object) ?
182 acpi_ut_get_object_type_name(*object)
183 : "NULL", (u32) index - 1, walk_state,
184 state->results.num_results));
185
186 return (AE_OK);
187 }
188 } 86 }
189 87
190 ACPI_ERROR((AE_INFO, "No result objects! State=%p", walk_state)); 88 if (!state && walk_state->result_count) {
191 return (AE_AML_NO_RETURN_VALUE); 89 ACPI_ERROR((AE_INFO, "No result state for result stack"));
192} 90 return (AE_AML_INTERNAL);
193 91 }
194/*******************************************************************************
195 *
196 * FUNCTION: acpi_ds_result_pop_from_bottom
197 *
198 * PARAMETERS: Object - Where to return the popped object
199 * walk_state - Current Walk state
200 *
201 * RETURN: Status
202 *
203 * DESCRIPTION: Pop an object off the bottom of this walk's result stack. In
204 * other words, this is a FIFO.
205 *
206 ******************************************************************************/
207
208acpi_status
209acpi_ds_result_pop_from_bottom(union acpi_operand_object ** object,
210 struct acpi_walk_state * walk_state)
211{
212 acpi_native_uint index;
213 union acpi_generic_state *state;
214 92
215 ACPI_FUNCTION_NAME(ds_result_pop_from_bottom); 93 /* Empty result stack */
216 94
217 state = walk_state->results;
218 if (!state) { 95 if (!state) {
219 ACPI_ERROR((AE_INFO, 96 ACPI_ERROR((AE_INFO, "Result stack is empty! State=%p",
220 "No result object pushed! State=%p", walk_state));
221 return (AE_NOT_EXIST);
222 }
223
224 if (!state->results.num_results) {
225 ACPI_ERROR((AE_INFO, "No result objects! State=%p",
226 walk_state)); 97 walk_state));
227 return (AE_AML_NO_RETURN_VALUE); 98 return (AE_AML_NO_RETURN_VALUE);
228 } 99 }
229 100
230 /* Remove Bottom element */ 101 /* Return object of the top element and clean that top element result stack */
231
232 *object = state->results.obj_desc[0];
233
234 /* Push entire stack down one element */
235
236 for (index = 0; index < state->results.num_results; index++) {
237 state->results.obj_desc[index] =
238 state->results.obj_desc[index + 1];
239 }
240 102
241 state->results.num_results--; 103 walk_state->result_count--;
242 104 index = walk_state->result_count % ACPI_RESULTS_FRAME_OBJ_NUM;
243 /* Check for a valid result object */
244 105
106 *object = state->results.obj_desc[index];
245 if (!*object) { 107 if (!*object) {
246 ACPI_ERROR((AE_INFO, 108 ACPI_ERROR((AE_INFO,
247 "Null operand! State=%p #Ops=%X Index=%X", 109 "No result objects on result stack, State=%p",
248 walk_state, state->results.num_results, 110 walk_state));
249 (u32) index));
250 return (AE_AML_NO_RETURN_VALUE); 111 return (AE_AML_NO_RETURN_VALUE);
251 } 112 }
252 113
253 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] Results=%p State=%p\n", 114 state->results.obj_desc[index] = NULL;
254 *object, 115 if (index == 0) {
255 (*object) ? acpi_ut_get_object_type_name(*object) : 116 status = acpi_ds_result_stack_pop(walk_state);
256 "NULL", state, walk_state)); 117 if (ACPI_FAILURE(status)) {
118 return (status);
119 }
120 }
121
122 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
123 "Obj=%p [%s] Index=%X State=%p Num=%X\n", *object,
124 acpi_ut_get_object_type_name(*object),
125 (u32) index, walk_state, walk_state->result_count));
257 126
258 return (AE_OK); 127 return (AE_OK);
259} 128}
@@ -276,39 +145,56 @@ acpi_ds_result_push(union acpi_operand_object * object,
276 struct acpi_walk_state * walk_state) 145 struct acpi_walk_state * walk_state)
277{ 146{
278 union acpi_generic_state *state; 147 union acpi_generic_state *state;
148 acpi_status status;
149 acpi_native_uint index;
279 150
280 ACPI_FUNCTION_NAME(ds_result_push); 151 ACPI_FUNCTION_NAME(ds_result_push);
281 152
153 if (walk_state->result_count > walk_state->result_size) {
154 ACPI_ERROR((AE_INFO, "Result stack is full"));
155 return (AE_AML_INTERNAL);
156 } else if (walk_state->result_count == walk_state->result_size) {
157
158 /* Extend the result stack */
159
160 status = acpi_ds_result_stack_push(walk_state);
161 if (ACPI_FAILURE(status)) {
162 ACPI_ERROR((AE_INFO,
163 "Failed to extend the result stack"));
164 return (status);
165 }
166 }
167
168 if (!(walk_state->result_count < walk_state->result_size)) {
169 ACPI_ERROR((AE_INFO, "No free elements in result stack"));
170 return (AE_AML_INTERNAL);
171 }
172
282 state = walk_state->results; 173 state = walk_state->results;
283 if (!state) { 174 if (!state) {
284 ACPI_ERROR((AE_INFO, "No result stack frame during push")); 175 ACPI_ERROR((AE_INFO, "No result stack frame during push"));
285 return (AE_AML_INTERNAL); 176 return (AE_AML_INTERNAL);
286 } 177 }
287 178
288 if (state->results.num_results == ACPI_OBJ_NUM_OPERANDS) {
289 ACPI_ERROR((AE_INFO,
290 "Result stack overflow: Obj=%p State=%p Num=%X",
291 object, walk_state, state->results.num_results));
292 return (AE_STACK_OVERFLOW);
293 }
294
295 if (!object) { 179 if (!object) {
296 ACPI_ERROR((AE_INFO, 180 ACPI_ERROR((AE_INFO,
297 "Null Object! Obj=%p State=%p Num=%X", 181 "Null Object! Obj=%p State=%p Num=%X",
298 object, walk_state, state->results.num_results)); 182 object, walk_state, walk_state->result_count));
299 return (AE_BAD_PARAMETER); 183 return (AE_BAD_PARAMETER);
300 } 184 }
301 185
302 state->results.obj_desc[state->results.num_results] = object; 186 /* Assign the address of object to the top free element of result stack */
303 state->results.num_results++; 187
188 index = walk_state->result_count % ACPI_RESULTS_FRAME_OBJ_NUM;
189 state->results.obj_desc[index] = object;
190 walk_state->result_count++;
304 191
305 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n", 192 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
306 object, 193 object,
307 object ?
308 acpi_ut_get_object_type_name((union 194 acpi_ut_get_object_type_name((union
309 acpi_operand_object *) 195 acpi_operand_object *)
310 object) : "NULL", 196 object), walk_state,
311 walk_state, state->results.num_results, 197 walk_state->result_count,
312 walk_state->current_result)); 198 walk_state->current_result));
313 199
314 return (AE_OK); 200 return (AE_OK);
@@ -322,16 +208,25 @@ acpi_ds_result_push(union acpi_operand_object * object,
322 * 208 *
323 * RETURN: Status 209 * RETURN: Status
324 * 210 *
325 * DESCRIPTION: Push an object onto the walk_state result stack. 211 * DESCRIPTION: Push an object onto the walk_state result stack
326 * 212 *
327 ******************************************************************************/ 213 ******************************************************************************/
328 214
329acpi_status acpi_ds_result_stack_push(struct acpi_walk_state * walk_state) 215static acpi_status acpi_ds_result_stack_push(struct acpi_walk_state *walk_state)
330{ 216{
331 union acpi_generic_state *state; 217 union acpi_generic_state *state;
332 218
333 ACPI_FUNCTION_NAME(ds_result_stack_push); 219 ACPI_FUNCTION_NAME(ds_result_stack_push);
334 220
221 /* Check for stack overflow */
222
223 if (((u32) walk_state->result_size + ACPI_RESULTS_FRAME_OBJ_NUM) >
224 ACPI_RESULTS_OBJ_NUM_MAX) {
225 ACPI_ERROR((AE_INFO, "Result stack overflow: State=%p Num=%X",
226 walk_state, walk_state->result_size));
227 return (AE_STACK_OVERFLOW);
228 }
229
335 state = acpi_ut_create_generic_state(); 230 state = acpi_ut_create_generic_state();
336 if (!state) { 231 if (!state) {
337 return (AE_NO_MEMORY); 232 return (AE_NO_MEMORY);
@@ -340,6 +235,10 @@ acpi_status acpi_ds_result_stack_push(struct acpi_walk_state * walk_state)
340 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_RESULT; 235 state->common.descriptor_type = ACPI_DESC_TYPE_STATE_RESULT;
341 acpi_ut_push_generic_state(&walk_state->results, state); 236 acpi_ut_push_generic_state(&walk_state->results, state);
342 237
238 /* Increase the length of the result stack by the length of frame */
239
240 walk_state->result_size += ACPI_RESULTS_FRAME_OBJ_NUM;
241
343 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Results=%p State=%p\n", 242 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Results=%p State=%p\n",
344 state, walk_state)); 243 state, walk_state));
345 244
@@ -354,11 +253,11 @@ acpi_status acpi_ds_result_stack_push(struct acpi_walk_state * walk_state)
354 * 253 *
355 * RETURN: Status 254 * RETURN: Status
356 * 255 *
357 * DESCRIPTION: Pop an object off of the walk_state result stack. 256 * DESCRIPTION: Pop an object off of the walk_state result stack
358 * 257 *
359 ******************************************************************************/ 258 ******************************************************************************/
360 259
361acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state * walk_state) 260static acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state *walk_state)
362{ 261{
363 union acpi_generic_state *state; 262 union acpi_generic_state *state;
364 263
@@ -367,18 +266,27 @@ acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state * walk_state)
367 /* Check for stack underflow */ 266 /* Check for stack underflow */
368 267
369 if (walk_state->results == NULL) { 268 if (walk_state->results == NULL) {
370 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Underflow - State=%p\n", 269 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
270 "Result stack underflow - State=%p\n",
371 walk_state)); 271 walk_state));
372 return (AE_AML_NO_OPERAND); 272 return (AE_AML_NO_OPERAND);
373 } 273 }
374 274
275 if (walk_state->result_size < ACPI_RESULTS_FRAME_OBJ_NUM) {
276 ACPI_ERROR((AE_INFO, "Insufficient result stack size"));
277 return (AE_AML_INTERNAL);
278 }
279
375 state = acpi_ut_pop_generic_state(&walk_state->results); 280 state = acpi_ut_pop_generic_state(&walk_state->results);
281 acpi_ut_delete_generic_state(state);
282
283 /* Decrease the length of result stack by the length of frame */
284
285 walk_state->result_size -= ACPI_RESULTS_FRAME_OBJ_NUM;
376 286
377 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, 287 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
378 "Result=%p RemainingResults=%X State=%p\n", 288 "Result=%p RemainingResults=%X State=%p\n",
379 state, state->results.num_results, walk_state)); 289 state, walk_state->result_count, walk_state));
380
381 acpi_ut_delete_generic_state(state);
382 290
383 return (AE_OK); 291 return (AE_OK);
384} 292}
@@ -412,9 +320,13 @@ acpi_ds_obj_stack_push(void *object, struct acpi_walk_state * walk_state)
412 320
413 /* Put the object onto the stack */ 321 /* Put the object onto the stack */
414 322
415 walk_state->operands[walk_state->num_operands] = object; 323 walk_state->operands[walk_state->operand_index] = object;
416 walk_state->num_operands++; 324 walk_state->num_operands++;
417 325
326 /* For the usual order of filling the operand stack */
327
328 walk_state->operand_index++;
329
418 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n", 330 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
419 object, 331 object,
420 acpi_ut_get_object_type_name((union 332 acpi_ut_get_object_type_name((union
@@ -484,43 +396,36 @@ acpi_ds_obj_stack_pop(u32 pop_count, struct acpi_walk_state * walk_state)
484 * 396 *
485 ******************************************************************************/ 397 ******************************************************************************/
486 398
487acpi_status 399void
488acpi_ds_obj_stack_pop_and_delete(u32 pop_count, 400acpi_ds_obj_stack_pop_and_delete(u32 pop_count,
489 struct acpi_walk_state * walk_state) 401 struct acpi_walk_state *walk_state)
490{ 402{
491 u32 i; 403 acpi_native_int i;
492 union acpi_operand_object *obj_desc; 404 union acpi_operand_object *obj_desc;
493 405
494 ACPI_FUNCTION_NAME(ds_obj_stack_pop_and_delete); 406 ACPI_FUNCTION_NAME(ds_obj_stack_pop_and_delete);
495 407
496 for (i = 0; i < pop_count; i++) { 408 if (pop_count == 0) {
497 409 return;
498 /* Check for stack underflow */ 410 }
499 411
412 for (i = (acpi_native_int) (pop_count - 1); i >= 0; i--) {
500 if (walk_state->num_operands == 0) { 413 if (walk_state->num_operands == 0) {
501 ACPI_ERROR((AE_INFO, 414 return;
502 "Object stack underflow! Count=%X State=%p #Ops=%X",
503 pop_count, walk_state,
504 walk_state->num_operands));
505 return (AE_STACK_UNDERFLOW);
506 } 415 }
507 416
508 /* Pop the stack and delete an object if present in this stack entry */ 417 /* Pop the stack and delete an object if present in this stack entry */
509 418
510 walk_state->num_operands--; 419 walk_state->num_operands--;
511 obj_desc = walk_state->operands[walk_state->num_operands]; 420 obj_desc = walk_state->operands[i];
512 if (obj_desc) { 421 if (obj_desc) {
513 acpi_ut_remove_reference(walk_state-> 422 acpi_ut_remove_reference(walk_state->operands[i]);
514 operands[walk_state-> 423 walk_state->operands[i] = NULL;
515 num_operands]);
516 walk_state->operands[walk_state->num_operands] = NULL;
517 } 424 }
518 } 425 }
519 426
520 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n", 427 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
521 pop_count, walk_state, walk_state->num_operands)); 428 pop_count, walk_state, walk_state->num_operands));
522
523 return (AE_OK);
524} 429}
525 430
526/******************************************************************************* 431/*******************************************************************************
@@ -560,7 +465,7 @@ struct acpi_walk_state *acpi_ds_get_current_walk_state(struct acpi_thread_state
560 * 465 *
561 * RETURN: None 466 * RETURN: None
562 * 467 *
563 * DESCRIPTION: Place the Thread state at the head of the state list. 468 * DESCRIPTION: Place the Thread state at the head of the state list
564 * 469 *
565 ******************************************************************************/ 470 ******************************************************************************/
566 471
@@ -636,7 +541,6 @@ struct acpi_walk_state *acpi_ds_create_walk_state(acpi_owner_id owner_id, union
636 *thread) 541 *thread)
637{ 542{
638 struct acpi_walk_state *walk_state; 543 struct acpi_walk_state *walk_state;
639 acpi_status status;
640 544
641 ACPI_FUNCTION_TRACE(ds_create_walk_state); 545 ACPI_FUNCTION_TRACE(ds_create_walk_state);
642 546
@@ -659,14 +563,6 @@ struct acpi_walk_state *acpi_ds_create_walk_state(acpi_owner_id owner_id, union
659 acpi_ds_method_data_init(walk_state); 563 acpi_ds_method_data_init(walk_state);
660#endif 564#endif
661 565
662 /* Create an initial result stack entry */
663
664 status = acpi_ds_result_stack_push(walk_state);
665 if (ACPI_FAILURE(status)) {
666 ACPI_FREE(walk_state);
667 return_PTR(NULL);
668 }
669
670 /* Put the new state at the head of the walk list */ 566 /* Put the new state at the head of the walk list */
671 567
672 if (thread) { 568 if (thread) {
@@ -860,190 +756,3 @@ void acpi_ds_delete_walk_state(struct acpi_walk_state *walk_state)
860 ACPI_FREE(walk_state); 756 ACPI_FREE(walk_state);
861 return_VOID; 757 return_VOID;
862} 758}
863
864#ifdef ACPI_OBSOLETE_FUNCTIONS
865/*******************************************************************************
866 *
867 * FUNCTION: acpi_ds_result_insert
868 *
869 * PARAMETERS: Object - Object to push
870 * Index - Where to insert the object
871 * walk_state - Current Walk state
872 *
873 * RETURN: Status
874 *
875 * DESCRIPTION: Insert an object onto this walk's result stack
876 *
877 ******************************************************************************/
878
879acpi_status
880acpi_ds_result_insert(void *object,
881 u32 index, struct acpi_walk_state *walk_state)
882{
883 union acpi_generic_state *state;
884
885 ACPI_FUNCTION_NAME(ds_result_insert);
886
887 state = walk_state->results;
888 if (!state) {
889 ACPI_ERROR((AE_INFO, "No result object pushed! State=%p",
890 walk_state));
891 return (AE_NOT_EXIST);
892 }
893
894 if (index >= ACPI_OBJ_NUM_OPERANDS) {
895 ACPI_ERROR((AE_INFO,
896 "Index out of range: %X Obj=%p State=%p Num=%X",
897 index, object, walk_state,
898 state->results.num_results));
899 return (AE_BAD_PARAMETER);
900 }
901
902 if (!object) {
903 ACPI_ERROR((AE_INFO,
904 "Null Object! Index=%X Obj=%p State=%p Num=%X",
905 index, object, walk_state,
906 state->results.num_results));
907 return (AE_BAD_PARAMETER);
908 }
909
910 state->results.obj_desc[index] = object;
911 state->results.num_results++;
912
913 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
914 "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
915 object,
916 object ?
917 acpi_ut_get_object_type_name((union
918 acpi_operand_object *)
919 object) : "NULL",
920 walk_state, state->results.num_results,
921 walk_state->current_result));
922
923 return (AE_OK);
924}
925
926/*******************************************************************************
927 *
928 * FUNCTION: acpi_ds_obj_stack_delete_all
929 *
930 * PARAMETERS: walk_state - Current Walk state
931 *
932 * RETURN: Status
933 *
934 * DESCRIPTION: Clear the object stack by deleting all objects that are on it.
935 * Should be used with great care, if at all!
936 *
937 ******************************************************************************/
938
939acpi_status acpi_ds_obj_stack_delete_all(struct acpi_walk_state * walk_state)
940{
941 u32 i;
942
943 ACPI_FUNCTION_TRACE_PTR(ds_obj_stack_delete_all, walk_state);
944
945 /* The stack size is configurable, but fixed */
946
947 for (i = 0; i < ACPI_OBJ_NUM_OPERANDS; i++) {
948 if (walk_state->operands[i]) {
949 acpi_ut_remove_reference(walk_state->operands[i]);
950 walk_state->operands[i] = NULL;
951 }
952 }
953
954 return_ACPI_STATUS(AE_OK);
955}
956
957/*******************************************************************************
958 *
959 * FUNCTION: acpi_ds_obj_stack_pop_object
960 *
961 * PARAMETERS: Object - Where to return the popped object
962 * walk_state - Current Walk state
963 *
964 * RETURN: Status
965 *
966 * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
967 * deleted by this routine.
968 *
969 ******************************************************************************/
970
971acpi_status
972acpi_ds_obj_stack_pop_object(union acpi_operand_object **object,
973 struct acpi_walk_state *walk_state)
974{
975 ACPI_FUNCTION_NAME(ds_obj_stack_pop_object);
976
977 /* Check for stack underflow */
978
979 if (walk_state->num_operands == 0) {
980 ACPI_ERROR((AE_INFO,
981 "Missing operand/stack empty! State=%p #Ops=%X",
982 walk_state, walk_state->num_operands));
983 *object = NULL;
984 return (AE_AML_NO_OPERAND);
985 }
986
987 /* Pop the stack */
988
989 walk_state->num_operands--;
990
991 /* Check for a valid operand */
992
993 if (!walk_state->operands[walk_state->num_operands]) {
994 ACPI_ERROR((AE_INFO,
995 "Null operand! State=%p #Ops=%X",
996 walk_state, walk_state->num_operands));
997 *object = NULL;
998 return (AE_AML_NO_OPERAND);
999 }
1000
1001 /* Get operand and set stack entry to null */
1002
1003 *object = walk_state->operands[walk_state->num_operands];
1004 walk_state->operands[walk_state->num_operands] = NULL;
1005
1006 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
1007 *object, acpi_ut_get_object_type_name(*object),
1008 walk_state, walk_state->num_operands));
1009
1010 return (AE_OK);
1011}
1012
1013/*******************************************************************************
1014 *
1015 * FUNCTION: acpi_ds_obj_stack_get_value
1016 *
1017 * PARAMETERS: Index - Stack index whose value is desired. Based
1018 * on the top of the stack (index=0 == top)
1019 * walk_state - Current Walk state
1020 *
1021 * RETURN: Pointer to the requested operand
1022 *
1023 * DESCRIPTION: Retrieve an object from this walk's operand stack. Index must
1024 * be within the range of the current stack pointer.
1025 *
1026 ******************************************************************************/
1027
1028void *acpi_ds_obj_stack_get_value(u32 index, struct acpi_walk_state *walk_state)
1029{
1030
1031 ACPI_FUNCTION_TRACE_PTR(ds_obj_stack_get_value, walk_state);
1032
1033 /* Can't do it if the stack is empty */
1034
1035 if (walk_state->num_operands == 0) {
1036 return_PTR(NULL);
1037 }
1038
1039 /* or if the index is past the top of the stack */
1040
1041 if (index > (walk_state->num_operands - (u32) 1)) {
1042 return_PTR(NULL);
1043 }
1044
1045 return_PTR(walk_state->
1046 operands[(acpi_native_uint) (walk_state->num_operands - 1) -
1047 index]);
1048}
1049#endif
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index e3f04b272f3f..0924992187e8 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -73,38 +73,14 @@ enum ec_event {
73 73
74#define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */ 74#define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */
75#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */ 75#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
76#define ACPI_EC_UDELAY 100 /* Wait 100us before polling EC again */
76 77
77enum { 78enum {
78 EC_FLAGS_WAIT_GPE = 0, /* Don't check status until GPE arrives */ 79 EC_FLAGS_WAIT_GPE = 0, /* Don't check status until GPE arrives */
79 EC_FLAGS_QUERY_PENDING, /* Query is pending */ 80 EC_FLAGS_QUERY_PENDING, /* Query is pending */
80 EC_FLAGS_GPE_MODE, /* Expect GPE to be sent for status change */ 81 EC_FLAGS_GPE_MODE, /* Expect GPE to be sent for status change */
81 EC_FLAGS_NO_ADDRESS_GPE, /* Expect GPE only for non-address event */ 82 EC_FLAGS_NO_GPE, /* Don't use GPE mode */
82 EC_FLAGS_ADDRESS, /* Address is being written */ 83 EC_FLAGS_RESCHEDULE_POLL /* Re-schedule poll */
83 EC_FLAGS_NO_WDATA_GPE, /* Don't expect WDATA GPE event */
84 EC_FLAGS_WDATA, /* Data is being written */
85 EC_FLAGS_NO_OBF1_GPE, /* Don't expect GPE before read */
86};
87
88static int acpi_ec_remove(struct acpi_device *device, int type);
89static int acpi_ec_start(struct acpi_device *device);
90static int acpi_ec_stop(struct acpi_device *device, int type);
91static int acpi_ec_add(struct acpi_device *device);
92
93static const struct acpi_device_id ec_device_ids[] = {
94 {"PNP0C09", 0},
95 {"", 0},
96};
97
98static struct acpi_driver acpi_ec_driver = {
99 .name = "ec",
100 .class = ACPI_EC_CLASS,
101 .ids = ec_device_ids,
102 .ops = {
103 .add = acpi_ec_add,
104 .remove = acpi_ec_remove,
105 .start = acpi_ec_start,
106 .stop = acpi_ec_stop,
107 },
108}; 84};
109 85
110/* If we find an EC via the ECDT, we need to keep a ptr to its context */ 86/* If we find an EC via the ECDT, we need to keep a ptr to its context */
@@ -129,6 +105,8 @@ static struct acpi_ec {
129 struct mutex lock; 105 struct mutex lock;
130 wait_queue_head_t wait; 106 wait_queue_head_t wait;
131 struct list_head list; 107 struct list_head list;
108 struct delayed_work work;
109 atomic_t irq_count;
132 u8 handlers_installed; 110 u8 handlers_installed;
133} *boot_ec, *first_ec; 111} *boot_ec, *first_ec;
134 112
@@ -177,65 +155,52 @@ static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event)
177 return 0; 155 return 0;
178} 156}
179 157
180static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, int force_poll) 158static void ec_schedule_ec_poll(struct acpi_ec *ec)
181{ 159{
182 int ret = 0; 160 if (test_bit(EC_FLAGS_RESCHEDULE_POLL, &ec->flags))
161 schedule_delayed_work(&ec->work,
162 msecs_to_jiffies(ACPI_EC_DELAY));
163}
183 164
184 if (unlikely(event == ACPI_EC_EVENT_OBF_1 && 165static void ec_switch_to_poll_mode(struct acpi_ec *ec)
185 test_bit(EC_FLAGS_NO_OBF1_GPE, &ec->flags))) 166{
186 force_poll = 1; 167 set_bit(EC_FLAGS_NO_GPE, &ec->flags);
187 if (unlikely(test_bit(EC_FLAGS_ADDRESS, &ec->flags) && 168 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags);
188 test_bit(EC_FLAGS_NO_ADDRESS_GPE, &ec->flags))) 169 acpi_disable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
189 force_poll = 1; 170 set_bit(EC_FLAGS_RESCHEDULE_POLL, &ec->flags);
190 if (unlikely(test_bit(EC_FLAGS_WDATA, &ec->flags) && 171}
191 test_bit(EC_FLAGS_NO_WDATA_GPE, &ec->flags))) 172
192 force_poll = 1; 173static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, int force_poll)
174{
175 atomic_set(&ec->irq_count, 0);
193 if (likely(test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) && 176 if (likely(test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) &&
194 likely(!force_poll)) { 177 likely(!force_poll)) {
195 if (wait_event_timeout(ec->wait, acpi_ec_check_status(ec, event), 178 if (wait_event_timeout(ec->wait, acpi_ec_check_status(ec, event),
196 msecs_to_jiffies(ACPI_EC_DELAY))) 179 msecs_to_jiffies(ACPI_EC_DELAY)))
197 goto end; 180 return 0;
198 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags); 181 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
199 if (acpi_ec_check_status(ec, event)) { 182 if (acpi_ec_check_status(ec, event)) {
200 if (event == ACPI_EC_EVENT_OBF_1) { 183 /* missing GPEs, switch back to poll mode */
201 /* miss OBF_1 GPE, don't expect it */ 184 if (printk_ratelimit())
202 pr_info(PREFIX "missing OBF confirmation, " 185 pr_info(PREFIX "missing confirmations, "
203 "don't expect it any longer.\n");
204 set_bit(EC_FLAGS_NO_OBF1_GPE, &ec->flags);
205 } else if (test_bit(EC_FLAGS_ADDRESS, &ec->flags)) {
206 /* miss address GPE, don't expect it anymore */
207 pr_info(PREFIX "missing address confirmation, "
208 "don't expect it any longer.\n");
209 set_bit(EC_FLAGS_NO_ADDRESS_GPE, &ec->flags);
210 } else if (test_bit(EC_FLAGS_WDATA, &ec->flags)) {
211 /* miss write data GPE, don't expect it */
212 pr_info(PREFIX "missing write data confirmation, "
213 "don't expect it any longer.\n");
214 set_bit(EC_FLAGS_NO_WDATA_GPE, &ec->flags);
215 } else {
216 /* missing GPEs, switch back to poll mode */
217 if (printk_ratelimit())
218 pr_info(PREFIX "missing confirmations, "
219 "switch off interrupt mode.\n"); 186 "switch off interrupt mode.\n");
220 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags); 187 ec_switch_to_poll_mode(ec);
221 } 188 ec_schedule_ec_poll(ec);
222 goto end; 189 return 0;
223 } 190 }
224 } else { 191 } else {
225 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY); 192 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
226 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags); 193 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
227 while (time_before(jiffies, delay)) { 194 while (time_before(jiffies, delay)) {
228 if (acpi_ec_check_status(ec, event)) 195 if (acpi_ec_check_status(ec, event))
229 goto end; 196 return 0;
197 udelay(ACPI_EC_UDELAY);
230 } 198 }
231 } 199 }
232 pr_err(PREFIX "acpi_ec_wait timeout," 200 pr_err(PREFIX "acpi_ec_wait timeout, status = 0x%2.2x, event = %s\n",
233 " status = %d, expect_event = %d\n", 201 acpi_ec_read_status(ec),
234 acpi_ec_read_status(ec), event); 202 (event == ACPI_EC_EVENT_OBF_1) ? "\"b0=1\"" : "\"b1=0\"");
235 ret = -ETIME; 203 return -ETIME;
236 end:
237 clear_bit(EC_FLAGS_ADDRESS, &ec->flags);
238 return ret;
239} 204}
240 205
241static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command, 206static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
@@ -245,8 +210,8 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
245{ 210{
246 int result = 0; 211 int result = 0;
247 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags); 212 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
248 acpi_ec_write_cmd(ec, command);
249 pr_debug(PREFIX "transaction start\n"); 213 pr_debug(PREFIX "transaction start\n");
214 acpi_ec_write_cmd(ec, command);
250 for (; wdata_len > 0; --wdata_len) { 215 for (; wdata_len > 0; --wdata_len) {
251 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll); 216 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll);
252 if (result) { 217 if (result) {
@@ -254,15 +219,11 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
254 "write_cmd timeout, command = %d\n", command); 219 "write_cmd timeout, command = %d\n", command);
255 goto end; 220 goto end;
256 } 221 }
257 /* mark the address byte written to EC */
258 if (rdata_len + wdata_len > 1)
259 set_bit(EC_FLAGS_ADDRESS, &ec->flags);
260 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags); 222 set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
261 acpi_ec_write_data(ec, *(wdata++)); 223 acpi_ec_write_data(ec, *(wdata++));
262 } 224 }
263 225
264 if (!rdata_len) { 226 if (!rdata_len) {
265 set_bit(EC_FLAGS_WDATA, &ec->flags);
266 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll); 227 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll);
267 if (result) { 228 if (result) {
268 pr_err(PREFIX 229 pr_err(PREFIX
@@ -527,47 +488,51 @@ static u32 acpi_ec_gpe_handler(void *data)
527{ 488{
528 acpi_status status = AE_OK; 489 acpi_status status = AE_OK;
529 struct acpi_ec *ec = data; 490 struct acpi_ec *ec = data;
491 u8 state = acpi_ec_read_status(ec);
530 492
531 pr_debug(PREFIX "~~~> interrupt\n"); 493 pr_debug(PREFIX "~~~> interrupt\n");
494 atomic_inc(&ec->irq_count);
495 if (atomic_read(&ec->irq_count) > 5) {
496 pr_err(PREFIX "GPE storm detected, disabling EC GPE\n");
497 ec_switch_to_poll_mode(ec);
498 goto end;
499 }
532 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags); 500 clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
533 if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags)) 501 if (test_bit(EC_FLAGS_GPE_MODE, &ec->flags))
534 wake_up(&ec->wait); 502 wake_up(&ec->wait);
535 503
536 if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_SCI) { 504 if (state & ACPI_EC_FLAG_SCI) {
537 if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) 505 if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags))
538 status = acpi_os_execute(OSL_EC_BURST_HANDLER, 506 status = acpi_os_execute(OSL_EC_BURST_HANDLER,
539 acpi_ec_gpe_query, ec); 507 acpi_ec_gpe_query, ec);
540 } else if (unlikely(!test_bit(EC_FLAGS_GPE_MODE, &ec->flags))) { 508 } else if (!test_bit(EC_FLAGS_GPE_MODE, &ec->flags) &&
509 !test_bit(EC_FLAGS_NO_GPE, &ec->flags) &&
510 in_interrupt()) {
541 /* this is non-query, must be confirmation */ 511 /* this is non-query, must be confirmation */
542 if (printk_ratelimit()) 512 if (printk_ratelimit())
543 pr_info(PREFIX "non-query interrupt received," 513 pr_info(PREFIX "non-query interrupt received,"
544 " switching to interrupt mode\n"); 514 " switching to interrupt mode\n");
545 set_bit(EC_FLAGS_GPE_MODE, &ec->flags); 515 set_bit(EC_FLAGS_GPE_MODE, &ec->flags);
516 clear_bit(EC_FLAGS_RESCHEDULE_POLL, &ec->flags);
546 } 517 }
547 518end:
519 ec_schedule_ec_poll(ec);
548 return ACPI_SUCCESS(status) ? 520 return ACPI_SUCCESS(status) ?
549 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; 521 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
550} 522}
551 523
524static void do_ec_poll(struct work_struct *work)
525{
526 struct acpi_ec *ec = container_of(work, struct acpi_ec, work.work);
527 atomic_set(&ec->irq_count, 0);
528 (void)acpi_ec_gpe_handler(ec);
529}
530
552/* -------------------------------------------------------------------------- 531/* --------------------------------------------------------------------------
553 Address Space Management 532 Address Space Management
554 -------------------------------------------------------------------------- */ 533 -------------------------------------------------------------------------- */
555 534
556static acpi_status 535static acpi_status
557acpi_ec_space_setup(acpi_handle region_handle,
558 u32 function, void *handler_context, void **return_context)
559{
560 /*
561 * The EC object is in the handler context and is needed
562 * when calling the acpi_ec_space_handler.
563 */
564 *return_context = (function != ACPI_REGION_DEACTIVATE) ?
565 handler_context : NULL;
566
567 return AE_OK;
568}
569
570static acpi_status
571acpi_ec_space_handler(u32 function, acpi_physical_address address, 536acpi_ec_space_handler(u32 function, acpi_physical_address address,
572 u32 bits, acpi_integer *value, 537 u32 bits, acpi_integer *value,
573 void *handler_context, void *region_context) 538 void *handler_context, void *region_context)
@@ -704,6 +669,8 @@ static struct acpi_ec *make_acpi_ec(void)
704 mutex_init(&ec->lock); 669 mutex_init(&ec->lock);
705 init_waitqueue_head(&ec->wait); 670 init_waitqueue_head(&ec->wait);
706 INIT_LIST_HEAD(&ec->list); 671 INIT_LIST_HEAD(&ec->list);
672 INIT_DELAYED_WORK_DEFERRABLE(&ec->work, do_ec_poll);
673 atomic_set(&ec->irq_count, 0);
707 return ec; 674 return ec;
708} 675}
709 676
@@ -736,17 +703,21 @@ ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval)
736 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec->gpe); 703 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec->gpe);
737 if (ACPI_FAILURE(status)) 704 if (ACPI_FAILURE(status))
738 return status; 705 return status;
739 /* Find and register all query methods */
740 acpi_walk_namespace(ACPI_TYPE_METHOD, handle, 1,
741 acpi_ec_register_query_methods, ec, NULL);
742 /* Use the global lock for all EC transactions? */ 706 /* Use the global lock for all EC transactions? */
743 acpi_evaluate_integer(handle, "_GLK", NULL, &ec->global_lock); 707 acpi_evaluate_integer(handle, "_GLK", NULL, &ec->global_lock);
744 ec->handle = handle; 708 ec->handle = handle;
745 return AE_CTRL_TERMINATE; 709 return AE_CTRL_TERMINATE;
746} 710}
747 711
712static void ec_poll_stop(struct acpi_ec *ec)
713{
714 clear_bit(EC_FLAGS_RESCHEDULE_POLL, &ec->flags);
715 cancel_delayed_work(&ec->work);
716}
717
748static void ec_remove_handlers(struct acpi_ec *ec) 718static void ec_remove_handlers(struct acpi_ec *ec)
749{ 719{
720 ec_poll_stop(ec);
750 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle, 721 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle,
751 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler))) 722 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler)))
752 pr_err(PREFIX "failed to remove space handler\n"); 723 pr_err(PREFIX "failed to remove space handler\n");
@@ -766,31 +737,28 @@ static int acpi_ec_add(struct acpi_device *device)
766 strcpy(acpi_device_class(device), ACPI_EC_CLASS); 737 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
767 738
768 /* Check for boot EC */ 739 /* Check for boot EC */
769 if (boot_ec) { 740 if (boot_ec &&
770 if (boot_ec->handle == device->handle) { 741 (boot_ec->handle == device->handle ||
771 /* Pre-loaded EC from DSDT, just move pointer */ 742 boot_ec->handle == ACPI_ROOT_OBJECT)) {
772 ec = boot_ec; 743 ec = boot_ec;
773 boot_ec = NULL; 744 boot_ec = NULL;
774 goto end; 745 } else {
775 } else if (boot_ec->handle == ACPI_ROOT_OBJECT) { 746 ec = make_acpi_ec();
776 /* ECDT-based EC, time to shut it down */ 747 if (!ec)
777 ec_remove_handlers(boot_ec); 748 return -ENOMEM;
778 kfree(boot_ec); 749 if (ec_parse_device(device->handle, 0, ec, NULL) !=
779 first_ec = boot_ec = NULL; 750 AE_CTRL_TERMINATE) {
751 kfree(ec);
752 return -EINVAL;
780 } 753 }
781 } 754 }
782 755
783 ec = make_acpi_ec();
784 if (!ec)
785 return -ENOMEM;
786
787 if (ec_parse_device(device->handle, 0, ec, NULL) !=
788 AE_CTRL_TERMINATE) {
789 kfree(ec);
790 return -EINVAL;
791 }
792 ec->handle = device->handle; 756 ec->handle = device->handle;
793 end: 757
758 /* Find and register all query methods */
759 acpi_walk_namespace(ACPI_TYPE_METHOD, ec->handle, 1,
760 acpi_ec_register_query_methods, ec, NULL);
761
794 if (!first_ec) 762 if (!first_ec)
795 first_ec = ec; 763 first_ec = ec;
796 acpi_driver_data(device) = ec; 764 acpi_driver_data(device) = ec;
@@ -865,7 +833,7 @@ static int ec_install_handlers(struct acpi_ec *ec)
865 status = acpi_install_address_space_handler(ec->handle, 833 status = acpi_install_address_space_handler(ec->handle,
866 ACPI_ADR_SPACE_EC, 834 ACPI_ADR_SPACE_EC,
867 &acpi_ec_space_handler, 835 &acpi_ec_space_handler,
868 &acpi_ec_space_setup, ec); 836 NULL, ec);
869 if (ACPI_FAILURE(status)) { 837 if (ACPI_FAILURE(status)) {
870 acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler); 838 acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler);
871 return -ENODEV; 839 return -ENODEV;
@@ -892,6 +860,7 @@ static int acpi_ec_start(struct acpi_device *device)
892 860
893 /* EC is fully operational, allow queries */ 861 /* EC is fully operational, allow queries */
894 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags); 862 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
863 ec_schedule_ec_poll(ec);
895 return ret; 864 return ret;
896} 865}
897 866
@@ -919,6 +888,11 @@ int __init acpi_boot_ec_enable(void)
919 return -EFAULT; 888 return -EFAULT;
920} 889}
921 890
891static const struct acpi_device_id ec_device_ids[] = {
892 {"PNP0C09", 0},
893 {"", 0},
894};
895
922int __init acpi_ec_ecdt_probe(void) 896int __init acpi_ec_ecdt_probe(void)
923{ 897{
924 int ret; 898 int ret;
@@ -939,6 +913,7 @@ int __init acpi_ec_ecdt_probe(void)
939 boot_ec->data_addr = ecdt_ptr->data.address; 913 boot_ec->data_addr = ecdt_ptr->data.address;
940 boot_ec->gpe = ecdt_ptr->gpe; 914 boot_ec->gpe = ecdt_ptr->gpe;
941 boot_ec->handle = ACPI_ROOT_OBJECT; 915 boot_ec->handle = ACPI_ROOT_OBJECT;
916 acpi_get_handle(ACPI_ROOT_OBJECT, ecdt_ptr->id, &boot_ec->handle);
942 } else { 917 } else {
943 /* This workaround is needed only on some broken machines, 918 /* This workaround is needed only on some broken machines,
944 * which require early EC, but fail to provide ECDT */ 919 * which require early EC, but fail to provide ECDT */
@@ -968,6 +943,39 @@ int __init acpi_ec_ecdt_probe(void)
968 return -ENODEV; 943 return -ENODEV;
969} 944}
970 945
946static int acpi_ec_suspend(struct acpi_device *device, pm_message_t state)
947{
948 struct acpi_ec *ec = acpi_driver_data(device);
949 /* Stop using GPE */
950 set_bit(EC_FLAGS_NO_GPE, &ec->flags);
951 clear_bit(EC_FLAGS_GPE_MODE, &ec->flags);
952 acpi_disable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
953 return 0;
954}
955
956static int acpi_ec_resume(struct acpi_device *device)
957{
958 struct acpi_ec *ec = acpi_driver_data(device);
959 /* Enable use of GPE back */
960 clear_bit(EC_FLAGS_NO_GPE, &ec->flags);
961 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
962 return 0;
963}
964
965static struct acpi_driver acpi_ec_driver = {
966 .name = "ec",
967 .class = ACPI_EC_CLASS,
968 .ids = ec_device_ids,
969 .ops = {
970 .add = acpi_ec_add,
971 .remove = acpi_ec_remove,
972 .start = acpi_ec_start,
973 .stop = acpi_ec_stop,
974 .suspend = acpi_ec_suspend,
975 .resume = acpi_ec_resume,
976 },
977};
978
971static int __init acpi_ec_init(void) 979static int __init acpi_ec_init(void)
972{ 980{
973 int result = 0; 981 int result = 0;
diff --git a/drivers/acpi/events/evevent.c b/drivers/acpi/events/evevent.c
index 3048801a37b5..5d30e5be1b1c 100644
--- a/drivers/acpi/events/evevent.c
+++ b/drivers/acpi/events/evevent.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/events/evgpe.c b/drivers/acpi/events/evgpe.c
index 0dadd2adc800..5354be44f876 100644
--- a/drivers/acpi/events/evgpe.c
+++ b/drivers/acpi/events/evgpe.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -248,10 +248,6 @@ acpi_status acpi_ev_disable_gpe(struct acpi_gpe_event_info *gpe_event_info)
248 248
249 ACPI_FUNCTION_TRACE(ev_disable_gpe); 249 ACPI_FUNCTION_TRACE(ev_disable_gpe);
250 250
251 if (!(gpe_event_info->flags & ACPI_GPE_ENABLE_MASK)) {
252 return_ACPI_STATUS(AE_OK);
253 }
254
255 /* Make sure HW enable masks are updated */ 251 /* Make sure HW enable masks are updated */
256 252
257 status = 253 status =
diff --git a/drivers/acpi/events/evgpeblk.c b/drivers/acpi/events/evgpeblk.c
index 361ebe6c4a6f..e6c4d4c49e79 100644
--- a/drivers/acpi/events/evgpeblk.c
+++ b/drivers/acpi/events/evgpeblk.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/events/evmisc.c b/drivers/acpi/events/evmisc.c
index 21cb749d0c75..2113e58e2221 100644
--- a/drivers/acpi/events/evmisc.c
+++ b/drivers/acpi/events/evmisc.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -49,22 +49,7 @@
49#define _COMPONENT ACPI_EVENTS 49#define _COMPONENT ACPI_EVENTS
50ACPI_MODULE_NAME("evmisc") 50ACPI_MODULE_NAME("evmisc")
51 51
52/* Names for Notify() values, used for debug output */
53#ifdef ACPI_DEBUG_OUTPUT
54static const char *acpi_notify_value_names[] = {
55 "Bus Check",
56 "Device Check",
57 "Device Wake",
58 "Eject Request",
59 "Device Check Light",
60 "Frequency Mismatch",
61 "Bus Mode Mismatch",
62 "Power Fault"
63};
64#endif
65
66/* Pointer to FACS needed for the Global Lock */ 52/* Pointer to FACS needed for the Global Lock */
67
68static struct acpi_table_facs *facs = NULL; 53static struct acpi_table_facs *facs = NULL;
69 54
70/* Local prototypes */ 55/* Local prototypes */
@@ -94,7 +79,6 @@ u8 acpi_ev_is_notify_object(struct acpi_namespace_node *node)
94 switch (node->type) { 79 switch (node->type) {
95 case ACPI_TYPE_DEVICE: 80 case ACPI_TYPE_DEVICE:
96 case ACPI_TYPE_PROCESSOR: 81 case ACPI_TYPE_PROCESSOR:
97 case ACPI_TYPE_POWER:
98 case ACPI_TYPE_THERMAL: 82 case ACPI_TYPE_THERMAL:
99 /* 83 /*
100 * These are the ONLY objects that can receive ACPI notifications 84 * These are the ONLY objects that can receive ACPI notifications
@@ -139,17 +123,9 @@ acpi_ev_queue_notify_request(struct acpi_namespace_node * node,
139 * initiate soft-off or sleep operation? 123 * initiate soft-off or sleep operation?
140 */ 124 */
141 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 125 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
142 "Dispatching Notify(%X) on node %p\n", notify_value, 126 "Dispatching Notify on [%4.4s] Node %p Value 0x%2.2X (%s)\n",
143 node)); 127 acpi_ut_get_node_name(node), node, notify_value,
144 128 acpi_ut_get_notify_name(notify_value)));
145 if (notify_value <= 7) {
146 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Notify value: %s\n",
147 acpi_notify_value_names[notify_value]));
148 } else {
149 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
150 "Notify value: 0x%2.2X **Device Specific**\n",
151 notify_value));
152 }
153 129
154 /* Get the notify object attached to the NS Node */ 130 /* Get the notify object attached to the NS Node */
155 131
@@ -159,10 +135,12 @@ acpi_ev_queue_notify_request(struct acpi_namespace_node * node,
159 /* We have the notify object, Get the right handler */ 135 /* We have the notify object, Get the right handler */
160 136
161 switch (node->type) { 137 switch (node->type) {
138
139 /* Notify allowed only on these types */
140
162 case ACPI_TYPE_DEVICE: 141 case ACPI_TYPE_DEVICE:
163 case ACPI_TYPE_THERMAL: 142 case ACPI_TYPE_THERMAL:
164 case ACPI_TYPE_PROCESSOR: 143 case ACPI_TYPE_PROCESSOR:
165 case ACPI_TYPE_POWER:
166 144
167 if (notify_value <= ACPI_MAX_SYS_NOTIFY) { 145 if (notify_value <= ACPI_MAX_SYS_NOTIFY) {
168 handler_obj = 146 handler_obj =
@@ -179,8 +157,13 @@ acpi_ev_queue_notify_request(struct acpi_namespace_node * node,
179 } 157 }
180 } 158 }
181 159
182 /* If there is any handler to run, schedule the dispatcher */ 160 /*
183 161 * If there is any handler to run, schedule the dispatcher.
162 * Check for:
163 * 1) Global system notify handler
164 * 2) Global device notify handler
165 * 3) Per-device notify handler
166 */
184 if ((acpi_gbl_system_notify.handler 167 if ((acpi_gbl_system_notify.handler
185 && (notify_value <= ACPI_MAX_SYS_NOTIFY)) 168 && (notify_value <= ACPI_MAX_SYS_NOTIFY))
186 || (acpi_gbl_device_notify.handler 169 || (acpi_gbl_device_notify.handler
@@ -190,6 +173,13 @@ acpi_ev_queue_notify_request(struct acpi_namespace_node * node,
190 return (AE_NO_MEMORY); 173 return (AE_NO_MEMORY);
191 } 174 }
192 175
176 if (!handler_obj) {
177 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
178 "Executing system notify handler for Notify (%4.4s, %X) node %p\n",
179 acpi_ut_get_node_name(node),
180 notify_value, node));
181 }
182
193 notify_info->common.descriptor_type = 183 notify_info->common.descriptor_type =
194 ACPI_DESC_TYPE_STATE_NOTIFY; 184 ACPI_DESC_TYPE_STATE_NOTIFY;
195 notify_info->notify.node = node; 185 notify_info->notify.node = node;
@@ -202,15 +192,12 @@ acpi_ev_queue_notify_request(struct acpi_namespace_node * node,
202 if (ACPI_FAILURE(status)) { 192 if (ACPI_FAILURE(status)) {
203 acpi_ut_delete_generic_state(notify_info); 193 acpi_ut_delete_generic_state(notify_info);
204 } 194 }
205 } 195 } else {
206
207 if (!handler_obj) {
208 /* 196 /*
209 * There is no per-device notify handler for this device. 197 * There is no notify handler (per-device or system) for this device.
210 * This may or may not be a problem.
211 */ 198 */
212 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 199 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
213 "No notify handler for Notify(%4.4s, %X) node %p\n", 200 "No notify handler for Notify (%4.4s, %X) node %p\n",
214 acpi_ut_get_node_name(node), notify_value, 201 acpi_ut_get_node_name(node), notify_value,
215 node)); 202 node));
216 } 203 }
@@ -349,9 +336,10 @@ acpi_status acpi_ev_init_global_lock_handler(void)
349 336
350 ACPI_FUNCTION_TRACE(ev_init_global_lock_handler); 337 ACPI_FUNCTION_TRACE(ev_init_global_lock_handler);
351 338
352 status = 339 status = acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS,
353 acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS, 340 ACPI_CAST_INDIRECT_PTR(struct
354 (struct acpi_table_header **)&facs); 341 acpi_table_header,
342 &facs));
355 if (ACPI_FAILURE(status)) { 343 if (ACPI_FAILURE(status)) {
356 return_ACPI_STATUS(status); 344 return_ACPI_STATUS(status);
357 } 345 }
@@ -439,7 +427,8 @@ acpi_status acpi_ev_acquire_global_lock(u16 timeout)
439 * Only one thread can acquire the GL at a time, the global_lock_mutex 427 * Only one thread can acquire the GL at a time, the global_lock_mutex
440 * enforces this. This interface releases the interpreter if we must wait. 428 * enforces this. This interface releases the interpreter if we must wait.
441 */ 429 */
442 status = acpi_ex_system_wait_mutex(acpi_gbl_global_lock_mutex, 0); 430 status = acpi_ex_system_wait_mutex(
431 acpi_gbl_global_lock_mutex->mutex.os_mutex, 0);
443 if (status == AE_TIME) { 432 if (status == AE_TIME) {
444 if (acpi_ev_global_lock_thread_id == acpi_os_get_thread_id()) { 433 if (acpi_ev_global_lock_thread_id == acpi_os_get_thread_id()) {
445 acpi_ev_global_lock_acquired++; 434 acpi_ev_global_lock_acquired++;
@@ -448,9 +437,9 @@ acpi_status acpi_ev_acquire_global_lock(u16 timeout)
448 } 437 }
449 438
450 if (ACPI_FAILURE(status)) { 439 if (ACPI_FAILURE(status)) {
451 status = 440 status = acpi_ex_system_wait_mutex(
452 acpi_ex_system_wait_mutex(acpi_gbl_global_lock_mutex, 441 acpi_gbl_global_lock_mutex->mutex.os_mutex,
453 timeout); 442 timeout);
454 } 443 }
455 if (ACPI_FAILURE(status)) { 444 if (ACPI_FAILURE(status)) {
456 return_ACPI_STATUS(status); 445 return_ACPI_STATUS(status);
@@ -460,6 +449,19 @@ acpi_status acpi_ev_acquire_global_lock(u16 timeout)
460 acpi_ev_global_lock_acquired++; 449 acpi_ev_global_lock_acquired++;
461 450
462 /* 451 /*
452 * Update the global lock handle and check for wraparound. The handle is
453 * only used for the external global lock interfaces, but it is updated
454 * here to properly handle the case where a single thread may acquire the
455 * lock via both the AML and the acpi_acquire_global_lock interfaces. The
456 * handle is therefore updated on the first acquire from a given thread
457 * regardless of where the acquisition request originated.
458 */
459 acpi_gbl_global_lock_handle++;
460 if (acpi_gbl_global_lock_handle == 0) {
461 acpi_gbl_global_lock_handle = 1;
462 }
463
464 /*
463 * Make sure that a global lock actually exists. If not, just treat 465 * Make sure that a global lock actually exists. If not, just treat
464 * the lock as a standard mutex. 466 * the lock as a standard mutex.
465 */ 467 */
@@ -555,7 +557,7 @@ acpi_status acpi_ev_release_global_lock(void)
555 /* Release the local GL mutex */ 557 /* Release the local GL mutex */
556 acpi_ev_global_lock_thread_id = NULL; 558 acpi_ev_global_lock_thread_id = NULL;
557 acpi_ev_global_lock_acquired = 0; 559 acpi_ev_global_lock_acquired = 0;
558 acpi_os_release_mutex(acpi_gbl_global_lock_mutex); 560 acpi_os_release_mutex(acpi_gbl_global_lock_mutex->mutex.os_mutex);
559 return_ACPI_STATUS(status); 561 return_ACPI_STATUS(status);
560} 562}
561 563
diff --git a/drivers/acpi/events/evregion.c b/drivers/acpi/events/evregion.c
index 58ad09725dd2..1628f5934752 100644
--- a/drivers/acpi/events/evregion.c
+++ b/drivers/acpi/events/evregion.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -394,7 +394,7 @@ acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
394 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, 394 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
395 "Handler %p (@%p) Address %8.8X%8.8X [%s]\n", 395 "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
396 &region_obj->region.handler->address_space, handler, 396 &region_obj->region.handler->address_space, handler,
397 ACPI_FORMAT_UINT64(address), 397 ACPI_FORMAT_NATIVE_UINT(address),
398 acpi_ut_get_region_name(region_obj->region. 398 acpi_ut_get_region_name(region_obj->region.
399 space_id))); 399 space_id)));
400 400
diff --git a/drivers/acpi/events/evrgnini.c b/drivers/acpi/events/evrgnini.c
index b1aaa0e84588..2e3d2c5e4f4d 100644
--- a/drivers/acpi/events/evrgnini.c
+++ b/drivers/acpi/events/evrgnini.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/events/evsci.c b/drivers/acpi/events/evsci.c
index 7e5d15ce2395..2a8b77877610 100644
--- a/drivers/acpi/events/evsci.c
+++ b/drivers/acpi/events/evsci.c
@@ -6,7 +6,7 @@
6 ******************************************************************************/ 6 ******************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/events/evxface.c b/drivers/acpi/events/evxface.c
index 6d866a01f5f4..94a6efe020be 100644
--- a/drivers/acpi/events/evxface.c
+++ b/drivers/acpi/events/evxface.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -758,6 +758,12 @@ ACPI_EXPORT_SYMBOL(acpi_remove_gpe_handler)
758 * 758 *
759 * DESCRIPTION: Acquire the ACPI Global Lock 759 * DESCRIPTION: Acquire the ACPI Global Lock
760 * 760 *
761 * Note: Allows callers with the same thread ID to acquire the global lock
762 * multiple times. In other words, externally, the behavior of the global lock
763 * is identical to an AML mutex. On the first acquire, a new handle is
764 * returned. On any subsequent calls to acquire by the same thread, the same
765 * handle is returned.
766 *
761 ******************************************************************************/ 767 ******************************************************************************/
762acpi_status acpi_acquire_global_lock(u16 timeout, u32 * handle) 768acpi_status acpi_acquire_global_lock(u16 timeout, u32 * handle)
763{ 769{
@@ -770,14 +776,19 @@ acpi_status acpi_acquire_global_lock(u16 timeout, u32 * handle)
770 /* Must lock interpreter to prevent race conditions */ 776 /* Must lock interpreter to prevent race conditions */
771 777
772 acpi_ex_enter_interpreter(); 778 acpi_ex_enter_interpreter();
773 status = acpi_ev_acquire_global_lock(timeout); 779
774 acpi_ex_exit_interpreter(); 780 status = acpi_ex_acquire_mutex_object(timeout,
781 acpi_gbl_global_lock_mutex,
782 acpi_os_get_thread_id());
775 783
776 if (ACPI_SUCCESS(status)) { 784 if (ACPI_SUCCESS(status)) {
777 acpi_gbl_global_lock_handle++; 785
786 /* Return the global lock handle (updated in acpi_ev_acquire_global_lock) */
787
778 *handle = acpi_gbl_global_lock_handle; 788 *handle = acpi_gbl_global_lock_handle;
779 } 789 }
780 790
791 acpi_ex_exit_interpreter();
781 return (status); 792 return (status);
782} 793}
783 794
@@ -798,11 +809,11 @@ acpi_status acpi_release_global_lock(u32 handle)
798{ 809{
799 acpi_status status; 810 acpi_status status;
800 811
801 if (handle != acpi_gbl_global_lock_handle) { 812 if (!handle || (handle != acpi_gbl_global_lock_handle)) {
802 return (AE_NOT_ACQUIRED); 813 return (AE_NOT_ACQUIRED);
803 } 814 }
804 815
805 status = acpi_ev_release_global_lock(); 816 status = acpi_ex_release_mutex_object(acpi_gbl_global_lock_mutex);
806 return (status); 817 return (status);
807} 818}
808 819
diff --git a/drivers/acpi/events/evxfevnt.c b/drivers/acpi/events/evxfevnt.c
index 9cbd3414a574..99a7502e6a87 100644
--- a/drivers/acpi/events/evxfevnt.c
+++ b/drivers/acpi/events/evxfevnt.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/events/evxfregn.c b/drivers/acpi/events/evxfregn.c
index 7bf09c5fb242..e8750807e57d 100644
--- a/drivers/acpi/events/evxfregn.c
+++ b/drivers/acpi/events/evxfregn.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/executer/exconfig.c b/drivers/acpi/executer/exconfig.c
index 25802f302ffe..24da921d13e3 100644
--- a/drivers/acpi/executer/exconfig.c
+++ b/drivers/acpi/executer/exconfig.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -45,7 +45,6 @@
45#include <acpi/acinterp.h> 45#include <acpi/acinterp.h>
46#include <acpi/amlcode.h> 46#include <acpi/amlcode.h>
47#include <acpi/acnamesp.h> 47#include <acpi/acnamesp.h>
48#include <acpi/acevents.h>
49#include <acpi/actables.h> 48#include <acpi/actables.h>
50#include <acpi/acdispat.h> 49#include <acpi/acdispat.h>
51 50
@@ -138,6 +137,14 @@ acpi_ex_load_table_op(struct acpi_walk_state *walk_state,
138 137
139 ACPI_FUNCTION_TRACE(ex_load_table_op); 138 ACPI_FUNCTION_TRACE(ex_load_table_op);
140 139
140 /* Validate lengths for the signature_string, OEMIDString, OEMtable_iD */
141
142 if ((operand[0]->string.length > ACPI_NAME_SIZE) ||
143 (operand[1]->string.length > ACPI_OEM_ID_SIZE) ||
144 (operand[2]->string.length > ACPI_OEM_TABLE_ID_SIZE)) {
145 return_ACPI_STATUS(AE_BAD_PARAMETER);
146 }
147
141 /* Find the ACPI table in the RSDT/XSDT */ 148 /* Find the ACPI table in the RSDT/XSDT */
142 149
143 status = acpi_tb_find_table(operand[0]->string.pointer, 150 status = acpi_tb_find_table(operand[0]->string.pointer,
@@ -229,11 +236,18 @@ acpi_ex_load_table_op(struct acpi_walk_state *walk_state,
229 status = acpi_get_table_by_index(table_index, &table); 236 status = acpi_get_table_by_index(table_index, &table);
230 if (ACPI_SUCCESS(status)) { 237 if (ACPI_SUCCESS(status)) {
231 ACPI_INFO((AE_INFO, 238 ACPI_INFO((AE_INFO,
232 "Dynamic OEM Table Load - [%4.4s] OemId [%6.6s] OemTableId [%8.8s]", 239 "Dynamic OEM Table Load - [%.4s] OemId [%.6s] OemTableId [%.8s]",
233 table->signature, table->oem_id, 240 table->signature, table->oem_id,
234 table->oem_table_id)); 241 table->oem_table_id));
235 } 242 }
236 243
244 /* Invoke table handler if present */
245
246 if (acpi_gbl_table_handler) {
247 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD, table,
248 acpi_gbl_table_handler_context);
249 }
250
237 *return_desc = ddb_handle; 251 *return_desc = ddb_handle;
238 return_ACPI_STATUS(status); 252 return_ACPI_STATUS(status);
239} 253}
@@ -268,6 +282,7 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
268 struct acpi_table_desc table_desc; 282 struct acpi_table_desc table_desc;
269 acpi_native_uint table_index; 283 acpi_native_uint table_index;
270 acpi_status status; 284 acpi_status status;
285 u32 length;
271 286
272 ACPI_FUNCTION_TRACE(ex_load_op); 287 ACPI_FUNCTION_TRACE(ex_load_op);
273 288
@@ -278,16 +293,16 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
278 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { 293 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
279 case ACPI_TYPE_REGION: 294 case ACPI_TYPE_REGION:
280 295
296 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Load from Region %p %s\n",
297 obj_desc,
298 acpi_ut_get_object_type_name(obj_desc)));
299
281 /* Region must be system_memory (from ACPI spec) */ 300 /* Region must be system_memory (from ACPI spec) */
282 301
283 if (obj_desc->region.space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) { 302 if (obj_desc->region.space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) {
284 return_ACPI_STATUS(AE_AML_OPERAND_TYPE); 303 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
285 } 304 }
286 305
287 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Load from Region %p %s\n",
288 obj_desc,
289 acpi_ut_get_object_type_name(obj_desc)));
290
291 /* 306 /*
292 * If the Region Address and Length have not been previously evaluated, 307 * If the Region Address and Length have not been previously evaluated,
293 * evaluate them now and save the results. 308 * evaluate them now and save the results.
@@ -299,6 +314,11 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
299 } 314 }
300 } 315 }
301 316
317 /*
318 * We will simply map the memory region for the table. However, the
319 * memory region is technically not guaranteed to remain stable and
320 * we may eventually have to copy the table to a local buffer.
321 */
302 table_desc.address = obj_desc->region.address; 322 table_desc.address = obj_desc->region.address;
303 table_desc.length = obj_desc->region.length; 323 table_desc.length = obj_desc->region.length;
304 table_desc.flags = ACPI_TABLE_ORIGIN_MAPPED; 324 table_desc.flags = ACPI_TABLE_ORIGIN_MAPPED;
@@ -306,18 +326,41 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
306 326
307 case ACPI_TYPE_BUFFER: /* Buffer or resolved region_field */ 327 case ACPI_TYPE_BUFFER: /* Buffer or resolved region_field */
308 328
309 /* Simply extract the buffer from the buffer object */
310
311 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, 329 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
312 "Load from Buffer or Field %p %s\n", obj_desc, 330 "Load from Buffer or Field %p %s\n", obj_desc,
313 acpi_ut_get_object_type_name(obj_desc))); 331 acpi_ut_get_object_type_name(obj_desc)));
314 332
315 table_desc.pointer = ACPI_CAST_PTR(struct acpi_table_header, 333 length = obj_desc->buffer.length;
316 obj_desc->buffer.pointer); 334
317 table_desc.length = table_desc.pointer->length; 335 /* Must have at least an ACPI table header */
318 table_desc.flags = ACPI_TABLE_ORIGIN_ALLOCATED; 336
337 if (length < sizeof(struct acpi_table_header)) {
338 return_ACPI_STATUS(AE_INVALID_TABLE_LENGTH);
339 }
340
341 /* Validate checksum here. It won't get validated in tb_add_table */
319 342
320 obj_desc->buffer.pointer = NULL; 343 status =
344 acpi_tb_verify_checksum(ACPI_CAST_PTR
345 (struct acpi_table_header,
346 obj_desc->buffer.pointer), length);
347 if (ACPI_FAILURE(status)) {
348 return_ACPI_STATUS(status);
349 }
350
351 /*
352 * We need to copy the buffer since the original buffer could be
353 * changed or deleted in the future
354 */
355 table_desc.pointer = ACPI_ALLOCATE(length);
356 if (!table_desc.pointer) {
357 return_ACPI_STATUS(AE_NO_MEMORY);
358 }
359
360 ACPI_MEMCPY(table_desc.pointer, obj_desc->buffer.pointer,
361 length);
362 table_desc.length = length;
363 table_desc.flags = ACPI_TABLE_ORIGIN_ALLOCATED;
321 break; 364 break;
322 365
323 default: 366 default:
@@ -333,7 +376,8 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
333 } 376 }
334 377
335 status = 378 status =
336 acpi_ex_add_table(table_index, acpi_gbl_root_node, &ddb_handle); 379 acpi_ex_add_table(table_index, walk_state->scope_info->scope.node,
380 &ddb_handle);
337 if (ACPI_FAILURE(status)) { 381 if (ACPI_FAILURE(status)) {
338 382
339 /* On error, table_ptr was deallocated above */ 383 /* On error, table_ptr was deallocated above */
@@ -349,11 +393,23 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
349 393
350 /* table_ptr was deallocated above */ 394 /* table_ptr was deallocated above */
351 395
396 acpi_ut_remove_reference(ddb_handle);
352 return_ACPI_STATUS(status); 397 return_ACPI_STATUS(status);
353 } 398 }
354 399
400 /* Invoke table handler if present */
401
402 if (acpi_gbl_table_handler) {
403 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_LOAD,
404 table_desc.pointer,
405 acpi_gbl_table_handler_context);
406 }
407
355 cleanup: 408 cleanup:
356 if (ACPI_FAILURE(status)) { 409 if (ACPI_FAILURE(status)) {
410
411 /* Delete allocated buffer or mapping */
412
357 acpi_tb_delete_table(&table_desc); 413 acpi_tb_delete_table(&table_desc);
358 } 414 }
359 return_ACPI_STATUS(status); 415 return_ACPI_STATUS(status);
@@ -376,6 +432,7 @@ acpi_status acpi_ex_unload_table(union acpi_operand_object *ddb_handle)
376 acpi_status status = AE_OK; 432 acpi_status status = AE_OK;
377 union acpi_operand_object *table_desc = ddb_handle; 433 union acpi_operand_object *table_desc = ddb_handle;
378 acpi_native_uint table_index; 434 acpi_native_uint table_index;
435 struct acpi_table_header *table;
379 436
380 ACPI_FUNCTION_TRACE(ex_unload_table); 437 ACPI_FUNCTION_TRACE(ex_unload_table);
381 438
@@ -395,17 +452,25 @@ acpi_status acpi_ex_unload_table(union acpi_operand_object *ddb_handle)
395 452
396 table_index = (acpi_native_uint) table_desc->reference.object; 453 table_index = (acpi_native_uint) table_desc->reference.object;
397 454
455 /* Invoke table handler if present */
456
457 if (acpi_gbl_table_handler) {
458 status = acpi_get_table_by_index(table_index, &table);
459 if (ACPI_SUCCESS(status)) {
460 (void)acpi_gbl_table_handler(ACPI_TABLE_EVENT_UNLOAD,
461 table,
462 acpi_gbl_table_handler_context);
463 }
464 }
465
398 /* 466 /*
399 * Delete the entire namespace under this table Node 467 * Delete the entire namespace under this table Node
400 * (Offset contains the table_id) 468 * (Offset contains the table_id)
401 */ 469 */
402 acpi_tb_delete_namespace_by_owner(table_index); 470 acpi_tb_delete_namespace_by_owner(table_index);
403 acpi_tb_release_owner_id(table_index); 471 (void)acpi_tb_release_owner_id(table_index);
404 472
405 acpi_tb_set_table_loaded_flag(table_index, FALSE); 473 acpi_tb_set_table_loaded_flag(table_index, FALSE);
406 474
407 /* Delete the table descriptor (ddb_handle) */ 475 return_ACPI_STATUS(AE_OK);
408
409 acpi_ut_remove_reference(table_desc);
410 return_ACPI_STATUS(status);
411} 476}
diff --git a/drivers/acpi/executer/exconvrt.c b/drivers/acpi/executer/exconvrt.c
index 79f2c0d42c06..fd954b4ed83d 100644
--- a/drivers/acpi/executer/exconvrt.c
+++ b/drivers/acpi/executer/exconvrt.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/executer/excreate.c b/drivers/acpi/executer/excreate.c
index 6e9a23e47fef..60e62c4f0577 100644
--- a/drivers/acpi/executer/excreate.c
+++ b/drivers/acpi/executer/excreate.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -96,6 +96,9 @@ acpi_status acpi_ex_create_alias(struct acpi_walk_state *walk_state)
96 * to the original Node. 96 * to the original Node.
97 */ 97 */
98 switch (target_node->type) { 98 switch (target_node->type) {
99
100 /* For these types, the sub-object can change dynamically via a Store */
101
99 case ACPI_TYPE_INTEGER: 102 case ACPI_TYPE_INTEGER:
100 case ACPI_TYPE_STRING: 103 case ACPI_TYPE_STRING:
101 case ACPI_TYPE_BUFFER: 104 case ACPI_TYPE_BUFFER:
@@ -103,9 +106,18 @@ acpi_status acpi_ex_create_alias(struct acpi_walk_state *walk_state)
103 case ACPI_TYPE_BUFFER_FIELD: 106 case ACPI_TYPE_BUFFER_FIELD:
104 107
105 /* 108 /*
109 * These types open a new scope, so we need the NS node in order to access
110 * any children.
111 */
112 case ACPI_TYPE_DEVICE:
113 case ACPI_TYPE_POWER:
114 case ACPI_TYPE_PROCESSOR:
115 case ACPI_TYPE_THERMAL:
116 case ACPI_TYPE_LOCAL_SCOPE:
117
118 /*
106 * The new alias has the type ALIAS and points to the original 119 * The new alias has the type ALIAS and points to the original
107 * NS node, not the object itself. This is because for these 120 * NS node, not the object itself.
108 * types, the object can change dynamically via a Store.
109 */ 121 */
110 alias_node->type = ACPI_TYPE_LOCAL_ALIAS; 122 alias_node->type = ACPI_TYPE_LOCAL_ALIAS;
111 alias_node->object = 123 alias_node->object =
@@ -115,9 +127,7 @@ acpi_status acpi_ex_create_alias(struct acpi_walk_state *walk_state)
115 case ACPI_TYPE_METHOD: 127 case ACPI_TYPE_METHOD:
116 128
117 /* 129 /*
118 * The new alias has the type ALIAS and points to the original 130 * Control method aliases need to be differentiated
119 * NS node, not the object itself. This is because for these
120 * types, the object can change dynamically via a Store.
121 */ 131 */
122 alias_node->type = ACPI_TYPE_LOCAL_METHOD_ALIAS; 132 alias_node->type = ACPI_TYPE_LOCAL_METHOD_ALIAS;
123 alias_node->object = 133 alias_node->object =
@@ -342,101 +352,6 @@ acpi_ex_create_region(u8 * aml_start,
342 352
343/******************************************************************************* 353/*******************************************************************************
344 * 354 *
345 * FUNCTION: acpi_ex_create_table_region
346 *
347 * PARAMETERS: walk_state - Current state
348 *
349 * RETURN: Status
350 *
351 * DESCRIPTION: Create a new data_table_region object
352 *
353 ******************************************************************************/
354
355acpi_status acpi_ex_create_table_region(struct acpi_walk_state *walk_state)
356{
357 acpi_status status;
358 union acpi_operand_object **operand = &walk_state->operands[0];
359 union acpi_operand_object *obj_desc;
360 struct acpi_namespace_node *node;
361 union acpi_operand_object *region_obj2;
362 acpi_native_uint table_index;
363 struct acpi_table_header *table;
364
365 ACPI_FUNCTION_TRACE(ex_create_table_region);
366
367 /* Get the Node from the object stack */
368
369 node = walk_state->op->common.node;
370
371 /*
372 * If the region object is already attached to this node,
373 * just return
374 */
375 if (acpi_ns_get_attached_object(node)) {
376 return_ACPI_STATUS(AE_OK);
377 }
378
379 /* Find the ACPI table */
380
381 status = acpi_tb_find_table(operand[1]->string.pointer,
382 operand[2]->string.pointer,
383 operand[3]->string.pointer, &table_index);
384 if (ACPI_FAILURE(status)) {
385 return_ACPI_STATUS(status);
386 }
387
388 /* Create the region descriptor */
389
390 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_REGION);
391 if (!obj_desc) {
392 return_ACPI_STATUS(AE_NO_MEMORY);
393 }
394
395 region_obj2 = obj_desc->common.next_object;
396 region_obj2->extra.region_context = NULL;
397
398 status = acpi_get_table_by_index(table_index, &table);
399 if (ACPI_FAILURE(status)) {
400 return_ACPI_STATUS(status);
401 }
402
403 /* Init the region from the operands */
404
405 obj_desc->region.space_id = REGION_DATA_TABLE;
406 obj_desc->region.address =
407 (acpi_physical_address) ACPI_TO_INTEGER(table);
408 obj_desc->region.length = table->length;
409 obj_desc->region.node = node;
410 obj_desc->region.flags = AOPOBJ_DATA_VALID;
411
412 /* Install the new region object in the parent Node */
413
414 status = acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_REGION);
415 if (ACPI_FAILURE(status)) {
416 goto cleanup;
417 }
418
419 status = acpi_ev_initialize_region(obj_desc, FALSE);
420 if (ACPI_FAILURE(status)) {
421 if (status == AE_NOT_EXIST) {
422 status = AE_OK;
423 } else {
424 goto cleanup;
425 }
426 }
427
428 obj_desc->region.flags |= AOPOBJ_SETUP_COMPLETE;
429
430 cleanup:
431
432 /* Remove local reference to the object */
433
434 acpi_ut_remove_reference(obj_desc);
435 return_ACPI_STATUS(status);
436}
437
438/*******************************************************************************
439 *
440 * FUNCTION: acpi_ex_create_processor 355 * FUNCTION: acpi_ex_create_processor
441 * 356 *
442 * PARAMETERS: walk_state - Current state 357 * PARAMETERS: walk_state - Current state
diff --git a/drivers/acpi/executer/exdump.c b/drivers/acpi/executer/exdump.c
index 51c9c29987c3..74f1b22601b3 100644
--- a/drivers/acpi/executer/exdump.c
+++ b/drivers/acpi/executer/exdump.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -500,25 +500,28 @@ void acpi_ex_dump_operand(union acpi_operand_object *obj_desc, u32 depth)
500 acpi_os_printf("Reference: Debug\n"); 500 acpi_os_printf("Reference: Debug\n");
501 break; 501 break;
502 502
503 case AML_NAME_OP: 503 case AML_INDEX_OP:
504 504
505 ACPI_DUMP_PATHNAME(obj_desc->reference.object, 505 acpi_os_printf("Reference: Index %p\n",
506 "Reference: Name: ", ACPI_LV_INFO, 506 obj_desc->reference.object);
507 _COMPONENT);
508 ACPI_DUMP_ENTRY(obj_desc->reference.object,
509 ACPI_LV_INFO);
510 break; 507 break;
511 508
512 case AML_INDEX_OP: 509 case AML_LOAD_OP:
513 510
514 acpi_os_printf("Reference: Index %p\n", 511 acpi_os_printf("Reference: [DdbHandle] TableIndex %p\n",
515 obj_desc->reference.object); 512 obj_desc->reference.object);
516 break; 513 break;
517 514
518 case AML_REF_OF_OP: 515 case AML_REF_OF_OP:
519 516
520 acpi_os_printf("Reference: (RefOf) %p\n", 517 acpi_os_printf("Reference: (RefOf) %p [%s]\n",
521 obj_desc->reference.object); 518 obj_desc->reference.object,
519 acpi_ut_get_type_name(((union
520 acpi_operand_object
521 *)obj_desc->
522 reference.
523 object)->common.
524 type));
522 break; 525 break;
523 526
524 case AML_ARG_OP: 527 case AML_ARG_OP:
@@ -559,8 +562,9 @@ void acpi_ex_dump_operand(union acpi_operand_object *obj_desc, u32 depth)
559 562
560 case AML_INT_NAMEPATH_OP: 563 case AML_INT_NAMEPATH_OP:
561 564
562 acpi_os_printf("Reference.Node->Name %X\n", 565 acpi_os_printf("Reference: Namepath %X [%4.4s]\n",
563 obj_desc->reference.node->name.integer); 566 obj_desc->reference.node->name.integer,
567 obj_desc->reference.node->name.ascii);
564 break; 568 break;
565 569
566 default: 570 default:
@@ -640,8 +644,8 @@ void acpi_ex_dump_operand(union acpi_operand_object *obj_desc, u32 depth)
640 acpi_os_printf("\n"); 644 acpi_os_printf("\n");
641 } else { 645 } else {
642 acpi_os_printf(" base %8.8X%8.8X Length %X\n", 646 acpi_os_printf(" base %8.8X%8.8X Length %X\n",
643 ACPI_FORMAT_UINT64(obj_desc->region. 647 ACPI_FORMAT_NATIVE_UINT(obj_desc->region.
644 address), 648 address),
645 obj_desc->region.length); 649 obj_desc->region.length);
646 } 650 }
647 break; 651 break;
@@ -877,20 +881,43 @@ static void acpi_ex_dump_reference_obj(union acpi_operand_object *obj_desc)
877 ret_buf.length = ACPI_ALLOCATE_LOCAL_BUFFER; 881 ret_buf.length = ACPI_ALLOCATE_LOCAL_BUFFER;
878 882
879 if (obj_desc->reference.opcode == AML_INT_NAMEPATH_OP) { 883 if (obj_desc->reference.opcode == AML_INT_NAMEPATH_OP) {
880 acpi_os_printf("Named Object %p ", obj_desc->reference.node); 884 acpi_os_printf(" Named Object %p ", obj_desc->reference.node);
881 885
882 status = 886 status =
883 acpi_ns_handle_to_pathname(obj_desc->reference.node, 887 acpi_ns_handle_to_pathname(obj_desc->reference.node,
884 &ret_buf); 888 &ret_buf);
885 if (ACPI_FAILURE(status)) { 889 if (ACPI_FAILURE(status)) {
886 acpi_os_printf("Could not convert name to pathname\n"); 890 acpi_os_printf(" Could not convert name to pathname\n");
887 } else { 891 } else {
888 acpi_os_printf("%s\n", (char *)ret_buf.pointer); 892 acpi_os_printf("%s\n", (char *)ret_buf.pointer);
889 ACPI_FREE(ret_buf.pointer); 893 ACPI_FREE(ret_buf.pointer);
890 } 894 }
891 } else if (obj_desc->reference.object) { 895 } else if (obj_desc->reference.object) {
892 acpi_os_printf("\nReferenced Object: %p\n", 896 if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
893 obj_desc->reference.object); 897 ACPI_DESC_TYPE_OPERAND) {
898 acpi_os_printf(" Target: %p",
899 obj_desc->reference.object);
900 if (obj_desc->reference.opcode == AML_LOAD_OP) {
901 /*
902 * For DDBHandle reference,
903 * obj_desc->Reference.Object is the table index
904 */
905 acpi_os_printf(" [DDBHandle]\n");
906 } else {
907 acpi_os_printf(" [%s]\n",
908 acpi_ut_get_type_name(((union
909 acpi_operand_object
910 *)
911 obj_desc->
912 reference.
913 object)->
914 common.
915 type));
916 }
917 } else {
918 acpi_os_printf(" Target: %p\n",
919 obj_desc->reference.object);
920 }
894 } 921 }
895} 922}
896 923
@@ -976,7 +1003,9 @@ acpi_ex_dump_package_obj(union acpi_operand_object *obj_desc,
976 1003
977 case ACPI_TYPE_LOCAL_REFERENCE: 1004 case ACPI_TYPE_LOCAL_REFERENCE:
978 1005
979 acpi_os_printf("[Object Reference] "); 1006 acpi_os_printf("[Object Reference] %s",
1007 (acpi_ps_get_opcode_info
1008 (obj_desc->reference.opcode))->name);
980 acpi_ex_dump_reference_obj(obj_desc); 1009 acpi_ex_dump_reference_obj(obj_desc);
981 break; 1010 break;
982 1011
diff --git a/drivers/acpi/executer/exfield.c b/drivers/acpi/executer/exfield.c
index 2d88a3d8d1ad..3e440d84226a 100644
--- a/drivers/acpi/executer/exfield.c
+++ b/drivers/acpi/executer/exfield.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -71,7 +71,6 @@ acpi_ex_read_data_from_field(struct acpi_walk_state *walk_state,
71 union acpi_operand_object *buffer_desc; 71 union acpi_operand_object *buffer_desc;
72 acpi_size length; 72 acpi_size length;
73 void *buffer; 73 void *buffer;
74 u8 locked;
75 74
76 ACPI_FUNCTION_TRACE_PTR(ex_read_data_from_field, obj_desc); 75 ACPI_FUNCTION_TRACE_PTR(ex_read_data_from_field, obj_desc);
77 76
@@ -111,9 +110,7 @@ acpi_ex_read_data_from_field(struct acpi_walk_state *walk_state,
111 110
112 /* Lock entire transaction if requested */ 111 /* Lock entire transaction if requested */
113 112
114 locked = 113 acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags);
115 acpi_ex_acquire_global_lock(obj_desc->common_field.
116 field_flags);
117 114
118 /* 115 /*
119 * Perform the read. 116 * Perform the read.
@@ -125,7 +122,7 @@ acpi_ex_read_data_from_field(struct acpi_walk_state *walk_state,
125 buffer.pointer), 122 buffer.pointer),
126 ACPI_READ | (obj_desc->field. 123 ACPI_READ | (obj_desc->field.
127 attribute << 16)); 124 attribute << 16));
128 acpi_ex_release_global_lock(locked); 125 acpi_ex_release_global_lock(obj_desc->common_field.field_flags);
129 goto exit; 126 goto exit;
130 } 127 }
131 128
@@ -175,13 +172,12 @@ acpi_ex_read_data_from_field(struct acpi_walk_state *walk_state,
175 172
176 /* Lock entire transaction if requested */ 173 /* Lock entire transaction if requested */
177 174
178 locked = 175 acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags);
179 acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags);
180 176
181 /* Read from the field */ 177 /* Read from the field */
182 178
183 status = acpi_ex_extract_from_field(obj_desc, buffer, (u32) length); 179 status = acpi_ex_extract_from_field(obj_desc, buffer, (u32) length);
184 acpi_ex_release_global_lock(locked); 180 acpi_ex_release_global_lock(obj_desc->common_field.field_flags);
185 181
186 exit: 182 exit:
187 if (ACPI_FAILURE(status)) { 183 if (ACPI_FAILURE(status)) {
@@ -214,10 +210,7 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
214{ 210{
215 acpi_status status; 211 acpi_status status;
216 u32 length; 212 u32 length;
217 u32 required_length;
218 void *buffer; 213 void *buffer;
219 void *new_buffer;
220 u8 locked;
221 union acpi_operand_object *buffer_desc; 214 union acpi_operand_object *buffer_desc;
222 215
223 ACPI_FUNCTION_TRACE_PTR(ex_write_data_to_field, obj_desc); 216 ACPI_FUNCTION_TRACE_PTR(ex_write_data_to_field, obj_desc);
@@ -278,9 +271,7 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
278 271
279 /* Lock entire transaction if requested */ 272 /* Lock entire transaction if requested */
280 273
281 locked = 274 acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags);
282 acpi_ex_acquire_global_lock(obj_desc->common_field.
283 field_flags);
284 275
285 /* 276 /*
286 * Perform the write (returns status and perhaps data in the 277 * Perform the write (returns status and perhaps data in the
@@ -291,7 +282,7 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
291 (acpi_integer *) buffer, 282 (acpi_integer *) buffer,
292 ACPI_WRITE | (obj_desc->field. 283 ACPI_WRITE | (obj_desc->field.
293 attribute << 16)); 284 attribute << 16));
294 acpi_ex_release_global_lock(locked); 285 acpi_ex_release_global_lock(obj_desc->common_field.field_flags);
295 286
296 *result_desc = buffer_desc; 287 *result_desc = buffer_desc;
297 return_ACPI_STATUS(status); 288 return_ACPI_STATUS(status);
@@ -319,35 +310,6 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
319 return_ACPI_STATUS(AE_AML_OPERAND_TYPE); 310 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
320 } 311 }
321 312
322 /*
323 * We must have a buffer that is at least as long as the field
324 * we are writing to. This is because individual fields are
325 * indivisible and partial writes are not supported -- as per
326 * the ACPI specification.
327 */
328 new_buffer = NULL;
329 required_length =
330 ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->common_field.bit_length);
331
332 if (length < required_length) {
333
334 /* We need to create a new buffer */
335
336 new_buffer = ACPI_ALLOCATE_ZEROED(required_length);
337 if (!new_buffer) {
338 return_ACPI_STATUS(AE_NO_MEMORY);
339 }
340
341 /*
342 * Copy the original data to the new buffer, starting
343 * at Byte zero. All unused (upper) bytes of the
344 * buffer will be 0.
345 */
346 ACPI_MEMCPY((char *)new_buffer, (char *)buffer, length);
347 buffer = new_buffer;
348 length = required_length;
349 }
350
351 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD, 313 ACPI_DEBUG_PRINT((ACPI_DB_BFIELD,
352 "FieldWrite [FROM]: Obj %p (%s:%X), Buf %p, ByteLen %X\n", 314 "FieldWrite [FROM]: Obj %p (%s:%X), Buf %p, ByteLen %X\n",
353 source_desc, 315 source_desc,
@@ -366,19 +328,12 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
366 328
367 /* Lock entire transaction if requested */ 329 /* Lock entire transaction if requested */
368 330
369 locked = 331 acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags);
370 acpi_ex_acquire_global_lock(obj_desc->common_field.field_flags);
371 332
372 /* Write to the field */ 333 /* Write to the field */
373 334
374 status = acpi_ex_insert_into_field(obj_desc, buffer, length); 335 status = acpi_ex_insert_into_field(obj_desc, buffer, length);
375 acpi_ex_release_global_lock(locked); 336 acpi_ex_release_global_lock(obj_desc->common_field.field_flags);
376
377 /* Free temporary buffer if we used one */
378
379 if (new_buffer) {
380 ACPI_FREE(new_buffer);
381 }
382 337
383 return_ACPI_STATUS(status); 338 return_ACPI_STATUS(status);
384} 339}
diff --git a/drivers/acpi/executer/exfldio.c b/drivers/acpi/executer/exfldio.c
index 65a48b6170ee..e336b5dc7a50 100644
--- a/drivers/acpi/executer/exfldio.c
+++ b/drivers/acpi/executer/exfldio.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -263,7 +263,8 @@ acpi_ex_access_region(union acpi_operand_object *obj_desc,
263 rgn_desc->region.space_id, 263 rgn_desc->region.space_id,
264 obj_desc->common_field.access_byte_width, 264 obj_desc->common_field.access_byte_width,
265 obj_desc->common_field.base_byte_offset, 265 obj_desc->common_field.base_byte_offset,
266 field_datum_byte_offset, (void *)address)); 266 field_datum_byte_offset, ACPI_CAST_PTR(void,
267 address)));
267 268
268 /* Invoke the appropriate address_space/op_region handler */ 269 /* Invoke the appropriate address_space/op_region handler */
269 270
@@ -805,18 +806,39 @@ acpi_ex_insert_into_field(union acpi_operand_object *obj_desc,
805 u32 datum_count; 806 u32 datum_count;
806 u32 field_datum_count; 807 u32 field_datum_count;
807 u32 i; 808 u32 i;
809 u32 required_length;
810 void *new_buffer;
808 811
809 ACPI_FUNCTION_TRACE(ex_insert_into_field); 812 ACPI_FUNCTION_TRACE(ex_insert_into_field);
810 813
811 /* Validate input buffer */ 814 /* Validate input buffer */
812 815
813 if (buffer_length < 816 new_buffer = NULL;
814 ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->common_field.bit_length)) { 817 required_length =
815 ACPI_ERROR((AE_INFO, 818 ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->common_field.bit_length);
816 "Field size %X (bits) is too large for buffer (%X)", 819 /*
817 obj_desc->common_field.bit_length, buffer_length)); 820 * We must have a buffer that is at least as long as the field
821 * we are writing to. This is because individual fields are
822 * indivisible and partial writes are not supported -- as per
823 * the ACPI specification.
824 */
825 if (buffer_length < required_length) {
818 826
819 return_ACPI_STATUS(AE_BUFFER_OVERFLOW); 827 /* We need to create a new buffer */
828
829 new_buffer = ACPI_ALLOCATE_ZEROED(required_length);
830 if (!new_buffer) {
831 return_ACPI_STATUS(AE_NO_MEMORY);
832 }
833
834 /*
835 * Copy the original data to the new buffer, starting
836 * at Byte zero. All unused (upper) bytes of the
837 * buffer will be 0.
838 */
839 ACPI_MEMCPY((char *)new_buffer, (char *)buffer, buffer_length);
840 buffer = new_buffer;
841 buffer_length = required_length;
820 } 842 }
821 843
822 /* 844 /*
@@ -866,7 +888,7 @@ acpi_ex_insert_into_field(union acpi_operand_object *obj_desc,
866 merged_datum, 888 merged_datum,
867 field_offset); 889 field_offset);
868 if (ACPI_FAILURE(status)) { 890 if (ACPI_FAILURE(status)) {
869 return_ACPI_STATUS(status); 891 goto exit;
870 } 892 }
871 893
872 field_offset += obj_desc->common_field.access_byte_width; 894 field_offset += obj_desc->common_field.access_byte_width;
@@ -924,5 +946,11 @@ acpi_ex_insert_into_field(union acpi_operand_object *obj_desc,
924 mask, merged_datum, 946 mask, merged_datum,
925 field_offset); 947 field_offset);
926 948
949 exit:
950 /* Free temporary buffer if we used one */
951
952 if (new_buffer) {
953 ACPI_FREE(new_buffer);
954 }
927 return_ACPI_STATUS(status); 955 return_ACPI_STATUS(status);
928} 956}
diff --git a/drivers/acpi/executer/exmisc.c b/drivers/acpi/executer/exmisc.c
index f13d1cec2d6d..cc956a5b5267 100644
--- a/drivers/acpi/executer/exmisc.c
+++ b/drivers/acpi/executer/exmisc.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/executer/exmutex.c b/drivers/acpi/executer/exmutex.c
index 6748e3ef0997..c873ab40cd0e 100644
--- a/drivers/acpi/executer/exmutex.c
+++ b/drivers/acpi/executer/exmutex.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -126,6 +126,79 @@ acpi_ex_link_mutex(union acpi_operand_object *obj_desc,
126 126
127/******************************************************************************* 127/*******************************************************************************
128 * 128 *
129 * FUNCTION: acpi_ex_acquire_mutex_object
130 *
131 * PARAMETERS: time_desc - Timeout in milliseconds
132 * obj_desc - Mutex object
133 * Thread - Current thread state
134 *
135 * RETURN: Status
136 *
137 * DESCRIPTION: Acquire an AML mutex, low-level interface. Provides a common
138 * path that supports multiple acquires by the same thread.
139 *
140 * MUTEX: Interpreter must be locked
141 *
142 * NOTE: This interface is called from three places:
143 * 1) From acpi_ex_acquire_mutex, via an AML Acquire() operator
144 * 2) From acpi_ex_acquire_global_lock when an AML Field access requires the
145 * global lock
146 * 3) From the external interface, acpi_acquire_global_lock
147 *
148 ******************************************************************************/
149
150acpi_status
151acpi_ex_acquire_mutex_object(u16 timeout,
152 union acpi_operand_object *obj_desc,
153 acpi_thread_id thread_id)
154{
155 acpi_status status;
156
157 ACPI_FUNCTION_TRACE_PTR(ex_acquire_mutex_object, obj_desc);
158
159 if (!obj_desc) {
160 return_ACPI_STATUS(AE_BAD_PARAMETER);
161 }
162
163 /* Support for multiple acquires by the owning thread */
164
165 if (obj_desc->mutex.thread_id == thread_id) {
166 /*
167 * The mutex is already owned by this thread, just increment the
168 * acquisition depth
169 */
170 obj_desc->mutex.acquisition_depth++;
171 return_ACPI_STATUS(AE_OK);
172 }
173
174 /* Acquire the mutex, wait if necessary. Special case for Global Lock */
175
176 if (obj_desc == acpi_gbl_global_lock_mutex) {
177 status = acpi_ev_acquire_global_lock(timeout);
178 } else {
179 status = acpi_ex_system_wait_mutex(obj_desc->mutex.os_mutex,
180 timeout);
181 }
182
183 if (ACPI_FAILURE(status)) {
184
185 /* Includes failure from a timeout on time_desc */
186
187 return_ACPI_STATUS(status);
188 }
189
190 /* Acquired the mutex: update mutex object */
191
192 obj_desc->mutex.thread_id = thread_id;
193 obj_desc->mutex.acquisition_depth = 1;
194 obj_desc->mutex.original_sync_level = 0;
195 obj_desc->mutex.owner_thread = NULL; /* Used only for AML Acquire() */
196
197 return_ACPI_STATUS(AE_OK);
198}
199
200/*******************************************************************************
201 *
129 * FUNCTION: acpi_ex_acquire_mutex 202 * FUNCTION: acpi_ex_acquire_mutex
130 * 203 *
131 * PARAMETERS: time_desc - Timeout integer 204 * PARAMETERS: time_desc - Timeout integer
@@ -151,7 +224,7 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
151 return_ACPI_STATUS(AE_BAD_PARAMETER); 224 return_ACPI_STATUS(AE_BAD_PARAMETER);
152 } 225 }
153 226
154 /* Sanity check: we must have a valid thread ID */ 227 /* Must have a valid thread ID */
155 228
156 if (!walk_state->thread) { 229 if (!walk_state->thread) {
157 ACPI_ERROR((AE_INFO, 230 ACPI_ERROR((AE_INFO,
@@ -161,7 +234,7 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
161 } 234 }
162 235
163 /* 236 /*
164 * Current Sync must be less than or equal to the sync level of the 237 * Current sync level must be less than or equal to the sync level of the
165 * mutex. This mechanism provides some deadlock prevention 238 * mutex. This mechanism provides some deadlock prevention
166 */ 239 */
167 if (walk_state->thread->current_sync_level > obj_desc->mutex.sync_level) { 240 if (walk_state->thread->current_sync_level > obj_desc->mutex.sync_level) {
@@ -172,51 +245,89 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
172 return_ACPI_STATUS(AE_AML_MUTEX_ORDER); 245 return_ACPI_STATUS(AE_AML_MUTEX_ORDER);
173 } 246 }
174 247
175 /* Support for multiple acquires by the owning thread */ 248 status = acpi_ex_acquire_mutex_object((u16) time_desc->integer.value,
249 obj_desc,
250 walk_state->thread->thread_id);
251 if (ACPI_SUCCESS(status) && obj_desc->mutex.acquisition_depth == 1) {
176 252
177 if (obj_desc->mutex.owner_thread) { 253 /* Save Thread object, original/current sync levels */
178 if (obj_desc->mutex.owner_thread->thread_id == 254
179 walk_state->thread->thread_id) { 255 obj_desc->mutex.owner_thread = walk_state->thread;
180 /* 256 obj_desc->mutex.original_sync_level =
181 * The mutex is already owned by this thread, just increment the 257 walk_state->thread->current_sync_level;
182 * acquisition depth 258 walk_state->thread->current_sync_level =
183 */ 259 obj_desc->mutex.sync_level;
184 obj_desc->mutex.acquisition_depth++; 260
185 return_ACPI_STATUS(AE_OK); 261 /* Link the mutex to the current thread for force-unlock at method exit */
186 } 262
263 acpi_ex_link_mutex(obj_desc, walk_state->thread);
187 } 264 }
188 265
189 /* Acquire the mutex, wait if necessary. Special case for Global Lock */ 266 return_ACPI_STATUS(status);
267}
190 268
191 if (obj_desc->mutex.os_mutex == acpi_gbl_global_lock_mutex) { 269/*******************************************************************************
192 status = 270 *
193 acpi_ev_acquire_global_lock((u16) time_desc->integer.value); 271 * FUNCTION: acpi_ex_release_mutex_object
194 } else { 272 *
195 status = acpi_ex_system_wait_mutex(obj_desc->mutex.os_mutex, 273 * PARAMETERS: obj_desc - The object descriptor for this op
196 (u16) time_desc->integer. 274 *
197 value); 275 * RETURN: Status
276 *
277 * DESCRIPTION: Release a previously acquired Mutex, low level interface.
278 * Provides a common path that supports multiple releases (after
279 * previous multiple acquires) by the same thread.
280 *
281 * MUTEX: Interpreter must be locked
282 *
283 * NOTE: This interface is called from three places:
284 * 1) From acpi_ex_release_mutex, via an AML Acquire() operator
285 * 2) From acpi_ex_release_global_lock when an AML Field access requires the
286 * global lock
287 * 3) From the external interface, acpi_release_global_lock
288 *
289 ******************************************************************************/
290
291acpi_status acpi_ex_release_mutex_object(union acpi_operand_object *obj_desc)
292{
293 acpi_status status = AE_OK;
294
295 ACPI_FUNCTION_TRACE(ex_release_mutex_object);
296
297 if (obj_desc->mutex.acquisition_depth == 0) {
298 return (AE_NOT_ACQUIRED);
198 } 299 }
199 300
200 if (ACPI_FAILURE(status)) { 301 /* Match multiple Acquires with multiple Releases */
201 302
202 /* Includes failure from a timeout on time_desc */ 303 obj_desc->mutex.acquisition_depth--;
304 if (obj_desc->mutex.acquisition_depth != 0) {
203 305
204 return_ACPI_STATUS(status); 306 /* Just decrement the depth and return */
307
308 return_ACPI_STATUS(AE_OK);
205 } 309 }
206 310
207 /* Have the mutex: update mutex and walk info and save the sync_level */ 311 if (obj_desc->mutex.owner_thread) {
208 312
209 obj_desc->mutex.owner_thread = walk_state->thread; 313 /* Unlink the mutex from the owner's list */
210 obj_desc->mutex.acquisition_depth = 1;
211 obj_desc->mutex.original_sync_level =
212 walk_state->thread->current_sync_level;
213 314
214 walk_state->thread->current_sync_level = obj_desc->mutex.sync_level; 315 acpi_ex_unlink_mutex(obj_desc);
316 obj_desc->mutex.owner_thread = NULL;
317 }
215 318
216 /* Link the mutex to the current thread for force-unlock at method exit */ 319 /* Release the mutex, special case for Global Lock */
217 320
218 acpi_ex_link_mutex(obj_desc, walk_state->thread); 321 if (obj_desc == acpi_gbl_global_lock_mutex) {
219 return_ACPI_STATUS(AE_OK); 322 status = acpi_ev_release_global_lock();
323 } else {
324 acpi_os_release_mutex(obj_desc->mutex.os_mutex);
325 }
326
327 /* Clear mutex info */
328
329 obj_desc->mutex.thread_id = 0;
330 return_ACPI_STATUS(status);
220} 331}
221 332
222/******************************************************************************* 333/*******************************************************************************
@@ -253,22 +364,13 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
253 return_ACPI_STATUS(AE_AML_MUTEX_NOT_ACQUIRED); 364 return_ACPI_STATUS(AE_AML_MUTEX_NOT_ACQUIRED);
254 } 365 }
255 366
256 /* Sanity check: we must have a valid thread ID */
257
258 if (!walk_state->thread) {
259 ACPI_ERROR((AE_INFO,
260 "Cannot release Mutex [%4.4s], null thread info",
261 acpi_ut_get_node_name(obj_desc->mutex.node)));
262 return_ACPI_STATUS(AE_AML_INTERNAL);
263 }
264
265 /* 367 /*
266 * The Mutex is owned, but this thread must be the owner. 368 * The Mutex is owned, but this thread must be the owner.
267 * Special case for Global Lock, any thread can release 369 * Special case for Global Lock, any thread can release
268 */ 370 */
269 if ((obj_desc->mutex.owner_thread->thread_id != 371 if ((obj_desc->mutex.owner_thread->thread_id !=
270 walk_state->thread->thread_id) 372 walk_state->thread->thread_id)
271 && (obj_desc->mutex.os_mutex != acpi_gbl_global_lock_mutex)) { 373 && (obj_desc != acpi_gbl_global_lock_mutex)) {
272 ACPI_ERROR((AE_INFO, 374 ACPI_ERROR((AE_INFO,
273 "Thread %lX cannot release Mutex [%4.4s] acquired by thread %lX", 375 "Thread %lX cannot release Mutex [%4.4s] acquired by thread %lX",
274 (unsigned long)walk_state->thread->thread_id, 376 (unsigned long)walk_state->thread->thread_id,
@@ -278,45 +380,37 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
278 return_ACPI_STATUS(AE_AML_NOT_OWNER); 380 return_ACPI_STATUS(AE_AML_NOT_OWNER);
279 } 381 }
280 382
383 /* Must have a valid thread ID */
384
385 if (!walk_state->thread) {
386 ACPI_ERROR((AE_INFO,
387 "Cannot release Mutex [%4.4s], null thread info",
388 acpi_ut_get_node_name(obj_desc->mutex.node)));
389 return_ACPI_STATUS(AE_AML_INTERNAL);
390 }
391
281 /* 392 /*
282 * The sync level of the mutex must be less than or equal to the current 393 * The sync level of the mutex must be less than or equal to the current
283 * sync level 394 * sync level
284 */ 395 */
285 if (obj_desc->mutex.sync_level > walk_state->thread->current_sync_level) { 396 if (obj_desc->mutex.sync_level > walk_state->thread->current_sync_level) {
286 ACPI_ERROR((AE_INFO, 397 ACPI_ERROR((AE_INFO,
287 "Cannot release Mutex [%4.4s], incorrect SyncLevel", 398 "Cannot release Mutex [%4.4s], SyncLevel mismatch: mutex %d current %d",
288 acpi_ut_get_node_name(obj_desc->mutex.node))); 399 acpi_ut_get_node_name(obj_desc->mutex.node),
400 obj_desc->mutex.sync_level,
401 walk_state->thread->current_sync_level));
289 return_ACPI_STATUS(AE_AML_MUTEX_ORDER); 402 return_ACPI_STATUS(AE_AML_MUTEX_ORDER);
290 } 403 }
291 404
292 /* Match multiple Acquires with multiple Releases */ 405 status = acpi_ex_release_mutex_object(obj_desc);
293
294 obj_desc->mutex.acquisition_depth--;
295 if (obj_desc->mutex.acquisition_depth != 0) {
296
297 /* Just decrement the depth and return */
298
299 return_ACPI_STATUS(AE_OK);
300 }
301
302 /* Unlink the mutex from the owner's list */
303 406
304 acpi_ex_unlink_mutex(obj_desc); 407 if (obj_desc->mutex.acquisition_depth == 0) {
305 408
306 /* Release the mutex, special case for Global Lock */ 409 /* Restore the original sync_level */
307 410
308 if (obj_desc->mutex.os_mutex == acpi_gbl_global_lock_mutex) { 411 walk_state->thread->current_sync_level =
309 status = acpi_ev_release_global_lock(); 412 obj_desc->mutex.original_sync_level;
310 } else {
311 acpi_os_release_mutex(obj_desc->mutex.os_mutex);
312 } 413 }
313
314 /* Update the mutex and restore sync_level */
315
316 obj_desc->mutex.owner_thread = NULL;
317 walk_state->thread->current_sync_level =
318 obj_desc->mutex.original_sync_level;
319
320 return_ACPI_STATUS(status); 414 return_ACPI_STATUS(status);
321} 415}
322 416
@@ -357,7 +451,7 @@ void acpi_ex_release_all_mutexes(struct acpi_thread_state *thread)
357 451
358 /* Release the mutex, special case for Global Lock */ 452 /* Release the mutex, special case for Global Lock */
359 453
360 if (obj_desc->mutex.os_mutex == acpi_gbl_global_lock_mutex) { 454 if (obj_desc == acpi_gbl_global_lock_mutex) {
361 455
362 /* Ignore errors */ 456 /* Ignore errors */
363 457
@@ -369,6 +463,7 @@ void acpi_ex_release_all_mutexes(struct acpi_thread_state *thread)
369 /* Mark mutex unowned */ 463 /* Mark mutex unowned */
370 464
371 obj_desc->mutex.owner_thread = NULL; 465 obj_desc->mutex.owner_thread = NULL;
466 obj_desc->mutex.thread_id = 0;
372 467
373 /* Update Thread sync_level (Last mutex is the important one) */ 468 /* Update Thread sync_level (Last mutex is the important one) */
374 469
diff --git a/drivers/acpi/executer/exnames.c b/drivers/acpi/executer/exnames.c
index 308eae52dc05..817e67be3697 100644
--- a/drivers/acpi/executer/exnames.c
+++ b/drivers/acpi/executer/exnames.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/executer/exoparg1.c b/drivers/acpi/executer/exoparg1.c
index 252f10acbbcc..7c3bea575e02 100644
--- a/drivers/acpi/executer/exoparg1.c
+++ b/drivers/acpi/executer/exoparg1.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -121,6 +121,7 @@ acpi_status acpi_ex_opcode_0A_0T_1R(struct acpi_walk_state *walk_state)
121 121
122 if ((ACPI_FAILURE(status)) || walk_state->result_obj) { 122 if ((ACPI_FAILURE(status)) || walk_state->result_obj) {
123 acpi_ut_remove_reference(return_desc); 123 acpi_ut_remove_reference(return_desc);
124 walk_state->result_obj = NULL;
124 } else { 125 } else {
125 /* Save the return value */ 126 /* Save the return value */
126 127
@@ -739,26 +740,38 @@ acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
739 value = acpi_gbl_integer_byte_width; 740 value = acpi_gbl_integer_byte_width;
740 break; 741 break;
741 742
742 case ACPI_TYPE_BUFFER:
743 value = temp_desc->buffer.length;
744 break;
745
746 case ACPI_TYPE_STRING: 743 case ACPI_TYPE_STRING:
747 value = temp_desc->string.length; 744 value = temp_desc->string.length;
748 break; 745 break;
749 746
747 case ACPI_TYPE_BUFFER:
748
749 /* Buffer arguments may not be evaluated at this point */
750
751 status = acpi_ds_get_buffer_arguments(temp_desc);
752 value = temp_desc->buffer.length;
753 break;
754
750 case ACPI_TYPE_PACKAGE: 755 case ACPI_TYPE_PACKAGE:
756
757 /* Package arguments may not be evaluated at this point */
758
759 status = acpi_ds_get_package_arguments(temp_desc);
751 value = temp_desc->package.count; 760 value = temp_desc->package.count;
752 break; 761 break;
753 762
754 default: 763 default:
755 ACPI_ERROR((AE_INFO, 764 ACPI_ERROR((AE_INFO,
756 "Operand is not Buf/Int/Str/Pkg - found type %s", 765 "Operand must be Buffer/Integer/String/Package - found type %s",
757 acpi_ut_get_type_name(type))); 766 acpi_ut_get_type_name(type)));
758 status = AE_AML_OPERAND_TYPE; 767 status = AE_AML_OPERAND_TYPE;
759 goto cleanup; 768 goto cleanup;
760 } 769 }
761 770
771 if (ACPI_FAILURE(status)) {
772 goto cleanup;
773 }
774
762 /* 775 /*
763 * Now that we have the size of the object, create a result 776 * Now that we have the size of the object, create a result
764 * object to hold the value 777 * object to hold the value
diff --git a/drivers/acpi/executer/exoparg2.c b/drivers/acpi/executer/exoparg2.c
index 17e652e65379..8e8bbb6ccebd 100644
--- a/drivers/acpi/executer/exoparg2.c
+++ b/drivers/acpi/executer/exoparg2.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -241,10 +241,6 @@ acpi_status acpi_ex_opcode_2A_2T_1R(struct acpi_walk_state *walk_state)
241 goto cleanup; 241 goto cleanup;
242 } 242 }
243 243
244 /* Return the remainder */
245
246 walk_state->result_obj = return_desc1;
247
248 cleanup: 244 cleanup:
249 /* 245 /*
250 * Since the remainder is not returned indirectly, remove a reference to 246 * Since the remainder is not returned indirectly, remove a reference to
@@ -259,6 +255,12 @@ acpi_status acpi_ex_opcode_2A_2T_1R(struct acpi_walk_state *walk_state)
259 acpi_ut_remove_reference(return_desc1); 255 acpi_ut_remove_reference(return_desc1);
260 } 256 }
261 257
258 /* Save return object (the remainder) on success */
259
260 else {
261 walk_state->result_obj = return_desc1;
262 }
263
262 return_ACPI_STATUS(status); 264 return_ACPI_STATUS(status);
263} 265}
264 266
@@ -490,6 +492,7 @@ acpi_status acpi_ex_opcode_2A_1T_1R(struct acpi_walk_state *walk_state)
490 492
491 if (ACPI_FAILURE(status)) { 493 if (ACPI_FAILURE(status)) {
492 acpi_ut_remove_reference(return_desc); 494 acpi_ut_remove_reference(return_desc);
495 walk_state->result_obj = NULL;
493 } 496 }
494 497
495 return_ACPI_STATUS(status); 498 return_ACPI_STATUS(status);
@@ -583,8 +586,6 @@ acpi_status acpi_ex_opcode_2A_0T_1R(struct acpi_walk_state *walk_state)
583 return_desc->integer.value = ACPI_INTEGER_MAX; 586 return_desc->integer.value = ACPI_INTEGER_MAX;
584 } 587 }
585 588
586 walk_state->result_obj = return_desc;
587
588 cleanup: 589 cleanup:
589 590
590 /* Delete return object on error */ 591 /* Delete return object on error */
@@ -593,5 +594,11 @@ acpi_status acpi_ex_opcode_2A_0T_1R(struct acpi_walk_state *walk_state)
593 acpi_ut_remove_reference(return_desc); 594 acpi_ut_remove_reference(return_desc);
594 } 595 }
595 596
597 /* Save return object on success */
598
599 else {
600 walk_state->result_obj = return_desc;
601 }
602
596 return_ACPI_STATUS(status); 603 return_ACPI_STATUS(status);
597} 604}
diff --git a/drivers/acpi/executer/exoparg3.c b/drivers/acpi/executer/exoparg3.c
index 7fe67cf82cee..9cb4197681af 100644
--- a/drivers/acpi/executer/exoparg3.c
+++ b/drivers/acpi/executer/exoparg3.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -260,6 +260,7 @@ acpi_status acpi_ex_opcode_3A_1T_1R(struct acpi_walk_state *walk_state)
260 260
261 if (ACPI_FAILURE(status) || walk_state->result_obj) { 261 if (ACPI_FAILURE(status) || walk_state->result_obj) {
262 acpi_ut_remove_reference(return_desc); 262 acpi_ut_remove_reference(return_desc);
263 walk_state->result_obj = NULL;
263 } 264 }
264 265
265 /* Set the return object and exit */ 266 /* Set the return object and exit */
diff --git a/drivers/acpi/executer/exoparg6.c b/drivers/acpi/executer/exoparg6.c
index bd80a9cb3d65..67d48737af53 100644
--- a/drivers/acpi/executer/exoparg6.c
+++ b/drivers/acpi/executer/exoparg6.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -322,8 +322,6 @@ acpi_status acpi_ex_opcode_6A_0T_1R(struct acpi_walk_state * walk_state)
322 goto cleanup; 322 goto cleanup;
323 } 323 }
324 324
325 walk_state->result_obj = return_desc;
326
327 cleanup: 325 cleanup:
328 326
329 /* Delete return object on error */ 327 /* Delete return object on error */
@@ -332,5 +330,11 @@ acpi_status acpi_ex_opcode_6A_0T_1R(struct acpi_walk_state * walk_state)
332 acpi_ut_remove_reference(return_desc); 330 acpi_ut_remove_reference(return_desc);
333 } 331 }
334 332
333 /* Save return object on success */
334
335 else {
336 walk_state->result_obj = return_desc;
337 }
338
335 return_ACPI_STATUS(status); 339 return_ACPI_STATUS(status);
336} 340}
diff --git a/drivers/acpi/executer/exprep.c b/drivers/acpi/executer/exprep.c
index efe5d4b461a4..3a2f8cd4c62a 100644
--- a/drivers/acpi/executer/exprep.c
+++ b/drivers/acpi/executer/exprep.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -412,6 +412,7 @@ acpi_ex_prep_common_field_object(union acpi_operand_object *obj_desc,
412acpi_status acpi_ex_prep_field_value(struct acpi_create_field_info *info) 412acpi_status acpi_ex_prep_field_value(struct acpi_create_field_info *info)
413{ 413{
414 union acpi_operand_object *obj_desc; 414 union acpi_operand_object *obj_desc;
415 union acpi_operand_object *second_desc = NULL;
415 u32 type; 416 u32 type;
416 acpi_status status; 417 acpi_status status;
417 418
@@ -494,6 +495,20 @@ acpi_status acpi_ex_prep_field_value(struct acpi_create_field_info *info)
494 obj_desc->field.access_byte_width, 495 obj_desc->field.access_byte_width,
495 obj_desc->bank_field.region_obj, 496 obj_desc->bank_field.region_obj,
496 obj_desc->bank_field.bank_obj)); 497 obj_desc->bank_field.bank_obj));
498
499 /*
500 * Remember location in AML stream of the field unit
501 * opcode and operands -- since the bank_value
502 * operands must be evaluated.
503 */
504 second_desc = obj_desc->common.next_object;
505 second_desc->extra.aml_start =
506 ((union acpi_parse_object *)(info->data_register_node))->
507 named.data;
508 second_desc->extra.aml_length =
509 ((union acpi_parse_object *)(info->data_register_node))->
510 named.length;
511
497 break; 512 break;
498 513
499 case ACPI_TYPE_LOCAL_INDEX_FIELD: 514 case ACPI_TYPE_LOCAL_INDEX_FIELD:
diff --git a/drivers/acpi/executer/exregion.c b/drivers/acpi/executer/exregion.c
index 3f51b7e84a17..7cd8bb54fa01 100644
--- a/drivers/acpi/executer/exregion.c
+++ b/drivers/acpi/executer/exregion.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -160,7 +160,7 @@ acpi_ex_system_memory_space_handler(u32 function,
160 if (!mem_info->mapped_logical_address) { 160 if (!mem_info->mapped_logical_address) {
161 ACPI_ERROR((AE_INFO, 161 ACPI_ERROR((AE_INFO,
162 "Could not map memory at %8.8X%8.8X, size %X", 162 "Could not map memory at %8.8X%8.8X, size %X",
163 ACPI_FORMAT_UINT64(address), 163 ACPI_FORMAT_NATIVE_UINT(address),
164 (u32) window_size)); 164 (u32) window_size));
165 mem_info->mapped_length = 0; 165 mem_info->mapped_length = 0;
166 return_ACPI_STATUS(AE_NO_MEMORY); 166 return_ACPI_STATUS(AE_NO_MEMORY);
@@ -182,7 +182,8 @@ acpi_ex_system_memory_space_handler(u32 function,
182 182
183 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 183 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
184 "System-Memory (width %d) R/W %d Address=%8.8X%8.8X\n", 184 "System-Memory (width %d) R/W %d Address=%8.8X%8.8X\n",
185 bit_width, function, ACPI_FORMAT_UINT64(address))); 185 bit_width, function,
186 ACPI_FORMAT_NATIVE_UINT(address)));
186 187
187 /* 188 /*
188 * Perform the memory read or write 189 * Perform the memory read or write
@@ -284,7 +285,8 @@ acpi_ex_system_io_space_handler(u32 function,
284 285
285 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 286 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
286 "System-IO (width %d) R/W %d Address=%8.8X%8.8X\n", 287 "System-IO (width %d) R/W %d Address=%8.8X%8.8X\n",
287 bit_width, function, ACPI_FORMAT_UINT64(address))); 288 bit_width, function,
289 ACPI_FORMAT_NATIVE_UINT(address)));
288 290
289 /* Decode the function parameter */ 291 /* Decode the function parameter */
290 292
diff --git a/drivers/acpi/executer/exresnte.c b/drivers/acpi/executer/exresnte.c
index 2b3a01cc4929..5596f42c9676 100644
--- a/drivers/acpi/executer/exresnte.c
+++ b/drivers/acpi/executer/exresnte.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -116,9 +116,11 @@ acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr,
116 * Several object types require no further processing: 116 * Several object types require no further processing:
117 * 1) Device/Thermal objects don't have a "real" subobject, return the Node 117 * 1) Device/Thermal objects don't have a "real" subobject, return the Node
118 * 2) Method locals and arguments have a pseudo-Node 118 * 2) Method locals and arguments have a pseudo-Node
119 * 3) 10/2007: Added method type to assist with Package construction.
119 */ 120 */
120 if ((entry_type == ACPI_TYPE_DEVICE) || 121 if ((entry_type == ACPI_TYPE_DEVICE) ||
121 (entry_type == ACPI_TYPE_THERMAL) || 122 (entry_type == ACPI_TYPE_THERMAL) ||
123 (entry_type == ACPI_TYPE_METHOD) ||
122 (node->flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) { 124 (node->flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) {
123 return_ACPI_STATUS(AE_OK); 125 return_ACPI_STATUS(AE_OK);
124 } 126 }
@@ -214,7 +216,6 @@ acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr,
214 /* For these objects, just return the object attached to the Node */ 216 /* For these objects, just return the object attached to the Node */
215 217
216 case ACPI_TYPE_MUTEX: 218 case ACPI_TYPE_MUTEX:
217 case ACPI_TYPE_METHOD:
218 case ACPI_TYPE_POWER: 219 case ACPI_TYPE_POWER:
219 case ACPI_TYPE_PROCESSOR: 220 case ACPI_TYPE_PROCESSOR:
220 case ACPI_TYPE_EVENT: 221 case ACPI_TYPE_EVENT:
@@ -238,13 +239,12 @@ acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr,
238 case ACPI_TYPE_LOCAL_REFERENCE: 239 case ACPI_TYPE_LOCAL_REFERENCE:
239 240
240 switch (source_desc->reference.opcode) { 241 switch (source_desc->reference.opcode) {
241 case AML_LOAD_OP: 242 case AML_LOAD_OP: /* This is a ddb_handle */
243 case AML_REF_OF_OP:
244 case AML_INDEX_OP:
242 245
243 /* This is a ddb_handle */
244 /* Return an additional reference to the object */ 246 /* Return an additional reference to the object */
245 247
246 case AML_REF_OF_OP:
247
248 obj_desc = source_desc; 248 obj_desc = source_desc;
249 acpi_ut_add_reference(obj_desc); 249 acpi_ut_add_reference(obj_desc);
250 break; 250 break;
diff --git a/drivers/acpi/executer/exresolv.c b/drivers/acpi/executer/exresolv.c
index 6c64e55dab0e..b35f7c817acf 100644
--- a/drivers/acpi/executer/exresolv.c
+++ b/drivers/acpi/executer/exresolv.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -140,7 +140,6 @@ acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr,
140{ 140{
141 acpi_status status = AE_OK; 141 acpi_status status = AE_OK;
142 union acpi_operand_object *stack_desc; 142 union acpi_operand_object *stack_desc;
143 void *temp_node;
144 union acpi_operand_object *obj_desc = NULL; 143 union acpi_operand_object *obj_desc = NULL;
145 u16 opcode; 144 u16 opcode;
146 145
@@ -156,23 +155,6 @@ acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr,
156 opcode = stack_desc->reference.opcode; 155 opcode = stack_desc->reference.opcode;
157 156
158 switch (opcode) { 157 switch (opcode) {
159 case AML_NAME_OP:
160
161 /*
162 * Convert name reference to a namespace node
163 * Then, acpi_ex_resolve_node_to_value can be used to get the value
164 */
165 temp_node = stack_desc->reference.object;
166
167 /* Delete the Reference Object */
168
169 acpi_ut_remove_reference(stack_desc);
170
171 /* Return the namespace node */
172
173 (*stack_ptr) = temp_node;
174 break;
175
176 case AML_LOCAL_OP: 158 case AML_LOCAL_OP:
177 case AML_ARG_OP: 159 case AML_ARG_OP:
178 160
@@ -207,15 +189,25 @@ acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr,
207 switch (stack_desc->reference.target_type) { 189 switch (stack_desc->reference.target_type) {
208 case ACPI_TYPE_BUFFER_FIELD: 190 case ACPI_TYPE_BUFFER_FIELD:
209 191
210 /* Just return - leave the Reference on the stack */ 192 /* Just return - do not dereference */
211 break; 193 break;
212 194
213 case ACPI_TYPE_PACKAGE: 195 case ACPI_TYPE_PACKAGE:
214 196
197 /* If method call or copy_object - do not dereference */
198
199 if ((walk_state->opcode ==
200 AML_INT_METHODCALL_OP)
201 || (walk_state->opcode == AML_COPY_OP)) {
202 break;
203 }
204
205 /* Otherwise, dereference the package_index to a package element */
206
215 obj_desc = *stack_desc->reference.where; 207 obj_desc = *stack_desc->reference.where;
216 if (obj_desc) { 208 if (obj_desc) {
217 /* 209 /*
218 * Valid obj descriptor, copy pointer to return value 210 * Valid object descriptor, copy pointer to return value
219 * (i.e., dereference the package index) 211 * (i.e., dereference the package index)
220 * Delete the ref object, increment the returned object 212 * Delete the ref object, increment the returned object
221 */ 213 */
@@ -224,11 +216,11 @@ acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr,
224 *stack_ptr = obj_desc; 216 *stack_ptr = obj_desc;
225 } else { 217 } else {
226 /* 218 /*
227 * A NULL object descriptor means an unitialized element of 219 * A NULL object descriptor means an uninitialized element of
228 * the package, can't dereference it 220 * the package, can't dereference it
229 */ 221 */
230 ACPI_ERROR((AE_INFO, 222 ACPI_ERROR((AE_INFO,
231 "Attempt to deref an Index to NULL pkg element Idx=%p", 223 "Attempt to dereference an Index to NULL package element Idx=%p",
232 stack_desc)); 224 stack_desc));
233 status = AE_AML_UNINITIALIZED_ELEMENT; 225 status = AE_AML_UNINITIALIZED_ELEMENT;
234 } 226 }
@@ -239,7 +231,7 @@ acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr,
239 /* Invalid reference object */ 231 /* Invalid reference object */
240 232
241 ACPI_ERROR((AE_INFO, 233 ACPI_ERROR((AE_INFO,
242 "Unknown TargetType %X in Index/Reference obj %p", 234 "Unknown TargetType %X in Index/Reference object %p",
243 stack_desc->reference.target_type, 235 stack_desc->reference.target_type,
244 stack_desc)); 236 stack_desc));
245 status = AE_AML_INTERNAL; 237 status = AE_AML_INTERNAL;
@@ -251,7 +243,7 @@ acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr,
251 case AML_DEBUG_OP: 243 case AML_DEBUG_OP:
252 case AML_LOAD_OP: 244 case AML_LOAD_OP:
253 245
254 /* Just leave the object as-is */ 246 /* Just leave the object as-is, do not dereference */
255 247
256 break; 248 break;
257 249
@@ -390,10 +382,10 @@ acpi_ex_resolve_multiple(struct acpi_walk_state *walk_state,
390 } 382 }
391 383
392 /* 384 /*
393 * For reference objects created via the ref_of or Index operators, 385 * For reference objects created via the ref_of, Index, or Load/load_table
394 * we need to get to the base object (as per the ACPI specification 386 * operators, we need to get to the base object (as per the ACPI
395 * of the object_type and size_of operators). This means traversing 387 * specification of the object_type and size_of operators). This means
396 * the list of possibly many nested references. 388 * traversing the list of possibly many nested references.
397 */ 389 */
398 while (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_LOCAL_REFERENCE) { 390 while (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_LOCAL_REFERENCE) {
399 switch (obj_desc->reference.opcode) { 391 switch (obj_desc->reference.opcode) {
@@ -463,6 +455,11 @@ acpi_ex_resolve_multiple(struct acpi_walk_state *walk_state,
463 } 455 }
464 break; 456 break;
465 457
458 case AML_LOAD_OP:
459
460 type = ACPI_TYPE_DDB_HANDLE;
461 goto exit;
462
466 case AML_LOCAL_OP: 463 case AML_LOCAL_OP:
467 case AML_ARG_OP: 464 case AML_ARG_OP:
468 465
diff --git a/drivers/acpi/executer/exresop.c b/drivers/acpi/executer/exresop.c
index 09d897b3f6d5..73e29e566a70 100644
--- a/drivers/acpi/executer/exresop.c
+++ b/drivers/acpi/executer/exresop.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -137,7 +137,6 @@ acpi_ex_resolve_operands(u16 opcode,
137 union acpi_operand_object *obj_desc; 137 union acpi_operand_object *obj_desc;
138 acpi_status status = AE_OK; 138 acpi_status status = AE_OK;
139 u8 object_type; 139 u8 object_type;
140 void *temp_node;
141 u32 arg_types; 140 u32 arg_types;
142 const struct acpi_opcode_info *op_info; 141 const struct acpi_opcode_info *op_info;
143 u32 this_arg_type; 142 u32 this_arg_type;
@@ -239,7 +238,6 @@ acpi_ex_resolve_operands(u16 opcode,
239 238
240 /*lint -fallthrough */ 239 /*lint -fallthrough */
241 240
242 case AML_NAME_OP:
243 case AML_INDEX_OP: 241 case AML_INDEX_OP:
244 case AML_REF_OF_OP: 242 case AML_REF_OF_OP:
245 case AML_ARG_OP: 243 case AML_ARG_OP:
@@ -332,15 +330,6 @@ acpi_ex_resolve_operands(u16 opcode,
332 if (ACPI_FAILURE(status)) { 330 if (ACPI_FAILURE(status)) {
333 return_ACPI_STATUS(status); 331 return_ACPI_STATUS(status);
334 } 332 }
335
336 if (obj_desc->reference.opcode == AML_NAME_OP) {
337
338 /* Convert a named reference to the actual named object */
339
340 temp_node = obj_desc->reference.object;
341 acpi_ut_remove_reference(obj_desc);
342 (*stack_ptr) = temp_node;
343 }
344 goto next_operand; 333 goto next_operand;
345 334
346 case ARGI_DATAREFOBJ: /* Store operator only */ 335 case ARGI_DATAREFOBJ: /* Store operator only */
diff --git a/drivers/acpi/executer/exstore.c b/drivers/acpi/executer/exstore.c
index f4b69a637820..76c875bc3154 100644
--- a/drivers/acpi/executer/exstore.c
+++ b/drivers/acpi/executer/exstore.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -84,8 +84,12 @@ acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
84 84
85 ACPI_FUNCTION_TRACE_PTR(ex_do_debug_object, source_desc); 85 ACPI_FUNCTION_TRACE_PTR(ex_do_debug_object, source_desc);
86 86
87 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[ACPI Debug] %*s", 87 /* Print line header as long as we are not in the middle of an object display */
88 level, " ")); 88
89 if (!((level > 0) && index == 0)) {
90 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[ACPI Debug] %*s",
91 level, " "));
92 }
89 93
90 /* Display index for package output only */ 94 /* Display index for package output only */
91 95
@@ -95,12 +99,12 @@ acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
95 } 99 }
96 100
97 if (!source_desc) { 101 if (!source_desc) {
98 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "<Null Object>\n")); 102 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[Null Object]\n"));
99 return_VOID; 103 return_VOID;
100 } 104 }
101 105
102 if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) == ACPI_DESC_TYPE_OPERAND) { 106 if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) == ACPI_DESC_TYPE_OPERAND) {
103 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "%s: ", 107 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "%s ",
104 acpi_ut_get_object_type_name 108 acpi_ut_get_object_type_name
105 (source_desc))); 109 (source_desc)));
106 110
@@ -123,6 +127,8 @@ acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
123 return_VOID; 127 return_VOID;
124 } 128 }
125 129
130 /* source_desc is of type ACPI_DESC_TYPE_OPERAND */
131
126 switch (ACPI_GET_OBJECT_TYPE(source_desc)) { 132 switch (ACPI_GET_OBJECT_TYPE(source_desc)) {
127 case ACPI_TYPE_INTEGER: 133 case ACPI_TYPE_INTEGER:
128 134
@@ -147,7 +153,7 @@ acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
147 (u32) source_desc->buffer.length)); 153 (u32) source_desc->buffer.length));
148 ACPI_DUMP_BUFFER(source_desc->buffer.pointer, 154 ACPI_DUMP_BUFFER(source_desc->buffer.pointer,
149 (source_desc->buffer.length < 155 (source_desc->buffer.length <
150 32) ? source_desc->buffer.length : 32); 156 256) ? source_desc->buffer.length : 256);
151 break; 157 break;
152 158
153 case ACPI_TYPE_STRING: 159 case ACPI_TYPE_STRING:
@@ -160,7 +166,7 @@ acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
160 case ACPI_TYPE_PACKAGE: 166 case ACPI_TYPE_PACKAGE:
161 167
162 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, 168 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
163 "[0x%.2X Elements]\n", 169 "[Contains 0x%.2X Elements]\n",
164 source_desc->package.count)); 170 source_desc->package.count));
165 171
166 /* Output the entire contents of the package */ 172 /* Output the entire contents of the package */
@@ -180,12 +186,59 @@ acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
180 (source_desc->reference.opcode), 186 (source_desc->reference.opcode),
181 source_desc->reference.offset)); 187 source_desc->reference.offset));
182 } else { 188 } else {
183 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[%s]\n", 189 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[%s]",
184 acpi_ps_get_opcode_name 190 acpi_ps_get_opcode_name
185 (source_desc->reference.opcode))); 191 (source_desc->reference.opcode)));
186 } 192 }
187 193
188 if (source_desc->reference.object) { 194 if (source_desc->reference.opcode == AML_LOAD_OP) { /* Load and load_table */
195 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
196 " Table OwnerId %p\n",
197 source_desc->reference.object));
198 break;
199 }
200
201 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, " "));
202
203 /* Check for valid node first, then valid object */
204
205 if (source_desc->reference.node) {
206 if (ACPI_GET_DESCRIPTOR_TYPE
207 (source_desc->reference.node) !=
208 ACPI_DESC_TYPE_NAMED) {
209 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
210 " %p - Not a valid namespace node\n",
211 source_desc->reference.
212 node));
213 } else {
214 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
215 "Node %p [%4.4s] ",
216 source_desc->reference.
217 node,
218 (source_desc->reference.
219 node)->name.ascii));
220
221 switch ((source_desc->reference.node)->type) {
222
223 /* These types have no attached object */
224
225 case ACPI_TYPE_DEVICE:
226 acpi_os_printf("Device\n");
227 break;
228
229 case ACPI_TYPE_THERMAL:
230 acpi_os_printf("Thermal Zone\n");
231 break;
232
233 default:
234 acpi_ex_do_debug_object((source_desc->
235 reference.
236 node)->object,
237 level + 4, 0);
238 break;
239 }
240 }
241 } else if (source_desc->reference.object) {
189 if (ACPI_GET_DESCRIPTOR_TYPE 242 if (ACPI_GET_DESCRIPTOR_TYPE
190 (source_desc->reference.object) == 243 (source_desc->reference.object) ==
191 ACPI_DESC_TYPE_NAMED) { 244 ACPI_DESC_TYPE_NAMED) {
@@ -198,18 +251,13 @@ acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
198 acpi_ex_do_debug_object(source_desc->reference. 251 acpi_ex_do_debug_object(source_desc->reference.
199 object, level + 4, 0); 252 object, level + 4, 0);
200 } 253 }
201 } else if (source_desc->reference.node) {
202 acpi_ex_do_debug_object((source_desc->reference.node)->
203 object, level + 4, 0);
204 } 254 }
205 break; 255 break;
206 256
207 default: 257 default:
208 258
209 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "%p %s\n", 259 ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "%p\n",
210 source_desc, 260 source_desc));
211 acpi_ut_get_object_type_name
212 (source_desc)));
213 break; 261 break;
214 } 262 }
215 263
@@ -313,7 +361,6 @@ acpi_ex_store(union acpi_operand_object *source_desc,
313 * 4) Store to the debug object 361 * 4) Store to the debug object
314 */ 362 */
315 switch (ref_desc->reference.opcode) { 363 switch (ref_desc->reference.opcode) {
316 case AML_NAME_OP:
317 case AML_REF_OF_OP: 364 case AML_REF_OF_OP:
318 365
319 /* Storing an object into a Name "container" */ 366 /* Storing an object into a Name "container" */
@@ -415,11 +462,24 @@ acpi_ex_store_object_to_index(union acpi_operand_object *source_desc,
415 */ 462 */
416 obj_desc = *(index_desc->reference.where); 463 obj_desc = *(index_desc->reference.where);
417 464
418 status = 465 if (ACPI_GET_OBJECT_TYPE(source_desc) ==
419 acpi_ut_copy_iobject_to_iobject(source_desc, &new_desc, 466 ACPI_TYPE_LOCAL_REFERENCE
420 walk_state); 467 && source_desc->reference.opcode == AML_LOAD_OP) {
421 if (ACPI_FAILURE(status)) { 468
422 return_ACPI_STATUS(status); 469 /* This is a DDBHandle, just add a reference to it */
470
471 acpi_ut_add_reference(source_desc);
472 new_desc = source_desc;
473 } else {
474 /* Normal object, copy it */
475
476 status =
477 acpi_ut_copy_iobject_to_iobject(source_desc,
478 &new_desc,
479 walk_state);
480 if (ACPI_FAILURE(status)) {
481 return_ACPI_STATUS(status);
482 }
423 } 483 }
424 484
425 if (obj_desc) { 485 if (obj_desc) {
@@ -571,10 +631,17 @@ acpi_ex_store_object_to_node(union acpi_operand_object *source_desc,
571 631
572 /* If no implicit conversion, drop into the default case below */ 632 /* If no implicit conversion, drop into the default case below */
573 633
574 if ((!implicit_conversion) || (walk_state->opcode == AML_COPY_OP)) { 634 if ((!implicit_conversion) ||
575 635 ((walk_state->opcode == AML_COPY_OP) &&
576 /* Force execution of default (no implicit conversion) */ 636 (target_type != ACPI_TYPE_LOCAL_REGION_FIELD) &&
577 637 (target_type != ACPI_TYPE_LOCAL_BANK_FIELD) &&
638 (target_type != ACPI_TYPE_LOCAL_INDEX_FIELD))) {
639 /*
640 * Force execution of default (no implicit conversion). Note:
641 * copy_object does not perform an implicit conversion, as per the ACPI
642 * spec -- except in case of region/bank/index fields -- because these
643 * objects must retain their original type permanently.
644 */
578 target_type = ACPI_TYPE_ANY; 645 target_type = ACPI_TYPE_ANY;
579 } 646 }
580 647
diff --git a/drivers/acpi/executer/exstoren.c b/drivers/acpi/executer/exstoren.c
index 1d622c625c64..a6d2168b81f9 100644
--- a/drivers/acpi/executer/exstoren.c
+++ b/drivers/acpi/executer/exstoren.c
@@ -7,7 +7,7 @@
7 *****************************************************************************/ 7 *****************************************************************************/
8 8
9/* 9/*
10 * Copyright (C) 2000 - 2007, R. Byron Moore 10 * Copyright (C) 2000 - 2008, Intel Corp.
11 * All rights reserved. 11 * All rights reserved.
12 * 12 *
13 * Redistribution and use in source and binary forms, with or without 13 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/executer/exstorob.c b/drivers/acpi/executer/exstorob.c
index 8233d40178ee..9a75ff09fb0c 100644
--- a/drivers/acpi/executer/exstorob.c
+++ b/drivers/acpi/executer/exstorob.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/executer/exsystem.c b/drivers/acpi/executer/exsystem.c
index 9460baff3032..68990f1df371 100644
--- a/drivers/acpi/executer/exsystem.c
+++ b/drivers/acpi/executer/exsystem.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -44,7 +44,6 @@
44 44
45#include <acpi/acpi.h> 45#include <acpi/acpi.h>
46#include <acpi/acinterp.h> 46#include <acpi/acinterp.h>
47#include <acpi/acevents.h>
48 47
49#define _COMPONENT ACPI_EXECUTER 48#define _COMPONENT ACPI_EXECUTER
50ACPI_MODULE_NAME("exsystem") 49ACPI_MODULE_NAME("exsystem")
diff --git a/drivers/acpi/executer/exutils.c b/drivers/acpi/executer/exutils.c
index 6b0aeccbb69b..86c03880b523 100644
--- a/drivers/acpi/executer/exutils.c
+++ b/drivers/acpi/executer/exutils.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -61,7 +61,6 @@
61#include <acpi/acpi.h> 61#include <acpi/acpi.h>
62#include <acpi/acinterp.h> 62#include <acpi/acinterp.h>
63#include <acpi/amlcode.h> 63#include <acpi/amlcode.h>
64#include <acpi/acevents.h>
65 64
66#define _COMPONENT ACPI_EXECUTER 65#define _COMPONENT ACPI_EXECUTER
67ACPI_MODULE_NAME("exutils") 66ACPI_MODULE_NAME("exutils")
@@ -217,9 +216,10 @@ void acpi_ex_truncate_for32bit_table(union acpi_operand_object *obj_desc)
217 216
218 /* 217 /*
219 * Object must be a valid number and we must be executing 218 * Object must be a valid number and we must be executing
220 * a control method 219 * a control method. NS node could be there for AML_INT_NAMEPATH_OP.
221 */ 220 */
222 if ((!obj_desc) || 221 if ((!obj_desc) ||
222 (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) != ACPI_DESC_TYPE_OPERAND) ||
223 (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_INTEGER)) { 223 (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_INTEGER)) {
224 return; 224 return;
225 } 225 }
@@ -240,72 +240,73 @@ void acpi_ex_truncate_for32bit_table(union acpi_operand_object *obj_desc)
240 * PARAMETERS: field_flags - Flags with Lock rule: 240 * PARAMETERS: field_flags - Flags with Lock rule:
241 * always_lock or never_lock 241 * always_lock or never_lock
242 * 242 *
243 * RETURN: TRUE/FALSE indicating whether the lock was actually acquired 243 * RETURN: None
244 * 244 *
245 * DESCRIPTION: Obtain the global lock and keep track of this fact via two 245 * DESCRIPTION: Obtain the ACPI hardware Global Lock, only if the field
246 * methods. A global variable keeps the state of the lock, and 246 * flags specifiy that it is to be obtained before field access.
247 * the state is returned to the caller.
248 * 247 *
249 ******************************************************************************/ 248 ******************************************************************************/
250 249
251u8 acpi_ex_acquire_global_lock(u32 field_flags) 250void acpi_ex_acquire_global_lock(u32 field_flags)
252{ 251{
253 u8 locked = FALSE;
254 acpi_status status; 252 acpi_status status;
255 253
256 ACPI_FUNCTION_TRACE(ex_acquire_global_lock); 254 ACPI_FUNCTION_TRACE(ex_acquire_global_lock);
257 255
258 /* Only attempt lock if the always_lock bit is set */ 256 /* Only use the lock if the always_lock bit is set */
257
258 if (!(field_flags & AML_FIELD_LOCK_RULE_MASK)) {
259 return_VOID;
260 }
259 261
260 if (field_flags & AML_FIELD_LOCK_RULE_MASK) { 262 /* Attempt to get the global lock, wait forever */
261 263
262 /* We should attempt to get the lock, wait forever */ 264 status = acpi_ex_acquire_mutex_object(ACPI_WAIT_FOREVER,
265 acpi_gbl_global_lock_mutex,
266 acpi_os_get_thread_id());
263 267
264 status = acpi_ev_acquire_global_lock(ACPI_WAIT_FOREVER); 268 if (ACPI_FAILURE(status)) {
265 if (ACPI_SUCCESS(status)) { 269 ACPI_EXCEPTION((AE_INFO, status,
266 locked = TRUE; 270 "Could not acquire Global Lock"));
267 } else {
268 ACPI_EXCEPTION((AE_INFO, status,
269 "Could not acquire Global Lock"));
270 }
271 } 271 }
272 272
273 return_UINT8(locked); 273 return_VOID;
274} 274}
275 275
276/******************************************************************************* 276/*******************************************************************************
277 * 277 *
278 * FUNCTION: acpi_ex_release_global_lock 278 * FUNCTION: acpi_ex_release_global_lock
279 * 279 *
280 * PARAMETERS: locked_by_me - Return value from corresponding call to 280 * PARAMETERS: field_flags - Flags with Lock rule:
281 * acquire_global_lock. 281 * always_lock or never_lock
282 * 282 *
283 * RETURN: None 283 * RETURN: None
284 * 284 *
285 * DESCRIPTION: Release the global lock if it is locked. 285 * DESCRIPTION: Release the ACPI hardware Global Lock
286 * 286 *
287 ******************************************************************************/ 287 ******************************************************************************/
288 288
289void acpi_ex_release_global_lock(u8 locked_by_me) 289void acpi_ex_release_global_lock(u32 field_flags)
290{ 290{
291 acpi_status status; 291 acpi_status status;
292 292
293 ACPI_FUNCTION_TRACE(ex_release_global_lock); 293 ACPI_FUNCTION_TRACE(ex_release_global_lock);
294 294
295 /* Only attempt unlock if the caller locked it */ 295 /* Only use the lock if the always_lock bit is set */
296 296
297 if (locked_by_me) { 297 if (!(field_flags & AML_FIELD_LOCK_RULE_MASK)) {
298 return_VOID;
299 }
298 300
299 /* OK, now release the lock */ 301 /* Release the global lock */
300 302
301 status = acpi_ev_release_global_lock(); 303 status = acpi_ex_release_mutex_object(acpi_gbl_global_lock_mutex);
302 if (ACPI_FAILURE(status)) { 304 if (ACPI_FAILURE(status)) {
303 305
304 /* Report the error, but there isn't much else we can do */ 306 /* Report the error, but there isn't much else we can do */
305 307
306 ACPI_EXCEPTION((AE_INFO, status, 308 ACPI_EXCEPTION((AE_INFO, status,
307 "Could not release ACPI Global Lock")); 309 "Could not release Global Lock"));
308 }
309 } 310 }
310 311
311 return_VOID; 312 return_VOID;
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
index 194077ab9b85..6cf10cbc1eee 100644
--- a/drivers/acpi/fan.c
+++ b/drivers/acpi/fan.c
@@ -256,24 +256,23 @@ static int acpi_fan_add(struct acpi_device *device)
256 result = PTR_ERR(cdev); 256 result = PTR_ERR(cdev);
257 goto end; 257 goto end;
258 } 258 }
259 if (cdev) { 259
260 printk(KERN_INFO PREFIX 260 printk(KERN_INFO PREFIX
261 "%s is registered as cooling_device%d\n", 261 "%s is registered as cooling_device%d\n",
262 device->dev.bus_id, cdev->id); 262 device->dev.bus_id, cdev->id);
263 263
264 acpi_driver_data(device) = cdev; 264 acpi_driver_data(device) = cdev;
265 result = sysfs_create_link(&device->dev.kobj, 265 result = sysfs_create_link(&device->dev.kobj,
266 &cdev->device.kobj, 266 &cdev->device.kobj,
267 "thermal_cooling"); 267 "thermal_cooling");
268 if (result) 268 if (result)
269 return result; 269 printk(KERN_ERR PREFIX "Create sysfs link\n");
270 270
271 result = sysfs_create_link(&cdev->device.kobj, 271 result = sysfs_create_link(&cdev->device.kobj,
272 &device->dev.kobj, 272 &device->dev.kobj,
273 "device"); 273 "device");
274 if (result) 274 if (result)
275 return result; 275 printk(KERN_ERR PREFIX "Create sysfs link\n");
276 }
277 276
278 result = acpi_fan_add_fs(device); 277 result = acpi_fan_add_fs(device);
279 if (result) 278 if (result)
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index eda0978b57c6..06f8634fe58b 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -142,6 +142,7 @@ EXPORT_SYMBOL(acpi_get_physical_device);
142 142
143static int acpi_bind_one(struct device *dev, acpi_handle handle) 143static int acpi_bind_one(struct device *dev, acpi_handle handle)
144{ 144{
145 struct acpi_device *acpi_dev;
145 acpi_status status; 146 acpi_status status;
146 147
147 if (dev->archdata.acpi_handle) { 148 if (dev->archdata.acpi_handle) {
@@ -157,6 +158,16 @@ static int acpi_bind_one(struct device *dev, acpi_handle handle)
157 } 158 }
158 dev->archdata.acpi_handle = handle; 159 dev->archdata.acpi_handle = handle;
159 160
161 status = acpi_bus_get_device(handle, &acpi_dev);
162 if (!ACPI_FAILURE(status)) {
163 int ret;
164
165 ret = sysfs_create_link(&dev->kobj, &acpi_dev->dev.kobj,
166 "firmware_node");
167 ret = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj,
168 "physical_node");
169 }
170
160 return 0; 171 return 0;
161} 172}
162 173
@@ -165,8 +176,17 @@ static int acpi_unbind_one(struct device *dev)
165 if (!dev->archdata.acpi_handle) 176 if (!dev->archdata.acpi_handle)
166 return 0; 177 return 0;
167 if (dev == acpi_get_physical_device(dev->archdata.acpi_handle)) { 178 if (dev == acpi_get_physical_device(dev->archdata.acpi_handle)) {
179 struct acpi_device *acpi_dev;
180
168 /* acpi_get_physical_device increase refcnt by one */ 181 /* acpi_get_physical_device increase refcnt by one */
169 put_device(dev); 182 put_device(dev);
183
184 if (!acpi_bus_get_device(dev->archdata.acpi_handle,
185 &acpi_dev)) {
186 sysfs_remove_link(&dev->kobj, "firmware_node");
187 sysfs_remove_link(&acpi_dev->dev.kobj, "physical_node");
188 }
189
170 acpi_detach_data(dev->archdata.acpi_handle, 190 acpi_detach_data(dev->archdata.acpi_handle,
171 acpi_glue_data_handler); 191 acpi_glue_data_handler);
172 dev->archdata.acpi_handle = NULL; 192 dev->archdata.acpi_handle = NULL;
diff --git a/drivers/acpi/hardware/hwacpi.c b/drivers/acpi/hardware/hwacpi.c
index 6031ca13dd2f..816894ea839e 100644
--- a/drivers/acpi/hardware/hwacpi.c
+++ b/drivers/acpi/hardware/hwacpi.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/hardware/hwgpe.c b/drivers/acpi/hardware/hwgpe.c
index 117a05cadaaa..14bc4f456ae8 100644
--- a/drivers/acpi/hardware/hwgpe.c
+++ b/drivers/acpi/hardware/hwgpe.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/hardware/hwregs.c b/drivers/acpi/hardware/hwregs.c
index 73f9c5fb1ba7..ddf792adcf96 100644
--- a/drivers/acpi/hardware/hwregs.c
+++ b/drivers/acpi/hardware/hwregs.c
@@ -7,7 +7,7 @@
7 ******************************************************************************/ 7 ******************************************************************************/
8 8
9/* 9/*
10 * Copyright (C) 2000 - 2007, R. Byron Moore 10 * Copyright (C) 2000 - 2008, Intel Corp.
11 * All rights reserved. 11 * All rights reserved.
12 * 12 *
13 * Redistribution and use in source and binary forms, with or without 13 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/hardware/hwsleep.c b/drivers/acpi/hardware/hwsleep.c
index 4290e0193097..d9937e05ec6a 100644
--- a/drivers/acpi/hardware/hwsleep.c
+++ b/drivers/acpi/hardware/hwsleep.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -70,9 +70,10 @@ acpi_set_firmware_waking_vector(acpi_physical_address physical_address)
70 70
71 /* Get the FACS */ 71 /* Get the FACS */
72 72
73 status = 73 status = acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS,
74 acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS, 74 ACPI_CAST_INDIRECT_PTR(struct
75 (struct acpi_table_header **)&facs); 75 acpi_table_header,
76 &facs));
76 if (ACPI_FAILURE(status)) { 77 if (ACPI_FAILURE(status)) {
77 return_ACPI_STATUS(status); 78 return_ACPI_STATUS(status);
78 } 79 }
@@ -124,9 +125,10 @@ acpi_get_firmware_waking_vector(acpi_physical_address * physical_address)
124 125
125 /* Get the FACS */ 126 /* Get the FACS */
126 127
127 status = 128 status = acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS,
128 acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS, 129 ACPI_CAST_INDIRECT_PTR(struct
129 (struct acpi_table_header **)&facs); 130 acpi_table_header,
131 &facs));
130 if (ACPI_FAILURE(status)) { 132 if (ACPI_FAILURE(status)) {
131 return_ACPI_STATUS(status); 133 return_ACPI_STATUS(status);
132 } 134 }
diff --git a/drivers/acpi/hardware/hwtimer.c b/drivers/acpi/hardware/hwtimer.c
index c32eab696acd..b53d575491b9 100644
--- a/drivers/acpi/hardware/hwtimer.c
+++ b/drivers/acpi/hardware/hwtimer.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/namespace/nsaccess.c b/drivers/acpi/namespace/nsaccess.c
index 57faf598bad8..c39a7f68b889 100644
--- a/drivers/acpi/namespace/nsaccess.c
+++ b/drivers/acpi/namespace/nsaccess.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -208,8 +208,7 @@ acpi_status acpi_ns_root_initialize(void)
208 /* Special case for ACPI Global Lock */ 208 /* Special case for ACPI Global Lock */
209 209
210 if (ACPI_STRCMP(init_val->name, "_GL_") == 0) { 210 if (ACPI_STRCMP(init_val->name, "_GL_") == 0) {
211 acpi_gbl_global_lock_mutex = 211 acpi_gbl_global_lock_mutex = obj_desc;
212 obj_desc->mutex.os_mutex;
213 212
214 /* Create additional counting semaphore for global lock */ 213 /* Create additional counting semaphore for global lock */
215 214
@@ -582,44 +581,68 @@ acpi_ns_lookup(union acpi_generic_state *scope_info,
582 return_ACPI_STATUS(status); 581 return_ACPI_STATUS(status);
583 } 582 }
584 583
585 /* 584 /* More segments to follow? */
586 * Sanity typecheck of the target object: 585
587 * 586 if (num_segments > 0) {
588 * If 1) This is the last segment (num_segments == 0) 587 /*
589 * 2) And we are looking for a specific type 588 * If we have an alias to an object that opens a scope (such as a
590 * (Not checking for TYPE_ANY) 589 * device or processor), we need to dereference the alias here so that
591 * 3) Which is not an alias 590 * we can access any children of the original node (via the remaining
592 * 4) Which is not a local type (TYPE_SCOPE) 591 * segments).
593 * 5) And the type of target object is known (not TYPE_ANY) 592 */
594 * 6) And target object does not match what we are looking for 593 if (this_node->type == ACPI_TYPE_LOCAL_ALIAS) {
595 * 594 if (acpi_ns_opens_scope
596 * Then we have a type mismatch. Just warn and ignore it. 595 (((struct acpi_namespace_node *)this_node->
597 */ 596 object)->type)) {
598 if ((num_segments == 0) && 597 this_node =
599 (type_to_check_for != ACPI_TYPE_ANY) && 598 (struct acpi_namespace_node *)
600 (type_to_check_for != ACPI_TYPE_LOCAL_ALIAS) && 599 this_node->object;
601 (type_to_check_for != ACPI_TYPE_LOCAL_METHOD_ALIAS) && 600 }
602 (type_to_check_for != ACPI_TYPE_LOCAL_SCOPE) && 601 }
603 (this_node->type != ACPI_TYPE_ANY) &&
604 (this_node->type != type_to_check_for)) {
605
606 /* Complain about a type mismatch */
607
608 ACPI_WARNING((AE_INFO,
609 "NsLookup: Type mismatch on %4.4s (%s), searching for (%s)",
610 ACPI_CAST_PTR(char, &simple_name),
611 acpi_ut_get_type_name(this_node->type),
612 acpi_ut_get_type_name
613 (type_to_check_for)));
614 } 602 }
615 603
616 /* 604 /* Special handling for the last segment (num_segments == 0) */
617 * If this is the last name segment and we are not looking for a 605
618 * specific type, but the type of found object is known, use that type 606 else {
619 * to see if it opens a scope. 607 /*
620 */ 608 * Sanity typecheck of the target object:
621 if ((num_segments == 0) && (type == ACPI_TYPE_ANY)) { 609 *
622 type = this_node->type; 610 * If 1) This is the last segment (num_segments == 0)
611 * 2) And we are looking for a specific type
612 * (Not checking for TYPE_ANY)
613 * 3) Which is not an alias
614 * 4) Which is not a local type (TYPE_SCOPE)
615 * 5) And the type of target object is known (not TYPE_ANY)
616 * 6) And target object does not match what we are looking for
617 *
618 * Then we have a type mismatch. Just warn and ignore it.
619 */
620 if ((type_to_check_for != ACPI_TYPE_ANY) &&
621 (type_to_check_for != ACPI_TYPE_LOCAL_ALIAS) &&
622 (type_to_check_for != ACPI_TYPE_LOCAL_METHOD_ALIAS)
623 && (type_to_check_for != ACPI_TYPE_LOCAL_SCOPE)
624 && (this_node->type != ACPI_TYPE_ANY)
625 && (this_node->type != type_to_check_for)) {
626
627 /* Complain about a type mismatch */
628
629 ACPI_WARNING((AE_INFO,
630 "NsLookup: Type mismatch on %4.4s (%s), searching for (%s)",
631 ACPI_CAST_PTR(char, &simple_name),
632 acpi_ut_get_type_name(this_node->
633 type),
634 acpi_ut_get_type_name
635 (type_to_check_for)));
636 }
637
638 /*
639 * If this is the last name segment and we are not looking for a
640 * specific type, but the type of found object is known, use that type
641 * to (later) see if it opens a scope.
642 */
643 if (type == ACPI_TYPE_ANY) {
644 type = this_node->type;
645 }
623 } 646 }
624 647
625 /* Point to next name segment and make this node current */ 648 /* Point to next name segment and make this node current */
diff --git a/drivers/acpi/namespace/nsalloc.c b/drivers/acpi/namespace/nsalloc.c
index 1d693d8ad2d8..3a1740ac2edc 100644
--- a/drivers/acpi/namespace/nsalloc.c
+++ b/drivers/acpi/namespace/nsalloc.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/namespace/nsdump.c b/drivers/acpi/namespace/nsdump.c
index 1fc4f86676e1..5445751b8a3e 100644
--- a/drivers/acpi/namespace/nsdump.c
+++ b/drivers/acpi/namespace/nsdump.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -249,7 +249,9 @@ acpi_ns_dump_one_object(acpi_handle obj_handle,
249 acpi_os_printf("ID %X Len %.4X Addr %p\n", 249 acpi_os_printf("ID %X Len %.4X Addr %p\n",
250 obj_desc->processor.proc_id, 250 obj_desc->processor.proc_id,
251 obj_desc->processor.length, 251 obj_desc->processor.length,
252 (char *)obj_desc->processor.address); 252 ACPI_CAST_PTR(void,
253 obj_desc->processor.
254 address));
253 break; 255 break;
254 256
255 case ACPI_TYPE_DEVICE: 257 case ACPI_TYPE_DEVICE:
@@ -320,9 +322,8 @@ acpi_ns_dump_one_object(acpi_handle obj_handle,
320 space_id)); 322 space_id));
321 if (obj_desc->region.flags & AOPOBJ_DATA_VALID) { 323 if (obj_desc->region.flags & AOPOBJ_DATA_VALID) {
322 acpi_os_printf(" Addr %8.8X%8.8X Len %.4X\n", 324 acpi_os_printf(" Addr %8.8X%8.8X Len %.4X\n",
323 ACPI_FORMAT_UINT64(obj_desc-> 325 ACPI_FORMAT_NATIVE_UINT
324 region. 326 (obj_desc->region.address),
325 address),
326 obj_desc->region.length); 327 obj_desc->region.length);
327 } else { 328 } else {
328 acpi_os_printf 329 acpi_os_printf
diff --git a/drivers/acpi/namespace/nsdumpdv.c b/drivers/acpi/namespace/nsdumpdv.c
index 5097e167939e..428f50fde11a 100644
--- a/drivers/acpi/namespace/nsdumpdv.c
+++ b/drivers/acpi/namespace/nsdumpdv.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/namespace/nseval.c b/drivers/acpi/namespace/nseval.c
index 97b2ac57c16b..14bdfa92bea0 100644
--- a/drivers/acpi/namespace/nseval.c
+++ b/drivers/acpi/namespace/nseval.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/namespace/nsinit.c b/drivers/acpi/namespace/nsinit.c
index 33db2241044e..6d6d930c8e18 100644
--- a/drivers/acpi/namespace/nsinit.c
+++ b/drivers/acpi/namespace/nsinit.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -244,6 +244,10 @@ acpi_ns_init_one_object(acpi_handle obj_handle,
244 info->field_count++; 244 info->field_count++;
245 break; 245 break;
246 246
247 case ACPI_TYPE_LOCAL_BANK_FIELD:
248 info->field_count++;
249 break;
250
247 case ACPI_TYPE_BUFFER: 251 case ACPI_TYPE_BUFFER:
248 info->buffer_count++; 252 info->buffer_count++;
249 break; 253 break;
@@ -287,6 +291,12 @@ acpi_ns_init_one_object(acpi_handle obj_handle,
287 status = acpi_ds_get_buffer_field_arguments(obj_desc); 291 status = acpi_ds_get_buffer_field_arguments(obj_desc);
288 break; 292 break;
289 293
294 case ACPI_TYPE_LOCAL_BANK_FIELD:
295
296 info->field_init++;
297 status = acpi_ds_get_bank_field_arguments(obj_desc);
298 break;
299
290 case ACPI_TYPE_BUFFER: 300 case ACPI_TYPE_BUFFER:
291 301
292 info->buffer_init++; 302 info->buffer_init++;
diff --git a/drivers/acpi/namespace/nsload.c b/drivers/acpi/namespace/nsload.c
index d4f9654fd20f..2c92f6cf5ce1 100644
--- a/drivers/acpi/namespace/nsload.c
+++ b/drivers/acpi/namespace/nsload.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -107,11 +107,11 @@ acpi_ns_load_table(acpi_native_uint table_index,
107 goto unlock; 107 goto unlock;
108 } 108 }
109 109
110 status = acpi_ns_parse_table(table_index, node->child); 110 status = acpi_ns_parse_table(table_index, node);
111 if (ACPI_SUCCESS(status)) { 111 if (ACPI_SUCCESS(status)) {
112 acpi_tb_set_table_loaded_flag(table_index, TRUE); 112 acpi_tb_set_table_loaded_flag(table_index, TRUE);
113 } else { 113 } else {
114 acpi_tb_release_owner_id(table_index); 114 (void)acpi_tb_release_owner_id(table_index);
115 } 115 }
116 116
117 unlock: 117 unlock:
diff --git a/drivers/acpi/namespace/nsnames.c b/drivers/acpi/namespace/nsnames.c
index cbd94af08cc5..cffef1bcbdbc 100644
--- a/drivers/acpi/namespace/nsnames.c
+++ b/drivers/acpi/namespace/nsnames.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -180,6 +180,12 @@ acpi_size acpi_ns_get_pathname_length(struct acpi_namespace_node *node)
180 next_node = node; 180 next_node = node;
181 181
182 while (next_node && (next_node != acpi_gbl_root_node)) { 182 while (next_node && (next_node != acpi_gbl_root_node)) {
183 if (ACPI_GET_DESCRIPTOR_TYPE(next_node) != ACPI_DESC_TYPE_NAMED) {
184 ACPI_ERROR((AE_INFO,
185 "Invalid NS Node (%p) while traversing path",
186 next_node));
187 return 0;
188 }
183 size += ACPI_PATH_SEGMENT_LENGTH; 189 size += ACPI_PATH_SEGMENT_LENGTH;
184 next_node = acpi_ns_get_parent_node(next_node); 190 next_node = acpi_ns_get_parent_node(next_node);
185 } 191 }
diff --git a/drivers/acpi/namespace/nsobject.c b/drivers/acpi/namespace/nsobject.c
index d9d7377bc6e6..15fe09e24f71 100644
--- a/drivers/acpi/namespace/nsobject.c
+++ b/drivers/acpi/namespace/nsobject.c
@@ -6,7 +6,7 @@
6 ******************************************************************************/ 6 ******************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/namespace/nsparse.c b/drivers/acpi/namespace/nsparse.c
index e696aa847990..46a79b0103b6 100644
--- a/drivers/acpi/namespace/nsparse.c
+++ b/drivers/acpi/namespace/nsparse.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -64,7 +64,8 @@ ACPI_MODULE_NAME("nsparse")
64 ******************************************************************************/ 64 ******************************************************************************/
65acpi_status 65acpi_status
66acpi_ns_one_complete_parse(acpi_native_uint pass_number, 66acpi_ns_one_complete_parse(acpi_native_uint pass_number,
67 acpi_native_uint table_index) 67 acpi_native_uint table_index,
68 struct acpi_namespace_node * start_node)
68{ 69{
69 union acpi_parse_object *parse_root; 70 union acpi_parse_object *parse_root;
70 acpi_status status; 71 acpi_status status;
@@ -111,14 +112,25 @@ acpi_ns_one_complete_parse(acpi_native_uint pass_number,
111 aml_start = (u8 *) table + sizeof(struct acpi_table_header); 112 aml_start = (u8 *) table + sizeof(struct acpi_table_header);
112 aml_length = table->length - sizeof(struct acpi_table_header); 113 aml_length = table->length - sizeof(struct acpi_table_header);
113 status = acpi_ds_init_aml_walk(walk_state, parse_root, NULL, 114 status = acpi_ds_init_aml_walk(walk_state, parse_root, NULL,
114 aml_start, aml_length, NULL, 115 aml_start, (u32) aml_length,
115 (u8) pass_number); 116 NULL, (u8) pass_number);
116 } 117 }
117 118
118 if (ACPI_FAILURE(status)) { 119 if (ACPI_FAILURE(status)) {
119 acpi_ds_delete_walk_state(walk_state); 120 acpi_ds_delete_walk_state(walk_state);
120 acpi_ps_delete_parse_tree(parse_root); 121 goto cleanup;
121 return_ACPI_STATUS(status); 122 }
123
124 /* start_node is the default location to load the table */
125
126 if (start_node && start_node != acpi_gbl_root_node) {
127 status =
128 acpi_ds_scope_stack_push(start_node, ACPI_TYPE_METHOD,
129 walk_state);
130 if (ACPI_FAILURE(status)) {
131 acpi_ds_delete_walk_state(walk_state);
132 goto cleanup;
133 }
122 } 134 }
123 135
124 /* Parse the AML */ 136 /* Parse the AML */
@@ -127,6 +139,7 @@ acpi_ns_one_complete_parse(acpi_native_uint pass_number,
127 (unsigned)pass_number)); 139 (unsigned)pass_number));
128 status = acpi_ps_parse_aml(walk_state); 140 status = acpi_ps_parse_aml(walk_state);
129 141
142 cleanup:
130 acpi_ps_delete_parse_tree(parse_root); 143 acpi_ps_delete_parse_tree(parse_root);
131 return_ACPI_STATUS(status); 144 return_ACPI_STATUS(status);
132} 145}
@@ -163,7 +176,9 @@ acpi_ns_parse_table(acpi_native_uint table_index,
163 * performs another complete parse of the AML. 176 * performs another complete parse of the AML.
164 */ 177 */
165 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Start pass 1\n")); 178 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Start pass 1\n"));
166 status = acpi_ns_one_complete_parse(ACPI_IMODE_LOAD_PASS1, table_index); 179 status =
180 acpi_ns_one_complete_parse(ACPI_IMODE_LOAD_PASS1, table_index,
181 start_node);
167 if (ACPI_FAILURE(status)) { 182 if (ACPI_FAILURE(status)) {
168 return_ACPI_STATUS(status); 183 return_ACPI_STATUS(status);
169 } 184 }
@@ -178,7 +193,9 @@ acpi_ns_parse_table(acpi_native_uint table_index,
178 * parse objects are all cached. 193 * parse objects are all cached.
179 */ 194 */
180 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Start pass 2\n")); 195 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "**** Start pass 2\n"));
181 status = acpi_ns_one_complete_parse(ACPI_IMODE_LOAD_PASS2, table_index); 196 status =
197 acpi_ns_one_complete_parse(ACPI_IMODE_LOAD_PASS2, table_index,
198 start_node);
182 if (ACPI_FAILURE(status)) { 199 if (ACPI_FAILURE(status)) {
183 return_ACPI_STATUS(status); 200 return_ACPI_STATUS(status);
184 } 201 }
diff --git a/drivers/acpi/namespace/nssearch.c b/drivers/acpi/namespace/nssearch.c
index e863be665ce8..8399276cba1e 100644
--- a/drivers/acpi/namespace/nssearch.c
+++ b/drivers/acpi/namespace/nssearch.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/namespace/nsutils.c b/drivers/acpi/namespace/nsutils.c
index 90fd059615ff..64c039843ed2 100644
--- a/drivers/acpi/namespace/nsutils.c
+++ b/drivers/acpi/namespace/nsutils.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/namespace/nswalk.c b/drivers/acpi/namespace/nswalk.c
index 280b8357c46c..3c905ce26d7d 100644
--- a/drivers/acpi/namespace/nswalk.c
+++ b/drivers/acpi/namespace/nswalk.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -77,9 +77,7 @@ struct acpi_namespace_node *acpi_ns_get_next_node(acpi_object_type type, struct
77 77
78 /* It's really the parent's _scope_ that we want */ 78 /* It's really the parent's _scope_ that we want */
79 79
80 if (parent_node->child) { 80 next_node = parent_node->child;
81 next_node = parent_node->child;
82 }
83 } 81 }
84 82
85 else { 83 else {
diff --git a/drivers/acpi/namespace/nsxfeval.c b/drivers/acpi/namespace/nsxfeval.c
index b92133faf5b7..a8d549187c84 100644
--- a/drivers/acpi/namespace/nsxfeval.c
+++ b/drivers/acpi/namespace/nsxfeval.c
@@ -6,7 +6,7 @@
6 ******************************************************************************/ 6 ******************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -467,10 +467,13 @@ acpi_ns_get_device_callback(acpi_handle obj_handle,
467 return (AE_CTRL_DEPTH); 467 return (AE_CTRL_DEPTH);
468 } 468 }
469 469
470 if (!(flags & ACPI_STA_DEVICE_PRESENT)) { 470 if (!(flags & ACPI_STA_DEVICE_PRESENT) &&
471 471 !(flags & ACPI_STA_DEVICE_FUNCTIONING)) {
472 /* Don't examine children of the device if not present */ 472 /*
473 473 * Don't examine the children of the device only when the
474 * device is neither present nor functional. See ACPI spec,
475 * description of _STA for more information.
476 */
474 return (AE_CTRL_DEPTH); 477 return (AE_CTRL_DEPTH);
475 } 478 }
476 479
@@ -539,7 +542,7 @@ acpi_ns_get_device_callback(acpi_handle obj_handle,
539 * value is returned to the caller. 542 * value is returned to the caller.
540 * 543 *
541 * This is a wrapper for walk_namespace, but the callback performs 544 * This is a wrapper for walk_namespace, but the callback performs
542 * additional filtering. Please see acpi_get_device_callback. 545 * additional filtering. Please see acpi_ns_get_device_callback.
543 * 546 *
544 ******************************************************************************/ 547 ******************************************************************************/
545 548
diff --git a/drivers/acpi/namespace/nsxfname.c b/drivers/acpi/namespace/nsxfname.c
index b489781b22a8..a287ed550f54 100644
--- a/drivers/acpi/namespace/nsxfname.c
+++ b/drivers/acpi/namespace/nsxfname.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/namespace/nsxfobj.c b/drivers/acpi/namespace/nsxfobj.c
index faa375887201..2b375ee80cef 100644
--- a/drivers/acpi/namespace/nsxfobj.c
+++ b/drivers/acpi/namespace/nsxfobj.c
@@ -6,7 +6,7 @@
6 ******************************************************************************/ 6 ******************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index a498a6cc68fe..235a1386888a 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -742,6 +742,7 @@ EXPORT_SYMBOL(acpi_os_execute);
742void acpi_os_wait_events_complete(void *context) 742void acpi_os_wait_events_complete(void *context)
743{ 743{
744 flush_workqueue(kacpid_wq); 744 flush_workqueue(kacpid_wq);
745 flush_workqueue(kacpi_notify_wq);
745} 746}
746 747
747EXPORT_SYMBOL(acpi_os_wait_events_complete); 748EXPORT_SYMBOL(acpi_os_wait_events_complete);
diff --git a/drivers/acpi/parser/psargs.c b/drivers/acpi/parser/psargs.c
index c2b9835c890b..f1e8bf65e24e 100644
--- a/drivers/acpi/parser/psargs.c
+++ b/drivers/acpi/parser/psargs.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -230,12 +230,12 @@ acpi_ps_get_next_namepath(struct acpi_walk_state *walk_state,
230 struct acpi_parse_state *parser_state, 230 struct acpi_parse_state *parser_state,
231 union acpi_parse_object *arg, u8 possible_method_call) 231 union acpi_parse_object *arg, u8 possible_method_call)
232{ 232{
233 acpi_status status;
233 char *path; 234 char *path;
234 union acpi_parse_object *name_op; 235 union acpi_parse_object *name_op;
235 acpi_status status;
236 union acpi_operand_object *method_desc; 236 union acpi_operand_object *method_desc;
237 struct acpi_namespace_node *node; 237 struct acpi_namespace_node *node;
238 union acpi_generic_state scope_info; 238 u8 *start = parser_state->aml;
239 239
240 ACPI_FUNCTION_TRACE(ps_get_next_namepath); 240 ACPI_FUNCTION_TRACE(ps_get_next_namepath);
241 241
@@ -249,25 +249,18 @@ acpi_ps_get_next_namepath(struct acpi_walk_state *walk_state,
249 return_ACPI_STATUS(AE_OK); 249 return_ACPI_STATUS(AE_OK);
250 } 250 }
251 251
252 /* Setup search scope info */
253
254 scope_info.scope.node = NULL;
255 node = parser_state->start_node;
256 if (node) {
257 scope_info.scope.node = node;
258 }
259
260 /* 252 /*
261 * Lookup the name in the internal namespace. We don't want to add 253 * Lookup the name in the internal namespace, starting with the current
262 * anything new to the namespace here, however, so we use MODE_EXECUTE. 254 * scope. We don't want to add anything new to the namespace here,
255 * however, so we use MODE_EXECUTE.
263 * Allow searching of the parent tree, but don't open a new scope - 256 * Allow searching of the parent tree, but don't open a new scope -
264 * we just want to lookup the object (must be mode EXECUTE to perform 257 * we just want to lookup the object (must be mode EXECUTE to perform
265 * the upsearch) 258 * the upsearch)
266 */ 259 */
267 status = 260 status = acpi_ns_lookup(walk_state->scope_info, path,
268 acpi_ns_lookup(&scope_info, path, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, 261 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
269 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, 262 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
270 NULL, &node); 263 NULL, &node);
271 264
272 /* 265 /*
273 * If this name is a control method invocation, we must 266 * If this name is a control method invocation, we must
@@ -275,6 +268,16 @@ acpi_ps_get_next_namepath(struct acpi_walk_state *walk_state,
275 */ 268 */
276 if (ACPI_SUCCESS(status) && 269 if (ACPI_SUCCESS(status) &&
277 possible_method_call && (node->type == ACPI_TYPE_METHOD)) { 270 possible_method_call && (node->type == ACPI_TYPE_METHOD)) {
271 if (walk_state->op->common.aml_opcode == AML_UNLOAD_OP) {
272 /*
273 * acpi_ps_get_next_namestring has increased the AML pointer,
274 * so we need to restore the saved AML pointer for method call.
275 */
276 walk_state->parser_state.aml = start;
277 walk_state->arg_count = 1;
278 acpi_ps_init_op(arg, AML_INT_METHODCALL_OP);
279 return_ACPI_STATUS(AE_OK);
280 }
278 281
279 /* This name is actually a control method invocation */ 282 /* This name is actually a control method invocation */
280 283
@@ -686,9 +689,29 @@ acpi_ps_get_next_arg(struct acpi_walk_state *walk_state,
686 return_ACPI_STATUS(AE_NO_MEMORY); 689 return_ACPI_STATUS(AE_NO_MEMORY);
687 } 690 }
688 691
689 status = 692 /* To support super_name arg of Unload */
690 acpi_ps_get_next_namepath(walk_state, parser_state, 693
691 arg, 0); 694 if (walk_state->op->common.aml_opcode == AML_UNLOAD_OP) {
695 status =
696 acpi_ps_get_next_namepath(walk_state,
697 parser_state, arg,
698 1);
699
700 /*
701 * If the super_name arg of Unload is a method call,
702 * we have restored the AML pointer, just free this Arg
703 */
704 if (arg->common.aml_opcode ==
705 AML_INT_METHODCALL_OP) {
706 acpi_ps_free_op(arg);
707 arg = NULL;
708 }
709 } else {
710 status =
711 acpi_ps_get_next_namepath(walk_state,
712 parser_state, arg,
713 0);
714 }
692 } else { 715 } else {
693 /* Single complex argument, nothing returned */ 716 /* Single complex argument, nothing returned */
694 717
diff --git a/drivers/acpi/parser/psloop.c b/drivers/acpi/parser/psloop.c
index 773aee82fbb8..c06238e55d98 100644
--- a/drivers/acpi/parser/psloop.c
+++ b/drivers/acpi/parser/psloop.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -182,6 +182,7 @@ acpi_ps_build_named_op(struct acpi_walk_state *walk_state,
182 ACPI_FUNCTION_TRACE_PTR(ps_build_named_op, walk_state); 182 ACPI_FUNCTION_TRACE_PTR(ps_build_named_op, walk_state);
183 183
184 unnamed_op->common.value.arg = NULL; 184 unnamed_op->common.value.arg = NULL;
185 unnamed_op->common.arg_list_length = 0;
185 unnamed_op->common.aml_opcode = walk_state->opcode; 186 unnamed_op->common.aml_opcode = walk_state->opcode;
186 187
187 /* 188 /*
@@ -241,7 +242,8 @@ acpi_ps_build_named_op(struct acpi_walk_state *walk_state,
241 acpi_ps_append_arg(*op, unnamed_op->common.value.arg); 242 acpi_ps_append_arg(*op, unnamed_op->common.value.arg);
242 acpi_gbl_depth++; 243 acpi_gbl_depth++;
243 244
244 if ((*op)->common.aml_opcode == AML_REGION_OP) { 245 if ((*op)->common.aml_opcode == AML_REGION_OP ||
246 (*op)->common.aml_opcode == AML_DATA_REGION_OP) {
245 /* 247 /*
246 * Defer final parsing of an operation_region body, because we don't 248 * Defer final parsing of an operation_region body, because we don't
247 * have enough info in the first pass to parse it correctly (i.e., 249 * have enough info in the first pass to parse it correctly (i.e.,
@@ -280,6 +282,9 @@ acpi_ps_create_op(struct acpi_walk_state *walk_state,
280 acpi_status status = AE_OK; 282 acpi_status status = AE_OK;
281 union acpi_parse_object *op; 283 union acpi_parse_object *op;
282 union acpi_parse_object *named_op = NULL; 284 union acpi_parse_object *named_op = NULL;
285 union acpi_parse_object *parent_scope;
286 u8 argument_count;
287 const struct acpi_opcode_info *op_info;
283 288
284 ACPI_FUNCTION_TRACE_PTR(ps_create_op, walk_state); 289 ACPI_FUNCTION_TRACE_PTR(ps_create_op, walk_state);
285 290
@@ -320,8 +325,32 @@ acpi_ps_create_op(struct acpi_walk_state *walk_state,
320 op->named.length = 0; 325 op->named.length = 0;
321 } 326 }
322 327
323 acpi_ps_append_arg(acpi_ps_get_parent_scope 328 if (walk_state->opcode == AML_BANK_FIELD_OP) {
324 (&(walk_state->parser_state)), op); 329 /*
330 * Backup to beginning of bank_field declaration
331 * body_length is unknown until we parse the body
332 */
333 op->named.data = aml_op_start;
334 op->named.length = 0;
335 }
336
337 parent_scope = acpi_ps_get_parent_scope(&(walk_state->parser_state));
338 acpi_ps_append_arg(parent_scope, op);
339
340 if (parent_scope) {
341 op_info =
342 acpi_ps_get_opcode_info(parent_scope->common.aml_opcode);
343 if (op_info->flags & AML_HAS_TARGET) {
344 argument_count =
345 acpi_ps_get_argument_count(op_info->type);
346 if (parent_scope->common.arg_list_length >
347 argument_count) {
348 op->common.flags |= ACPI_PARSEOP_TARGET;
349 }
350 } else if (parent_scope->common.aml_opcode == AML_INCREMENT_OP) {
351 op->common.flags |= ACPI_PARSEOP_TARGET;
352 }
353 }
325 354
326 if (walk_state->descending_callback != NULL) { 355 if (walk_state->descending_callback != NULL) {
327 /* 356 /*
@@ -603,13 +632,6 @@ acpi_ps_complete_op(struct acpi_walk_state *walk_state,
603 acpi_ps_pop_scope(&(walk_state->parser_state), op, 632 acpi_ps_pop_scope(&(walk_state->parser_state), op,
604 &walk_state->arg_types, 633 &walk_state->arg_types,
605 &walk_state->arg_count); 634 &walk_state->arg_count);
606
607 if ((*op)->common.aml_opcode != AML_WHILE_OP) {
608 status2 = acpi_ds_result_stack_pop(walk_state);
609 if (ACPI_FAILURE(status2)) {
610 return_ACPI_STATUS(status2);
611 }
612 }
613 } 635 }
614 636
615 /* Close this iteration of the While loop */ 637 /* Close this iteration of the While loop */
@@ -640,10 +662,6 @@ acpi_ps_complete_op(struct acpi_walk_state *walk_state,
640 if (ACPI_FAILURE(status2)) { 662 if (ACPI_FAILURE(status2)) {
641 return_ACPI_STATUS(status2); 663 return_ACPI_STATUS(status2);
642 } 664 }
643 status2 = acpi_ds_result_stack_pop(walk_state);
644 if (ACPI_FAILURE(status2)) {
645 return_ACPI_STATUS(status2);
646 }
647 665
648 acpi_ut_delete_generic_state 666 acpi_ut_delete_generic_state
649 (acpi_ut_pop_generic_state 667 (acpi_ut_pop_generic_state
@@ -1005,7 +1023,8 @@ acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
1005 acpi_gbl_depth--; 1023 acpi_gbl_depth--;
1006 } 1024 }
1007 1025
1008 if (op->common.aml_opcode == AML_REGION_OP) { 1026 if (op->common.aml_opcode == AML_REGION_OP ||
1027 op->common.aml_opcode == AML_DATA_REGION_OP) {
1009 /* 1028 /*
1010 * Skip parsing of control method or opregion body, 1029 * Skip parsing of control method or opregion body,
1011 * because we don't have enough info in the first pass 1030 * because we don't have enough info in the first pass
@@ -1030,6 +1049,16 @@ acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
1030 (u32) (parser_state->aml - op->named.data); 1049 (u32) (parser_state->aml - op->named.data);
1031 } 1050 }
1032 1051
1052 if (op->common.aml_opcode == AML_BANK_FIELD_OP) {
1053 /*
1054 * Backup to beginning of bank_field declaration
1055 *
1056 * body_length is unknown until we parse the body
1057 */
1058 op->named.length =
1059 (u32) (parser_state->aml - op->named.data);
1060 }
1061
1033 /* This op complete, notify the dispatcher */ 1062 /* This op complete, notify the dispatcher */
1034 1063
1035 if (walk_state->ascending_callback != NULL) { 1064 if (walk_state->ascending_callback != NULL) {
diff --git a/drivers/acpi/parser/psopcode.c b/drivers/acpi/parser/psopcode.c
index 9296e86761d7..f425ab30eae8 100644
--- a/drivers/acpi/parser/psopcode.c
+++ b/drivers/acpi/parser/psopcode.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -49,6 +49,9 @@
49#define _COMPONENT ACPI_PARSER 49#define _COMPONENT ACPI_PARSER
50ACPI_MODULE_NAME("psopcode") 50ACPI_MODULE_NAME("psopcode")
51 51
52static const u8 acpi_gbl_argument_count[] =
53 { 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 6 };
54
52/******************************************************************************* 55/*******************************************************************************
53 * 56 *
54 * NAME: acpi_gbl_aml_op_info 57 * NAME: acpi_gbl_aml_op_info
@@ -59,6 +62,7 @@ ACPI_MODULE_NAME("psopcode")
59 * the operand type. 62 * the operand type.
60 * 63 *
61 ******************************************************************************/ 64 ******************************************************************************/
65
62/* 66/*
63 * Summary of opcode types/flags 67 * Summary of opcode types/flags
64 * 68 *
@@ -176,6 +180,7 @@ ACPI_MODULE_NAME("psopcode")
176 AML_CREATE_QWORD_FIELD_OP 180 AML_CREATE_QWORD_FIELD_OP
177 181
178 ******************************************************************************/ 182 ******************************************************************************/
183
179/* 184/*
180 * Master Opcode information table. A summary of everything we know about each 185 * Master Opcode information table. A summary of everything we know about each
181 * opcode, all in one place. 186 * opcode, all in one place.
@@ -515,9 +520,10 @@ const struct acpi_opcode_info acpi_gbl_aml_op_info[AML_NUM_OPCODES] = {
515 AML_TYPE_NAMED_FIELD, 520 AML_TYPE_NAMED_FIELD,
516 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_FIELD), 521 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_FIELD),
517/* 5F */ ACPI_OP("BankField", ARGP_BANK_FIELD_OP, ARGI_BANK_FIELD_OP, 522/* 5F */ ACPI_OP("BankField", ARGP_BANK_FIELD_OP, ARGI_BANK_FIELD_OP,
518 ACPI_TYPE_ANY, AML_CLASS_NAMED_OBJECT, 523 ACPI_TYPE_LOCAL_BANK_FIELD, AML_CLASS_NAMED_OBJECT,
519 AML_TYPE_NAMED_FIELD, 524 AML_TYPE_NAMED_FIELD,
520 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_FIELD), 525 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_FIELD |
526 AML_DEFER),
521 527
522/* Internal opcodes that map to invalid AML opcodes */ 528/* Internal opcodes that map to invalid AML opcodes */
523 529
@@ -619,9 +625,9 @@ const struct acpi_opcode_info acpi_gbl_aml_op_info[AML_NUM_OPCODES] = {
619 AML_TYPE_EXEC_6A_0T_1R, AML_FLAGS_EXEC_6A_0T_1R), 625 AML_TYPE_EXEC_6A_0T_1R, AML_FLAGS_EXEC_6A_0T_1R),
620/* 7C */ ACPI_OP("DataTableRegion", ARGP_DATA_REGION_OP, 626/* 7C */ ACPI_OP("DataTableRegion", ARGP_DATA_REGION_OP,
621 ARGI_DATA_REGION_OP, ACPI_TYPE_REGION, 627 ARGI_DATA_REGION_OP, ACPI_TYPE_REGION,
622 AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_SIMPLE, 628 AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_COMPLEX,
623 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | 629 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE |
624 AML_NSNODE | AML_NAMED), 630 AML_NSNODE | AML_NAMED | AML_DEFER),
625/* 7D */ ACPI_OP("[EvalSubTree]", ARGP_SCOPE_OP, ARGI_SCOPE_OP, 631/* 7D */ ACPI_OP("[EvalSubTree]", ARGP_SCOPE_OP, ARGI_SCOPE_OP,
626 ACPI_TYPE_ANY, AML_CLASS_NAMED_OBJECT, 632 ACPI_TYPE_ANY, AML_CLASS_NAMED_OBJECT,
627 AML_TYPE_NAMED_NO_OBJ, 633 AML_TYPE_NAMED_NO_OBJ,
@@ -779,3 +785,25 @@ char *acpi_ps_get_opcode_name(u16 opcode)
779 785
780#endif 786#endif
781} 787}
788
789/*******************************************************************************
790 *
791 * FUNCTION: acpi_ps_get_argument_count
792 *
793 * PARAMETERS: op_type - Type associated with the AML opcode
794 *
795 * RETURN: Argument count
796 *
797 * DESCRIPTION: Obtain the number of expected arguments for an AML opcode
798 *
799 ******************************************************************************/
800
801u8 acpi_ps_get_argument_count(u32 op_type)
802{
803
804 if (op_type <= AML_TYPE_EXEC_6A_0T_1R) {
805 return (acpi_gbl_argument_count[op_type]);
806 }
807
808 return (0);
809}
diff --git a/drivers/acpi/parser/psparse.c b/drivers/acpi/parser/psparse.c
index 5d63f48e56b5..15e1702e48d6 100644
--- a/drivers/acpi/parser/psparse.c
+++ b/drivers/acpi/parser/psparse.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -205,6 +205,8 @@ acpi_ps_complete_this_op(struct acpi_walk_state * walk_state,
205 || (op->common.parent->common.aml_opcode == 205 || (op->common.parent->common.aml_opcode ==
206 AML_PACKAGE_OP) 206 AML_PACKAGE_OP)
207 || (op->common.parent->common.aml_opcode == 207 || (op->common.parent->common.aml_opcode ==
208 AML_BANK_FIELD_OP)
209 || (op->common.parent->common.aml_opcode ==
208 AML_VAR_PACKAGE_OP)) { 210 AML_VAR_PACKAGE_OP)) {
209 replacement_op = 211 replacement_op =
210 acpi_ps_alloc_op(AML_INT_RETURN_VALUE_OP); 212 acpi_ps_alloc_op(AML_INT_RETURN_VALUE_OP);
@@ -349,19 +351,13 @@ acpi_ps_next_parse_state(struct acpi_walk_state *walk_state,
349 351
350 parser_state->aml = walk_state->aml_last_while; 352 parser_state->aml = walk_state->aml_last_while;
351 walk_state->control_state->common.value = FALSE; 353 walk_state->control_state->common.value = FALSE;
352 status = acpi_ds_result_stack_pop(walk_state); 354 status = AE_CTRL_BREAK;
353 if (ACPI_SUCCESS(status)) {
354 status = AE_CTRL_BREAK;
355 }
356 break; 355 break;
357 356
358 case AE_CTRL_CONTINUE: 357 case AE_CTRL_CONTINUE:
359 358
360 parser_state->aml = walk_state->aml_last_while; 359 parser_state->aml = walk_state->aml_last_while;
361 status = acpi_ds_result_stack_pop(walk_state); 360 status = AE_CTRL_CONTINUE;
362 if (ACPI_SUCCESS(status)) {
363 status = AE_CTRL_CONTINUE;
364 }
365 break; 361 break;
366 362
367 case AE_CTRL_PENDING: 363 case AE_CTRL_PENDING:
@@ -383,10 +379,7 @@ acpi_ps_next_parse_state(struct acpi_walk_state *walk_state,
383 * Just close out this package 379 * Just close out this package
384 */ 380 */
385 parser_state->aml = acpi_ps_get_next_package_end(parser_state); 381 parser_state->aml = acpi_ps_get_next_package_end(parser_state);
386 status = acpi_ds_result_stack_pop(walk_state); 382 status = AE_CTRL_PENDING;
387 if (ACPI_SUCCESS(status)) {
388 status = AE_CTRL_PENDING;
389 }
390 break; 383 break;
391 384
392 case AE_CTRL_FALSE: 385 case AE_CTRL_FALSE:
@@ -541,7 +534,7 @@ acpi_status acpi_ps_parse_aml(struct acpi_walk_state *walk_state)
541 if ((status == AE_ALREADY_EXISTS) && 534 if ((status == AE_ALREADY_EXISTS) &&
542 (!walk_state->method_desc->method.mutex)) { 535 (!walk_state->method_desc->method.mutex)) {
543 ACPI_INFO((AE_INFO, 536 ACPI_INFO((AE_INFO,
544 "Marking method %4.4s as Serialized", 537 "Marking method %4.4s as Serialized because of AE_ALREADY_EXISTS error",
545 walk_state->method_node->name. 538 walk_state->method_node->name.
546 ascii)); 539 ascii));
547 540
@@ -601,6 +594,30 @@ acpi_status acpi_ps_parse_aml(struct acpi_walk_state *walk_state)
601 * The object is deleted 594 * The object is deleted
602 */ 595 */
603 if (!previous_walk_state->return_desc) { 596 if (!previous_walk_state->return_desc) {
597 /*
598 * In slack mode execution, if there is no return value
599 * we should implicitly return zero (0) as a default value.
600 */
601 if (acpi_gbl_enable_interpreter_slack &&
602 !previous_walk_state->
603 implicit_return_obj) {
604 previous_walk_state->
605 implicit_return_obj =
606 acpi_ut_create_internal_object
607 (ACPI_TYPE_INTEGER);
608 if (!previous_walk_state->
609 implicit_return_obj) {
610 return_ACPI_STATUS
611 (AE_NO_MEMORY);
612 }
613
614 previous_walk_state->
615 implicit_return_obj->
616 integer.value = 0;
617 }
618
619 /* Restart the calling control method */
620
604 status = 621 status =
605 acpi_ds_restart_control_method 622 acpi_ds_restart_control_method
606 (walk_state, 623 (walk_state,
diff --git a/drivers/acpi/parser/psscope.c b/drivers/acpi/parser/psscope.c
index 77cfa4ed0cfe..ee50e67c9443 100644
--- a/drivers/acpi/parser/psscope.c
+++ b/drivers/acpi/parser/psscope.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/parser/pstree.c b/drivers/acpi/parser/pstree.c
index 966e7ea2a0c4..1dd355ddd182 100644
--- a/drivers/acpi/parser/pstree.c
+++ b/drivers/acpi/parser/pstree.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -171,6 +171,8 @@ acpi_ps_append_arg(union acpi_parse_object *op, union acpi_parse_object *arg)
171 while (arg) { 171 while (arg) {
172 arg->common.parent = op; 172 arg->common.parent = op;
173 arg = arg->common.next; 173 arg = arg->common.next;
174
175 op->common.arg_list_length++;
174 } 176 }
175} 177}
176 178
diff --git a/drivers/acpi/parser/psutils.c b/drivers/acpi/parser/psutils.c
index 8ca52002db55..7cf1f65cd5bb 100644
--- a/drivers/acpi/parser/psutils.c
+++ b/drivers/acpi/parser/psutils.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/parser/pswalk.c b/drivers/acpi/parser/pswalk.c
index 49f9757434e4..8b86ad5a3201 100644
--- a/drivers/acpi/parser/pswalk.c
+++ b/drivers/acpi/parser/pswalk.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/parser/psxface.c b/drivers/acpi/parser/psxface.c
index 94103bced75e..52581454c47c 100644
--- a/drivers/acpi/parser/psxface.c
+++ b/drivers/acpi/parser/psxface.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index 21fc8bf0d31f..81e4f081a4ae 100644
--- a/drivers/acpi/power.c
+++ b/drivers/acpi/power.c
@@ -122,7 +122,7 @@ acpi_power_get_context(acpi_handle handle,
122 } 122 }
123 123
124 *resource = acpi_driver_data(device); 124 *resource = acpi_driver_data(device);
125 if (!resource) 125 if (!*resource)
126 return -ENODEV; 126 return -ENODEV;
127 127
128 return 0; 128 return 0;
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index dd28c912e84f..386e5aa48834 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -603,6 +603,15 @@ static int acpi_processor_get_info(struct acpi_processor *pr, unsigned has_uid)
603 request_region(pr->throttling.address, 6, "ACPI CPU throttle"); 603 request_region(pr->throttling.address, 6, "ACPI CPU throttle");
604 } 604 }
605 605
606 /*
607 * If ACPI describes a slot number for this CPU, we can use it
608 * ensure we get the right value in the "physical id" field
609 * of /proc/cpuinfo
610 */
611 status = acpi_evaluate_object(pr->handle, "_SUN", NULL, &buffer);
612 if (ACPI_SUCCESS(status))
613 arch_fix_phys_package_id(pr->id, object.integer.value);
614
606 return 0; 615 return 0;
607} 616}
608 617
@@ -665,22 +674,21 @@ static int __cpuinit acpi_processor_start(struct acpi_device *device)
665 result = PTR_ERR(pr->cdev); 674 result = PTR_ERR(pr->cdev);
666 goto end; 675 goto end;
667 } 676 }
668 if (pr->cdev) { 677
669 printk(KERN_INFO PREFIX 678 printk(KERN_INFO PREFIX
670 "%s is registered as cooling_device%d\n", 679 "%s is registered as cooling_device%d\n",
671 device->dev.bus_id, pr->cdev->id); 680 device->dev.bus_id, pr->cdev->id);
672 681
673 result = sysfs_create_link(&device->dev.kobj, 682 result = sysfs_create_link(&device->dev.kobj,
674 &pr->cdev->device.kobj, 683 &pr->cdev->device.kobj,
675 "thermal_cooling"); 684 "thermal_cooling");
676 if (result) 685 if (result)
677 return result; 686 printk(KERN_ERR PREFIX "Create sysfs link\n");
678 result = sysfs_create_link(&pr->cdev->device.kobj, 687 result = sysfs_create_link(&pr->cdev->device.kobj,
679 &device->dev.kobj, 688 &device->dev.kobj,
680 "device"); 689 "device");
681 if (result) 690 if (result)
682 return result; 691 printk(KERN_ERR PREFIX "Create sysfs link\n");
683 }
684 692
685 if (pr->flags.throttling) { 693 if (pr->flags.throttling) {
686 printk(KERN_INFO PREFIX "%s [%s] (supports", 694 printk(KERN_INFO PREFIX "%s [%s] (supports",
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 789d4947ed31..2dd2c1f3a01c 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -847,6 +847,7 @@ static int acpi_processor_get_power_info_default(struct acpi_processor *pr)
847 /* all processors need to support C1 */ 847 /* all processors need to support C1 */
848 pr->power.states[ACPI_STATE_C1].type = ACPI_STATE_C1; 848 pr->power.states[ACPI_STATE_C1].type = ACPI_STATE_C1;
849 pr->power.states[ACPI_STATE_C1].valid = 1; 849 pr->power.states[ACPI_STATE_C1].valid = 1;
850 pr->power.states[ACPI_STATE_C1].entry_method = ACPI_CSTATE_HALT;
850 } 851 }
851 /* the C0 state only exists as a filler in our array */ 852 /* the C0 state only exists as a filler in our array */
852 pr->power.states[ACPI_STATE_C0].valid = 1; 853 pr->power.states[ACPI_STATE_C0].valid = 1;
@@ -959,6 +960,9 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
959 cx.address); 960 cx.address);
960 } 961 }
961 962
963 if (cx.type == ACPI_STATE_C1) {
964 cx.valid = 1;
965 }
962 966
963 obj = &(element->package.elements[2]); 967 obj = &(element->package.elements[2]);
964 if (obj->type != ACPI_TYPE_INTEGER) 968 if (obj->type != ACPI_TYPE_INTEGER)
@@ -1295,6 +1299,8 @@ int acpi_processor_cst_has_changed(struct acpi_processor *pr)
1295{ 1299{
1296 int result = 0; 1300 int result = 0;
1297 1301
1302 if (boot_option_idle_override)
1303 return 0;
1298 1304
1299 if (!pr) 1305 if (!pr)
1300 return -EINVAL; 1306 return -EINVAL;
@@ -1734,6 +1740,9 @@ int acpi_processor_cst_has_changed(struct acpi_processor *pr)
1734{ 1740{
1735 int ret; 1741 int ret;
1736 1742
1743 if (boot_option_idle_override)
1744 return 0;
1745
1737 if (!pr) 1746 if (!pr)
1738 return -EINVAL; 1747 return -EINVAL;
1739 1748
@@ -1764,6 +1773,8 @@ int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
1764 struct proc_dir_entry *entry = NULL; 1773 struct proc_dir_entry *entry = NULL;
1765 unsigned int i; 1774 unsigned int i;
1766 1775
1776 if (boot_option_idle_override)
1777 return 0;
1767 1778
1768 if (!first_run) { 1779 if (!first_run) {
1769 dmi_check_system(processor_power_dmi_table); 1780 dmi_check_system(processor_power_dmi_table);
@@ -1799,7 +1810,7 @@ int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
1799 * Note that we use previously set idle handler will be used on 1810 * Note that we use previously set idle handler will be used on
1800 * platforms that only support C1. 1811 * platforms that only support C1.
1801 */ 1812 */
1802 if ((pr->flags.power) && (!boot_option_idle_override)) { 1813 if (pr->flags.power) {
1803#ifdef CONFIG_CPU_IDLE 1814#ifdef CONFIG_CPU_IDLE
1804 acpi_processor_setup_cpuidle(pr); 1815 acpi_processor_setup_cpuidle(pr);
1805 pr->power.dev.cpu = pr->id; 1816 pr->power.dev.cpu = pr->id;
@@ -1835,8 +1846,11 @@ int __cpuinit acpi_processor_power_init(struct acpi_processor *pr,
1835int acpi_processor_power_exit(struct acpi_processor *pr, 1846int acpi_processor_power_exit(struct acpi_processor *pr,
1836 struct acpi_device *device) 1847 struct acpi_device *device)
1837{ 1848{
1849 if (boot_option_idle_override)
1850 return 0;
1851
1838#ifdef CONFIG_CPU_IDLE 1852#ifdef CONFIG_CPU_IDLE
1839 if ((pr->flags.power) && (!boot_option_idle_override)) 1853 if (pr->flags.power)
1840 cpuidle_unregister_device(&pr->power.dev); 1854 cpuidle_unregister_device(&pr->power.dev);
1841#endif 1855#endif
1842 pr->flags.power_setup_done = 0; 1856 pr->flags.power_setup_done = 0;
diff --git a/drivers/acpi/resources/rsaddr.c b/drivers/acpi/resources/rsaddr.c
index 271e61509eeb..7f96332822bf 100644
--- a/drivers/acpi/resources/rsaddr.c
+++ b/drivers/acpi/resources/rsaddr.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/resources/rscalc.c b/drivers/acpi/resources/rscalc.c
index 0dd2ce8a3475..8a112d11d491 100644
--- a/drivers/acpi/resources/rscalc.c
+++ b/drivers/acpi/resources/rscalc.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -73,7 +73,7 @@ acpi_rs_stream_option_length(u32 resource_length, u32 minimum_total_length);
73 73
74static u8 acpi_rs_count_set_bits(u16 bit_field) 74static u8 acpi_rs_count_set_bits(u16 bit_field)
75{ 75{
76 u8 bits_set; 76 acpi_native_uint bits_set;
77 77
78 ACPI_FUNCTION_ENTRY(); 78 ACPI_FUNCTION_ENTRY();
79 79
@@ -81,10 +81,10 @@ static u8 acpi_rs_count_set_bits(u16 bit_field)
81 81
82 /* Zero the least significant bit that is set */ 82 /* Zero the least significant bit that is set */
83 83
84 bit_field &= (bit_field - 1); 84 bit_field &= (u16) (bit_field - 1);
85 } 85 }
86 86
87 return (bits_set); 87 return ((u8) bits_set);
88} 88}
89 89
90/******************************************************************************* 90/*******************************************************************************
@@ -211,6 +211,24 @@ acpi_rs_get_aml_length(struct acpi_resource * resource, acpi_size * size_needed)
211 * variable-length fields 211 * variable-length fields
212 */ 212 */
213 switch (resource->type) { 213 switch (resource->type) {
214 case ACPI_RESOURCE_TYPE_IRQ:
215
216 /* Length can be 3 or 2 */
217
218 if (resource->data.irq.descriptor_length == 2) {
219 total_size--;
220 }
221 break;
222
223 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
224
225 /* Length can be 1 or 0 */
226
227 if (resource->data.irq.descriptor_length == 0) {
228 total_size--;
229 }
230 break;
231
214 case ACPI_RESOURCE_TYPE_VENDOR: 232 case ACPI_RESOURCE_TYPE_VENDOR:
215 /* 233 /*
216 * Vendor Defined Resource: 234 * Vendor Defined Resource:
diff --git a/drivers/acpi/resources/rscreate.c b/drivers/acpi/resources/rscreate.c
index 50da494c3ee2..faddaee1bc07 100644
--- a/drivers/acpi/resources/rscreate.c
+++ b/drivers/acpi/resources/rscreate.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/resources/rsdump.c b/drivers/acpi/resources/rsdump.c
index 46da116a4030..6bbbb7b8941a 100644
--- a/drivers/acpi/resources/rsdump.c
+++ b/drivers/acpi/resources/rsdump.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -87,8 +87,10 @@ acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table);
87 * 87 *
88 ******************************************************************************/ 88 ******************************************************************************/
89 89
90struct acpi_rsdump_info acpi_rs_dump_irq[6] = { 90struct acpi_rsdump_info acpi_rs_dump_irq[7] = {
91 {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_irq), "IRQ", NULL}, 91 {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_irq), "IRQ", NULL},
92 {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(irq.descriptor_length),
93 "Descriptor Length", NULL},
92 {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(irq.triggering), "Triggering", 94 {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(irq.triggering), "Triggering",
93 acpi_gbl_he_decode}, 95 acpi_gbl_he_decode},
94 {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(irq.polarity), "Polarity", 96 {ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(irq.polarity), "Polarity",
@@ -115,9 +117,11 @@ struct acpi_rsdump_info acpi_rs_dump_dma[6] = {
115 NULL} 117 NULL}
116}; 118};
117 119
118struct acpi_rsdump_info acpi_rs_dump_start_dpf[3] = { 120struct acpi_rsdump_info acpi_rs_dump_start_dpf[4] = {
119 {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_start_dpf), 121 {ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_start_dpf),
120 "Start-Dependent-Functions", NULL}, 122 "Start-Dependent-Functions", NULL},
123 {ACPI_RSD_UINT8, ACPI_RSD_OFFSET(start_dpf.descriptor_length),
124 "Descriptor Length", NULL},
121 {ACPI_RSD_2BITFLAG, ACPI_RSD_OFFSET(start_dpf.compatibility_priority), 125 {ACPI_RSD_2BITFLAG, ACPI_RSD_OFFSET(start_dpf.compatibility_priority),
122 "Compatibility Priority", acpi_gbl_config_decode}, 126 "Compatibility Priority", acpi_gbl_config_decode},
123 {ACPI_RSD_2BITFLAG, ACPI_RSD_OFFSET(start_dpf.performance_robustness), 127 {ACPI_RSD_2BITFLAG, ACPI_RSD_OFFSET(start_dpf.performance_robustness),
diff --git a/drivers/acpi/resources/rsinfo.c b/drivers/acpi/resources/rsinfo.c
index 2c2adb6292c1..3f0a1fedbe0e 100644
--- a/drivers/acpi/resources/rsinfo.c
+++ b/drivers/acpi/resources/rsinfo.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/resources/rsio.c b/drivers/acpi/resources/rsio.c
index b297bc3e4419..b66d42e7402e 100644
--- a/drivers/acpi/resources/rsio.c
+++ b/drivers/acpi/resources/rsio.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -185,7 +185,7 @@ struct acpi_rsconvert_info acpi_rs_convert_end_tag[2] = {
185 * 185 *
186 ******************************************************************************/ 186 ******************************************************************************/
187 187
188struct acpi_rsconvert_info acpi_rs_get_start_dpf[5] = { 188struct acpi_rsconvert_info acpi_rs_get_start_dpf[6] = {
189 {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_START_DEPENDENT, 189 {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_START_DEPENDENT,
190 ACPI_RS_SIZE(struct acpi_resource_start_dependent), 190 ACPI_RS_SIZE(struct acpi_resource_start_dependent),
191 ACPI_RSC_TABLE_SIZE(acpi_rs_get_start_dpf)}, 191 ACPI_RSC_TABLE_SIZE(acpi_rs_get_start_dpf)},
@@ -196,6 +196,12 @@ struct acpi_rsconvert_info acpi_rs_get_start_dpf[5] = {
196 ACPI_ACCEPTABLE_CONFIGURATION, 196 ACPI_ACCEPTABLE_CONFIGURATION,
197 2}, 197 2},
198 198
199 /* Get the descriptor length (0 or 1 for Start Dpf descriptor) */
200
201 {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.start_dpf.descriptor_length),
202 AML_OFFSET(start_dpf.descriptor_type),
203 0},
204
199 /* All done if there is no flag byte present in the descriptor */ 205 /* All done if there is no flag byte present in the descriptor */
200 206
201 {ACPI_RSC_EXIT_NE, ACPI_RSC_COMPARE_AML_LENGTH, 0, 1}, 207 {ACPI_RSC_EXIT_NE, ACPI_RSC_COMPARE_AML_LENGTH, 0, 1},
@@ -219,7 +225,9 @@ struct acpi_rsconvert_info acpi_rs_get_start_dpf[5] = {
219 * 225 *
220 ******************************************************************************/ 226 ******************************************************************************/
221 227
222struct acpi_rsconvert_info acpi_rs_set_start_dpf[6] = { 228struct acpi_rsconvert_info acpi_rs_set_start_dpf[10] = {
229 /* Start with a default descriptor of length 1 */
230
223 {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_START_DEPENDENT, 231 {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_START_DEPENDENT,
224 sizeof(struct aml_resource_start_dependent), 232 sizeof(struct aml_resource_start_dependent),
225 ACPI_RSC_TABLE_SIZE(acpi_rs_set_start_dpf)}, 233 ACPI_RSC_TABLE_SIZE(acpi_rs_set_start_dpf)},
@@ -236,6 +244,33 @@ struct acpi_rsconvert_info acpi_rs_set_start_dpf[6] = {
236 AML_OFFSET(start_dpf.flags), 244 AML_OFFSET(start_dpf.flags),
237 2}, 245 2},
238 /* 246 /*
247 * All done if the output descriptor length is required to be 1
248 * (i.e., optimization to 0 bytes cannot be attempted)
249 */
250 {ACPI_RSC_EXIT_EQ, ACPI_RSC_COMPARE_VALUE,
251 ACPI_RS_OFFSET(data.start_dpf.descriptor_length),
252 1},
253
254 /* Set length to 0 bytes (no flags byte) */
255
256 {ACPI_RSC_LENGTH, 0, 0,
257 sizeof(struct aml_resource_start_dependent_noprio)},
258
259 /*
260 * All done if the output descriptor length is required to be 0.
261 *
262 * TBD: Perhaps we should check for error if input flags are not
263 * compatible with a 0-byte descriptor.
264 */
265 {ACPI_RSC_EXIT_EQ, ACPI_RSC_COMPARE_VALUE,
266 ACPI_RS_OFFSET(data.start_dpf.descriptor_length),
267 0},
268
269 /* Reset length to 1 byte (descriptor with flags byte) */
270
271 {ACPI_RSC_LENGTH, 0, 0, sizeof(struct aml_resource_start_dependent)},
272
273 /*
239 * All done if flags byte is necessary -- if either priority value 274 * All done if flags byte is necessary -- if either priority value
240 * is not ACPI_ACCEPTABLE_CONFIGURATION 275 * is not ACPI_ACCEPTABLE_CONFIGURATION
241 */ 276 */
diff --git a/drivers/acpi/resources/rsirq.c b/drivers/acpi/resources/rsirq.c
index 5657f7b95039..a8805efc0366 100644
--- a/drivers/acpi/resources/rsirq.c
+++ b/drivers/acpi/resources/rsirq.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -52,7 +52,7 @@ ACPI_MODULE_NAME("rsirq")
52 * acpi_rs_get_irq 52 * acpi_rs_get_irq
53 * 53 *
54 ******************************************************************************/ 54 ******************************************************************************/
55struct acpi_rsconvert_info acpi_rs_get_irq[7] = { 55struct acpi_rsconvert_info acpi_rs_get_irq[8] = {
56 {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_IRQ, 56 {ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_IRQ,
57 ACPI_RS_SIZE(struct acpi_resource_irq), 57 ACPI_RS_SIZE(struct acpi_resource_irq),
58 ACPI_RSC_TABLE_SIZE(acpi_rs_get_irq)}, 58 ACPI_RSC_TABLE_SIZE(acpi_rs_get_irq)},
@@ -69,6 +69,12 @@ struct acpi_rsconvert_info acpi_rs_get_irq[7] = {
69 ACPI_EDGE_SENSITIVE, 69 ACPI_EDGE_SENSITIVE,
70 1}, 70 1},
71 71
72 /* Get the descriptor length (2 or 3 for IRQ descriptor) */
73
74 {ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.irq.descriptor_length),
75 AML_OFFSET(irq.descriptor_type),
76 0},
77
72 /* All done if no flag byte present in descriptor */ 78 /* All done if no flag byte present in descriptor */
73 79
74 {ACPI_RSC_EXIT_NE, ACPI_RSC_COMPARE_AML_LENGTH, 0, 3}, 80 {ACPI_RSC_EXIT_NE, ACPI_RSC_COMPARE_AML_LENGTH, 0, 3},
@@ -94,7 +100,9 @@ struct acpi_rsconvert_info acpi_rs_get_irq[7] = {
94 * 100 *
95 ******************************************************************************/ 101 ******************************************************************************/
96 102
97struct acpi_rsconvert_info acpi_rs_set_irq[9] = { 103struct acpi_rsconvert_info acpi_rs_set_irq[13] = {
104 /* Start with a default descriptor of length 3 */
105
98 {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_IRQ, 106 {ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_IRQ,
99 sizeof(struct aml_resource_irq), 107 sizeof(struct aml_resource_irq),
100 ACPI_RSC_TABLE_SIZE(acpi_rs_set_irq)}, 108 ACPI_RSC_TABLE_SIZE(acpi_rs_set_irq)},
@@ -105,7 +113,7 @@ struct acpi_rsconvert_info acpi_rs_set_irq[9] = {
105 AML_OFFSET(irq.irq_mask), 113 AML_OFFSET(irq.irq_mask),
106 ACPI_RS_OFFSET(data.irq.interrupt_count)}, 114 ACPI_RS_OFFSET(data.irq.interrupt_count)},
107 115
108 /* Set the flags byte by default */ 116 /* Set the flags byte */
109 117
110 {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.irq.triggering), 118 {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.irq.triggering),
111 AML_OFFSET(irq.flags), 119 AML_OFFSET(irq.flags),
@@ -118,6 +126,33 @@ struct acpi_rsconvert_info acpi_rs_set_irq[9] = {
118 {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.irq.sharable), 126 {ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.irq.sharable),
119 AML_OFFSET(irq.flags), 127 AML_OFFSET(irq.flags),
120 4}, 128 4},
129
130 /*
131 * All done if the output descriptor length is required to be 3
132 * (i.e., optimization to 2 bytes cannot be attempted)
133 */
134 {ACPI_RSC_EXIT_EQ, ACPI_RSC_COMPARE_VALUE,
135 ACPI_RS_OFFSET(data.irq.descriptor_length),
136 3},
137
138 /* Set length to 2 bytes (no flags byte) */
139
140 {ACPI_RSC_LENGTH, 0, 0, sizeof(struct aml_resource_irq_noflags)},
141
142 /*
143 * All done if the output descriptor length is required to be 2.
144 *
145 * TBD: Perhaps we should check for error if input flags are not
146 * compatible with a 2-byte descriptor.
147 */
148 {ACPI_RSC_EXIT_EQ, ACPI_RSC_COMPARE_VALUE,
149 ACPI_RS_OFFSET(data.irq.descriptor_length),
150 2},
151
152 /* Reset length to 3 bytes (descriptor with flags byte) */
153
154 {ACPI_RSC_LENGTH, 0, 0, sizeof(struct aml_resource_irq)},
155
121 /* 156 /*
122 * Check if the flags byte is necessary. Not needed if the flags are: 157 * Check if the flags byte is necessary. Not needed if the flags are:
123 * ACPI_EDGE_SENSITIVE, ACPI_ACTIVE_HIGH, ACPI_EXCLUSIVE 158 * ACPI_EDGE_SENSITIVE, ACPI_ACTIVE_HIGH, ACPI_EXCLUSIVE
@@ -134,7 +169,7 @@ struct acpi_rsconvert_info acpi_rs_set_irq[9] = {
134 ACPI_RS_OFFSET(data.irq.sharable), 169 ACPI_RS_OFFSET(data.irq.sharable),
135 ACPI_EXCLUSIVE}, 170 ACPI_EXCLUSIVE},
136 171
137 /* irq_no_flags() descriptor can be used */ 172 /* We can optimize to a 2-byte irq_no_flags() descriptor */
138 173
139 {ACPI_RSC_LENGTH, 0, 0, sizeof(struct aml_resource_irq_noflags)} 174 {ACPI_RSC_LENGTH, 0, 0, sizeof(struct aml_resource_irq_noflags)}
140}; 175};
diff --git a/drivers/acpi/resources/rslist.c b/drivers/acpi/resources/rslist.c
index ca21e4660c79..b78c7e797a19 100644
--- a/drivers/acpi/resources/rslist.c
+++ b/drivers/acpi/resources/rslist.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/resources/rsmemory.c b/drivers/acpi/resources/rsmemory.c
index 521eab7dd8df..63b21abd90bb 100644
--- a/drivers/acpi/resources/rsmemory.c
+++ b/drivers/acpi/resources/rsmemory.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/resources/rsmisc.c b/drivers/acpi/resources/rsmisc.c
index c7081afa893a..de1ac3881b22 100644
--- a/drivers/acpi/resources/rsmisc.c
+++ b/drivers/acpi/resources/rsmisc.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -497,6 +497,17 @@ acpi_rs_convert_resource_to_aml(struct acpi_resource *resource,
497 } 497 }
498 break; 498 break;
499 499
500 case ACPI_RSC_EXIT_EQ:
501 /*
502 * Control - Exit conversion if equal
503 */
504 if (*ACPI_ADD_PTR(u8, resource,
505 COMPARE_TARGET(info)) ==
506 COMPARE_VALUE(info)) {
507 goto exit;
508 }
509 break;
510
500 default: 511 default:
501 512
502 ACPI_ERROR((AE_INFO, "Invalid conversion opcode")); 513 ACPI_ERROR((AE_INFO, "Invalid conversion opcode"));
diff --git a/drivers/acpi/resources/rsutils.c b/drivers/acpi/resources/rsutils.c
index 11c0bd7b9cfd..befe2302f41b 100644
--- a/drivers/acpi/resources/rsutils.c
+++ b/drivers/acpi/resources/rsutils.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -97,17 +97,17 @@ u8 acpi_rs_decode_bitmask(u16 mask, u8 * list)
97u16 acpi_rs_encode_bitmask(u8 * list, u8 count) 97u16 acpi_rs_encode_bitmask(u8 * list, u8 count)
98{ 98{
99 acpi_native_uint i; 99 acpi_native_uint i;
100 u16 mask; 100 acpi_native_uint mask;
101 101
102 ACPI_FUNCTION_ENTRY(); 102 ACPI_FUNCTION_ENTRY();
103 103
104 /* Encode the list into a single bitmask */ 104 /* Encode the list into a single bitmask */
105 105
106 for (i = 0, mask = 0; i < count; i++) { 106 for (i = 0, mask = 0; i < count; i++) {
107 mask |= (0x0001 << list[i]); 107 mask |= (0x1 << list[i]);
108 } 108 }
109 109
110 return (mask); 110 return ((u16) mask);
111} 111}
112 112
113/******************************************************************************* 113/*******************************************************************************
diff --git a/drivers/acpi/resources/rsxface.c b/drivers/acpi/resources/rsxface.c
index 4c3fd4cdaf73..f59f4c4e034c 100644
--- a/drivers/acpi/resources/rsxface.c
+++ b/drivers/acpi/resources/rsxface.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index e6ce262b5d44..6d85289f1c12 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -677,9 +677,8 @@ acpi_bus_extract_wakeup_device_power_package(struct acpi_device *device,
677 device->wakeup.resources.count = package->package.count - 2; 677 device->wakeup.resources.count = package->package.count - 2;
678 for (i = 0; i < device->wakeup.resources.count; i++) { 678 for (i = 0; i < device->wakeup.resources.count; i++) {
679 element = &(package->package.elements[i + 2]); 679 element = &(package->package.elements[i + 2]);
680 if (element->type != ACPI_TYPE_ANY) { 680 if (element->type != ACPI_TYPE_LOCAL_REFERENCE)
681 return AE_BAD_DATA; 681 return AE_BAD_DATA;
682 }
683 682
684 device->wakeup.resources.handles[i] = element->reference.handle; 683 device->wakeup.resources.handles[i] = element->reference.handle;
685 } 684 }
@@ -692,6 +691,9 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
692 acpi_status status = 0; 691 acpi_status status = 0;
693 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 692 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
694 union acpi_object *package = NULL; 693 union acpi_object *package = NULL;
694 union acpi_object in_arg[3];
695 struct acpi_object_list arg_list = { 3, in_arg };
696 acpi_status psw_status = AE_OK;
695 697
696 struct acpi_device_id button_device_ids[] = { 698 struct acpi_device_id button_device_ids[] = {
697 {"PNP0C0D", 0}, 699 {"PNP0C0D", 0},
@@ -700,7 +702,6 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
700 {"", 0}, 702 {"", 0},
701 }; 703 };
702 704
703
704 /* _PRW */ 705 /* _PRW */
705 status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer); 706 status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer);
706 if (ACPI_FAILURE(status)) { 707 if (ACPI_FAILURE(status)) {
@@ -718,6 +719,45 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
718 kfree(buffer.pointer); 719 kfree(buffer.pointer);
719 720
720 device->wakeup.flags.valid = 1; 721 device->wakeup.flags.valid = 1;
722 /* Call _PSW/_DSW object to disable its ability to wake the sleeping
723 * system for the ACPI device with the _PRW object.
724 * The _PSW object is depreciated in ACPI 3.0 and is replaced by _DSW.
725 * So it is necessary to call _DSW object first. Only when it is not
726 * present will the _PSW object used.
727 */
728 /*
729 * Three agruments are needed for the _DSW object.
730 * Argument 0: enable/disable the wake capabilities
731 * When _DSW object is called to disable the wake capabilities, maybe
732 * the first argument is filled. The value of the other two agruments
733 * is meaningless.
734 */
735 in_arg[0].type = ACPI_TYPE_INTEGER;
736 in_arg[0].integer.value = 0;
737 in_arg[1].type = ACPI_TYPE_INTEGER;
738 in_arg[1].integer.value = 0;
739 in_arg[2].type = ACPI_TYPE_INTEGER;
740 in_arg[2].integer.value = 0;
741 psw_status = acpi_evaluate_object(device->handle, "_DSW",
742 &arg_list, NULL);
743 if (ACPI_FAILURE(psw_status) && (psw_status != AE_NOT_FOUND))
744 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "error in evaluate _DSW\n"));
745 /*
746 * When the _DSW object is not present, OSPM will call _PSW object.
747 */
748 if (psw_status == AE_NOT_FOUND) {
749 /*
750 * Only one agruments is required for the _PSW object.
751 * agrument 0: enable/disable the wake capabilities
752 */
753 arg_list.count = 1;
754 in_arg[0].integer.value = 0;
755 psw_status = acpi_evaluate_object(device->handle, "_PSW",
756 &arg_list, NULL);
757 if (ACPI_FAILURE(psw_status) && (psw_status != AE_NOT_FOUND))
758 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "error in "
759 "evaluate _PSW\n"));
760 }
721 /* Power button, Lid switch always enable wakeup */ 761 /* Power button, Lid switch always enable wakeup */
722 if (!acpi_match_device_ids(device, button_device_ids)) 762 if (!acpi_match_device_ids(device, button_device_ids))
723 device->wakeup.flags.run_wake = 1; 763 device->wakeup.flags.run_wake = 1;
@@ -882,10 +922,7 @@ static void acpi_device_get_busid(struct acpi_device *device,
882static int 922static int
883acpi_video_bus_match(struct acpi_device *device) 923acpi_video_bus_match(struct acpi_device *device)
884{ 924{
885 acpi_handle h_dummy1; 925 acpi_handle h_dummy;
886 acpi_handle h_dummy2;
887 acpi_handle h_dummy3;
888
889 926
890 if (!device) 927 if (!device)
891 return -EINVAL; 928 return -EINVAL;
@@ -895,18 +932,18 @@ acpi_video_bus_match(struct acpi_device *device)
895 */ 932 */
896 933
897 /* Does this device able to support video switching ? */ 934 /* Does this device able to support video switching ? */
898 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOD", &h_dummy1)) && 935 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOD", &h_dummy)) &&
899 ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOS", &h_dummy2))) 936 ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOS", &h_dummy)))
900 return 0; 937 return 0;
901 938
902 /* Does this device able to retrieve a video ROM ? */ 939 /* Does this device able to retrieve a video ROM ? */
903 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ROM", &h_dummy1))) 940 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ROM", &h_dummy)))
904 return 0; 941 return 0;
905 942
906 /* Does this device able to configure which video head to be POSTed ? */ 943 /* Does this device able to configure which video head to be POSTed ? */
907 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_VPO", &h_dummy1)) && 944 if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_VPO", &h_dummy)) &&
908 ACPI_SUCCESS(acpi_get_handle(device->handle, "_GPD", &h_dummy2)) && 945 ACPI_SUCCESS(acpi_get_handle(device->handle, "_GPD", &h_dummy)) &&
909 ACPI_SUCCESS(acpi_get_handle(device->handle, "_SPD", &h_dummy3))) 946 ACPI_SUCCESS(acpi_get_handle(device->handle, "_SPD", &h_dummy)))
910 return 0; 947 return 0;
911 948
912 return -ENODEV; 949 return -ENODEV;
diff --git a/drivers/acpi/sleep/main.c b/drivers/acpi/sleep/main.c
index 71183eea7906..c3b0cd88d09f 100644
--- a/drivers/acpi/sleep/main.c
+++ b/drivers/acpi/sleep/main.c
@@ -51,7 +51,7 @@ static int acpi_sleep_prepare(u32 acpi_state)
51} 51}
52 52
53#ifdef CONFIG_SUSPEND 53#ifdef CONFIG_SUSPEND
54static struct platform_suspend_ops acpi_pm_ops; 54static struct platform_suspend_ops acpi_suspend_ops;
55 55
56extern void do_suspend_lowlevel(void); 56extern void do_suspend_lowlevel(void);
57 57
@@ -65,11 +65,11 @@ static u32 acpi_suspend_states[] = {
65static int init_8259A_after_S1; 65static int init_8259A_after_S1;
66 66
67/** 67/**
68 * acpi_pm_begin - Set the target system sleep state to the state 68 * acpi_suspend_begin - Set the target system sleep state to the state
69 * associated with given @pm_state, if supported. 69 * associated with given @pm_state, if supported.
70 */ 70 */
71 71
72static int acpi_pm_begin(suspend_state_t pm_state) 72static int acpi_suspend_begin(suspend_state_t pm_state)
73{ 73{
74 u32 acpi_state = acpi_suspend_states[pm_state]; 74 u32 acpi_state = acpi_suspend_states[pm_state];
75 int error = 0; 75 int error = 0;
@@ -85,13 +85,13 @@ static int acpi_pm_begin(suspend_state_t pm_state)
85} 85}
86 86
87/** 87/**
88 * acpi_pm_prepare - Do preliminary suspend work. 88 * acpi_suspend_prepare - Do preliminary suspend work.
89 * 89 *
90 * If necessary, set the firmware waking vector and do arch-specific 90 * If necessary, set the firmware waking vector and do arch-specific
91 * nastiness to get the wakeup code to the waking vector. 91 * nastiness to get the wakeup code to the waking vector.
92 */ 92 */
93 93
94static int acpi_pm_prepare(void) 94static int acpi_suspend_prepare(void)
95{ 95{
96 int error = acpi_sleep_prepare(acpi_target_sleep_state); 96 int error = acpi_sleep_prepare(acpi_target_sleep_state);
97 97
@@ -104,7 +104,7 @@ static int acpi_pm_prepare(void)
104} 104}
105 105
106/** 106/**
107 * acpi_pm_enter - Actually enter a sleep state. 107 * acpi_suspend_enter - Actually enter a sleep state.
108 * @pm_state: ignored 108 * @pm_state: ignored
109 * 109 *
110 * Flush caches and go to sleep. For STR we have to call arch-specific 110 * Flush caches and go to sleep. For STR we have to call arch-specific
@@ -112,7 +112,7 @@ static int acpi_pm_prepare(void)
112 * It's unfortunate, but it works. Please fix if you're feeling frisky. 112 * It's unfortunate, but it works. Please fix if you're feeling frisky.
113 */ 113 */
114 114
115static int acpi_pm_enter(suspend_state_t pm_state) 115static int acpi_suspend_enter(suspend_state_t pm_state)
116{ 116{
117 acpi_status status = AE_OK; 117 acpi_status status = AE_OK;
118 unsigned long flags = 0; 118 unsigned long flags = 0;
@@ -169,13 +169,13 @@ static int acpi_pm_enter(suspend_state_t pm_state)
169} 169}
170 170
171/** 171/**
172 * acpi_pm_finish - Instruct the platform to leave a sleep state. 172 * acpi_suspend_finish - Instruct the platform to leave a sleep state.
173 * 173 *
174 * This is called after we wake back up (or if entering the sleep state 174 * This is called after we wake back up (or if entering the sleep state
175 * failed). 175 * failed).
176 */ 176 */
177 177
178static void acpi_pm_finish(void) 178static void acpi_suspend_finish(void)
179{ 179{
180 u32 acpi_state = acpi_target_sleep_state; 180 u32 acpi_state = acpi_target_sleep_state;
181 181
@@ -196,19 +196,19 @@ static void acpi_pm_finish(void)
196} 196}
197 197
198/** 198/**
199 * acpi_pm_end - Finish up suspend sequence. 199 * acpi_suspend_end - Finish up suspend sequence.
200 */ 200 */
201 201
202static void acpi_pm_end(void) 202static void acpi_suspend_end(void)
203{ 203{
204 /* 204 /*
205 * This is necessary in case acpi_pm_finish() is not called during a 205 * This is necessary in case acpi_suspend_finish() is not called during a
206 * failing transition to a sleep state. 206 * failing transition to a sleep state.
207 */ 207 */
208 acpi_target_sleep_state = ACPI_STATE_S0; 208 acpi_target_sleep_state = ACPI_STATE_S0;
209} 209}
210 210
211static int acpi_pm_state_valid(suspend_state_t pm_state) 211static int acpi_suspend_state_valid(suspend_state_t pm_state)
212{ 212{
213 u32 acpi_state; 213 u32 acpi_state;
214 214
@@ -224,13 +224,13 @@ static int acpi_pm_state_valid(suspend_state_t pm_state)
224 } 224 }
225} 225}
226 226
227static struct platform_suspend_ops acpi_pm_ops = { 227static struct platform_suspend_ops acpi_suspend_ops = {
228 .valid = acpi_pm_state_valid, 228 .valid = acpi_suspend_state_valid,
229 .begin = acpi_pm_begin, 229 .begin = acpi_suspend_begin,
230 .prepare = acpi_pm_prepare, 230 .prepare = acpi_suspend_prepare,
231 .enter = acpi_pm_enter, 231 .enter = acpi_suspend_enter,
232 .finish = acpi_pm_finish, 232 .finish = acpi_suspend_finish,
233 .end = acpi_pm_end, 233 .end = acpi_suspend_end,
234}; 234};
235 235
236/* 236/*
@@ -492,7 +492,7 @@ int __init acpi_sleep_init(void)
492 } 492 }
493 } 493 }
494 494
495 suspend_set_ops(&acpi_pm_ops); 495 suspend_set_ops(&acpi_suspend_ops);
496#endif 496#endif
497 497
498#ifdef CONFIG_HIBERNATION 498#ifdef CONFIG_HIBERNATION
diff --git a/drivers/acpi/tables/tbfadt.c b/drivers/acpi/tables/tbfadt.c
index 002bb33003af..949d4114eb9f 100644
--- a/drivers/acpi/tables/tbfadt.c
+++ b/drivers/acpi/tables/tbfadt.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/tables/tbfind.c b/drivers/acpi/tables/tbfind.c
index 058c064948e1..9ca3afc98c80 100644
--- a/drivers/acpi/tables/tbfind.c
+++ b/drivers/acpi/tables/tbfind.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -70,12 +70,22 @@ acpi_tb_find_table(char *signature,
70{ 70{
71 acpi_native_uint i; 71 acpi_native_uint i;
72 acpi_status status; 72 acpi_status status;
73 struct acpi_table_header header;
73 74
74 ACPI_FUNCTION_TRACE(tb_find_table); 75 ACPI_FUNCTION_TRACE(tb_find_table);
75 76
77 /* Normalize the input strings */
78
79 ACPI_MEMSET(&header, 0, sizeof(struct acpi_table_header));
80 ACPI_STRNCPY(header.signature, signature, ACPI_NAME_SIZE);
81 ACPI_STRNCPY(header.oem_id, oem_id, ACPI_OEM_ID_SIZE);
82 ACPI_STRNCPY(header.oem_table_id, oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
83
84 /* Search for the table */
85
76 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) { 86 for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
77 if (ACPI_MEMCMP(&(acpi_gbl_root_table_list.tables[i].signature), 87 if (ACPI_MEMCMP(&(acpi_gbl_root_table_list.tables[i].signature),
78 signature, ACPI_NAME_SIZE)) { 88 header.signature, ACPI_NAME_SIZE)) {
79 89
80 /* Not the requested table */ 90 /* Not the requested table */
81 91
@@ -104,20 +114,24 @@ acpi_tb_find_table(char *signature,
104 114
105 if (!ACPI_MEMCMP 115 if (!ACPI_MEMCMP
106 (acpi_gbl_root_table_list.tables[i].pointer->signature, 116 (acpi_gbl_root_table_list.tables[i].pointer->signature,
107 signature, ACPI_NAME_SIZE) && (!oem_id[0] 117 header.signature, ACPI_NAME_SIZE) && (!oem_id[0]
108 || 118 ||
109 !ACPI_MEMCMP 119 !ACPI_MEMCMP
110 (acpi_gbl_root_table_list. 120 (acpi_gbl_root_table_list.
111 tables[i].pointer->oem_id, 121 tables[i].pointer->
112 oem_id, ACPI_OEM_ID_SIZE)) 122 oem_id,
123 header.oem_id,
124 ACPI_OEM_ID_SIZE))
113 && (!oem_table_id[0] 125 && (!oem_table_id[0]
114 || !ACPI_MEMCMP(acpi_gbl_root_table_list.tables[i]. 126 || !ACPI_MEMCMP(acpi_gbl_root_table_list.tables[i].
115 pointer->oem_table_id, oem_table_id, 127 pointer->oem_table_id,
128 header.oem_table_id,
116 ACPI_OEM_TABLE_ID_SIZE))) { 129 ACPI_OEM_TABLE_ID_SIZE))) {
117 *table_index = i; 130 *table_index = i;
118 131
119 ACPI_DEBUG_PRINT((ACPI_DB_TABLES, 132 ACPI_DEBUG_PRINT((ACPI_DB_TABLES,
120 "Found table [%4.4s]\n", signature)); 133 "Found table [%4.4s]\n",
134 header.signature));
121 return_ACPI_STATUS(AE_OK); 135 return_ACPI_STATUS(AE_OK);
122 } 136 }
123 } 137 }
diff --git a/drivers/acpi/tables/tbinstal.c b/drivers/acpi/tables/tbinstal.c
index 3bc0c67a9283..402f93e1ff20 100644
--- a/drivers/acpi/tables/tbinstal.c
+++ b/drivers/acpi/tables/tbinstal.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -125,13 +125,20 @@ acpi_tb_add_table(struct acpi_table_desc *table_desc,
125 125
126 /* The table must be either an SSDT or a PSDT or an OEMx */ 126 /* The table must be either an SSDT or a PSDT or an OEMx */
127 127
128 if ((!ACPI_COMPARE_NAME(table_desc->pointer->signature, ACPI_SIG_PSDT)) 128 if (!ACPI_COMPARE_NAME(table_desc->pointer->signature, ACPI_SIG_PSDT)&&
129 && 129 !ACPI_COMPARE_NAME(table_desc->pointer->signature, ACPI_SIG_SSDT)&&
130 (!ACPI_COMPARE_NAME(table_desc->pointer->signature, ACPI_SIG_SSDT)) 130 strncmp(table_desc->pointer->signature, "OEM", 3)) {
131 && (strncmp(table_desc->pointer->signature, "OEM", 3))) { 131 /* Check for a printable name */
132 ACPI_ERROR((AE_INFO, 132 if (acpi_ut_valid_acpi_name(
133 "Table has invalid signature [%4.4s], must be SSDT, PSDT or OEMx", 133 *(u32 *) table_desc->pointer->signature)) {
134 table_desc->pointer->signature)); 134 ACPI_ERROR((AE_INFO, "Table has invalid signature "
135 "[%4.4s], must be SSDT or PSDT",
136 table_desc->pointer->signature));
137 } else {
138 ACPI_ERROR((AE_INFO, "Table has invalid signature "
139 "(0x%8.8X), must be SSDT or PSDT",
140 *(u32 *) table_desc->pointer->signature));
141 }
135 return_ACPI_STATUS(AE_BAD_SIGNATURE); 142 return_ACPI_STATUS(AE_BAD_SIGNATURE);
136 } 143 }
137 144
@@ -162,6 +169,7 @@ acpi_tb_add_table(struct acpi_table_desc *table_desc,
162 169
163 acpi_tb_delete_table(table_desc); 170 acpi_tb_delete_table(table_desc);
164 *table_index = i; 171 *table_index = i;
172 status = AE_ALREADY_EXISTS;
165 goto release; 173 goto release;
166 } 174 }
167 175
diff --git a/drivers/acpi/tables/tbutils.c b/drivers/acpi/tables/tbutils.c
index 010f19652f80..bc019b9b6a68 100644
--- a/drivers/acpi/tables/tbutils.c
+++ b/drivers/acpi/tables/tbutils.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -212,7 +212,7 @@ acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length)
212 212
213 if (checksum) { 213 if (checksum) {
214 ACPI_WARNING((AE_INFO, 214 ACPI_WARNING((AE_INFO,
215 "Incorrect checksum in table [%4.4s] - %2.2X, should be %2.2X", 215 "Incorrect checksum in table [%4.4s] - %2.2X, should be %2.2X",
216 table->signature, table->checksum, 216 table->signature, table->checksum,
217 (u8) (table->checksum - checksum))); 217 (u8) (table->checksum - checksum)));
218 218
diff --git a/drivers/acpi/tables/tbxface.c b/drivers/acpi/tables/tbxface.c
index a9e3331fee5d..fb57b93c2495 100644
--- a/drivers/acpi/tables/tbxface.c
+++ b/drivers/acpi/tables/tbxface.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -635,6 +635,95 @@ acpi_status acpi_load_tables(void)
635ACPI_EXPORT_SYMBOL(acpi_load_tables) 635ACPI_EXPORT_SYMBOL(acpi_load_tables)
636 636
637 637
638/*******************************************************************************
639 *
640 * FUNCTION: acpi_install_table_handler
641 *
642 * PARAMETERS: Handler - Table event handler
643 * Context - Value passed to the handler on each event
644 *
645 * RETURN: Status
646 *
647 * DESCRIPTION: Install table event handler
648 *
649 ******************************************************************************/
650acpi_status
651acpi_install_table_handler(acpi_tbl_handler handler, void *context)
652{
653 acpi_status status;
654
655 ACPI_FUNCTION_TRACE(acpi_install_table_handler);
656
657 if (!handler) {
658 return_ACPI_STATUS(AE_BAD_PARAMETER);
659 }
660
661 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
662 if (ACPI_FAILURE(status)) {
663 return_ACPI_STATUS(status);
664 }
665
666 /* Don't allow more than one handler */
667
668 if (acpi_gbl_table_handler) {
669 status = AE_ALREADY_EXISTS;
670 goto cleanup;
671 }
672
673 /* Install the handler */
674
675 acpi_gbl_table_handler = handler;
676 acpi_gbl_table_handler_context = context;
677
678 cleanup:
679 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
680 return_ACPI_STATUS(status);
681}
682
683ACPI_EXPORT_SYMBOL(acpi_install_table_handler)
684
685/*******************************************************************************
686 *
687 * FUNCTION: acpi_remove_table_handler
688 *
689 * PARAMETERS: Handler - Table event handler that was installed
690 * previously.
691 *
692 * RETURN: Status
693 *
694 * DESCRIPTION: Remove table event handler
695 *
696 ******************************************************************************/
697acpi_status acpi_remove_table_handler(acpi_tbl_handler handler)
698{
699 acpi_status status;
700
701 ACPI_FUNCTION_TRACE(acpi_remove_table_handler);
702
703 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
704 if (ACPI_FAILURE(status)) {
705 return_ACPI_STATUS(status);
706 }
707
708 /* Make sure that the installed handler is the same */
709
710 if (!handler || handler != acpi_gbl_table_handler) {
711 status = AE_BAD_PARAMETER;
712 goto cleanup;
713 }
714
715 /* Remove the handler */
716
717 acpi_gbl_table_handler = NULL;
718
719 cleanup:
720 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
721 return_ACPI_STATUS(status);
722}
723
724ACPI_EXPORT_SYMBOL(acpi_remove_table_handler)
725
726
638static int __init acpi_no_auto_ssdt_setup(char *s) { 727static int __init acpi_no_auto_ssdt_setup(char *s) {
639 728
640 printk(KERN_NOTICE "ACPI: SSDT auto-load disabled\n"); 729 printk(KERN_NOTICE "ACPI: SSDT auto-load disabled\n");
diff --git a/drivers/acpi/tables/tbxfroot.c b/drivers/acpi/tables/tbxfroot.c
index 9ecb4b6c1e7d..b8c0dfa084f6 100644
--- a/drivers/acpi/tables/tbxfroot.c
+++ b/drivers/acpi/tables/tbxfroot.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 0815ac3ae3d6..504385b1f211 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -889,10 +889,15 @@ static void acpi_thermal_check(void *data)
889static int thermal_get_temp(struct thermal_zone_device *thermal, char *buf) 889static int thermal_get_temp(struct thermal_zone_device *thermal, char *buf)
890{ 890{
891 struct acpi_thermal *tz = thermal->devdata; 891 struct acpi_thermal *tz = thermal->devdata;
892 int result;
892 893
893 if (!tz) 894 if (!tz)
894 return -EINVAL; 895 return -EINVAL;
895 896
897 result = acpi_thermal_get_temperature(tz);
898 if (result)
899 return result;
900
896 return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS(tz->temperature)); 901 return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS(tz->temperature));
897} 902}
898 903
@@ -1017,6 +1022,18 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
1017 return -EINVAL; 1022 return -EINVAL;
1018} 1023}
1019 1024
1025static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
1026 unsigned long *temperature) {
1027 struct acpi_thermal *tz = thermal->devdata;
1028
1029 if (tz->trips.critical.flags.valid) {
1030 *temperature = KELVIN_TO_MILLICELSIUS(
1031 tz->trips.critical.temperature);
1032 return 0;
1033 } else
1034 return -EINVAL;
1035}
1036
1020typedef int (*cb)(struct thermal_zone_device *, int, 1037typedef int (*cb)(struct thermal_zone_device *, int,
1021 struct thermal_cooling_device *); 1038 struct thermal_cooling_device *);
1022static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal, 1039static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
@@ -1108,6 +1125,7 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
1108 .set_mode = thermal_set_mode, 1125 .set_mode = thermal_set_mode,
1109 .get_trip_type = thermal_get_trip_type, 1126 .get_trip_type = thermal_get_trip_type,
1110 .get_trip_temp = thermal_get_trip_temp, 1127 .get_trip_temp = thermal_get_trip_temp,
1128 .get_crit_temp = thermal_get_crit_temp,
1111}; 1129};
1112 1130
1113static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) 1131static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
@@ -1128,7 +1146,7 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
1128 1146
1129 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && 1147 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
1130 tz->trips.active[i].flags.valid; i++, trips++); 1148 tz->trips.active[i].flags.valid; i++, trips++);
1131 tz->thermal_zone = thermal_zone_device_register("ACPI thermal zone", 1149 tz->thermal_zone = thermal_zone_device_register("acpitz",
1132 trips, tz, &acpi_thermal_zone_ops); 1150 trips, tz, &acpi_thermal_zone_ops);
1133 if (IS_ERR(tz->thermal_zone)) 1151 if (IS_ERR(tz->thermal_zone))
1134 return -ENODEV; 1152 return -ENODEV;
diff --git a/drivers/acpi/utilities/utalloc.c b/drivers/acpi/utilities/utalloc.c
index 6e56d5f7c43a..ede084829a70 100644
--- a/drivers/acpi/utilities/utalloc.c
+++ b/drivers/acpi/utilities/utalloc.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -147,7 +147,7 @@ acpi_status acpi_ut_delete_caches(void)
147 147
148 if (acpi_gbl_display_final_mem_stats) { 148 if (acpi_gbl_display_final_mem_stats) {
149 ACPI_STRCPY(buffer, "MEMORY"); 149 ACPI_STRCPY(buffer, "MEMORY");
150 acpi_db_display_statistics(buffer); 150 (void)acpi_db_display_statistics(buffer);
151 } 151 }
152#endif 152#endif
153 153
diff --git a/drivers/acpi/utilities/utcache.c b/drivers/acpi/utilities/utcache.c
index 285a0f531760..245fa80cf600 100644
--- a/drivers/acpi/utilities/utcache.c
+++ b/drivers/acpi/utilities/utcache.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/utilities/utcopy.c b/drivers/acpi/utilities/utcopy.c
index 879eaa10d3ae..655c290aca7b 100644
--- a/drivers/acpi/utilities/utcopy.c
+++ b/drivers/acpi/utilities/utcopy.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -43,6 +43,8 @@
43 43
44#include <acpi/acpi.h> 44#include <acpi/acpi.h>
45#include <acpi/amlcode.h> 45#include <acpi/amlcode.h>
46#include <acpi/acnamesp.h>
47
46 48
47#define _COMPONENT ACPI_UTILITIES 49#define _COMPONENT ACPI_UTILITIES
48ACPI_MODULE_NAME("utcopy") 50ACPI_MODULE_NAME("utcopy")
@@ -172,22 +174,21 @@ acpi_ut_copy_isimple_to_esimple(union acpi_operand_object *internal_object,
172 174
173 case ACPI_TYPE_LOCAL_REFERENCE: 175 case ACPI_TYPE_LOCAL_REFERENCE:
174 176
175 /* 177 /* This is an object reference. */
176 * This is an object reference. Attempt to dereference it. 178
177 */
178 switch (internal_object->reference.opcode) { 179 switch (internal_object->reference.opcode) {
179 case AML_INT_NAMEPATH_OP: 180 case AML_INT_NAMEPATH_OP:
180 181
181 /* For namepath, return the object handle ("reference") */ 182 /* For namepath, return the object handle ("reference") */
182 183
183 default: 184 default:
184 /* 185
185 * Use the object type of "Any" to indicate a reference 186 /* We are referring to the namespace node */
186 * to object containing a handle to an ACPI named object. 187
187 */
188 external_object->type = ACPI_TYPE_ANY;
189 external_object->reference.handle = 188 external_object->reference.handle =
190 internal_object->reference.node; 189 internal_object->reference.node;
190 external_object->reference.actual_type =
191 acpi_ns_get_type(internal_object->reference.node);
191 break; 192 break;
192 } 193 }
193 break; 194 break;
@@ -215,6 +216,11 @@ acpi_ut_copy_isimple_to_esimple(union acpi_operand_object *internal_object,
215 /* 216 /*
216 * There is no corresponding external object type 217 * There is no corresponding external object type
217 */ 218 */
219 ACPI_ERROR((AE_INFO,
220 "Unsupported object type, cannot convert to external object: %s",
221 acpi_ut_get_type_name(ACPI_GET_OBJECT_TYPE
222 (internal_object))));
223
218 return_ACPI_STATUS(AE_SUPPORT); 224 return_ACPI_STATUS(AE_SUPPORT);
219 } 225 }
220 226
@@ -455,6 +461,7 @@ acpi_ut_copy_esimple_to_isimple(union acpi_object *external_object,
455 case ACPI_TYPE_STRING: 461 case ACPI_TYPE_STRING:
456 case ACPI_TYPE_BUFFER: 462 case ACPI_TYPE_BUFFER:
457 case ACPI_TYPE_INTEGER: 463 case ACPI_TYPE_INTEGER:
464 case ACPI_TYPE_LOCAL_REFERENCE:
458 465
459 internal_object = acpi_ut_create_internal_object((u8) 466 internal_object = acpi_ut_create_internal_object((u8)
460 external_object-> 467 external_object->
@@ -464,9 +471,18 @@ acpi_ut_copy_esimple_to_isimple(union acpi_object *external_object,
464 } 471 }
465 break; 472 break;
466 473
474 case ACPI_TYPE_ANY: /* This is the case for a NULL object */
475
476 *ret_internal_object = NULL;
477 return_ACPI_STATUS(AE_OK);
478
467 default: 479 default:
468 /* All other types are not supported */ 480 /* All other types are not supported */
469 481
482 ACPI_ERROR((AE_INFO,
483 "Unsupported object type, cannot convert to internal object: %s",
484 acpi_ut_get_type_name(external_object->type)));
485
470 return_ACPI_STATUS(AE_SUPPORT); 486 return_ACPI_STATUS(AE_SUPPORT);
471 } 487 }
472 488
@@ -502,6 +518,10 @@ acpi_ut_copy_esimple_to_isimple(union acpi_object *external_object,
502 external_object->buffer.length); 518 external_object->buffer.length);
503 519
504 internal_object->buffer.length = external_object->buffer.length; 520 internal_object->buffer.length = external_object->buffer.length;
521
522 /* Mark buffer data valid */
523
524 internal_object->buffer.flags |= AOPOBJ_DATA_VALID;
505 break; 525 break;
506 526
507 case ACPI_TYPE_INTEGER: 527 case ACPI_TYPE_INTEGER:
@@ -509,6 +529,15 @@ acpi_ut_copy_esimple_to_isimple(union acpi_object *external_object,
509 internal_object->integer.value = external_object->integer.value; 529 internal_object->integer.value = external_object->integer.value;
510 break; 530 break;
511 531
532 case ACPI_TYPE_LOCAL_REFERENCE:
533
534 /* TBD: should validate incoming handle */
535
536 internal_object->reference.opcode = AML_INT_NAMEPATH_OP;
537 internal_object->reference.node =
538 external_object->reference.handle;
539 break;
540
512 default: 541 default:
513 /* Other types can't get here */ 542 /* Other types can't get here */
514 break; 543 break;
@@ -570,13 +599,17 @@ acpi_ut_copy_epackage_to_ipackage(union acpi_object *external_object,
570 599
571 /* Truncate package and delete it */ 600 /* Truncate package and delete it */
572 601
573 package_object->package.count = i; 602 package_object->package.count = (u32) i;
574 package_elements[i] = NULL; 603 package_elements[i] = NULL;
575 acpi_ut_remove_reference(package_object); 604 acpi_ut_remove_reference(package_object);
576 return_ACPI_STATUS(status); 605 return_ACPI_STATUS(status);
577 } 606 }
578 } 607 }
579 608
609 /* Mark package data valid */
610
611 package_object->package.flags |= AOPOBJ_DATA_VALID;
612
580 *internal_object = package_object; 613 *internal_object = package_object;
581 return_ACPI_STATUS(status); 614 return_ACPI_STATUS(status);
582} 615}
@@ -709,7 +742,15 @@ acpi_ut_copy_simple_object(union acpi_operand_object *source_desc,
709 /* 742 /*
710 * We copied the reference object, so we now must add a reference 743 * We copied the reference object, so we now must add a reference
711 * to the object pointed to by the reference 744 * to the object pointed to by the reference
745 *
746 * DDBHandle reference (from Load/load_table is a special reference,
747 * it's Reference.Object is the table index, so does not need to
748 * increase the reference count
712 */ 749 */
750 if (source_desc->reference.opcode == AML_LOAD_OP) {
751 break;
752 }
753
713 acpi_ut_add_reference(source_desc->reference.object); 754 acpi_ut_add_reference(source_desc->reference.object);
714 break; 755 break;
715 756
diff --git a/drivers/acpi/utilities/utdebug.c b/drivers/acpi/utilities/utdebug.c
index 7361204b1eef..f938f465efa4 100644
--- a/drivers/acpi/utilities/utdebug.c
+++ b/drivers/acpi/utilities/utdebug.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -68,9 +68,9 @@ static const char *acpi_ut_trim_function_name(const char *function_name);
68 68
69void acpi_ut_init_stack_ptr_trace(void) 69void acpi_ut_init_stack_ptr_trace(void)
70{ 70{
71 u32 current_sp; 71 acpi_size current_sp;
72 72
73 acpi_gbl_entry_stack_pointer = ACPI_PTR_DIFF(&current_sp, NULL); 73 acpi_gbl_entry_stack_pointer = &current_sp;
74} 74}
75 75
76/******************************************************************************* 76/*******************************************************************************
@@ -89,10 +89,8 @@ void acpi_ut_track_stack_ptr(void)
89{ 89{
90 acpi_size current_sp; 90 acpi_size current_sp;
91 91
92 current_sp = ACPI_PTR_DIFF(&current_sp, NULL); 92 if (&current_sp < acpi_gbl_lowest_stack_pointer) {
93 93 acpi_gbl_lowest_stack_pointer = &current_sp;
94 if (current_sp < acpi_gbl_lowest_stack_pointer) {
95 acpi_gbl_lowest_stack_pointer = current_sp;
96 } 94 }
97 95
98 if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) { 96 if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) {
@@ -203,6 +201,7 @@ acpi_ut_debug_print(u32 requested_debug_level,
203 201
204 va_start(args, format); 202 va_start(args, format);
205 acpi_os_vprintf(format, args); 203 acpi_os_vprintf(format, args);
204 va_end(args);
206} 205}
207 206
208ACPI_EXPORT_SYMBOL(acpi_ut_debug_print) 207ACPI_EXPORT_SYMBOL(acpi_ut_debug_print)
@@ -240,6 +239,7 @@ acpi_ut_debug_print_raw(u32 requested_debug_level,
240 239
241 va_start(args, format); 240 va_start(args, format);
242 acpi_os_vprintf(format, args); 241 acpi_os_vprintf(format, args);
242 va_end(args);
243} 243}
244 244
245ACPI_EXPORT_SYMBOL(acpi_ut_debug_print_raw) 245ACPI_EXPORT_SYMBOL(acpi_ut_debug_print_raw)
@@ -524,6 +524,11 @@ void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display)
524 u32 temp32; 524 u32 temp32;
525 u8 buf_char; 525 u8 buf_char;
526 526
527 if (!buffer) {
528 acpi_os_printf("Null Buffer Pointer in DumpBuffer!\n");
529 return;
530 }
531
527 if ((count < 4) || (count & 0x01)) { 532 if ((count < 4) || (count & 0x01)) {
528 display = DB_BYTE_DISPLAY; 533 display = DB_BYTE_DISPLAY;
529 } 534 }
diff --git a/drivers/acpi/utilities/utdelete.c b/drivers/acpi/utilities/utdelete.c
index f777cebdc46d..1fbc35139e84 100644
--- a/drivers/acpi/utilities/utdelete.c
+++ b/drivers/acpi/utilities/utdelete.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -158,7 +158,7 @@ static void acpi_ut_delete_internal_obj(union acpi_operand_object *object)
158 "***** Mutex %p, OS Mutex %p\n", 158 "***** Mutex %p, OS Mutex %p\n",
159 object, object->mutex.os_mutex)); 159 object, object->mutex.os_mutex));
160 160
161 if (object->mutex.os_mutex == acpi_gbl_global_lock_mutex) { 161 if (object == acpi_gbl_global_lock_mutex) {
162 162
163 /* Global Lock has extra semaphore */ 163 /* Global Lock has extra semaphore */
164 164
@@ -252,6 +252,17 @@ static void acpi_ut_delete_internal_obj(union acpi_operand_object *object)
252 } 252 }
253 break; 253 break;
254 254
255 case ACPI_TYPE_LOCAL_BANK_FIELD:
256
257 ACPI_DEBUG_PRINT((ACPI_DB_ALLOCATIONS,
258 "***** Bank Field %p\n", object));
259
260 second_desc = acpi_ns_get_secondary_object(object);
261 if (second_desc) {
262 acpi_ut_delete_object_desc(second_desc);
263 }
264 break;
265
255 default: 266 default:
256 break; 267 break;
257 } 268 }
@@ -524,10 +535,12 @@ acpi_ut_update_object_reference(union acpi_operand_object *object, u16 action)
524 535
525 case ACPI_TYPE_LOCAL_REFERENCE: 536 case ACPI_TYPE_LOCAL_REFERENCE:
526 /* 537 /*
527 * The target of an Index (a package, string, or buffer) must track 538 * The target of an Index (a package, string, or buffer) or a named
528 * changes to the ref count of the index. 539 * reference must track changes to the ref count of the index or
540 * target object.
529 */ 541 */
530 if (object->reference.opcode == AML_INDEX_OP) { 542 if ((object->reference.opcode == AML_INDEX_OP) ||
543 (object->reference.opcode == AML_INT_NAMEPATH_OP)) {
531 next_object = object->reference.object; 544 next_object = object->reference.object;
532 } 545 }
533 break; 546 break;
diff --git a/drivers/acpi/utilities/uteval.c b/drivers/acpi/utilities/uteval.c
index 0042b7e78b26..05e61be267d5 100644
--- a/drivers/acpi/utilities/uteval.c
+++ b/drivers/acpi/utilities/uteval.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/utilities/utglobal.c b/drivers/acpi/utilities/utglobal.c
index 630c9a2c5b7b..a6e71b801d2d 100644
--- a/drivers/acpi/utilities/utglobal.c
+++ b/drivers/acpi/utilities/utglobal.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -602,6 +602,48 @@ char *acpi_ut_get_mutex_name(u32 mutex_id)
602 602
603 return (acpi_gbl_mutex_names[mutex_id]); 603 return (acpi_gbl_mutex_names[mutex_id]);
604} 604}
605
606/*******************************************************************************
607 *
608 * FUNCTION: acpi_ut_get_notify_name
609 *
610 * PARAMETERS: notify_value - Value from the Notify() request
611 *
612 * RETURN: String corresponding to the Notify Value.
613 *
614 * DESCRIPTION: Translate a Notify Value to a notify namestring.
615 *
616 ******************************************************************************/
617
618/* Names for Notify() values, used for debug output */
619
620static const char *acpi_gbl_notify_value_names[] = {
621 "Bus Check",
622 "Device Check",
623 "Device Wake",
624 "Eject Request",
625 "Device Check Light",
626 "Frequency Mismatch",
627 "Bus Mode Mismatch",
628 "Power Fault",
629 "Capabilities Check",
630 "Device PLD Check",
631 "Reserved",
632 "System Locality Update"
633};
634
635const char *acpi_ut_get_notify_name(u32 notify_value)
636{
637
638 if (notify_value <= ACPI_NOTIFY_MAX) {
639 return (acpi_gbl_notify_value_names[notify_value]);
640 } else if (notify_value <= ACPI_MAX_SYS_NOTIFY) {
641 return ("Reserved");
642 } else { /* Greater or equal to 0x80 */
643
644 return ("**Device Specific**");
645 }
646}
605#endif 647#endif
606 648
607/******************************************************************************* 649/*******************************************************************************
@@ -675,12 +717,13 @@ void acpi_ut_init_globals(void)
675 acpi_gbl_gpe_fadt_blocks[0] = NULL; 717 acpi_gbl_gpe_fadt_blocks[0] = NULL;
676 acpi_gbl_gpe_fadt_blocks[1] = NULL; 718 acpi_gbl_gpe_fadt_blocks[1] = NULL;
677 719
678 /* Global notify handlers */ 720 /* Global handlers */
679 721
680 acpi_gbl_system_notify.handler = NULL; 722 acpi_gbl_system_notify.handler = NULL;
681 acpi_gbl_device_notify.handler = NULL; 723 acpi_gbl_device_notify.handler = NULL;
682 acpi_gbl_exception_handler = NULL; 724 acpi_gbl_exception_handler = NULL;
683 acpi_gbl_init_handler = NULL; 725 acpi_gbl_init_handler = NULL;
726 acpi_gbl_table_handler = NULL;
684 727
685 /* Global Lock support */ 728 /* Global Lock support */
686 729
@@ -722,7 +765,7 @@ void acpi_ut_init_globals(void)
722 acpi_gbl_root_node_struct.flags = ANOBJ_END_OF_PEER_LIST; 765 acpi_gbl_root_node_struct.flags = ANOBJ_END_OF_PEER_LIST;
723 766
724#ifdef ACPI_DEBUG_OUTPUT 767#ifdef ACPI_DEBUG_OUTPUT
725 acpi_gbl_lowest_stack_pointer = ACPI_SIZE_MAX; 768 acpi_gbl_lowest_stack_pointer = ACPI_CAST_PTR(acpi_size, ACPI_SIZE_MAX);
726#endif 769#endif
727 770
728#ifdef ACPI_DBG_TRACK_ALLOCATIONS 771#ifdef ACPI_DBG_TRACK_ALLOCATIONS
diff --git a/drivers/acpi/utilities/utinit.c b/drivers/acpi/utilities/utinit.c
index ad3c0d0a5cf8..cae515fc02d3 100644
--- a/drivers/acpi/utilities/utinit.c
+++ b/drivers/acpi/utilities/utinit.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -125,9 +125,12 @@ void acpi_ut_subsystem_shutdown(void)
125 acpi_gbl_startup_flags = 0; 125 acpi_gbl_startup_flags = 0;
126 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Shutting down ACPI Subsystem\n")); 126 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Shutting down ACPI Subsystem\n"));
127 127
128#ifndef ACPI_ASL_COMPILER
129
128 /* Close the acpi_event Handling */ 130 /* Close the acpi_event Handling */
129 131
130 acpi_ev_terminate(); 132 acpi_ev_terminate();
133#endif
131 134
132 /* Close the Namespace */ 135 /* Close the Namespace */
133 136
diff --git a/drivers/acpi/utilities/utmath.c b/drivers/acpi/utilities/utmath.c
index 0c56a0d20b29..c927324fdd26 100644
--- a/drivers/acpi/utilities/utmath.c
+++ b/drivers/acpi/utilities/utmath.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -276,7 +276,7 @@ acpi_ut_short_divide(acpi_integer in_dividend,
276 *out_quotient = in_dividend / divisor; 276 *out_quotient = in_dividend / divisor;
277 } 277 }
278 if (out_remainder) { 278 if (out_remainder) {
279 *out_remainder = (u32) in_dividend % divisor; 279 *out_remainder = (u32) (in_dividend % divisor);
280 } 280 }
281 281
282 return_ACPI_STATUS(AE_OK); 282 return_ACPI_STATUS(AE_OK);
diff --git a/drivers/acpi/utilities/utmisc.c b/drivers/acpi/utilities/utmisc.c
index 2d19f71e9cfa..e4ba7192cd15 100644
--- a/drivers/acpi/utilities/utmisc.c
+++ b/drivers/acpi/utilities/utmisc.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -1033,6 +1033,7 @@ acpi_ut_error(char *module_name, u32 line_number, char *format, ...)
1033 va_start(args, format); 1033 va_start(args, format);
1034 acpi_os_vprintf(format, args); 1034 acpi_os_vprintf(format, args);
1035 acpi_os_printf(" [%X]\n", ACPI_CA_VERSION); 1035 acpi_os_printf(" [%X]\n", ACPI_CA_VERSION);
1036 va_end(args);
1036} 1037}
1037 1038
1038void ACPI_INTERNAL_VAR_XFACE 1039void ACPI_INTERNAL_VAR_XFACE
@@ -1061,6 +1062,8 @@ acpi_ut_warning(char *module_name, u32 line_number, char *format, ...)
1061 va_start(args, format); 1062 va_start(args, format);
1062 acpi_os_vprintf(format, args); 1063 acpi_os_vprintf(format, args);
1063 acpi_os_printf(" [%X]\n", ACPI_CA_VERSION); 1064 acpi_os_printf(" [%X]\n", ACPI_CA_VERSION);
1065 va_end(args);
1066 va_end(args);
1064} 1067}
1065 1068
1066void ACPI_INTERNAL_VAR_XFACE 1069void ACPI_INTERNAL_VAR_XFACE
@@ -1077,4 +1080,5 @@ acpi_ut_info(char *module_name, u32 line_number, char *format, ...)
1077 va_start(args, format); 1080 va_start(args, format);
1078 acpi_os_vprintf(format, args); 1081 acpi_os_vprintf(format, args);
1079 acpi_os_printf("\n"); 1082 acpi_os_printf("\n");
1083 va_end(args);
1080} 1084}
diff --git a/drivers/acpi/utilities/utmutex.c b/drivers/acpi/utilities/utmutex.c
index 4820bc86d1f5..f7d602b1a894 100644
--- a/drivers/acpi/utilities/utmutex.c
+++ b/drivers/acpi/utilities/utmutex.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/utilities/utobject.c b/drivers/acpi/utilities/utobject.c
index e08b3fa6639f..e68466de8044 100644
--- a/drivers/acpi/utilities/utobject.c
+++ b/drivers/acpi/utilities/utobject.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -107,6 +107,7 @@ union acpi_operand_object *acpi_ut_create_internal_object_dbg(char *module_name,
107 switch (type) { 107 switch (type) {
108 case ACPI_TYPE_REGION: 108 case ACPI_TYPE_REGION:
109 case ACPI_TYPE_BUFFER_FIELD: 109 case ACPI_TYPE_BUFFER_FIELD:
110 case ACPI_TYPE_LOCAL_BANK_FIELD:
110 111
111 /* These types require a secondary object */ 112 /* These types require a secondary object */
112 113
@@ -469,9 +470,8 @@ acpi_ut_get_simple_object_size(union acpi_operand_object *internal_object,
469 case ACPI_TYPE_PROCESSOR: 470 case ACPI_TYPE_PROCESSOR:
470 case ACPI_TYPE_POWER: 471 case ACPI_TYPE_POWER:
471 472
472 /* 473 /* No extra data for these types */
473 * No extra data for these types 474
474 */
475 break; 475 break;
476 476
477 case ACPI_TYPE_LOCAL_REFERENCE: 477 case ACPI_TYPE_LOCAL_REFERENCE:
diff --git a/drivers/acpi/utilities/utresrc.c b/drivers/acpi/utilities/utresrc.c
index b630ee137ee1..c3e3e1308edc 100644
--- a/drivers/acpi/utilities/utresrc.c
+++ b/drivers/acpi/utilities/utresrc.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/utilities/utstate.c b/drivers/acpi/utilities/utstate.c
index edcaafad0a31..63a6d3d77d88 100644
--- a/drivers/acpi/utilities/utstate.c
+++ b/drivers/acpi/utilities/utstate.c
@@ -5,7 +5,7 @@
5 ******************************************************************************/ 5 ******************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/drivers/acpi/utilities/utxface.c b/drivers/acpi/utilities/utxface.c
index 2d496918b3cd..f8bdadf3c32f 100644
--- a/drivers/acpi/utilities/utxface.c
+++ b/drivers/acpi/utilities/utxface.c
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -49,6 +49,7 @@
49#define _COMPONENT ACPI_UTILITIES 49#define _COMPONENT ACPI_UTILITIES
50ACPI_MODULE_NAME("utxface") 50ACPI_MODULE_NAME("utxface")
51 51
52#ifndef ACPI_ASL_COMPILER
52/******************************************************************************* 53/*******************************************************************************
53 * 54 *
54 * FUNCTION: acpi_initialize_subsystem 55 * FUNCTION: acpi_initialize_subsystem
@@ -192,24 +193,6 @@ acpi_status acpi_enable_subsystem(u32 flags)
192 } 193 }
193 } 194 }
194 195
195 /*
196 * Complete the GPE initialization for the GPE blocks defined in the FADT
197 * (GPE block 0 and 1).
198 *
199 * Note1: This is where the _PRW methods are executed for the GPEs. These
200 * methods can only be executed after the SCI and Global Lock handlers are
201 * installed and initialized.
202 *
203 * Note2: Currently, there seems to be no need to run the _REG methods
204 * before execution of the _PRW methods and enabling of the GPEs.
205 */
206 if (!(flags & ACPI_NO_EVENT_INIT)) {
207 status = acpi_ev_install_fadt_gpes();
208 if (ACPI_FAILURE(status)) {
209 return (status);
210 }
211 }
212
213 return_ACPI_STATUS(status); 196 return_ACPI_STATUS(status);
214} 197}
215 198
@@ -280,6 +263,23 @@ acpi_status acpi_initialize_objects(u32 flags)
280 } 263 }
281 264
282 /* 265 /*
266 * Complete the GPE initialization for the GPE blocks defined in the FADT
267 * (GPE block 0 and 1).
268 *
269 * Note1: This is where the _PRW methods are executed for the GPEs. These
270 * methods can only be executed after the SCI and Global Lock handlers are
271 * installed and initialized.
272 *
273 * Note2: Currently, there seems to be no need to run the _REG methods
274 * before execution of the _PRW methods and enabling of the GPEs.
275 */
276 if (!(flags & ACPI_NO_EVENT_INIT)) {
277 status = acpi_ev_install_fadt_gpes();
278 if (ACPI_FAILURE(status))
279 return (status);
280 }
281
282 /*
283 * Empty the caches (delete the cached objects) on the assumption that 283 * Empty the caches (delete the cached objects) on the assumption that
284 * the table load filled them up more than they will be at runtime -- 284 * the table load filled them up more than they will be at runtime --
285 * thus wasting non-paged memory. 285 * thus wasting non-paged memory.
@@ -292,6 +292,7 @@ acpi_status acpi_initialize_objects(u32 flags)
292 292
293ACPI_EXPORT_SYMBOL(acpi_initialize_objects) 293ACPI_EXPORT_SYMBOL(acpi_initialize_objects)
294 294
295#endif
295/******************************************************************************* 296/*******************************************************************************
296 * 297 *
297 * FUNCTION: acpi_terminate 298 * FUNCTION: acpi_terminate
@@ -335,6 +336,7 @@ acpi_status acpi_terminate(void)
335} 336}
336 337
337ACPI_EXPORT_SYMBOL(acpi_terminate) 338ACPI_EXPORT_SYMBOL(acpi_terminate)
339#ifndef ACPI_ASL_COMPILER
338#ifdef ACPI_FUTURE_USAGE 340#ifdef ACPI_FUTURE_USAGE
339/******************************************************************************* 341/*******************************************************************************
340 * 342 *
@@ -490,3 +492,4 @@ acpi_status acpi_purge_cached_objects(void)
490} 492}
491 493
492ACPI_EXPORT_SYMBOL(acpi_purge_cached_objects) 494ACPI_EXPORT_SYMBOL(acpi_purge_cached_objects)
495#endif
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 44ea60cf21c0..100926143818 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -398,7 +398,7 @@ acpi_evaluate_reference(acpi_handle handle,
398 398
399 element = &(package->package.elements[i]); 399 element = &(package->package.elements[i]);
400 400
401 if (element->type != ACPI_TYPE_ANY) { 401 if (element->type != ACPI_TYPE_LOCAL_REFERENCE) {
402 status = AE_BAD_DATA; 402 status = AE_BAD_DATA;
403 printk(KERN_ERR PREFIX 403 printk(KERN_ERR PREFIX
404 "Expecting a [Reference] package element, found type %X\n", 404 "Expecting a [Reference] package element, found type %X\n",
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index 43b228314a86..5e5dda3a3027 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -57,8 +57,6 @@
57#define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88 57#define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
58#define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89 58#define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
59 59
60#define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
61#define ACPI_VIDEO_HEAD_END (~0u)
62#define MAX_NAME_LEN 20 60#define MAX_NAME_LEN 20
63 61
64#define ACPI_VIDEO_DISPLAY_CRT 1 62#define ACPI_VIDEO_DISPLAY_CRT 1
@@ -743,21 +741,19 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
743 if (IS_ERR(device->cdev)) 741 if (IS_ERR(device->cdev))
744 return; 742 return;
745 743
746 if (device->cdev) { 744 printk(KERN_INFO PREFIX
747 printk(KERN_INFO PREFIX 745 "%s is registered as cooling_device%d\n",
748 "%s is registered as cooling_device%d\n", 746 device->dev->dev.bus_id, device->cdev->id);
749 device->dev->dev.bus_id, device->cdev->id); 747 result = sysfs_create_link(&device->dev->dev.kobj,
750 result = sysfs_create_link(&device->dev->dev.kobj, 748 &device->cdev->device.kobj,
751 &device->cdev->device.kobj, 749 "thermal_cooling");
752 "thermal_cooling"); 750 if (result)
753 if (result) 751 printk(KERN_ERR PREFIX "Create sysfs link\n");
754 printk(KERN_ERR PREFIX "Create sysfs link\n"); 752 result = sysfs_create_link(&device->cdev->device.kobj,
755 result = sysfs_create_link(&device->cdev->device.kobj, 753 &device->dev->dev.kobj, "device");
756 &device->dev->dev.kobj, 754 if (result)
757 "device"); 755 printk(KERN_ERR PREFIX "Create sysfs link\n");
758 if (result) 756
759 printk(KERN_ERR PREFIX "Create sysfs link\n");
760 }
761 } 757 }
762 if (device->cap._DCS && device->cap._DSS){ 758 if (device->cap._DCS && device->cap._DSS){
763 static int count = 0; 759 static int count = 0;
@@ -1059,72 +1055,82 @@ acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
1059 1055
1060static int acpi_video_device_add_fs(struct acpi_device *device) 1056static int acpi_video_device_add_fs(struct acpi_device *device)
1061{ 1057{
1062 struct proc_dir_entry *entry = NULL; 1058 struct proc_dir_entry *entry, *device_dir;
1063 struct acpi_video_device *vid_dev; 1059 struct acpi_video_device *vid_dev;
1064 1060
1065
1066 if (!device)
1067 return -ENODEV;
1068
1069 vid_dev = acpi_driver_data(device); 1061 vid_dev = acpi_driver_data(device);
1070 if (!vid_dev) 1062 if (!vid_dev)
1071 return -ENODEV; 1063 return -ENODEV;
1072 1064
1073 if (!acpi_device_dir(device)) { 1065 device_dir = proc_mkdir(acpi_device_bid(device),
1074 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), 1066 vid_dev->video->dir);
1075 vid_dev->video->dir); 1067 if (!device_dir)
1076 if (!acpi_device_dir(device)) 1068 return -ENOMEM;
1077 return -ENODEV; 1069
1078 acpi_device_dir(device)->owner = THIS_MODULE; 1070 device_dir->owner = THIS_MODULE;
1079 }
1080 1071
1081 /* 'info' [R] */ 1072 /* 'info' [R] */
1082 entry = proc_create_data("info", S_IRUGO, acpi_device_dir(device), 1073 entry = proc_create_data("info", S_IRUGO, device_dir,
1083 &acpi_video_device_info_fops, acpi_driver_data(device)); 1074 &acpi_video_device_info_fops, acpi_driver_data(device));
1084 if (!entry) 1075 if (!entry)
1085 return -ENODEV; 1076 goto err_remove_dir;
1086 1077
1087 /* 'state' [R/W] */ 1078 /* 'state' [R/W] */
1088 acpi_video_device_state_fops.write = acpi_video_device_write_state; 1079 acpi_video_device_state_fops.write = acpi_video_device_write_state;
1089 entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR, 1080 entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR,
1090 acpi_device_dir(device), 1081 device_dir,
1091 &acpi_video_device_state_fops, 1082 &acpi_video_device_state_fops,
1092 acpi_driver_data(device)); 1083 acpi_driver_data(device));
1093 if (!entry) 1084 if (!entry)
1094 return -ENODEV; 1085 goto err_remove_info;
1095 1086
1096 /* 'brightness' [R/W] */ 1087 /* 'brightness' [R/W] */
1097 acpi_video_device_brightness_fops.write = 1088 acpi_video_device_brightness_fops.write =
1098 acpi_video_device_write_brightness; 1089 acpi_video_device_write_brightness;
1099 entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR, 1090 entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1100 acpi_device_dir(device), 1091 device_dir,
1101 &acpi_video_device_brightness_fops, 1092 &acpi_video_device_brightness_fops,
1102 acpi_driver_data(device)); 1093 acpi_driver_data(device));
1103 if (!entry) 1094 if (!entry)
1104 return -ENODEV; 1095 goto err_remove_state;
1105 1096
1106 /* 'EDID' [R] */ 1097 /* 'EDID' [R] */
1107 entry = proc_create_data("EDID", S_IRUGO, acpi_device_dir(device), 1098 entry = proc_create_data("EDID", S_IRUGO, device_dir,
1108 &acpi_video_device_EDID_fops, 1099 &acpi_video_device_EDID_fops,
1109 acpi_driver_data(device)); 1100 acpi_driver_data(device));
1110 if (!entry) 1101 if (!entry)
1111 return -ENODEV; 1102 goto err_remove_brightness;
1103
1104 acpi_device_dir(device) = device_dir;
1105
1112 return 0; 1106 return 0;
1107
1108 err_remove_brightness:
1109 remove_proc_entry("brightness", device_dir);
1110 err_remove_state:
1111 remove_proc_entry("state", device_dir);
1112 err_remove_info:
1113 remove_proc_entry("info", device_dir);
1114 err_remove_dir:
1115 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1116 return -ENOMEM;
1113} 1117}
1114 1118
1115static int acpi_video_device_remove_fs(struct acpi_device *device) 1119static int acpi_video_device_remove_fs(struct acpi_device *device)
1116{ 1120{
1117 struct acpi_video_device *vid_dev; 1121 struct acpi_video_device *vid_dev;
1122 struct proc_dir_entry *device_dir;
1118 1123
1119 vid_dev = acpi_driver_data(device); 1124 vid_dev = acpi_driver_data(device);
1120 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir) 1125 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
1121 return -ENODEV; 1126 return -ENODEV;
1122 1127
1123 if (acpi_device_dir(device)) { 1128 device_dir = acpi_device_dir(device);
1124 remove_proc_entry("info", acpi_device_dir(device)); 1129 if (device_dir) {
1125 remove_proc_entry("state", acpi_device_dir(device)); 1130 remove_proc_entry("info", device_dir);
1126 remove_proc_entry("brightness", acpi_device_dir(device)); 1131 remove_proc_entry("state", device_dir);
1127 remove_proc_entry("EDID", acpi_device_dir(device)); 1132 remove_proc_entry("brightness", device_dir);
1133 remove_proc_entry("EDID", device_dir);
1128 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir); 1134 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
1129 acpi_device_dir(device) = NULL; 1135 acpi_device_dir(device) = NULL;
1130 } 1136 }
@@ -1331,76 +1337,81 @@ acpi_video_bus_write_DOS(struct file *file,
1331 1337
1332static int acpi_video_bus_add_fs(struct acpi_device *device) 1338static int acpi_video_bus_add_fs(struct acpi_device *device)
1333{ 1339{
1334 struct proc_dir_entry *entry = NULL; 1340 struct acpi_video_bus *video = acpi_driver_data(device);
1335 struct acpi_video_bus *video; 1341 struct proc_dir_entry *device_dir;
1342 struct proc_dir_entry *entry;
1336 1343
1344 device_dir = proc_mkdir(acpi_device_bid(device), acpi_video_dir);
1345 if (!device_dir)
1346 return -ENOMEM;
1337 1347
1338 video = acpi_driver_data(device); 1348 device_dir->owner = THIS_MODULE;
1339
1340 if (!acpi_device_dir(device)) {
1341 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
1342 acpi_video_dir);
1343 if (!acpi_device_dir(device))
1344 return -ENODEV;
1345 video->dir = acpi_device_dir(device);
1346 acpi_device_dir(device)->owner = THIS_MODULE;
1347 }
1348 1349
1349 /* 'info' [R] */ 1350 /* 'info' [R] */
1350 entry = proc_create_data("info", S_IRUGO, acpi_device_dir(device), 1351 entry = proc_create_data("info", S_IRUGO, device_dir,
1351 &acpi_video_bus_info_fops, 1352 &acpi_video_bus_info_fops,
1352 acpi_driver_data(device)); 1353 acpi_driver_data(device));
1353 if (!entry) 1354 if (!entry)
1354 return -ENODEV; 1355 goto err_remove_dir;
1355 1356
1356 /* 'ROM' [R] */ 1357 /* 'ROM' [R] */
1357 entry = proc_create_data("ROM", S_IRUGO, acpi_device_dir(device), 1358 entry = proc_create_data("ROM", S_IRUGO, device_dir,
1358 &acpi_video_bus_ROM_fops, 1359 &acpi_video_bus_ROM_fops,
1359 acpi_driver_data(device)); 1360 acpi_driver_data(device));
1360 if (!entry) 1361 if (!entry)
1361 return -ENODEV; 1362 goto err_remove_info;
1362 1363
1363 /* 'POST_info' [R] */ 1364 /* 'POST_info' [R] */
1364 entry = proc_create_data("POST_info", S_IRUGO, acpi_device_dir(device), 1365 entry = proc_create_data("POST_info", S_IRUGO, device_dir,
1365 &acpi_video_bus_POST_info_fops, 1366 &acpi_video_bus_POST_info_fops,
1366 acpi_driver_data(device)); 1367 acpi_driver_data(device));
1367 if (!entry) 1368 if (!entry)
1368 return -ENODEV; 1369 goto err_remove_rom;
1369 1370
1370 /* 'POST' [R/W] */ 1371 /* 'POST' [R/W] */
1371 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST; 1372 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
1372 entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IRUSR, 1373 entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR,
1373 acpi_device_dir(device), 1374 device_dir,
1374 &acpi_video_bus_POST_fops, 1375 &acpi_video_bus_POST_fops,
1375 acpi_driver_data(device)); 1376 acpi_driver_data(device));
1376 if (!entry) 1377 if (!entry)
1377 return -ENODEV; 1378 goto err_remove_post_info;
1378 1379
1379 /* 'DOS' [R/W] */ 1380 /* 'DOS' [R/W] */
1380 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS; 1381 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
1381 entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IRUSR, 1382 entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR,
1382 acpi_device_dir(device), 1383 device_dir,
1383 &acpi_video_bus_DOS_fops, 1384 &acpi_video_bus_DOS_fops,
1384 acpi_driver_data(device)); 1385 acpi_driver_data(device));
1385 if (!entry) 1386 if (!entry)
1386 return -ENODEV; 1387 goto err_remove_post;
1387 1388
1389 video->dir = acpi_device_dir(device) = device_dir;
1388 return 0; 1390 return 0;
1391
1392 err_remove_post:
1393 remove_proc_entry("POST", device_dir);
1394 err_remove_post_info:
1395 remove_proc_entry("POST_info", device_dir);
1396 err_remove_rom:
1397 remove_proc_entry("ROM", device_dir);
1398 err_remove_info:
1399 remove_proc_entry("info", device_dir);
1400 err_remove_dir:
1401 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1402 return -ENOMEM;
1389} 1403}
1390 1404
1391static int acpi_video_bus_remove_fs(struct acpi_device *device) 1405static int acpi_video_bus_remove_fs(struct acpi_device *device)
1392{ 1406{
1393 struct acpi_video_bus *video; 1407 struct proc_dir_entry *device_dir = acpi_device_dir(device);
1394
1395 1408
1396 video = acpi_driver_data(device); 1409 if (device_dir) {
1397 1410 remove_proc_entry("info", device_dir);
1398 if (acpi_device_dir(device)) { 1411 remove_proc_entry("ROM", device_dir);
1399 remove_proc_entry("info", acpi_device_dir(device)); 1412 remove_proc_entry("POST_info", device_dir);
1400 remove_proc_entry("ROM", acpi_device_dir(device)); 1413 remove_proc_entry("POST", device_dir);
1401 remove_proc_entry("POST_info", acpi_device_dir(device)); 1414 remove_proc_entry("DOS", device_dir);
1402 remove_proc_entry("POST", acpi_device_dir(device));
1403 remove_proc_entry("DOS", acpi_device_dir(device));
1404 remove_proc_entry(acpi_device_bid(device), acpi_video_dir); 1415 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
1405 acpi_device_dir(device) = NULL; 1416 acpi_device_dir(device) = NULL;
1406 } 1417 }
@@ -1416,11 +1427,15 @@ static int acpi_video_bus_remove_fs(struct acpi_device *device)
1416static struct acpi_video_device_attrib* 1427static struct acpi_video_device_attrib*
1417acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id) 1428acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1418{ 1429{
1419 int count; 1430 struct acpi_video_enumerated_device *ids;
1431 int i;
1432
1433 for (i = 0; i < video->attached_count; i++) {
1434 ids = &video->attached_array[i];
1435 if ((ids->value.int_val & 0xffff) == device_id)
1436 return &ids->value.attrib;
1437 }
1420 1438
1421 for(count = 0; count < video->attached_count; count++)
1422 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1423 return &(video->attached_array[count].value.attrib);
1424 return NULL; 1439 return NULL;
1425} 1440}
1426 1441
@@ -1547,20 +1562,16 @@ static void
1547acpi_video_device_bind(struct acpi_video_bus *video, 1562acpi_video_device_bind(struct acpi_video_bus *video,
1548 struct acpi_video_device *device) 1563 struct acpi_video_device *device)
1549{ 1564{
1565 struct acpi_video_enumerated_device *ids;
1550 int i; 1566 int i;
1551 1567
1552#define IDS_VAL(i) video->attached_array[i].value.int_val 1568 for (i = 0; i < video->attached_count; i++) {
1553#define IDS_BIND(i) video->attached_array[i].bind_info 1569 ids = &video->attached_array[i];
1554 1570 if (device->device_id == (ids->value.int_val & 0xffff)) {
1555 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID && 1571 ids->bind_info = device;
1556 i < video->attached_count; i++) {
1557 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
1558 IDS_BIND(i) = device;
1559 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i)); 1572 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1560 } 1573 }
1561 } 1574 }
1562#undef IDS_VAL
1563#undef IDS_BIND
1564} 1575}
1565 1576
1566/* 1577/*
@@ -1579,7 +1590,7 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1579 int status; 1590 int status;
1580 int count; 1591 int count;
1581 int i; 1592 int i;
1582 struct acpi_video_enumerated_device *active_device_list; 1593 struct acpi_video_enumerated_device *active_list;
1583 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 1594 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1584 union acpi_object *dod = NULL; 1595 union acpi_object *dod = NULL;
1585 union acpi_object *obj; 1596 union acpi_object *obj;
@@ -1600,13 +1611,10 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1600 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n", 1611 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
1601 dod->package.count)); 1612 dod->package.count));
1602 1613
1603 active_device_list = kmalloc((1 + 1614 active_list = kcalloc(1 + dod->package.count,
1604 dod->package.count) * 1615 sizeof(struct acpi_video_enumerated_device),
1605 sizeof(struct 1616 GFP_KERNEL);
1606 acpi_video_enumerated_device), 1617 if (!active_list) {
1607 GFP_KERNEL);
1608
1609 if (!active_device_list) {
1610 status = -ENOMEM; 1618 status = -ENOMEM;
1611 goto out; 1619 goto out;
1612 } 1620 }
@@ -1616,23 +1624,24 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1616 obj = &dod->package.elements[i]; 1624 obj = &dod->package.elements[i];
1617 1625
1618 if (obj->type != ACPI_TYPE_INTEGER) { 1626 if (obj->type != ACPI_TYPE_INTEGER) {
1619 printk(KERN_ERR PREFIX "Invalid _DOD data\n"); 1627 printk(KERN_ERR PREFIX
1620 active_device_list[i].value.int_val = 1628 "Invalid _DOD data in element %d\n", i);
1621 ACPI_VIDEO_HEAD_INVALID; 1629 continue;
1622 } 1630 }
1623 active_device_list[i].value.int_val = obj->integer.value; 1631
1624 active_device_list[i].bind_info = NULL; 1632 active_list[count].value.int_val = obj->integer.value;
1633 active_list[count].bind_info = NULL;
1625 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i, 1634 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1626 (int)obj->integer.value)); 1635 (int)obj->integer.value));
1627 count++; 1636 count++;
1628 } 1637 }
1629 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1630 1638
1631 kfree(video->attached_array); 1639 kfree(video->attached_array);
1632 1640
1633 video->attached_array = active_device_list; 1641 video->attached_array = active_list;
1634 video->attached_count = count; 1642 video->attached_count = count;
1635 out: 1643
1644 out:
1636 kfree(buffer.pointer); 1645 kfree(buffer.pointer);
1637 return status; 1646 return status;
1638} 1647}
diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
index 5aa12b011a9a..6adb72a2f876 100644
--- a/drivers/atm/ambassador.c
+++ b/drivers/atm/ambassador.c
@@ -33,6 +33,7 @@
33#include <linux/interrupt.h> 33#include <linux/interrupt.h>
34#include <linux/poison.h> 34#include <linux/poison.h>
35#include <linux/bitrev.h> 35#include <linux/bitrev.h>
36#include <linux/mutex.h>
36 37
37#include <asm/atomic.h> 38#include <asm/atomic.h>
38#include <asm/io.h> 39#include <asm/io.h>
@@ -1177,7 +1178,7 @@ static int amb_open (struct atm_vcc * atm_vcc)
1177 1178
1178 vcc->tx_frame_bits = tx_frame_bits; 1179 vcc->tx_frame_bits = tx_frame_bits;
1179 1180
1180 down (&dev->vcc_sf); 1181 mutex_lock(&dev->vcc_sf);
1181 if (dev->rxer[vci]) { 1182 if (dev->rxer[vci]) {
1182 // RXer on the channel already, just modify rate... 1183 // RXer on the channel already, just modify rate...
1183 cmd.request = cpu_to_be32 (SRB_MODIFY_VC_RATE); 1184 cmd.request = cpu_to_be32 (SRB_MODIFY_VC_RATE);
@@ -1203,7 +1204,7 @@ static int amb_open (struct atm_vcc * atm_vcc)
1203 schedule(); 1204 schedule();
1204 } 1205 }
1205 dev->txer[vci].tx_present = 1; 1206 dev->txer[vci].tx_present = 1;
1206 up (&dev->vcc_sf); 1207 mutex_unlock(&dev->vcc_sf);
1207 } 1208 }
1208 1209
1209 if (rxtp->traffic_class != ATM_NONE) { 1210 if (rxtp->traffic_class != ATM_NONE) {
@@ -1211,7 +1212,7 @@ static int amb_open (struct atm_vcc * atm_vcc)
1211 1212
1212 vcc->rx_info.pool = pool; 1213 vcc->rx_info.pool = pool;
1213 1214
1214 down (&dev->vcc_sf); 1215 mutex_lock(&dev->vcc_sf);
1215 /* grow RX buffer pool */ 1216 /* grow RX buffer pool */
1216 if (!dev->rxq[pool].buffers_wanted) 1217 if (!dev->rxq[pool].buffers_wanted)
1217 dev->rxq[pool].buffers_wanted = rx_lats; 1218 dev->rxq[pool].buffers_wanted = rx_lats;
@@ -1237,7 +1238,7 @@ static int amb_open (struct atm_vcc * atm_vcc)
1237 schedule(); 1238 schedule();
1238 // this link allows RX frames through 1239 // this link allows RX frames through
1239 dev->rxer[vci] = atm_vcc; 1240 dev->rxer[vci] = atm_vcc;
1240 up (&dev->vcc_sf); 1241 mutex_unlock(&dev->vcc_sf);
1241 } 1242 }
1242 1243
1243 // indicate readiness 1244 // indicate readiness
@@ -1262,7 +1263,7 @@ static void amb_close (struct atm_vcc * atm_vcc) {
1262 if (atm_vcc->qos.txtp.traffic_class != ATM_NONE) { 1263 if (atm_vcc->qos.txtp.traffic_class != ATM_NONE) {
1263 command cmd; 1264 command cmd;
1264 1265
1265 down (&dev->vcc_sf); 1266 mutex_lock(&dev->vcc_sf);
1266 if (dev->rxer[vci]) { 1267 if (dev->rxer[vci]) {
1267 // RXer still on the channel, just modify rate... XXX not really needed 1268 // RXer still on the channel, just modify rate... XXX not really needed
1268 cmd.request = cpu_to_be32 (SRB_MODIFY_VC_RATE); 1269 cmd.request = cpu_to_be32 (SRB_MODIFY_VC_RATE);
@@ -1277,7 +1278,7 @@ static void amb_close (struct atm_vcc * atm_vcc) {
1277 dev->txer[vci].tx_present = 0; 1278 dev->txer[vci].tx_present = 0;
1278 while (command_do (dev, &cmd)) 1279 while (command_do (dev, &cmd))
1279 schedule(); 1280 schedule();
1280 up (&dev->vcc_sf); 1281 mutex_unlock(&dev->vcc_sf);
1281 } 1282 }
1282 1283
1283 // disable RXing 1284 // disable RXing
@@ -1287,7 +1288,7 @@ static void amb_close (struct atm_vcc * atm_vcc) {
1287 // this is (the?) one reason why we need the amb_vcc struct 1288 // this is (the?) one reason why we need the amb_vcc struct
1288 unsigned char pool = vcc->rx_info.pool; 1289 unsigned char pool = vcc->rx_info.pool;
1289 1290
1290 down (&dev->vcc_sf); 1291 mutex_lock(&dev->vcc_sf);
1291 if (dev->txer[vci].tx_present) { 1292 if (dev->txer[vci].tx_present) {
1292 // TXer still on the channel, just go to pool zero XXX not really needed 1293 // TXer still on the channel, just go to pool zero XXX not really needed
1293 cmd.request = cpu_to_be32 (SRB_MODIFY_VC_FLAGS); 1294 cmd.request = cpu_to_be32 (SRB_MODIFY_VC_FLAGS);
@@ -1314,7 +1315,7 @@ static void amb_close (struct atm_vcc * atm_vcc) {
1314 dev->rxq[pool].buffers_wanted = 0; 1315 dev->rxq[pool].buffers_wanted = 0;
1315 drain_rx_pool (dev, pool); 1316 drain_rx_pool (dev, pool);
1316 } 1317 }
1317 up (&dev->vcc_sf); 1318 mutex_unlock(&dev->vcc_sf);
1318 } 1319 }
1319 1320
1320 // free our structure 1321 // free our structure
@@ -2188,7 +2189,7 @@ static void setup_dev(amb_dev *dev, struct pci_dev *pci_dev)
2188 2189
2189 // semaphore for txer/rxer modifications - we cannot use a 2190 // semaphore for txer/rxer modifications - we cannot use a
2190 // spinlock as the critical region needs to switch processes 2191 // spinlock as the critical region needs to switch processes
2191 init_MUTEX (&dev->vcc_sf); 2192 mutex_init(&dev->vcc_sf);
2192 // queue manipulation spinlocks; we want atomic reads and 2193 // queue manipulation spinlocks; we want atomic reads and
2193 // writes to the queue descriptors (handles IRQ and SMP) 2194 // writes to the queue descriptors (handles IRQ and SMP)
2194 // consider replacing "int pending" -> "atomic_t available" 2195 // consider replacing "int pending" -> "atomic_t available"
diff --git a/drivers/atm/ambassador.h b/drivers/atm/ambassador.h
index ff2a303cbe00..df55fa8387dc 100644
--- a/drivers/atm/ambassador.h
+++ b/drivers/atm/ambassador.h
@@ -638,7 +638,7 @@ struct amb_dev {
638 amb_txq txq; 638 amb_txq txq;
639 amb_rxq rxq[NUM_RX_POOLS]; 639 amb_rxq rxq[NUM_RX_POOLS];
640 640
641 struct semaphore vcc_sf; 641 struct mutex vcc_sf;
642 amb_tx_info txer[NUM_VCS]; 642 amb_tx_info txer[NUM_VCS];
643 struct atm_vcc * rxer[NUM_VCS]; 643 struct atm_vcc * rxer[NUM_VCS];
644 unsigned int tx_avail; 644 unsigned int tx_avail;
diff --git a/drivers/base/base.h b/drivers/base/base.h
index c0444146c09a..2c9ae43e2219 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -64,17 +64,6 @@ extern void sysdev_shutdown(void);
64extern int sysdev_suspend(pm_message_t state); 64extern int sysdev_suspend(pm_message_t state);
65extern int sysdev_resume(void); 65extern int sysdev_resume(void);
66 66
67static inline struct class_device *to_class_dev(struct kobject *obj)
68{
69 return container_of(obj, struct class_device, kobj);
70}
71
72static inline
73struct class_device_attribute *to_class_dev_attr(struct attribute *_attr)
74{
75 return container_of(_attr, struct class_device_attribute, attr);
76}
77
78extern char *make_class_name(const char *name, struct kobject *kobj); 67extern char *make_class_name(const char *name, struct kobject *kobj);
79 68
80extern int devres_release_all(struct device *dev); 69extern int devres_release_all(struct device *dev);
diff --git a/drivers/base/class.c b/drivers/base/class.c
index b4901799308b..0ef00e8d4153 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -179,27 +179,13 @@ static void class_create_release(struct class *cls)
179 kfree(cls); 179 kfree(cls);
180} 180}
181 181
182static void class_device_create_release(struct class_device *class_dev)
183{
184 pr_debug("%s called for %s\n", __func__, class_dev->class_id);
185 kfree(class_dev);
186}
187
188/* needed to allow these devices to have parent class devices */
189static int class_device_create_uevent(struct class_device *class_dev,
190 struct kobj_uevent_env *env)
191{
192 pr_debug("%s called for %s\n", __func__, class_dev->class_id);
193 return 0;
194}
195
196/** 182/**
197 * class_create - create a struct class structure 183 * class_create - create a struct class structure
198 * @owner: pointer to the module that is to "own" this struct class 184 * @owner: pointer to the module that is to "own" this struct class
199 * @name: pointer to a string for the name of this class. 185 * @name: pointer to a string for the name of this class.
200 * 186 *
201 * This is used to create a struct class pointer that can then be used 187 * This is used to create a struct class pointer that can then be used
202 * in calls to class_device_create(). 188 * in calls to device_create().
203 * 189 *
204 * Note, the pointer created here is to be destroyed when finished by 190 * Note, the pointer created here is to be destroyed when finished by
205 * making a call to class_destroy(). 191 * making a call to class_destroy().
@@ -218,7 +204,6 @@ struct class *class_create(struct module *owner, const char *name)
218 cls->name = name; 204 cls->name = name;
219 cls->owner = owner; 205 cls->owner = owner;
220 cls->class_release = class_create_release; 206 cls->class_release = class_create_release;
221 cls->release = class_device_create_release;
222 207
223 retval = class_register(cls); 208 retval = class_register(cls);
224 if (retval) 209 if (retval)
@@ -246,113 +231,6 @@ void class_destroy(struct class *cls)
246 class_unregister(cls); 231 class_unregister(cls);
247} 232}
248 233
249/* Class Device Stuff */
250
251int class_device_create_file(struct class_device *class_dev,
252 const struct class_device_attribute *attr)
253{
254 int error = -EINVAL;
255 if (class_dev)
256 error = sysfs_create_file(&class_dev->kobj, &attr->attr);
257 return error;
258}
259
260void class_device_remove_file(struct class_device *class_dev,
261 const struct class_device_attribute *attr)
262{
263 if (class_dev)
264 sysfs_remove_file(&class_dev->kobj, &attr->attr);
265}
266
267int class_device_create_bin_file(struct class_device *class_dev,
268 struct bin_attribute *attr)
269{
270 int error = -EINVAL;
271 if (class_dev)
272 error = sysfs_create_bin_file(&class_dev->kobj, attr);
273 return error;
274}
275
276void class_device_remove_bin_file(struct class_device *class_dev,
277 struct bin_attribute *attr)
278{
279 if (class_dev)
280 sysfs_remove_bin_file(&class_dev->kobj, attr);
281}
282
283static ssize_t class_device_attr_show(struct kobject *kobj,
284 struct attribute *attr, char *buf)
285{
286 struct class_device_attribute *class_dev_attr = to_class_dev_attr(attr);
287 struct class_device *cd = to_class_dev(kobj);
288 ssize_t ret = 0;
289
290 if (class_dev_attr->show)
291 ret = class_dev_attr->show(cd, buf);
292 return ret;
293}
294
295static ssize_t class_device_attr_store(struct kobject *kobj,
296 struct attribute *attr,
297 const char *buf, size_t count)
298{
299 struct class_device_attribute *class_dev_attr = to_class_dev_attr(attr);
300 struct class_device *cd = to_class_dev(kobj);
301 ssize_t ret = 0;
302
303 if (class_dev_attr->store)
304 ret = class_dev_attr->store(cd, buf, count);
305 return ret;
306}
307
308static struct sysfs_ops class_dev_sysfs_ops = {
309 .show = class_device_attr_show,
310 .store = class_device_attr_store,
311};
312
313static void class_dev_release(struct kobject *kobj)
314{
315 struct class_device *cd = to_class_dev(kobj);
316 struct class *cls = cd->class;
317
318 pr_debug("device class '%s': release.\n", cd->class_id);
319
320 if (cd->release)
321 cd->release(cd);
322 else if (cls->release)
323 cls->release(cd);
324 else {
325 printk(KERN_ERR "Class Device '%s' does not have a release() "
326 "function, it is broken and must be fixed.\n",
327 cd->class_id);
328 WARN_ON(1);
329 }
330}
331
332static struct kobj_type class_device_ktype = {
333 .sysfs_ops = &class_dev_sysfs_ops,
334 .release = class_dev_release,
335};
336
337static int class_uevent_filter(struct kset *kset, struct kobject *kobj)
338{
339 struct kobj_type *ktype = get_ktype(kobj);
340
341 if (ktype == &class_device_ktype) {
342 struct class_device *class_dev = to_class_dev(kobj);
343 if (class_dev->class)
344 return 1;
345 }
346 return 0;
347}
348
349static const char *class_uevent_name(struct kset *kset, struct kobject *kobj)
350{
351 struct class_device *class_dev = to_class_dev(kobj);
352
353 return class_dev->class->name;
354}
355
356#ifdef CONFIG_SYSFS_DEPRECATED 234#ifdef CONFIG_SYSFS_DEPRECATED
357char *make_class_name(const char *name, struct kobject *kobj) 235char *make_class_name(const char *name, struct kobject *kobj)
358{ 236{
@@ -370,445 +248,8 @@ char *make_class_name(const char *name, struct kobject *kobj)
370 strcat(class_name, kobject_name(kobj)); 248 strcat(class_name, kobject_name(kobj));
371 return class_name; 249 return class_name;
372} 250}
373
374static int make_deprecated_class_device_links(struct class_device *class_dev)
375{
376 char *class_name;
377 int error;
378
379 if (!class_dev->dev)
380 return 0;
381
382 class_name = make_class_name(class_dev->class->name, &class_dev->kobj);
383 if (class_name)
384 error = sysfs_create_link(&class_dev->dev->kobj,
385 &class_dev->kobj, class_name);
386 else
387 error = -ENOMEM;
388 kfree(class_name);
389 return error;
390}
391
392static void remove_deprecated_class_device_links(struct class_device *class_dev)
393{
394 char *class_name;
395
396 if (!class_dev->dev)
397 return;
398
399 class_name = make_class_name(class_dev->class->name, &class_dev->kobj);
400 if (class_name)
401 sysfs_remove_link(&class_dev->dev->kobj, class_name);
402 kfree(class_name);
403}
404#else
405static inline int make_deprecated_class_device_links(struct class_device *cd)
406{ return 0; }
407static void remove_deprecated_class_device_links(struct class_device *cd)
408{ }
409#endif 251#endif
410 252
411static int class_uevent(struct kset *kset, struct kobject *kobj,
412 struct kobj_uevent_env *env)
413{
414 struct class_device *class_dev = to_class_dev(kobj);
415 struct device *dev = class_dev->dev;
416 int retval = 0;
417
418 pr_debug("%s - name = %s\n", __func__, class_dev->class_id);
419
420 if (MAJOR(class_dev->devt)) {
421 add_uevent_var(env, "MAJOR=%u", MAJOR(class_dev->devt));
422
423 add_uevent_var(env, "MINOR=%u", MINOR(class_dev->devt));
424 }
425
426 if (dev) {
427 const char *path = kobject_get_path(&dev->kobj, GFP_KERNEL);
428 if (path) {
429 add_uevent_var(env, "PHYSDEVPATH=%s", path);
430 kfree(path);
431 }
432
433 if (dev->bus)
434 add_uevent_var(env, "PHYSDEVBUS=%s", dev->bus->name);
435
436 if (dev->driver)
437 add_uevent_var(env, "PHYSDEVDRIVER=%s",
438 dev->driver->name);
439 }
440
441 if (class_dev->uevent) {
442 /* have the class device specific function add its stuff */
443 retval = class_dev->uevent(class_dev, env);
444 if (retval)
445 pr_debug("class_dev->uevent() returned %d\n", retval);
446 } else if (class_dev->class->uevent) {
447 /* have the class specific function add its stuff */
448 retval = class_dev->class->uevent(class_dev, env);
449 if (retval)
450 pr_debug("class->uevent() returned %d\n", retval);
451 }
452
453 return retval;
454}
455
456static struct kset_uevent_ops class_uevent_ops = {
457 .filter = class_uevent_filter,
458 .name = class_uevent_name,
459 .uevent = class_uevent,
460};
461
462/*
463 * DO NOT copy how this is created, kset_create_and_add() should be
464 * called, but this is a hold-over from the old-way and will be deleted
465 * entirely soon.
466 */
467static struct kset class_obj_subsys = {
468 .uevent_ops = &class_uevent_ops,
469};
470
471static int class_device_add_attrs(struct class_device *cd)
472{
473 int i;
474 int error = 0;
475 struct class *cls = cd->class;
476
477 if (cls->class_dev_attrs) {
478 for (i = 0; attr_name(cls->class_dev_attrs[i]); i++) {
479 error = class_device_create_file(cd,
480 &cls->class_dev_attrs[i]);
481 if (error)
482 goto err;
483 }
484 }
485done:
486 return error;
487err:
488 while (--i >= 0)
489 class_device_remove_file(cd, &cls->class_dev_attrs[i]);
490 goto done;
491}
492
493static void class_device_remove_attrs(struct class_device *cd)
494{
495 int i;
496 struct class *cls = cd->class;
497
498 if (cls->class_dev_attrs) {
499 for (i = 0; attr_name(cls->class_dev_attrs[i]); i++)
500 class_device_remove_file(cd, &cls->class_dev_attrs[i]);
501 }
502}
503
504static int class_device_add_groups(struct class_device *cd)
505{
506 int i;
507 int error = 0;
508
509 if (cd->groups) {
510 for (i = 0; cd->groups[i]; i++) {
511 error = sysfs_create_group(&cd->kobj, cd->groups[i]);
512 if (error) {
513 while (--i >= 0)
514 sysfs_remove_group(&cd->kobj,
515 cd->groups[i]);
516 goto out;
517 }
518 }
519 }
520out:
521 return error;
522}
523
524static void class_device_remove_groups(struct class_device *cd)
525{
526 int i;
527 if (cd->groups)
528 for (i = 0; cd->groups[i]; i++)
529 sysfs_remove_group(&cd->kobj, cd->groups[i]);
530}
531
532static ssize_t show_dev(struct class_device *class_dev, char *buf)
533{
534 return print_dev_t(buf, class_dev->devt);
535}
536
537static struct class_device_attribute class_devt_attr =
538 __ATTR(dev, S_IRUGO, show_dev, NULL);
539
540static ssize_t store_uevent(struct class_device *class_dev,
541 const char *buf, size_t count)
542{
543 kobject_uevent(&class_dev->kobj, KOBJ_ADD);
544 return count;
545}
546
547static struct class_device_attribute class_uevent_attr =
548 __ATTR(uevent, S_IWUSR, NULL, store_uevent);
549
550void class_device_initialize(struct class_device *class_dev)
551{
552 class_dev->kobj.kset = &class_obj_subsys;
553 kobject_init(&class_dev->kobj, &class_device_ktype);
554 INIT_LIST_HEAD(&class_dev->node);
555}
556
557int class_device_add(struct class_device *class_dev)
558{
559 struct class *parent_class = NULL;
560 struct class_device *parent_class_dev = NULL;
561 struct class_interface *class_intf;
562 int error = -EINVAL;
563
564 class_dev = class_device_get(class_dev);
565 if (!class_dev)
566 return -EINVAL;
567
568 if (!strlen(class_dev->class_id))
569 goto out1;
570
571 parent_class = class_get(class_dev->class);
572 if (!parent_class)
573 goto out1;
574
575 parent_class_dev = class_device_get(class_dev->parent);
576
577 pr_debug("CLASS: registering class device: ID = '%s'\n",
578 class_dev->class_id);
579
580 /* first, register with generic layer. */
581 if (parent_class_dev)
582 class_dev->kobj.parent = &parent_class_dev->kobj;
583 else
584 class_dev->kobj.parent = &parent_class->subsys.kobj;
585
586 error = kobject_add(&class_dev->kobj, class_dev->kobj.parent,
587 "%s", class_dev->class_id);
588 if (error)
589 goto out2;
590
591 /* add the needed attributes to this device */
592 error = sysfs_create_link(&class_dev->kobj,
593 &parent_class->subsys.kobj, "subsystem");
594 if (error)
595 goto out3;
596
597 error = class_device_create_file(class_dev, &class_uevent_attr);
598 if (error)
599 goto out3;
600
601 if (MAJOR(class_dev->devt)) {
602 error = class_device_create_file(class_dev, &class_devt_attr);
603 if (error)
604 goto out4;
605 }
606
607 error = class_device_add_attrs(class_dev);
608 if (error)
609 goto out5;
610
611 if (class_dev->dev) {
612 error = sysfs_create_link(&class_dev->kobj,
613 &class_dev->dev->kobj, "device");
614 if (error)
615 goto out6;
616 }
617
618 error = class_device_add_groups(class_dev);
619 if (error)
620 goto out7;
621
622 error = make_deprecated_class_device_links(class_dev);
623 if (error)
624 goto out8;
625
626 kobject_uevent(&class_dev->kobj, KOBJ_ADD);
627
628 /* notify any interfaces this device is now here */
629 down(&parent_class->sem);
630 list_add_tail(&class_dev->node, &parent_class->children);
631 list_for_each_entry(class_intf, &parent_class->interfaces, node) {
632 if (class_intf->add)
633 class_intf->add(class_dev, class_intf);
634 }
635 up(&parent_class->sem);
636
637 goto out1;
638
639 out8:
640 class_device_remove_groups(class_dev);
641 out7:
642 if (class_dev->dev)
643 sysfs_remove_link(&class_dev->kobj, "device");
644 out6:
645 class_device_remove_attrs(class_dev);
646 out5:
647 if (MAJOR(class_dev->devt))
648 class_device_remove_file(class_dev, &class_devt_attr);
649 out4:
650 class_device_remove_file(class_dev, &class_uevent_attr);
651 out3:
652 kobject_del(&class_dev->kobj);
653 out2:
654 if (parent_class_dev)
655 class_device_put(parent_class_dev);
656 class_put(parent_class);
657 out1:
658 class_device_put(class_dev);
659 return error;
660}
661
662int class_device_register(struct class_device *class_dev)
663{
664 class_device_initialize(class_dev);
665 return class_device_add(class_dev);
666}
667
668/**
669 * class_device_create - creates a class device and registers it with sysfs
670 * @cls: pointer to the struct class that this device should be registered to.
671 * @parent: pointer to the parent struct class_device of this new device, if
672 * any.
673 * @devt: the dev_t for the char device to be added.
674 * @device: a pointer to a struct device that is assiociated with this class
675 * device.
676 * @fmt: string for the class device's name
677 *
678 * This function can be used by char device classes. A struct
679 * class_device will be created in sysfs, registered to the specified
680 * class.
681 * A "dev" file will be created, showing the dev_t for the device, if
682 * the dev_t is not 0,0.
683 * If a pointer to a parent struct class_device is passed in, the newly
684 * created struct class_device will be a child of that device in sysfs.
685 * The pointer to the struct class_device will be returned from the
686 * call. Any further sysfs files that might be required can be created
687 * using this pointer.
688 *
689 * Note: the struct class passed to this function must have previously
690 * been created with a call to class_create().
691 */
692struct class_device *class_device_create(struct class *cls,
693 struct class_device *parent,
694 dev_t devt,
695 struct device *device,
696 const char *fmt, ...)
697{
698 va_list args;
699 struct class_device *class_dev = NULL;
700 int retval = -ENODEV;
701
702 if (cls == NULL || IS_ERR(cls))
703 goto error;
704
705 class_dev = kzalloc(sizeof(*class_dev), GFP_KERNEL);
706 if (!class_dev) {
707 retval = -ENOMEM;
708 goto error;
709 }
710
711 class_dev->devt = devt;
712 class_dev->dev = device;
713 class_dev->class = cls;
714 class_dev->parent = parent;
715 class_dev->release = class_device_create_release;
716 class_dev->uevent = class_device_create_uevent;
717
718 va_start(args, fmt);
719 vsnprintf(class_dev->class_id, BUS_ID_SIZE, fmt, args);
720 va_end(args);
721 retval = class_device_register(class_dev);
722 if (retval)
723 goto error;
724
725 return class_dev;
726
727error:
728 kfree(class_dev);
729 return ERR_PTR(retval);
730}
731
732void class_device_del(struct class_device *class_dev)
733{
734 struct class *parent_class = class_dev->class;
735 struct class_device *parent_device = class_dev->parent;
736 struct class_interface *class_intf;
737
738 if (parent_class) {
739 down(&parent_class->sem);
740 list_del_init(&class_dev->node);
741 list_for_each_entry(class_intf, &parent_class->interfaces, node)
742 if (class_intf->remove)
743 class_intf->remove(class_dev, class_intf);
744 up(&parent_class->sem);
745 }
746
747 if (class_dev->dev) {
748 remove_deprecated_class_device_links(class_dev);
749 sysfs_remove_link(&class_dev->kobj, "device");
750 }
751 sysfs_remove_link(&class_dev->kobj, "subsystem");
752 class_device_remove_file(class_dev, &class_uevent_attr);
753 if (MAJOR(class_dev->devt))
754 class_device_remove_file(class_dev, &class_devt_attr);
755 class_device_remove_attrs(class_dev);
756 class_device_remove_groups(class_dev);
757
758 kobject_uevent(&class_dev->kobj, KOBJ_REMOVE);
759 kobject_del(&class_dev->kobj);
760
761 class_device_put(parent_device);
762 class_put(parent_class);
763}
764
765void class_device_unregister(struct class_device *class_dev)
766{
767 pr_debug("CLASS: Unregistering class device. ID = '%s'\n",
768 class_dev->class_id);
769 class_device_del(class_dev);
770 class_device_put(class_dev);
771}
772
773/**
774 * class_device_destroy - removes a class device that was created with class_device_create()
775 * @cls: the pointer to the struct class that this device was registered * with.
776 * @devt: the dev_t of the device that was previously registered.
777 *
778 * This call unregisters and cleans up a class device that was created with a
779 * call to class_device_create()
780 */
781void class_device_destroy(struct class *cls, dev_t devt)
782{
783 struct class_device *class_dev = NULL;
784 struct class_device *class_dev_tmp;
785
786 down(&cls->sem);
787 list_for_each_entry(class_dev_tmp, &cls->children, node) {
788 if (class_dev_tmp->devt == devt) {
789 class_dev = class_dev_tmp;
790 break;
791 }
792 }
793 up(&cls->sem);
794
795 if (class_dev)
796 class_device_unregister(class_dev);
797}
798
799struct class_device *class_device_get(struct class_device *class_dev)
800{
801 if (class_dev)
802 return to_class_dev(kobject_get(&class_dev->kobj));
803 return NULL;
804}
805
806void class_device_put(struct class_device *class_dev)
807{
808 if (class_dev)
809 kobject_put(&class_dev->kobj);
810}
811
812/** 253/**
813 * class_for_each_device - device iterator 254 * class_for_each_device - device iterator
814 * @class: the class we're iterating 255 * @class: the class we're iterating
@@ -897,56 +338,9 @@ struct device *class_find_device(struct class *class, void *data,
897} 338}
898EXPORT_SYMBOL_GPL(class_find_device); 339EXPORT_SYMBOL_GPL(class_find_device);
899 340
900/**
901 * class_find_child - device iterator for locating a particular class_device
902 * @class: the class we're iterating
903 * @data: data for the match function
904 * @match: function to check class_device
905 *
906 * This function returns a reference to a class_device that is 'found' for
907 * later use, as determined by the @match callback.
908 *
909 * The callback should return 0 if the class_device doesn't match and non-zero
910 * if it does. If the callback returns non-zero, this function will
911 * return to the caller and not iterate over any more class_devices.
912 *
913 * Note, you will need to drop the reference with class_device_put() after use.
914 *
915 * We hold class->sem in this function, so it can not be
916 * re-acquired in @match, otherwise it will self-deadlocking. For
917 * example, calls to add or remove class members would be verboten.
918 */
919struct class_device *class_find_child(struct class *class, void *data,
920 int (*match)(struct class_device *, void *))
921{
922 struct class_device *dev;
923 int found = 0;
924
925 if (!class)
926 return NULL;
927
928 down(&class->sem);
929 list_for_each_entry(dev, &class->children, node) {
930 dev = class_device_get(dev);
931 if (dev) {
932 if (match(dev, data)) {
933 found = 1;
934 break;
935 } else
936 class_device_put(dev);
937 } else
938 break;
939 }
940 up(&class->sem);
941
942 return found ? dev : NULL;
943}
944EXPORT_SYMBOL_GPL(class_find_child);
945
946int class_interface_register(struct class_interface *class_intf) 341int class_interface_register(struct class_interface *class_intf)
947{ 342{
948 struct class *parent; 343 struct class *parent;
949 struct class_device *class_dev;
950 struct device *dev; 344 struct device *dev;
951 345
952 if (!class_intf || !class_intf->class) 346 if (!class_intf || !class_intf->class)
@@ -958,10 +352,6 @@ int class_interface_register(struct class_interface *class_intf)
958 352
959 down(&parent->sem); 353 down(&parent->sem);
960 list_add_tail(&class_intf->node, &parent->interfaces); 354 list_add_tail(&class_intf->node, &parent->interfaces);
961 if (class_intf->add) {
962 list_for_each_entry(class_dev, &parent->children, node)
963 class_intf->add(class_dev, class_intf);
964 }
965 if (class_intf->add_dev) { 355 if (class_intf->add_dev) {
966 list_for_each_entry(dev, &parent->devices, node) 356 list_for_each_entry(dev, &parent->devices, node)
967 class_intf->add_dev(dev, class_intf); 357 class_intf->add_dev(dev, class_intf);
@@ -974,7 +364,6 @@ int class_interface_register(struct class_interface *class_intf)
974void class_interface_unregister(struct class_interface *class_intf) 364void class_interface_unregister(struct class_interface *class_intf)
975{ 365{
976 struct class *parent = class_intf->class; 366 struct class *parent = class_intf->class;
977 struct class_device *class_dev;
978 struct device *dev; 367 struct device *dev;
979 368
980 if (!parent) 369 if (!parent)
@@ -982,10 +371,6 @@ void class_interface_unregister(struct class_interface *class_intf)
982 371
983 down(&parent->sem); 372 down(&parent->sem);
984 list_del_init(&class_intf->node); 373 list_del_init(&class_intf->node);
985 if (class_intf->remove) {
986 list_for_each_entry(class_dev, &parent->children, node)
987 class_intf->remove(class_dev, class_intf);
988 }
989 if (class_intf->remove_dev) { 374 if (class_intf->remove_dev) {
990 list_for_each_entry(dev, &parent->devices, node) 375 list_for_each_entry(dev, &parent->devices, node)
991 class_intf->remove_dev(dev, class_intf); 376 class_intf->remove_dev(dev, class_intf);
@@ -1000,13 +385,6 @@ int __init classes_init(void)
1000 class_kset = kset_create_and_add("class", NULL, NULL); 385 class_kset = kset_create_and_add("class", NULL, NULL);
1001 if (!class_kset) 386 if (!class_kset)
1002 return -ENOMEM; 387 return -ENOMEM;
1003
1004 /* ick, this is ugly, the things we go through to keep from showing up
1005 * in sysfs... */
1006 kset_init(&class_obj_subsys);
1007 kobject_set_name(&class_obj_subsys.kobj, "class_obj");
1008 if (!class_obj_subsys.kobj.parent)
1009 class_obj_subsys.kobj.parent = &class_obj_subsys.kobj;
1010 return 0; 388 return 0;
1011} 389}
1012 390
@@ -1017,19 +395,5 @@ EXPORT_SYMBOL_GPL(class_unregister);
1017EXPORT_SYMBOL_GPL(class_create); 395EXPORT_SYMBOL_GPL(class_create);
1018EXPORT_SYMBOL_GPL(class_destroy); 396EXPORT_SYMBOL_GPL(class_destroy);
1019 397
1020EXPORT_SYMBOL_GPL(class_device_register);
1021EXPORT_SYMBOL_GPL(class_device_unregister);
1022EXPORT_SYMBOL_GPL(class_device_initialize);
1023EXPORT_SYMBOL_GPL(class_device_add);
1024EXPORT_SYMBOL_GPL(class_device_del);
1025EXPORT_SYMBOL_GPL(class_device_get);
1026EXPORT_SYMBOL_GPL(class_device_put);
1027EXPORT_SYMBOL_GPL(class_device_create);
1028EXPORT_SYMBOL_GPL(class_device_destroy);
1029EXPORT_SYMBOL_GPL(class_device_create_file);
1030EXPORT_SYMBOL_GPL(class_device_remove_file);
1031EXPORT_SYMBOL_GPL(class_device_create_bin_file);
1032EXPORT_SYMBOL_GPL(class_device_remove_bin_file);
1033
1034EXPORT_SYMBOL_GPL(class_interface_register); 398EXPORT_SYMBOL_GPL(class_interface_register);
1035EXPORT_SYMBOL_GPL(class_interface_unregister); 399EXPORT_SYMBOL_GPL(class_interface_unregister);
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 6fe417429977..e38dfed41d80 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -18,7 +18,7 @@ struct sysdev_class cpu_sysdev_class = {
18}; 18};
19EXPORT_SYMBOL(cpu_sysdev_class); 19EXPORT_SYMBOL(cpu_sysdev_class);
20 20
21static struct sys_device *cpu_sys_devices[NR_CPUS]; 21static DEFINE_PER_CPU(struct sys_device *, cpu_sys_devices);
22 22
23#ifdef CONFIG_HOTPLUG_CPU 23#ifdef CONFIG_HOTPLUG_CPU
24static ssize_t show_online(struct sys_device *dev, char *buf) 24static ssize_t show_online(struct sys_device *dev, char *buf)
@@ -68,7 +68,7 @@ void unregister_cpu(struct cpu *cpu)
68 sysdev_remove_file(&cpu->sysdev, &attr_online); 68 sysdev_remove_file(&cpu->sysdev, &attr_online);
69 69
70 sysdev_unregister(&cpu->sysdev); 70 sysdev_unregister(&cpu->sysdev);
71 cpu_sys_devices[logical_cpu] = NULL; 71 per_cpu(cpu_sys_devices, logical_cpu) = NULL;
72 return; 72 return;
73} 73}
74#else /* ... !CONFIG_HOTPLUG_CPU */ 74#else /* ... !CONFIG_HOTPLUG_CPU */
@@ -167,7 +167,7 @@ int __cpuinit register_cpu(struct cpu *cpu, int num)
167 if (!error && cpu->hotpluggable) 167 if (!error && cpu->hotpluggable)
168 register_cpu_control(cpu); 168 register_cpu_control(cpu);
169 if (!error) 169 if (!error)
170 cpu_sys_devices[num] = &cpu->sysdev; 170 per_cpu(cpu_sys_devices, num) = &cpu->sysdev;
171 if (!error) 171 if (!error)
172 register_cpu_under_node(num, cpu_to_node(num)); 172 register_cpu_under_node(num, cpu_to_node(num));
173 173
@@ -180,8 +180,8 @@ int __cpuinit register_cpu(struct cpu *cpu, int num)
180 180
181struct sys_device *get_cpu_sysdev(unsigned cpu) 181struct sys_device *get_cpu_sysdev(unsigned cpu)
182{ 182{
183 if (cpu < NR_CPUS) 183 if (cpu < nr_cpu_ids && cpu_possible(cpu))
184 return cpu_sys_devices[cpu]; 184 return per_cpu(cpu_sys_devices, cpu);
185 else 185 else
186 return NULL; 186 return NULL;
187} 187}
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 9a6537f14401..2ef5acf4368b 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -217,12 +217,22 @@ static void driver_remove_groups(struct device_driver *drv,
217int driver_register(struct device_driver *drv) 217int driver_register(struct device_driver *drv)
218{ 218{
219 int ret; 219 int ret;
220 struct device_driver *other;
220 221
221 if ((drv->bus->probe && drv->probe) || 222 if ((drv->bus->probe && drv->probe) ||
222 (drv->bus->remove && drv->remove) || 223 (drv->bus->remove && drv->remove) ||
223 (drv->bus->shutdown && drv->shutdown)) 224 (drv->bus->shutdown && drv->shutdown))
224 printk(KERN_WARNING "Driver '%s' needs updating - please use " 225 printk(KERN_WARNING "Driver '%s' needs updating - please use "
225 "bus_type methods\n", drv->name); 226 "bus_type methods\n", drv->name);
227
228 other = driver_find(drv->name, drv->bus);
229 if (other) {
230 put_driver(other);
231 printk(KERN_ERR "Error: Driver '%s' is already registered, "
232 "aborting...\n", drv->name);
233 return -EEXIST;
234 }
235
226 ret = bus_add_driver(drv); 236 ret = bus_add_driver(drv);
227 if (ret) 237 if (ret)
228 return ret; 238 return ret;
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 12fde2d03d69..39f3d1b3a213 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -77,6 +77,7 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
77 "Node %d PageTables: %8lu kB\n" 77 "Node %d PageTables: %8lu kB\n"
78 "Node %d NFS_Unstable: %8lu kB\n" 78 "Node %d NFS_Unstable: %8lu kB\n"
79 "Node %d Bounce: %8lu kB\n" 79 "Node %d Bounce: %8lu kB\n"
80 "Node %d WritebackTmp: %8lu kB\n"
80 "Node %d Slab: %8lu kB\n" 81 "Node %d Slab: %8lu kB\n"
81 "Node %d SReclaimable: %8lu kB\n" 82 "Node %d SReclaimable: %8lu kB\n"
82 "Node %d SUnreclaim: %8lu kB\n", 83 "Node %d SUnreclaim: %8lu kB\n",
@@ -99,6 +100,7 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
99 nid, K(node_page_state(nid, NR_PAGETABLE)), 100 nid, K(node_page_state(nid, NR_PAGETABLE)),
100 nid, K(node_page_state(nid, NR_UNSTABLE_NFS)), 101 nid, K(node_page_state(nid, NR_UNSTABLE_NFS)),
101 nid, K(node_page_state(nid, NR_BOUNCE)), 102 nid, K(node_page_state(nid, NR_BOUNCE)),
103 nid, K(node_page_state(nid, NR_WRITEBACK_TEMP)),
102 nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE) + 104 nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE) +
103 node_page_state(nid, NR_SLAB_UNRECLAIMABLE)), 105 node_page_state(nid, NR_SLAB_UNRECLAIMABLE)),
104 nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE)), 106 nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE)),
diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index e8e38faeafd8..a196ef7f147f 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -387,10 +387,14 @@ static struct block_device_operations brd_fops = {
387 */ 387 */
388static int rd_nr; 388static int rd_nr;
389int rd_size = CONFIG_BLK_DEV_RAM_SIZE; 389int rd_size = CONFIG_BLK_DEV_RAM_SIZE;
390static int max_part;
391static int part_shift;
390module_param(rd_nr, int, 0); 392module_param(rd_nr, int, 0);
391MODULE_PARM_DESC(rd_nr, "Maximum number of brd devices"); 393MODULE_PARM_DESC(rd_nr, "Maximum number of brd devices");
392module_param(rd_size, int, 0); 394module_param(rd_size, int, 0);
393MODULE_PARM_DESC(rd_size, "Size of each RAM disk in kbytes."); 395MODULE_PARM_DESC(rd_size, "Size of each RAM disk in kbytes.");
396module_param(max_part, int, 0);
397MODULE_PARM_DESC(max_part, "Maximum number of partitions per RAM disk");
394MODULE_LICENSE("GPL"); 398MODULE_LICENSE("GPL");
395MODULE_ALIAS_BLOCKDEV_MAJOR(RAMDISK_MAJOR); 399MODULE_ALIAS_BLOCKDEV_MAJOR(RAMDISK_MAJOR);
396 400
@@ -435,11 +439,11 @@ static struct brd_device *brd_alloc(int i)
435 blk_queue_max_sectors(brd->brd_queue, 1024); 439 blk_queue_max_sectors(brd->brd_queue, 1024);
436 blk_queue_bounce_limit(brd->brd_queue, BLK_BOUNCE_ANY); 440 blk_queue_bounce_limit(brd->brd_queue, BLK_BOUNCE_ANY);
437 441
438 disk = brd->brd_disk = alloc_disk(1); 442 disk = brd->brd_disk = alloc_disk(1 << part_shift);
439 if (!disk) 443 if (!disk)
440 goto out_free_queue; 444 goto out_free_queue;
441 disk->major = RAMDISK_MAJOR; 445 disk->major = RAMDISK_MAJOR;
442 disk->first_minor = i; 446 disk->first_minor = i << part_shift;
443 disk->fops = &brd_fops; 447 disk->fops = &brd_fops;
444 disk->private_data = brd; 448 disk->private_data = brd;
445 disk->queue = brd->brd_queue; 449 disk->queue = brd->brd_queue;
@@ -523,7 +527,12 @@ static int __init brd_init(void)
523 * themselves and have kernel automatically instantiate actual 527 * themselves and have kernel automatically instantiate actual
524 * device on-demand. 528 * device on-demand.
525 */ 529 */
526 if (rd_nr > 1UL << MINORBITS) 530
531 part_shift = 0;
532 if (max_part > 0)
533 part_shift = fls(max_part);
534
535 if (rd_nr > 1UL << (MINORBITS - part_shift))
527 return -EINVAL; 536 return -EINVAL;
528 537
529 if (rd_nr) { 538 if (rd_nr) {
@@ -531,7 +540,7 @@ static int __init brd_init(void)
531 range = rd_nr; 540 range = rd_nr;
532 } else { 541 } else {
533 nr = CONFIG_BLK_DEV_RAM_COUNT; 542 nr = CONFIG_BLK_DEV_RAM_COUNT;
534 range = 1UL << MINORBITS; 543 range = 1UL << (MINORBITS - part_shift);
535 } 544 }
536 545
537 if (register_blkdev(RAMDISK_MAJOR, "ramdisk")) 546 if (register_blkdev(RAMDISK_MAJOR, "ramdisk"))
@@ -570,7 +579,7 @@ static void __exit brd_exit(void)
570 unsigned long range; 579 unsigned long range;
571 struct brd_device *brd, *next; 580 struct brd_device *brd, *next;
572 581
573 range = rd_nr ? rd_nr : 1UL << MINORBITS; 582 range = rd_nr ? rd_nr : 1UL << (MINORBITS - part_shift);
574 583
575 list_for_each_entry_safe(brd, next, &brd_devices, brd_list) 584 list_for_each_entry_safe(brd, next, &brd_devices, brd_list)
576 brd_del_one(brd); 585 brd_del_one(brd);
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index e539be5750dc..e336b05fe4a7 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -428,13 +428,9 @@ static void __devinit cciss_procinit(int i)
428 proc_cciss = proc_mkdir("driver/cciss", NULL); 428 proc_cciss = proc_mkdir("driver/cciss", NULL);
429 if (!proc_cciss) 429 if (!proc_cciss)
430 return; 430 return;
431 pde = proc_create(hba[i]->devname, S_IWUSR | S_IRUSR | S_IRGRP | 431 pde = proc_create_data(hba[i]->devname, S_IWUSR | S_IRUSR | S_IRGRP |
432 S_IROTH, proc_cciss, 432 S_IROTH, proc_cciss,
433 &cciss_proc_fops); 433 &cciss_proc_fops, hba[i]);
434 if (!pde)
435 return;
436
437 pde->data = hba[i];
438} 434}
439#endif /* CONFIG_PROC_FS */ 435#endif /* CONFIG_PROC_FS */
440 436
diff --git a/drivers/block/ub.c b/drivers/block/ub.c
index e322cce8c12d..3a281ef11ffa 100644
--- a/drivers/block/ub.c
+++ b/drivers/block/ub.c
@@ -205,6 +205,7 @@ struct ub_scsi_cmd {
205 unsigned char key, asc, ascq; /* May be valid if error==-EIO */ 205 unsigned char key, asc, ascq; /* May be valid if error==-EIO */
206 206
207 int stat_count; /* Retries getting status. */ 207 int stat_count; /* Retries getting status. */
208 unsigned int timeo; /* jiffies until rq->timeout changes */
208 209
209 unsigned int len; /* Requested length */ 210 unsigned int len; /* Requested length */
210 unsigned int current_sg; 211 unsigned int current_sg;
@@ -318,6 +319,7 @@ struct ub_dev {
318 int openc; /* protected by ub_lock! */ 319 int openc; /* protected by ub_lock! */
319 /* kref is too implicit for our taste */ 320 /* kref is too implicit for our taste */
320 int reset; /* Reset is running */ 321 int reset; /* Reset is running */
322 int bad_resid;
321 unsigned int tagcnt; 323 unsigned int tagcnt;
322 char name[12]; 324 char name[12];
323 struct usb_device *dev; 325 struct usb_device *dev;
@@ -764,6 +766,12 @@ static void ub_cmd_build_packet(struct ub_dev *sc, struct ub_lun *lun,
764 cmd->cdb_len = rq->cmd_len; 766 cmd->cdb_len = rq->cmd_len;
765 767
766 cmd->len = rq->data_len; 768 cmd->len = rq->data_len;
769
770 /*
771 * To reapply this to every URB is not as incorrect as it looks.
772 * In return, we avoid any complicated tracking calculations.
773 */
774 cmd->timeo = rq->timeout;
767} 775}
768 776
769static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd) 777static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
@@ -785,10 +793,6 @@ static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
785 scsi_status = 0; 793 scsi_status = 0;
786 } else { 794 } else {
787 if (cmd->act_len != cmd->len) { 795 if (cmd->act_len != cmd->len) {
788 if ((cmd->key == MEDIUM_ERROR ||
789 cmd->key == UNIT_ATTENTION) &&
790 ub_rw_cmd_retry(sc, lun, urq, cmd) == 0)
791 return;
792 scsi_status = SAM_STAT_CHECK_CONDITION; 796 scsi_status = SAM_STAT_CHECK_CONDITION;
793 } else { 797 } else {
794 scsi_status = 0; 798 scsi_status = 0;
@@ -804,7 +808,10 @@ static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
804 else 808 else
805 scsi_status = DID_ERROR << 16; 809 scsi_status = DID_ERROR << 16;
806 } else { 810 } else {
807 if (cmd->error == -EIO) { 811 if (cmd->error == -EIO &&
812 (cmd->key == 0 ||
813 cmd->key == MEDIUM_ERROR ||
814 cmd->key == UNIT_ATTENTION)) {
808 if (ub_rw_cmd_retry(sc, lun, urq, cmd) == 0) 815 if (ub_rw_cmd_retry(sc, lun, urq, cmd) == 0)
809 return; 816 return;
810 } 817 }
@@ -1259,14 +1266,19 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1259 return; 1266 return;
1260 } 1267 }
1261 1268
1262 len = le32_to_cpu(bcs->Residue); 1269 if (!sc->bad_resid) {
1263 if (len != cmd->len - cmd->act_len) { 1270 len = le32_to_cpu(bcs->Residue);
1264 /* 1271 if (len != cmd->len - cmd->act_len) {
1265 * It is all right to transfer less, the caller has 1272 /*
1266 * to check. But it's not all right if the device 1273 * Only start ignoring if this cmd ended well.
1267 * counts disagree with our counts. 1274 */
1268 */ 1275 if (cmd->len == cmd->act_len) {
1269 goto Bad_End; 1276 printk(KERN_NOTICE "%s: "
1277 "bad residual %d of %d, ignoring\n",
1278 sc->name, len, cmd->len);
1279 sc->bad_resid = 1;
1280 }
1281 }
1270 } 1282 }
1271 1283
1272 switch (bcs->Status) { 1284 switch (bcs->Status) {
@@ -1297,8 +1309,7 @@ static void ub_scsi_urb_compl(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1297 ub_state_done(sc, cmd, -EIO); 1309 ub_state_done(sc, cmd, -EIO);
1298 1310
1299 } else { 1311 } else {
1300 printk(KERN_WARNING "%s: " 1312 printk(KERN_WARNING "%s: wrong command state %d\n",
1301 "wrong command state %d\n",
1302 sc->name, cmd->state); 1313 sc->name, cmd->state);
1303 ub_state_done(sc, cmd, -EINVAL); 1314 ub_state_done(sc, cmd, -EINVAL);
1304 return; 1315 return;
@@ -1336,7 +1347,10 @@ static void ub_data_start(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1336 return; 1347 return;
1337 } 1348 }
1338 1349
1339 sc->work_timer.expires = jiffies + UB_DATA_TIMEOUT; 1350 if (cmd->timeo)
1351 sc->work_timer.expires = jiffies + cmd->timeo;
1352 else
1353 sc->work_timer.expires = jiffies + UB_DATA_TIMEOUT;
1340 add_timer(&sc->work_timer); 1354 add_timer(&sc->work_timer);
1341 1355
1342 cmd->state = UB_CMDST_DATA; 1356 cmd->state = UB_CMDST_DATA;
@@ -1376,7 +1390,10 @@ static int __ub_state_stat(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
1376 return -1; 1390 return -1;
1377 } 1391 }
1378 1392
1379 sc->work_timer.expires = jiffies + UB_STAT_TIMEOUT; 1393 if (cmd->timeo)
1394 sc->work_timer.expires = jiffies + cmd->timeo;
1395 else
1396 sc->work_timer.expires = jiffies + UB_STAT_TIMEOUT;
1380 add_timer(&sc->work_timer); 1397 add_timer(&sc->work_timer);
1381 return 0; 1398 return 0;
1382} 1399}
@@ -1515,8 +1532,7 @@ static void ub_top_sense_done(struct ub_dev *sc, struct ub_scsi_cmd *scmd)
1515 return; 1532 return;
1516 } 1533 }
1517 if (cmd->state != UB_CMDST_SENSE) { 1534 if (cmd->state != UB_CMDST_SENSE) {
1518 printk(KERN_WARNING "%s: " 1535 printk(KERN_WARNING "%s: sense done with bad cmd state %d\n",
1519 "sense done with bad cmd state %d\n",
1520 sc->name, cmd->state); 1536 sc->name, cmd->state);
1521 return; 1537 return;
1522 } 1538 }
@@ -1720,7 +1736,7 @@ static int ub_bd_ioctl(struct inode *inode, struct file *filp,
1720} 1736}
1721 1737
1722/* 1738/*
1723 * This is called once a new disk was seen by the block layer or by ub_probe(). 1739 * This is called by check_disk_change if we reported a media change.
1724 * The main onjective here is to discover the features of the media such as 1740 * The main onjective here is to discover the features of the media such as
1725 * the capacity, read-only status, etc. USB storage generally does not 1741 * the capacity, read-only status, etc. USB storage generally does not
1726 * need to be spun up, but if we needed it, this would be the place. 1742 * need to be spun up, but if we needed it, this would be the place.
@@ -2136,8 +2152,7 @@ static int ub_get_pipes(struct ub_dev *sc, struct usb_device *dev,
2136 } 2152 }
2137 2153
2138 if (ep_in == NULL || ep_out == NULL) { 2154 if (ep_in == NULL || ep_out == NULL) {
2139 printk(KERN_NOTICE "%s: failed endpoint check\n", 2155 printk(KERN_NOTICE "%s: failed endpoint check\n", sc->name);
2140 sc->name);
2141 return -ENODEV; 2156 return -ENODEV;
2142 } 2157 }
2143 2158
@@ -2354,7 +2369,7 @@ static void ub_disconnect(struct usb_interface *intf)
2354 spin_unlock_irqrestore(&ub_lock, flags); 2369 spin_unlock_irqrestore(&ub_lock, flags);
2355 2370
2356 /* 2371 /*
2357 * Fence stall clearnings, operations triggered by unlinkings and so on. 2372 * Fence stall clearings, operations triggered by unlinkings and so on.
2358 * We do not attempt to unlink any URBs, because we do not trust the 2373 * We do not attempt to unlink any URBs, because we do not trust the
2359 * unlink paths in HC drivers. Also, we get -84 upon disconnect anyway. 2374 * unlink paths in HC drivers. Also, we get -84 upon disconnect anyway.
2360 */ 2375 */
@@ -2417,7 +2432,7 @@ static void ub_disconnect(struct usb_interface *intf)
2417 spin_unlock_irqrestore(sc->lock, flags); 2432 spin_unlock_irqrestore(sc->lock, flags);
2418 2433
2419 /* 2434 /*
2420 * There is virtually no chance that other CPU runs times so long 2435 * There is virtually no chance that other CPU runs a timeout so long
2421 * after ub_urb_complete should have called del_timer, but only if HCD 2436 * after ub_urb_complete should have called del_timer, but only if HCD
2422 * didn't forget to deliver a callback on unlink. 2437 * didn't forget to deliver a callback on unlink.
2423 */ 2438 */
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 0cfbe8c594a5..84e064ffee52 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -35,7 +35,7 @@ struct virtblk_req
35 struct list_head list; 35 struct list_head list;
36 struct request *req; 36 struct request *req;
37 struct virtio_blk_outhdr out_hdr; 37 struct virtio_blk_outhdr out_hdr;
38 struct virtio_blk_inhdr in_hdr; 38 u8 status;
39}; 39};
40 40
41static void blk_done(struct virtqueue *vq) 41static void blk_done(struct virtqueue *vq)
@@ -48,7 +48,7 @@ static void blk_done(struct virtqueue *vq)
48 spin_lock_irqsave(&vblk->lock, flags); 48 spin_lock_irqsave(&vblk->lock, flags);
49 while ((vbr = vblk->vq->vq_ops->get_buf(vblk->vq, &len)) != NULL) { 49 while ((vbr = vblk->vq->vq_ops->get_buf(vblk->vq, &len)) != NULL) {
50 int uptodate; 50 int uptodate;
51 switch (vbr->in_hdr.status) { 51 switch (vbr->status) {
52 case VIRTIO_BLK_S_OK: 52 case VIRTIO_BLK_S_OK:
53 uptodate = 1; 53 uptodate = 1;
54 break; 54 break;
@@ -101,7 +101,7 @@ static bool do_req(struct request_queue *q, struct virtio_blk *vblk,
101 sg_init_table(vblk->sg, VIRTIO_MAX_SG); 101 sg_init_table(vblk->sg, VIRTIO_MAX_SG);
102 sg_set_buf(&vblk->sg[0], &vbr->out_hdr, sizeof(vbr->out_hdr)); 102 sg_set_buf(&vblk->sg[0], &vbr->out_hdr, sizeof(vbr->out_hdr));
103 num = blk_rq_map_sg(q, vbr->req, vblk->sg+1); 103 num = blk_rq_map_sg(q, vbr->req, vblk->sg+1);
104 sg_set_buf(&vblk->sg[num+1], &vbr->in_hdr, sizeof(vbr->in_hdr)); 104 sg_set_buf(&vblk->sg[num+1], &vbr->status, sizeof(vbr->status));
105 105
106 if (rq_data_dir(vbr->req) == WRITE) { 106 if (rq_data_dir(vbr->req) == WRITE) {
107 vbr->out_hdr.type |= VIRTIO_BLK_T_OUT; 107 vbr->out_hdr.type |= VIRTIO_BLK_T_OUT;
@@ -157,10 +157,25 @@ static int virtblk_ioctl(struct inode *inode, struct file *filp,
157/* We provide getgeo only to please some old bootloader/partitioning tools */ 157/* We provide getgeo only to please some old bootloader/partitioning tools */
158static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo) 158static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo)
159{ 159{
160 /* some standard values, similar to sd */ 160 struct virtio_blk *vblk = bd->bd_disk->private_data;
161 geo->heads = 1 << 6; 161 struct virtio_blk_geometry vgeo;
162 geo->sectors = 1 << 5; 162 int err;
163 geo->cylinders = get_capacity(bd->bd_disk) >> 11; 163
164 /* see if the host passed in geometry config */
165 err = virtio_config_val(vblk->vdev, VIRTIO_BLK_F_GEOMETRY,
166 offsetof(struct virtio_blk_config, geometry),
167 &vgeo);
168
169 if (!err) {
170 geo->heads = vgeo.heads;
171 geo->sectors = vgeo.sectors;
172 geo->cylinders = vgeo.cylinders;
173 } else {
174 /* some standard values, similar to sd */
175 geo->heads = 1 << 6;
176 geo->sectors = 1 << 5;
177 geo->cylinders = get_capacity(bd->bd_disk) >> 11;
178 }
164 return 0; 179 return 0;
165} 180}
166 181
@@ -242,12 +257,12 @@ static int virtblk_probe(struct virtio_device *vdev)
242 index++; 257 index++;
243 258
244 /* If barriers are supported, tell block layer that queue is ordered */ 259 /* If barriers are supported, tell block layer that queue is ordered */
245 if (vdev->config->feature(vdev, VIRTIO_BLK_F_BARRIER)) 260 if (virtio_has_feature(vdev, VIRTIO_BLK_F_BARRIER))
246 blk_queue_ordered(vblk->disk->queue, QUEUE_ORDERED_TAG, NULL); 261 blk_queue_ordered(vblk->disk->queue, QUEUE_ORDERED_TAG, NULL);
247 262
248 /* Host must always specify the capacity. */ 263 /* Host must always specify the capacity. */
249 __virtio_config_val(vdev, offsetof(struct virtio_blk_config, capacity), 264 vdev->config->get(vdev, offsetof(struct virtio_blk_config, capacity),
250 &cap); 265 &cap, sizeof(cap));
251 266
252 /* If capacity is too big, truncate with warning. */ 267 /* If capacity is too big, truncate with warning. */
253 if ((sector_t)cap != cap) { 268 if ((sector_t)cap != cap) {
@@ -289,7 +304,6 @@ out:
289static void virtblk_remove(struct virtio_device *vdev) 304static void virtblk_remove(struct virtio_device *vdev)
290{ 305{
291 struct virtio_blk *vblk = vdev->priv; 306 struct virtio_blk *vblk = vdev->priv;
292 int major = vblk->disk->major;
293 307
294 /* Nothing should be pending. */ 308 /* Nothing should be pending. */
295 BUG_ON(!list_empty(&vblk->reqs)); 309 BUG_ON(!list_empty(&vblk->reqs));
@@ -299,7 +313,6 @@ static void virtblk_remove(struct virtio_device *vdev)
299 313
300 blk_cleanup_queue(vblk->disk->queue); 314 blk_cleanup_queue(vblk->disk->queue);
301 put_disk(vblk->disk); 315 put_disk(vblk->disk);
302 unregister_blkdev(major, "virtblk");
303 mempool_destroy(vblk->pool); 316 mempool_destroy(vblk->pool);
304 vdev->config->del_vq(vblk->vq); 317 vdev->config->del_vq(vblk->vq);
305 kfree(vblk); 318 kfree(vblk);
@@ -310,7 +323,14 @@ static struct virtio_device_id id_table[] = {
310 { 0 }, 323 { 0 },
311}; 324};
312 325
326static unsigned int features[] = {
327 VIRTIO_BLK_F_BARRIER, VIRTIO_BLK_F_SEG_MAX, VIRTIO_BLK_F_SIZE_MAX,
328 VIRTIO_BLK_F_GEOMETRY,
329};
330
313static struct virtio_driver virtio_blk = { 331static struct virtio_driver virtio_blk = {
332 .feature_table = features,
333 .feature_table_size = ARRAY_SIZE(features),
314 .driver.name = KBUILD_MODNAME, 334 .driver.name = KBUILD_MODNAME,
315 .driver.owner = THIS_MODULE, 335 .driver.owner = THIS_MODULE,
316 .id_table = id_table, 336 .id_table = id_table,
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index 7e31d5f1bc8a..e5cd856a2fea 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -143,7 +143,7 @@ restart:
143 int len; 143 int len;
144 144
145 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 145 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
146 len = tty->driver->write(tty, skb->data, skb->len); 146 len = tty->ops->write(tty, skb->data, skb->len);
147 hdev->stat.byte_tx += len; 147 hdev->stat.byte_tx += len;
148 148
149 skb_pull(skb, len); 149 skb_pull(skb, len);
@@ -190,8 +190,7 @@ static int hci_uart_flush(struct hci_dev *hdev)
190 190
191 /* Flush any pending characters in the driver and discipline. */ 191 /* Flush any pending characters in the driver and discipline. */
192 tty_ldisc_flush(tty); 192 tty_ldisc_flush(tty);
193 if (tty->driver && tty->driver->flush_buffer) 193 tty_driver_flush_buffer(tty);
194 tty->driver->flush_buffer(tty);
195 194
196 if (test_bit(HCI_UART_PROTO_SET, &hu->flags)) 195 if (test_bit(HCI_UART_PROTO_SET, &hu->flags))
197 hu->proto->flush(hu); 196 hu->proto->flush(hu);
@@ -285,9 +284,7 @@ static int hci_uart_tty_open(struct tty_struct *tty)
285 284
286 if (tty->ldisc.flush_buffer) 285 if (tty->ldisc.flush_buffer)
287 tty->ldisc.flush_buffer(tty); 286 tty->ldisc.flush_buffer(tty);
288 287 tty_driver_flush_buffer(tty);
289 if (tty->driver && tty->driver->flush_buffer)
290 tty->driver->flush_buffer(tty);
291 288
292 return 0; 289 return 0;
293} 290}
@@ -373,9 +370,7 @@ static void hci_uart_tty_receive(struct tty_struct *tty, const u8 *data, char *f
373 hu->hdev->stat.byte_rx += count; 370 hu->hdev->stat.byte_rx += count;
374 spin_unlock(&hu->rx_lock); 371 spin_unlock(&hu->rx_lock);
375 372
376 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) && 373 tty_unthrottle(tty);
377 tty->driver->unthrottle)
378 tty->driver->unthrottle(tty);
379} 374}
380 375
381static int hci_uart_register_dev(struct hci_uart *hu) 376static int hci_uart_register_dev(struct hci_uart *hu)
diff --git a/drivers/bluetooth/hci_usb.h b/drivers/bluetooth/hci_usb.h
index 414080a4e8ff..1790cc8e431e 100644
--- a/drivers/bluetooth/hci_usb.h
+++ b/drivers/bluetooth/hci_usb.h
@@ -70,7 +70,8 @@ static inline void _urb_queue_head(struct _urb_queue *q, struct _urb *_urb)
70{ 70{
71 unsigned long flags; 71 unsigned long flags;
72 spin_lock_irqsave(&q->lock, flags); 72 spin_lock_irqsave(&q->lock, flags);
73 list_add(&_urb->list, &q->head); _urb->queue = q; 73 /* _urb_unlink needs to know which spinlock to use, thus mb(). */
74 _urb->queue = q; mb(); list_add(&_urb->list, &q->head);
74 spin_unlock_irqrestore(&q->lock, flags); 75 spin_unlock_irqrestore(&q->lock, flags);
75} 76}
76 77
@@ -78,19 +79,23 @@ static inline void _urb_queue_tail(struct _urb_queue *q, struct _urb *_urb)
78{ 79{
79 unsigned long flags; 80 unsigned long flags;
80 spin_lock_irqsave(&q->lock, flags); 81 spin_lock_irqsave(&q->lock, flags);
81 list_add_tail(&_urb->list, &q->head); _urb->queue = q; 82 /* _urb_unlink needs to know which spinlock to use, thus mb(). */
83 _urb->queue = q; mb(); list_add_tail(&_urb->list, &q->head);
82 spin_unlock_irqrestore(&q->lock, flags); 84 spin_unlock_irqrestore(&q->lock, flags);
83} 85}
84 86
85static inline void _urb_unlink(struct _urb *_urb) 87static inline void _urb_unlink(struct _urb *_urb)
86{ 88{
87 struct _urb_queue *q = _urb->queue; 89 struct _urb_queue *q;
88 unsigned long flags; 90 unsigned long flags;
89 if (q) { 91
90 spin_lock_irqsave(&q->lock, flags); 92 mb();
91 list_del(&_urb->list); _urb->queue = NULL; 93 q = _urb->queue;
92 spin_unlock_irqrestore(&q->lock, flags); 94 /* If q is NULL, it will die at easy-to-debug NULL pointer dereference.
93 } 95 No need to BUG(). */
96 spin_lock_irqsave(&q->lock, flags);
97 list_del(&_urb->list); _urb->queue = NULL;
98 spin_unlock_irqrestore(&q->lock, flags);
94} 99}
95 100
96struct hci_usb { 101struct hci_usb {
diff --git a/drivers/char/agp/agp.h b/drivers/char/agp/agp.h
index c69f79598e47..99e6a406efb4 100644
--- a/drivers/char/agp/agp.h
+++ b/drivers/char/agp/agp.h
@@ -35,7 +35,7 @@
35 35
36//#define AGP_DEBUG 1 36//#define AGP_DEBUG 1
37#ifdef AGP_DEBUG 37#ifdef AGP_DEBUG
38#define DBG(x,y...) printk (KERN_DEBUG PFX "%s: " x "\n", __FUNCTION__ , ## y) 38#define DBG(x,y...) printk (KERN_DEBUG PFX "%s: " x "\n", __func__ , ## y)
39#else 39#else
40#define DBG(x,y...) do { } while (0) 40#define DBG(x,y...) do { } while (0)
41#endif 41#endif
diff --git a/drivers/char/amiserial.c b/drivers/char/amiserial.c
index 3d468f502d2d..37457e5a4f2b 100644
--- a/drivers/char/amiserial.c
+++ b/drivers/char/amiserial.c
@@ -832,33 +832,34 @@ static void change_speed(struct async_struct *info,
832 local_irq_restore(flags); 832 local_irq_restore(flags);
833} 833}
834 834
835static void rs_put_char(struct tty_struct *tty, unsigned char ch) 835static int rs_put_char(struct tty_struct *tty, unsigned char ch)
836{ 836{
837 struct async_struct *info; 837 struct async_struct *info;
838 unsigned long flags; 838 unsigned long flags;
839 839
840 if (!tty) 840 if (!tty)
841 return; 841 return 0;
842 842
843 info = tty->driver_data; 843 info = tty->driver_data;
844 844
845 if (serial_paranoia_check(info, tty->name, "rs_put_char")) 845 if (serial_paranoia_check(info, tty->name, "rs_put_char"))
846 return; 846 return 0;
847 847
848 if (!info->xmit.buf) 848 if (!info->xmit.buf)
849 return; 849 return 0;
850 850
851 local_irq_save(flags); 851 local_irq_save(flags);
852 if (CIRC_SPACE(info->xmit.head, 852 if (CIRC_SPACE(info->xmit.head,
853 info->xmit.tail, 853 info->xmit.tail,
854 SERIAL_XMIT_SIZE) == 0) { 854 SERIAL_XMIT_SIZE) == 0) {
855 local_irq_restore(flags); 855 local_irq_restore(flags);
856 return; 856 return 0;
857 } 857 }
858 858
859 info->xmit.buf[info->xmit.head++] = ch; 859 info->xmit.buf[info->xmit.head++] = ch;
860 info->xmit.head &= SERIAL_XMIT_SIZE-1; 860 info->xmit.head &= SERIAL_XMIT_SIZE-1;
861 local_irq_restore(flags); 861 local_irq_restore(flags);
862 return 1;
862} 863}
863 864
864static void rs_flush_chars(struct tty_struct *tty) 865static void rs_flush_chars(struct tty_struct *tty)
@@ -1074,6 +1075,7 @@ static int get_serial_info(struct async_struct * info,
1074 if (!retinfo) 1075 if (!retinfo)
1075 return -EFAULT; 1076 return -EFAULT;
1076 memset(&tmp, 0, sizeof(tmp)); 1077 memset(&tmp, 0, sizeof(tmp));
1078 lock_kernel();
1077 tmp.type = state->type; 1079 tmp.type = state->type;
1078 tmp.line = state->line; 1080 tmp.line = state->line;
1079 tmp.port = state->port; 1081 tmp.port = state->port;
@@ -1084,6 +1086,7 @@ static int get_serial_info(struct async_struct * info,
1084 tmp.close_delay = state->close_delay; 1086 tmp.close_delay = state->close_delay;
1085 tmp.closing_wait = state->closing_wait; 1087 tmp.closing_wait = state->closing_wait;
1086 tmp.custom_divisor = state->custom_divisor; 1088 tmp.custom_divisor = state->custom_divisor;
1089 unlock_kernel();
1087 if (copy_to_user(retinfo,&tmp,sizeof(*retinfo))) 1090 if (copy_to_user(retinfo,&tmp,sizeof(*retinfo)))
1088 return -EFAULT; 1091 return -EFAULT;
1089 return 0; 1092 return 0;
@@ -1099,13 +1102,17 @@ static int set_serial_info(struct async_struct * info,
1099 1102
1100 if (copy_from_user(&new_serial,new_info,sizeof(new_serial))) 1103 if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
1101 return -EFAULT; 1104 return -EFAULT;
1105
1106 lock_kernel();
1102 state = info->state; 1107 state = info->state;
1103 old_state = *state; 1108 old_state = *state;
1104 1109
1105 change_irq = new_serial.irq != state->irq; 1110 change_irq = new_serial.irq != state->irq;
1106 change_port = (new_serial.port != state->port); 1111 change_port = (new_serial.port != state->port);
1107 if(change_irq || change_port || (new_serial.xmit_fifo_size != state->xmit_fifo_size)) 1112 if(change_irq || change_port || (new_serial.xmit_fifo_size != state->xmit_fifo_size)) {
1113 unlock_kernel();
1108 return -EINVAL; 1114 return -EINVAL;
1115 }
1109 1116
1110 if (!serial_isroot()) { 1117 if (!serial_isroot()) {
1111 if ((new_serial.baud_base != state->baud_base) || 1118 if ((new_serial.baud_base != state->baud_base) ||
@@ -1122,8 +1129,10 @@ static int set_serial_info(struct async_struct * info,
1122 goto check_and_exit; 1129 goto check_and_exit;
1123 } 1130 }
1124 1131
1125 if (new_serial.baud_base < 9600) 1132 if (new_serial.baud_base < 9600) {
1133 unlock_kernel();
1126 return -EINVAL; 1134 return -EINVAL;
1135 }
1127 1136
1128 /* 1137 /*
1129 * OK, past this point, all the error checking has been done. 1138 * OK, past this point, all the error checking has been done.
@@ -1157,6 +1166,7 @@ check_and_exit:
1157 } 1166 }
1158 } else 1167 } else
1159 retval = startup(info); 1168 retval = startup(info);
1169 unlock_kernel();
1160 return retval; 1170 return retval;
1161} 1171}
1162 1172
@@ -1496,8 +1506,7 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
1496 rs_wait_until_sent(tty, info->timeout); 1506 rs_wait_until_sent(tty, info->timeout);
1497 } 1507 }
1498 shutdown(info); 1508 shutdown(info);
1499 if (tty->driver->flush_buffer) 1509 rs_flush_buffer(tty);
1500 tty->driver->flush_buffer(tty);
1501 1510
1502 tty_ldisc_flush(tty); 1511 tty_ldisc_flush(tty);
1503 tty->closing = 0; 1512 tty->closing = 0;
@@ -1530,6 +1539,8 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
1530 return; /* Just in case.... */ 1539 return; /* Just in case.... */
1531 1540
1532 orig_jiffies = jiffies; 1541 orig_jiffies = jiffies;
1542
1543 lock_kernel();
1533 /* 1544 /*
1534 * Set the check interval to be 1/5 of the estimated time to 1545 * Set the check interval to be 1/5 of the estimated time to
1535 * send a single character, and make it at least 1. The check 1546 * send a single character, and make it at least 1. The check
@@ -1570,6 +1581,7 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
1570 break; 1581 break;
1571 } 1582 }
1572 __set_current_state(TASK_RUNNING); 1583 __set_current_state(TASK_RUNNING);
1584 unlock_kernel();
1573#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT 1585#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1574 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies); 1586 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
1575#endif 1587#endif
diff --git a/drivers/char/applicom.c b/drivers/char/applicom.c
index a7c4990b5b6b..31d08b641f5b 100644
--- a/drivers/char/applicom.c
+++ b/drivers/char/applicom.c
@@ -199,7 +199,7 @@ static int __init applicom_init(void)
199 if (pci_enable_device(dev)) 199 if (pci_enable_device(dev))
200 return -EIO; 200 return -EIO;
201 201
202 RamIO = ioremap(pci_resource_start(dev, 0), LEN_RAM_IO); 202 RamIO = ioremap_nocache(pci_resource_start(dev, 0), LEN_RAM_IO);
203 203
204 if (!RamIO) { 204 if (!RamIO) {
205 printk(KERN_INFO "ac.o: Failed to ioremap PCI memory " 205 printk(KERN_INFO "ac.o: Failed to ioremap PCI memory "
@@ -254,7 +254,7 @@ static int __init applicom_init(void)
254 /* Now try the specified ISA cards */ 254 /* Now try the specified ISA cards */
255 255
256 for (i = 0; i < MAX_ISA_BOARD; i++) { 256 for (i = 0; i < MAX_ISA_BOARD; i++) {
257 RamIO = ioremap(mem + (LEN_RAM_IO * i), LEN_RAM_IO); 257 RamIO = ioremap_nocache(mem + (LEN_RAM_IO * i), LEN_RAM_IO);
258 258
259 if (!RamIO) { 259 if (!RamIO) {
260 printk(KERN_INFO "ac.o: Failed to ioremap the ISA card's memory space (slot #%d)\n", i + 1); 260 printk(KERN_INFO "ac.o: Failed to ioremap the ISA card's memory space (slot #%d)\n", i + 1);
diff --git a/drivers/char/consolemap.c b/drivers/char/consolemap.c
index 6b104e45a322..4246b8e36cb3 100644
--- a/drivers/char/consolemap.c
+++ b/drivers/char/consolemap.c
@@ -277,6 +277,7 @@ u16 inverse_translate(struct vc_data *conp, int glyph, int use_unicode)
277 return p->inverse_translations[m][glyph]; 277 return p->inverse_translations[m][glyph];
278 } 278 }
279} 279}
280EXPORT_SYMBOL_GPL(inverse_translate);
280 281
281static void update_user_maps(void) 282static void update_user_maps(void)
282{ 283{
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index e4f579c3e245..ef73e72daedc 100644
--- a/drivers/char/cyclades.c
+++ b/drivers/char/cyclades.c
@@ -21,7 +21,6 @@
21 * 21 *
22 * This version supports shared IRQ's (only for PCI boards). 22 * This version supports shared IRQ's (only for PCI boards).
23 * 23 *
24 * $Log: cyclades.c,v $
25 * Prevent users from opening non-existing Z ports. 24 * Prevent users from opening non-existing Z ports.
26 * 25 *
27 * Revision 2.3.2.8 2000/07/06 18:14:16 ivan 26 * Revision 2.3.2.8 2000/07/06 18:14:16 ivan
@@ -62,7 +61,7 @@
62 * Driver now makes sure that the constant SERIAL_XMIT_SIZE is defined; 61 * Driver now makes sure that the constant SERIAL_XMIT_SIZE is defined;
63 * 62 *
64 * Revision 2.3.2.2 1999/10/01 11:27:43 ivan 63 * Revision 2.3.2.2 1999/10/01 11:27:43 ivan
65 * Fixed bug in cyz_poll that would make all ports but port 0 64 * Fixed bug in cyz_poll that would make all ports but port 0
66 * unable to transmit/receive data (Cyclades-Z only); 65 * unable to transmit/receive data (Cyclades-Z only);
67 * Implemented logic to prevent the RX buffer from being stuck with data 66 * Implemented logic to prevent the RX buffer from being stuck with data
68 * due to a driver / firmware race condition in interrupt op mode 67 * due to a driver / firmware race condition in interrupt op mode
@@ -83,25 +82,25 @@
83 * Revision 2.3.1.1 1999/07/15 16:45:53 ivan 82 * Revision 2.3.1.1 1999/07/15 16:45:53 ivan
84 * Removed CY_PROC conditional compilation; 83 * Removed CY_PROC conditional compilation;
85 * Implemented SMP-awareness for the driver; 84 * Implemented SMP-awareness for the driver;
86 * Implemented a new ISA IRQ autoprobe that uses the irq_probe_[on|off] 85 * Implemented a new ISA IRQ autoprobe that uses the irq_probe_[on|off]
87 * functions; 86 * functions;
88 * The driver now accepts memory addresses (maddr=0xMMMMM) and IRQs 87 * The driver now accepts memory addresses (maddr=0xMMMMM) and IRQs
89 * (irq=NN) as parameters (only for ISA boards); 88 * (irq=NN) as parameters (only for ISA boards);
90 * Fixed bug in set_line_char that would prevent the Cyclades-Z 89 * Fixed bug in set_line_char that would prevent the Cyclades-Z
91 * ports from being configured at speeds above 115.2Kbps; 90 * ports from being configured at speeds above 115.2Kbps;
92 * Fixed bug in cy_set_termios that would prevent XON/XOFF flow control 91 * Fixed bug in cy_set_termios that would prevent XON/XOFF flow control
93 * switching from working properly; 92 * switching from working properly;
94 * The driver now only prints IRQ info for the Cyclades-Z if it's 93 * The driver now only prints IRQ info for the Cyclades-Z if it's
95 * configured to work in interrupt mode; 94 * configured to work in interrupt mode;
96 * 95 *
97 * Revision 2.2.2.3 1999/06/28 11:13:29 ivan 96 * Revision 2.2.2.3 1999/06/28 11:13:29 ivan
98 * Added support for interrupt mode operation for the Z cards; 97 * Added support for interrupt mode operation for the Z cards;
99 * Removed the driver inactivity control for the Z; 98 * Removed the driver inactivity control for the Z;
100 * Added a missing MOD_DEC_USE_COUNT in the cy_open function for when 99 * Added a missing MOD_DEC_USE_COUNT in the cy_open function for when
101 * the Z firmware is not loaded yet; 100 * the Z firmware is not loaded yet;
102 * Replaced the "manual" Z Tx flush buffer by a call to a FW command of 101 * Replaced the "manual" Z Tx flush buffer by a call to a FW command of
103 * same functionality; 102 * same functionality;
104 * Implemented workaround for IRQ setting loss on the PCI configuration 103 * Implemented workaround for IRQ setting loss on the PCI configuration
105 * registers after a PCI bridge EEPROM reload (affects PLX9060 only); 104 * registers after a PCI bridge EEPROM reload (affects PLX9060 only);
106 * 105 *
107 * Revision 2.2.2.2 1999/05/14 17:18:15 ivan 106 * Revision 2.2.2.2 1999/05/14 17:18:15 ivan
@@ -112,22 +111,22 @@
112 * BREAK implementation changed in order to make use of the 'break_ctl' 111 * BREAK implementation changed in order to make use of the 'break_ctl'
113 * TTY facility; 112 * TTY facility;
114 * Fixed typo in TTY structure field 'driver_name'; 113 * Fixed typo in TTY structure field 'driver_name';
115 * Included a PCI bridge reset and EEPROM reload in the board 114 * Included a PCI bridge reset and EEPROM reload in the board
116 * initialization code (for both Y and Z series). 115 * initialization code (for both Y and Z series).
117 * 116 *
118 * Revision 2.2.2.1 1999/04/08 16:17:43 ivan 117 * Revision 2.2.2.1 1999/04/08 16:17:43 ivan
119 * Fixed a bug in cy_wait_until_sent that was preventing the port to be 118 * Fixed a bug in cy_wait_until_sent that was preventing the port to be
120 * closed properly after a SIGINT; 119 * closed properly after a SIGINT;
121 * Module usage counter scheme revisited; 120 * Module usage counter scheme revisited;
122 * Added support to the upcoming Y PCI boards (i.e., support to additional 121 * Added support to the upcoming Y PCI boards (i.e., support to additional
123 * PCI Device ID's). 122 * PCI Device ID's).
124 * 123 *
125 * Revision 2.2.1.10 1999/01/20 16:14:29 ivan 124 * Revision 2.2.1.10 1999/01/20 16:14:29 ivan
126 * Removed all unnecessary page-alignement operations in ioremap calls 125 * Removed all unnecessary page-alignement operations in ioremap calls
127 * (ioremap is currently safe for these operations). 126 * (ioremap is currently safe for these operations).
128 * 127 *
129 * Revision 2.2.1.9 1998/12/30 18:18:30 ivan 128 * Revision 2.2.1.9 1998/12/30 18:18:30 ivan
130 * Changed access to PLX PCI bridge registers from I/O to MMIO, in 129 * Changed access to PLX PCI bridge registers from I/O to MMIO, in
131 * order to make PLX9050-based boards work with certain motherboards. 130 * order to make PLX9050-based boards work with certain motherboards.
132 * 131 *
133 * Revision 2.2.1.8 1998/11/13 12:46:20 ivan 132 * Revision 2.2.1.8 1998/11/13 12:46:20 ivan
@@ -148,7 +147,7 @@
148 * Fixed Cyclom-4Yo hardware detection bug. 147 * Fixed Cyclom-4Yo hardware detection bug.
149 * 148 *
150 * Revision 2.2.1.4 1998/08/04 11:02:50 ivan 149 * Revision 2.2.1.4 1998/08/04 11:02:50 ivan
151 * /proc/cyclades implementation with great collaboration of 150 * /proc/cyclades implementation with great collaboration of
152 * Marc Lewis <marc@blarg.net>; 151 * Marc Lewis <marc@blarg.net>;
153 * cyy_interrupt was changed to avoid occurrence of kernel oopses 152 * cyy_interrupt was changed to avoid occurrence of kernel oopses
154 * during PPP operation. 153 * during PPP operation.
@@ -157,7 +156,7 @@
157 * General code review in order to comply with 2.1 kernel standards; 156 * General code review in order to comply with 2.1 kernel standards;
158 * data loss prevention for slow devices revisited (cy_wait_until_sent 157 * data loss prevention for slow devices revisited (cy_wait_until_sent
159 * was created); 158 * was created);
160 * removed conditional compilation for new/old PCI structure support 159 * removed conditional compilation for new/old PCI structure support
161 * (now the driver only supports the new PCI structure). 160 * (now the driver only supports the new PCI structure).
162 * 161 *
163 * Revision 2.2.1.1 1998/03/19 16:43:12 ivan 162 * Revision 2.2.1.1 1998/03/19 16:43:12 ivan
@@ -168,7 +167,7 @@
168 * cleaned up the data loss fix; 167 * cleaned up the data loss fix;
169 * fixed XON/XOFF handling once more (Cyclades-Z); 168 * fixed XON/XOFF handling once more (Cyclades-Z);
170 * general review of the driver routines; 169 * general review of the driver routines;
171 * introduction of a mechanism to prevent data loss with slow 170 * introduction of a mechanism to prevent data loss with slow
172 * printers, by forcing a delay before closing the port. 171 * printers, by forcing a delay before closing the port.
173 * 172 *
174 * Revision 2.1.1.2 1998/02/17 16:50:00 ivan 173 * Revision 2.1.1.2 1998/02/17 16:50:00 ivan
@@ -182,12 +181,12 @@
182 * Code review for the module cleanup routine; 181 * Code review for the module cleanup routine;
183 * fixed RTS and DTR status report for new CD1400's in get_modem_info; 182 * fixed RTS and DTR status report for new CD1400's in get_modem_info;
184 * includes anonymous changes regarding signal_pending. 183 * includes anonymous changes regarding signal_pending.
185 * 184 *
186 * Revision 2.1 1997/11/01 17:42:41 ivan 185 * Revision 2.1 1997/11/01 17:42:41 ivan
187 * Changes in the driver to support Alpha systems (except 8Zo V_1); 186 * Changes in the driver to support Alpha systems (except 8Zo V_1);
188 * BREAK fix for the Cyclades-Z boards; 187 * BREAK fix for the Cyclades-Z boards;
189 * driver inactivity control by FW implemented; 188 * driver inactivity control by FW implemented;
190 * introduction of flag that allows driver to take advantage of 189 * introduction of flag that allows driver to take advantage of
191 * a special CD1400 feature related to HW flow control; 190 * a special CD1400 feature related to HW flow control;
192 * added support for the CD1400 rev. J (Cyclom-Y boards); 191 * added support for the CD1400 rev. J (Cyclom-Y boards);
193 * introduction of ioctls to: 192 * introduction of ioctls to:
@@ -196,17 +195,17 @@
196 * - adjust the polling interval (Cyclades-Z); 195 * - adjust the polling interval (Cyclades-Z);
197 * 196 *
198 * Revision 1.36.4.33 1997/06/27 19:00:00 ivan 197 * Revision 1.36.4.33 1997/06/27 19:00:00 ivan
199 * Fixes related to kernel version conditional 198 * Fixes related to kernel version conditional
200 * compilation. 199 * compilation.
201 * 200 *
202 * Revision 1.36.4.32 1997/06/14 19:30:00 ivan 201 * Revision 1.36.4.32 1997/06/14 19:30:00 ivan
203 * Compatibility issues between kernels 2.0.x and 202 * Compatibility issues between kernels 2.0.x and
204 * 2.1.x (mainly related to clear_bit function). 203 * 2.1.x (mainly related to clear_bit function).
205 * 204 *
206 * Revision 1.36.4.31 1997/06/03 15:30:00 ivan 205 * Revision 1.36.4.31 1997/06/03 15:30:00 ivan
207 * Changes to define the memory window according to the 206 * Changes to define the memory window according to the
208 * board type. 207 * board type.
209 * 208 *
210 * Revision 1.36.4.30 1997/05/16 15:30:00 daniel 209 * Revision 1.36.4.30 1997/05/16 15:30:00 daniel
211 * Changes to support new cycladesZ boards. 210 * Changes to support new cycladesZ boards.
212 * 211 *
@@ -624,7 +623,7 @@
624#undef CY_PCI_DEBUG 623#undef CY_PCI_DEBUG
625 624
626/* 625/*
627 * Include section 626 * Include section
628 */ 627 */
629#include <linux/module.h> 628#include <linux/module.h>
630#include <linux/errno.h> 629#include <linux/errno.h>
@@ -649,9 +648,9 @@
649#include <linux/firmware.h> 648#include <linux/firmware.h>
650 649
651#include <asm/system.h> 650#include <asm/system.h>
652#include <asm/io.h> 651#include <linux/io.h>
653#include <asm/irq.h> 652#include <asm/irq.h>
654#include <asm/uaccess.h> 653#include <linux/uaccess.h>
655 654
656#include <linux/kernel.h> 655#include <linux/kernel.h>
657#include <linux/pci.h> 656#include <linux/pci.h>
@@ -668,10 +667,10 @@ static void cy_send_xchar(struct tty_struct *tty, char ch);
668 ((readl(&((struct RUNTIME_9060 __iomem *) \ 667 ((readl(&((struct RUNTIME_9060 __iomem *) \
669 ((card).ctl_addr))->init_ctrl) & (1<<17)) != 0) 668 ((card).ctl_addr))->init_ctrl) & (1<<17)) != 0)
670 669
671#define ISZLOADED(card) (((ZO_V1==readl(&((struct RUNTIME_9060 __iomem *) \ 670#define ISZLOADED(card) (((ZO_V1 == readl(&((struct RUNTIME_9060 __iomem *) \
672 ((card).ctl_addr))->mail_box_0)) || \ 671 ((card).ctl_addr))->mail_box_0)) || \
673 Z_FPGA_CHECK(card)) && \ 672 Z_FPGA_CHECK(card)) && \
674 (ZFIRM_ID==readl(&((struct FIRM_ID __iomem *) \ 673 (ZFIRM_ID == readl(&((struct FIRM_ID __iomem *) \
675 ((card).base_addr+ID_ADDRESS))->signature))) 674 ((card).base_addr+ID_ADDRESS))->signature)))
676 675
677#ifndef SERIAL_XMIT_SIZE 676#ifndef SERIAL_XMIT_SIZE
@@ -809,12 +808,12 @@ static char baud_cor3[] = { /* receive threshold */
809 808
810/* 809/*
811 * The Cyclades driver implements HW flow control as any serial driver. 810 * The Cyclades driver implements HW flow control as any serial driver.
812 * The cyclades_port structure member rflow and the vector rflow_thr 811 * The cyclades_port structure member rflow and the vector rflow_thr
813 * allows us to take advantage of a special feature in the CD1400 to avoid 812 * allows us to take advantage of a special feature in the CD1400 to avoid
814 * data loss even when the system interrupt latency is too high. These flags 813 * data loss even when the system interrupt latency is too high. These flags
815 * are to be used only with very special applications. Setting these flags 814 * are to be used only with very special applications. Setting these flags
816 * requires the use of a special cable (DTR and RTS reversed). In the new 815 * requires the use of a special cable (DTR and RTS reversed). In the new
817 * CD1400-based boards (rev. 6.00 or later), there is no need for special 816 * CD1400-based boards (rev. 6.00 or later), there is no need for special
818 * cables. 817 * cables.
819 */ 818 */
820 819
@@ -841,14 +840,22 @@ static int cy_chip_offset[] = { 0x0000,
841 840
842#ifdef CONFIG_PCI 841#ifdef CONFIG_PCI
843static struct pci_device_id cy_pci_dev_id[] __devinitdata = { 842static struct pci_device_id cy_pci_dev_id[] __devinitdata = {
844 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_Y_Lo) }, /* PCI < 1Mb */ 843 /* PCI < 1Mb */
845 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_Y_Hi) }, /* PCI > 1Mb */ 844 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_Y_Lo) },
846 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_4Y_Lo) }, /* 4Y PCI < 1Mb */ 845 /* PCI > 1Mb */
847 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_4Y_Hi) }, /* 4Y PCI > 1Mb */ 846 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_Y_Hi) },
848 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_8Y_Lo) }, /* 8Y PCI < 1Mb */ 847 /* 4Y PCI < 1Mb */
849 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_8Y_Hi) }, /* 8Y PCI > 1Mb */ 848 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_4Y_Lo) },
850 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_Z_Lo) }, /* Z PCI < 1Mb */ 849 /* 4Y PCI > 1Mb */
851 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_Z_Hi) }, /* Z PCI > 1Mb */ 850 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_4Y_Hi) },
851 /* 8Y PCI < 1Mb */
852 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_8Y_Lo) },
853 /* 8Y PCI > 1Mb */
854 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_8Y_Hi) },
855 /* Z PCI < 1Mb */
856 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_Z_Lo) },
857 /* Z PCI > 1Mb */
858 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_Z_Hi) },
852 { } /* end of table */ 859 { } /* end of table */
853}; 860};
854MODULE_DEVICE_TABLE(pci, cy_pci_dev_id); 861MODULE_DEVICE_TABLE(pci, cy_pci_dev_id);
@@ -905,15 +912,14 @@ static inline int serial_paranoia_check(struct cyclades_port *info,
905 912
906 This function is only called from inside spinlock-protected code. 913 This function is only called from inside spinlock-protected code.
907 */ 914 */
908static int cyy_issue_cmd(void __iomem * base_addr, u_char cmd, int index) 915static int cyy_issue_cmd(void __iomem *base_addr, u_char cmd, int index)
909{ 916{
910 unsigned int i; 917 unsigned int i;
911 918
912 /* Check to see that the previous command has completed */ 919 /* Check to see that the previous command has completed */
913 for (i = 0; i < 100; i++) { 920 for (i = 0; i < 100; i++) {
914 if (readb(base_addr + (CyCCR << index)) == 0) { 921 if (readb(base_addr + (CyCCR << index)) == 0)
915 break; 922 break;
916 }
917 udelay(10L); 923 udelay(10L);
918 } 924 }
919 /* if the CCR never cleared, the previous command 925 /* if the CCR never cleared, the previous command
@@ -929,7 +935,7 @@ static int cyy_issue_cmd(void __iomem * base_addr, u_char cmd, int index)
929 935
930#ifdef CONFIG_ISA 936#ifdef CONFIG_ISA
931/* ISA interrupt detection code */ 937/* ISA interrupt detection code */
932static unsigned detect_isa_irq(void __iomem * address) 938static unsigned detect_isa_irq(void __iomem *address)
933{ 939{
934 int irq; 940 int irq;
935 unsigned long irqs, flags; 941 unsigned long irqs, flags;
@@ -1038,7 +1044,7 @@ static void cyy_chip_rx(struct cyclades_card *cinfo, int chip,
1038 if (info->flags & ASYNC_SAK) 1044 if (info->flags & ASYNC_SAK)
1039 do_SAK(tty); 1045 do_SAK(tty);
1040 } else if (data & CyFRAME) { 1046 } else if (data & CyFRAME) {
1041 tty_insert_flip_char( tty, 1047 tty_insert_flip_char(tty,
1042 readb(base_addr + (CyRDSR << 1048 readb(base_addr + (CyRDSR <<
1043 index)), TTY_FRAME); 1049 index)), TTY_FRAME);
1044 info->icount.rx++; 1050 info->icount.rx++;
@@ -1320,7 +1326,8 @@ static irqreturn_t cyy_interrupt(int irq, void *dev_id)
1320 1326
1321 if (unlikely(cinfo == NULL)) { 1327 if (unlikely(cinfo == NULL)) {
1322#ifdef CY_DEBUG_INTERRUPTS 1328#ifdef CY_DEBUG_INTERRUPTS
1323 printk(KERN_DEBUG "cyy_interrupt: spurious interrupt %d\n",irq); 1329 printk(KERN_DEBUG "cyy_interrupt: spurious interrupt %d\n",
1330 irq);
1324#endif 1331#endif
1325 return IRQ_NONE; /* spurious interrupt */ 1332 return IRQ_NONE; /* spurious interrupt */
1326 } 1333 }
@@ -1375,12 +1382,12 @@ static irqreturn_t cyy_interrupt(int irq, void *dev_id)
1375 1382
1376/***********************************************************/ 1383/***********************************************************/
1377/********* End of block of Cyclom-Y specific code **********/ 1384/********* End of block of Cyclom-Y specific code **********/
1378/******** Start of block of Cyclades-Z specific code *********/ 1385/******** Start of block of Cyclades-Z specific code *******/
1379/***********************************************************/ 1386/***********************************************************/
1380 1387
1381static int 1388static int
1382cyz_fetch_msg(struct cyclades_card *cinfo, 1389cyz_fetch_msg(struct cyclades_card *cinfo,
1383 __u32 * channel, __u8 * cmd, __u32 * param) 1390 __u32 *channel, __u8 *cmd, __u32 *param)
1384{ 1391{
1385 struct FIRM_ID __iomem *firm_id; 1392 struct FIRM_ID __iomem *firm_id;
1386 struct ZFW_CTRL __iomem *zfw_ctrl; 1393 struct ZFW_CTRL __iomem *zfw_ctrl;
@@ -1388,9 +1395,8 @@ cyz_fetch_msg(struct cyclades_card *cinfo,
1388 unsigned long loc_doorbell; 1395 unsigned long loc_doorbell;
1389 1396
1390 firm_id = cinfo->base_addr + ID_ADDRESS; 1397 firm_id = cinfo->base_addr + ID_ADDRESS;
1391 if (!ISZLOADED(*cinfo)) { 1398 if (!ISZLOADED(*cinfo))
1392 return -1; 1399 return -1;
1393 }
1394 zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff); 1400 zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff);
1395 board_ctrl = &zfw_ctrl->board_ctrl; 1401 board_ctrl = &zfw_ctrl->board_ctrl;
1396 1402
@@ -1418,9 +1424,9 @@ cyz_issue_cmd(struct cyclades_card *cinfo,
1418 unsigned int index; 1424 unsigned int index;
1419 1425
1420 firm_id = cinfo->base_addr + ID_ADDRESS; 1426 firm_id = cinfo->base_addr + ID_ADDRESS;
1421 if (!ISZLOADED(*cinfo)) { 1427 if (!ISZLOADED(*cinfo))
1422 return -1; 1428 return -1;
1423 } 1429
1424 zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff); 1430 zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff);
1425 board_ctrl = &zfw_ctrl->board_ctrl; 1431 board_ctrl = &zfw_ctrl->board_ctrl;
1426 1432
@@ -1428,9 +1434,8 @@ cyz_issue_cmd(struct cyclades_card *cinfo,
1428 pci_doorbell = 1434 pci_doorbell =
1429 &((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->pci_doorbell; 1435 &((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->pci_doorbell;
1430 while ((readl(pci_doorbell) & 0xff) != 0) { 1436 while ((readl(pci_doorbell) & 0xff) != 0) {
1431 if (index++ == 1000) { 1437 if (index++ == 1000)
1432 return (int)(readl(pci_doorbell) & 0xff); 1438 return (int)(readl(pci_doorbell) & 0xff);
1433 }
1434 udelay(50L); 1439 udelay(50L);
1435 } 1440 }
1436 cy_writel(&board_ctrl->hcmd_channel, channel); 1441 cy_writel(&board_ctrl->hcmd_channel, channel);
@@ -1504,7 +1509,8 @@ static void cyz_handle_rx(struct cyclades_port *info,
1504 while (len--) { 1509 while (len--) {
1505 data = readb(cinfo->base_addr + rx_bufaddr + 1510 data = readb(cinfo->base_addr + rx_bufaddr +
1506 new_rx_get); 1511 new_rx_get);
1507 new_rx_get = (new_rx_get + 1)& (rx_bufsize - 1); 1512 new_rx_get = (new_rx_get + 1) &
1513 (rx_bufsize - 1);
1508 tty_insert_flip_char(tty, data, TTY_NORMAL); 1514 tty_insert_flip_char(tty, data, TTY_NORMAL);
1509 info->idle_stats.recv_bytes++; 1515 info->idle_stats.recv_bytes++;
1510 info->icount.rx++; 1516 info->icount.rx++;
@@ -1636,7 +1642,8 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo)
1636 special_count = 0; 1642 special_count = 0;
1637 delta_count = 0; 1643 delta_count = 0;
1638 info = &cinfo->ports[channel]; 1644 info = &cinfo->ports[channel];
1639 if ((tty = info->tty) == NULL) 1645 tty = info->tty;
1646 if (tty == NULL)
1640 continue; 1647 continue;
1641 1648
1642 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]); 1649 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
@@ -1732,7 +1739,8 @@ static irqreturn_t cyz_interrupt(int irq, void *dev_id)
1732 1739
1733 if (unlikely(cinfo == NULL)) { 1740 if (unlikely(cinfo == NULL)) {
1734#ifdef CY_DEBUG_INTERRUPTS 1741#ifdef CY_DEBUG_INTERRUPTS
1735 printk(KERN_DEBUG "cyz_interrupt: spurious interrupt %d\n",irq); 1742 printk(KERN_DEBUG "cyz_interrupt: spurious interrupt %d\n",
1743 irq);
1736#endif 1744#endif
1737 return IRQ_NONE; /* spurious interrupt */ 1745 return IRQ_NONE; /* spurious interrupt */
1738 } 1746 }
@@ -1851,9 +1859,8 @@ static int startup(struct cyclades_port *info)
1851 } 1859 }
1852 1860
1853 if (!info->type) { 1861 if (!info->type) {
1854 if (info->tty) { 1862 if (info->tty)
1855 set_bit(TTY_IO_ERROR, &info->tty->flags); 1863 set_bit(TTY_IO_ERROR, &info->tty->flags);
1856 }
1857 free_page(page); 1864 free_page(page);
1858 goto errout; 1865 goto errout;
1859 } 1866 }
@@ -1904,9 +1911,8 @@ static int startup(struct cyclades_port *info)
1904 readb(base_addr + (CySRER << index)) | CyRxData); 1911 readb(base_addr + (CySRER << index)) | CyRxData);
1905 info->flags |= ASYNC_INITIALIZED; 1912 info->flags |= ASYNC_INITIALIZED;
1906 1913
1907 if (info->tty) { 1914 if (info->tty)
1908 clear_bit(TTY_IO_ERROR, &info->tty->flags); 1915 clear_bit(TTY_IO_ERROR, &info->tty->flags);
1909 }
1910 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 1916 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1911 info->breakon = info->breakoff = 0; 1917 info->breakon = info->breakoff = 0;
1912 memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats)); 1918 memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats));
@@ -1925,9 +1931,8 @@ static int startup(struct cyclades_port *info)
1925 base_addr = card->base_addr; 1931 base_addr = card->base_addr;
1926 1932
1927 firm_id = base_addr + ID_ADDRESS; 1933 firm_id = base_addr + ID_ADDRESS;
1928 if (!ISZLOADED(*card)) { 1934 if (!ISZLOADED(*card))
1929 return -ENODEV; 1935 return -ENODEV;
1930 }
1931 1936
1932 zfw_ctrl = card->base_addr + 1937 zfw_ctrl = card->base_addr +
1933 (readl(&firm_id->zfwctrl_addr) & 0xfffff); 1938 (readl(&firm_id->zfwctrl_addr) & 0xfffff);
@@ -1990,9 +1995,8 @@ static int startup(struct cyclades_port *info)
1990 /* enable send, recv, modem !!! */ 1995 /* enable send, recv, modem !!! */
1991 1996
1992 info->flags |= ASYNC_INITIALIZED; 1997 info->flags |= ASYNC_INITIALIZED;
1993 if (info->tty) { 1998 if (info->tty)
1994 clear_bit(TTY_IO_ERROR, &info->tty->flags); 1999 clear_bit(TTY_IO_ERROR, &info->tty->flags);
1995 }
1996 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 2000 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1997 info->breakon = info->breakoff = 0; 2001 info->breakon = info->breakoff = 0;
1998 memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats)); 2002 memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats));
@@ -2061,9 +2065,8 @@ static void shutdown(struct cyclades_port *info)
2061 void __iomem *base_addr; 2065 void __iomem *base_addr;
2062 int chip, channel, index; 2066 int chip, channel, index;
2063 2067
2064 if (!(info->flags & ASYNC_INITIALIZED)) { 2068 if (!(info->flags & ASYNC_INITIALIZED))
2065 return; 2069 return;
2066 }
2067 2070
2068 card = info->card; 2071 card = info->card;
2069 channel = info->line - card->first_line; 2072 channel = info->line - card->first_line;
@@ -2105,9 +2108,8 @@ static void shutdown(struct cyclades_port *info)
2105 /* it may be appropriate to clear _XMIT at 2108 /* it may be appropriate to clear _XMIT at
2106 some later date (after testing)!!! */ 2109 some later date (after testing)!!! */
2107 2110
2108 if (info->tty) { 2111 if (info->tty)
2109 set_bit(TTY_IO_ERROR, &info->tty->flags); 2112 set_bit(TTY_IO_ERROR, &info->tty->flags);
2110 }
2111 info->flags &= ~ASYNC_INITIALIZED; 2113 info->flags &= ~ASYNC_INITIALIZED;
2112 spin_unlock_irqrestore(&card->card_lock, flags); 2114 spin_unlock_irqrestore(&card->card_lock, flags);
2113 } else { 2115 } else {
@@ -2124,9 +2126,8 @@ static void shutdown(struct cyclades_port *info)
2124#endif 2126#endif
2125 2127
2126 firm_id = base_addr + ID_ADDRESS; 2128 firm_id = base_addr + ID_ADDRESS;
2127 if (!ISZLOADED(*card)) { 2129 if (!ISZLOADED(*card))
2128 return; 2130 return;
2129 }
2130 2131
2131 zfw_ctrl = card->base_addr + 2132 zfw_ctrl = card->base_addr +
2132 (readl(&firm_id->zfwctrl_addr) & 0xfffff); 2133 (readl(&firm_id->zfwctrl_addr) & 0xfffff);
@@ -2157,9 +2158,8 @@ static void shutdown(struct cyclades_port *info)
2157#endif 2158#endif
2158 } 2159 }
2159 2160
2160 if (info->tty) { 2161 if (info->tty)
2161 set_bit(TTY_IO_ERROR, &info->tty->flags); 2162 set_bit(TTY_IO_ERROR, &info->tty->flags);
2162 }
2163 info->flags &= ~ASYNC_INITIALIZED; 2163 info->flags &= ~ASYNC_INITIALIZED;
2164 2164
2165 spin_unlock_irqrestore(&card->card_lock, flags); 2165 spin_unlock_irqrestore(&card->card_lock, flags);
@@ -2204,7 +2204,8 @@ block_til_ready(struct tty_struct *tty, struct file *filp,
2204 * If non-blocking mode is set, then make the check up front 2204 * If non-blocking mode is set, then make the check up front
2205 * and then exit. 2205 * and then exit.
2206 */ 2206 */
2207 if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) { 2207 if ((filp->f_flags & O_NONBLOCK) ||
2208 (tty->flags & (1 << TTY_IO_ERROR))) {
2208 info->flags |= ASYNC_NORMAL_ACTIVE; 2209 info->flags |= ASYNC_NORMAL_ACTIVE;
2209 return 0; 2210 return 0;
2210 } 2211 }
@@ -2301,7 +2302,8 @@ block_til_ready(struct tty_struct *tty, struct file *filp,
2301 return -EINVAL; 2302 return -EINVAL;
2302 } 2303 }
2303 2304
2304 zfw_ctrl = base_addr + (readl(&firm_id->zfwctrl_addr)& 0xfffff); 2305 zfw_ctrl = base_addr + (readl(&firm_id->zfwctrl_addr)
2306 & 0xfffff);
2305 board_ctrl = &zfw_ctrl->board_ctrl; 2307 board_ctrl = &zfw_ctrl->board_ctrl;
2306 ch_ctrl = zfw_ctrl->ch_ctrl; 2308 ch_ctrl = zfw_ctrl->ch_ctrl;
2307 2309
@@ -2378,9 +2380,9 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
2378 int retval; 2380 int retval;
2379 2381
2380 line = tty->index; 2382 line = tty->index;
2381 if ((tty->index < 0) || (NR_PORTS <= line)) { 2383 if (tty->index < 0 || NR_PORTS <= line)
2382 return -ENODEV; 2384 return -ENODEV;
2383 } 2385
2384 for (i = 0; i < NR_CARDS; i++) 2386 for (i = 0; i < NR_CARDS; i++)
2385 if (line < cy_card[i].first_line + cy_card[i].nports && 2387 if (line < cy_card[i].first_line + cy_card[i].nports &&
2386 line >= cy_card[i].first_line) 2388 line >= cy_card[i].first_line)
@@ -2388,9 +2390,8 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
2388 if (i >= NR_CARDS) 2390 if (i >= NR_CARDS)
2389 return -ENODEV; 2391 return -ENODEV;
2390 info = &cy_card[i].ports[line - cy_card[i].first_line]; 2392 info = &cy_card[i].ports[line - cy_card[i].first_line];
2391 if (info->line < 0) { 2393 if (info->line < 0)
2392 return -ENODEV; 2394 return -ENODEV;
2393 }
2394 2395
2395 /* If the card's firmware hasn't been loaded, 2396 /* If the card's firmware hasn't been loaded,
2396 treat it as absent from the system. This 2397 treat it as absent from the system. This
@@ -2456,9 +2457,9 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
2456#endif 2457#endif
2457 tty->driver_data = info; 2458 tty->driver_data = info;
2458 info->tty = tty; 2459 info->tty = tty;
2459 if (serial_paranoia_check(info, tty->name, "cy_open")) { 2460 if (serial_paranoia_check(info, tty->name, "cy_open"))
2460 return -ENODEV; 2461 return -ENODEV;
2461 } 2462
2462#ifdef CY_DEBUG_OPEN 2463#ifdef CY_DEBUG_OPEN
2463 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line, 2464 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
2464 info->count); 2465 info->count);
@@ -2482,9 +2483,8 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
2482 * Start up serial port 2483 * Start up serial port
2483 */ 2484 */
2484 retval = startup(info); 2485 retval = startup(info);
2485 if (retval) { 2486 if (retval)
2486 return retval; 2487 return retval;
2487 }
2488 2488
2489 retval = block_til_ready(tty, filp, info); 2489 retval = block_til_ready(tty, filp, info);
2490 if (retval) { 2490 if (retval) {
@@ -2522,6 +2522,7 @@ static void cy_wait_until_sent(struct tty_struct *tty, int timeout)
2522 return; /* Just in case.... */ 2522 return; /* Just in case.... */
2523 2523
2524 orig_jiffies = jiffies; 2524 orig_jiffies = jiffies;
2525 lock_kernel();
2525 /* 2526 /*
2526 * Set the check interval to be 1/5 of the estimated time to 2527 * Set the check interval to be 1/5 of the estimated time to
2527 * send a single character, and make it at least 1. The check 2528 * send a single character, and make it at least 1. The check
@@ -2573,11 +2574,47 @@ static void cy_wait_until_sent(struct tty_struct *tty, int timeout)
2573 } 2574 }
2574 /* Run one more char cycle */ 2575 /* Run one more char cycle */
2575 msleep_interruptible(jiffies_to_msecs(char_time * 5)); 2576 msleep_interruptible(jiffies_to_msecs(char_time * 5));
2577 unlock_kernel();
2576#ifdef CY_DEBUG_WAIT_UNTIL_SENT 2578#ifdef CY_DEBUG_WAIT_UNTIL_SENT
2577 printk(KERN_DEBUG "Clean (jiff=%lu)...done\n", jiffies); 2579 printk(KERN_DEBUG "Clean (jiff=%lu)...done\n", jiffies);
2578#endif 2580#endif
2579} 2581}
2580 2582
2583static void cy_flush_buffer(struct tty_struct *tty)
2584{
2585 struct cyclades_port *info = tty->driver_data;
2586 struct cyclades_card *card;
2587 int channel, retval;
2588 unsigned long flags;
2589
2590#ifdef CY_DEBUG_IO
2591 printk(KERN_DEBUG "cyc:cy_flush_buffer ttyC%d\n", info->line);
2592#endif
2593
2594 if (serial_paranoia_check(info, tty->name, "cy_flush_buffer"))
2595 return;
2596
2597 card = info->card;
2598 channel = info->line - card->first_line;
2599
2600 spin_lock_irqsave(&card->card_lock, flags);
2601 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
2602 spin_unlock_irqrestore(&card->card_lock, flags);
2603
2604 if (IS_CYC_Z(*card)) { /* If it is a Z card, flush the on-board
2605 buffers as well */
2606 spin_lock_irqsave(&card->card_lock, flags);
2607 retval = cyz_issue_cmd(card, channel, C_CM_FLUSH_TX, 0L);
2608 if (retval != 0) {
2609 printk(KERN_ERR "cyc: flush_buffer retval on ttyC%d "
2610 "was %x\n", info->line, retval);
2611 }
2612 spin_unlock_irqrestore(&card->card_lock, flags);
2613 }
2614 tty_wakeup(tty);
2615} /* cy_flush_buffer */
2616
2617
2581/* 2618/*
2582 * This routine is called when a particular tty device is closed. 2619 * This routine is called when a particular tty device is closed.
2583 */ 2620 */
@@ -2591,9 +2628,8 @@ static void cy_close(struct tty_struct *tty, struct file *filp)
2591 printk(KERN_DEBUG "cyc:cy_close ttyC%d\n", info->line); 2628 printk(KERN_DEBUG "cyc:cy_close ttyC%d\n", info->line);
2592#endif 2629#endif
2593 2630
2594 if (!info || serial_paranoia_check(info, tty->name, "cy_close")) { 2631 if (!info || serial_paranoia_check(info, tty->name, "cy_close"))
2595 return; 2632 return;
2596 }
2597 2633
2598 card = info->card; 2634 card = info->card;
2599 2635
@@ -2641,9 +2677,9 @@ static void cy_close(struct tty_struct *tty, struct file *filp)
2641 */ 2677 */
2642 tty->closing = 1; 2678 tty->closing = 1;
2643 spin_unlock_irqrestore(&card->card_lock, flags); 2679 spin_unlock_irqrestore(&card->card_lock, flags);
2644 if (info->closing_wait != CY_CLOSING_WAIT_NONE) { 2680 if (info->closing_wait != CY_CLOSING_WAIT_NONE)
2645 tty_wait_until_sent(tty, info->closing_wait); 2681 tty_wait_until_sent(tty, info->closing_wait);
2646 } 2682
2647 spin_lock_irqsave(&card->card_lock, flags); 2683 spin_lock_irqsave(&card->card_lock, flags);
2648 2684
2649 if (!IS_CYC_Z(*card)) { 2685 if (!IS_CYC_Z(*card)) {
@@ -2657,15 +2693,16 @@ static void cy_close(struct tty_struct *tty, struct file *filp)
2657 cy_writeb(base_addr + (CySRER << index), 2693 cy_writeb(base_addr + (CySRER << index),
2658 readb(base_addr + (CySRER << index)) & ~CyRxData); 2694 readb(base_addr + (CySRER << index)) & ~CyRxData);
2659 if (info->flags & ASYNC_INITIALIZED) { 2695 if (info->flags & ASYNC_INITIALIZED) {
2660 /* Waiting for on-board buffers to be empty before closing 2696 /* Waiting for on-board buffers to be empty before
2661 the port */ 2697 closing the port */
2662 spin_unlock_irqrestore(&card->card_lock, flags); 2698 spin_unlock_irqrestore(&card->card_lock, flags);
2663 cy_wait_until_sent(tty, info->timeout); 2699 cy_wait_until_sent(tty, info->timeout);
2664 spin_lock_irqsave(&card->card_lock, flags); 2700 spin_lock_irqsave(&card->card_lock, flags);
2665 } 2701 }
2666 } else { 2702 } else {
2667#ifdef Z_WAKE 2703#ifdef Z_WAKE
2668 /* Waiting for on-board buffers to be empty before closing the port */ 2704 /* Waiting for on-board buffers to be empty before closing
2705 the port */
2669 void __iomem *base_addr = card->base_addr; 2706 void __iomem *base_addr = card->base_addr;
2670 struct FIRM_ID __iomem *firm_id = base_addr + ID_ADDRESS; 2707 struct FIRM_ID __iomem *firm_id = base_addr + ID_ADDRESS;
2671 struct ZFW_CTRL __iomem *zfw_ctrl = 2708 struct ZFW_CTRL __iomem *zfw_ctrl =
@@ -2689,8 +2726,7 @@ static void cy_close(struct tty_struct *tty, struct file *filp)
2689 2726
2690 spin_unlock_irqrestore(&card->card_lock, flags); 2727 spin_unlock_irqrestore(&card->card_lock, flags);
2691 shutdown(info); 2728 shutdown(info);
2692 if (tty->driver->flush_buffer) 2729 cy_flush_buffer(tty);
2693 tty->driver->flush_buffer(tty);
2694 tty_ldisc_flush(tty); 2730 tty_ldisc_flush(tty);
2695 spin_lock_irqsave(&card->card_lock, flags); 2731 spin_lock_irqsave(&card->card_lock, flags);
2696 2732
@@ -2738,17 +2774,16 @@ static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count)
2738 printk(KERN_DEBUG "cyc:cy_write ttyC%d\n", info->line); 2774 printk(KERN_DEBUG "cyc:cy_write ttyC%d\n", info->line);
2739#endif 2775#endif
2740 2776
2741 if (serial_paranoia_check(info, tty->name, "cy_write")) { 2777 if (serial_paranoia_check(info, tty->name, "cy_write"))
2742 return 0; 2778 return 0;
2743 }
2744 2779
2745 if (!info->xmit_buf) 2780 if (!info->xmit_buf)
2746 return 0; 2781 return 0;
2747 2782
2748 spin_lock_irqsave(&info->card->card_lock, flags); 2783 spin_lock_irqsave(&info->card->card_lock, flags);
2749 while (1) { 2784 while (1) {
2750 c = min(count, min((int)(SERIAL_XMIT_SIZE - info->xmit_cnt - 1), 2785 c = min(count, (int)(SERIAL_XMIT_SIZE - info->xmit_cnt - 1));
2751 (int)(SERIAL_XMIT_SIZE - info->xmit_head))); 2786 c = min(c, (int)(SERIAL_XMIT_SIZE - info->xmit_head));
2752 2787
2753 if (c <= 0) 2788 if (c <= 0)
2754 break; 2789 break;
@@ -2766,9 +2801,9 @@ static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count)
2766 info->idle_stats.xmit_bytes += ret; 2801 info->idle_stats.xmit_bytes += ret;
2767 info->idle_stats.xmit_idle = jiffies; 2802 info->idle_stats.xmit_idle = jiffies;
2768 2803
2769 if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) { 2804 if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped)
2770 start_xmit(info); 2805 start_xmit(info);
2771 } 2806
2772 return ret; 2807 return ret;
2773} /* cy_write */ 2808} /* cy_write */
2774 2809
@@ -2779,7 +2814,7 @@ static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count)
2779 * done stuffing characters into the driver. If there is no room 2814 * done stuffing characters into the driver. If there is no room
2780 * in the queue, the character is ignored. 2815 * in the queue, the character is ignored.
2781 */ 2816 */
2782static void cy_put_char(struct tty_struct *tty, unsigned char ch) 2817static int cy_put_char(struct tty_struct *tty, unsigned char ch)
2783{ 2818{
2784 struct cyclades_port *info = tty->driver_data; 2819 struct cyclades_port *info = tty->driver_data;
2785 unsigned long flags; 2820 unsigned long flags;
@@ -2789,15 +2824,15 @@ static void cy_put_char(struct tty_struct *tty, unsigned char ch)
2789#endif 2824#endif
2790 2825
2791 if (serial_paranoia_check(info, tty->name, "cy_put_char")) 2826 if (serial_paranoia_check(info, tty->name, "cy_put_char"))
2792 return; 2827 return 0;
2793 2828
2794 if (!info->xmit_buf) 2829 if (!info->xmit_buf)
2795 return; 2830 return 0;
2796 2831
2797 spin_lock_irqsave(&info->card->card_lock, flags); 2832 spin_lock_irqsave(&info->card->card_lock, flags);
2798 if (info->xmit_cnt >= (int)(SERIAL_XMIT_SIZE - 1)) { 2833 if (info->xmit_cnt >= (int)(SERIAL_XMIT_SIZE - 1)) {
2799 spin_unlock_irqrestore(&info->card->card_lock, flags); 2834 spin_unlock_irqrestore(&info->card->card_lock, flags);
2800 return; 2835 return 0;
2801 } 2836 }
2802 2837
2803 info->xmit_buf[info->xmit_head++] = ch; 2838 info->xmit_buf[info->xmit_head++] = ch;
@@ -2806,11 +2841,12 @@ static void cy_put_char(struct tty_struct *tty, unsigned char ch)
2806 info->idle_stats.xmit_bytes++; 2841 info->idle_stats.xmit_bytes++;
2807 info->idle_stats.xmit_idle = jiffies; 2842 info->idle_stats.xmit_idle = jiffies;
2808 spin_unlock_irqrestore(&info->card->card_lock, flags); 2843 spin_unlock_irqrestore(&info->card->card_lock, flags);
2844 return 1;
2809} /* cy_put_char */ 2845} /* cy_put_char */
2810 2846
2811/* 2847/*
2812 * This routine is called by the kernel after it has written a 2848 * This routine is called by the kernel after it has written a
2813 * series of characters to the tty device using put_char(). 2849 * series of characters to the tty device using put_char().
2814 */ 2850 */
2815static void cy_flush_chars(struct tty_struct *tty) 2851static void cy_flush_chars(struct tty_struct *tty)
2816{ 2852{
@@ -2882,6 +2918,7 @@ static int cy_chars_in_buffer(struct tty_struct *tty)
2882 int char_count; 2918 int char_count;
2883 __u32 tx_put, tx_get, tx_bufsize; 2919 __u32 tx_put, tx_get, tx_bufsize;
2884 2920
2921 lock_kernel();
2885 firm_id = card->base_addr + ID_ADDRESS; 2922 firm_id = card->base_addr + ID_ADDRESS;
2886 zfw_ctrl = card->base_addr + 2923 zfw_ctrl = card->base_addr +
2887 (readl(&firm_id->zfwctrl_addr) & 0xfffff); 2924 (readl(&firm_id->zfwctrl_addr) & 0xfffff);
@@ -2899,6 +2936,7 @@ static int cy_chars_in_buffer(struct tty_struct *tty)
2899 printk(KERN_DEBUG "cyc:cy_chars_in_buffer ttyC%d %d\n", 2936 printk(KERN_DEBUG "cyc:cy_chars_in_buffer ttyC%d %d\n",
2900 info->line, info->xmit_cnt + char_count); 2937 info->line, info->xmit_cnt + char_count);
2901#endif 2938#endif
2939 unlock_kernel();
2902 return info->xmit_cnt + char_count; 2940 return info->xmit_cnt + char_count;
2903 } 2941 }
2904#endif /* Z_EXT_CHARS_IN_BUFFER */ 2942#endif /* Z_EXT_CHARS_IN_BUFFER */
@@ -2950,12 +2988,12 @@ static void set_line_char(struct cyclades_port *info)
2950 int baud, baud_rate = 0; 2988 int baud, baud_rate = 0;
2951 int i; 2989 int i;
2952 2990
2953 if (!info->tty || !info->tty->termios) { 2991 if (!info->tty || !info->tty->termios)
2954 return; 2992 return;
2955 } 2993
2956 if (info->line == -1) { 2994 if (info->line == -1)
2957 return; 2995 return;
2958 } 2996
2959 cflag = info->tty->termios->c_cflag; 2997 cflag = info->tty->termios->c_cflag;
2960 iflag = info->tty->termios->c_iflag; 2998 iflag = info->tty->termios->c_iflag;
2961 2999
@@ -2994,13 +3032,11 @@ static void set_line_char(struct cyclades_port *info)
2994 } 3032 }
2995 /* find the baud index */ 3033 /* find the baud index */
2996 for (i = 0; i < 20; i++) { 3034 for (i = 0; i < 20; i++) {
2997 if (baud == baud_table[i]) { 3035 if (baud == baud_table[i])
2998 break; 3036 break;
2999 }
3000 } 3037 }
3001 if (i == 20) { 3038 if (i == 20)
3002 i = 19; /* CD1400_MAX_SPEED */ 3039 i = 19; /* CD1400_MAX_SPEED */
3003 }
3004 3040
3005 if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) == 3041 if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
3006 ASYNC_SPD_CUST) { 3042 ASYNC_SPD_CUST) {
@@ -3059,18 +3095,16 @@ static void set_line_char(struct cyclades_port *info)
3059 info->cor1 = Cy_8_BITS; 3095 info->cor1 = Cy_8_BITS;
3060 break; 3096 break;
3061 } 3097 }
3062 if (cflag & CSTOPB) { 3098 if (cflag & CSTOPB)
3063 info->cor1 |= Cy_2_STOP; 3099 info->cor1 |= Cy_2_STOP;
3064 } 3100
3065 if (cflag & PARENB) { 3101 if (cflag & PARENB) {
3066 if (cflag & PARODD) { 3102 if (cflag & PARODD)
3067 info->cor1 |= CyPARITY_O; 3103 info->cor1 |= CyPARITY_O;
3068 } else { 3104 else
3069 info->cor1 |= CyPARITY_E; 3105 info->cor1 |= CyPARITY_E;
3070 } 3106 } else
3071 } else {
3072 info->cor1 |= CyPARITY_NONE; 3107 info->cor1 |= CyPARITY_NONE;
3073 }
3074 3108
3075 /* CTS flow control flag */ 3109 /* CTS flow control flag */
3076 if (cflag & CRTSCTS) { 3110 if (cflag & CRTSCTS) {
@@ -3123,7 +3157,8 @@ static void set_line_char(struct cyclades_port *info)
3123 cyy_issue_cmd(base_addr, CyCOR_CHANGE | CyCOR1ch | CyCOR2ch | 3157 cyy_issue_cmd(base_addr, CyCOR_CHANGE | CyCOR1ch | CyCOR2ch |
3124 CyCOR3ch, index); 3158 CyCOR3ch, index);
3125 3159
3126 cy_writeb(base_addr + (CyCAR << index), (u_char) channel); /* !!! Is this needed? */ 3160 /* !!! Is this needed? */
3161 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
3127 cy_writeb(base_addr + (CyRTPR << index), 3162 cy_writeb(base_addr + (CyRTPR << index),
3128 (info->default_timeout ? info->default_timeout : 0x02)); 3163 (info->default_timeout ? info->default_timeout : 0x02));
3129 /* 10ms rx timeout */ 3164 /* 10ms rx timeout */
@@ -3191,9 +3226,8 @@ static void set_line_char(struct cyclades_port *info)
3191#endif 3226#endif
3192 } 3227 }
3193 3228
3194 if (info->tty) { 3229 if (info->tty)
3195 clear_bit(TTY_IO_ERROR, &info->tty->flags); 3230 clear_bit(TTY_IO_ERROR, &info->tty->flags);
3196 }
3197 spin_unlock_irqrestore(&card->card_lock, flags); 3231 spin_unlock_irqrestore(&card->card_lock, flags);
3198 3232
3199 } else { 3233 } else {
@@ -3206,9 +3240,8 @@ static void set_line_char(struct cyclades_port *info)
3206 int retval; 3240 int retval;
3207 3241
3208 firm_id = card->base_addr + ID_ADDRESS; 3242 firm_id = card->base_addr + ID_ADDRESS;
3209 if (!ISZLOADED(*card)) { 3243 if (!ISZLOADED(*card))
3210 return; 3244 return;
3211 }
3212 3245
3213 zfw_ctrl = card->base_addr + 3246 zfw_ctrl = card->base_addr +
3214 (readl(&firm_id->zfwctrl_addr) & 0xfffff); 3247 (readl(&firm_id->zfwctrl_addr) & 0xfffff);
@@ -3268,14 +3301,12 @@ static void set_line_char(struct cyclades_port *info)
3268 readl(&ch_ctrl->comm_data_l) | C_DL_1STOP); 3301 readl(&ch_ctrl->comm_data_l) | C_DL_1STOP);
3269 } 3302 }
3270 if (cflag & PARENB) { 3303 if (cflag & PARENB) {
3271 if (cflag & PARODD) { 3304 if (cflag & PARODD)
3272 cy_writel(&ch_ctrl->comm_parity, C_PR_ODD); 3305 cy_writel(&ch_ctrl->comm_parity, C_PR_ODD);
3273 } else { 3306 else
3274 cy_writel(&ch_ctrl->comm_parity, C_PR_EVEN); 3307 cy_writel(&ch_ctrl->comm_parity, C_PR_EVEN);
3275 } 3308 } else
3276 } else {
3277 cy_writel(&ch_ctrl->comm_parity, C_PR_NONE); 3309 cy_writel(&ch_ctrl->comm_parity, C_PR_NONE);
3278 }
3279 3310
3280 /* CTS flow control flag */ 3311 /* CTS flow control flag */
3281 if (cflag & CRTSCTS) { 3312 if (cflag & CRTSCTS) {
@@ -3305,11 +3336,10 @@ static void set_line_char(struct cyclades_port *info)
3305 } 3336 }
3306 3337
3307 /* CD sensitivity */ 3338 /* CD sensitivity */
3308 if (cflag & CLOCAL) { 3339 if (cflag & CLOCAL)
3309 info->flags &= ~ASYNC_CHECK_CD; 3340 info->flags &= ~ASYNC_CHECK_CD;
3310 } else { 3341 else
3311 info->flags |= ASYNC_CHECK_CD; 3342 info->flags |= ASYNC_CHECK_CD;
3312 }
3313 3343
3314 if (baud == 0) { /* baud rate is zero, turn off line */ 3344 if (baud == 0) { /* baud rate is zero, turn off line */
3315 cy_writel(&ch_ctrl->rs_control, 3345 cy_writel(&ch_ctrl->rs_control,
@@ -3325,21 +3355,20 @@ static void set_line_char(struct cyclades_port *info)
3325#endif 3355#endif
3326 } 3356 }
3327 3357
3328 retval = cyz_issue_cmd(card, channel, C_CM_IOCTLM,0L); 3358 retval = cyz_issue_cmd(card, channel, C_CM_IOCTLM, 0L);
3329 if (retval != 0) { 3359 if (retval != 0) {
3330 printk(KERN_ERR "cyc:set_line_char(2) retval on ttyC%d " 3360 printk(KERN_ERR "cyc:set_line_char(2) retval on ttyC%d "
3331 "was %x\n", info->line, retval); 3361 "was %x\n", info->line, retval);
3332 } 3362 }
3333 3363
3334 if (info->tty) { 3364 if (info->tty)
3335 clear_bit(TTY_IO_ERROR, &info->tty->flags); 3365 clear_bit(TTY_IO_ERROR, &info->tty->flags);
3336 }
3337 } 3366 }
3338} /* set_line_char */ 3367} /* set_line_char */
3339 3368
3340static int 3369static int
3341get_serial_info(struct cyclades_port *info, 3370get_serial_info(struct cyclades_port *info,
3342 struct serial_struct __user * retinfo) 3371 struct serial_struct __user *retinfo)
3343{ 3372{
3344 struct serial_struct tmp; 3373 struct serial_struct tmp;
3345 struct cyclades_card *cinfo = info->card; 3374 struct cyclades_card *cinfo = info->card;
@@ -3363,7 +3392,7 @@ get_serial_info(struct cyclades_port *info,
3363 3392
3364static int 3393static int
3365set_serial_info(struct cyclades_port *info, 3394set_serial_info(struct cyclades_port *info,
3366 struct serial_struct __user * new_info) 3395 struct serial_struct __user *new_info)
3367{ 3396{
3368 struct serial_struct new_serial; 3397 struct serial_struct new_serial;
3369 struct cyclades_port old_info; 3398 struct cyclades_port old_info;
@@ -3417,7 +3446,7 @@ check_and_exit:
3417 * transmit holding register is empty. This functionality 3446 * transmit holding register is empty. This functionality
3418 * allows an RS485 driver to be written in user space. 3447 * allows an RS485 driver to be written in user space.
3419 */ 3448 */
3420static int get_lsr_info(struct cyclades_port *info, unsigned int __user * value) 3449static int get_lsr_info(struct cyclades_port *info, unsigned int __user *value)
3421{ 3450{
3422 struct cyclades_card *card; 3451 struct cyclades_card *card;
3423 int chip, channel, index; 3452 int chip, channel, index;
@@ -3461,9 +3490,11 @@ static int cy_tiocmget(struct tty_struct *tty, struct file *file)
3461 struct BOARD_CTRL __iomem *board_ctrl; 3490 struct BOARD_CTRL __iomem *board_ctrl;
3462 struct CH_CTRL __iomem *ch_ctrl; 3491 struct CH_CTRL __iomem *ch_ctrl;
3463 3492
3464 if (serial_paranoia_check(info, tty->name, __FUNCTION__)) 3493 if (serial_paranoia_check(info, tty->name, __func__))
3465 return -ENODEV; 3494 return -ENODEV;
3466 3495
3496 lock_kernel();
3497
3467 card = info->card; 3498 card = info->card;
3468 channel = info->line - card->first_line; 3499 channel = info->line - card->first_line;
3469 if (!IS_CYC_Z(*card)) { 3500 if (!IS_CYC_Z(*card)) {
@@ -3506,10 +3537,12 @@ static int cy_tiocmget(struct tty_struct *tty, struct file *file)
3506 ((lstatus & C_RS_CTS) ? TIOCM_CTS : 0); 3537 ((lstatus & C_RS_CTS) ? TIOCM_CTS : 0);
3507 } else { 3538 } else {
3508 result = 0; 3539 result = 0;
3540 unlock_kernel();
3509 return -ENODEV; 3541 return -ENODEV;
3510 } 3542 }
3511 3543
3512 } 3544 }
3545 unlock_kernel();
3513 return result; 3546 return result;
3514} /* cy_tiomget */ 3547} /* cy_tiomget */
3515 3548
@@ -3528,7 +3561,7 @@ cy_tiocmset(struct tty_struct *tty, struct file *file,
3528 struct CH_CTRL __iomem *ch_ctrl; 3561 struct CH_CTRL __iomem *ch_ctrl;
3529 int retval; 3562 int retval;
3530 3563
3531 if (serial_paranoia_check(info, tty->name, __FUNCTION__)) 3564 if (serial_paranoia_check(info, tty->name, __func__))
3532 return -ENODEV; 3565 return -ENODEV;
3533 3566
3534 card = info->card; 3567 card = info->card;
@@ -3727,8 +3760,8 @@ static void cy_break(struct tty_struct *tty, int break_state)
3727 spin_unlock_irqrestore(&card->card_lock, flags); 3760 spin_unlock_irqrestore(&card->card_lock, flags);
3728} /* cy_break */ 3761} /* cy_break */
3729 3762
3730static int 3763static int get_mon_info(struct cyclades_port *info,
3731get_mon_info(struct cyclades_port *info, struct cyclades_monitor __user * mon) 3764 struct cyclades_monitor __user *mon)
3732{ 3765{
3733 3766
3734 if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor))) 3767 if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor)))
@@ -3767,8 +3800,8 @@ static int set_threshold(struct cyclades_port *info, unsigned long value)
3767 return 0; 3800 return 0;
3768} /* set_threshold */ 3801} /* set_threshold */
3769 3802
3770static int 3803static int get_threshold(struct cyclades_port *info,
3771get_threshold(struct cyclades_port *info, unsigned long __user * value) 3804 unsigned long __user *value)
3772{ 3805{
3773 struct cyclades_card *card; 3806 struct cyclades_card *card;
3774 void __iomem *base_addr; 3807 void __iomem *base_addr;
@@ -3789,15 +3822,15 @@ get_threshold(struct cyclades_port *info, unsigned long __user * value)
3789 return 0; 3822 return 0;
3790} /* get_threshold */ 3823} /* get_threshold */
3791 3824
3792static int 3825static int set_default_threshold(struct cyclades_port *info,
3793set_default_threshold(struct cyclades_port *info, unsigned long value) 3826 unsigned long value)
3794{ 3827{
3795 info->default_threshold = value & 0x0f; 3828 info->default_threshold = value & 0x0f;
3796 return 0; 3829 return 0;
3797} /* set_default_threshold */ 3830} /* set_default_threshold */
3798 3831
3799static int 3832static int get_default_threshold(struct cyclades_port *info,
3800get_default_threshold(struct cyclades_port *info, unsigned long __user * value) 3833 unsigned long __user *value)
3801{ 3834{
3802 return put_user(info->default_threshold, value); 3835 return put_user(info->default_threshold, value);
3803} /* get_default_threshold */ 3836} /* get_default_threshold */
@@ -3824,7 +3857,8 @@ static int set_timeout(struct cyclades_port *info, unsigned long value)
3824 return 0; 3857 return 0;
3825} /* set_timeout */ 3858} /* set_timeout */
3826 3859
3827static int get_timeout(struct cyclades_port *info, unsigned long __user * value) 3860static int get_timeout(struct cyclades_port *info,
3861 unsigned long __user *value)
3828{ 3862{
3829 struct cyclades_card *card; 3863 struct cyclades_card *card;
3830 void __iomem *base_addr; 3864 void __iomem *base_addr;
@@ -3851,8 +3885,8 @@ static int set_default_timeout(struct cyclades_port *info, unsigned long value)
3851 return 0; 3885 return 0;
3852} /* set_default_timeout */ 3886} /* set_default_timeout */
3853 3887
3854static int 3888static int get_default_timeout(struct cyclades_port *info,
3855get_default_timeout(struct cyclades_port *info, unsigned long __user * value) 3889 unsigned long __user *value)
3856{ 3890{
3857 return put_user(info->default_timeout, value); 3891 return put_user(info->default_timeout, value);
3858} /* get_default_timeout */ 3892} /* get_default_timeout */
@@ -3880,6 +3914,7 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
3880 printk(KERN_DEBUG "cyc:cy_ioctl ttyC%d, cmd = %x arg = %lx\n", 3914 printk(KERN_DEBUG "cyc:cy_ioctl ttyC%d, cmd = %x arg = %lx\n",
3881 info->line, cmd, arg); 3915 info->line, cmd, arg);
3882#endif 3916#endif
3917 lock_kernel();
3883 3918
3884 switch (cmd) { 3919 switch (cmd) {
3885 case CYGETMON: 3920 case CYGETMON:
@@ -3936,7 +3971,7 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
3936 break; 3971 break;
3937#endif /* CONFIG_CYZ_INTR */ 3972#endif /* CONFIG_CYZ_INTR */
3938 case CYSETWAIT: 3973 case CYSETWAIT:
3939 info->closing_wait = (unsigned short)arg *HZ / 100; 3974 info->closing_wait = (unsigned short)arg * HZ / 100;
3940 ret_val = 0; 3975 ret_val = 0;
3941 break; 3976 break;
3942 case CYGETWAIT: 3977 case CYGETWAIT:
@@ -3988,47 +4023,47 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
3988 p_cuser = argp; 4023 p_cuser = argp;
3989 ret_val = put_user(cnow.cts, &p_cuser->cts); 4024 ret_val = put_user(cnow.cts, &p_cuser->cts);
3990 if (ret_val) 4025 if (ret_val)
3991 return ret_val; 4026 break;
3992 ret_val = put_user(cnow.dsr, &p_cuser->dsr); 4027 ret_val = put_user(cnow.dsr, &p_cuser->dsr);
3993 if (ret_val) 4028 if (ret_val)
3994 return ret_val; 4029 break;
3995 ret_val = put_user(cnow.rng, &p_cuser->rng); 4030 ret_val = put_user(cnow.rng, &p_cuser->rng);
3996 if (ret_val) 4031 if (ret_val)
3997 return ret_val; 4032 break;
3998 ret_val = put_user(cnow.dcd, &p_cuser->dcd); 4033 ret_val = put_user(cnow.dcd, &p_cuser->dcd);
3999 if (ret_val) 4034 if (ret_val)
4000 return ret_val; 4035 break;
4001 ret_val = put_user(cnow.rx, &p_cuser->rx); 4036 ret_val = put_user(cnow.rx, &p_cuser->rx);
4002 if (ret_val) 4037 if (ret_val)
4003 return ret_val; 4038 break;
4004 ret_val = put_user(cnow.tx, &p_cuser->tx); 4039 ret_val = put_user(cnow.tx, &p_cuser->tx);
4005 if (ret_val) 4040 if (ret_val)
4006 return ret_val; 4041 break;
4007 ret_val = put_user(cnow.frame, &p_cuser->frame); 4042 ret_val = put_user(cnow.frame, &p_cuser->frame);
4008 if (ret_val) 4043 if (ret_val)
4009 return ret_val; 4044 break;
4010 ret_val = put_user(cnow.overrun, &p_cuser->overrun); 4045 ret_val = put_user(cnow.overrun, &p_cuser->overrun);
4011 if (ret_val) 4046 if (ret_val)
4012 return ret_val; 4047 break;
4013 ret_val = put_user(cnow.parity, &p_cuser->parity); 4048 ret_val = put_user(cnow.parity, &p_cuser->parity);
4014 if (ret_val) 4049 if (ret_val)
4015 return ret_val; 4050 break;
4016 ret_val = put_user(cnow.brk, &p_cuser->brk); 4051 ret_val = put_user(cnow.brk, &p_cuser->brk);
4017 if (ret_val) 4052 if (ret_val)
4018 return ret_val; 4053 break;
4019 ret_val = put_user(cnow.buf_overrun, &p_cuser->buf_overrun); 4054 ret_val = put_user(cnow.buf_overrun, &p_cuser->buf_overrun);
4020 if (ret_val) 4055 if (ret_val)
4021 return ret_val; 4056 break;
4022 ret_val = 0; 4057 ret_val = 0;
4023 break; 4058 break;
4024 default: 4059 default:
4025 ret_val = -ENOIOCTLCMD; 4060 ret_val = -ENOIOCTLCMD;
4026 } 4061 }
4062 unlock_kernel();
4027 4063
4028#ifdef CY_DEBUG_OTHER 4064#ifdef CY_DEBUG_OTHER
4029 printk(KERN_DEBUG "cyc:cy_ioctl done\n"); 4065 printk(KERN_DEBUG "cyc:cy_ioctl done\n");
4030#endif 4066#endif
4031
4032 return ret_val; 4067 return ret_val;
4033} /* cy_ioctl */ 4068} /* cy_ioctl */
4034 4069
@@ -4113,9 +4148,8 @@ static void cy_throttle(struct tty_struct *tty)
4113 tty->ldisc.chars_in_buffer(tty), info->line); 4148 tty->ldisc.chars_in_buffer(tty), info->line);
4114#endif 4149#endif
4115 4150
4116 if (serial_paranoia_check(info, tty->name, "cy_throttle")) { 4151 if (serial_paranoia_check(info, tty->name, "cy_throttle"))
4117 return; 4152 return;
4118 }
4119 4153
4120 card = info->card; 4154 card = info->card;
4121 4155
@@ -4169,12 +4203,11 @@ static void cy_unthrottle(struct tty_struct *tty)
4169 char buf[64]; 4203 char buf[64];
4170 4204
4171 printk(KERN_DEBUG "cyc:unthrottle %s: %ld...ttyC%d\n", 4205 printk(KERN_DEBUG "cyc:unthrottle %s: %ld...ttyC%d\n",
4172 tty_name(tty, buf), tty->ldisc.chars_in_buffer(tty),info->line); 4206 tty_name(tty, buf), tty_chars_in_buffer(tty), info->line);
4173#endif 4207#endif
4174 4208
4175 if (serial_paranoia_check(info, tty->name, "cy_unthrottle")) { 4209 if (serial_paranoia_check(info, tty->name, "cy_unthrottle"))
4176 return; 4210 return;
4177 }
4178 4211
4179 if (I_IXOFF(tty)) { 4212 if (I_IXOFF(tty)) {
4180 if (info->x_char) 4213 if (info->x_char)
@@ -4269,47 +4302,14 @@ static void cy_start(struct tty_struct *tty)
4269 base_addr = cinfo->base_addr + (cy_chip_offset[chip] << index); 4302 base_addr = cinfo->base_addr + (cy_chip_offset[chip] << index);
4270 4303
4271 spin_lock_irqsave(&cinfo->card_lock, flags); 4304 spin_lock_irqsave(&cinfo->card_lock, flags);
4272 cy_writeb(base_addr + (CyCAR << index), (u_char) (channel & 0x0003)); /* index channel */ 4305 cy_writeb(base_addr + (CyCAR << index),
4306 (u_char) (channel & 0x0003)); /* index channel */
4273 cy_writeb(base_addr + (CySRER << index), 4307 cy_writeb(base_addr + (CySRER << index),
4274 readb(base_addr + (CySRER << index)) | CyTxRdy); 4308 readb(base_addr + (CySRER << index)) | CyTxRdy);
4275 spin_unlock_irqrestore(&cinfo->card_lock, flags); 4309 spin_unlock_irqrestore(&cinfo->card_lock, flags);
4276 } 4310 }
4277} /* cy_start */ 4311} /* cy_start */
4278 4312
4279static void cy_flush_buffer(struct tty_struct *tty)
4280{
4281 struct cyclades_port *info = tty->driver_data;
4282 struct cyclades_card *card;
4283 int channel, retval;
4284 unsigned long flags;
4285
4286#ifdef CY_DEBUG_IO
4287 printk(KERN_DEBUG "cyc:cy_flush_buffer ttyC%d\n", info->line);
4288#endif
4289
4290 if (serial_paranoia_check(info, tty->name, "cy_flush_buffer"))
4291 return;
4292
4293 card = info->card;
4294 channel = info->line - card->first_line;
4295
4296 spin_lock_irqsave(&card->card_lock, flags);
4297 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
4298 spin_unlock_irqrestore(&card->card_lock, flags);
4299
4300 if (IS_CYC_Z(*card)) { /* If it is a Z card, flush the on-board
4301 buffers as well */
4302 spin_lock_irqsave(&card->card_lock, flags);
4303 retval = cyz_issue_cmd(card, channel, C_CM_FLUSH_TX, 0L);
4304 if (retval != 0) {
4305 printk(KERN_ERR "cyc: flush_buffer retval on ttyC%d "
4306 "was %x\n", info->line, retval);
4307 }
4308 spin_unlock_irqrestore(&card->card_lock, flags);
4309 }
4310 tty_wakeup(tty);
4311} /* cy_flush_buffer */
4312
4313/* 4313/*
4314 * cy_hangup() --- called by tty_hangup() when a hangup is signaled. 4314 * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
4315 */ 4315 */
@@ -4406,10 +4406,11 @@ static int __devinit cy_init_card(struct cyclades_card *cinfo)
4406 info->cor3 = 0x08; /* _very_ small rcv threshold */ 4406 info->cor3 = 0x08; /* _very_ small rcv threshold */
4407 4407
4408 chip_number = (port - cinfo->first_line) / 4; 4408 chip_number = (port - cinfo->first_line) / 4;
4409 if ((info->chip_rev = readb(cinfo->base_addr + 4409 info->chip_rev = readb(cinfo->base_addr +
4410 (cy_chip_offset[chip_number] << 4410 (cy_chip_offset[chip_number] << index) +
4411 index) + (CyGFRCR << index))) >= 4411 (CyGFRCR << index));
4412 CD1400_REV_J) { 4412
4413 if (info->chip_rev >= CD1400_REV_J) {
4413 /* It is a CD1400 rev. J or later */ 4414 /* It is a CD1400 rev. J or later */
4414 info->tbpr = baud_bpr_60[13]; /* Tx BPR */ 4415 info->tbpr = baud_bpr_60[13]; /* Tx BPR */
4415 info->tco = baud_co_60[13]; /* Tx CO */ 4416 info->tco = baud_co_60[13]; /* Tx CO */
@@ -4454,7 +4455,8 @@ static unsigned short __devinit cyy_init_card(void __iomem *true_base_addr,
4454 /* Cy_ClrIntr is 0x1800 */ 4455 /* Cy_ClrIntr is 0x1800 */
4455 udelay(500L); 4456 udelay(500L);
4456 4457
4457 for (chip_number = 0; chip_number < CyMAX_CHIPS_PER_CARD; chip_number++) { 4458 for (chip_number = 0; chip_number < CyMAX_CHIPS_PER_CARD;
4459 chip_number++) {
4458 base_addr = 4460 base_addr =
4459 true_base_addr + (cy_chip_offset[chip_number] << index); 4461 true_base_addr + (cy_chip_offset[chip_number] << index);
4460 mdelay(1); 4462 mdelay(1);
@@ -4555,12 +4557,11 @@ static int __init cy_detect_isa(void)
4555 /* scan the address table probing for Cyclom-Y/ISA boards */ 4557 /* scan the address table probing for Cyclom-Y/ISA boards */
4556 for (i = 0; i < NR_ISA_ADDRS; i++) { 4558 for (i = 0; i < NR_ISA_ADDRS; i++) {
4557 unsigned int isa_address = cy_isa_addresses[i]; 4559 unsigned int isa_address = cy_isa_addresses[i];
4558 if (isa_address == 0x0000) { 4560 if (isa_address == 0x0000)
4559 return nboard; 4561 return nboard;
4560 }
4561 4562
4562 /* probe for CD1400... */ 4563 /* probe for CD1400... */
4563 cy_isa_address = ioremap(isa_address, CyISA_Ywin); 4564 cy_isa_address = ioremap_nocache(isa_address, CyISA_Ywin);
4564 if (cy_isa_address == NULL) { 4565 if (cy_isa_address == NULL) {
4565 printk(KERN_ERR "Cyclom-Y/ISA: can't remap base " 4566 printk(KERN_ERR "Cyclom-Y/ISA: can't remap base "
4566 "address\n"); 4567 "address\n");
@@ -4847,12 +4848,10 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr,
4847 if (mailbox != 0) { 4848 if (mailbox != 0) {
4848 /* set window to last 512K of RAM */ 4849 /* set window to last 512K of RAM */
4849 cy_writel(&ctl_addr->loc_addr_base, WIN_RAM + RAM_SIZE); 4850 cy_writel(&ctl_addr->loc_addr_base, WIN_RAM + RAM_SIZE);
4850 //sleep(1);
4851 for (tmp = base_addr; tmp < base_addr + RAM_SIZE; tmp++) 4851 for (tmp = base_addr; tmp < base_addr + RAM_SIZE; tmp++)
4852 cy_writeb(tmp, 255); 4852 cy_writeb(tmp, 255);
4853 /* set window to beginning of RAM */ 4853 /* set window to beginning of RAM */
4854 cy_writel(&ctl_addr->loc_addr_base, WIN_RAM); 4854 cy_writel(&ctl_addr->loc_addr_base, WIN_RAM);
4855 //sleep(1);
4856 } 4855 }
4857 4856
4858 retval = __cyz_load_fw(fw, "Cyclom-Z", mailbox, base_addr, NULL); 4857 retval = __cyz_load_fw(fw, "Cyclom-Z", mailbox, base_addr, NULL);
@@ -5382,7 +5381,8 @@ static void __exit cy_cleanup_module(void)
5382 del_timer_sync(&cyz_timerlist); 5381 del_timer_sync(&cyz_timerlist);
5383#endif /* CONFIG_CYZ_INTR */ 5382#endif /* CONFIG_CYZ_INTR */
5384 5383
5385 if ((e1 = tty_unregister_driver(cy_serial_driver))) 5384 e1 = tty_unregister_driver(cy_serial_driver);
5385 if (e1)
5386 printk(KERN_ERR "failed to unregister Cyclades serial " 5386 printk(KERN_ERR "failed to unregister Cyclades serial "
5387 "driver(%d)\n", e1); 5387 "driver(%d)\n", e1);
5388 5388
diff --git a/drivers/char/drm/drmP.h b/drivers/char/drm/drmP.h
index ecee3547a13f..213b3ca3468e 100644
--- a/drivers/char/drm/drmP.h
+++ b/drivers/char/drm/drmP.h
@@ -160,7 +160,7 @@ struct drm_device;
160 * \param arg arguments 160 * \param arg arguments
161 */ 161 */
162#define DRM_ERROR(fmt, arg...) \ 162#define DRM_ERROR(fmt, arg...) \
163 printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __FUNCTION__ , ##arg) 163 printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* " fmt , __func__ , ##arg)
164 164
165/** 165/**
166 * Memory error output. 166 * Memory error output.
@@ -170,7 +170,7 @@ struct drm_device;
170 * \param arg arguments 170 * \param arg arguments
171 */ 171 */
172#define DRM_MEM_ERROR(area, fmt, arg...) \ 172#define DRM_MEM_ERROR(area, fmt, arg...) \
173 printk(KERN_ERR "[" DRM_NAME ":%s:%s] *ERROR* " fmt , __FUNCTION__, \ 173 printk(KERN_ERR "[" DRM_NAME ":%s:%s] *ERROR* " fmt , __func__, \
174 drm_mem_stats[area].name , ##arg) 174 drm_mem_stats[area].name , ##arg)
175 175
176#define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg) 176#define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg)
@@ -187,7 +187,7 @@ struct drm_device;
187 if ( drm_debug ) \ 187 if ( drm_debug ) \
188 printk(KERN_DEBUG \ 188 printk(KERN_DEBUG \
189 "[" DRM_NAME ":%s] " fmt , \ 189 "[" DRM_NAME ":%s] " fmt , \
190 __FUNCTION__ , ##arg); \ 190 __func__ , ##arg); \
191 } while (0) 191 } while (0)
192#else 192#else
193#define DRM_DEBUG(fmt, arg...) do { } while (0) 193#define DRM_DEBUG(fmt, arg...) do { } while (0)
@@ -238,7 +238,7 @@ do { \
238 if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) || \ 238 if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) || \
239 dev->lock.file_priv != file_priv ) { \ 239 dev->lock.file_priv != file_priv ) { \
240 DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\ 240 DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\
241 __FUNCTION__, _DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ),\ 241 __func__, _DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ),\
242 dev->lock.file_priv, file_priv ); \ 242 dev->lock.file_priv, file_priv ); \
243 return -EINVAL; \ 243 return -EINVAL; \
244 } \ 244 } \
diff --git a/drivers/char/drm/drm_sysfs.c b/drivers/char/drm/drm_sysfs.c
index 7a1d9a782ddb..9a32169e88fb 100644
--- a/drivers/char/drm/drm_sysfs.c
+++ b/drivers/char/drm/drm_sysfs.c
@@ -34,7 +34,7 @@ static int drm_sysfs_suspend(struct device *dev, pm_message_t state)
34 struct drm_minor *drm_minor = to_drm_minor(dev); 34 struct drm_minor *drm_minor = to_drm_minor(dev);
35 struct drm_device *drm_dev = drm_minor->dev; 35 struct drm_device *drm_dev = drm_minor->dev;
36 36
37 printk(KERN_ERR "%s\n", __FUNCTION__); 37 printk(KERN_ERR "%s\n", __func__);
38 38
39 if (drm_dev->driver->suspend) 39 if (drm_dev->driver->suspend)
40 return drm_dev->driver->suspend(drm_dev, state); 40 return drm_dev->driver->suspend(drm_dev, state);
diff --git a/drivers/char/drm/i830_dma.c b/drivers/char/drm/i830_dma.c
index 60c9376be486..a86ab30b4620 100644
--- a/drivers/char/drm/i830_dma.c
+++ b/drivers/char/drm/i830_dma.c
@@ -692,7 +692,7 @@ static void i830EmitState(struct drm_device * dev)
692 drm_i830_sarea_t *sarea_priv = dev_priv->sarea_priv; 692 drm_i830_sarea_t *sarea_priv = dev_priv->sarea_priv;
693 unsigned int dirty = sarea_priv->dirty; 693 unsigned int dirty = sarea_priv->dirty;
694 694
695 DRM_DEBUG("%s %x\n", __FUNCTION__, dirty); 695 DRM_DEBUG("%s %x\n", __func__, dirty);
696 696
697 if (dirty & I830_UPLOAD_BUFFERS) { 697 if (dirty & I830_UPLOAD_BUFFERS) {
698 i830EmitDestVerified(dev, sarea_priv->BufferState); 698 i830EmitDestVerified(dev, sarea_priv->BufferState);
@@ -1043,7 +1043,7 @@ static void i830_dma_dispatch_flip(struct drm_device * dev)
1043 RING_LOCALS; 1043 RING_LOCALS;
1044 1044
1045 DRM_DEBUG("%s: page=%d pfCurrentPage=%d\n", 1045 DRM_DEBUG("%s: page=%d pfCurrentPage=%d\n",
1046 __FUNCTION__, 1046 __func__,
1047 dev_priv->current_page, 1047 dev_priv->current_page,
1048 dev_priv->sarea_priv->pf_current_page); 1048 dev_priv->sarea_priv->pf_current_page);
1049 1049
@@ -1206,7 +1206,7 @@ static void i830_dma_quiescent(struct drm_device * dev)
1206 OUT_RING(0); 1206 OUT_RING(0);
1207 ADVANCE_LP_RING(); 1207 ADVANCE_LP_RING();
1208 1208
1209 i830_wait_ring(dev, dev_priv->ring.Size - 8, __FUNCTION__); 1209 i830_wait_ring(dev, dev_priv->ring.Size - 8, __func__);
1210} 1210}
1211 1211
1212static int i830_flush_queue(struct drm_device * dev) 1212static int i830_flush_queue(struct drm_device * dev)
@@ -1223,7 +1223,7 @@ static int i830_flush_queue(struct drm_device * dev)
1223 OUT_RING(0); 1223 OUT_RING(0);
1224 ADVANCE_LP_RING(); 1224 ADVANCE_LP_RING();
1225 1225
1226 i830_wait_ring(dev, dev_priv->ring.Size - 8, __FUNCTION__); 1226 i830_wait_ring(dev, dev_priv->ring.Size - 8, __func__);
1227 1227
1228 for (i = 0; i < dma->buf_count; i++) { 1228 for (i = 0; i < dma->buf_count; i++) {
1229 struct drm_buf *buf = dma->buflist[i]; 1229 struct drm_buf *buf = dma->buflist[i];
@@ -1344,7 +1344,7 @@ static void i830_do_init_pageflip(struct drm_device * dev)
1344{ 1344{
1345 drm_i830_private_t *dev_priv = dev->dev_private; 1345 drm_i830_private_t *dev_priv = dev->dev_private;
1346 1346
1347 DRM_DEBUG("%s\n", __FUNCTION__); 1347 DRM_DEBUG("%s\n", __func__);
1348 dev_priv->page_flipping = 1; 1348 dev_priv->page_flipping = 1;
1349 dev_priv->current_page = 0; 1349 dev_priv->current_page = 0;
1350 dev_priv->sarea_priv->pf_current_page = dev_priv->current_page; 1350 dev_priv->sarea_priv->pf_current_page = dev_priv->current_page;
@@ -1354,7 +1354,7 @@ static int i830_do_cleanup_pageflip(struct drm_device * dev)
1354{ 1354{
1355 drm_i830_private_t *dev_priv = dev->dev_private; 1355 drm_i830_private_t *dev_priv = dev->dev_private;
1356 1356
1357 DRM_DEBUG("%s\n", __FUNCTION__); 1357 DRM_DEBUG("%s\n", __func__);
1358 if (dev_priv->current_page != 0) 1358 if (dev_priv->current_page != 0)
1359 i830_dma_dispatch_flip(dev); 1359 i830_dma_dispatch_flip(dev);
1360 1360
@@ -1367,7 +1367,7 @@ static int i830_flip_bufs(struct drm_device *dev, void *data,
1367{ 1367{
1368 drm_i830_private_t *dev_priv = dev->dev_private; 1368 drm_i830_private_t *dev_priv = dev->dev_private;
1369 1369
1370 DRM_DEBUG("%s\n", __FUNCTION__); 1370 DRM_DEBUG("%s\n", __func__);
1371 1371
1372 LOCK_TEST_WITH_RETURN(dev, file_priv); 1372 LOCK_TEST_WITH_RETURN(dev, file_priv);
1373 1373
@@ -1437,7 +1437,7 @@ static int i830_getparam(struct drm_device *dev, void *data,
1437 int value; 1437 int value;
1438 1438
1439 if (!dev_priv) { 1439 if (!dev_priv) {
1440 DRM_ERROR("%s called with no initialization\n", __FUNCTION__); 1440 DRM_ERROR("%s called with no initialization\n", __func__);
1441 return -EINVAL; 1441 return -EINVAL;
1442 } 1442 }
1443 1443
@@ -1464,7 +1464,7 @@ static int i830_setparam(struct drm_device *dev, void *data,
1464 drm_i830_setparam_t *param = data; 1464 drm_i830_setparam_t *param = data;
1465 1465
1466 if (!dev_priv) { 1466 if (!dev_priv) {
1467 DRM_ERROR("%s called with no initialization\n", __FUNCTION__); 1467 DRM_ERROR("%s called with no initialization\n", __func__);
1468 return -EINVAL; 1468 return -EINVAL;
1469 } 1469 }
1470 1470
diff --git a/drivers/char/drm/i830_drv.h b/drivers/char/drm/i830_drv.h
index 4caba8c54455..b5bf8cc0fdaa 100644
--- a/drivers/char/drm/i830_drv.h
+++ b/drivers/char/drm/i830_drv.h
@@ -158,7 +158,7 @@ extern int i830_driver_device_is_agp(struct drm_device * dev);
158 if (I830_VERBOSE) \ 158 if (I830_VERBOSE) \
159 printk("BEGIN_LP_RING(%d)\n", (n)); \ 159 printk("BEGIN_LP_RING(%d)\n", (n)); \
160 if (dev_priv->ring.space < n*4) \ 160 if (dev_priv->ring.space < n*4) \
161 i830_wait_ring(dev, n*4, __FUNCTION__); \ 161 i830_wait_ring(dev, n*4, __func__); \
162 outcount = 0; \ 162 outcount = 0; \
163 outring = dev_priv->ring.tail; \ 163 outring = dev_priv->ring.tail; \
164 ringmask = dev_priv->ring.tail_mask; \ 164 ringmask = dev_priv->ring.tail_mask; \
diff --git a/drivers/char/drm/i830_irq.c b/drivers/char/drm/i830_irq.c
index a33db5f0967f..91ec2bb497e9 100644
--- a/drivers/char/drm/i830_irq.c
+++ b/drivers/char/drm/i830_irq.c
@@ -58,7 +58,7 @@ static int i830_emit_irq(struct drm_device * dev)
58 drm_i830_private_t *dev_priv = dev->dev_private; 58 drm_i830_private_t *dev_priv = dev->dev_private;
59 RING_LOCALS; 59 RING_LOCALS;
60 60
61 DRM_DEBUG("%s\n", __FUNCTION__); 61 DRM_DEBUG("%s\n", __func__);
62 62
63 atomic_inc(&dev_priv->irq_emitted); 63 atomic_inc(&dev_priv->irq_emitted);
64 64
@@ -77,7 +77,7 @@ static int i830_wait_irq(struct drm_device * dev, int irq_nr)
77 unsigned long end = jiffies + HZ * 3; 77 unsigned long end = jiffies + HZ * 3;
78 int ret = 0; 78 int ret = 0;
79 79
80 DRM_DEBUG("%s\n", __FUNCTION__); 80 DRM_DEBUG("%s\n", __func__);
81 81
82 if (atomic_read(&dev_priv->irq_received) >= irq_nr) 82 if (atomic_read(&dev_priv->irq_received) >= irq_nr)
83 return 0; 83 return 0;
@@ -124,7 +124,7 @@ int i830_irq_emit(struct drm_device *dev, void *data,
124 LOCK_TEST_WITH_RETURN(dev, file_priv); 124 LOCK_TEST_WITH_RETURN(dev, file_priv);
125 125
126 if (!dev_priv) { 126 if (!dev_priv) {
127 DRM_ERROR("%s called with no initialization\n", __FUNCTION__); 127 DRM_ERROR("%s called with no initialization\n", __func__);
128 return -EINVAL; 128 return -EINVAL;
129 } 129 }
130 130
@@ -147,7 +147,7 @@ int i830_irq_wait(struct drm_device *dev, void *data,
147 drm_i830_irq_wait_t *irqwait = data; 147 drm_i830_irq_wait_t *irqwait = data;
148 148
149 if (!dev_priv) { 149 if (!dev_priv) {
150 DRM_ERROR("%s called with no initialization\n", __FUNCTION__); 150 DRM_ERROR("%s called with no initialization\n", __func__);
151 return -EINVAL; 151 return -EINVAL;
152 } 152 }
153 153
diff --git a/drivers/char/drm/i915_dma.c b/drivers/char/drm/i915_dma.c
index ef7bf143a80c..f47e46e3529f 100644
--- a/drivers/char/drm/i915_dma.c
+++ b/drivers/char/drm/i915_dma.c
@@ -194,7 +194,7 @@ static int i915_dma_resume(struct drm_device * dev)
194{ 194{
195 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 195 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
196 196
197 DRM_DEBUG("%s\n", __FUNCTION__); 197 DRM_DEBUG("%s\n", __func__);
198 198
199 if (!dev_priv->sarea) { 199 if (!dev_priv->sarea) {
200 DRM_ERROR("can not find sarea!\n"); 200 DRM_ERROR("can not find sarea!\n");
@@ -609,7 +609,7 @@ static int i915_quiescent(struct drm_device * dev)
609 drm_i915_private_t *dev_priv = dev->dev_private; 609 drm_i915_private_t *dev_priv = dev->dev_private;
610 610
611 i915_kernel_lost_context(dev); 611 i915_kernel_lost_context(dev);
612 return i915_wait_ring(dev, dev_priv->ring.Size - 8, __FUNCTION__); 612 return i915_wait_ring(dev, dev_priv->ring.Size - 8, __func__);
613} 613}
614 614
615static int i915_flush_ioctl(struct drm_device *dev, void *data, 615static int i915_flush_ioctl(struct drm_device *dev, void *data,
diff --git a/drivers/char/drm/i915_drv.h b/drivers/char/drm/i915_drv.h
index c614d78b3dfd..db7001f22561 100644
--- a/drivers/char/drm/i915_drv.h
+++ b/drivers/char/drm/i915_drv.h
@@ -272,7 +272,7 @@ extern void i915_mem_release(struct drm_device * dev,
272 if (I915_VERBOSE) \ 272 if (I915_VERBOSE) \
273 DRM_DEBUG("BEGIN_LP_RING(%d)\n", (n)); \ 273 DRM_DEBUG("BEGIN_LP_RING(%d)\n", (n)); \
274 if (dev_priv->ring.space < (n)*4) \ 274 if (dev_priv->ring.space < (n)*4) \
275 i915_wait_ring(dev, (n)*4, __FUNCTION__); \ 275 i915_wait_ring(dev, (n)*4, __func__); \
276 outcount = 0; \ 276 outcount = 0; \
277 outring = dev_priv->ring.tail; \ 277 outring = dev_priv->ring.tail; \
278 ringmask = dev_priv->ring.tail_mask; \ 278 ringmask = dev_priv->ring.tail_mask; \
diff --git a/drivers/char/drm/radeon_cp.c b/drivers/char/drm/radeon_cp.c
index 9072e4a1894e..f6f6c92bf771 100644
--- a/drivers/char/drm/radeon_cp.c
+++ b/drivers/char/drm/radeon_cp.c
@@ -894,7 +894,7 @@ static u32 RADEON_READ_IGPGART(drm_radeon_private_t *dev_priv, int addr)
894#if RADEON_FIFO_DEBUG 894#if RADEON_FIFO_DEBUG
895static void radeon_status(drm_radeon_private_t * dev_priv) 895static void radeon_status(drm_radeon_private_t * dev_priv)
896{ 896{
897 printk("%s:\n", __FUNCTION__); 897 printk("%s:\n", __func__);
898 printk("RBBM_STATUS = 0x%08x\n", 898 printk("RBBM_STATUS = 0x%08x\n",
899 (unsigned int)RADEON_READ(RADEON_RBBM_STATUS)); 899 (unsigned int)RADEON_READ(RADEON_RBBM_STATUS));
900 printk("CP_RB_RTPR = 0x%08x\n", 900 printk("CP_RB_RTPR = 0x%08x\n",
diff --git a/drivers/char/ds1286.c b/drivers/char/ds1286.c
index 59146e3365ba..ea35ab2c9909 100644
--- a/drivers/char/ds1286.c
+++ b/drivers/char/ds1286.c
@@ -39,6 +39,7 @@
39#include <linux/spinlock.h> 39#include <linux/spinlock.h>
40#include <linux/bcd.h> 40#include <linux/bcd.h>
41#include <linux/proc_fs.h> 41#include <linux/proc_fs.h>
42#include <linux/jiffies.h>
42 43
43#include <asm/uaccess.h> 44#include <asm/uaccess.h>
44#include <asm/system.h> 45#include <asm/system.h>
@@ -451,7 +452,7 @@ static void ds1286_get_time(struct rtc_time *rtc_tm)
451 */ 452 */
452 453
453 if (ds1286_is_updating() != 0) 454 if (ds1286_is_updating() != 0)
454 while (jiffies - uip_watchdog < 2*HZ/100) 455 while (time_before(jiffies, uip_watchdog + 2*HZ/100))
455 barrier(); 456 barrier();
456 457
457 /* 458 /*
diff --git a/drivers/char/epca.c b/drivers/char/epca.c
index ffd747c5dff0..60a4df7dac12 100644
--- a/drivers/char/epca.c
+++ b/drivers/char/epca.c
@@ -38,8 +38,8 @@
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/ioport.h> 39#include <linux/ioport.h>
40#include <linux/interrupt.h> 40#include <linux/interrupt.h>
41#include <asm/uaccess.h> 41#include <linux/uaccess.h>
42#include <asm/io.h> 42#include <linux/io.h>
43#include <linux/spinlock.h> 43#include <linux/spinlock.h>
44#include <linux/pci.h> 44#include <linux/pci.h>
45#include "digiPCI.h" 45#include "digiPCI.h"
@@ -73,7 +73,8 @@ static int invalid_lilo_config;
73 */ 73 */
74static DEFINE_SPINLOCK(epca_lock); 74static DEFINE_SPINLOCK(epca_lock);
75 75
76/* MAXBOARDS is typically 12, but ISA and EISA cards are restricted to 7 below. */ 76/* MAXBOARDS is typically 12, but ISA and EISA cards are restricted
77 to 7 below. */
77static struct board_info boards[MAXBOARDS]; 78static struct board_info boards[MAXBOARDS];
78 79
79static struct tty_driver *pc_driver; 80static struct tty_driver *pc_driver;
@@ -157,13 +158,12 @@ static void epca_error(int, char *);
157static void pc_close(struct tty_struct *, struct file *); 158static void pc_close(struct tty_struct *, struct file *);
158static void shutdown(struct channel *); 159static void shutdown(struct channel *);
159static void pc_hangup(struct tty_struct *); 160static void pc_hangup(struct tty_struct *);
160static void pc_put_char(struct tty_struct *, unsigned char);
161static int pc_write_room(struct tty_struct *); 161static int pc_write_room(struct tty_struct *);
162static int pc_chars_in_buffer(struct tty_struct *); 162static int pc_chars_in_buffer(struct tty_struct *);
163static void pc_flush_buffer(struct tty_struct *); 163static void pc_flush_buffer(struct tty_struct *);
164static void pc_flush_chars(struct tty_struct *); 164static void pc_flush_chars(struct tty_struct *);
165static int block_til_ready(struct tty_struct *, struct file *, 165static int block_til_ready(struct tty_struct *, struct file *,
166 struct channel *); 166 struct channel *);
167static int pc_open(struct tty_struct *, struct file *); 167static int pc_open(struct tty_struct *, struct file *);
168static void post_fep_init(unsigned int crd); 168static void post_fep_init(unsigned int crd);
169static void epcapoll(unsigned long); 169static void epcapoll(unsigned long);
@@ -175,18 +175,18 @@ static unsigned termios2digi_c(struct channel *ch, unsigned);
175static void epcaparam(struct tty_struct *, struct channel *); 175static void epcaparam(struct tty_struct *, struct channel *);
176static void receive_data(struct channel *); 176static void receive_data(struct channel *);
177static int pc_ioctl(struct tty_struct *, struct file *, 177static int pc_ioctl(struct tty_struct *, struct file *,
178 unsigned int, unsigned long); 178 unsigned int, unsigned long);
179static int info_ioctl(struct tty_struct *, struct file *, 179static int info_ioctl(struct tty_struct *, struct file *,
180 unsigned int, unsigned long); 180 unsigned int, unsigned long);
181static void pc_set_termios(struct tty_struct *, struct ktermios *); 181static void pc_set_termios(struct tty_struct *, struct ktermios *);
182static void do_softint(struct work_struct *work); 182static void do_softint(struct work_struct *work);
183static void pc_stop(struct tty_struct *); 183static void pc_stop(struct tty_struct *);
184static void pc_start(struct tty_struct *); 184static void pc_start(struct tty_struct *);
185static void pc_throttle(struct tty_struct * tty); 185static void pc_throttle(struct tty_struct *tty);
186static void pc_unthrottle(struct tty_struct *tty); 186static void pc_unthrottle(struct tty_struct *tty);
187static void digi_send_break(struct channel *ch, int msec); 187static void digi_send_break(struct channel *ch, int msec);
188static void setup_empty_event(struct tty_struct *tty, struct channel *ch); 188static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
189void epca_setup(char *, int *); 189static void epca_setup(char *, int *);
190 190
191static int pc_write(struct tty_struct *, const unsigned char *, int); 191static int pc_write(struct tty_struct *, const unsigned char *, int);
192static int pc_init(void); 192static int pc_init(void);
@@ -243,7 +243,7 @@ static void assertmemoff(struct channel *ch)
243/* PCXEM windowing is the same as that used in the PCXR and CX series cards. */ 243/* PCXEM windowing is the same as that used in the PCXR and CX series cards. */
244static void pcxem_memwinon(struct board_info *b, unsigned int win) 244static void pcxem_memwinon(struct board_info *b, unsigned int win)
245{ 245{
246 outb_p(FEPWIN|win, b->port + 1); 246 outb_p(FEPWIN | win, b->port + 1);
247} 247}
248 248
249static void pcxem_memwinoff(struct board_info *b, unsigned int win) 249static void pcxem_memwinoff(struct board_info *b, unsigned int win)
@@ -253,7 +253,7 @@ static void pcxem_memwinoff(struct board_info *b, unsigned int win)
253 253
254static void pcxem_globalwinon(struct channel *ch) 254static void pcxem_globalwinon(struct channel *ch)
255{ 255{
256 outb_p( FEPWIN, (int)ch->board->port + 1); 256 outb_p(FEPWIN, (int)ch->board->port + 1);
257} 257}
258 258
259static void pcxem_rxwinon(struct channel *ch) 259static void pcxem_rxwinon(struct channel *ch)
@@ -394,7 +394,7 @@ static struct channel *verifyChannel(struct tty_struct *tty)
394 */ 394 */
395 if (tty) { 395 if (tty) {
396 struct channel *ch = (struct channel *)tty->driver_data; 396 struct channel *ch = (struct channel *)tty->driver_data;
397 if ((ch >= &digi_channels[0]) && (ch < &digi_channels[nbdevs])) { 397 if (ch >= &digi_channels[0] && ch < &digi_channels[nbdevs]) {
398 if (ch->magic == EPCA_MAGIC) 398 if (ch->magic == EPCA_MAGIC)
399 return ch; 399 return ch;
400 } 400 }
@@ -414,7 +414,7 @@ static void pc_sched_event(struct channel *ch, int event)
414 414
415static void epca_error(int line, char *msg) 415static void epca_error(int line, char *msg)
416{ 416{
417 printk(KERN_ERR "epca_error (Digi): line = %d %s\n",line,msg); 417 printk(KERN_ERR "epca_error (Digi): line = %d %s\n", line, msg);
418} 418}
419 419
420static void pc_close(struct tty_struct *tty, struct file *filp) 420static void pc_close(struct tty_struct *tty, struct file *filp)
@@ -425,7 +425,8 @@ static void pc_close(struct tty_struct *tty, struct file *filp)
425 * verifyChannel returns the channel from the tty struct if it is 425 * verifyChannel returns the channel from the tty struct if it is
426 * valid. This serves as a sanity check. 426 * valid. This serves as a sanity check.
427 */ 427 */
428 if ((ch = verifyChannel(tty)) != NULL) { 428 ch = verifyChannel(tty);
429 if (ch != NULL) {
429 spin_lock_irqsave(&epca_lock, flags); 430 spin_lock_irqsave(&epca_lock, flags);
430 if (tty_hung_up_p(filp)) { 431 if (tty_hung_up_p(filp)) {
431 spin_unlock_irqrestore(&epca_lock, flags); 432 spin_unlock_irqrestore(&epca_lock, flags);
@@ -440,7 +441,6 @@ static void pc_close(struct tty_struct *tty, struct file *filp)
440 spin_unlock_irqrestore(&epca_lock, flags); 441 spin_unlock_irqrestore(&epca_lock, flags);
441 return; 442 return;
442 } 443 }
443
444 /* Port open only once go ahead with shutdown & reset */ 444 /* Port open only once go ahead with shutdown & reset */
445 BUG_ON(ch->count < 0); 445 BUG_ON(ch->count < 0);
446 446
@@ -455,12 +455,13 @@ static void pc_close(struct tty_struct *tty, struct file *filp)
455 spin_unlock_irqrestore(&epca_lock, flags); 455 spin_unlock_irqrestore(&epca_lock, flags);
456 456
457 if (ch->asyncflags & ASYNC_INITIALIZED) { 457 if (ch->asyncflags & ASYNC_INITIALIZED) {
458 /* Setup an event to indicate when the transmit buffer empties */ 458 /* Setup an event to indicate when the
459 transmit buffer empties */
459 setup_empty_event(tty, ch); 460 setup_empty_event(tty, ch);
460 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */ 461 /* 30 seconds timeout */
462 tty_wait_until_sent(tty, 3000);
461 } 463 }
462 if (tty->driver->flush_buffer) 464 pc_flush_buffer(tty);
463 tty->driver->flush_buffer(tty);
464 465
465 tty_ldisc_flush(tty); 466 tty_ldisc_flush(tty);
466 shutdown(ch); 467 shutdown(ch);
@@ -477,7 +478,7 @@ static void pc_close(struct tty_struct *tty, struct file *filp)
477 wake_up_interruptible(&ch->open_wait); 478 wake_up_interruptible(&ch->open_wait);
478 } 479 }
479 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED | 480 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
480 ASYNC_CLOSING); 481 ASYNC_CLOSING);
481 wake_up_interruptible(&ch->close_wait); 482 wake_up_interruptible(&ch->close_wait);
482 } 483 }
483} 484}
@@ -524,16 +525,15 @@ static void shutdown(struct channel *ch)
524static void pc_hangup(struct tty_struct *tty) 525static void pc_hangup(struct tty_struct *tty)
525{ 526{
526 struct channel *ch; 527 struct channel *ch;
527
528 /* 528 /*
529 * verifyChannel returns the channel from the tty struct if it is 529 * verifyChannel returns the channel from the tty struct if it is
530 * valid. This serves as a sanity check. 530 * valid. This serves as a sanity check.
531 */ 531 */
532 if ((ch = verifyChannel(tty)) != NULL) { 532 ch = verifyChannel(tty);
533 if (ch != NULL) {
533 unsigned long flags; 534 unsigned long flags;
534 535
535 if (tty->driver->flush_buffer) 536 pc_flush_buffer(tty);
536 tty->driver->flush_buffer(tty);
537 tty_ldisc_flush(tty); 537 tty_ldisc_flush(tty);
538 shutdown(ch); 538 shutdown(ch);
539 539
@@ -548,7 +548,7 @@ static void pc_hangup(struct tty_struct *tty)
548} 548}
549 549
550static int pc_write(struct tty_struct *tty, 550static int pc_write(struct tty_struct *tty,
551 const unsigned char *buf, int bytesAvailable) 551 const unsigned char *buf, int bytesAvailable)
552{ 552{
553 unsigned int head, tail; 553 unsigned int head, tail;
554 int dataLen; 554 int dataLen;
@@ -572,7 +572,8 @@ static int pc_write(struct tty_struct *tty,
572 * verifyChannel returns the channel from the tty struct if it is 572 * verifyChannel returns the channel from the tty struct if it is
573 * valid. This serves as a sanity check. 573 * valid. This serves as a sanity check.
574 */ 574 */
575 if ((ch = verifyChannel(tty)) == NULL) 575 ch = verifyChannel(tty);
576 if (ch == NULL)
576 return 0; 577 return 0;
577 578
578 /* Make a pointer to the channel data structure found on the board. */ 579 /* Make a pointer to the channel data structure found on the board. */
@@ -645,26 +646,19 @@ static int pc_write(struct tty_struct *tty,
645 return amountCopied; 646 return amountCopied;
646} 647}
647 648
648static void pc_put_char(struct tty_struct *tty, unsigned char c)
649{
650 pc_write(tty, &c, 1);
651}
652
653static int pc_write_room(struct tty_struct *tty) 649static int pc_write_room(struct tty_struct *tty)
654{ 650{
655 int remain; 651 int remain = 0;
656 struct channel *ch; 652 struct channel *ch;
657 unsigned long flags; 653 unsigned long flags;
658 unsigned int head, tail; 654 unsigned int head, tail;
659 struct board_chan __iomem *bc; 655 struct board_chan __iomem *bc;
660
661 remain = 0;
662
663 /* 656 /*
664 * verifyChannel returns the channel from the tty struct if it is 657 * verifyChannel returns the channel from the tty struct if it is
665 * valid. This serves as a sanity check. 658 * valid. This serves as a sanity check.
666 */ 659 */
667 if ((ch = verifyChannel(tty)) != NULL) { 660 ch = verifyChannel(tty);
661 if (ch != NULL) {
668 spin_lock_irqsave(&epca_lock, flags); 662 spin_lock_irqsave(&epca_lock, flags);
669 globalwinon(ch); 663 globalwinon(ch);
670 664
@@ -676,8 +670,8 @@ static int pc_write_room(struct tty_struct *tty)
676 tail = readw(&bc->tout); 670 tail = readw(&bc->tout);
677 /* Wrap tail if necessary */ 671 /* Wrap tail if necessary */
678 tail &= (ch->txbufsize - 1); 672 tail &= (ch->txbufsize - 1);
679 673 remain = tail - head - 1;
680 if ((remain = tail - head - 1) < 0 ) 674 if (remain < 0)
681 remain += ch->txbufsize; 675 remain += ch->txbufsize;
682 676
683 if (remain && (ch->statusflags & LOWWAIT) == 0) { 677 if (remain && (ch->statusflags & LOWWAIT) == 0) {
@@ -699,12 +693,12 @@ static int pc_chars_in_buffer(struct tty_struct *tty)
699 unsigned long flags; 693 unsigned long flags;
700 struct channel *ch; 694 struct channel *ch;
701 struct board_chan __iomem *bc; 695 struct board_chan __iomem *bc;
702
703 /* 696 /*
704 * verifyChannel returns the channel from the tty struct if it is 697 * verifyChannel returns the channel from the tty struct if it is
705 * valid. This serves as a sanity check. 698 * valid. This serves as a sanity check.
706 */ 699 */
707 if ((ch = verifyChannel(tty)) == NULL) 700 ch = verifyChannel(tty);
701 if (ch == NULL)
708 return 0; 702 return 0;
709 703
710 spin_lock_irqsave(&epca_lock, flags); 704 spin_lock_irqsave(&epca_lock, flags);
@@ -715,7 +709,8 @@ static int pc_chars_in_buffer(struct tty_struct *tty)
715 head = readw(&bc->tin); 709 head = readw(&bc->tin);
716 ctail = readw(&ch->mailbox->cout); 710 ctail = readw(&ch->mailbox->cout);
717 711
718 if (tail == head && readw(&ch->mailbox->cin) == ctail && readb(&bc->tbusy) == 0) 712 if (tail == head && readw(&ch->mailbox->cin) == ctail &&
713 readb(&bc->tbusy) == 0)
719 chars = 0; 714 chars = 0;
720 else { /* Begin if some space on the card has been used */ 715 else { /* Begin if some space on the card has been used */
721 head = readw(&bc->tin) & (ch->txbufsize - 1); 716 head = readw(&bc->tin) & (ch->txbufsize - 1);
@@ -725,7 +720,8 @@ static int pc_chars_in_buffer(struct tty_struct *tty)
725 * pc_write_room here we are finding the amount of bytes in the 720 * pc_write_room here we are finding the amount of bytes in the
726 * buffer filled. Not the amount of bytes empty. 721 * buffer filled. Not the amount of bytes empty.
727 */ 722 */
728 if ((remain = tail - head - 1) < 0 ) 723 remain = tail - head - 1;
724 if (remain < 0)
729 remain += ch->txbufsize; 725 remain += ch->txbufsize;
730 chars = (int)(ch->txbufsize - remain); 726 chars = (int)(ch->txbufsize - remain);
731 /* 727 /*
@@ -736,7 +732,7 @@ static int pc_chars_in_buffer(struct tty_struct *tty)
736 * transmit buffer empties. 732 * transmit buffer empties.
737 */ 733 */
738 if (!(ch->statusflags & EMPTYWAIT)) 734 if (!(ch->statusflags & EMPTYWAIT))
739 setup_empty_event(tty,ch); 735 setup_empty_event(tty, ch);
740 } /* End if some space on the card has been used */ 736 } /* End if some space on the card has been used */
741 memoff(ch); 737 memoff(ch);
742 spin_unlock_irqrestore(&epca_lock, flags); 738 spin_unlock_irqrestore(&epca_lock, flags);
@@ -754,7 +750,8 @@ static void pc_flush_buffer(struct tty_struct *tty)
754 * verifyChannel returns the channel from the tty struct if it is 750 * verifyChannel returns the channel from the tty struct if it is
755 * valid. This serves as a sanity check. 751 * valid. This serves as a sanity check.
756 */ 752 */
757 if ((ch = verifyChannel(tty)) == NULL) 753 ch = verifyChannel(tty);
754 if (ch == NULL)
758 return; 755 return;
759 756
760 spin_lock_irqsave(&epca_lock, flags); 757 spin_lock_irqsave(&epca_lock, flags);
@@ -775,23 +772,25 @@ static void pc_flush_chars(struct tty_struct *tty)
775 * verifyChannel returns the channel from the tty struct if it is 772 * verifyChannel returns the channel from the tty struct if it is
776 * valid. This serves as a sanity check. 773 * valid. This serves as a sanity check.
777 */ 774 */
778 if ((ch = verifyChannel(tty)) != NULL) { 775 ch = verifyChannel(tty);
776 if (ch != NULL) {
779 unsigned long flags; 777 unsigned long flags;
780 spin_lock_irqsave(&epca_lock, flags); 778 spin_lock_irqsave(&epca_lock, flags);
781 /* 779 /*
782 * If not already set and the transmitter is busy setup an 780 * If not already set and the transmitter is busy setup an
783 * event to indicate when the transmit empties. 781 * event to indicate when the transmit empties.
784 */ 782 */
785 if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT)) 783 if ((ch->statusflags & TXBUSY) &&
786 setup_empty_event(tty,ch); 784 !(ch->statusflags & EMPTYWAIT))
785 setup_empty_event(tty, ch);
787 spin_unlock_irqrestore(&epca_lock, flags); 786 spin_unlock_irqrestore(&epca_lock, flags);
788 } 787 }
789} 788}
790 789
791static int block_til_ready(struct tty_struct *tty, 790static int block_til_ready(struct tty_struct *tty,
792 struct file *filp, struct channel *ch) 791 struct file *filp, struct channel *ch)
793{ 792{
794 DECLARE_WAITQUEUE(wait,current); 793 DECLARE_WAITQUEUE(wait, current);
795 int retval, do_clocal = 0; 794 int retval, do_clocal = 0;
796 unsigned long flags; 795 unsigned long flags;
797 796
@@ -839,8 +838,7 @@ static int block_til_ready(struct tty_struct *tty,
839 while (1) { 838 while (1) {
840 set_current_state(TASK_INTERRUPTIBLE); 839 set_current_state(TASK_INTERRUPTIBLE);
841 if (tty_hung_up_p(filp) || 840 if (tty_hung_up_p(filp) ||
842 !(ch->asyncflags & ASYNC_INITIALIZED)) 841 !(ch->asyncflags & ASYNC_INITIALIZED)) {
843 {
844 if (ch->asyncflags & ASYNC_HUP_NOTIFY) 842 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
845 retval = -EAGAIN; 843 retval = -EAGAIN;
846 else 844 else
@@ -880,7 +878,7 @@ static int block_til_ready(struct tty_struct *tty,
880 return 0; 878 return 0;
881} 879}
882 880
883static int pc_open(struct tty_struct *tty, struct file * filp) 881static int pc_open(struct tty_struct *tty, struct file *filp)
884{ 882{
885 struct channel *ch; 883 struct channel *ch;
886 unsigned long flags; 884 unsigned long flags;
@@ -923,7 +921,8 @@ static int pc_open(struct tty_struct *tty, struct file * filp)
923 return(-ENODEV); 921 return(-ENODEV);
924 } 922 }
925 923
926 if ((bc = ch->brdchan) == 0) { 924 bc = ch->brdchan;
925 if (bc == NULL) {
927 tty->driver_data = NULL; 926 tty->driver_data = NULL;
928 return -ENODEV; 927 return -ENODEV;
929 } 928 }
@@ -964,7 +963,7 @@ static int pc_open(struct tty_struct *tty, struct file * filp)
964 * The below routine generally sets up parity, baud, flow control 963 * The below routine generally sets up parity, baud, flow control
965 * issues, etc.... It effect both control flags and input flags. 964 * issues, etc.... It effect both control flags and input flags.
966 */ 965 */
967 epcaparam(tty,ch); 966 epcaparam(tty, ch);
968 ch->asyncflags |= ASYNC_INITIALIZED; 967 ch->asyncflags |= ASYNC_INITIALIZED;
969 memoff(ch); 968 memoff(ch);
970 spin_unlock_irqrestore(&epca_lock, flags); 969 spin_unlock_irqrestore(&epca_lock, flags);
@@ -1002,8 +1001,8 @@ static void __exit epca_module_exit(void)
1002 1001
1003 del_timer_sync(&epca_timer); 1002 del_timer_sync(&epca_timer);
1004 1003
1005 if (tty_unregister_driver(pc_driver) || tty_unregister_driver(pc_info)) 1004 if (tty_unregister_driver(pc_driver) ||
1006 { 1005 tty_unregister_driver(pc_info)) {
1007 printk(KERN_WARNING "epca: cleanup_module failed to un-register tty driver\n"); 1006 printk(KERN_WARNING "epca: cleanup_module failed to un-register tty driver\n");
1008 return; 1007 return;
1009 } 1008 }
@@ -1034,7 +1033,6 @@ static const struct tty_operations pc_ops = {
1034 .flush_buffer = pc_flush_buffer, 1033 .flush_buffer = pc_flush_buffer,
1035 .chars_in_buffer = pc_chars_in_buffer, 1034 .chars_in_buffer = pc_chars_in_buffer,
1036 .flush_chars = pc_flush_chars, 1035 .flush_chars = pc_flush_chars,
1037 .put_char = pc_put_char,
1038 .ioctl = pc_ioctl, 1036 .ioctl = pc_ioctl,
1039 .set_termios = pc_set_termios, 1037 .set_termios = pc_set_termios,
1040 .stop = pc_stop, 1038 .stop = pc_stop,
@@ -1044,7 +1042,7 @@ static const struct tty_operations pc_ops = {
1044 .hangup = pc_hangup, 1042 .hangup = pc_hangup,
1045}; 1043};
1046 1044
1047static int info_open(struct tty_struct *tty, struct file * filp) 1045static int info_open(struct tty_struct *tty, struct file *filp)
1048{ 1046{
1049 return 0; 1047 return 0;
1050} 1048}
@@ -1099,7 +1097,7 @@ static int __init pc_init(void)
1099 * Set up interrupt, we will worry about memory allocation in 1097 * Set up interrupt, we will worry about memory allocation in
1100 * post_fep_init. 1098 * post_fep_init.
1101 */ 1099 */
1102 printk(KERN_INFO "DIGI epca driver version %s loaded.\n",VERSION); 1100 printk(KERN_INFO "DIGI epca driver version %s loaded.\n", VERSION);
1103 1101
1104 /* 1102 /*
1105 * NOTE : This code assumes that the number of ports found in the 1103 * NOTE : This code assumes that the number of ports found in the
@@ -1252,7 +1250,7 @@ static int __init pc_init(void)
1252 if ((board_id & 0x30) == 0x30) 1250 if ((board_id & 0x30) == 0x30)
1253 bd->memory_seg = 0x8000; 1251 bd->memory_seg = 0x8000;
1254 } else 1252 } else
1255 printk(KERN_ERR "epca: Board at 0x%x doesn't appear to be an XI\n",(int)bd->port); 1253 printk(KERN_ERR "epca: Board at 0x%x doesn't appear to be an XI\n", (int)bd->port);
1256 break; 1254 break;
1257 } 1255 }
1258 } 1256 }
@@ -1326,12 +1324,12 @@ static void post_fep_init(unsigned int crd)
1326 */ 1324 */
1327 /* PCI cards are already remapped at this point ISA are not */ 1325 /* PCI cards are already remapped at this point ISA are not */
1328 bd->numports = readw(bd->re_map_membase + XEMPORTS); 1326 bd->numports = readw(bd->re_map_membase + XEMPORTS);
1329 epcaassert(bd->numports <= 64,"PCI returned a invalid number of ports"); 1327 epcaassert(bd->numports <= 64, "PCI returned a invalid number of ports");
1330 nbdevs += (bd->numports); 1328 nbdevs += (bd->numports);
1331 } else { 1329 } else {
1332 /* Fix up the mappings for ISA/EISA etc */ 1330 /* Fix up the mappings for ISA/EISA etc */
1333 /* FIXME: 64K - can we be smarter ? */ 1331 /* FIXME: 64K - can we be smarter ? */
1334 bd->re_map_membase = ioremap(bd->membase, 0x10000); 1332 bd->re_map_membase = ioremap_nocache(bd->membase, 0x10000);
1335 } 1333 }
1336 1334
1337 if (crd != 0) 1335 if (crd != 0)
@@ -1362,7 +1360,8 @@ static void post_fep_init(unsigned int crd)
1362 * XEPORTS (address 0xc22) points at the number of channels the card 1360 * XEPORTS (address 0xc22) points at the number of channels the card
1363 * supports. (For 64XE, XI, XEM, and XR use 0xc02) 1361 * supports. (For 64XE, XI, XEM, and XR use 0xc02)
1364 */ 1362 */
1365 if ((bd->type == PCXEVE || bd->type == PCXE) && (readw(memaddr + XEPORTS) < 3)) 1363 if ((bd->type == PCXEVE || bd->type == PCXE) &&
1364 (readw(memaddr + XEPORTS) < 3))
1366 shrinkmem = 1; 1365 shrinkmem = 1;
1367 if (bd->type < PCIXEM) 1366 if (bd->type < PCIXEM)
1368 if (!request_region((int)bd->port, 4, board_desc[bd->type])) 1367 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
@@ -1461,10 +1460,12 @@ static void post_fep_init(unsigned int crd)
1461 1460
1462 case PCXEVE: 1461 case PCXEVE:
1463 case PCXE: 1462 case PCXE:
1464 ch->txptr = memaddr + (((tseg - bd->memory_seg) << 4) & 0x1fff); 1463 ch->txptr = memaddr + (((tseg - bd->memory_seg) << 4)
1464 & 0x1fff);
1465 ch->txwin = FEPWIN | ((tseg - bd->memory_seg) >> 9); 1465 ch->txwin = FEPWIN | ((tseg - bd->memory_seg) >> 9);
1466 ch->rxptr = memaddr + (((rseg - bd->memory_seg) << 4) & 0x1fff); 1466 ch->rxptr = memaddr + (((rseg - bd->memory_seg) << 4)
1467 ch->rxwin = FEPWIN | ((rseg - bd->memory_seg) >>9 ); 1467 & 0x1fff);
1468 ch->rxwin = FEPWIN | ((rseg - bd->memory_seg) >> 9);
1468 break; 1469 break;
1469 1470
1470 case PCXI: 1471 case PCXI:
@@ -1518,8 +1519,9 @@ static void post_fep_init(unsigned int crd)
1518 } 1519 }
1519 1520
1520 printk(KERN_INFO 1521 printk(KERN_INFO
1521 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n", 1522 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
1522 VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports); 1523 VERSION, board_desc[bd->type], (long)bd->port,
1524 (long)bd->membase, bd->numports);
1523 memwinoff(bd, 0); 1525 memwinoff(bd, 0);
1524} 1526}
1525 1527
@@ -1527,7 +1529,7 @@ static void epcapoll(unsigned long ignored)
1527{ 1529{
1528 unsigned long flags; 1530 unsigned long flags;
1529 int crd; 1531 int crd;
1530 volatile unsigned int head, tail; 1532 unsigned int head, tail;
1531 struct channel *ch; 1533 struct channel *ch;
1532 struct board_info *bd; 1534 struct board_info *bd;
1533 1535
@@ -1593,7 +1595,9 @@ static void doevent(int crd)
1593 chan0 = card_ptr[crd]; 1595 chan0 = card_ptr[crd];
1594 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range"); 1596 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
1595 assertgwinon(chan0); 1597 assertgwinon(chan0);
1596 while ((tail = readw(&chan0->mailbox->eout)) != (head = readw(&chan0->mailbox->ein))) { /* Begin while something in event queue */ 1598 while ((tail = readw(&chan0->mailbox->eout)) !=
1599 (head = readw(&chan0->mailbox->ein))) {
1600 /* Begin while something in event queue */
1597 assertgwinon(chan0); 1601 assertgwinon(chan0);
1598 eventbuf = bd->re_map_membase + tail + ISTART; 1602 eventbuf = bd->re_map_membase + tail + ISTART;
1599 /* Get the channel the event occurred on */ 1603 /* Get the channel the event occurred on */
@@ -1617,7 +1621,8 @@ static void doevent(int crd)
1617 goto next; 1621 goto next;
1618 } 1622 }
1619 1623
1620 if ((bc = ch->brdchan) == NULL) 1624 bc = ch->brdchan;
1625 if (bc == NULL)
1621 goto next; 1626 goto next;
1622 1627
1623 if (event & DATA_IND) { /* Begin DATA_IND */ 1628 if (event & DATA_IND) { /* Begin DATA_IND */
@@ -1629,10 +1634,11 @@ static void doevent(int crd)
1629 /* A modem signal change has been indicated */ 1634 /* A modem signal change has been indicated */
1630 ch->imodem = mstat; 1635 ch->imodem = mstat;
1631 if (ch->asyncflags & ASYNC_CHECK_CD) { 1636 if (ch->asyncflags & ASYNC_CHECK_CD) {
1632 if (mstat & ch->dcd) /* We are now receiving dcd */ 1637 /* We are now receiving dcd */
1638 if (mstat & ch->dcd)
1633 wake_up_interruptible(&ch->open_wait); 1639 wake_up_interruptible(&ch->open_wait);
1634 else 1640 else /* No dcd; hangup */
1635 pc_sched_event(ch, EPCA_EVENT_HANGUP); /* No dcd; hangup */ 1641 pc_sched_event(ch, EPCA_EVENT_HANGUP);
1636 } 1642 }
1637 } 1643 }
1638 tty = ch->tty; 1644 tty = ch->tty;
@@ -1647,7 +1653,8 @@ static void doevent(int crd)
1647 tty_wakeup(tty); 1653 tty_wakeup(tty);
1648 } 1654 }
1649 } else if (event & EMPTYTX_IND) { 1655 } else if (event & EMPTYTX_IND) {
1650 /* This event is generated by setup_empty_event */ 1656 /* This event is generated by
1657 setup_empty_event */
1651 ch->statusflags &= ~TXBUSY; 1658 ch->statusflags &= ~TXBUSY;
1652 if (ch->statusflags & EMPTYWAIT) { 1659 if (ch->statusflags & EMPTYWAIT) {
1653 ch->statusflags &= ~EMPTYWAIT; 1660 ch->statusflags &= ~EMPTYWAIT;
@@ -1655,7 +1662,7 @@ static void doevent(int crd)
1655 } 1662 }
1656 } 1663 }
1657 } 1664 }
1658 next: 1665next:
1659 globalwinon(ch); 1666 globalwinon(ch);
1660 BUG_ON(!bc); 1667 BUG_ON(!bc);
1661 writew(1, &bc->idata); 1668 writew(1, &bc->idata);
@@ -1665,7 +1672,7 @@ static void doevent(int crd)
1665} 1672}
1666 1673
1667static void fepcmd(struct channel *ch, int cmd, int word_or_byte, 1674static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
1668 int byte2, int ncmds, int bytecmd) 1675 int byte2, int ncmds, int bytecmd)
1669{ 1676{
1670 unchar __iomem *memaddr; 1677 unchar __iomem *memaddr;
1671 unsigned int head, cmdTail, cmdStart, cmdMax; 1678 unsigned int head, cmdTail, cmdStart, cmdMax;
@@ -1690,8 +1697,10 @@ static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
1690 memaddr = ch->board->re_map_membase; 1697 memaddr = ch->board->re_map_membase;
1691 1698
1692 if (head >= (cmdMax - cmdStart) || (head & 03)) { 1699 if (head >= (cmdMax - cmdStart) || (head & 03)) {
1693 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", __LINE__, cmd, head); 1700 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n",
1694 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__, cmdMax, cmdStart); 1701 __LINE__, cmd, head);
1702 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n",
1703 __LINE__, cmdMax, cmdStart);
1695 return; 1704 return;
1696 } 1705 }
1697 if (bytecmd) { 1706 if (bytecmd) {
@@ -1770,7 +1779,7 @@ static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
1770static unsigned termios2digi_i(struct channel *ch, unsigned iflag) 1779static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
1771{ 1780{
1772 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK | 1781 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
1773 INPCK | ISTRIP|IXON|IXANY|IXOFF); 1782 INPCK | ISTRIP | IXON | IXANY | IXOFF);
1774 if (ch->digiext.digi_flags & DIGI_AIXON) 1783 if (ch->digiext.digi_flags & DIGI_AIXON)
1775 res |= IAIXON; 1784 res |= IAIXON;
1776 return res; 1785 return res;
@@ -1838,7 +1847,7 @@ static void epcaparam(struct tty_struct *tty, struct channel *ch)
1838 unsigned mval, hflow, cflag, iflag; 1847 unsigned mval, hflow, cflag, iflag;
1839 1848
1840 bc = ch->brdchan; 1849 bc = ch->brdchan;
1841 epcaassert(bc !=0, "bc out of range"); 1850 epcaassert(bc != NULL, "bc out of range");
1842 1851
1843 assertgwinon(ch); 1852 assertgwinon(ch);
1844 ts = tty->termios; 1853 ts = tty->termios;
@@ -1884,8 +1893,10 @@ static void epcaparam(struct tty_struct *tty, struct channel *ch)
1884 * Command sets channels iflag structure on the board. Such 1893 * Command sets channels iflag structure on the board. Such
1885 * things as input soft flow control, handling of parity 1894 * things as input soft flow control, handling of parity
1886 * errors, and break handling are all set here. 1895 * errors, and break handling are all set here.
1896 *
1897 * break handling, parity handling, input stripping,
1898 * flow control chars
1887 */ 1899 */
1888 /* break handling, parity handling, input stripping, flow control chars */
1889 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0); 1900 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
1890 } 1901 }
1891 /* 1902 /*
@@ -1981,7 +1992,7 @@ static void receive_data(struct channel *ch)
1981 return; 1992 return;
1982 1993
1983 /* If CREAD bit is off or device not open, set TX tail to head */ 1994 /* If CREAD bit is off or device not open, set TX tail to head */
1984 if (!tty || !ts || !(ts->c_cflag & CREAD)) { 1995 if (!tty || !ts || !(ts->c_cflag & CREAD)) {
1985 writew(head, &bc->rout); 1996 writew(head, &bc->rout);
1986 return; 1997 return;
1987 } 1998 }
@@ -1991,18 +2002,21 @@ static void receive_data(struct channel *ch)
1991 2002
1992 if (readb(&bc->orun)) { 2003 if (readb(&bc->orun)) {
1993 writeb(0, &bc->orun); 2004 writeb(0, &bc->orun);
1994 printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n",tty->name); 2005 printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n",
2006 tty->name);
1995 tty_insert_flip_char(tty, 0, TTY_OVERRUN); 2007 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
1996 } 2008 }
1997 rxwinon(ch); 2009 rxwinon(ch);
1998 while (bytesAvailable > 0) { /* Begin while there is data on the card */ 2010 while (bytesAvailable > 0) {
2011 /* Begin while there is data on the card */
1999 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail; 2012 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
2000 /* 2013 /*
2001 * Even if head has wrapped around only report the amount of 2014 * Even if head has wrapped around only report the amount of
2002 * data to be equal to the size - tail. Remember memcpy can't 2015 * data to be equal to the size - tail. Remember memcpy can't
2003 * automaticly wrap around the receive buffer. 2016 * automaticly wrap around the receive buffer.
2004 */ 2017 */
2005 dataToRead = (wrapgap < bytesAvailable) ? wrapgap : bytesAvailable; 2018 dataToRead = (wrapgap < bytesAvailable) ? wrapgap
2019 : bytesAvailable;
2006 /* Make sure we don't overflow the buffer */ 2020 /* Make sure we don't overflow the buffer */
2007 dataToRead = tty_prepare_flip_string(tty, &rptr, dataToRead); 2021 dataToRead = tty_prepare_flip_string(tty, &rptr, dataToRead);
2008 if (dataToRead == 0) 2022 if (dataToRead == 0)
@@ -2153,14 +2167,14 @@ static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2153 * The below routine generally sets up parity, baud, flow control 2167 * The below routine generally sets up parity, baud, flow control
2154 * issues, etc.... It effect both control flags and input flags. 2168 * issues, etc.... It effect both control flags and input flags.
2155 */ 2169 */
2156 epcaparam(tty,ch); 2170 epcaparam(tty, ch);
2157 memoff(ch); 2171 memoff(ch);
2158 spin_unlock_irqrestore(&epca_lock, flags); 2172 spin_unlock_irqrestore(&epca_lock, flags);
2159 return 0; 2173 return 0;
2160} 2174}
2161 2175
2162static int pc_ioctl(struct tty_struct *tty, struct file * file, 2176static int pc_ioctl(struct tty_struct *tty, struct file *file,
2163 unsigned int cmd, unsigned long arg) 2177 unsigned int cmd, unsigned long arg)
2164{ 2178{
2165 digiflow_t dflow; 2179 digiflow_t dflow;
2166 int retval; 2180 int retval;
@@ -2175,7 +2189,6 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
2175 bc = ch->brdchan; 2189 bc = ch->brdchan;
2176 else 2190 else
2177 return -EINVAL; 2191 return -EINVAL;
2178
2179 /* 2192 /*
2180 * For POSIX compliance we need to add more ioctls. See tty_ioctl.c in 2193 * For POSIX compliance we need to add more ioctls. See tty_ioctl.c in
2181 * /usr/src/linux/drivers/char for a good example. In particular think 2194 * /usr/src/linux/drivers/char for a good example. In particular think
@@ -2186,9 +2199,10 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
2186 retval = tty_check_change(tty); 2199 retval = tty_check_change(tty);
2187 if (retval) 2200 if (retval)
2188 return retval; 2201 return retval;
2189 /* Setup an event to indicate when the transmit buffer empties */ 2202 /* Setup an event to indicate when the transmit
2203 buffer empties */
2190 spin_lock_irqsave(&epca_lock, flags); 2204 spin_lock_irqsave(&epca_lock, flags);
2191 setup_empty_event(tty,ch); 2205 setup_empty_event(tty, ch);
2192 spin_unlock_irqrestore(&epca_lock, flags); 2206 spin_unlock_irqrestore(&epca_lock, flags);
2193 tty_wait_until_sent(tty, 0); 2207 tty_wait_until_sent(tty, 0);
2194 if (!arg) 2208 if (!arg)
@@ -2198,29 +2212,14 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
2198 retval = tty_check_change(tty); 2212 retval = tty_check_change(tty);
2199 if (retval) 2213 if (retval)
2200 return retval; 2214 return retval;
2201 2215 /* Setup an event to indicate when the transmit buffer
2202 /* Setup an event to indicate when the transmit buffer empties */ 2216 empties */
2203 spin_lock_irqsave(&epca_lock, flags); 2217 spin_lock_irqsave(&epca_lock, flags);
2204 setup_empty_event(tty,ch); 2218 setup_empty_event(tty, ch);
2205 spin_unlock_irqrestore(&epca_lock, flags); 2219 spin_unlock_irqrestore(&epca_lock, flags);
2206 tty_wait_until_sent(tty, 0); 2220 tty_wait_until_sent(tty, 0);
2207 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4); 2221 digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
2208 return 0; 2222 return 0;
2209 case TIOCGSOFTCAR:
2210 if (put_user(C_CLOCAL(tty)?1:0, (unsigned long __user *)arg))
2211 return -EFAULT;
2212 return 0;
2213 case TIOCSSOFTCAR:
2214 {
2215 unsigned int value;
2216
2217 if (get_user(value, (unsigned __user *)argp))
2218 return -EFAULT;
2219 tty->termios->c_cflag =
2220 ((tty->termios->c_cflag & ~CLOCAL) |
2221 (value ? CLOCAL : 0));
2222 return 0;
2223 }
2224 case TIOCMODG: 2223 case TIOCMODG:
2225 mflag = pc_tiocmget(tty, file); 2224 mflag = pc_tiocmget(tty, file);
2226 if (put_user(mflag, (unsigned long __user *)argp)) 2225 if (put_user(mflag, (unsigned long __user *)argp))
@@ -2253,10 +2252,12 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
2253 break; 2252 break;
2254 case DIGI_SETAW: 2253 case DIGI_SETAW:
2255 case DIGI_SETAF: 2254 case DIGI_SETAF:
2255 lock_kernel();
2256 if (cmd == DIGI_SETAW) { 2256 if (cmd == DIGI_SETAW) {
2257 /* Setup an event to indicate when the transmit buffer empties */ 2257 /* Setup an event to indicate when the transmit
2258 buffer empties */
2258 spin_lock_irqsave(&epca_lock, flags); 2259 spin_lock_irqsave(&epca_lock, flags);
2259 setup_empty_event(tty,ch); 2260 setup_empty_event(tty, ch);
2260 spin_unlock_irqrestore(&epca_lock, flags); 2261 spin_unlock_irqrestore(&epca_lock, flags);
2261 tty_wait_until_sent(tty, 0); 2262 tty_wait_until_sent(tty, 0);
2262 } else { 2263 } else {
@@ -2264,6 +2265,7 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
2264 if (tty->ldisc.flush_buffer) 2265 if (tty->ldisc.flush_buffer)
2265 tty->ldisc.flush_buffer(tty); 2266 tty->ldisc.flush_buffer(tty);
2266 } 2267 }
2268 unlock_kernel();
2267 /* Fall Thru */ 2269 /* Fall Thru */
2268 case DIGI_SETA: 2270 case DIGI_SETA:
2269 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t))) 2271 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
@@ -2285,7 +2287,7 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
2285 * control issues, etc.... It effect both control flags and 2287 * control issues, etc.... It effect both control flags and
2286 * input flags. 2288 * input flags.
2287 */ 2289 */
2288 epcaparam(tty,ch); 2290 epcaparam(tty, ch);
2289 memoff(ch); 2291 memoff(ch);
2290 spin_unlock_irqrestore(&epca_lock, flags); 2292 spin_unlock_irqrestore(&epca_lock, flags);
2291 break; 2293 break;
@@ -2321,18 +2323,21 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
2321 if (copy_from_user(&dflow, argp, sizeof(dflow))) 2323 if (copy_from_user(&dflow, argp, sizeof(dflow)))
2322 return -EFAULT; 2324 return -EFAULT;
2323 2325
2324 if (dflow.startc != startc || dflow.stopc != stopc) { /* Begin if setflow toggled */ 2326 if (dflow.startc != startc || dflow.stopc != stopc) {
2327 /* Begin if setflow toggled */
2325 spin_lock_irqsave(&epca_lock, flags); 2328 spin_lock_irqsave(&epca_lock, flags);
2326 globalwinon(ch); 2329 globalwinon(ch);
2327 2330
2328 if (cmd == DIGI_SETFLOW) { 2331 if (cmd == DIGI_SETFLOW) {
2329 ch->fepstartc = ch->startc = dflow.startc; 2332 ch->fepstartc = ch->startc = dflow.startc;
2330 ch->fepstopc = ch->stopc = dflow.stopc; 2333 ch->fepstopc = ch->stopc = dflow.stopc;
2331 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1); 2334 fepcmd(ch, SONOFFC, ch->fepstartc,
2335 ch->fepstopc, 0, 1);
2332 } else { 2336 } else {
2333 ch->fepstartca = ch->startca = dflow.startc; 2337 ch->fepstartca = ch->startca = dflow.startc;
2334 ch->fepstopca = ch->stopca = dflow.stopc; 2338 ch->fepstopca = ch->stopca = dflow.stopc;
2335 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1); 2339 fepcmd(ch, SAUXONOFFC, ch->fepstartca,
2340 ch->fepstopca, 0, 1);
2336 } 2341 }
2337 2342
2338 if (ch->statusflags & TXSTOPPED) 2343 if (ch->statusflags & TXSTOPPED)
@@ -2356,7 +2361,9 @@ static void pc_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
2356 * verifyChannel returns the channel from the tty struct if it is 2361 * verifyChannel returns the channel from the tty struct if it is
2357 * valid. This serves as a sanity check. 2362 * valid. This serves as a sanity check.
2358 */ 2363 */
2359 if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */ 2364 ch = verifyChannel(tty);
2365
2366 if (ch != NULL) { /* Begin if channel valid */
2360 spin_lock_irqsave(&epca_lock, flags); 2367 spin_lock_irqsave(&epca_lock, flags);
2361 globalwinon(ch); 2368 globalwinon(ch);
2362 epcaparam(tty, ch); 2369 epcaparam(tty, ch);
@@ -2383,7 +2390,7 @@ static void do_softint(struct work_struct *work)
2383 2390
2384 if (tty && tty->driver_data) { 2391 if (tty && tty->driver_data) {
2385 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) { 2392 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) {
2386 tty_hangup(tty); /* FIXME: module removal race here - AKPM */ 2393 tty_hangup(tty);
2387 wake_up_interruptible(&ch->open_wait); 2394 wake_up_interruptible(&ch->open_wait);
2388 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE; 2395 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
2389 } 2396 }
@@ -2403,9 +2410,11 @@ static void pc_stop(struct tty_struct *tty)
2403 * verifyChannel returns the channel from the tty struct if it is 2410 * verifyChannel returns the channel from the tty struct if it is
2404 * valid. This serves as a sanity check. 2411 * valid. This serves as a sanity check.
2405 */ 2412 */
2406 if ((ch = verifyChannel(tty)) != NULL) { 2413 ch = verifyChannel(tty);
2414 if (ch != NULL) {
2407 spin_lock_irqsave(&epca_lock, flags); 2415 spin_lock_irqsave(&epca_lock, flags);
2408 if ((ch->statusflags & TXSTOPPED) == 0) { /* Begin if transmit stop requested */ 2416 if ((ch->statusflags & TXSTOPPED) == 0) {
2417 /* Begin if transmit stop requested */
2409 globalwinon(ch); 2418 globalwinon(ch);
2410 /* STOP transmitting now !! */ 2419 /* STOP transmitting now !! */
2411 fepcmd(ch, PAUSETX, 0, 0, 0, 0); 2420 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
@@ -2423,11 +2432,14 @@ static void pc_start(struct tty_struct *tty)
2423 * verifyChannel returns the channel from the tty struct if it is 2432 * verifyChannel returns the channel from the tty struct if it is
2424 * valid. This serves as a sanity check. 2433 * valid. This serves as a sanity check.
2425 */ 2434 */
2426 if ((ch = verifyChannel(tty)) != NULL) { 2435 ch = verifyChannel(tty);
2436 if (ch != NULL) {
2427 unsigned long flags; 2437 unsigned long flags;
2428 spin_lock_irqsave(&epca_lock, flags); 2438 spin_lock_irqsave(&epca_lock, flags);
2429 /* Just in case output was resumed because of a change in Digi-flow */ 2439 /* Just in case output was resumed because of a change
2430 if (ch->statusflags & TXSTOPPED) { /* Begin transmit resume requested */ 2440 in Digi-flow */
2441 if (ch->statusflags & TXSTOPPED) {
2442 /* Begin transmit resume requested */
2431 struct board_chan __iomem *bc; 2443 struct board_chan __iomem *bc;
2432 globalwinon(ch); 2444 globalwinon(ch);
2433 bc = ch->brdchan; 2445 bc = ch->brdchan;
@@ -2457,7 +2469,8 @@ static void pc_throttle(struct tty_struct *tty)
2457 * verifyChannel returns the channel from the tty struct if it is 2469 * verifyChannel returns the channel from the tty struct if it is
2458 * valid. This serves as a sanity check. 2470 * valid. This serves as a sanity check.
2459 */ 2471 */
2460 if ((ch = verifyChannel(tty)) != NULL) { 2472 ch = verifyChannel(tty);
2473 if (ch != NULL) {
2461 spin_lock_irqsave(&epca_lock, flags); 2474 spin_lock_irqsave(&epca_lock, flags);
2462 if ((ch->statusflags & RXSTOPPED) == 0) { 2475 if ((ch->statusflags & RXSTOPPED) == 0) {
2463 globalwinon(ch); 2476 globalwinon(ch);
@@ -2477,8 +2490,10 @@ static void pc_unthrottle(struct tty_struct *tty)
2477 * verifyChannel returns the channel from the tty struct if it is 2490 * verifyChannel returns the channel from the tty struct if it is
2478 * valid. This serves as a sanity check. 2491 * valid. This serves as a sanity check.
2479 */ 2492 */
2480 if ((ch = verifyChannel(tty)) != NULL) { 2493 ch = verifyChannel(tty);
2481 /* Just in case output was resumed because of a change in Digi-flow */ 2494 if (ch != NULL) {
2495 /* Just in case output was resumed because of a change
2496 in Digi-flow */
2482 spin_lock_irqsave(&epca_lock, flags); 2497 spin_lock_irqsave(&epca_lock, flags);
2483 if (ch->statusflags & RXSTOPPED) { 2498 if (ch->statusflags & RXSTOPPED) {
2484 globalwinon(ch); 2499 globalwinon(ch);
@@ -2490,7 +2505,7 @@ static void pc_unthrottle(struct tty_struct *tty)
2490 } 2505 }
2491} 2506}
2492 2507
2493void digi_send_break(struct channel *ch, int msec) 2508static void digi_send_break(struct channel *ch, int msec)
2494{ 2509{
2495 unsigned long flags; 2510 unsigned long flags;
2496 2511
@@ -2523,7 +2538,7 @@ static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
2523 memoff(ch); 2538 memoff(ch);
2524} 2539}
2525 2540
2526void epca_setup(char *str, int *ints) 2541static void epca_setup(char *str, int *ints)
2527{ 2542{
2528 struct board_info board; 2543 struct board_info board;
2529 int index, loop, last; 2544 int index, loop, last;
@@ -2552,14 +2567,16 @@ void epca_setup(char *str, int *ints)
2552 * instructing the driver to ignore epcaconfig.) For 2567 * instructing the driver to ignore epcaconfig.) For
2553 * this reason we check for 2. 2568 * this reason we check for 2.
2554 */ 2569 */
2555 if (board.status == 2) { /* Begin ignore epcaconfig as well as lilo cmd line */ 2570 if (board.status == 2) {
2571 /* Begin ignore epcaconfig as well as lilo cmd line */
2556 nbdevs = 0; 2572 nbdevs = 0;
2557 num_cards = 0; 2573 num_cards = 0;
2558 return; 2574 return;
2559 } /* End ignore epcaconfig as well as lilo cmd line */ 2575 } /* End ignore epcaconfig as well as lilo cmd line */
2560 2576
2561 if (board.status > 2) { 2577 if (board.status > 2) {
2562 printk(KERN_ERR "epca_setup: Invalid board status 0x%x\n", board.status); 2578 printk(KERN_ERR "epca_setup: Invalid board status 0x%x\n",
2579 board.status);
2563 invalid_lilo_config = 1; 2580 invalid_lilo_config = 1;
2564 setup_error_code |= INVALID_BOARD_STATUS; 2581 setup_error_code |= INVALID_BOARD_STATUS;
2565 return; 2582 return;
@@ -2613,7 +2630,8 @@ void epca_setup(char *str, int *ints)
2613 case 6: 2630 case 6:
2614 board.membase = ints[index]; 2631 board.membase = ints[index];
2615 if (ints[index] <= 0) { 2632 if (ints[index] <= 0) {
2616 printk(KERN_ERR "epca_setup: Invalid memory base 0x%x\n",(unsigned int)board.membase); 2633 printk(KERN_ERR "epca_setup: Invalid memory base 0x%x\n",
2634 (unsigned int)board.membase);
2617 invalid_lilo_config = 1; 2635 invalid_lilo_config = 1;
2618 setup_error_code |= INVALID_MEM_BASE; 2636 setup_error_code |= INVALID_MEM_BASE;
2619 return; 2637 return;
@@ -2744,7 +2762,7 @@ void epca_setup(char *str, int *ints)
2744 t2++; 2762 t2++;
2745 2763
2746 if (*t2) { 2764 if (*t2) {
2747 printk(KERN_ERR "epca_setup: Invalid memory base %s\n",str); 2765 printk(KERN_ERR "epca_setup: Invalid memory base %s\n", str);
2748 invalid_lilo_config = 1; 2766 invalid_lilo_config = 1;
2749 setup_error_code |= INVALID_MEM_BASE; 2767 setup_error_code |= INVALID_MEM_BASE;
2750 return; 2768 return;
@@ -2766,7 +2784,7 @@ void epca_setup(char *str, int *ints)
2766 2784
2767 /* I should REALLY validate the stuff here */ 2785 /* I should REALLY validate the stuff here */
2768 /* Copies our local copy of board into boards */ 2786 /* Copies our local copy of board into boards */
2769 memcpy((void *)&boards[num_cards],(void *)&board, sizeof(board)); 2787 memcpy((void *)&boards[num_cards], (void *)&board, sizeof(board));
2770 /* Does this get called once per lilo arg are what ? */ 2788 /* Does this get called once per lilo arg are what ? */
2771 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n", 2789 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
2772 num_cards, board_desc[board.type], 2790 num_cards, board_desc[board.type],
@@ -2807,9 +2825,9 @@ static int __devinit epca_init_one(struct pci_dev *pdev,
2807 if (board_idx >= MAXBOARDS) 2825 if (board_idx >= MAXBOARDS)
2808 goto err_out; 2826 goto err_out;
2809 2827
2810 addr = pci_resource_start (pdev, epca_info_tbl[info_idx].bar_idx); 2828 addr = pci_resource_start(pdev, epca_info_tbl[info_idx].bar_idx);
2811 if (!addr) { 2829 if (!addr) {
2812 printk (KERN_ERR PFX "PCI region #%d not available (size 0)\n", 2830 printk(KERN_ERR PFX "PCI region #%d not available (size 0)\n",
2813 epca_info_tbl[info_idx].bar_idx); 2831 epca_info_tbl[info_idx].bar_idx);
2814 goto err_out; 2832 goto err_out;
2815 } 2833 }
@@ -2820,28 +2838,29 @@ static int __devinit epca_init_one(struct pci_dev *pdev,
2820 boards[board_idx].port = addr + PCI_IO_OFFSET; 2838 boards[board_idx].port = addr + PCI_IO_OFFSET;
2821 boards[board_idx].membase = addr; 2839 boards[board_idx].membase = addr;
2822 2840
2823 if (!request_mem_region (addr + PCI_IO_OFFSET, 0x200000, "epca")) { 2841 if (!request_mem_region(addr + PCI_IO_OFFSET, 0x200000, "epca")) {
2824 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n", 2842 printk(KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
2825 0x200000, addr + PCI_IO_OFFSET); 2843 0x200000, addr + PCI_IO_OFFSET);
2826 goto err_out; 2844 goto err_out;
2827 } 2845 }
2828 2846
2829 boards[board_idx].re_map_port = ioremap(addr + PCI_IO_OFFSET, 0x200000); 2847 boards[board_idx].re_map_port = ioremap_nocache(addr + PCI_IO_OFFSET,
2848 0x200000);
2830 if (!boards[board_idx].re_map_port) { 2849 if (!boards[board_idx].re_map_port) {
2831 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n", 2850 printk(KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
2832 0x200000, addr + PCI_IO_OFFSET); 2851 0x200000, addr + PCI_IO_OFFSET);
2833 goto err_out_free_pciio; 2852 goto err_out_free_pciio;
2834 } 2853 }
2835 2854
2836 if (!request_mem_region (addr, 0x200000, "epca")) { 2855 if (!request_mem_region(addr, 0x200000, "epca")) {
2837 printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n", 2856 printk(KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
2838 0x200000, addr); 2857 0x200000, addr);
2839 goto err_out_free_iounmap; 2858 goto err_out_free_iounmap;
2840 } 2859 }
2841 2860
2842 boards[board_idx].re_map_membase = ioremap(addr, 0x200000); 2861 boards[board_idx].re_map_membase = ioremap_nocache(addr, 0x200000);
2843 if (!boards[board_idx].re_map_membase) { 2862 if (!boards[board_idx].re_map_membase) {
2844 printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n", 2863 printk(KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
2845 0x200000, addr + PCI_IO_OFFSET); 2864 0x200000, addr + PCI_IO_OFFSET);
2846 goto err_out_free_memregion; 2865 goto err_out_free_memregion;
2847 } 2866 }
@@ -2858,11 +2877,11 @@ static int __devinit epca_init_one(struct pci_dev *pdev,
2858 return 0; 2877 return 0;
2859 2878
2860err_out_free_memregion: 2879err_out_free_memregion:
2861 release_mem_region (addr, 0x200000); 2880 release_mem_region(addr, 0x200000);
2862err_out_free_iounmap: 2881err_out_free_iounmap:
2863 iounmap (boards[board_idx].re_map_port); 2882 iounmap(boards[board_idx].re_map_port);
2864err_out_free_pciio: 2883err_out_free_pciio:
2865 release_mem_region (addr + PCI_IO_OFFSET, 0x200000); 2884 release_mem_region(addr + PCI_IO_OFFSET, 0x200000);
2866err_out: 2885err_out:
2867 return -ENODEV; 2886 return -ENODEV;
2868} 2887}
@@ -2878,9 +2897,9 @@ static struct pci_device_id epca_pci_tbl[] = {
2878 2897
2879MODULE_DEVICE_TABLE(pci, epca_pci_tbl); 2898MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
2880 2899
2881int __init init_PCI (void) 2900static int __init init_PCI(void)
2882{ 2901{
2883 memset (&epca_driver, 0, sizeof (epca_driver)); 2902 memset(&epca_driver, 0, sizeof(epca_driver));
2884 epca_driver.name = "epca"; 2903 epca_driver.name = "epca";
2885 epca_driver.id_table = epca_pci_tbl; 2904 epca_driver.id_table = epca_pci_tbl;
2886 epca_driver.probe = epca_init_one; 2905 epca_driver.probe = epca_init_one;
diff --git a/drivers/char/esp.c b/drivers/char/esp.c
index f3fe62067344..84840ba13ff0 100644
--- a/drivers/char/esp.c
+++ b/drivers/char/esp.c
@@ -8,7 +8,7 @@
8 * Extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92. Now 8 * Extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92. Now
9 * much more extensible to support other serial cards based on the 9 * much more extensible to support other serial cards based on the
10 * 16450/16550A UART's. Added support for the AST FourPort and the 10 * 16450/16550A UART's. Added support for the AST FourPort and the
11 * Accent Async board. 11 * Accent Async board.
12 * 12 *
13 * set_serial_info fixed to set the flags, custom divisor, and uart 13 * set_serial_info fixed to set the flags, custom divisor, and uart
14 * type fields. Fix suggested by Michael K. Johnson 12/12/92. 14 * type fields. Fix suggested by Michael K. Johnson 12/12/92.
@@ -61,11 +61,11 @@
61#include <linux/bitops.h> 61#include <linux/bitops.h>
62 62
63#include <asm/system.h> 63#include <asm/system.h>
64#include <asm/io.h> 64#include <linux/io.h>
65 65
66#include <asm/dma.h> 66#include <asm/dma.h>
67#include <linux/slab.h> 67#include <linux/slab.h>
68#include <asm/uaccess.h> 68#include <linux/uaccess.h>
69 69
70#include <linux/hayesesp.h> 70#include <linux/hayesesp.h>
71 71
@@ -127,8 +127,10 @@ static struct tty_driver *esp_driver;
127#undef SERIAL_DEBUG_FLOW 127#undef SERIAL_DEBUG_FLOW
128 128
129#if defined(MODULE) && defined(SERIAL_DEBUG_MCOUNT) 129#if defined(MODULE) && defined(SERIAL_DEBUG_MCOUNT)
130#define DBG_CNT(s) printk("(%s): [%x] refc=%d, serc=%d, ttyc=%d -> %s\n", \ 130#define DBG_CNT(s) printk(KERN_DEBUG "(%s): [%x] refc=%d, serc=%d, ttyc=%d -> %s\n", \
131 tty->name, (info->flags), serial_driver.refcount,info->count,tty->count,s) 131 tty->name, info->flags, \
132 serial_driver.refcount, \
133 info->count, tty->count, s)
132#else 134#else
133#define DBG_CNT(s) 135#define DBG_CNT(s)
134#endif 136#endif
@@ -189,7 +191,7 @@ static inline void serial_out(struct esp_struct *info, int offset,
189 */ 191 */
190static void rs_stop(struct tty_struct *tty) 192static void rs_stop(struct tty_struct *tty)
191{ 193{
192 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 194 struct esp_struct *info = tty->driver_data;
193 unsigned long flags; 195 unsigned long flags;
194 196
195 if (serial_paranoia_check(info, tty->name, "rs_stop")) 197 if (serial_paranoia_check(info, tty->name, "rs_stop"))
@@ -206,12 +208,12 @@ static void rs_stop(struct tty_struct *tty)
206 208
207static void rs_start(struct tty_struct *tty) 209static void rs_start(struct tty_struct *tty)
208{ 210{
209 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 211 struct esp_struct *info = tty->driver_data;
210 unsigned long flags; 212 unsigned long flags;
211 213
212 if (serial_paranoia_check(info, tty->name, "rs_start")) 214 if (serial_paranoia_check(info, tty->name, "rs_start"))
213 return; 215 return;
214 216
215 spin_lock_irqsave(&info->lock, flags); 217 spin_lock_irqsave(&info->lock, flags);
216 if (info->xmit_cnt && info->xmit_buf && !(info->IER & UART_IER_THRI)) { 218 if (info->xmit_cnt && info->xmit_buf && !(info->IER & UART_IER_THRI)) {
217 info->IER |= UART_IER_THRI; 219 info->IER |= UART_IER_THRI;
@@ -233,7 +235,7 @@ static void rs_start(struct tty_struct *tty)
233 * rs_interrupt() should try to keep the interrupt handler as fast as 235 * rs_interrupt() should try to keep the interrupt handler as fast as
234 * possible. After you are done making modifications, it is not a bad 236 * possible. After you are done making modifications, it is not a bad
235 * idea to do: 237 * idea to do:
236 * 238 *
237 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c 239 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
238 * 240 *
239 * and look at the resulting assemble code in serial.s. 241 * and look at the resulting assemble code in serial.s.
@@ -290,7 +292,7 @@ static inline void receive_chars_pio(struct esp_struct *info, int num_bytes)
290 } 292 }
291 293
292 status_mask = (info->read_status_mask >> 2) & 0x07; 294 status_mask = (info->read_status_mask >> 2) & 0x07;
293 295
294 for (i = 0; i < num_bytes - 1; i += 2) { 296 for (i = 0; i < num_bytes - 1; i += 2) {
295 *((unsigned short *)(pio_buf->data + i)) = 297 *((unsigned short *)(pio_buf->data + i)) =
296 inw(info->port + UART_ESI_RX); 298 inw(info->port + UART_ESI_RX);
@@ -325,8 +327,7 @@ static inline void receive_chars_pio(struct esp_struct *info, int num_bytes)
325 flag = TTY_BREAK; 327 flag = TTY_BREAK;
326 if (info->flags & ASYNC_SAK) 328 if (info->flags & ASYNC_SAK)
327 do_SAK(tty); 329 do_SAK(tty);
328 } 330 } else if (err_buf->data[i] & 0x02)
329 else if (err_buf->data[i] & 0x02)
330 flag = TTY_FRAME; 331 flag = TTY_FRAME;
331 else if (err_buf->data[i] & 0x01) 332 else if (err_buf->data[i] & 0x01)
332 flag = TTY_PARITY; 333 flag = TTY_PARITY;
@@ -341,23 +342,29 @@ static inline void receive_chars_pio(struct esp_struct *info, int num_bytes)
341 release_pio_buffer(err_buf); 342 release_pio_buffer(err_buf);
342} 343}
343 344
344static inline void receive_chars_dma(struct esp_struct *info, int num_bytes) 345static void program_isa_dma(int dma, int dir, unsigned long addr, int len)
345{ 346{
346 unsigned long flags; 347 unsigned long flags;
348
349 flags = claim_dma_lock();
350 disable_dma(dma);
351 clear_dma_ff(dma);
352 set_dma_mode(dma, dir);
353 set_dma_addr(dma, addr);
354 set_dma_count(dma, len);
355 enable_dma(dma);
356 release_dma_lock(flags);
357}
358
359static void receive_chars_dma(struct esp_struct *info, int num_bytes)
360{
347 info->stat_flags &= ~ESP_STAT_RX_TIMEOUT; 361 info->stat_flags &= ~ESP_STAT_RX_TIMEOUT;
348 dma_bytes = num_bytes; 362 dma_bytes = num_bytes;
349 info->stat_flags |= ESP_STAT_DMA_RX; 363 info->stat_flags |= ESP_STAT_DMA_RX;
350 364
351 flags=claim_dma_lock(); 365 program_isa_dma(dma, DMA_MODE_READ, isa_virt_to_bus(dma_buffer),
352 disable_dma(dma); 366 dma_bytes);
353 clear_dma_ff(dma); 367 serial_out(info, UART_ESI_CMD1, ESI_START_DMA_RX);
354 set_dma_mode(dma, DMA_MODE_READ);
355 set_dma_addr(dma, isa_virt_to_bus(dma_buffer));
356 set_dma_count(dma, dma_bytes);
357 enable_dma(dma);
358 release_dma_lock(flags);
359
360 serial_out(info, UART_ESI_CMD1, ESI_START_DMA_RX);
361} 368}
362 369
363static inline void receive_chars_dma_done(struct esp_struct *info, 370static inline void receive_chars_dma_done(struct esp_struct *info,
@@ -366,22 +373,22 @@ static inline void receive_chars_dma_done(struct esp_struct *info,
366 struct tty_struct *tty = info->tty; 373 struct tty_struct *tty = info->tty;
367 int num_bytes; 374 int num_bytes;
368 unsigned long flags; 375 unsigned long flags;
369 376
370 flags=claim_dma_lock(); 377 flags = claim_dma_lock();
371 disable_dma(dma); 378 disable_dma(dma);
372 clear_dma_ff(dma); 379 clear_dma_ff(dma);
373 380
374 info->stat_flags &= ~ESP_STAT_DMA_RX; 381 info->stat_flags &= ~ESP_STAT_DMA_RX;
375 num_bytes = dma_bytes - get_dma_residue(dma); 382 num_bytes = dma_bytes - get_dma_residue(dma);
376 release_dma_lock(flags); 383 release_dma_lock(flags);
377 384
378 info->icount.rx += num_bytes; 385 info->icount.rx += num_bytes;
379 386
380 if (num_bytes > 0) { 387 if (num_bytes > 0) {
381 tty_insert_flip_string(tty, dma_buffer, num_bytes - 1); 388 tty_insert_flip_string(tty, dma_buffer, num_bytes - 1);
382 389
383 status &= (0x1c & info->read_status_mask); 390 status &= (0x1c & info->read_status_mask);
384 391
385 /* Is the status significant or do we throw the last byte ? */ 392 /* Is the status significant or do we throw the last byte ? */
386 if (!(status & info->ignore_status_mask)) { 393 if (!(status & info->ignore_status_mask)) {
387 int statflag = 0; 394 int statflag = 0;
@@ -393,13 +400,13 @@ static inline void receive_chars_dma_done(struct esp_struct *info,
393 do_SAK(tty); 400 do_SAK(tty);
394 } else if (status & 0x08) { 401 } else if (status & 0x08) {
395 statflag = TTY_FRAME; 402 statflag = TTY_FRAME;
396 (info->icount.frame)++; 403 info->icount.frame++;
397 } 404 } else if (status & 0x04) {
398 else if (status & 0x04) {
399 statflag = TTY_PARITY; 405 statflag = TTY_PARITY;
400 (info->icount.parity)++; 406 info->icount.parity++;
401 } 407 }
402 tty_insert_flip_char(tty, dma_buffer[num_bytes - 1], statflag); 408 tty_insert_flip_char(tty, dma_buffer[num_bytes - 1],
409 statflag);
403 } 410 }
404 tty_schedule_flip(tty); 411 tty_schedule_flip(tty);
405 } 412 }
@@ -484,8 +491,6 @@ static inline void transmit_chars_pio(struct esp_struct *info,
484/* Caller must hold info->lock */ 491/* Caller must hold info->lock */
485static inline void transmit_chars_dma(struct esp_struct *info, int num_bytes) 492static inline void transmit_chars_dma(struct esp_struct *info, int num_bytes)
486{ 493{
487 unsigned long flags;
488
489 dma_bytes = num_bytes; 494 dma_bytes = num_bytes;
490 495
491 if (info->xmit_tail + dma_bytes <= ESP_XMIT_SIZE) { 496 if (info->xmit_tail + dma_bytes <= ESP_XMIT_SIZE) {
@@ -517,26 +522,18 @@ static inline void transmit_chars_dma(struct esp_struct *info, int num_bytes)
517 } 522 }
518 523
519 info->stat_flags |= ESP_STAT_DMA_TX; 524 info->stat_flags |= ESP_STAT_DMA_TX;
520 525
521 flags=claim_dma_lock(); 526 program_isa_dma(dma, DMA_MODE_WRITE, isa_virt_to_bus(dma_buffer),
522 disable_dma(dma); 527 dma_bytes);
523 clear_dma_ff(dma); 528 serial_out(info, UART_ESI_CMD1, ESI_START_DMA_TX);
524 set_dma_mode(dma, DMA_MODE_WRITE);
525 set_dma_addr(dma, isa_virt_to_bus(dma_buffer));
526 set_dma_count(dma, dma_bytes);
527 enable_dma(dma);
528 release_dma_lock(flags);
529
530 serial_out(info, UART_ESI_CMD1, ESI_START_DMA_TX);
531} 529}
532 530
533static inline void transmit_chars_dma_done(struct esp_struct *info) 531static inline void transmit_chars_dma_done(struct esp_struct *info)
534{ 532{
535 int num_bytes; 533 int num_bytes;
536 unsigned long flags; 534 unsigned long flags;
537
538 535
539 flags=claim_dma_lock(); 536 flags = claim_dma_lock();
540 disable_dma(dma); 537 disable_dma(dma);
541 clear_dma_ff(dma); 538 clear_dma_ff(dma);
542 539
@@ -547,27 +544,21 @@ static inline void transmit_chars_dma_done(struct esp_struct *info)
547 if (dma_bytes != num_bytes) { 544 if (dma_bytes != num_bytes) {
548 dma_bytes -= num_bytes; 545 dma_bytes -= num_bytes;
549 memmove(dma_buffer, dma_buffer + num_bytes, dma_bytes); 546 memmove(dma_buffer, dma_buffer + num_bytes, dma_bytes);
550 547
551 flags=claim_dma_lock(); 548 program_isa_dma(dma, DMA_MODE_WRITE,
552 disable_dma(dma); 549 isa_virt_to_bus(dma_buffer), dma_bytes);
553 clear_dma_ff(dma); 550
554 set_dma_mode(dma, DMA_MODE_WRITE); 551 serial_out(info, UART_ESI_CMD1, ESI_START_DMA_TX);
555 set_dma_addr(dma, isa_virt_to_bus(dma_buffer));
556 set_dma_count(dma, dma_bytes);
557 enable_dma(dma);
558 release_dma_lock(flags);
559
560 serial_out(info, UART_ESI_CMD1, ESI_START_DMA_TX);
561 } else { 552 } else {
562 dma_bytes = 0; 553 dma_bytes = 0;
563 info->stat_flags &= ~ESP_STAT_DMA_TX; 554 info->stat_flags &= ~ESP_STAT_DMA_TX;
564 } 555 }
565} 556}
566 557
567static inline void check_modem_status(struct esp_struct *info) 558static void check_modem_status(struct esp_struct *info)
568{ 559{
569 int status; 560 int status;
570 561
571 serial_out(info, UART_ESI_CMD1, ESI_GET_UART_STAT); 562 serial_out(info, UART_ESI_CMD1, ESI_GET_UART_STAT);
572 status = serial_in(info, UART_ESI_STAT2); 563 status = serial_in(info, UART_ESI_STAT2);
573 564
@@ -588,7 +579,7 @@ static inline void check_modem_status(struct esp_struct *info)
588#if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR)) 579#if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
589 printk("ttys%d CD now %s...", info->line, 580 printk("ttys%d CD now %s...", info->line,
590 (status & UART_MSR_DCD) ? "on" : "off"); 581 (status & UART_MSR_DCD) ? "on" : "off");
591#endif 582#endif
592 if (status & UART_MSR_DCD) 583 if (status & UART_MSR_DCD)
593 wake_up_interruptible(&info->open_wait); 584 wake_up_interruptible(&info->open_wait);
594 else { 585 else {
@@ -605,7 +596,7 @@ static inline void check_modem_status(struct esp_struct *info)
605 */ 596 */
606static irqreturn_t rs_interrupt_single(int irq, void *dev_id) 597static irqreturn_t rs_interrupt_single(int irq, void *dev_id)
607{ 598{
608 struct esp_struct * info; 599 struct esp_struct *info;
609 unsigned err_status; 600 unsigned err_status;
610 unsigned int scratch; 601 unsigned int scratch;
611 602
@@ -617,7 +608,7 @@ static irqreturn_t rs_interrupt_single(int irq, void *dev_id)
617 scratch = serial_in(info, UART_ESI_SID); 608 scratch = serial_in(info, UART_ESI_SID);
618 609
619 spin_lock(&info->lock); 610 spin_lock(&info->lock);
620 611
621 if (!info->tty) { 612 if (!info->tty) {
622 spin_unlock(&info->lock); 613 spin_unlock(&info->lock);
623 return IRQ_NONE; 614 return IRQ_NONE;
@@ -637,7 +628,7 @@ static irqreturn_t rs_interrupt_single(int irq, void *dev_id)
637 if (err_status & 0x80) /* Start break */ 628 if (err_status & 0x80) /* Start break */
638 wake_up_interruptible(&info->break_wait); 629 wake_up_interruptible(&info->break_wait);
639 } 630 }
640 631
641 if ((scratch & 0x88) || /* DMA completed or timed out */ 632 if ((scratch & 0x88) || /* DMA completed or timed out */
642 (err_status & 0x1c) /* receive error */) { 633 (err_status & 0x1c) /* receive error */) {
643 if (info->stat_flags & ESP_STAT_DMA_RX) 634 if (info->stat_flags & ESP_STAT_DMA_RX)
@@ -667,7 +658,7 @@ static irqreturn_t rs_interrupt_single(int irq, void *dev_id)
667 receive_chars_dma(info, num_bytes); 658 receive_chars_dma(info, num_bytes);
668 } 659 }
669 } 660 }
670 661
671 if (!(info->stat_flags & (ESP_STAT_DMA_RX | ESP_STAT_DMA_TX)) && 662 if (!(info->stat_flags & (ESP_STAT_DMA_RX | ESP_STAT_DMA_TX)) &&
672 (scratch & 0x02) && (info->IER & UART_IER_THRI)) { 663 (scratch & 0x02) && (info->IER & UART_IER_THRI)) {
673 if ((info->xmit_cnt <= 0) || info->tty->stopped) { 664 if ((info->xmit_cnt <= 0) || info->tty->stopped) {
@@ -722,11 +713,11 @@ static irqreturn_t rs_interrupt_single(int irq, void *dev_id)
722 * --------------------------------------------------------------- 713 * ---------------------------------------------------------------
723 */ 714 */
724 715
725static inline void esp_basic_init(struct esp_struct * info) 716static void esp_basic_init(struct esp_struct *info)
726{ 717{
727 /* put ESPC in enhanced mode */ 718 /* put ESPC in enhanced mode */
728 serial_out(info, UART_ESI_CMD1, ESI_SET_MODE); 719 serial_out(info, UART_ESI_CMD1, ESI_SET_MODE);
729 720
730 if (info->stat_flags & ESP_STAT_NEVER_DMA) 721 if (info->stat_flags & ESP_STAT_NEVER_DMA)
731 serial_out(info, UART_ESI_CMD2, 0x01); 722 serial_out(info, UART_ESI_CMD2, 0x01);
732 else 723 else
@@ -783,13 +774,13 @@ static inline void esp_basic_init(struct esp_struct * info)
783 serial_out(info, UART_ESI_CMD2, 0xff); 774 serial_out(info, UART_ESI_CMD2, 0xff);
784} 775}
785 776
786static int startup(struct esp_struct * info) 777static int startup(struct esp_struct *info)
787{ 778{
788 unsigned long flags; 779 unsigned long flags;
789 int retval=0; 780 int retval = 0;
790 unsigned int num_chars; 781 unsigned int num_chars;
791 782
792 spin_lock_irqsave(&info->lock, flags); 783 spin_lock_irqsave(&info->lock, flags);
793 784
794 if (info->flags & ASYNC_INITIALIZED) 785 if (info->flags & ASYNC_INITIALIZED)
795 goto out; 786 goto out;
@@ -802,7 +793,8 @@ static int startup(struct esp_struct * info)
802 } 793 }
803 794
804#ifdef SERIAL_DEBUG_OPEN 795#ifdef SERIAL_DEBUG_OPEN
805 printk("starting up ttys%d (irq %d)...", info->line, info->irq); 796 printk(KERN_DEBUG "starting up ttys%d (irq %d)...",
797 info->line, info->irq);
806#endif 798#endif
807 799
808 /* Flush the RX buffer. Using the ESI flush command may cause */ 800 /* Flush the RX buffer. Using the ESI flush command may cause */
@@ -863,7 +855,7 @@ static int startup(struct esp_struct * info)
863 dma_buffer = NULL; 855 dma_buffer = NULL;
864 info->stat_flags |= ESP_STAT_USE_PIO; 856 info->stat_flags |= ESP_STAT_USE_PIO;
865 } 857 }
866 858
867 } 859 }
868 860
869 info->MCR = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2; 861 info->MCR = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2;
@@ -872,7 +864,7 @@ static int startup(struct esp_struct * info)
872 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART); 864 serial_out(info, UART_ESI_CMD1, ESI_WRITE_UART);
873 serial_out(info, UART_ESI_CMD2, UART_MCR); 865 serial_out(info, UART_ESI_CMD2, UART_MCR);
874 serial_out(info, UART_ESI_CMD2, info->MCR); 866 serial_out(info, UART_ESI_CMD2, info->MCR);
875 867
876 /* 868 /*
877 * Finally, enable interrupts 869 * Finally, enable interrupts
878 */ 870 */
@@ -881,7 +873,7 @@ static int startup(struct esp_struct * info)
881 UART_IER_DMA_TC; 873 UART_IER_DMA_TC;
882 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK); 874 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
883 serial_out(info, UART_ESI_CMD2, info->IER); 875 serial_out(info, UART_ESI_CMD2, info->IER);
884 876
885 if (info->tty) 877 if (info->tty)
886 clear_bit(TTY_IO_ERROR, &info->tty->flags); 878 clear_bit(TTY_IO_ERROR, &info->tty->flags);
887 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 879 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
@@ -900,7 +892,7 @@ static int startup(struct esp_struct * info)
900 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP) 892 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
901 info->tty->alt_speed = 460800; 893 info->tty->alt_speed = 460800;
902 } 894 }
903 895
904 /* 896 /*
905 * set the speed of the serial port 897 * set the speed of the serial port
906 */ 898 */
@@ -918,7 +910,7 @@ out_unlocked:
918 * This routine will shutdown a serial port; interrupts are disabled, and 910 * This routine will shutdown a serial port; interrupts are disabled, and
919 * DTR is dropped if the hangup on close termio flag is on. 911 * DTR is dropped if the hangup on close termio flag is on.
920 */ 912 */
921static void shutdown(struct esp_struct * info) 913static void shutdown(struct esp_struct *info)
922{ 914{
923 unsigned long flags, f; 915 unsigned long flags, f;
924 916
@@ -929,7 +921,7 @@ static void shutdown(struct esp_struct * info)
929 printk("Shutting down serial port %d (irq %d)....", info->line, 921 printk("Shutting down serial port %d (irq %d)....", info->line,
930 info->irq); 922 info->irq);
931#endif 923#endif
932 924
933 spin_lock_irqsave(&info->lock, flags); 925 spin_lock_irqsave(&info->lock, flags);
934 /* 926 /*
935 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq 927 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
@@ -941,14 +933,14 @@ static void shutdown(struct esp_struct * info)
941 /* stop a DMA transfer on the port being closed */ 933 /* stop a DMA transfer on the port being closed */
942 /* DMA lock is higher priority always */ 934 /* DMA lock is higher priority always */
943 if (info->stat_flags & (ESP_STAT_DMA_RX | ESP_STAT_DMA_TX)) { 935 if (info->stat_flags & (ESP_STAT_DMA_RX | ESP_STAT_DMA_TX)) {
944 f=claim_dma_lock(); 936 f = claim_dma_lock();
945 disable_dma(dma); 937 disable_dma(dma);
946 clear_dma_ff(dma); 938 clear_dma_ff(dma);
947 release_dma_lock(f); 939 release_dma_lock(f);
948 940
949 dma_bytes = 0; 941 dma_bytes = 0;
950 } 942 }
951 943
952 /* 944 /*
953 * Free the IRQ 945 * Free the IRQ
954 */ 946 */
@@ -970,7 +962,7 @@ static void shutdown(struct esp_struct * info)
970 free_pages((unsigned long)dma_buffer, 962 free_pages((unsigned long)dma_buffer,
971 get_order(DMA_BUFFER_SZ)); 963 get_order(DMA_BUFFER_SZ));
972 dma_buffer = NULL; 964 dma_buffer = NULL;
973 } 965 }
974 } 966 }
975 967
976 if (info->xmit_buf) { 968 if (info->xmit_buf) {
@@ -992,7 +984,7 @@ static void shutdown(struct esp_struct * info)
992 984
993 if (info->tty) 985 if (info->tty)
994 set_bit(TTY_IO_ERROR, &info->tty->flags); 986 set_bit(TTY_IO_ERROR, &info->tty->flags);
995 987
996 info->flags &= ~ASYNC_INITIALIZED; 988 info->flags &= ~ASYNC_INITIALIZED;
997 spin_unlock_irqrestore(&info->lock, flags); 989 spin_unlock_irqrestore(&info->lock, flags);
998} 990}
@@ -1005,7 +997,7 @@ static void change_speed(struct esp_struct *info)
1005{ 997{
1006 unsigned short port; 998 unsigned short port;
1007 int quot = 0; 999 int quot = 0;
1008 unsigned cflag,cval; 1000 unsigned cflag, cval;
1009 int baud, bits; 1001 int baud, bits;
1010 unsigned char flow1 = 0, flow2 = 0; 1002 unsigned char flow1 = 0, flow2 = 0;
1011 unsigned long flags; 1003 unsigned long flags;
@@ -1014,14 +1006,14 @@ static void change_speed(struct esp_struct *info)
1014 return; 1006 return;
1015 cflag = info->tty->termios->c_cflag; 1007 cflag = info->tty->termios->c_cflag;
1016 port = info->port; 1008 port = info->port;
1017 1009
1018 /* byte size and parity */ 1010 /* byte size and parity */
1019 switch (cflag & CSIZE) { 1011 switch (cflag & CSIZE) {
1020 case CS5: cval = 0x00; bits = 7; break; 1012 case CS5: cval = 0x00; bits = 7; break;
1021 case CS6: cval = 0x01; bits = 8; break; 1013 case CS6: cval = 0x01; bits = 8; break;
1022 case CS7: cval = 0x02; bits = 9; break; 1014 case CS7: cval = 0x02; bits = 9; break;
1023 case CS8: cval = 0x03; bits = 10; break; 1015 case CS8: cval = 0x03; bits = 10; break;
1024 default: cval = 0x00; bits = 7; break; 1016 default: cval = 0x00; bits = 7; break;
1025 } 1017 }
1026 if (cflag & CSTOPB) { 1018 if (cflag & CSTOPB) {
1027 cval |= 0x04; 1019 cval |= 0x04;
@@ -1037,14 +1029,12 @@ static void change_speed(struct esp_struct *info)
1037 if (cflag & CMSPAR) 1029 if (cflag & CMSPAR)
1038 cval |= UART_LCR_SPAR; 1030 cval |= UART_LCR_SPAR;
1039#endif 1031#endif
1040
1041 baud = tty_get_baud_rate(info->tty); 1032 baud = tty_get_baud_rate(info->tty);
1042 if (baud == 38400 && 1033 if (baud == 38400 &&
1043 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) 1034 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST))
1044 quot = info->custom_divisor; 1035 quot = info->custom_divisor;
1045 else { 1036 else {
1046 if (baud == 134) 1037 if (baud == 134) /* Special case since 134 is really 134.5 */
1047 /* Special case since 134 is really 134.5 */
1048 quot = (2*BASE_BAUD / 269); 1038 quot = (2*BASE_BAUD / 269);
1049 else if (baud) 1039 else if (baud)
1050 quot = BASE_BAUD / baud; 1040 quot = BASE_BAUD / baud;
@@ -1052,7 +1042,12 @@ static void change_speed(struct esp_struct *info)
1052 /* If the quotient is ever zero, default to 9600 bps */ 1042 /* If the quotient is ever zero, default to 9600 bps */
1053 if (!quot) 1043 if (!quot)
1054 quot = BASE_BAUD / 9600; 1044 quot = BASE_BAUD / 9600;
1055 1045
1046 if (baud) {
1047 /* Actual rate */
1048 baud = BASE_BAUD/quot;
1049 tty_encode_baud_rate(info->tty, baud, baud);
1050 }
1056 info->timeout = ((1024 * HZ * bits * quot) / BASE_BAUD) + (HZ / 50); 1051 info->timeout = ((1024 * HZ * bits * quot) / BASE_BAUD) + (HZ / 50);
1057 1052
1058 /* CTS flow control flag and modem status interrupts */ 1053 /* CTS flow control flag and modem status interrupts */
@@ -1066,10 +1061,8 @@ static void change_speed(struct esp_struct *info)
1066 info->flags &= ~ASYNC_CTS_FLOW; 1061 info->flags &= ~ASYNC_CTS_FLOW;
1067 if (cflag & CLOCAL) 1062 if (cflag & CLOCAL)
1068 info->flags &= ~ASYNC_CHECK_CD; 1063 info->flags &= ~ASYNC_CHECK_CD;
1069 else { 1064 else
1070 info->flags |= ASYNC_CHECK_CD; 1065 info->flags |= ASYNC_CHECK_CD;
1071 /* info->IER |= UART_IER_MSI; */
1072 }
1073 1066
1074 /* 1067 /*
1075 * Set up parity check flag 1068 * Set up parity check flag
@@ -1079,7 +1072,7 @@ static void change_speed(struct esp_struct *info)
1079 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE; 1072 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
1080 if (I_BRKINT(info->tty) || I_PARMRK(info->tty)) 1073 if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
1081 info->read_status_mask |= UART_LSR_BI; 1074 info->read_status_mask |= UART_LSR_BI;
1082 1075
1083 info->ignore_status_mask = 0; 1076 info->ignore_status_mask = 0;
1084#if 0 1077#if 0
1085 /* This should be safe, but for some broken bits of hardware... */ 1078 /* This should be safe, but for some broken bits of hardware... */
@@ -1092,7 +1085,7 @@ static void change_speed(struct esp_struct *info)
1092 info->ignore_status_mask |= UART_LSR_BI; 1085 info->ignore_status_mask |= UART_LSR_BI;
1093 info->read_status_mask |= UART_LSR_BI; 1086 info->read_status_mask |= UART_LSR_BI;
1094 /* 1087 /*
1095 * If we're ignore parity and break indicators, ignore 1088 * If we're ignore parity and break indicators, ignore
1096 * overruns too. (For real raw support). 1089 * overruns too. (For real raw support).
1097 */ 1090 */
1098 if (I_IGNPAR(info->tty)) { 1091 if (I_IGNPAR(info->tty)) {
@@ -1130,19 +1123,19 @@ static void change_speed(struct esp_struct *info)
1130 serial_out(info, UART_ESI_CMD2, 0x10); 1123 serial_out(info, UART_ESI_CMD2, 0x10);
1131 serial_out(info, UART_ESI_CMD2, 0x21); 1124 serial_out(info, UART_ESI_CMD2, 0x21);
1132 switch (cflag & CSIZE) { 1125 switch (cflag & CSIZE) {
1133 case CS5: 1126 case CS5:
1134 serial_out(info, UART_ESI_CMD2, 0x1f); 1127 serial_out(info, UART_ESI_CMD2, 0x1f);
1135 break; 1128 break;
1136 case CS6: 1129 case CS6:
1137 serial_out(info, UART_ESI_CMD2, 0x3f); 1130 serial_out(info, UART_ESI_CMD2, 0x3f);
1138 break; 1131 break;
1139 case CS7: 1132 case CS7:
1140 case CS8: 1133 case CS8:
1141 serial_out(info, UART_ESI_CMD2, 0x7f); 1134 serial_out(info, UART_ESI_CMD2, 0x7f);
1142 break; 1135 break;
1143 default: 1136 default:
1144 serial_out(info, UART_ESI_CMD2, 0xff); 1137 serial_out(info, UART_ESI_CMD2, 0xff);
1145 break; 1138 break;
1146 } 1139 }
1147 } 1140 }
1148 1141
@@ -1156,31 +1149,34 @@ static void change_speed(struct esp_struct *info)
1156 spin_unlock_irqrestore(&info->lock, flags); 1149 spin_unlock_irqrestore(&info->lock, flags);
1157} 1150}
1158 1151
1159static void rs_put_char(struct tty_struct *tty, unsigned char ch) 1152static int rs_put_char(struct tty_struct *tty, unsigned char ch)
1160{ 1153{
1161 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 1154 struct esp_struct *info = tty->driver_data;
1162 unsigned long flags; 1155 unsigned long flags;
1156 int ret = 0;
1163 1157
1164 if (serial_paranoia_check(info, tty->name, "rs_put_char")) 1158 if (serial_paranoia_check(info, tty->name, "rs_put_char"))
1165 return; 1159 return 0;
1166 1160
1167 if (!info->xmit_buf) 1161 if (!info->xmit_buf)
1168 return; 1162 return 0;
1169 1163
1170 spin_lock_irqsave(&info->lock, flags); 1164 spin_lock_irqsave(&info->lock, flags);
1171 if (info->xmit_cnt < ESP_XMIT_SIZE - 1) { 1165 if (info->xmit_cnt < ESP_XMIT_SIZE - 1) {
1172 info->xmit_buf[info->xmit_head++] = ch; 1166 info->xmit_buf[info->xmit_head++] = ch;
1173 info->xmit_head &= ESP_XMIT_SIZE-1; 1167 info->xmit_head &= ESP_XMIT_SIZE-1;
1174 info->xmit_cnt++; 1168 info->xmit_cnt++;
1169 ret = 1;
1175 } 1170 }
1176 spin_unlock_irqrestore(&info->lock, flags); 1171 spin_unlock_irqrestore(&info->lock, flags);
1172 return ret;
1177} 1173}
1178 1174
1179static void rs_flush_chars(struct tty_struct *tty) 1175static void rs_flush_chars(struct tty_struct *tty)
1180{ 1176{
1181 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 1177 struct esp_struct *info = tty->driver_data;
1182 unsigned long flags; 1178 unsigned long flags;
1183 1179
1184 if (serial_paranoia_check(info, tty->name, "rs_flush_chars")) 1180 if (serial_paranoia_check(info, tty->name, "rs_flush_chars"))
1185 return; 1181 return;
1186 1182
@@ -1198,11 +1194,11 @@ out:
1198 spin_unlock_irqrestore(&info->lock, flags); 1194 spin_unlock_irqrestore(&info->lock, flags);
1199} 1195}
1200 1196
1201static int rs_write(struct tty_struct * tty, 1197static int rs_write(struct tty_struct *tty,
1202 const unsigned char *buf, int count) 1198 const unsigned char *buf, int count)
1203{ 1199{
1204 int c, t, ret = 0; 1200 int c, t, ret = 0;
1205 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 1201 struct esp_struct *info = tty->driver_data;
1206 unsigned long flags; 1202 unsigned long flags;
1207 1203
1208 if (serial_paranoia_check(info, tty->name, "rs_write")) 1204 if (serial_paranoia_check(info, tty->name, "rs_write"))
@@ -1210,19 +1206,19 @@ static int rs_write(struct tty_struct * tty,
1210 1206
1211 if (!info->xmit_buf) 1207 if (!info->xmit_buf)
1212 return 0; 1208 return 0;
1213 1209
1214 while (1) { 1210 while (1) {
1215 /* Thanks to R. Wolff for suggesting how to do this with */ 1211 /* Thanks to R. Wolff for suggesting how to do this with */
1216 /* interrupts enabled */ 1212 /* interrupts enabled */
1217 1213
1218 c = count; 1214 c = count;
1219 t = ESP_XMIT_SIZE - info->xmit_cnt - 1; 1215 t = ESP_XMIT_SIZE - info->xmit_cnt - 1;
1220 1216
1221 if (t < c) 1217 if (t < c)
1222 c = t; 1218 c = t;
1223 1219
1224 t = ESP_XMIT_SIZE - info->xmit_head; 1220 t = ESP_XMIT_SIZE - info->xmit_head;
1225 1221
1226 if (t < c) 1222 if (t < c)
1227 c = t; 1223 c = t;
1228 1224
@@ -1252,10 +1248,10 @@ static int rs_write(struct tty_struct * tty,
1252 1248
1253static int rs_write_room(struct tty_struct *tty) 1249static int rs_write_room(struct tty_struct *tty)
1254{ 1250{
1255 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 1251 struct esp_struct *info = tty->driver_data;
1256 int ret; 1252 int ret;
1257 unsigned long flags; 1253 unsigned long flags;
1258 1254
1259 if (serial_paranoia_check(info, tty->name, "rs_write_room")) 1255 if (serial_paranoia_check(info, tty->name, "rs_write_room"))
1260 return 0; 1256 return 0;
1261 1257
@@ -1270,8 +1266,8 @@ static int rs_write_room(struct tty_struct *tty)
1270 1266
1271static int rs_chars_in_buffer(struct tty_struct *tty) 1267static int rs_chars_in_buffer(struct tty_struct *tty)
1272{ 1268{
1273 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 1269 struct esp_struct *info = tty->driver_data;
1274 1270
1275 if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer")) 1271 if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer"))
1276 return 0; 1272 return 0;
1277 return info->xmit_cnt; 1273 return info->xmit_cnt;
@@ -1279,9 +1275,9 @@ static int rs_chars_in_buffer(struct tty_struct *tty)
1279 1275
1280static void rs_flush_buffer(struct tty_struct *tty) 1276static void rs_flush_buffer(struct tty_struct *tty)
1281{ 1277{
1282 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 1278 struct esp_struct *info = tty->driver_data;
1283 unsigned long flags; 1279 unsigned long flags;
1284 1280
1285 if (serial_paranoia_check(info, tty->name, "rs_flush_buffer")) 1281 if (serial_paranoia_check(info, tty->name, "rs_flush_buffer"))
1286 return; 1282 return;
1287 spin_lock_irqsave(&info->lock, flags); 1283 spin_lock_irqsave(&info->lock, flags);
@@ -1293,20 +1289,20 @@ static void rs_flush_buffer(struct tty_struct *tty)
1293/* 1289/*
1294 * ------------------------------------------------------------ 1290 * ------------------------------------------------------------
1295 * rs_throttle() 1291 * rs_throttle()
1296 * 1292 *
1297 * This routine is called by the upper-layer tty layer to signal that 1293 * This routine is called by the upper-layer tty layer to signal that
1298 * incoming characters should be throttled. 1294 * incoming characters should be throttled.
1299 * ------------------------------------------------------------ 1295 * ------------------------------------------------------------
1300 */ 1296 */
1301static void rs_throttle(struct tty_struct * tty) 1297static void rs_throttle(struct tty_struct *tty)
1302{ 1298{
1303 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 1299 struct esp_struct *info = tty->driver_data;
1304 unsigned long flags; 1300 unsigned long flags;
1305#ifdef SERIAL_DEBUG_THROTTLE 1301#ifdef SERIAL_DEBUG_THROTTLE
1306 char buf[64]; 1302 char buf[64];
1307 1303
1308 printk("throttle %s: %d....\n", tty_name(tty, buf), 1304 printk("throttle %s: %d....\n", tty_name(tty, buf),
1309 tty->ldisc.chars_in_buffer(tty)); 1305 tty_chars_in_buffer(tty));
1310#endif 1306#endif
1311 1307
1312 if (serial_paranoia_check(info, tty->name, "rs_throttle")) 1308 if (serial_paranoia_check(info, tty->name, "rs_throttle"))
@@ -1321,20 +1317,20 @@ static void rs_throttle(struct tty_struct * tty)
1321 spin_unlock_irqrestore(&info->lock, flags); 1317 spin_unlock_irqrestore(&info->lock, flags);
1322} 1318}
1323 1319
1324static void rs_unthrottle(struct tty_struct * tty) 1320static void rs_unthrottle(struct tty_struct *tty)
1325{ 1321{
1326 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 1322 struct esp_struct *info = tty->driver_data;
1327 unsigned long flags; 1323 unsigned long flags;
1328#ifdef SERIAL_DEBUG_THROTTLE 1324#ifdef SERIAL_DEBUG_THROTTLE
1329 char buf[64]; 1325 char buf[64];
1330 1326
1331 printk("unthrottle %s: %d....\n", tty_name(tty, buf), 1327 printk(KERN_DEBUG "unthrottle %s: %d....\n", tty_name(tty, buf),
1332 tty->ldisc.chars_in_buffer(tty)); 1328 tty_chars_in_buffer(tty));
1333#endif 1329#endif
1334 1330
1335 if (serial_paranoia_check(info, tty->name, "rs_unthrottle")) 1331 if (serial_paranoia_check(info, tty->name, "rs_unthrottle"))
1336 return; 1332 return;
1337 1333
1338 spin_lock_irqsave(&info->lock, flags); 1334 spin_lock_irqsave(&info->lock, flags);
1339 info->IER |= UART_IER_RDI; 1335 info->IER |= UART_IER_RDI;
1340 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK); 1336 serial_out(info, UART_ESI_CMD1, ESI_SET_SRV_MASK);
@@ -1350,11 +1346,12 @@ static void rs_unthrottle(struct tty_struct * tty)
1350 * ------------------------------------------------------------ 1346 * ------------------------------------------------------------
1351 */ 1347 */
1352 1348
1353static int get_serial_info(struct esp_struct * info, 1349static int get_serial_info(struct esp_struct *info,
1354 struct serial_struct __user *retinfo) 1350 struct serial_struct __user *retinfo)
1355{ 1351{
1356 struct serial_struct tmp; 1352 struct serial_struct tmp;
1357 1353
1354 lock_kernel();
1358 memset(&tmp, 0, sizeof(tmp)); 1355 memset(&tmp, 0, sizeof(tmp));
1359 tmp.type = PORT_16550A; 1356 tmp.type = PORT_16550A;
1360 tmp.line = info->line; 1357 tmp.line = info->line;
@@ -1367,20 +1364,22 @@ static int get_serial_info(struct esp_struct * info,
1367 tmp.closing_wait = info->closing_wait; 1364 tmp.closing_wait = info->closing_wait;
1368 tmp.custom_divisor = info->custom_divisor; 1365 tmp.custom_divisor = info->custom_divisor;
1369 tmp.hub6 = 0; 1366 tmp.hub6 = 0;
1370 if (copy_to_user(retinfo,&tmp,sizeof(*retinfo))) 1367 unlock_kernel();
1368 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
1371 return -EFAULT; 1369 return -EFAULT;
1372 return 0; 1370 return 0;
1373} 1371}
1374 1372
1375static int get_esp_config(struct esp_struct * info, 1373static int get_esp_config(struct esp_struct *info,
1376 struct hayes_esp_config __user *retinfo) 1374 struct hayes_esp_config __user *retinfo)
1377{ 1375{
1378 struct hayes_esp_config tmp; 1376 struct hayes_esp_config tmp;
1379 1377
1380 if (!retinfo) 1378 if (!retinfo)
1381 return -EFAULT; 1379 return -EFAULT;
1382 1380
1383 memset(&tmp, 0, sizeof(tmp)); 1381 memset(&tmp, 0, sizeof(tmp));
1382 lock_kernel();
1384 tmp.rx_timeout = info->config.rx_timeout; 1383 tmp.rx_timeout = info->config.rx_timeout;
1385 tmp.rx_trigger = info->config.rx_trigger; 1384 tmp.rx_trigger = info->config.rx_trigger;
1386 tmp.tx_trigger = info->config.tx_trigger; 1385 tmp.tx_trigger = info->config.tx_trigger;
@@ -1388,11 +1387,12 @@ static int get_esp_config(struct esp_struct * info,
1388 tmp.flow_on = info->config.flow_on; 1387 tmp.flow_on = info->config.flow_on;
1389 tmp.pio_threshold = info->config.pio_threshold; 1388 tmp.pio_threshold = info->config.pio_threshold;
1390 tmp.dma_channel = (info->stat_flags & ESP_STAT_NEVER_DMA ? 0 : dma); 1389 tmp.dma_channel = (info->stat_flags & ESP_STAT_NEVER_DMA ? 0 : dma);
1390 unlock_kernel();
1391 1391
1392 return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0; 1392 return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
1393} 1393}
1394 1394
1395static int set_serial_info(struct esp_struct * info, 1395static int set_serial_info(struct esp_struct *info,
1396 struct serial_struct __user *new_info) 1396 struct serial_struct __user *new_info)
1397{ 1397{
1398 struct serial_struct new_serial; 1398 struct serial_struct new_serial;
@@ -1401,7 +1401,7 @@ static int set_serial_info(struct esp_struct * info,
1401 int retval = 0; 1401 int retval = 0;
1402 struct esp_struct *current_async; 1402 struct esp_struct *current_async;
1403 1403
1404 if (copy_from_user(&new_serial,new_info,sizeof(new_serial))) 1404 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
1405 return -EFAULT; 1405 return -EFAULT;
1406 old_info = *info; 1406 old_info = *info;
1407 1407
@@ -1422,7 +1422,7 @@ static int set_serial_info(struct esp_struct * info,
1422 return -EINVAL; 1422 return -EINVAL;
1423 1423
1424 if (!capable(CAP_SYS_ADMIN)) { 1424 if (!capable(CAP_SYS_ADMIN)) {
1425 if (change_irq || 1425 if (change_irq ||
1426 (new_serial.close_delay != info->close_delay) || 1426 (new_serial.close_delay != info->close_delay) ||
1427 ((new_serial.flags & ~ASYNC_USR_MASK) != 1427 ((new_serial.flags & ~ASYNC_USR_MASK) !=
1428 (info->flags & ~ASYNC_USR_MASK))) 1428 (info->flags & ~ASYNC_USR_MASK)))
@@ -1507,8 +1507,8 @@ static int set_serial_info(struct esp_struct * info,
1507 return retval; 1507 return retval;
1508} 1508}
1509 1509
1510static int set_esp_config(struct esp_struct * info, 1510static int set_esp_config(struct esp_struct *info,
1511 struct hayes_esp_config __user * new_info) 1511 struct hayes_esp_config __user *new_info)
1512{ 1512{
1513 struct hayes_esp_config new_config; 1513 struct hayes_esp_config new_config;
1514 unsigned int change_dma; 1514 unsigned int change_dma;
@@ -1550,7 +1550,6 @@ static int set_esp_config(struct esp_struct * info,
1550 if (new_config.dma_channel) { 1550 if (new_config.dma_channel) {
1551 /* PIO mode to DMA mode transition OR */ 1551 /* PIO mode to DMA mode transition OR */
1552 /* change current DMA channel */ 1552 /* change current DMA channel */
1553
1554 current_async = ports; 1553 current_async = ports;
1555 1554
1556 while (current_async) { 1555 while (current_async) {
@@ -1559,16 +1558,15 @@ static int set_esp_config(struct esp_struct * info,
1559 return -EBUSY; 1558 return -EBUSY;
1560 } else if (current_async->count) 1559 } else if (current_async->count)
1561 return -EBUSY; 1560 return -EBUSY;
1562 1561
1563 current_async = 1562 current_async = current_async->next_port;
1564 current_async->next_port;
1565 } 1563 }
1566 1564
1567 shutdown(info); 1565 shutdown(info);
1568 dma = new_config.dma_channel; 1566 dma = new_config.dma_channel;
1569 info->stat_flags &= ~ESP_STAT_NEVER_DMA; 1567 info->stat_flags &= ~ESP_STAT_NEVER_DMA;
1570 1568
1571 /* all ports must use the same DMA channel */ 1569 /* all ports must use the same DMA channel */
1572 1570
1573 spin_lock_irqsave(&info->lock, flags); 1571 spin_lock_irqsave(&info->lock, flags);
1574 current_async = ports; 1572 current_async = ports;
@@ -1580,7 +1578,6 @@ static int set_esp_config(struct esp_struct * info,
1580 spin_unlock_irqrestore(&info->lock, flags); 1578 spin_unlock_irqrestore(&info->lock, flags);
1581 } else { 1579 } else {
1582 /* DMA mode to PIO mode only */ 1580 /* DMA mode to PIO mode only */
1583
1584 if (info->count > 1) 1581 if (info->count > 1)
1585 return -EBUSY; 1582 return -EBUSY;
1586 1583
@@ -1596,8 +1593,6 @@ static int set_esp_config(struct esp_struct * info,
1596 1593
1597 if ((new_config.flow_off != info->config.flow_off) || 1594 if ((new_config.flow_off != info->config.flow_off) ||
1598 (new_config.flow_on != info->config.flow_on)) { 1595 (new_config.flow_on != info->config.flow_on)) {
1599 unsigned long flags;
1600
1601 info->config.flow_off = new_config.flow_off; 1596 info->config.flow_off = new_config.flow_off;
1602 info->config.flow_on = new_config.flow_on; 1597 info->config.flow_on = new_config.flow_on;
1603 1598
@@ -1612,8 +1607,6 @@ static int set_esp_config(struct esp_struct * info,
1612 1607
1613 if ((new_config.rx_trigger != info->config.rx_trigger) || 1608 if ((new_config.rx_trigger != info->config.rx_trigger) ||
1614 (new_config.tx_trigger != info->config.tx_trigger)) { 1609 (new_config.tx_trigger != info->config.tx_trigger)) {
1615 unsigned long flags;
1616
1617 info->config.rx_trigger = new_config.rx_trigger; 1610 info->config.rx_trigger = new_config.rx_trigger;
1618 info->config.tx_trigger = new_config.tx_trigger; 1611 info->config.tx_trigger = new_config.tx_trigger;
1619 spin_lock_irqsave(&info->lock, flags); 1612 spin_lock_irqsave(&info->lock, flags);
@@ -1628,8 +1621,6 @@ static int set_esp_config(struct esp_struct * info,
1628 } 1621 }
1629 1622
1630 if (new_config.rx_timeout != info->config.rx_timeout) { 1623 if (new_config.rx_timeout != info->config.rx_timeout) {
1631 unsigned long flags;
1632
1633 info->config.rx_timeout = new_config.rx_timeout; 1624 info->config.rx_timeout = new_config.rx_timeout;
1634 spin_lock_irqsave(&info->lock, flags); 1625 spin_lock_irqsave(&info->lock, flags);
1635 1626
@@ -1657,9 +1648,9 @@ static int set_esp_config(struct esp_struct * info,
1657 * release the bus after transmitting. This must be done when 1648 * release the bus after transmitting. This must be done when
1658 * the transmit shift register is empty, not be done when the 1649 * the transmit shift register is empty, not be done when the
1659 * transmit holding register is empty. This functionality 1650 * transmit holding register is empty. This functionality
1660 * allows an RS485 driver to be written in user space. 1651 * allows an RS485 driver to be written in user space.
1661 */ 1652 */
1662static int get_lsr_info(struct esp_struct * info, unsigned int __user *value) 1653static int get_lsr_info(struct esp_struct *info, unsigned int __user *value)
1663{ 1654{
1664 unsigned char status; 1655 unsigned char status;
1665 unsigned int result; 1656 unsigned int result;
@@ -1670,17 +1661,17 @@ static int get_lsr_info(struct esp_struct * info, unsigned int __user *value)
1670 status = serial_in(info, UART_ESI_STAT1); 1661 status = serial_in(info, UART_ESI_STAT1);
1671 spin_unlock_irqrestore(&info->lock, flags); 1662 spin_unlock_irqrestore(&info->lock, flags);
1672 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0); 1663 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
1673 return put_user(result,value); 1664 return put_user(result, value);
1674} 1665}
1675 1666
1676 1667
1677static int esp_tiocmget(struct tty_struct *tty, struct file *file) 1668static int esp_tiocmget(struct tty_struct *tty, struct file *file)
1678{ 1669{
1679 struct esp_struct * info = (struct esp_struct *)tty->driver_data; 1670 struct esp_struct *info = tty->driver_data;
1680 unsigned char control, status; 1671 unsigned char control, status;
1681 unsigned long flags; 1672 unsigned long flags;
1682 1673
1683 if (serial_paranoia_check(info, tty->name, __FUNCTION__)) 1674 if (serial_paranoia_check(info, tty->name, __func__))
1684 return -ENODEV; 1675 return -ENODEV;
1685 if (tty->flags & (1 << TTY_IO_ERROR)) 1676 if (tty->flags & (1 << TTY_IO_ERROR))
1686 return -EIO; 1677 return -EIO;
@@ -1703,10 +1694,10 @@ static int esp_tiocmget(struct tty_struct *tty, struct file *file)
1703static int esp_tiocmset(struct tty_struct *tty, struct file *file, 1694static int esp_tiocmset(struct tty_struct *tty, struct file *file,
1704 unsigned int set, unsigned int clear) 1695 unsigned int set, unsigned int clear)
1705{ 1696{
1706 struct esp_struct * info = (struct esp_struct *)tty->driver_data; 1697 struct esp_struct *info = tty->driver_data;
1707 unsigned long flags; 1698 unsigned long flags;
1708 1699
1709 if (serial_paranoia_check(info, tty->name, __FUNCTION__)) 1700 if (serial_paranoia_check(info, tty->name, __func__))
1710 return -ENODEV; 1701 return -ENODEV;
1711 if (tty->flags & (1 << TTY_IO_ERROR)) 1702 if (tty->flags & (1 << TTY_IO_ERROR))
1712 return -EIO; 1703 return -EIO;
@@ -1736,9 +1727,9 @@ static int esp_tiocmset(struct tty_struct *tty, struct file *file,
1736 */ 1727 */
1737static void esp_break(struct tty_struct *tty, int break_state) 1728static void esp_break(struct tty_struct *tty, int break_state)
1738{ 1729{
1739 struct esp_struct * info = (struct esp_struct *)tty->driver_data; 1730 struct esp_struct *info = tty->driver_data;
1740 unsigned long flags; 1731 unsigned long flags;
1741 1732
1742 if (serial_paranoia_check(info, tty->name, "esp_break")) 1733 if (serial_paranoia_check(info, tty->name, "esp_break"))
1743 return; 1734 return;
1744 1735
@@ -1758,14 +1749,15 @@ static void esp_break(struct tty_struct *tty, int break_state)
1758 } 1749 }
1759} 1750}
1760 1751
1761static int rs_ioctl(struct tty_struct *tty, struct file * file, 1752static int rs_ioctl(struct tty_struct *tty, struct file *file,
1762 unsigned int cmd, unsigned long arg) 1753 unsigned int cmd, unsigned long arg)
1763{ 1754{
1764 struct esp_struct * info = (struct esp_struct *)tty->driver_data; 1755 struct esp_struct *info = tty->driver_data;
1765 struct async_icount cprev, cnow; /* kernel counter temps */ 1756 struct async_icount cprev, cnow; /* kernel counter temps */
1766 struct serial_icounter_struct __user *p_cuser; /* user space */ 1757 struct serial_icounter_struct __user *p_cuser; /* user space */
1767 void __user *argp = (void __user *)arg; 1758 void __user *argp = (void __user *)arg;
1768 unsigned long flags; 1759 unsigned long flags;
1760 int ret;
1769 1761
1770 if (serial_paranoia_check(info, tty->name, "rs_ioctl")) 1762 if (serial_paranoia_check(info, tty->name, "rs_ioctl"))
1771 return -ENODEV; 1763 return -ENODEV;
@@ -1778,97 +1770,93 @@ static int rs_ioctl(struct tty_struct *tty, struct file * file,
1778 if (tty->flags & (1 << TTY_IO_ERROR)) 1770 if (tty->flags & (1 << TTY_IO_ERROR))
1779 return -EIO; 1771 return -EIO;
1780 } 1772 }
1781
1782 switch (cmd) {
1783 case TIOCGSERIAL:
1784 return get_serial_info(info, argp);
1785 case TIOCSSERIAL:
1786 return set_serial_info(info, argp);
1787 case TIOCSERCONFIG:
1788 /* do not reconfigure after initial configuration */
1789 return 0;
1790
1791 case TIOCSERGWILD:
1792 return put_user(0L, (unsigned long __user *)argp);
1793 1773
1794 case TIOCSERGETLSR: /* Get line status register */ 1774 switch (cmd) {
1795 return get_lsr_info(info, argp); 1775 case TIOCGSERIAL:
1796 1776 return get_serial_info(info, argp);
1797 case TIOCSERSWILD: 1777 case TIOCSSERIAL:
1798 if (!capable(CAP_SYS_ADMIN)) 1778 lock_kernel();
1799 return -EPERM; 1779 ret = set_serial_info(info, argp);
1800 return 0; 1780 unlock_kernel();
1801 1781 return ret;
1802 /* 1782 case TIOCSERGWILD:
1803 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change 1783 return put_user(0L, (unsigned long __user *)argp);
1804 * - mask passed in arg for lines of interest 1784 case TIOCSERGETLSR: /* Get line status register */
1805 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking) 1785 return get_lsr_info(info, argp);
1806 * Caller should use TIOCGICOUNT to see which one it was 1786 case TIOCSERSWILD:
1807 */ 1787 if (!capable(CAP_SYS_ADMIN))
1808 case TIOCMIWAIT: 1788 return -EPERM;
1789 return 0;
1790 /*
1791 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1792 * - mask passed in arg for lines of interest
1793 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1794 * Caller should use TIOCGICOUNT to see which one it was
1795 */
1796 case TIOCMIWAIT:
1797 spin_lock_irqsave(&info->lock, flags);
1798 cprev = info->icount; /* note the counters on entry */
1799 spin_unlock_irqrestore(&info->lock, flags);
1800 while (1) {
1801 /* FIXME: convert to new style wakeup */
1802 interruptible_sleep_on(&info->delta_msr_wait);
1803 /* see if a signal did it */
1804 if (signal_pending(current))
1805 return -ERESTARTSYS;
1809 spin_lock_irqsave(&info->lock, flags); 1806 spin_lock_irqsave(&info->lock, flags);
1810 cprev = info->icount; /* note the counters on entry */ 1807 cnow = info->icount; /* atomic copy */
1811 spin_unlock_irqrestore(&info->lock, flags); 1808 spin_unlock_irqrestore(&info->lock, flags);
1812 while (1) { 1809 if (cnow.rng == cprev.rng &&
1813 /* FIXME: convert to new style wakeup */ 1810 cnow.dsr == cprev.dsr &&
1814 interruptible_sleep_on(&info->delta_msr_wait); 1811 cnow.dcd == cprev.dcd &&
1815 /* see if a signal did it */ 1812 cnow.cts == cprev.cts)
1816 if (signal_pending(current)) 1813 return -EIO; /* no change => error */
1817 return -ERESTARTSYS; 1814 if (((arg & TIOCM_RNG) &&
1818 spin_lock_irqsave(&info->lock, flags); 1815 (cnow.rng != cprev.rng)) ||
1819 cnow = info->icount; /* atomic copy */ 1816 ((arg & TIOCM_DSR) &&
1820 spin_unlock_irqrestore(&info->lock, flags); 1817 (cnow.dsr != cprev.dsr)) ||
1821 if (cnow.rng == cprev.rng && 1818 ((arg & TIOCM_CD) &&
1822 cnow.dsr == cprev.dsr && 1819 (cnow.dcd != cprev.dcd)) ||
1823 cnow.dcd == cprev.dcd && 1820 ((arg & TIOCM_CTS) &&
1824 cnow.cts == cprev.cts) 1821 (cnow.cts != cprev.cts))) {
1825 return -EIO; /* no change => error */ 1822 return 0;
1826 if (((arg & TIOCM_RNG) &&
1827 (cnow.rng != cprev.rng)) ||
1828 ((arg & TIOCM_DSR) &&
1829 (cnow.dsr != cprev.dsr)) ||
1830 ((arg & TIOCM_CD) &&
1831 (cnow.dcd != cprev.dcd)) ||
1832 ((arg & TIOCM_CTS) &&
1833 (cnow.cts != cprev.cts)) ) {
1834 return 0;
1835 }
1836 cprev = cnow;
1837 } 1823 }
1838 /* NOTREACHED */ 1824 cprev = cnow;
1839 1825 }
1840 /* 1826 /* NOTREACHED */
1841 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS) 1827 /*
1842 * Return: write counters to the user passed counter struct 1828 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1843 * NB: both 1->0 and 0->1 transitions are counted except for 1829 * Return: write counters to the user passed counter struct
1844 * RI where only 0->1 is counted. 1830 * NB: both 1->0 and 0->1 transitions are counted except for
1845 */ 1831 * RI where only 0->1 is counted.
1846 case TIOCGICOUNT: 1832 */
1847 spin_lock_irqsave(&info->lock, flags); 1833 case TIOCGICOUNT:
1848 cnow = info->icount; 1834 spin_lock_irqsave(&info->lock, flags);
1849 spin_unlock_irqrestore(&info->lock, flags); 1835 cnow = info->icount;
1850 p_cuser = argp; 1836 spin_unlock_irqrestore(&info->lock, flags);
1851 if (put_user(cnow.cts, &p_cuser->cts) || 1837 p_cuser = argp;
1852 put_user(cnow.dsr, &p_cuser->dsr) || 1838 if (put_user(cnow.cts, &p_cuser->cts) ||
1853 put_user(cnow.rng, &p_cuser->rng) || 1839 put_user(cnow.dsr, &p_cuser->dsr) ||
1854 put_user(cnow.dcd, &p_cuser->dcd)) 1840 put_user(cnow.rng, &p_cuser->rng) ||
1855 return -EFAULT; 1841 put_user(cnow.dcd, &p_cuser->dcd))
1856 1842 return -EFAULT;
1857 return 0; 1843 return 0;
1858 case TIOCGHAYESESP: 1844 case TIOCGHAYESESP:
1859 return get_esp_config(info, argp); 1845 return get_esp_config(info, argp);
1860 case TIOCSHAYESESP: 1846 case TIOCSHAYESESP:
1861 return set_esp_config(info, argp); 1847 lock_kernel();
1862 1848 ret = set_esp_config(info, argp);
1863 default: 1849 unlock_kernel();
1864 return -ENOIOCTLCMD; 1850 return ret;
1865 } 1851 default:
1852 return -ENOIOCTLCMD;
1853 }
1866 return 0; 1854 return 0;
1867} 1855}
1868 1856
1869static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios) 1857static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1870{ 1858{
1871 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 1859 struct esp_struct *info = tty->driver_data;
1872 unsigned long flags; 1860 unsigned long flags;
1873 1861
1874 change_speed(info); 1862 change_speed(info);
@@ -1905,32 +1893,33 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1905/* 1893/*
1906 * ------------------------------------------------------------ 1894 * ------------------------------------------------------------
1907 * rs_close() 1895 * rs_close()
1908 * 1896 *
1909 * This routine is called when the serial port gets closed. First, we 1897 * This routine is called when the serial port gets closed. First, we
1910 * wait for the last remaining data to be sent. Then, we unlink its 1898 * wait for the last remaining data to be sent. Then, we unlink its
1911 * async structure from the interrupt chain if necessary, and we free 1899 * async structure from the interrupt chain if necessary, and we free
1912 * that IRQ if nothing is left in the chain. 1900 * that IRQ if nothing is left in the chain.
1913 * ------------------------------------------------------------ 1901 * ------------------------------------------------------------
1914 */ 1902 */
1915static void rs_close(struct tty_struct *tty, struct file * filp) 1903static void rs_close(struct tty_struct *tty, struct file *filp)
1916{ 1904{
1917 struct esp_struct * info = (struct esp_struct *)tty->driver_data; 1905 struct esp_struct *info = tty->driver_data;
1918 unsigned long flags; 1906 unsigned long flags;
1919 1907
1920 if (!info || serial_paranoia_check(info, tty->name, "rs_close")) 1908 if (!info || serial_paranoia_check(info, tty->name, "rs_close"))
1921 return; 1909 return;
1922 1910
1923 spin_lock_irqsave(&info->lock, flags); 1911 spin_lock_irqsave(&info->lock, flags);
1924 1912
1925 if (tty_hung_up_p(filp)) { 1913 if (tty_hung_up_p(filp)) {
1926 DBG_CNT("before DEC-hung"); 1914 DBG_CNT("before DEC-hung");
1927 goto out; 1915 goto out;
1928 } 1916 }
1929 1917
1930#ifdef SERIAL_DEBUG_OPEN 1918#ifdef SERIAL_DEBUG_OPEN
1931 printk("rs_close ttys%d, count = %d\n", info->line, info->count); 1919 printk(KERN_DEBUG "rs_close ttys%d, count = %d\n",
1920 info->line, info->count);
1932#endif 1921#endif
1933 if ((tty->count == 1) && (info->count != 1)) { 1922 if (tty->count == 1 && info->count != 1) {
1934 /* 1923 /*
1935 * Uh, oh. tty->count is 1, which means that the tty 1924 * Uh, oh. tty->count is 1, which means that the tty
1936 * structure will be freed. Info->count should always 1925 * structure will be freed. Info->count should always
@@ -1938,12 +1927,11 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
1938 * one, we've got real problems, since it means the 1927 * one, we've got real problems, since it means the
1939 * serial port won't be shutdown. 1928 * serial port won't be shutdown.
1940 */ 1929 */
1941 printk("rs_close: bad serial port count; tty->count is 1, " 1930 printk(KERN_DEBUG "rs_close: bad serial port count; tty->count is 1, info->count is %d\n", info->count);
1942 "info->count is %d\n", info->count);
1943 info->count = 1; 1931 info->count = 1;
1944 } 1932 }
1945 if (--info->count < 0) { 1933 if (--info->count < 0) {
1946 printk("rs_close: bad serial port count for ttys%d: %d\n", 1934 printk(KERN_ERR "rs_close: bad serial port count for ttys%d: %d\n",
1947 info->line, info->count); 1935 info->line, info->count);
1948 info->count = 0; 1936 info->count = 0;
1949 } 1937 }
@@ -1955,7 +1943,7 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
1955 1943
1956 spin_unlock_irqrestore(&info->lock, flags); 1944 spin_unlock_irqrestore(&info->lock, flags);
1957 /* 1945 /*
1958 * Now we wait for the transmit buffer to clear; and we notify 1946 * Now we wait for the transmit buffer to clear; and we notify
1959 * the line discipline to only process XON/XOFF characters. 1947 * the line discipline to only process XON/XOFF characters.
1960 */ 1948 */
1961 tty->closing = 1; 1949 tty->closing = 1;
@@ -1990,16 +1978,14 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
1990 rs_wait_until_sent(tty, info->timeout); 1978 rs_wait_until_sent(tty, info->timeout);
1991 } 1979 }
1992 shutdown(info); 1980 shutdown(info);
1993 if (tty->driver->flush_buffer) 1981 rs_flush_buffer(tty);
1994 tty->driver->flush_buffer(tty);
1995 tty_ldisc_flush(tty); 1982 tty_ldisc_flush(tty);
1996 tty->closing = 0; 1983 tty->closing = 0;
1997 info->tty = NULL; 1984 info->tty = NULL;
1998 1985
1999 if (info->blocked_open) { 1986 if (info->blocked_open) {
2000 if (info->close_delay) { 1987 if (info->close_delay)
2001 msleep_interruptible(jiffies_to_msecs(info->close_delay)); 1988 msleep_interruptible(jiffies_to_msecs(info->close_delay));
2002 }
2003 wake_up_interruptible(&info->open_wait); 1989 wake_up_interruptible(&info->open_wait);
2004 } 1990 }
2005 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 1991 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
@@ -2012,7 +1998,7 @@ out:
2012 1998
2013static void rs_wait_until_sent(struct tty_struct *tty, int timeout) 1999static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
2014{ 2000{
2015 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 2001 struct esp_struct *info = tty->driver_data;
2016 unsigned long orig_jiffies, char_time; 2002 unsigned long orig_jiffies, char_time;
2017 unsigned long flags; 2003 unsigned long flags;
2018 2004
@@ -2036,10 +2022,10 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
2036 msleep_interruptible(jiffies_to_msecs(char_time)); 2022 msleep_interruptible(jiffies_to_msecs(char_time));
2037 2023
2038 if (signal_pending(current)) 2024 if (signal_pending(current))
2039 break; 2025 return;
2040 2026
2041 if (timeout && time_after(jiffies, orig_jiffies + timeout)) 2027 if (timeout && time_after(jiffies, orig_jiffies + timeout))
2042 break; 2028 return;
2043 2029
2044 spin_lock_irqsave(&info->lock, flags); 2030 spin_lock_irqsave(&info->lock, flags);
2045 serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND); 2031 serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND);
@@ -2054,11 +2040,11 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
2054 */ 2040 */
2055static void esp_hangup(struct tty_struct *tty) 2041static void esp_hangup(struct tty_struct *tty)
2056{ 2042{
2057 struct esp_struct * info = (struct esp_struct *)tty->driver_data; 2043 struct esp_struct *info = tty->driver_data;
2058 2044
2059 if (serial_paranoia_check(info, tty->name, "esp_hangup")) 2045 if (serial_paranoia_check(info, tty->name, "esp_hangup"))
2060 return; 2046 return;
2061 2047
2062 rs_flush_buffer(tty); 2048 rs_flush_buffer(tty);
2063 shutdown(info); 2049 shutdown(info);
2064 info->count = 0; 2050 info->count = 0;
@@ -2072,7 +2058,7 @@ static void esp_hangup(struct tty_struct *tty)
2072 * esp_open() and friends 2058 * esp_open() and friends
2073 * ------------------------------------------------------------ 2059 * ------------------------------------------------------------
2074 */ 2060 */
2075static int block_til_ready(struct tty_struct *tty, struct file * filp, 2061static int block_til_ready(struct tty_struct *tty, struct file *filp,
2076 struct esp_struct *info) 2062 struct esp_struct *info)
2077{ 2063{
2078 DECLARE_WAITQUEUE(wait, current); 2064 DECLARE_WAITQUEUE(wait, current);
@@ -2121,11 +2107,11 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
2121 retval = 0; 2107 retval = 0;
2122 add_wait_queue(&info->open_wait, &wait); 2108 add_wait_queue(&info->open_wait, &wait);
2123#ifdef SERIAL_DEBUG_OPEN 2109#ifdef SERIAL_DEBUG_OPEN
2124 printk("block_til_ready before block: ttys%d, count = %d\n", 2110 printk(KERN_DEBUG "block_til_ready before block: ttys%d, count = %d\n",
2125 info->line, info->count); 2111 info->line, info->count);
2126#endif 2112#endif
2127 spin_lock_irqsave(&info->lock, flags); 2113 spin_lock_irqsave(&info->lock, flags);
2128 if (!tty_hung_up_p(filp)) 2114 if (!tty_hung_up_p(filp))
2129 info->count--; 2115 info->count--;
2130 info->blocked_open++; 2116 info->blocked_open++;
2131 while (1) { 2117 while (1) {
@@ -2147,7 +2133,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
2147 if (info->flags & ASYNC_HUP_NOTIFY) 2133 if (info->flags & ASYNC_HUP_NOTIFY)
2148 retval = -EAGAIN; 2134 retval = -EAGAIN;
2149 else 2135 else
2150 retval = -ERESTARTSYS; 2136 retval = -ERESTARTSYS;
2151#else 2137#else
2152 retval = -EAGAIN; 2138 retval = -EAGAIN;
2153#endif 2139#endif
@@ -2166,7 +2152,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
2166 break; 2152 break;
2167 } 2153 }
2168#ifdef SERIAL_DEBUG_OPEN 2154#ifdef SERIAL_DEBUG_OPEN
2169 printk("block_til_ready blocking: ttys%d, count = %d\n", 2155 printk(KERN_DEBUG "block_til_ready blocking: ttys%d, count = %d\n",
2170 info->line, info->count); 2156 info->line, info->count);
2171#endif 2157#endif
2172 spin_unlock_irqrestore(&info->lock, flags); 2158 spin_unlock_irqrestore(&info->lock, flags);
@@ -2180,14 +2166,14 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
2180 info->blocked_open--; 2166 info->blocked_open--;
2181 spin_unlock_irqrestore(&info->lock, flags); 2167 spin_unlock_irqrestore(&info->lock, flags);
2182#ifdef SERIAL_DEBUG_OPEN 2168#ifdef SERIAL_DEBUG_OPEN
2183 printk("block_til_ready after blocking: ttys%d, count = %d\n", 2169 printk(KERN_DEBUG "block_til_ready after blocking: ttys%d, count = %d\n",
2184 info->line, info->count); 2170 info->line, info->count);
2185#endif 2171#endif
2186 if (retval) 2172 if (retval)
2187 return retval; 2173 return retval;
2188 info->flags |= ASYNC_NORMAL_ACTIVE; 2174 info->flags |= ASYNC_NORMAL_ACTIVE;
2189 return 0; 2175 return 0;
2190} 2176}
2191 2177
2192/* 2178/*
2193 * This routine is called whenever a serial port is opened. It 2179 * This routine is called whenever a serial port is opened. It
@@ -2195,7 +2181,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
2195 * the IRQ chain. It also performs the serial-specific 2181 * the IRQ chain. It also performs the serial-specific
2196 * initialization for the tty structure. 2182 * initialization for the tty structure.
2197 */ 2183 */
2198static int esp_open(struct tty_struct *tty, struct file * filp) 2184static int esp_open(struct tty_struct *tty, struct file *filp)
2199{ 2185{
2200 struct esp_struct *info; 2186 struct esp_struct *info;
2201 int retval, line; 2187 int retval, line;
@@ -2218,7 +2204,7 @@ static int esp_open(struct tty_struct *tty, struct file * filp)
2218 } 2204 }
2219 2205
2220#ifdef SERIAL_DEBUG_OPEN 2206#ifdef SERIAL_DEBUG_OPEN
2221 printk("esp_open %s, count = %d\n", tty->name, info->count); 2207 printk(KERN_DEBUG "esp_open %s, count = %d\n", tty->name, info->count);
2222#endif 2208#endif
2223 spin_lock_irqsave(&info->lock, flags); 2209 spin_lock_irqsave(&info->lock, flags);
2224 info->count++; 2210 info->count++;
@@ -2226,7 +2212,7 @@ static int esp_open(struct tty_struct *tty, struct file * filp)
2226 info->tty = tty; 2212 info->tty = tty;
2227 2213
2228 spin_unlock_irqrestore(&info->lock, flags); 2214 spin_unlock_irqrestore(&info->lock, flags);
2229 2215
2230 /* 2216 /*
2231 * Start up serial port 2217 * Start up serial port
2232 */ 2218 */
@@ -2237,14 +2223,13 @@ static int esp_open(struct tty_struct *tty, struct file * filp)
2237 retval = block_til_ready(tty, filp, info); 2223 retval = block_til_ready(tty, filp, info);
2238 if (retval) { 2224 if (retval) {
2239#ifdef SERIAL_DEBUG_OPEN 2225#ifdef SERIAL_DEBUG_OPEN
2240 printk("esp_open returning after block_til_ready with %d\n", 2226 printk(KERN_DEBUG "esp_open returning after block_til_ready with %d\n",
2241 retval); 2227 retval);
2242#endif 2228#endif
2243 return retval; 2229 return retval;
2244 } 2230 }
2245
2246#ifdef SERIAL_DEBUG_OPEN 2231#ifdef SERIAL_DEBUG_OPEN
2247 printk("esp_open %s successful...", tty->name); 2232 printk(KERN_DEBUG "esp_open %s successful...", tty->name);
2248#endif 2233#endif
2249 return 0; 2234 return 0;
2250} 2235}
@@ -2262,10 +2247,10 @@ static int esp_open(struct tty_struct *tty, struct file * filp)
2262 * number, and identifies which options were configured into this 2247 * number, and identifies which options were configured into this
2263 * driver. 2248 * driver.
2264 */ 2249 */
2265 2250
2266static inline void show_serial_version(void) 2251static void show_serial_version(void)
2267{ 2252{
2268 printk(KERN_INFO "%s version %s (DMA %u)\n", 2253 printk(KERN_INFO "%s version %s (DMA %u)\n",
2269 serial_name, serial_version, dma); 2254 serial_name, serial_version, dma);
2270} 2255}
2271 2256
@@ -2273,7 +2258,7 @@ static inline void show_serial_version(void)
2273 * This routine is called by espserial_init() to initialize a specific serial 2258 * This routine is called by espserial_init() to initialize a specific serial
2274 * port. 2259 * port.
2275 */ 2260 */
2276static inline int autoconfig(struct esp_struct * info) 2261static int autoconfig(struct esp_struct *info)
2277{ 2262{
2278 int port_detected = 0; 2263 int port_detected = 0;
2279 unsigned long flags; 2264 unsigned long flags;
@@ -2349,14 +2334,14 @@ static const struct tty_operations esp_ops = {
2349static int __init espserial_init(void) 2334static int __init espserial_init(void)
2350{ 2335{
2351 int i, offset; 2336 int i, offset;
2352 struct esp_struct * info; 2337 struct esp_struct *info;
2353 struct esp_struct *last_primary = NULL; 2338 struct esp_struct *last_primary = NULL;
2354 int esp[] = {0x100,0x140,0x180,0x200,0x240,0x280,0x300,0x380}; 2339 int esp[] = { 0x100, 0x140, 0x180, 0x200, 0x240, 0x280, 0x300, 0x380 };
2355 2340
2356 esp_driver = alloc_tty_driver(NR_PORTS); 2341 esp_driver = alloc_tty_driver(NR_PORTS);
2357 if (!esp_driver) 2342 if (!esp_driver)
2358 return -ENOMEM; 2343 return -ENOMEM;
2359 2344
2360 for (i = 0; i < NR_PRIMARY; i++) { 2345 for (i = 0; i < NR_PRIMARY; i++) {
2361 if (irq[i] != 0) { 2346 if (irq[i] != 0) {
2362 if ((irq[i] < 2) || (irq[i] > 15) || (irq[i] == 6) || 2347 if ((irq[i] < 2) || (irq[i] > 15) || (irq[i] == 6) ||
@@ -2378,20 +2363,20 @@ static int __init espserial_init(void)
2378 2363
2379 if ((flow_off < 1) || (flow_off > 1023)) 2364 if ((flow_off < 1) || (flow_off > 1023))
2380 flow_off = 1016; 2365 flow_off = 1016;
2381 2366
2382 if ((flow_on < 1) || (flow_on > 1023)) 2367 if ((flow_on < 1) || (flow_on > 1023))
2383 flow_on = 944; 2368 flow_on = 944;
2384 2369
2385 if ((rx_timeout < 0) || (rx_timeout > 255)) 2370 if ((rx_timeout < 0) || (rx_timeout > 255))
2386 rx_timeout = 128; 2371 rx_timeout = 128;
2387 2372
2388 if (flow_on >= flow_off) 2373 if (flow_on >= flow_off)
2389 flow_on = flow_off - 1; 2374 flow_on = flow_off - 1;
2390 2375
2391 show_serial_version(); 2376 show_serial_version();
2392 2377
2393 /* Initialize the tty_driver structure */ 2378 /* Initialize the tty_driver structure */
2394 2379
2395 esp_driver->owner = THIS_MODULE; 2380 esp_driver->owner = THIS_MODULE;
2396 esp_driver->name = "ttyP"; 2381 esp_driver->name = "ttyP";
2397 esp_driver->major = ESP_IN_MAJOR; 2382 esp_driver->major = ESP_IN_MAJOR;
@@ -2401,10 +2386,11 @@ static int __init espserial_init(void)
2401 esp_driver->init_termios = tty_std_termios; 2386 esp_driver->init_termios = tty_std_termios;
2402 esp_driver->init_termios.c_cflag = 2387 esp_driver->init_termios.c_cflag =
2403 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 2388 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2389 esp_driver->init_termios.c_ispeed = 9600;
2390 esp_driver->init_termios.c_ospeed = 9600;
2404 esp_driver->flags = TTY_DRIVER_REAL_RAW; 2391 esp_driver->flags = TTY_DRIVER_REAL_RAW;
2405 tty_set_operations(esp_driver, &esp_ops); 2392 tty_set_operations(esp_driver, &esp_ops);
2406 if (tty_register_driver(esp_driver)) 2393 if (tty_register_driver(esp_driver)) {
2407 {
2408 printk(KERN_ERR "Couldn't register esp serial driver"); 2394 printk(KERN_ERR "Couldn't register esp serial driver");
2409 put_tty_driver(esp_driver); 2395 put_tty_driver(esp_driver);
2410 return 1; 2396 return 1;
@@ -2412,8 +2398,7 @@ static int __init espserial_init(void)
2412 2398
2413 info = kzalloc(sizeof(struct esp_struct), GFP_KERNEL); 2399 info = kzalloc(sizeof(struct esp_struct), GFP_KERNEL);
2414 2400
2415 if (!info) 2401 if (!info) {
2416 {
2417 printk(KERN_ERR "Couldn't allocate memory for esp serial device information\n"); 2402 printk(KERN_ERR "Couldn't allocate memory for esp serial device information\n");
2418 tty_unregister_driver(esp_driver); 2403 tty_unregister_driver(esp_driver);
2419 put_tty_driver(esp_driver); 2404 put_tty_driver(esp_driver);
@@ -2476,10 +2461,8 @@ static int __init espserial_init(void)
2476 info->stat_flags |= ESP_STAT_NEVER_DMA; 2461 info->stat_flags |= ESP_STAT_NEVER_DMA;
2477 2462
2478 info = kzalloc(sizeof(struct esp_struct), GFP_KERNEL); 2463 info = kzalloc(sizeof(struct esp_struct), GFP_KERNEL);
2479 if (!info) 2464 if (!info) {
2480 { 2465 printk(KERN_ERR "Couldn't allocate memory for esp serial device information\n");
2481 printk(KERN_ERR "Couldn't allocate memory for esp serial device information\n");
2482
2483 /* allow use of the already detected ports */ 2466 /* allow use of the already detected ports */
2484 return 0; 2467 return 0;
2485 } 2468 }
@@ -2503,22 +2486,20 @@ static int __init espserial_init(void)
2503 return 0; 2486 return 0;
2504} 2487}
2505 2488
2506static void __exit espserial_exit(void) 2489static void __exit espserial_exit(void)
2507{ 2490{
2508 int e1; 2491 int e1;
2509 struct esp_struct *temp_async; 2492 struct esp_struct *temp_async;
2510 struct esp_pio_buffer *pio_buf; 2493 struct esp_pio_buffer *pio_buf;
2511 2494
2512 /* printk("Unloading %s: version %s\n", serial_name, serial_version); */ 2495 e1 = tty_unregister_driver(esp_driver);
2513 if ((e1 = tty_unregister_driver(esp_driver))) 2496 if (e1)
2514 printk("SERIAL: failed to unregister serial driver (%d)\n", 2497 printk(KERN_ERR "esp: failed to unregister driver (%d)\n", e1);
2515 e1);
2516 put_tty_driver(esp_driver); 2498 put_tty_driver(esp_driver);
2517 2499
2518 while (ports) { 2500 while (ports) {
2519 if (ports->port) { 2501 if (ports->port)
2520 release_region(ports->port, REGION_SIZE); 2502 release_region(ports->port, REGION_SIZE);
2521 }
2522 temp_async = ports->next_port; 2503 temp_async = ports->next_port;
2523 kfree(ports); 2504 kfree(ports);
2524 ports = temp_async; 2505 ports = temp_async;
diff --git a/drivers/char/generic_serial.c b/drivers/char/generic_serial.c
index 7ed7da1d99cf..252f73e48596 100644
--- a/drivers/char/generic_serial.c
+++ b/drivers/char/generic_serial.c
@@ -40,27 +40,27 @@ static int gs_debug;
40#define gs_dprintk(f, str...) /* nothing */ 40#define gs_dprintk(f, str...) /* nothing */
41#endif 41#endif
42 42
43#define func_enter() gs_dprintk (GS_DEBUG_FLOW, "gs: enter %s\n", __FUNCTION__) 43#define func_enter() gs_dprintk (GS_DEBUG_FLOW, "gs: enter %s\n", __func__)
44#define func_exit() gs_dprintk (GS_DEBUG_FLOW, "gs: exit %s\n", __FUNCTION__) 44#define func_exit() gs_dprintk (GS_DEBUG_FLOW, "gs: exit %s\n", __func__)
45 45
46#define RS_EVENT_WRITE_WAKEUP 1 46#define RS_EVENT_WRITE_WAKEUP 1
47 47
48module_param(gs_debug, int, 0644); 48module_param(gs_debug, int, 0644);
49 49
50 50
51void gs_put_char(struct tty_struct * tty, unsigned char ch) 51int gs_put_char(struct tty_struct * tty, unsigned char ch)
52{ 52{
53 struct gs_port *port; 53 struct gs_port *port;
54 54
55 func_enter (); 55 func_enter ();
56 56
57 if (!tty) return; 57 if (!tty) return 0;
58 58
59 port = tty->driver_data; 59 port = tty->driver_data;
60 60
61 if (!port) return; 61 if (!port) return 0;
62 62
63 if (! (port->flags & ASYNC_INITIALIZED)) return; 63 if (! (port->flags & ASYNC_INITIALIZED)) return 0;
64 64
65 /* Take a lock on the serial tranmit buffer! */ 65 /* Take a lock on the serial tranmit buffer! */
66 mutex_lock(& port->port_write_mutex); 66 mutex_lock(& port->port_write_mutex);
@@ -68,7 +68,7 @@ void gs_put_char(struct tty_struct * tty, unsigned char ch)
68 if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) { 68 if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) {
69 /* Sorry, buffer is full, drop character. Update statistics???? -- REW */ 69 /* Sorry, buffer is full, drop character. Update statistics???? -- REW */
70 mutex_unlock(&port->port_write_mutex); 70 mutex_unlock(&port->port_write_mutex);
71 return; 71 return 0;
72 } 72 }
73 73
74 port->xmit_buf[port->xmit_head++] = ch; 74 port->xmit_buf[port->xmit_head++] = ch;
@@ -77,6 +77,7 @@ void gs_put_char(struct tty_struct * tty, unsigned char ch)
77 77
78 mutex_unlock(&port->port_write_mutex); 78 mutex_unlock(&port->port_write_mutex);
79 func_exit (); 79 func_exit ();
80 return 1;
80} 81}
81 82
82 83
@@ -586,8 +587,7 @@ void gs_close(struct tty_struct * tty, struct file * filp)
586 587
587 port->flags &= ~GS_ACTIVE; 588 port->flags &= ~GS_ACTIVE;
588 589
589 if (tty->driver->flush_buffer) 590 gs_flush_buffer(tty);
590 tty->driver->flush_buffer(tty);
591 591
592 tty_ldisc_flush(tty); 592 tty_ldisc_flush(tty);
593 tty->closing = 0; 593 tty->closing = 0;
diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index 1399971be689..e7fb0bca3667 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -308,7 +308,7 @@ static int hpet_mmap(struct file *file, struct vm_area_struct *vma)
308 if (io_remap_pfn_range(vma, vma->vm_start, addr >> PAGE_SHIFT, 308 if (io_remap_pfn_range(vma, vma->vm_start, addr >> PAGE_SHIFT,
309 PAGE_SIZE, vma->vm_page_prot)) { 309 PAGE_SIZE, vma->vm_page_prot)) {
310 printk(KERN_ERR "%s: io_remap_pfn_range failed\n", 310 printk(KERN_ERR "%s: io_remap_pfn_range failed\n",
311 __FUNCTION__); 311 __func__);
312 return -EAGAIN; 312 return -EAGAIN;
313 } 313 }
314 314
@@ -748,7 +748,7 @@ int hpet_alloc(struct hpet_data *hdp)
748 */ 748 */
749 if (hpet_is_known(hdp)) { 749 if (hpet_is_known(hdp)) {
750 printk(KERN_DEBUG "%s: duplicate HPET ignored\n", 750 printk(KERN_DEBUG "%s: duplicate HPET ignored\n",
751 __FUNCTION__); 751 __func__);
752 return 0; 752 return 0;
753 } 753 }
754 754
@@ -869,7 +869,7 @@ static acpi_status hpet_resources(struct acpi_resource *res, void *data)
869 869
870 if (hpet_is_known(hdp)) { 870 if (hpet_is_known(hdp)) {
871 printk(KERN_DEBUG "%s: 0x%lx is busy\n", 871 printk(KERN_DEBUG "%s: 0x%lx is busy\n",
872 __FUNCTION__, hdp->hd_phys_address); 872 __func__, hdp->hd_phys_address);
873 iounmap(hdp->hd_address); 873 iounmap(hdp->hd_address);
874 return AE_ALREADY_EXISTS; 874 return AE_ALREADY_EXISTS;
875 } 875 }
@@ -886,7 +886,7 @@ static acpi_status hpet_resources(struct acpi_resource *res, void *data)
886 886
887 if (hpet_is_known(hdp)) { 887 if (hpet_is_known(hdp)) {
888 printk(KERN_DEBUG "%s: 0x%lx is busy\n", 888 printk(KERN_DEBUG "%s: 0x%lx is busy\n",
889 __FUNCTION__, hdp->hd_phys_address); 889 __func__, hdp->hd_phys_address);
890 iounmap(hdp->hd_address); 890 iounmap(hdp->hd_address);
891 return AE_ALREADY_EXISTS; 891 return AE_ALREADY_EXISTS;
892 } 892 }
@@ -925,7 +925,7 @@ static int hpet_acpi_add(struct acpi_device *device)
925 return -ENODEV; 925 return -ENODEV;
926 926
927 if (!data.hd_address || !data.hd_nirqs) { 927 if (!data.hd_address || !data.hd_nirqs) {
928 printk("%s: no address or irqs in _CRS\n", __FUNCTION__); 928 printk("%s: no address or irqs in _CRS\n", __func__);
929 return -ENODEV; 929 return -ENODEV;
930 } 930 }
931 931
diff --git a/drivers/char/hvsi.c b/drivers/char/hvsi.c
index d5a752da322f..59c6f9ab94e4 100644
--- a/drivers/char/hvsi.c
+++ b/drivers/char/hvsi.c
@@ -246,7 +246,7 @@ static void compact_inbuf(struct hvsi_struct *hp, uint8_t *read_to)
246{ 246{
247 int remaining = (int)(hp->inbuf_end - read_to); 247 int remaining = (int)(hp->inbuf_end - read_to);
248 248
249 pr_debug("%s: %i chars remain\n", __FUNCTION__, remaining); 249 pr_debug("%s: %i chars remain\n", __func__, remaining);
250 250
251 if (read_to != hp->inbuf) 251 if (read_to != hp->inbuf)
252 memmove(hp->inbuf, read_to, remaining); 252 memmove(hp->inbuf, read_to, remaining);
@@ -365,7 +365,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
365 packet.u.version = HVSI_VERSION; 365 packet.u.version = HVSI_VERSION;
366 packet.query_seqno = query_seqno+1; 366 packet.query_seqno = query_seqno+1;
367 367
368 pr_debug("%s: sending %i bytes\n", __FUNCTION__, packet.len); 368 pr_debug("%s: sending %i bytes\n", __func__, packet.len);
369 dbg_dump_hex((uint8_t*)&packet, packet.len); 369 dbg_dump_hex((uint8_t*)&packet, packet.len);
370 370
371 wrote = hvc_put_chars(hp->vtermno, (char *)&packet, packet.len); 371 wrote = hvc_put_chars(hp->vtermno, (char *)&packet, packet.len);
@@ -437,7 +437,7 @@ static struct tty_struct *hvsi_recv_data(struct hvsi_struct *hp,
437 return NULL; 437 return NULL;
438 438
439 if (overflow > 0) { 439 if (overflow > 0) {
440 pr_debug("%s: got >TTY_THRESHOLD_THROTTLE bytes\n", __FUNCTION__); 440 pr_debug("%s: got >TTY_THRESHOLD_THROTTLE bytes\n", __func__);
441 datalen = TTY_THRESHOLD_THROTTLE; 441 datalen = TTY_THRESHOLD_THROTTLE;
442 } 442 }
443 443
@@ -448,7 +448,7 @@ static struct tty_struct *hvsi_recv_data(struct hvsi_struct *hp,
448 * we still have more data to deliver, so we need to save off the 448 * we still have more data to deliver, so we need to save off the
449 * overflow and send it later 449 * overflow and send it later
450 */ 450 */
451 pr_debug("%s: deferring overflow\n", __FUNCTION__); 451 pr_debug("%s: deferring overflow\n", __func__);
452 memcpy(hp->throttle_buf, data + TTY_THRESHOLD_THROTTLE, overflow); 452 memcpy(hp->throttle_buf, data + TTY_THRESHOLD_THROTTLE, overflow);
453 hp->n_throttle = overflow; 453 hp->n_throttle = overflow;
454 } 454 }
@@ -474,11 +474,11 @@ static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct **flip,
474 474
475 chunklen = hvsi_read(hp, hp->inbuf_end, HVSI_MAX_READ); 475 chunklen = hvsi_read(hp, hp->inbuf_end, HVSI_MAX_READ);
476 if (chunklen == 0) { 476 if (chunklen == 0) {
477 pr_debug("%s: 0-length read\n", __FUNCTION__); 477 pr_debug("%s: 0-length read\n", __func__);
478 return 0; 478 return 0;
479 } 479 }
480 480
481 pr_debug("%s: got %i bytes\n", __FUNCTION__, chunklen); 481 pr_debug("%s: got %i bytes\n", __func__, chunklen);
482 dbg_dump_hex(hp->inbuf_end, chunklen); 482 dbg_dump_hex(hp->inbuf_end, chunklen);
483 483
484 hp->inbuf_end += chunklen; 484 hp->inbuf_end += chunklen;
@@ -495,7 +495,7 @@ static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct **flip,
495 continue; 495 continue;
496 } 496 }
497 497
498 pr_debug("%s: handling %i-byte packet\n", __FUNCTION__, 498 pr_debug("%s: handling %i-byte packet\n", __func__,
499 len_packet(packet)); 499 len_packet(packet));
500 dbg_dump_packet(packet); 500 dbg_dump_packet(packet);
501 501
@@ -526,7 +526,7 @@ static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct **flip,
526 packet += len_packet(packet); 526 packet += len_packet(packet);
527 527
528 if (*hangup || *handshake) { 528 if (*hangup || *handshake) {
529 pr_debug("%s: hangup or handshake\n", __FUNCTION__); 529 pr_debug("%s: hangup or handshake\n", __func__);
530 /* 530 /*
531 * we need to send the hangup now before receiving any more data. 531 * we need to send the hangup now before receiving any more data.
532 * If we get "data, hangup, data", we can't deliver the second 532 * If we get "data, hangup, data", we can't deliver the second
@@ -543,7 +543,7 @@ static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct **flip,
543 543
544static void hvsi_send_overflow(struct hvsi_struct *hp) 544static void hvsi_send_overflow(struct hvsi_struct *hp)
545{ 545{
546 pr_debug("%s: delivering %i bytes overflow\n", __FUNCTION__, 546 pr_debug("%s: delivering %i bytes overflow\n", __func__,
547 hp->n_throttle); 547 hp->n_throttle);
548 548
549 hvsi_insert_chars(hp, hp->throttle_buf, hp->n_throttle); 549 hvsi_insert_chars(hp, hp->throttle_buf, hp->n_throttle);
@@ -563,7 +563,7 @@ static irqreturn_t hvsi_interrupt(int irq, void *arg)
563 unsigned long flags; 563 unsigned long flags;
564 int again = 1; 564 int again = 1;
565 565
566 pr_debug("%s\n", __FUNCTION__); 566 pr_debug("%s\n", __func__);
567 567
568 while (again) { 568 while (again) {
569 spin_lock_irqsave(&hp->lock, flags); 569 spin_lock_irqsave(&hp->lock, flags);
@@ -647,7 +647,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
647 packet.seqno = atomic_inc_return(&hp->seqno); 647 packet.seqno = atomic_inc_return(&hp->seqno);
648 packet.verb = verb; 648 packet.verb = verb;
649 649
650 pr_debug("%s: sending %i bytes\n", __FUNCTION__, packet.len); 650 pr_debug("%s: sending %i bytes\n", __func__, packet.len);
651 dbg_dump_hex((uint8_t*)&packet, packet.len); 651 dbg_dump_hex((uint8_t*)&packet, packet.len);
652 652
653 wrote = hvc_put_chars(hp->vtermno, (char *)&packet, packet.len); 653 wrote = hvc_put_chars(hp->vtermno, (char *)&packet, packet.len);
@@ -674,7 +674,7 @@ static int hvsi_get_mctrl(struct hvsi_struct *hp)
674 return ret; 674 return ret;
675 } 675 }
676 676
677 pr_debug("%s: mctrl 0x%x\n", __FUNCTION__, hp->mctrl); 677 pr_debug("%s: mctrl 0x%x\n", __func__, hp->mctrl);
678 678
679 return 0; 679 return 0;
680} 680}
@@ -694,7 +694,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
694 if (mctrl & TIOCM_DTR) 694 if (mctrl & TIOCM_DTR)
695 packet.word = HVSI_TSDTR; 695 packet.word = HVSI_TSDTR;
696 696
697 pr_debug("%s: sending %i bytes\n", __FUNCTION__, packet.len); 697 pr_debug("%s: sending %i bytes\n", __func__, packet.len);
698 dbg_dump_hex((uint8_t*)&packet, packet.len); 698 dbg_dump_hex((uint8_t*)&packet, packet.len);
699 699
700 wrote = hvc_put_chars(hp->vtermno, (char *)&packet, packet.len); 700 wrote = hvc_put_chars(hp->vtermno, (char *)&packet, packet.len);
@@ -790,7 +790,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
790 packet.len = 6; 790 packet.len = 6;
791 packet.verb = VSV_CLOSE_PROTOCOL; 791 packet.verb = VSV_CLOSE_PROTOCOL;
792 792
793 pr_debug("%s: sending %i bytes\n", __FUNCTION__, packet.len); 793 pr_debug("%s: sending %i bytes\n", __func__, packet.len);
794 dbg_dump_hex((uint8_t*)&packet, packet.len); 794 dbg_dump_hex((uint8_t*)&packet, packet.len);
795 795
796 hvc_put_chars(hp->vtermno, (char *)&packet, packet.len); 796 hvc_put_chars(hp->vtermno, (char *)&packet, packet.len);
@@ -803,7 +803,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
803 int line = tty->index; 803 int line = tty->index;
804 int ret; 804 int ret;
805 805
806 pr_debug("%s\n", __FUNCTION__); 806 pr_debug("%s\n", __func__);
807 807
808 if (line < 0 || line >= hvsi_count) 808 if (line < 0 || line >= hvsi_count)
809 return -ENODEV; 809 return -ENODEV;
@@ -868,7 +868,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
868 struct hvsi_struct *hp = tty->driver_data; 868 struct hvsi_struct *hp = tty->driver_data;
869 unsigned long flags; 869 unsigned long flags;
870 870
871 pr_debug("%s\n", __FUNCTION__); 871 pr_debug("%s\n", __func__);
872 872
873 if (tty_hung_up_p(filp)) 873 if (tty_hung_up_p(filp))
874 return; 874 return;
@@ -920,7 +920,7 @@ static void hvsi_hangup(struct tty_struct *tty)
920 struct hvsi_struct *hp = tty->driver_data; 920 struct hvsi_struct *hp = tty->driver_data;
921 unsigned long flags; 921 unsigned long flags;
922 922
923 pr_debug("%s\n", __FUNCTION__); 923 pr_debug("%s\n", __func__);
924 924
925 spin_lock_irqsave(&hp->lock, flags); 925 spin_lock_irqsave(&hp->lock, flags);
926 926
@@ -942,7 +942,7 @@ static void hvsi_push(struct hvsi_struct *hp)
942 n = hvsi_put_chars(hp, hp->outbuf, hp->n_outbuf); 942 n = hvsi_put_chars(hp, hp->outbuf, hp->n_outbuf);
943 if (n > 0) { 943 if (n > 0) {
944 /* success */ 944 /* success */
945 pr_debug("%s: wrote %i chars\n", __FUNCTION__, n); 945 pr_debug("%s: wrote %i chars\n", __func__, n);
946 hp->n_outbuf = 0; 946 hp->n_outbuf = 0;
947 } else if (n == -EIO) { 947 } else if (n == -EIO) {
948 __set_state(hp, HVSI_FSP_DIED); 948 __set_state(hp, HVSI_FSP_DIED);
@@ -965,7 +965,7 @@ static void hvsi_write_worker(struct work_struct *work)
965 965
966 spin_lock_irqsave(&hp->lock, flags); 966 spin_lock_irqsave(&hp->lock, flags);
967 967
968 pr_debug("%s: %i chars in buffer\n", __FUNCTION__, hp->n_outbuf); 968 pr_debug("%s: %i chars in buffer\n", __func__, hp->n_outbuf);
969 969
970 if (!is_open(hp)) { 970 if (!is_open(hp)) {
971 /* 971 /*
@@ -983,7 +983,7 @@ static void hvsi_write_worker(struct work_struct *work)
983 schedule_delayed_work(&hp->writer, 10); 983 schedule_delayed_work(&hp->writer, 10);
984 else { 984 else {
985#ifdef DEBUG 985#ifdef DEBUG
986 pr_debug("%s: outbuf emptied after %li jiffies\n", __FUNCTION__, 986 pr_debug("%s: outbuf emptied after %li jiffies\n", __func__,
987 jiffies - start_j); 987 jiffies - start_j);
988 start_j = 0; 988 start_j = 0;
989#endif /* DEBUG */ 989#endif /* DEBUG */
@@ -1020,11 +1020,11 @@ static int hvsi_write(struct tty_struct *tty,
1020 1020
1021 spin_lock_irqsave(&hp->lock, flags); 1021 spin_lock_irqsave(&hp->lock, flags);
1022 1022
1023 pr_debug("%s: %i chars in buffer\n", __FUNCTION__, hp->n_outbuf); 1023 pr_debug("%s: %i chars in buffer\n", __func__, hp->n_outbuf);
1024 1024
1025 if (!is_open(hp)) { 1025 if (!is_open(hp)) {
1026 /* we're either closing or not yet open; don't accept data */ 1026 /* we're either closing or not yet open; don't accept data */
1027 pr_debug("%s: not open\n", __FUNCTION__); 1027 pr_debug("%s: not open\n", __func__);
1028 goto out; 1028 goto out;
1029 } 1029 }
1030 1030
@@ -1058,7 +1058,7 @@ out:
1058 spin_unlock_irqrestore(&hp->lock, flags); 1058 spin_unlock_irqrestore(&hp->lock, flags);
1059 1059
1060 if (total != origcount) 1060 if (total != origcount)
1061 pr_debug("%s: wanted %i, only wrote %i\n", __FUNCTION__, origcount, 1061 pr_debug("%s: wanted %i, only wrote %i\n", __func__, origcount,
1062 total); 1062 total);
1063 1063
1064 return total; 1064 return total;
@@ -1072,7 +1072,7 @@ static void hvsi_throttle(struct tty_struct *tty)
1072{ 1072{
1073 struct hvsi_struct *hp = (struct hvsi_struct *)tty->driver_data; 1073 struct hvsi_struct *hp = (struct hvsi_struct *)tty->driver_data;
1074 1074
1075 pr_debug("%s\n", __FUNCTION__); 1075 pr_debug("%s\n", __func__);
1076 1076
1077 h_vio_signal(hp->vtermno, VIO_IRQ_DISABLE); 1077 h_vio_signal(hp->vtermno, VIO_IRQ_DISABLE);
1078} 1078}
@@ -1083,7 +1083,7 @@ static void hvsi_unthrottle(struct tty_struct *tty)
1083 unsigned long flags; 1083 unsigned long flags;
1084 int shouldflip = 0; 1084 int shouldflip = 0;
1085 1085
1086 pr_debug("%s\n", __FUNCTION__); 1086 pr_debug("%s\n", __func__);
1087 1087
1088 spin_lock_irqsave(&hp->lock, flags); 1088 spin_lock_irqsave(&hp->lock, flags);
1089 if (hp->n_throttle) { 1089 if (hp->n_throttle) {
@@ -1302,7 +1302,7 @@ static int __init hvsi_console_init(void)
1302 hp->virq = irq_create_mapping(NULL, irq[0]); 1302 hp->virq = irq_create_mapping(NULL, irq[0]);
1303 if (hp->virq == NO_IRQ) { 1303 if (hp->virq == NO_IRQ) {
1304 printk(KERN_ERR "%s: couldn't create irq mapping for 0x%x\n", 1304 printk(KERN_ERR "%s: couldn't create irq mapping for 0x%x\n",
1305 __FUNCTION__, irq[0]); 1305 __func__, irq[0]);
1306 continue; 1306 continue;
1307 } 1307 }
1308 1308
diff --git a/drivers/char/i8k.c b/drivers/char/i8k.c
index f49037b744f9..b60d425ce8d1 100644
--- a/drivers/char/i8k.c
+++ b/drivers/char/i8k.c
@@ -77,6 +77,10 @@ static int power_status;
77module_param(power_status, bool, 0600); 77module_param(power_status, bool, 0600);
78MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k"); 78MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k");
79 79
80static int fan_mult = I8K_FAN_MULT;
81module_param(fan_mult, int, 0);
82MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with");
83
80static int i8k_open_fs(struct inode *inode, struct file *file); 84static int i8k_open_fs(struct inode *inode, struct file *file);
81static int i8k_ioctl(struct inode *, struct file *, unsigned int, 85static int i8k_ioctl(struct inode *, struct file *, unsigned int,
82 unsigned long); 86 unsigned long);
@@ -239,7 +243,7 @@ static int i8k_get_fan_speed(int fan)
239 struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, }; 243 struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, };
240 244
241 regs.ebx = fan & 0xff; 245 regs.ebx = fan & 0xff;
242 return i8k_smm(&regs) ? : (regs.eax & 0xffff) * I8K_FAN_MULT; 246 return i8k_smm(&regs) ? : (regs.eax & 0xffff) * fan_mult;
243} 247}
244 248
245/* 249/*
diff --git a/drivers/char/ip2/i2ellis.c b/drivers/char/ip2/i2ellis.c
index 61ef013b8445..3601017f58cf 100644
--- a/drivers/char/ip2/i2ellis.c
+++ b/drivers/char/ip2/i2ellis.c
@@ -53,7 +53,7 @@ static int ii2Safe; // Safe I/O address for delay routine
53 53
54static int iiDelayed; // Set when the iiResetDelay function is 54static int iiDelayed; // Set when the iiResetDelay function is
55 // called. Cleared when ANY board is reset. 55 // called. Cleared when ANY board is reset.
56static rwlock_t Dl_spinlock; 56static DEFINE_RWLOCK(Dl_spinlock);
57 57
58//******** 58//********
59//* Code * 59//* Code *
@@ -82,7 +82,6 @@ static rwlock_t Dl_spinlock;
82static void 82static void
83iiEllisInit(void) 83iiEllisInit(void)
84{ 84{
85 LOCK_INIT(&Dl_spinlock);
86} 85}
87 86
88//****************************************************************************** 87//******************************************************************************
@@ -132,7 +131,7 @@ iiSetAddress( i2eBordStrPtr pB, int address, delayFunc_t delay )
132 || (address & 0x7) 131 || (address & 0x7)
133 ) 132 )
134 { 133 {
135 COMPLETE(pB,I2EE_BADADDR); 134 I2_COMPLETE(pB, I2EE_BADADDR);
136 } 135 }
137 136
138 // Initialize accelerators 137 // Initialize accelerators
@@ -152,7 +151,7 @@ iiSetAddress( i2eBordStrPtr pB, int address, delayFunc_t delay )
152 pB->i2eValid = I2E_MAGIC; 151 pB->i2eValid = I2E_MAGIC;
153 pB->i2eState = II_STATE_COLD; 152 pB->i2eState = II_STATE_COLD;
154 153
155 COMPLETE(pB, I2EE_GOOD); 154 I2_COMPLETE(pB, I2EE_GOOD);
156} 155}
157 156
158//****************************************************************************** 157//******************************************************************************
@@ -177,12 +176,12 @@ iiReset(i2eBordStrPtr pB)
177 // Magic number should be set, else even the address is suspect 176 // Magic number should be set, else even the address is suspect
178 if (pB->i2eValid != I2E_MAGIC) 177 if (pB->i2eValid != I2E_MAGIC)
179 { 178 {
180 COMPLETE(pB, I2EE_BADMAGIC); 179 I2_COMPLETE(pB, I2EE_BADMAGIC);
181 } 180 }
182 181
183 OUTB(pB->i2eBase + FIFO_RESET, 0); // Any data will do 182 outb(0, pB->i2eBase + FIFO_RESET); /* Any data will do */
184 iiDelay(pB, 50); // Pause between resets 183 iiDelay(pB, 50); // Pause between resets
185 OUTB(pB->i2eBase + FIFO_RESET, 0); // Second reset 184 outb(0, pB->i2eBase + FIFO_RESET); /* Second reset */
186 185
187 // We must wait before even attempting to read anything from the FIFO: the 186 // We must wait before even attempting to read anything from the FIFO: the
188 // board's P.O.S.T may actually attempt to read and write its end of the 187 // board's P.O.S.T may actually attempt to read and write its end of the
@@ -203,7 +202,7 @@ iiReset(i2eBordStrPtr pB)
203 // Ensure anything which would have been of use to standard loadware is 202 // Ensure anything which would have been of use to standard loadware is
204 // blanked out, since board has now forgotten everything!. 203 // blanked out, since board has now forgotten everything!.
205 204
206 pB->i2eUsingIrq = IRQ_UNDEFINED; // Not set up to use an interrupt yet 205 pB->i2eUsingIrq = I2_IRQ_UNDEFINED; /* to not use an interrupt so far */
207 pB->i2eWaitingForEmptyFifo = 0; 206 pB->i2eWaitingForEmptyFifo = 0;
208 pB->i2eOutMailWaiting = 0; 207 pB->i2eOutMailWaiting = 0;
209 pB->i2eChannelPtr = NULL; 208 pB->i2eChannelPtr = NULL;
@@ -215,7 +214,7 @@ iiReset(i2eBordStrPtr pB)
215 pB->i2eFatalTrap = NULL; 214 pB->i2eFatalTrap = NULL;
216 pB->i2eFatal = 0; 215 pB->i2eFatal = 0;
217 216
218 COMPLETE(pB, I2EE_GOOD); 217 I2_COMPLETE(pB, I2EE_GOOD);
219} 218}
220 219
221//****************************************************************************** 220//******************************************************************************
@@ -235,14 +234,14 @@ static int
235iiResetDelay(i2eBordStrPtr pB) 234iiResetDelay(i2eBordStrPtr pB)
236{ 235{
237 if (pB->i2eValid != I2E_MAGIC) { 236 if (pB->i2eValid != I2E_MAGIC) {
238 COMPLETE(pB, I2EE_BADMAGIC); 237 I2_COMPLETE(pB, I2EE_BADMAGIC);
239 } 238 }
240 if (pB->i2eState != II_STATE_RESET) { 239 if (pB->i2eState != II_STATE_RESET) {
241 COMPLETE(pB, I2EE_BADSTATE); 240 I2_COMPLETE(pB, I2EE_BADSTATE);
242 } 241 }
243 iiDelay(pB,2000); /* Now we wait for two seconds. */ 242 iiDelay(pB,2000); /* Now we wait for two seconds. */
244 iiDelayed = 1; /* Delay has been called: ok to initialize */ 243 iiDelayed = 1; /* Delay has been called: ok to initialize */
245 COMPLETE(pB, I2EE_GOOD); 244 I2_COMPLETE(pB, I2EE_GOOD);
246} 245}
247 246
248//****************************************************************************** 247//******************************************************************************
@@ -273,12 +272,12 @@ iiInitialize(i2eBordStrPtr pB)
273 272
274 if (pB->i2eValid != I2E_MAGIC) 273 if (pB->i2eValid != I2E_MAGIC)
275 { 274 {
276 COMPLETE(pB, I2EE_BADMAGIC); 275 I2_COMPLETE(pB, I2EE_BADMAGIC);
277 } 276 }
278 277
279 if (pB->i2eState != II_STATE_RESET || !iiDelayed) 278 if (pB->i2eState != II_STATE_RESET || !iiDelayed)
280 { 279 {
281 COMPLETE(pB, I2EE_BADSTATE); 280 I2_COMPLETE(pB, I2EE_BADSTATE);
282 } 281 }
283 282
284 // In case there is a failure short of our completely reading the power-up 283 // In case there is a failure short of our completely reading the power-up
@@ -291,13 +290,12 @@ iiInitialize(i2eBordStrPtr pB)
291 for (itemp = 0; itemp < sizeof(porStr); itemp++) 290 for (itemp = 0; itemp < sizeof(porStr); itemp++)
292 { 291 {
293 // We expect the entire message is ready. 292 // We expect the entire message is ready.
294 if (HAS_NO_INPUT(pB)) 293 if (!I2_HAS_INPUT(pB)) {
295 {
296 pB->i2ePomSize = itemp; 294 pB->i2ePomSize = itemp;
297 COMPLETE(pB, I2EE_PORM_SHORT); 295 I2_COMPLETE(pB, I2EE_PORM_SHORT);
298 } 296 }
299 297
300 pB->i2ePom.c[itemp] = c = BYTE_FROM(pB); 298 pB->i2ePom.c[itemp] = c = inb(pB->i2eData);
301 299
302 // We check the magic numbers as soon as they are supposed to be read 300 // We check the magic numbers as soon as they are supposed to be read
303 // (rather than after) to minimize effect of reading something we 301 // (rather than after) to minimize effect of reading something we
@@ -306,22 +304,22 @@ iiInitialize(i2eBordStrPtr pB)
306 (itemp == POR_2_INDEX && c != POR_MAGIC_2)) 304 (itemp == POR_2_INDEX && c != POR_MAGIC_2))
307 { 305 {
308 pB->i2ePomSize = itemp+1; 306 pB->i2ePomSize = itemp+1;
309 COMPLETE(pB, I2EE_BADMAGIC); 307 I2_COMPLETE(pB, I2EE_BADMAGIC);
310 } 308 }
311 } 309 }
312 310
313 pB->i2ePomSize = itemp; 311 pB->i2ePomSize = itemp;
314 312
315 // Ensure that this was all the data... 313 // Ensure that this was all the data...
316 if (HAS_INPUT(pB)) 314 if (I2_HAS_INPUT(pB))
317 COMPLETE(pB, I2EE_PORM_LONG); 315 I2_COMPLETE(pB, I2EE_PORM_LONG);
318 316
319 // For now, we'll fail to initialize if P.O.S.T reports bad chip mapper: 317 // For now, we'll fail to initialize if P.O.S.T reports bad chip mapper:
320 // Implying we will not be able to download any code either: That's ok: the 318 // Implying we will not be able to download any code either: That's ok: the
321 // condition is pretty explicit. 319 // condition is pretty explicit.
322 if (pB->i2ePom.e.porDiag1 & POR_BAD_MAPPER) 320 if (pB->i2ePom.e.porDiag1 & POR_BAD_MAPPER)
323 { 321 {
324 COMPLETE(pB, I2EE_POSTERR); 322 I2_COMPLETE(pB, I2EE_POSTERR);
325 } 323 }
326 324
327 // Determine anything which must be done differently depending on the family 325 // Determine anything which must be done differently depending on the family
@@ -332,7 +330,7 @@ iiInitialize(i2eBordStrPtr pB)
332 330
333 pB->i2eFifoStyle = FIFO_II; 331 pB->i2eFifoStyle = FIFO_II;
334 pB->i2eFifoSize = 512; // 512 bytes, always 332 pB->i2eFifoSize = 512; // 512 bytes, always
335 pB->i2eDataWidth16 = NO; 333 pB->i2eDataWidth16 = false;
336 334
337 pB->i2eMaxIrq = 15; // Because board cannot tell us it is in an 8-bit 335 pB->i2eMaxIrq = 15; // Because board cannot tell us it is in an 8-bit
338 // slot, we do allow it to be done (documentation!) 336 // slot, we do allow it to be done (documentation!)
@@ -354,7 +352,7 @@ iiInitialize(i2eBordStrPtr pB)
354 // should always be consistent for IntelliPort-II. Ditto below... 352 // should always be consistent for IntelliPort-II. Ditto below...
355 if (pB->i2ePom.e.porPorts1 != 4) 353 if (pB->i2ePom.e.porPorts1 != 4)
356 { 354 {
357 COMPLETE(pB, I2EE_INCONSIST); 355 I2_COMPLETE(pB, I2EE_INCONSIST);
358 } 356 }
359 break; 357 break;
360 358
@@ -364,7 +362,7 @@ iiInitialize(i2eBordStrPtr pB)
364 pB->i2eChannelMap[0] = 0xff; // Eight port 362 pB->i2eChannelMap[0] = 0xff; // Eight port
365 if (pB->i2ePom.e.porPorts1 != 8) 363 if (pB->i2ePom.e.porPorts1 != 8)
366 { 364 {
367 COMPLETE(pB, I2EE_INCONSIST); 365 I2_COMPLETE(pB, I2EE_INCONSIST);
368 } 366 }
369 break; 367 break;
370 368
@@ -373,7 +371,7 @@ iiInitialize(i2eBordStrPtr pB)
373 pB->i2eChannelMap[0] = 0x3f; // Six Port 371 pB->i2eChannelMap[0] = 0x3f; // Six Port
374 if (pB->i2ePom.e.porPorts1 != 6) 372 if (pB->i2ePom.e.porPorts1 != 6)
375 { 373 {
376 COMPLETE(pB, I2EE_INCONSIST); 374 I2_COMPLETE(pB, I2EE_INCONSIST);
377 } 375 }
378 break; 376 break;
379 } 377 }
@@ -402,7 +400,7 @@ iiInitialize(i2eBordStrPtr pB)
402 400
403 if (itemp < 8 || itemp > 15) 401 if (itemp < 8 || itemp > 15)
404 { 402 {
405 COMPLETE(pB, I2EE_INCONSIST); 403 I2_COMPLETE(pB, I2EE_INCONSIST);
406 } 404 }
407 pB->i2eFifoSize = (1 << itemp); 405 pB->i2eFifoSize = (1 << itemp);
408 406
@@ -450,26 +448,26 @@ iiInitialize(i2eBordStrPtr pB)
450 switch (pB->i2ePom.e.porBus & (POR_BUS_SLOT16 | POR_BUS_DIP16) ) 448 switch (pB->i2ePom.e.porBus & (POR_BUS_SLOT16 | POR_BUS_DIP16) )
451 { 449 {
452 case POR_BUS_SLOT16 | POR_BUS_DIP16: 450 case POR_BUS_SLOT16 | POR_BUS_DIP16:
453 pB->i2eDataWidth16 = YES; 451 pB->i2eDataWidth16 = true;
454 pB->i2eMaxIrq = 15; 452 pB->i2eMaxIrq = 15;
455 break; 453 break;
456 454
457 case POR_BUS_SLOT16: 455 case POR_BUS_SLOT16:
458 pB->i2eDataWidth16 = NO; 456 pB->i2eDataWidth16 = false;
459 pB->i2eMaxIrq = 15; 457 pB->i2eMaxIrq = 15;
460 break; 458 break;
461 459
462 case 0: 460 case 0:
463 case POR_BUS_DIP16: // In an 8-bit slot, DIP switch don't care. 461 case POR_BUS_DIP16: // In an 8-bit slot, DIP switch don't care.
464 default: 462 default:
465 pB->i2eDataWidth16 = NO; 463 pB->i2eDataWidth16 = false;
466 pB->i2eMaxIrq = 7; 464 pB->i2eMaxIrq = 7;
467 break; 465 break;
468 } 466 }
469 break; // POR_ID_FIIEX case 467 break; // POR_ID_FIIEX case
470 468
471 default: // Unknown type of board 469 default: // Unknown type of board
472 COMPLETE(pB, I2EE_BAD_FAMILY); 470 I2_COMPLETE(pB, I2EE_BAD_FAMILY);
473 break; 471 break;
474 } // End the switch based on family 472 } // End the switch based on family
475 473
@@ -483,17 +481,14 @@ iiInitialize(i2eBordStrPtr pB)
483 { 481 {
484 case POR_BUS_T_ISA: 482 case POR_BUS_T_ISA:
485 case POR_BUS_T_UNK: // If the type of bus is undeclared, assume ok. 483 case POR_BUS_T_UNK: // If the type of bus is undeclared, assume ok.
486 pB->i2eChangeIrq = YES;
487 break;
488 case POR_BUS_T_MCA: 484 case POR_BUS_T_MCA:
489 case POR_BUS_T_EISA: 485 case POR_BUS_T_EISA:
490 pB->i2eChangeIrq = NO;
491 break; 486 break;
492 default: 487 default:
493 COMPLETE(pB, I2EE_BADBUS); 488 I2_COMPLETE(pB, I2EE_BADBUS);
494 } 489 }
495 490
496 if (pB->i2eDataWidth16 == YES) 491 if (pB->i2eDataWidth16)
497 { 492 {
498 pB->i2eWriteBuf = iiWriteBuf16; 493 pB->i2eWriteBuf = iiWriteBuf16;
499 pB->i2eReadBuf = iiReadBuf16; 494 pB->i2eReadBuf = iiReadBuf16;
@@ -529,7 +524,7 @@ iiInitialize(i2eBordStrPtr pB)
529 break; 524 break;
530 525
531 default: 526 default:
532 COMPLETE(pB, I2EE_INCONSIST); 527 I2_COMPLETE(pB, I2EE_INCONSIST);
533 } 528 }
534 529
535 // Initialize state information. 530 // Initialize state information.
@@ -549,7 +544,7 @@ iiInitialize(i2eBordStrPtr pB)
549 // Everything is ok now, return with good status/ 544 // Everything is ok now, return with good status/
550 545
551 pB->i2eValid = I2E_MAGIC; 546 pB->i2eValid = I2E_MAGIC;
552 COMPLETE(pB, I2EE_GOOD); 547 I2_COMPLETE(pB, I2EE_GOOD);
553} 548}
554 549
555//****************************************************************************** 550//******************************************************************************
@@ -658,7 +653,7 @@ ii2DelayIO(unsigned int mseconds)
658 while(mseconds--) { 653 while(mseconds--) {
659 int i = ii2DelValue; 654 int i = ii2DelValue;
660 while ( i-- ) { 655 while ( i-- ) {
661 INB ( ii2Safe ); 656 inb(ii2Safe);
662 } 657 }
663 } 658 }
664} 659}
@@ -709,11 +704,11 @@ iiWriteBuf16(i2eBordStrPtr pB, unsigned char *address, int count)
709{ 704{
710 // Rudimentary sanity checking here. 705 // Rudimentary sanity checking here.
711 if (pB->i2eValid != I2E_MAGIC) 706 if (pB->i2eValid != I2E_MAGIC)
712 COMPLETE(pB, I2EE_INVALID); 707 I2_COMPLETE(pB, I2EE_INVALID);
713 708
714 OUTSW ( pB->i2eData, address, count); 709 I2_OUTSW(pB->i2eData, address, count);
715 710
716 COMPLETE(pB, I2EE_GOOD); 711 I2_COMPLETE(pB, I2EE_GOOD);
717} 712}
718 713
719//****************************************************************************** 714//******************************************************************************
@@ -738,11 +733,11 @@ iiWriteBuf8(i2eBordStrPtr pB, unsigned char *address, int count)
738{ 733{
739 /* Rudimentary sanity checking here */ 734 /* Rudimentary sanity checking here */
740 if (pB->i2eValid != I2E_MAGIC) 735 if (pB->i2eValid != I2E_MAGIC)
741 COMPLETE(pB, I2EE_INVALID); 736 I2_COMPLETE(pB, I2EE_INVALID);
742 737
743 OUTSB ( pB->i2eData, address, count ); 738 I2_OUTSB(pB->i2eData, address, count);
744 739
745 COMPLETE(pB, I2EE_GOOD); 740 I2_COMPLETE(pB, I2EE_GOOD);
746} 741}
747 742
748//****************************************************************************** 743//******************************************************************************
@@ -767,11 +762,11 @@ iiReadBuf16(i2eBordStrPtr pB, unsigned char *address, int count)
767{ 762{
768 // Rudimentary sanity checking here. 763 // Rudimentary sanity checking here.
769 if (pB->i2eValid != I2E_MAGIC) 764 if (pB->i2eValid != I2E_MAGIC)
770 COMPLETE(pB, I2EE_INVALID); 765 I2_COMPLETE(pB, I2EE_INVALID);
771 766
772 INSW ( pB->i2eData, address, count); 767 I2_INSW(pB->i2eData, address, count);
773 768
774 COMPLETE(pB, I2EE_GOOD); 769 I2_COMPLETE(pB, I2EE_GOOD);
775} 770}
776 771
777//****************************************************************************** 772//******************************************************************************
@@ -796,11 +791,11 @@ iiReadBuf8(i2eBordStrPtr pB, unsigned char *address, int count)
796{ 791{
797 // Rudimentary sanity checking here. 792 // Rudimentary sanity checking here.
798 if (pB->i2eValid != I2E_MAGIC) 793 if (pB->i2eValid != I2E_MAGIC)
799 COMPLETE(pB, I2EE_INVALID); 794 I2_COMPLETE(pB, I2EE_INVALID);
800 795
801 INSB ( pB->i2eData, address, count); 796 I2_INSB(pB->i2eData, address, count);
802 797
803 COMPLETE(pB, I2EE_GOOD); 798 I2_COMPLETE(pB, I2EE_GOOD);
804} 799}
805 800
806//****************************************************************************** 801//******************************************************************************
@@ -820,7 +815,7 @@ iiReadBuf8(i2eBordStrPtr pB, unsigned char *address, int count)
820static unsigned short 815static unsigned short
821iiReadWord16(i2eBordStrPtr pB) 816iiReadWord16(i2eBordStrPtr pB)
822{ 817{
823 return (unsigned short)( INW(pB->i2eData) ); 818 return inw(pB->i2eData);
824} 819}
825 820
826//****************************************************************************** 821//******************************************************************************
@@ -842,9 +837,9 @@ iiReadWord8(i2eBordStrPtr pB)
842{ 837{
843 unsigned short urs; 838 unsigned short urs;
844 839
845 urs = INB ( pB->i2eData ); 840 urs = inb(pB->i2eData);
846 841
847 return ( ( INB ( pB->i2eData ) << 8 ) | urs ); 842 return (inb(pB->i2eData) << 8) | urs;
848} 843}
849 844
850//****************************************************************************** 845//******************************************************************************
@@ -865,7 +860,7 @@ iiReadWord8(i2eBordStrPtr pB)
865static void 860static void
866iiWriteWord16(i2eBordStrPtr pB, unsigned short value) 861iiWriteWord16(i2eBordStrPtr pB, unsigned short value)
867{ 862{
868 WORD_TO(pB, (int)value); 863 outw((int)value, pB->i2eData);
869} 864}
870 865
871//****************************************************************************** 866//******************************************************************************
@@ -886,8 +881,8 @@ iiWriteWord16(i2eBordStrPtr pB, unsigned short value)
886static void 881static void
887iiWriteWord8(i2eBordStrPtr pB, unsigned short value) 882iiWriteWord8(i2eBordStrPtr pB, unsigned short value)
888{ 883{
889 BYTE_TO(pB, (char)value); 884 outb((char)value, pB->i2eData);
890 BYTE_TO(pB, (char)(value >> 8) ); 885 outb((char)(value >> 8), pB->i2eData);
891} 886}
892 887
893//****************************************************************************** 888//******************************************************************************
@@ -939,30 +934,30 @@ iiWaitForTxEmptyII(i2eBordStrPtr pB, int mSdelay)
939 // interrupts of any kind. 934 // interrupts of any kind.
940 935
941 936
942 WRITE_LOCK_IRQSAVE(&Dl_spinlock,flags) 937 write_lock_irqsave(&Dl_spinlock, flags);
943 OUTB(pB->i2ePointer, SEL_COMMAND); 938 outb(SEL_COMMAND, pB->i2ePointer);
944 OUTB(pB->i2ePointer, SEL_CMD_SH); 939 outb(SEL_CMD_SH, pB->i2ePointer);
945 940
946 itemp = INB(pB->i2eStatus); 941 itemp = inb(pB->i2eStatus);
947 942
948 OUTB(pB->i2ePointer, SEL_COMMAND); 943 outb(SEL_COMMAND, pB->i2ePointer);
949 OUTB(pB->i2ePointer, SEL_CMD_UNSH); 944 outb(SEL_CMD_UNSH, pB->i2ePointer);
950 945
951 if (itemp & ST_IN_EMPTY) 946 if (itemp & ST_IN_EMPTY)
952 { 947 {
953 UPDATE_FIFO_ROOM(pB); 948 I2_UPDATE_FIFO_ROOM(pB);
954 WRITE_UNLOCK_IRQRESTORE(&Dl_spinlock,flags) 949 write_unlock_irqrestore(&Dl_spinlock, flags);
955 COMPLETE(pB, I2EE_GOOD); 950 I2_COMPLETE(pB, I2EE_GOOD);
956 } 951 }
957 952
958 WRITE_UNLOCK_IRQRESTORE(&Dl_spinlock,flags) 953 write_unlock_irqrestore(&Dl_spinlock, flags);
959 954
960 if (mSdelay-- == 0) 955 if (mSdelay-- == 0)
961 break; 956 break;
962 957
963 iiDelay(pB, 1); /* 1 mS granularity on checking condition */ 958 iiDelay(pB, 1); /* 1 mS granularity on checking condition */
964 } 959 }
965 COMPLETE(pB, I2EE_TXE_TIME); 960 I2_COMPLETE(pB, I2EE_TXE_TIME);
966} 961}
967 962
968//****************************************************************************** 963//******************************************************************************
@@ -1002,21 +997,21 @@ iiWaitForTxEmptyIIEX(i2eBordStrPtr pB, int mSdelay)
1002 // you will generally not want to service interrupts or in any way 997 // you will generally not want to service interrupts or in any way
1003 // disrupt the assumptions implicit in the larger context. 998 // disrupt the assumptions implicit in the larger context.
1004 999
1005 WRITE_LOCK_IRQSAVE(&Dl_spinlock,flags) 1000 write_lock_irqsave(&Dl_spinlock, flags);
1006 1001
1007 if (INB(pB->i2eStatus) & STE_OUT_MT) { 1002 if (inb(pB->i2eStatus) & STE_OUT_MT) {
1008 UPDATE_FIFO_ROOM(pB); 1003 I2_UPDATE_FIFO_ROOM(pB);
1009 WRITE_UNLOCK_IRQRESTORE(&Dl_spinlock,flags) 1004 write_unlock_irqrestore(&Dl_spinlock, flags);
1010 COMPLETE(pB, I2EE_GOOD); 1005 I2_COMPLETE(pB, I2EE_GOOD);
1011 } 1006 }
1012 WRITE_UNLOCK_IRQRESTORE(&Dl_spinlock,flags) 1007 write_unlock_irqrestore(&Dl_spinlock, flags);
1013 1008
1014 if (mSdelay-- == 0) 1009 if (mSdelay-- == 0)
1015 break; 1010 break;
1016 1011
1017 iiDelay(pB, 1); // 1 mS granularity on checking condition 1012 iiDelay(pB, 1); // 1 mS granularity on checking condition
1018 } 1013 }
1019 COMPLETE(pB, I2EE_TXE_TIME); 1014 I2_COMPLETE(pB, I2EE_TXE_TIME);
1020} 1015}
1021 1016
1022//****************************************************************************** 1017//******************************************************************************
@@ -1038,8 +1033,8 @@ static int
1038iiTxMailEmptyII(i2eBordStrPtr pB) 1033iiTxMailEmptyII(i2eBordStrPtr pB)
1039{ 1034{
1040 int port = pB->i2ePointer; 1035 int port = pB->i2ePointer;
1041 OUTB ( port, SEL_OUTMAIL ); 1036 outb(SEL_OUTMAIL, port);
1042 return ( INB(port) == 0 ); 1037 return inb(port) == 0;
1043} 1038}
1044 1039
1045//****************************************************************************** 1040//******************************************************************************
@@ -1060,7 +1055,7 @@ iiTxMailEmptyII(i2eBordStrPtr pB)
1060static int 1055static int
1061iiTxMailEmptyIIEX(i2eBordStrPtr pB) 1056iiTxMailEmptyIIEX(i2eBordStrPtr pB)
1062{ 1057{
1063 return !(INB(pB->i2eStatus) & STE_OUT_MAIL); 1058 return !(inb(pB->i2eStatus) & STE_OUT_MAIL);
1064} 1059}
1065 1060
1066//****************************************************************************** 1061//******************************************************************************
@@ -1084,10 +1079,10 @@ iiTrySendMailII(i2eBordStrPtr pB, unsigned char mail)
1084{ 1079{
1085 int port = pB->i2ePointer; 1080 int port = pB->i2ePointer;
1086 1081
1087 OUTB(port, SEL_OUTMAIL); 1082 outb(SEL_OUTMAIL, port);
1088 if (INB(port) == 0) { 1083 if (inb(port) == 0) {
1089 OUTB(port, SEL_OUTMAIL); 1084 outb(SEL_OUTMAIL, port);
1090 OUTB(port, mail); 1085 outb(mail, port);
1091 return 1; 1086 return 1;
1092 } 1087 }
1093 return 0; 1088 return 0;
@@ -1112,10 +1107,9 @@ iiTrySendMailII(i2eBordStrPtr pB, unsigned char mail)
1112static int 1107static int
1113iiTrySendMailIIEX(i2eBordStrPtr pB, unsigned char mail) 1108iiTrySendMailIIEX(i2eBordStrPtr pB, unsigned char mail)
1114{ 1109{
1115 if(INB(pB->i2eStatus) & STE_OUT_MAIL) { 1110 if (inb(pB->i2eStatus) & STE_OUT_MAIL)
1116 return 0; 1111 return 0;
1117 } 1112 outb(mail, pB->i2eXMail);
1118 OUTB(pB->i2eXMail, mail);
1119 return 1; 1113 return 1;
1120} 1114}
1121 1115
@@ -1136,9 +1130,9 @@ iiTrySendMailIIEX(i2eBordStrPtr pB, unsigned char mail)
1136static unsigned short 1130static unsigned short
1137iiGetMailII(i2eBordStrPtr pB) 1131iiGetMailII(i2eBordStrPtr pB)
1138{ 1132{
1139 if (HAS_MAIL(pB)) { 1133 if (I2_HAS_MAIL(pB)) {
1140 OUTB(pB->i2ePointer, SEL_INMAIL); 1134 outb(SEL_INMAIL, pB->i2ePointer);
1141 return INB(pB->i2ePointer); 1135 return inb(pB->i2ePointer);
1142 } else { 1136 } else {
1143 return NO_MAIL_HERE; 1137 return NO_MAIL_HERE;
1144 } 1138 }
@@ -1161,11 +1155,10 @@ iiGetMailII(i2eBordStrPtr pB)
1161static unsigned short 1155static unsigned short
1162iiGetMailIIEX(i2eBordStrPtr pB) 1156iiGetMailIIEX(i2eBordStrPtr pB)
1163{ 1157{
1164 if (HAS_MAIL(pB)) { 1158 if (I2_HAS_MAIL(pB))
1165 return INB(pB->i2eXMail); 1159 return inb(pB->i2eXMail);
1166 } else { 1160 else
1167 return NO_MAIL_HERE; 1161 return NO_MAIL_HERE;
1168 }
1169} 1162}
1170 1163
1171//****************************************************************************** 1164//******************************************************************************
@@ -1184,8 +1177,8 @@ iiGetMailIIEX(i2eBordStrPtr pB)
1184static void 1177static void
1185iiEnableMailIrqII(i2eBordStrPtr pB) 1178iiEnableMailIrqII(i2eBordStrPtr pB)
1186{ 1179{
1187 OUTB(pB->i2ePointer, SEL_MASK); 1180 outb(SEL_MASK, pB->i2ePointer);
1188 OUTB(pB->i2ePointer, ST_IN_MAIL); 1181 outb(ST_IN_MAIL, pB->i2ePointer);
1189} 1182}
1190 1183
1191//****************************************************************************** 1184//******************************************************************************
@@ -1204,7 +1197,7 @@ iiEnableMailIrqII(i2eBordStrPtr pB)
1204static void 1197static void
1205iiEnableMailIrqIIEX(i2eBordStrPtr pB) 1198iiEnableMailIrqIIEX(i2eBordStrPtr pB)
1206{ 1199{
1207 OUTB(pB->i2eXMask, MX_IN_MAIL); 1200 outb(MX_IN_MAIL, pB->i2eXMask);
1208} 1201}
1209 1202
1210//****************************************************************************** 1203//******************************************************************************
@@ -1223,8 +1216,8 @@ iiEnableMailIrqIIEX(i2eBordStrPtr pB)
1223static void 1216static void
1224iiWriteMaskII(i2eBordStrPtr pB, unsigned char value) 1217iiWriteMaskII(i2eBordStrPtr pB, unsigned char value)
1225{ 1218{
1226 OUTB(pB->i2ePointer, SEL_MASK); 1219 outb(SEL_MASK, pB->i2ePointer);
1227 OUTB(pB->i2ePointer, value); 1220 outb(value, pB->i2ePointer);
1228} 1221}
1229 1222
1230//****************************************************************************** 1223//******************************************************************************
@@ -1243,7 +1236,7 @@ iiWriteMaskII(i2eBordStrPtr pB, unsigned char value)
1243static void 1236static void
1244iiWriteMaskIIEX(i2eBordStrPtr pB, unsigned char value) 1237iiWriteMaskIIEX(i2eBordStrPtr pB, unsigned char value)
1245{ 1238{
1246 OUTB(pB->i2eXMask, value); 1239 outb(value, pB->i2eXMask);
1247} 1240}
1248 1241
1249//****************************************************************************** 1242//******************************************************************************
@@ -1354,9 +1347,8 @@ iiDownloadBlock ( i2eBordStrPtr pB, loadHdrStrPtr pSource, int isStandard)
1354 // immediately and be harmless, though not strictly necessary. 1347 // immediately and be harmless, though not strictly necessary.
1355 itemp = MAX_DLOAD_ACK_TIME/10; 1348 itemp = MAX_DLOAD_ACK_TIME/10;
1356 while (--itemp) { 1349 while (--itemp) {
1357 if (HAS_INPUT(pB)) { 1350 if (I2_HAS_INPUT(pB)) {
1358 switch(BYTE_FROM(pB)) 1351 switch (inb(pB->i2eData)) {
1359 {
1360 case LOADWARE_OK: 1352 case LOADWARE_OK:
1361 pB->i2eState = 1353 pB->i2eState =
1362 isStandard ? II_STATE_STDLOADED :II_STATE_LOADED; 1354 isStandard ? II_STATE_STDLOADED :II_STATE_LOADED;
diff --git a/drivers/char/ip2/i2ellis.h b/drivers/char/ip2/i2ellis.h
index 433305062fb8..c88a64e527aa 100644
--- a/drivers/char/ip2/i2ellis.h
+++ b/drivers/char/ip2/i2ellis.h
@@ -185,10 +185,6 @@ typedef struct _i2eBordStr
185 // The highest allowable IRQ, based on the 185 // The highest allowable IRQ, based on the
186 // slot size. 186 // slot size.
187 187
188 unsigned char i2eChangeIrq;
189 // Whether tis valid to change IRQ's
190 // ISA = ok, EISA, MicroChannel, no
191
192 // Accelerators for various addresses on the board 188 // Accelerators for various addresses on the board
193 int i2eBase; // I/O Address of the Board 189 int i2eBase; // I/O Address of the Board
194 int i2eData; // From here data transfers happen 190 int i2eData; // From here data transfers happen
@@ -431,12 +427,6 @@ typedef struct _i2eBordStr
431// Manifests for i2eBordStr: 427// Manifests for i2eBordStr:
432//------------------------------------------- 428//-------------------------------------------
433 429
434#define YES 1
435#define NO 0
436
437#define NULLFUNC (void (*)(void))0
438#define NULLPTR (void *)0
439
440typedef void (*delayFunc_t)(unsigned int); 430typedef void (*delayFunc_t)(unsigned int);
441 431
442// i2eValid 432// i2eValid
@@ -494,8 +484,8 @@ typedef void (*delayFunc_t)(unsigned int);
494 484
495// i2eUsingIrq 485// i2eUsingIrq
496// 486//
497#define IRQ_UNDEFINED 0x1352 // No valid irq (or polling = 0) can ever 487#define I2_IRQ_UNDEFINED 0x1352 /* No valid irq (or polling = 0) can
498 // promote to this! 488 * ever promote to this! */
499//------------------------------------------ 489//------------------------------------------
500// Handy Macros for i2ellis.c and others 490// Handy Macros for i2ellis.c and others
501// Note these are common to -II and -IIEX 491// Note these are common to -II and -IIEX
@@ -504,41 +494,14 @@ typedef void (*delayFunc_t)(unsigned int);
504// Given a pointer to the board structure, does the input FIFO have any data or 494// Given a pointer to the board structure, does the input FIFO have any data or
505// not? 495// not?
506// 496//
507#define HAS_INPUT(pB) !(INB(pB->i2eStatus) & ST_IN_EMPTY) 497#define I2_HAS_INPUT(pB) !(inb(pB->i2eStatus) & ST_IN_EMPTY)
508#define HAS_NO_INPUT(pB) (INB(pB->i2eStatus) & ST_IN_EMPTY)
509
510// Given a pointer to board structure, read a byte or word from the fifo
511//
512#define BYTE_FROM(pB) (unsigned char)INB(pB->i2eData)
513#define WORD_FROM(pB) (unsigned short)INW(pB->i2eData)
514
515// Given a pointer to board structure, is there room for any data to be written
516// to the data fifo?
517//
518#define HAS_OUTROOM(pB) !(INB(pB->i2eStatus) & ST_OUT_FULL)
519#define HAS_NO_OUTROOM(pB) (INB(pB->i2eStatus) & ST_OUT_FULL)
520
521// Given a pointer to board structure, write a single byte to the fifo
522// structure. Note that for 16-bit interfaces, the high order byte is undefined
523// and unknown.
524//
525#define BYTE_TO(pB, c) OUTB(pB->i2eData,(c))
526
527// Write a word to the fifo structure. For 8-bit interfaces, this may have
528// unknown results.
529//
530#define WORD_TO(pB, c) OUTW(pB->i2eData,(c))
531 498
532// Given a pointer to the board structure, is there anything in the incoming 499// Given a pointer to the board structure, is there anything in the incoming
533// mailbox? 500// mailbox?
534// 501//
535#define HAS_MAIL(pB) (INB(pB->i2eStatus) & ST_IN_MAIL) 502#define I2_HAS_MAIL(pB) (inb(pB->i2eStatus) & ST_IN_MAIL)
536 503
537#define UPDATE_FIFO_ROOM(pB) (pB)->i2eFifoRemains=(pB)->i2eFifoSize 504#define I2_UPDATE_FIFO_ROOM(pB) ((pB)->i2eFifoRemains = (pB)->i2eFifoSize)
538
539// Handy macro to round up a number (like the buffer write and read routines do)
540//
541#define ROUNDUP(number) (((number)+1) & (~1))
542 505
543//------------------------------------------ 506//------------------------------------------
544// Function Declarations for i2ellis.c 507// Function Declarations for i2ellis.c
@@ -593,20 +556,11 @@ static int iiDownloadBlock(i2eBordStrPtr, loadHdrStrPtr, int);
593// 556//
594static int iiDownloadAll(i2eBordStrPtr, loadHdrStrPtr, int, int); 557static int iiDownloadAll(i2eBordStrPtr, loadHdrStrPtr, int, int);
595 558
596// Called indirectly always. Needed externally so the routine might be
597// SPECIFIED as an argument to iiReset()
598//
599//static void ii2DelayIO(unsigned int); // N-millisecond delay using
600 //hardware spin
601//static void ii2DelayTimer(unsigned int); // N-millisecond delay using Linux
602 //timer
603
604// Many functions defined here return True if good, False otherwise, with an 559// Many functions defined here return True if good, False otherwise, with an
605// error code in i2eError field. Here is a handy macro for setting the error 560// error code in i2eError field. Here is a handy macro for setting the error
606// code and returning. 561// code and returning.
607// 562//
608#define COMPLETE(pB,code) \ 563#define I2_COMPLETE(pB,code) do { \
609 do { \
610 pB->i2eError = code; \ 564 pB->i2eError = code; \
611 return (code == I2EE_GOOD);\ 565 return (code == I2EE_GOOD);\
612 } while (0) 566 } while (0)
diff --git a/drivers/char/ip2/i2hw.h b/drivers/char/ip2/i2hw.h
index 15fe04e748f4..8aa6e7ab8d5b 100644
--- a/drivers/char/ip2/i2hw.h
+++ b/drivers/char/ip2/i2hw.h
@@ -129,7 +129,6 @@ registers, use byte operations only.
129//------------------------------------------------ 129//------------------------------------------------
130// 130//
131#include "ip2types.h" 131#include "ip2types.h"
132#include "i2os.h" /* For any o.s., compiler, or host-related issues */
133 132
134//------------------------------------------------------------------------- 133//-------------------------------------------------------------------------
135// Manifests for the I/O map: 134// Manifests for the I/O map:
@@ -644,5 +643,10 @@ typedef union _loadHdrStr
644#define ABS_BIGGEST_BOX 16 // Absolute the most ports per box 643#define ABS_BIGGEST_BOX 16 // Absolute the most ports per box
645#define ABS_MOST_PORTS (ABS_MAX_BOXES * ABS_BIGGEST_BOX) 644#define ABS_MOST_PORTS (ABS_MAX_BOXES * ABS_BIGGEST_BOX)
646 645
646#define I2_OUTSW(port, addr, count) outsw((port), (addr), (((count)+1)/2))
647#define I2_OUTSB(port, addr, count) outsb((port), (addr), (((count)+1))&-2)
648#define I2_INSW(port, addr, count) insw((port), (addr), (((count)+1)/2))
649#define I2_INSB(port, addr, count) insb((port), (addr), (((count)+1))&-2)
650
647#endif // I2HW_H 651#endif // I2HW_H
648 652
diff --git a/drivers/char/ip2/i2lib.c b/drivers/char/ip2/i2lib.c
index 9c25320121ef..938879cc7bcc 100644
--- a/drivers/char/ip2/i2lib.c
+++ b/drivers/char/ip2/i2lib.c
@@ -227,17 +227,17 @@ i2InitChannels ( i2eBordStrPtr pB, int nChannels, i2ChanStrPtr pCh)
227 i2ChanStrPtr *ppCh; 227 i2ChanStrPtr *ppCh;
228 228
229 if (pB->i2eValid != I2E_MAGIC) { 229 if (pB->i2eValid != I2E_MAGIC) {
230 COMPLETE(pB, I2EE_BADMAGIC); 230 I2_COMPLETE(pB, I2EE_BADMAGIC);
231 } 231 }
232 if (pB->i2eState != II_STATE_STDLOADED) { 232 if (pB->i2eState != II_STATE_STDLOADED) {
233 COMPLETE(pB, I2EE_BADSTATE); 233 I2_COMPLETE(pB, I2EE_BADSTATE);
234 } 234 }
235 235
236 LOCK_INIT(&pB->read_fifo_spinlock); 236 rwlock_init(&pB->read_fifo_spinlock);
237 LOCK_INIT(&pB->write_fifo_spinlock); 237 rwlock_init(&pB->write_fifo_spinlock);
238 LOCK_INIT(&pB->Dbuf_spinlock); 238 rwlock_init(&pB->Dbuf_spinlock);
239 LOCK_INIT(&pB->Bbuf_spinlock); 239 rwlock_init(&pB->Bbuf_spinlock);
240 LOCK_INIT(&pB->Fbuf_spinlock); 240 rwlock_init(&pB->Fbuf_spinlock);
241 241
242 // NO LOCK needed yet - this is init 242 // NO LOCK needed yet - this is init
243 243
@@ -259,10 +259,10 @@ i2InitChannels ( i2eBordStrPtr pB, int nChannels, i2ChanStrPtr pCh)
259 if ( !(pB->i2eChannelMap[index >> 4] & (1 << (index & 0xf)) ) ) { 259 if ( !(pB->i2eChannelMap[index >> 4] & (1 << (index & 0xf)) ) ) {
260 continue; 260 continue;
261 } 261 }
262 LOCK_INIT(&pCh->Ibuf_spinlock); 262 rwlock_init(&pCh->Ibuf_spinlock);
263 LOCK_INIT(&pCh->Obuf_spinlock); 263 rwlock_init(&pCh->Obuf_spinlock);
264 LOCK_INIT(&pCh->Cbuf_spinlock); 264 rwlock_init(&pCh->Cbuf_spinlock);
265 LOCK_INIT(&pCh->Pbuf_spinlock); 265 rwlock_init(&pCh->Pbuf_spinlock);
266 // NO LOCK needed yet - this is init 266 // NO LOCK needed yet - this is init
267 // Set up validity flag according to support level 267 // Set up validity flag according to support level
268 if (pB->i2eGoodMap[index >> 4] & (1 << (index & 0xf)) ) { 268 if (pB->i2eGoodMap[index >> 4] & (1 << (index & 0xf)) ) {
@@ -347,7 +347,7 @@ i2InitChannels ( i2eBordStrPtr pB, int nChannels, i2ChanStrPtr pCh)
347 } 347 }
348 // No need to check for wrap here; this is initialization. 348 // No need to check for wrap here; this is initialization.
349 pB->i2Fbuf_stuff = stuffIndex; 349 pB->i2Fbuf_stuff = stuffIndex;
350 COMPLETE(pB, I2EE_GOOD); 350 I2_COMPLETE(pB, I2EE_GOOD);
351 351
352} 352}
353 353
@@ -374,7 +374,7 @@ i2DeQueueNeeds(i2eBordStrPtr pB, int type)
374 374
375 case NEED_INLINE: 375 case NEED_INLINE:
376 376
377 WRITE_LOCK_IRQSAVE(&pB->Dbuf_spinlock,flags); 377 write_lock_irqsave(&pB->Dbuf_spinlock, flags);
378 if ( pB->i2Dbuf_stuff != pB->i2Dbuf_strip) 378 if ( pB->i2Dbuf_stuff != pB->i2Dbuf_strip)
379 { 379 {
380 queueIndex = pB->i2Dbuf_strip; 380 queueIndex = pB->i2Dbuf_strip;
@@ -386,12 +386,12 @@ i2DeQueueNeeds(i2eBordStrPtr pB, int type)
386 pB->i2Dbuf_strip = queueIndex; 386 pB->i2Dbuf_strip = queueIndex;
387 pCh->channelNeeds &= ~NEED_INLINE; 387 pCh->channelNeeds &= ~NEED_INLINE;
388 } 388 }
389 WRITE_UNLOCK_IRQRESTORE(&pB->Dbuf_spinlock,flags); 389 write_unlock_irqrestore(&pB->Dbuf_spinlock, flags);
390 break; 390 break;
391 391
392 case NEED_BYPASS: 392 case NEED_BYPASS:
393 393
394 WRITE_LOCK_IRQSAVE(&pB->Bbuf_spinlock,flags); 394 write_lock_irqsave(&pB->Bbuf_spinlock, flags);
395 if (pB->i2Bbuf_stuff != pB->i2Bbuf_strip) 395 if (pB->i2Bbuf_stuff != pB->i2Bbuf_strip)
396 { 396 {
397 queueIndex = pB->i2Bbuf_strip; 397 queueIndex = pB->i2Bbuf_strip;
@@ -403,12 +403,12 @@ i2DeQueueNeeds(i2eBordStrPtr pB, int type)
403 pB->i2Bbuf_strip = queueIndex; 403 pB->i2Bbuf_strip = queueIndex;
404 pCh->channelNeeds &= ~NEED_BYPASS; 404 pCh->channelNeeds &= ~NEED_BYPASS;
405 } 405 }
406 WRITE_UNLOCK_IRQRESTORE(&pB->Bbuf_spinlock,flags); 406 write_unlock_irqrestore(&pB->Bbuf_spinlock, flags);
407 break; 407 break;
408 408
409 case NEED_FLOW: 409 case NEED_FLOW:
410 410
411 WRITE_LOCK_IRQSAVE(&pB->Fbuf_spinlock,flags); 411 write_lock_irqsave(&pB->Fbuf_spinlock, flags);
412 if (pB->i2Fbuf_stuff != pB->i2Fbuf_strip) 412 if (pB->i2Fbuf_stuff != pB->i2Fbuf_strip)
413 { 413 {
414 queueIndex = pB->i2Fbuf_strip; 414 queueIndex = pB->i2Fbuf_strip;
@@ -420,7 +420,7 @@ i2DeQueueNeeds(i2eBordStrPtr pB, int type)
420 pB->i2Fbuf_strip = queueIndex; 420 pB->i2Fbuf_strip = queueIndex;
421 pCh->channelNeeds &= ~NEED_FLOW; 421 pCh->channelNeeds &= ~NEED_FLOW;
422 } 422 }
423 WRITE_UNLOCK_IRQRESTORE(&pB->Fbuf_spinlock,flags); 423 write_unlock_irqrestore(&pB->Fbuf_spinlock, flags);
424 break; 424 break;
425 default: 425 default:
426 printk(KERN_ERR "i2DeQueueNeeds called with bad type:%x\n",type); 426 printk(KERN_ERR "i2DeQueueNeeds called with bad type:%x\n",type);
@@ -453,7 +453,7 @@ i2QueueNeeds(i2eBordStrPtr pB, i2ChanStrPtr pCh, int type)
453 453
454 case NEED_INLINE: 454 case NEED_INLINE:
455 455
456 WRITE_LOCK_IRQSAVE(&pB->Dbuf_spinlock,flags); 456 write_lock_irqsave(&pB->Dbuf_spinlock, flags);
457 if ( !(pCh->channelNeeds & NEED_INLINE) ) 457 if ( !(pCh->channelNeeds & NEED_INLINE) )
458 { 458 {
459 pCh->channelNeeds |= NEED_INLINE; 459 pCh->channelNeeds |= NEED_INLINE;
@@ -463,12 +463,12 @@ i2QueueNeeds(i2eBordStrPtr pB, i2ChanStrPtr pCh, int type)
463 queueIndex = 0; 463 queueIndex = 0;
464 pB->i2Dbuf_stuff = queueIndex; 464 pB->i2Dbuf_stuff = queueIndex;
465 } 465 }
466 WRITE_UNLOCK_IRQRESTORE(&pB->Dbuf_spinlock,flags); 466 write_unlock_irqrestore(&pB->Dbuf_spinlock, flags);
467 break; 467 break;
468 468
469 case NEED_BYPASS: 469 case NEED_BYPASS:
470 470
471 WRITE_LOCK_IRQSAVE(&pB->Bbuf_spinlock,flags); 471 write_lock_irqsave(&pB->Bbuf_spinlock, flags);
472 if ((type & NEED_BYPASS) && !(pCh->channelNeeds & NEED_BYPASS)) 472 if ((type & NEED_BYPASS) && !(pCh->channelNeeds & NEED_BYPASS))
473 { 473 {
474 pCh->channelNeeds |= NEED_BYPASS; 474 pCh->channelNeeds |= NEED_BYPASS;
@@ -478,12 +478,12 @@ i2QueueNeeds(i2eBordStrPtr pB, i2ChanStrPtr pCh, int type)
478 queueIndex = 0; 478 queueIndex = 0;
479 pB->i2Bbuf_stuff = queueIndex; 479 pB->i2Bbuf_stuff = queueIndex;
480 } 480 }
481 WRITE_UNLOCK_IRQRESTORE(&pB->Bbuf_spinlock,flags); 481 write_unlock_irqrestore(&pB->Bbuf_spinlock, flags);
482 break; 482 break;
483 483
484 case NEED_FLOW: 484 case NEED_FLOW:
485 485
486 WRITE_LOCK_IRQSAVE(&pB->Fbuf_spinlock,flags); 486 write_lock_irqsave(&pB->Fbuf_spinlock, flags);
487 if ((type & NEED_FLOW) && !(pCh->channelNeeds & NEED_FLOW)) 487 if ((type & NEED_FLOW) && !(pCh->channelNeeds & NEED_FLOW))
488 { 488 {
489 pCh->channelNeeds |= NEED_FLOW; 489 pCh->channelNeeds |= NEED_FLOW;
@@ -493,7 +493,7 @@ i2QueueNeeds(i2eBordStrPtr pB, i2ChanStrPtr pCh, int type)
493 queueIndex = 0; 493 queueIndex = 0;
494 pB->i2Fbuf_stuff = queueIndex; 494 pB->i2Fbuf_stuff = queueIndex;
495 } 495 }
496 WRITE_UNLOCK_IRQRESTORE(&pB->Fbuf_spinlock,flags); 496 write_unlock_irqrestore(&pB->Fbuf_spinlock, flags);
497 break; 497 break;
498 498
499 case NEED_CREDIT: 499 case NEED_CREDIT:
@@ -562,9 +562,8 @@ i2QueueCommands(int type, i2ChanStrPtr pCh, int timeout, int nCommands,
562 pB = pCh->pMyBord; 562 pB = pCh->pMyBord;
563 563
564 // Board must also exist, and THE INTERRUPT COMMAND ALREADY SENT 564 // Board must also exist, and THE INTERRUPT COMMAND ALREADY SENT
565 if (pB->i2eValid != I2E_MAGIC || pB->i2eUsingIrq == IRQ_UNDEFINED) { 565 if (pB->i2eValid != I2E_MAGIC || pB->i2eUsingIrq == I2_IRQ_UNDEFINED)
566 return -2; 566 return -2;
567 }
568 // If the board has gone fatal, return bad, and also hit the trap routine if 567 // If the board has gone fatal, return bad, and also hit the trap routine if
569 // it exists. 568 // it exists.
570 if (pB->i2eFatal) { 569 if (pB->i2eFatal) {
@@ -620,13 +619,13 @@ i2QueueCommands(int type, i2ChanStrPtr pCh, int timeout, int nCommands,
620 switch(type) { 619 switch(type) {
621 case PTYPE_INLINE: 620 case PTYPE_INLINE:
622 lock_var_p = &pCh->Obuf_spinlock; 621 lock_var_p = &pCh->Obuf_spinlock;
623 WRITE_LOCK_IRQSAVE(lock_var_p,flags); 622 write_lock_irqsave(lock_var_p, flags);
624 stuffIndex = pCh->Obuf_stuff; 623 stuffIndex = pCh->Obuf_stuff;
625 bufroom = pCh->Obuf_strip - stuffIndex; 624 bufroom = pCh->Obuf_strip - stuffIndex;
626 break; 625 break;
627 case PTYPE_BYPASS: 626 case PTYPE_BYPASS:
628 lock_var_p = &pCh->Cbuf_spinlock; 627 lock_var_p = &pCh->Cbuf_spinlock;
629 WRITE_LOCK_IRQSAVE(lock_var_p,flags); 628 write_lock_irqsave(lock_var_p, flags);
630 stuffIndex = pCh->Cbuf_stuff; 629 stuffIndex = pCh->Cbuf_stuff;
631 bufroom = pCh->Cbuf_strip - stuffIndex; 630 bufroom = pCh->Cbuf_strip - stuffIndex;
632 break; 631 break;
@@ -645,7 +644,7 @@ i2QueueCommands(int type, i2ChanStrPtr pCh, int timeout, int nCommands,
645 break; /* from for()- Enough room: goto proceed */ 644 break; /* from for()- Enough room: goto proceed */
646 } 645 }
647 ip2trace(CHANN, ITRC_QUEUE, 3, 1, totalsize); 646 ip2trace(CHANN, ITRC_QUEUE, 3, 1, totalsize);
648 WRITE_UNLOCK_IRQRESTORE(lock_var_p, flags); 647 write_unlock_irqrestore(lock_var_p, flags);
649 } else 648 } else
650 ip2trace(CHANN, ITRC_QUEUE, 3, 1, totalsize); 649 ip2trace(CHANN, ITRC_QUEUE, 3, 1, totalsize);
651 650
@@ -747,7 +746,7 @@ i2QueueCommands(int type, i2ChanStrPtr pCh, int timeout, int nCommands,
747 { 746 {
748 case PTYPE_INLINE: 747 case PTYPE_INLINE:
749 pCh->Obuf_stuff = stuffIndex; // Store buffer pointer 748 pCh->Obuf_stuff = stuffIndex; // Store buffer pointer
750 WRITE_UNLOCK_IRQRESTORE(&pCh->Obuf_spinlock,flags); 749 write_unlock_irqrestore(&pCh->Obuf_spinlock, flags);
751 750
752 pB->debugInlineQueued++; 751 pB->debugInlineQueued++;
753 // Add the channel pointer to list of channels needing service (first 752 // Add the channel pointer to list of channels needing service (first
@@ -757,7 +756,7 @@ i2QueueCommands(int type, i2ChanStrPtr pCh, int timeout, int nCommands,
757 756
758 case PTYPE_BYPASS: 757 case PTYPE_BYPASS:
759 pCh->Cbuf_stuff = stuffIndex; // Store buffer pointer 758 pCh->Cbuf_stuff = stuffIndex; // Store buffer pointer
760 WRITE_UNLOCK_IRQRESTORE(&pCh->Cbuf_spinlock,flags); 759 write_unlock_irqrestore(&pCh->Cbuf_spinlock, flags);
761 760
762 pB->debugBypassQueued++; 761 pB->debugBypassQueued++;
763 // Add the channel pointer to list of channels needing service (first 762 // Add the channel pointer to list of channels needing service (first
@@ -840,7 +839,7 @@ i2Input(i2ChanStrPtr pCh)
840 count = -1; 839 count = -1;
841 goto i2Input_exit; 840 goto i2Input_exit;
842 } 841 }
843 WRITE_LOCK_IRQSAVE(&pCh->Ibuf_spinlock,flags); 842 write_lock_irqsave(&pCh->Ibuf_spinlock, flags);
844 843
845 // initialize some accelerators and private copies 844 // initialize some accelerators and private copies
846 stripIndex = pCh->Ibuf_strip; 845 stripIndex = pCh->Ibuf_strip;
@@ -850,7 +849,7 @@ i2Input(i2ChanStrPtr pCh)
850 // If buffer is empty or requested data count was 0, (trivial case) return 849 // If buffer is empty or requested data count was 0, (trivial case) return
851 // without any further thought. 850 // without any further thought.
852 if ( count == 0 ) { 851 if ( count == 0 ) {
853 WRITE_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags); 852 write_unlock_irqrestore(&pCh->Ibuf_spinlock, flags);
854 goto i2Input_exit; 853 goto i2Input_exit;
855 } 854 }
856 // Adjust for buffer wrap 855 // Adjust for buffer wrap
@@ -891,10 +890,10 @@ i2Input(i2ChanStrPtr pCh)
891 890
892 if ((pCh->sinceLastFlow += count) >= pCh->whenSendFlow) { 891 if ((pCh->sinceLastFlow += count) >= pCh->whenSendFlow) {
893 pCh->sinceLastFlow -= pCh->whenSendFlow; 892 pCh->sinceLastFlow -= pCh->whenSendFlow;
894 WRITE_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags); 893 write_unlock_irqrestore(&pCh->Ibuf_spinlock, flags);
895 i2QueueNeeds(pCh->pMyBord, pCh, NEED_FLOW); 894 i2QueueNeeds(pCh->pMyBord, pCh, NEED_FLOW);
896 } else { 895 } else {
897 WRITE_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags); 896 write_unlock_irqrestore(&pCh->Ibuf_spinlock, flags);
898 } 897 }
899 898
900i2Input_exit: 899i2Input_exit:
@@ -926,7 +925,7 @@ i2InputFlush(i2ChanStrPtr pCh)
926 925
927 ip2trace (CHANN, ITRC_INPUT, 10, 0); 926 ip2trace (CHANN, ITRC_INPUT, 10, 0);
928 927
929 WRITE_LOCK_IRQSAVE(&pCh->Ibuf_spinlock,flags); 928 write_lock_irqsave(&pCh->Ibuf_spinlock, flags);
930 count = pCh->Ibuf_stuff - pCh->Ibuf_strip; 929 count = pCh->Ibuf_stuff - pCh->Ibuf_strip;
931 930
932 // Adjust for buffer wrap 931 // Adjust for buffer wrap
@@ -947,10 +946,10 @@ i2InputFlush(i2ChanStrPtr pCh)
947 if ( (pCh->sinceLastFlow += count) >= pCh->whenSendFlow ) 946 if ( (pCh->sinceLastFlow += count) >= pCh->whenSendFlow )
948 { 947 {
949 pCh->sinceLastFlow -= pCh->whenSendFlow; 948 pCh->sinceLastFlow -= pCh->whenSendFlow;
950 WRITE_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags); 949 write_unlock_irqrestore(&pCh->Ibuf_spinlock, flags);
951 i2QueueNeeds(pCh->pMyBord, pCh, NEED_FLOW); 950 i2QueueNeeds(pCh->pMyBord, pCh, NEED_FLOW);
952 } else { 951 } else {
953 WRITE_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags); 952 write_unlock_irqrestore(&pCh->Ibuf_spinlock, flags);
954 } 953 }
955 954
956 ip2trace (CHANN, ITRC_INPUT, 19, 1, count); 955 ip2trace (CHANN, ITRC_INPUT, 19, 1, count);
@@ -979,9 +978,9 @@ i2InputAvailable(i2ChanStrPtr pCh)
979 978
980 979
981 // initialize some accelerators and private copies 980 // initialize some accelerators and private copies
982 READ_LOCK_IRQSAVE(&pCh->Ibuf_spinlock,flags); 981 read_lock_irqsave(&pCh->Ibuf_spinlock, flags);
983 count = pCh->Ibuf_stuff - pCh->Ibuf_strip; 982 count = pCh->Ibuf_stuff - pCh->Ibuf_strip;
984 READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags); 983 read_unlock_irqrestore(&pCh->Ibuf_spinlock, flags);
985 984
986 // Adjust for buffer wrap 985 // Adjust for buffer wrap
987 if (count < 0) 986 if (count < 0)
@@ -1045,9 +1044,9 @@ i2Output(i2ChanStrPtr pCh, const char *pSource, int count)
1045 while ( count > 0 ) { 1044 while ( count > 0 ) {
1046 1045
1047 // How much room in output buffer is there? 1046 // How much room in output buffer is there?
1048 READ_LOCK_IRQSAVE(&pCh->Obuf_spinlock,flags); 1047 read_lock_irqsave(&pCh->Obuf_spinlock, flags);
1049 amountToMove = pCh->Obuf_strip - pCh->Obuf_stuff - 1; 1048 amountToMove = pCh->Obuf_strip - pCh->Obuf_stuff - 1;
1050 READ_UNLOCK_IRQRESTORE(&pCh->Obuf_spinlock,flags); 1049 read_unlock_irqrestore(&pCh->Obuf_spinlock, flags);
1051 if (amountToMove < 0) { 1050 if (amountToMove < 0) {
1052 amountToMove += OBUF_SIZE; 1051 amountToMove += OBUF_SIZE;
1053 } 1052 }
@@ -1075,7 +1074,7 @@ i2Output(i2ChanStrPtr pCh, const char *pSource, int count)
1075 if ( !(pCh->flush_flags && i2RetryFlushOutput(pCh) ) 1074 if ( !(pCh->flush_flags && i2RetryFlushOutput(pCh) )
1076 && amountToMove > 0 ) 1075 && amountToMove > 0 )
1077 { 1076 {
1078 WRITE_LOCK_IRQSAVE(&pCh->Obuf_spinlock,flags); 1077 write_lock_irqsave(&pCh->Obuf_spinlock, flags);
1079 stuffIndex = pCh->Obuf_stuff; 1078 stuffIndex = pCh->Obuf_stuff;
1080 1079
1081 // Had room to move some data: don't know whether the block size, 1080 // Had room to move some data: don't know whether the block size,
@@ -1102,7 +1101,7 @@ i2Output(i2ChanStrPtr pCh, const char *pSource, int count)
1102 } 1101 }
1103 pCh->Obuf_stuff = stuffIndex; 1102 pCh->Obuf_stuff = stuffIndex;
1104 1103
1105 WRITE_UNLOCK_IRQRESTORE(&pCh->Obuf_spinlock,flags); 1104 write_unlock_irqrestore(&pCh->Obuf_spinlock, flags);
1106 1105
1107 ip2trace (CHANN, ITRC_OUTPUT, 13, 1, stuffIndex ); 1106 ip2trace (CHANN, ITRC_OUTPUT, 13, 1, stuffIndex );
1108 1107
@@ -1352,9 +1351,9 @@ i2OutputFree(i2ChanStrPtr pCh)
1352 if ( !i2Validate ( pCh ) ) { 1351 if ( !i2Validate ( pCh ) ) {
1353 return -1; 1352 return -1;
1354 } 1353 }
1355 READ_LOCK_IRQSAVE(&pCh->Obuf_spinlock,flags); 1354 read_lock_irqsave(&pCh->Obuf_spinlock, flags);
1356 amountToMove = pCh->Obuf_strip - pCh->Obuf_stuff - 1; 1355 amountToMove = pCh->Obuf_strip - pCh->Obuf_stuff - 1;
1357 READ_UNLOCK_IRQRESTORE(&pCh->Obuf_spinlock,flags); 1356 read_unlock_irqrestore(&pCh->Obuf_spinlock, flags);
1358 1357
1359 if (amountToMove < 0) { 1358 if (amountToMove < 0) {
1360 amountToMove += OBUF_SIZE; 1359 amountToMove += OBUF_SIZE;
@@ -1464,11 +1463,11 @@ i2StripFifo(i2eBordStrPtr pB)
1464 1463
1465// ip2trace (ITRC_NO_PORT, ITRC_SFIFO, ITRC_ENTER, 0 ); 1464// ip2trace (ITRC_NO_PORT, ITRC_SFIFO, ITRC_ENTER, 0 );
1466 1465
1467 while (HAS_INPUT(pB)) { 1466 while (I2_HAS_INPUT(pB)) {
1468// ip2trace (ITRC_NO_PORT, ITRC_SFIFO, 2, 0 ); 1467// ip2trace (ITRC_NO_PORT, ITRC_SFIFO, 2, 0 );
1469 1468
1470 // Process packet from fifo a one atomic unit 1469 // Process packet from fifo a one atomic unit
1471 WRITE_LOCK_IRQSAVE(&pB->read_fifo_spinlock,bflags); 1470 write_lock_irqsave(&pB->read_fifo_spinlock, bflags);
1472 1471
1473 // The first word (or two bytes) will have channel number and type of 1472 // The first word (or two bytes) will have channel number and type of
1474 // packet, possibly other information 1473 // packet, possibly other information
@@ -1490,7 +1489,8 @@ i2StripFifo(i2eBordStrPtr pB)
1490// sick! 1489// sick!
1491 if ( ((unsigned int)count) > IBUF_SIZE ) { 1490 if ( ((unsigned int)count) > IBUF_SIZE ) {
1492 pB->i2eFatal = 2; 1491 pB->i2eFatal = 2;
1493 WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock,bflags); 1492 write_unlock_irqrestore(&pB->read_fifo_spinlock,
1493 bflags);
1494 return; /* Bail out ASAP */ 1494 return; /* Bail out ASAP */
1495 } 1495 }
1496 // Channel is illegally big ? 1496 // Channel is illegally big ?
@@ -1498,7 +1498,8 @@ i2StripFifo(i2eBordStrPtr pB)
1498 (NULL==(pCh = ((i2ChanStrPtr*)pB->i2eChannelPtr)[channel]))) 1498 (NULL==(pCh = ((i2ChanStrPtr*)pB->i2eChannelPtr)[channel])))
1499 { 1499 {
1500 iiReadBuf(pB, junkBuffer, count); 1500 iiReadBuf(pB, junkBuffer, count);
1501 WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock,bflags); 1501 write_unlock_irqrestore(&pB->read_fifo_spinlock,
1502 bflags);
1502 break; /* From switch: ready for next packet */ 1503 break; /* From switch: ready for next packet */
1503 } 1504 }
1504 1505
@@ -1512,14 +1513,15 @@ i2StripFifo(i2eBordStrPtr pB)
1512 if(ID_OF(pB->i2eLeadoffWord) == ID_HOT_KEY) 1513 if(ID_OF(pB->i2eLeadoffWord) == ID_HOT_KEY)
1513 { 1514 {
1514 pCh->hotKeyIn = iiReadWord(pB) & 0xff; 1515 pCh->hotKeyIn = iiReadWord(pB) & 0xff;
1515 WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock,bflags); 1516 write_unlock_irqrestore(&pB->read_fifo_spinlock,
1517 bflags);
1516 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_HOTACK); 1518 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_HOTACK);
1517 break; /* From the switch: ready for next packet */ 1519 break; /* From the switch: ready for next packet */
1518 } 1520 }
1519 1521
1520 // Normal data! We crudely assume there is room for the data in our 1522 // Normal data! We crudely assume there is room for the data in our
1521 // buffer because the board wouldn't have exceeded his credit limit. 1523 // buffer because the board wouldn't have exceeded his credit limit.
1522 WRITE_LOCK_IRQSAVE(&pCh->Ibuf_spinlock,cflags); 1524 write_lock_irqsave(&pCh->Ibuf_spinlock, cflags);
1523 // We have 2 locks now 1525 // We have 2 locks now
1524 stuffIndex = pCh->Ibuf_stuff; 1526 stuffIndex = pCh->Ibuf_stuff;
1525 amountToRead = IBUF_SIZE - stuffIndex; 1527 amountToRead = IBUF_SIZE - stuffIndex;
@@ -1562,8 +1564,9 @@ i2StripFifo(i2eBordStrPtr pB)
1562 1564
1563 // Update stuff index 1565 // Update stuff index
1564 pCh->Ibuf_stuff = stuffIndex; 1566 pCh->Ibuf_stuff = stuffIndex;
1565 WRITE_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,cflags); 1567 write_unlock_irqrestore(&pCh->Ibuf_spinlock, cflags);
1566 WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock,bflags); 1568 write_unlock_irqrestore(&pB->read_fifo_spinlock,
1569 bflags);
1567 1570
1568#ifdef USE_IQ 1571#ifdef USE_IQ
1569 schedule_work(&pCh->tqueue_input); 1572 schedule_work(&pCh->tqueue_input);
@@ -1585,7 +1588,8 @@ i2StripFifo(i2eBordStrPtr pB)
1585 1588
1586 iiReadBuf(pB, cmdBuffer, count); 1589 iiReadBuf(pB, cmdBuffer, count);
1587 // We can release early with buffer grab 1590 // We can release early with buffer grab
1588 WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock,bflags); 1591 write_unlock_irqrestore(&pB->read_fifo_spinlock,
1592 bflags);
1589 1593
1590 pc = cmdBuffer; 1594 pc = cmdBuffer;
1591 pcLimit = &(cmdBuffer[count]); 1595 pcLimit = &(cmdBuffer[count]);
@@ -1830,12 +1834,12 @@ i2StripFifo(i2eBordStrPtr pB)
1830 default: // Neither packet? should be impossible 1834 default: // Neither packet? should be impossible
1831 ip2trace (ITRC_NO_PORT, ITRC_SFIFO, 5, 1, 1835 ip2trace (ITRC_NO_PORT, ITRC_SFIFO, 5, 1,
1832 PTYPE_OF(pB->i2eLeadoffWord) ); 1836 PTYPE_OF(pB->i2eLeadoffWord) );
1833 WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock, 1837 write_unlock_irqrestore(&pB->read_fifo_spinlock,
1834 bflags); 1838 bflags);
1835 1839
1836 break; 1840 break;
1837 } // End of switch on type of packets 1841 } // End of switch on type of packets
1838 } //while(board HAS_INPUT) 1842 } /*while(board I2_HAS_INPUT)*/
1839 1843
1840 ip2trace (ITRC_NO_PORT, ITRC_SFIFO, ITRC_RETURN, 0 ); 1844 ip2trace (ITRC_NO_PORT, ITRC_SFIFO, ITRC_RETURN, 0 );
1841 1845
@@ -1858,7 +1862,7 @@ i2Write2Fifo(i2eBordStrPtr pB, unsigned char *source, int count,int reserve)
1858{ 1862{
1859 int rc = 0; 1863 int rc = 0;
1860 unsigned long flags; 1864 unsigned long flags;
1861 WRITE_LOCK_IRQSAVE(&pB->write_fifo_spinlock,flags); 1865 write_lock_irqsave(&pB->write_fifo_spinlock, flags);
1862 if (!pB->i2eWaitingForEmptyFifo) { 1866 if (!pB->i2eWaitingForEmptyFifo) {
1863 if (pB->i2eFifoRemains > (count+reserve)) { 1867 if (pB->i2eFifoRemains > (count+reserve)) {
1864 pB->i2eFifoRemains -= count; 1868 pB->i2eFifoRemains -= count;
@@ -1867,7 +1871,7 @@ i2Write2Fifo(i2eBordStrPtr pB, unsigned char *source, int count,int reserve)
1867 rc = count; 1871 rc = count;
1868 } 1872 }
1869 } 1873 }
1870 WRITE_UNLOCK_IRQRESTORE(&pB->write_fifo_spinlock,flags); 1874 write_unlock_irqrestore(&pB->write_fifo_spinlock, flags);
1871 return rc; 1875 return rc;
1872} 1876}
1873//****************************************************************************** 1877//******************************************************************************
@@ -1898,7 +1902,7 @@ i2StuffFifoBypass(i2eBordStrPtr pB)
1898 while ( --bailout && notClogged && 1902 while ( --bailout && notClogged &&
1899 (NULL != (pCh = i2DeQueueNeeds(pB,NEED_BYPASS)))) 1903 (NULL != (pCh = i2DeQueueNeeds(pB,NEED_BYPASS))))
1900 { 1904 {
1901 WRITE_LOCK_IRQSAVE(&pCh->Cbuf_spinlock,flags); 1905 write_lock_irqsave(&pCh->Cbuf_spinlock, flags);
1902 stripIndex = pCh->Cbuf_strip; 1906 stripIndex = pCh->Cbuf_strip;
1903 1907
1904 // as long as there are packets for this channel... 1908 // as long as there are packets for this channel...
@@ -1906,7 +1910,7 @@ i2StuffFifoBypass(i2eBordStrPtr pB)
1906 while (stripIndex != pCh->Cbuf_stuff) { 1910 while (stripIndex != pCh->Cbuf_stuff) {
1907 pRemove = &(pCh->Cbuf[stripIndex]); 1911 pRemove = &(pCh->Cbuf[stripIndex]);
1908 packetSize = CMD_COUNT_OF(pRemove) + sizeof(i2CmdHeader); 1912 packetSize = CMD_COUNT_OF(pRemove) + sizeof(i2CmdHeader);
1909 paddedSize = ROUNDUP(packetSize); 1913 paddedSize = roundup(packetSize, 2);
1910 1914
1911 if (paddedSize > 0) { 1915 if (paddedSize > 0) {
1912 if ( 0 == i2Write2Fifo(pB, pRemove, paddedSize,0)) { 1916 if ( 0 == i2Write2Fifo(pB, pRemove, paddedSize,0)) {
@@ -1930,7 +1934,7 @@ WriteDBGBuf("BYPS", pRemove, paddedSize);
1930 // Done with this channel. Move to next, removing this one from 1934 // Done with this channel. Move to next, removing this one from
1931 // the queue of channels if we cleaned it out (i.e., didn't get clogged. 1935 // the queue of channels if we cleaned it out (i.e., didn't get clogged.
1932 pCh->Cbuf_strip = stripIndex; 1936 pCh->Cbuf_strip = stripIndex;
1933 WRITE_UNLOCK_IRQRESTORE(&pCh->Cbuf_spinlock,flags); 1937 write_unlock_irqrestore(&pCh->Cbuf_spinlock, flags);
1934 } // Either clogged or finished all the work 1938 } // Either clogged or finished all the work
1935 1939
1936#ifdef IP2DEBUG_TRACE 1940#ifdef IP2DEBUG_TRACE
@@ -1954,7 +1958,7 @@ static inline void
1954i2StuffFifoFlow(i2eBordStrPtr pB) 1958i2StuffFifoFlow(i2eBordStrPtr pB)
1955{ 1959{
1956 i2ChanStrPtr pCh; 1960 i2ChanStrPtr pCh;
1957 unsigned short paddedSize = ROUNDUP(sizeof(flowIn)); 1961 unsigned short paddedSize = roundup(sizeof(flowIn), 2);
1958 1962
1959 ip2trace (ITRC_NO_PORT, ITRC_SFLOW, ITRC_ENTER, 2, 1963 ip2trace (ITRC_NO_PORT, ITRC_SFLOW, ITRC_ENTER, 2,
1960 pB->i2eFifoRemains, paddedSize ); 1964 pB->i2eFifoRemains, paddedSize );
@@ -2010,7 +2014,7 @@ i2StuffFifoInline(i2eBordStrPtr pB)
2010 while ( --bailout && notClogged && 2014 while ( --bailout && notClogged &&
2011 (NULL != (pCh = i2DeQueueNeeds(pB,NEED_INLINE))) ) 2015 (NULL != (pCh = i2DeQueueNeeds(pB,NEED_INLINE))) )
2012 { 2016 {
2013 WRITE_LOCK_IRQSAVE(&pCh->Obuf_spinlock,flags); 2017 write_lock_irqsave(&pCh->Obuf_spinlock, flags);
2014 stripIndex = pCh->Obuf_strip; 2018 stripIndex = pCh->Obuf_strip;
2015 2019
2016 ip2trace (CHANN, ITRC_SICMD, 3, 2, stripIndex, pCh->Obuf_stuff ); 2020 ip2trace (CHANN, ITRC_SICMD, 3, 2, stripIndex, pCh->Obuf_stuff );
@@ -2031,7 +2035,7 @@ i2StuffFifoInline(i2eBordStrPtr pB)
2031 packetSize = flowsize + sizeof(i2CmdHeader); 2035 packetSize = flowsize + sizeof(i2CmdHeader);
2032 } 2036 }
2033 flowsize = CREDIT_USAGE(flowsize); 2037 flowsize = CREDIT_USAGE(flowsize);
2034 paddedSize = ROUNDUP(packetSize); 2038 paddedSize = roundup(packetSize, 2);
2035 2039
2036 ip2trace (CHANN, ITRC_SICMD, 4, 2, pB->i2eFifoRemains, paddedSize ); 2040 ip2trace (CHANN, ITRC_SICMD, 4, 2, pB->i2eFifoRemains, paddedSize );
2037 2041
@@ -2086,7 +2090,7 @@ WriteDBGBuf("DATA", pRemove, paddedSize);
2086 // Done with this channel. Move to next, removing this one from the 2090 // Done with this channel. Move to next, removing this one from the
2087 // queue of channels if we cleaned it out (i.e., didn't get clogged. 2091 // queue of channels if we cleaned it out (i.e., didn't get clogged.
2088 pCh->Obuf_strip = stripIndex; 2092 pCh->Obuf_strip = stripIndex;
2089 WRITE_UNLOCK_IRQRESTORE(&pCh->Obuf_spinlock,flags); 2093 write_unlock_irqrestore(&pCh->Obuf_spinlock, flags);
2090 if ( notClogged ) 2094 if ( notClogged )
2091 { 2095 {
2092 2096
@@ -2190,10 +2194,11 @@ i2ServiceBoard ( i2eBordStrPtr pB )
2190 2194
2191 if (inmail & MB_OUT_STRIPPED) { 2195 if (inmail & MB_OUT_STRIPPED) {
2192 pB->i2eFifoOutInts++; 2196 pB->i2eFifoOutInts++;
2193 WRITE_LOCK_IRQSAVE(&pB->write_fifo_spinlock,flags); 2197 write_lock_irqsave(&pB->write_fifo_spinlock, flags);
2194 pB->i2eFifoRemains = pB->i2eFifoSize; 2198 pB->i2eFifoRemains = pB->i2eFifoSize;
2195 pB->i2eWaitingForEmptyFifo = 0; 2199 pB->i2eWaitingForEmptyFifo = 0;
2196 WRITE_UNLOCK_IRQRESTORE(&pB->write_fifo_spinlock,flags); 2200 write_unlock_irqrestore(&pB->write_fifo_spinlock,
2201 flags);
2197 2202
2198 ip2trace (ITRC_NO_PORT, ITRC_INTR, 30, 1, pB->i2eFifoRemains ); 2203 ip2trace (ITRC_NO_PORT, ITRC_INTR, 30, 1, pB->i2eFifoRemains );
2199 2204
diff --git a/drivers/char/ip2/i2os.h b/drivers/char/ip2/i2os.h
deleted file mode 100644
index eff9b542d699..000000000000
--- a/drivers/char/ip2/i2os.h
+++ /dev/null
@@ -1,127 +0,0 @@
1/*******************************************************************************
2*
3* (c) 1999 by Computone Corporation
4*
5********************************************************************************
6*
7*
8* PACKAGE: Linux tty Device Driver for IntelliPort II family of multiport
9* serial I/O controllers.
10*
11* DESCRIPTION: Defines, definitions and includes which are heavily dependent
12* on O/S, host, compiler, etc. This file is tailored for:
13* Linux v2.0.0 and later
14* Gnu gcc c2.7.2
15* 80x86 architecture
16*
17*******************************************************************************/
18
19#ifndef I2OS_H /* To prevent multiple includes */
20#define I2OS_H 1
21
22//-------------------------------------------------
23// Required Includes
24//-------------------------------------------------
25
26#include "ip2types.h"
27#include <asm/io.h> /* For inb, etc */
28
29//------------------------------------
30// Defines for I/O instructions:
31//------------------------------------
32
33#define INB(port) inb(port)
34#define OUTB(port,value) outb((value),(port))
35#define INW(port) inw(port)
36#define OUTW(port,value) outw((value),(port))
37#define OUTSW(port,addr,count) outsw((port),(addr),(((count)+1)/2))
38#define OUTSB(port,addr,count) outsb((port),(addr),(((count)+1))&-2)
39#define INSW(port,addr,count) insw((port),(addr),(((count)+1)/2))
40#define INSB(port,addr,count) insb((port),(addr),(((count)+1))&-2)
41
42//--------------------------------------------
43// Interrupt control
44//--------------------------------------------
45
46#define LOCK_INIT(a) rwlock_init(a)
47
48#define SAVE_AND_DISABLE_INTS(a,b) { \
49 /* printk("get_lock: 0x%x,%4d,%s\n",(int)a,__LINE__,__FILE__);*/ \
50 spin_lock_irqsave(a,b); \
51}
52
53#define RESTORE_INTS(a,b) { \
54 /* printk("rel_lock: 0x%x,%4d,%s\n",(int)a,__LINE__,__FILE__);*/ \
55 spin_unlock_irqrestore(a,b); \
56}
57
58#define READ_LOCK_IRQSAVE(a,b) { \
59 /* printk("get_read_lock: 0x%x,%4d,%s\n",(int)a,__LINE__,__FILE__);*/ \
60 read_lock_irqsave(a,b); \
61}
62
63#define READ_UNLOCK_IRQRESTORE(a,b) { \
64 /* printk("rel_read_lock: 0x%x,%4d,%s\n",(int)a,__LINE__,__FILE__);*/ \
65 read_unlock_irqrestore(a,b); \
66}
67
68#define WRITE_LOCK_IRQSAVE(a,b) { \
69 /* printk("get_write_lock: 0x%x,%4d,%s\n",(int)a,__LINE__,__FILE__);*/ \
70 write_lock_irqsave(a,b); \
71}
72
73#define WRITE_UNLOCK_IRQRESTORE(a,b) { \
74 /* printk("rel_write_lock: 0x%x,%4d,%s\n",(int)a,__LINE__,__FILE__);*/ \
75 write_unlock_irqrestore(a,b); \
76}
77
78
79//------------------------------------------------------------------------------
80// Hardware-delay loop
81//
82// Probably used in only one place (see i2ellis.c) but this helps keep things
83// together. Note we have unwound the IN instructions. On machines with a
84// reasonable cache, the eight instructions (1 byte each) should fit in cache
85// nicely, and on un-cached machines, the code-fetch would tend not to dominate.
86// Note that cx is shifted so that "count" still reflects the total number of
87// iterations assuming no unwinding.
88//------------------------------------------------------------------------------
89
90//#define DELAY1MS(port,count,label)
91
92//------------------------------------------------------------------------------
93// Macros to switch to a new stack, saving stack pointers, and to restore the
94// old stack (Used, for example, in i2lib.c) "heap" is the address of some
95// buffer which will become the new stack (working down from highest address).
96// The two words at the two lowest addresses in this stack are for storing the
97// SS and SP.
98//------------------------------------------------------------------------------
99
100//#define TO_NEW_STACK(heap,size)
101//#define TO_OLD_STACK(heap)
102
103//------------------------------------------------------------------------------
104// Macros to save the original IRQ vectors and masks, and to patch in new ones.
105//------------------------------------------------------------------------------
106
107//#define SAVE_IRQ_MASKS(dest)
108//#define WRITE_IRQ_MASKS(src)
109//#define SAVE_IRQ_VECTOR(value,dest)
110//#define WRITE_IRQ_VECTOR(value,src)
111
112//------------------------------------------------------------------------------
113// Macro to copy data from one far pointer to another.
114//------------------------------------------------------------------------------
115
116#define I2_MOVE_DATA(fpSource,fpDest,count) memmove(fpDest,fpSource,count);
117
118//------------------------------------------------------------------------------
119// Macros to issue eoi's to host interrupt control (IBM AT 8259-style).
120//------------------------------------------------------------------------------
121
122//#define MASTER_EOI
123//#define SLAVE_EOI
124
125#endif /* I2OS_H */
126
127
diff --git a/drivers/char/ip2/ip2main.c b/drivers/char/ip2/ip2main.c
index 0a61856c631f..70957acaa960 100644
--- a/drivers/char/ip2/ip2main.c
+++ b/drivers/char/ip2/ip2main.c
@@ -169,7 +169,7 @@ static int Fip_firmware_size;
169static int ip2_open(PTTY, struct file *); 169static int ip2_open(PTTY, struct file *);
170static void ip2_close(PTTY, struct file *); 170static void ip2_close(PTTY, struct file *);
171static int ip2_write(PTTY, const unsigned char *, int); 171static int ip2_write(PTTY, const unsigned char *, int);
172static void ip2_putchar(PTTY, unsigned char); 172static int ip2_putchar(PTTY, unsigned char);
173static void ip2_flush_chars(PTTY); 173static void ip2_flush_chars(PTTY);
174static int ip2_write_room(PTTY); 174static int ip2_write_room(PTTY);
175static int ip2_chars_in_buf(PTTY); 175static int ip2_chars_in_buf(PTTY);
@@ -355,14 +355,15 @@ have_requested_irq( char irq )
355/* the driver initialisation function and returns what it returns. */ 355/* the driver initialisation function and returns what it returns. */
356/******************************************************************************/ 356/******************************************************************************/
357#ifdef MODULE 357#ifdef MODULE
358int 358static int __init
359init_module(void) 359ip2_init_module(void)
360{ 360{
361#ifdef IP2DEBUG_INIT 361#ifdef IP2DEBUG_INIT
362 printk (KERN_DEBUG "Loading module ...\n" ); 362 printk (KERN_DEBUG "Loading module ...\n" );
363#endif 363#endif
364 return 0; 364 return 0;
365} 365}
366module_init(ip2_init_module);
366#endif /* MODULE */ 367#endif /* MODULE */
367 368
368/******************************************************************************/ 369/******************************************************************************/
@@ -381,8 +382,8 @@ init_module(void)
381/* driver should be returned since it may be unloaded from memory. */ 382/* driver should be returned since it may be unloaded from memory. */
382/******************************************************************************/ 383/******************************************************************************/
383#ifdef MODULE 384#ifdef MODULE
384void 385void __exit
385cleanup_module(void) 386ip2_cleanup_module(void)
386{ 387{
387 int err; 388 int err;
388 int i; 389 int i;
@@ -452,6 +453,7 @@ cleanup_module(void)
452 printk (KERN_DEBUG "IP2 Unloaded\n" ); 453 printk (KERN_DEBUG "IP2 Unloaded\n" );
453#endif 454#endif
454} 455}
456module_exit(ip2_cleanup_module);
455#endif /* MODULE */ 457#endif /* MODULE */
456 458
457static const struct tty_operations ip2_ops = { 459static const struct tty_operations ip2_ops = {
@@ -1050,9 +1052,9 @@ set_irq( int boardnum, int boardIrq )
1050 * Write to FIFO; don't bother to adjust fifo capacity for this, since 1052 * Write to FIFO; don't bother to adjust fifo capacity for this, since
1051 * board will respond almost immediately after SendMail hit. 1053 * board will respond almost immediately after SendMail hit.
1052 */ 1054 */
1053 WRITE_LOCK_IRQSAVE(&pB->write_fifo_spinlock,flags); 1055 write_lock_irqsave(&pB->write_fifo_spinlock, flags);
1054 iiWriteBuf(pB, tempCommand, 4); 1056 iiWriteBuf(pB, tempCommand, 4);
1055 WRITE_UNLOCK_IRQRESTORE(&pB->write_fifo_spinlock,flags); 1057 write_unlock_irqrestore(&pB->write_fifo_spinlock, flags);
1056 pB->i2eUsingIrq = boardIrq; 1058 pB->i2eUsingIrq = boardIrq;
1057 pB->i2eOutMailWaiting |= MB_OUT_STUFFED; 1059 pB->i2eOutMailWaiting |= MB_OUT_STUFFED;
1058 1060
@@ -1070,9 +1072,9 @@ set_irq( int boardnum, int boardIrq )
1070 (CMD_OF(tempCommand))[4] = 64; // chars 1072 (CMD_OF(tempCommand))[4] = 64; // chars
1071 1073
1072 (CMD_OF(tempCommand))[5] = 87; // HW_TEST 1074 (CMD_OF(tempCommand))[5] = 87; // HW_TEST
1073 WRITE_LOCK_IRQSAVE(&pB->write_fifo_spinlock,flags); 1075 write_lock_irqsave(&pB->write_fifo_spinlock, flags);
1074 iiWriteBuf(pB, tempCommand, 8); 1076 iiWriteBuf(pB, tempCommand, 8);
1075 WRITE_UNLOCK_IRQRESTORE(&pB->write_fifo_spinlock,flags); 1077 write_unlock_irqrestore(&pB->write_fifo_spinlock, flags);
1076 1078
1077 CHANNEL_OF(tempCommand) = 0; 1079 CHANNEL_OF(tempCommand) = 0;
1078 PTYPE_OF(tempCommand) = PTYPE_BYPASS; 1080 PTYPE_OF(tempCommand) = PTYPE_BYPASS;
@@ -1087,9 +1089,9 @@ set_irq( int boardnum, int boardIrq )
1087 CMD_COUNT_OF(tempCommand) = 2; 1089 CMD_COUNT_OF(tempCommand) = 2;
1088 (CMD_OF(tempCommand))[0] = 44; /* get ping */ 1090 (CMD_OF(tempCommand))[0] = 44; /* get ping */
1089 (CMD_OF(tempCommand))[1] = 200; /* 200 ms */ 1091 (CMD_OF(tempCommand))[1] = 200; /* 200 ms */
1090 WRITE_LOCK_IRQSAVE(&pB->write_fifo_spinlock,flags); 1092 write_lock_irqsave(&pB->write_fifo_spinlock, flags);
1091 iiWriteBuf(pB, tempCommand, 4); 1093 iiWriteBuf(pB, tempCommand, 4);
1092 WRITE_UNLOCK_IRQRESTORE(&pB->write_fifo_spinlock,flags); 1094 write_unlock_irqrestore(&pB->write_fifo_spinlock, flags);
1093#endif 1095#endif
1094 1096
1095 iiEnableMailIrq(pB); 1097 iiEnableMailIrq(pB);
@@ -1268,12 +1270,12 @@ static void do_input(struct work_struct *work)
1268 1270
1269 // Data input 1271 // Data input
1270 if ( pCh->pTTY != NULL ) { 1272 if ( pCh->pTTY != NULL ) {
1271 READ_LOCK_IRQSAVE(&pCh->Ibuf_spinlock,flags) 1273 read_lock_irqsave(&pCh->Ibuf_spinlock, flags);
1272 if (!pCh->throttled && (pCh->Ibuf_stuff != pCh->Ibuf_strip)) { 1274 if (!pCh->throttled && (pCh->Ibuf_stuff != pCh->Ibuf_strip)) {
1273 READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags) 1275 read_unlock_irqrestore(&pCh->Ibuf_spinlock, flags);
1274 i2Input( pCh ); 1276 i2Input( pCh );
1275 } else 1277 } else
1276 READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags) 1278 read_unlock_irqrestore(&pCh->Ibuf_spinlock, flags);
1277 } else { 1279 } else {
1278 ip2trace(CHANN, ITRC_INPUT, 22, 0 ); 1280 ip2trace(CHANN, ITRC_INPUT, 22, 0 );
1279 1281
@@ -1614,10 +1616,8 @@ ip2_close( PTTY tty, struct file *pFile )
1614 1616
1615 serviceOutgoingFifo ( pCh->pMyBord ); 1617 serviceOutgoingFifo ( pCh->pMyBord );
1616 1618
1617 if ( tty->driver->flush_buffer ) 1619 tty_ldisc_flush(tty);
1618 tty->driver->flush_buffer(tty); 1620 tty_driver_flush_buffer(tty);
1619 if ( tty->ldisc.flush_buffer )
1620 tty->ldisc.flush_buffer(tty);
1621 tty->closing = 0; 1621 tty->closing = 0;
1622 1622
1623 pCh->pTTY = NULL; 1623 pCh->pTTY = NULL;
@@ -1717,9 +1717,9 @@ ip2_write( PTTY tty, const unsigned char *pData, int count)
1717 ip2_flush_chars( tty ); 1717 ip2_flush_chars( tty );
1718 1718
1719 /* This is the actual move bit. Make sure it does what we need!!!!! */ 1719 /* This is the actual move bit. Make sure it does what we need!!!!! */
1720 WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags); 1720 write_lock_irqsave(&pCh->Pbuf_spinlock, flags);
1721 bytesSent = i2Output( pCh, pData, count); 1721 bytesSent = i2Output( pCh, pData, count);
1722 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags); 1722 write_unlock_irqrestore(&pCh->Pbuf_spinlock, flags);
1723 1723
1724 ip2trace (CHANN, ITRC_WRITE, ITRC_RETURN, 1, bytesSent ); 1724 ip2trace (CHANN, ITRC_WRITE, ITRC_RETURN, 1, bytesSent );
1725 1725
@@ -1736,7 +1736,7 @@ ip2_write( PTTY tty, const unsigned char *pData, int count)
1736/* */ 1736/* */
1737/* */ 1737/* */
1738/******************************************************************************/ 1738/******************************************************************************/
1739static void 1739static int
1740ip2_putchar( PTTY tty, unsigned char ch ) 1740ip2_putchar( PTTY tty, unsigned char ch )
1741{ 1741{
1742 i2ChanStrPtr pCh = tty->driver_data; 1742 i2ChanStrPtr pCh = tty->driver_data;
@@ -1744,13 +1744,14 @@ ip2_putchar( PTTY tty, unsigned char ch )
1744 1744
1745// ip2trace (CHANN, ITRC_PUTC, ITRC_ENTER, 1, ch ); 1745// ip2trace (CHANN, ITRC_PUTC, ITRC_ENTER, 1, ch );
1746 1746
1747 WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags); 1747 write_lock_irqsave(&pCh->Pbuf_spinlock, flags);
1748 pCh->Pbuf[pCh->Pbuf_stuff++] = ch; 1748 pCh->Pbuf[pCh->Pbuf_stuff++] = ch;
1749 if ( pCh->Pbuf_stuff == sizeof pCh->Pbuf ) { 1749 if ( pCh->Pbuf_stuff == sizeof pCh->Pbuf ) {
1750 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags); 1750 write_unlock_irqrestore(&pCh->Pbuf_spinlock, flags);
1751 ip2_flush_chars( tty ); 1751 ip2_flush_chars( tty );
1752 } else 1752 } else
1753 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags); 1753 write_unlock_irqrestore(&pCh->Pbuf_spinlock, flags);
1754 return 1;
1754 1755
1755// ip2trace (CHANN, ITRC_PUTC, ITRC_RETURN, 1, ch ); 1756// ip2trace (CHANN, ITRC_PUTC, ITRC_RETURN, 1, ch );
1756} 1757}
@@ -1770,7 +1771,7 @@ ip2_flush_chars( PTTY tty )
1770 i2ChanStrPtr pCh = tty->driver_data; 1771 i2ChanStrPtr pCh = tty->driver_data;
1771 unsigned long flags; 1772 unsigned long flags;
1772 1773
1773 WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags); 1774 write_lock_irqsave(&pCh->Pbuf_spinlock, flags);
1774 if ( pCh->Pbuf_stuff ) { 1775 if ( pCh->Pbuf_stuff ) {
1775 1776
1776// ip2trace (CHANN, ITRC_PUTC, 10, 1, strip ); 1777// ip2trace (CHANN, ITRC_PUTC, 10, 1, strip );
@@ -1784,7 +1785,7 @@ ip2_flush_chars( PTTY tty )
1784 } 1785 }
1785 pCh->Pbuf_stuff -= strip; 1786 pCh->Pbuf_stuff -= strip;
1786 } 1787 }
1787 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags); 1788 write_unlock_irqrestore(&pCh->Pbuf_spinlock, flags);
1788} 1789}
1789 1790
1790/******************************************************************************/ 1791/******************************************************************************/
@@ -1802,9 +1803,9 @@ ip2_write_room ( PTTY tty )
1802 i2ChanStrPtr pCh = tty->driver_data; 1803 i2ChanStrPtr pCh = tty->driver_data;
1803 unsigned long flags; 1804 unsigned long flags;
1804 1805
1805 READ_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags); 1806 read_lock_irqsave(&pCh->Pbuf_spinlock, flags);
1806 bytesFree = i2OutputFree( pCh ) - pCh->Pbuf_stuff; 1807 bytesFree = i2OutputFree( pCh ) - pCh->Pbuf_stuff;
1807 READ_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags); 1808 read_unlock_irqrestore(&pCh->Pbuf_spinlock, flags);
1808 1809
1809 ip2trace (CHANN, ITRC_WRITE, 11, 1, bytesFree ); 1810 ip2trace (CHANN, ITRC_WRITE, 11, 1, bytesFree );
1810 1811
@@ -1834,12 +1835,12 @@ ip2_chars_in_buf ( PTTY tty )
1834 pCh->Obuf_char_count + pCh->Pbuf_stuff, 1835 pCh->Obuf_char_count + pCh->Pbuf_stuff,
1835 pCh->Obuf_char_count, pCh->Pbuf_stuff ); 1836 pCh->Obuf_char_count, pCh->Pbuf_stuff );
1836#endif 1837#endif
1837 READ_LOCK_IRQSAVE(&pCh->Obuf_spinlock,flags); 1838 read_lock_irqsave(&pCh->Obuf_spinlock, flags);
1838 rc = pCh->Obuf_char_count; 1839 rc = pCh->Obuf_char_count;
1839 READ_UNLOCK_IRQRESTORE(&pCh->Obuf_spinlock,flags); 1840 read_unlock_irqrestore(&pCh->Obuf_spinlock, flags);
1840 READ_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags); 1841 read_lock_irqsave(&pCh->Pbuf_spinlock, flags);
1841 rc += pCh->Pbuf_stuff; 1842 rc += pCh->Pbuf_stuff;
1842 READ_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags); 1843 read_unlock_irqrestore(&pCh->Pbuf_spinlock, flags);
1843 return rc; 1844 return rc;
1844} 1845}
1845 1846
@@ -1863,9 +1864,9 @@ ip2_flush_buffer( PTTY tty )
1863#ifdef IP2DEBUG_WRITE 1864#ifdef IP2DEBUG_WRITE
1864 printk (KERN_DEBUG "IP2: flush buffer\n" ); 1865 printk (KERN_DEBUG "IP2: flush buffer\n" );
1865#endif 1866#endif
1866 WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags); 1867 write_lock_irqsave(&pCh->Pbuf_spinlock, flags);
1867 pCh->Pbuf_stuff = 0; 1868 pCh->Pbuf_stuff = 0;
1868 WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags); 1869 write_unlock_irqrestore(&pCh->Pbuf_spinlock, flags);
1869 i2FlushOutput( pCh ); 1870 i2FlushOutput( pCh );
1870 ip2_owake(tty); 1871 ip2_owake(tty);
1871 1872
@@ -1951,15 +1952,15 @@ ip2_unthrottle ( PTTY tty )
1951 pCh->throttled = 0; 1952 pCh->throttled = 0;
1952 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_RESUME); 1953 i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_RESUME);
1953 serviceOutgoingFifo( pCh->pMyBord ); 1954 serviceOutgoingFifo( pCh->pMyBord );
1954 READ_LOCK_IRQSAVE(&pCh->Ibuf_spinlock,flags) 1955 read_lock_irqsave(&pCh->Ibuf_spinlock, flags);
1955 if ( pCh->Ibuf_stuff != pCh->Ibuf_strip ) { 1956 if ( pCh->Ibuf_stuff != pCh->Ibuf_strip ) {
1956 READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags) 1957 read_unlock_irqrestore(&pCh->Ibuf_spinlock, flags);
1957#ifdef IP2DEBUG_READ 1958#ifdef IP2DEBUG_READ
1958 printk (KERN_DEBUG "i2Input called from unthrottle\n" ); 1959 printk (KERN_DEBUG "i2Input called from unthrottle\n" );
1959#endif 1960#endif
1960 i2Input( pCh ); 1961 i2Input( pCh );
1961 } else 1962 } else
1962 READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags) 1963 read_unlock_irqrestore(&pCh->Ibuf_spinlock, flags);
1963} 1964}
1964 1965
1965static void 1966static void
@@ -2202,9 +2203,9 @@ ip2_ioctl ( PTTY tty, struct file *pFile, UINT cmd, ULONG arg )
2202 * for masking). Caller should use TIOCGICOUNT to see which one it was 2203 * for masking). Caller should use TIOCGICOUNT to see which one it was
2203 */ 2204 */
2204 case TIOCMIWAIT: 2205 case TIOCMIWAIT:
2205 WRITE_LOCK_IRQSAVE(&pB->read_fifo_spinlock, flags); 2206 write_lock_irqsave(&pB->read_fifo_spinlock, flags);
2206 cprev = pCh->icount; /* note the counters on entry */ 2207 cprev = pCh->icount; /* note the counters on entry */
2207 WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock, flags); 2208 write_unlock_irqrestore(&pB->read_fifo_spinlock, flags);
2208 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 4, 2209 i2QueueCommands(PTYPE_BYPASS, pCh, 100, 4,
2209 CMD_DCD_REP, CMD_CTS_REP, CMD_DSR_REP, CMD_RI_REP); 2210 CMD_DCD_REP, CMD_CTS_REP, CMD_DSR_REP, CMD_RI_REP);
2210 init_waitqueue_entry(&wait, current); 2211 init_waitqueue_entry(&wait, current);
@@ -2224,9 +2225,9 @@ ip2_ioctl ( PTTY tty, struct file *pFile, UINT cmd, ULONG arg )
2224 rc = -ERESTARTSYS; 2225 rc = -ERESTARTSYS;
2225 break; 2226 break;
2226 } 2227 }
2227 WRITE_LOCK_IRQSAVE(&pB->read_fifo_spinlock, flags); 2228 write_lock_irqsave(&pB->read_fifo_spinlock, flags);
2228 cnow = pCh->icount; /* atomic copy */ 2229 cnow = pCh->icount; /* atomic copy */
2229 WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock, flags); 2230 write_unlock_irqrestore(&pB->read_fifo_spinlock, flags);
2230 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && 2231 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2231 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) { 2232 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
2232 rc = -EIO; /* no change => rc */ 2233 rc = -EIO; /* no change => rc */
@@ -2264,9 +2265,9 @@ ip2_ioctl ( PTTY tty, struct file *pFile, UINT cmd, ULONG arg )
2264 case TIOCGICOUNT: 2265 case TIOCGICOUNT:
2265 ip2trace (CHANN, ITRC_IOCTL, 11, 1, rc ); 2266 ip2trace (CHANN, ITRC_IOCTL, 11, 1, rc );
2266 2267
2267 WRITE_LOCK_IRQSAVE(&pB->read_fifo_spinlock, flags); 2268 write_lock_irqsave(&pB->read_fifo_spinlock, flags);
2268 cnow = pCh->icount; 2269 cnow = pCh->icount;
2269 WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock, flags); 2270 write_unlock_irqrestore(&pB->read_fifo_spinlock, flags);
2270 p_cuser = argp; 2271 p_cuser = argp;
2271 rc = put_user(cnow.cts, &p_cuser->cts); 2272 rc = put_user(cnow.cts, &p_cuser->cts);
2272 rc = put_user(cnow.dsr, &p_cuser->dsr); 2273 rc = put_user(cnow.dsr, &p_cuser->dsr);
@@ -2872,7 +2873,7 @@ ip2_ipl_ioctl ( struct inode *pInode, struct file *pFile, UINT cmd, ULONG arg )
2872 case 65: /* Board - ip2stat */ 2873 case 65: /* Board - ip2stat */
2873 if ( pB ) { 2874 if ( pB ) {
2874 rc = copy_to_user(argp, pB, sizeof(i2eBordStr)); 2875 rc = copy_to_user(argp, pB, sizeof(i2eBordStr));
2875 rc = put_user(INB(pB->i2eStatus), 2876 rc = put_user(inb(pB->i2eStatus),
2876 (ULONG __user *)(arg + (ULONG)(&pB->i2eStatus) - (ULONG)pB ) ); 2877 (ULONG __user *)(arg + (ULONG)(&pB->i2eStatus) - (ULONG)pB ) );
2877 } else { 2878 } else {
2878 rc = -ENODEV; 2879 rc = -ENODEV;
diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c
index eba2883b630e..4f3cefa8eb0e 100644
--- a/drivers/char/isicom.c
+++ b/drivers/char/isicom.c
@@ -126,8 +126,8 @@
126#include <linux/delay.h> 126#include <linux/delay.h>
127#include <linux/ioport.h> 127#include <linux/ioport.h>
128 128
129#include <asm/uaccess.h> 129#include <linux/uaccess.h>
130#include <asm/io.h> 130#include <linux/io.h>
131#include <asm/system.h> 131#include <asm/system.h>
132 132
133#include <linux/pci.h> 133#include <linux/pci.h>
@@ -189,7 +189,7 @@ struct isi_board {
189 unsigned short status; 189 unsigned short status;
190 unsigned short port_status; /* each bit for each port */ 190 unsigned short port_status; /* each bit for each port */
191 unsigned short shift_count; 191 unsigned short shift_count;
192 struct isi_port * ports; 192 struct isi_port *ports;
193 signed char count; 193 signed char count;
194 spinlock_t card_lock; /* Card wide lock 11/5/00 -sameer */ 194 spinlock_t card_lock; /* Card wide lock 11/5/00 -sameer */
195 unsigned long flags; 195 unsigned long flags;
@@ -205,11 +205,11 @@ struct isi_port {
205 u16 channel; 205 u16 channel;
206 u16 status; 206 u16 status;
207 u16 closing_wait; 207 u16 closing_wait;
208 struct isi_board * card; 208 struct isi_board *card;
209 struct tty_struct * tty; 209 struct tty_struct *tty;
210 wait_queue_head_t close_wait; 210 wait_queue_head_t close_wait;
211 wait_queue_head_t open_wait; 211 wait_queue_head_t open_wait;
212 unsigned char * xmit_buf; 212 unsigned char *xmit_buf;
213 int xmit_head; 213 int xmit_head;
214 int xmit_tail; 214 int xmit_tail;
215 int xmit_cnt; 215 int xmit_cnt;
@@ -405,7 +405,7 @@ static void isicom_tx(unsigned long _data)
405 405
406 /* find next active board */ 406 /* find next active board */
407 card = (prev_card + 1) & 0x0003; 407 card = (prev_card + 1) & 0x0003;
408 while(count-- > 0) { 408 while (count-- > 0) {
409 if (isi_card[card].status & BOARD_ACTIVE) 409 if (isi_card[card].status & BOARD_ACTIVE)
410 break; 410 break;
411 card = (card + 1) & 0x0003; 411 card = (card + 1) & 0x0003;
@@ -428,7 +428,7 @@ static void isicom_tx(unsigned long _data)
428 if (retries >= 100) 428 if (retries >= 100)
429 goto unlock; 429 goto unlock;
430 430
431 for (;count > 0;count--, port++) { 431 for (; count > 0; count--, port++) {
432 /* port not active or tx disabled to force flow control */ 432 /* port not active or tx disabled to force flow control */
433 if (!(port->flags & ASYNC_INITIALIZED) || 433 if (!(port->flags & ASYNC_INITIALIZED) ||
434 !(port->status & ISI_TXOK)) 434 !(port->status & ISI_TXOK))
@@ -471,9 +471,10 @@ static void isicom_tx(unsigned long _data)
471 break; 471 break;
472 } 472 }
473 } 473 }
474 if (cnt <= 0) break; 474 if (cnt <= 0)
475 break;
475 word_count = cnt >> 1; 476 word_count = cnt >> 1;
476 outsw(base, port->xmit_buf+port->xmit_tail,word_count); 477 outsw(base, port->xmit_buf+port->xmit_tail, word_count);
477 port->xmit_tail = (port->xmit_tail 478 port->xmit_tail = (port->xmit_tail
478 + (word_count << 1)) & (SERIAL_XMIT_SIZE - 1); 479 + (word_count << 1)) & (SERIAL_XMIT_SIZE - 1);
479 txcount -= (word_count << 1); 480 txcount -= (word_count << 1);
@@ -556,7 +557,7 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id)
556 tty = port->tty; 557 tty = port->tty;
557 if (tty == NULL) { 558 if (tty == NULL) {
558 word_count = byte_count >> 1; 559 word_count = byte_count >> 1;
559 while(byte_count > 1) { 560 while (byte_count > 1) {
560 inw(base); 561 inw(base);
561 byte_count -= 2; 562 byte_count -= 2;
562 } 563 }
@@ -569,7 +570,7 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id)
569 570
570 if (header & 0x8000) { /* Status Packet */ 571 if (header & 0x8000) { /* Status Packet */
571 header = inw(base); 572 header = inw(base);
572 switch(header & 0xff) { 573 switch (header & 0xff) {
573 case 0: /* Change in EIA signals */ 574 case 0: /* Change in EIA signals */
574 if (port->flags & ASYNC_CHECK_CD) { 575 if (port->flags & ASYNC_CHECK_CD) {
575 if (port->status & ISI_DCD) { 576 if (port->status & ISI_DCD) {
@@ -656,7 +657,8 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id)
656 if (byte_count > 0) { 657 if (byte_count > 0) {
657 pr_dbg("Intr(0x%lx:%d): Flip buffer overflow! dropping " 658 pr_dbg("Intr(0x%lx:%d): Flip buffer overflow! dropping "
658 "bytes...\n", base, channel + 1); 659 "bytes...\n", base, channel + 1);
659 while(byte_count > 0) { /* drain out unread xtra data */ 660 /* drain out unread xtra data */
661 while (byte_count > 0) {
660 inw(base); 662 inw(base);
661 byte_count -= 2; 663 byte_count -= 2;
662 } 664 }
@@ -679,8 +681,11 @@ static void isicom_config_port(struct isi_port *port)
679 shift_count = card->shift_count; 681 shift_count = card->shift_count;
680 unsigned char flow_ctrl; 682 unsigned char flow_ctrl;
681 683
682 if (!(tty = port->tty) || !tty->termios) 684 tty = port->tty;
685
686 if (tty == NULL)
683 return; 687 return;
688 /* FIXME: Switch to new tty baud API */
684 baud = C_BAUD(tty); 689 baud = C_BAUD(tty);
685 if (baud & CBAUDEX) { 690 if (baud & CBAUDEX) {
686 baud &= ~CBAUDEX; 691 baud &= ~CBAUDEX;
@@ -706,7 +711,7 @@ static void isicom_config_port(struct isi_port *port)
706 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) 711 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
707 baud++; /* 57.6 Kbps */ 712 baud++; /* 57.6 Kbps */
708 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) 713 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
709 baud +=2; /* 115 Kbps */ 714 baud += 2; /* 115 Kbps */
710 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI) 715 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
711 baud += 3; /* 230 kbps*/ 716 baud += 3; /* 230 kbps*/
712 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP) 717 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
@@ -716,15 +721,14 @@ static void isicom_config_port(struct isi_port *port)
716 /* hang up */ 721 /* hang up */
717 drop_dtr(port); 722 drop_dtr(port);
718 return; 723 return;
719 } 724 } else
720 else
721 raise_dtr(port); 725 raise_dtr(port);
722 726
723 if (WaitTillCardIsFree(base) == 0) { 727 if (WaitTillCardIsFree(base) == 0) {
724 outw(0x8000 | (channel << shift_count) |0x03, base); 728 outw(0x8000 | (channel << shift_count) | 0x03, base);
725 outw(linuxb_to_isib[baud] << 8 | 0x03, base); 729 outw(linuxb_to_isib[baud] << 8 | 0x03, base);
726 channel_setup = 0; 730 channel_setup = 0;
727 switch(C_CSIZE(tty)) { 731 switch (C_CSIZE(tty)) {
728 case CS5: 732 case CS5:
729 channel_setup |= ISICOM_CS5; 733 channel_setup |= ISICOM_CS5;
730 break; 734 break;
@@ -767,7 +771,7 @@ static void isicom_config_port(struct isi_port *port)
767 flow_ctrl |= ISICOM_INITIATE_XONXOFF; 771 flow_ctrl |= ISICOM_INITIATE_XONXOFF;
768 772
769 if (WaitTillCardIsFree(base) == 0) { 773 if (WaitTillCardIsFree(base) == 0) {
770 outw(0x8000 | (channel << shift_count) |0x04, base); 774 outw(0x8000 | (channel << shift_count) | 0x04, base);
771 outw(flow_ctrl << 8 | 0x05, base); 775 outw(flow_ctrl << 8 | 0x05, base);
772 outw((STOP_CHAR(tty)) << 8 | (START_CHAR(tty)), base); 776 outw((STOP_CHAR(tty)) << 8 | (START_CHAR(tty)), base);
773 InterruptTheCard(base); 777 InterruptTheCard(base);
@@ -805,20 +809,17 @@ static int isicom_setup_port(struct isi_port *port)
805 struct isi_board *card = port->card; 809 struct isi_board *card = port->card;
806 unsigned long flags; 810 unsigned long flags;
807 811
808 if (port->flags & ASYNC_INITIALIZED) { 812 if (port->flags & ASYNC_INITIALIZED)
809 return 0; 813 return 0;
810 }
811 if (!port->xmit_buf) { 814 if (!port->xmit_buf) {
812 unsigned long page; 815 /* Relies on BKL */
813 816 unsigned long page = get_zeroed_page(GFP_KERNEL);
814 if (!(page = get_zeroed_page(GFP_KERNEL))) 817 if (page == 0)
815 return -ENOMEM; 818 return -ENOMEM;
816 819 if (port->xmit_buf)
817 if (port->xmit_buf) {
818 free_page(page); 820 free_page(page);
819 return -ERESTARTSYS; 821 else
820 } 822 port->xmit_buf = (unsigned char *) page;
821 port->xmit_buf = (unsigned char *) page;
822 } 823 }
823 824
824 spin_lock_irqsave(&card->card_lock, flags); 825 spin_lock_irqsave(&card->card_lock, flags);
@@ -949,21 +950,18 @@ static int isicom_open(struct tty_struct *tty, struct file *filp)
949 port->count++; 950 port->count++;
950 tty->driver_data = port; 951 tty->driver_data = port;
951 port->tty = tty; 952 port->tty = tty;
952 if ((error = isicom_setup_port(port))!=0) 953 error = isicom_setup_port(port);
953 return error; 954 if (error == 0)
954 if ((error = block_til_ready(tty, filp, port))!=0) 955 error = block_til_ready(tty, filp, port);
955 return error; 956 return error;
956
957 return 0;
958} 957}
959 958
960/* close et all */ 959/* close et all */
961 960
962static inline void isicom_shutdown_board(struct isi_board *bp) 961static inline void isicom_shutdown_board(struct isi_board *bp)
963{ 962{
964 if (bp->status & BOARD_ACTIVE) { 963 if (bp->status & BOARD_ACTIVE)
965 bp->status &= ~BOARD_ACTIVE; 964 bp->status &= ~BOARD_ACTIVE;
966 }
967} 965}
968 966
969/* card->lock HAS to be held */ 967/* card->lock HAS to be held */
@@ -1012,6 +1010,22 @@ static void isicom_shutdown_port(struct isi_port *port)
1012 } 1010 }
1013} 1011}
1014 1012
1013static void isicom_flush_buffer(struct tty_struct *tty)
1014{
1015 struct isi_port *port = tty->driver_data;
1016 struct isi_board *card = port->card;
1017 unsigned long flags;
1018
1019 if (isicom_paranoia_check(port, tty->name, "isicom_flush_buffer"))
1020 return;
1021
1022 spin_lock_irqsave(&card->card_lock, flags);
1023 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1024 spin_unlock_irqrestore(&card->card_lock, flags);
1025
1026 tty_wakeup(tty);
1027}
1028
1015static void isicom_close(struct tty_struct *tty, struct file *filp) 1029static void isicom_close(struct tty_struct *tty, struct file *filp)
1016{ 1030{
1017 struct isi_port *port = tty->driver_data; 1031 struct isi_port *port = tty->driver_data;
@@ -1065,8 +1079,7 @@ static void isicom_close(struct tty_struct *tty, struct file *filp)
1065 isicom_shutdown_port(port); 1079 isicom_shutdown_port(port);
1066 spin_unlock_irqrestore(&card->card_lock, flags); 1080 spin_unlock_irqrestore(&card->card_lock, flags);
1067 1081
1068 if (tty->driver->flush_buffer) 1082 isicom_flush_buffer(tty);
1069 tty->driver->flush_buffer(tty);
1070 tty_ldisc_flush(tty); 1083 tty_ldisc_flush(tty);
1071 1084
1072 spin_lock_irqsave(&card->card_lock, flags); 1085 spin_lock_irqsave(&card->card_lock, flags);
@@ -1104,7 +1117,7 @@ static int isicom_write(struct tty_struct *tty, const unsigned char *buf,
1104 1117
1105 spin_lock_irqsave(&card->card_lock, flags); 1118 spin_lock_irqsave(&card->card_lock, flags);
1106 1119
1107 while(1) { 1120 while (1) {
1108 cnt = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt 1121 cnt = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt
1109 - 1, SERIAL_XMIT_SIZE - port->xmit_head)); 1122 - 1, SERIAL_XMIT_SIZE - port->xmit_head));
1110 if (cnt <= 0) 1123 if (cnt <= 0)
@@ -1125,28 +1138,29 @@ static int isicom_write(struct tty_struct *tty, const unsigned char *buf,
1125} 1138}
1126 1139
1127/* put_char et all */ 1140/* put_char et all */
1128static void isicom_put_char(struct tty_struct *tty, unsigned char ch) 1141static int isicom_put_char(struct tty_struct *tty, unsigned char ch)
1129{ 1142{
1130 struct isi_port *port = tty->driver_data; 1143 struct isi_port *port = tty->driver_data;
1131 struct isi_board *card = port->card; 1144 struct isi_board *card = port->card;
1132 unsigned long flags; 1145 unsigned long flags;
1133 1146
1134 if (isicom_paranoia_check(port, tty->name, "isicom_put_char")) 1147 if (isicom_paranoia_check(port, tty->name, "isicom_put_char"))
1135 return; 1148 return 0;
1136 1149
1137 if (!port->xmit_buf) 1150 if (!port->xmit_buf)
1138 return; 1151 return 0;
1139 1152
1140 spin_lock_irqsave(&card->card_lock, flags); 1153 spin_lock_irqsave(&card->card_lock, flags);
1141 if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) { 1154 if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) {
1142 spin_unlock_irqrestore(&card->card_lock, flags); 1155 spin_unlock_irqrestore(&card->card_lock, flags);
1143 return; 1156 return 0;
1144 } 1157 }
1145 1158
1146 port->xmit_buf[port->xmit_head++] = ch; 1159 port->xmit_buf[port->xmit_head++] = ch;
1147 port->xmit_head &= (SERIAL_XMIT_SIZE - 1); 1160 port->xmit_head &= (SERIAL_XMIT_SIZE - 1);
1148 port->xmit_cnt++; 1161 port->xmit_cnt++;
1149 spin_unlock_irqrestore(&card->card_lock, flags); 1162 spin_unlock_irqrestore(&card->card_lock, flags);
1163 return 1;
1150} 1164}
1151 1165
1152/* flush_chars et all */ 1166/* flush_chars et all */
@@ -1258,6 +1272,8 @@ static int isicom_set_serial_info(struct isi_port *port,
1258 if (copy_from_user(&newinfo, info, sizeof(newinfo))) 1272 if (copy_from_user(&newinfo, info, sizeof(newinfo)))
1259 return -EFAULT; 1273 return -EFAULT;
1260 1274
1275 lock_kernel();
1276
1261 reconfig_port = ((port->flags & ASYNC_SPD_MASK) != 1277 reconfig_port = ((port->flags & ASYNC_SPD_MASK) !=
1262 (newinfo.flags & ASYNC_SPD_MASK)); 1278 (newinfo.flags & ASYNC_SPD_MASK));
1263 1279
@@ -1265,12 +1281,13 @@ static int isicom_set_serial_info(struct isi_port *port,
1265 if ((newinfo.close_delay != port->close_delay) || 1281 if ((newinfo.close_delay != port->close_delay) ||
1266 (newinfo.closing_wait != port->closing_wait) || 1282 (newinfo.closing_wait != port->closing_wait) ||
1267 ((newinfo.flags & ~ASYNC_USR_MASK) != 1283 ((newinfo.flags & ~ASYNC_USR_MASK) !=
1268 (port->flags & ~ASYNC_USR_MASK))) 1284 (port->flags & ~ASYNC_USR_MASK))) {
1285 unlock_kernel();
1269 return -EPERM; 1286 return -EPERM;
1270 port->flags = ((port->flags & ~ ASYNC_USR_MASK) | 1287 }
1288 port->flags = ((port->flags & ~ASYNC_USR_MASK) |
1271 (newinfo.flags & ASYNC_USR_MASK)); 1289 (newinfo.flags & ASYNC_USR_MASK));
1272 } 1290 } else {
1273 else {
1274 port->close_delay = newinfo.close_delay; 1291 port->close_delay = newinfo.close_delay;
1275 port->closing_wait = newinfo.closing_wait; 1292 port->closing_wait = newinfo.closing_wait;
1276 port->flags = ((port->flags & ~ASYNC_FLAGS) | 1293 port->flags = ((port->flags & ~ASYNC_FLAGS) |
@@ -1282,6 +1299,7 @@ static int isicom_set_serial_info(struct isi_port *port,
1282 isicom_config_port(port); 1299 isicom_config_port(port);
1283 spin_unlock_irqrestore(&port->card->card_lock, flags); 1300 spin_unlock_irqrestore(&port->card->card_lock, flags);
1284 } 1301 }
1302 unlock_kernel();
1285 return 0; 1303 return 0;
1286} 1304}
1287 1305
@@ -1290,6 +1308,7 @@ static int isicom_get_serial_info(struct isi_port *port,
1290{ 1308{
1291 struct serial_struct out_info; 1309 struct serial_struct out_info;
1292 1310
1311 lock_kernel();
1293 memset(&out_info, 0, sizeof(out_info)); 1312 memset(&out_info, 0, sizeof(out_info));
1294/* out_info.type = ? */ 1313/* out_info.type = ? */
1295 out_info.line = port - isi_ports; 1314 out_info.line = port - isi_ports;
@@ -1299,6 +1318,7 @@ static int isicom_get_serial_info(struct isi_port *port,
1299/* out_info.baud_base = ? */ 1318/* out_info.baud_base = ? */
1300 out_info.close_delay = port->close_delay; 1319 out_info.close_delay = port->close_delay;
1301 out_info.closing_wait = port->closing_wait; 1320 out_info.closing_wait = port->closing_wait;
1321 unlock_kernel();
1302 if (copy_to_user(info, &out_info, sizeof(out_info))) 1322 if (copy_to_user(info, &out_info, sizeof(out_info)))
1303 return -EFAULT; 1323 return -EFAULT;
1304 return 0; 1324 return 0;
@@ -1314,7 +1334,7 @@ static int isicom_ioctl(struct tty_struct *tty, struct file *filp,
1314 if (isicom_paranoia_check(port, tty->name, "isicom_ioctl")) 1334 if (isicom_paranoia_check(port, tty->name, "isicom_ioctl"))
1315 return -ENODEV; 1335 return -ENODEV;
1316 1336
1317 switch(cmd) { 1337 switch (cmd) {
1318 case TCSBRK: 1338 case TCSBRK:
1319 retval = tty_check_change(tty); 1339 retval = tty_check_change(tty);
1320 if (retval) 1340 if (retval)
@@ -1331,19 +1351,6 @@ static int isicom_ioctl(struct tty_struct *tty, struct file *filp,
1331 tty_wait_until_sent(tty, 0); 1351 tty_wait_until_sent(tty, 0);
1332 isicom_send_break(port, arg ? arg * (HZ/10) : HZ/4); 1352 isicom_send_break(port, arg ? arg * (HZ/10) : HZ/4);
1333 return 0; 1353 return 0;
1334
1335 case TIOCGSOFTCAR:
1336 return put_user(C_CLOCAL(tty) ? 1 : 0,
1337 (unsigned long __user *)argp);
1338
1339 case TIOCSSOFTCAR:
1340 if (get_user(arg, (unsigned long __user *) argp))
1341 return -EFAULT;
1342 tty->termios->c_cflag =
1343 ((tty->termios->c_cflag & ~CLOCAL) |
1344 (arg ? CLOCAL : 0));
1345 return 0;
1346
1347 case TIOCGSERIAL: 1354 case TIOCGSERIAL:
1348 return isicom_get_serial_info(port, argp); 1355 return isicom_get_serial_info(port, argp);
1349 1356
@@ -1453,22 +1460,6 @@ static void isicom_hangup(struct tty_struct *tty)
1453 wake_up_interruptible(&port->open_wait); 1460 wake_up_interruptible(&port->open_wait);
1454} 1461}
1455 1462
1456/* flush_buffer et all */
1457static void isicom_flush_buffer(struct tty_struct *tty)
1458{
1459 struct isi_port *port = tty->driver_data;
1460 struct isi_board *card = port->card;
1461 unsigned long flags;
1462
1463 if (isicom_paranoia_check(port, tty->name, "isicom_flush_buffer"))
1464 return;
1465
1466 spin_lock_irqsave(&card->card_lock, flags);
1467 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1468 spin_unlock_irqrestore(&card->card_lock, flags);
1469
1470 tty_wakeup(tty);
1471}
1472 1463
1473/* 1464/*
1474 * Driver init and deinit functions 1465 * Driver init and deinit functions
@@ -1592,7 +1583,7 @@ static int __devinit load_firmware(struct pci_dev *pdev,
1592 default: 1583 default:
1593 dev_err(&pdev->dev, "Unknown signature.\n"); 1584 dev_err(&pdev->dev, "Unknown signature.\n");
1594 goto end; 1585 goto end;
1595 } 1586 }
1596 1587
1597 retval = request_firmware(&fw, name, &pdev->dev); 1588 retval = request_firmware(&fw, name, &pdev->dev);
1598 if (retval) 1589 if (retval)
@@ -1620,7 +1611,8 @@ static int __devinit load_firmware(struct pci_dev *pdev,
1620 if (WaitTillCardIsFree(base)) 1611 if (WaitTillCardIsFree(base))
1621 goto errrelfw; 1612 goto errrelfw;
1622 1613
1623 if ((status = inw(base + 0x4)) != 0) { 1614 status = inw(base + 0x4);
1615 if (status != 0) {
1624 dev_warn(&pdev->dev, "Card%d rejected load header:\n" 1616 dev_warn(&pdev->dev, "Card%d rejected load header:\n"
1625 KERN_WARNING "Address:0x%x\n" 1617 KERN_WARNING "Address:0x%x\n"
1626 KERN_WARNING "Count:0x%x\n" 1618 KERN_WARNING "Count:0x%x\n"
@@ -1637,12 +1629,13 @@ static int __devinit load_firmware(struct pci_dev *pdev,
1637 if (WaitTillCardIsFree(base)) 1629 if (WaitTillCardIsFree(base))
1638 goto errrelfw; 1630 goto errrelfw;
1639 1631
1640 if ((status = inw(base + 0x4)) != 0) { 1632 status = inw(base + 0x4);
1633 if (status != 0) {
1641 dev_err(&pdev->dev, "Card%d got out of sync.Card " 1634 dev_err(&pdev->dev, "Card%d got out of sync.Card "
1642 "Status:0x%x\n", index + 1, status); 1635 "Status:0x%x\n", index + 1, status);
1643 goto errrelfw; 1636 goto errrelfw;
1644 } 1637 }
1645 } 1638 }
1646 1639
1647/* XXX: should we test it by reading it back and comparing with original like 1640/* XXX: should we test it by reading it back and comparing with original like
1648 * in load firmware package? */ 1641 * in load firmware package? */
@@ -1666,7 +1659,8 @@ static int __devinit load_firmware(struct pci_dev *pdev,
1666 if (WaitTillCardIsFree(base)) 1659 if (WaitTillCardIsFree(base))
1667 goto errrelfw; 1660 goto errrelfw;
1668 1661
1669 if ((status = inw(base + 0x4)) != 0) { 1662 status = inw(base + 0x4);
1663 if (status != 0) {
1670 dev_warn(&pdev->dev, "Card%d rejected verify header:\n" 1664 dev_warn(&pdev->dev, "Card%d rejected verify header:\n"
1671 KERN_WARNING "Address:0x%x\n" 1665 KERN_WARNING "Address:0x%x\n"
1672 KERN_WARNING "Count:0x%x\n" 1666 KERN_WARNING "Count:0x%x\n"
@@ -1699,7 +1693,8 @@ static int __devinit load_firmware(struct pci_dev *pdev,
1699 if (WaitTillCardIsFree(base)) 1693 if (WaitTillCardIsFree(base))
1700 goto errrelfw; 1694 goto errrelfw;
1701 1695
1702 if ((status = inw(base + 0x4)) != 0) { 1696 status = inw(base + 0x4);
1697 if (status != 0) {
1703 dev_err(&pdev->dev, "Card%d verify got out of sync. " 1698 dev_err(&pdev->dev, "Card%d verify got out of sync. "
1704 "Card Status:0x%x\n", index + 1, status); 1699 "Card Status:0x%x\n", index + 1, status);
1705 goto errrelfw; 1700 goto errrelfw;
@@ -1764,7 +1759,7 @@ static int __devinit isicom_probe(struct pci_dev *pdev,
1764 index + 1); 1759 index + 1);
1765 retval = -EBUSY; 1760 retval = -EBUSY;
1766 goto errdec; 1761 goto errdec;
1767 } 1762 }
1768 1763
1769 retval = request_irq(board->irq, isicom_interrupt, 1764 retval = request_irq(board->irq, isicom_interrupt,
1770 IRQF_SHARED | IRQF_DISABLED, ISICOM_NAME, board); 1765 IRQF_SHARED | IRQF_DISABLED, ISICOM_NAME, board);
@@ -1818,7 +1813,7 @@ static int __init isicom_init(void)
1818 int retval, idx, channel; 1813 int retval, idx, channel;
1819 struct isi_port *port; 1814 struct isi_port *port;
1820 1815
1821 for(idx = 0; idx < BOARD_COUNT; idx++) { 1816 for (idx = 0; idx < BOARD_COUNT; idx++) {
1822 port = &isi_ports[idx * 16]; 1817 port = &isi_ports[idx * 16];
1823 isi_card[idx].ports = port; 1818 isi_card[idx].ports = port;
1824 spin_lock_init(&isi_card[idx].card_lock); 1819 spin_lock_init(&isi_card[idx].card_lock);
@@ -1832,7 +1827,7 @@ static int __init isicom_init(void)
1832 init_waitqueue_head(&port->open_wait); 1827 init_waitqueue_head(&port->open_wait);
1833 init_waitqueue_head(&port->close_wait); 1828 init_waitqueue_head(&port->close_wait);
1834 /* . . . */ 1829 /* . . . */
1835 } 1830 }
1836 isi_card[idx].base = 0; 1831 isi_card[idx].base = 0;
1837 isi_card[idx].irq = 0; 1832 isi_card[idx].irq = 0;
1838 } 1833 }
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index c645455c3fd1..7c8b62f162bf 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -1682,16 +1682,6 @@ static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cm
1682 rc = 0; 1682 rc = 0;
1683 1683
1684 switch (cmd) { 1684 switch (cmd) {
1685 case TIOCGSOFTCAR:
1686 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1687 (unsigned __user *) arg);
1688 break;
1689 case TIOCSSOFTCAR:
1690 if ((rc = get_user(ival, (unsigned __user *) arg)) == 0)
1691 tty->termios->c_cflag =
1692 (tty->termios->c_cflag & ~CLOCAL) |
1693 (ival ? CLOCAL : 0);
1694 break;
1695 case TIOCGSERIAL: 1685 case TIOCGSERIAL:
1696 rc = stli_getserial(portp, argp); 1686 rc = stli_getserial(portp, argp);
1697 break; 1687 break;
@@ -3267,7 +3257,7 @@ static int stli_initecp(struct stlibrd *brdp)
3267 */ 3257 */
3268 EBRDINIT(brdp); 3258 EBRDINIT(brdp);
3269 3259
3270 brdp->membase = ioremap(brdp->memaddr, brdp->memsize); 3260 brdp->membase = ioremap_nocache(brdp->memaddr, brdp->memsize);
3271 if (brdp->membase == NULL) { 3261 if (brdp->membase == NULL) {
3272 retval = -ENOMEM; 3262 retval = -ENOMEM;
3273 goto err_reg; 3263 goto err_reg;
@@ -3424,7 +3414,7 @@ static int stli_initonb(struct stlibrd *brdp)
3424 */ 3414 */
3425 EBRDINIT(brdp); 3415 EBRDINIT(brdp);
3426 3416
3427 brdp->membase = ioremap(brdp->memaddr, brdp->memsize); 3417 brdp->membase = ioremap_nocache(brdp->memaddr, brdp->memsize);
3428 if (brdp->membase == NULL) { 3418 if (brdp->membase == NULL) {
3429 retval = -ENOMEM; 3419 retval = -ENOMEM;
3430 goto err_reg; 3420 goto err_reg;
@@ -3675,7 +3665,7 @@ static int stli_eisamemprobe(struct stlibrd *brdp)
3675 */ 3665 */
3676 for (i = 0; (i < stli_eisamempsize); i++) { 3666 for (i = 0; (i < stli_eisamempsize); i++) {
3677 brdp->memaddr = stli_eisamemprobeaddrs[i]; 3667 brdp->memaddr = stli_eisamemprobeaddrs[i];
3678 brdp->membase = ioremap(brdp->memaddr, brdp->memsize); 3668 brdp->membase = ioremap_nocache(brdp->memaddr, brdp->memsize);
3679 if (brdp->membase == NULL) 3669 if (brdp->membase == NULL)
3680 continue; 3670 continue;
3681 3671
@@ -4433,6 +4423,8 @@ static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, un
4433 done = 0; 4423 done = 0;
4434 rc = 0; 4424 rc = 0;
4435 4425
4426 lock_kernel();
4427
4436 switch (cmd) { 4428 switch (cmd) {
4437 case COM_GETPORTSTATS: 4429 case COM_GETPORTSTATS:
4438 rc = stli_getportstats(NULL, argp); 4430 rc = stli_getportstats(NULL, argp);
@@ -4455,6 +4447,7 @@ static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, un
4455 done++; 4447 done++;
4456 break; 4448 break;
4457 } 4449 }
4450 unlock_kernel();
4458 4451
4459 if (done) 4452 if (done)
4460 return rc; 4453 return rc;
@@ -4472,6 +4465,8 @@ static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, un
4472 if (brdp->state == 0) 4465 if (brdp->state == 0)
4473 return -ENODEV; 4466 return -ENODEV;
4474 4467
4468 lock_kernel();
4469
4475 switch (cmd) { 4470 switch (cmd) {
4476 case STL_BINTR: 4471 case STL_BINTR:
4477 EBRDINTR(brdp); 4472 EBRDINTR(brdp);
@@ -4494,6 +4489,7 @@ static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, un
4494 rc = -ENOIOCTLCMD; 4489 rc = -ENOIOCTLCMD;
4495 break; 4490 break;
4496 } 4491 }
4492 unlock_kernel();
4497 return rc; 4493 return rc;
4498} 4494}
4499 4495
diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
index 60b934adea65..7f7e798c1384 100644
--- a/drivers/char/keyboard.c
+++ b/drivers/char/keyboard.c
@@ -110,6 +110,7 @@ const int max_vals[] = {
110const int NR_TYPES = ARRAY_SIZE(max_vals); 110const int NR_TYPES = ARRAY_SIZE(max_vals);
111 111
112struct kbd_struct kbd_table[MAX_NR_CONSOLES]; 112struct kbd_struct kbd_table[MAX_NR_CONSOLES];
113EXPORT_SYMBOL_GPL(kbd_table);
113static struct kbd_struct *kbd = kbd_table; 114static struct kbd_struct *kbd = kbd_table;
114 115
115struct vt_spawn_console vt_spawn_con = { 116struct vt_spawn_console vt_spawn_con = {
@@ -260,6 +261,7 @@ void kd_mksound(unsigned int hz, unsigned int ticks)
260 } else 261 } else
261 kd_nosound(0); 262 kd_nosound(0);
262} 263}
264EXPORT_SYMBOL(kd_mksound);
263 265
264/* 266/*
265 * Setting the keyboard rate. 267 * Setting the keyboard rate.
@@ -1230,7 +1232,7 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw)
1230 1232
1231 if (rep && 1233 if (rep &&
1232 (!vc_kbd_mode(kbd, VC_REPEAT) || 1234 (!vc_kbd_mode(kbd, VC_REPEAT) ||
1233 (tty && !L_ECHO(tty) && tty->driver->chars_in_buffer(tty)))) { 1235 (tty && !L_ECHO(tty) && tty_chars_in_buffer(tty)))) {
1234 /* 1236 /*
1235 * Don't repeat a key if the input buffers are not empty and the 1237 * Don't repeat a key if the input buffers are not empty and the
1236 * characters get aren't echoed locally. This makes key repeat 1238 * characters get aren't echoed locally. This makes key repeat
diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index e60a74c66e3d..192961fd7173 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -30,6 +30,8 @@
30#include <linux/miscdevice.h> 30#include <linux/miscdevice.h>
31#include <linux/posix-timers.h> 31#include <linux/posix-timers.h>
32#include <linux/interrupt.h> 32#include <linux/interrupt.h>
33#include <linux/time.h>
34#include <linux/math64.h>
33 35
34#include <asm/uaccess.h> 36#include <asm/uaccess.h>
35#include <asm/sn/addrs.h> 37#include <asm/sn/addrs.h>
@@ -74,9 +76,8 @@ static const struct file_operations mmtimer_fops = {
74 * We only have comparison registers RTC1-4 currently available per 76 * We only have comparison registers RTC1-4 currently available per
75 * node. RTC0 is used by SAL. 77 * node. RTC0 is used by SAL.
76 */ 78 */
77#define NUM_COMPARATORS 3
78/* Check for an RTC interrupt pending */ 79/* Check for an RTC interrupt pending */
79static int inline mmtimer_int_pending(int comparator) 80static int mmtimer_int_pending(int comparator)
80{ 81{
81 if (HUB_L((unsigned long *)LOCAL_MMR_ADDR(SH_EVENT_OCCURRED)) & 82 if (HUB_L((unsigned long *)LOCAL_MMR_ADDR(SH_EVENT_OCCURRED)) &
82 SH_EVENT_OCCURRED_RTC1_INT_MASK << comparator) 83 SH_EVENT_OCCURRED_RTC1_INT_MASK << comparator)
@@ -84,15 +85,16 @@ static int inline mmtimer_int_pending(int comparator)
84 else 85 else
85 return 0; 86 return 0;
86} 87}
88
87/* Clear the RTC interrupt pending bit */ 89/* Clear the RTC interrupt pending bit */
88static void inline mmtimer_clr_int_pending(int comparator) 90static void mmtimer_clr_int_pending(int comparator)
89{ 91{
90 HUB_S((u64 *)LOCAL_MMR_ADDR(SH_EVENT_OCCURRED_ALIAS), 92 HUB_S((u64 *)LOCAL_MMR_ADDR(SH_EVENT_OCCURRED_ALIAS),
91 SH_EVENT_OCCURRED_RTC1_INT_MASK << comparator); 93 SH_EVENT_OCCURRED_RTC1_INT_MASK << comparator);
92} 94}
93 95
94/* Setup timer on comparator RTC1 */ 96/* Setup timer on comparator RTC1 */
95static void inline mmtimer_setup_int_0(u64 expires) 97static void mmtimer_setup_int_0(int cpu, u64 expires)
96{ 98{
97 u64 val; 99 u64 val;
98 100
@@ -106,7 +108,7 @@ static void inline mmtimer_setup_int_0(u64 expires)
106 mmtimer_clr_int_pending(0); 108 mmtimer_clr_int_pending(0);
107 109
108 val = ((u64)SGI_MMTIMER_VECTOR << SH_RTC1_INT_CONFIG_IDX_SHFT) | 110 val = ((u64)SGI_MMTIMER_VECTOR << SH_RTC1_INT_CONFIG_IDX_SHFT) |
109 ((u64)cpu_physical_id(smp_processor_id()) << 111 ((u64)cpu_physical_id(cpu) <<
110 SH_RTC1_INT_CONFIG_PID_SHFT); 112 SH_RTC1_INT_CONFIG_PID_SHFT);
111 113
112 /* Set configuration */ 114 /* Set configuration */
@@ -122,7 +124,7 @@ static void inline mmtimer_setup_int_0(u64 expires)
122} 124}
123 125
124/* Setup timer on comparator RTC2 */ 126/* Setup timer on comparator RTC2 */
125static void inline mmtimer_setup_int_1(u64 expires) 127static void mmtimer_setup_int_1(int cpu, u64 expires)
126{ 128{
127 u64 val; 129 u64 val;
128 130
@@ -133,7 +135,7 @@ static void inline mmtimer_setup_int_1(u64 expires)
133 mmtimer_clr_int_pending(1); 135 mmtimer_clr_int_pending(1);
134 136
135 val = ((u64)SGI_MMTIMER_VECTOR << SH_RTC2_INT_CONFIG_IDX_SHFT) | 137 val = ((u64)SGI_MMTIMER_VECTOR << SH_RTC2_INT_CONFIG_IDX_SHFT) |
136 ((u64)cpu_physical_id(smp_processor_id()) << 138 ((u64)cpu_physical_id(cpu) <<
137 SH_RTC2_INT_CONFIG_PID_SHFT); 139 SH_RTC2_INT_CONFIG_PID_SHFT);
138 140
139 HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC2_INT_CONFIG), val); 141 HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC2_INT_CONFIG), val);
@@ -144,7 +146,7 @@ static void inline mmtimer_setup_int_1(u64 expires)
144} 146}
145 147
146/* Setup timer on comparator RTC3 */ 148/* Setup timer on comparator RTC3 */
147static void inline mmtimer_setup_int_2(u64 expires) 149static void mmtimer_setup_int_2(int cpu, u64 expires)
148{ 150{
149 u64 val; 151 u64 val;
150 152
@@ -155,7 +157,7 @@ static void inline mmtimer_setup_int_2(u64 expires)
155 mmtimer_clr_int_pending(2); 157 mmtimer_clr_int_pending(2);
156 158
157 val = ((u64)SGI_MMTIMER_VECTOR << SH_RTC3_INT_CONFIG_IDX_SHFT) | 159 val = ((u64)SGI_MMTIMER_VECTOR << SH_RTC3_INT_CONFIG_IDX_SHFT) |
158 ((u64)cpu_physical_id(smp_processor_id()) << 160 ((u64)cpu_physical_id(cpu) <<
159 SH_RTC3_INT_CONFIG_PID_SHFT); 161 SH_RTC3_INT_CONFIG_PID_SHFT);
160 162
161 HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC3_INT_CONFIG), val); 163 HUB_S((u64 *)LOCAL_MMR_ADDR(SH_RTC3_INT_CONFIG), val);
@@ -170,22 +172,22 @@ static void inline mmtimer_setup_int_2(u64 expires)
170 * in order to insure that the setup succeeds in a deterministic time frame. 172 * in order to insure that the setup succeeds in a deterministic time frame.
171 * It will check if the interrupt setup succeeded. 173 * It will check if the interrupt setup succeeded.
172 */ 174 */
173static int inline mmtimer_setup(int comparator, unsigned long expires) 175static int mmtimer_setup(int cpu, int comparator, unsigned long expires)
174{ 176{
175 177
176 switch (comparator) { 178 switch (comparator) {
177 case 0: 179 case 0:
178 mmtimer_setup_int_0(expires); 180 mmtimer_setup_int_0(cpu, expires);
179 break; 181 break;
180 case 1: 182 case 1:
181 mmtimer_setup_int_1(expires); 183 mmtimer_setup_int_1(cpu, expires);
182 break; 184 break;
183 case 2: 185 case 2:
184 mmtimer_setup_int_2(expires); 186 mmtimer_setup_int_2(cpu, expires);
185 break; 187 break;
186 } 188 }
187 /* We might've missed our expiration time */ 189 /* We might've missed our expiration time */
188 if (rtc_time() < expires) 190 if (rtc_time() <= expires)
189 return 1; 191 return 1;
190 192
191 /* 193 /*
@@ -195,7 +197,7 @@ static int inline mmtimer_setup(int comparator, unsigned long expires)
195 return mmtimer_int_pending(comparator); 197 return mmtimer_int_pending(comparator);
196} 198}
197 199
198static int inline mmtimer_disable_int(long nasid, int comparator) 200static int mmtimer_disable_int(long nasid, int comparator)
199{ 201{
200 switch (comparator) { 202 switch (comparator) {
201 case 0: 203 case 0:
@@ -216,18 +218,124 @@ static int inline mmtimer_disable_int(long nasid, int comparator)
216 return 0; 218 return 0;
217} 219}
218 220
219#define TIMER_OFF 0xbadcabLL 221#define COMPARATOR 1 /* The comparator to use */
220 222
221/* There is one of these for each comparator */ 223#define TIMER_OFF 0xbadcabLL /* Timer is not setup */
222typedef struct mmtimer { 224#define TIMER_SET 0 /* Comparator is set for this timer */
223 spinlock_t lock ____cacheline_aligned; 225
226/* There is one of these for each timer */
227struct mmtimer {
228 struct rb_node list;
224 struct k_itimer *timer; 229 struct k_itimer *timer;
225 int i;
226 int cpu; 230 int cpu;
231};
232
233struct mmtimer_node {
234 spinlock_t lock ____cacheline_aligned;
235 struct rb_root timer_head;
236 struct rb_node *next;
227 struct tasklet_struct tasklet; 237 struct tasklet_struct tasklet;
228} mmtimer_t; 238};
239static struct mmtimer_node *timers;
240
241
242/*
243 * Add a new mmtimer struct to the node's mmtimer list.
244 * This function assumes the struct mmtimer_node is locked.
245 */
246static void mmtimer_add_list(struct mmtimer *n)
247{
248 int nodeid = n->timer->it.mmtimer.node;
249 unsigned long expires = n->timer->it.mmtimer.expires;
250 struct rb_node **link = &timers[nodeid].timer_head.rb_node;
251 struct rb_node *parent = NULL;
252 struct mmtimer *x;
253
254 /*
255 * Find the right place in the rbtree:
256 */
257 while (*link) {
258 parent = *link;
259 x = rb_entry(parent, struct mmtimer, list);
260
261 if (expires < x->timer->it.mmtimer.expires)
262 link = &(*link)->rb_left;
263 else
264 link = &(*link)->rb_right;
265 }
266
267 /*
268 * Insert the timer to the rbtree and check whether it
269 * replaces the first pending timer
270 */
271 rb_link_node(&n->list, parent, link);
272 rb_insert_color(&n->list, &timers[nodeid].timer_head);
273
274 if (!timers[nodeid].next || expires < rb_entry(timers[nodeid].next,
275 struct mmtimer, list)->timer->it.mmtimer.expires)
276 timers[nodeid].next = &n->list;
277}
278
279/*
280 * Set the comparator for the next timer.
281 * This function assumes the struct mmtimer_node is locked.
282 */
283static void mmtimer_set_next_timer(int nodeid)
284{
285 struct mmtimer_node *n = &timers[nodeid];
286 struct mmtimer *x;
287 struct k_itimer *t;
288 int o;
289
290restart:
291 if (n->next == NULL)
292 return;
229 293
230static mmtimer_t ** timers; 294 x = rb_entry(n->next, struct mmtimer, list);
295 t = x->timer;
296 if (!t->it.mmtimer.incr) {
297 /* Not an interval timer */
298 if (!mmtimer_setup(x->cpu, COMPARATOR,
299 t->it.mmtimer.expires)) {
300 /* Late setup, fire now */
301 tasklet_schedule(&n->tasklet);
302 }
303 return;
304 }
305
306 /* Interval timer */
307 o = 0;
308 while (!mmtimer_setup(x->cpu, COMPARATOR, t->it.mmtimer.expires)) {
309 unsigned long e, e1;
310 struct rb_node *next;
311 t->it.mmtimer.expires += t->it.mmtimer.incr << o;
312 t->it_overrun += 1 << o;
313 o++;
314 if (o > 20) {
315 printk(KERN_ALERT "mmtimer: cannot reschedule timer\n");
316 t->it.mmtimer.clock = TIMER_OFF;
317 n->next = rb_next(&x->list);
318 rb_erase(&x->list, &n->timer_head);
319 kfree(x);
320 goto restart;
321 }
322
323 e = t->it.mmtimer.expires;
324 next = rb_next(&x->list);
325
326 if (next == NULL)
327 continue;
328
329 e1 = rb_entry(next, struct mmtimer, list)->
330 timer->it.mmtimer.expires;
331 if (e > e1) {
332 n->next = next;
333 rb_erase(&x->list, &n->timer_head);
334 mmtimer_add_list(x);
335 goto restart;
336 }
337 }
338}
231 339
232/** 340/**
233 * mmtimer_ioctl - ioctl interface for /dev/mmtimer 341 * mmtimer_ioctl - ioctl interface for /dev/mmtimer
@@ -366,8 +474,8 @@ static int sgi_clock_get(clockid_t clockid, struct timespec *tp)
366 474
367 nsec = rtc_time() * sgi_clock_period 475 nsec = rtc_time() * sgi_clock_period
368 + sgi_clock_offset.tv_nsec; 476 + sgi_clock_offset.tv_nsec;
369 tp->tv_sec = div_long_long_rem(nsec, NSEC_PER_SEC, &tp->tv_nsec) 477 *tp = ns_to_timespec(nsec);
370 + sgi_clock_offset.tv_sec; 478 tp->tv_sec += sgi_clock_offset.tv_sec;
371 return 0; 479 return 0;
372}; 480};
373 481
@@ -375,11 +483,11 @@ static int sgi_clock_set(clockid_t clockid, struct timespec *tp)
375{ 483{
376 484
377 u64 nsec; 485 u64 nsec;
378 u64 rem; 486 u32 rem;
379 487
380 nsec = rtc_time() * sgi_clock_period; 488 nsec = rtc_time() * sgi_clock_period;
381 489
382 sgi_clock_offset.tv_sec = tp->tv_sec - div_long_long_rem(nsec, NSEC_PER_SEC, &rem); 490 sgi_clock_offset.tv_sec = tp->tv_sec - div_u64_rem(nsec, NSEC_PER_SEC, &rem);
383 491
384 if (rem <= tp->tv_nsec) 492 if (rem <= tp->tv_nsec)
385 sgi_clock_offset.tv_nsec = tp->tv_sec - rem; 493 sgi_clock_offset.tv_nsec = tp->tv_sec - rem;
@@ -390,35 +498,6 @@ static int sgi_clock_set(clockid_t clockid, struct timespec *tp)
390 return 0; 498 return 0;
391} 499}
392 500
393/*
394 * Schedule the next periodic interrupt. This function will attempt
395 * to schedule a periodic interrupt later if necessary. If the scheduling
396 * of an interrupt fails then the time to skip is lengthened
397 * exponentially in order to ensure that the next interrupt
398 * can be properly scheduled..
399 */
400static int inline reschedule_periodic_timer(mmtimer_t *x)
401{
402 int n;
403 struct k_itimer *t = x->timer;
404
405 t->it.mmtimer.clock = x->i;
406 t->it_overrun--;
407
408 n = 0;
409 do {
410
411 t->it.mmtimer.expires += t->it.mmtimer.incr << n;
412 t->it_overrun += 1 << n;
413 n++;
414 if (n > 20)
415 return 1;
416
417 } while (!mmtimer_setup(x->i, t->it.mmtimer.expires));
418
419 return 0;
420}
421
422/** 501/**
423 * mmtimer_interrupt - timer interrupt handler 502 * mmtimer_interrupt - timer interrupt handler
424 * @irq: irq received 503 * @irq: irq received
@@ -435,71 +514,75 @@ static int inline reschedule_periodic_timer(mmtimer_t *x)
435static irqreturn_t 514static irqreturn_t
436mmtimer_interrupt(int irq, void *dev_id) 515mmtimer_interrupt(int irq, void *dev_id)
437{ 516{
438 int i;
439 unsigned long expires = 0; 517 unsigned long expires = 0;
440 int result = IRQ_NONE; 518 int result = IRQ_NONE;
441 unsigned indx = cpu_to_node(smp_processor_id()); 519 unsigned indx = cpu_to_node(smp_processor_id());
520 struct mmtimer *base;
442 521
443 /* 522 spin_lock(&timers[indx].lock);
444 * Do this once for each comparison register 523 base = rb_entry(timers[indx].next, struct mmtimer, list);
445 */ 524 if (base == NULL) {
446 for (i = 0; i < NUM_COMPARATORS; i++) { 525 spin_unlock(&timers[indx].lock);
447 mmtimer_t *base = timers[indx] + i; 526 return result;
448 /* Make sure this doesn't get reused before tasklet_sched */ 527 }
449 spin_lock(&base->lock); 528
450 if (base->cpu == smp_processor_id()) { 529 if (base->cpu == smp_processor_id()) {
451 if (base->timer) 530 if (base->timer)
452 expires = base->timer->it.mmtimer.expires; 531 expires = base->timer->it.mmtimer.expires;
453 /* expires test won't work with shared irqs */ 532 /* expires test won't work with shared irqs */
454 if ((mmtimer_int_pending(i) > 0) || 533 if ((mmtimer_int_pending(COMPARATOR) > 0) ||
455 (expires && (expires < rtc_time()))) { 534 (expires && (expires <= rtc_time()))) {
456 mmtimer_clr_int_pending(i); 535 mmtimer_clr_int_pending(COMPARATOR);
457 tasklet_schedule(&base->tasklet); 536 tasklet_schedule(&timers[indx].tasklet);
458 result = IRQ_HANDLED; 537 result = IRQ_HANDLED;
459 }
460 } 538 }
461 spin_unlock(&base->lock);
462 expires = 0;
463 } 539 }
540 spin_unlock(&timers[indx].lock);
464 return result; 541 return result;
465} 542}
466 543
467void mmtimer_tasklet(unsigned long data) { 544static void mmtimer_tasklet(unsigned long data)
468 mmtimer_t *x = (mmtimer_t *)data; 545{
469 struct k_itimer *t = x->timer; 546 int nodeid = data;
547 struct mmtimer_node *mn = &timers[nodeid];
548 struct mmtimer *x = rb_entry(mn->next, struct mmtimer, list);
549 struct k_itimer *t;
470 unsigned long flags; 550 unsigned long flags;
471 551
472 if (t == NULL)
473 return;
474
475 /* Send signal and deal with periodic signals */ 552 /* Send signal and deal with periodic signals */
476 spin_lock_irqsave(&t->it_lock, flags); 553 spin_lock_irqsave(&mn->lock, flags);
477 spin_lock(&x->lock); 554 if (!mn->next)
478 /* If timer was deleted between interrupt and here, leave */
479 if (t != x->timer)
480 goto out; 555 goto out;
481 t->it_overrun = 0;
482 556
483 if (posix_timer_event(t, 0) != 0) { 557 x = rb_entry(mn->next, struct mmtimer, list);
558 t = x->timer;
559
560 if (t->it.mmtimer.clock == TIMER_OFF)
561 goto out;
562
563 t->it_overrun = 0;
484 564
485 // printk(KERN_WARNING "mmtimer: cannot deliver signal.\n"); 565 mn->next = rb_next(&x->list);
566 rb_erase(&x->list, &mn->timer_head);
486 567
568 if (posix_timer_event(t, 0) != 0)
487 t->it_overrun++; 569 t->it_overrun++;
488 } 570
489 if(t->it.mmtimer.incr) { 571 if(t->it.mmtimer.incr) {
490 /* Periodic timer */ 572 t->it.mmtimer.expires += t->it.mmtimer.incr;
491 if (reschedule_periodic_timer(x)) { 573 mmtimer_add_list(x);
492 printk(KERN_WARNING "mmtimer: unable to reschedule\n");
493 x->timer = NULL;
494 }
495 } else { 574 } else {
496 /* Ensure we don't false trigger in mmtimer_interrupt */ 575 /* Ensure we don't false trigger in mmtimer_interrupt */
576 t->it.mmtimer.clock = TIMER_OFF;
497 t->it.mmtimer.expires = 0; 577 t->it.mmtimer.expires = 0;
578 kfree(x);
498 } 579 }
580 /* Set comparator for next timer, if there is one */
581 mmtimer_set_next_timer(nodeid);
582
499 t->it_overrun_last = t->it_overrun; 583 t->it_overrun_last = t->it_overrun;
500out: 584out:
501 spin_unlock(&x->lock); 585 spin_unlock_irqrestore(&mn->lock, flags);
502 spin_unlock_irqrestore(&t->it_lock, flags);
503} 586}
504 587
505static int sgi_timer_create(struct k_itimer *timer) 588static int sgi_timer_create(struct k_itimer *timer)
@@ -516,25 +599,53 @@ static int sgi_timer_create(struct k_itimer *timer)
516 */ 599 */
517static int sgi_timer_del(struct k_itimer *timr) 600static int sgi_timer_del(struct k_itimer *timr)
518{ 601{
519 int i = timr->it.mmtimer.clock;
520 cnodeid_t nodeid = timr->it.mmtimer.node; 602 cnodeid_t nodeid = timr->it.mmtimer.node;
521 mmtimer_t *t = timers[nodeid] + i;
522 unsigned long irqflags; 603 unsigned long irqflags;
523 604
524 if (i != TIMER_OFF) { 605 spin_lock_irqsave(&timers[nodeid].lock, irqflags);
525 spin_lock_irqsave(&t->lock, irqflags); 606 if (timr->it.mmtimer.clock != TIMER_OFF) {
526 mmtimer_disable_int(cnodeid_to_nasid(nodeid),i); 607 unsigned long expires = timr->it.mmtimer.expires;
527 t->timer = NULL; 608 struct rb_node *n = timers[nodeid].timer_head.rb_node;
609 struct mmtimer *uninitialized_var(t);
610 int r = 0;
611
528 timr->it.mmtimer.clock = TIMER_OFF; 612 timr->it.mmtimer.clock = TIMER_OFF;
529 timr->it.mmtimer.expires = 0; 613 timr->it.mmtimer.expires = 0;
530 spin_unlock_irqrestore(&t->lock, irqflags); 614
615 while (n) {
616 t = rb_entry(n, struct mmtimer, list);
617 if (t->timer == timr)
618 break;
619
620 if (expires < t->timer->it.mmtimer.expires)
621 n = n->rb_left;
622 else
623 n = n->rb_right;
624 }
625
626 if (!n) {
627 spin_unlock_irqrestore(&timers[nodeid].lock, irqflags);
628 return 0;
629 }
630
631 if (timers[nodeid].next == n) {
632 timers[nodeid].next = rb_next(n);
633 r = 1;
634 }
635
636 rb_erase(n, &timers[nodeid].timer_head);
637 kfree(t);
638
639 if (r) {
640 mmtimer_disable_int(cnodeid_to_nasid(nodeid),
641 COMPARATOR);
642 mmtimer_set_next_timer(nodeid);
643 }
531 } 644 }
645 spin_unlock_irqrestore(&timers[nodeid].lock, irqflags);
532 return 0; 646 return 0;
533} 647}
534 648
535#define timespec_to_ns(x) ((x).tv_nsec + (x).tv_sec * NSEC_PER_SEC)
536#define ns_to_timespec(ts, nsec) (ts).tv_sec = div_long_long_rem(nsec, NSEC_PER_SEC, &(ts).tv_nsec)
537
538/* Assumption: it_lock is already held with irq's disabled */ 649/* Assumption: it_lock is already held with irq's disabled */
539static void sgi_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting) 650static void sgi_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting)
540{ 651{
@@ -547,9 +658,8 @@ static void sgi_timer_get(struct k_itimer *timr, struct itimerspec *cur_setting)
547 return; 658 return;
548 } 659 }
549 660
550 ns_to_timespec(cur_setting->it_interval, timr->it.mmtimer.incr * sgi_clock_period); 661 cur_setting->it_interval = ns_to_timespec(timr->it.mmtimer.incr * sgi_clock_period);
551 ns_to_timespec(cur_setting->it_value, (timr->it.mmtimer.expires - rtc_time())* sgi_clock_period); 662 cur_setting->it_value = ns_to_timespec((timr->it.mmtimer.expires - rtc_time()) * sgi_clock_period);
552 return;
553} 663}
554 664
555 665
@@ -557,30 +667,33 @@ static int sgi_timer_set(struct k_itimer *timr, int flags,
557 struct itimerspec * new_setting, 667 struct itimerspec * new_setting,
558 struct itimerspec * old_setting) 668 struct itimerspec * old_setting)
559{ 669{
560
561 int i;
562 unsigned long when, period, irqflags; 670 unsigned long when, period, irqflags;
563 int err = 0; 671 int err = 0;
564 cnodeid_t nodeid; 672 cnodeid_t nodeid;
565 mmtimer_t *base; 673 struct mmtimer *base;
674 struct rb_node *n;
566 675
567 if (old_setting) 676 if (old_setting)
568 sgi_timer_get(timr, old_setting); 677 sgi_timer_get(timr, old_setting);
569 678
570 sgi_timer_del(timr); 679 sgi_timer_del(timr);
571 when = timespec_to_ns(new_setting->it_value); 680 when = timespec_to_ns(&new_setting->it_value);
572 period = timespec_to_ns(new_setting->it_interval); 681 period = timespec_to_ns(&new_setting->it_interval);
573 682
574 if (when == 0) 683 if (when == 0)
575 /* Clear timer */ 684 /* Clear timer */
576 return 0; 685 return 0;
577 686
687 base = kmalloc(sizeof(struct mmtimer), GFP_KERNEL);
688 if (base == NULL)
689 return -ENOMEM;
690
578 if (flags & TIMER_ABSTIME) { 691 if (flags & TIMER_ABSTIME) {
579 struct timespec n; 692 struct timespec n;
580 unsigned long now; 693 unsigned long now;
581 694
582 getnstimeofday(&n); 695 getnstimeofday(&n);
583 now = timespec_to_ns(n); 696 now = timespec_to_ns(&n);
584 if (when > now) 697 if (when > now)
585 when -= now; 698 when -= now;
586 else 699 else
@@ -604,47 +717,38 @@ static int sgi_timer_set(struct k_itimer *timr, int flags,
604 preempt_disable(); 717 preempt_disable();
605 718
606 nodeid = cpu_to_node(smp_processor_id()); 719 nodeid = cpu_to_node(smp_processor_id());
607retry:
608 /* Don't use an allocated timer, or a deleted one that's pending */
609 for(i = 0; i< NUM_COMPARATORS; i++) {
610 base = timers[nodeid] + i;
611 if (!base->timer && !base->tasklet.state) {
612 break;
613 }
614 }
615
616 if (i == NUM_COMPARATORS) {
617 preempt_enable();
618 return -EBUSY;
619 }
620 720
621 spin_lock_irqsave(&base->lock, irqflags); 721 /* Lock the node timer structure */
722 spin_lock_irqsave(&timers[nodeid].lock, irqflags);
622 723
623 if (base->timer || base->tasklet.state != 0) {
624 spin_unlock_irqrestore(&base->lock, irqflags);
625 goto retry;
626 }
627 base->timer = timr; 724 base->timer = timr;
628 base->cpu = smp_processor_id(); 725 base->cpu = smp_processor_id();
629 726
630 timr->it.mmtimer.clock = i; 727 timr->it.mmtimer.clock = TIMER_SET;
631 timr->it.mmtimer.node = nodeid; 728 timr->it.mmtimer.node = nodeid;
632 timr->it.mmtimer.incr = period; 729 timr->it.mmtimer.incr = period;
633 timr->it.mmtimer.expires = when; 730 timr->it.mmtimer.expires = when;
634 731
635 if (period == 0) { 732 n = timers[nodeid].next;
636 if (!mmtimer_setup(i, when)) { 733
637 mmtimer_disable_int(-1, i); 734 /* Add the new struct mmtimer to node's timer list */
638 posix_timer_event(timr, 0); 735 mmtimer_add_list(base);
639 timr->it.mmtimer.expires = 0; 736
640 } 737 if (timers[nodeid].next == n) {
641 } else { 738 /* No need to reprogram comparator for now */
642 timr->it.mmtimer.expires -= period; 739 spin_unlock_irqrestore(&timers[nodeid].lock, irqflags);
643 if (reschedule_periodic_timer(base)) 740 preempt_enable();
644 err = -EINVAL; 741 return err;
645 } 742 }
646 743
647 spin_unlock_irqrestore(&base->lock, irqflags); 744 /* We need to reprogram the comparator */
745 if (n)
746 mmtimer_disable_int(cnodeid_to_nasid(nodeid), COMPARATOR);
747
748 mmtimer_set_next_timer(nodeid);
749
750 /* Unlock the node timer structure */
751 spin_unlock_irqrestore(&timers[nodeid].lock, irqflags);
648 752
649 preempt_enable(); 753 preempt_enable();
650 754
@@ -669,7 +773,6 @@ static struct k_clock sgi_clock = {
669 */ 773 */
670static int __init mmtimer_init(void) 774static int __init mmtimer_init(void)
671{ 775{
672 unsigned i;
673 cnodeid_t node, maxn = -1; 776 cnodeid_t node, maxn = -1;
674 777
675 if (!ia64_platform_is("sn2")) 778 if (!ia64_platform_is("sn2"))
@@ -706,31 +809,18 @@ static int __init mmtimer_init(void)
706 maxn++; 809 maxn++;
707 810
708 /* Allocate list of node ptrs to mmtimer_t's */ 811 /* Allocate list of node ptrs to mmtimer_t's */
709 timers = kzalloc(sizeof(mmtimer_t *)*maxn, GFP_KERNEL); 812 timers = kzalloc(sizeof(struct mmtimer_node)*maxn, GFP_KERNEL);
710 if (timers == NULL) { 813 if (timers == NULL) {
711 printk(KERN_ERR "%s: failed to allocate memory for device\n", 814 printk(KERN_ERR "%s: failed to allocate memory for device\n",
712 MMTIMER_NAME); 815 MMTIMER_NAME);
713 goto out3; 816 goto out3;
714 } 817 }
715 818
716 /* Allocate mmtimer_t's for each online node */ 819 /* Initialize struct mmtimer's for each online node */
717 for_each_online_node(node) { 820 for_each_online_node(node) {
718 timers[node] = kmalloc_node(sizeof(mmtimer_t)*NUM_COMPARATORS, GFP_KERNEL, node); 821 spin_lock_init(&timers[node].lock);
719 if (timers[node] == NULL) { 822 tasklet_init(&timers[node].tasklet, mmtimer_tasklet,
720 printk(KERN_ERR "%s: failed to allocate memory for device\n", 823 (unsigned long) node);
721 MMTIMER_NAME);
722 goto out4;
723 }
724 for (i=0; i< NUM_COMPARATORS; i++) {
725 mmtimer_t * base = timers[node] + i;
726
727 spin_lock_init(&base->lock);
728 base->timer = NULL;
729 base->cpu = 0;
730 base->i = i;
731 tasklet_init(&base->tasklet, mmtimer_tasklet,
732 (unsigned long) (base));
733 }
734 } 824 }
735 825
736 sgi_clock_period = sgi_clock.res = NSEC_PER_SEC / sn_rtc_cycles_per_second; 826 sgi_clock_period = sgi_clock.res = NSEC_PER_SEC / sn_rtc_cycles_per_second;
@@ -741,11 +831,8 @@ static int __init mmtimer_init(void)
741 831
742 return 0; 832 return 0;
743 833
744out4:
745 for_each_online_node(node) {
746 kfree(timers[node]);
747 }
748out3: 834out3:
835 kfree(timers);
749 misc_deregister(&mmtimer_miscdev); 836 misc_deregister(&mmtimer_miscdev);
750out2: 837out2:
751 free_irq(SGI_MMTIMER_VECTOR, NULL); 838 free_irq(SGI_MMTIMER_VECTOR, NULL);
@@ -754,4 +841,3 @@ out1:
754} 841}
755 842
756module_init(mmtimer_init); 843module_init(mmtimer_init);
757
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index 64b7b2b18352..d57d3a61919b 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -2,7 +2,8 @@
2/* 2/*
3 * moxa.c -- MOXA Intellio family multiport serial driver. 3 * moxa.c -- MOXA Intellio family multiport serial driver.
4 * 4 *
5 * Copyright (C) 1999-2000 Moxa Technologies (support@moxa.com.tw). 5 * Copyright (C) 1999-2000 Moxa Technologies (support@moxa.com).
6 * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
6 * 7 *
7 * This code is loosely based on the Linux serial driver, written by 8 * This code is loosely based on the Linux serial driver, written by
8 * Linus Torvalds, Theodore T'so and others. 9 * Linus Torvalds, Theodore T'so and others.
@@ -25,6 +26,7 @@
25#include <linux/mm.h> 26#include <linux/mm.h>
26#include <linux/ioport.h> 27#include <linux/ioport.h>
27#include <linux/errno.h> 28#include <linux/errno.h>
29#include <linux/firmware.h>
28#include <linux/signal.h> 30#include <linux/signal.h>
29#include <linux/sched.h> 31#include <linux/sched.h>
30#include <linux/timer.h> 32#include <linux/timer.h>
@@ -41,21 +43,26 @@
41#include <linux/pci.h> 43#include <linux/pci.h>
42#include <linux/init.h> 44#include <linux/init.h>
43#include <linux/bitops.h> 45#include <linux/bitops.h>
44#include <linux/completion.h>
45 46
46#include <asm/system.h> 47#include <asm/system.h>
47#include <asm/io.h> 48#include <asm/io.h>
48#include <asm/uaccess.h> 49#include <asm/uaccess.h>
49 50
50#define MOXA_VERSION "5.1k" 51#include "moxa.h"
52
53#define MOXA_VERSION "6.0k"
54
55#define MOXA_FW_HDRLEN 32
51 56
52#define MOXAMAJOR 172 57#define MOXAMAJOR 172
53#define MOXACUMAJOR 173
54 58
55#define MAX_BOARDS 4 /* Don't change this value */ 59#define MAX_BOARDS 4 /* Don't change this value */
56#define MAX_PORTS_PER_BOARD 32 /* Don't change this value */ 60#define MAX_PORTS_PER_BOARD 32 /* Don't change this value */
57#define MAX_PORTS (MAX_BOARDS * MAX_PORTS_PER_BOARD) 61#define MAX_PORTS (MAX_BOARDS * MAX_PORTS_PER_BOARD)
58 62
63#define MOXA_IS_320(brd) ((brd)->boardType == MOXA_BOARD_C320_ISA || \
64 (brd)->boardType == MOXA_BOARD_C320_PCI)
65
59/* 66/*
60 * Define the Moxa PCI vendor and device IDs. 67 * Define the Moxa PCI vendor and device IDs.
61 */ 68 */
@@ -92,24 +99,16 @@ static struct pci_device_id moxa_pcibrds[] = {
92MODULE_DEVICE_TABLE(pci, moxa_pcibrds); 99MODULE_DEVICE_TABLE(pci, moxa_pcibrds);
93#endif /* CONFIG_PCI */ 100#endif /* CONFIG_PCI */
94 101
95struct moxa_isa_board_conf { 102struct moxa_port;
96 int boardType;
97 int numPorts;
98 unsigned long baseAddr;
99};
100
101static struct moxa_isa_board_conf moxa_isa_boards[] =
102{
103/* {MOXA_BOARD_C218_ISA,8,0xDC000}, */
104};
105 103
106static struct moxa_board_conf { 104static struct moxa_board_conf {
107 int boardType; 105 int boardType;
108 int numPorts; 106 int numPorts;
109 unsigned long baseAddr;
110 int busType; 107 int busType;
111 108
112 int loadstat; 109 unsigned int ready;
110
111 struct moxa_port *ports;
113 112
114 void __iomem *basemem; 113 void __iomem *basemem;
115 void __iomem *intNdx; 114 void __iomem *intNdx;
@@ -131,30 +130,27 @@ struct moxaq_str {
131}; 130};
132 131
133struct moxa_port { 132struct moxa_port {
133 struct moxa_board_conf *board;
134 struct tty_struct *tty;
135 void __iomem *tableAddr;
136
134 int type; 137 int type;
135 int port;
136 int close_delay; 138 int close_delay;
137 unsigned short closing_wait; 139 unsigned int count;
138 int count;
139 int blocked_open;
140 long event; /* long req'd for set_bit --RR */
141 int asyncflags; 140 int asyncflags;
142 unsigned long statusflags;
143 struct tty_struct *tty;
144 int cflag; 141 int cflag;
142 unsigned long statusflags;
145 wait_queue_head_t open_wait; 143 wait_queue_head_t open_wait;
146 struct completion close_wait;
147
148 struct timer_list emptyTimer;
149 144
150 char chkPort; 145 u8 DCDState;
151 char lineCtrl; 146 u8 lineCtrl;
152 void __iomem *tableAddr; 147 u8 lowChkFlag;
153 long curBaud; 148};
154 char DCDState;
155 char lowChkFlag;
156 149
157 ushort breakCnt; 150struct mon_str {
151 int tick;
152 int rxcnt[MAX_PORTS];
153 int txcnt[MAX_PORTS];
158}; 154};
159 155
160/* statusflags */ 156/* statusflags */
@@ -168,20 +164,27 @@ struct moxa_port {
168#define WAKEUP_CHARS 256 164#define WAKEUP_CHARS 256
169 165
170static int ttymajor = MOXAMAJOR; 166static int ttymajor = MOXAMAJOR;
167static struct mon_str moxaLog;
168static unsigned int moxaFuncTout = HZ / 2;
169static unsigned int moxaLowWaterChk;
170static DEFINE_MUTEX(moxa_openlock);
171/* Variables for insmod */ 171/* Variables for insmod */
172#ifdef MODULE 172#ifdef MODULE
173static int baseaddr[4]; 173static unsigned long baseaddr[MAX_BOARDS];
174static int type[4]; 174static unsigned int type[MAX_BOARDS];
175static int numports[4]; 175static unsigned int numports[MAX_BOARDS];
176#endif 176#endif
177 177
178MODULE_AUTHOR("William Chen"); 178MODULE_AUTHOR("William Chen");
179MODULE_DESCRIPTION("MOXA Intellio Family Multiport Board Device Driver"); 179MODULE_DESCRIPTION("MOXA Intellio Family Multiport Board Device Driver");
180MODULE_LICENSE("GPL"); 180MODULE_LICENSE("GPL");
181#ifdef MODULE 181#ifdef MODULE
182module_param_array(type, int, NULL, 0); 182module_param_array(type, uint, NULL, 0);
183module_param_array(baseaddr, int, NULL, 0); 183MODULE_PARM_DESC(type, "card type: C218=2, C320=4");
184module_param_array(numports, int, NULL, 0); 184module_param_array(baseaddr, ulong, NULL, 0);
185MODULE_PARM_DESC(baseaddr, "base address");
186module_param_array(numports, uint, NULL, 0);
187MODULE_PARM_DESC(numports, "numports (ignored for C218)");
185#endif 188#endif
186module_param(ttymajor, int, 0); 189module_param(ttymajor, int, 0);
187 190
@@ -194,9 +197,6 @@ static int moxa_write(struct tty_struct *, const unsigned char *, int);
194static int moxa_write_room(struct tty_struct *); 197static int moxa_write_room(struct tty_struct *);
195static void moxa_flush_buffer(struct tty_struct *); 198static void moxa_flush_buffer(struct tty_struct *);
196static int moxa_chars_in_buffer(struct tty_struct *); 199static int moxa_chars_in_buffer(struct tty_struct *);
197static void moxa_flush_chars(struct tty_struct *);
198static void moxa_put_char(struct tty_struct *, unsigned char);
199static int moxa_ioctl(struct tty_struct *, struct file *, unsigned int, unsigned long);
200static void moxa_throttle(struct tty_struct *); 200static void moxa_throttle(struct tty_struct *);
201static void moxa_unthrottle(struct tty_struct *); 201static void moxa_unthrottle(struct tty_struct *);
202static void moxa_set_termios(struct tty_struct *, struct ktermios *); 202static void moxa_set_termios(struct tty_struct *, struct ktermios *);
@@ -208,44 +208,183 @@ static int moxa_tiocmset(struct tty_struct *tty, struct file *file,
208 unsigned int set, unsigned int clear); 208 unsigned int set, unsigned int clear);
209static void moxa_poll(unsigned long); 209static void moxa_poll(unsigned long);
210static void moxa_set_tty_param(struct tty_struct *, struct ktermios *); 210static void moxa_set_tty_param(struct tty_struct *, struct ktermios *);
211static int moxa_block_till_ready(struct tty_struct *, struct file *,
212 struct moxa_port *);
213static void moxa_setup_empty_event(struct tty_struct *); 211static void moxa_setup_empty_event(struct tty_struct *);
214static void moxa_check_xmit_empty(unsigned long);
215static void moxa_shut_down(struct moxa_port *); 212static void moxa_shut_down(struct moxa_port *);
216static void moxa_receive_data(struct moxa_port *);
217/* 213/*
218 * moxa board interface functions: 214 * moxa board interface functions:
219 */ 215 */
220static void MoxaDriverInit(void); 216static void MoxaPortEnable(struct moxa_port *);
221static int MoxaDriverIoctl(unsigned int, unsigned long, int); 217static void MoxaPortDisable(struct moxa_port *);
222static int MoxaDriverPoll(void); 218static int MoxaPortSetTermio(struct moxa_port *, struct ktermios *, speed_t);
223static int MoxaPortsOfCard(int); 219static int MoxaPortGetLineOut(struct moxa_port *, int *, int *);
224static int MoxaPortIsValid(int); 220static void MoxaPortLineCtrl(struct moxa_port *, int, int);
225static void MoxaPortEnable(int); 221static void MoxaPortFlowCtrl(struct moxa_port *, int, int, int, int, int);
226static void MoxaPortDisable(int); 222static int MoxaPortLineStatus(struct moxa_port *);
227static long MoxaPortGetMaxBaud(int); 223static void MoxaPortFlushData(struct moxa_port *, int);
228static long MoxaPortSetBaud(int, long); 224static int MoxaPortWriteData(struct moxa_port *, const unsigned char *, int);
229static int MoxaPortSetTermio(int, struct ktermios *, speed_t); 225static int MoxaPortReadData(struct moxa_port *);
230static int MoxaPortGetLineOut(int, int *, int *); 226static int MoxaPortTxQueue(struct moxa_port *);
231static void MoxaPortLineCtrl(int, int, int); 227static int MoxaPortRxQueue(struct moxa_port *);
232static void MoxaPortFlowCtrl(int, int, int, int, int, int); 228static int MoxaPortTxFree(struct moxa_port *);
233static int MoxaPortLineStatus(int); 229static void MoxaPortTxDisable(struct moxa_port *);
234static int MoxaPortDCDChange(int); 230static void MoxaPortTxEnable(struct moxa_port *);
235static int MoxaPortDCDON(int);
236static void MoxaPortFlushData(int, int);
237static int MoxaPortWriteData(int, unsigned char *, int);
238static int MoxaPortReadData(int, struct tty_struct *tty);
239static int MoxaPortTxQueue(int);
240static int MoxaPortRxQueue(int);
241static int MoxaPortTxFree(int);
242static void MoxaPortTxDisable(int);
243static void MoxaPortTxEnable(int);
244static int MoxaPortResetBrkCnt(int);
245static void MoxaPortSendBreak(int, int);
246static int moxa_get_serial_info(struct moxa_port *, struct serial_struct __user *); 231static int moxa_get_serial_info(struct moxa_port *, struct serial_struct __user *);
247static int moxa_set_serial_info(struct moxa_port *, struct serial_struct __user *); 232static int moxa_set_serial_info(struct moxa_port *, struct serial_struct __user *);
248static void MoxaSetFifo(int port, int enable); 233static void MoxaSetFifo(struct moxa_port *port, int enable);
234
235/*
236 * I/O functions
237 */
238
239static void moxa_wait_finish(void __iomem *ofsAddr)
240{
241 unsigned long end = jiffies + moxaFuncTout;
242
243 while (readw(ofsAddr + FuncCode) != 0)
244 if (time_after(jiffies, end))
245 return;
246 if (readw(ofsAddr + FuncCode) != 0 && printk_ratelimit())
247 printk(KERN_WARNING "moxa function expired\n");
248}
249
250static void moxafunc(void __iomem *ofsAddr, u16 cmd, u16 arg)
251{
252 writew(arg, ofsAddr + FuncArg);
253 writew(cmd, ofsAddr + FuncCode);
254 moxa_wait_finish(ofsAddr);
255}
256
257static void moxa_low_water_check(void __iomem *ofsAddr)
258{
259 u16 rptr, wptr, mask, len;
260
261 if (readb(ofsAddr + FlagStat) & Xoff_state) {
262 rptr = readw(ofsAddr + RXrptr);
263 wptr = readw(ofsAddr + RXwptr);
264 mask = readw(ofsAddr + RX_mask);
265 len = (wptr - rptr) & mask;
266 if (len <= Low_water)
267 moxafunc(ofsAddr, FC_SendXon, 0);
268 }
269}
270
271/*
272 * TTY operations
273 */
274
275static int moxa_ioctl(struct tty_struct *tty, struct file *file,
276 unsigned int cmd, unsigned long arg)
277{
278 struct moxa_port *ch = tty->driver_data;
279 void __user *argp = (void __user *)arg;
280 int status, ret = 0;
281
282 if (tty->index == MAX_PORTS) {
283 if (cmd != MOXA_GETDATACOUNT && cmd != MOXA_GET_IOQUEUE &&
284 cmd != MOXA_GETMSTATUS)
285 return -EINVAL;
286 } else if (!ch)
287 return -ENODEV;
288
289 switch (cmd) {
290 case MOXA_GETDATACOUNT:
291 moxaLog.tick = jiffies;
292 if (copy_to_user(argp, &moxaLog, sizeof(moxaLog)))
293 ret = -EFAULT;
294 break;
295 case MOXA_FLUSH_QUEUE:
296 MoxaPortFlushData(ch, arg);
297 break;
298 case MOXA_GET_IOQUEUE: {
299 struct moxaq_str __user *argm = argp;
300 struct moxaq_str tmp;
301 struct moxa_port *p;
302 unsigned int i, j;
303
304 mutex_lock(&moxa_openlock);
305 for (i = 0; i < MAX_BOARDS; i++) {
306 p = moxa_boards[i].ports;
307 for (j = 0; j < MAX_PORTS_PER_BOARD; j++, p++, argm++) {
308 memset(&tmp, 0, sizeof(tmp));
309 if (moxa_boards[i].ready) {
310 tmp.inq = MoxaPortRxQueue(p);
311 tmp.outq = MoxaPortTxQueue(p);
312 }
313 if (copy_to_user(argm, &tmp, sizeof(tmp))) {
314 mutex_unlock(&moxa_openlock);
315 return -EFAULT;
316 }
317 }
318 }
319 mutex_unlock(&moxa_openlock);
320 break;
321 } case MOXA_GET_OQUEUE:
322 status = MoxaPortTxQueue(ch);
323 ret = put_user(status, (unsigned long __user *)argp);
324 break;
325 case MOXA_GET_IQUEUE:
326 status = MoxaPortRxQueue(ch);
327 ret = put_user(status, (unsigned long __user *)argp);
328 break;
329 case MOXA_GETMSTATUS: {
330 struct mxser_mstatus __user *argm = argp;
331 struct mxser_mstatus tmp;
332 struct moxa_port *p;
333 unsigned int i, j;
334
335 mutex_lock(&moxa_openlock);
336 for (i = 0; i < MAX_BOARDS; i++) {
337 p = moxa_boards[i].ports;
338 for (j = 0; j < MAX_PORTS_PER_BOARD; j++, p++, argm++) {
339 memset(&tmp, 0, sizeof(tmp));
340 if (!moxa_boards[i].ready)
341 goto copy;
342
343 status = MoxaPortLineStatus(p);
344 if (status & 1)
345 tmp.cts = 1;
346 if (status & 2)
347 tmp.dsr = 1;
348 if (status & 4)
349 tmp.dcd = 1;
350
351 if (!p->tty || !p->tty->termios)
352 tmp.cflag = p->cflag;
353 else
354 tmp.cflag = p->tty->termios->c_cflag;
355copy:
356 if (copy_to_user(argm, &tmp, sizeof(tmp))) {
357 mutex_unlock(&moxa_openlock);
358 return -EFAULT;
359 }
360 }
361 }
362 mutex_unlock(&moxa_openlock);
363 break;
364 }
365 case TIOCGSERIAL:
366 mutex_lock(&moxa_openlock);
367 ret = moxa_get_serial_info(ch, argp);
368 mutex_unlock(&moxa_openlock);
369 break;
370 case TIOCSSERIAL:
371 mutex_lock(&moxa_openlock);
372 ret = moxa_set_serial_info(ch, argp);
373 mutex_unlock(&moxa_openlock);
374 break;
375 default:
376 ret = -ENOIOCTLCMD;
377 }
378 return ret;
379}
380
381static void moxa_break_ctl(struct tty_struct *tty, int state)
382{
383 struct moxa_port *port = tty->driver_data;
384
385 moxafunc(port->tableAddr, state ? FC_SendBreak : FC_StopBreak,
386 Magic_code);
387}
249 388
250static const struct tty_operations moxa_ops = { 389static const struct tty_operations moxa_ops = {
251 .open = moxa_open, 390 .open = moxa_open,
@@ -254,8 +393,6 @@ static const struct tty_operations moxa_ops = {
254 .write_room = moxa_write_room, 393 .write_room = moxa_write_room,
255 .flush_buffer = moxa_flush_buffer, 394 .flush_buffer = moxa_flush_buffer,
256 .chars_in_buffer = moxa_chars_in_buffer, 395 .chars_in_buffer = moxa_chars_in_buffer,
257 .flush_chars = moxa_flush_chars,
258 .put_char = moxa_put_char,
259 .ioctl = moxa_ioctl, 396 .ioctl = moxa_ioctl,
260 .throttle = moxa_throttle, 397 .throttle = moxa_throttle,
261 .unthrottle = moxa_unthrottle, 398 .unthrottle = moxa_unthrottle,
@@ -263,15 +400,509 @@ static const struct tty_operations moxa_ops = {
263 .stop = moxa_stop, 400 .stop = moxa_stop,
264 .start = moxa_start, 401 .start = moxa_start,
265 .hangup = moxa_hangup, 402 .hangup = moxa_hangup,
403 .break_ctl = moxa_break_ctl,
266 .tiocmget = moxa_tiocmget, 404 .tiocmget = moxa_tiocmget,
267 .tiocmset = moxa_tiocmset, 405 .tiocmset = moxa_tiocmset,
268}; 406};
269 407
270static struct tty_driver *moxaDriver; 408static struct tty_driver *moxaDriver;
271static struct moxa_port moxa_ports[MAX_PORTS];
272static DEFINE_TIMER(moxaTimer, moxa_poll, 0, 0); 409static DEFINE_TIMER(moxaTimer, moxa_poll, 0, 0);
273static DEFINE_SPINLOCK(moxa_lock); 410static DEFINE_SPINLOCK(moxa_lock);
274 411
412/*
413 * HW init
414 */
415
416static int moxa_check_fw_model(struct moxa_board_conf *brd, u8 model)
417{
418 switch (brd->boardType) {
419 case MOXA_BOARD_C218_ISA:
420 case MOXA_BOARD_C218_PCI:
421 if (model != 1)
422 goto err;
423 break;
424 case MOXA_BOARD_CP204J:
425 if (model != 3)
426 goto err;
427 break;
428 default:
429 if (model != 2)
430 goto err;
431 break;
432 }
433 return 0;
434err:
435 return -EINVAL;
436}
437
438static int moxa_check_fw(const void *ptr)
439{
440 const __le16 *lptr = ptr;
441
442 if (*lptr != cpu_to_le16(0x7980))
443 return -EINVAL;
444
445 return 0;
446}
447
448static int moxa_load_bios(struct moxa_board_conf *brd, const u8 *buf,
449 size_t len)
450{
451 void __iomem *baseAddr = brd->basemem;
452 u16 tmp;
453
454 writeb(HW_reset, baseAddr + Control_reg); /* reset */
455 msleep(10);
456 memset_io(baseAddr, 0, 4096);
457 memcpy_toio(baseAddr, buf, len); /* download BIOS */
458 writeb(0, baseAddr + Control_reg); /* restart */
459
460 msleep(2000);
461
462 switch (brd->boardType) {
463 case MOXA_BOARD_C218_ISA:
464 case MOXA_BOARD_C218_PCI:
465 tmp = readw(baseAddr + C218_key);
466 if (tmp != C218_KeyCode)
467 goto err;
468 break;
469 case MOXA_BOARD_CP204J:
470 tmp = readw(baseAddr + C218_key);
471 if (tmp != CP204J_KeyCode)
472 goto err;
473 break;
474 default:
475 tmp = readw(baseAddr + C320_key);
476 if (tmp != C320_KeyCode)
477 goto err;
478 tmp = readw(baseAddr + C320_status);
479 if (tmp != STS_init) {
480 printk(KERN_ERR "MOXA: bios upload failed -- CPU/Basic "
481 "module not found\n");
482 return -EIO;
483 }
484 break;
485 }
486
487 return 0;
488err:
489 printk(KERN_ERR "MOXA: bios upload failed -- board not found\n");
490 return -EIO;
491}
492
493static int moxa_load_320b(struct moxa_board_conf *brd, const u8 *ptr,
494 size_t len)
495{
496 void __iomem *baseAddr = brd->basemem;
497
498 if (len < 7168) {
499 printk(KERN_ERR "MOXA: invalid 320 bios -- too short\n");
500 return -EINVAL;
501 }
502
503 writew(len - 7168 - 2, baseAddr + C320bapi_len);
504 writeb(1, baseAddr + Control_reg); /* Select Page 1 */
505 memcpy_toio(baseAddr + DynPage_addr, ptr, 7168);
506 writeb(2, baseAddr + Control_reg); /* Select Page 2 */
507 memcpy_toio(baseAddr + DynPage_addr, ptr + 7168, len - 7168);
508
509 return 0;
510}
511
512static int moxa_real_load_code(struct moxa_board_conf *brd, const void *ptr,
513 size_t len)
514{
515 void __iomem *baseAddr = brd->basemem;
516 const u16 *uptr = ptr;
517 size_t wlen, len2, j;
518 unsigned long key, loadbuf, loadlen, checksum, checksum_ok;
519 unsigned int i, retry;
520 u16 usum, keycode;
521
522 keycode = (brd->boardType == MOXA_BOARD_CP204J) ? CP204J_KeyCode :
523 C218_KeyCode;
524
525 switch (brd->boardType) {
526 case MOXA_BOARD_CP204J:
527 case MOXA_BOARD_C218_ISA:
528 case MOXA_BOARD_C218_PCI:
529 key = C218_key;
530 loadbuf = C218_LoadBuf;
531 loadlen = C218DLoad_len;
532 checksum = C218check_sum;
533 checksum_ok = C218chksum_ok;
534 break;
535 default:
536 key = C320_key;
537 keycode = C320_KeyCode;
538 loadbuf = C320_LoadBuf;
539 loadlen = C320DLoad_len;
540 checksum = C320check_sum;
541 checksum_ok = C320chksum_ok;
542 break;
543 }
544
545 usum = 0;
546 wlen = len >> 1;
547 for (i = 0; i < wlen; i++)
548 usum += le16_to_cpu(uptr[i]);
549 retry = 0;
550 do {
551 wlen = len >> 1;
552 j = 0;
553 while (wlen) {
554 len2 = (wlen > 2048) ? 2048 : wlen;
555 wlen -= len2;
556 memcpy_toio(baseAddr + loadbuf, ptr + j, len2 << 1);
557 j += len2 << 1;
558
559 writew(len2, baseAddr + loadlen);
560 writew(0, baseAddr + key);
561 for (i = 0; i < 100; i++) {
562 if (readw(baseAddr + key) == keycode)
563 break;
564 msleep(10);
565 }
566 if (readw(baseAddr + key) != keycode)
567 return -EIO;
568 }
569 writew(0, baseAddr + loadlen);
570 writew(usum, baseAddr + checksum);
571 writew(0, baseAddr + key);
572 for (i = 0; i < 100; i++) {
573 if (readw(baseAddr + key) == keycode)
574 break;
575 msleep(10);
576 }
577 retry++;
578 } while ((readb(baseAddr + checksum_ok) != 1) && (retry < 3));
579 if (readb(baseAddr + checksum_ok) != 1)
580 return -EIO;
581
582 writew(0, baseAddr + key);
583 for (i = 0; i < 600; i++) {
584 if (readw(baseAddr + Magic_no) == Magic_code)
585 break;
586 msleep(10);
587 }
588 if (readw(baseAddr + Magic_no) != Magic_code)
589 return -EIO;
590
591 if (MOXA_IS_320(brd)) {
592 if (brd->busType == MOXA_BUS_TYPE_PCI) { /* ASIC board */
593 writew(0x3800, baseAddr + TMS320_PORT1);
594 writew(0x3900, baseAddr + TMS320_PORT2);
595 writew(28499, baseAddr + TMS320_CLOCK);
596 } else {
597 writew(0x3200, baseAddr + TMS320_PORT1);
598 writew(0x3400, baseAddr + TMS320_PORT2);
599 writew(19999, baseAddr + TMS320_CLOCK);
600 }
601 }
602 writew(1, baseAddr + Disable_IRQ);
603 writew(0, baseAddr + Magic_no);
604 for (i = 0; i < 500; i++) {
605 if (readw(baseAddr + Magic_no) == Magic_code)
606 break;
607 msleep(10);
608 }
609 if (readw(baseAddr + Magic_no) != Magic_code)
610 return -EIO;
611
612 if (MOXA_IS_320(brd)) {
613 j = readw(baseAddr + Module_cnt);
614 if (j <= 0)
615 return -EIO;
616 brd->numPorts = j * 8;
617 writew(j, baseAddr + Module_no);
618 writew(0, baseAddr + Magic_no);
619 for (i = 0; i < 600; i++) {
620 if (readw(baseAddr + Magic_no) == Magic_code)
621 break;
622 msleep(10);
623 }
624 if (readw(baseAddr + Magic_no) != Magic_code)
625 return -EIO;
626 }
627 brd->intNdx = baseAddr + IRQindex;
628 brd->intPend = baseAddr + IRQpending;
629 brd->intTable = baseAddr + IRQtable;
630
631 return 0;
632}
633
634static int moxa_load_code(struct moxa_board_conf *brd, const void *ptr,
635 size_t len)
636{
637 void __iomem *ofsAddr, *baseAddr = brd->basemem;
638 struct moxa_port *port;
639 int retval, i;
640
641 if (len % 2) {
642 printk(KERN_ERR "MOXA: bios length is not even\n");
643 return -EINVAL;
644 }
645
646 retval = moxa_real_load_code(brd, ptr, len); /* may change numPorts */
647 if (retval)
648 return retval;
649
650 switch (brd->boardType) {
651 case MOXA_BOARD_C218_ISA:
652 case MOXA_BOARD_C218_PCI:
653 case MOXA_BOARD_CP204J:
654 port = brd->ports;
655 for (i = 0; i < brd->numPorts; i++, port++) {
656 port->board = brd;
657 port->DCDState = 0;
658 port->tableAddr = baseAddr + Extern_table +
659 Extern_size * i;
660 ofsAddr = port->tableAddr;
661 writew(C218rx_mask, ofsAddr + RX_mask);
662 writew(C218tx_mask, ofsAddr + TX_mask);
663 writew(C218rx_spage + i * C218buf_pageno, ofsAddr + Page_rxb);
664 writew(readw(ofsAddr + Page_rxb) + C218rx_pageno, ofsAddr + EndPage_rxb);
665
666 writew(C218tx_spage + i * C218buf_pageno, ofsAddr + Page_txb);
667 writew(readw(ofsAddr + Page_txb) + C218tx_pageno, ofsAddr + EndPage_txb);
668
669 }
670 break;
671 default:
672 port = brd->ports;
673 for (i = 0; i < brd->numPorts; i++, port++) {
674 port->board = brd;
675 port->DCDState = 0;
676 port->tableAddr = baseAddr + Extern_table +
677 Extern_size * i;
678 ofsAddr = port->tableAddr;
679 switch (brd->numPorts) {
680 case 8:
681 writew(C320p8rx_mask, ofsAddr + RX_mask);
682 writew(C320p8tx_mask, ofsAddr + TX_mask);
683 writew(C320p8rx_spage + i * C320p8buf_pgno, ofsAddr + Page_rxb);
684 writew(readw(ofsAddr + Page_rxb) + C320p8rx_pgno, ofsAddr + EndPage_rxb);
685 writew(C320p8tx_spage + i * C320p8buf_pgno, ofsAddr + Page_txb);
686 writew(readw(ofsAddr + Page_txb) + C320p8tx_pgno, ofsAddr + EndPage_txb);
687
688 break;
689 case 16:
690 writew(C320p16rx_mask, ofsAddr + RX_mask);
691 writew(C320p16tx_mask, ofsAddr + TX_mask);
692 writew(C320p16rx_spage + i * C320p16buf_pgno, ofsAddr + Page_rxb);
693 writew(readw(ofsAddr + Page_rxb) + C320p16rx_pgno, ofsAddr + EndPage_rxb);
694 writew(C320p16tx_spage + i * C320p16buf_pgno, ofsAddr + Page_txb);
695 writew(readw(ofsAddr + Page_txb) + C320p16tx_pgno, ofsAddr + EndPage_txb);
696 break;
697
698 case 24:
699 writew(C320p24rx_mask, ofsAddr + RX_mask);
700 writew(C320p24tx_mask, ofsAddr + TX_mask);
701 writew(C320p24rx_spage + i * C320p24buf_pgno, ofsAddr + Page_rxb);
702 writew(readw(ofsAddr + Page_rxb) + C320p24rx_pgno, ofsAddr + EndPage_rxb);
703 writew(C320p24tx_spage + i * C320p24buf_pgno, ofsAddr + Page_txb);
704 writew(readw(ofsAddr + Page_txb), ofsAddr + EndPage_txb);
705 break;
706 case 32:
707 writew(C320p32rx_mask, ofsAddr + RX_mask);
708 writew(C320p32tx_mask, ofsAddr + TX_mask);
709 writew(C320p32tx_ofs, ofsAddr + Ofs_txb);
710 writew(C320p32rx_spage + i * C320p32buf_pgno, ofsAddr + Page_rxb);
711 writew(readb(ofsAddr + Page_rxb), ofsAddr + EndPage_rxb);
712 writew(C320p32tx_spage + i * C320p32buf_pgno, ofsAddr + Page_txb);
713 writew(readw(ofsAddr + Page_txb), ofsAddr + EndPage_txb);
714 break;
715 }
716 }
717 break;
718 }
719 return 0;
720}
721
722static int moxa_load_fw(struct moxa_board_conf *brd, const struct firmware *fw)
723{
724 void *ptr = fw->data;
725 char rsn[64];
726 u16 lens[5];
727 size_t len;
728 unsigned int a, lenp, lencnt;
729 int ret = -EINVAL;
730 struct {
731 __le32 magic; /* 0x34303430 */
732 u8 reserved1[2];
733 u8 type; /* UNIX = 3 */
734 u8 model; /* C218T=1, C320T=2, CP204=3 */
735 u8 reserved2[8];
736 __le16 len[5];
737 } *hdr = ptr;
738
739 BUILD_BUG_ON(ARRAY_SIZE(hdr->len) != ARRAY_SIZE(lens));
740
741 if (fw->size < MOXA_FW_HDRLEN) {
742 strcpy(rsn, "too short (even header won't fit)");
743 goto err;
744 }
745 if (hdr->magic != cpu_to_le32(0x30343034)) {
746 sprintf(rsn, "bad magic: %.8x", le32_to_cpu(hdr->magic));
747 goto err;
748 }
749 if (hdr->type != 3) {
750 sprintf(rsn, "not for linux, type is %u", hdr->type);
751 goto err;
752 }
753 if (moxa_check_fw_model(brd, hdr->model)) {
754 sprintf(rsn, "not for this card, model is %u", hdr->model);
755 goto err;
756 }
757
758 len = MOXA_FW_HDRLEN;
759 lencnt = hdr->model == 2 ? 5 : 3;
760 for (a = 0; a < ARRAY_SIZE(lens); a++) {
761 lens[a] = le16_to_cpu(hdr->len[a]);
762 if (lens[a] && len + lens[a] <= fw->size &&
763 moxa_check_fw(&fw->data[len]))
764 printk(KERN_WARNING "MOXA firmware: unexpected input "
765 "at offset %u, but going on\n", (u32)len);
766 if (!lens[a] && a < lencnt) {
767 sprintf(rsn, "too few entries in fw file");
768 goto err;
769 }
770 len += lens[a];
771 }
772
773 if (len != fw->size) {
774 sprintf(rsn, "bad length: %u (should be %u)", (u32)fw->size,
775 (u32)len);
776 goto err;
777 }
778
779 ptr += MOXA_FW_HDRLEN;
780 lenp = 0; /* bios */
781
782 strcpy(rsn, "read above");
783
784 ret = moxa_load_bios(brd, ptr, lens[lenp]);
785 if (ret)
786 goto err;
787
788 /* we skip the tty section (lens[1]), since we don't need it */
789 ptr += lens[lenp] + lens[lenp + 1];
790 lenp += 2; /* comm */
791
792 if (hdr->model == 2) {
793 ret = moxa_load_320b(brd, ptr, lens[lenp]);
794 if (ret)
795 goto err;
796 /* skip another tty */
797 ptr += lens[lenp] + lens[lenp + 1];
798 lenp += 2;
799 }
800
801 ret = moxa_load_code(brd, ptr, lens[lenp]);
802 if (ret)
803 goto err;
804
805 return 0;
806err:
807 printk(KERN_ERR "firmware failed to load, reason: %s\n", rsn);
808 return ret;
809}
810
811static int moxa_init_board(struct moxa_board_conf *brd, struct device *dev)
812{
813 const struct firmware *fw;
814 const char *file;
815 struct moxa_port *p;
816 unsigned int i;
817 int ret;
818
819 brd->ports = kcalloc(MAX_PORTS_PER_BOARD, sizeof(*brd->ports),
820 GFP_KERNEL);
821 if (brd->ports == NULL) {
822 printk(KERN_ERR "cannot allocate memory for ports\n");
823 ret = -ENOMEM;
824 goto err;
825 }
826
827 for (i = 0, p = brd->ports; i < MAX_PORTS_PER_BOARD; i++, p++) {
828 p->type = PORT_16550A;
829 p->close_delay = 5 * HZ / 10;
830 p->cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
831 init_waitqueue_head(&p->open_wait);
832 }
833
834 switch (brd->boardType) {
835 case MOXA_BOARD_C218_ISA:
836 case MOXA_BOARD_C218_PCI:
837 file = "c218tunx.cod";
838 break;
839 case MOXA_BOARD_CP204J:
840 file = "cp204unx.cod";
841 break;
842 default:
843 file = "c320tunx.cod";
844 break;
845 }
846
847 ret = request_firmware(&fw, file, dev);
848 if (ret) {
849 printk(KERN_ERR "MOXA: request_firmware failed. Make sure "
850 "you've placed '%s' file into your firmware "
851 "loader directory (e.g. /lib/firmware)\n",
852 file);
853 goto err_free;
854 }
855
856 ret = moxa_load_fw(brd, fw);
857
858 release_firmware(fw);
859
860 if (ret)
861 goto err_free;
862
863 spin_lock_bh(&moxa_lock);
864 brd->ready = 1;
865 if (!timer_pending(&moxaTimer))
866 mod_timer(&moxaTimer, jiffies + HZ / 50);
867 spin_unlock_bh(&moxa_lock);
868
869 return 0;
870err_free:
871 kfree(brd->ports);
872err:
873 return ret;
874}
875
876static void moxa_board_deinit(struct moxa_board_conf *brd)
877{
878 unsigned int a, opened;
879
880 mutex_lock(&moxa_openlock);
881 spin_lock_bh(&moxa_lock);
882 brd->ready = 0;
883 spin_unlock_bh(&moxa_lock);
884
885 /* pci hot-un-plug support */
886 for (a = 0; a < brd->numPorts; a++)
887 if (brd->ports[a].asyncflags & ASYNC_INITIALIZED)
888 tty_hangup(brd->ports[a].tty);
889 while (1) {
890 opened = 0;
891 for (a = 0; a < brd->numPorts; a++)
892 if (brd->ports[a].asyncflags & ASYNC_INITIALIZED)
893 opened++;
894 mutex_unlock(&moxa_openlock);
895 if (!opened)
896 break;
897 msleep(50);
898 mutex_lock(&moxa_openlock);
899 }
900
901 iounmap(brd->basemem);
902 brd->basemem = NULL;
903 kfree(brd->ports);
904}
905
275#ifdef CONFIG_PCI 906#ifdef CONFIG_PCI
276static int __devinit moxa_pci_probe(struct pci_dev *pdev, 907static int __devinit moxa_pci_probe(struct pci_dev *pdev,
277 const struct pci_device_id *ent) 908 const struct pci_device_id *ent)
@@ -299,10 +930,17 @@ static int __devinit moxa_pci_probe(struct pci_dev *pdev,
299 } 930 }
300 931
301 board = &moxa_boards[i]; 932 board = &moxa_boards[i];
302 board->basemem = pci_iomap(pdev, 2, 0x4000); 933
934 retval = pci_request_region(pdev, 2, "moxa-base");
935 if (retval) {
936 dev_err(&pdev->dev, "can't request pci region 2\n");
937 goto err;
938 }
939
940 board->basemem = ioremap_nocache(pci_resource_start(pdev, 2), 0x4000);
303 if (board->basemem == NULL) { 941 if (board->basemem == NULL) {
304 dev_err(&pdev->dev, "can't remap io space 2\n"); 942 dev_err(&pdev->dev, "can't remap io space 2\n");
305 goto err; 943 goto err_reg;
306 } 944 }
307 945
308 board->boardType = board_type; 946 board->boardType = board_type;
@@ -321,9 +959,21 @@ static int __devinit moxa_pci_probe(struct pci_dev *pdev,
321 } 959 }
322 board->busType = MOXA_BUS_TYPE_PCI; 960 board->busType = MOXA_BUS_TYPE_PCI;
323 961
962 retval = moxa_init_board(board, &pdev->dev);
963 if (retval)
964 goto err_base;
965
324 pci_set_drvdata(pdev, board); 966 pci_set_drvdata(pdev, board);
325 967
326 return (0); 968 dev_info(&pdev->dev, "board '%s' ready (%u ports, firmware loaded)\n",
969 moxa_brdname[board_type - 1], board->numPorts);
970
971 return 0;
972err_base:
973 iounmap(board->basemem);
974 board->basemem = NULL;
975err_reg:
976 pci_release_region(pdev, 2);
327err: 977err:
328 return retval; 978 return retval;
329} 979}
@@ -332,8 +982,9 @@ static void __devexit moxa_pci_remove(struct pci_dev *pdev)
332{ 982{
333 struct moxa_board_conf *brd = pci_get_drvdata(pdev); 983 struct moxa_board_conf *brd = pci_get_drvdata(pdev);
334 984
335 pci_iounmap(pdev, brd->basemem); 985 moxa_board_deinit(brd);
336 brd->basemem = NULL; 986
987 pci_release_region(pdev, 2);
337} 988}
338 989
339static struct pci_driver moxa_pci_driver = { 990static struct pci_driver moxa_pci_driver = {
@@ -346,8 +997,8 @@ static struct pci_driver moxa_pci_driver = {
346 997
347static int __init moxa_init(void) 998static int __init moxa_init(void)
348{ 999{
349 int i, numBoards, retval = 0; 1000 unsigned int isabrds = 0;
350 struct moxa_port *ch; 1001 int retval = 0;
351 1002
352 printk(KERN_INFO "MOXA Intellio family driver version %s\n", 1003 printk(KERN_INFO "MOXA Intellio family driver version %s\n",
353 MOXA_VERSION); 1004 MOXA_VERSION);
@@ -368,154 +1019,176 @@ static int __init moxa_init(void)
368 moxaDriver->flags = TTY_DRIVER_REAL_RAW; 1019 moxaDriver->flags = TTY_DRIVER_REAL_RAW;
369 tty_set_operations(moxaDriver, &moxa_ops); 1020 tty_set_operations(moxaDriver, &moxa_ops);
370 1021
371 for (i = 0, ch = moxa_ports; i < MAX_PORTS; i++, ch++) {
372 ch->type = PORT_16550A;
373 ch->port = i;
374 ch->close_delay = 5 * HZ / 10;
375 ch->closing_wait = 30 * HZ;
376 ch->cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
377 init_waitqueue_head(&ch->open_wait);
378 init_completion(&ch->close_wait);
379
380 setup_timer(&ch->emptyTimer, moxa_check_xmit_empty,
381 (unsigned long)ch);
382 }
383
384 pr_debug("Moxa tty devices major number = %d\n", ttymajor);
385
386 if (tty_register_driver(moxaDriver)) { 1022 if (tty_register_driver(moxaDriver)) {
387 printk(KERN_ERR "Couldn't install MOXA Smartio family driver !\n"); 1023 printk(KERN_ERR "can't register MOXA Smartio tty driver!\n");
388 put_tty_driver(moxaDriver); 1024 put_tty_driver(moxaDriver);
389 return -1; 1025 return -1;
390 } 1026 }
391 1027
392 mod_timer(&moxaTimer, jiffies + HZ / 50); 1028 /* Find the boards defined from module args. */
393
394 /* Find the boards defined in source code */
395 numBoards = 0;
396 for (i = 0; i < MAX_BOARDS; i++) {
397 if ((moxa_isa_boards[i].boardType == MOXA_BOARD_C218_ISA) ||
398 (moxa_isa_boards[i].boardType == MOXA_BOARD_C320_ISA)) {
399 moxa_boards[numBoards].boardType = moxa_isa_boards[i].boardType;
400 if (moxa_isa_boards[i].boardType == MOXA_BOARD_C218_ISA)
401 moxa_boards[numBoards].numPorts = 8;
402 else
403 moxa_boards[numBoards].numPorts = moxa_isa_boards[i].numPorts;
404 moxa_boards[numBoards].busType = MOXA_BUS_TYPE_ISA;
405 moxa_boards[numBoards].baseAddr = moxa_isa_boards[i].baseAddr;
406 pr_debug("Moxa board %2d: %s board(baseAddr=%lx)\n",
407 numBoards + 1,
408 moxa_brdname[moxa_boards[numBoards].boardType-1],
409 moxa_boards[numBoards].baseAddr);
410 numBoards++;
411 }
412 }
413 /* Find the boards defined form module args. */
414#ifdef MODULE 1029#ifdef MODULE
1030 {
1031 struct moxa_board_conf *brd = moxa_boards;
1032 unsigned int i;
415 for (i = 0; i < MAX_BOARDS; i++) { 1033 for (i = 0; i < MAX_BOARDS; i++) {
416 if ((type[i] == MOXA_BOARD_C218_ISA) || 1034 if (!baseaddr[i])
417 (type[i] == MOXA_BOARD_C320_ISA)) { 1035 break;
1036 if (type[i] == MOXA_BOARD_C218_ISA ||
1037 type[i] == MOXA_BOARD_C320_ISA) {
418 pr_debug("Moxa board %2d: %s board(baseAddr=%lx)\n", 1038 pr_debug("Moxa board %2d: %s board(baseAddr=%lx)\n",
419 numBoards + 1, moxa_brdname[type[i] - 1], 1039 isabrds + 1, moxa_brdname[type[i] - 1],
420 (unsigned long)baseaddr[i]); 1040 baseaddr[i]);
421 if (numBoards >= MAX_BOARDS) { 1041 brd->boardType = type[i];
422 printk(KERN_WARNING "More than %d MOXA " 1042 brd->numPorts = type[i] == MOXA_BOARD_C218_ISA ? 8 :
423 "Intellio family boards found. Board " 1043 numports[i];
424 "is ignored.\n", MAX_BOARDS); 1044 brd->busType = MOXA_BUS_TYPE_ISA;
1045 brd->basemem = ioremap_nocache(baseaddr[i], 0x4000);
1046 if (!brd->basemem) {
1047 printk(KERN_ERR "MOXA: can't remap %lx\n",
1048 baseaddr[i]);
425 continue; 1049 continue;
426 } 1050 }
427 moxa_boards[numBoards].boardType = type[i]; 1051 if (moxa_init_board(brd, NULL)) {
428 if (moxa_isa_boards[i].boardType == MOXA_BOARD_C218_ISA) 1052 iounmap(brd->basemem);
429 moxa_boards[numBoards].numPorts = 8; 1053 brd->basemem = NULL;
430 else 1054 continue;
431 moxa_boards[numBoards].numPorts = numports[i]; 1055 }
432 moxa_boards[numBoards].busType = MOXA_BUS_TYPE_ISA; 1056
433 moxa_boards[numBoards].baseAddr = baseaddr[i]; 1057 printk(KERN_INFO "MOXA isa board found at 0x%.8lu and "
434 numBoards++; 1058 "ready (%u ports, firmware loaded)\n",
1059 baseaddr[i], brd->numPorts);
1060
1061 brd++;
1062 isabrds++;
435 } 1063 }
436 } 1064 }
1065 }
437#endif 1066#endif
438 1067
439#ifdef CONFIG_PCI 1068#ifdef CONFIG_PCI
440 retval = pci_register_driver(&moxa_pci_driver); 1069 retval = pci_register_driver(&moxa_pci_driver);
441 if (retval) { 1070 if (retval) {
442 printk(KERN_ERR "Can't register moxa pci driver!\n"); 1071 printk(KERN_ERR "Can't register MOXA pci driver!\n");
443 if (numBoards) 1072 if (isabrds)
444 retval = 0; 1073 retval = 0;
445 } 1074 }
446#endif 1075#endif
447 1076
448 for (i = 0; i < numBoards; i++) {
449 moxa_boards[i].basemem = ioremap(moxa_boards[i].baseAddr,
450 0x4000);
451 }
452
453 return retval; 1077 return retval;
454} 1078}
455 1079
456static void __exit moxa_exit(void) 1080static void __exit moxa_exit(void)
457{ 1081{
458 int i; 1082 unsigned int i;
459 1083
460 del_timer_sync(&moxaTimer); 1084#ifdef CONFIG_PCI
1085 pci_unregister_driver(&moxa_pci_driver);
1086#endif
1087
1088 for (i = 0; i < MAX_BOARDS; i++) /* ISA boards */
1089 if (moxa_boards[i].ready)
1090 moxa_board_deinit(&moxa_boards[i]);
461 1091
462 for (i = 0; i < MAX_PORTS; i++) 1092 del_timer_sync(&moxaTimer);
463 del_timer_sync(&moxa_ports[i].emptyTimer);
464 1093
465 if (tty_unregister_driver(moxaDriver)) 1094 if (tty_unregister_driver(moxaDriver))
466 printk(KERN_ERR "Couldn't unregister MOXA Intellio family " 1095 printk(KERN_ERR "Couldn't unregister MOXA Intellio family "
467 "serial driver\n"); 1096 "serial driver\n");
468 put_tty_driver(moxaDriver); 1097 put_tty_driver(moxaDriver);
469
470#ifdef CONFIG_PCI
471 pci_unregister_driver(&moxa_pci_driver);
472#endif
473
474 for (i = 0; i < MAX_BOARDS; i++)
475 if (moxa_boards[i].basemem)
476 iounmap(moxa_boards[i].basemem);
477} 1098}
478 1099
479module_init(moxa_init); 1100module_init(moxa_init);
480module_exit(moxa_exit); 1101module_exit(moxa_exit);
481 1102
1103static void moxa_close_port(struct moxa_port *ch)
1104{
1105 moxa_shut_down(ch);
1106 MoxaPortFlushData(ch, 2);
1107 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
1108 ch->tty->driver_data = NULL;
1109 ch->tty = NULL;
1110}
1111
1112static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp,
1113 struct moxa_port *ch)
1114{
1115 DEFINE_WAIT(wait);
1116 int retval = 0;
1117 u8 dcd;
1118
1119 while (1) {
1120 prepare_to_wait(&ch->open_wait, &wait, TASK_INTERRUPTIBLE);
1121 if (tty_hung_up_p(filp)) {
1122#ifdef SERIAL_DO_RESTART
1123 retval = -ERESTARTSYS;
1124#else
1125 retval = -EAGAIN;
1126#endif
1127 break;
1128 }
1129 spin_lock_bh(&moxa_lock);
1130 dcd = ch->DCDState;
1131 spin_unlock_bh(&moxa_lock);
1132 if (dcd)
1133 break;
1134
1135 if (signal_pending(current)) {
1136 retval = -ERESTARTSYS;
1137 break;
1138 }
1139 schedule();
1140 }
1141 finish_wait(&ch->open_wait, &wait);
1142
1143 return retval;
1144}
1145
482static int moxa_open(struct tty_struct *tty, struct file *filp) 1146static int moxa_open(struct tty_struct *tty, struct file *filp)
483{ 1147{
1148 struct moxa_board_conf *brd;
484 struct moxa_port *ch; 1149 struct moxa_port *ch;
485 int port; 1150 int port;
486 int retval; 1151 int retval;
487 1152
488 port = tty->index; 1153 port = tty->index;
489 if (port == MAX_PORTS) { 1154 if (port == MAX_PORTS) {
490 return (0); 1155 return capable(CAP_SYS_ADMIN) ? 0 : -EPERM;
491 } 1156 }
492 if (!MoxaPortIsValid(port)) { 1157 if (mutex_lock_interruptible(&moxa_openlock))
493 tty->driver_data = NULL; 1158 return -ERESTARTSYS;
494 return (-ENODEV); 1159 brd = &moxa_boards[port / MAX_PORTS_PER_BOARD];
1160 if (!brd->ready) {
1161 mutex_unlock(&moxa_openlock);
1162 return -ENODEV;
495 } 1163 }
496 1164
497 ch = &moxa_ports[port]; 1165 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
498 ch->count++; 1166 ch->count++;
499 tty->driver_data = ch; 1167 tty->driver_data = ch;
500 ch->tty = tty; 1168 ch->tty = tty;
501 if (!(ch->asyncflags & ASYNC_INITIALIZED)) { 1169 if (!(ch->asyncflags & ASYNC_INITIALIZED)) {
502 ch->statusflags = 0; 1170 ch->statusflags = 0;
503 moxa_set_tty_param(tty, tty->termios); 1171 moxa_set_tty_param(tty, tty->termios);
504 MoxaPortLineCtrl(ch->port, 1, 1); 1172 MoxaPortLineCtrl(ch, 1, 1);
505 MoxaPortEnable(ch->port); 1173 MoxaPortEnable(ch);
1174 MoxaSetFifo(ch, ch->type == PORT_16550A);
506 ch->asyncflags |= ASYNC_INITIALIZED; 1175 ch->asyncflags |= ASYNC_INITIALIZED;
507 } 1176 }
508 retval = moxa_block_till_ready(tty, filp, ch); 1177 mutex_unlock(&moxa_openlock);
509 1178
510 moxa_unthrottle(tty); 1179 retval = 0;
511 1180 if (!(filp->f_flags & O_NONBLOCK) && !C_CLOCAL(tty))
512 if (ch->type == PORT_16550A) { 1181 retval = moxa_block_till_ready(tty, filp, ch);
513 MoxaSetFifo(ch->port, 1); 1182 mutex_lock(&moxa_openlock);
514 } else { 1183 if (retval) {
515 MoxaSetFifo(ch->port, 0); 1184 if (ch->count) /* 0 means already hung up... */
516 } 1185 if (--ch->count == 0)
1186 moxa_close_port(ch);
1187 } else
1188 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1189 mutex_unlock(&moxa_openlock);
517 1190
518 return (retval); 1191 return retval;
519} 1192}
520 1193
521static void moxa_close(struct tty_struct *tty, struct file *filp) 1194static void moxa_close(struct tty_struct *tty, struct file *filp)
@@ -524,23 +1197,14 @@ static void moxa_close(struct tty_struct *tty, struct file *filp)
524 int port; 1197 int port;
525 1198
526 port = tty->index; 1199 port = tty->index;
527 if (port == MAX_PORTS) { 1200 if (port == MAX_PORTS || tty_hung_up_p(filp))
528 return;
529 }
530 if (!MoxaPortIsValid(port)) {
531 pr_debug("Invalid portno in moxa_close\n");
532 tty->driver_data = NULL;
533 return;
534 }
535 if (tty->driver_data == NULL) {
536 return; 1201 return;
537 }
538 if (tty_hung_up_p(filp)) {
539 return;
540 }
541 ch = (struct moxa_port *) tty->driver_data;
542 1202
543 if ((tty->count == 1) && (ch->count != 1)) { 1203 mutex_lock(&moxa_openlock);
1204 ch = tty->driver_data;
1205 if (ch == NULL)
1206 goto unlock;
1207 if (tty->count == 1 && ch->count != 1) {
544 printk(KERN_WARNING "moxa_close: bad serial port count; " 1208 printk(KERN_WARNING "moxa_close: bad serial port count; "
545 "tty->count is 1, ch->count is %d\n", ch->count); 1209 "tty->count is 1, ch->count is %d\n", ch->count);
546 ch->count = 1; 1210 ch->count = 1;
@@ -550,59 +1214,35 @@ static void moxa_close(struct tty_struct *tty, struct file *filp)
550 "device=%s\n", tty->name); 1214 "device=%s\n", tty->name);
551 ch->count = 0; 1215 ch->count = 0;
552 } 1216 }
553 if (ch->count) { 1217 if (ch->count)
554 return; 1218 goto unlock;
555 }
556 ch->asyncflags |= ASYNC_CLOSING;
557 1219
558 ch->cflag = tty->termios->c_cflag; 1220 ch->cflag = tty->termios->c_cflag;
559 if (ch->asyncflags & ASYNC_INITIALIZED) { 1221 if (ch->asyncflags & ASYNC_INITIALIZED) {
560 moxa_setup_empty_event(tty); 1222 moxa_setup_empty_event(tty);
561 tty_wait_until_sent(tty, 30 * HZ); /* 30 seconds timeout */ 1223 tty_wait_until_sent(tty, 30 * HZ); /* 30 seconds timeout */
562 del_timer_sync(&moxa_ports[ch->port].emptyTimer);
563 }
564 moxa_shut_down(ch);
565 MoxaPortFlushData(port, 2);
566
567 if (tty->driver->flush_buffer)
568 tty->driver->flush_buffer(tty);
569 tty_ldisc_flush(tty);
570
571 tty->closing = 0;
572 ch->event = 0;
573 ch->tty = NULL;
574 if (ch->blocked_open) {
575 if (ch->close_delay) {
576 msleep_interruptible(jiffies_to_msecs(ch->close_delay));
577 }
578 wake_up_interruptible(&ch->open_wait);
579 } 1224 }
580 ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING); 1225
581 complete_all(&ch->close_wait); 1226 moxa_close_port(ch);
1227unlock:
1228 mutex_unlock(&moxa_openlock);
582} 1229}
583 1230
584static int moxa_write(struct tty_struct *tty, 1231static int moxa_write(struct tty_struct *tty,
585 const unsigned char *buf, int count) 1232 const unsigned char *buf, int count)
586{ 1233{
587 struct moxa_port *ch; 1234 struct moxa_port *ch = tty->driver_data;
588 int len, port; 1235 int len;
589 unsigned long flags;
590 1236
591 ch = (struct moxa_port *) tty->driver_data;
592 if (ch == NULL) 1237 if (ch == NULL)
593 return (0); 1238 return 0;
594 port = ch->port;
595 1239
596 spin_lock_irqsave(&moxa_lock, flags); 1240 spin_lock_bh(&moxa_lock);
597 len = MoxaPortWriteData(port, (unsigned char *) buf, count); 1241 len = MoxaPortWriteData(ch, buf, count);
598 spin_unlock_irqrestore(&moxa_lock, flags); 1242 spin_unlock_bh(&moxa_lock);
599 1243
600 /*********************************************
601 if ( !(ch->statusflags & LOWWAIT) &&
602 ((len != count) || (MoxaPortTxFree(port) <= 100)) )
603 ************************************************/
604 ch->statusflags |= LOWWAIT; 1244 ch->statusflags |= LOWWAIT;
605 return (len); 1245 return len;
606} 1246}
607 1247
608static int moxa_write_room(struct tty_struct *tty) 1248static int moxa_write_room(struct tty_struct *tty)
@@ -610,27 +1250,27 @@ static int moxa_write_room(struct tty_struct *tty)
610 struct moxa_port *ch; 1250 struct moxa_port *ch;
611 1251
612 if (tty->stopped) 1252 if (tty->stopped)
613 return (0); 1253 return 0;
614 ch = (struct moxa_port *) tty->driver_data; 1254 ch = tty->driver_data;
615 if (ch == NULL) 1255 if (ch == NULL)
616 return (0); 1256 return 0;
617 return (MoxaPortTxFree(ch->port)); 1257 return MoxaPortTxFree(ch);
618} 1258}
619 1259
620static void moxa_flush_buffer(struct tty_struct *tty) 1260static void moxa_flush_buffer(struct tty_struct *tty)
621{ 1261{
622 struct moxa_port *ch = (struct moxa_port *) tty->driver_data; 1262 struct moxa_port *ch = tty->driver_data;
623 1263
624 if (ch == NULL) 1264 if (ch == NULL)
625 return; 1265 return;
626 MoxaPortFlushData(ch->port, 1); 1266 MoxaPortFlushData(ch, 1);
627 tty_wakeup(tty); 1267 tty_wakeup(tty);
628} 1268}
629 1269
630static int moxa_chars_in_buffer(struct tty_struct *tty) 1270static int moxa_chars_in_buffer(struct tty_struct *tty)
631{ 1271{
1272 struct moxa_port *ch = tty->driver_data;
632 int chars; 1273 int chars;
633 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
634 1274
635 /* 1275 /*
636 * Sigh...I have to check if driver_data is NULL here, because 1276 * Sigh...I have to check if driver_data is NULL here, because
@@ -639,8 +1279,9 @@ static int moxa_chars_in_buffer(struct tty_struct *tty)
639 * routine. And since the open() failed, we return 0 here. TDJ 1279 * routine. And since the open() failed, we return 0 here. TDJ
640 */ 1280 */
641 if (ch == NULL) 1281 if (ch == NULL)
642 return (0); 1282 return 0;
643 chars = MoxaPortTxQueue(ch->port); 1283 lock_kernel();
1284 chars = MoxaPortTxQueue(ch);
644 if (chars) { 1285 if (chars) {
645 /* 1286 /*
646 * Make it possible to wakeup anything waiting for output 1287 * Make it possible to wakeup anything waiting for output
@@ -649,73 +1290,54 @@ static int moxa_chars_in_buffer(struct tty_struct *tty)
649 if (!(ch->statusflags & EMPTYWAIT)) 1290 if (!(ch->statusflags & EMPTYWAIT))
650 moxa_setup_empty_event(tty); 1291 moxa_setup_empty_event(tty);
651 } 1292 }
652 return (chars); 1293 unlock_kernel();
653} 1294 return chars;
654
655static void moxa_flush_chars(struct tty_struct *tty)
656{
657 /*
658 * Don't think I need this, because this is called to empty the TX
659 * buffer for the 16450, 16550, etc.
660 */
661}
662
663static void moxa_put_char(struct tty_struct *tty, unsigned char c)
664{
665 struct moxa_port *ch;
666 int port;
667 unsigned long flags;
668
669 ch = (struct moxa_port *) tty->driver_data;
670 if (ch == NULL)
671 return;
672 port = ch->port;
673 spin_lock_irqsave(&moxa_lock, flags);
674 MoxaPortWriteData(port, &c, 1);
675 spin_unlock_irqrestore(&moxa_lock, flags);
676 /************************************************
677 if ( !(ch->statusflags & LOWWAIT) && (MoxaPortTxFree(port) <= 100) )
678 *************************************************/
679 ch->statusflags |= LOWWAIT;
680} 1295}
681 1296
682static int moxa_tiocmget(struct tty_struct *tty, struct file *file) 1297static int moxa_tiocmget(struct tty_struct *tty, struct file *file)
683{ 1298{
684 struct moxa_port *ch = (struct moxa_port *) tty->driver_data; 1299 struct moxa_port *ch;
685 int port;
686 int flag = 0, dtr, rts; 1300 int flag = 0, dtr, rts;
687 1301
688 port = tty->index; 1302 mutex_lock(&moxa_openlock);
689 if ((port != MAX_PORTS) && (!ch)) 1303 ch = tty->driver_data;
690 return (-EINVAL); 1304 if (!ch) {
1305 mutex_unlock(&moxa_openlock);
1306 return -EINVAL;
1307 }
691 1308
692 MoxaPortGetLineOut(ch->port, &dtr, &rts); 1309 MoxaPortGetLineOut(ch, &dtr, &rts);
693 if (dtr) 1310 if (dtr)
694 flag |= TIOCM_DTR; 1311 flag |= TIOCM_DTR;
695 if (rts) 1312 if (rts)
696 flag |= TIOCM_RTS; 1313 flag |= TIOCM_RTS;
697 dtr = MoxaPortLineStatus(ch->port); 1314 dtr = MoxaPortLineStatus(ch);
698 if (dtr & 1) 1315 if (dtr & 1)
699 flag |= TIOCM_CTS; 1316 flag |= TIOCM_CTS;
700 if (dtr & 2) 1317 if (dtr & 2)
701 flag |= TIOCM_DSR; 1318 flag |= TIOCM_DSR;
702 if (dtr & 4) 1319 if (dtr & 4)
703 flag |= TIOCM_CD; 1320 flag |= TIOCM_CD;
1321 mutex_unlock(&moxa_openlock);
704 return flag; 1322 return flag;
705} 1323}
706 1324
707static int moxa_tiocmset(struct tty_struct *tty, struct file *file, 1325static int moxa_tiocmset(struct tty_struct *tty, struct file *file,
708 unsigned int set, unsigned int clear) 1326 unsigned int set, unsigned int clear)
709{ 1327{
710 struct moxa_port *ch = (struct moxa_port *) tty->driver_data; 1328 struct moxa_port *ch;
711 int port; 1329 int port;
712 int dtr, rts; 1330 int dtr, rts;
713 1331
714 port = tty->index; 1332 port = tty->index;
715 if ((port != MAX_PORTS) && (!ch)) 1333 mutex_lock(&moxa_openlock);
716 return (-EINVAL); 1334 ch = tty->driver_data;
1335 if (!ch) {
1336 mutex_unlock(&moxa_openlock);
1337 return -EINVAL;
1338 }
717 1339
718 MoxaPortGetLineOut(ch->port, &dtr, &rts); 1340 MoxaPortGetLineOut(ch, &dtr, &rts);
719 if (set & TIOCM_RTS) 1341 if (set & TIOCM_RTS)
720 rts = 1; 1342 rts = 1;
721 if (set & TIOCM_DTR) 1343 if (set & TIOCM_DTR)
@@ -724,105 +1346,51 @@ static int moxa_tiocmset(struct tty_struct *tty, struct file *file,
724 rts = 0; 1346 rts = 0;
725 if (clear & TIOCM_DTR) 1347 if (clear & TIOCM_DTR)
726 dtr = 0; 1348 dtr = 0;
727 MoxaPortLineCtrl(ch->port, dtr, rts); 1349 MoxaPortLineCtrl(ch, dtr, rts);
1350 mutex_unlock(&moxa_openlock);
728 return 0; 1351 return 0;
729} 1352}
730 1353
731static int moxa_ioctl(struct tty_struct *tty, struct file *file,
732 unsigned int cmd, unsigned long arg)
733{
734 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
735 register int port;
736 void __user *argp = (void __user *)arg;
737 int retval;
738
739 port = tty->index;
740 if ((port != MAX_PORTS) && (!ch))
741 return (-EINVAL);
742
743 switch (cmd) {
744 case TCSBRK: /* SVID version: non-zero arg --> no break */
745 retval = tty_check_change(tty);
746 if (retval)
747 return (retval);
748 moxa_setup_empty_event(tty);
749 tty_wait_until_sent(tty, 0);
750 if (!arg)
751 MoxaPortSendBreak(ch->port, 0);
752 return (0);
753 case TCSBRKP: /* support for POSIX tcsendbreak() */
754 retval = tty_check_change(tty);
755 if (retval)
756 return (retval);
757 moxa_setup_empty_event(tty);
758 tty_wait_until_sent(tty, 0);
759 MoxaPortSendBreak(ch->port, arg);
760 return (0);
761 case TIOCGSOFTCAR:
762 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *) argp);
763 case TIOCSSOFTCAR:
764 if(get_user(retval, (unsigned long __user *) argp))
765 return -EFAULT;
766 arg = retval;
767 tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL) |
768 (arg ? CLOCAL : 0));
769 if (C_CLOCAL(tty))
770 ch->asyncflags &= ~ASYNC_CHECK_CD;
771 else
772 ch->asyncflags |= ASYNC_CHECK_CD;
773 return (0);
774 case TIOCGSERIAL:
775 return moxa_get_serial_info(ch, argp);
776
777 case TIOCSSERIAL:
778 return moxa_set_serial_info(ch, argp);
779 default:
780 retval = MoxaDriverIoctl(cmd, arg, port);
781 }
782 return (retval);
783}
784
785static void moxa_throttle(struct tty_struct *tty) 1354static void moxa_throttle(struct tty_struct *tty)
786{ 1355{
787 struct moxa_port *ch = (struct moxa_port *) tty->driver_data; 1356 struct moxa_port *ch = tty->driver_data;
788 1357
789 ch->statusflags |= THROTTLE; 1358 ch->statusflags |= THROTTLE;
790} 1359}
791 1360
792static void moxa_unthrottle(struct tty_struct *tty) 1361static void moxa_unthrottle(struct tty_struct *tty)
793{ 1362{
794 struct moxa_port *ch = (struct moxa_port *) tty->driver_data; 1363 struct moxa_port *ch = tty->driver_data;
795 1364
796 ch->statusflags &= ~THROTTLE; 1365 ch->statusflags &= ~THROTTLE;
797} 1366}
798 1367
799static void moxa_set_termios(struct tty_struct *tty, 1368static void moxa_set_termios(struct tty_struct *tty,
800 struct ktermios *old_termios) 1369 struct ktermios *old_termios)
801{ 1370{
802 struct moxa_port *ch = (struct moxa_port *) tty->driver_data; 1371 struct moxa_port *ch = tty->driver_data;
803 1372
804 if (ch == NULL) 1373 if (ch == NULL)
805 return; 1374 return;
806 moxa_set_tty_param(tty, old_termios); 1375 moxa_set_tty_param(tty, old_termios);
807 if (!(old_termios->c_cflag & CLOCAL) && 1376 if (!(old_termios->c_cflag & CLOCAL) && C_CLOCAL(tty))
808 (tty->termios->c_cflag & CLOCAL))
809 wake_up_interruptible(&ch->open_wait); 1377 wake_up_interruptible(&ch->open_wait);
810} 1378}
811 1379
812static void moxa_stop(struct tty_struct *tty) 1380static void moxa_stop(struct tty_struct *tty)
813{ 1381{
814 struct moxa_port *ch = (struct moxa_port *) tty->driver_data; 1382 struct moxa_port *ch = tty->driver_data;
815 1383
816 if (ch == NULL) 1384 if (ch == NULL)
817 return; 1385 return;
818 MoxaPortTxDisable(ch->port); 1386 MoxaPortTxDisable(ch);
819 ch->statusflags |= TXSTOPPED; 1387 ch->statusflags |= TXSTOPPED;
820} 1388}
821 1389
822 1390
823static void moxa_start(struct tty_struct *tty) 1391static void moxa_start(struct tty_struct *tty)
824{ 1392{
825 struct moxa_port *ch = (struct moxa_port *) tty->driver_data; 1393 struct moxa_port *ch = tty->driver_data;
826 1394
827 if (ch == NULL) 1395 if (ch == NULL)
828 return; 1396 return;
@@ -830,91 +1398,143 @@ static void moxa_start(struct tty_struct *tty)
830 if (!(ch->statusflags & TXSTOPPED)) 1398 if (!(ch->statusflags & TXSTOPPED))
831 return; 1399 return;
832 1400
833 MoxaPortTxEnable(ch->port); 1401 MoxaPortTxEnable(ch);
834 ch->statusflags &= ~TXSTOPPED; 1402 ch->statusflags &= ~TXSTOPPED;
835} 1403}
836 1404
837static void moxa_hangup(struct tty_struct *tty) 1405static void moxa_hangup(struct tty_struct *tty)
838{ 1406{
839 struct moxa_port *ch = (struct moxa_port *) tty->driver_data; 1407 struct moxa_port *ch;
840 1408
841 moxa_flush_buffer(tty); 1409 mutex_lock(&moxa_openlock);
842 moxa_shut_down(ch); 1410 ch = tty->driver_data;
843 ch->event = 0; 1411 if (ch == NULL) {
1412 mutex_unlock(&moxa_openlock);
1413 return;
1414 }
844 ch->count = 0; 1415 ch->count = 0;
845 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE; 1416 moxa_close_port(ch);
846 ch->tty = NULL; 1417 mutex_unlock(&moxa_openlock);
1418
847 wake_up_interruptible(&ch->open_wait); 1419 wake_up_interruptible(&ch->open_wait);
848} 1420}
849 1421
850static void moxa_poll(unsigned long ignored) 1422static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd)
851{ 1423{
852 register int card; 1424 dcd = !!dcd;
853 struct moxa_port *ch;
854 struct tty_struct *tp;
855 int i, ports;
856 1425
857 del_timer(&moxaTimer); 1426 if (dcd != p->DCDState && p->tty && C_CLOCAL(p->tty)) {
1427 if (!dcd)
1428 tty_hangup(p->tty);
1429 }
1430 p->DCDState = dcd;
1431}
858 1432
859 if (MoxaDriverPoll() < 0) { 1433static int moxa_poll_port(struct moxa_port *p, unsigned int handle,
860 mod_timer(&moxaTimer, jiffies + HZ / 50); 1434 u16 __iomem *ip)
861 return; 1435{
1436 struct tty_struct *tty = p->tty;
1437 void __iomem *ofsAddr;
1438 unsigned int inited = p->asyncflags & ASYNC_INITIALIZED;
1439 u16 intr;
1440
1441 if (tty) {
1442 if ((p->statusflags & EMPTYWAIT) &&
1443 MoxaPortTxQueue(p) == 0) {
1444 p->statusflags &= ~EMPTYWAIT;
1445 tty_wakeup(tty);
1446 }
1447 if ((p->statusflags & LOWWAIT) && !tty->stopped &&
1448 MoxaPortTxQueue(p) <= WAKEUP_CHARS) {
1449 p->statusflags &= ~LOWWAIT;
1450 tty_wakeup(tty);
1451 }
1452
1453 if (inited && !(p->statusflags & THROTTLE) &&
1454 MoxaPortRxQueue(p) > 0) { /* RX */
1455 MoxaPortReadData(p);
1456 tty_schedule_flip(tty);
1457 }
1458 } else {
1459 p->statusflags &= ~EMPTYWAIT;
1460 MoxaPortFlushData(p, 0); /* flush RX */
862 } 1461 }
1462
1463 if (!handle) /* nothing else to do */
1464 return 0;
1465
1466 intr = readw(ip); /* port irq status */
1467 if (intr == 0)
1468 return 0;
1469
1470 writew(0, ip); /* ACK port */
1471 ofsAddr = p->tableAddr;
1472 if (intr & IntrTx) /* disable tx intr */
1473 writew(readw(ofsAddr + HostStat) & ~WakeupTx,
1474 ofsAddr + HostStat);
1475
1476 if (!inited)
1477 return 0;
1478
1479 if (tty && (intr & IntrBreak) && !I_IGNBRK(tty)) { /* BREAK */
1480 tty_insert_flip_char(tty, 0, TTY_BREAK);
1481 tty_schedule_flip(tty);
1482 }
1483
1484 if (intr & IntrLine)
1485 moxa_new_dcdstate(p, readb(ofsAddr + FlagStat) & DCD_state);
1486
1487 return 0;
1488}
1489
1490static void moxa_poll(unsigned long ignored)
1491{
1492 struct moxa_board_conf *brd;
1493 u16 __iomem *ip;
1494 unsigned int card, port, served = 0;
1495
1496 spin_lock(&moxa_lock);
863 for (card = 0; card < MAX_BOARDS; card++) { 1497 for (card = 0; card < MAX_BOARDS; card++) {
864 if ((ports = MoxaPortsOfCard(card)) <= 0) 1498 brd = &moxa_boards[card];
1499 if (!brd->ready)
865 continue; 1500 continue;
866 ch = &moxa_ports[card * MAX_PORTS_PER_BOARD]; 1501
867 for (i = 0; i < ports; i++, ch++) { 1502 served++;
868 if ((ch->asyncflags & ASYNC_INITIALIZED) == 0) 1503
869 continue; 1504 ip = NULL;
870 if (!(ch->statusflags & THROTTLE) && 1505 if (readb(brd->intPend) == 0xff)
871 (MoxaPortRxQueue(ch->port) > 0)) 1506 ip = brd->intTable + readb(brd->intNdx);
872 moxa_receive_data(ch); 1507
873 if ((tp = ch->tty) == 0) 1508 for (port = 0; port < brd->numPorts; port++)
874 continue; 1509 moxa_poll_port(&brd->ports[port], !!ip, ip + port);
875 if (ch->statusflags & LOWWAIT) { 1510
876 if (MoxaPortTxQueue(ch->port) <= WAKEUP_CHARS) { 1511 if (ip)
877 if (!tp->stopped) { 1512 writeb(0, brd->intPend); /* ACK */
878 ch->statusflags &= ~LOWWAIT; 1513
879 tty_wakeup(tp); 1514 if (moxaLowWaterChk) {
880 } 1515 struct moxa_port *p = brd->ports;
881 } 1516 for (port = 0; port < brd->numPorts; port++, p++)
882 } 1517 if (p->lowChkFlag) {
883 if (!I_IGNBRK(tp) && (MoxaPortResetBrkCnt(ch->port) > 0)) { 1518 p->lowChkFlag = 0;
884 tty_insert_flip_char(tp, 0, TTY_BREAK); 1519 moxa_low_water_check(p->tableAddr);
885 tty_schedule_flip(tp);
886 }
887 if (MoxaPortDCDChange(ch->port)) {
888 if (ch->asyncflags & ASYNC_CHECK_CD) {
889 if (MoxaPortDCDON(ch->port))
890 wake_up_interruptible(&ch->open_wait);
891 else {
892 tty_hangup(tp);
893 wake_up_interruptible(&ch->open_wait);
894 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
895 }
896 } 1520 }
897 }
898 } 1521 }
899 } 1522 }
1523 moxaLowWaterChk = 0;
900 1524
901 mod_timer(&moxaTimer, jiffies + HZ / 50); 1525 if (served)
1526 mod_timer(&moxaTimer, jiffies + HZ / 50);
1527 spin_unlock(&moxa_lock);
902} 1528}
903 1529
904/******************************************************************************/ 1530/******************************************************************************/
905 1531
906static void moxa_set_tty_param(struct tty_struct *tty, struct ktermios *old_termios) 1532static void moxa_set_tty_param(struct tty_struct *tty, struct ktermios *old_termios)
907{ 1533{
908 register struct ktermios *ts; 1534 register struct ktermios *ts = tty->termios;
909 struct moxa_port *ch; 1535 struct moxa_port *ch = tty->driver_data;
910 int rts, cts, txflow, rxflow, xany, baud; 1536 int rts, cts, txflow, rxflow, xany, baud;
911 1537
912 ch = (struct moxa_port *) tty->driver_data;
913 ts = tty->termios;
914 if (ts->c_cflag & CLOCAL)
915 ch->asyncflags &= ~ASYNC_CHECK_CD;
916 else
917 ch->asyncflags |= ASYNC_CHECK_CD;
918 rts = cts = txflow = rxflow = xany = 0; 1538 rts = cts = txflow = rxflow = xany = 0;
919 if (ts->c_cflag & CRTSCTS) 1539 if (ts->c_cflag & CRTSCTS)
920 rts = cts = 1; 1540 rts = cts = 1;
@@ -927,776 +1547,60 @@ static void moxa_set_tty_param(struct tty_struct *tty, struct ktermios *old_term
927 1547
928 /* Clear the features we don't support */ 1548 /* Clear the features we don't support */
929 ts->c_cflag &= ~CMSPAR; 1549 ts->c_cflag &= ~CMSPAR;
930 MoxaPortFlowCtrl(ch->port, rts, cts, txflow, rxflow, xany); 1550 MoxaPortFlowCtrl(ch, rts, cts, txflow, rxflow, xany);
931 baud = MoxaPortSetTermio(ch->port, ts, tty_get_baud_rate(tty)); 1551 baud = MoxaPortSetTermio(ch, ts, tty_get_baud_rate(tty));
932 if (baud == -1) 1552 if (baud == -1)
933 baud = tty_termios_baud_rate(old_termios); 1553 baud = tty_termios_baud_rate(old_termios);
934 /* Not put the baud rate into the termios data */ 1554 /* Not put the baud rate into the termios data */
935 tty_encode_baud_rate(tty, baud, baud); 1555 tty_encode_baud_rate(tty, baud, baud);
936} 1556}
937 1557
938static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp,
939 struct moxa_port *ch)
940{
941 DECLARE_WAITQUEUE(wait,current);
942 unsigned long flags;
943 int retval;
944 int do_clocal = C_CLOCAL(tty);
945
946 /*
947 * If the device is in the middle of being closed, then block
948 * until it's done, and then try again.
949 */
950 if (tty_hung_up_p(filp) || (ch->asyncflags & ASYNC_CLOSING)) {
951 if (ch->asyncflags & ASYNC_CLOSING)
952 wait_for_completion_interruptible(&ch->close_wait);
953#ifdef SERIAL_DO_RESTART
954 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
955 return (-EAGAIN);
956 else
957 return (-ERESTARTSYS);
958#else
959 return (-EAGAIN);
960#endif
961 }
962 /*
963 * If non-blocking mode is set, then make the check up front
964 * and then exit.
965 */
966 if (filp->f_flags & O_NONBLOCK) {
967 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
968 return (0);
969 }
970 /*
971 * Block waiting for the carrier detect and the line to become free
972 */
973 retval = 0;
974 add_wait_queue(&ch->open_wait, &wait);
975 pr_debug("block_til_ready before block: ttys%d, count = %d\n",
976 ch->port, ch->count);
977 spin_lock_irqsave(&moxa_lock, flags);
978 if (!tty_hung_up_p(filp))
979 ch->count--;
980 ch->blocked_open++;
981 spin_unlock_irqrestore(&moxa_lock, flags);
982
983 while (1) {
984 set_current_state(TASK_INTERRUPTIBLE);
985 if (tty_hung_up_p(filp) ||
986 !(ch->asyncflags & ASYNC_INITIALIZED)) {
987#ifdef SERIAL_DO_RESTART
988 if (ch->asyncflags & ASYNC_HUP_NOTIFY)
989 retval = -EAGAIN;
990 else
991 retval = -ERESTARTSYS;
992#else
993 retval = -EAGAIN;
994#endif
995 break;
996 }
997 if (!(ch->asyncflags & ASYNC_CLOSING) && (do_clocal ||
998 MoxaPortDCDON(ch->port)))
999 break;
1000
1001 if (signal_pending(current)) {
1002 retval = -ERESTARTSYS;
1003 break;
1004 }
1005 schedule();
1006 }
1007 set_current_state(TASK_RUNNING);
1008 remove_wait_queue(&ch->open_wait, &wait);
1009
1010 spin_lock_irqsave(&moxa_lock, flags);
1011 if (!tty_hung_up_p(filp))
1012 ch->count++;
1013 ch->blocked_open--;
1014 spin_unlock_irqrestore(&moxa_lock, flags);
1015 pr_debug("block_til_ready after blocking: ttys%d, count = %d\n",
1016 ch->port, ch->count);
1017 if (retval)
1018 return (retval);
1019 /* FIXME: review to see if we need to use set_bit on these */
1020 ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1021 return 0;
1022}
1023
1024static void moxa_setup_empty_event(struct tty_struct *tty) 1558static void moxa_setup_empty_event(struct tty_struct *tty)
1025{ 1559{
1026 struct moxa_port *ch = tty->driver_data; 1560 struct moxa_port *ch = tty->driver_data;
1027 unsigned long flags;
1028 1561
1029 spin_lock_irqsave(&moxa_lock, flags); 1562 spin_lock_bh(&moxa_lock);
1030 ch->statusflags |= EMPTYWAIT; 1563 ch->statusflags |= EMPTYWAIT;
1031 mod_timer(&moxa_ports[ch->port].emptyTimer, jiffies + HZ); 1564 spin_unlock_bh(&moxa_lock);
1032 spin_unlock_irqrestore(&moxa_lock, flags);
1033}
1034
1035static void moxa_check_xmit_empty(unsigned long data)
1036{
1037 struct moxa_port *ch;
1038
1039 ch = (struct moxa_port *) data;
1040 if (ch->tty && (ch->statusflags & EMPTYWAIT)) {
1041 if (MoxaPortTxQueue(ch->port) == 0) {
1042 ch->statusflags &= ~EMPTYWAIT;
1043 tty_wakeup(ch->tty);
1044 return;
1045 }
1046 mod_timer(&moxa_ports[ch->port].emptyTimer,
1047 round_jiffies(jiffies + HZ));
1048 } else
1049 ch->statusflags &= ~EMPTYWAIT;
1050} 1565}
1051 1566
1052static void moxa_shut_down(struct moxa_port *ch) 1567static void moxa_shut_down(struct moxa_port *ch)
1053{ 1568{
1054 struct tty_struct *tp; 1569 struct tty_struct *tp = ch->tty;
1055 1570
1056 if (!(ch->asyncflags & ASYNC_INITIALIZED)) 1571 if (!(ch->asyncflags & ASYNC_INITIALIZED))
1057 return; 1572 return;
1058 1573
1059 tp = ch->tty; 1574 MoxaPortDisable(ch);
1060
1061 MoxaPortDisable(ch->port);
1062 1575
1063 /* 1576 /*
1064 * If we're a modem control device and HUPCL is on, drop RTS & DTR. 1577 * If we're a modem control device and HUPCL is on, drop RTS & DTR.
1065 */ 1578 */
1066 if (tp->termios->c_cflag & HUPCL) 1579 if (C_HUPCL(tp))
1067 MoxaPortLineCtrl(ch->port, 0, 0); 1580 MoxaPortLineCtrl(ch, 0, 0);
1068 1581
1582 spin_lock_bh(&moxa_lock);
1069 ch->asyncflags &= ~ASYNC_INITIALIZED; 1583 ch->asyncflags &= ~ASYNC_INITIALIZED;
1584 spin_unlock_bh(&moxa_lock);
1070} 1585}
1071 1586
1072static void moxa_receive_data(struct moxa_port *ch)
1073{
1074 struct tty_struct *tp;
1075 struct ktermios *ts;
1076 unsigned long flags;
1077
1078 ts = NULL;
1079 tp = ch->tty;
1080 if (tp)
1081 ts = tp->termios;
1082 /**************************************************
1083 if ( !tp || !ts || !(ts->c_cflag & CREAD) ) {
1084 *****************************************************/
1085 if (!tp || !ts) {
1086 MoxaPortFlushData(ch->port, 0);
1087 return;
1088 }
1089 spin_lock_irqsave(&moxa_lock, flags);
1090 MoxaPortReadData(ch->port, tp);
1091 spin_unlock_irqrestore(&moxa_lock, flags);
1092 tty_schedule_flip(tp);
1093}
1094
1095#define Magic_code 0x404
1096
1097/*
1098 * System Configuration
1099 */
1100/*
1101 * for C218 BIOS initialization
1102 */
1103#define C218_ConfBase 0x800
1104#define C218_status (C218_ConfBase + 0) /* BIOS running status */
1105#define C218_diag (C218_ConfBase + 2) /* diagnostic status */
1106#define C218_key (C218_ConfBase + 4) /* WORD (0x218 for C218) */
1107#define C218DLoad_len (C218_ConfBase + 6) /* WORD */
1108#define C218check_sum (C218_ConfBase + 8) /* BYTE */
1109#define C218chksum_ok (C218_ConfBase + 0x0a) /* BYTE (1:ok) */
1110#define C218_TestRx (C218_ConfBase + 0x10) /* 8 bytes for 8 ports */
1111#define C218_TestTx (C218_ConfBase + 0x18) /* 8 bytes for 8 ports */
1112#define C218_RXerr (C218_ConfBase + 0x20) /* 8 bytes for 8 ports */
1113#define C218_ErrFlag (C218_ConfBase + 0x28) /* 8 bytes for 8 ports */
1114
1115#define C218_LoadBuf 0x0F00
1116#define C218_KeyCode 0x218
1117#define CP204J_KeyCode 0x204
1118
1119/*
1120 * for C320 BIOS initialization
1121 */
1122#define C320_ConfBase 0x800
1123#define C320_LoadBuf 0x0f00
1124#define STS_init 0x05 /* for C320_status */
1125
1126#define C320_status C320_ConfBase + 0 /* BIOS running status */
1127#define C320_diag C320_ConfBase + 2 /* diagnostic status */
1128#define C320_key C320_ConfBase + 4 /* WORD (0320H for C320) */
1129#define C320DLoad_len C320_ConfBase + 6 /* WORD */
1130#define C320check_sum C320_ConfBase + 8 /* WORD */
1131#define C320chksum_ok C320_ConfBase + 0x0a /* WORD (1:ok) */
1132#define C320bapi_len C320_ConfBase + 0x0c /* WORD */
1133#define C320UART_no C320_ConfBase + 0x0e /* WORD */
1134
1135#define C320_KeyCode 0x320
1136
1137#define FixPage_addr 0x0000 /* starting addr of static page */
1138#define DynPage_addr 0x2000 /* starting addr of dynamic page */
1139#define C218_start 0x3000 /* starting addr of C218 BIOS prg */
1140#define Control_reg 0x1ff0 /* select page and reset control */
1141#define HW_reset 0x80
1142
1143/*
1144 * Function Codes
1145 */
1146#define FC_CardReset 0x80
1147#define FC_ChannelReset 1 /* C320 firmware not supported */
1148#define FC_EnableCH 2
1149#define FC_DisableCH 3
1150#define FC_SetParam 4
1151#define FC_SetMode 5
1152#define FC_SetRate 6
1153#define FC_LineControl 7
1154#define FC_LineStatus 8
1155#define FC_XmitControl 9
1156#define FC_FlushQueue 10
1157#define FC_SendBreak 11
1158#define FC_StopBreak 12
1159#define FC_LoopbackON 13
1160#define FC_LoopbackOFF 14
1161#define FC_ClrIrqTable 15
1162#define FC_SendXon 16
1163#define FC_SetTermIrq 17 /* C320 firmware not supported */
1164#define FC_SetCntIrq 18 /* C320 firmware not supported */
1165#define FC_SetBreakIrq 19
1166#define FC_SetLineIrq 20
1167#define FC_SetFlowCtl 21
1168#define FC_GenIrq 22
1169#define FC_InCD180 23
1170#define FC_OutCD180 24
1171#define FC_InUARTreg 23
1172#define FC_OutUARTreg 24
1173#define FC_SetXonXoff 25
1174#define FC_OutCD180CCR 26
1175#define FC_ExtIQueue 27
1176#define FC_ExtOQueue 28
1177#define FC_ClrLineIrq 29
1178#define FC_HWFlowCtl 30
1179#define FC_GetClockRate 35
1180#define FC_SetBaud 36
1181#define FC_SetDataMode 41
1182#define FC_GetCCSR 43
1183#define FC_GetDataError 45
1184#define FC_RxControl 50
1185#define FC_ImmSend 51
1186#define FC_SetXonState 52
1187#define FC_SetXoffState 53
1188#define FC_SetRxFIFOTrig 54
1189#define FC_SetTxFIFOCnt 55
1190#define FC_UnixRate 56
1191#define FC_UnixResetTimer 57
1192
1193#define RxFIFOTrig1 0
1194#define RxFIFOTrig4 1
1195#define RxFIFOTrig8 2
1196#define RxFIFOTrig14 3
1197
1198/*
1199 * Dual-Ported RAM
1200 */
1201#define DRAM_global 0
1202#define INT_data (DRAM_global + 0)
1203#define Config_base (DRAM_global + 0x108)
1204
1205#define IRQindex (INT_data + 0)
1206#define IRQpending (INT_data + 4)
1207#define IRQtable (INT_data + 8)
1208
1209/*
1210 * Interrupt Status
1211 */
1212#define IntrRx 0x01 /* receiver data O.K. */
1213#define IntrTx 0x02 /* transmit buffer empty */
1214#define IntrFunc 0x04 /* function complete */
1215#define IntrBreak 0x08 /* received break */
1216#define IntrLine 0x10 /* line status change
1217 for transmitter */
1218#define IntrIntr 0x20 /* received INTR code */
1219#define IntrQuit 0x40 /* received QUIT code */
1220#define IntrEOF 0x80 /* received EOF code */
1221
1222#define IntrRxTrigger 0x100 /* rx data count reach tigger value */
1223#define IntrTxTrigger 0x200 /* tx data count below trigger value */
1224
1225#define Magic_no (Config_base + 0)
1226#define Card_model_no (Config_base + 2)
1227#define Total_ports (Config_base + 4)
1228#define Module_cnt (Config_base + 8)
1229#define Module_no (Config_base + 10)
1230#define Timer_10ms (Config_base + 14)
1231#define Disable_IRQ (Config_base + 20)
1232#define TMS320_PORT1 (Config_base + 22)
1233#define TMS320_PORT2 (Config_base + 24)
1234#define TMS320_CLOCK (Config_base + 26)
1235
1236/*
1237 * DATA BUFFER in DRAM
1238 */
1239#define Extern_table 0x400 /* Base address of the external table
1240 (24 words * 64) total 3K bytes
1241 (24 words * 128) total 6K bytes */
1242#define Extern_size 0x60 /* 96 bytes */
1243#define RXrptr 0x00 /* read pointer for RX buffer */
1244#define RXwptr 0x02 /* write pointer for RX buffer */
1245#define TXrptr 0x04 /* read pointer for TX buffer */
1246#define TXwptr 0x06 /* write pointer for TX buffer */
1247#define HostStat 0x08 /* IRQ flag and general flag */
1248#define FlagStat 0x0A
1249#define FlowControl 0x0C /* B7 B6 B5 B4 B3 B2 B1 B0 */
1250 /* x x x x | | | | */
1251 /* | | | + CTS flow */
1252 /* | | +--- RTS flow */
1253 /* | +------ TX Xon/Xoff */
1254 /* +--------- RX Xon/Xoff */
1255#define Break_cnt 0x0E /* received break count */
1256#define CD180TXirq 0x10 /* if non-0: enable TX irq */
1257#define RX_mask 0x12
1258#define TX_mask 0x14
1259#define Ofs_rxb 0x16
1260#define Ofs_txb 0x18
1261#define Page_rxb 0x1A
1262#define Page_txb 0x1C
1263#define EndPage_rxb 0x1E
1264#define EndPage_txb 0x20
1265#define Data_error 0x22
1266#define RxTrigger 0x28
1267#define TxTrigger 0x2a
1268
1269#define rRXwptr 0x34
1270#define Low_water 0x36
1271
1272#define FuncCode 0x40
1273#define FuncArg 0x42
1274#define FuncArg1 0x44
1275
1276#define C218rx_size 0x2000 /* 8K bytes */
1277#define C218tx_size 0x8000 /* 32K bytes */
1278
1279#define C218rx_mask (C218rx_size - 1)
1280#define C218tx_mask (C218tx_size - 1)
1281
1282#define C320p8rx_size 0x2000
1283#define C320p8tx_size 0x8000
1284#define C320p8rx_mask (C320p8rx_size - 1)
1285#define C320p8tx_mask (C320p8tx_size - 1)
1286
1287#define C320p16rx_size 0x2000
1288#define C320p16tx_size 0x4000
1289#define C320p16rx_mask (C320p16rx_size - 1)
1290#define C320p16tx_mask (C320p16tx_size - 1)
1291
1292#define C320p24rx_size 0x2000
1293#define C320p24tx_size 0x2000
1294#define C320p24rx_mask (C320p24rx_size - 1)
1295#define C320p24tx_mask (C320p24tx_size - 1)
1296
1297#define C320p32rx_size 0x1000
1298#define C320p32tx_size 0x1000
1299#define C320p32rx_mask (C320p32rx_size - 1)
1300#define C320p32tx_mask (C320p32tx_size - 1)
1301
1302#define Page_size 0x2000
1303#define Page_mask (Page_size - 1)
1304#define C218rx_spage 3
1305#define C218tx_spage 4
1306#define C218rx_pageno 1
1307#define C218tx_pageno 4
1308#define C218buf_pageno 5
1309
1310#define C320p8rx_spage 3
1311#define C320p8tx_spage 4
1312#define C320p8rx_pgno 1
1313#define C320p8tx_pgno 4
1314#define C320p8buf_pgno 5
1315
1316#define C320p16rx_spage 3
1317#define C320p16tx_spage 4
1318#define C320p16rx_pgno 1
1319#define C320p16tx_pgno 2
1320#define C320p16buf_pgno 3
1321
1322#define C320p24rx_spage 3
1323#define C320p24tx_spage 4
1324#define C320p24rx_pgno 1
1325#define C320p24tx_pgno 1
1326#define C320p24buf_pgno 2
1327
1328#define C320p32rx_spage 3
1329#define C320p32tx_ofs C320p32rx_size
1330#define C320p32tx_spage 3
1331#define C320p32buf_pgno 1
1332
1333/*
1334 * Host Status
1335 */
1336#define WakeupRx 0x01
1337#define WakeupTx 0x02
1338#define WakeupBreak 0x08
1339#define WakeupLine 0x10
1340#define WakeupIntr 0x20
1341#define WakeupQuit 0x40
1342#define WakeupEOF 0x80 /* used in VTIME control */
1343#define WakeupRxTrigger 0x100
1344#define WakeupTxTrigger 0x200
1345/*
1346 * Flag status
1347 */
1348#define Rx_over 0x01
1349#define Xoff_state 0x02
1350#define Tx_flowOff 0x04
1351#define Tx_enable 0x08
1352#define CTS_state 0x10
1353#define DSR_state 0x20
1354#define DCD_state 0x80
1355/*
1356 * FlowControl
1357 */
1358#define CTS_FlowCtl 1
1359#define RTS_FlowCtl 2
1360#define Tx_FlowCtl 4
1361#define Rx_FlowCtl 8
1362#define IXM_IXANY 0x10
1363
1364#define LowWater 128
1365
1366#define DTR_ON 1
1367#define RTS_ON 2
1368#define CTS_ON 1
1369#define DSR_ON 2
1370#define DCD_ON 8
1371
1372/* mode definition */
1373#define MX_CS8 0x03
1374#define MX_CS7 0x02
1375#define MX_CS6 0x01
1376#define MX_CS5 0x00
1377
1378#define MX_STOP1 0x00
1379#define MX_STOP15 0x04
1380#define MX_STOP2 0x08
1381
1382#define MX_PARNONE 0x00
1383#define MX_PAREVEN 0x40
1384#define MX_PARODD 0xC0
1385
1386/*
1387 * Query
1388 */
1389
1390struct mon_str {
1391 int tick;
1392 int rxcnt[MAX_PORTS];
1393 int txcnt[MAX_PORTS];
1394};
1395
1396#define DCD_changed 0x01
1397#define DCD_oldstate 0x80
1398
1399static unsigned char moxaBuff[10240];
1400static int moxaLowWaterChk;
1401static int moxaCard;
1402static struct mon_str moxaLog;
1403static int moxaFuncTout = HZ / 2;
1404
1405static void moxafunc(void __iomem *, int, ushort);
1406static void moxa_wait_finish(void __iomem *);
1407static void moxa_low_water_check(void __iomem *);
1408static int moxaloadbios(int, unsigned char __user *, int);
1409static int moxafindcard(int);
1410static int moxaload320b(int, unsigned char __user *, int);
1411static int moxaloadcode(int, unsigned char __user *, int);
1412static int moxaloadc218(int, void __iomem *, int);
1413static int moxaloadc320(int, void __iomem *, int, int *);
1414
1415/***************************************************************************** 1587/*****************************************************************************
1416 * Driver level functions: * 1588 * Driver level functions: *
1417 * 1. MoxaDriverInit(void); *
1418 * 2. MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port); *
1419 * 3. MoxaDriverPoll(void); *
1420 *****************************************************************************/ 1589 *****************************************************************************/
1421void MoxaDriverInit(void)
1422{
1423 struct moxa_port *p;
1424 unsigned int i;
1425 1590
1426 moxaFuncTout = HZ / 2; /* 500 mini-seconds */ 1591static void MoxaPortFlushData(struct moxa_port *port, int mode)
1427 moxaCard = 0;
1428 moxaLog.tick = 0;
1429 moxaLowWaterChk = 0;
1430 for (i = 0; i < MAX_PORTS; i++) {
1431 p = &moxa_ports[i];
1432 p->chkPort = 0;
1433 p->lowChkFlag = 0;
1434 p->lineCtrl = 0;
1435 moxaLog.rxcnt[i] = 0;
1436 moxaLog.txcnt[i] = 0;
1437 }
1438}
1439
1440#define MOXA 0x400
1441#define MOXA_GET_IQUEUE (MOXA + 1) /* get input buffered count */
1442#define MOXA_GET_OQUEUE (MOXA + 2) /* get output buffered count */
1443#define MOXA_INIT_DRIVER (MOXA + 6) /* moxaCard=0 */
1444#define MOXA_LOAD_BIOS (MOXA + 9) /* download BIOS */
1445#define MOXA_FIND_BOARD (MOXA + 10) /* Check if MOXA card exist? */
1446#define MOXA_LOAD_C320B (MOXA + 11) /* download 320B firmware */
1447#define MOXA_LOAD_CODE (MOXA + 12) /* download firmware */
1448#define MOXA_GETDATACOUNT (MOXA + 23)
1449#define MOXA_GET_IOQUEUE (MOXA + 27)
1450#define MOXA_FLUSH_QUEUE (MOXA + 28)
1451#define MOXA_GET_CONF (MOXA + 35) /* configuration */
1452#define MOXA_GET_MAJOR (MOXA + 63)
1453#define MOXA_GET_CUMAJOR (MOXA + 64)
1454#define MOXA_GETMSTATUS (MOXA + 65)
1455
1456struct dl_str {
1457 char __user *buf;
1458 int len;
1459 int cardno;
1460};
1461
1462static struct dl_str dltmp;
1463
1464void MoxaPortFlushData(int port, int mode)
1465{ 1592{
1466 void __iomem *ofsAddr; 1593 void __iomem *ofsAddr;
1467 if ((mode < 0) || (mode > 2)) 1594 if (mode < 0 || mode > 2)
1468 return; 1595 return;
1469 ofsAddr = moxa_ports[port].tableAddr; 1596 ofsAddr = port->tableAddr;
1470 moxafunc(ofsAddr, FC_FlushQueue, mode); 1597 moxafunc(ofsAddr, FC_FlushQueue, mode);
1471 if (mode != 1) { 1598 if (mode != 1) {
1472 moxa_ports[port].lowChkFlag = 0; 1599 port->lowChkFlag = 0;
1473 moxa_low_water_check(ofsAddr); 1600 moxa_low_water_check(ofsAddr);
1474 } 1601 }
1475} 1602}
1476 1603
1477int MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port)
1478{
1479 int i;
1480 int status;
1481 int MoxaPortTxQueue(int), MoxaPortRxQueue(int);
1482 void __user *argp = (void __user *)arg;
1483
1484 if (port == MAX_PORTS) {
1485 if ((cmd != MOXA_GET_CONF) && (cmd != MOXA_INIT_DRIVER) &&
1486 (cmd != MOXA_LOAD_BIOS) && (cmd != MOXA_FIND_BOARD) && (cmd != MOXA_LOAD_C320B) &&
1487 (cmd != MOXA_LOAD_CODE) && (cmd != MOXA_GETDATACOUNT) &&
1488 (cmd != MOXA_GET_IOQUEUE) && (cmd != MOXA_GET_MAJOR) &&
1489 (cmd != MOXA_GET_CUMAJOR) && (cmd != MOXA_GETMSTATUS))
1490 return (-EINVAL);
1491 }
1492 switch (cmd) {
1493 case MOXA_GET_CONF:
1494 if(copy_to_user(argp, &moxa_boards, MAX_BOARDS *
1495 sizeof(struct moxa_board_conf)))
1496 return -EFAULT;
1497 return (0);
1498 case MOXA_INIT_DRIVER:
1499 if ((int) arg == 0x404)
1500 MoxaDriverInit();
1501 return (0);
1502 case MOXA_GETDATACOUNT:
1503 moxaLog.tick = jiffies;
1504 if(copy_to_user(argp, &moxaLog, sizeof(struct mon_str)))
1505 return -EFAULT;
1506 return (0);
1507 case MOXA_FLUSH_QUEUE:
1508 MoxaPortFlushData(port, arg);
1509 return (0);
1510 case MOXA_GET_IOQUEUE: {
1511 struct moxaq_str __user *argm = argp;
1512 struct moxaq_str tmp;
1513
1514 for (i = 0; i < MAX_PORTS; i++, argm++) {
1515 memset(&tmp, 0, sizeof(tmp));
1516 if (moxa_ports[i].chkPort) {
1517 tmp.inq = MoxaPortRxQueue(i);
1518 tmp.outq = MoxaPortTxQueue(i);
1519 }
1520 if (copy_to_user(argm, &tmp, sizeof(tmp)))
1521 return -EFAULT;
1522 }
1523 return (0);
1524 } case MOXA_GET_OQUEUE:
1525 i = MoxaPortTxQueue(port);
1526 return put_user(i, (unsigned long __user *)argp);
1527 case MOXA_GET_IQUEUE:
1528 i = MoxaPortRxQueue(port);
1529 return put_user(i, (unsigned long __user *)argp);
1530 case MOXA_GET_MAJOR:
1531 if(copy_to_user(argp, &ttymajor, sizeof(int)))
1532 return -EFAULT;
1533 return 0;
1534 case MOXA_GET_CUMAJOR:
1535 i = 0;
1536 if(copy_to_user(argp, &i, sizeof(int)))
1537 return -EFAULT;
1538 return 0;
1539 case MOXA_GETMSTATUS: {
1540 struct mxser_mstatus __user *argm = argp;
1541 struct mxser_mstatus tmp;
1542 struct moxa_port *p;
1543
1544 for (i = 0; i < MAX_PORTS; i++, argm++) {
1545 p = &moxa_ports[i];
1546 memset(&tmp, 0, sizeof(tmp));
1547 if (!p->chkPort) {
1548 goto copy;
1549 } else {
1550 status = MoxaPortLineStatus(p->port);
1551 if (status & 1)
1552 tmp.cts = 1;
1553 if (status & 2)
1554 tmp.dsr = 1;
1555 if (status & 4)
1556 tmp.dcd = 1;
1557 }
1558
1559 if (!p->tty || !p->tty->termios)
1560 tmp.cflag = p->cflag;
1561 else
1562 tmp.cflag = p->tty->termios->c_cflag;
1563copy:
1564 if (copy_to_user(argm, &tmp, sizeof(tmp)))
1565 return -EFAULT;
1566 }
1567 return 0;
1568 } default:
1569 return (-ENOIOCTLCMD);
1570 case MOXA_LOAD_BIOS:
1571 case MOXA_FIND_BOARD:
1572 case MOXA_LOAD_C320B:
1573 case MOXA_LOAD_CODE:
1574 if (!capable(CAP_SYS_RAWIO))
1575 return -EPERM;
1576 break;
1577 }
1578
1579 if(copy_from_user(&dltmp, argp, sizeof(struct dl_str)))
1580 return -EFAULT;
1581 if(dltmp.cardno < 0 || dltmp.cardno >= MAX_BOARDS || dltmp.len < 0)
1582 return -EINVAL;
1583
1584 switch(cmd)
1585 {
1586 case MOXA_LOAD_BIOS:
1587 i = moxaloadbios(dltmp.cardno, dltmp.buf, dltmp.len);
1588 return (i);
1589 case MOXA_FIND_BOARD:
1590 return moxafindcard(dltmp.cardno);
1591 case MOXA_LOAD_C320B:
1592 moxaload320b(dltmp.cardno, dltmp.buf, dltmp.len);
1593 default: /* to keep gcc happy */
1594 return (0);
1595 case MOXA_LOAD_CODE:
1596 i = moxaloadcode(dltmp.cardno, dltmp.buf, dltmp.len);
1597 if (i == -1)
1598 return (-EFAULT);
1599 return (i);
1600
1601 }
1602}
1603
1604int MoxaDriverPoll(void)
1605{
1606 struct moxa_board_conf *brd;
1607 register ushort temp;
1608 register int card;
1609 void __iomem *ofsAddr;
1610 void __iomem *ip;
1611 int port, p, ports;
1612
1613 if (moxaCard == 0)
1614 return (-1);
1615 for (card = 0; card < MAX_BOARDS; card++) {
1616 brd = &moxa_boards[card];
1617 if (brd->loadstat == 0)
1618 continue;
1619 if ((ports = brd->numPorts) == 0)
1620 continue;
1621 if (readb(brd->intPend) == 0xff) {
1622 ip = brd->intTable + readb(brd->intNdx);
1623 p = card * MAX_PORTS_PER_BOARD;
1624 ports <<= 1;
1625 for (port = 0; port < ports; port += 2, p++) {
1626 if ((temp = readw(ip + port)) != 0) {
1627 writew(0, ip + port);
1628 ofsAddr = moxa_ports[p].tableAddr;
1629 if (temp & IntrTx)
1630 writew(readw(ofsAddr + HostStat) & ~WakeupTx, ofsAddr + HostStat);
1631 if (temp & IntrBreak) {
1632 moxa_ports[p].breakCnt++;
1633 }
1634 if (temp & IntrLine) {
1635 if (readb(ofsAddr + FlagStat) & DCD_state) {
1636 if ((moxa_ports[p].DCDState & DCD_oldstate) == 0)
1637 moxa_ports[p].DCDState = (DCD_oldstate |
1638 DCD_changed);
1639 } else {
1640 if (moxa_ports[p].DCDState & DCD_oldstate)
1641 moxa_ports[p].DCDState = DCD_changed;
1642 }
1643 }
1644 }
1645 }
1646 writeb(0, brd->intPend);
1647 }
1648 if (moxaLowWaterChk) {
1649 p = card * MAX_PORTS_PER_BOARD;
1650 for (port = 0; port < ports; port++, p++) {
1651 if (moxa_ports[p].lowChkFlag) {
1652 moxa_ports[p].lowChkFlag = 0;
1653 ofsAddr = moxa_ports[p].tableAddr;
1654 moxa_low_water_check(ofsAddr);
1655 }
1656 }
1657 }
1658 }
1659 moxaLowWaterChk = 0;
1660 return (0);
1661}
1662
1663/*****************************************************************************
1664 * Card level function: *
1665 * 1. MoxaPortsOfCard(int cardno); *
1666 *****************************************************************************/
1667int MoxaPortsOfCard(int cardno)
1668{
1669
1670 if (moxa_boards[cardno].boardType == 0)
1671 return (0);
1672 return (moxa_boards[cardno].numPorts);
1673}
1674
1675/*****************************************************************************
1676 * Port level functions: *
1677 * 1. MoxaPortIsValid(int port); *
1678 * 2. MoxaPortEnable(int port); *
1679 * 3. MoxaPortDisable(int port); *
1680 * 4. MoxaPortGetMaxBaud(int port); *
1681 * 6. MoxaPortSetBaud(int port, long baud); *
1682 * 8. MoxaPortSetTermio(int port, unsigned char *termio); *
1683 * 9. MoxaPortGetLineOut(int port, int *dtrState, int *rtsState); *
1684 * 10. MoxaPortLineCtrl(int port, int dtrState, int rtsState); *
1685 * 11. MoxaPortFlowCtrl(int port, int rts, int cts, int rx, int tx,int xany); *
1686 * 12. MoxaPortLineStatus(int port); *
1687 * 13. MoxaPortDCDChange(int port); *
1688 * 14. MoxaPortDCDON(int port); *
1689 * 15. MoxaPortFlushData(int port, int mode); *
1690 * 16. MoxaPortWriteData(int port, unsigned char * buffer, int length); *
1691 * 17. MoxaPortReadData(int port, struct tty_struct *tty); *
1692 * 20. MoxaPortTxQueue(int port); *
1693 * 21. MoxaPortTxFree(int port); *
1694 * 22. MoxaPortRxQueue(int port); *
1695 * 24. MoxaPortTxDisable(int port); *
1696 * 25. MoxaPortTxEnable(int port); *
1697 * 27. MoxaPortResetBrkCnt(int port); *
1698 * 30. MoxaPortSendBreak(int port, int ticks); *
1699 *****************************************************************************/
1700/* 1604/*
1701 * Moxa Port Number Description: 1605 * Moxa Port Number Description:
1702 * 1606 *
@@ -1733,33 +1637,6 @@ int MoxaPortsOfCard(int cardno)
1733 * -ENOIOCTLCMD 1637 * -ENOIOCTLCMD
1734 * 1638 *
1735 * 1639 *
1736 * Function 3: Moxa driver polling process routine.
1737 * Syntax:
1738 * int MoxaDriverPoll(void);
1739 *
1740 * return: 0 ; polling O.K.
1741 * -1 : no any Moxa card.
1742 *
1743 *
1744 * Function 4: Get the ports of this card.
1745 * Syntax:
1746 * int MoxaPortsOfCard(int cardno);
1747 *
1748 * int cardno : card number (0 - 3)
1749 *
1750 * return: 0 : this card is invalid
1751 * 8/16/24/32
1752 *
1753 *
1754 * Function 5: Check this port is valid or invalid
1755 * Syntax:
1756 * int MoxaPortIsValid(int port);
1757 * int port : port number (0 - 127, ref port description)
1758 *
1759 * return: 0 : this port is invalid
1760 * 1 : this port is valid
1761 *
1762 *
1763 * Function 6: Enable this port to start Tx/Rx data. 1640 * Function 6: Enable this port to start Tx/Rx data.
1764 * Syntax: 1641 * Syntax:
1765 * void MoxaPortEnable(int port); 1642 * void MoxaPortEnable(int port);
@@ -1772,18 +1649,9 @@ int MoxaPortsOfCard(int cardno)
1772 * int port : port number (0 - 127) 1649 * int port : port number (0 - 127)
1773 * 1650 *
1774 * 1651 *
1775 * Function 8: Get the maximun available baud rate of this port.
1776 * Syntax:
1777 * long MoxaPortGetMaxBaud(int port);
1778 * int port : port number (0 - 127)
1779 *
1780 * return: 0 : this port is invalid
1781 * 38400/57600/115200 bps
1782 *
1783 *
1784 * Function 10: Setting baud rate of this port. 1652 * Function 10: Setting baud rate of this port.
1785 * Syntax: 1653 * Syntax:
1786 * long MoxaPortSetBaud(int port, long baud); 1654 * speed_t MoxaPortSetBaud(int port, speed_t baud);
1787 * int port : port number (0 - 127) 1655 * int port : port number (0 - 127)
1788 * long baud : baud rate (50 - 115200) 1656 * long baud : baud rate (50 - 115200)
1789 * 1657 *
@@ -1850,25 +1718,6 @@ int MoxaPortsOfCard(int cardno)
1850 * Bit 2 - DCD state (0: off, 1: on) 1718 * Bit 2 - DCD state (0: off, 1: on)
1851 * 1719 *
1852 * 1720 *
1853 * Function 17: Check the DCD state has changed since the last read
1854 * of this function.
1855 * Syntax:
1856 * int MoxaPortDCDChange(int port);
1857 * int port : port number (0 - 127)
1858 *
1859 * return: 0 : no changed
1860 * 1 : DCD has changed
1861 *
1862 *
1863 * Function 18: Check ths current DCD state is ON or not.
1864 * Syntax:
1865 * int MoxaPortDCDON(int port);
1866 * int port : port number (0 - 127)
1867 *
1868 * return: 0 : DCD off
1869 * 1 : DCD on
1870 *
1871 *
1872 * Function 19: Flush the Rx/Tx buffer data of this port. 1721 * Function 19: Flush the Rx/Tx buffer data of this port.
1873 * Syntax: 1722 * Syntax:
1874 * void MoxaPortFlushData(int port, int mode); 1723 * void MoxaPortFlushData(int port, int mode);
@@ -1942,40 +1791,20 @@ int MoxaPortsOfCard(int cardno)
1942 * return: 0 - .. : BREAK signal count 1791 * return: 0 - .. : BREAK signal count
1943 * 1792 *
1944 * 1793 *
1945 * Function 34: Send out a BREAK signal.
1946 * Syntax:
1947 * void MoxaPortSendBreak(int port, int ms100);
1948 * int port : port number (0 - 127)
1949 * int ms100 : break signal time interval.
1950 * unit: 100 mini-second. if ms100 == 0, it will
1951 * send out a about 250 ms BREAK signal.
1952 *
1953 */ 1794 */
1954int MoxaPortIsValid(int port)
1955{
1956
1957 if (moxaCard == 0)
1958 return (0);
1959 if (moxa_ports[port].chkPort == 0)
1960 return (0);
1961 return (1);
1962}
1963 1795
1964void MoxaPortEnable(int port) 1796static void MoxaPortEnable(struct moxa_port *port)
1965{ 1797{
1966 void __iomem *ofsAddr; 1798 void __iomem *ofsAddr;
1967 int MoxaPortLineStatus(int); 1799 u16 lowwater = 512;
1968 short lowwater = 512;
1969 1800
1970 ofsAddr = moxa_ports[port].tableAddr; 1801 ofsAddr = port->tableAddr;
1971 writew(lowwater, ofsAddr + Low_water); 1802 writew(lowwater, ofsAddr + Low_water);
1972 moxa_ports[port].breakCnt = 0; 1803 if (MOXA_IS_320(port->board))
1973 if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) ||
1974 (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) {
1975 moxafunc(ofsAddr, FC_SetBreakIrq, 0); 1804 moxafunc(ofsAddr, FC_SetBreakIrq, 0);
1976 } else { 1805 else
1977 writew(readw(ofsAddr + HostStat) | WakeupBreak, ofsAddr + HostStat); 1806 writew(readw(ofsAddr + HostStat) | WakeupBreak,
1978 } 1807 ofsAddr + HostStat);
1979 1808
1980 moxafunc(ofsAddr, FC_SetLineIrq, Magic_code); 1809 moxafunc(ofsAddr, FC_SetLineIrq, Magic_code);
1981 moxafunc(ofsAddr, FC_FlushQueue, 2); 1810 moxafunc(ofsAddr, FC_FlushQueue, 2);
@@ -1984,9 +1813,9 @@ void MoxaPortEnable(int port)
1984 MoxaPortLineStatus(port); 1813 MoxaPortLineStatus(port);
1985} 1814}
1986 1815
1987void MoxaPortDisable(int port) 1816static void MoxaPortDisable(struct moxa_port *port)
1988{ 1817{
1989 void __iomem *ofsAddr = moxa_ports[port].tableAddr; 1818 void __iomem *ofsAddr = port->tableAddr;
1990 1819
1991 moxafunc(ofsAddr, FC_SetFlowCtl, 0); /* disable flow control */ 1820 moxafunc(ofsAddr, FC_SetFlowCtl, 0); /* disable flow control */
1992 moxafunc(ofsAddr, FC_ClrLineIrq, Magic_code); 1821 moxafunc(ofsAddr, FC_ClrLineIrq, Magic_code);
@@ -1994,49 +1823,32 @@ void MoxaPortDisable(int port)
1994 moxafunc(ofsAddr, FC_DisableCH, Magic_code); 1823 moxafunc(ofsAddr, FC_DisableCH, Magic_code);
1995} 1824}
1996 1825
1997long MoxaPortGetMaxBaud(int port) 1826static speed_t MoxaPortSetBaud(struct moxa_port *port, speed_t baud)
1998{
1999 if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) ||
2000 (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI))
2001 return (460800L);
2002 else
2003 return (921600L);
2004}
2005
2006
2007long MoxaPortSetBaud(int port, long baud)
2008{ 1827{
2009 void __iomem *ofsAddr; 1828 void __iomem *ofsAddr = port->tableAddr;
2010 long max, clock; 1829 unsigned int clock, val;
2011 unsigned int val; 1830 speed_t max;
2012 1831
2013 if ((baud < 50L) || ((max = MoxaPortGetMaxBaud(port)) == 0)) 1832 max = MOXA_IS_320(port->board) ? 460800 : 921600;
2014 return (0); 1833 if (baud < 50)
2015 ofsAddr = moxa_ports[port].tableAddr; 1834 return 0;
2016 if (baud > max) 1835 if (baud > max)
2017 baud = max; 1836 baud = max;
2018 if (max == 38400L) 1837 clock = 921600;
2019 clock = 614400L; /* for 9.8304 Mhz : max. 38400 bps */
2020 else if (max == 57600L)
2021 clock = 691200L; /* for 11.0592 Mhz : max. 57600 bps */
2022 else
2023 clock = 921600L; /* for 14.7456 Mhz : max. 115200 bps */
2024 val = clock / baud; 1838 val = clock / baud;
2025 moxafunc(ofsAddr, FC_SetBaud, val); 1839 moxafunc(ofsAddr, FC_SetBaud, val);
2026 baud = clock / val; 1840 baud = clock / val;
2027 moxa_ports[port].curBaud = baud; 1841 return baud;
2028 return (baud);
2029} 1842}
2030 1843
2031int MoxaPortSetTermio(int port, struct ktermios *termio, speed_t baud) 1844static int MoxaPortSetTermio(struct moxa_port *port, struct ktermios *termio,
1845 speed_t baud)
2032{ 1846{
2033 void __iomem *ofsAddr; 1847 void __iomem *ofsAddr;
2034 tcflag_t cflag; 1848 tcflag_t cflag;
2035 tcflag_t mode = 0; 1849 tcflag_t mode = 0;
2036 1850
2037 if (moxa_ports[port].chkPort == 0 || termio == 0) 1851 ofsAddr = port->tableAddr;
2038 return (-1);
2039 ofsAddr = moxa_ports[port].tableAddr;
2040 cflag = termio->c_cflag; /* termio->c_cflag */ 1852 cflag = termio->c_cflag; /* termio->c_cflag */
2041 1853
2042 mode = termio->c_cflag & CSIZE; 1854 mode = termio->c_cflag & CSIZE;
@@ -2065,13 +1877,11 @@ int MoxaPortSetTermio(int port, struct ktermios *termio, speed_t baud)
2065 } else 1877 } else
2066 mode |= MX_PARNONE; 1878 mode |= MX_PARNONE;
2067 1879
2068 moxafunc(ofsAddr, FC_SetDataMode, (ushort) mode); 1880 moxafunc(ofsAddr, FC_SetDataMode, (u16)mode);
1881
1882 if (MOXA_IS_320(port->board) && baud >= 921600)
1883 return -1;
2069 1884
2070 if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) ||
2071 (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) {
2072 if (baud >= 921600L)
2073 return (-1);
2074 }
2075 baud = MoxaPortSetBaud(port, baud); 1885 baud = MoxaPortSetBaud(port, baud);
2076 1886
2077 if (termio->c_iflag & (IXON | IXOFF | IXANY)) { 1887 if (termio->c_iflag & (IXON | IXOFF | IXANY)) {
@@ -2081,51 +1891,37 @@ int MoxaPortSetTermio(int port, struct ktermios *termio, speed_t baud)
2081 moxa_wait_finish(ofsAddr); 1891 moxa_wait_finish(ofsAddr);
2082 1892
2083 } 1893 }
2084 return (baud); 1894 return baud;
2085} 1895}
2086 1896
2087int MoxaPortGetLineOut(int port, int *dtrState, int *rtsState) 1897static int MoxaPortGetLineOut(struct moxa_port *port, int *dtrState,
1898 int *rtsState)
2088{ 1899{
1900 if (dtrState)
1901 *dtrState = !!(port->lineCtrl & DTR_ON);
1902 if (rtsState)
1903 *rtsState = !!(port->lineCtrl & RTS_ON);
2089 1904
2090 if (!MoxaPortIsValid(port)) 1905 return 0;
2091 return (-1);
2092 if (dtrState) {
2093 if (moxa_ports[port].lineCtrl & DTR_ON)
2094 *dtrState = 1;
2095 else
2096 *dtrState = 0;
2097 }
2098 if (rtsState) {
2099 if (moxa_ports[port].lineCtrl & RTS_ON)
2100 *rtsState = 1;
2101 else
2102 *rtsState = 0;
2103 }
2104 return (0);
2105} 1906}
2106 1907
2107void MoxaPortLineCtrl(int port, int dtr, int rts) 1908static void MoxaPortLineCtrl(struct moxa_port *port, int dtr, int rts)
2108{ 1909{
2109 void __iomem *ofsAddr; 1910 u8 mode = 0;
2110 int mode;
2111 1911
2112 ofsAddr = moxa_ports[port].tableAddr;
2113 mode = 0;
2114 if (dtr) 1912 if (dtr)
2115 mode |= DTR_ON; 1913 mode |= DTR_ON;
2116 if (rts) 1914 if (rts)
2117 mode |= RTS_ON; 1915 mode |= RTS_ON;
2118 moxa_ports[port].lineCtrl = mode; 1916 port->lineCtrl = mode;
2119 moxafunc(ofsAddr, FC_LineControl, mode); 1917 moxafunc(port->tableAddr, FC_LineControl, mode);
2120} 1918}
2121 1919
2122void MoxaPortFlowCtrl(int port, int rts, int cts, int txflow, int rxflow, int txany) 1920static void MoxaPortFlowCtrl(struct moxa_port *port, int rts, int cts,
1921 int txflow, int rxflow, int txany)
2123{ 1922{
2124 void __iomem *ofsAddr; 1923 int mode = 0;
2125 int mode;
2126 1924
2127 ofsAddr = moxa_ports[port].tableAddr;
2128 mode = 0;
2129 if (rts) 1925 if (rts)
2130 mode |= RTS_FlowCtl; 1926 mode |= RTS_FlowCtl;
2131 if (cts) 1927 if (cts)
@@ -2136,81 +1932,50 @@ void MoxaPortFlowCtrl(int port, int rts, int cts, int txflow, int rxflow, int tx
2136 mode |= Rx_FlowCtl; 1932 mode |= Rx_FlowCtl;
2137 if (txany) 1933 if (txany)
2138 mode |= IXM_IXANY; 1934 mode |= IXM_IXANY;
2139 moxafunc(ofsAddr, FC_SetFlowCtl, mode); 1935 moxafunc(port->tableAddr, FC_SetFlowCtl, mode);
2140} 1936}
2141 1937
2142int MoxaPortLineStatus(int port) 1938static int MoxaPortLineStatus(struct moxa_port *port)
2143{ 1939{
2144 void __iomem *ofsAddr; 1940 void __iomem *ofsAddr;
2145 int val; 1941 int val;
2146 1942
2147 ofsAddr = moxa_ports[port].tableAddr; 1943 ofsAddr = port->tableAddr;
2148 if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) || 1944 if (MOXA_IS_320(port->board)) {
2149 (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) {
2150 moxafunc(ofsAddr, FC_LineStatus, 0); 1945 moxafunc(ofsAddr, FC_LineStatus, 0);
2151 val = readw(ofsAddr + FuncArg); 1946 val = readw(ofsAddr + FuncArg);
2152 } else { 1947 } else {
2153 val = readw(ofsAddr + FlagStat) >> 4; 1948 val = readw(ofsAddr + FlagStat) >> 4;
2154 } 1949 }
2155 val &= 0x0B; 1950 val &= 0x0B;
2156 if (val & 8) { 1951 if (val & 8)
2157 val |= 4; 1952 val |= 4;
2158 if ((moxa_ports[port].DCDState & DCD_oldstate) == 0) 1953 spin_lock_bh(&moxa_lock);
2159 moxa_ports[port].DCDState = (DCD_oldstate | DCD_changed); 1954 moxa_new_dcdstate(port, val & 8);
2160 } else { 1955 spin_unlock_bh(&moxa_lock);
2161 if (moxa_ports[port].DCDState & DCD_oldstate)
2162 moxa_ports[port].DCDState = DCD_changed;
2163 }
2164 val &= 7; 1956 val &= 7;
2165 return (val); 1957 return val;
2166}
2167
2168int MoxaPortDCDChange(int port)
2169{
2170 int n;
2171
2172 if (moxa_ports[port].chkPort == 0)
2173 return (0);
2174 n = moxa_ports[port].DCDState;
2175 moxa_ports[port].DCDState &= ~DCD_changed;
2176 n &= DCD_changed;
2177 return (n);
2178}
2179
2180int MoxaPortDCDON(int port)
2181{
2182 int n;
2183
2184 if (moxa_ports[port].chkPort == 0)
2185 return (0);
2186 if (moxa_ports[port].DCDState & DCD_oldstate)
2187 n = 1;
2188 else
2189 n = 0;
2190 return (n);
2191} 1958}
2192 1959
2193int MoxaPortWriteData(int port, unsigned char * buffer, int len) 1960static int MoxaPortWriteData(struct moxa_port *port,
1961 const unsigned char *buffer, int len)
2194{ 1962{
2195 int c, total, i;
2196 ushort tail;
2197 int cnt;
2198 ushort head, tx_mask, spage, epage;
2199 ushort pageno, pageofs, bufhead;
2200 void __iomem *baseAddr, *ofsAddr, *ofs; 1963 void __iomem *baseAddr, *ofsAddr, *ofs;
1964 unsigned int c, total;
1965 u16 head, tail, tx_mask, spage, epage;
1966 u16 pageno, pageofs, bufhead;
2201 1967
2202 ofsAddr = moxa_ports[port].tableAddr; 1968 ofsAddr = port->tableAddr;
2203 baseAddr = moxa_boards[port / MAX_PORTS_PER_BOARD].basemem; 1969 baseAddr = port->board->basemem;
2204 tx_mask = readw(ofsAddr + TX_mask); 1970 tx_mask = readw(ofsAddr + TX_mask);
2205 spage = readw(ofsAddr + Page_txb); 1971 spage = readw(ofsAddr + Page_txb);
2206 epage = readw(ofsAddr + EndPage_txb); 1972 epage = readw(ofsAddr + EndPage_txb);
2207 tail = readw(ofsAddr + TXwptr); 1973 tail = readw(ofsAddr + TXwptr);
2208 head = readw(ofsAddr + TXrptr); 1974 head = readw(ofsAddr + TXrptr);
2209 c = (head > tail) ? (head - tail - 1) 1975 c = (head > tail) ? (head - tail - 1) : (head - tail + tx_mask);
2210 : (head - tail + tx_mask);
2211 if (c > len) 1976 if (c > len)
2212 c = len; 1977 c = len;
2213 moxaLog.txcnt[port] += c; 1978 moxaLog.txcnt[port->tty->index] += c;
2214 total = c; 1979 total = c;
2215 if (spage == epage) { 1980 if (spage == epage) {
2216 bufhead = readw(ofsAddr + Ofs_txb); 1981 bufhead = readw(ofsAddr + Ofs_txb);
@@ -2222,249 +1987,179 @@ int MoxaPortWriteData(int port, unsigned char * buffer, int len)
2222 len = tx_mask + 1 - tail; 1987 len = tx_mask + 1 - tail;
2223 len = (c > len) ? len : c; 1988 len = (c > len) ? len : c;
2224 ofs = baseAddr + DynPage_addr + bufhead + tail; 1989 ofs = baseAddr + DynPage_addr + bufhead + tail;
2225 for (i = 0; i < len; i++) 1990 memcpy_toio(ofs, buffer, len);
2226 writeb(*buffer++, ofs + i); 1991 buffer += len;
2227 tail = (tail + len) & tx_mask; 1992 tail = (tail + len) & tx_mask;
2228 c -= len; 1993 c -= len;
2229 } 1994 }
2230 writew(tail, ofsAddr + TXwptr);
2231 } else { 1995 } else {
2232 len = c;
2233 pageno = spage + (tail >> 13); 1996 pageno = spage + (tail >> 13);
2234 pageofs = tail & Page_mask; 1997 pageofs = tail & Page_mask;
2235 do { 1998 while (c > 0) {
2236 cnt = Page_size - pageofs; 1999 len = Page_size - pageofs;
2237 if (cnt > c) 2000 if (len > c)
2238 cnt = c; 2001 len = c;
2239 c -= cnt;
2240 writeb(pageno, baseAddr + Control_reg); 2002 writeb(pageno, baseAddr + Control_reg);
2241 ofs = baseAddr + DynPage_addr + pageofs; 2003 ofs = baseAddr + DynPage_addr + pageofs;
2242 for (i = 0; i < cnt; i++) 2004 memcpy_toio(ofs, buffer, len);
2243 writeb(*buffer++, ofs + i); 2005 buffer += len;
2244 if (c == 0) {
2245 writew((tail + len) & tx_mask, ofsAddr + TXwptr);
2246 break;
2247 }
2248 if (++pageno == epage) 2006 if (++pageno == epage)
2249 pageno = spage; 2007 pageno = spage;
2250 pageofs = 0; 2008 pageofs = 0;
2251 } while (1); 2009 c -= len;
2010 }
2011 tail = (tail + total) & tx_mask;
2252 } 2012 }
2013 writew(tail, ofsAddr + TXwptr);
2253 writeb(1, ofsAddr + CD180TXirq); /* start to send */ 2014 writeb(1, ofsAddr + CD180TXirq); /* start to send */
2254 return (total); 2015 return total;
2255} 2016}
2256 2017
2257int MoxaPortReadData(int port, struct tty_struct *tty) 2018static int MoxaPortReadData(struct moxa_port *port)
2258{ 2019{
2259 register ushort head, pageofs; 2020 struct tty_struct *tty = port->tty;
2260 int i, count, cnt, len, total, remain; 2021 unsigned char *dst;
2261 ushort tail, rx_mask, spage, epage;
2262 ushort pageno, bufhead;
2263 void __iomem *baseAddr, *ofsAddr, *ofs; 2022 void __iomem *baseAddr, *ofsAddr, *ofs;
2023 unsigned int count, len, total;
2024 u16 tail, rx_mask, spage, epage;
2025 u16 pageno, pageofs, bufhead, head;
2264 2026
2265 ofsAddr = moxa_ports[port].tableAddr; 2027 ofsAddr = port->tableAddr;
2266 baseAddr = moxa_boards[port / MAX_PORTS_PER_BOARD].basemem; 2028 baseAddr = port->board->basemem;
2267 head = readw(ofsAddr + RXrptr); 2029 head = readw(ofsAddr + RXrptr);
2268 tail = readw(ofsAddr + RXwptr); 2030 tail = readw(ofsAddr + RXwptr);
2269 rx_mask = readw(ofsAddr + RX_mask); 2031 rx_mask = readw(ofsAddr + RX_mask);
2270 spage = readw(ofsAddr + Page_rxb); 2032 spage = readw(ofsAddr + Page_rxb);
2271 epage = readw(ofsAddr + EndPage_rxb); 2033 epage = readw(ofsAddr + EndPage_rxb);
2272 count = (tail >= head) ? (tail - head) 2034 count = (tail >= head) ? (tail - head) : (tail - head + rx_mask + 1);
2273 : (tail - head + rx_mask + 1);
2274 if (count == 0) 2035 if (count == 0)
2275 return 0; 2036 return 0;
2276 2037
2277 total = count; 2038 total = count;
2278 remain = count - total; 2039 moxaLog.rxcnt[tty->index] += total;
2279 moxaLog.rxcnt[port] += total;
2280 count = total;
2281 if (spage == epage) { 2040 if (spage == epage) {
2282 bufhead = readw(ofsAddr + Ofs_rxb); 2041 bufhead = readw(ofsAddr + Ofs_rxb);
2283 writew(spage, baseAddr + Control_reg); 2042 writew(spage, baseAddr + Control_reg);
2284 while (count > 0) { 2043 while (count > 0) {
2285 if (tail >= head)
2286 len = tail - head;
2287 else
2288 len = rx_mask + 1 - head;
2289 len = (count > len) ? len : count;
2290 ofs = baseAddr + DynPage_addr + bufhead + head; 2044 ofs = baseAddr + DynPage_addr + bufhead + head;
2291 for (i = 0; i < len; i++) 2045 len = (tail >= head) ? (tail - head) :
2292 tty_insert_flip_char(tty, readb(ofs + i), TTY_NORMAL); 2046 (rx_mask + 1 - head);
2047 len = tty_prepare_flip_string(tty, &dst,
2048 min(len, count));
2049 memcpy_fromio(dst, ofs, len);
2293 head = (head + len) & rx_mask; 2050 head = (head + len) & rx_mask;
2294 count -= len; 2051 count -= len;
2295 } 2052 }
2296 writew(head, ofsAddr + RXrptr);
2297 } else { 2053 } else {
2298 len = count;
2299 pageno = spage + (head >> 13); 2054 pageno = spage + (head >> 13);
2300 pageofs = head & Page_mask; 2055 pageofs = head & Page_mask;
2301 do { 2056 while (count > 0) {
2302 cnt = Page_size - pageofs;
2303 if (cnt > count)
2304 cnt = count;
2305 count -= cnt;
2306 writew(pageno, baseAddr + Control_reg); 2057 writew(pageno, baseAddr + Control_reg);
2307 ofs = baseAddr + DynPage_addr + pageofs; 2058 ofs = baseAddr + DynPage_addr + pageofs;
2308 for (i = 0; i < cnt; i++) 2059 len = tty_prepare_flip_string(tty, &dst,
2309 tty_insert_flip_char(tty, readb(ofs + i), TTY_NORMAL); 2060 min(Page_size - pageofs, count));
2310 if (count == 0) { 2061 memcpy_fromio(dst, ofs, len);
2311 writew((head + len) & rx_mask, ofsAddr + RXrptr); 2062
2312 break; 2063 count -= len;
2313 } 2064 pageofs = (pageofs + len) & Page_mask;
2314 if (++pageno == epage) 2065 if (pageofs == 0 && ++pageno == epage)
2315 pageno = spage; 2066 pageno = spage;
2316 pageofs = 0; 2067 }
2317 } while (1); 2068 head = (head + total) & rx_mask;
2318 } 2069 }
2319 if ((readb(ofsAddr + FlagStat) & Xoff_state) && (remain < LowWater)) { 2070 writew(head, ofsAddr + RXrptr);
2071 if (readb(ofsAddr + FlagStat) & Xoff_state) {
2320 moxaLowWaterChk = 1; 2072 moxaLowWaterChk = 1;
2321 moxa_ports[port].lowChkFlag = 1; 2073 port->lowChkFlag = 1;
2322 } 2074 }
2323 return (total); 2075 return total;
2324} 2076}
2325 2077
2326 2078
2327int MoxaPortTxQueue(int port) 2079static int MoxaPortTxQueue(struct moxa_port *port)
2328{ 2080{
2329 void __iomem *ofsAddr; 2081 void __iomem *ofsAddr = port->tableAddr;
2330 ushort rptr, wptr, mask; 2082 u16 rptr, wptr, mask;
2331 int len;
2332 2083
2333 ofsAddr = moxa_ports[port].tableAddr;
2334 rptr = readw(ofsAddr + TXrptr); 2084 rptr = readw(ofsAddr + TXrptr);
2335 wptr = readw(ofsAddr + TXwptr); 2085 wptr = readw(ofsAddr + TXwptr);
2336 mask = readw(ofsAddr + TX_mask); 2086 mask = readw(ofsAddr + TX_mask);
2337 len = (wptr - rptr) & mask; 2087 return (wptr - rptr) & mask;
2338 return (len);
2339} 2088}
2340 2089
2341int MoxaPortTxFree(int port) 2090static int MoxaPortTxFree(struct moxa_port *port)
2342{ 2091{
2343 void __iomem *ofsAddr; 2092 void __iomem *ofsAddr = port->tableAddr;
2344 ushort rptr, wptr, mask; 2093 u16 rptr, wptr, mask;
2345 int len;
2346 2094
2347 ofsAddr = moxa_ports[port].tableAddr;
2348 rptr = readw(ofsAddr + TXrptr); 2095 rptr = readw(ofsAddr + TXrptr);
2349 wptr = readw(ofsAddr + TXwptr); 2096 wptr = readw(ofsAddr + TXwptr);
2350 mask = readw(ofsAddr + TX_mask); 2097 mask = readw(ofsAddr + TX_mask);
2351 len = mask - ((wptr - rptr) & mask); 2098 return mask - ((wptr - rptr) & mask);
2352 return (len);
2353} 2099}
2354 2100
2355int MoxaPortRxQueue(int port) 2101static int MoxaPortRxQueue(struct moxa_port *port)
2356{ 2102{
2357 void __iomem *ofsAddr; 2103 void __iomem *ofsAddr = port->tableAddr;
2358 ushort rptr, wptr, mask; 2104 u16 rptr, wptr, mask;
2359 int len;
2360 2105
2361 ofsAddr = moxa_ports[port].tableAddr;
2362 rptr = readw(ofsAddr + RXrptr); 2106 rptr = readw(ofsAddr + RXrptr);
2363 wptr = readw(ofsAddr + RXwptr); 2107 wptr = readw(ofsAddr + RXwptr);
2364 mask = readw(ofsAddr + RX_mask); 2108 mask = readw(ofsAddr + RX_mask);
2365 len = (wptr - rptr) & mask; 2109 return (wptr - rptr) & mask;
2366 return (len);
2367} 2110}
2368 2111
2369 2112static void MoxaPortTxDisable(struct moxa_port *port)
2370void MoxaPortTxDisable(int port)
2371{ 2113{
2372 void __iomem *ofsAddr; 2114 moxafunc(port->tableAddr, FC_SetXoffState, Magic_code);
2373
2374 ofsAddr = moxa_ports[port].tableAddr;
2375 moxafunc(ofsAddr, FC_SetXoffState, Magic_code);
2376} 2115}
2377 2116
2378void MoxaPortTxEnable(int port) 2117static void MoxaPortTxEnable(struct moxa_port *port)
2379{ 2118{
2380 void __iomem *ofsAddr; 2119 moxafunc(port->tableAddr, FC_SetXonState, Magic_code);
2381
2382 ofsAddr = moxa_ports[port].tableAddr;
2383 moxafunc(ofsAddr, FC_SetXonState, Magic_code);
2384}
2385
2386
2387int MoxaPortResetBrkCnt(int port)
2388{
2389 ushort cnt;
2390 cnt = moxa_ports[port].breakCnt;
2391 moxa_ports[port].breakCnt = 0;
2392 return (cnt);
2393}
2394
2395
2396void MoxaPortSendBreak(int port, int ms100)
2397{
2398 void __iomem *ofsAddr;
2399
2400 ofsAddr = moxa_ports[port].tableAddr;
2401 if (ms100) {
2402 moxafunc(ofsAddr, FC_SendBreak, Magic_code);
2403 msleep(ms100 * 10);
2404 } else {
2405 moxafunc(ofsAddr, FC_SendBreak, Magic_code);
2406 msleep(250);
2407 }
2408 moxafunc(ofsAddr, FC_StopBreak, Magic_code);
2409} 2120}
2410 2121
2411static int moxa_get_serial_info(struct moxa_port *info, 2122static int moxa_get_serial_info(struct moxa_port *info,
2412 struct serial_struct __user *retinfo) 2123 struct serial_struct __user *retinfo)
2413{ 2124{
2414 struct serial_struct tmp; 2125 struct serial_struct tmp = {
2415 2126 .type = info->type,
2416 memset(&tmp, 0, sizeof(tmp)); 2127 .line = info->tty->index,
2417 tmp.type = info->type; 2128 .flags = info->asyncflags,
2418 tmp.line = info->port; 2129 .baud_base = 921600,
2419 tmp.port = 0; 2130 .close_delay = info->close_delay
2420 tmp.irq = 0; 2131 };
2421 tmp.flags = info->asyncflags; 2132 return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
2422 tmp.baud_base = 921600;
2423 tmp.close_delay = info->close_delay;
2424 tmp.closing_wait = info->closing_wait;
2425 tmp.custom_divisor = 0;
2426 tmp.hub6 = 0;
2427 if(copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2428 return -EFAULT;
2429 return (0);
2430} 2133}
2431 2134
2432 2135
2433static int moxa_set_serial_info(struct moxa_port *info, 2136static int moxa_set_serial_info(struct moxa_port *info,
2434 struct serial_struct __user *new_info) 2137 struct serial_struct __user *new_info)
2435{ 2138{
2436 struct serial_struct new_serial; 2139 struct serial_struct new_serial;
2437 2140
2438 if(copy_from_user(&new_serial, new_info, sizeof(new_serial))) 2141 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
2439 return -EFAULT; 2142 return -EFAULT;
2440 2143
2441 if ((new_serial.irq != 0) || 2144 if (new_serial.irq != 0 || new_serial.port != 0 ||
2442 (new_serial.port != 0) || 2145 new_serial.custom_divisor != 0 ||
2443// (new_serial.type != info->type) || 2146 new_serial.baud_base != 921600)
2444 (new_serial.custom_divisor != 0) || 2147 return -EPERM;
2445 (new_serial.baud_base != 921600))
2446 return (-EPERM);
2447 2148
2448 if (!capable(CAP_SYS_ADMIN)) { 2149 if (!capable(CAP_SYS_ADMIN)) {
2449 if (((new_serial.flags & ~ASYNC_USR_MASK) != 2150 if (((new_serial.flags & ~ASYNC_USR_MASK) !=
2450 (info->asyncflags & ~ASYNC_USR_MASK))) 2151 (info->asyncflags & ~ASYNC_USR_MASK)))
2451 return (-EPERM); 2152 return -EPERM;
2452 } else { 2153 } else
2453 info->close_delay = new_serial.close_delay * HZ / 100; 2154 info->close_delay = new_serial.close_delay * HZ / 100;
2454 info->closing_wait = new_serial.closing_wait * HZ / 100;
2455 }
2456 2155
2457 new_serial.flags = (new_serial.flags & ~ASYNC_FLAGS); 2156 new_serial.flags = (new_serial.flags & ~ASYNC_FLAGS);
2458 new_serial.flags |= (info->asyncflags & ASYNC_FLAGS); 2157 new_serial.flags |= (info->asyncflags & ASYNC_FLAGS);
2459 2158
2460 if (new_serial.type == PORT_16550A) { 2159 MoxaSetFifo(info, new_serial.type == PORT_16550A);
2461 MoxaSetFifo(info->port, 1);
2462 } else {
2463 MoxaSetFifo(info->port, 0);
2464 }
2465 2160
2466 info->type = new_serial.type; 2161 info->type = new_serial.type;
2467 return (0); 2162 return 0;
2468} 2163}
2469 2164
2470 2165
@@ -2472,374 +2167,10 @@ static int moxa_set_serial_info(struct moxa_port *info,
2472/***************************************************************************** 2167/*****************************************************************************
2473 * Static local functions: * 2168 * Static local functions: *
2474 *****************************************************************************/ 2169 *****************************************************************************/
2475static void moxafunc(void __iomem *ofsAddr, int cmd, ushort arg)
2476{
2477
2478 writew(arg, ofsAddr + FuncArg);
2479 writew(cmd, ofsAddr + FuncCode);
2480 moxa_wait_finish(ofsAddr);
2481}
2482
2483static void moxa_wait_finish(void __iomem *ofsAddr)
2484{
2485 unsigned long i, j;
2486
2487 i = jiffies;
2488 while (readw(ofsAddr + FuncCode) != 0) {
2489 j = jiffies;
2490 if ((j - i) > moxaFuncTout) {
2491 return;
2492 }
2493 }
2494}
2495
2496static void moxa_low_water_check(void __iomem *ofsAddr)
2497{
2498 int len;
2499 ushort rptr, wptr, mask;
2500
2501 if (readb(ofsAddr + FlagStat) & Xoff_state) {
2502 rptr = readw(ofsAddr + RXrptr);
2503 wptr = readw(ofsAddr + RXwptr);
2504 mask = readw(ofsAddr + RX_mask);
2505 len = (wptr - rptr) & mask;
2506 if (len <= Low_water)
2507 moxafunc(ofsAddr, FC_SendXon, 0);
2508 }
2509}
2510
2511static int moxaloadbios(int cardno, unsigned char __user *tmp, int len)
2512{
2513 void __iomem *baseAddr;
2514 int i;
2515
2516 if(len < 0 || len > sizeof(moxaBuff))
2517 return -EINVAL;
2518 if(copy_from_user(moxaBuff, tmp, len))
2519 return -EFAULT;
2520 baseAddr = moxa_boards[cardno].basemem;
2521 writeb(HW_reset, baseAddr + Control_reg); /* reset */
2522 msleep(10);
2523 for (i = 0; i < 4096; i++)
2524 writeb(0, baseAddr + i); /* clear fix page */
2525 for (i = 0; i < len; i++)
2526 writeb(moxaBuff[i], baseAddr + i); /* download BIOS */
2527 writeb(0, baseAddr + Control_reg); /* restart */
2528 return (0);
2529}
2530
2531static int moxafindcard(int cardno)
2532{
2533 void __iomem *baseAddr;
2534 ushort tmp;
2535
2536 baseAddr = moxa_boards[cardno].basemem;
2537 switch (moxa_boards[cardno].boardType) {
2538 case MOXA_BOARD_C218_ISA:
2539 case MOXA_BOARD_C218_PCI:
2540 if ((tmp = readw(baseAddr + C218_key)) != C218_KeyCode) {
2541 return (-1);
2542 }
2543 break;
2544 case MOXA_BOARD_CP204J:
2545 if ((tmp = readw(baseAddr + C218_key)) != CP204J_KeyCode) {
2546 return (-1);
2547 }
2548 break;
2549 default:
2550 if ((tmp = readw(baseAddr + C320_key)) != C320_KeyCode) {
2551 return (-1);
2552 }
2553 if ((tmp = readw(baseAddr + C320_status)) != STS_init) {
2554 return (-2);
2555 }
2556 }
2557 return (0);
2558}
2559
2560static int moxaload320b(int cardno, unsigned char __user *tmp, int len)
2561{
2562 void __iomem *baseAddr;
2563 int i;
2564
2565 if(len < 0 || len > sizeof(moxaBuff))
2566 return -EINVAL;
2567 if(copy_from_user(moxaBuff, tmp, len))
2568 return -EFAULT;
2569 baseAddr = moxa_boards[cardno].basemem;
2570 writew(len - 7168 - 2, baseAddr + C320bapi_len);
2571 writeb(1, baseAddr + Control_reg); /* Select Page 1 */
2572 for (i = 0; i < 7168; i++)
2573 writeb(moxaBuff[i], baseAddr + DynPage_addr + i);
2574 writeb(2, baseAddr + Control_reg); /* Select Page 2 */
2575 for (i = 0; i < (len - 7168); i++)
2576 writeb(moxaBuff[i + 7168], baseAddr + DynPage_addr + i);
2577 return (0);
2578}
2579
2580static int moxaloadcode(int cardno, unsigned char __user *tmp, int len)
2581{
2582 void __iomem *baseAddr, *ofsAddr;
2583 int retval, port, i;
2584
2585 if(len < 0 || len > sizeof(moxaBuff))
2586 return -EINVAL;
2587 if(copy_from_user(moxaBuff, tmp, len))
2588 return -EFAULT;
2589 baseAddr = moxa_boards[cardno].basemem;
2590 switch (moxa_boards[cardno].boardType) {
2591 case MOXA_BOARD_C218_ISA:
2592 case MOXA_BOARD_C218_PCI:
2593 case MOXA_BOARD_CP204J:
2594 retval = moxaloadc218(cardno, baseAddr, len);
2595 if (retval)
2596 return (retval);
2597 port = cardno * MAX_PORTS_PER_BOARD;
2598 for (i = 0; i < moxa_boards[cardno].numPorts; i++, port++) {
2599 struct moxa_port *p = &moxa_ports[port];
2600
2601 p->chkPort = 1;
2602 p->curBaud = 9600L;
2603 p->DCDState = 0;
2604 p->tableAddr = baseAddr + Extern_table + Extern_size * i;
2605 ofsAddr = p->tableAddr;
2606 writew(C218rx_mask, ofsAddr + RX_mask);
2607 writew(C218tx_mask, ofsAddr + TX_mask);
2608 writew(C218rx_spage + i * C218buf_pageno, ofsAddr + Page_rxb);
2609 writew(readw(ofsAddr + Page_rxb) + C218rx_pageno, ofsAddr + EndPage_rxb);
2610
2611 writew(C218tx_spage + i * C218buf_pageno, ofsAddr + Page_txb);
2612 writew(readw(ofsAddr + Page_txb) + C218tx_pageno, ofsAddr + EndPage_txb);
2613
2614 }
2615 break;
2616 default:
2617 retval = moxaloadc320(cardno, baseAddr, len,
2618 &moxa_boards[cardno].numPorts);
2619 if (retval)
2620 return (retval);
2621 port = cardno * MAX_PORTS_PER_BOARD;
2622 for (i = 0; i < moxa_boards[cardno].numPorts; i++, port++) {
2623 struct moxa_port *p = &moxa_ports[port];
2624
2625 p->chkPort = 1;
2626 p->curBaud = 9600L;
2627 p->DCDState = 0;
2628 p->tableAddr = baseAddr + Extern_table + Extern_size * i;
2629 ofsAddr = p->tableAddr;
2630 if (moxa_boards[cardno].numPorts == 8) {
2631 writew(C320p8rx_mask, ofsAddr + RX_mask);
2632 writew(C320p8tx_mask, ofsAddr + TX_mask);
2633 writew(C320p8rx_spage + i * C320p8buf_pgno, ofsAddr + Page_rxb);
2634 writew(readw(ofsAddr + Page_rxb) + C320p8rx_pgno, ofsAddr + EndPage_rxb);
2635 writew(C320p8tx_spage + i * C320p8buf_pgno, ofsAddr + Page_txb);
2636 writew(readw(ofsAddr + Page_txb) + C320p8tx_pgno, ofsAddr + EndPage_txb);
2637
2638 } else if (moxa_boards[cardno].numPorts == 16) {
2639 writew(C320p16rx_mask, ofsAddr + RX_mask);
2640 writew(C320p16tx_mask, ofsAddr + TX_mask);
2641 writew(C320p16rx_spage + i * C320p16buf_pgno, ofsAddr + Page_rxb);
2642 writew(readw(ofsAddr + Page_rxb) + C320p16rx_pgno, ofsAddr + EndPage_rxb);
2643 writew(C320p16tx_spage + i * C320p16buf_pgno, ofsAddr + Page_txb);
2644 writew(readw(ofsAddr + Page_txb) + C320p16tx_pgno, ofsAddr + EndPage_txb);
2645
2646 } else if (moxa_boards[cardno].numPorts == 24) {
2647 writew(C320p24rx_mask, ofsAddr + RX_mask);
2648 writew(C320p24tx_mask, ofsAddr + TX_mask);
2649 writew(C320p24rx_spage + i * C320p24buf_pgno, ofsAddr + Page_rxb);
2650 writew(readw(ofsAddr + Page_rxb) + C320p24rx_pgno, ofsAddr + EndPage_rxb);
2651 writew(C320p24tx_spage + i * C320p24buf_pgno, ofsAddr + Page_txb);
2652 writew(readw(ofsAddr + Page_txb), ofsAddr + EndPage_txb);
2653 } else if (moxa_boards[cardno].numPorts == 32) {
2654 writew(C320p32rx_mask, ofsAddr + RX_mask);
2655 writew(C320p32tx_mask, ofsAddr + TX_mask);
2656 writew(C320p32tx_ofs, ofsAddr + Ofs_txb);
2657 writew(C320p32rx_spage + i * C320p32buf_pgno, ofsAddr + Page_rxb);
2658 writew(readb(ofsAddr + Page_rxb), ofsAddr + EndPage_rxb);
2659 writew(C320p32tx_spage + i * C320p32buf_pgno, ofsAddr + Page_txb);
2660 writew(readw(ofsAddr + Page_txb), ofsAddr + EndPage_txb);
2661 }
2662 }
2663 break;
2664 }
2665 moxa_boards[cardno].loadstat = 1;
2666 return (0);
2667}
2668
2669static int moxaloadc218(int cardno, void __iomem *baseAddr, int len)
2670{
2671 char retry;
2672 int i, j, len1, len2;
2673 ushort usum, *ptr, keycode;
2674
2675 if (moxa_boards[cardno].boardType == MOXA_BOARD_CP204J)
2676 keycode = CP204J_KeyCode;
2677 else
2678 keycode = C218_KeyCode;
2679 usum = 0;
2680 len1 = len >> 1;
2681 ptr = (ushort *) moxaBuff;
2682 for (i = 0; i < len1; i++)
2683 usum += le16_to_cpu(*(ptr + i));
2684 retry = 0;
2685 do {
2686 len1 = len >> 1;
2687 j = 0;
2688 while (len1) {
2689 len2 = (len1 > 2048) ? 2048 : len1;
2690 len1 -= len2;
2691 for (i = 0; i < len2 << 1; i++)
2692 writeb(moxaBuff[i + j], baseAddr + C218_LoadBuf + i);
2693 j += i;
2694
2695 writew(len2, baseAddr + C218DLoad_len);
2696 writew(0, baseAddr + C218_key);
2697 for (i = 0; i < 100; i++) {
2698 if (readw(baseAddr + C218_key) == keycode)
2699 break;
2700 msleep(10);
2701 }
2702 if (readw(baseAddr + C218_key) != keycode) {
2703 return (-1);
2704 }
2705 }
2706 writew(0, baseAddr + C218DLoad_len);
2707 writew(usum, baseAddr + C218check_sum);
2708 writew(0, baseAddr + C218_key);
2709 for (i = 0; i < 100; i++) {
2710 if (readw(baseAddr + C218_key) == keycode)
2711 break;
2712 msleep(10);
2713 }
2714 retry++;
2715 } while ((readb(baseAddr + C218chksum_ok) != 1) && (retry < 3));
2716 if (readb(baseAddr + C218chksum_ok) != 1) {
2717 return (-1);
2718 }
2719 writew(0, baseAddr + C218_key);
2720 for (i = 0; i < 100; i++) {
2721 if (readw(baseAddr + Magic_no) == Magic_code)
2722 break;
2723 msleep(10);
2724 }
2725 if (readw(baseAddr + Magic_no) != Magic_code) {
2726 return (-1);
2727 }
2728 writew(1, baseAddr + Disable_IRQ);
2729 writew(0, baseAddr + Magic_no);
2730 for (i = 0; i < 100; i++) {
2731 if (readw(baseAddr + Magic_no) == Magic_code)
2732 break;
2733 msleep(10);
2734 }
2735 if (readw(baseAddr + Magic_no) != Magic_code) {
2736 return (-1);
2737 }
2738 moxaCard = 1;
2739 moxa_boards[cardno].intNdx = baseAddr + IRQindex;
2740 moxa_boards[cardno].intPend = baseAddr + IRQpending;
2741 moxa_boards[cardno].intTable = baseAddr + IRQtable;
2742 return (0);
2743}
2744
2745static int moxaloadc320(int cardno, void __iomem *baseAddr, int len, int *numPorts)
2746{
2747 ushort usum;
2748 int i, j, wlen, len2, retry;
2749 ushort *uptr;
2750
2751 usum = 0;
2752 wlen = len >> 1;
2753 uptr = (ushort *) moxaBuff;
2754 for (i = 0; i < wlen; i++)
2755 usum += le16_to_cpu(uptr[i]);
2756 retry = 0;
2757 j = 0;
2758 do {
2759 while (wlen) {
2760 if (wlen > 2048)
2761 len2 = 2048;
2762 else
2763 len2 = wlen;
2764 wlen -= len2;
2765 len2 <<= 1;
2766 for (i = 0; i < len2; i++)
2767 writeb(moxaBuff[j + i], baseAddr + C320_LoadBuf + i);
2768 len2 >>= 1;
2769 j += i;
2770 writew(len2, baseAddr + C320DLoad_len);
2771 writew(0, baseAddr + C320_key);
2772 for (i = 0; i < 10; i++) {
2773 if (readw(baseAddr + C320_key) == C320_KeyCode)
2774 break;
2775 msleep(10);
2776 }
2777 if (readw(baseAddr + C320_key) != C320_KeyCode)
2778 return (-1);
2779 }
2780 writew(0, baseAddr + C320DLoad_len);
2781 writew(usum, baseAddr + C320check_sum);
2782 writew(0, baseAddr + C320_key);
2783 for (i = 0; i < 10; i++) {
2784 if (readw(baseAddr + C320_key) == C320_KeyCode)
2785 break;
2786 msleep(10);
2787 }
2788 retry++;
2789 } while ((readb(baseAddr + C320chksum_ok) != 1) && (retry < 3));
2790 if (readb(baseAddr + C320chksum_ok) != 1)
2791 return (-1);
2792 writew(0, baseAddr + C320_key);
2793 for (i = 0; i < 600; i++) {
2794 if (readw(baseAddr + Magic_no) == Magic_code)
2795 break;
2796 msleep(10);
2797 }
2798 if (readw(baseAddr + Magic_no) != Magic_code)
2799 return (-100);
2800
2801 if (moxa_boards[cardno].busType == MOXA_BUS_TYPE_PCI) { /* ASIC board */
2802 writew(0x3800, baseAddr + TMS320_PORT1);
2803 writew(0x3900, baseAddr + TMS320_PORT2);
2804 writew(28499, baseAddr + TMS320_CLOCK);
2805 } else {
2806 writew(0x3200, baseAddr + TMS320_PORT1);
2807 writew(0x3400, baseAddr + TMS320_PORT2);
2808 writew(19999, baseAddr + TMS320_CLOCK);
2809 }
2810 writew(1, baseAddr + Disable_IRQ);
2811 writew(0, baseAddr + Magic_no);
2812 for (i = 0; i < 500; i++) {
2813 if (readw(baseAddr + Magic_no) == Magic_code)
2814 break;
2815 msleep(10);
2816 }
2817 if (readw(baseAddr + Magic_no) != Magic_code)
2818 return (-102);
2819
2820 j = readw(baseAddr + Module_cnt);
2821 if (j <= 0)
2822 return (-101);
2823 *numPorts = j * 8;
2824 writew(j, baseAddr + Module_no);
2825 writew(0, baseAddr + Magic_no);
2826 for (i = 0; i < 600; i++) {
2827 if (readw(baseAddr + Magic_no) == Magic_code)
2828 break;
2829 msleep(10);
2830 }
2831 if (readw(baseAddr + Magic_no) != Magic_code)
2832 return (-102);
2833 moxaCard = 1;
2834 moxa_boards[cardno].intNdx = baseAddr + IRQindex;
2835 moxa_boards[cardno].intPend = baseAddr + IRQpending;
2836 moxa_boards[cardno].intTable = baseAddr + IRQtable;
2837 return (0);
2838}
2839 2170
2840static void MoxaSetFifo(int port, int enable) 2171static void MoxaSetFifo(struct moxa_port *port, int enable)
2841{ 2172{
2842 void __iomem *ofsAddr = moxa_ports[port].tableAddr; 2173 void __iomem *ofsAddr = port->tableAddr;
2843 2174
2844 if (!enable) { 2175 if (!enable) {
2845 moxafunc(ofsAddr, FC_SetRxFIFOTrig, 0); 2176 moxafunc(ofsAddr, FC_SetRxFIFOTrig, 0);
diff --git a/drivers/char/moxa.h b/drivers/char/moxa.h
new file mode 100644
index 000000000000..87d16ce57be7
--- /dev/null
+++ b/drivers/char/moxa.h
@@ -0,0 +1,304 @@
1#ifndef MOXA_H_FILE
2#define MOXA_H_FILE
3
4#define MOXA 0x400
5#define MOXA_GET_IQUEUE (MOXA + 1) /* get input buffered count */
6#define MOXA_GET_OQUEUE (MOXA + 2) /* get output buffered count */
7#define MOXA_GETDATACOUNT (MOXA + 23)
8#define MOXA_GET_IOQUEUE (MOXA + 27)
9#define MOXA_FLUSH_QUEUE (MOXA + 28)
10#define MOXA_GETMSTATUS (MOXA + 65)
11
12/*
13 * System Configuration
14 */
15
16#define Magic_code 0x404
17
18/*
19 * for C218 BIOS initialization
20 */
21#define C218_ConfBase 0x800
22#define C218_status (C218_ConfBase + 0) /* BIOS running status */
23#define C218_diag (C218_ConfBase + 2) /* diagnostic status */
24#define C218_key (C218_ConfBase + 4) /* WORD (0x218 for C218) */
25#define C218DLoad_len (C218_ConfBase + 6) /* WORD */
26#define C218check_sum (C218_ConfBase + 8) /* BYTE */
27#define C218chksum_ok (C218_ConfBase + 0x0a) /* BYTE (1:ok) */
28#define C218_TestRx (C218_ConfBase + 0x10) /* 8 bytes for 8 ports */
29#define C218_TestTx (C218_ConfBase + 0x18) /* 8 bytes for 8 ports */
30#define C218_RXerr (C218_ConfBase + 0x20) /* 8 bytes for 8 ports */
31#define C218_ErrFlag (C218_ConfBase + 0x28) /* 8 bytes for 8 ports */
32
33#define C218_LoadBuf 0x0F00
34#define C218_KeyCode 0x218
35#define CP204J_KeyCode 0x204
36
37/*
38 * for C320 BIOS initialization
39 */
40#define C320_ConfBase 0x800
41#define C320_LoadBuf 0x0f00
42#define STS_init 0x05 /* for C320_status */
43
44#define C320_status C320_ConfBase + 0 /* BIOS running status */
45#define C320_diag C320_ConfBase + 2 /* diagnostic status */
46#define C320_key C320_ConfBase + 4 /* WORD (0320H for C320) */
47#define C320DLoad_len C320_ConfBase + 6 /* WORD */
48#define C320check_sum C320_ConfBase + 8 /* WORD */
49#define C320chksum_ok C320_ConfBase + 0x0a /* WORD (1:ok) */
50#define C320bapi_len C320_ConfBase + 0x0c /* WORD */
51#define C320UART_no C320_ConfBase + 0x0e /* WORD */
52
53#define C320_KeyCode 0x320
54
55#define FixPage_addr 0x0000 /* starting addr of static page */
56#define DynPage_addr 0x2000 /* starting addr of dynamic page */
57#define C218_start 0x3000 /* starting addr of C218 BIOS prg */
58#define Control_reg 0x1ff0 /* select page and reset control */
59#define HW_reset 0x80
60
61/*
62 * Function Codes
63 */
64#define FC_CardReset 0x80
65#define FC_ChannelReset 1 /* C320 firmware not supported */
66#define FC_EnableCH 2
67#define FC_DisableCH 3
68#define FC_SetParam 4
69#define FC_SetMode 5
70#define FC_SetRate 6
71#define FC_LineControl 7
72#define FC_LineStatus 8
73#define FC_XmitControl 9
74#define FC_FlushQueue 10
75#define FC_SendBreak 11
76#define FC_StopBreak 12
77#define FC_LoopbackON 13
78#define FC_LoopbackOFF 14
79#define FC_ClrIrqTable 15
80#define FC_SendXon 16
81#define FC_SetTermIrq 17 /* C320 firmware not supported */
82#define FC_SetCntIrq 18 /* C320 firmware not supported */
83#define FC_SetBreakIrq 19
84#define FC_SetLineIrq 20
85#define FC_SetFlowCtl 21
86#define FC_GenIrq 22
87#define FC_InCD180 23
88#define FC_OutCD180 24
89#define FC_InUARTreg 23
90#define FC_OutUARTreg 24
91#define FC_SetXonXoff 25
92#define FC_OutCD180CCR 26
93#define FC_ExtIQueue 27
94#define FC_ExtOQueue 28
95#define FC_ClrLineIrq 29
96#define FC_HWFlowCtl 30
97#define FC_GetClockRate 35
98#define FC_SetBaud 36
99#define FC_SetDataMode 41
100#define FC_GetCCSR 43
101#define FC_GetDataError 45
102#define FC_RxControl 50
103#define FC_ImmSend 51
104#define FC_SetXonState 52
105#define FC_SetXoffState 53
106#define FC_SetRxFIFOTrig 54
107#define FC_SetTxFIFOCnt 55
108#define FC_UnixRate 56
109#define FC_UnixResetTimer 57
110
111#define RxFIFOTrig1 0
112#define RxFIFOTrig4 1
113#define RxFIFOTrig8 2
114#define RxFIFOTrig14 3
115
116/*
117 * Dual-Ported RAM
118 */
119#define DRAM_global 0
120#define INT_data (DRAM_global + 0)
121#define Config_base (DRAM_global + 0x108)
122
123#define IRQindex (INT_data + 0)
124#define IRQpending (INT_data + 4)
125#define IRQtable (INT_data + 8)
126
127/*
128 * Interrupt Status
129 */
130#define IntrRx 0x01 /* receiver data O.K. */
131#define IntrTx 0x02 /* transmit buffer empty */
132#define IntrFunc 0x04 /* function complete */
133#define IntrBreak 0x08 /* received break */
134#define IntrLine 0x10 /* line status change
135 for transmitter */
136#define IntrIntr 0x20 /* received INTR code */
137#define IntrQuit 0x40 /* received QUIT code */
138#define IntrEOF 0x80 /* received EOF code */
139
140#define IntrRxTrigger 0x100 /* rx data count reach tigger value */
141#define IntrTxTrigger 0x200 /* tx data count below trigger value */
142
143#define Magic_no (Config_base + 0)
144#define Card_model_no (Config_base + 2)
145#define Total_ports (Config_base + 4)
146#define Module_cnt (Config_base + 8)
147#define Module_no (Config_base + 10)
148#define Timer_10ms (Config_base + 14)
149#define Disable_IRQ (Config_base + 20)
150#define TMS320_PORT1 (Config_base + 22)
151#define TMS320_PORT2 (Config_base + 24)
152#define TMS320_CLOCK (Config_base + 26)
153
154/*
155 * DATA BUFFER in DRAM
156 */
157#define Extern_table 0x400 /* Base address of the external table
158 (24 words * 64) total 3K bytes
159 (24 words * 128) total 6K bytes */
160#define Extern_size 0x60 /* 96 bytes */
161#define RXrptr 0x00 /* read pointer for RX buffer */
162#define RXwptr 0x02 /* write pointer for RX buffer */
163#define TXrptr 0x04 /* read pointer for TX buffer */
164#define TXwptr 0x06 /* write pointer for TX buffer */
165#define HostStat 0x08 /* IRQ flag and general flag */
166#define FlagStat 0x0A
167#define FlowControl 0x0C /* B7 B6 B5 B4 B3 B2 B1 B0 */
168 /* x x x x | | | | */
169 /* | | | + CTS flow */
170 /* | | +--- RTS flow */
171 /* | +------ TX Xon/Xoff */
172 /* +--------- RX Xon/Xoff */
173#define Break_cnt 0x0E /* received break count */
174#define CD180TXirq 0x10 /* if non-0: enable TX irq */
175#define RX_mask 0x12
176#define TX_mask 0x14
177#define Ofs_rxb 0x16
178#define Ofs_txb 0x18
179#define Page_rxb 0x1A
180#define Page_txb 0x1C
181#define EndPage_rxb 0x1E
182#define EndPage_txb 0x20
183#define Data_error 0x22
184#define RxTrigger 0x28
185#define TxTrigger 0x2a
186
187#define rRXwptr 0x34
188#define Low_water 0x36
189
190#define FuncCode 0x40
191#define FuncArg 0x42
192#define FuncArg1 0x44
193
194#define C218rx_size 0x2000 /* 8K bytes */
195#define C218tx_size 0x8000 /* 32K bytes */
196
197#define C218rx_mask (C218rx_size - 1)
198#define C218tx_mask (C218tx_size - 1)
199
200#define C320p8rx_size 0x2000
201#define C320p8tx_size 0x8000
202#define C320p8rx_mask (C320p8rx_size - 1)
203#define C320p8tx_mask (C320p8tx_size - 1)
204
205#define C320p16rx_size 0x2000
206#define C320p16tx_size 0x4000
207#define C320p16rx_mask (C320p16rx_size - 1)
208#define C320p16tx_mask (C320p16tx_size - 1)
209
210#define C320p24rx_size 0x2000
211#define C320p24tx_size 0x2000
212#define C320p24rx_mask (C320p24rx_size - 1)
213#define C320p24tx_mask (C320p24tx_size - 1)
214
215#define C320p32rx_size 0x1000
216#define C320p32tx_size 0x1000
217#define C320p32rx_mask (C320p32rx_size - 1)
218#define C320p32tx_mask (C320p32tx_size - 1)
219
220#define Page_size 0x2000U
221#define Page_mask (Page_size - 1)
222#define C218rx_spage 3
223#define C218tx_spage 4
224#define C218rx_pageno 1
225#define C218tx_pageno 4
226#define C218buf_pageno 5
227
228#define C320p8rx_spage 3
229#define C320p8tx_spage 4
230#define C320p8rx_pgno 1
231#define C320p8tx_pgno 4
232#define C320p8buf_pgno 5
233
234#define C320p16rx_spage 3
235#define C320p16tx_spage 4
236#define C320p16rx_pgno 1
237#define C320p16tx_pgno 2
238#define C320p16buf_pgno 3
239
240#define C320p24rx_spage 3
241#define C320p24tx_spage 4
242#define C320p24rx_pgno 1
243#define C320p24tx_pgno 1
244#define C320p24buf_pgno 2
245
246#define C320p32rx_spage 3
247#define C320p32tx_ofs C320p32rx_size
248#define C320p32tx_spage 3
249#define C320p32buf_pgno 1
250
251/*
252 * Host Status
253 */
254#define WakeupRx 0x01
255#define WakeupTx 0x02
256#define WakeupBreak 0x08
257#define WakeupLine 0x10
258#define WakeupIntr 0x20
259#define WakeupQuit 0x40
260#define WakeupEOF 0x80 /* used in VTIME control */
261#define WakeupRxTrigger 0x100
262#define WakeupTxTrigger 0x200
263/*
264 * Flag status
265 */
266#define Rx_over 0x01
267#define Xoff_state 0x02
268#define Tx_flowOff 0x04
269#define Tx_enable 0x08
270#define CTS_state 0x10
271#define DSR_state 0x20
272#define DCD_state 0x80
273/*
274 * FlowControl
275 */
276#define CTS_FlowCtl 1
277#define RTS_FlowCtl 2
278#define Tx_FlowCtl 4
279#define Rx_FlowCtl 8
280#define IXM_IXANY 0x10
281
282#define LowWater 128
283
284#define DTR_ON 1
285#define RTS_ON 2
286#define CTS_ON 1
287#define DSR_ON 2
288#define DCD_ON 8
289
290/* mode definition */
291#define MX_CS8 0x03
292#define MX_CS7 0x02
293#define MX_CS6 0x01
294#define MX_CS5 0x00
295
296#define MX_STOP1 0x00
297#define MX_STOP15 0x04
298#define MX_STOP2 0x08
299
300#define MX_PARNONE 0x00
301#define MX_PAREVEN 0x40
302#define MX_PARODD 0xC0
303
304#endif
diff --git a/drivers/char/mspec.c b/drivers/char/mspec.c
index ff146c2b08fd..fe2a95b5d3c0 100644
--- a/drivers/char/mspec.c
+++ b/drivers/char/mspec.c
@@ -180,7 +180,7 @@ mspec_close(struct vm_area_struct *vma)
180 my_page = vdata->maddr[index]; 180 my_page = vdata->maddr[index];
181 vdata->maddr[index] = 0; 181 vdata->maddr[index] = 0;
182 if (!mspec_zero_block(my_page, PAGE_SIZE)) 182 if (!mspec_zero_block(my_page, PAGE_SIZE))
183 uncached_free_page(my_page); 183 uncached_free_page(my_page, 1);
184 else 184 else
185 printk(KERN_WARNING "mspec_close(): " 185 printk(KERN_WARNING "mspec_close(): "
186 "failed to zero page %ld\n", my_page); 186 "failed to zero page %ld\n", my_page);
@@ -209,7 +209,7 @@ mspec_nopfn(struct vm_area_struct *vma, unsigned long address)
209 index = (address - vdata->vm_start) >> PAGE_SHIFT; 209 index = (address - vdata->vm_start) >> PAGE_SHIFT;
210 maddr = (volatile unsigned long) vdata->maddr[index]; 210 maddr = (volatile unsigned long) vdata->maddr[index];
211 if (maddr == 0) { 211 if (maddr == 0) {
212 maddr = uncached_alloc_page(numa_node_id()); 212 maddr = uncached_alloc_page(numa_node_id(), 1);
213 if (maddr == 0) 213 if (maddr == 0)
214 return NOPFN_OOM; 214 return NOPFN_OOM;
215 215
@@ -218,7 +218,7 @@ mspec_nopfn(struct vm_area_struct *vma, unsigned long address)
218 vdata->count++; 218 vdata->count++;
219 vdata->maddr[index] = maddr; 219 vdata->maddr[index] = maddr;
220 } else { 220 } else {
221 uncached_free_page(maddr); 221 uncached_free_page(maddr, 1);
222 maddr = vdata->maddr[index]; 222 maddr = vdata->maddr[index];
223 } 223 }
224 spin_unlock(&vdata->lock); 224 spin_unlock(&vdata->lock);
@@ -367,7 +367,7 @@ mspec_init(void)
367 int nasid; 367 int nasid;
368 unsigned long phys; 368 unsigned long phys;
369 369
370 scratch_page[nid] = uncached_alloc_page(nid); 370 scratch_page[nid] = uncached_alloc_page(nid, 1);
371 if (scratch_page[nid] == 0) 371 if (scratch_page[nid] == 0)
372 goto free_scratch_pages; 372 goto free_scratch_pages;
373 phys = __pa(scratch_page[nid]); 373 phys = __pa(scratch_page[nid]);
@@ -414,7 +414,7 @@ mspec_init(void)
414 free_scratch_pages: 414 free_scratch_pages:
415 for_each_node(nid) { 415 for_each_node(nid) {
416 if (scratch_page[nid] != 0) 416 if (scratch_page[nid] != 0)
417 uncached_free_page(scratch_page[nid]); 417 uncached_free_page(scratch_page[nid], 1);
418 } 418 }
419 return ret; 419 return ret;
420} 420}
@@ -431,7 +431,7 @@ mspec_exit(void)
431 431
432 for_each_node(nid) { 432 for_each_node(nid) {
433 if (scratch_page[nid] != 0) 433 if (scratch_page[nid] != 0)
434 uncached_free_page(scratch_page[nid]); 434 uncached_free_page(scratch_page[nid], 1);
435 } 435 }
436 } 436 }
437} 437}
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index 68c2e9234691..4b81a85c5b53 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -307,6 +307,200 @@ static unsigned char mxser_msr[MXSER_PORTS + 1];
307static struct mxser_mon_ext mon_data_ext; 307static struct mxser_mon_ext mon_data_ext;
308static int mxser_set_baud_method[MXSER_PORTS + 1]; 308static int mxser_set_baud_method[MXSER_PORTS + 1];
309 309
310static void mxser_enable_must_enchance_mode(unsigned long baseio)
311{
312 u8 oldlcr;
313 u8 efr;
314
315 oldlcr = inb(baseio + UART_LCR);
316 outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR);
317
318 efr = inb(baseio + MOXA_MUST_EFR_REGISTER);
319 efr |= MOXA_MUST_EFR_EFRB_ENABLE;
320
321 outb(efr, baseio + MOXA_MUST_EFR_REGISTER);
322 outb(oldlcr, baseio + UART_LCR);
323}
324
325static void mxser_disable_must_enchance_mode(unsigned long baseio)
326{
327 u8 oldlcr;
328 u8 efr;
329
330 oldlcr = inb(baseio + UART_LCR);
331 outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR);
332
333 efr = inb(baseio + MOXA_MUST_EFR_REGISTER);
334 efr &= ~MOXA_MUST_EFR_EFRB_ENABLE;
335
336 outb(efr, baseio + MOXA_MUST_EFR_REGISTER);
337 outb(oldlcr, baseio + UART_LCR);
338}
339
340static void mxser_set_must_xon1_value(unsigned long baseio, u8 value)
341{
342 u8 oldlcr;
343 u8 efr;
344
345 oldlcr = inb(baseio + UART_LCR);
346 outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR);
347
348 efr = inb(baseio + MOXA_MUST_EFR_REGISTER);
349 efr &= ~MOXA_MUST_EFR_BANK_MASK;
350 efr |= MOXA_MUST_EFR_BANK0;
351
352 outb(efr, baseio + MOXA_MUST_EFR_REGISTER);
353 outb(value, baseio + MOXA_MUST_XON1_REGISTER);
354 outb(oldlcr, baseio + UART_LCR);
355}
356
357static void mxser_set_must_xoff1_value(unsigned long baseio, u8 value)
358{
359 u8 oldlcr;
360 u8 efr;
361
362 oldlcr = inb(baseio + UART_LCR);
363 outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR);
364
365 efr = inb(baseio + MOXA_MUST_EFR_REGISTER);
366 efr &= ~MOXA_MUST_EFR_BANK_MASK;
367 efr |= MOXA_MUST_EFR_BANK0;
368
369 outb(efr, baseio + MOXA_MUST_EFR_REGISTER);
370 outb(value, baseio + MOXA_MUST_XOFF1_REGISTER);
371 outb(oldlcr, baseio + UART_LCR);
372}
373
374static void mxser_set_must_fifo_value(struct mxser_port *info)
375{
376 u8 oldlcr;
377 u8 efr;
378
379 oldlcr = inb(info->ioaddr + UART_LCR);
380 outb(MOXA_MUST_ENTER_ENCHANCE, info->ioaddr + UART_LCR);
381
382 efr = inb(info->ioaddr + MOXA_MUST_EFR_REGISTER);
383 efr &= ~MOXA_MUST_EFR_BANK_MASK;
384 efr |= MOXA_MUST_EFR_BANK1;
385
386 outb(efr, info->ioaddr + MOXA_MUST_EFR_REGISTER);
387 outb((u8)info->rx_high_water, info->ioaddr + MOXA_MUST_RBRTH_REGISTER);
388 outb((u8)info->rx_trigger, info->ioaddr + MOXA_MUST_RBRTI_REGISTER);
389 outb((u8)info->rx_low_water, info->ioaddr + MOXA_MUST_RBRTL_REGISTER);
390 outb(oldlcr, info->ioaddr + UART_LCR);
391}
392
393static void mxser_set_must_enum_value(unsigned long baseio, u8 value)
394{
395 u8 oldlcr;
396 u8 efr;
397
398 oldlcr = inb(baseio + UART_LCR);
399 outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR);
400
401 efr = inb(baseio + MOXA_MUST_EFR_REGISTER);
402 efr &= ~MOXA_MUST_EFR_BANK_MASK;
403 efr |= MOXA_MUST_EFR_BANK2;
404
405 outb(efr, baseio + MOXA_MUST_EFR_REGISTER);
406 outb(value, baseio + MOXA_MUST_ENUM_REGISTER);
407 outb(oldlcr, baseio + UART_LCR);
408}
409
410static void mxser_get_must_hardware_id(unsigned long baseio, u8 *pId)
411{
412 u8 oldlcr;
413 u8 efr;
414
415 oldlcr = inb(baseio + UART_LCR);
416 outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR);
417
418 efr = inb(baseio + MOXA_MUST_EFR_REGISTER);
419 efr &= ~MOXA_MUST_EFR_BANK_MASK;
420 efr |= MOXA_MUST_EFR_BANK2;
421
422 outb(efr, baseio + MOXA_MUST_EFR_REGISTER);
423 *pId = inb(baseio + MOXA_MUST_HWID_REGISTER);
424 outb(oldlcr, baseio + UART_LCR);
425}
426
427static void SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(unsigned long baseio)
428{
429 u8 oldlcr;
430 u8 efr;
431
432 oldlcr = inb(baseio + UART_LCR);
433 outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR);
434
435 efr = inb(baseio + MOXA_MUST_EFR_REGISTER);
436 efr &= ~MOXA_MUST_EFR_SF_MASK;
437
438 outb(efr, baseio + MOXA_MUST_EFR_REGISTER);
439 outb(oldlcr, baseio + UART_LCR);
440}
441
442static void mxser_enable_must_tx_software_flow_control(unsigned long baseio)
443{
444 u8 oldlcr;
445 u8 efr;
446
447 oldlcr = inb(baseio + UART_LCR);
448 outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR);
449
450 efr = inb(baseio + MOXA_MUST_EFR_REGISTER);
451 efr &= ~MOXA_MUST_EFR_SF_TX_MASK;
452 efr |= MOXA_MUST_EFR_SF_TX1;
453
454 outb(efr, baseio + MOXA_MUST_EFR_REGISTER);
455 outb(oldlcr, baseio + UART_LCR);
456}
457
458static void mxser_disable_must_tx_software_flow_control(unsigned long baseio)
459{
460 u8 oldlcr;
461 u8 efr;
462
463 oldlcr = inb(baseio + UART_LCR);
464 outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR);
465
466 efr = inb(baseio + MOXA_MUST_EFR_REGISTER);
467 efr &= ~MOXA_MUST_EFR_SF_TX_MASK;
468
469 outb(efr, baseio + MOXA_MUST_EFR_REGISTER);
470 outb(oldlcr, baseio + UART_LCR);
471}
472
473static void mxser_enable_must_rx_software_flow_control(unsigned long baseio)
474{
475 u8 oldlcr;
476 u8 efr;
477
478 oldlcr = inb(baseio + UART_LCR);
479 outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR);
480
481 efr = inb(baseio + MOXA_MUST_EFR_REGISTER);
482 efr &= ~MOXA_MUST_EFR_SF_RX_MASK;
483 efr |= MOXA_MUST_EFR_SF_RX1;
484
485 outb(efr, baseio + MOXA_MUST_EFR_REGISTER);
486 outb(oldlcr, baseio + UART_LCR);
487}
488
489static void mxser_disable_must_rx_software_flow_control(unsigned long baseio)
490{
491 u8 oldlcr;
492 u8 efr;
493
494 oldlcr = inb(baseio + UART_LCR);
495 outb(MOXA_MUST_ENTER_ENCHANCE, baseio + UART_LCR);
496
497 efr = inb(baseio + MOXA_MUST_EFR_REGISTER);
498 efr &= ~MOXA_MUST_EFR_SF_RX_MASK;
499
500 outb(efr, baseio + MOXA_MUST_EFR_REGISTER);
501 outb(oldlcr, baseio + UART_LCR);
502}
503
310#ifdef CONFIG_PCI 504#ifdef CONFIG_PCI
311static int __devinit CheckIsMoxaMust(unsigned long io) 505static int __devinit CheckIsMoxaMust(unsigned long io)
312{ 506{
@@ -314,16 +508,16 @@ static int __devinit CheckIsMoxaMust(unsigned long io)
314 int i; 508 int i;
315 509
316 outb(0, io + UART_LCR); 510 outb(0, io + UART_LCR);
317 DISABLE_MOXA_MUST_ENCHANCE_MODE(io); 511 mxser_disable_must_enchance_mode(io);
318 oldmcr = inb(io + UART_MCR); 512 oldmcr = inb(io + UART_MCR);
319 outb(0, io + UART_MCR); 513 outb(0, io + UART_MCR);
320 SET_MOXA_MUST_XON1_VALUE(io, 0x11); 514 mxser_set_must_xon1_value(io, 0x11);
321 if ((hwid = inb(io + UART_MCR)) != 0) { 515 if ((hwid = inb(io + UART_MCR)) != 0) {
322 outb(oldmcr, io + UART_MCR); 516 outb(oldmcr, io + UART_MCR);
323 return MOXA_OTHER_UART; 517 return MOXA_OTHER_UART;
324 } 518 }
325 519
326 GET_MOXA_MUST_HARDWARE_ID(io, &hwid); 520 mxser_get_must_hardware_id(io, &hwid);
327 for (i = 1; i < UART_INFO_NUM; i++) { /* 0 = OTHER_UART */ 521 for (i = 1; i < UART_INFO_NUM; i++) { /* 0 = OTHER_UART */
328 if (hwid == Gpci_uart_info[i].type) 522 if (hwid == Gpci_uart_info[i].type)
329 return (int)hwid; 523 return (int)hwid;
@@ -494,10 +688,10 @@ static int mxser_set_baud(struct mxser_port *info, long newspd)
494 } else 688 } else
495 quot /= newspd; 689 quot /= newspd;
496 690
497 SET_MOXA_MUST_ENUM_VALUE(info->ioaddr, quot); 691 mxser_set_must_enum_value(info->ioaddr, quot);
498 } else 692 } else
499#endif 693#endif
500 SET_MOXA_MUST_ENUM_VALUE(info->ioaddr, 0); 694 mxser_set_must_enum_value(info->ioaddr, 0);
501 695
502 return 0; 696 return 0;
503} 697}
@@ -553,14 +747,14 @@ static int mxser_change_speed(struct mxser_port *info,
553 if (info->board->chip_flag) { 747 if (info->board->chip_flag) {
554 fcr = UART_FCR_ENABLE_FIFO; 748 fcr = UART_FCR_ENABLE_FIFO;
555 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE; 749 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
556 SET_MOXA_MUST_FIFO_VALUE(info); 750 mxser_set_must_fifo_value(info);
557 } else 751 } else
558 fcr = 0; 752 fcr = 0;
559 } else { 753 } else {
560 fcr = UART_FCR_ENABLE_FIFO; 754 fcr = UART_FCR_ENABLE_FIFO;
561 if (info->board->chip_flag) { 755 if (info->board->chip_flag) {
562 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE; 756 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
563 SET_MOXA_MUST_FIFO_VALUE(info); 757 mxser_set_must_fifo_value(info);
564 } else { 758 } else {
565 switch (info->rx_trigger) { 759 switch (info->rx_trigger) {
566 case 1: 760 case 1:
@@ -657,17 +851,21 @@ static int mxser_change_speed(struct mxser_port *info,
657 } 851 }
658 } 852 }
659 if (info->board->chip_flag) { 853 if (info->board->chip_flag) {
660 SET_MOXA_MUST_XON1_VALUE(info->ioaddr, START_CHAR(info->tty)); 854 mxser_set_must_xon1_value(info->ioaddr, START_CHAR(info->tty));
661 SET_MOXA_MUST_XOFF1_VALUE(info->ioaddr, STOP_CHAR(info->tty)); 855 mxser_set_must_xoff1_value(info->ioaddr, STOP_CHAR(info->tty));
662 if (I_IXON(info->tty)) { 856 if (I_IXON(info->tty)) {
663 ENABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->ioaddr); 857 mxser_enable_must_rx_software_flow_control(
858 info->ioaddr);
664 } else { 859 } else {
665 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->ioaddr); 860 mxser_disable_must_rx_software_flow_control(
861 info->ioaddr);
666 } 862 }
667 if (I_IXOFF(info->tty)) { 863 if (I_IXOFF(info->tty)) {
668 ENABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->ioaddr); 864 mxser_enable_must_tx_software_flow_control(
865 info->ioaddr);
669 } else { 866 } else {
670 DISABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->ioaddr); 867 mxser_disable_must_tx_software_flow_control(
868 info->ioaddr);
671 } 869 }
672 } 870 }
673 871
@@ -927,6 +1125,27 @@ static int mxser_open(struct tty_struct *tty, struct file *filp)
927 return 0; 1125 return 0;
928} 1126}
929 1127
1128static void mxser_flush_buffer(struct tty_struct *tty)
1129{
1130 struct mxser_port *info = tty->driver_data;
1131 char fcr;
1132 unsigned long flags;
1133
1134
1135 spin_lock_irqsave(&info->slock, flags);
1136 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1137
1138 fcr = inb(info->ioaddr + UART_FCR);
1139 outb((fcr | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
1140 info->ioaddr + UART_FCR);
1141 outb(fcr, info->ioaddr + UART_FCR);
1142
1143 spin_unlock_irqrestore(&info->slock, flags);
1144
1145 tty_wakeup(tty);
1146}
1147
1148
930/* 1149/*
931 * This routine is called when the serial port gets closed. First, we 1150 * This routine is called when the serial port gets closed. First, we
932 * wait for the last remaining data to be sent. Then, we unlink its 1151 * wait for the last remaining data to be sent. Then, we unlink its
@@ -1013,9 +1232,7 @@ static void mxser_close(struct tty_struct *tty, struct file *filp)
1013 } 1232 }
1014 mxser_shutdown(info); 1233 mxser_shutdown(info);
1015 1234
1016 if (tty->driver->flush_buffer) 1235 mxser_flush_buffer(tty);
1017 tty->driver->flush_buffer(tty);
1018
1019 tty_ldisc_flush(tty); 1236 tty_ldisc_flush(tty);
1020 1237
1021 tty->closing = 0; 1238 tty->closing = 0;
@@ -1072,16 +1289,16 @@ static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int cou
1072 return total; 1289 return total;
1073} 1290}
1074 1291
1075static void mxser_put_char(struct tty_struct *tty, unsigned char ch) 1292static int mxser_put_char(struct tty_struct *tty, unsigned char ch)
1076{ 1293{
1077 struct mxser_port *info = tty->driver_data; 1294 struct mxser_port *info = tty->driver_data;
1078 unsigned long flags; 1295 unsigned long flags;
1079 1296
1080 if (!info->xmit_buf) 1297 if (!info->xmit_buf)
1081 return; 1298 return 0;
1082 1299
1083 if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1) 1300 if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
1084 return; 1301 return 0;
1085 1302
1086 spin_lock_irqsave(&info->slock, flags); 1303 spin_lock_irqsave(&info->slock, flags);
1087 info->xmit_buf[info->xmit_head++] = ch; 1304 info->xmit_buf[info->xmit_head++] = ch;
@@ -1099,6 +1316,7 @@ static void mxser_put_char(struct tty_struct *tty, unsigned char ch)
1099 spin_unlock_irqrestore(&info->slock, flags); 1316 spin_unlock_irqrestore(&info->slock, flags);
1100 } 1317 }
1101 } 1318 }
1319 return 1;
1102} 1320}
1103 1321
1104 1322
@@ -1142,26 +1360,6 @@ static int mxser_chars_in_buffer(struct tty_struct *tty)
1142 return info->xmit_cnt; 1360 return info->xmit_cnt;
1143} 1361}
1144 1362
1145static void mxser_flush_buffer(struct tty_struct *tty)
1146{
1147 struct mxser_port *info = tty->driver_data;
1148 char fcr;
1149 unsigned long flags;
1150
1151
1152 spin_lock_irqsave(&info->slock, flags);
1153 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1154
1155 fcr = inb(info->ioaddr + UART_FCR);
1156 outb((fcr | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
1157 info->ioaddr + UART_FCR);
1158 outb(fcr, info->ioaddr + UART_FCR);
1159
1160 spin_unlock_irqrestore(&info->slock, flags);
1161
1162 tty_wakeup(tty);
1163}
1164
1165/* 1363/*
1166 * ------------------------------------------------------------ 1364 * ------------------------------------------------------------
1167 * friends of mxser_ioctl() 1365 * friends of mxser_ioctl()
@@ -1460,6 +1658,7 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1460 struct mxser_port *port; 1658 struct mxser_port *port;
1461 int result, status; 1659 int result, status;
1462 unsigned int i, j; 1660 unsigned int i, j;
1661 int ret = 0;
1463 1662
1464 switch (cmd) { 1663 switch (cmd) {
1465 case MOXA_GET_MAJOR: 1664 case MOXA_GET_MAJOR:
@@ -1467,18 +1666,21 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1467 1666
1468 case MOXA_CHKPORTENABLE: 1667 case MOXA_CHKPORTENABLE:
1469 result = 0; 1668 result = 0;
1470 1669 lock_kernel();
1471 for (i = 0; i < MXSER_BOARDS; i++) 1670 for (i = 0; i < MXSER_BOARDS; i++)
1472 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) 1671 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++)
1473 if (mxser_boards[i].ports[j].ioaddr) 1672 if (mxser_boards[i].ports[j].ioaddr)
1474 result |= (1 << i); 1673 result |= (1 << i);
1475 1674 unlock_kernel();
1476 return put_user(result, (unsigned long __user *)argp); 1675 return put_user(result, (unsigned long __user *)argp);
1477 case MOXA_GETDATACOUNT: 1676 case MOXA_GETDATACOUNT:
1677 lock_kernel();
1478 if (copy_to_user(argp, &mxvar_log, sizeof(mxvar_log))) 1678 if (copy_to_user(argp, &mxvar_log, sizeof(mxvar_log)))
1479 return -EFAULT; 1679 ret = -EFAULT;
1480 return 0; 1680 unlock_kernel();
1681 return ret;
1481 case MOXA_GETMSTATUS: 1682 case MOXA_GETMSTATUS:
1683 lock_kernel();
1482 for (i = 0; i < MXSER_BOARDS; i++) 1684 for (i = 0; i < MXSER_BOARDS; i++)
1483 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) { 1685 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) {
1484 port = &mxser_boards[i].ports[j]; 1686 port = &mxser_boards[i].ports[j];
@@ -1515,6 +1717,7 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1515 else 1717 else
1516 GMStatus[i].cts = 0; 1718 GMStatus[i].cts = 0;
1517 } 1719 }
1720 unlock_kernel();
1518 if (copy_to_user(argp, GMStatus, 1721 if (copy_to_user(argp, GMStatus,
1519 sizeof(struct mxser_mstatus) * MXSER_PORTS)) 1722 sizeof(struct mxser_mstatus) * MXSER_PORTS))
1520 return -EFAULT; 1723 return -EFAULT;
@@ -1524,7 +1727,8 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1524 unsigned long opmode; 1727 unsigned long opmode;
1525 unsigned cflag, iflag; 1728 unsigned cflag, iflag;
1526 1729
1527 for (i = 0; i < MXSER_BOARDS; i++) 1730 lock_kernel();
1731 for (i = 0; i < MXSER_BOARDS; i++) {
1528 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) { 1732 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) {
1529 port = &mxser_boards[i].ports[j]; 1733 port = &mxser_boards[i].ports[j];
1530 if (!port->ioaddr) 1734 if (!port->ioaddr)
@@ -1589,13 +1793,14 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1589 mon_data_ext.iftype[i] = opmode; 1793 mon_data_ext.iftype[i] = opmode;
1590 1794
1591 } 1795 }
1592 if (copy_to_user(argp, &mon_data_ext, 1796 }
1593 sizeof(mon_data_ext))) 1797 unlock_kernel();
1594 return -EFAULT; 1798 if (copy_to_user(argp, &mon_data_ext,
1595 1799 sizeof(mon_data_ext)))
1596 return 0; 1800 return -EFAULT;
1597 1801 return 0;
1598 } default: 1802 }
1803 default:
1599 return -ENOIOCTLCMD; 1804 return -ENOIOCTLCMD;
1600 } 1805 }
1601 return 0; 1806 return 0;
@@ -1651,16 +1856,20 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1651 opmode != RS422_MODE && 1856 opmode != RS422_MODE &&
1652 opmode != RS485_4WIRE_MODE) 1857 opmode != RS485_4WIRE_MODE)
1653 return -EFAULT; 1858 return -EFAULT;
1859 lock_kernel();
1654 mask = ModeMask[p]; 1860 mask = ModeMask[p];
1655 shiftbit = p * 2; 1861 shiftbit = p * 2;
1656 val = inb(info->opmode_ioaddr); 1862 val = inb(info->opmode_ioaddr);
1657 val &= mask; 1863 val &= mask;
1658 val |= (opmode << shiftbit); 1864 val |= (opmode << shiftbit);
1659 outb(val, info->opmode_ioaddr); 1865 outb(val, info->opmode_ioaddr);
1866 unlock_kernel();
1660 } else { 1867 } else {
1868 lock_kernel();
1661 shiftbit = p * 2; 1869 shiftbit = p * 2;
1662 opmode = inb(info->opmode_ioaddr) >> shiftbit; 1870 opmode = inb(info->opmode_ioaddr) >> shiftbit;
1663 opmode &= OP_MODE_MASK; 1871 opmode &= OP_MODE_MASK;
1872 unlock_kernel();
1664 if (put_user(opmode, (int __user *)argp)) 1873 if (put_user(opmode, (int __user *)argp))
1665 return -EFAULT; 1874 return -EFAULT;
1666 } 1875 }
@@ -1687,19 +1896,18 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1687 tty_wait_until_sent(tty, 0); 1896 tty_wait_until_sent(tty, 0);
1688 mxser_send_break(info, arg ? arg * (HZ / 10) : HZ / 4); 1897 mxser_send_break(info, arg ? arg * (HZ / 10) : HZ / 4);
1689 return 0; 1898 return 0;
1690 case TIOCGSOFTCAR:
1691 return put_user(!!C_CLOCAL(tty), (unsigned long __user *)argp);
1692 case TIOCSSOFTCAR:
1693 if (get_user(arg, (unsigned long __user *)argp))
1694 return -EFAULT;
1695 tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
1696 return 0;
1697 case TIOCGSERIAL: 1899 case TIOCGSERIAL:
1698 return mxser_get_serial_info(info, argp); 1900 lock_kernel();
1901 retval = mxser_get_serial_info(info, argp);
1902 unlock_kernel();
1903 return retval;
1699 case TIOCSSERIAL: 1904 case TIOCSSERIAL:
1700 return mxser_set_serial_info(info, argp); 1905 lock_kernel();
1906 retval = mxser_set_serial_info(info, argp);
1907 unlock_kernel();
1908 return retval;
1701 case TIOCSERGETLSR: /* Get line status register */ 1909 case TIOCSERGETLSR: /* Get line status register */
1702 return mxser_get_lsr_info(info, argp); 1910 return mxser_get_lsr_info(info, argp);
1703 /* 1911 /*
1704 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change 1912 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1705 * - mask passed in arg for lines of interest 1913 * - mask passed in arg for lines of interest
@@ -1746,24 +1954,27 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1746 case MOXA_HighSpeedOn: 1954 case MOXA_HighSpeedOn:
1747 return put_user(info->baud_base != 115200 ? 1 : 0, (int __user *)argp); 1955 return put_user(info->baud_base != 115200 ? 1 : 0, (int __user *)argp);
1748 case MOXA_SDS_RSTICOUNTER: 1956 case MOXA_SDS_RSTICOUNTER:
1957 lock_kernel();
1749 info->mon_data.rxcnt = 0; 1958 info->mon_data.rxcnt = 0;
1750 info->mon_data.txcnt = 0; 1959 info->mon_data.txcnt = 0;
1960 unlock_kernel();
1751 return 0; 1961 return 0;
1752 1962
1753 case MOXA_ASPP_OQUEUE:{ 1963 case MOXA_ASPP_OQUEUE:{
1754 int len, lsr; 1964 int len, lsr;
1755 1965
1966 lock_kernel();
1756 len = mxser_chars_in_buffer(tty); 1967 len = mxser_chars_in_buffer(tty);
1757
1758 lsr = inb(info->ioaddr + UART_LSR) & UART_LSR_TEMT; 1968 lsr = inb(info->ioaddr + UART_LSR) & UART_LSR_TEMT;
1759
1760 len += (lsr ? 0 : 1); 1969 len += (lsr ? 0 : 1);
1970 unlock_kernel();
1761 1971
1762 return put_user(len, (int __user *)argp); 1972 return put_user(len, (int __user *)argp);
1763 } 1973 }
1764 case MOXA_ASPP_MON: { 1974 case MOXA_ASPP_MON: {
1765 int mcr, status; 1975 int mcr, status;
1766 1976
1977 lock_kernel();
1767 status = mxser_get_msr(info->ioaddr, 1, tty->index); 1978 status = mxser_get_msr(info->ioaddr, 1, tty->index);
1768 mxser_check_modem_status(info, status); 1979 mxser_check_modem_status(info, status);
1769 1980
@@ -1782,7 +1993,7 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1782 info->mon_data.hold_reason |= NPPI_NOTIFY_CTSHOLD; 1993 info->mon_data.hold_reason |= NPPI_NOTIFY_CTSHOLD;
1783 else 1994 else
1784 info->mon_data.hold_reason &= ~NPPI_NOTIFY_CTSHOLD; 1995 info->mon_data.hold_reason &= ~NPPI_NOTIFY_CTSHOLD;
1785 1996 unlock_kernel();
1786 if (copy_to_user(argp, &info->mon_data, 1997 if (copy_to_user(argp, &info->mon_data,
1787 sizeof(struct mxser_mon))) 1998 sizeof(struct mxser_mon)))
1788 return -EFAULT; 1999 return -EFAULT;
@@ -1925,7 +2136,8 @@ static void mxser_set_termios(struct tty_struct *tty, struct ktermios *old_termi
1925 2136
1926 if (info->board->chip_flag) { 2137 if (info->board->chip_flag) {
1927 spin_lock_irqsave(&info->slock, flags); 2138 spin_lock_irqsave(&info->slock, flags);
1928 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->ioaddr); 2139 mxser_disable_must_rx_software_flow_control(
2140 info->ioaddr);
1929 spin_unlock_irqrestore(&info->slock, flags); 2141 spin_unlock_irqrestore(&info->slock, flags);
1930 } 2142 }
1931 2143
@@ -1979,6 +2191,7 @@ static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
1979 timeout, char_time); 2191 timeout, char_time);
1980 printk("jiff=%lu...", jiffies); 2192 printk("jiff=%lu...", jiffies);
1981#endif 2193#endif
2194 lock_kernel();
1982 while (!((lsr = inb(info->ioaddr + UART_LSR)) & UART_LSR_TEMT)) { 2195 while (!((lsr = inb(info->ioaddr + UART_LSR)) & UART_LSR_TEMT)) {
1983#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT 2196#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1984 printk("lsr = %d (jiff=%lu)...", lsr, jiffies); 2197 printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
@@ -1990,6 +2203,7 @@ static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
1990 break; 2203 break;
1991 } 2204 }
1992 set_current_state(TASK_RUNNING); 2205 set_current_state(TASK_RUNNING);
2206 unlock_kernel();
1993 2207
1994#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT 2208#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1995 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies); 2209 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
@@ -2342,7 +2556,7 @@ static int __devinit mxser_initbrd(struct mxser_board *brd,
2342 2556
2343 /* Enhance mode enabled here */ 2557 /* Enhance mode enabled here */
2344 if (brd->chip_flag != MOXA_OTHER_UART) 2558 if (brd->chip_flag != MOXA_OTHER_UART)
2345 ENABLE_MOXA_MUST_ENCHANCE_MODE(info->ioaddr); 2559 mxser_enable_must_enchance_mode(info->ioaddr);
2346 2560
2347 info->flags = ASYNC_SHARE_IRQ; 2561 info->flags = ASYNC_SHARE_IRQ;
2348 info->type = brd->uart_type; 2562 info->type = brd->uart_type;
diff --git a/drivers/char/mxser.h b/drivers/char/mxser.h
index 844171115954..41878a69203d 100644
--- a/drivers/char/mxser.h
+++ b/drivers/char/mxser.h
@@ -147,141 +147,4 @@
147/* Rx software flow control mask */ 147/* Rx software flow control mask */
148#define MOXA_MUST_EFR_SF_RX_MASK 0x03 148#define MOXA_MUST_EFR_SF_RX_MASK 0x03
149 149
150#define ENABLE_MOXA_MUST_ENCHANCE_MODE(baseio) do { \
151 u8 __oldlcr, __efr; \
152 __oldlcr = inb((baseio)+UART_LCR); \
153 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
154 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
155 __efr |= MOXA_MUST_EFR_EFRB_ENABLE; \
156 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
157 outb(__oldlcr, (baseio)+UART_LCR); \
158} while (0)
159
160#define DISABLE_MOXA_MUST_ENCHANCE_MODE(baseio) do { \
161 u8 __oldlcr, __efr; \
162 __oldlcr = inb((baseio)+UART_LCR); \
163 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
164 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
165 __efr &= ~MOXA_MUST_EFR_EFRB_ENABLE; \
166 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
167 outb(__oldlcr, (baseio)+UART_LCR); \
168} while (0)
169
170#define SET_MOXA_MUST_XON1_VALUE(baseio, Value) do { \
171 u8 __oldlcr, __efr; \
172 __oldlcr = inb((baseio)+UART_LCR); \
173 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
174 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
175 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
176 __efr |= MOXA_MUST_EFR_BANK0; \
177 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
178 outb((u8)(Value), (baseio)+MOXA_MUST_XON1_REGISTER); \
179 outb(__oldlcr, (baseio)+UART_LCR); \
180} while (0)
181
182#define SET_MOXA_MUST_XOFF1_VALUE(baseio, Value) do { \
183 u8 __oldlcr, __efr; \
184 __oldlcr = inb((baseio)+UART_LCR); \
185 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
186 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
187 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
188 __efr |= MOXA_MUST_EFR_BANK0; \
189 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
190 outb((u8)(Value), (baseio)+MOXA_MUST_XOFF1_REGISTER); \
191 outb(__oldlcr, (baseio)+UART_LCR); \
192} while (0)
193
194#define SET_MOXA_MUST_FIFO_VALUE(info) do { \
195 u8 __oldlcr, __efr; \
196 __oldlcr = inb((info)->ioaddr+UART_LCR); \
197 outb(MOXA_MUST_ENTER_ENCHANCE, (info)->ioaddr+UART_LCR);\
198 __efr = inb((info)->ioaddr+MOXA_MUST_EFR_REGISTER); \
199 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
200 __efr |= MOXA_MUST_EFR_BANK1; \
201 outb(__efr, (info)->ioaddr+MOXA_MUST_EFR_REGISTER); \
202 outb((u8)((info)->rx_high_water), (info)->ioaddr+ \
203 MOXA_MUST_RBRTH_REGISTER); \
204 outb((u8)((info)->rx_trigger), (info)->ioaddr+ \
205 MOXA_MUST_RBRTI_REGISTER); \
206 outb((u8)((info)->rx_low_water), (info)->ioaddr+ \
207 MOXA_MUST_RBRTL_REGISTER); \
208 outb(__oldlcr, (info)->ioaddr+UART_LCR); \
209} while (0)
210
211#define SET_MOXA_MUST_ENUM_VALUE(baseio, Value) do { \
212 u8 __oldlcr, __efr; \
213 __oldlcr = inb((baseio)+UART_LCR); \
214 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
215 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
216 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
217 __efr |= MOXA_MUST_EFR_BANK2; \
218 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
219 outb((u8)(Value), (baseio)+MOXA_MUST_ENUM_REGISTER); \
220 outb(__oldlcr, (baseio)+UART_LCR); \
221} while (0)
222
223#define GET_MOXA_MUST_HARDWARE_ID(baseio, pId) do { \
224 u8 __oldlcr, __efr; \
225 __oldlcr = inb((baseio)+UART_LCR); \
226 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
227 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
228 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
229 __efr |= MOXA_MUST_EFR_BANK2; \
230 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
231 *pId = inb((baseio)+MOXA_MUST_HWID_REGISTER); \
232 outb(__oldlcr, (baseio)+UART_LCR); \
233} while (0)
234
235#define SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(baseio) do { \
236 u8 __oldlcr, __efr; \
237 __oldlcr = inb((baseio)+UART_LCR); \
238 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
239 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
240 __efr &= ~MOXA_MUST_EFR_SF_MASK; \
241 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
242 outb(__oldlcr, (baseio)+UART_LCR); \
243} while (0)
244
245#define ENABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(baseio) do { \
246 u8 __oldlcr, __efr; \
247 __oldlcr = inb((baseio)+UART_LCR); \
248 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
249 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
250 __efr &= ~MOXA_MUST_EFR_SF_TX_MASK; \
251 __efr |= MOXA_MUST_EFR_SF_TX1; \
252 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
253 outb(__oldlcr, (baseio)+UART_LCR); \
254} while (0)
255
256#define DISABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(baseio) do { \
257 u8 __oldlcr, __efr; \
258 __oldlcr = inb((baseio)+UART_LCR); \
259 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
260 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
261 __efr &= ~MOXA_MUST_EFR_SF_TX_MASK; \
262 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
263 outb(__oldlcr, (baseio)+UART_LCR); \
264} while (0)
265
266#define ENABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(baseio) do { \
267 u8 __oldlcr, __efr; \
268 __oldlcr = inb((baseio)+UART_LCR); \
269 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
270 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
271 __efr &= ~MOXA_MUST_EFR_SF_RX_MASK; \
272 __efr |= MOXA_MUST_EFR_SF_RX1; \
273 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
274 outb(__oldlcr, (baseio)+UART_LCR); \
275} while (0)
276
277#define DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(baseio) do { \
278 u8 __oldlcr, __efr; \
279 __oldlcr = inb((baseio)+UART_LCR); \
280 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
281 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
282 __efr &= ~MOXA_MUST_EFR_SF_RX_MASK; \
283 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
284 outb(__oldlcr, (baseio)+UART_LCR); \
285} while (0)
286
287#endif 150#endif
diff --git a/drivers/char/n_hdlc.c b/drivers/char/n_hdlc.c
index 06803ed5568c..a35bfd7ee80e 100644
--- a/drivers/char/n_hdlc.c
+++ b/drivers/char/n_hdlc.c
@@ -342,12 +342,10 @@ 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
346 if (tty->ldisc.flush_buffer) 345 if (tty->ldisc.flush_buffer)
347 tty->ldisc.flush_buffer (tty); 346 tty->ldisc.flush_buffer(tty);
348 347
349 if (tty->driver->flush_buffer) 348 tty_driver_flush_buffer(tty);
350 tty->driver->flush_buffer (tty);
351 349
352 if (debuglevel >= DEBUG_LEVEL_INFO) 350 if (debuglevel >= DEBUG_LEVEL_INFO)
353 printk("%s(%d)n_hdlc_tty_open() success\n",__FILE__,__LINE__); 351 printk("%s(%d)n_hdlc_tty_open() success\n",__FILE__,__LINE__);
@@ -399,7 +397,7 @@ static void n_hdlc_send_frames(struct n_hdlc *n_hdlc, struct tty_struct *tty)
399 397
400 /* Send the next block of data to device */ 398 /* Send the next block of data to device */
401 tty->flags |= (1 << TTY_DO_WRITE_WAKEUP); 399 tty->flags |= (1 << TTY_DO_WRITE_WAKEUP);
402 actual = tty->driver->write(tty, tbuf->buf, tbuf->count); 400 actual = tty->ops->write(tty, tbuf->buf, tbuf->count);
403 401
404 /* rollback was possible and has been done */ 402 /* rollback was possible and has been done */
405 if (actual == -ERESTARTSYS) { 403 if (actual == -ERESTARTSYS) {
@@ -578,26 +576,36 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
578 return -EFAULT; 576 return -EFAULT;
579 } 577 }
580 578
579 lock_kernel();
580
581 for (;;) { 581 for (;;) {
582 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) 582 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) {
583 unlock_kernel();
583 return -EIO; 584 return -EIO;
585 }
584 586
585 n_hdlc = tty2n_hdlc (tty); 587 n_hdlc = tty2n_hdlc (tty);
586 if (!n_hdlc || n_hdlc->magic != HDLC_MAGIC || 588 if (!n_hdlc || n_hdlc->magic != HDLC_MAGIC ||
587 tty != n_hdlc->tty) 589 tty != n_hdlc->tty) {
590 unlock_kernel();
588 return 0; 591 return 0;
592 }
589 593
590 rbuf = n_hdlc_buf_get(&n_hdlc->rx_buf_list); 594 rbuf = n_hdlc_buf_get(&n_hdlc->rx_buf_list);
591 if (rbuf) 595 if (rbuf)
592 break; 596 break;
593 597
594 /* no data */ 598 /* no data */
595 if (file->f_flags & O_NONBLOCK) 599 if (file->f_flags & O_NONBLOCK) {
600 unlock_kernel();
596 return -EAGAIN; 601 return -EAGAIN;
602 }
597 603
598 interruptible_sleep_on (&tty->read_wait); 604 interruptible_sleep_on (&tty->read_wait);
599 if (signal_pending(current)) 605 if (signal_pending(current)) {
606 unlock_kernel();
600 return -EINTR; 607 return -EINTR;
608 }
601 } 609 }
602 610
603 if (rbuf->count > nr) 611 if (rbuf->count > nr)
@@ -618,7 +626,7 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
618 kfree(rbuf); 626 kfree(rbuf);
619 else 627 else
620 n_hdlc_buf_put(&n_hdlc->rx_free_buf_list,rbuf); 628 n_hdlc_buf_put(&n_hdlc->rx_free_buf_list,rbuf);
621 629 unlock_kernel();
622 return ret; 630 return ret;
623 631
624} /* end of n_hdlc_tty_read() */ 632} /* end of n_hdlc_tty_read() */
@@ -661,6 +669,8 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file,
661 count = maxframe; 669 count = maxframe;
662 } 670 }
663 671
672 lock_kernel();
673
664 add_wait_queue(&tty->write_wait, &wait); 674 add_wait_queue(&tty->write_wait, &wait);
665 set_current_state(TASK_INTERRUPTIBLE); 675 set_current_state(TASK_INTERRUPTIBLE);
666 676
@@ -695,7 +705,7 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file,
695 n_hdlc_buf_put(&n_hdlc->tx_buf_list,tbuf); 705 n_hdlc_buf_put(&n_hdlc->tx_buf_list,tbuf);
696 n_hdlc_send_frames(n_hdlc,tty); 706 n_hdlc_send_frames(n_hdlc,tty);
697 } 707 }
698 708 unlock_kernel();
699 return error; 709 return error;
700 710
701} /* end of n_hdlc_tty_write() */ 711} /* end of n_hdlc_tty_write() */
@@ -740,8 +750,7 @@ static int n_hdlc_tty_ioctl(struct tty_struct *tty, struct file *file,
740 750
741 case TIOCOUTQ: 751 case TIOCOUTQ:
742 /* get the pending tx byte count in the driver */ 752 /* get the pending tx byte count in the driver */
743 count = tty->driver->chars_in_buffer ? 753 count = tty_chars_in_buffer(tty);
744 tty->driver->chars_in_buffer(tty) : 0;
745 /* add size of next output frame in queue */ 754 /* add size of next output frame in queue */
746 spin_lock_irqsave(&n_hdlc->tx_buf_list.spinlock,flags); 755 spin_lock_irqsave(&n_hdlc->tx_buf_list.spinlock,flags);
747 if (n_hdlc->tx_buf_list.head) 756 if (n_hdlc->tx_buf_list.head)
diff --git a/drivers/char/n_r3964.c b/drivers/char/n_r3964.c
index 6b918b80f73e..902169062332 100644
--- a/drivers/char/n_r3964.c
+++ b/drivers/char/n_r3964.c
@@ -376,8 +376,9 @@ static void put_char(struct r3964_info *pInfo, unsigned char ch)
376 if (tty == NULL) 376 if (tty == NULL)
377 return; 377 return;
378 378
379 if (tty->driver->put_char) { 379 /* FIXME: put_char should not be called from an IRQ */
380 tty->driver->put_char(tty, ch); 380 if (tty->ops->put_char) {
381 tty->ops->put_char(tty, ch);
381 } 382 }
382 pInfo->bcc ^= ch; 383 pInfo->bcc ^= ch;
383} 384}
@@ -386,12 +387,9 @@ static void flush(struct r3964_info *pInfo)
386{ 387{
387 struct tty_struct *tty = pInfo->tty; 388 struct tty_struct *tty = pInfo->tty;
388 389
389 if (tty == NULL) 390 if (tty == NULL || tty->ops->flush_chars == NULL)
390 return; 391 return;
391 392 tty->ops->flush_chars(tty);
392 if (tty->driver->flush_chars) {
393 tty->driver->flush_chars(tty);
394 }
395} 393}
396 394
397static void trigger_transmit(struct r3964_info *pInfo) 395static void trigger_transmit(struct r3964_info *pInfo)
@@ -449,12 +447,11 @@ static void transmit_block(struct r3964_info *pInfo)
449 struct r3964_block_header *pBlock = pInfo->tx_first; 447 struct r3964_block_header *pBlock = pInfo->tx_first;
450 int room = 0; 448 int room = 0;
451 449
452 if ((tty == NULL) || (pBlock == NULL)) { 450 if (tty == NULL || pBlock == NULL) {
453 return; 451 return;
454 } 452 }
455 453
456 if (tty->driver->write_room) 454 room = tty_write_room(tty);
457 room = tty->driver->write_room(tty);
458 455
459 TRACE_PS("transmit_block %p, room %d, length %d", 456 TRACE_PS("transmit_block %p, room %d, length %d",
460 pBlock, room, pBlock->length); 457 pBlock, room, pBlock->length);
@@ -1075,12 +1072,15 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
1075 1072
1076 TRACE_L("read()"); 1073 TRACE_L("read()");
1077 1074
1075 lock_kernel();
1076
1078 pClient = findClient(pInfo, task_pid(current)); 1077 pClient = findClient(pInfo, task_pid(current));
1079 if (pClient) { 1078 if (pClient) {
1080 pMsg = remove_msg(pInfo, pClient); 1079 pMsg = remove_msg(pInfo, pClient);
1081 if (pMsg == NULL) { 1080 if (pMsg == NULL) {
1082 /* no messages available. */ 1081 /* no messages available. */
1083 if (file->f_flags & O_NONBLOCK) { 1082 if (file->f_flags & O_NONBLOCK) {
1083 unlock_kernel();
1084 return -EAGAIN; 1084 return -EAGAIN;
1085 } 1085 }
1086 /* block until there is a message: */ 1086 /* block until there is a message: */
@@ -1090,8 +1090,10 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
1090 1090
1091 /* If we still haven't got a message, we must have been signalled */ 1091 /* If we still haven't got a message, we must have been signalled */
1092 1092
1093 if (!pMsg) 1093 if (!pMsg) {
1094 unlock_kernel();
1094 return -EINTR; 1095 return -EINTR;
1096 }
1095 1097
1096 /* deliver msg to client process: */ 1098 /* deliver msg to client process: */
1097 theMsg.msg_id = pMsg->msg_id; 1099 theMsg.msg_id = pMsg->msg_id;
@@ -1102,12 +1104,15 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
1102 kfree(pMsg); 1104 kfree(pMsg);
1103 TRACE_M("r3964_read - msg kfree %p", pMsg); 1105 TRACE_M("r3964_read - msg kfree %p", pMsg);
1104 1106
1105 if (copy_to_user(buf, &theMsg, count)) 1107 if (copy_to_user(buf, &theMsg, count)) {
1108 unlock_kernel();
1106 return -EFAULT; 1109 return -EFAULT;
1110 }
1107 1111
1108 TRACE_PS("read - return %d", count); 1112 TRACE_PS("read - return %d", count);
1109 return count; 1113 return count;
1110 } 1114 }
1115 unlock_kernel();
1111 return -EPERM; 1116 return -EPERM;
1112} 1117}
1113 1118
@@ -1156,6 +1161,8 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
1156 pHeader->locks = 0; 1161 pHeader->locks = 0;
1157 pHeader->owner = NULL; 1162 pHeader->owner = NULL;
1158 1163
1164 lock_kernel();
1165
1159 pClient = findClient(pInfo, task_pid(current)); 1166 pClient = findClient(pInfo, task_pid(current));
1160 if (pClient) { 1167 if (pClient) {
1161 pHeader->owner = pClient; 1168 pHeader->owner = pClient;
@@ -1173,6 +1180,8 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
1173 add_tx_queue(pInfo, pHeader); 1180 add_tx_queue(pInfo, pHeader);
1174 trigger_transmit(pInfo); 1181 trigger_transmit(pInfo);
1175 1182
1183 unlock_kernel();
1184
1176 return 0; 1185 return 0;
1177} 1186}
1178 1187
diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c
index 0c09409fa45d..19105ec203f7 100644
--- a/drivers/char/n_tty.c
+++ b/drivers/char/n_tty.c
@@ -147,10 +147,8 @@ static void put_tty_queue(unsigned char c, struct tty_struct *tty)
147 147
148static void check_unthrottle(struct tty_struct *tty) 148static void check_unthrottle(struct tty_struct *tty)
149{ 149{
150 if (tty->count && 150 if (tty->count)
151 test_and_clear_bit(TTY_THROTTLED, &tty->flags) && 151 tty_unthrottle(tty);
152 tty->driver->unthrottle)
153 tty->driver->unthrottle(tty);
154} 152}
155 153
156/** 154/**
@@ -183,22 +181,24 @@ static void reset_buffer_flags(struct tty_struct *tty)
183 * at hangup) or when the N_TTY line discipline internally has to 181 * at hangup) or when the N_TTY line discipline internally has to
184 * clean the pending queue (for example some signals). 182 * clean the pending queue (for example some signals).
185 * 183 *
186 * FIXME: tty->ctrl_status is not spinlocked and relies on 184 * Locking: ctrl_lock
187 * lock_kernel() still.
188 */ 185 */
189 186
190static void n_tty_flush_buffer(struct tty_struct *tty) 187static void n_tty_flush_buffer(struct tty_struct *tty)
191{ 188{
189 unsigned long flags;
192 /* clear everything and unthrottle the driver */ 190 /* clear everything and unthrottle the driver */
193 reset_buffer_flags(tty); 191 reset_buffer_flags(tty);
194 192
195 if (!tty->link) 193 if (!tty->link)
196 return; 194 return;
197 195
196 spin_lock_irqsave(&tty->ctrl_lock, flags);
198 if (tty->link->packet) { 197 if (tty->link->packet) {
199 tty->ctrl_status |= TIOCPKT_FLUSHREAD; 198 tty->ctrl_status |= TIOCPKT_FLUSHREAD;
200 wake_up_interruptible(&tty->link->read_wait); 199 wake_up_interruptible(&tty->link->read_wait);
201 } 200 }
201 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
202} 202}
203 203
204/** 204/**
@@ -264,17 +264,18 @@ static inline int is_continuation(unsigned char c, struct tty_struct *tty)
264 * relevant in the world today. If you ever need them, add them here. 264 * relevant in the world today. If you ever need them, add them here.
265 * 265 *
266 * Called from both the receive and transmit sides and can be called 266 * Called from both the receive and transmit sides and can be called
267 * re-entrantly. Relies on lock_kernel() still. 267 * re-entrantly. Relies on lock_kernel() for tty->column state.
268 */ 268 */
269 269
270static int opost(unsigned char c, struct tty_struct *tty) 270static int opost(unsigned char c, struct tty_struct *tty)
271{ 271{
272 int space, spaces; 272 int space, spaces;
273 273
274 space = tty->driver->write_room(tty); 274 space = tty_write_room(tty);
275 if (!space) 275 if (!space)
276 return -1; 276 return -1;
277 277
278 lock_kernel();
278 if (O_OPOST(tty)) { 279 if (O_OPOST(tty)) {
279 switch (c) { 280 switch (c) {
280 case '\n': 281 case '\n':
@@ -283,7 +284,7 @@ static int opost(unsigned char c, struct tty_struct *tty)
283 if (O_ONLCR(tty)) { 284 if (O_ONLCR(tty)) {
284 if (space < 2) 285 if (space < 2)
285 return -1; 286 return -1;
286 tty->driver->put_char(tty, '\r'); 287 tty_put_char(tty, '\r');
287 tty->column = 0; 288 tty->column = 0;
288 } 289 }
289 tty->canon_column = tty->column; 290 tty->canon_column = tty->column;
@@ -305,7 +306,7 @@ static int opost(unsigned char c, struct tty_struct *tty)
305 if (space < spaces) 306 if (space < spaces)
306 return -1; 307 return -1;
307 tty->column += spaces; 308 tty->column += spaces;
308 tty->driver->write(tty, " ", spaces); 309 tty->ops->write(tty, " ", spaces);
309 return 0; 310 return 0;
310 } 311 }
311 tty->column += spaces; 312 tty->column += spaces;
@@ -322,7 +323,8 @@ static int opost(unsigned char c, struct tty_struct *tty)
322 break; 323 break;
323 } 324 }
324 } 325 }
325 tty->driver->put_char(tty, c); 326 tty_put_char(tty, c);
327 unlock_kernel();
326 return 0; 328 return 0;
327} 329}
328 330
@@ -337,7 +339,8 @@ static int opost(unsigned char c, struct tty_struct *tty)
337 * the simple cases normally found and helps to generate blocks of 339 * the simple cases normally found and helps to generate blocks of
338 * symbols for the console driver and thus improve performance. 340 * symbols for the console driver and thus improve performance.
339 * 341 *
340 * Called from write_chan under the tty layer write lock. 342 * Called from write_chan under the tty layer write lock. Relies
343 * on lock_kernel for the tty->column state.
341 */ 344 */
342 345
343static ssize_t opost_block(struct tty_struct *tty, 346static ssize_t opost_block(struct tty_struct *tty,
@@ -347,12 +350,13 @@ static ssize_t opost_block(struct tty_struct *tty,
347 int i; 350 int i;
348 const unsigned char *cp; 351 const unsigned char *cp;
349 352
350 space = tty->driver->write_room(tty); 353 space = tty_write_room(tty);
351 if (!space) 354 if (!space)
352 return 0; 355 return 0;
353 if (nr > space) 356 if (nr > space)
354 nr = space; 357 nr = space;
355 358
359 lock_kernel();
356 for (i = 0, cp = buf; i < nr; i++, cp++) { 360 for (i = 0, cp = buf; i < nr; i++, cp++) {
357 switch (*cp) { 361 switch (*cp) {
358 case '\n': 362 case '\n':
@@ -384,27 +388,15 @@ static ssize_t opost_block(struct tty_struct *tty,
384 } 388 }
385 } 389 }
386break_out: 390break_out:
387 if (tty->driver->flush_chars) 391 if (tty->ops->flush_chars)
388 tty->driver->flush_chars(tty); 392 tty->ops->flush_chars(tty);
389 i = tty->driver->write(tty, buf, i); 393 i = tty->ops->write(tty, buf, i);
394 unlock_kernel();
390 return i; 395 return i;
391} 396}
392 397
393 398
394/** 399/**
395 * put_char - write character to driver
396 * @c: character (or part of unicode symbol)
397 * @tty: terminal device
398 *
399 * Queue a byte to the driver layer for output
400 */
401
402static inline void put_char(unsigned char c, struct tty_struct *tty)
403{
404 tty->driver->put_char(tty, c);
405}
406
407/**
408 * echo_char - echo characters 400 * echo_char - echo characters
409 * @c: unicode byte to echo 401 * @c: unicode byte to echo
410 * @tty: terminal device 402 * @tty: terminal device
@@ -416,8 +408,8 @@ static inline void put_char(unsigned char c, struct tty_struct *tty)
416static void echo_char(unsigned char c, struct tty_struct *tty) 408static void echo_char(unsigned char c, struct tty_struct *tty)
417{ 409{
418 if (L_ECHOCTL(tty) && iscntrl(c) && c != '\t') { 410 if (L_ECHOCTL(tty) && iscntrl(c) && c != '\t') {
419 put_char('^', tty); 411 tty_put_char(tty, '^');
420 put_char(c ^ 0100, tty); 412 tty_put_char(tty, c ^ 0100);
421 tty->column += 2; 413 tty->column += 2;
422 } else 414 } else
423 opost(c, tty); 415 opost(c, tty);
@@ -426,7 +418,7 @@ static void echo_char(unsigned char c, struct tty_struct *tty)
426static inline void finish_erasing(struct tty_struct *tty) 418static inline void finish_erasing(struct tty_struct *tty)
427{ 419{
428 if (tty->erasing) { 420 if (tty->erasing) {
429 put_char('/', tty); 421 tty_put_char(tty, '/');
430 tty->column++; 422 tty->column++;
431 tty->erasing = 0; 423 tty->erasing = 0;
432 } 424 }
@@ -510,7 +502,7 @@ static void eraser(unsigned char c, struct tty_struct *tty)
510 if (L_ECHO(tty)) { 502 if (L_ECHO(tty)) {
511 if (L_ECHOPRT(tty)) { 503 if (L_ECHOPRT(tty)) {
512 if (!tty->erasing) { 504 if (!tty->erasing) {
513 put_char('\\', tty); 505 tty_put_char(tty, '\\');
514 tty->column++; 506 tty->column++;
515 tty->erasing = 1; 507 tty->erasing = 1;
516 } 508 }
@@ -518,7 +510,7 @@ static void eraser(unsigned char c, struct tty_struct *tty)
518 echo_char(c, tty); 510 echo_char(c, tty);
519 while (--cnt > 0) { 511 while (--cnt > 0) {
520 head = (head+1) & (N_TTY_BUF_SIZE-1); 512 head = (head+1) & (N_TTY_BUF_SIZE-1);
521 put_char(tty->read_buf[head], tty); 513 tty_put_char(tty, tty->read_buf[head]);
522 } 514 }
523 } else if (kill_type == ERASE && !L_ECHOE(tty)) { 515 } else if (kill_type == ERASE && !L_ECHOE(tty)) {
524 echo_char(ERASE_CHAR(tty), tty); 516 echo_char(ERASE_CHAR(tty), tty);
@@ -546,22 +538,22 @@ static void eraser(unsigned char c, struct tty_struct *tty)
546 /* Now backup to that column. */ 538 /* Now backup to that column. */
547 while (tty->column > col) { 539 while (tty->column > col) {
548 /* Can't use opost here. */ 540 /* Can't use opost here. */
549 put_char('\b', tty); 541 tty_put_char(tty, '\b');
550 if (tty->column > 0) 542 if (tty->column > 0)
551 tty->column--; 543 tty->column--;
552 } 544 }
553 } else { 545 } else {
554 if (iscntrl(c) && L_ECHOCTL(tty)) { 546 if (iscntrl(c) && L_ECHOCTL(tty)) {
555 put_char('\b', tty); 547 tty_put_char(tty, '\b');
556 put_char(' ', tty); 548 tty_put_char(tty, ' ');
557 put_char('\b', tty); 549 tty_put_char(tty, '\b');
558 if (tty->column > 0) 550 if (tty->column > 0)
559 tty->column--; 551 tty->column--;
560 } 552 }
561 if (!iscntrl(c) || L_ECHOCTL(tty)) { 553 if (!iscntrl(c) || L_ECHOCTL(tty)) {
562 put_char('\b', tty); 554 tty_put_char(tty, '\b');
563 put_char(' ', tty); 555 tty_put_char(tty, ' ');
564 put_char('\b', tty); 556 tty_put_char(tty, '\b');
565 if (tty->column > 0) 557 if (tty->column > 0)
566 tty->column--; 558 tty->column--;
567 } 559 }
@@ -592,8 +584,7 @@ static inline void isig(int sig, struct tty_struct *tty, int flush)
592 kill_pgrp(tty->pgrp, sig, 1); 584 kill_pgrp(tty->pgrp, sig, 1);
593 if (flush || !L_NOFLSH(tty)) { 585 if (flush || !L_NOFLSH(tty)) {
594 n_tty_flush_buffer(tty); 586 n_tty_flush_buffer(tty);
595 if (tty->driver->flush_buffer) 587 tty_driver_flush_buffer(tty);
596 tty->driver->flush_buffer(tty);
597 } 588 }
598} 589}
599 590
@@ -701,7 +692,7 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
701 692
702 if (tty->stopped && !tty->flow_stopped && I_IXON(tty) && 693 if (tty->stopped && !tty->flow_stopped && I_IXON(tty) &&
703 ((I_IXANY(tty) && c != START_CHAR(tty) && c != STOP_CHAR(tty)) || 694 ((I_IXANY(tty) && c != START_CHAR(tty) && c != STOP_CHAR(tty)) ||
704 c == INTR_CHAR(tty) || c == QUIT_CHAR(tty))) 695 c == INTR_CHAR(tty) || c == QUIT_CHAR(tty) || c == SUSP_CHAR(tty)))
705 start_tty(tty); 696 start_tty(tty);
706 697
707 if (tty->closing) { 698 if (tty->closing) {
@@ -725,7 +716,7 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
725 tty->lnext = 0; 716 tty->lnext = 0;
726 if (L_ECHO(tty)) { 717 if (L_ECHO(tty)) {
727 if (tty->read_cnt >= N_TTY_BUF_SIZE-1) { 718 if (tty->read_cnt >= N_TTY_BUF_SIZE-1) {
728 put_char('\a', tty); /* beep if no space */ 719 tty_put_char(tty, '\a'); /* beep if no space */
729 return; 720 return;
730 } 721 }
731 /* Record the column of first canon char. */ 722 /* Record the column of first canon char. */
@@ -739,13 +730,6 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
739 return; 730 return;
740 } 731 }
741 732
742 if (c == '\r') {
743 if (I_IGNCR(tty))
744 return;
745 if (I_ICRNL(tty))
746 c = '\n';
747 } else if (c == '\n' && I_INLCR(tty))
748 c = '\r';
749 if (I_IXON(tty)) { 733 if (I_IXON(tty)) {
750 if (c == START_CHAR(tty)) { 734 if (c == START_CHAR(tty)) {
751 start_tty(tty); 735 start_tty(tty);
@@ -756,6 +740,7 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
756 return; 740 return;
757 } 741 }
758 } 742 }
743
759 if (L_ISIG(tty)) { 744 if (L_ISIG(tty)) {
760 int signal; 745 int signal;
761 signal = SIGINT; 746 signal = SIGINT;
@@ -775,8 +760,7 @@ send_signal:
775 */ 760 */
776 if (!L_NOFLSH(tty)) { 761 if (!L_NOFLSH(tty)) {
777 n_tty_flush_buffer(tty); 762 n_tty_flush_buffer(tty);
778 if (tty->driver->flush_buffer) 763 tty_driver_flush_buffer(tty);
779 tty->driver->flush_buffer(tty);
780 } 764 }
781 if (L_ECHO(tty)) 765 if (L_ECHO(tty))
782 echo_char(c, tty); 766 echo_char(c, tty);
@@ -785,6 +769,15 @@ send_signal:
785 return; 769 return;
786 } 770 }
787 } 771 }
772
773 if (c == '\r') {
774 if (I_IGNCR(tty))
775 return;
776 if (I_ICRNL(tty))
777 c = '\n';
778 } else if (c == '\n' && I_INLCR(tty))
779 c = '\r';
780
788 if (tty->icanon) { 781 if (tty->icanon) {
789 if (c == ERASE_CHAR(tty) || c == KILL_CHAR(tty) || 782 if (c == ERASE_CHAR(tty) || c == KILL_CHAR(tty) ||
790 (c == WERASE_CHAR(tty) && L_IEXTEN(tty))) { 783 (c == WERASE_CHAR(tty) && L_IEXTEN(tty))) {
@@ -796,8 +789,8 @@ send_signal:
796 if (L_ECHO(tty)) { 789 if (L_ECHO(tty)) {
797 finish_erasing(tty); 790 finish_erasing(tty);
798 if (L_ECHOCTL(tty)) { 791 if (L_ECHOCTL(tty)) {
799 put_char('^', tty); 792 tty_put_char(tty, '^');
800 put_char('\b', tty); 793 tty_put_char(tty, '\b');
801 } 794 }
802 } 795 }
803 return; 796 return;
@@ -818,7 +811,7 @@ send_signal:
818 if (c == '\n') { 811 if (c == '\n') {
819 if (L_ECHO(tty) || L_ECHONL(tty)) { 812 if (L_ECHO(tty) || L_ECHONL(tty)) {
820 if (tty->read_cnt >= N_TTY_BUF_SIZE-1) 813 if (tty->read_cnt >= N_TTY_BUF_SIZE-1)
821 put_char('\a', tty); 814 tty_put_char(tty, '\a');
822 opost('\n', tty); 815 opost('\n', tty);
823 } 816 }
824 goto handle_newline; 817 goto handle_newline;
@@ -836,7 +829,7 @@ send_signal:
836 */ 829 */
837 if (L_ECHO(tty)) { 830 if (L_ECHO(tty)) {
838 if (tty->read_cnt >= N_TTY_BUF_SIZE-1) 831 if (tty->read_cnt >= N_TTY_BUF_SIZE-1)
839 put_char('\a', tty); 832 tty_put_char(tty, '\a');
840 /* Record the column of first canon char. */ 833 /* Record the column of first canon char. */
841 if (tty->canon_head == tty->read_head) 834 if (tty->canon_head == tty->read_head)
842 tty->canon_column = tty->column; 835 tty->canon_column = tty->column;
@@ -866,7 +859,7 @@ handle_newline:
866 finish_erasing(tty); 859 finish_erasing(tty);
867 if (L_ECHO(tty)) { 860 if (L_ECHO(tty)) {
868 if (tty->read_cnt >= N_TTY_BUF_SIZE-1) { 861 if (tty->read_cnt >= N_TTY_BUF_SIZE-1) {
869 put_char('\a', tty); /* beep if no space */ 862 tty_put_char(tty, '\a'); /* beep if no space */
870 return; 863 return;
871 } 864 }
872 if (c == '\n') 865 if (c == '\n')
@@ -970,8 +963,8 @@ static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp,
970 break; 963 break;
971 } 964 }
972 } 965 }
973 if (tty->driver->flush_chars) 966 if (tty->ops->flush_chars)
974 tty->driver->flush_chars(tty); 967 tty->ops->flush_chars(tty);
975 } 968 }
976 969
977 n_tty_set_room(tty); 970 n_tty_set_room(tty);
@@ -987,12 +980,8 @@ static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp,
987 * mode. We don't want to throttle the driver if we're in 980 * mode. We don't want to throttle the driver if we're in
988 * canonical mode and don't have a newline yet! 981 * canonical mode and don't have a newline yet!
989 */ 982 */
990 if (tty->receive_room < TTY_THRESHOLD_THROTTLE) { 983 if (tty->receive_room < TTY_THRESHOLD_THROTTLE)
991 /* check TTY_THROTTLED first so it indicates our state */ 984 tty_throttle(tty);
992 if (!test_and_set_bit(TTY_THROTTLED, &tty->flags) &&
993 tty->driver->throttle)
994 tty->driver->throttle(tty);
995 }
996} 985}
997 986
998int is_ignored(int sig) 987int is_ignored(int sig)
@@ -1076,6 +1065,9 @@ static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old)
1076 tty->real_raw = 0; 1065 tty->real_raw = 0;
1077 } 1066 }
1078 n_tty_set_room(tty); 1067 n_tty_set_room(tty);
1068 /* The termios change make the tty ready for I/O */
1069 wake_up_interruptible(&tty->write_wait);
1070 wake_up_interruptible(&tty->read_wait);
1079} 1071}
1080 1072
1081/** 1073/**
@@ -1194,6 +1186,11 @@ extern ssize_t redirected_tty_write(struct file *, const char __user *,
1194 * Perform job control management checks on this file/tty descriptor 1186 * Perform job control management checks on this file/tty descriptor
1195 * and if appropriate send any needed signals and return a negative 1187 * and if appropriate send any needed signals and return a negative
1196 * error code if action should be taken. 1188 * error code if action should be taken.
1189 *
1190 * FIXME:
1191 * Locking: None - redirected write test is safe, testing
1192 * current->signal should possibly lock current->sighand
1193 * pgrp locking ?
1197 */ 1194 */
1198 1195
1199static int job_control(struct tty_struct *tty, struct file *file) 1196static int job_control(struct tty_struct *tty, struct file *file)
@@ -1246,6 +1243,7 @@ static ssize_t read_chan(struct tty_struct *tty, struct file *file,
1246 ssize_t size; 1243 ssize_t size;
1247 long timeout; 1244 long timeout;
1248 unsigned long flags; 1245 unsigned long flags;
1246 int packet;
1249 1247
1250do_it_again: 1248do_it_again:
1251 1249
@@ -1289,16 +1287,19 @@ do_it_again:
1289 if (mutex_lock_interruptible(&tty->atomic_read_lock)) 1287 if (mutex_lock_interruptible(&tty->atomic_read_lock))
1290 return -ERESTARTSYS; 1288 return -ERESTARTSYS;
1291 } 1289 }
1290 packet = tty->packet;
1292 1291
1293 add_wait_queue(&tty->read_wait, &wait); 1292 add_wait_queue(&tty->read_wait, &wait);
1294 while (nr) { 1293 while (nr) {
1295 /* First test for status change. */ 1294 /* First test for status change. */
1296 if (tty->packet && tty->link->ctrl_status) { 1295 if (packet && tty->link->ctrl_status) {
1297 unsigned char cs; 1296 unsigned char cs;
1298 if (b != buf) 1297 if (b != buf)
1299 break; 1298 break;
1299 spin_lock_irqsave(&tty->link->ctrl_lock, flags);
1300 cs = tty->link->ctrl_status; 1300 cs = tty->link->ctrl_status;
1301 tty->link->ctrl_status = 0; 1301 tty->link->ctrl_status = 0;
1302 spin_unlock_irqrestore(&tty->link->ctrl_lock, flags);
1302 if (tty_put_user(tty, cs, b++)) { 1303 if (tty_put_user(tty, cs, b++)) {
1303 retval = -EFAULT; 1304 retval = -EFAULT;
1304 b--; 1305 b--;
@@ -1333,6 +1334,7 @@ do_it_again:
1333 retval = -ERESTARTSYS; 1334 retval = -ERESTARTSYS;
1334 break; 1335 break;
1335 } 1336 }
1337 /* FIXME: does n_tty_set_room need locking ? */
1336 n_tty_set_room(tty); 1338 n_tty_set_room(tty);
1337 timeout = schedule_timeout(timeout); 1339 timeout = schedule_timeout(timeout);
1338 continue; 1340 continue;
@@ -1340,7 +1342,7 @@ do_it_again:
1340 __set_current_state(TASK_RUNNING); 1342 __set_current_state(TASK_RUNNING);
1341 1343
1342 /* Deal with packet mode. */ 1344 /* Deal with packet mode. */
1343 if (tty->packet && b == buf) { 1345 if (packet && b == buf) {
1344 if (tty_put_user(tty, TIOCPKT_DATA, b++)) { 1346 if (tty_put_user(tty, TIOCPKT_DATA, b++)) {
1345 retval = -EFAULT; 1347 retval = -EFAULT;
1346 b--; 1348 b--;
@@ -1388,6 +1390,8 @@ do_it_again:
1388 break; 1390 break;
1389 } else { 1391 } else {
1390 int uncopied; 1392 int uncopied;
1393 /* The copy function takes the read lock and handles
1394 locking internally for this case */
1391 uncopied = copy_from_read_buf(tty, &b, &nr); 1395 uncopied = copy_from_read_buf(tty, &b, &nr);
1392 uncopied += copy_from_read_buf(tty, &b, &nr); 1396 uncopied += copy_from_read_buf(tty, &b, &nr);
1393 if (uncopied) { 1397 if (uncopied) {
@@ -1429,7 +1433,6 @@ do_it_again:
1429 goto do_it_again; 1433 goto do_it_again;
1430 1434
1431 n_tty_set_room(tty); 1435 n_tty_set_room(tty);
1432
1433 return retval; 1436 return retval;
1434} 1437}
1435 1438
@@ -1492,11 +1495,11 @@ static ssize_t write_chan(struct tty_struct *tty, struct file *file,
1492 break; 1495 break;
1493 b++; nr--; 1496 b++; nr--;
1494 } 1497 }
1495 if (tty->driver->flush_chars) 1498 if (tty->ops->flush_chars)
1496 tty->driver->flush_chars(tty); 1499 tty->ops->flush_chars(tty);
1497 } else { 1500 } else {
1498 while (nr > 0) { 1501 while (nr > 0) {
1499 c = tty->driver->write(tty, b, nr); 1502 c = tty->ops->write(tty, b, nr);
1500 if (c < 0) { 1503 if (c < 0) {
1501 retval = c; 1504 retval = c;
1502 goto break_out; 1505 goto break_out;
@@ -1533,11 +1536,6 @@ break_out:
1533 * 1536 *
1534 * This code must be sure never to sleep through a hangup. 1537 * This code must be sure never to sleep through a hangup.
1535 * Called without the kernel lock held - fine 1538 * Called without the kernel lock held - fine
1536 *
1537 * FIXME: if someone changes the VMIN or discipline settings for the
1538 * terminal while another process is in poll() the poll does not
1539 * recompute the new limits. Possibly set_termios should issue
1540 * a read wakeup to fix this bug.
1541 */ 1539 */
1542 1540
1543static unsigned int normal_poll(struct tty_struct *tty, struct file *file, 1541static unsigned int normal_poll(struct tty_struct *tty, struct file *file,
@@ -1561,9 +1559,9 @@ static unsigned int normal_poll(struct tty_struct *tty, struct file *file,
1561 else 1559 else
1562 tty->minimum_to_wake = 1; 1560 tty->minimum_to_wake = 1;
1563 } 1561 }
1564 if (!tty_is_writelocked(tty) && 1562 if (tty->ops->write && !tty_is_writelocked(tty) &&
1565 tty->driver->chars_in_buffer(tty) < WAKEUP_CHARS && 1563 tty_chars_in_buffer(tty) < WAKEUP_CHARS &&
1566 tty->driver->write_room(tty) > 0) 1564 tty_write_room(tty) > 0)
1567 mask |= POLLOUT | POLLWRNORM; 1565 mask |= POLLOUT | POLLWRNORM;
1568 return mask; 1566 return mask;
1569} 1567}
diff --git a/drivers/char/nozomi.c b/drivers/char/nozomi.c
index 6a6843a0a674..66a0f931c66c 100644
--- a/drivers/char/nozomi.c
+++ b/drivers/char/nozomi.c
@@ -73,7 +73,7 @@ do { \
73 char tmp[P_BUF_SIZE]; \ 73 char tmp[P_BUF_SIZE]; \
74 snprintf(tmp, sizeof(tmp), ##args); \ 74 snprintf(tmp, sizeof(tmp), ##args); \
75 printk(_err_flag_ "[%d] %s(): %s\n", __LINE__, \ 75 printk(_err_flag_ "[%d] %s(): %s\n", __LINE__, \
76 __FUNCTION__, tmp); \ 76 __func__, tmp); \
77} while (0) 77} while (0)
78 78
79#define DBG1(args...) D_(0x01, ##args) 79#define DBG1(args...) D_(0x01, ##args)
@@ -1407,7 +1407,7 @@ static int __devinit nozomi_card_init(struct pci_dev *pdev,
1407 /* Find out what card type it is */ 1407 /* Find out what card type it is */
1408 nozomi_get_card_type(dc); 1408 nozomi_get_card_type(dc);
1409 1409
1410 dc->base_addr = ioremap(start, dc->card_type); 1410 dc->base_addr = ioremap_nocache(start, dc->card_type);
1411 if (!dc->base_addr) { 1411 if (!dc->base_addr) {
1412 dev_err(&pdev->dev, "Unable to map card MMIO\n"); 1412 dev_err(&pdev->dev, "Unable to map card MMIO\n");
1413 ret = -ENODEV; 1413 ret = -ENODEV;
@@ -1724,6 +1724,8 @@ static int ntty_tiocmget(struct tty_struct *tty, struct file *file)
1724 const struct ctrl_dl *ctrl_dl = &port->ctrl_dl; 1724 const struct ctrl_dl *ctrl_dl = &port->ctrl_dl;
1725 const struct ctrl_ul *ctrl_ul = &port->ctrl_ul; 1725 const struct ctrl_ul *ctrl_ul = &port->ctrl_ul;
1726 1726
1727 /* Note: these could change under us but it is not clear this
1728 matters if so */
1727 return (ctrl_ul->RTS ? TIOCM_RTS : 0) | 1729 return (ctrl_ul->RTS ? TIOCM_RTS : 0) |
1728 (ctrl_ul->DTR ? TIOCM_DTR : 0) | 1730 (ctrl_ul->DTR ? TIOCM_DTR : 0) |
1729 (ctrl_dl->DCD ? TIOCM_CAR : 0) | 1731 (ctrl_dl->DCD ? TIOCM_CAR : 0) |
@@ -1849,16 +1851,6 @@ static void ntty_throttle(struct tty_struct *tty)
1849 spin_unlock_irqrestore(&dc->spin_mutex, flags); 1851 spin_unlock_irqrestore(&dc->spin_mutex, flags);
1850} 1852}
1851 1853
1852/* just to discard single character writes */
1853static void ntty_put_char(struct tty_struct *tty, unsigned char c)
1854{
1855 /*
1856 * card does not react correct when we write single chars
1857 * to the card, so we discard them
1858 */
1859 DBG2("PUT CHAR Function: %c", c);
1860}
1861
1862/* Returns number of chars in buffer, called by tty layer */ 1854/* Returns number of chars in buffer, called by tty layer */
1863static s32 ntty_chars_in_buffer(struct tty_struct *tty) 1855static s32 ntty_chars_in_buffer(struct tty_struct *tty)
1864{ 1856{
@@ -1892,7 +1884,6 @@ static const struct tty_operations tty_ops = {
1892 .unthrottle = ntty_unthrottle, 1884 .unthrottle = ntty_unthrottle,
1893 .throttle = ntty_throttle, 1885 .throttle = ntty_throttle,
1894 .chars_in_buffer = ntty_chars_in_buffer, 1886 .chars_in_buffer = ntty_chars_in_buffer,
1895 .put_char = ntty_put_char,
1896 .tiocmget = ntty_tiocmget, 1887 .tiocmget = ntty_tiocmget,
1897 .tiocmset = ntty_tiocmset, 1888 .tiocmset = ntty_tiocmset,
1898}; 1889};
diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c
index 454d7324ba40..4a933d413423 100644
--- a/drivers/char/pcmcia/cm4000_cs.c
+++ b/drivers/char/pcmcia/cm4000_cs.c
@@ -53,7 +53,7 @@ module_param(pc_debug, int, 0600);
53#define DEBUGP(n, rdr, x, args...) do { \ 53#define DEBUGP(n, rdr, x, args...) do { \
54 if (pc_debug >= (n)) \ 54 if (pc_debug >= (n)) \
55 dev_printk(KERN_DEBUG, reader_to_dev(rdr), "%s:" x, \ 55 dev_printk(KERN_DEBUG, reader_to_dev(rdr), "%s:" x, \
56 __FUNCTION__ , ## args); \ 56 __func__ , ## args); \
57 } while (0) 57 } while (0)
58#else 58#else
59#define DEBUGP(n, rdr, x, args...) 59#define DEBUGP(n, rdr, x, args...)
diff --git a/drivers/char/pcmcia/cm4040_cs.c b/drivers/char/pcmcia/cm4040_cs.c
index 5f291bf739a6..035084c07329 100644
--- a/drivers/char/pcmcia/cm4040_cs.c
+++ b/drivers/char/pcmcia/cm4040_cs.c
@@ -47,7 +47,7 @@ module_param(pc_debug, int, 0600);
47#define DEBUGP(n, rdr, x, args...) do { \ 47#define DEBUGP(n, rdr, x, args...) do { \
48 if (pc_debug >= (n)) \ 48 if (pc_debug >= (n)) \
49 dev_printk(KERN_DEBUG, reader_to_dev(rdr), "%s:" x, \ 49 dev_printk(KERN_DEBUG, reader_to_dev(rdr), "%s:" x, \
50 __FUNCTION__ , ##args); \ 50 __func__ , ##args); \
51 } while (0) 51 } while (0)
52#else 52#else
53#define DEBUGP(n, rdr, x, args...) 53#define DEBUGP(n, rdr, x, args...)
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index 583356426dfb..1dd0e992c83d 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -503,20 +503,9 @@ static void* mgslpc_get_text_ptr(void)
503 * The wrappers maintain line discipline references 503 * The wrappers maintain line discipline references
504 * while calling into the line discipline. 504 * while calling into the line discipline.
505 * 505 *
506 * ldisc_flush_buffer - flush line discipline receive buffers
507 * ldisc_receive_buf - pass receive data to line discipline 506 * ldisc_receive_buf - pass receive data to line discipline
508 */ 507 */
509 508
510static void ldisc_flush_buffer(struct tty_struct *tty)
511{
512 struct tty_ldisc *ld = tty_ldisc_ref(tty);
513 if (ld) {
514 if (ld->flush_buffer)
515 ld->flush_buffer(tty);
516 tty_ldisc_deref(ld);
517 }
518}
519
520static void ldisc_receive_buf(struct tty_struct *tty, 509static void ldisc_receive_buf(struct tty_struct *tty,
521 const __u8 *data, char *flags, int count) 510 const __u8 *data, char *flags, int count)
522{ 511{
@@ -1556,7 +1545,7 @@ static void mgslpc_change_params(MGSLPC_INFO *info)
1556 1545
1557/* Add a character to the transmit buffer 1546/* Add a character to the transmit buffer
1558 */ 1547 */
1559static void mgslpc_put_char(struct tty_struct *tty, unsigned char ch) 1548static int mgslpc_put_char(struct tty_struct *tty, unsigned char ch)
1560{ 1549{
1561 MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data; 1550 MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
1562 unsigned long flags; 1551 unsigned long flags;
@@ -1567,10 +1556,10 @@ static void mgslpc_put_char(struct tty_struct *tty, unsigned char ch)
1567 } 1556 }
1568 1557
1569 if (mgslpc_paranoia_check(info, tty->name, "mgslpc_put_char")) 1558 if (mgslpc_paranoia_check(info, tty->name, "mgslpc_put_char"))
1570 return; 1559 return 0;
1571 1560
1572 if (!info->tx_buf) 1561 if (!info->tx_buf)
1573 return; 1562 return 0;
1574 1563
1575 spin_lock_irqsave(&info->lock,flags); 1564 spin_lock_irqsave(&info->lock,flags);
1576 1565
@@ -1583,6 +1572,7 @@ static void mgslpc_put_char(struct tty_struct *tty, unsigned char ch)
1583 } 1572 }
1584 1573
1585 spin_unlock_irqrestore(&info->lock,flags); 1574 spin_unlock_irqrestore(&info->lock,flags);
1575 return 1;
1586} 1576}
1587 1577
1588/* Enable transmitter so remaining characters in the 1578/* Enable transmitter so remaining characters in the
@@ -2467,10 +2457,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
2467 if (info->flags & ASYNC_INITIALIZED) 2457 if (info->flags & ASYNC_INITIALIZED)
2468 mgslpc_wait_until_sent(tty, info->timeout); 2458 mgslpc_wait_until_sent(tty, info->timeout);
2469 2459
2470 if (tty->driver->flush_buffer) 2460 mgslpc_flush_buffer(tty);
2471 tty->driver->flush_buffer(tty);
2472 2461
2473 ldisc_flush_buffer(tty); 2462 tty_ldisc_flush(tty);
2474 2463
2475 shutdown(info); 2464 shutdown(info);
2476 2465
diff --git a/drivers/char/pty.c b/drivers/char/pty.c
index 706ff34728f1..0a05c038ae6f 100644
--- a/drivers/char/pty.c
+++ b/drivers/char/pty.c
@@ -181,6 +181,7 @@ static int pty_set_lock(struct tty_struct *tty, int __user * arg)
181static void pty_flush_buffer(struct tty_struct *tty) 181static void pty_flush_buffer(struct tty_struct *tty)
182{ 182{
183 struct tty_struct *to = tty->link; 183 struct tty_struct *to = tty->link;
184 unsigned long flags;
184 185
185 if (!to) 186 if (!to)
186 return; 187 return;
@@ -189,8 +190,10 @@ static void pty_flush_buffer(struct tty_struct *tty)
189 to->ldisc.flush_buffer(to); 190 to->ldisc.flush_buffer(to);
190 191
191 if (to->packet) { 192 if (to->packet) {
193 spin_lock_irqsave(&tty->ctrl_lock, flags);
192 tty->ctrl_status |= TIOCPKT_FLUSHWRITE; 194 tty->ctrl_status |= TIOCPKT_FLUSHWRITE;
193 wake_up_interruptible(&to->read_wait); 195 wake_up_interruptible(&to->read_wait);
196 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
194 } 197 }
195} 198}
196 199
@@ -251,6 +254,18 @@ static int pty_bsd_ioctl(struct tty_struct *tty, struct file *file,
251static int legacy_count = CONFIG_LEGACY_PTY_COUNT; 254static int legacy_count = CONFIG_LEGACY_PTY_COUNT;
252module_param(legacy_count, int, 0); 255module_param(legacy_count, int, 0);
253 256
257static const struct tty_operations pty_ops_bsd = {
258 .open = pty_open,
259 .close = pty_close,
260 .write = pty_write,
261 .write_room = pty_write_room,
262 .flush_buffer = pty_flush_buffer,
263 .chars_in_buffer = pty_chars_in_buffer,
264 .unthrottle = pty_unthrottle,
265 .set_termios = pty_set_termios,
266 .ioctl = pty_bsd_ioctl,
267};
268
254static void __init legacy_pty_init(void) 269static void __init legacy_pty_init(void)
255{ 270{
256 if (legacy_count <= 0) 271 if (legacy_count <= 0)
@@ -281,7 +296,6 @@ static void __init legacy_pty_init(void)
281 pty_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW; 296 pty_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW;
282 pty_driver->other = pty_slave_driver; 297 pty_driver->other = pty_slave_driver;
283 tty_set_operations(pty_driver, &pty_ops); 298 tty_set_operations(pty_driver, &pty_ops);
284 pty_driver->ioctl = pty_bsd_ioctl;
285 299
286 pty_slave_driver->owner = THIS_MODULE; 300 pty_slave_driver->owner = THIS_MODULE;
287 pty_slave_driver->driver_name = "pty_slave"; 301 pty_slave_driver->driver_name = "pty_slave";
@@ -374,6 +388,19 @@ static int pty_unix98_ioctl(struct tty_struct *tty, struct file *file,
374 return -ENOIOCTLCMD; 388 return -ENOIOCTLCMD;
375} 389}
376 390
391static const struct tty_operations pty_unix98_ops = {
392 .open = pty_open,
393 .close = pty_close,
394 .write = pty_write,
395 .write_room = pty_write_room,
396 .flush_buffer = pty_flush_buffer,
397 .chars_in_buffer = pty_chars_in_buffer,
398 .unthrottle = pty_unthrottle,
399 .set_termios = pty_set_termios,
400 .ioctl = pty_unix98_ioctl
401};
402
403
377static void __init unix98_pty_init(void) 404static void __init unix98_pty_init(void)
378{ 405{
379 ptm_driver = alloc_tty_driver(NR_UNIX98_PTY_MAX); 406 ptm_driver = alloc_tty_driver(NR_UNIX98_PTY_MAX);
@@ -400,8 +427,7 @@ static void __init unix98_pty_init(void)
400 ptm_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW | 427 ptm_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW |
401 TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_DEVPTS_MEM; 428 TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_DEVPTS_MEM;
402 ptm_driver->other = pts_driver; 429 ptm_driver->other = pts_driver;
403 tty_set_operations(ptm_driver, &pty_ops); 430 tty_set_operations(ptm_driver, &pty_unix98_ops);
404 ptm_driver->ioctl = pty_unix98_ioctl;
405 431
406 pts_driver->owner = THIS_MODULE; 432 pts_driver->owner = THIS_MODULE;
407 pts_driver->driver_name = "pty_slave"; 433 pts_driver->driver_name = "pty_slave";
diff --git a/drivers/char/rio/cirrus.h b/drivers/char/rio/cirrus.h
index f4f837f86829..a03a538a3efb 100644
--- a/drivers/char/rio/cirrus.h
+++ b/drivers/char/rio/cirrus.h
@@ -43,83 +43,83 @@
43/* Bit fields for particular registers shared with driver */ 43/* Bit fields for particular registers shared with driver */
44 44
45/* COR1 - driver and RTA */ 45/* COR1 - driver and RTA */
46#define COR1_ODD 0x80 /* Odd parity */ 46#define RIOC_COR1_ODD 0x80 /* Odd parity */
47#define COR1_EVEN 0x00 /* Even parity */ 47#define RIOC_COR1_EVEN 0x00 /* Even parity */
48#define COR1_NOP 0x00 /* No parity */ 48#define RIOC_COR1_NOP 0x00 /* No parity */
49#define COR1_FORCE 0x20 /* Force parity */ 49#define RIOC_COR1_FORCE 0x20 /* Force parity */
50#define COR1_NORMAL 0x40 /* With parity */ 50#define RIOC_COR1_NORMAL 0x40 /* With parity */
51#define COR1_1STOP 0x00 /* 1 stop bit */ 51#define RIOC_COR1_1STOP 0x00 /* 1 stop bit */
52#define COR1_15STOP 0x04 /* 1.5 stop bits */ 52#define RIOC_COR1_15STOP 0x04 /* 1.5 stop bits */
53#define COR1_2STOP 0x08 /* 2 stop bits */ 53#define RIOC_COR1_2STOP 0x08 /* 2 stop bits */
54#define COR1_5BITS 0x00 /* 5 data bits */ 54#define RIOC_COR1_5BITS 0x00 /* 5 data bits */
55#define COR1_6BITS 0x01 /* 6 data bits */ 55#define RIOC_COR1_6BITS 0x01 /* 6 data bits */
56#define COR1_7BITS 0x02 /* 7 data bits */ 56#define RIOC_COR1_7BITS 0x02 /* 7 data bits */
57#define COR1_8BITS 0x03 /* 8 data bits */ 57#define RIOC_COR1_8BITS 0x03 /* 8 data bits */
58 58
59#define COR1_HOST 0xef /* Safe host bits */ 59#define RIOC_COR1_HOST 0xef /* Safe host bits */
60 60
61/* RTA only */ 61/* RTA only */
62#define COR1_CINPCK 0x00 /* Check parity of received characters */ 62#define RIOC_COR1_CINPCK 0x00 /* Check parity of received characters */
63#define COR1_CNINPCK 0x10 /* Don't check parity */ 63#define RIOC_COR1_CNINPCK 0x10 /* Don't check parity */
64 64
65/* COR2 bits for both RTA and driver use */ 65/* COR2 bits for both RTA and driver use */
66#define COR2_IXANY 0x80 /* IXANY - any character is XON */ 66#define RIOC_COR2_IXANY 0x80 /* IXANY - any character is XON */
67#define COR2_IXON 0x40 /* IXON - enable tx soft flowcontrol */ 67#define RIOC_COR2_IXON 0x40 /* IXON - enable tx soft flowcontrol */
68#define COR2_RTSFLOW 0x02 /* Enable tx hardware flow control */ 68#define RIOC_COR2_RTSFLOW 0x02 /* Enable tx hardware flow control */
69 69
70/* Additional driver bits */ 70/* Additional driver bits */
71#define COR2_HUPCL 0x20 /* Hang up on close */ 71#define RIOC_COR2_HUPCL 0x20 /* Hang up on close */
72#define COR2_CTSFLOW 0x04 /* Enable rx hardware flow control */ 72#define RIOC_COR2_CTSFLOW 0x04 /* Enable rx hardware flow control */
73#define COR2_IXOFF 0x01 /* Enable rx software flow control */ 73#define RIOC_COR2_IXOFF 0x01 /* Enable rx software flow control */
74#define COR2_DTRFLOW 0x08 /* Enable tx hardware flow control */ 74#define RIOC_COR2_DTRFLOW 0x08 /* Enable tx hardware flow control */
75 75
76/* RTA use only */ 76/* RTA use only */
77#define COR2_ETC 0x20 /* Embedded transmit options */ 77#define RIOC_COR2_ETC 0x20 /* Embedded transmit options */
78#define COR2_LOCAL 0x10 /* Local loopback mode */ 78#define RIOC_COR2_LOCAL 0x10 /* Local loopback mode */
79#define COR2_REMOTE 0x08 /* Remote loopback mode */ 79#define RIOC_COR2_REMOTE 0x08 /* Remote loopback mode */
80#define COR2_HOST 0xc2 /* Safe host bits */ 80#define RIOC_COR2_HOST 0xc2 /* Safe host bits */
81 81
82/* COR3 - RTA use only */ 82/* COR3 - RTA use only */
83#define COR3_SCDRNG 0x80 /* Enable special char detect for range */ 83#define RIOC_COR3_SCDRNG 0x80 /* Enable special char detect for range */
84#define COR3_SCD34 0x40 /* Special character detect for SCHR's 3 + 4 */ 84#define RIOC_COR3_SCD34 0x40 /* Special character detect for SCHR's 3 + 4 */
85#define COR3_FCT 0x20 /* Flow control transparency */ 85#define RIOC_COR3_FCT 0x20 /* Flow control transparency */
86#define COR3_SCD12 0x10 /* Special character detect for SCHR's 1 + 2 */ 86#define RIOC_COR3_SCD12 0x10 /* Special character detect for SCHR's 1 + 2 */
87#define COR3_FIFO12 0x0c /* 12 chars for receive FIFO threshold */ 87#define RIOC_COR3_FIFO12 0x0c /* 12 chars for receive FIFO threshold */
88#define COR3_FIFO10 0x0a /* 10 chars for receive FIFO threshold */ 88#define RIOC_COR3_FIFO10 0x0a /* 10 chars for receive FIFO threshold */
89#define COR3_FIFO8 0x08 /* 8 chars for receive FIFO threshold */ 89#define RIOC_COR3_FIFO8 0x08 /* 8 chars for receive FIFO threshold */
90#define COR3_FIFO6 0x06 /* 6 chars for receive FIFO threshold */ 90#define RIOC_COR3_FIFO6 0x06 /* 6 chars for receive FIFO threshold */
91 91
92#define COR3_THRESHOLD COR3_FIFO8 /* MUST BE LESS THAN MCOR_THRESHOLD */ 92#define RIOC_COR3_THRESHOLD RIOC_COR3_FIFO8 /* MUST BE LESS THAN MCOR_THRESHOLD */
93 93
94#define COR3_DEFAULT (COR3_FCT | COR3_THRESHOLD) 94#define RIOC_COR3_DEFAULT (RIOC_COR3_FCT | RIOC_COR3_THRESHOLD)
95 /* Default bits for COR3 */ 95 /* Default bits for COR3 */
96 96
97/* COR4 driver and RTA use */ 97/* COR4 driver and RTA use */
98#define COR4_IGNCR 0x80 /* Throw away CR's on input */ 98#define RIOC_COR4_IGNCR 0x80 /* Throw away CR's on input */
99#define COR4_ICRNL 0x40 /* Map CR -> NL on input */ 99#define RIOC_COR4_ICRNL 0x40 /* Map CR -> NL on input */
100#define COR4_INLCR 0x20 /* Map NL -> CR on input */ 100#define RIOC_COR4_INLCR 0x20 /* Map NL -> CR on input */
101#define COR4_IGNBRK 0x10 /* Ignore Break */ 101#define RIOC_COR4_IGNBRK 0x10 /* Ignore Break */
102#define COR4_NBRKINT 0x08 /* No interrupt on break (-BRKINT) */ 102#define RIOC_COR4_NBRKINT 0x08 /* No interrupt on break (-BRKINT) */
103#define COR4_RAISEMOD 0x01 /* Raise modem output lines on non-zero baud */ 103#define RIOC_COR4_RAISEMOD 0x01 /* Raise modem output lines on non-zero baud */
104 104
105 105
106/* COR4 driver only */ 106/* COR4 driver only */
107#define COR4_IGNPAR 0x04 /* IGNPAR (ignore characters with errors) */ 107#define RIOC_COR4_IGNPAR 0x04 /* IGNPAR (ignore characters with errors) */
108#define COR4_PARMRK 0x02 /* PARMRK */ 108#define RIOC_COR4_PARMRK 0x02 /* PARMRK */
109 109
110#define COR4_HOST 0xf8 /* Safe host bits */ 110#define RIOC_COR4_HOST 0xf8 /* Safe host bits */
111 111
112/* COR4 RTA only */ 112/* COR4 RTA only */
113#define COR4_CIGNPAR 0x02 /* Thrown away bad characters */ 113#define RIOC_COR4_CIGNPAR 0x02 /* Thrown away bad characters */
114#define COR4_CPARMRK 0x04 /* PARMRK characters */ 114#define RIOC_COR4_CPARMRK 0x04 /* PARMRK characters */
115#define COR4_CNPARMRK 0x03 /* Don't PARMRK */ 115#define RIOC_COR4_CNPARMRK 0x03 /* Don't PARMRK */
116 116
117/* COR5 driver and RTA use */ 117/* COR5 driver and RTA use */
118#define COR5_ISTRIP 0x80 /* Strip input chars to 7 bits */ 118#define RIOC_COR5_ISTRIP 0x80 /* Strip input chars to 7 bits */
119#define COR5_LNE 0x40 /* Enable LNEXT processing */ 119#define RIOC_COR5_LNE 0x40 /* Enable LNEXT processing */
120#define COR5_CMOE 0x20 /* Match good and errored characters */ 120#define RIOC_COR5_CMOE 0x20 /* Match good and errored characters */
121#define COR5_ONLCR 0x02 /* NL -> CR NL on output */ 121#define RIOC_COR5_ONLCR 0x02 /* NL -> CR NL on output */
122#define COR5_OCRNL 0x01 /* CR -> NL on output */ 122#define RIOC_COR5_OCRNL 0x01 /* CR -> NL on output */
123 123
124/* 124/*
125** Spare bits - these are not used in the CIRRUS registers, so we use 125** Spare bits - these are not used in the CIRRUS registers, so we use
@@ -128,86 +128,86 @@
128/* 128/*
129** tstop and tbusy indication 129** tstop and tbusy indication
130*/ 130*/
131#define COR5_TSTATE_ON 0x08 /* Turn on monitoring of tbusy and tstop */ 131#define RIOC_COR5_TSTATE_ON 0x08 /* Turn on monitoring of tbusy and tstop */
132#define COR5_TSTATE_OFF 0x04 /* Turn off monitoring of tbusy and tstop */ 132#define RIOC_COR5_TSTATE_OFF 0x04 /* Turn off monitoring of tbusy and tstop */
133/* 133/*
134** TAB3 134** TAB3
135*/ 135*/
136#define COR5_TAB3 0x10 /* TAB3 mode */ 136#define RIOC_COR5_TAB3 0x10 /* TAB3 mode */
137 137
138#define COR5_HOST 0xc3 /* Safe host bits */ 138#define RIOC_COR5_HOST 0xc3 /* Safe host bits */
139 139
140/* CCSR */ 140/* CCSR */
141#define CCSR_TXFLOFF 0x04 /* Tx is xoffed */ 141#define RIOC_CCSR_TXFLOFF 0x04 /* Tx is xoffed */
142 142
143/* MSVR1 */ 143/* MSVR1 */
144/* NB. DTR / CD swapped from Cirrus spec as the pins are also reversed on the 144/* NB. DTR / CD swapped from Cirrus spec as the pins are also reversed on the
145 RTA. This is because otherwise DCD would get lost on the 1 parallel / 3 145 RTA. This is because otherwise DCD would get lost on the 1 parallel / 3
146 serial option. 146 serial option.
147*/ 147*/
148#define MSVR1_CD 0x80 /* CD (DSR on Cirrus) */ 148#define RIOC_MSVR1_CD 0x80 /* CD (DSR on Cirrus) */
149#define MSVR1_RTS 0x40 /* RTS (CTS on Cirrus) */ 149#define RIOC_MSVR1_RTS 0x40 /* RTS (CTS on Cirrus) */
150#define MSVR1_RI 0x20 /* RI */ 150#define RIOC_MSVR1_RI 0x20 /* RI */
151#define MSVR1_DTR 0x10 /* DTR (CD on Cirrus) */ 151#define RIOC_MSVR1_DTR 0x10 /* DTR (CD on Cirrus) */
152#define MSVR1_CTS 0x01 /* CTS output pin (RTS on Cirrus) */ 152#define RIOC_MSVR1_CTS 0x01 /* CTS output pin (RTS on Cirrus) */
153/* Next two used to indicate state of tbusy and tstop to driver */ 153/* Next two used to indicate state of tbusy and tstop to driver */
154#define MSVR1_TSTOP 0x08 /* Set if port flow controlled */ 154#define RIOC_MSVR1_TSTOP 0x08 /* Set if port flow controlled */
155#define MSVR1_TEMPTY 0x04 /* Set if port tx buffer empty */ 155#define RIOC_MSVR1_TEMPTY 0x04 /* Set if port tx buffer empty */
156 156
157#define MSVR1_HOST 0xf3 /* The bits the host wants */ 157#define RIOC_MSVR1_HOST 0xf3 /* The bits the host wants */
158 158
159/* Defines for the subscripts of a CONFIG packet */ 159/* Defines for the subscripts of a CONFIG packet */
160#define CONFIG_COR1 1 /* Option register 1 */ 160#define RIOC_CONFIG_COR1 1 /* Option register 1 */
161#define CONFIG_COR2 2 /* Option register 2 */ 161#define RIOC_CONFIG_COR2 2 /* Option register 2 */
162#define CONFIG_COR4 3 /* Option register 4 */ 162#define RIOC_CONFIG_COR4 3 /* Option register 4 */
163#define CONFIG_COR5 4 /* Option register 5 */ 163#define RIOC_CONFIG_COR5 4 /* Option register 5 */
164#define CONFIG_TXXON 5 /* Tx XON character */ 164#define RIOC_CONFIG_TXXON 5 /* Tx XON character */
165#define CONFIG_TXXOFF 6 /* Tx XOFF character */ 165#define RIOC_CONFIG_TXXOFF 6 /* Tx XOFF character */
166#define CONFIG_RXXON 7 /* Rx XON character */ 166#define RIOC_CONFIG_RXXON 7 /* Rx XON character */
167#define CONFIG_RXXOFF 8 /* Rx XOFF character */ 167#define RIOC_CONFIG_RXXOFF 8 /* Rx XOFF character */
168#define CONFIG_LNEXT 9 /* LNEXT character */ 168#define RIOC_CONFIG_LNEXT 9 /* LNEXT character */
169#define CONFIG_TXBAUD 10 /* Tx baud rate */ 169#define RIOC_CONFIG_TXBAUD 10 /* Tx baud rate */
170#define CONFIG_RXBAUD 11 /* Rx baud rate */ 170#define RIOC_CONFIG_RXBAUD 11 /* Rx baud rate */
171 171
172#define PRE_EMPTIVE 0x80 /* Pre-emptive bit in command field */ 172#define RIOC_PRE_EMPTIVE 0x80 /* Pre-emptive bit in command field */
173 173
174/* Packet types going from Host to remote - with the exception of OPEN, MOPEN, 174/* Packet types going from Host to remote - with the exception of OPEN, MOPEN,
175 CONFIG, SBREAK and MEMDUMP the remaining bytes of the data array will not 175 CONFIG, SBREAK and MEMDUMP the remaining bytes of the data array will not
176 be used 176 be used
177*/ 177*/
178#define OPEN 0x00 /* Open a port */ 178#define RIOC_OPEN 0x00 /* Open a port */
179#define CONFIG 0x01 /* Configure a port */ 179#define RIOC_CONFIG 0x01 /* Configure a port */
180#define MOPEN 0x02 /* Modem open (block for DCD) */ 180#define RIOC_MOPEN 0x02 /* Modem open (block for DCD) */
181#define CLOSE 0x03 /* Close a port */ 181#define RIOC_CLOSE 0x03 /* Close a port */
182#define WFLUSH (0x04 | PRE_EMPTIVE) /* Write flush */ 182#define RIOC_WFLUSH (0x04 | RIOC_PRE_EMPTIVE) /* Write flush */
183#define RFLUSH (0x05 | PRE_EMPTIVE) /* Read flush */ 183#define RIOC_RFLUSH (0x05 | RIOC_PRE_EMPTIVE) /* Read flush */
184#define RESUME (0x06 | PRE_EMPTIVE) /* Resume if xoffed */ 184#define RIOC_RESUME (0x06 | RIOC_PRE_EMPTIVE) /* Resume if xoffed */
185#define SBREAK 0x07 /* Start break */ 185#define RIOC_SBREAK 0x07 /* Start break */
186#define EBREAK 0x08 /* End break */ 186#define RIOC_EBREAK 0x08 /* End break */
187#define SUSPEND (0x09 | PRE_EMPTIVE) /* Susp op (behave as tho xoffed) */ 187#define RIOC_SUSPEND (0x09 | RIOC_PRE_EMPTIVE) /* Susp op (behave as tho xoffed) */
188#define FCLOSE (0x0a | PRE_EMPTIVE) /* Force close */ 188#define RIOC_FCLOSE (0x0a | RIOC_PRE_EMPTIVE) /* Force close */
189#define XPRINT 0x0b /* Xprint packet */ 189#define RIOC_XPRINT 0x0b /* Xprint packet */
190#define MBIS (0x0c | PRE_EMPTIVE) /* Set modem lines */ 190#define RIOC_MBIS (0x0c | RIOC_PRE_EMPTIVE) /* Set modem lines */
191#define MBIC (0x0d | PRE_EMPTIVE) /* Clear modem lines */ 191#define RIOC_MBIC (0x0d | RIOC_PRE_EMPTIVE) /* Clear modem lines */
192#define MSET (0x0e | PRE_EMPTIVE) /* Set modem lines */ 192#define RIOC_MSET (0x0e | RIOC_PRE_EMPTIVE) /* Set modem lines */
193#define PCLOSE 0x0f /* Pseudo close - Leaves rx/tx enabled */ 193#define RIOC_PCLOSE 0x0f /* Pseudo close - Leaves rx/tx enabled */
194#define MGET (0x10 | PRE_EMPTIVE) /* Force update of modem status */ 194#define RIOC_MGET (0x10 | RIOC_PRE_EMPTIVE) /* Force update of modem status */
195#define MEMDUMP (0x11 | PRE_EMPTIVE) /* Send back mem from addr supplied */ 195#define RIOC_MEMDUMP (0x11 | RIOC_PRE_EMPTIVE) /* Send back mem from addr supplied */
196#define READ_REGISTER (0x12 | PRE_EMPTIVE) /* Read CD1400 register (debug) */ 196#define RIOC_READ_REGISTER (0x12 | RIOC_PRE_EMPTIVE) /* Read CD1400 register (debug) */
197 197
198/* "Command" packets going from remote to host COMPLETE and MODEM_STATUS 198/* "Command" packets going from remote to host COMPLETE and MODEM_STATUS
199 use data[4] / data[3] to indicate current state and modem status respectively 199 use data[4] / data[3] to indicate current state and modem status respectively
200*/ 200*/
201 201
202#define COMPLETE (0x20 | PRE_EMPTIVE) 202#define RIOC_COMPLETE (0x20 | RIOC_PRE_EMPTIVE)
203 /* Command complete */ 203 /* Command complete */
204#define BREAK_RECEIVED (0x21 | PRE_EMPTIVE) 204#define RIOC_BREAK_RECEIVED (0x21 | RIOC_PRE_EMPTIVE)
205 /* Break received */ 205 /* Break received */
206#define MODEM_STATUS (0x22 | PRE_EMPTIVE) 206#define RIOC_MODEM_STATUS (0x22 | RIOC_PRE_EMPTIVE)
207 /* Change in modem status */ 207 /* Change in modem status */
208 208
209/* "Command" packet that could go either way - handshake wake-up */ 209/* "Command" packet that could go either way - handshake wake-up */
210#define HANDSHAKE (0x23 | PRE_EMPTIVE) 210#define RIOC_HANDSHAKE (0x23 | RIOC_PRE_EMPTIVE)
211 /* Wake-up to HOST / RTA */ 211 /* Wake-up to HOST / RTA */
212 212
213#endif 213#endif
diff --git a/drivers/char/rio/rio_linux.c b/drivers/char/rio/rio_linux.c
index 0ce96670f979..412777cd1e68 100644
--- a/drivers/char/rio/rio_linux.c
+++ b/drivers/char/rio/rio_linux.c
@@ -344,7 +344,7 @@ int rio_minor(struct tty_struct *tty)
344 344
345static int rio_set_real_termios(void *ptr) 345static int rio_set_real_termios(void *ptr)
346{ 346{
347 return RIOParam((struct Port *) ptr, CONFIG, 1, 1); 347 return RIOParam((struct Port *) ptr, RIOC_CONFIG, 1, 1);
348} 348}
349 349
350 350
@@ -487,7 +487,7 @@ static int rio_get_CD(void *ptr)
487 int rv; 487 int rv;
488 488
489 func_enter(); 489 func_enter();
490 rv = (PortP->ModemState & MSVR1_CD) != 0; 490 rv = (PortP->ModemState & RIOC_MSVR1_CD) != 0;
491 491
492 rio_dprintk(RIO_DEBUG_INIT, "Getting CD status: %d\n", rv); 492 rio_dprintk(RIO_DEBUG_INIT, "Getting CD status: %d\n", rv);
493 493
@@ -607,7 +607,8 @@ static int rio_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd
607 rio_dprintk(RIO_DEBUG_TTY, "BREAK on deleted RTA\n"); 607 rio_dprintk(RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
608 rc = -EIO; 608 rc = -EIO;
609 } else { 609 } else {
610 if (RIOShortCommand(p, PortP, SBREAK, 2, 250) == RIO_FAIL) { 610 if (RIOShortCommand(p, PortP, RIOC_SBREAK, 2, 250) ==
611 RIO_FAIL) {
611 rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n"); 612 rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
612 rc = -EIO; 613 rc = -EIO;
613 } 614 }
@@ -622,7 +623,8 @@ static int rio_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd
622 l = arg ? arg * 100 : 250; 623 l = arg ? arg * 100 : 250;
623 if (l > 255) 624 if (l > 255)
624 l = 255; 625 l = 255;
625 if (RIOShortCommand(p, PortP, SBREAK, 2, arg ? arg * 100 : 250) == RIO_FAIL) { 626 if (RIOShortCommand(p, PortP, RIOC_SBREAK, 2,
627 arg ? arg * 100 : 250) == RIO_FAIL) {
626 rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n"); 628 rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
627 rc = -EIO; 629 rc = -EIO;
628 } 630 }
diff --git a/drivers/char/rio/rio_linux.h b/drivers/char/rio/rio_linux.h
index dc3f005614a3..7f26cd7c815e 100644
--- a/drivers/char/rio/rio_linux.h
+++ b/drivers/char/rio/rio_linux.h
@@ -186,9 +186,9 @@ static inline void *rio_memcpy_fromio(void *dest, void __iomem *source, int n)
186 186
187#ifdef DEBUG 187#ifdef DEBUG
188#define rio_dprintk(f, str...) do { if (rio_debug & f) printk (str);} while (0) 188#define rio_dprintk(f, str...) do { if (rio_debug & f) printk (str);} while (0)
189#define func_enter() rio_dprintk (RIO_DEBUG_FLOW, "rio: enter %s\n", __FUNCTION__) 189#define func_enter() rio_dprintk (RIO_DEBUG_FLOW, "rio: enter %s\n", __func__)
190#define func_exit() rio_dprintk (RIO_DEBUG_FLOW, "rio: exit %s\n", __FUNCTION__) 190#define func_exit() rio_dprintk (RIO_DEBUG_FLOW, "rio: exit %s\n", __func__)
191#define func_enter2() rio_dprintk (RIO_DEBUG_FLOW, "rio: enter %s (port %d)\n",__FUNCTION__, port->line) 191#define func_enter2() rio_dprintk (RIO_DEBUG_FLOW, "rio: enter %s (port %d)\n",__func__, port->line)
192#else 192#else
193#define rio_dprintk(f, str...) /* nothing */ 193#define rio_dprintk(f, str...) /* nothing */
194#define func_enter() 194#define func_enter()
diff --git a/drivers/char/rio/riocmd.c b/drivers/char/rio/riocmd.c
index bf36959fc121..7b96e0814887 100644
--- a/drivers/char/rio/riocmd.c
+++ b/drivers/char/rio/riocmd.c
@@ -417,7 +417,7 @@ static int RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, struc
417 PortP = p->RIOPortp[SysPort]; 417 PortP = p->RIOPortp[SysPort];
418 rio_spin_lock_irqsave(&PortP->portSem, flags); 418 rio_spin_lock_irqsave(&PortP->portSem, flags);
419 switch (readb(&PktCmdP->Command)) { 419 switch (readb(&PktCmdP->Command)) {
420 case BREAK_RECEIVED: 420 case RIOC_BREAK_RECEIVED:
421 rio_dprintk(RIO_DEBUG_CMD, "Received a break!\n"); 421 rio_dprintk(RIO_DEBUG_CMD, "Received a break!\n");
422 /* If the current line disc. is not multi-threading and 422 /* If the current line disc. is not multi-threading and
423 the current processor is not the default, reset rup_intr 423 the current processor is not the default, reset rup_intr
@@ -428,16 +428,16 @@ static int RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, struc
428 gs_got_break(&PortP->gs); 428 gs_got_break(&PortP->gs);
429 break; 429 break;
430 430
431 case COMPLETE: 431 case RIOC_COMPLETE:
432 rio_dprintk(RIO_DEBUG_CMD, "Command complete on phb %d host %Zd\n", readb(&PktCmdP->PhbNum), HostP - p->RIOHosts); 432 rio_dprintk(RIO_DEBUG_CMD, "Command complete on phb %d host %Zd\n", readb(&PktCmdP->PhbNum), HostP - p->RIOHosts);
433 subCommand = 1; 433 subCommand = 1;
434 switch (readb(&PktCmdP->SubCommand)) { 434 switch (readb(&PktCmdP->SubCommand)) {
435 case MEMDUMP: 435 case RIOC_MEMDUMP:
436 rio_dprintk(RIO_DEBUG_CMD, "Memory dump cmd (0x%x) from addr 0x%x\n", readb(&PktCmdP->SubCommand), readw(&PktCmdP->SubAddr)); 436 rio_dprintk(RIO_DEBUG_CMD, "Memory dump cmd (0x%x) from addr 0x%x\n", readb(&PktCmdP->SubCommand), readw(&PktCmdP->SubAddr));
437 break; 437 break;
438 case READ_REGISTER: 438 case RIOC_READ_REGISTER:
439 rio_dprintk(RIO_DEBUG_CMD, "Read register (0x%x)\n", readw(&PktCmdP->SubAddr)); 439 rio_dprintk(RIO_DEBUG_CMD, "Read register (0x%x)\n", readw(&PktCmdP->SubAddr));
440 p->CdRegister = (readb(&PktCmdP->ModemStatus) & MSVR1_HOST); 440 p->CdRegister = (readb(&PktCmdP->ModemStatus) & RIOC_MSVR1_HOST);
441 break; 441 break;
442 default: 442 default:
443 subCommand = 0; 443 subCommand = 0;
@@ -456,14 +456,15 @@ static int RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, struc
456 rio_dprintk(RIO_DEBUG_CMD, "No change\n"); 456 rio_dprintk(RIO_DEBUG_CMD, "No change\n");
457 457
458 /* FALLTHROUGH */ 458 /* FALLTHROUGH */
459 case MODEM_STATUS: 459 case RIOC_MODEM_STATUS:
460 /* 460 /*
461 ** Knock out the tbusy and tstop bits, as these are not relevant 461 ** Knock out the tbusy and tstop bits, as these are not relevant
462 ** to the check for modem status change (they're just there because 462 ** to the check for modem status change (they're just there because
463 ** it's a convenient place to put them!). 463 ** it's a convenient place to put them!).
464 */ 464 */
465 ReportedModemStatus = readb(&PktCmdP->ModemStatus); 465 ReportedModemStatus = readb(&PktCmdP->ModemStatus);
466 if ((PortP->ModemState & MSVR1_HOST) == (ReportedModemStatus & MSVR1_HOST)) { 466 if ((PortP->ModemState & RIOC_MSVR1_HOST) ==
467 (ReportedModemStatus & RIOC_MSVR1_HOST)) {
467 rio_dprintk(RIO_DEBUG_CMD, "Modem status unchanged 0x%x\n", PortP->ModemState); 468 rio_dprintk(RIO_DEBUG_CMD, "Modem status unchanged 0x%x\n", PortP->ModemState);
468 /* 469 /*
469 ** Update ModemState just in case tbusy or tstop states have 470 ** Update ModemState just in case tbusy or tstop states have
@@ -497,7 +498,7 @@ static int RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, struc
497 /* 498 /*
498 ** Is there a carrier? 499 ** Is there a carrier?
499 */ 500 */
500 if (PortP->ModemState & MSVR1_CD) { 501 if (PortP->ModemState & RIOC_MSVR1_CD) {
501 /* 502 /*
502 ** Has carrier just appeared? 503 ** Has carrier just appeared?
503 */ 504 */
@@ -691,7 +692,7 @@ void RIOPollHostCommands(struct rio_info *p, struct Host *HostP)
691 */ 692 */
692 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags); 693 rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
693 FreeMe = RIOCommandRup(p, Rup, HostP, PacketP); 694 FreeMe = RIOCommandRup(p, Rup, HostP, PacketP);
694 if (readb(&PacketP->data[5]) == MEMDUMP) { 695 if (readb(&PacketP->data[5]) == RIOC_MEMDUMP) {
695 rio_dprintk(RIO_DEBUG_CMD, "Memdump from 0x%x complete\n", readw(&(PacketP->data[6]))); 696 rio_dprintk(RIO_DEBUG_CMD, "Memdump from 0x%x complete\n", readw(&(PacketP->data[6])));
696 rio_memcpy_fromio(p->RIOMemDump, &(PacketP->data[8]), 32); 697 rio_memcpy_fromio(p->RIOMemDump, &(PacketP->data[8]), 32);
697 } 698 }
diff --git a/drivers/char/rio/rioctrl.c b/drivers/char/rio/rioctrl.c
index d8eb2bcbe015..d65ceb9a434a 100644
--- a/drivers/char/rio/rioctrl.c
+++ b/drivers/char/rio/rioctrl.c
@@ -422,7 +422,8 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
422 } 422 }
423 423
424 rio_spin_lock_irqsave(&PortP->portSem, flags); 424 rio_spin_lock_irqsave(&PortP->portSem, flags);
425 if (RIOPreemptiveCmd(p, (p->RIOPortp[port]), RESUME) == RIO_FAIL) { 425 if (RIOPreemptiveCmd(p, (p->RIOPortp[port]), RIOC_RESUME) ==
426 RIO_FAIL) {
426 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME failed\n"); 427 rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME failed\n");
427 rio_spin_unlock_irqrestore(&PortP->portSem, flags); 428 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
428 return -EBUSY; 429 return -EBUSY;
@@ -636,7 +637,8 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
636 return -ENXIO; 637 return -ENXIO;
637 } 638 }
638 PortP = (p->RIOPortp[PortTty.port]); 639 PortP = (p->RIOPortp[PortTty.port]);
639 RIOParam(PortP, CONFIG, PortP->State & RIO_MODEM, OK_TO_SLEEP); 640 RIOParam(PortP, RIOC_CONFIG, PortP->State & RIO_MODEM,
641 OK_TO_SLEEP);
640 return retval; 642 return retval;
641 643
642 case RIO_SET_PORT_PARAMS: 644 case RIO_SET_PORT_PARAMS:
@@ -1247,7 +1249,7 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
1247 1249
1248 rio_spin_lock_irqsave(&PortP->portSem, flags); 1250 rio_spin_lock_irqsave(&PortP->portSem, flags);
1249 1251
1250 if (RIOPreemptiveCmd(p, PortP, MEMDUMP) == RIO_FAIL) { 1252 if (RIOPreemptiveCmd(p, PortP, RIOC_MEMDUMP) == RIO_FAIL) {
1251 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP failed\n"); 1253 rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP failed\n");
1252 rio_spin_unlock_irqrestore(&PortP->portSem, flags); 1254 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1253 return -EBUSY; 1255 return -EBUSY;
@@ -1313,7 +1315,8 @@ int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su
1313 1315
1314 rio_spin_lock_irqsave(&PortP->portSem, flags); 1316 rio_spin_lock_irqsave(&PortP->portSem, flags);
1315 1317
1316 if (RIOPreemptiveCmd(p, PortP, READ_REGISTER) == RIO_FAIL) { 1318 if (RIOPreemptiveCmd(p, PortP, RIOC_READ_REGISTER) ==
1319 RIO_FAIL) {
1317 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER failed\n"); 1320 rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER failed\n");
1318 rio_spin_unlock_irqrestore(&PortP->portSem, flags); 1321 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1319 return -EBUSY; 1322 return -EBUSY;
@@ -1434,50 +1437,50 @@ int RIOPreemptiveCmd(struct rio_info *p, struct Port *PortP, u8 Cmd)
1434 PktCmdP->PhbNum = port; 1437 PktCmdP->PhbNum = port;
1435 1438
1436 switch (Cmd) { 1439 switch (Cmd) {
1437 case MEMDUMP: 1440 case RIOC_MEMDUMP:
1438 rio_dprintk(RIO_DEBUG_CTRL, "Queue MEMDUMP command blk %p " 1441 rio_dprintk(RIO_DEBUG_CTRL, "Queue MEMDUMP command blk %p "
1439 "(addr 0x%x)\n", CmdBlkP, (int) SubCmd.Addr); 1442 "(addr 0x%x)\n", CmdBlkP, (int) SubCmd.Addr);
1440 PktCmdP->SubCommand = MEMDUMP; 1443 PktCmdP->SubCommand = RIOC_MEMDUMP;
1441 PktCmdP->SubAddr = SubCmd.Addr; 1444 PktCmdP->SubAddr = SubCmd.Addr;
1442 break; 1445 break;
1443 case FCLOSE: 1446 case RIOC_FCLOSE:
1444 rio_dprintk(RIO_DEBUG_CTRL, "Queue FCLOSE command blk %p\n", 1447 rio_dprintk(RIO_DEBUG_CTRL, "Queue FCLOSE command blk %p\n",
1445 CmdBlkP); 1448 CmdBlkP);
1446 break; 1449 break;
1447 case READ_REGISTER: 1450 case RIOC_READ_REGISTER:
1448 rio_dprintk(RIO_DEBUG_CTRL, "Queue READ_REGISTER (0x%x) " 1451 rio_dprintk(RIO_DEBUG_CTRL, "Queue READ_REGISTER (0x%x) "
1449 "command blk %p\n", (int) SubCmd.Addr, CmdBlkP); 1452 "command blk %p\n", (int) SubCmd.Addr, CmdBlkP);
1450 PktCmdP->SubCommand = READ_REGISTER; 1453 PktCmdP->SubCommand = RIOC_READ_REGISTER;
1451 PktCmdP->SubAddr = SubCmd.Addr; 1454 PktCmdP->SubAddr = SubCmd.Addr;
1452 break; 1455 break;
1453 case RESUME: 1456 case RIOC_RESUME:
1454 rio_dprintk(RIO_DEBUG_CTRL, "Queue RESUME command blk %p\n", 1457 rio_dprintk(RIO_DEBUG_CTRL, "Queue RESUME command blk %p\n",
1455 CmdBlkP); 1458 CmdBlkP);
1456 break; 1459 break;
1457 case RFLUSH: 1460 case RIOC_RFLUSH:
1458 rio_dprintk(RIO_DEBUG_CTRL, "Queue RFLUSH command blk %p\n", 1461 rio_dprintk(RIO_DEBUG_CTRL, "Queue RFLUSH command blk %p\n",
1459 CmdBlkP); 1462 CmdBlkP);
1460 CmdBlkP->PostFuncP = RIORFlushEnable; 1463 CmdBlkP->PostFuncP = RIORFlushEnable;
1461 break; 1464 break;
1462 case SUSPEND: 1465 case RIOC_SUSPEND:
1463 rio_dprintk(RIO_DEBUG_CTRL, "Queue SUSPEND command blk %p\n", 1466 rio_dprintk(RIO_DEBUG_CTRL, "Queue SUSPEND command blk %p\n",
1464 CmdBlkP); 1467 CmdBlkP);
1465 break; 1468 break;
1466 1469
1467 case MGET: 1470 case RIOC_MGET:
1468 rio_dprintk(RIO_DEBUG_CTRL, "Queue MGET command blk %p\n", 1471 rio_dprintk(RIO_DEBUG_CTRL, "Queue MGET command blk %p\n",
1469 CmdBlkP); 1472 CmdBlkP);
1470 break; 1473 break;
1471 1474
1472 case MSET: 1475 case RIOC_MSET:
1473 case MBIC: 1476 case RIOC_MBIC:
1474 case MBIS: 1477 case RIOC_MBIS:
1475 CmdBlkP->Packet.data[4] = (char) PortP->ModemLines; 1478 CmdBlkP->Packet.data[4] = (char) PortP->ModemLines;
1476 rio_dprintk(RIO_DEBUG_CTRL, "Queue MSET/MBIC/MBIS command " 1479 rio_dprintk(RIO_DEBUG_CTRL, "Queue MSET/MBIC/MBIS command "
1477 "blk %p\n", CmdBlkP); 1480 "blk %p\n", CmdBlkP);
1478 break; 1481 break;
1479 1482
1480 case WFLUSH: 1483 case RIOC_WFLUSH:
1481 /* 1484 /*
1482 ** If we have queued up the maximum number of Write flushes 1485 ** If we have queued up the maximum number of Write flushes
1483 ** allowed then we should not bother sending any more to the 1486 ** allowed then we should not bother sending any more to the
diff --git a/drivers/char/rio/riointr.c b/drivers/char/rio/riointr.c
index 4734e26e1ccd..ea21686c69a4 100644
--- a/drivers/char/rio/riointr.c
+++ b/drivers/char/rio/riointr.c
@@ -401,9 +401,8 @@ void RIOServiceHost(struct rio_info *p, struct Host *HostP)
401 PortP->InUse = NOT_INUSE; 401 PortP->InUse = NOT_INUSE;
402 402
403 rio_spin_unlock(&PortP->portSem); 403 rio_spin_unlock(&PortP->portSem);
404 if (RIOParam(PortP, OPEN, ((PortP->Cor2Copy & (COR2_RTSFLOW | COR2_CTSFLOW)) == (COR2_RTSFLOW | COR2_CTSFLOW)) ? 1 : 0, DONT_SLEEP) == RIO_FAIL) { 404 if (RIOParam(PortP, RIOC_OPEN, ((PortP->Cor2Copy & (RIOC_COR2_RTSFLOW | RIOC_COR2_CTSFLOW)) == (RIOC_COR2_RTSFLOW | RIOC_COR2_CTSFLOW)) ? 1 : 0, DONT_SLEEP) == RIO_FAIL)
405 continue; /* with next port */ 405 continue; /* with next port */
406 }
407 rio_spin_lock(&PortP->portSem); 406 rio_spin_lock(&PortP->portSem);
408 PortP->MagicFlags &= ~MAGIC_REBOOT; 407 PortP->MagicFlags &= ~MAGIC_REBOOT;
409 } 408 }
@@ -429,7 +428,7 @@ void RIOServiceHost(struct rio_info *p, struct Host *HostP)
429 */ 428 */
430 PktCmdP = (struct PktCmd __iomem *) &PacketP->data[0]; 429 PktCmdP = (struct PktCmd __iomem *) &PacketP->data[0];
431 430
432 writeb(WFLUSH, &PktCmdP->Command); 431 writeb(RIOC_WFLUSH, &PktCmdP->Command);
433 432
434 p = PortP->HostPort % (u16) PORTS_PER_RTA; 433 p = PortP->HostPort % (u16) PORTS_PER_RTA;
435 434
diff --git a/drivers/char/rio/rioparam.c b/drivers/char/rio/rioparam.c
index da276ed57b3f..4810b845cc21 100644
--- a/drivers/char/rio/rioparam.c
+++ b/drivers/char/rio/rioparam.c
@@ -177,7 +177,7 @@ int RIOParam(struct Port *PortP, int cmd, int Modem, int SleepFlag)
177 } 177 }
178 rio_spin_lock_irqsave(&PortP->portSem, flags); 178 rio_spin_lock_irqsave(&PortP->portSem, flags);
179 179
180 if (cmd == OPEN) { 180 if (cmd == RIOC_OPEN) {
181 /* 181 /*
182 ** If the port is set to store or lock the parameters, and it is 182 ** If the port is set to store or lock the parameters, and it is
183 ** paramed with OPEN, we want to restore the saved port termio, but 183 ** paramed with OPEN, we want to restore the saved port termio, but
@@ -241,50 +241,50 @@ int RIOParam(struct Port *PortP, int cmd, int Modem, int SleepFlag)
241 case CS5: 241 case CS5:
242 { 242 {
243 rio_dprintk(RIO_DEBUG_PARAM, "5 bit data\n"); 243 rio_dprintk(RIO_DEBUG_PARAM, "5 bit data\n");
244 Cor1 |= COR1_5BITS; 244 Cor1 |= RIOC_COR1_5BITS;
245 break; 245 break;
246 } 246 }
247 case CS6: 247 case CS6:
248 { 248 {
249 rio_dprintk(RIO_DEBUG_PARAM, "6 bit data\n"); 249 rio_dprintk(RIO_DEBUG_PARAM, "6 bit data\n");
250 Cor1 |= COR1_6BITS; 250 Cor1 |= RIOC_COR1_6BITS;
251 break; 251 break;
252 } 252 }
253 case CS7: 253 case CS7:
254 { 254 {
255 rio_dprintk(RIO_DEBUG_PARAM, "7 bit data\n"); 255 rio_dprintk(RIO_DEBUG_PARAM, "7 bit data\n");
256 Cor1 |= COR1_7BITS; 256 Cor1 |= RIOC_COR1_7BITS;
257 break; 257 break;
258 } 258 }
259 case CS8: 259 case CS8:
260 { 260 {
261 rio_dprintk(RIO_DEBUG_PARAM, "8 bit data\n"); 261 rio_dprintk(RIO_DEBUG_PARAM, "8 bit data\n");
262 Cor1 |= COR1_8BITS; 262 Cor1 |= RIOC_COR1_8BITS;
263 break; 263 break;
264 } 264 }
265 } 265 }
266 266
267 if (TtyP->termios->c_cflag & CSTOPB) { 267 if (TtyP->termios->c_cflag & CSTOPB) {
268 rio_dprintk(RIO_DEBUG_PARAM, "2 stop bits\n"); 268 rio_dprintk(RIO_DEBUG_PARAM, "2 stop bits\n");
269 Cor1 |= COR1_2STOP; 269 Cor1 |= RIOC_COR1_2STOP;
270 } else { 270 } else {
271 rio_dprintk(RIO_DEBUG_PARAM, "1 stop bit\n"); 271 rio_dprintk(RIO_DEBUG_PARAM, "1 stop bit\n");
272 Cor1 |= COR1_1STOP; 272 Cor1 |= RIOC_COR1_1STOP;
273 } 273 }
274 274
275 if (TtyP->termios->c_cflag & PARENB) { 275 if (TtyP->termios->c_cflag & PARENB) {
276 rio_dprintk(RIO_DEBUG_PARAM, "Enable parity\n"); 276 rio_dprintk(RIO_DEBUG_PARAM, "Enable parity\n");
277 Cor1 |= COR1_NORMAL; 277 Cor1 |= RIOC_COR1_NORMAL;
278 } else { 278 } else {
279 rio_dprintk(RIO_DEBUG_PARAM, "Disable parity\n"); 279 rio_dprintk(RIO_DEBUG_PARAM, "Disable parity\n");
280 Cor1 |= COR1_NOP; 280 Cor1 |= RIOC_COR1_NOP;
281 } 281 }
282 if (TtyP->termios->c_cflag & PARODD) { 282 if (TtyP->termios->c_cflag & PARODD) {
283 rio_dprintk(RIO_DEBUG_PARAM, "Odd parity\n"); 283 rio_dprintk(RIO_DEBUG_PARAM, "Odd parity\n");
284 Cor1 |= COR1_ODD; 284 Cor1 |= RIOC_COR1_ODD;
285 } else { 285 } else {
286 rio_dprintk(RIO_DEBUG_PARAM, "Even parity\n"); 286 rio_dprintk(RIO_DEBUG_PARAM, "Even parity\n");
287 Cor1 |= COR1_EVEN; 287 Cor1 |= RIOC_COR1_EVEN;
288 } 288 }
289 289
290 /* 290 /*
@@ -292,11 +292,11 @@ int RIOParam(struct Port *PortP, int cmd, int Modem, int SleepFlag)
292 */ 292 */
293 if (TtyP->termios->c_iflag & IXON) { 293 if (TtyP->termios->c_iflag & IXON) {
294 rio_dprintk(RIO_DEBUG_PARAM, "Enable start/stop output control\n"); 294 rio_dprintk(RIO_DEBUG_PARAM, "Enable start/stop output control\n");
295 Cor2 |= COR2_IXON; 295 Cor2 |= RIOC_COR2_IXON;
296 } else { 296 } else {
297 if (PortP->Config & RIO_IXON) { 297 if (PortP->Config & RIO_IXON) {
298 rio_dprintk(RIO_DEBUG_PARAM, "Force enable start/stop output control\n"); 298 rio_dprintk(RIO_DEBUG_PARAM, "Force enable start/stop output control\n");
299 Cor2 |= COR2_IXON; 299 Cor2 |= RIOC_COR2_IXON;
300 } else 300 } else
301 rio_dprintk(RIO_DEBUG_PARAM, "IXON has been disabled.\n"); 301 rio_dprintk(RIO_DEBUG_PARAM, "IXON has been disabled.\n");
302 } 302 }
@@ -304,29 +304,29 @@ int RIOParam(struct Port *PortP, int cmd, int Modem, int SleepFlag)
304 if (TtyP->termios->c_iflag & IXANY) { 304 if (TtyP->termios->c_iflag & IXANY) {
305 if (PortP->Config & RIO_IXANY) { 305 if (PortP->Config & RIO_IXANY) {
306 rio_dprintk(RIO_DEBUG_PARAM, "Enable any key to restart output\n"); 306 rio_dprintk(RIO_DEBUG_PARAM, "Enable any key to restart output\n");
307 Cor2 |= COR2_IXANY; 307 Cor2 |= RIOC_COR2_IXANY;
308 } else 308 } else
309 rio_dprintk(RIO_DEBUG_PARAM, "IXANY has been disabled due to sanity reasons.\n"); 309 rio_dprintk(RIO_DEBUG_PARAM, "IXANY has been disabled due to sanity reasons.\n");
310 } 310 }
311 311
312 if (TtyP->termios->c_iflag & IXOFF) { 312 if (TtyP->termios->c_iflag & IXOFF) {
313 rio_dprintk(RIO_DEBUG_PARAM, "Enable start/stop input control 2\n"); 313 rio_dprintk(RIO_DEBUG_PARAM, "Enable start/stop input control 2\n");
314 Cor2 |= COR2_IXOFF; 314 Cor2 |= RIOC_COR2_IXOFF;
315 } 315 }
316 316
317 if (TtyP->termios->c_cflag & HUPCL) { 317 if (TtyP->termios->c_cflag & HUPCL) {
318 rio_dprintk(RIO_DEBUG_PARAM, "Hangup on last close\n"); 318 rio_dprintk(RIO_DEBUG_PARAM, "Hangup on last close\n");
319 Cor2 |= COR2_HUPCL; 319 Cor2 |= RIOC_COR2_HUPCL;
320 } 320 }
321 321
322 if (C_CRTSCTS(TtyP)) { 322 if (C_CRTSCTS(TtyP)) {
323 rio_dprintk(RIO_DEBUG_PARAM, "Rx hardware flow control enabled\n"); 323 rio_dprintk(RIO_DEBUG_PARAM, "Rx hardware flow control enabled\n");
324 Cor2 |= COR2_CTSFLOW; 324 Cor2 |= RIOC_COR2_CTSFLOW;
325 Cor2 |= COR2_RTSFLOW; 325 Cor2 |= RIOC_COR2_RTSFLOW;
326 } else { 326 } else {
327 rio_dprintk(RIO_DEBUG_PARAM, "Rx hardware flow control disabled\n"); 327 rio_dprintk(RIO_DEBUG_PARAM, "Rx hardware flow control disabled\n");
328 Cor2 &= ~COR2_CTSFLOW; 328 Cor2 &= ~RIOC_COR2_CTSFLOW;
329 Cor2 &= ~COR2_RTSFLOW; 329 Cor2 &= ~RIOC_COR2_RTSFLOW;
330 } 330 }
331 331
332 332
@@ -341,36 +341,36 @@ int RIOParam(struct Port *PortP, int cmd, int Modem, int SleepFlag)
341 */ 341 */
342 if (TtyP->termios->c_iflag & IGNBRK) { 342 if (TtyP->termios->c_iflag & IGNBRK) {
343 rio_dprintk(RIO_DEBUG_PARAM, "Ignore break condition\n"); 343 rio_dprintk(RIO_DEBUG_PARAM, "Ignore break condition\n");
344 Cor4 |= COR4_IGNBRK; 344 Cor4 |= RIOC_COR4_IGNBRK;
345 } 345 }
346 if (!(TtyP->termios->c_iflag & BRKINT)) { 346 if (!(TtyP->termios->c_iflag & BRKINT)) {
347 rio_dprintk(RIO_DEBUG_PARAM, "Break generates NULL condition\n"); 347 rio_dprintk(RIO_DEBUG_PARAM, "Break generates NULL condition\n");
348 Cor4 |= COR4_NBRKINT; 348 Cor4 |= RIOC_COR4_NBRKINT;
349 } else { 349 } else {
350 rio_dprintk(RIO_DEBUG_PARAM, "Interrupt on break condition\n"); 350 rio_dprintk(RIO_DEBUG_PARAM, "Interrupt on break condition\n");
351 } 351 }
352 352
353 if (TtyP->termios->c_iflag & INLCR) { 353 if (TtyP->termios->c_iflag & INLCR) {
354 rio_dprintk(RIO_DEBUG_PARAM, "Map newline to carriage return on input\n"); 354 rio_dprintk(RIO_DEBUG_PARAM, "Map newline to carriage return on input\n");
355 Cor4 |= COR4_INLCR; 355 Cor4 |= RIOC_COR4_INLCR;
356 } 356 }
357 357
358 if (TtyP->termios->c_iflag & IGNCR) { 358 if (TtyP->termios->c_iflag & IGNCR) {
359 rio_dprintk(RIO_DEBUG_PARAM, "Ignore carriage return on input\n"); 359 rio_dprintk(RIO_DEBUG_PARAM, "Ignore carriage return on input\n");
360 Cor4 |= COR4_IGNCR; 360 Cor4 |= RIOC_COR4_IGNCR;
361 } 361 }
362 362
363 if (TtyP->termios->c_iflag & ICRNL) { 363 if (TtyP->termios->c_iflag & ICRNL) {
364 rio_dprintk(RIO_DEBUG_PARAM, "Map carriage return to newline on input\n"); 364 rio_dprintk(RIO_DEBUG_PARAM, "Map carriage return to newline on input\n");
365 Cor4 |= COR4_ICRNL; 365 Cor4 |= RIOC_COR4_ICRNL;
366 } 366 }
367 if (TtyP->termios->c_iflag & IGNPAR) { 367 if (TtyP->termios->c_iflag & IGNPAR) {
368 rio_dprintk(RIO_DEBUG_PARAM, "Ignore characters with parity errors\n"); 368 rio_dprintk(RIO_DEBUG_PARAM, "Ignore characters with parity errors\n");
369 Cor4 |= COR4_IGNPAR; 369 Cor4 |= RIOC_COR4_IGNPAR;
370 } 370 }
371 if (TtyP->termios->c_iflag & PARMRK) { 371 if (TtyP->termios->c_iflag & PARMRK) {
372 rio_dprintk(RIO_DEBUG_PARAM, "Mark parity errors\n"); 372 rio_dprintk(RIO_DEBUG_PARAM, "Mark parity errors\n");
373 Cor4 |= COR4_PARMRK; 373 Cor4 |= RIOC_COR4_PARMRK;
374 } 374 }
375 375
376 /* 376 /*
@@ -378,22 +378,22 @@ int RIOParam(struct Port *PortP, int cmd, int Modem, int SleepFlag)
378 ** on reception of a config packet. 378 ** on reception of a config packet.
379 ** The download code handles the zero baud condition. 379 ** The download code handles the zero baud condition.
380 */ 380 */
381 Cor4 |= COR4_RAISEMOD; 381 Cor4 |= RIOC_COR4_RAISEMOD;
382 382
383 /* 383 /*
384 ** COR 5 384 ** COR 5
385 */ 385 */
386 386
387 Cor5 = COR5_CMOE; 387 Cor5 = RIOC_COR5_CMOE;
388 388
389 /* 389 /*
390 ** Set to monitor tbusy/tstop (or not). 390 ** Set to monitor tbusy/tstop (or not).
391 */ 391 */
392 392
393 if (PortP->MonitorTstate) 393 if (PortP->MonitorTstate)
394 Cor5 |= COR5_TSTATE_ON; 394 Cor5 |= RIOC_COR5_TSTATE_ON;
395 else 395 else
396 Cor5 |= COR5_TSTATE_OFF; 396 Cor5 |= RIOC_COR5_TSTATE_OFF;
397 397
398 /* 398 /*
399 ** Could set LNE here if you wanted LNext processing. SVR4 will use it. 399 ** Could set LNE here if you wanted LNext processing. SVR4 will use it.
@@ -401,24 +401,24 @@ int RIOParam(struct Port *PortP, int cmd, int Modem, int SleepFlag)
401 if (TtyP->termios->c_iflag & ISTRIP) { 401 if (TtyP->termios->c_iflag & ISTRIP) {
402 rio_dprintk(RIO_DEBUG_PARAM, "Strip input characters\n"); 402 rio_dprintk(RIO_DEBUG_PARAM, "Strip input characters\n");
403 if (!(PortP->State & RIO_TRIAD_MODE)) { 403 if (!(PortP->State & RIO_TRIAD_MODE)) {
404 Cor5 |= COR5_ISTRIP; 404 Cor5 |= RIOC_COR5_ISTRIP;
405 } 405 }
406 } 406 }
407 407
408 if (TtyP->termios->c_oflag & ONLCR) { 408 if (TtyP->termios->c_oflag & ONLCR) {
409 rio_dprintk(RIO_DEBUG_PARAM, "Map newline to carriage-return, newline on output\n"); 409 rio_dprintk(RIO_DEBUG_PARAM, "Map newline to carriage-return, newline on output\n");
410 if (PortP->CookMode == COOK_MEDIUM) 410 if (PortP->CookMode == COOK_MEDIUM)
411 Cor5 |= COR5_ONLCR; 411 Cor5 |= RIOC_COR5_ONLCR;
412 } 412 }
413 if (TtyP->termios->c_oflag & OCRNL) { 413 if (TtyP->termios->c_oflag & OCRNL) {
414 rio_dprintk(RIO_DEBUG_PARAM, "Map carriage return to newline on output\n"); 414 rio_dprintk(RIO_DEBUG_PARAM, "Map carriage return to newline on output\n");
415 if (PortP->CookMode == COOK_MEDIUM) 415 if (PortP->CookMode == COOK_MEDIUM)
416 Cor5 |= COR5_OCRNL; 416 Cor5 |= RIOC_COR5_OCRNL;
417 } 417 }
418 if ((TtyP->termios->c_oflag & TABDLY) == TAB3) { 418 if ((TtyP->termios->c_oflag & TABDLY) == TAB3) {
419 rio_dprintk(RIO_DEBUG_PARAM, "Tab delay 3 set\n"); 419 rio_dprintk(RIO_DEBUG_PARAM, "Tab delay 3 set\n");
420 if (PortP->CookMode == COOK_MEDIUM) 420 if (PortP->CookMode == COOK_MEDIUM)
421 Cor5 |= COR5_TAB3; 421 Cor5 |= RIOC_COR5_TAB3;
422 } 422 }
423 423
424 /* 424 /*
diff --git a/drivers/char/rio/riotty.c b/drivers/char/rio/riotty.c
index 1cb8580a161d..c99354843be1 100644
--- a/drivers/char/rio/riotty.c
+++ b/drivers/char/rio/riotty.c
@@ -211,7 +211,7 @@ int riotopen(struct tty_struct *tty, struct file *filp)
211 rio_dprintk(RIO_DEBUG_TTY, "Waiting for RIO_CLOSING to go away\n"); 211 rio_dprintk(RIO_DEBUG_TTY, "Waiting for RIO_CLOSING to go away\n");
212 if (repeat_this-- <= 0) { 212 if (repeat_this-- <= 0) {
213 rio_dprintk(RIO_DEBUG_TTY, "Waiting for not idle closed broken by signal\n"); 213 rio_dprintk(RIO_DEBUG_TTY, "Waiting for not idle closed broken by signal\n");
214 RIOPreemptiveCmd(p, PortP, FCLOSE); 214 RIOPreemptiveCmd(p, PortP, RIOC_FCLOSE);
215 retval = -EINTR; 215 retval = -EINTR;
216 goto bombout; 216 goto bombout;
217 } 217 }
@@ -264,7 +264,7 @@ int riotopen(struct tty_struct *tty, struct file *filp)
264 here. If I read the docs correctly the "open" 264 here. If I read the docs correctly the "open"
265 command piggybacks the parameters immediately. 265 command piggybacks the parameters immediately.
266 -- REW */ 266 -- REW */
267 RIOParam(PortP, OPEN, 1, OK_TO_SLEEP); /* Open the port */ 267 RIOParam(PortP, RIOC_OPEN, 1, OK_TO_SLEEP); /* Open the port */
268 rio_spin_lock_irqsave(&PortP->portSem, flags); 268 rio_spin_lock_irqsave(&PortP->portSem, flags);
269 269
270 /* 270 /*
@@ -275,7 +275,7 @@ int riotopen(struct tty_struct *tty, struct file *filp)
275 rio_spin_unlock_irqrestore(&PortP->portSem, flags); 275 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
276 if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) { 276 if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
277 rio_dprintk(RIO_DEBUG_TTY, "Waiting for open to finish broken by signal\n"); 277 rio_dprintk(RIO_DEBUG_TTY, "Waiting for open to finish broken by signal\n");
278 RIOPreemptiveCmd(p, PortP, FCLOSE); 278 RIOPreemptiveCmd(p, PortP, RIOC_FCLOSE);
279 func_exit(); 279 func_exit();
280 return -EINTR; 280 return -EINTR;
281 } 281 }
@@ -297,7 +297,8 @@ int riotopen(struct tty_struct *tty, struct file *filp)
297 ** insert test for carrier here. -- ??? 297 ** insert test for carrier here. -- ???
298 ** I already see that test here. What's the deal? -- REW 298 ** I already see that test here. What's the deal? -- REW
299 */ 299 */
300 if ((PortP->gs.tty->termios->c_cflag & CLOCAL) || (PortP->ModemState & MSVR1_CD)) { 300 if ((PortP->gs.tty->termios->c_cflag & CLOCAL) ||
301 (PortP->ModemState & RIOC_MSVR1_CD)) {
301 rio_dprintk(RIO_DEBUG_TTY, "open(%d) Modem carr on\n", SysPort); 302 rio_dprintk(RIO_DEBUG_TTY, "open(%d) Modem carr on\n", SysPort);
302 /* 303 /*
303 tp->tm.c_state |= CARR_ON; 304 tp->tm.c_state |= CARR_ON;
@@ -325,7 +326,7 @@ int riotopen(struct tty_struct *tty, struct file *filp)
325 ** I think it's OK. -- REW 326 ** I think it's OK. -- REW
326 */ 327 */
327 rio_dprintk(RIO_DEBUG_TTY, "open(%d) sleeping for carr broken by signal\n", SysPort); 328 rio_dprintk(RIO_DEBUG_TTY, "open(%d) sleeping for carr broken by signal\n", SysPort);
328 RIOPreemptiveCmd(p, PortP, FCLOSE); 329 RIOPreemptiveCmd(p, PortP, RIOC_FCLOSE);
329 /* 330 /*
330 tp->tm.c_state &= ~WOPEN; 331 tp->tm.c_state &= ~WOPEN;
331 */ 332 */
@@ -416,7 +417,7 @@ int riotclose(void *ptr)
416 */ 417 */
417 PortP->State &= ~RIO_MOPEN; 418 PortP->State &= ~RIO_MOPEN;
418 PortP->State &= ~RIO_CARR_ON; 419 PortP->State &= ~RIO_CARR_ON;
419 PortP->ModemState &= ~MSVR1_CD; 420 PortP->ModemState &= ~RIOC_MSVR1_CD;
420 /* 421 /*
421 ** If the device was open as both a Modem and a tty line 422 ** If the device was open as both a Modem and a tty line
422 ** then we need to wimp out here, as the port has not really 423 ** then we need to wimp out here, as the port has not really
@@ -453,7 +454,7 @@ int riotclose(void *ptr)
453 if (repeat_this-- <= 0) { 454 if (repeat_this-- <= 0) {
454 rv = -EINTR; 455 rv = -EINTR;
455 rio_dprintk(RIO_DEBUG_TTY, "Waiting for not idle closed broken by signal\n"); 456 rio_dprintk(RIO_DEBUG_TTY, "Waiting for not idle closed broken by signal\n");
456 RIOPreemptiveCmd(p, PortP, FCLOSE); 457 RIOPreemptiveCmd(p, PortP, RIOC_FCLOSE);
457 goto close_end; 458 goto close_end;
458 } 459 }
459 rio_dprintk(RIO_DEBUG_TTY, "Calling timeout to flush in closing\n"); 460 rio_dprintk(RIO_DEBUG_TTY, "Calling timeout to flush in closing\n");
@@ -492,8 +493,8 @@ int riotclose(void *ptr)
492 /* Can't call RIOShortCommand with the port locked. */ 493 /* Can't call RIOShortCommand with the port locked. */
493 rio_spin_unlock_irqrestore(&PortP->portSem, flags); 494 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
494 495
495 if (RIOShortCommand(p, PortP, CLOSE, 1, 0) == RIO_FAIL) { 496 if (RIOShortCommand(p, PortP, RIOC_CLOSE, 1, 0) == RIO_FAIL) {
496 RIOPreemptiveCmd(p, PortP, FCLOSE); 497 RIOPreemptiveCmd(p, PortP, RIOC_FCLOSE);
497 rio_spin_lock_irqsave(&PortP->portSem, flags); 498 rio_spin_lock_irqsave(&PortP->portSem, flags);
498 goto close_end; 499 goto close_end;
499 } 500 }
@@ -503,7 +504,7 @@ int riotclose(void *ptr)
503 try--; 504 try--;
504 if (time_after(jiffies, end_time)) { 505 if (time_after(jiffies, end_time)) {
505 rio_dprintk(RIO_DEBUG_TTY, "Run out of tries - force the bugger shut!\n"); 506 rio_dprintk(RIO_DEBUG_TTY, "Run out of tries - force the bugger shut!\n");
506 RIOPreemptiveCmd(p, PortP, FCLOSE); 507 RIOPreemptiveCmd(p, PortP, RIOC_FCLOSE);
507 break; 508 break;
508 } 509 }
509 rio_dprintk(RIO_DEBUG_TTY, "Close: PortState:ISOPEN is %d\n", PortP->PortState & PORT_ISOPEN); 510 rio_dprintk(RIO_DEBUG_TTY, "Close: PortState:ISOPEN is %d\n", PortP->PortState & PORT_ISOPEN);
@@ -515,14 +516,14 @@ int riotclose(void *ptr)
515 } 516 }
516 if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) { 517 if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
517 rio_dprintk(RIO_DEBUG_TTY, "RTA EINTR in delay \n"); 518 rio_dprintk(RIO_DEBUG_TTY, "RTA EINTR in delay \n");
518 RIOPreemptiveCmd(p, PortP, FCLOSE); 519 RIOPreemptiveCmd(p, PortP, RIOC_FCLOSE);
519 break; 520 break;
520 } 521 }
521 } 522 }
522 rio_spin_lock_irqsave(&PortP->portSem, flags); 523 rio_spin_lock_irqsave(&PortP->portSem, flags);
523 rio_dprintk(RIO_DEBUG_TTY, "Close: try was %d on completion\n", try); 524 rio_dprintk(RIO_DEBUG_TTY, "Close: try was %d on completion\n", try);
524 525
525 /* RIOPreemptiveCmd(p, PortP, FCLOSE); */ 526 /* RIOPreemptiveCmd(p, PortP, RIOC_FCLOSE); */
526 527
527/* 528/*
528** 15.10.1998 ARG - ESIL 0761 part fix 529** 15.10.1998 ARG - ESIL 0761 part fix
diff --git a/drivers/char/riscom8.c b/drivers/char/riscom8.c
index 3f9d0a9ac36d..f073c710ab8d 100644
--- a/drivers/char/riscom8.c
+++ b/drivers/char/riscom8.c
@@ -4,9 +4,9 @@
4 * Copyright (C) 1994-1996 Dmitry Gorodchanin (pgmdsg@ibi.com) 4 * Copyright (C) 1994-1996 Dmitry Gorodchanin (pgmdsg@ibi.com)
5 * 5 *
6 * This code is loosely based on the Linux serial driver, written by 6 * This code is loosely based on the Linux serial driver, written by
7 * Linus Torvalds, Theodore T'so and others. The RISCom/8 card 7 * Linus Torvalds, Theodore T'so and others. The RISCom/8 card
8 * programming info was obtained from various drivers for other OSes 8 * programming info was obtained from various drivers for other OSes
9 * (FreeBSD, ISC, etc), but no source code from those drivers were 9 * (FreeBSD, ISC, etc), but no source code from those drivers were
10 * directly included in this driver. 10 * directly included in this driver.
11 * 11 *
12 * 12 *
@@ -33,7 +33,7 @@
33 33
34#include <linux/module.h> 34#include <linux/module.h>
35 35
36#include <asm/io.h> 36#include <linux/io.h>
37#include <linux/kernel.h> 37#include <linux/kernel.h>
38#include <linux/sched.h> 38#include <linux/sched.h>
39#include <linux/ioport.h> 39#include <linux/ioport.h>
@@ -49,7 +49,7 @@
49#include <linux/tty_flip.h> 49#include <linux/tty_flip.h>
50#include <linux/spinlock.h> 50#include <linux/spinlock.h>
51 51
52#include <asm/uaccess.h> 52#include <linux/uaccess.h>
53 53
54#include "riscom8.h" 54#include "riscom8.h"
55#include "riscom8_reg.h" 55#include "riscom8_reg.h"
@@ -57,15 +57,15 @@
57/* Am I paranoid or not ? ;-) */ 57/* Am I paranoid or not ? ;-) */
58#define RISCOM_PARANOIA_CHECK 58#define RISCOM_PARANOIA_CHECK
59 59
60/* 60/*
61 * Crazy InteliCom/8 boards sometimes has swapped CTS & DSR signals. 61 * Crazy InteliCom/8 boards sometimes have swapped CTS & DSR signals.
62 * You can slightly speed up things by #undefing the following option, 62 * You can slightly speed up things by #undefing the following option,
63 * if you are REALLY sure that your board is correct one. 63 * if you are REALLY sure that your board is correct one.
64 */ 64 */
65 65
66#define RISCOM_BRAIN_DAMAGED_CTS 66#define RISCOM_BRAIN_DAMAGED_CTS
67 67
68/* 68/*
69 * The following defines are mostly for testing purposes. But if you need 69 * The following defines are mostly for testing purposes. But if you need
70 * some nice reporting in your syslog, you can define them also. 70 * some nice reporting in your syslog, you can define them also.
71 */ 71 */
@@ -112,7 +112,7 @@ static unsigned short rc_ioport[] = {
112#define RC_NIOPORT ARRAY_SIZE(rc_ioport) 112#define RC_NIOPORT ARRAY_SIZE(rc_ioport)
113 113
114 114
115static inline int rc_paranoia_check(struct riscom_port const * port, 115static int rc_paranoia_check(struct riscom_port const *port,
116 char *name, const char *routine) 116 char *name, const char *routine)
117{ 117{
118#ifdef RISCOM_PARANOIA_CHECK 118#ifdef RISCOM_PARANOIA_CHECK
@@ -134,52 +134,53 @@ static inline int rc_paranoia_check(struct riscom_port const * port,
134} 134}
135 135
136/* 136/*
137 * 137 *
138 * Service functions for RISCom/8 driver. 138 * Service functions for RISCom/8 driver.
139 * 139 *
140 */ 140 */
141 141
142/* Get board number from pointer */ 142/* Get board number from pointer */
143static inline int board_No (struct riscom_board const * bp) 143static inline int board_No(struct riscom_board const *bp)
144{ 144{
145 return bp - rc_board; 145 return bp - rc_board;
146} 146}
147 147
148/* Get port number from pointer */ 148/* Get port number from pointer */
149static inline int port_No (struct riscom_port const * port) 149static inline int port_No(struct riscom_port const *port)
150{ 150{
151 return RC_PORT(port - rc_port); 151 return RC_PORT(port - rc_port);
152} 152}
153 153
154/* Get pointer to board from pointer to port */ 154/* Get pointer to board from pointer to port */
155static inline struct riscom_board * port_Board(struct riscom_port const * port) 155static inline struct riscom_board *port_Board(struct riscom_port const *port)
156{ 156{
157 return &rc_board[RC_BOARD(port - rc_port)]; 157 return &rc_board[RC_BOARD(port - rc_port)];
158} 158}
159 159
160/* Input Byte from CL CD180 register */ 160/* Input Byte from CL CD180 register */
161static inline unsigned char rc_in(struct riscom_board const * bp, unsigned short reg) 161static inline unsigned char rc_in(struct riscom_board const *bp,
162 unsigned short reg)
162{ 163{
163 return inb(bp->base + RC_TO_ISA(reg)); 164 return inb(bp->base + RC_TO_ISA(reg));
164} 165}
165 166
166/* Output Byte to CL CD180 register */ 167/* Output Byte to CL CD180 register */
167static inline void rc_out(struct riscom_board const * bp, unsigned short reg, 168static inline void rc_out(struct riscom_board const *bp, unsigned short reg,
168 unsigned char val) 169 unsigned char val)
169{ 170{
170 outb(val, bp->base + RC_TO_ISA(reg)); 171 outb(val, bp->base + RC_TO_ISA(reg));
171} 172}
172 173
173/* Wait for Channel Command Register ready */ 174/* Wait for Channel Command Register ready */
174static inline void rc_wait_CCR(struct riscom_board const * bp) 175static void rc_wait_CCR(struct riscom_board const *bp)
175{ 176{
176 unsigned long delay; 177 unsigned long delay;
177 178
178 /* FIXME: need something more descriptive then 100000 :) */ 179 /* FIXME: need something more descriptive then 100000 :) */
179 for (delay = 100000; delay; delay--) 180 for (delay = 100000; delay; delay--)
180 if (!rc_in(bp, CD180_CCR)) 181 if (!rc_in(bp, CD180_CCR))
181 return; 182 return;
182 183
183 printk(KERN_INFO "rc%d: Timeout waiting for CCR.\n", board_No(bp)); 184 printk(KERN_INFO "rc%d: Timeout waiting for CCR.\n", board_No(bp));
184} 185}
185 186
@@ -187,11 +188,11 @@ static inline void rc_wait_CCR(struct riscom_board const * bp)
187 * RISCom/8 probe functions. 188 * RISCom/8 probe functions.
188 */ 189 */
189 190
190static inline int rc_request_io_range(struct riscom_board * const bp) 191static int rc_request_io_range(struct riscom_board * const bp)
191{ 192{
192 int i; 193 int i;
193 194
194 for (i = 0; i < RC_NIOPORT; i++) 195 for (i = 0; i < RC_NIOPORT; i++)
195 if (!request_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1, 196 if (!request_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1,
196 "RISCom/8")) { 197 "RISCom/8")) {
197 goto out_release; 198 goto out_release;
@@ -200,42 +201,42 @@ static inline int rc_request_io_range(struct riscom_board * const bp)
200out_release: 201out_release:
201 printk(KERN_INFO "rc%d: Skipping probe at 0x%03x. IO address in use.\n", 202 printk(KERN_INFO "rc%d: Skipping probe at 0x%03x. IO address in use.\n",
202 board_No(bp), bp->base); 203 board_No(bp), bp->base);
203 while(--i >= 0) 204 while (--i >= 0)
204 release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1); 205 release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1);
205 return 1; 206 return 1;
206} 207}
207 208
208static inline void rc_release_io_range(struct riscom_board * const bp) 209static void rc_release_io_range(struct riscom_board * const bp)
209{ 210{
210 int i; 211 int i;
211 212
212 for (i = 0; i < RC_NIOPORT; i++) 213 for (i = 0; i < RC_NIOPORT; i++)
213 release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1); 214 release_region(RC_TO_ISA(rc_ioport[i]) + bp->base, 1);
214} 215}
215 216
216/* Reset and setup CD180 chip */ 217/* Reset and setup CD180 chip */
217static void __init rc_init_CD180(struct riscom_board const * bp) 218static void __init rc_init_CD180(struct riscom_board const *bp)
218{ 219{
219 unsigned long flags; 220 unsigned long flags;
220 221
221 spin_lock_irqsave(&riscom_lock, flags); 222 spin_lock_irqsave(&riscom_lock, flags);
222 223
223 rc_out(bp, RC_CTOUT, 0); /* Clear timeout */ 224 rc_out(bp, RC_CTOUT, 0); /* Clear timeout */
224 rc_wait_CCR(bp); /* Wait for CCR ready */ 225 rc_wait_CCR(bp); /* Wait for CCR ready */
225 rc_out(bp, CD180_CCR, CCR_HARDRESET); /* Reset CD180 chip */ 226 rc_out(bp, CD180_CCR, CCR_HARDRESET); /* Reset CD180 chip */
226 spin_unlock_irqrestore(&riscom_lock, flags); 227 spin_unlock_irqrestore(&riscom_lock, flags);
227 msleep(50); /* Delay 0.05 sec */ 228 msleep(50); /* Delay 0.05 sec */
228 spin_lock_irqsave(&riscom_lock, flags); 229 spin_lock_irqsave(&riscom_lock, flags);
229 rc_out(bp, CD180_GIVR, RC_ID); /* Set ID for this chip */ 230 rc_out(bp, CD180_GIVR, RC_ID); /* Set ID for this chip */
230 rc_out(bp, CD180_GICR, 0); /* Clear all bits */ 231 rc_out(bp, CD180_GICR, 0); /* Clear all bits */
231 rc_out(bp, CD180_PILR1, RC_ACK_MINT); /* Prio for modem intr */ 232 rc_out(bp, CD180_PILR1, RC_ACK_MINT); /* Prio for modem intr */
232 rc_out(bp, CD180_PILR2, RC_ACK_TINT); /* Prio for transmitter intr */ 233 rc_out(bp, CD180_PILR2, RC_ACK_TINT); /* Prio for tx intr */
233 rc_out(bp, CD180_PILR3, RC_ACK_RINT); /* Prio for receiver intr */ 234 rc_out(bp, CD180_PILR3, RC_ACK_RINT); /* Prio for rx intr */
234 235
235 /* Setting up prescaler. We need 4 ticks per 1 ms */ 236 /* Setting up prescaler. We need 4 ticks per 1 ms */
236 rc_out(bp, CD180_PPRH, (RC_OSCFREQ/(1000000/RISCOM_TPS)) >> 8); 237 rc_out(bp, CD180_PPRH, (RC_OSCFREQ/(1000000/RISCOM_TPS)) >> 8);
237 rc_out(bp, CD180_PPRL, (RC_OSCFREQ/(1000000/RISCOM_TPS)) & 0xff); 238 rc_out(bp, CD180_PPRL, (RC_OSCFREQ/(1000000/RISCOM_TPS)) & 0xff);
238 239
239 spin_unlock_irqrestore(&riscom_lock, flags); 240 spin_unlock_irqrestore(&riscom_lock, flags);
240} 241}
241 242
@@ -245,12 +246,12 @@ static int __init rc_probe(struct riscom_board *bp)
245 unsigned char val1, val2; 246 unsigned char val1, val2;
246 int irqs = 0; 247 int irqs = 0;
247 int retries; 248 int retries;
248 249
249 bp->irq = 0; 250 bp->irq = 0;
250 251
251 if (rc_request_io_range(bp)) 252 if (rc_request_io_range(bp))
252 return 1; 253 return 1;
253 254
254 /* Are the I/O ports here ? */ 255 /* Are the I/O ports here ? */
255 rc_out(bp, CD180_PPRL, 0x5a); 256 rc_out(bp, CD180_PPRL, 0x5a);
256 outb(0xff, 0x80); 257 outb(0xff, 0x80);
@@ -258,34 +259,34 @@ static int __init rc_probe(struct riscom_board *bp)
258 rc_out(bp, CD180_PPRL, 0xa5); 259 rc_out(bp, CD180_PPRL, 0xa5);
259 outb(0x00, 0x80); 260 outb(0x00, 0x80);
260 val2 = rc_in(bp, CD180_PPRL); 261 val2 = rc_in(bp, CD180_PPRL);
261 262
262 if ((val1 != 0x5a) || (val2 != 0xa5)) { 263 if ((val1 != 0x5a) || (val2 != 0xa5)) {
263 printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not found.\n", 264 printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not found.\n",
264 board_No(bp), bp->base); 265 board_No(bp), bp->base);
265 goto out_release; 266 goto out_release;
266 } 267 }
267 268
268 /* It's time to find IRQ for this board */ 269 /* It's time to find IRQ for this board */
269 for (retries = 0; retries < 5 && irqs <= 0; retries++) { 270 for (retries = 0; retries < 5 && irqs <= 0; retries++) {
270 irqs = probe_irq_on(); 271 irqs = probe_irq_on();
271 rc_init_CD180(bp); /* Reset CD180 chip */ 272 rc_init_CD180(bp); /* Reset CD180 chip */
272 rc_out(bp, CD180_CAR, 2); /* Select port 2 */ 273 rc_out(bp, CD180_CAR, 2); /* Select port 2 */
273 rc_wait_CCR(bp); 274 rc_wait_CCR(bp);
274 rc_out(bp, CD180_CCR, CCR_TXEN); /* Enable transmitter */ 275 rc_out(bp, CD180_CCR, CCR_TXEN); /* Enable transmitter */
275 rc_out(bp, CD180_IER, IER_TXRDY); /* Enable tx empty intr */ 276 rc_out(bp, CD180_IER, IER_TXRDY);/* Enable tx empty intr */
276 msleep(50); 277 msleep(50);
277 irqs = probe_irq_off(irqs); 278 irqs = probe_irq_off(irqs);
278 val1 = rc_in(bp, RC_BSR); /* Get Board Status reg */ 279 val1 = rc_in(bp, RC_BSR); /* Get Board Status reg */
279 val2 = rc_in(bp, RC_ACK_TINT); /* ACK interrupt */ 280 val2 = rc_in(bp, RC_ACK_TINT); /* ACK interrupt */
280 rc_init_CD180(bp); /* Reset CD180 again */ 281 rc_init_CD180(bp); /* Reset CD180 again */
281 282
282 if ((val1 & RC_BSR_TINT) || (val2 != (RC_ID | GIVR_IT_TX))) { 283 if ((val1 & RC_BSR_TINT) || (val2 != (RC_ID | GIVR_IT_TX))) {
283 printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not " 284 printk(KERN_ERR "rc%d: RISCom/8 Board at 0x%03x not "
284 "found.\n", board_No(bp), bp->base); 285 "found.\n", board_No(bp), bp->base);
285 goto out_release; 286 goto out_release;
286 } 287 }
287 } 288 }
288 289
289 if (irqs <= 0) { 290 if (irqs <= 0) {
290 printk(KERN_ERR "rc%d: Can't find IRQ for RISCom/8 board " 291 printk(KERN_ERR "rc%d: Can't find IRQ for RISCom/8 board "
291 "at 0x%03x.\n", board_No(bp), bp->base); 292 "at 0x%03x.\n", board_No(bp), bp->base);
@@ -293,113 +294,112 @@ static int __init rc_probe(struct riscom_board *bp)
293 } 294 }
294 bp->irq = irqs; 295 bp->irq = irqs;
295 bp->flags |= RC_BOARD_PRESENT; 296 bp->flags |= RC_BOARD_PRESENT;
296 297
297 printk(KERN_INFO "rc%d: RISCom/8 Rev. %c board detected at " 298 printk(KERN_INFO "rc%d: RISCom/8 Rev. %c board detected at "
298 "0x%03x, IRQ %d.\n", 299 "0x%03x, IRQ %d.\n",
299 board_No(bp), 300 board_No(bp),
300 (rc_in(bp, CD180_GFRCR) & 0x0f) + 'A', /* Board revision */ 301 (rc_in(bp, CD180_GFRCR) & 0x0f) + 'A', /* Board revision */
301 bp->base, bp->irq); 302 bp->base, bp->irq);
302 303
303 return 0; 304 return 0;
304out_release: 305out_release:
305 rc_release_io_range(bp); 306 rc_release_io_range(bp);
306 return 1; 307 return 1;
307} 308}
308 309
309/* 310/*
310 * 311 *
311 * Interrupt processing routines. 312 * Interrupt processing routines.
312 * 313 *
313 */ 314 */
314 315
315static inline struct riscom_port * rc_get_port(struct riscom_board const * bp, 316static struct riscom_port *rc_get_port(struct riscom_board const *bp,
316 unsigned char const * what) 317 unsigned char const *what)
317{ 318{
318 unsigned char channel; 319 unsigned char channel;
319 struct riscom_port * port; 320 struct riscom_port *port;
320 321
321 channel = rc_in(bp, CD180_GICR) >> GICR_CHAN_OFF; 322 channel = rc_in(bp, CD180_GICR) >> GICR_CHAN_OFF;
322 if (channel < CD180_NCH) { 323 if (channel < CD180_NCH) {
323 port = &rc_port[board_No(bp) * RC_NPORT + channel]; 324 port = &rc_port[board_No(bp) * RC_NPORT + channel];
324 if (port->flags & ASYNC_INITIALIZED) { 325 if (port->flags & ASYNC_INITIALIZED)
325 return port; 326 return port;
326 }
327 } 327 }
328 printk(KERN_ERR "rc%d: %s interrupt from invalid port %d\n", 328 printk(KERN_ERR "rc%d: %s interrupt from invalid port %d\n",
329 board_No(bp), what, channel); 329 board_No(bp), what, channel);
330 return NULL; 330 return NULL;
331} 331}
332 332
333static inline void rc_receive_exc(struct riscom_board const * bp) 333static void rc_receive_exc(struct riscom_board const *bp)
334{ 334{
335 struct riscom_port *port; 335 struct riscom_port *port;
336 struct tty_struct *tty; 336 struct tty_struct *tty;
337 unsigned char status; 337 unsigned char status;
338 unsigned char ch, flag; 338 unsigned char ch, flag;
339 339
340 if (!(port = rc_get_port(bp, "Receive"))) 340 port = rc_get_port(bp, "Receive");
341 if (port == NULL)
341 return; 342 return;
342 343
343 tty = port->tty; 344 tty = port->tty;
344 345
345#ifdef RC_REPORT_OVERRUN 346#ifdef RC_REPORT_OVERRUN
346 status = rc_in(bp, CD180_RCSR); 347 status = rc_in(bp, CD180_RCSR);
347 if (status & RCSR_OE) 348 if (status & RCSR_OE)
348 port->overrun++; 349 port->overrun++;
349 status &= port->mark_mask; 350 status &= port->mark_mask;
350#else 351#else
351 status = rc_in(bp, CD180_RCSR) & port->mark_mask; 352 status = rc_in(bp, CD180_RCSR) & port->mark_mask;
352#endif 353#endif
353 ch = rc_in(bp, CD180_RDR); 354 ch = rc_in(bp, CD180_RDR);
354 if (!status) { 355 if (!status)
355 return; 356 return;
356 }
357 if (status & RCSR_TOUT) { 357 if (status & RCSR_TOUT) {
358 printk(KERN_WARNING "rc%d: port %d: Receiver timeout. " 358 printk(KERN_WARNING "rc%d: port %d: Receiver timeout. "
359 "Hardware problems ?\n", 359 "Hardware problems ?\n",
360 board_No(bp), port_No(port)); 360 board_No(bp), port_No(port));
361 return; 361 return;
362 362
363 } else if (status & RCSR_BREAK) { 363 } else if (status & RCSR_BREAK) {
364 printk(KERN_INFO "rc%d: port %d: Handling break...\n", 364 printk(KERN_INFO "rc%d: port %d: Handling break...\n",
365 board_No(bp), port_No(port)); 365 board_No(bp), port_No(port));
366 flag = TTY_BREAK; 366 flag = TTY_BREAK;
367 if (port->flags & ASYNC_SAK) 367 if (port->flags & ASYNC_SAK)
368 do_SAK(tty); 368 do_SAK(tty);
369 369
370 } else if (status & RCSR_PE) 370 } else if (status & RCSR_PE)
371 flag = TTY_PARITY; 371 flag = TTY_PARITY;
372 372
373 else if (status & RCSR_FE) 373 else if (status & RCSR_FE)
374 flag = TTY_FRAME; 374 flag = TTY_FRAME;
375 375
376 else if (status & RCSR_OE) 376 else if (status & RCSR_OE)
377 flag = TTY_OVERRUN; 377 flag = TTY_OVERRUN;
378
379 else 378 else
380 flag = TTY_NORMAL; 379 flag = TTY_NORMAL;
381 380
382 tty_insert_flip_char(tty, ch, flag); 381 tty_insert_flip_char(tty, ch, flag);
383 tty_flip_buffer_push(tty); 382 tty_flip_buffer_push(tty);
384} 383}
385 384
386static inline void rc_receive(struct riscom_board const * bp) 385static void rc_receive(struct riscom_board const *bp)
387{ 386{
388 struct riscom_port *port; 387 struct riscom_port *port;
389 struct tty_struct *tty; 388 struct tty_struct *tty;
390 unsigned char count; 389 unsigned char count;
391 390
392 if (!(port = rc_get_port(bp, "Receive"))) 391 port = rc_get_port(bp, "Receive");
392 if (port == NULL)
393 return; 393 return;
394 394
395 tty = port->tty; 395 tty = port->tty;
396 396
397 count = rc_in(bp, CD180_RDCR); 397 count = rc_in(bp, CD180_RDCR);
398 398
399#ifdef RC_REPORT_FIFO 399#ifdef RC_REPORT_FIFO
400 port->hits[count > 8 ? 9 : count]++; 400 port->hits[count > 8 ? 9 : count]++;
401#endif 401#endif
402 402
403 while (count--) { 403 while (count--) {
404 if (tty_buffer_request_room(tty, 1) == 0) { 404 if (tty_buffer_request_room(tty, 1) == 0) {
405 printk(KERN_WARNING "rc%d: port %d: Working around " 405 printk(KERN_WARNING "rc%d: port %d: Working around "
@@ -412,26 +412,26 @@ static inline void rc_receive(struct riscom_board const * bp)
412 tty_flip_buffer_push(tty); 412 tty_flip_buffer_push(tty);
413} 413}
414 414
415static inline void rc_transmit(struct riscom_board const * bp) 415static void rc_transmit(struct riscom_board const *bp)
416{ 416{
417 struct riscom_port *port; 417 struct riscom_port *port;
418 struct tty_struct *tty; 418 struct tty_struct *tty;
419 unsigned char count; 419 unsigned char count;
420 420
421 421 port = rc_get_port(bp, "Transmit");
422 if (!(port = rc_get_port(bp, "Transmit"))) 422 if (port == NULL)
423 return; 423 return;
424 424
425 tty = port->tty; 425 tty = port->tty;
426 426
427 if (port->IER & IER_TXEMPTY) { 427 if (port->IER & IER_TXEMPTY) {
428 /* FIFO drained */ 428 /* FIFO drained */
429 rc_out(bp, CD180_CAR, port_No(port)); 429 rc_out(bp, CD180_CAR, port_No(port));
430 port->IER &= ~IER_TXEMPTY; 430 port->IER &= ~IER_TXEMPTY;
431 rc_out(bp, CD180_IER, port->IER); 431 rc_out(bp, CD180_IER, port->IER);
432 return; 432 return;
433 } 433 }
434 434
435 if ((port->xmit_cnt <= 0 && !port->break_length) 435 if ((port->xmit_cnt <= 0 && !port->break_length)
436 || tty->stopped || tty->hw_stopped) { 436 || tty->stopped || tty->hw_stopped) {
437 rc_out(bp, CD180_CAR, port_No(port)); 437 rc_out(bp, CD180_CAR, port_No(port));
@@ -439,7 +439,7 @@ static inline void rc_transmit(struct riscom_board const * bp)
439 rc_out(bp, CD180_IER, port->IER); 439 rc_out(bp, CD180_IER, port->IER);
440 return; 440 return;
441 } 441 }
442 442
443 if (port->break_length) { 443 if (port->break_length) {
444 if (port->break_length > 0) { 444 if (port->break_length > 0) {
445 if (port->COR2 & COR2_ETC) { 445 if (port->COR2 & COR2_ETC) {
@@ -451,7 +451,8 @@ static inline void rc_transmit(struct riscom_board const * bp)
451 rc_out(bp, CD180_TDR, CD180_C_ESC); 451 rc_out(bp, CD180_TDR, CD180_C_ESC);
452 rc_out(bp, CD180_TDR, CD180_C_DELAY); 452 rc_out(bp, CD180_TDR, CD180_C_DELAY);
453 rc_out(bp, CD180_TDR, count); 453 rc_out(bp, CD180_TDR, count);
454 if (!(port->break_length -= count)) 454 port->break_length -= count;
455 if (port->break_length == 0)
455 port->break_length--; 456 port->break_length--;
456 } else { 457 } else {
457 rc_out(bp, CD180_TDR, CD180_C_ESC); 458 rc_out(bp, CD180_TDR, CD180_C_ESC);
@@ -463,7 +464,7 @@ static inline void rc_transmit(struct riscom_board const * bp)
463 } 464 }
464 return; 465 return;
465 } 466 }
466 467
467 count = CD180_NFIFO; 468 count = CD180_NFIFO;
468 do { 469 do {
469 rc_out(bp, CD180_TDR, port->xmit_buf[port->xmit_tail++]); 470 rc_out(bp, CD180_TDR, port->xmit_buf[port->xmit_tail++]);
@@ -471,7 +472,7 @@ static inline void rc_transmit(struct riscom_board const * bp)
471 if (--port->xmit_cnt <= 0) 472 if (--port->xmit_cnt <= 0)
472 break; 473 break;
473 } while (--count > 0); 474 } while (--count > 0);
474 475
475 if (port->xmit_cnt <= 0) { 476 if (port->xmit_cnt <= 0) {
476 rc_out(bp, CD180_CAR, port_No(port)); 477 rc_out(bp, CD180_CAR, port_No(port));
477 port->IER &= ~IER_TXRDY; 478 port->IER &= ~IER_TXRDY;
@@ -481,25 +482,26 @@ static inline void rc_transmit(struct riscom_board const * bp)
481 tty_wakeup(tty); 482 tty_wakeup(tty);
482} 483}
483 484
484static inline void rc_check_modem(struct riscom_board const * bp) 485static void rc_check_modem(struct riscom_board const *bp)
485{ 486{
486 struct riscom_port *port; 487 struct riscom_port *port;
487 struct tty_struct *tty; 488 struct tty_struct *tty;
488 unsigned char mcr; 489 unsigned char mcr;
489 490
490 if (!(port = rc_get_port(bp, "Modem"))) 491 port = rc_get_port(bp, "Modem");
492 if (port == NULL)
491 return; 493 return;
492 494
493 tty = port->tty; 495 tty = port->tty;
494 496
495 mcr = rc_in(bp, CD180_MCR); 497 mcr = rc_in(bp, CD180_MCR);
496 if (mcr & MCR_CDCHG) { 498 if (mcr & MCR_CDCHG) {
497 if (rc_in(bp, CD180_MSVR) & MSVR_CD) 499 if (rc_in(bp, CD180_MSVR) & MSVR_CD)
498 wake_up_interruptible(&port->open_wait); 500 wake_up_interruptible(&port->open_wait);
499 else 501 else
500 tty_hangup(tty); 502 tty_hangup(tty);
501 } 503 }
502 504
503#ifdef RISCOM_BRAIN_DAMAGED_CTS 505#ifdef RISCOM_BRAIN_DAMAGED_CTS
504 if (mcr & MCR_CTSCHG) { 506 if (mcr & MCR_CTSCHG) {
505 if (rc_in(bp, CD180_MSVR) & MSVR_CTS) { 507 if (rc_in(bp, CD180_MSVR) & MSVR_CTS) {
@@ -526,13 +528,13 @@ static inline void rc_check_modem(struct riscom_board const * bp)
526 rc_out(bp, CD180_IER, port->IER); 528 rc_out(bp, CD180_IER, port->IER);
527 } 529 }
528#endif /* RISCOM_BRAIN_DAMAGED_CTS */ 530#endif /* RISCOM_BRAIN_DAMAGED_CTS */
529 531
530 /* Clear change bits */ 532 /* Clear change bits */
531 rc_out(bp, CD180_MCR, 0); 533 rc_out(bp, CD180_MCR, 0);
532} 534}
533 535
534/* The main interrupt processing routine */ 536/* The main interrupt processing routine */
535static irqreturn_t rc_interrupt(int dummy, void * dev_id) 537static irqreturn_t rc_interrupt(int dummy, void *dev_id)
536{ 538{
537 unsigned char status; 539 unsigned char status;
538 unsigned char ack; 540 unsigned char ack;
@@ -547,13 +549,11 @@ static irqreturn_t rc_interrupt(int dummy, void * dev_id)
547 (RC_BSR_TOUT | RC_BSR_TINT | 549 (RC_BSR_TOUT | RC_BSR_TINT |
548 RC_BSR_MINT | RC_BSR_RINT))) { 550 RC_BSR_MINT | RC_BSR_RINT))) {
549 handled = 1; 551 handled = 1;
550 if (status & RC_BSR_TOUT) 552 if (status & RC_BSR_TOUT)
551 printk(KERN_WARNING "rc%d: Got timeout. Hardware " 553 printk(KERN_WARNING "rc%d: Got timeout. Hardware "
552 "error?\n", board_No(bp)); 554 "error?\n", board_No(bp));
553
554 else if (status & RC_BSR_RINT) { 555 else if (status & RC_BSR_RINT) {
555 ack = rc_in(bp, RC_ACK_RINT); 556 ack = rc_in(bp, RC_ACK_RINT);
556
557 if (ack == (RC_ID | GIVR_IT_RCV)) 557 if (ack == (RC_ID | GIVR_IT_RCV))
558 rc_receive(bp); 558 rc_receive(bp);
559 else if (ack == (RC_ID | GIVR_IT_REXC)) 559 else if (ack == (RC_ID | GIVR_IT_REXC))
@@ -562,29 +562,23 @@ static irqreturn_t rc_interrupt(int dummy, void * dev_id)
562 printk(KERN_WARNING "rc%d: Bad receive ack " 562 printk(KERN_WARNING "rc%d: Bad receive ack "
563 "0x%02x.\n", 563 "0x%02x.\n",
564 board_No(bp), ack); 564 board_No(bp), ack);
565
566 } else if (status & RC_BSR_TINT) { 565 } else if (status & RC_BSR_TINT) {
567 ack = rc_in(bp, RC_ACK_TINT); 566 ack = rc_in(bp, RC_ACK_TINT);
568
569 if (ack == (RC_ID | GIVR_IT_TX)) 567 if (ack == (RC_ID | GIVR_IT_TX))
570 rc_transmit(bp); 568 rc_transmit(bp);
571 else 569 else
572 printk(KERN_WARNING "rc%d: Bad transmit ack " 570 printk(KERN_WARNING "rc%d: Bad transmit ack "
573 "0x%02x.\n", 571 "0x%02x.\n",
574 board_No(bp), ack); 572 board_No(bp), ack);
575
576 } else /* if (status & RC_BSR_MINT) */ { 573 } else /* if (status & RC_BSR_MINT) */ {
577 ack = rc_in(bp, RC_ACK_MINT); 574 ack = rc_in(bp, RC_ACK_MINT);
578 575 if (ack == (RC_ID | GIVR_IT_MODEM))
579 if (ack == (RC_ID | GIVR_IT_MODEM))
580 rc_check_modem(bp); 576 rc_check_modem(bp);
581 else 577 else
582 printk(KERN_WARNING "rc%d: Bad modem ack " 578 printk(KERN_WARNING "rc%d: Bad modem ack "
583 "0x%02x.\n", 579 "0x%02x.\n",
584 board_No(bp), ack); 580 board_No(bp), ack);
585 581 }
586 }
587
588 rc_out(bp, CD180_EOIR, 0); /* Mark end of interrupt */ 582 rc_out(bp, CD180_EOIR, 0); /* Mark end of interrupt */
589 rc_out(bp, RC_CTOUT, 0); /* Clear timeout flag */ 583 rc_out(bp, RC_CTOUT, 0); /* Clear timeout flag */
590 } 584 }
@@ -596,24 +590,24 @@ static irqreturn_t rc_interrupt(int dummy, void * dev_id)
596 */ 590 */
597 591
598/* Called with disabled interrupts */ 592/* Called with disabled interrupts */
599static int rc_setup_board(struct riscom_board * bp) 593static int rc_setup_board(struct riscom_board *bp)
600{ 594{
601 int error; 595 int error;
602 596
603 if (bp->flags & RC_BOARD_ACTIVE) 597 if (bp->flags & RC_BOARD_ACTIVE)
604 return 0; 598 return 0;
605 599
606 error = request_irq(bp->irq, rc_interrupt, IRQF_DISABLED, 600 error = request_irq(bp->irq, rc_interrupt, IRQF_DISABLED,
607 "RISCom/8", bp); 601 "RISCom/8", bp);
608 if (error) 602 if (error)
609 return error; 603 return error;
610 604
611 rc_out(bp, RC_CTOUT, 0); /* Just in case */ 605 rc_out(bp, RC_CTOUT, 0); /* Just in case */
612 bp->DTR = ~0; 606 bp->DTR = ~0;
613 rc_out(bp, RC_DTR, bp->DTR); /* Drop DTR on all ports */ 607 rc_out(bp, RC_DTR, bp->DTR); /* Drop DTR on all ports */
614 608
615 bp->flags |= RC_BOARD_ACTIVE; 609 bp->flags |= RC_BOARD_ACTIVE;
616 610
617 return 0; 611 return 0;
618} 612}
619 613
@@ -622,40 +616,40 @@ static void rc_shutdown_board(struct riscom_board *bp)
622{ 616{
623 if (!(bp->flags & RC_BOARD_ACTIVE)) 617 if (!(bp->flags & RC_BOARD_ACTIVE))
624 return; 618 return;
625 619
626 bp->flags &= ~RC_BOARD_ACTIVE; 620 bp->flags &= ~RC_BOARD_ACTIVE;
627 621
628 free_irq(bp->irq, NULL); 622 free_irq(bp->irq, NULL);
629 623
630 bp->DTR = ~0; 624 bp->DTR = ~0;
631 rc_out(bp, RC_DTR, bp->DTR); /* Drop DTR on all ports */ 625 rc_out(bp, RC_DTR, bp->DTR); /* Drop DTR on all ports */
632 626
633} 627}
634 628
635/* 629/*
636 * Setting up port characteristics. 630 * Setting up port characteristics.
637 * Must be called with disabled interrupts 631 * Must be called with disabled interrupts
638 */ 632 */
639static void rc_change_speed(struct riscom_board *bp, struct riscom_port *port) 633static void rc_change_speed(struct riscom_board *bp, struct riscom_port *port)
640{ 634{
641 struct tty_struct *tty; 635 struct tty_struct *tty = port->tty;
642 unsigned long baud; 636 unsigned long baud;
643 long tmp; 637 long tmp;
644 unsigned char cor1 = 0, cor3 = 0; 638 unsigned char cor1 = 0, cor3 = 0;
645 unsigned char mcor1 = 0, mcor2 = 0; 639 unsigned char mcor1 = 0, mcor2 = 0;
646 640
647 if (!(tty = port->tty) || !tty->termios) 641 if (tty == NULL || tty->termios == NULL)
648 return; 642 return;
649 643
650 port->IER = 0; 644 port->IER = 0;
651 port->COR2 = 0; 645 port->COR2 = 0;
652 port->MSVR = MSVR_RTS; 646 port->MSVR = MSVR_RTS;
653 647
654 baud = tty_get_baud_rate(tty); 648 baud = tty_get_baud_rate(tty);
655 649
656 /* Select port on the board */ 650 /* Select port on the board */
657 rc_out(bp, CD180_CAR, port_No(port)); 651 rc_out(bp, CD180_CAR, port_No(port));
658 652
659 if (!baud) { 653 if (!baud) {
660 /* Drop DTR & exit */ 654 /* Drop DTR & exit */
661 bp->DTR |= (1u << port_No(port)); 655 bp->DTR |= (1u << port_No(port));
@@ -666,69 +660,68 @@ static void rc_change_speed(struct riscom_board *bp, struct riscom_port *port)
666 bp->DTR &= ~(1u << port_No(port)); 660 bp->DTR &= ~(1u << port_No(port));
667 rc_out(bp, RC_DTR, bp->DTR); 661 rc_out(bp, RC_DTR, bp->DTR);
668 } 662 }
669 663
670 /* 664 /*
671 * Now we must calculate some speed depended things 665 * Now we must calculate some speed depended things
672 */ 666 */
673 667
674 /* Set baud rate for port */ 668 /* Set baud rate for port */
675 tmp = (((RC_OSCFREQ + baud/2) / baud + 669 tmp = (((RC_OSCFREQ + baud/2) / baud +
676 CD180_TPC/2) / CD180_TPC); 670 CD180_TPC/2) / CD180_TPC);
677 671
678 rc_out(bp, CD180_RBPRH, (tmp >> 8) & 0xff); 672 rc_out(bp, CD180_RBPRH, (tmp >> 8) & 0xff);
679 rc_out(bp, CD180_TBPRH, (tmp >> 8) & 0xff); 673 rc_out(bp, CD180_TBPRH, (tmp >> 8) & 0xff);
680 rc_out(bp, CD180_RBPRL, tmp & 0xff); 674 rc_out(bp, CD180_RBPRL, tmp & 0xff);
681 rc_out(bp, CD180_TBPRL, tmp & 0xff); 675 rc_out(bp, CD180_TBPRL, tmp & 0xff);
682 676
683 baud = (baud + 5) / 10; /* Estimated CPS */ 677 baud = (baud + 5) / 10; /* Estimated CPS */
684 678
685 /* Two timer ticks seems enough to wakeup something like SLIP driver */ 679 /* Two timer ticks seems enough to wakeup something like SLIP driver */
686 tmp = ((baud + HZ/2) / HZ) * 2 - CD180_NFIFO; 680 tmp = ((baud + HZ/2) / HZ) * 2 - CD180_NFIFO;
687 port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ? 681 port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ?
688 SERIAL_XMIT_SIZE - 1 : tmp); 682 SERIAL_XMIT_SIZE - 1 : tmp);
689 683
690 /* Receiver timeout will be transmission time for 1.5 chars */ 684 /* Receiver timeout will be transmission time for 1.5 chars */
691 tmp = (RISCOM_TPS + RISCOM_TPS/2 + baud/2) / baud; 685 tmp = (RISCOM_TPS + RISCOM_TPS/2 + baud/2) / baud;
692 tmp = (tmp > 0xff) ? 0xff : tmp; 686 tmp = (tmp > 0xff) ? 0xff : tmp;
693 rc_out(bp, CD180_RTPR, tmp); 687 rc_out(bp, CD180_RTPR, tmp);
694 688
695 switch (C_CSIZE(tty)) { 689 switch (C_CSIZE(tty)) {
696 case CS5: 690 case CS5:
697 cor1 |= COR1_5BITS; 691 cor1 |= COR1_5BITS;
698 break; 692 break;
699 case CS6: 693 case CS6:
700 cor1 |= COR1_6BITS; 694 cor1 |= COR1_6BITS;
701 break; 695 break;
702 case CS7: 696 case CS7:
703 cor1 |= COR1_7BITS; 697 cor1 |= COR1_7BITS;
704 break; 698 break;
705 case CS8: 699 case CS8:
706 cor1 |= COR1_8BITS; 700 cor1 |= COR1_8BITS;
707 break; 701 break;
708 } 702 }
709 703 if (C_CSTOPB(tty))
710 if (C_CSTOPB(tty))
711 cor1 |= COR1_2SB; 704 cor1 |= COR1_2SB;
712 705
713 cor1 |= COR1_IGNORE; 706 cor1 |= COR1_IGNORE;
714 if (C_PARENB(tty)) { 707 if (C_PARENB(tty)) {
715 cor1 |= COR1_NORMPAR; 708 cor1 |= COR1_NORMPAR;
716 if (C_PARODD(tty)) 709 if (C_PARODD(tty))
717 cor1 |= COR1_ODDP; 710 cor1 |= COR1_ODDP;
718 if (I_INPCK(tty)) 711 if (I_INPCK(tty))
719 cor1 &= ~COR1_IGNORE; 712 cor1 &= ~COR1_IGNORE;
720 } 713 }
721 /* Set marking of some errors */ 714 /* Set marking of some errors */
722 port->mark_mask = RCSR_OE | RCSR_TOUT; 715 port->mark_mask = RCSR_OE | RCSR_TOUT;
723 if (I_INPCK(tty)) 716 if (I_INPCK(tty))
724 port->mark_mask |= RCSR_FE | RCSR_PE; 717 port->mark_mask |= RCSR_FE | RCSR_PE;
725 if (I_BRKINT(tty) || I_PARMRK(tty)) 718 if (I_BRKINT(tty) || I_PARMRK(tty))
726 port->mark_mask |= RCSR_BREAK; 719 port->mark_mask |= RCSR_BREAK;
727 if (I_IGNPAR(tty)) 720 if (I_IGNPAR(tty))
728 port->mark_mask &= ~(RCSR_FE | RCSR_PE); 721 port->mark_mask &= ~(RCSR_FE | RCSR_PE);
729 if (I_IGNBRK(tty)) { 722 if (I_IGNBRK(tty)) {
730 port->mark_mask &= ~RCSR_BREAK; 723 port->mark_mask &= ~RCSR_BREAK;
731 if (I_IGNPAR(tty)) 724 if (I_IGNPAR(tty))
732 /* Real raw mode. Ignore all */ 725 /* Real raw mode. Ignore all */
733 port->mark_mask &= ~RCSR_OE; 726 port->mark_mask &= ~RCSR_OE;
734 } 727 }
@@ -738,7 +731,8 @@ static void rc_change_speed(struct riscom_board *bp, struct riscom_port *port)
738 port->IER |= IER_DSR | IER_CTS; 731 port->IER |= IER_DSR | IER_CTS;
739 mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD; 732 mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD;
740 mcor2 |= MCOR2_DSROD | MCOR2_CTSOD; 733 mcor2 |= MCOR2_DSROD | MCOR2_CTSOD;
741 tty->hw_stopped = !(rc_in(bp, CD180_MSVR) & (MSVR_CTS|MSVR_DSR)); 734 tty->hw_stopped = !(rc_in(bp, CD180_MSVR) &
735 (MSVR_CTS|MSVR_DSR));
742#else 736#else
743 port->COR2 |= COR2_CTSAE; 737 port->COR2 |= COR2_CTSAE;
744#endif 738#endif
@@ -761,13 +755,13 @@ static void rc_change_speed(struct riscom_board *bp, struct riscom_port *port)
761 mcor1 |= MCOR1_CDZD; 755 mcor1 |= MCOR1_CDZD;
762 mcor2 |= MCOR2_CDOD; 756 mcor2 |= MCOR2_CDOD;
763 } 757 }
764 758
765 if (C_CREAD(tty)) 759 if (C_CREAD(tty))
766 /* Enable receiver */ 760 /* Enable receiver */
767 port->IER |= IER_RXD; 761 port->IER |= IER_RXD;
768 762
769 /* Set input FIFO size (1-8 bytes) */ 763 /* Set input FIFO size (1-8 bytes) */
770 cor3 |= RISCOM_RXFIFO; 764 cor3 |= RISCOM_RXFIFO;
771 /* Setting up CD180 channel registers */ 765 /* Setting up CD180 channel registers */
772 rc_out(bp, CD180_COR1, cor1); 766 rc_out(bp, CD180_COR1, cor1);
773 rc_out(bp, CD180_COR2, port->COR2); 767 rc_out(bp, CD180_COR2, port->COR2);
@@ -791,36 +785,30 @@ static void rc_change_speed(struct riscom_board *bp, struct riscom_port *port)
791static int rc_setup_port(struct riscom_board *bp, struct riscom_port *port) 785static int rc_setup_port(struct riscom_board *bp, struct riscom_port *port)
792{ 786{
793 unsigned long flags; 787 unsigned long flags;
794 788
795 if (port->flags & ASYNC_INITIALIZED) 789 if (port->flags & ASYNC_INITIALIZED)
796 return 0; 790 return 0;
797 791
798 if (!port->xmit_buf) { 792 if (!port->xmit_buf) {
799 /* We may sleep in get_zeroed_page() */ 793 /* We may sleep in get_zeroed_page() */
800 unsigned long tmp; 794 unsigned long tmp = get_zeroed_page(GFP_KERNEL);
801 795 if (tmp == 0)
802 if (!(tmp = get_zeroed_page(GFP_KERNEL)))
803 return -ENOMEM; 796 return -ENOMEM;
804 797 if (port->xmit_buf)
805 if (port->xmit_buf) {
806 free_page(tmp); 798 free_page(tmp);
807 return -ERESTARTSYS; 799 else
808 } 800 port->xmit_buf = (unsigned char *) tmp;
809 port->xmit_buf = (unsigned char *) tmp;
810 } 801 }
811
812 spin_lock_irqsave(&riscom_lock, flags); 802 spin_lock_irqsave(&riscom_lock, flags);
813 803
814 if (port->tty) 804 if (port->tty)
815 clear_bit(TTY_IO_ERROR, &port->tty->flags); 805 clear_bit(TTY_IO_ERROR, &port->tty->flags);
816 806 if (port->count == 1)
817 if (port->count == 1)
818 bp->count++; 807 bp->count++;
819
820 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0; 808 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
821 rc_change_speed(bp, port); 809 rc_change_speed(bp, port);
822 port->flags |= ASYNC_INITIALIZED; 810 port->flags |= ASYNC_INITIALIZED;
823 811
824 spin_unlock_irqrestore(&riscom_lock, flags); 812 spin_unlock_irqrestore(&riscom_lock, flags);
825 return 0; 813 return 0;
826} 814}
@@ -829,38 +817,39 @@ static int rc_setup_port(struct riscom_board *bp, struct riscom_port *port)
829static void rc_shutdown_port(struct riscom_board *bp, struct riscom_port *port) 817static void rc_shutdown_port(struct riscom_board *bp, struct riscom_port *port)
830{ 818{
831 struct tty_struct *tty; 819 struct tty_struct *tty;
832 820
833 if (!(port->flags & ASYNC_INITIALIZED)) 821 if (!(port->flags & ASYNC_INITIALIZED))
834 return; 822 return;
835 823
836#ifdef RC_REPORT_OVERRUN 824#ifdef RC_REPORT_OVERRUN
837 printk(KERN_INFO "rc%d: port %d: Total %ld overruns were detected.\n", 825 printk(KERN_INFO "rc%d: port %d: Total %ld overruns were detected.\n",
838 board_No(bp), port_No(port), port->overrun); 826 board_No(bp), port_No(port), port->overrun);
839#endif 827#endif
840#ifdef RC_REPORT_FIFO 828#ifdef RC_REPORT_FIFO
841 { 829 {
842 int i; 830 int i;
843 831
844 printk(KERN_INFO "rc%d: port %d: FIFO hits [ ", 832 printk(KERN_INFO "rc%d: port %d: FIFO hits [ ",
845 board_No(bp), port_No(port)); 833 board_No(bp), port_No(port));
846 for (i = 0; i < 10; i++) { 834 for (i = 0; i < 10; i++)
847 printk("%ld ", port->hits[i]); 835 printk("%ld ", port->hits[i]);
848 }
849 printk("].\n"); 836 printk("].\n");
850 } 837 }
851#endif 838#endif
852 if (port->xmit_buf) { 839 if (port->xmit_buf) {
853 free_page((unsigned long) port->xmit_buf); 840 free_page((unsigned long) port->xmit_buf);
854 port->xmit_buf = NULL; 841 port->xmit_buf = NULL;
855 } 842 }
856 843
857 if (!(tty = port->tty) || C_HUPCL(tty)) { 844 tty = port->tty;
845
846 if (tty == NULL || C_HUPCL(tty)) {
858 /* Drop DTR */ 847 /* Drop DTR */
859 bp->DTR |= (1u << port_No(port)); 848 bp->DTR |= (1u << port_No(port));
860 rc_out(bp, RC_DTR, bp->DTR); 849 rc_out(bp, RC_DTR, bp->DTR);
861 } 850 }
862 851
863 /* Select port */ 852 /* Select port */
864 rc_out(bp, CD180_CAR, port_No(port)); 853 rc_out(bp, CD180_CAR, port_No(port));
865 /* Reset port */ 854 /* Reset port */
866 rc_wait_CCR(bp); 855 rc_wait_CCR(bp);
@@ -868,28 +857,26 @@ static void rc_shutdown_port(struct riscom_board *bp, struct riscom_port *port)
868 /* Disable all interrupts from this port */ 857 /* Disable all interrupts from this port */
869 port->IER = 0; 858 port->IER = 0;
870 rc_out(bp, CD180_IER, port->IER); 859 rc_out(bp, CD180_IER, port->IER);
871 860
872 if (tty) 861 if (tty)
873 set_bit(TTY_IO_ERROR, &tty->flags); 862 set_bit(TTY_IO_ERROR, &tty->flags);
874 port->flags &= ~ASYNC_INITIALIZED; 863 port->flags &= ~ASYNC_INITIALIZED;
875 864
876 if (--bp->count < 0) { 865 if (--bp->count < 0) {
877 printk(KERN_INFO "rc%d: rc_shutdown_port: " 866 printk(KERN_INFO "rc%d: rc_shutdown_port: "
878 "bad board count: %d\n", 867 "bad board count: %d\n",
879 board_No(bp), bp->count); 868 board_No(bp), bp->count);
880 bp->count = 0; 869 bp->count = 0;
881 } 870 }
882
883 /* 871 /*
884 * If this is the last opened port on the board 872 * If this is the last opened port on the board
885 * shutdown whole board 873 * shutdown whole board
886 */ 874 */
887 if (!bp->count) 875 if (!bp->count)
888 rc_shutdown_board(bp); 876 rc_shutdown_board(bp);
889} 877}
890 878
891 879static int block_til_ready(struct tty_struct *tty, struct file *filp,
892static int block_til_ready(struct tty_struct *tty, struct file * filp,
893 struct riscom_port *port) 880 struct riscom_port *port)
894{ 881{
895 DECLARE_WAITQUEUE(wait, current); 882 DECLARE_WAITQUEUE(wait, current);
@@ -921,7 +908,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
921 return 0; 908 return 0;
922 } 909 }
923 910
924 if (C_CLOCAL(tty)) 911 if (C_CLOCAL(tty))
925 do_clocal = 1; 912 do_clocal = 1;
926 913
927 /* 914 /*
@@ -959,7 +946,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
959 if (port->flags & ASYNC_HUP_NOTIFY) 946 if (port->flags & ASYNC_HUP_NOTIFY)
960 retval = -EAGAIN; 947 retval = -EAGAIN;
961 else 948 else
962 retval = -ERESTARTSYS; 949 retval = -ERESTARTSYS;
963 break; 950 break;
964 } 951 }
965 if (!(port->flags & ASYNC_CLOSING) && 952 if (!(port->flags & ASYNC_CLOSING) &&
@@ -978,50 +965,63 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
978 port->blocked_open--; 965 port->blocked_open--;
979 if (retval) 966 if (retval)
980 return retval; 967 return retval;
981 968
982 port->flags |= ASYNC_NORMAL_ACTIVE; 969 port->flags |= ASYNC_NORMAL_ACTIVE;
983 return 0; 970 return 0;
984} 971}
985 972
986static int rc_open(struct tty_struct * tty, struct file * filp) 973static int rc_open(struct tty_struct *tty, struct file *filp)
987{ 974{
988 int board; 975 int board;
989 int error; 976 int error;
990 struct riscom_port * port; 977 struct riscom_port *port;
991 struct riscom_board * bp; 978 struct riscom_board *bp;
992 979
993 board = RC_BOARD(tty->index); 980 board = RC_BOARD(tty->index);
994 if (board >= RC_NBOARD || !(rc_board[board].flags & RC_BOARD_PRESENT)) 981 if (board >= RC_NBOARD || !(rc_board[board].flags & RC_BOARD_PRESENT))
995 return -ENODEV; 982 return -ENODEV;
996 983
997 bp = &rc_board[board]; 984 bp = &rc_board[board];
998 port = rc_port + board * RC_NPORT + RC_PORT(tty->index); 985 port = rc_port + board * RC_NPORT + RC_PORT(tty->index);
999 if (rc_paranoia_check(port, tty->name, "rc_open")) 986 if (rc_paranoia_check(port, tty->name, "rc_open"))
1000 return -ENODEV; 987 return -ENODEV;
1001 988
1002 if ((error = rc_setup_board(bp))) 989 error = rc_setup_board(bp);
990 if (error)
1003 return error; 991 return error;
1004 992
1005 port->count++; 993 port->count++;
1006 tty->driver_data = port; 994 tty->driver_data = port;
1007 port->tty = tty; 995 port->tty = tty;
1008 996
1009 if ((error = rc_setup_port(bp, port))) 997 error = rc_setup_port(bp, port);
1010 return error; 998 if (error == 0)
1011 999 error = block_til_ready(tty, filp, port);
1012 if ((error = block_til_ready(tty, filp, port))) 1000 return error;
1013 return error;
1014
1015 return 0;
1016} 1001}
1017 1002
1018static void rc_close(struct tty_struct * tty, struct file * filp) 1003static void rc_flush_buffer(struct tty_struct *tty)
1004{
1005 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1006 unsigned long flags;
1007
1008 if (rc_paranoia_check(port, tty->name, "rc_flush_buffer"))
1009 return;
1010
1011 spin_lock_irqsave(&riscom_lock, flags);
1012 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1013 spin_unlock_irqrestore(&riscom_lock, flags);
1014
1015 tty_wakeup(tty);
1016}
1017
1018static void rc_close(struct tty_struct *tty, struct file *filp)
1019{ 1019{
1020 struct riscom_port *port = (struct riscom_port *) tty->driver_data; 1020 struct riscom_port *port = (struct riscom_port *) tty->driver_data;
1021 struct riscom_board *bp; 1021 struct riscom_board *bp;
1022 unsigned long flags; 1022 unsigned long flags;
1023 unsigned long timeout; 1023 unsigned long timeout;
1024 1024
1025 if (!port || rc_paranoia_check(port, tty->name, "close")) 1025 if (!port || rc_paranoia_check(port, tty->name, "close"))
1026 return; 1026 return;
1027 1027
@@ -1029,7 +1029,7 @@ static void rc_close(struct tty_struct * tty, struct file * filp)
1029 1029
1030 if (tty_hung_up_p(filp)) 1030 if (tty_hung_up_p(filp))
1031 goto out; 1031 goto out;
1032 1032
1033 bp = port_Board(port); 1033 bp = port_Board(port);
1034 if ((tty->count == 1) && (port->count != 1)) { 1034 if ((tty->count == 1) && (port->count != 1)) {
1035 printk(KERN_INFO "rc%d: rc_close: bad port count;" 1035 printk(KERN_INFO "rc%d: rc_close: bad port count;"
@@ -1047,7 +1047,7 @@ static void rc_close(struct tty_struct * tty, struct file * filp)
1047 goto out; 1047 goto out;
1048 port->flags |= ASYNC_CLOSING; 1048 port->flags |= ASYNC_CLOSING;
1049 /* 1049 /*
1050 * Now we wait for the transmit buffer to clear; and we notify 1050 * Now we wait for the transmit buffer to clear; and we notify
1051 * the line discipline to only process XON/XOFF characters. 1051 * the line discipline to only process XON/XOFF characters.
1052 */ 1052 */
1053 tty->closing = 1; 1053 tty->closing = 1;
@@ -1070,24 +1070,22 @@ static void rc_close(struct tty_struct * tty, struct file * filp)
1070 * has completely drained; this is especially 1070 * has completely drained; this is especially
1071 * important if there is a transmit FIFO! 1071 * important if there is a transmit FIFO!
1072 */ 1072 */
1073 timeout = jiffies+HZ; 1073 timeout = jiffies + HZ;
1074 while(port->IER & IER_TXEMPTY) { 1074 while (port->IER & IER_TXEMPTY) {
1075 msleep_interruptible(jiffies_to_msecs(port->timeout)); 1075 msleep_interruptible(jiffies_to_msecs(port->timeout));
1076 if (time_after(jiffies, timeout)) 1076 if (time_after(jiffies, timeout))
1077 break; 1077 break;
1078 } 1078 }
1079 } 1079 }
1080 rc_shutdown_port(bp, port); 1080 rc_shutdown_port(bp, port);
1081 if (tty->driver->flush_buffer) 1081 rc_flush_buffer(tty);
1082 tty->driver->flush_buffer(tty);
1083 tty_ldisc_flush(tty); 1082 tty_ldisc_flush(tty);
1084 1083
1085 tty->closing = 0; 1084 tty->closing = 0;
1086 port->tty = NULL; 1085 port->tty = NULL;
1087 if (port->blocked_open) { 1086 if (port->blocked_open) {
1088 if (port->close_delay) { 1087 if (port->close_delay)
1089 msleep_interruptible(jiffies_to_msecs(port->close_delay)); 1088 msleep_interruptible(jiffies_to_msecs(port->close_delay));
1090 }
1091 wake_up_interruptible(&port->open_wait); 1089 wake_up_interruptible(&port->open_wait);
1092 } 1090 }
1093 port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 1091 port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
@@ -1097,17 +1095,17 @@ out:
1097 spin_unlock_irqrestore(&riscom_lock, flags); 1095 spin_unlock_irqrestore(&riscom_lock, flags);
1098} 1096}
1099 1097
1100static int rc_write(struct tty_struct * tty, 1098static int rc_write(struct tty_struct *tty,
1101 const unsigned char *buf, int count) 1099 const unsigned char *buf, int count)
1102{ 1100{
1103 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1101 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1104 struct riscom_board *bp; 1102 struct riscom_board *bp;
1105 int c, total = 0; 1103 int c, total = 0;
1106 unsigned long flags; 1104 unsigned long flags;
1107 1105
1108 if (rc_paranoia_check(port, tty->name, "rc_write")) 1106 if (rc_paranoia_check(port, tty->name, "rc_write"))
1109 return 0; 1107 return 0;
1110 1108
1111 bp = port_Board(port); 1109 bp = port_Board(port);
1112 1110
1113 if (!tty || !port->xmit_buf) 1111 if (!tty || !port->xmit_buf)
@@ -1144,38 +1142,41 @@ static int rc_write(struct tty_struct * tty,
1144 return total; 1142 return total;
1145} 1143}
1146 1144
1147static void rc_put_char(struct tty_struct * tty, unsigned char ch) 1145static int rc_put_char(struct tty_struct *tty, unsigned char ch)
1148{ 1146{
1149 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1147 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1150 unsigned long flags; 1148 unsigned long flags;
1149 int ret = 0;
1151 1150
1152 if (rc_paranoia_check(port, tty->name, "rc_put_char")) 1151 if (rc_paranoia_check(port, tty->name, "rc_put_char"))
1153 return; 1152 return 0;
1154 1153
1155 if (!tty || !port->xmit_buf) 1154 if (!tty || !port->xmit_buf)
1156 return; 1155 return 0;
1157 1156
1158 spin_lock_irqsave(&riscom_lock, flags); 1157 spin_lock_irqsave(&riscom_lock, flags);
1159 1158
1160 if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) 1159 if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
1161 goto out; 1160 goto out;
1162 1161
1163 port->xmit_buf[port->xmit_head++] = ch; 1162 port->xmit_buf[port->xmit_head++] = ch;
1164 port->xmit_head &= SERIAL_XMIT_SIZE - 1; 1163 port->xmit_head &= SERIAL_XMIT_SIZE - 1;
1165 port->xmit_cnt++; 1164 port->xmit_cnt++;
1165 ret = 1;
1166 1166
1167out: 1167out:
1168 spin_unlock_irqrestore(&riscom_lock, flags); 1168 spin_unlock_irqrestore(&riscom_lock, flags);
1169 return ret;
1169} 1170}
1170 1171
1171static void rc_flush_chars(struct tty_struct * tty) 1172static void rc_flush_chars(struct tty_struct *tty)
1172{ 1173{
1173 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1174 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1174 unsigned long flags; 1175 unsigned long flags;
1175 1176
1176 if (rc_paranoia_check(port, tty->name, "rc_flush_chars")) 1177 if (rc_paranoia_check(port, tty->name, "rc_flush_chars"))
1177 return; 1178 return;
1178 1179
1179 if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped || 1180 if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
1180 !port->xmit_buf) 1181 !port->xmit_buf)
1181 return; 1182 return;
@@ -1189,11 +1190,11 @@ static void rc_flush_chars(struct tty_struct * tty)
1189 spin_unlock_irqrestore(&riscom_lock, flags); 1190 spin_unlock_irqrestore(&riscom_lock, flags);
1190} 1191}
1191 1192
1192static int rc_write_room(struct tty_struct * tty) 1193static int rc_write_room(struct tty_struct *tty)
1193{ 1194{
1194 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1195 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1195 int ret; 1196 int ret;
1196 1197
1197 if (rc_paranoia_check(port, tty->name, "rc_write_room")) 1198 if (rc_paranoia_check(port, tty->name, "rc_write_room"))
1198 return 0; 1199 return 0;
1199 1200
@@ -1206,39 +1207,22 @@ static int rc_write_room(struct tty_struct * tty)
1206static int rc_chars_in_buffer(struct tty_struct *tty) 1207static int rc_chars_in_buffer(struct tty_struct *tty)
1207{ 1208{
1208 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1209 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1209 1210
1210 if (rc_paranoia_check(port, tty->name, "rc_chars_in_buffer")) 1211 if (rc_paranoia_check(port, tty->name, "rc_chars_in_buffer"))
1211 return 0; 1212 return 0;
1212
1213 return port->xmit_cnt;
1214}
1215
1216static void rc_flush_buffer(struct tty_struct *tty)
1217{
1218 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1219 unsigned long flags;
1220
1221 if (rc_paranoia_check(port, tty->name, "rc_flush_buffer"))
1222 return;
1223
1224 spin_lock_irqsave(&riscom_lock, flags);
1225
1226 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1227 1213
1228 spin_unlock_irqrestore(&riscom_lock, flags); 1214 return port->xmit_cnt;
1229
1230 tty_wakeup(tty);
1231} 1215}
1232 1216
1233static int rc_tiocmget(struct tty_struct *tty, struct file *file) 1217static int rc_tiocmget(struct tty_struct *tty, struct file *file)
1234{ 1218{
1235 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1219 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1236 struct riscom_board * bp; 1220 struct riscom_board *bp;
1237 unsigned char status; 1221 unsigned char status;
1238 unsigned int result; 1222 unsigned int result;
1239 unsigned long flags; 1223 unsigned long flags;
1240 1224
1241 if (rc_paranoia_check(port, tty->name, __FUNCTION__)) 1225 if (rc_paranoia_check(port, tty->name, __func__))
1242 return -ENODEV; 1226 return -ENODEV;
1243 1227
1244 bp = port_Board(port); 1228 bp = port_Board(port);
@@ -1266,7 +1250,7 @@ static int rc_tiocmset(struct tty_struct *tty, struct file *file,
1266 unsigned long flags; 1250 unsigned long flags;
1267 struct riscom_board *bp; 1251 struct riscom_board *bp;
1268 1252
1269 if (rc_paranoia_check(port, tty->name, __FUNCTION__)) 1253 if (rc_paranoia_check(port, tty->name, __func__))
1270 return -ENODEV; 1254 return -ENODEV;
1271 1255
1272 bp = port_Board(port); 1256 bp = port_Board(port);
@@ -1292,11 +1276,11 @@ static int rc_tiocmset(struct tty_struct *tty, struct file *file,
1292 return 0; 1276 return 0;
1293} 1277}
1294 1278
1295static inline void rc_send_break(struct riscom_port * port, unsigned long length) 1279static void rc_send_break(struct riscom_port *port, unsigned long length)
1296{ 1280{
1297 struct riscom_board *bp = port_Board(port); 1281 struct riscom_board *bp = port_Board(port);
1298 unsigned long flags; 1282 unsigned long flags;
1299 1283
1300 spin_lock_irqsave(&riscom_lock, flags); 1284 spin_lock_irqsave(&riscom_lock, flags);
1301 1285
1302 port->break_length = RISCOM_TPS / HZ * length; 1286 port->break_length = RISCOM_TPS / HZ * length;
@@ -1312,17 +1296,17 @@ static inline void rc_send_break(struct riscom_port * port, unsigned long length
1312 spin_unlock_irqrestore(&riscom_lock, flags); 1296 spin_unlock_irqrestore(&riscom_lock, flags);
1313} 1297}
1314 1298
1315static inline int rc_set_serial_info(struct riscom_port * port, 1299static int rc_set_serial_info(struct riscom_port *port,
1316 struct serial_struct __user * newinfo) 1300 struct serial_struct __user *newinfo)
1317{ 1301{
1318 struct serial_struct tmp; 1302 struct serial_struct tmp;
1319 struct riscom_board *bp = port_Board(port); 1303 struct riscom_board *bp = port_Board(port);
1320 int change_speed; 1304 int change_speed;
1321 1305
1322 if (copy_from_user(&tmp, newinfo, sizeof(tmp))) 1306 if (copy_from_user(&tmp, newinfo, sizeof(tmp)))
1323 return -EFAULT; 1307 return -EFAULT;
1324 1308
1325#if 0 1309#if 0
1326 if ((tmp.irq != bp->irq) || 1310 if ((tmp.irq != bp->irq) ||
1327 (tmp.port != bp->base) || 1311 (tmp.port != bp->base) ||
1328 (tmp.type != PORT_CIRRUS) || 1312 (tmp.type != PORT_CIRRUS) ||
@@ -1331,16 +1315,16 @@ static inline int rc_set_serial_info(struct riscom_port * port,
1331 (tmp.xmit_fifo_size != CD180_NFIFO) || 1315 (tmp.xmit_fifo_size != CD180_NFIFO) ||
1332 (tmp.flags & ~RISCOM_LEGAL_FLAGS)) 1316 (tmp.flags & ~RISCOM_LEGAL_FLAGS))
1333 return -EINVAL; 1317 return -EINVAL;
1334#endif 1318#endif
1335 1319
1336 change_speed = ((port->flags & ASYNC_SPD_MASK) != 1320 change_speed = ((port->flags & ASYNC_SPD_MASK) !=
1337 (tmp.flags & ASYNC_SPD_MASK)); 1321 (tmp.flags & ASYNC_SPD_MASK));
1338 1322
1339 if (!capable(CAP_SYS_ADMIN)) { 1323 if (!capable(CAP_SYS_ADMIN)) {
1340 if ((tmp.close_delay != port->close_delay) || 1324 if ((tmp.close_delay != port->close_delay) ||
1341 (tmp.closing_wait != port->closing_wait) || 1325 (tmp.closing_wait != port->closing_wait) ||
1342 ((tmp.flags & ~ASYNC_USR_MASK) != 1326 ((tmp.flags & ~ASYNC_USR_MASK) !=
1343 (port->flags & ~ASYNC_USR_MASK))) 1327 (port->flags & ~ASYNC_USR_MASK)))
1344 return -EPERM; 1328 return -EPERM;
1345 port->flags = ((port->flags & ~ASYNC_USR_MASK) | 1329 port->flags = ((port->flags & ~ASYNC_USR_MASK) |
1346 (tmp.flags & ASYNC_USR_MASK)); 1330 (tmp.flags & ASYNC_USR_MASK));
@@ -1360,12 +1344,12 @@ static inline int rc_set_serial_info(struct riscom_port * port,
1360 return 0; 1344 return 0;
1361} 1345}
1362 1346
1363static inline int rc_get_serial_info(struct riscom_port * port, 1347static int rc_get_serial_info(struct riscom_port *port,
1364 struct serial_struct __user *retinfo) 1348 struct serial_struct __user *retinfo)
1365{ 1349{
1366 struct serial_struct tmp; 1350 struct serial_struct tmp;
1367 struct riscom_board *bp = port_Board(port); 1351 struct riscom_board *bp = port_Board(port);
1368 1352
1369 memset(&tmp, 0, sizeof(tmp)); 1353 memset(&tmp, 0, sizeof(tmp));
1370 tmp.type = PORT_CIRRUS; 1354 tmp.type = PORT_CIRRUS;
1371 tmp.line = port - rc_port; 1355 tmp.line = port - rc_port;
@@ -1379,19 +1363,18 @@ static inline int rc_get_serial_info(struct riscom_port * port,
1379 return copy_to_user(retinfo, &tmp, sizeof(tmp)) ? -EFAULT : 0; 1363 return copy_to_user(retinfo, &tmp, sizeof(tmp)) ? -EFAULT : 0;
1380} 1364}
1381 1365
1382static int rc_ioctl(struct tty_struct * tty, struct file * filp, 1366static int rc_ioctl(struct tty_struct *tty, struct file *filp,
1383 unsigned int cmd, unsigned long arg) 1367 unsigned int cmd, unsigned long arg)
1384
1385{ 1368{
1386 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1369 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1387 void __user *argp = (void __user *)arg; 1370 void __user *argp = (void __user *)arg;
1388 int retval; 1371 int retval = 0;
1389 1372
1390 if (rc_paranoia_check(port, tty->name, "rc_ioctl")) 1373 if (rc_paranoia_check(port, tty->name, "rc_ioctl"))
1391 return -ENODEV; 1374 return -ENODEV;
1392 1375
1393 switch (cmd) { 1376 switch (cmd) {
1394 case TCSBRK: /* SVID version: non-zero arg --> no break */ 1377 case TCSBRK: /* SVID version: non-zero arg --> no break */
1395 retval = tty_check_change(tty); 1378 retval = tty_check_change(tty);
1396 if (retval) 1379 if (retval)
1397 return retval; 1380 return retval;
@@ -1399,45 +1382,40 @@ static int rc_ioctl(struct tty_struct * tty, struct file * filp,
1399 if (!arg) 1382 if (!arg)
1400 rc_send_break(port, HZ/4); /* 1/4 second */ 1383 rc_send_break(port, HZ/4); /* 1/4 second */
1401 break; 1384 break;
1402 case TCSBRKP: /* support for POSIX tcsendbreak() */ 1385 case TCSBRKP: /* support for POSIX tcsendbreak() */
1403 retval = tty_check_change(tty); 1386 retval = tty_check_change(tty);
1404 if (retval) 1387 if (retval)
1405 return retval; 1388 return retval;
1406 tty_wait_until_sent(tty, 0); 1389 tty_wait_until_sent(tty, 0);
1407 rc_send_break(port, arg ? arg*(HZ/10) : HZ/4); 1390 rc_send_break(port, arg ? arg*(HZ/10) : HZ/4);
1408 break; 1391 break;
1409 case TIOCGSOFTCAR: 1392 case TIOCGSERIAL:
1410 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned __user *)argp); 1393 lock_kernel();
1411 case TIOCSSOFTCAR: 1394 retval = rc_get_serial_info(port, argp);
1412 if (get_user(arg,(unsigned __user *) argp)) 1395 unlock_kernel();
1413 return -EFAULT;
1414 tty->termios->c_cflag =
1415 ((tty->termios->c_cflag & ~CLOCAL) |
1416 (arg ? CLOCAL : 0));
1417 break; 1396 break;
1418 case TIOCGSERIAL: 1397 case TIOCSSERIAL:
1419 return rc_get_serial_info(port, argp); 1398 lock_kernel();
1420 case TIOCSSERIAL: 1399 retval = rc_set_serial_info(port, argp);
1421 return rc_set_serial_info(port, argp); 1400 unlock_kernel();
1422 default: 1401 break;
1423 return -ENOIOCTLCMD; 1402 default:
1403 retval = -ENOIOCTLCMD;
1424 } 1404 }
1425 return 0; 1405 return retval;
1426} 1406}
1427 1407
1428static void rc_throttle(struct tty_struct * tty) 1408static void rc_throttle(struct tty_struct *tty)
1429{ 1409{
1430 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1410 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1431 struct riscom_board *bp; 1411 struct riscom_board *bp;
1432 unsigned long flags; 1412 unsigned long flags;
1433 1413
1434 if (rc_paranoia_check(port, tty->name, "rc_throttle")) 1414 if (rc_paranoia_check(port, tty->name, "rc_throttle"))
1435 return; 1415 return;
1436
1437 bp = port_Board(port); 1416 bp = port_Board(port);
1438 1417
1439 spin_lock_irqsave(&riscom_lock, flags); 1418 spin_lock_irqsave(&riscom_lock, flags);
1440
1441 port->MSVR &= ~MSVR_RTS; 1419 port->MSVR &= ~MSVR_RTS;
1442 rc_out(bp, CD180_CAR, port_No(port)); 1420 rc_out(bp, CD180_CAR, port_No(port));
1443 if (I_IXOFF(tty)) { 1421 if (I_IXOFF(tty)) {
@@ -1446,23 +1424,20 @@ static void rc_throttle(struct tty_struct * tty)
1446 rc_wait_CCR(bp); 1424 rc_wait_CCR(bp);
1447 } 1425 }
1448 rc_out(bp, CD180_MSVR, port->MSVR); 1426 rc_out(bp, CD180_MSVR, port->MSVR);
1449
1450 spin_unlock_irqrestore(&riscom_lock, flags); 1427 spin_unlock_irqrestore(&riscom_lock, flags);
1451} 1428}
1452 1429
1453static void rc_unthrottle(struct tty_struct * tty) 1430static void rc_unthrottle(struct tty_struct *tty)
1454{ 1431{
1455 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1432 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1456 struct riscom_board *bp; 1433 struct riscom_board *bp;
1457 unsigned long flags; 1434 unsigned long flags;
1458 1435
1459 if (rc_paranoia_check(port, tty->name, "rc_unthrottle")) 1436 if (rc_paranoia_check(port, tty->name, "rc_unthrottle"))
1460 return; 1437 return;
1461
1462 bp = port_Board(port); 1438 bp = port_Board(port);
1463
1464 spin_lock_irqsave(&riscom_lock, flags);
1465 1439
1440 spin_lock_irqsave(&riscom_lock, flags);
1466 port->MSVR |= MSVR_RTS; 1441 port->MSVR |= MSVR_RTS;
1467 rc_out(bp, CD180_CAR, port_No(port)); 1442 rc_out(bp, CD180_CAR, port_No(port));
1468 if (I_IXOFF(tty)) { 1443 if (I_IXOFF(tty)) {
@@ -1471,62 +1446,58 @@ static void rc_unthrottle(struct tty_struct * tty)
1471 rc_wait_CCR(bp); 1446 rc_wait_CCR(bp);
1472 } 1447 }
1473 rc_out(bp, CD180_MSVR, port->MSVR); 1448 rc_out(bp, CD180_MSVR, port->MSVR);
1474
1475 spin_unlock_irqrestore(&riscom_lock, flags); 1449 spin_unlock_irqrestore(&riscom_lock, flags);
1476} 1450}
1477 1451
1478static void rc_stop(struct tty_struct * tty) 1452static void rc_stop(struct tty_struct *tty)
1479{ 1453{
1480 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1454 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1481 struct riscom_board *bp; 1455 struct riscom_board *bp;
1482 unsigned long flags; 1456 unsigned long flags;
1483 1457
1484 if (rc_paranoia_check(port, tty->name, "rc_stop")) 1458 if (rc_paranoia_check(port, tty->name, "rc_stop"))
1485 return; 1459 return;
1486 1460
1487 bp = port_Board(port); 1461 bp = port_Board(port);
1488
1489 spin_lock_irqsave(&riscom_lock, flags);
1490 1462
1463 spin_lock_irqsave(&riscom_lock, flags);
1491 port->IER &= ~IER_TXRDY; 1464 port->IER &= ~IER_TXRDY;
1492 rc_out(bp, CD180_CAR, port_No(port)); 1465 rc_out(bp, CD180_CAR, port_No(port));
1493 rc_out(bp, CD180_IER, port->IER); 1466 rc_out(bp, CD180_IER, port->IER);
1494
1495 spin_unlock_irqrestore(&riscom_lock, flags); 1467 spin_unlock_irqrestore(&riscom_lock, flags);
1496} 1468}
1497 1469
1498static void rc_start(struct tty_struct * tty) 1470static void rc_start(struct tty_struct *tty)
1499{ 1471{
1500 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1472 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1501 struct riscom_board *bp; 1473 struct riscom_board *bp;
1502 unsigned long flags; 1474 unsigned long flags;
1503 1475
1504 if (rc_paranoia_check(port, tty->name, "rc_start")) 1476 if (rc_paranoia_check(port, tty->name, "rc_start"))
1505 return; 1477 return;
1506 1478
1507 bp = port_Board(port); 1479 bp = port_Board(port);
1508 1480
1509 spin_lock_irqsave(&riscom_lock, flags); 1481 spin_lock_irqsave(&riscom_lock, flags);
1510 1482
1511 if (port->xmit_cnt && port->xmit_buf && !(port->IER & IER_TXRDY)) { 1483 if (port->xmit_cnt && port->xmit_buf && !(port->IER & IER_TXRDY)) {
1512 port->IER |= IER_TXRDY; 1484 port->IER |= IER_TXRDY;
1513 rc_out(bp, CD180_CAR, port_No(port)); 1485 rc_out(bp, CD180_CAR, port_No(port));
1514 rc_out(bp, CD180_IER, port->IER); 1486 rc_out(bp, CD180_IER, port->IER);
1515 } 1487 }
1516
1517 spin_unlock_irqrestore(&riscom_lock, flags); 1488 spin_unlock_irqrestore(&riscom_lock, flags);
1518} 1489}
1519 1490
1520static void rc_hangup(struct tty_struct * tty) 1491static void rc_hangup(struct tty_struct *tty)
1521{ 1492{
1522 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1493 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1523 struct riscom_board *bp; 1494 struct riscom_board *bp;
1524 1495
1525 if (rc_paranoia_check(port, tty->name, "rc_hangup")) 1496 if (rc_paranoia_check(port, tty->name, "rc_hangup"))
1526 return; 1497 return;
1527 1498
1528 bp = port_Board(port); 1499 bp = port_Board(port);
1529 1500
1530 rc_shutdown_port(bp, port); 1501 rc_shutdown_port(bp, port);
1531 port->count = 0; 1502 port->count = 0;
1532 port->flags &= ~ASYNC_NORMAL_ACTIVE; 1503 port->flags &= ~ASYNC_NORMAL_ACTIVE;
@@ -1534,17 +1505,14 @@ static void rc_hangup(struct tty_struct * tty)
1534 wake_up_interruptible(&port->open_wait); 1505 wake_up_interruptible(&port->open_wait);
1535} 1506}
1536 1507
1537static void rc_set_termios(struct tty_struct * tty, struct ktermios * old_termios) 1508static void rc_set_termios(struct tty_struct *tty,
1509 struct ktermios *old_termios)
1538{ 1510{
1539 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1511 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1540 unsigned long flags; 1512 unsigned long flags;
1541 1513
1542 if (rc_paranoia_check(port, tty->name, "rc_set_termios")) 1514 if (rc_paranoia_check(port, tty->name, "rc_set_termios"))
1543 return; 1515 return;
1544
1545 if (tty->termios->c_cflag == old_termios->c_cflag &&
1546 tty->termios->c_iflag == old_termios->c_iflag)
1547 return;
1548 1516
1549 spin_lock_irqsave(&riscom_lock, flags); 1517 spin_lock_irqsave(&riscom_lock, flags);
1550 rc_change_speed(port_Board(port), port); 1518 rc_change_speed(port_Board(port), port);
@@ -1583,9 +1551,9 @@ static int __init rc_init_drivers(void)
1583 int i; 1551 int i;
1584 1552
1585 riscom_driver = alloc_tty_driver(RC_NBOARD * RC_NPORT); 1553 riscom_driver = alloc_tty_driver(RC_NBOARD * RC_NPORT);
1586 if (!riscom_driver) 1554 if (!riscom_driver)
1587 return -ENOMEM; 1555 return -ENOMEM;
1588 1556
1589 riscom_driver->owner = THIS_MODULE; 1557 riscom_driver->owner = THIS_MODULE;
1590 riscom_driver->name = "ttyL"; 1558 riscom_driver->name = "ttyL";
1591 riscom_driver->major = RISCOM8_NORMAL_MAJOR; 1559 riscom_driver->major = RISCOM8_NORMAL_MAJOR;
@@ -1598,23 +1566,21 @@ static int __init rc_init_drivers(void)
1598 riscom_driver->init_termios.c_ospeed = 9600; 1566 riscom_driver->init_termios.c_ospeed = 9600;
1599 riscom_driver->flags = TTY_DRIVER_REAL_RAW; 1567 riscom_driver->flags = TTY_DRIVER_REAL_RAW;
1600 tty_set_operations(riscom_driver, &riscom_ops); 1568 tty_set_operations(riscom_driver, &riscom_ops);
1601 if ((error = tty_register_driver(riscom_driver))) { 1569 error = tty_register_driver(riscom_driver);
1570 if (error != 0) {
1602 put_tty_driver(riscom_driver); 1571 put_tty_driver(riscom_driver);
1603 printk(KERN_ERR "rc: Couldn't register RISCom/8 driver, " 1572 printk(KERN_ERR "rc: Couldn't register RISCom/8 driver, "
1604 "error = %d\n", 1573 "error = %d\n", error);
1605 error);
1606 return 1; 1574 return 1;
1607 } 1575 }
1608
1609 memset(rc_port, 0, sizeof(rc_port)); 1576 memset(rc_port, 0, sizeof(rc_port));
1610 for (i = 0; i < RC_NPORT * RC_NBOARD; i++) { 1577 for (i = 0; i < RC_NPORT * RC_NBOARD; i++) {
1611 rc_port[i].magic = RISCOM8_MAGIC; 1578 rc_port[i].magic = RISCOM8_MAGIC;
1612 rc_port[i].close_delay = 50 * HZ/100; 1579 rc_port[i].close_delay = 50 * HZ / 100;
1613 rc_port[i].closing_wait = 3000 * HZ/100; 1580 rc_port[i].closing_wait = 3000 * HZ / 100;
1614 init_waitqueue_head(&rc_port[i].open_wait); 1581 init_waitqueue_head(&rc_port[i].open_wait);
1615 init_waitqueue_head(&rc_port[i].close_wait); 1582 init_waitqueue_head(&rc_port[i].close_wait);
1616 } 1583 }
1617
1618 return 0; 1584 return 0;
1619} 1585}
1620 1586
@@ -1627,13 +1593,13 @@ static void rc_release_drivers(void)
1627#ifndef MODULE 1593#ifndef MODULE
1628/* 1594/*
1629 * Called at boot time. 1595 * Called at boot time.
1630 * 1596 *
1631 * You can specify IO base for up to RC_NBOARD cards, 1597 * You can specify IO base for up to RC_NBOARD cards,
1632 * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt. 1598 * using line "riscom8=0xiobase1,0xiobase2,.." at LILO prompt.
1633 * Note that there will be no probing at default 1599 * Note that there will be no probing at default
1634 * addresses in this case. 1600 * addresses in this case.
1635 * 1601 *
1636 */ 1602 */
1637static int __init riscom8_setup(char *str) 1603static int __init riscom8_setup(char *str)
1638{ 1604{
1639 int ints[RC_NBOARD]; 1605 int ints[RC_NBOARD];
@@ -1644,7 +1610,7 @@ static int __init riscom8_setup(char *str)
1644 for (i = 0; i < RC_NBOARD; i++) { 1610 for (i = 0; i < RC_NBOARD; i++) {
1645 if (i < ints[0]) 1611 if (i < ints[0])
1646 rc_board[i].base = ints[i+1]; 1612 rc_board[i].base = ints[i+1];
1647 else 1613 else
1648 rc_board[i].base = 0; 1614 rc_board[i].base = 0;
1649 } 1615 }
1650 return 1; 1616 return 1;
@@ -1659,8 +1625,8 @@ static char banner[] __initdata =
1659static char no_boards_msg[] __initdata = 1625static char no_boards_msg[] __initdata =
1660 KERN_INFO "rc: No RISCom/8 boards detected.\n"; 1626 KERN_INFO "rc: No RISCom/8 boards detected.\n";
1661 1627
1662/* 1628/*
1663 * This routine must be called by kernel at boot time 1629 * This routine must be called by kernel at boot time
1664 */ 1630 */
1665static int __init riscom8_init(void) 1631static int __init riscom8_init(void)
1666{ 1632{
@@ -1669,13 +1635,12 @@ static int __init riscom8_init(void)
1669 1635
1670 printk(banner); 1636 printk(banner);
1671 1637
1672 if (rc_init_drivers()) 1638 if (rc_init_drivers())
1673 return -EIO; 1639 return -EIO;
1674 1640
1675 for (i = 0; i < RC_NBOARD; i++) 1641 for (i = 0; i < RC_NBOARD; i++)
1676 if (rc_board[i].base && !rc_probe(&rc_board[i])) 1642 if (rc_board[i].base && !rc_probe(&rc_board[i]))
1677 found++; 1643 found++;
1678
1679 if (!found) { 1644 if (!found) {
1680 rc_release_drivers(); 1645 rc_release_drivers();
1681 printk(no_boards_msg); 1646 printk(no_boards_msg);
@@ -1702,13 +1667,13 @@ MODULE_LICENSE("GPL");
1702 * by specifying "iobase=0xXXX iobase1=0xXXX ..." as insmod parameter. 1667 * by specifying "iobase=0xXXX iobase1=0xXXX ..." as insmod parameter.
1703 * 1668 *
1704 */ 1669 */
1705static int __init riscom8_init_module (void) 1670static int __init riscom8_init_module(void)
1706{ 1671{
1707#ifdef MODULE 1672#ifdef MODULE
1708 int i; 1673 int i;
1709 1674
1710 if (iobase || iobase1 || iobase2 || iobase3) { 1675 if (iobase || iobase1 || iobase2 || iobase3) {
1711 for(i = 0; i < RC_NBOARD; i++) 1676 for (i = 0; i < RC_NBOARD; i++)
1712 rc_board[i].base = 0; 1677 rc_board[i].base = 0;
1713 } 1678 }
1714 1679
@@ -1724,18 +1689,17 @@ static int __init riscom8_init_module (void)
1724 1689
1725 return riscom8_init(); 1690 return riscom8_init();
1726} 1691}
1727 1692
1728static void __exit riscom8_exit_module (void) 1693static void __exit riscom8_exit_module(void)
1729{ 1694{
1730 int i; 1695 int i;
1731 1696
1732 rc_release_drivers(); 1697 rc_release_drivers();
1733 for (i = 0; i < RC_NBOARD; i++) 1698 for (i = 0; i < RC_NBOARD; i++)
1734 if (rc_board[i].flags & RC_BOARD_PRESENT) 1699 if (rc_board[i].flags & RC_BOARD_PRESENT)
1735 rc_release_io_range(&rc_board[i]); 1700 rc_release_io_range(&rc_board[i]);
1736 1701
1737} 1702}
1738 1703
1739module_init(riscom8_init_module); 1704module_init(riscom8_init_module);
1740module_exit(riscom8_exit_module); 1705module_exit(riscom8_exit_module);
1741
diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
index f585bc8579e9..743dc80a9325 100644
--- a/drivers/char/rocket.c
+++ b/drivers/char/rocket.c
@@ -449,7 +449,8 @@ static void rp_do_transmit(struct r_port *info)
449 while (1) { 449 while (1) {
450 if (tty->stopped || tty->hw_stopped) 450 if (tty->stopped || tty->hw_stopped)
451 break; 451 break;
452 c = min(info->xmit_fifo_room, min(info->xmit_cnt, XMIT_BUF_SIZE - info->xmit_tail)); 452 c = min(info->xmit_fifo_room, info->xmit_cnt);
453 c = min(c, XMIT_BUF_SIZE - info->xmit_tail);
453 if (c <= 0 || info->xmit_fifo_room <= 0) 454 if (c <= 0 || info->xmit_fifo_room <= 0)
454 break; 455 break;
455 sOutStrW(sGetTxRxDataIO(cp), (unsigned short *) (info->xmit_buf + info->xmit_tail), c / 2); 456 sOutStrW(sGetTxRxDataIO(cp), (unsigned short *) (info->xmit_buf + info->xmit_tail), c / 2);
@@ -1433,29 +1434,38 @@ static int rp_ioctl(struct tty_struct *tty, struct file *file,
1433{ 1434{
1434 struct r_port *info = (struct r_port *) tty->driver_data; 1435 struct r_port *info = (struct r_port *) tty->driver_data;
1435 void __user *argp = (void __user *)arg; 1436 void __user *argp = (void __user *)arg;
1437 int ret = 0;
1436 1438
1437 if (cmd != RCKP_GET_PORTS && rocket_paranoia_check(info, "rp_ioctl")) 1439 if (cmd != RCKP_GET_PORTS && rocket_paranoia_check(info, "rp_ioctl"))
1438 return -ENXIO; 1440 return -ENXIO;
1439 1441
1442 lock_kernel();
1443
1440 switch (cmd) { 1444 switch (cmd) {
1441 case RCKP_GET_STRUCT: 1445 case RCKP_GET_STRUCT:
1442 if (copy_to_user(argp, info, sizeof (struct r_port))) 1446 if (copy_to_user(argp, info, sizeof (struct r_port)))
1443 return -EFAULT; 1447 ret = -EFAULT;
1444 return 0; 1448 break;
1445 case RCKP_GET_CONFIG: 1449 case RCKP_GET_CONFIG:
1446 return get_config(info, argp); 1450 ret = get_config(info, argp);
1451 break;
1447 case RCKP_SET_CONFIG: 1452 case RCKP_SET_CONFIG:
1448 return set_config(info, argp); 1453 ret = set_config(info, argp);
1454 break;
1449 case RCKP_GET_PORTS: 1455 case RCKP_GET_PORTS:
1450 return get_ports(info, argp); 1456 ret = get_ports(info, argp);
1457 break;
1451 case RCKP_RESET_RM2: 1458 case RCKP_RESET_RM2:
1452 return reset_rm2(info, argp); 1459 ret = reset_rm2(info, argp);
1460 break;
1453 case RCKP_GET_VERSION: 1461 case RCKP_GET_VERSION:
1454 return get_version(info, argp); 1462 ret = get_version(info, argp);
1463 break;
1455 default: 1464 default:
1456 return -ENOIOCTLCMD; 1465 ret = -ENOIOCTLCMD;
1457 } 1466 }
1458 return 0; 1467 unlock_kernel();
1468 return ret;
1459} 1469}
1460 1470
1461static void rp_send_xchar(struct tty_struct *tty, char ch) 1471static void rp_send_xchar(struct tty_struct *tty, char ch)
@@ -1575,6 +1585,7 @@ static void rp_wait_until_sent(struct tty_struct *tty, int timeout)
1575 jiffies); 1585 jiffies);
1576 printk(KERN_INFO "cps=%d...\n", info->cps); 1586 printk(KERN_INFO "cps=%d...\n", info->cps);
1577#endif 1587#endif
1588 lock_kernel();
1578 while (1) { 1589 while (1) {
1579 txcnt = sGetTxCnt(cp); 1590 txcnt = sGetTxCnt(cp);
1580 if (!txcnt) { 1591 if (!txcnt) {
@@ -1602,6 +1613,7 @@ static void rp_wait_until_sent(struct tty_struct *tty, int timeout)
1602 break; 1613 break;
1603 } 1614 }
1604 __set_current_state(TASK_RUNNING); 1615 __set_current_state(TASK_RUNNING);
1616 unlock_kernel();
1605#ifdef ROCKET_DEBUG_WAIT_UNTIL_SENT 1617#ifdef ROCKET_DEBUG_WAIT_UNTIL_SENT
1606 printk(KERN_INFO "txcnt = %d (jiff=%lu)...done\n", txcnt, jiffies); 1618 printk(KERN_INFO "txcnt = %d (jiff=%lu)...done\n", txcnt, jiffies);
1607#endif 1619#endif
@@ -1651,14 +1663,14 @@ static void rp_hangup(struct tty_struct *tty)
1651 * writing routines will write directly to transmit FIFO. 1663 * writing routines will write directly to transmit FIFO.
1652 * Write buffer and counters protected by spinlocks 1664 * Write buffer and counters protected by spinlocks
1653 */ 1665 */
1654static void rp_put_char(struct tty_struct *tty, unsigned char ch) 1666static int rp_put_char(struct tty_struct *tty, unsigned char ch)
1655{ 1667{
1656 struct r_port *info = (struct r_port *) tty->driver_data; 1668 struct r_port *info = (struct r_port *) tty->driver_data;
1657 CHANNEL_t *cp; 1669 CHANNEL_t *cp;
1658 unsigned long flags; 1670 unsigned long flags;
1659 1671
1660 if (rocket_paranoia_check(info, "rp_put_char")) 1672 if (rocket_paranoia_check(info, "rp_put_char"))
1661 return; 1673 return 0;
1662 1674
1663 /* 1675 /*
1664 * Grab the port write mutex, locking out other processes that try to 1676 * Grab the port write mutex, locking out other processes that try to
@@ -1687,6 +1699,7 @@ static void rp_put_char(struct tty_struct *tty, unsigned char ch)
1687 } 1699 }
1688 spin_unlock_irqrestore(&info->slock, flags); 1700 spin_unlock_irqrestore(&info->slock, flags);
1689 mutex_unlock(&info->write_mtx); 1701 mutex_unlock(&info->write_mtx);
1702 return 1;
1690} 1703}
1691 1704
1692/* 1705/*
@@ -1749,10 +1762,10 @@ static int rp_write(struct tty_struct *tty,
1749 1762
1750 /* Write remaining data into the port's xmit_buf */ 1763 /* Write remaining data into the port's xmit_buf */
1751 while (1) { 1764 while (1) {
1752 if (!info->tty) /* Seemingly obligatory check... */ 1765 if (!info->tty) /* Seemingly obligatory check... */
1753 goto end; 1766 goto end;
1754 1767 c = min(count, XMIT_BUF_SIZE - info->xmit_cnt - 1);
1755 c = min(count, min(XMIT_BUF_SIZE - info->xmit_cnt - 1, XMIT_BUF_SIZE - info->xmit_head)); 1768 c = min(c, XMIT_BUF_SIZE - info->xmit_head);
1756 if (c <= 0) 1769 if (c <= 0)
1757 break; 1770 break;
1758 1771
diff --git a/drivers/char/serial167.c b/drivers/char/serial167.c
index df8cd0ca97eb..3b23270eaa65 100644
--- a/drivers/char/serial167.c
+++ b/drivers/char/serial167.c
@@ -1060,7 +1060,7 @@ static void config_setup(struct cyclades_port *info)
1060 1060
1061} /* config_setup */ 1061} /* config_setup */
1062 1062
1063static void cy_put_char(struct tty_struct *tty, unsigned char ch) 1063static int cy_put_char(struct tty_struct *tty, unsigned char ch)
1064{ 1064{
1065 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1065 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1066 unsigned long flags; 1066 unsigned long flags;
@@ -1070,21 +1070,22 @@ static void cy_put_char(struct tty_struct *tty, unsigned char ch)
1070#endif 1070#endif
1071 1071
1072 if (serial_paranoia_check(info, tty->name, "cy_put_char")) 1072 if (serial_paranoia_check(info, tty->name, "cy_put_char"))
1073 return; 1073 return 0;
1074 1074
1075 if (!info->xmit_buf) 1075 if (!info->xmit_buf)
1076 return; 1076 return 0;
1077 1077
1078 local_irq_save(flags); 1078 local_irq_save(flags);
1079 if (info->xmit_cnt >= PAGE_SIZE - 1) { 1079 if (info->xmit_cnt >= PAGE_SIZE - 1) {
1080 local_irq_restore(flags); 1080 local_irq_restore(flags);
1081 return; 1081 return 0;
1082 } 1082 }
1083 1083
1084 info->xmit_buf[info->xmit_head++] = ch; 1084 info->xmit_buf[info->xmit_head++] = ch;
1085 info->xmit_head &= PAGE_SIZE - 1; 1085 info->xmit_head &= PAGE_SIZE - 1;
1086 info->xmit_cnt++; 1086 info->xmit_cnt++;
1087 local_irq_restore(flags); 1087 local_irq_restore(flags);
1088 return 1;
1088} /* cy_put_char */ 1089} /* cy_put_char */
1089 1090
1090static void cy_flush_chars(struct tty_struct *tty) 1091static void cy_flush_chars(struct tty_struct *tty)
@@ -1539,6 +1540,8 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
1539 printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg); /* */ 1540 printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg); /* */
1540#endif 1541#endif
1541 1542
1543 lock_kernel();
1544
1542 switch (cmd) { 1545 switch (cmd) {
1543 case CYGETMON: 1546 case CYGETMON:
1544 ret_val = get_mon_info(info, argp); 1547 ret_val = get_mon_info(info, argp);
@@ -1584,18 +1587,6 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
1584 break; 1587 break;
1585 1588
1586/* The following commands are incompletely implemented!!! */ 1589/* The following commands are incompletely implemented!!! */
1587 case TIOCGSOFTCAR:
1588 ret_val =
1589 put_user(C_CLOCAL(tty) ? 1 : 0,
1590 (unsigned long __user *)argp);
1591 break;
1592 case TIOCSSOFTCAR:
1593 ret_val = get_user(val, (unsigned long __user *)argp);
1594 if (ret_val)
1595 break;
1596 tty->termios->c_cflag =
1597 ((tty->termios->c_cflag & ~CLOCAL) | (val ? CLOCAL : 0));
1598 break;
1599 case TIOCGSERIAL: 1590 case TIOCGSERIAL:
1600 ret_val = get_serial_info(info, argp); 1591 ret_val = get_serial_info(info, argp);
1601 break; 1592 break;
@@ -1605,6 +1596,7 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
1605 default: 1596 default:
1606 ret_val = -ENOIOCTLCMD; 1597 ret_val = -ENOIOCTLCMD;
1607 } 1598 }
1599 unlock_kernel();
1608 1600
1609#ifdef SERIAL_DEBUG_OTHER 1601#ifdef SERIAL_DEBUG_OTHER
1610 printk("cy_ioctl done\n"); 1602 printk("cy_ioctl done\n");
@@ -1683,8 +1675,7 @@ static void cy_close(struct tty_struct *tty, struct file *filp)
1683 if (info->flags & ASYNC_INITIALIZED) 1675 if (info->flags & ASYNC_INITIALIZED)
1684 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */ 1676 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
1685 shutdown(info); 1677 shutdown(info);
1686 if (tty->driver->flush_buffer) 1678 cy_flush_buffer(tty);
1687 tty->driver->flush_buffer(tty);
1688 tty_ldisc_flush(tty); 1679 tty_ldisc_flush(tty);
1689 info->tty = NULL; 1680 info->tty = NULL;
1690 if (info->blocked_open) { 1681 if (info->blocked_open) {
diff --git a/drivers/char/snsc.c b/drivers/char/snsc.c
index b9c1dba6bd01..8fe099a41065 100644
--- a/drivers/char/snsc.c
+++ b/drivers/char/snsc.c
@@ -80,7 +80,7 @@ scdrv_open(struct inode *inode, struct file *file)
80 sd = kzalloc(sizeof (struct subch_data_s), GFP_KERNEL); 80 sd = kzalloc(sizeof (struct subch_data_s), GFP_KERNEL);
81 if (sd == NULL) { 81 if (sd == NULL) {
82 printk("%s: couldn't allocate subchannel data\n", 82 printk("%s: couldn't allocate subchannel data\n",
83 __FUNCTION__); 83 __func__);
84 return -ENOMEM; 84 return -ENOMEM;
85 } 85 }
86 86
@@ -90,7 +90,7 @@ scdrv_open(struct inode *inode, struct file *file)
90 90
91 if (sd->sd_subch < 0) { 91 if (sd->sd_subch < 0) {
92 kfree(sd); 92 kfree(sd);
93 printk("%s: couldn't allocate subchannel\n", __FUNCTION__); 93 printk("%s: couldn't allocate subchannel\n", __func__);
94 return -EBUSY; 94 return -EBUSY;
95 } 95 }
96 96
@@ -110,7 +110,7 @@ scdrv_open(struct inode *inode, struct file *file)
110 if (rv) { 110 if (rv) {
111 ia64_sn_irtr_close(sd->sd_nasid, sd->sd_subch); 111 ia64_sn_irtr_close(sd->sd_nasid, sd->sd_subch);
112 kfree(sd); 112 kfree(sd);
113 printk("%s: irq request failed (%d)\n", __FUNCTION__, rv); 113 printk("%s: irq request failed (%d)\n", __func__, rv);
114 return -EBUSY; 114 return -EBUSY;
115 } 115 }
116 116
@@ -215,7 +215,7 @@ scdrv_read(struct file *file, char __user *buf, size_t count, loff_t *f_pos)
215 */ 215 */
216 if (count < len) { 216 if (count < len) {
217 pr_debug("%s: only accepting %d of %d bytes\n", 217 pr_debug("%s: only accepting %d of %d bytes\n",
218 __FUNCTION__, (int) count, len); 218 __func__, (int) count, len);
219 } 219 }
220 len = min((int) count, len); 220 len = min((int) count, len);
221 if (copy_to_user(buf, sd->sd_rb, len)) 221 if (copy_to_user(buf, sd->sd_rb, len))
@@ -384,7 +384,7 @@ scdrv_init(void)
384 if (alloc_chrdev_region(&first_dev, 0, num_cnodes, 384 if (alloc_chrdev_region(&first_dev, 0, num_cnodes,
385 SYSCTL_BASENAME) < 0) { 385 SYSCTL_BASENAME) < 0) {
386 printk("%s: failed to register SN system controller device\n", 386 printk("%s: failed to register SN system controller device\n",
387 __FUNCTION__); 387 __func__);
388 return -ENODEV; 388 return -ENODEV;
389 } 389 }
390 snsc_class = class_create(THIS_MODULE, SYSCTL_BASENAME); 390 snsc_class = class_create(THIS_MODULE, SYSCTL_BASENAME);
@@ -403,7 +403,7 @@ scdrv_init(void)
403 GFP_KERNEL); 403 GFP_KERNEL);
404 if (!scd) { 404 if (!scd) {
405 printk("%s: failed to allocate device info" 405 printk("%s: failed to allocate device info"
406 "for %s/%s\n", __FUNCTION__, 406 "for %s/%s\n", __func__,
407 SYSCTL_BASENAME, devname); 407 SYSCTL_BASENAME, devname);
408 continue; 408 continue;
409 } 409 }
@@ -412,7 +412,7 @@ scdrv_init(void)
412 scd->scd_nasid = cnodeid_to_nasid(cnode); 412 scd->scd_nasid = cnodeid_to_nasid(cnode);
413 if (!(salbuf = kmalloc(SCDRV_BUFSZ, GFP_KERNEL))) { 413 if (!(salbuf = kmalloc(SCDRV_BUFSZ, GFP_KERNEL))) {
414 printk("%s: failed to allocate driver buffer" 414 printk("%s: failed to allocate driver buffer"
415 "(%s%s)\n", __FUNCTION__, 415 "(%s%s)\n", __func__,
416 SYSCTL_BASENAME, devname); 416 SYSCTL_BASENAME, devname);
417 kfree(scd); 417 kfree(scd);
418 continue; 418 continue;
@@ -424,7 +424,7 @@ scdrv_init(void)
424 ("%s: failed to initialize SAL for" 424 ("%s: failed to initialize SAL for"
425 " system controller communication" 425 " system controller communication"
426 " (%s/%s): outdated PROM?\n", 426 " (%s/%s): outdated PROM?\n",
427 __FUNCTION__, SYSCTL_BASENAME, devname); 427 __func__, SYSCTL_BASENAME, devname);
428 kfree(scd); 428 kfree(scd);
429 kfree(salbuf); 429 kfree(salbuf);
430 continue; 430 continue;
@@ -435,7 +435,7 @@ scdrv_init(void)
435 if (cdev_add(&scd->scd_cdev, dev, 1)) { 435 if (cdev_add(&scd->scd_cdev, dev, 1)) {
436 printk("%s: failed to register system" 436 printk("%s: failed to register system"
437 " controller device (%s%s)\n", 437 " controller device (%s%s)\n",
438 __FUNCTION__, SYSCTL_BASENAME, devname); 438 __func__, SYSCTL_BASENAME, devname);
439 kfree(scd); 439 kfree(scd);
440 kfree(salbuf); 440 kfree(salbuf);
441 continue; 441 continue;
diff --git a/drivers/char/snsc_event.c b/drivers/char/snsc_event.c
index 31a7765eaf73..53b3d44f8c06 100644
--- a/drivers/char/snsc_event.c
+++ b/drivers/char/snsc_event.c
@@ -271,7 +271,7 @@ scdrv_event_init(struct sysctl_data_s *scd)
271 event_sd = kzalloc(sizeof (struct subch_data_s), GFP_KERNEL); 271 event_sd = kzalloc(sizeof (struct subch_data_s), GFP_KERNEL);
272 if (event_sd == NULL) { 272 if (event_sd == NULL) {
273 printk(KERN_WARNING "%s: couldn't allocate subchannel info" 273 printk(KERN_WARNING "%s: couldn't allocate subchannel info"
274 " for event monitoring\n", __FUNCTION__); 274 " for event monitoring\n", __func__);
275 return; 275 return;
276 } 276 }
277 277
@@ -285,7 +285,7 @@ scdrv_event_init(struct sysctl_data_s *scd)
285 if (event_sd->sd_subch < 0) { 285 if (event_sd->sd_subch < 0) {
286 kfree(event_sd); 286 kfree(event_sd);
287 printk(KERN_WARNING "%s: couldn't open event subchannel\n", 287 printk(KERN_WARNING "%s: couldn't open event subchannel\n",
288 __FUNCTION__); 288 __func__);
289 return; 289 return;
290 } 290 }
291 291
@@ -295,7 +295,7 @@ scdrv_event_init(struct sysctl_data_s *scd)
295 "system controller events", event_sd); 295 "system controller events", event_sd);
296 if (rv) { 296 if (rv) {
297 printk(KERN_WARNING "%s: irq request failed (%d)\n", 297 printk(KERN_WARNING "%s: irq request failed (%d)\n",
298 __FUNCTION__, rv); 298 __func__, rv);
299 ia64_sn_irtr_close(event_sd->sd_nasid, event_sd->sd_subch); 299 ia64_sn_irtr_close(event_sd->sd_nasid, event_sd->sd_subch);
300 kfree(event_sd); 300 kfree(event_sd);
301 return; 301 return;
diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
index c03ad164c39a..58533de59027 100644
--- a/drivers/char/sonypi.c
+++ b/drivers/char/sonypi.c
@@ -506,7 +506,7 @@ static struct sonypi_device {
506 while (--n && (command)) \ 506 while (--n && (command)) \
507 udelay(1); \ 507 udelay(1); \
508 if (!n && (verbose || !quiet)) \ 508 if (!n && (verbose || !quiet)) \
509 printk(KERN_WARNING "sonypi command failed at %s : %s (line %d)\n", __FILE__, __FUNCTION__, __LINE__); \ 509 printk(KERN_WARNING "sonypi command failed at %s : %s (line %d)\n", __FILE__, __func__, __LINE__); \
510} 510}
511 511
512#ifdef CONFIG_ACPI 512#ifdef CONFIG_ACPI
diff --git a/drivers/char/specialix.c b/drivers/char/specialix.c
index 4b5b5b78acb4..2ee4d9893757 100644
--- a/drivers/char/specialix.c
+++ b/drivers/char/specialix.c
@@ -131,8 +131,8 @@ static int sx_rxfifo = SPECIALIX_RXFIFO;
131#define SX_DEBUG_FIFO 0x0800 131#define SX_DEBUG_FIFO 0x0800
132 132
133 133
134#define func_enter() dprintk (SX_DEBUG_FLOW, "io8: enter %s\n",__FUNCTION__) 134#define func_enter() dprintk (SX_DEBUG_FLOW, "io8: enter %s\n",__func__)
135#define func_exit() dprintk (SX_DEBUG_FLOW, "io8: exit %s\n", __FUNCTION__) 135#define func_exit() dprintk (SX_DEBUG_FLOW, "io8: exit %s\n", __func__)
136 136
137#define jiffies_from_ms(a) ((((a) * HZ)/1000)+1) 137#define jiffies_from_ms(a) ((((a) * HZ)/1000)+1)
138 138
@@ -874,7 +874,7 @@ static irqreturn_t sx_interrupt(int dummy, void *dev_id)
874 874
875 spin_lock_irqsave(&bp->lock, flags); 875 spin_lock_irqsave(&bp->lock, flags);
876 876
877 dprintk (SX_DEBUG_FLOW, "enter %s port %d room: %ld\n", __FUNCTION__, port_No(sx_get_port(bp, "INT")), SERIAL_XMIT_SIZE - sx_get_port(bp, "ITN")->xmit_cnt - 1); 877 dprintk (SX_DEBUG_FLOW, "enter %s port %d room: %ld\n", __func__, port_No(sx_get_port(bp, "INT")), SERIAL_XMIT_SIZE - sx_get_port(bp, "ITN")->xmit_cnt - 1);
878 if (!(bp->flags & SX_BOARD_ACTIVE)) { 878 if (!(bp->flags & SX_BOARD_ACTIVE)) {
879 dprintk (SX_DEBUG_IRQ, "sx: False interrupt. irq %d.\n", bp->irq); 879 dprintk (SX_DEBUG_IRQ, "sx: False interrupt. irq %d.\n", bp->irq);
880 spin_unlock_irqrestore(&bp->lock, flags); 880 spin_unlock_irqrestore(&bp->lock, flags);
@@ -1504,6 +1504,27 @@ static int sx_open(struct tty_struct * tty, struct file * filp)
1504 return 0; 1504 return 0;
1505} 1505}
1506 1506
1507static void sx_flush_buffer(struct tty_struct *tty)
1508{
1509 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1510 unsigned long flags;
1511 struct specialix_board * bp;
1512
1513 func_enter();
1514
1515 if (sx_paranoia_check(port, tty->name, "sx_flush_buffer")) {
1516 func_exit();
1517 return;
1518 }
1519
1520 bp = port_Board(port);
1521 spin_lock_irqsave(&port->lock, flags);
1522 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1523 spin_unlock_irqrestore(&port->lock, flags);
1524 tty_wakeup(tty);
1525
1526 func_exit();
1527}
1507 1528
1508static void sx_close(struct tty_struct * tty, struct file * filp) 1529static void sx_close(struct tty_struct * tty, struct file * filp)
1509{ 1530{
@@ -1597,8 +1618,7 @@ static void sx_close(struct tty_struct * tty, struct file * filp)
1597 } 1618 }
1598 1619
1599 sx_shutdown_port(bp, port); 1620 sx_shutdown_port(bp, port);
1600 if (tty->driver->flush_buffer) 1621 sx_flush_buffer(tty);
1601 tty->driver->flush_buffer(tty);
1602 tty_ldisc_flush(tty); 1622 tty_ldisc_flush(tty);
1603 spin_lock_irqsave(&port->lock, flags); 1623 spin_lock_irqsave(&port->lock, flags);
1604 tty->closing = 0; 1624 tty->closing = 0;
@@ -1670,7 +1690,7 @@ static int sx_write(struct tty_struct * tty,
1670} 1690}
1671 1691
1672 1692
1673static void sx_put_char(struct tty_struct * tty, unsigned char ch) 1693static int sx_put_char(struct tty_struct * tty, unsigned char ch)
1674{ 1694{
1675 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1695 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1676 unsigned long flags; 1696 unsigned long flags;
@@ -1680,12 +1700,12 @@ static void sx_put_char(struct tty_struct * tty, unsigned char ch)
1680 1700
1681 if (sx_paranoia_check(port, tty->name, "sx_put_char")) { 1701 if (sx_paranoia_check(port, tty->name, "sx_put_char")) {
1682 func_exit(); 1702 func_exit();
1683 return; 1703 return 0;
1684 } 1704 }
1685 dprintk (SX_DEBUG_TX, "check tty: %p %p\n", tty, port->xmit_buf); 1705 dprintk (SX_DEBUG_TX, "check tty: %p %p\n", tty, port->xmit_buf);
1686 if (!port->xmit_buf) { 1706 if (!port->xmit_buf) {
1687 func_exit(); 1707 func_exit();
1688 return; 1708 return 0;
1689 } 1709 }
1690 bp = port_Board(port); 1710 bp = port_Board(port);
1691 spin_lock_irqsave(&port->lock, flags); 1711 spin_lock_irqsave(&port->lock, flags);
@@ -1695,7 +1715,7 @@ static void sx_put_char(struct tty_struct * tty, unsigned char ch)
1695 spin_unlock_irqrestore(&port->lock, flags); 1715 spin_unlock_irqrestore(&port->lock, flags);
1696 dprintk (SX_DEBUG_TX, "Exit size\n"); 1716 dprintk (SX_DEBUG_TX, "Exit size\n");
1697 func_exit(); 1717 func_exit();
1698 return; 1718 return 0;
1699 } 1719 }
1700 dprintk (SX_DEBUG_TX, "Handle xmit: %p %p\n", port, port->xmit_buf); 1720 dprintk (SX_DEBUG_TX, "Handle xmit: %p %p\n", port, port->xmit_buf);
1701 port->xmit_buf[port->xmit_head++] = ch; 1721 port->xmit_buf[port->xmit_head++] = ch;
@@ -1704,6 +1724,7 @@ static void sx_put_char(struct tty_struct * tty, unsigned char ch)
1704 spin_unlock_irqrestore(&port->lock, flags); 1724 spin_unlock_irqrestore(&port->lock, flags);
1705 1725
1706 func_exit(); 1726 func_exit();
1727 return 1;
1707} 1728}
1708 1729
1709 1730
@@ -1770,28 +1791,6 @@ static int sx_chars_in_buffer(struct tty_struct *tty)
1770} 1791}
1771 1792
1772 1793
1773static void sx_flush_buffer(struct tty_struct *tty)
1774{
1775 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
1776 unsigned long flags;
1777 struct specialix_board * bp;
1778
1779 func_enter();
1780
1781 if (sx_paranoia_check(port, tty->name, "sx_flush_buffer")) {
1782 func_exit();
1783 return;
1784 }
1785
1786 bp = port_Board(port);
1787 spin_lock_irqsave(&port->lock, flags);
1788 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1789 spin_unlock_irqrestore(&port->lock, flags);
1790 tty_wakeup(tty);
1791
1792 func_exit();
1793}
1794
1795 1794
1796static int sx_tiocmget(struct tty_struct *tty, struct file *file) 1795static int sx_tiocmget(struct tty_struct *tty, struct file *file)
1797{ 1796{
@@ -1803,7 +1802,7 @@ static int sx_tiocmget(struct tty_struct *tty, struct file *file)
1803 1802
1804 func_enter(); 1803 func_enter();
1805 1804
1806 if (sx_paranoia_check(port, tty->name, __FUNCTION__)) { 1805 if (sx_paranoia_check(port, tty->name, __func__)) {
1807 func_exit(); 1806 func_exit();
1808 return -ENODEV; 1807 return -ENODEV;
1809 } 1808 }
@@ -1845,7 +1844,7 @@ static int sx_tiocmset(struct tty_struct *tty, struct file *file,
1845 1844
1846 func_enter(); 1845 func_enter();
1847 1846
1848 if (sx_paranoia_check(port, tty->name, __FUNCTION__)) { 1847 if (sx_paranoia_check(port, tty->name, __func__)) {
1849 func_exit(); 1848 func_exit();
1850 return -ENODEV; 1849 return -ENODEV;
1851 } 1850 }
@@ -1922,29 +1921,13 @@ static inline int sx_set_serial_info(struct specialix_port * port,
1922 int change_speed; 1921 int change_speed;
1923 1922
1924 func_enter(); 1923 func_enter();
1925 /* 1924
1926 if (!access_ok(VERIFY_READ, (void *) newinfo, sizeof(tmp))) {
1927 func_exit();
1928 return -EFAULT;
1929 }
1930 */
1931 if (copy_from_user(&tmp, newinfo, sizeof(tmp))) { 1925 if (copy_from_user(&tmp, newinfo, sizeof(tmp))) {
1932 func_enter(); 1926 func_enter();
1933 return -EFAULT; 1927 return -EFAULT;
1934 } 1928 }
1935 1929
1936#if 0 1930 lock_kernel();
1937 if ((tmp.irq != bp->irq) ||
1938 (tmp.port != bp->base) ||
1939 (tmp.type != PORT_CIRRUS) ||
1940 (tmp.baud_base != (SX_OSCFREQ + CD186x_TPC/2) / CD186x_TPC) ||
1941 (tmp.custom_divisor != 0) ||
1942 (tmp.xmit_fifo_size != CD186x_NFIFO) ||
1943 (tmp.flags & ~SPECIALIX_LEGAL_FLAGS)) {
1944 func_exit();
1945 return -EINVAL;
1946 }
1947#endif
1948 1931
1949 change_speed = ((port->flags & ASYNC_SPD_MASK) != 1932 change_speed = ((port->flags & ASYNC_SPD_MASK) !=
1950 (tmp.flags & ASYNC_SPD_MASK)); 1933 (tmp.flags & ASYNC_SPD_MASK));
@@ -1956,6 +1939,7 @@ static inline int sx_set_serial_info(struct specialix_port * port,
1956 ((tmp.flags & ~ASYNC_USR_MASK) != 1939 ((tmp.flags & ~ASYNC_USR_MASK) !=
1957 (port->flags & ~ASYNC_USR_MASK))) { 1940 (port->flags & ~ASYNC_USR_MASK))) {
1958 func_exit(); 1941 func_exit();
1942 unlock_kernel();
1959 return -EPERM; 1943 return -EPERM;
1960 } 1944 }
1961 port->flags = ((port->flags & ~ASYNC_USR_MASK) | 1945 port->flags = ((port->flags & ~ASYNC_USR_MASK) |
@@ -1972,6 +1956,7 @@ static inline int sx_set_serial_info(struct specialix_port * port,
1972 sx_change_speed(bp, port); 1956 sx_change_speed(bp, port);
1973 } 1957 }
1974 func_exit(); 1958 func_exit();
1959 unlock_kernel();
1975 return 0; 1960 return 0;
1976} 1961}
1977 1962
@@ -1984,12 +1969,8 @@ static inline int sx_get_serial_info(struct specialix_port * port,
1984 1969
1985 func_enter(); 1970 func_enter();
1986 1971
1987 /*
1988 if (!access_ok(VERIFY_WRITE, (void *) retinfo, sizeof(tmp)))
1989 return -EFAULT;
1990 */
1991
1992 memset(&tmp, 0, sizeof(tmp)); 1972 memset(&tmp, 0, sizeof(tmp));
1973 lock_kernel();
1993 tmp.type = PORT_CIRRUS; 1974 tmp.type = PORT_CIRRUS;
1994 tmp.line = port - sx_port; 1975 tmp.line = port - sx_port;
1995 tmp.port = bp->base; 1976 tmp.port = bp->base;
@@ -2000,6 +1981,7 @@ static inline int sx_get_serial_info(struct specialix_port * port,
2000 tmp.closing_wait = port->closing_wait * HZ/100; 1981 tmp.closing_wait = port->closing_wait * HZ/100;
2001 tmp.custom_divisor = port->custom_divisor; 1982 tmp.custom_divisor = port->custom_divisor;
2002 tmp.xmit_fifo_size = CD186x_NFIFO; 1983 tmp.xmit_fifo_size = CD186x_NFIFO;
1984 unlock_kernel();
2003 if (copy_to_user(retinfo, &tmp, sizeof(tmp))) { 1985 if (copy_to_user(retinfo, &tmp, sizeof(tmp))) {
2004 func_exit(); 1986 func_exit();
2005 return -EFAULT; 1987 return -EFAULT;
@@ -2045,23 +2027,6 @@ static int sx_ioctl(struct tty_struct * tty, struct file * filp,
2045 sx_send_break(port, arg ? arg*(HZ/10) : HZ/4); 2027 sx_send_break(port, arg ? arg*(HZ/10) : HZ/4);
2046 func_exit(); 2028 func_exit();
2047 return 0; 2029 return 0;
2048 case TIOCGSOFTCAR:
2049 if (put_user(C_CLOCAL(tty)?1:0, (unsigned long __user *)argp)) {
2050 func_exit();
2051 return -EFAULT;
2052 }
2053 func_exit();
2054 return 0;
2055 case TIOCSSOFTCAR:
2056 if (get_user(arg, (unsigned long __user *) argp)) {
2057 func_exit();
2058 return -EFAULT;
2059 }
2060 tty->termios->c_cflag =
2061 ((tty->termios->c_cflag & ~CLOCAL) |
2062 (arg ? CLOCAL : 0));
2063 func_exit();
2064 return 0;
2065 case TIOCGSERIAL: 2030 case TIOCGSERIAL:
2066 func_exit(); 2031 func_exit();
2067 return sx_get_serial_info(port, argp); 2032 return sx_get_serial_info(port, argp);
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index 874aaa08e956..d17be10c5d21 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -875,6 +875,7 @@ static void stl_waituntilsent(struct tty_struct *tty, int timeout)
875 timeout = HZ; 875 timeout = HZ;
876 tend = jiffies + timeout; 876 tend = jiffies + timeout;
877 877
878 lock_kernel();
878 while (stl_datastate(portp)) { 879 while (stl_datastate(portp)) {
879 if (signal_pending(current)) 880 if (signal_pending(current))
880 break; 881 break;
@@ -882,6 +883,7 @@ static void stl_waituntilsent(struct tty_struct *tty, int timeout)
882 if (time_after_eq(jiffies, tend)) 883 if (time_after_eq(jiffies, tend))
883 break; 884 break;
884 } 885 }
886 unlock_kernel();
885} 887}
886 888
887/*****************************************************************************/ 889/*****************************************************************************/
@@ -1273,18 +1275,9 @@ static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd
1273 1275
1274 rc = 0; 1276 rc = 0;
1275 1277
1278 lock_kernel();
1279
1276 switch (cmd) { 1280 switch (cmd) {
1277 case TIOCGSOFTCAR:
1278 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1279 (unsigned __user *) argp);
1280 break;
1281 case TIOCSSOFTCAR:
1282 if (get_user(ival, (unsigned int __user *) arg))
1283 return -EFAULT;
1284 tty->termios->c_cflag =
1285 (tty->termios->c_cflag & ~CLOCAL) |
1286 (ival ? CLOCAL : 0);
1287 break;
1288 case TIOCGSERIAL: 1281 case TIOCGSERIAL:
1289 rc = stl_getserial(portp, argp); 1282 rc = stl_getserial(portp, argp);
1290 break; 1283 break;
@@ -1308,7 +1301,7 @@ static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd
1308 rc = -ENOIOCTLCMD; 1301 rc = -ENOIOCTLCMD;
1309 break; 1302 break;
1310 } 1303 }
1311 1304 unlock_kernel();
1312 return rc; 1305 return rc;
1313} 1306}
1314 1307
diff --git a/drivers/char/sx.c b/drivers/char/sx.c
index a6e1c9ba1217..f39f6fd89350 100644
--- a/drivers/char/sx.c
+++ b/drivers/char/sx.c
@@ -384,11 +384,11 @@ static struct real_driver sx_real_driver = {
384#define sx_dprintk(f, str...) /* nothing */ 384#define sx_dprintk(f, str...) /* nothing */
385#endif 385#endif
386 386
387#define func_enter() sx_dprintk(SX_DEBUG_FLOW, "sx: enter %s\n",__FUNCTION__) 387#define func_enter() sx_dprintk(SX_DEBUG_FLOW, "sx: enter %s\n",__func__)
388#define func_exit() sx_dprintk(SX_DEBUG_FLOW, "sx: exit %s\n",__FUNCTION__) 388#define func_exit() sx_dprintk(SX_DEBUG_FLOW, "sx: exit %s\n",__func__)
389 389
390#define func_enter2() sx_dprintk(SX_DEBUG_FLOW, "sx: enter %s (port %d)\n", \ 390#define func_enter2() sx_dprintk(SX_DEBUG_FLOW, "sx: enter %s (port %d)\n", \
391 __FUNCTION__, port->line) 391 __func__, port->line)
392 392
393/* 393/*
394 * Firmware loader driver specific routines 394 * Firmware loader driver specific routines
@@ -1574,7 +1574,7 @@ static void sx_close(void *ptr)
1574 sx_dprintk(SX_DEBUG_CLOSE, "WARNING port count:%d\n", 1574 sx_dprintk(SX_DEBUG_CLOSE, "WARNING port count:%d\n",
1575 port->gs.count); 1575 port->gs.count);
1576 /*printk("%s SETTING port count to zero: %p count: %d\n", 1576 /*printk("%s SETTING port count to zero: %p count: %d\n",
1577 __FUNCTION__, port, port->gs.count); 1577 __func__, port, port->gs.count);
1578 port->gs.count = 0;*/ 1578 port->gs.count = 0;*/
1579 } 1579 }
1580 1580
@@ -1844,6 +1844,7 @@ static void sx_break(struct tty_struct *tty, int flag)
1844 int rv; 1844 int rv;
1845 1845
1846 func_enter(); 1846 func_enter();
1847 lock_kernel();
1847 1848
1848 if (flag) 1849 if (flag)
1849 rv = sx_send_command(port, HS_START, -1, HS_IDLE_BREAK); 1850 rv = sx_send_command(port, HS_START, -1, HS_IDLE_BREAK);
@@ -1852,7 +1853,7 @@ static void sx_break(struct tty_struct *tty, int flag)
1852 if (rv != 1) 1853 if (rv != 1)
1853 printk(KERN_ERR "sx: couldn't send break (%x).\n", 1854 printk(KERN_ERR "sx: couldn't send break (%x).\n",
1854 read_sx_byte(port->board, CHAN_OFFSET(port, hi_hstat))); 1855 read_sx_byte(port->board, CHAN_OFFSET(port, hi_hstat)));
1855 1856 unlock_kernel();
1856 func_exit(); 1857 func_exit();
1857} 1858}
1858 1859
@@ -1888,23 +1889,12 @@ static int sx_ioctl(struct tty_struct *tty, struct file *filp,
1888 int rc; 1889 int rc;
1889 struct sx_port *port = tty->driver_data; 1890 struct sx_port *port = tty->driver_data;
1890 void __user *argp = (void __user *)arg; 1891 void __user *argp = (void __user *)arg;
1891 int ival;
1892 1892
1893 /* func_enter2(); */ 1893 /* func_enter2(); */
1894 1894
1895 rc = 0; 1895 rc = 0;
1896 lock_kernel();
1896 switch (cmd) { 1897 switch (cmd) {
1897 case TIOCGSOFTCAR:
1898 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1899 (unsigned __user *)argp);
1900 break;
1901 case TIOCSSOFTCAR:
1902 if ((rc = get_user(ival, (unsigned __user *)argp)) == 0) {
1903 tty->termios->c_cflag =
1904 (tty->termios->c_cflag & ~CLOCAL) |
1905 (ival ? CLOCAL : 0);
1906 }
1907 break;
1908 case TIOCGSERIAL: 1898 case TIOCGSERIAL:
1909 rc = gs_getserial(&port->gs, argp); 1899 rc = gs_getserial(&port->gs, argp);
1910 break; 1900 break;
@@ -1915,6 +1905,7 @@ static int sx_ioctl(struct tty_struct *tty, struct file *filp,
1915 rc = -ENOIOCTLCMD; 1905 rc = -ENOIOCTLCMD;
1916 break; 1906 break;
1917 } 1907 }
1908 unlock_kernel();
1918 1909
1919 /* func_exit(); */ 1910 /* func_exit(); */
1920 return rc; 1911 return rc;
@@ -2549,7 +2540,7 @@ static int __devinit sx_eisa_probe(struct device *dev)
2549 goto err_flag; 2540 goto err_flag;
2550 } 2541 }
2551 board->base2 = 2542 board->base2 =
2552 board->base = ioremap(board->hw_base, SI2_EISA_WINDOW_LEN); 2543 board->base = ioremap_nocache(board->hw_base, SI2_EISA_WINDOW_LEN);
2553 if (!board->base) { 2544 if (!board->base) {
2554 dev_err(dev, "can't remap memory\n"); 2545 dev_err(dev, "can't remap memory\n");
2555 goto err_reg; 2546 goto err_reg;
@@ -2626,7 +2617,7 @@ static void __devinit fix_sx_pci(struct pci_dev *pdev, struct sx_board *board)
2626 2617
2627 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase); 2618 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase);
2628 hwbase &= PCI_BASE_ADDRESS_MEM_MASK; 2619 hwbase &= PCI_BASE_ADDRESS_MEM_MASK;
2629 rebase = ioremap(hwbase, 0x80); 2620 rebase = ioremap_nocache(hwbase, 0x80);
2630 t = readl(rebase + CNTRL_REG_OFFSET); 2621 t = readl(rebase + CNTRL_REG_OFFSET);
2631 if (t != CNTRL_REG_GOODVALUE) { 2622 if (t != CNTRL_REG_GOODVALUE) {
2632 printk(KERN_DEBUG "sx: performing cntrl reg fix: %08x -> " 2623 printk(KERN_DEBUG "sx: performing cntrl reg fix: %08x -> "
@@ -2770,7 +2761,7 @@ static int __init sx_init(void)
2770 if (!request_region(board->hw_base, board->hw_len, "sx")) 2761 if (!request_region(board->hw_base, board->hw_len, "sx"))
2771 continue; 2762 continue;
2772 board->base2 = 2763 board->base2 =
2773 board->base = ioremap(board->hw_base, board->hw_len); 2764 board->base = ioremap_nocache(board->hw_base, board->hw_len);
2774 if (!board->base) 2765 if (!board->base)
2775 goto err_sx_reg; 2766 goto err_sx_reg;
2776 board->flags &= ~SX_BOARD_TYPE; 2767 board->flags &= ~SX_BOARD_TYPE;
@@ -2794,7 +2785,7 @@ err_sx_reg:
2794 if (!request_region(board->hw_base, board->hw_len, "sx")) 2785 if (!request_region(board->hw_base, board->hw_len, "sx"))
2795 continue; 2786 continue;
2796 board->base2 = 2787 board->base2 =
2797 board->base = ioremap(board->hw_base, board->hw_len); 2788 board->base = ioremap_nocache(board->hw_base, board->hw_len);
2798 if (!board->base) 2789 if (!board->base)
2799 goto err_si_reg; 2790 goto err_si_reg;
2800 board->flags &= ~SX_BOARD_TYPE; 2791 board->flags &= ~SX_BOARD_TYPE;
@@ -2817,7 +2808,7 @@ err_si_reg:
2817 if (!request_region(board->hw_base, board->hw_len, "sx")) 2808 if (!request_region(board->hw_base, board->hw_len, "sx"))
2818 continue; 2809 continue;
2819 board->base2 = 2810 board->base2 =
2820 board->base = ioremap(board->hw_base, board->hw_len); 2811 board->base = ioremap_nocache(board->hw_base, board->hw_len);
2821 if (!board->base) 2812 if (!board->base)
2822 goto err_si1_reg; 2813 goto err_si1_reg;
2823 board->flags &= ~SX_BOARD_TYPE; 2814 board->flags &= ~SX_BOARD_TYPE;
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c
index fadab1d9510f..ac5080df2565 100644
--- a/drivers/char/synclink.c
+++ b/drivers/char/synclink.c
@@ -2026,34 +2026,35 @@ static void mgsl_change_params(struct mgsl_struct *info)
2026 * 2026 *
2027 * Return Value: None 2027 * Return Value: None
2028 */ 2028 */
2029static void mgsl_put_char(struct tty_struct *tty, unsigned char ch) 2029static int mgsl_put_char(struct tty_struct *tty, unsigned char ch)
2030{ 2030{
2031 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; 2031 struct mgsl_struct *info = tty->driver_data;
2032 unsigned long flags; 2032 unsigned long flags;
2033 int ret = 0;
2033 2034
2034 if ( debug_level >= DEBUG_LEVEL_INFO ) { 2035 if (debug_level >= DEBUG_LEVEL_INFO) {
2035 printk( "%s(%d):mgsl_put_char(%d) on %s\n", 2036 printk(KERN_DEBUG "%s(%d):mgsl_put_char(%d) on %s\n",
2036 __FILE__,__LINE__,ch,info->device_name); 2037 __FILE__, __LINE__, ch, info->device_name);
2037 } 2038 }
2038 2039
2039 if (mgsl_paranoia_check(info, tty->name, "mgsl_put_char")) 2040 if (mgsl_paranoia_check(info, tty->name, "mgsl_put_char"))
2040 return; 2041 return 0;
2041 2042
2042 if (!tty || !info->xmit_buf) 2043 if (!tty || !info->xmit_buf)
2043 return; 2044 return 0;
2044 2045
2045 spin_lock_irqsave(&info->irq_spinlock,flags); 2046 spin_lock_irqsave(&info->irq_spinlock, flags);
2046
2047 if ( (info->params.mode == MGSL_MODE_ASYNC ) || !info->tx_active ) {
2048 2047
2048 if ((info->params.mode == MGSL_MODE_ASYNC ) || !info->tx_active) {
2049 if (info->xmit_cnt < SERIAL_XMIT_SIZE - 1) { 2049 if (info->xmit_cnt < SERIAL_XMIT_SIZE - 1) {
2050 info->xmit_buf[info->xmit_head++] = ch; 2050 info->xmit_buf[info->xmit_head++] = ch;
2051 info->xmit_head &= SERIAL_XMIT_SIZE-1; 2051 info->xmit_head &= SERIAL_XMIT_SIZE-1;
2052 info->xmit_cnt++; 2052 info->xmit_cnt++;
2053 ret = 1;
2053 } 2054 }
2054 } 2055 }
2055 2056 spin_unlock_irqrestore(&info->irq_spinlock, flags);
2056 spin_unlock_irqrestore(&info->irq_spinlock,flags); 2057 return ret;
2057 2058
2058} /* end of mgsl_put_char() */ 2059} /* end of mgsl_put_char() */
2059 2060
@@ -2942,6 +2943,7 @@ static int mgsl_ioctl(struct tty_struct *tty, struct file * file,
2942 unsigned int cmd, unsigned long arg) 2943 unsigned int cmd, unsigned long arg)
2943{ 2944{
2944 struct mgsl_struct * info = (struct mgsl_struct *)tty->driver_data; 2945 struct mgsl_struct * info = (struct mgsl_struct *)tty->driver_data;
2946 int ret;
2945 2947
2946 if (debug_level >= DEBUG_LEVEL_INFO) 2948 if (debug_level >= DEBUG_LEVEL_INFO)
2947 printk("%s(%d):mgsl_ioctl %s cmd=%08X\n", __FILE__,__LINE__, 2949 printk("%s(%d):mgsl_ioctl %s cmd=%08X\n", __FILE__,__LINE__,
@@ -2956,7 +2958,10 @@ static int mgsl_ioctl(struct tty_struct *tty, struct file * file,
2956 return -EIO; 2958 return -EIO;
2957 } 2959 }
2958 2960
2959 return mgsl_ioctl_common(info, cmd, arg); 2961 lock_kernel();
2962 ret = mgsl_ioctl_common(info, cmd, arg);
2963 unlock_kernel();
2964 return ret;
2960} 2965}
2961 2966
2962static int mgsl_ioctl_common(struct mgsl_struct *info, unsigned int cmd, unsigned long arg) 2967static int mgsl_ioctl_common(struct mgsl_struct *info, unsigned int cmd, unsigned long arg)
@@ -3153,8 +3158,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
3153 if (info->flags & ASYNC_INITIALIZED) 3158 if (info->flags & ASYNC_INITIALIZED)
3154 mgsl_wait_until_sent(tty, info->timeout); 3159 mgsl_wait_until_sent(tty, info->timeout);
3155 3160
3156 if (tty->driver->flush_buffer) 3161 mgsl_flush_buffer(tty);
3157 tty->driver->flush_buffer(tty);
3158 3162
3159 tty_ldisc_flush(tty); 3163 tty_ldisc_flush(tty);
3160 3164
@@ -3217,7 +3221,8 @@ static void mgsl_wait_until_sent(struct tty_struct *tty, int timeout)
3217 * interval should also be less than the timeout. 3221 * interval should also be less than the timeout.
3218 * Note: use tight timings here to satisfy the NIST-PCTS. 3222 * Note: use tight timings here to satisfy the NIST-PCTS.
3219 */ 3223 */
3220 3224
3225 lock_kernel();
3221 if ( info->params.data_rate ) { 3226 if ( info->params.data_rate ) {
3222 char_time = info->timeout/(32 * 5); 3227 char_time = info->timeout/(32 * 5);
3223 if (!char_time) 3228 if (!char_time)
@@ -3247,6 +3252,7 @@ static void mgsl_wait_until_sent(struct tty_struct *tty, int timeout)
3247 break; 3252 break;
3248 } 3253 }
3249 } 3254 }
3255 unlock_kernel();
3250 3256
3251exit: 3257exit:
3252 if (debug_level >= DEBUG_LEVEL_INFO) 3258 if (debug_level >= DEBUG_LEVEL_INFO)
@@ -4144,7 +4150,8 @@ static int mgsl_claim_resources(struct mgsl_struct *info)
4144 } 4150 }
4145 info->lcr_mem_requested = true; 4151 info->lcr_mem_requested = true;
4146 4152
4147 info->memory_base = ioremap(info->phys_memory_base,0x40000); 4153 info->memory_base = ioremap_nocache(info->phys_memory_base,
4154 0x40000);
4148 if (!info->memory_base) { 4155 if (!info->memory_base) {
4149 printk( "%s(%d):Cant map shared memory on device %s MemAddr=%08X\n", 4156 printk( "%s(%d):Cant map shared memory on device %s MemAddr=%08X\n",
4150 __FILE__,__LINE__,info->device_name, info->phys_memory_base ); 4157 __FILE__,__LINE__,info->device_name, info->phys_memory_base );
@@ -4157,12 +4164,14 @@ static int mgsl_claim_resources(struct mgsl_struct *info)
4157 goto errout; 4164 goto errout;
4158 } 4165 }
4159 4166
4160 info->lcr_base = ioremap(info->phys_lcr_base,PAGE_SIZE) + info->lcr_offset; 4167 info->lcr_base = ioremap_nocache(info->phys_lcr_base,
4168 PAGE_SIZE);
4161 if (!info->lcr_base) { 4169 if (!info->lcr_base) {
4162 printk( "%s(%d):Cant map LCR memory on device %s MemAddr=%08X\n", 4170 printk( "%s(%d):Cant map LCR memory on device %s MemAddr=%08X\n",
4163 __FILE__,__LINE__,info->device_name, info->phys_lcr_base ); 4171 __FILE__,__LINE__,info->device_name, info->phys_lcr_base );
4164 goto errout; 4172 goto errout;
4165 } 4173 }
4174 info->lcr_base += info->lcr_offset;
4166 4175
4167 } else { 4176 } else {
4168 /* claim DMA channel */ 4177 /* claim DMA channel */
diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c
index f3d8d72e5ea4..2001b0e52dc6 100644
--- a/drivers/char/synclink_gt.c
+++ b/drivers/char/synclink_gt.c
@@ -151,7 +151,7 @@ static void hangup(struct tty_struct *tty);
151static void set_termios(struct tty_struct *tty, struct ktermios *old_termios); 151static void set_termios(struct tty_struct *tty, struct ktermios *old_termios);
152 152
153static int write(struct tty_struct *tty, const unsigned char *buf, int count); 153static int write(struct tty_struct *tty, const unsigned char *buf, int count);
154static void put_char(struct tty_struct *tty, unsigned char ch); 154static int put_char(struct tty_struct *tty, unsigned char ch);
155static void send_xchar(struct tty_struct *tty, char ch); 155static void send_xchar(struct tty_struct *tty, char ch);
156static void wait_until_sent(struct tty_struct *tty, int timeout); 156static void wait_until_sent(struct tty_struct *tty, int timeout);
157static int write_room(struct tty_struct *tty); 157static int write_room(struct tty_struct *tty);
@@ -771,8 +771,7 @@ static void close(struct tty_struct *tty, struct file *filp)
771 771
772 if (info->flags & ASYNC_INITIALIZED) 772 if (info->flags & ASYNC_INITIALIZED)
773 wait_until_sent(tty, info->timeout); 773 wait_until_sent(tty, info->timeout);
774 if (tty->driver->flush_buffer) 774 flush_buffer(tty);
775 tty->driver->flush_buffer(tty);
776 tty_ldisc_flush(tty); 775 tty_ldisc_flush(tty);
777 776
778 shutdown(info); 777 shutdown(info);
@@ -913,20 +912,24 @@ cleanup:
913 return ret; 912 return ret;
914} 913}
915 914
916static void put_char(struct tty_struct *tty, unsigned char ch) 915static int put_char(struct tty_struct *tty, unsigned char ch)
917{ 916{
918 struct slgt_info *info = tty->driver_data; 917 struct slgt_info *info = tty->driver_data;
919 unsigned long flags; 918 unsigned long flags;
919 int ret;
920 920
921 if (sanity_check(info, tty->name, "put_char")) 921 if (sanity_check(info, tty->name, "put_char"))
922 return; 922 return 0;
923 DBGINFO(("%s put_char(%d)\n", info->device_name, ch)); 923 DBGINFO(("%s put_char(%d)\n", info->device_name, ch));
924 if (!info->tx_buf) 924 if (!info->tx_buf)
925 return; 925 return 0;
926 spin_lock_irqsave(&info->lock,flags); 926 spin_lock_irqsave(&info->lock,flags);
927 if (!info->tx_active && (info->tx_count < info->max_frame_size)) 927 if (!info->tx_active && (info->tx_count < info->max_frame_size)) {
928 info->tx_buf[info->tx_count++] = ch; 928 info->tx_buf[info->tx_count++] = ch;
929 ret = 1;
930 }
929 spin_unlock_irqrestore(&info->lock,flags); 931 spin_unlock_irqrestore(&info->lock,flags);
932 return ret;
930} 933}
931 934
932static void send_xchar(struct tty_struct *tty, char ch) 935static void send_xchar(struct tty_struct *tty, char ch)
@@ -967,6 +970,8 @@ static void wait_until_sent(struct tty_struct *tty, int timeout)
967 * Note: use tight timings here to satisfy the NIST-PCTS. 970 * Note: use tight timings here to satisfy the NIST-PCTS.
968 */ 971 */
969 972
973 lock_kernel();
974
970 if (info->params.data_rate) { 975 if (info->params.data_rate) {
971 char_time = info->timeout/(32 * 5); 976 char_time = info->timeout/(32 * 5);
972 if (!char_time) 977 if (!char_time)
@@ -984,6 +989,7 @@ static void wait_until_sent(struct tty_struct *tty, int timeout)
984 if (timeout && time_after(jiffies, orig_jiffies + timeout)) 989 if (timeout && time_after(jiffies, orig_jiffies + timeout))
985 break; 990 break;
986 } 991 }
992 unlock_kernel();
987 993
988exit: 994exit:
989 DBGINFO(("%s wait_until_sent exit\n", info->device_name)); 995 DBGINFO(("%s wait_until_sent exit\n", info->device_name));
@@ -1097,6 +1103,7 @@ static int ioctl(struct tty_struct *tty, struct file *file,
1097 struct serial_icounter_struct __user *p_cuser; /* user space */ 1103 struct serial_icounter_struct __user *p_cuser; /* user space */
1098 unsigned long flags; 1104 unsigned long flags;
1099 void __user *argp = (void __user *)arg; 1105 void __user *argp = (void __user *)arg;
1106 int ret;
1100 1107
1101 if (sanity_check(info, tty->name, "ioctl")) 1108 if (sanity_check(info, tty->name, "ioctl"))
1102 return -ENODEV; 1109 return -ENODEV;
@@ -1108,37 +1115,54 @@ static int ioctl(struct tty_struct *tty, struct file *file,
1108 return -EIO; 1115 return -EIO;
1109 } 1116 }
1110 1117
1118 lock_kernel();
1119
1111 switch (cmd) { 1120 switch (cmd) {
1112 case MGSL_IOCGPARAMS: 1121 case MGSL_IOCGPARAMS:
1113 return get_params(info, argp); 1122 ret = get_params(info, argp);
1123 break;
1114 case MGSL_IOCSPARAMS: 1124 case MGSL_IOCSPARAMS:
1115 return set_params(info, argp); 1125 ret = set_params(info, argp);
1126 break;
1116 case MGSL_IOCGTXIDLE: 1127 case MGSL_IOCGTXIDLE:
1117 return get_txidle(info, argp); 1128 ret = get_txidle(info, argp);
1129 break;
1118 case MGSL_IOCSTXIDLE: 1130 case MGSL_IOCSTXIDLE:
1119 return set_txidle(info, (int)arg); 1131 ret = set_txidle(info, (int)arg);
1132 break;
1120 case MGSL_IOCTXENABLE: 1133 case MGSL_IOCTXENABLE:
1121 return tx_enable(info, (int)arg); 1134 ret = tx_enable(info, (int)arg);
1135 break;
1122 case MGSL_IOCRXENABLE: 1136 case MGSL_IOCRXENABLE:
1123 return rx_enable(info, (int)arg); 1137 ret = rx_enable(info, (int)arg);
1138 break;
1124 case MGSL_IOCTXABORT: 1139 case MGSL_IOCTXABORT:
1125 return tx_abort(info); 1140 ret = tx_abort(info);
1141 break;
1126 case MGSL_IOCGSTATS: 1142 case MGSL_IOCGSTATS:
1127 return get_stats(info, argp); 1143 ret = get_stats(info, argp);
1144 break;
1128 case MGSL_IOCWAITEVENT: 1145 case MGSL_IOCWAITEVENT:
1129 return wait_mgsl_event(info, argp); 1146 ret = wait_mgsl_event(info, argp);
1147 break;
1130 case TIOCMIWAIT: 1148 case TIOCMIWAIT:
1131 return modem_input_wait(info,(int)arg); 1149 ret = modem_input_wait(info,(int)arg);
1150 break;
1132 case MGSL_IOCGIF: 1151 case MGSL_IOCGIF:
1133 return get_interface(info, argp); 1152 ret = get_interface(info, argp);
1153 break;
1134 case MGSL_IOCSIF: 1154 case MGSL_IOCSIF:
1135 return set_interface(info,(int)arg); 1155 ret = set_interface(info,(int)arg);
1156 break;
1136 case MGSL_IOCSGPIO: 1157 case MGSL_IOCSGPIO:
1137 return set_gpio(info, argp); 1158 ret = set_gpio(info, argp);
1159 break;
1138 case MGSL_IOCGGPIO: 1160 case MGSL_IOCGGPIO:
1139 return get_gpio(info, argp); 1161 ret = get_gpio(info, argp);
1162 break;
1140 case MGSL_IOCWAITGPIO: 1163 case MGSL_IOCWAITGPIO:
1141 return wait_gpio(info, argp); 1164 ret = wait_gpio(info, argp);
1165 break;
1142 case TIOCGICOUNT: 1166 case TIOCGICOUNT:
1143 spin_lock_irqsave(&info->lock,flags); 1167 spin_lock_irqsave(&info->lock,flags);
1144 cnow = info->icount; 1168 cnow = info->icount;
@@ -1155,12 +1179,14 @@ static int ioctl(struct tty_struct *tty, struct file *file,
1155 put_user(cnow.parity, &p_cuser->parity) || 1179 put_user(cnow.parity, &p_cuser->parity) ||
1156 put_user(cnow.brk, &p_cuser->brk) || 1180 put_user(cnow.brk, &p_cuser->brk) ||
1157 put_user(cnow.buf_overrun, &p_cuser->buf_overrun)) 1181 put_user(cnow.buf_overrun, &p_cuser->buf_overrun))
1158 return -EFAULT; 1182 ret = -EFAULT;
1159 return 0; 1183 ret = 0;
1184 break;
1160 default: 1185 default:
1161 return -ENOIOCTLCMD; 1186 ret = -ENOIOCTLCMD;
1162 } 1187 }
1163 return 0; 1188 unlock_kernel();
1189 return ret;
1164} 1190}
1165 1191
1166/* 1192/*
@@ -3324,7 +3350,7 @@ static int claim_resources(struct slgt_info *info)
3324 else 3350 else
3325 info->reg_addr_requested = true; 3351 info->reg_addr_requested = true;
3326 3352
3327 info->reg_addr = ioremap(info->phys_reg_addr, SLGT_REG_SIZE); 3353 info->reg_addr = ioremap_nocache(info->phys_reg_addr, SLGT_REG_SIZE);
3328 if (!info->reg_addr) { 3354 if (!info->reg_addr) {
3329 DBGERR(("%s cant map device registers, addr=%08X\n", 3355 DBGERR(("%s cant map device registers, addr=%08X\n",
3330 info->device_name, info->phys_reg_addr)); 3356 info->device_name, info->phys_reg_addr));
diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c
index e98c3e6f8216..bec54866e0bb 100644
--- a/drivers/char/synclinkmp.c
+++ b/drivers/char/synclinkmp.c
@@ -519,7 +519,7 @@ static void hangup(struct tty_struct *tty);
519static void set_termios(struct tty_struct *tty, struct ktermios *old_termios); 519static void set_termios(struct tty_struct *tty, struct ktermios *old_termios);
520 520
521static int write(struct tty_struct *tty, const unsigned char *buf, int count); 521static int write(struct tty_struct *tty, const unsigned char *buf, int count);
522static void put_char(struct tty_struct *tty, unsigned char ch); 522static int put_char(struct tty_struct *tty, unsigned char ch);
523static void send_xchar(struct tty_struct *tty, char ch); 523static void send_xchar(struct tty_struct *tty, char ch);
524static void wait_until_sent(struct tty_struct *tty, int timeout); 524static void wait_until_sent(struct tty_struct *tty, int timeout);
525static int write_room(struct tty_struct *tty); 525static int write_room(struct tty_struct *tty);
@@ -862,8 +862,7 @@ static void close(struct tty_struct *tty, struct file *filp)
862 if (info->flags & ASYNC_INITIALIZED) 862 if (info->flags & ASYNC_INITIALIZED)
863 wait_until_sent(tty, info->timeout); 863 wait_until_sent(tty, info->timeout);
864 864
865 if (tty->driver->flush_buffer) 865 flush_buffer(tty);
866 tty->driver->flush_buffer(tty);
867 866
868 tty_ldisc_flush(tty); 867 tty_ldisc_flush(tty);
869 868
@@ -1046,10 +1045,11 @@ cleanup:
1046 1045
1047/* Add a character to the transmit buffer. 1046/* Add a character to the transmit buffer.
1048 */ 1047 */
1049static void put_char(struct tty_struct *tty, unsigned char ch) 1048static int put_char(struct tty_struct *tty, unsigned char ch)
1050{ 1049{
1051 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; 1050 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
1052 unsigned long flags; 1051 unsigned long flags;
1052 int ret = 0;
1053 1053
1054 if ( debug_level >= DEBUG_LEVEL_INFO ) { 1054 if ( debug_level >= DEBUG_LEVEL_INFO ) {
1055 printk( "%s(%d):%s put_char(%d)\n", 1055 printk( "%s(%d):%s put_char(%d)\n",
@@ -1057,10 +1057,10 @@ static void put_char(struct tty_struct *tty, unsigned char ch)
1057 } 1057 }
1058 1058
1059 if (sanity_check(info, tty->name, "put_char")) 1059 if (sanity_check(info, tty->name, "put_char"))
1060 return; 1060 return 0;
1061 1061
1062 if (!info->tx_buf) 1062 if (!info->tx_buf)
1063 return; 1063 return 0;
1064 1064
1065 spin_lock_irqsave(&info->lock,flags); 1065 spin_lock_irqsave(&info->lock,flags);
1066 1066
@@ -1072,10 +1072,12 @@ static void put_char(struct tty_struct *tty, unsigned char ch)
1072 if (info->tx_put >= info->max_frame_size) 1072 if (info->tx_put >= info->max_frame_size)
1073 info->tx_put -= info->max_frame_size; 1073 info->tx_put -= info->max_frame_size;
1074 info->tx_count++; 1074 info->tx_count++;
1075 ret = 1;
1075 } 1076 }
1076 } 1077 }
1077 1078
1078 spin_unlock_irqrestore(&info->lock,flags); 1079 spin_unlock_irqrestore(&info->lock,flags);
1080 return ret;
1079} 1081}
1080 1082
1081/* Send a high-priority XON/XOFF character 1083/* Send a high-priority XON/XOFF character
@@ -1119,6 +1121,8 @@ static void wait_until_sent(struct tty_struct *tty, int timeout)
1119 if (sanity_check(info, tty->name, "wait_until_sent")) 1121 if (sanity_check(info, tty->name, "wait_until_sent"))
1120 return; 1122 return;
1121 1123
1124 lock_kernel();
1125
1122 if (!(info->flags & ASYNC_INITIALIZED)) 1126 if (!(info->flags & ASYNC_INITIALIZED))
1123 goto exit; 1127 goto exit;
1124 1128
@@ -1161,6 +1165,7 @@ static void wait_until_sent(struct tty_struct *tty, int timeout)
1161 } 1165 }
1162 1166
1163exit: 1167exit:
1168 unlock_kernel();
1164 if (debug_level >= DEBUG_LEVEL_INFO) 1169 if (debug_level >= DEBUG_LEVEL_INFO)
1165 printk("%s(%d):%s wait_until_sent() exit\n", 1170 printk("%s(%d):%s wait_until_sent() exit\n",
1166 __FILE__,__LINE__, info->device_name ); 1171 __FILE__,__LINE__, info->device_name );
@@ -1176,6 +1181,7 @@ static int write_room(struct tty_struct *tty)
1176 if (sanity_check(info, tty->name, "write_room")) 1181 if (sanity_check(info, tty->name, "write_room"))
1177 return 0; 1182 return 0;
1178 1183
1184 lock_kernel();
1179 if (info->params.mode == MGSL_MODE_HDLC) { 1185 if (info->params.mode == MGSL_MODE_HDLC) {
1180 ret = (info->tx_active) ? 0 : HDLC_MAX_FRAME_SIZE; 1186 ret = (info->tx_active) ? 0 : HDLC_MAX_FRAME_SIZE;
1181 } else { 1187 } else {
@@ -1183,6 +1189,7 @@ static int write_room(struct tty_struct *tty)
1183 if (ret < 0) 1189 if (ret < 0)
1184 ret = 0; 1190 ret = 0;
1185 } 1191 }
1192 unlock_kernel();
1186 1193
1187 if (debug_level >= DEBUG_LEVEL_INFO) 1194 if (debug_level >= DEBUG_LEVEL_INFO)
1188 printk("%s(%d):%s write_room()=%d\n", 1195 printk("%s(%d):%s write_room()=%d\n",
@@ -1303,7 +1310,7 @@ static void tx_release(struct tty_struct *tty)
1303 * 1310 *
1304 * Return Value: 0 if success, otherwise error code 1311 * Return Value: 0 if success, otherwise error code
1305 */ 1312 */
1306static int ioctl(struct tty_struct *tty, struct file *file, 1313static int do_ioctl(struct tty_struct *tty, struct file *file,
1307 unsigned int cmd, unsigned long arg) 1314 unsigned int cmd, unsigned long arg)
1308{ 1315{
1309 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; 1316 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
@@ -1393,6 +1400,16 @@ static int ioctl(struct tty_struct *tty, struct file *file,
1393 return 0; 1400 return 0;
1394} 1401}
1395 1402
1403static int ioctl(struct tty_struct *tty, struct file *file,
1404 unsigned int cmd, unsigned long arg)
1405{
1406 int ret;
1407 lock_kernel();
1408 ret = do_ioctl(tty, file, cmd, arg);
1409 unlock_kernel();
1410 return ret;
1411}
1412
1396/* 1413/*
1397 * /proc fs routines.... 1414 * /proc fs routines....
1398 */ 1415 */
@@ -3626,7 +3643,8 @@ static int claim_resources(SLMP_INFO *info)
3626 else 3643 else
3627 info->sca_statctrl_requested = true; 3644 info->sca_statctrl_requested = true;
3628 3645
3629 info->memory_base = ioremap(info->phys_memory_base,SCA_MEM_SIZE); 3646 info->memory_base = ioremap_nocache(info->phys_memory_base,
3647 SCA_MEM_SIZE);
3630 if (!info->memory_base) { 3648 if (!info->memory_base) {
3631 printk( "%s(%d):%s Cant map shared memory, MemAddr=%08X\n", 3649 printk( "%s(%d):%s Cant map shared memory, MemAddr=%08X\n",
3632 __FILE__,__LINE__,info->device_name, info->phys_memory_base ); 3650 __FILE__,__LINE__,info->device_name, info->phys_memory_base );
@@ -3634,7 +3652,7 @@ static int claim_resources(SLMP_INFO *info)
3634 goto errout; 3652 goto errout;
3635 } 3653 }
3636 3654
3637 info->lcr_base = ioremap(info->phys_lcr_base,PAGE_SIZE); 3655 info->lcr_base = ioremap_nocache(info->phys_lcr_base, PAGE_SIZE);
3638 if (!info->lcr_base) { 3656 if (!info->lcr_base) {
3639 printk( "%s(%d):%s Cant map LCR memory, MemAddr=%08X\n", 3657 printk( "%s(%d):%s Cant map LCR memory, MemAddr=%08X\n",
3640 __FILE__,__LINE__,info->device_name, info->phys_lcr_base ); 3658 __FILE__,__LINE__,info->device_name, info->phys_lcr_base );
@@ -3643,7 +3661,7 @@ static int claim_resources(SLMP_INFO *info)
3643 } 3661 }
3644 info->lcr_base += info->lcr_offset; 3662 info->lcr_base += info->lcr_offset;
3645 3663
3646 info->sca_base = ioremap(info->phys_sca_base,PAGE_SIZE); 3664 info->sca_base = ioremap_nocache(info->phys_sca_base, PAGE_SIZE);
3647 if (!info->sca_base) { 3665 if (!info->sca_base) {
3648 printk( "%s(%d):%s Cant map SCA memory, MemAddr=%08X\n", 3666 printk( "%s(%d):%s Cant map SCA memory, MemAddr=%08X\n",
3649 __FILE__,__LINE__,info->device_name, info->phys_sca_base ); 3667 __FILE__,__LINE__,info->device_name, info->phys_sca_base );
@@ -3652,7 +3670,8 @@ static int claim_resources(SLMP_INFO *info)
3652 } 3670 }
3653 info->sca_base += info->sca_offset; 3671 info->sca_base += info->sca_offset;
3654 3672
3655 info->statctrl_base = ioremap(info->phys_statctrl_base,PAGE_SIZE); 3673 info->statctrl_base = ioremap_nocache(info->phys_statctrl_base,
3674 PAGE_SIZE);
3656 if (!info->statctrl_base) { 3675 if (!info->statctrl_base) {
3657 printk( "%s(%d):%s Cant map SCA Status/Control memory, MemAddr=%08X\n", 3676 printk( "%s(%d):%s Cant map SCA Status/Control memory, MemAddr=%08X\n",
3658 __FILE__,__LINE__,info->device_name, info->phys_statctrl_base ); 3677 __FILE__,__LINE__,info->device_name, info->phys_statctrl_base );
diff --git a/drivers/char/toshiba.c b/drivers/char/toshiba.c
index 64f1ceed0b2c..663cd15d7c78 100644
--- a/drivers/char/toshiba.c
+++ b/drivers/char/toshiba.c
@@ -426,7 +426,7 @@ static int tosh_probe(void)
426 int i,major,minor,day,year,month,flag; 426 int i,major,minor,day,year,month,flag;
427 unsigned char signature[7] = { 0x54,0x4f,0x53,0x48,0x49,0x42,0x41 }; 427 unsigned char signature[7] = { 0x54,0x4f,0x53,0x48,0x49,0x42,0x41 };
428 SMMRegisters regs; 428 SMMRegisters regs;
429 void __iomem *bios = ioremap(0xf0000, 0x10000); 429 void __iomem *bios = ioremap_cache(0xf0000, 0x10000);
430 430
431 if (!bios) 431 if (!bios)
432 return -ENOMEM; 432 return -ENOMEM;
diff --git a/drivers/char/tty_audit.c b/drivers/char/tty_audit.c
index 6342b0534f4d..3582f43345a8 100644
--- a/drivers/char/tty_audit.c
+++ b/drivers/char/tty_audit.c
@@ -11,6 +11,7 @@
11 11
12#include <linux/audit.h> 12#include <linux/audit.h>
13#include <linux/file.h> 13#include <linux/file.h>
14#include <linux/fdtable.h>
14#include <linux/tty.h> 15#include <linux/tty.h>
15 16
16struct tty_audit_buf { 17struct tty_audit_buf {
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 2fa6856706ab..49c1a2267a55 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -78,6 +78,7 @@
78#include <linux/tty_flip.h> 78#include <linux/tty_flip.h>
79#include <linux/devpts_fs.h> 79#include <linux/devpts_fs.h>
80#include <linux/file.h> 80#include <linux/file.h>
81#include <linux/fdtable.h>
81#include <linux/console.h> 82#include <linux/console.h>
82#include <linux/timer.h> 83#include <linux/timer.h>
83#include <linux/ctype.h> 84#include <linux/ctype.h>
@@ -91,7 +92,6 @@
91#include <linux/module.h> 92#include <linux/module.h>
92#include <linux/smp_lock.h> 93#include <linux/smp_lock.h>
93#include <linux/device.h> 94#include <linux/device.h>
94#include <linux/idr.h>
95#include <linux/wait.h> 95#include <linux/wait.h>
96#include <linux/bitops.h> 96#include <linux/bitops.h>
97#include <linux/delay.h> 97#include <linux/delay.h>
@@ -137,9 +137,6 @@ EXPORT_SYMBOL(tty_mutex);
137 137
138#ifdef CONFIG_UNIX98_PTYS 138#ifdef CONFIG_UNIX98_PTYS
139extern struct tty_driver *ptm_driver; /* Unix98 pty masters; for /dev/ptmx */ 139extern struct tty_driver *ptm_driver; /* Unix98 pty masters; for /dev/ptmx */
140extern int pty_limit; /* Config limit on Unix98 ptys */
141static DEFINE_IDR(allocated_ptys);
142static DEFINE_MUTEX(allocated_ptys_lock);
143static int ptmx_open(struct inode *, struct file *); 140static int ptmx_open(struct inode *, struct file *);
144#endif 141#endif
145 142
@@ -152,8 +149,7 @@ ssize_t redirected_tty_write(struct file *, const char __user *,
152static unsigned int tty_poll(struct file *, poll_table *); 149static unsigned int tty_poll(struct file *, poll_table *);
153static int tty_open(struct inode *, struct file *); 150static int tty_open(struct inode *, struct file *);
154static int tty_release(struct inode *, struct file *); 151static int tty_release(struct inode *, struct file *);
155int tty_ioctl(struct inode *inode, struct file *file, 152long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
156 unsigned int cmd, unsigned long arg);
157#ifdef CONFIG_COMPAT 153#ifdef CONFIG_COMPAT
158static long tty_compat_ioctl(struct file *file, unsigned int cmd, 154static long tty_compat_ioctl(struct file *file, unsigned int cmd,
159 unsigned long arg); 155 unsigned long arg);
@@ -1109,8 +1105,8 @@ restart:
1109 a reference to the old ldisc. If we ended up flipping back 1105 a reference to the old ldisc. If we ended up flipping back
1110 to the existing ldisc we have two references to it */ 1106 to the existing ldisc we have two references to it */
1111 1107
1112 if (tty->ldisc.num != o_ldisc.num && tty->driver->set_ldisc) 1108 if (tty->ldisc.num != o_ldisc.num && tty->ops->set_ldisc)
1113 tty->driver->set_ldisc(tty); 1109 tty->ops->set_ldisc(tty);
1114 1110
1115 tty_ldisc_put(o_ldisc.num); 1111 tty_ldisc_put(o_ldisc.num);
1116 1112
@@ -1182,9 +1178,8 @@ struct tty_driver *tty_find_polling_driver(char *name, int *line)
1182 if (*str == '\0') 1178 if (*str == '\0')
1183 str = NULL; 1179 str = NULL;
1184 1180
1185 if (tty_line >= 0 && tty_line <= p->num && p->poll_init && 1181 if (tty_line >= 0 && tty_line <= p->num && p->ops &&
1186 !p->poll_init(p, tty_line, str)) { 1182 p->ops->poll_init && !p->ops->poll_init(p, tty_line, str)) {
1187
1188 res = p; 1183 res = p;
1189 *line = tty_line; 1184 *line = tty_line;
1190 break; 1185 break;
@@ -1205,26 +1200,37 @@ EXPORT_SYMBOL_GPL(tty_find_polling_driver);
1205 * not in the foreground, send a SIGTTOU. If the signal is blocked or 1200 * not in the foreground, send a SIGTTOU. If the signal is blocked or
1206 * ignored, go ahead and perform the operation. (POSIX 7.2) 1201 * ignored, go ahead and perform the operation. (POSIX 7.2)
1207 * 1202 *
1208 * Locking: none 1203 * Locking: ctrl_lock
1209 */ 1204 */
1210 1205
1211int tty_check_change(struct tty_struct *tty) 1206int tty_check_change(struct tty_struct *tty)
1212{ 1207{
1208 unsigned long flags;
1209 int ret = 0;
1210
1213 if (current->signal->tty != tty) 1211 if (current->signal->tty != tty)
1214 return 0; 1212 return 0;
1213
1214 spin_lock_irqsave(&tty->ctrl_lock, flags);
1215
1215 if (!tty->pgrp) { 1216 if (!tty->pgrp) {
1216 printk(KERN_WARNING "tty_check_change: tty->pgrp == NULL!\n"); 1217 printk(KERN_WARNING "tty_check_change: tty->pgrp == NULL!\n");
1217 return 0; 1218 goto out;
1218 } 1219 }
1219 if (task_pgrp(current) == tty->pgrp) 1220 if (task_pgrp(current) == tty->pgrp)
1220 return 0; 1221 goto out;
1221 if (is_ignored(SIGTTOU)) 1222 if (is_ignored(SIGTTOU))
1222 return 0; 1223 goto out;
1223 if (is_current_pgrp_orphaned()) 1224 if (is_current_pgrp_orphaned()) {
1224 return -EIO; 1225 ret = -EIO;
1226 goto out;
1227 }
1225 kill_pgrp(task_pgrp(current), SIGTTOU, 1); 1228 kill_pgrp(task_pgrp(current), SIGTTOU, 1);
1226 set_thread_flag(TIF_SIGPENDING); 1229 set_thread_flag(TIF_SIGPENDING);
1227 return -ERESTARTSYS; 1230 ret = -ERESTARTSYS;
1231out:
1232 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
1233 return ret;
1228} 1234}
1229 1235
1230EXPORT_SYMBOL(tty_check_change); 1236EXPORT_SYMBOL(tty_check_change);
@@ -1247,8 +1253,8 @@ static unsigned int hung_up_tty_poll(struct file *filp, poll_table *wait)
1247 return POLLIN | POLLOUT | POLLERR | POLLHUP | POLLRDNORM | POLLWRNORM; 1253 return POLLIN | POLLOUT | POLLERR | POLLHUP | POLLRDNORM | POLLWRNORM;
1248} 1254}
1249 1255
1250static int hung_up_tty_ioctl(struct inode *inode, struct file *file, 1256static long hung_up_tty_ioctl(struct file *file, unsigned int cmd,
1251 unsigned int cmd, unsigned long arg) 1257 unsigned long arg)
1252{ 1258{
1253 return cmd == TIOCSPGRP ? -ENOTTY : -EIO; 1259 return cmd == TIOCSPGRP ? -ENOTTY : -EIO;
1254} 1260}
@@ -1264,7 +1270,7 @@ static const struct file_operations tty_fops = {
1264 .read = tty_read, 1270 .read = tty_read,
1265 .write = tty_write, 1271 .write = tty_write,
1266 .poll = tty_poll, 1272 .poll = tty_poll,
1267 .ioctl = tty_ioctl, 1273 .unlocked_ioctl = tty_ioctl,
1268 .compat_ioctl = tty_compat_ioctl, 1274 .compat_ioctl = tty_compat_ioctl,
1269 .open = tty_open, 1275 .open = tty_open,
1270 .release = tty_release, 1276 .release = tty_release,
@@ -1277,7 +1283,7 @@ static const struct file_operations ptmx_fops = {
1277 .read = tty_read, 1283 .read = tty_read,
1278 .write = tty_write, 1284 .write = tty_write,
1279 .poll = tty_poll, 1285 .poll = tty_poll,
1280 .ioctl = tty_ioctl, 1286 .unlocked_ioctl = tty_ioctl,
1281 .compat_ioctl = tty_compat_ioctl, 1287 .compat_ioctl = tty_compat_ioctl,
1282 .open = ptmx_open, 1288 .open = ptmx_open,
1283 .release = tty_release, 1289 .release = tty_release,
@@ -1290,7 +1296,7 @@ static const struct file_operations console_fops = {
1290 .read = tty_read, 1296 .read = tty_read,
1291 .write = redirected_tty_write, 1297 .write = redirected_tty_write,
1292 .poll = tty_poll, 1298 .poll = tty_poll,
1293 .ioctl = tty_ioctl, 1299 .unlocked_ioctl = tty_ioctl,
1294 .compat_ioctl = tty_compat_ioctl, 1300 .compat_ioctl = tty_compat_ioctl,
1295 .open = tty_open, 1301 .open = tty_open,
1296 .release = tty_release, 1302 .release = tty_release,
@@ -1302,7 +1308,7 @@ static const struct file_operations hung_up_tty_fops = {
1302 .read = hung_up_tty_read, 1308 .read = hung_up_tty_read,
1303 .write = hung_up_tty_write, 1309 .write = hung_up_tty_write,
1304 .poll = hung_up_tty_poll, 1310 .poll = hung_up_tty_poll,
1305 .ioctl = hung_up_tty_ioctl, 1311 .unlocked_ioctl = hung_up_tty_ioctl,
1306 .compat_ioctl = hung_up_tty_compat_ioctl, 1312 .compat_ioctl = hung_up_tty_compat_ioctl,
1307 .release = tty_release, 1313 .release = tty_release,
1308}; 1314};
@@ -1404,6 +1410,7 @@ static void do_tty_hangup(struct work_struct *work)
1404 struct task_struct *p; 1410 struct task_struct *p;
1405 struct tty_ldisc *ld; 1411 struct tty_ldisc *ld;
1406 int closecount = 0, n; 1412 int closecount = 0, n;
1413 unsigned long flags;
1407 1414
1408 if (!tty) 1415 if (!tty)
1409 return; 1416 return;
@@ -1441,8 +1448,7 @@ static void do_tty_hangup(struct work_struct *work)
1441 /* We may have no line discipline at this point */ 1448 /* We may have no line discipline at this point */
1442 if (ld->flush_buffer) 1449 if (ld->flush_buffer)
1443 ld->flush_buffer(tty); 1450 ld->flush_buffer(tty);
1444 if (tty->driver->flush_buffer) 1451 tty_driver_flush_buffer(tty);
1445 tty->driver->flush_buffer(tty);
1446 if ((test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) && 1452 if ((test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) &&
1447 ld->write_wakeup) 1453 ld->write_wakeup)
1448 ld->write_wakeup(tty); 1454 ld->write_wakeup(tty);
@@ -1480,19 +1486,24 @@ static void do_tty_hangup(struct work_struct *work)
1480 __group_send_sig_info(SIGHUP, SEND_SIG_PRIV, p); 1486 __group_send_sig_info(SIGHUP, SEND_SIG_PRIV, p);
1481 __group_send_sig_info(SIGCONT, SEND_SIG_PRIV, p); 1487 __group_send_sig_info(SIGCONT, SEND_SIG_PRIV, p);
1482 put_pid(p->signal->tty_old_pgrp); /* A noop */ 1488 put_pid(p->signal->tty_old_pgrp); /* A noop */
1489 spin_lock_irqsave(&tty->ctrl_lock, flags);
1483 if (tty->pgrp) 1490 if (tty->pgrp)
1484 p->signal->tty_old_pgrp = get_pid(tty->pgrp); 1491 p->signal->tty_old_pgrp = get_pid(tty->pgrp);
1492 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
1485 spin_unlock_irq(&p->sighand->siglock); 1493 spin_unlock_irq(&p->sighand->siglock);
1486 } while_each_pid_task(tty->session, PIDTYPE_SID, p); 1494 } while_each_pid_task(tty->session, PIDTYPE_SID, p);
1487 } 1495 }
1488 read_unlock(&tasklist_lock); 1496 read_unlock(&tasklist_lock);
1489 1497
1498 spin_lock_irqsave(&tty->ctrl_lock, flags);
1490 tty->flags = 0; 1499 tty->flags = 0;
1491 put_pid(tty->session); 1500 put_pid(tty->session);
1492 put_pid(tty->pgrp); 1501 put_pid(tty->pgrp);
1493 tty->session = NULL; 1502 tty->session = NULL;
1494 tty->pgrp = NULL; 1503 tty->pgrp = NULL;
1495 tty->ctrl_status = 0; 1504 tty->ctrl_status = 0;
1505 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
1506
1496 /* 1507 /*
1497 * If one of the devices matches a console pointer, we 1508 * If one of the devices matches a console pointer, we
1498 * cannot just call hangup() because that will cause 1509 * cannot just call hangup() because that will cause
@@ -1500,11 +1511,11 @@ static void do_tty_hangup(struct work_struct *work)
1500 * So we just call close() the right number of times. 1511 * So we just call close() the right number of times.
1501 */ 1512 */
1502 if (cons_filp) { 1513 if (cons_filp) {
1503 if (tty->driver->close) 1514 if (tty->ops->close)
1504 for (n = 0; n < closecount; n++) 1515 for (n = 0; n < closecount; n++)
1505 tty->driver->close(tty, cons_filp); 1516 tty->ops->close(tty, cons_filp);
1506 } else if (tty->driver->hangup) 1517 } else if (tty->ops->hangup)
1507 (tty->driver->hangup)(tty); 1518 (tty->ops->hangup)(tty);
1508 /* 1519 /*
1509 * We don't want to have driver/ldisc interactions beyond 1520 * We don't want to have driver/ldisc interactions beyond
1510 * the ones we did here. The driver layer expects no 1521 * the ones we did here. The driver layer expects no
@@ -1626,16 +1637,17 @@ void disassociate_ctty(int on_exit)
1626 struct tty_struct *tty; 1637 struct tty_struct *tty;
1627 struct pid *tty_pgrp = NULL; 1638 struct pid *tty_pgrp = NULL;
1628 1639
1629 lock_kernel();
1630 1640
1631 mutex_lock(&tty_mutex); 1641 mutex_lock(&tty_mutex);
1632 tty = get_current_tty(); 1642 tty = get_current_tty();
1633 if (tty) { 1643 if (tty) {
1634 tty_pgrp = get_pid(tty->pgrp); 1644 tty_pgrp = get_pid(tty->pgrp);
1635 mutex_unlock(&tty_mutex); 1645 mutex_unlock(&tty_mutex);
1646 lock_kernel();
1636 /* XXX: here we race, there is nothing protecting tty */ 1647 /* XXX: here we race, there is nothing protecting tty */
1637 if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY) 1648 if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY)
1638 tty_vhangup(tty); 1649 tty_vhangup(tty);
1650 unlock_kernel();
1639 } else if (on_exit) { 1651 } else if (on_exit) {
1640 struct pid *old_pgrp; 1652 struct pid *old_pgrp;
1641 spin_lock_irq(&current->sighand->siglock); 1653 spin_lock_irq(&current->sighand->siglock);
@@ -1648,7 +1660,6 @@ void disassociate_ctty(int on_exit)
1648 put_pid(old_pgrp); 1660 put_pid(old_pgrp);
1649 } 1661 }
1650 mutex_unlock(&tty_mutex); 1662 mutex_unlock(&tty_mutex);
1651 unlock_kernel();
1652 return; 1663 return;
1653 } 1664 }
1654 if (tty_pgrp) { 1665 if (tty_pgrp) {
@@ -1667,10 +1678,13 @@ void disassociate_ctty(int on_exit)
1667 /* It is possible that do_tty_hangup has free'd this tty */ 1678 /* It is possible that do_tty_hangup has free'd this tty */
1668 tty = get_current_tty(); 1679 tty = get_current_tty();
1669 if (tty) { 1680 if (tty) {
1681 unsigned long flags;
1682 spin_lock_irqsave(&tty->ctrl_lock, flags);
1670 put_pid(tty->session); 1683 put_pid(tty->session);
1671 put_pid(tty->pgrp); 1684 put_pid(tty->pgrp);
1672 tty->session = NULL; 1685 tty->session = NULL;
1673 tty->pgrp = NULL; 1686 tty->pgrp = NULL;
1687 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
1674 } else { 1688 } else {
1675#ifdef TTY_DEBUG_HANGUP 1689#ifdef TTY_DEBUG_HANGUP
1676 printk(KERN_DEBUG "error attempted to write to tty [0x%p]" 1690 printk(KERN_DEBUG "error attempted to write to tty [0x%p]"
@@ -1683,7 +1697,6 @@ void disassociate_ctty(int on_exit)
1683 read_lock(&tasklist_lock); 1697 read_lock(&tasklist_lock);
1684 session_clear_tty(task_session(current)); 1698 session_clear_tty(task_session(current));
1685 read_unlock(&tasklist_lock); 1699 read_unlock(&tasklist_lock);
1686 unlock_kernel();
1687} 1700}
1688 1701
1689/** 1702/**
@@ -1693,8 +1706,10 @@ void disassociate_ctty(int on_exit)
1693void no_tty(void) 1706void no_tty(void)
1694{ 1707{
1695 struct task_struct *tsk = current; 1708 struct task_struct *tsk = current;
1709 lock_kernel();
1696 if (tsk->signal->leader) 1710 if (tsk->signal->leader)
1697 disassociate_ctty(0); 1711 disassociate_ctty(0);
1712 unlock_kernel();
1698 proc_clear_tty(tsk); 1713 proc_clear_tty(tsk);
1699} 1714}
1700 1715
@@ -1714,21 +1729,26 @@ void no_tty(void)
1714 * but not always. 1729 * but not always.
1715 * 1730 *
1716 * Locking: 1731 * Locking:
1717 * Broken. Relies on BKL which is unsafe here. 1732 * Uses the tty control lock internally
1718 */ 1733 */
1719 1734
1720void stop_tty(struct tty_struct *tty) 1735void stop_tty(struct tty_struct *tty)
1721{ 1736{
1722 if (tty->stopped) 1737 unsigned long flags;
1738 spin_lock_irqsave(&tty->ctrl_lock, flags);
1739 if (tty->stopped) {
1740 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
1723 return; 1741 return;
1742 }
1724 tty->stopped = 1; 1743 tty->stopped = 1;
1725 if (tty->link && tty->link->packet) { 1744 if (tty->link && tty->link->packet) {
1726 tty->ctrl_status &= ~TIOCPKT_START; 1745 tty->ctrl_status &= ~TIOCPKT_START;
1727 tty->ctrl_status |= TIOCPKT_STOP; 1746 tty->ctrl_status |= TIOCPKT_STOP;
1728 wake_up_interruptible(&tty->link->read_wait); 1747 wake_up_interruptible(&tty->link->read_wait);
1729 } 1748 }
1730 if (tty->driver->stop) 1749 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
1731 (tty->driver->stop)(tty); 1750 if (tty->ops->stop)
1751 (tty->ops->stop)(tty);
1732} 1752}
1733 1753
1734EXPORT_SYMBOL(stop_tty); 1754EXPORT_SYMBOL(stop_tty);
@@ -1743,21 +1763,26 @@ EXPORT_SYMBOL(stop_tty);
1743 * driver start method is invoked and the line discipline woken. 1763 * driver start method is invoked and the line discipline woken.
1744 * 1764 *
1745 * Locking: 1765 * Locking:
1746 * Broken. Relies on BKL which is unsafe here. 1766 * ctrl_lock
1747 */ 1767 */
1748 1768
1749void start_tty(struct tty_struct *tty) 1769void start_tty(struct tty_struct *tty)
1750{ 1770{
1751 if (!tty->stopped || tty->flow_stopped) 1771 unsigned long flags;
1772 spin_lock_irqsave(&tty->ctrl_lock, flags);
1773 if (!tty->stopped || tty->flow_stopped) {
1774 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
1752 return; 1775 return;
1776 }
1753 tty->stopped = 0; 1777 tty->stopped = 0;
1754 if (tty->link && tty->link->packet) { 1778 if (tty->link && tty->link->packet) {
1755 tty->ctrl_status &= ~TIOCPKT_STOP; 1779 tty->ctrl_status &= ~TIOCPKT_STOP;
1756 tty->ctrl_status |= TIOCPKT_START; 1780 tty->ctrl_status |= TIOCPKT_START;
1757 wake_up_interruptible(&tty->link->read_wait); 1781 wake_up_interruptible(&tty->link->read_wait);
1758 } 1782 }
1759 if (tty->driver->start) 1783 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
1760 (tty->driver->start)(tty); 1784 if (tty->ops->start)
1785 (tty->ops->start)(tty);
1761 /* If we have a running line discipline it may need kicking */ 1786 /* If we have a running line discipline it may need kicking */
1762 tty_wakeup(tty); 1787 tty_wakeup(tty);
1763} 1788}
@@ -1775,10 +1800,8 @@ EXPORT_SYMBOL(start_tty);
1775 * for hung up devices before calling the line discipline method. 1800 * for hung up devices before calling the line discipline method.
1776 * 1801 *
1777 * Locking: 1802 * Locking:
1778 * Locks the line discipline internally while needed 1803 * Locks the line discipline internally while needed. Multiple
1779 * For historical reasons the line discipline read method is 1804 * read calls may be outstanding in parallel.
1780 * invoked under the BKL. This will go away in time so do not rely on it
1781 * in new code. Multiple read calls may be outstanding in parallel.
1782 */ 1805 */
1783 1806
1784static ssize_t tty_read(struct file *file, char __user *buf, size_t count, 1807static ssize_t tty_read(struct file *file, char __user *buf, size_t count,
@@ -1799,13 +1822,11 @@ static ssize_t tty_read(struct file *file, char __user *buf, size_t count,
1799 /* We want to wait for the line discipline to sort out in this 1822 /* We want to wait for the line discipline to sort out in this
1800 situation */ 1823 situation */
1801 ld = tty_ldisc_ref_wait(tty); 1824 ld = tty_ldisc_ref_wait(tty);
1802 lock_kernel();
1803 if (ld->read) 1825 if (ld->read)
1804 i = (ld->read)(tty, file, buf, count); 1826 i = (ld->read)(tty, file, buf, count);
1805 else 1827 else
1806 i = -EIO; 1828 i = -EIO;
1807 tty_ldisc_deref(ld); 1829 tty_ldisc_deref(ld);
1808 unlock_kernel();
1809 if (i > 0) 1830 if (i > 0)
1810 inode->i_atime = current_fs_time(inode->i_sb); 1831 inode->i_atime = current_fs_time(inode->i_sb);
1811 return i; 1832 return i;
@@ -1893,9 +1914,7 @@ static inline ssize_t do_tty_write(
1893 ret = -EFAULT; 1914 ret = -EFAULT;
1894 if (copy_from_user(tty->write_buf, buf, size)) 1915 if (copy_from_user(tty->write_buf, buf, size))
1895 break; 1916 break;
1896 lock_kernel();
1897 ret = write(tty, file, tty->write_buf, size); 1917 ret = write(tty, file, tty->write_buf, size);
1898 unlock_kernel();
1899 if (ret <= 0) 1918 if (ret <= 0)
1900 break; 1919 break;
1901 written += ret; 1920 written += ret;
@@ -1948,10 +1967,13 @@ static ssize_t tty_write(struct file *file, const char __user *buf,
1948 tty = (struct tty_struct *)file->private_data; 1967 tty = (struct tty_struct *)file->private_data;
1949 if (tty_paranoia_check(tty, inode, "tty_write")) 1968 if (tty_paranoia_check(tty, inode, "tty_write"))
1950 return -EIO; 1969 return -EIO;
1951 if (!tty || !tty->driver->write || 1970 if (!tty || !tty->ops->write ||
1952 (test_bit(TTY_IO_ERROR, &tty->flags))) 1971 (test_bit(TTY_IO_ERROR, &tty->flags)))
1953 return -EIO; 1972 return -EIO;
1954 1973 /* Short term debug to catch buggy drivers */
1974 if (tty->ops->write_room == NULL)
1975 printk(KERN_ERR "tty driver %s lacks a write_room method.\n",
1976 tty->driver->name);
1955 ld = tty_ldisc_ref_wait(tty); 1977 ld = tty_ldisc_ref_wait(tty);
1956 if (!ld->write) 1978 if (!ld->write)
1957 ret = -EIO; 1979 ret = -EIO;
@@ -2098,6 +2120,7 @@ static int init_dev(struct tty_driver *driver, int idx,
2098 goto fail_no_mem; 2120 goto fail_no_mem;
2099 initialize_tty_struct(tty); 2121 initialize_tty_struct(tty);
2100 tty->driver = driver; 2122 tty->driver = driver;
2123 tty->ops = driver->ops;
2101 tty->index = idx; 2124 tty->index = idx;
2102 tty_line_name(driver, idx, tty->name); 2125 tty_line_name(driver, idx, tty->name);
2103 2126
@@ -2128,6 +2151,7 @@ static int init_dev(struct tty_driver *driver, int idx,
2128 goto free_mem_out; 2151 goto free_mem_out;
2129 initialize_tty_struct(o_tty); 2152 initialize_tty_struct(o_tty);
2130 o_tty->driver = driver->other; 2153 o_tty->driver = driver->other;
2154 o_tty->ops = driver->ops;
2131 o_tty->index = idx; 2155 o_tty->index = idx;
2132 tty_line_name(driver->other, idx, o_tty->name); 2156 tty_line_name(driver->other, idx, o_tty->name);
2133 2157
@@ -2432,8 +2456,8 @@ static void release_dev(struct file *filp)
2432 } 2456 }
2433 } 2457 }
2434#endif 2458#endif
2435 if (tty->driver->close) 2459 if (tty->ops->close)
2436 tty->driver->close(tty, filp); 2460 tty->ops->close(tty, filp);
2437 2461
2438 /* 2462 /*
2439 * Sanity check: if tty->count is going to zero, there shouldn't be 2463 * Sanity check: if tty->count is going to zero, there shouldn't be
@@ -2612,15 +2636,9 @@ static void release_dev(struct file *filp)
2612 */ 2636 */
2613 release_tty(tty, idx); 2637 release_tty(tty, idx);
2614 2638
2615#ifdef CONFIG_UNIX98_PTYS
2616 /* Make this pty number available for reallocation */ 2639 /* Make this pty number available for reallocation */
2617 if (devpts) { 2640 if (devpts)
2618 mutex_lock(&allocated_ptys_lock); 2641 devpts_kill_index(idx);
2619 idr_remove(&allocated_ptys, idx);
2620 mutex_unlock(&allocated_ptys_lock);
2621 }
2622#endif
2623
2624} 2642}
2625 2643
2626/** 2644/**
@@ -2716,8 +2734,8 @@ got_driver:
2716 printk(KERN_DEBUG "opening %s...", tty->name); 2734 printk(KERN_DEBUG "opening %s...", tty->name);
2717#endif 2735#endif
2718 if (!retval) { 2736 if (!retval) {
2719 if (tty->driver->open) 2737 if (tty->ops->open)
2720 retval = tty->driver->open(tty, filp); 2738 retval = tty->ops->open(tty, filp);
2721 else 2739 else
2722 retval = -ENODEV; 2740 retval = -ENODEV;
2723 } 2741 }
@@ -2776,29 +2794,13 @@ static int ptmx_open(struct inode *inode, struct file *filp)
2776 struct tty_struct *tty; 2794 struct tty_struct *tty;
2777 int retval; 2795 int retval;
2778 int index; 2796 int index;
2779 int idr_ret;
2780 2797
2781 nonseekable_open(inode, filp); 2798 nonseekable_open(inode, filp);
2782 2799
2783 /* find a device that is not in use. */ 2800 /* find a device that is not in use. */
2784 mutex_lock(&allocated_ptys_lock); 2801 index = devpts_new_index();
2785 if (!idr_pre_get(&allocated_ptys, GFP_KERNEL)) { 2802 if (index < 0)
2786 mutex_unlock(&allocated_ptys_lock); 2803 return index;
2787 return -ENOMEM;
2788 }
2789 idr_ret = idr_get_new(&allocated_ptys, NULL, &index);
2790 if (idr_ret < 0) {
2791 mutex_unlock(&allocated_ptys_lock);
2792 if (idr_ret == -EAGAIN)
2793 return -ENOMEM;
2794 return -EIO;
2795 }
2796 if (index >= pty_limit) {
2797 idr_remove(&allocated_ptys, index);
2798 mutex_unlock(&allocated_ptys_lock);
2799 return -EIO;
2800 }
2801 mutex_unlock(&allocated_ptys_lock);
2802 2804
2803 mutex_lock(&tty_mutex); 2805 mutex_lock(&tty_mutex);
2804 retval = init_dev(ptm_driver, index, &tty); 2806 retval = init_dev(ptm_driver, index, &tty);
@@ -2811,21 +2813,19 @@ static int ptmx_open(struct inode *inode, struct file *filp)
2811 filp->private_data = tty; 2813 filp->private_data = tty;
2812 file_move(filp, &tty->tty_files); 2814 file_move(filp, &tty->tty_files);
2813 2815
2814 retval = -ENOMEM; 2816 retval = devpts_pty_new(tty->link);
2815 if (devpts_pty_new(tty->link)) 2817 if (retval)
2816 goto out1; 2818 goto out1;
2817 2819
2818 check_tty_count(tty, "tty_open"); 2820 check_tty_count(tty, "ptmx_open");
2819 retval = ptm_driver->open(tty, filp); 2821 retval = ptm_driver->ops->open(tty, filp);
2820 if (!retval) 2822 if (!retval)
2821 return 0; 2823 return 0;
2822out1: 2824out1:
2823 release_dev(filp); 2825 release_dev(filp);
2824 return retval; 2826 return retval;
2825out: 2827out:
2826 mutex_lock(&allocated_ptys_lock); 2828 devpts_kill_index(index);
2827 idr_remove(&allocated_ptys, index);
2828 mutex_unlock(&allocated_ptys_lock);
2829 return retval; 2829 return retval;
2830} 2830}
2831#endif 2831#endif
@@ -2882,6 +2882,7 @@ static unsigned int tty_poll(struct file *filp, poll_table *wait)
2882static int tty_fasync(int fd, struct file *filp, int on) 2882static int tty_fasync(int fd, struct file *filp, int on)
2883{ 2883{
2884 struct tty_struct *tty; 2884 struct tty_struct *tty;
2885 unsigned long flags;
2885 int retval; 2886 int retval;
2886 2887
2887 tty = (struct tty_struct *)filp->private_data; 2888 tty = (struct tty_struct *)filp->private_data;
@@ -2897,6 +2898,7 @@ static int tty_fasync(int fd, struct file *filp, int on)
2897 struct pid *pid; 2898 struct pid *pid;
2898 if (!waitqueue_active(&tty->read_wait)) 2899 if (!waitqueue_active(&tty->read_wait))
2899 tty->minimum_to_wake = 1; 2900 tty->minimum_to_wake = 1;
2901 spin_lock_irqsave(&tty->ctrl_lock, flags);
2900 if (tty->pgrp) { 2902 if (tty->pgrp) {
2901 pid = tty->pgrp; 2903 pid = tty->pgrp;
2902 type = PIDTYPE_PGID; 2904 type = PIDTYPE_PGID;
@@ -2904,6 +2906,7 @@ static int tty_fasync(int fd, struct file *filp, int on)
2904 pid = task_pid(current); 2906 pid = task_pid(current);
2905 type = PIDTYPE_PID; 2907 type = PIDTYPE_PID;
2906 } 2908 }
2909 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
2907 retval = __f_setown(filp, pid, type, 0); 2910 retval = __f_setown(filp, pid, type, 0);
2908 if (retval) 2911 if (retval)
2909 return retval; 2912 return retval;
@@ -2989,6 +2992,8 @@ static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty,
2989 struct winsize __user *arg) 2992 struct winsize __user *arg)
2990{ 2993{
2991 struct winsize tmp_ws; 2994 struct winsize tmp_ws;
2995 struct pid *pgrp, *rpgrp;
2996 unsigned long flags;
2992 2997
2993 if (copy_from_user(&tmp_ws, arg, sizeof(*arg))) 2998 if (copy_from_user(&tmp_ws, arg, sizeof(*arg)))
2994 return -EFAULT; 2999 return -EFAULT;
@@ -3006,10 +3011,21 @@ static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty,
3006 } 3011 }
3007 } 3012 }
3008#endif 3013#endif
3009 if (tty->pgrp) 3014 /* Get the PID values and reference them so we can
3010 kill_pgrp(tty->pgrp, SIGWINCH, 1); 3015 avoid holding the tty ctrl lock while sending signals */
3011 if ((real_tty->pgrp != tty->pgrp) && real_tty->pgrp) 3016 spin_lock_irqsave(&tty->ctrl_lock, flags);
3012 kill_pgrp(real_tty->pgrp, SIGWINCH, 1); 3017 pgrp = get_pid(tty->pgrp);
3018 rpgrp = get_pid(real_tty->pgrp);
3019 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
3020
3021 if (pgrp)
3022 kill_pgrp(pgrp, SIGWINCH, 1);
3023 if (rpgrp != pgrp && rpgrp)
3024 kill_pgrp(rpgrp, SIGWINCH, 1);
3025
3026 put_pid(pgrp);
3027 put_pid(rpgrp);
3028
3013 tty->winsize = tmp_ws; 3029 tty->winsize = tmp_ws;
3014 real_tty->winsize = tmp_ws; 3030 real_tty->winsize = tmp_ws;
3015done: 3031done:
@@ -3070,10 +3086,13 @@ static int fionbio(struct file *file, int __user *p)
3070 if (get_user(nonblock, p)) 3086 if (get_user(nonblock, p))
3071 return -EFAULT; 3087 return -EFAULT;
3072 3088
3089 /* file->f_flags is still BKL protected in the fs layer - vomit */
3090 lock_kernel();
3073 if (nonblock) 3091 if (nonblock)
3074 file->f_flags |= O_NONBLOCK; 3092 file->f_flags |= O_NONBLOCK;
3075 else 3093 else
3076 file->f_flags &= ~O_NONBLOCK; 3094 file->f_flags &= ~O_NONBLOCK;
3095 unlock_kernel();
3077 return 0; 3096 return 0;
3078} 3097}
3079 3098
@@ -3131,6 +3150,27 @@ unlock:
3131} 3150}
3132 3151
3133/** 3152/**
3153 * tty_get_pgrp - return a ref counted pgrp pid
3154 * @tty: tty to read
3155 *
3156 * Returns a refcounted instance of the pid struct for the process
3157 * group controlling the tty.
3158 */
3159
3160struct pid *tty_get_pgrp(struct tty_struct *tty)
3161{
3162 unsigned long flags;
3163 struct pid *pgrp;
3164
3165 spin_lock_irqsave(&tty->ctrl_lock, flags);
3166 pgrp = get_pid(tty->pgrp);
3167 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
3168
3169 return pgrp;
3170}
3171EXPORT_SYMBOL_GPL(tty_get_pgrp);
3172
3173/**
3134 * tiocgpgrp - get process group 3174 * tiocgpgrp - get process group
3135 * @tty: tty passed by user 3175 * @tty: tty passed by user
3136 * @real_tty: tty side of the tty pased by the user if a pty else the tty 3176 * @real_tty: tty side of the tty pased by the user if a pty else the tty
@@ -3144,13 +3184,18 @@ unlock:
3144 3184
3145static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) 3185static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p)
3146{ 3186{
3187 struct pid *pid;
3188 int ret;
3147 /* 3189 /*
3148 * (tty == real_tty) is a cheap way of 3190 * (tty == real_tty) is a cheap way of
3149 * testing if the tty is NOT a master pty. 3191 * testing if the tty is NOT a master pty.
3150 */ 3192 */
3151 if (tty == real_tty && current->signal->tty != real_tty) 3193 if (tty == real_tty && current->signal->tty != real_tty)
3152 return -ENOTTY; 3194 return -ENOTTY;
3153 return put_user(pid_vnr(real_tty->pgrp), p); 3195 pid = tty_get_pgrp(real_tty);
3196 ret = put_user(pid_vnr(pid), p);
3197 put_pid(pid);
3198 return ret;
3154} 3199}
3155 3200
3156/** 3201/**
@@ -3162,7 +3207,7 @@ static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
3162 * Set the process group of the tty to the session passed. Only 3207 * Set the process group of the tty to the session passed. Only
3163 * permitted where the tty session is our session. 3208 * permitted where the tty session is our session.
3164 * 3209 *
3165 * Locking: None 3210 * Locking: RCU, ctrl lock
3166 */ 3211 */
3167 3212
3168static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) 3213static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p)
@@ -3170,6 +3215,7 @@ static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
3170 struct pid *pgrp; 3215 struct pid *pgrp;
3171 pid_t pgrp_nr; 3216 pid_t pgrp_nr;
3172 int retval = tty_check_change(real_tty); 3217 int retval = tty_check_change(real_tty);
3218 unsigned long flags;
3173 3219
3174 if (retval == -EIO) 3220 if (retval == -EIO)
3175 return -ENOTTY; 3221 return -ENOTTY;
@@ -3192,8 +3238,10 @@ static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
3192 if (session_of_pgrp(pgrp) != task_session(current)) 3238 if (session_of_pgrp(pgrp) != task_session(current))
3193 goto out_unlock; 3239 goto out_unlock;
3194 retval = 0; 3240 retval = 0;
3241 spin_lock_irqsave(&tty->ctrl_lock, flags);
3195 put_pid(real_tty->pgrp); 3242 put_pid(real_tty->pgrp);
3196 real_tty->pgrp = get_pid(pgrp); 3243 real_tty->pgrp = get_pid(pgrp);
3244 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
3197out_unlock: 3245out_unlock:
3198 rcu_read_unlock(); 3246 rcu_read_unlock();
3199 return retval; 3247 return retval;
@@ -3237,10 +3285,16 @@ static int tiocgsid(struct tty_struct *tty, struct tty_struct *real_tty, pid_t _
3237static int tiocsetd(struct tty_struct *tty, int __user *p) 3285static int tiocsetd(struct tty_struct *tty, int __user *p)
3238{ 3286{
3239 int ldisc; 3287 int ldisc;
3288 int ret;
3240 3289
3241 if (get_user(ldisc, p)) 3290 if (get_user(ldisc, p))
3242 return -EFAULT; 3291 return -EFAULT;
3243 return tty_set_ldisc(tty, ldisc); 3292
3293 lock_kernel();
3294 ret = tty_set_ldisc(tty, ldisc);
3295 unlock_kernel();
3296
3297 return ret;
3244} 3298}
3245 3299
3246/** 3300/**
@@ -3260,18 +3314,18 @@ static int send_break(struct tty_struct *tty, unsigned int duration)
3260{ 3314{
3261 if (tty_write_lock(tty, 0) < 0) 3315 if (tty_write_lock(tty, 0) < 0)
3262 return -EINTR; 3316 return -EINTR;
3263 tty->driver->break_ctl(tty, -1); 3317 tty->ops->break_ctl(tty, -1);
3264 if (!signal_pending(current)) 3318 if (!signal_pending(current))
3265 msleep_interruptible(duration); 3319 msleep_interruptible(duration);
3266 tty->driver->break_ctl(tty, 0); 3320 tty->ops->break_ctl(tty, 0);
3267 tty_write_unlock(tty); 3321 tty_write_unlock(tty);
3268 if (signal_pending(current)) 3322 if (!signal_pending(current))
3269 return -EINTR; 3323 return -EINTR;
3270 return 0; 3324 return 0;
3271} 3325}
3272 3326
3273/** 3327/**
3274 * tiocmget - get modem status 3328 * tty_tiocmget - get modem status
3275 * @tty: tty device 3329 * @tty: tty device
3276 * @file: user file pointer 3330 * @file: user file pointer
3277 * @p: pointer to result 3331 * @p: pointer to result
@@ -3286,8 +3340,8 @@ static int tty_tiocmget(struct tty_struct *tty, struct file *file, int __user *p
3286{ 3340{
3287 int retval = -EINVAL; 3341 int retval = -EINVAL;
3288 3342
3289 if (tty->driver->tiocmget) { 3343 if (tty->ops->tiocmget) {
3290 retval = tty->driver->tiocmget(tty, file); 3344 retval = tty->ops->tiocmget(tty, file);
3291 3345
3292 if (retval >= 0) 3346 if (retval >= 0)
3293 retval = put_user(retval, p); 3347 retval = put_user(retval, p);
@@ -3296,7 +3350,7 @@ static int tty_tiocmget(struct tty_struct *tty, struct file *file, int __user *p
3296} 3350}
3297 3351
3298/** 3352/**
3299 * tiocmset - set modem status 3353 * tty_tiocmset - set modem status
3300 * @tty: tty device 3354 * @tty: tty device
3301 * @file: user file pointer 3355 * @file: user file pointer
3302 * @cmd: command - clear bits, set bits or set all 3356 * @cmd: command - clear bits, set bits or set all
@@ -3313,7 +3367,7 @@ static int tty_tiocmset(struct tty_struct *tty, struct file *file, unsigned int
3313{ 3367{
3314 int retval = -EINVAL; 3368 int retval = -EINVAL;
3315 3369
3316 if (tty->driver->tiocmset) { 3370 if (tty->ops->tiocmset) {
3317 unsigned int set, clear, val; 3371 unsigned int set, clear, val;
3318 3372
3319 retval = get_user(val, p); 3373 retval = get_user(val, p);
@@ -3337,7 +3391,7 @@ static int tty_tiocmset(struct tty_struct *tty, struct file *file, unsigned int
3337 set &= TIOCM_DTR|TIOCM_RTS|TIOCM_OUT1|TIOCM_OUT2|TIOCM_LOOP; 3391 set &= TIOCM_DTR|TIOCM_RTS|TIOCM_OUT1|TIOCM_OUT2|TIOCM_LOOP;
3338 clear &= TIOCM_DTR|TIOCM_RTS|TIOCM_OUT1|TIOCM_OUT2|TIOCM_LOOP; 3392 clear &= TIOCM_DTR|TIOCM_RTS|TIOCM_OUT1|TIOCM_OUT2|TIOCM_LOOP;
3339 3393
3340 retval = tty->driver->tiocmset(tty, file, set, clear); 3394 retval = tty->ops->tiocmset(tty, file, set, clear);
3341 } 3395 }
3342 return retval; 3396 return retval;
3343} 3397}
@@ -3345,20 +3399,18 @@ static int tty_tiocmset(struct tty_struct *tty, struct file *file, unsigned int
3345/* 3399/*
3346 * Split this up, as gcc can choke on it otherwise.. 3400 * Split this up, as gcc can choke on it otherwise..
3347 */ 3401 */
3348int tty_ioctl(struct inode *inode, struct file *file, 3402long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
3349 unsigned int cmd, unsigned long arg)
3350{ 3403{
3351 struct tty_struct *tty, *real_tty; 3404 struct tty_struct *tty, *real_tty;
3352 void __user *p = (void __user *)arg; 3405 void __user *p = (void __user *)arg;
3353 int retval; 3406 int retval;
3354 struct tty_ldisc *ld; 3407 struct tty_ldisc *ld;
3408 struct inode *inode = file->f_dentry->d_inode;
3355 3409
3356 tty = (struct tty_struct *)file->private_data; 3410 tty = (struct tty_struct *)file->private_data;
3357 if (tty_paranoia_check(tty, inode, "tty_ioctl")) 3411 if (tty_paranoia_check(tty, inode, "tty_ioctl"))
3358 return -EINVAL; 3412 return -EINVAL;
3359 3413
3360 /* CHECKME: is this safe as one end closes ? */
3361
3362 real_tty = tty; 3414 real_tty = tty;
3363 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && 3415 if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
3364 tty->driver->subtype == PTY_TYPE_MASTER) 3416 tty->driver->subtype == PTY_TYPE_MASTER)
@@ -3367,21 +3419,28 @@ int tty_ioctl(struct inode *inode, struct file *file,
3367 /* 3419 /*
3368 * Break handling by driver 3420 * Break handling by driver
3369 */ 3421 */
3370 if (!tty->driver->break_ctl) { 3422
3423 retval = -EINVAL;
3424
3425 if (!tty->ops->break_ctl) {
3371 switch (cmd) { 3426 switch (cmd) {
3372 case TIOCSBRK: 3427 case TIOCSBRK:
3373 case TIOCCBRK: 3428 case TIOCCBRK:
3374 if (tty->driver->ioctl) 3429 if (tty->ops->ioctl)
3375 return tty->driver->ioctl(tty, file, cmd, arg); 3430 retval = tty->ops->ioctl(tty, file, cmd, arg);
3376 return -EINVAL; 3431 if (retval != -EINVAL && retval != -ENOIOCTLCMD)
3432 printk(KERN_WARNING "tty: driver %s needs updating to use break_ctl\n", tty->driver->name);
3433 return retval;
3377 3434
3378 /* These two ioctl's always return success; even if */ 3435 /* These two ioctl's always return success; even if */
3379 /* the driver doesn't support them. */ 3436 /* the driver doesn't support them. */
3380 case TCSBRK: 3437 case TCSBRK:
3381 case TCSBRKP: 3438 case TCSBRKP:
3382 if (!tty->driver->ioctl) 3439 if (!tty->ops->ioctl)
3383 return 0; 3440 return 0;
3384 retval = tty->driver->ioctl(tty, file, cmd, arg); 3441 retval = tty->ops->ioctl(tty, file, cmd, arg);
3442 if (retval != -EINVAL && retval != -ENOIOCTLCMD)
3443 printk(KERN_WARNING "tty: driver %s needs updating to use break_ctl\n", tty->driver->name);
3385 if (retval == -ENOIOCTLCMD) 3444 if (retval == -ENOIOCTLCMD)
3386 retval = 0; 3445 retval = 0;
3387 return retval; 3446 return retval;
@@ -3439,7 +3498,6 @@ int tty_ioctl(struct inode *inode, struct file *file,
3439 case TIOCGSID: 3498 case TIOCGSID:
3440 return tiocgsid(tty, real_tty, p); 3499 return tiocgsid(tty, real_tty, p);
3441 case TIOCGETD: 3500 case TIOCGETD:
3442 /* FIXME: check this is ok */
3443 return put_user(tty->ldisc.num, (int __user *)p); 3501 return put_user(tty->ldisc.num, (int __user *)p);
3444 case TIOCSETD: 3502 case TIOCSETD:
3445 return tiocsetd(tty, p); 3503 return tiocsetd(tty, p);
@@ -3451,11 +3509,13 @@ int tty_ioctl(struct inode *inode, struct file *file,
3451 * Break handling 3509 * Break handling
3452 */ 3510 */
3453 case TIOCSBRK: /* Turn break on, unconditionally */ 3511 case TIOCSBRK: /* Turn break on, unconditionally */
3454 tty->driver->break_ctl(tty, -1); 3512 if (tty->ops->break_ctl)
3513 tty->ops->break_ctl(tty, -1);
3455 return 0; 3514 return 0;
3456 3515
3457 case TIOCCBRK: /* Turn break off, unconditionally */ 3516 case TIOCCBRK: /* Turn break off, unconditionally */
3458 tty->driver->break_ctl(tty, 0); 3517 if (tty->ops->break_ctl)
3518 tty->ops->break_ctl(tty, 0);
3459 return 0; 3519 return 0;
3460 case TCSBRK: /* SVID version: non-zero arg --> no break */ 3520 case TCSBRK: /* SVID version: non-zero arg --> no break */
3461 /* non-zero arg means wait for all output data 3521 /* non-zero arg means wait for all output data
@@ -3484,8 +3544,8 @@ int tty_ioctl(struct inode *inode, struct file *file,
3484 } 3544 }
3485 break; 3545 break;
3486 } 3546 }
3487 if (tty->driver->ioctl) { 3547 if (tty->ops->ioctl) {
3488 retval = (tty->driver->ioctl)(tty, file, cmd, arg); 3548 retval = (tty->ops->ioctl)(tty, file, cmd, arg);
3489 if (retval != -ENOIOCTLCMD) 3549 if (retval != -ENOIOCTLCMD)
3490 return retval; 3550 return retval;
3491 } 3551 }
@@ -3512,8 +3572,8 @@ static long tty_compat_ioctl(struct file *file, unsigned int cmd,
3512 if (tty_paranoia_check(tty, inode, "tty_ioctl")) 3572 if (tty_paranoia_check(tty, inode, "tty_ioctl"))
3513 return -EINVAL; 3573 return -EINVAL;
3514 3574
3515 if (tty->driver->compat_ioctl) { 3575 if (tty->ops->compat_ioctl) {
3516 retval = (tty->driver->compat_ioctl)(tty, file, cmd, arg); 3576 retval = (tty->ops->compat_ioctl)(tty, file, cmd, arg);
3517 if (retval != -ENOIOCTLCMD) 3577 if (retval != -ENOIOCTLCMD)
3518 return retval; 3578 return retval;
3519 } 3579 }
@@ -3563,8 +3623,7 @@ void __do_SAK(struct tty_struct *tty)
3563 3623
3564 tty_ldisc_flush(tty); 3624 tty_ldisc_flush(tty);
3565 3625
3566 if (tty->driver->flush_buffer) 3626 tty_driver_flush_buffer(tty);
3567 tty->driver->flush_buffer(tty);
3568 3627
3569 read_lock(&tasklist_lock); 3628 read_lock(&tasklist_lock);
3570 /* Kill the entire session */ 3629 /* Kill the entire session */
@@ -3770,19 +3829,32 @@ static void initialize_tty_struct(struct tty_struct *tty)
3770 mutex_init(&tty->atomic_read_lock); 3829 mutex_init(&tty->atomic_read_lock);
3771 mutex_init(&tty->atomic_write_lock); 3830 mutex_init(&tty->atomic_write_lock);
3772 spin_lock_init(&tty->read_lock); 3831 spin_lock_init(&tty->read_lock);
3832 spin_lock_init(&tty->ctrl_lock);
3773 INIT_LIST_HEAD(&tty->tty_files); 3833 INIT_LIST_HEAD(&tty->tty_files);
3774 INIT_WORK(&tty->SAK_work, do_SAK_work); 3834 INIT_WORK(&tty->SAK_work, do_SAK_work);
3775} 3835}
3776 3836
3777/* 3837/**
3778 * The default put_char routine if the driver did not define one. 3838 * tty_put_char - write one character to a tty
3839 * @tty: tty
3840 * @ch: character
3841 *
3842 * Write one byte to the tty using the provided put_char method
3843 * if present. Returns the number of characters successfully output.
3844 *
3845 * Note: the specific put_char operation in the driver layer may go
3846 * away soon. Don't call it directly, use this method
3779 */ 3847 */
3780 3848
3781static void tty_default_put_char(struct tty_struct *tty, unsigned char ch) 3849int tty_put_char(struct tty_struct *tty, unsigned char ch)
3782{ 3850{
3783 tty->driver->write(tty, &ch, 1); 3851 if (tty->ops->put_char)
3852 return tty->ops->put_char(tty, ch);
3853 return tty->ops->write(tty, &ch, 1);
3784} 3854}
3785 3855
3856EXPORT_SYMBOL_GPL(tty_put_char);
3857
3786static struct class *tty_class; 3858static struct class *tty_class;
3787 3859
3788/** 3860/**
@@ -3865,37 +3937,8 @@ void put_tty_driver(struct tty_driver *driver)
3865void tty_set_operations(struct tty_driver *driver, 3937void tty_set_operations(struct tty_driver *driver,
3866 const struct tty_operations *op) 3938 const struct tty_operations *op)
3867{ 3939{
3868 driver->open = op->open; 3940 driver->ops = op;
3869 driver->close = op->close; 3941};
3870 driver->write = op->write;
3871 driver->put_char = op->put_char;
3872 driver->flush_chars = op->flush_chars;
3873 driver->write_room = op->write_room;
3874 driver->chars_in_buffer = op->chars_in_buffer;
3875 driver->ioctl = op->ioctl;
3876 driver->compat_ioctl = op->compat_ioctl;
3877 driver->set_termios = op->set_termios;
3878 driver->throttle = op->throttle;
3879 driver->unthrottle = op->unthrottle;
3880 driver->stop = op->stop;
3881 driver->start = op->start;
3882 driver->hangup = op->hangup;
3883 driver->break_ctl = op->break_ctl;
3884 driver->flush_buffer = op->flush_buffer;
3885 driver->set_ldisc = op->set_ldisc;
3886 driver->wait_until_sent = op->wait_until_sent;
3887 driver->send_xchar = op->send_xchar;
3888 driver->read_proc = op->read_proc;
3889 driver->write_proc = op->write_proc;
3890 driver->tiocmget = op->tiocmget;
3891 driver->tiocmset = op->tiocmset;
3892#ifdef CONFIG_CONSOLE_POLL
3893 driver->poll_init = op->poll_init;
3894 driver->poll_get_char = op->poll_get_char;
3895 driver->poll_put_char = op->poll_put_char;
3896#endif
3897}
3898
3899 3942
3900EXPORT_SYMBOL(alloc_tty_driver); 3943EXPORT_SYMBOL(alloc_tty_driver);
3901EXPORT_SYMBOL(put_tty_driver); 3944EXPORT_SYMBOL(put_tty_driver);
@@ -3958,9 +4001,6 @@ int tty_register_driver(struct tty_driver *driver)
3958 return error; 4001 return error;
3959 } 4002 }
3960 4003
3961 if (!driver->put_char)
3962 driver->put_char = tty_default_put_char;
3963
3964 mutex_lock(&tty_mutex); 4004 mutex_lock(&tty_mutex);
3965 list_add(&driver->tty_drivers, &tty_drivers); 4005 list_add(&driver->tty_drivers, &tty_drivers);
3966 mutex_unlock(&tty_mutex); 4006 mutex_unlock(&tty_mutex);
@@ -4036,14 +4076,19 @@ void proc_clear_tty(struct task_struct *p)
4036} 4076}
4037EXPORT_SYMBOL(proc_clear_tty); 4077EXPORT_SYMBOL(proc_clear_tty);
4038 4078
4079/* Called under the sighand lock */
4080
4039static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty) 4081static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
4040{ 4082{
4041 if (tty) { 4083 if (tty) {
4042 /* We should not have a session or pgrp to here but.... */ 4084 unsigned long flags;
4085 /* We should not have a session or pgrp to put here but.... */
4086 spin_lock_irqsave(&tty->ctrl_lock, flags);
4043 put_pid(tty->session); 4087 put_pid(tty->session);
4044 put_pid(tty->pgrp); 4088 put_pid(tty->pgrp);
4045 tty->session = get_pid(task_session(tsk));
4046 tty->pgrp = get_pid(task_pgrp(tsk)); 4089 tty->pgrp = get_pid(task_pgrp(tsk));
4090 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
4091 tty->session = get_pid(task_session(tsk));
4047 } 4092 }
4048 put_pid(tsk->signal->tty_old_pgrp); 4093 put_pid(tsk->signal->tty_old_pgrp);
4049 tsk->signal->tty = tty; 4094 tsk->signal->tty = tty;
diff --git a/drivers/char/tty_ioctl.c b/drivers/char/tty_ioctl.c
index f95a80b2265f..b1a757a5ee27 100644
--- a/drivers/char/tty_ioctl.c
+++ b/drivers/char/tty_ioctl.c
@@ -21,6 +21,7 @@
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/bitops.h> 22#include <linux/bitops.h>
23#include <linux/mutex.h> 23#include <linux/mutex.h>
24#include <linux/smp_lock.h>
24 25
25#include <asm/io.h> 26#include <asm/io.h>
26#include <asm/uaccess.h> 27#include <asm/uaccess.h>
@@ -39,6 +40,50 @@
39#define TERMIOS_OLD 8 40#define TERMIOS_OLD 8
40 41
41 42
43int tty_chars_in_buffer(struct tty_struct *tty)
44{
45 if (tty->ops->chars_in_buffer)
46 return tty->ops->chars_in_buffer(tty);
47 else
48 return 0;
49}
50
51EXPORT_SYMBOL(tty_chars_in_buffer);
52
53int tty_write_room(struct tty_struct *tty)
54{
55 if (tty->ops->write_room)
56 return tty->ops->write_room(tty);
57 return 2048;
58}
59
60EXPORT_SYMBOL(tty_write_room);
61
62void tty_driver_flush_buffer(struct tty_struct *tty)
63{
64 if (tty->ops->flush_buffer)
65 tty->ops->flush_buffer(tty);
66}
67
68EXPORT_SYMBOL(tty_driver_flush_buffer);
69
70void tty_throttle(struct tty_struct *tty)
71{
72 /* check TTY_THROTTLED first so it indicates our state */
73 if (!test_and_set_bit(TTY_THROTTLED, &tty->flags) &&
74 tty->ops->throttle)
75 tty->ops->throttle(tty);
76}
77EXPORT_SYMBOL(tty_throttle);
78
79void tty_unthrottle(struct tty_struct *tty)
80{
81 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) &&
82 tty->ops->unthrottle)
83 tty->ops->unthrottle(tty);
84}
85EXPORT_SYMBOL(tty_unthrottle);
86
42/** 87/**
43 * tty_wait_until_sent - wait for I/O to finish 88 * tty_wait_until_sent - wait for I/O to finish
44 * @tty: tty we are waiting for 89 * @tty: tty we are waiting for
@@ -57,15 +102,13 @@ void tty_wait_until_sent(struct tty_struct *tty, long timeout)
57 102
58 printk(KERN_DEBUG "%s wait until sent...\n", tty_name(tty, buf)); 103 printk(KERN_DEBUG "%s wait until sent...\n", tty_name(tty, buf));
59#endif 104#endif
60 if (!tty->driver->chars_in_buffer)
61 return;
62 if (!timeout) 105 if (!timeout)
63 timeout = MAX_SCHEDULE_TIMEOUT; 106 timeout = MAX_SCHEDULE_TIMEOUT;
64 if (wait_event_interruptible_timeout(tty->write_wait, 107 if (wait_event_interruptible_timeout(tty->write_wait,
65 !tty->driver->chars_in_buffer(tty), timeout) < 0) 108 !tty_chars_in_buffer(tty), timeout) >= 0) {
66 return; 109 if (tty->ops->wait_until_sent)
67 if (tty->driver->wait_until_sent) 110 tty->ops->wait_until_sent(tty, timeout);
68 tty->driver->wait_until_sent(tty, timeout); 111 }
69} 112}
70EXPORT_SYMBOL(tty_wait_until_sent); 113EXPORT_SYMBOL(tty_wait_until_sent);
71 114
@@ -393,8 +436,9 @@ EXPORT_SYMBOL(tty_termios_hw_change);
393static void change_termios(struct tty_struct *tty, struct ktermios *new_termios) 436static void change_termios(struct tty_struct *tty, struct ktermios *new_termios)
394{ 437{
395 int canon_change; 438 int canon_change;
396 struct ktermios old_termios = *tty->termios; 439 struct ktermios old_termios;
397 struct tty_ldisc *ld; 440 struct tty_ldisc *ld;
441 unsigned long flags;
398 442
399 /* 443 /*
400 * Perform the actual termios internal changes under lock. 444 * Perform the actual termios internal changes under lock.
@@ -404,7 +448,7 @@ static void change_termios(struct tty_struct *tty, struct ktermios *new_termios)
404 /* FIXME: we need to decide on some locking/ordering semantics 448 /* FIXME: we need to decide on some locking/ordering semantics
405 for the set_termios notification eventually */ 449 for the set_termios notification eventually */
406 mutex_lock(&tty->termios_mutex); 450 mutex_lock(&tty->termios_mutex);
407 451 old_termios = *tty->termios;
408 *tty->termios = *new_termios; 452 *tty->termios = *new_termios;
409 unset_locked_termios(tty->termios, &old_termios, tty->termios_locked); 453 unset_locked_termios(tty->termios, &old_termios, tty->termios_locked);
410 canon_change = (old_termios.c_lflag ^ tty->termios->c_lflag) & ICANON; 454 canon_change = (old_termios.c_lflag ^ tty->termios->c_lflag) & ICANON;
@@ -429,17 +473,19 @@ static void change_termios(struct tty_struct *tty, struct ktermios *new_termios)
429 STOP_CHAR(tty) == '\023' && 473 STOP_CHAR(tty) == '\023' &&
430 START_CHAR(tty) == '\021'); 474 START_CHAR(tty) == '\021');
431 if (old_flow != new_flow) { 475 if (old_flow != new_flow) {
476 spin_lock_irqsave(&tty->ctrl_lock, flags);
432 tty->ctrl_status &= ~(TIOCPKT_DOSTOP | TIOCPKT_NOSTOP); 477 tty->ctrl_status &= ~(TIOCPKT_DOSTOP | TIOCPKT_NOSTOP);
433 if (new_flow) 478 if (new_flow)
434 tty->ctrl_status |= TIOCPKT_DOSTOP; 479 tty->ctrl_status |= TIOCPKT_DOSTOP;
435 else 480 else
436 tty->ctrl_status |= TIOCPKT_NOSTOP; 481 tty->ctrl_status |= TIOCPKT_NOSTOP;
482 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
437 wake_up_interruptible(&tty->link->read_wait); 483 wake_up_interruptible(&tty->link->read_wait);
438 } 484 }
439 } 485 }
440 486
441 if (tty->driver->set_termios) 487 if (tty->ops->set_termios)
442 (*tty->driver->set_termios)(tty, &old_termios); 488 (*tty->ops->set_termios)(tty, &old_termios);
443 else 489 else
444 tty_termios_copy_hw(tty->termios, &old_termios); 490 tty_termios_copy_hw(tty->termios, &old_termios);
445 491
@@ -474,7 +520,9 @@ static int set_termios(struct tty_struct *tty, void __user *arg, int opt)
474 if (retval) 520 if (retval)
475 return retval; 521 return retval;
476 522
523 mutex_lock(&tty->termios_mutex);
477 memcpy(&tmp_termios, tty->termios, sizeof(struct ktermios)); 524 memcpy(&tmp_termios, tty->termios, sizeof(struct ktermios));
525 mutex_unlock(&tty->termios_mutex);
478 526
479 if (opt & TERMIOS_TERMIO) { 527 if (opt & TERMIOS_TERMIO) {
480 if (user_termio_to_kernel_termios(&tmp_termios, 528 if (user_termio_to_kernel_termios(&tmp_termios,
@@ -660,12 +708,14 @@ static int get_tchars(struct tty_struct *tty, struct tchars __user *tchars)
660{ 708{
661 struct tchars tmp; 709 struct tchars tmp;
662 710
711 mutex_lock(&tty->termios_mutex);
663 tmp.t_intrc = tty->termios->c_cc[VINTR]; 712 tmp.t_intrc = tty->termios->c_cc[VINTR];
664 tmp.t_quitc = tty->termios->c_cc[VQUIT]; 713 tmp.t_quitc = tty->termios->c_cc[VQUIT];
665 tmp.t_startc = tty->termios->c_cc[VSTART]; 714 tmp.t_startc = tty->termios->c_cc[VSTART];
666 tmp.t_stopc = tty->termios->c_cc[VSTOP]; 715 tmp.t_stopc = tty->termios->c_cc[VSTOP];
667 tmp.t_eofc = tty->termios->c_cc[VEOF]; 716 tmp.t_eofc = tty->termios->c_cc[VEOF];
668 tmp.t_brkc = tty->termios->c_cc[VEOL2]; /* what is brkc anyway? */ 717 tmp.t_brkc = tty->termios->c_cc[VEOL2]; /* what is brkc anyway? */
718 mutex_unlock(&tty->termios_mutex);
669 return copy_to_user(tchars, &tmp, sizeof(tmp)) ? -EFAULT : 0; 719 return copy_to_user(tchars, &tmp, sizeof(tmp)) ? -EFAULT : 0;
670} 720}
671 721
@@ -675,12 +725,14 @@ static int set_tchars(struct tty_struct *tty, struct tchars __user *tchars)
675 725
676 if (copy_from_user(&tmp, tchars, sizeof(tmp))) 726 if (copy_from_user(&tmp, tchars, sizeof(tmp)))
677 return -EFAULT; 727 return -EFAULT;
728 mutex_lock(&tty->termios_mutex);
678 tty->termios->c_cc[VINTR] = tmp.t_intrc; 729 tty->termios->c_cc[VINTR] = tmp.t_intrc;
679 tty->termios->c_cc[VQUIT] = tmp.t_quitc; 730 tty->termios->c_cc[VQUIT] = tmp.t_quitc;
680 tty->termios->c_cc[VSTART] = tmp.t_startc; 731 tty->termios->c_cc[VSTART] = tmp.t_startc;
681 tty->termios->c_cc[VSTOP] = tmp.t_stopc; 732 tty->termios->c_cc[VSTOP] = tmp.t_stopc;
682 tty->termios->c_cc[VEOF] = tmp.t_eofc; 733 tty->termios->c_cc[VEOF] = tmp.t_eofc;
683 tty->termios->c_cc[VEOL2] = tmp.t_brkc; /* what is brkc anyway? */ 734 tty->termios->c_cc[VEOL2] = tmp.t_brkc; /* what is brkc anyway? */
735 mutex_unlock(&tty->termios_mutex);
684 return 0; 736 return 0;
685} 737}
686#endif 738#endif
@@ -690,6 +742,7 @@ static int get_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars)
690{ 742{
691 struct ltchars tmp; 743 struct ltchars tmp;
692 744
745 mutex_lock(&tty->termios_mutex);
693 tmp.t_suspc = tty->termios->c_cc[VSUSP]; 746 tmp.t_suspc = tty->termios->c_cc[VSUSP];
694 /* what is dsuspc anyway? */ 747 /* what is dsuspc anyway? */
695 tmp.t_dsuspc = tty->termios->c_cc[VSUSP]; 748 tmp.t_dsuspc = tty->termios->c_cc[VSUSP];
@@ -698,6 +751,7 @@ static int get_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars)
698 tmp.t_flushc = tty->termios->c_cc[VEOL2]; 751 tmp.t_flushc = tty->termios->c_cc[VEOL2];
699 tmp.t_werasc = tty->termios->c_cc[VWERASE]; 752 tmp.t_werasc = tty->termios->c_cc[VWERASE];
700 tmp.t_lnextc = tty->termios->c_cc[VLNEXT]; 753 tmp.t_lnextc = tty->termios->c_cc[VLNEXT];
754 mutex_unlock(&tty->termios_mutex);
701 return copy_to_user(ltchars, &tmp, sizeof(tmp)) ? -EFAULT : 0; 755 return copy_to_user(ltchars, &tmp, sizeof(tmp)) ? -EFAULT : 0;
702} 756}
703 757
@@ -708,6 +762,7 @@ static int set_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars)
708 if (copy_from_user(&tmp, ltchars, sizeof(tmp))) 762 if (copy_from_user(&tmp, ltchars, sizeof(tmp)))
709 return -EFAULT; 763 return -EFAULT;
710 764
765 mutex_lock(&tty->termios_mutex);
711 tty->termios->c_cc[VSUSP] = tmp.t_suspc; 766 tty->termios->c_cc[VSUSP] = tmp.t_suspc;
712 /* what is dsuspc anyway? */ 767 /* what is dsuspc anyway? */
713 tty->termios->c_cc[VEOL2] = tmp.t_dsuspc; 768 tty->termios->c_cc[VEOL2] = tmp.t_dsuspc;
@@ -716,6 +771,7 @@ static int set_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars)
716 tty->termios->c_cc[VEOL2] = tmp.t_flushc; 771 tty->termios->c_cc[VEOL2] = tmp.t_flushc;
717 tty->termios->c_cc[VWERASE] = tmp.t_werasc; 772 tty->termios->c_cc[VWERASE] = tmp.t_werasc;
718 tty->termios->c_cc[VLNEXT] = tmp.t_lnextc; 773 tty->termios->c_cc[VLNEXT] = tmp.t_lnextc;
774 mutex_unlock(&tty->termios_mutex);
719 return 0; 775 return 0;
720} 776}
721#endif 777#endif
@@ -732,8 +788,8 @@ static int send_prio_char(struct tty_struct *tty, char ch)
732{ 788{
733 int was_stopped = tty->stopped; 789 int was_stopped = tty->stopped;
734 790
735 if (tty->driver->send_xchar) { 791 if (tty->ops->send_xchar) {
736 tty->driver->send_xchar(tty, ch); 792 tty->ops->send_xchar(tty, ch);
737 return 0; 793 return 0;
738 } 794 }
739 795
@@ -742,7 +798,7 @@ static int send_prio_char(struct tty_struct *tty, char ch)
742 798
743 if (was_stopped) 799 if (was_stopped)
744 start_tty(tty); 800 start_tty(tty);
745 tty->driver->write(tty, &ch, 1); 801 tty->ops->write(tty, &ch, 1);
746 if (was_stopped) 802 if (was_stopped)
747 stop_tty(tty); 803 stop_tty(tty);
748 tty_write_unlock(tty); 804 tty_write_unlock(tty);
@@ -750,6 +806,33 @@ static int send_prio_char(struct tty_struct *tty, char ch)
750} 806}
751 807
752/** 808/**
809 * tty_change_softcar - carrier change ioctl helper
810 * @tty: tty to update
811 * @arg: enable/disable CLOCAL
812 *
813 * Perform a change to the CLOCAL state and call into the driver
814 * layer to make it visible. All done with the termios mutex
815 */
816
817static int tty_change_softcar(struct tty_struct *tty, int arg)
818{
819 int ret = 0;
820 int bit = arg ? CLOCAL : 0;
821 struct ktermios old;
822
823 mutex_lock(&tty->termios_mutex);
824 old = *tty->termios;
825 tty->termios->c_cflag &= ~CLOCAL;
826 tty->termios->c_cflag |= bit;
827 if (tty->ops->set_termios)
828 tty->ops->set_termios(tty, &old);
829 if ((tty->termios->c_cflag & CLOCAL) != bit)
830 ret = -EINVAL;
831 mutex_unlock(&tty->termios_mutex);
832 return ret;
833}
834
835/**
753 * tty_mode_ioctl - mode related ioctls 836 * tty_mode_ioctl - mode related ioctls
754 * @tty: tty for the ioctl 837 * @tty: tty for the ioctl
755 * @file: file pointer for the tty 838 * @file: file pointer for the tty
@@ -859,12 +942,7 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file,
859 case TIOCSSOFTCAR: 942 case TIOCSSOFTCAR:
860 if (get_user(arg, (unsigned int __user *) arg)) 943 if (get_user(arg, (unsigned int __user *) arg))
861 return -EFAULT; 944 return -EFAULT;
862 mutex_lock(&tty->termios_mutex); 945 return tty_change_softcar(tty, arg);
863 tty->termios->c_cflag =
864 ((tty->termios->c_cflag & ~CLOCAL) |
865 (arg ? CLOCAL : 0));
866 mutex_unlock(&tty->termios_mutex);
867 return 0;
868 default: 946 default:
869 return -ENOIOCTLCMD; 947 return -ENOIOCTLCMD;
870 } 948 }
@@ -889,8 +967,7 @@ int tty_perform_flush(struct tty_struct *tty, unsigned long arg)
889 ld->flush_buffer(tty); 967 ld->flush_buffer(tty);
890 /* fall through */ 968 /* fall through */
891 case TCOFLUSH: 969 case TCOFLUSH:
892 if (tty->driver->flush_buffer) 970 tty_driver_flush_buffer(tty);
893 tty->driver->flush_buffer(tty);
894 break; 971 break;
895 default: 972 default:
896 tty_ldisc_deref(ld); 973 tty_ldisc_deref(ld);
@@ -905,6 +982,7 @@ int n_tty_ioctl(struct tty_struct *tty, struct file *file,
905 unsigned int cmd, unsigned long arg) 982 unsigned int cmd, unsigned long arg)
906{ 983{
907 struct tty_struct *real_tty; 984 struct tty_struct *real_tty;
985 unsigned long flags;
908 int retval; 986 int retval;
909 987
910 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && 988 if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
@@ -946,9 +1024,7 @@ int n_tty_ioctl(struct tty_struct *tty, struct file *file,
946 case TCFLSH: 1024 case TCFLSH:
947 return tty_perform_flush(tty, arg); 1025 return tty_perform_flush(tty, arg);
948 case TIOCOUTQ: 1026 case TIOCOUTQ:
949 return put_user(tty->driver->chars_in_buffer ? 1027 return put_user(tty_chars_in_buffer(tty), (int __user *) arg);
950 tty->driver->chars_in_buffer(tty) : 0,
951 (int __user *) arg);
952 case TIOCINQ: 1028 case TIOCINQ:
953 retval = tty->read_cnt; 1029 retval = tty->read_cnt;
954 if (L_ICANON(tty)) 1030 if (L_ICANON(tty))
@@ -963,6 +1039,7 @@ int n_tty_ioctl(struct tty_struct *tty, struct file *file,
963 return -ENOTTY; 1039 return -ENOTTY;
964 if (get_user(pktmode, (int __user *) arg)) 1040 if (get_user(pktmode, (int __user *) arg))
965 return -EFAULT; 1041 return -EFAULT;
1042 spin_lock_irqsave(&tty->ctrl_lock, flags);
966 if (pktmode) { 1043 if (pktmode) {
967 if (!tty->packet) { 1044 if (!tty->packet) {
968 tty->packet = 1; 1045 tty->packet = 1;
@@ -970,6 +1047,7 @@ int n_tty_ioctl(struct tty_struct *tty, struct file *file,
970 } 1047 }
971 } else 1048 } else
972 tty->packet = 0; 1049 tty->packet = 0;
1050 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
973 return 0; 1051 return 0;
974 } 1052 }
975 default: 1053 default:
diff --git a/drivers/char/viocons.c b/drivers/char/viocons.c
index 8de6b95aeb84..3d3e1c2b310f 100644
--- a/drivers/char/viocons.c
+++ b/drivers/char/viocons.c
@@ -628,13 +628,13 @@ static int viotty_write(struct tty_struct *tty, const unsigned char *buf,
628/* 628/*
629 * TTY put_char method 629 * TTY put_char method
630 */ 630 */
631static void viotty_put_char(struct tty_struct *tty, unsigned char ch) 631static int viotty_put_char(struct tty_struct *tty, unsigned char ch)
632{ 632{
633 struct port_info *pi; 633 struct port_info *pi;
634 634
635 pi = get_port_data(tty); 635 pi = get_port_data(tty);
636 if (pi == NULL) 636 if (pi == NULL)
637 return; 637 return 0;
638 638
639 /* This will append '\r' as well if the char is '\n' */ 639 /* This will append '\r' as well if the char is '\n' */
640 if (viochar_is_console(pi)) 640 if (viochar_is_console(pi))
@@ -642,6 +642,7 @@ static void viotty_put_char(struct tty_struct *tty, unsigned char ch)
642 642
643 if (viopath_isactive(pi->lp)) 643 if (viopath_isactive(pi->lp))
644 internal_write(pi, &ch, 1); 644 internal_write(pi, &ch, 1);
645 return 1;
645} 646}
646 647
647/* 648/*
@@ -704,8 +705,11 @@ static int viotty_ioctl(struct tty_struct *tty, struct file *file,
704 case KDSKBLED: 705 case KDSKBLED:
705 return 0; 706 return 0;
706 } 707 }
707 708 /* FIXME: WTF is this being called for ??? */
708 return n_tty_ioctl(tty, file, cmd, arg); 709 lock_kernel();
710 ret = n_tty_ioctl(tty, file, cmd, arg);
711 unlock_kernel();
712 return ret;
709} 713}
710 714
711/* 715/*
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index 1c2660477135..e458b08139af 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -909,15 +909,21 @@ int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int lines)
909 909
910 if (vc->vc_tty) { 910 if (vc->vc_tty) {
911 struct winsize ws, *cws = &vc->vc_tty->winsize; 911 struct winsize ws, *cws = &vc->vc_tty->winsize;
912 unsigned long flags;
912 913
913 memset(&ws, 0, sizeof(ws)); 914 memset(&ws, 0, sizeof(ws));
914 ws.ws_row = vc->vc_rows; 915 ws.ws_row = vc->vc_rows;
915 ws.ws_col = vc->vc_cols; 916 ws.ws_col = vc->vc_cols;
916 ws.ws_ypixel = vc->vc_scan_lines; 917 ws.ws_ypixel = vc->vc_scan_lines;
918
919 mutex_lock(&vc->vc_tty->termios_mutex);
920 spin_lock_irqsave(&vc->vc_tty->ctrl_lock, flags);
917 if ((ws.ws_row != cws->ws_row || ws.ws_col != cws->ws_col) && 921 if ((ws.ws_row != cws->ws_row || ws.ws_col != cws->ws_col) &&
918 vc->vc_tty->pgrp) 922 vc->vc_tty->pgrp)
919 kill_pgrp(vc->vc_tty->pgrp, SIGWINCH, 1); 923 kill_pgrp(vc->vc_tty->pgrp, SIGWINCH, 1);
924 spin_unlock_irqrestore(&vc->vc_tty->ctrl_lock, flags);
920 *cws = ws; 925 *cws = ws;
926 mutex_unlock(&vc->vc_tty->termios_mutex);
921 } 927 }
922 928
923 if (CON_IS_VISIBLE(vc)) 929 if (CON_IS_VISIBLE(vc))
@@ -2541,6 +2547,9 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)
2541 if (get_user(type, p)) 2547 if (get_user(type, p))
2542 return -EFAULT; 2548 return -EFAULT;
2543 ret = 0; 2549 ret = 0;
2550
2551 lock_kernel();
2552
2544 switch (type) 2553 switch (type)
2545 { 2554 {
2546 case TIOCL_SETSEL: 2555 case TIOCL_SETSEL:
@@ -2560,7 +2569,7 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)
2560 ret = sel_loadlut(p); 2569 ret = sel_loadlut(p);
2561 break; 2570 break;
2562 case TIOCL_GETSHIFTSTATE: 2571 case TIOCL_GETSHIFTSTATE:
2563 2572
2564 /* 2573 /*
2565 * Make it possible to react to Shift+Mousebutton. 2574 * Make it possible to react to Shift+Mousebutton.
2566 * Note that 'shift_state' is an undocumented 2575 * Note that 'shift_state' is an undocumented
@@ -2615,6 +2624,7 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)
2615 ret = -EINVAL; 2624 ret = -EINVAL;
2616 break; 2625 break;
2617 } 2626 }
2627 unlock_kernel();
2618 return ret; 2628 return ret;
2619} 2629}
2620 2630
@@ -2632,11 +2642,11 @@ static int con_write(struct tty_struct *tty, const unsigned char *buf, int count
2632 return retval; 2642 return retval;
2633} 2643}
2634 2644
2635static void con_put_char(struct tty_struct *tty, unsigned char ch) 2645static int con_put_char(struct tty_struct *tty, unsigned char ch)
2636{ 2646{
2637 if (in_interrupt()) 2647 if (in_interrupt())
2638 return; /* n_r3964 calls put_char() from interrupt context */ 2648 return 0; /* n_r3964 calls put_char() from interrupt context */
2639 do_con_write(tty, &ch, 1); 2649 return do_con_write(tty, &ch, 1);
2640} 2650}
2641 2651
2642static int con_write_room(struct tty_struct *tty) 2652static int con_write_room(struct tty_struct *tty)
@@ -3829,7 +3839,7 @@ static int con_font_get(struct vc_data *vc, struct console_font_op *op)
3829 goto out; 3839 goto out;
3830 3840
3831 c = (font.width+7)/8 * 32 * font.charcount; 3841 c = (font.width+7)/8 * 32 * font.charcount;
3832 3842
3833 if (op->data && font.charcount > op->charcount) 3843 if (op->data && font.charcount > op->charcount)
3834 rc = -ENOSPC; 3844 rc = -ENOSPC;
3835 if (!(op->flags & KD_FONT_FLAG_OLD)) { 3845 if (!(op->flags & KD_FONT_FLAG_OLD)) {
@@ -3994,6 +4004,7 @@ u16 screen_glyph(struct vc_data *vc, int offset)
3994 c |= 0x100; 4004 c |= 0x100;
3995 return c; 4005 return c;
3996} 4006}
4007EXPORT_SYMBOL_GPL(screen_glyph);
3997 4008
3998/* used by vcs - note the word offset */ 4009/* used by vcs - note the word offset */
3999unsigned short *screen_pos(struct vc_data *vc, int w_offset, int viewed) 4010unsigned short *screen_pos(struct vc_data *vc, int w_offset, int viewed)
diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
index e6f89e8b9258..3211afd9d57e 100644
--- a/drivers/char/vt_ioctl.c
+++ b/drivers/char/vt_ioctl.c
@@ -373,11 +373,17 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
373 unsigned char ucval; 373 unsigned char ucval;
374 void __user *up = (void __user *)arg; 374 void __user *up = (void __user *)arg;
375 int i, perm; 375 int i, perm;
376 376 int ret = 0;
377
377 console = vc->vc_num; 378 console = vc->vc_num;
378 379
379 if (!vc_cons_allocated(console)) /* impossible? */ 380 lock_kernel();
380 return -ENOIOCTLCMD; 381
382 if (!vc_cons_allocated(console)) { /* impossible? */
383 ret = -ENOIOCTLCMD;
384 goto out;
385 }
386
381 387
382 /* 388 /*
383 * To have permissions to do most of the vt ioctls, we either have 389 * To have permissions to do most of the vt ioctls, we either have
@@ -391,15 +397,15 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
391 switch (cmd) { 397 switch (cmd) {
392 case KIOCSOUND: 398 case KIOCSOUND:
393 if (!perm) 399 if (!perm)
394 return -EPERM; 400 goto eperm;
395 if (arg) 401 if (arg)
396 arg = CLOCK_TICK_RATE / arg; 402 arg = CLOCK_TICK_RATE / arg;
397 kd_mksound(arg, 0); 403 kd_mksound(arg, 0);
398 return 0; 404 break;
399 405
400 case KDMKTONE: 406 case KDMKTONE:
401 if (!perm) 407 if (!perm)
402 return -EPERM; 408 goto eperm;
403 { 409 {
404 unsigned int ticks, count; 410 unsigned int ticks, count;
405 411
@@ -412,7 +418,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
412 if (count) 418 if (count)
413 count = CLOCK_TICK_RATE / count; 419 count = CLOCK_TICK_RATE / count;
414 kd_mksound(count, ticks); 420 kd_mksound(count, ticks);
415 return 0; 421 break;
416 } 422 }
417 423
418 case KDGKBTYPE: 424 case KDGKBTYPE:
@@ -435,14 +441,18 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
435 * KDADDIO and KDDELIO may be able to add ports beyond what 441 * KDADDIO and KDDELIO may be able to add ports beyond what
436 * we reject here, but to be safe... 442 * we reject here, but to be safe...
437 */ 443 */
438 if (arg < GPFIRST || arg > GPLAST) 444 if (arg < GPFIRST || arg > GPLAST) {
439 return -EINVAL; 445 ret = -EINVAL;
440 return sys_ioperm(arg, 1, (cmd == KDADDIO)) ? -ENXIO : 0; 446 break;
447 }
448 ret = sys_ioperm(arg, 1, (cmd == KDADDIO)) ? -ENXIO : 0;
449 break;
441 450
442 case KDENABIO: 451 case KDENABIO:
443 case KDDISABIO: 452 case KDDISABIO:
444 return sys_ioperm(GPFIRST, GPNUM, 453 ret = sys_ioperm(GPFIRST, GPNUM,
445 (cmd == KDENABIO)) ? -ENXIO : 0; 454 (cmd == KDENABIO)) ? -ENXIO : 0;
455 break;
446#endif 456#endif
447 457
448 /* Linux m68k/i386 interface for setting the keyboard delay/repeat rate */ 458 /* Linux m68k/i386 interface for setting the keyboard delay/repeat rate */
@@ -450,19 +460,20 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
450 case KDKBDREP: 460 case KDKBDREP:
451 { 461 {
452 struct kbd_repeat kbrep; 462 struct kbd_repeat kbrep;
453 int err;
454 463
455 if (!capable(CAP_SYS_TTY_CONFIG)) 464 if (!capable(CAP_SYS_TTY_CONFIG))
456 return -EPERM; 465 goto eperm;
457 466
458 if (copy_from_user(&kbrep, up, sizeof(struct kbd_repeat))) 467 if (copy_from_user(&kbrep, up, sizeof(struct kbd_repeat))) {
459 return -EFAULT; 468 ret = -EFAULT;
460 err = kbd_rate(&kbrep); 469 break;
461 if (err) 470 }
462 return err; 471 ret = kbd_rate(&kbrep);
472 if (ret)
473 break;
463 if (copy_to_user(up, &kbrep, sizeof(struct kbd_repeat))) 474 if (copy_to_user(up, &kbrep, sizeof(struct kbd_repeat)))
464 return -EFAULT; 475 ret = -EFAULT;
465 return 0; 476 break;
466 } 477 }
467 478
468 case KDSETMODE: 479 case KDSETMODE:
@@ -475,7 +486,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
475 * need to restore their engine state. --BenH 486 * need to restore their engine state. --BenH
476 */ 487 */
477 if (!perm) 488 if (!perm)
478 return -EPERM; 489 goto eperm;
479 switch (arg) { 490 switch (arg) {
480 case KD_GRAPHICS: 491 case KD_GRAPHICS:
481 break; 492 break;
@@ -485,13 +496,14 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
485 case KD_TEXT: 496 case KD_TEXT:
486 break; 497 break;
487 default: 498 default:
488 return -EINVAL; 499 ret = -EINVAL;
500 goto out;
489 } 501 }
490 if (vc->vc_mode == (unsigned char) arg) 502 if (vc->vc_mode == (unsigned char) arg)
491 return 0; 503 break;
492 vc->vc_mode = (unsigned char) arg; 504 vc->vc_mode = (unsigned char) arg;
493 if (console != fg_console) 505 if (console != fg_console)
494 return 0; 506 break;
495 /* 507 /*
496 * explicitly blank/unblank the screen if switching modes 508 * explicitly blank/unblank the screen if switching modes
497 */ 509 */
@@ -501,7 +513,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
501 else 513 else
502 do_blank_screen(1); 514 do_blank_screen(1);
503 release_console_sem(); 515 release_console_sem();
504 return 0; 516 break;
505 517
506 case KDGETMODE: 518 case KDGETMODE:
507 ucval = vc->vc_mode; 519 ucval = vc->vc_mode;
@@ -513,11 +525,12 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
513 * these work like a combination of mmap and KDENABIO. 525 * these work like a combination of mmap and KDENABIO.
514 * this could be easily finished. 526 * this could be easily finished.
515 */ 527 */
516 return -EINVAL; 528 ret = -EINVAL;
529 break;
517 530
518 case KDSKBMODE: 531 case KDSKBMODE:
519 if (!perm) 532 if (!perm)
520 return -EPERM; 533 goto eperm;
521 switch(arg) { 534 switch(arg) {
522 case K_RAW: 535 case K_RAW:
523 kbd->kbdmode = VC_RAW; 536 kbd->kbdmode = VC_RAW;
@@ -534,10 +547,11 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
534 compute_shiftstate(); 547 compute_shiftstate();
535 break; 548 break;
536 default: 549 default:
537 return -EINVAL; 550 ret = -EINVAL;
551 goto out;
538 } 552 }
539 tty_ldisc_flush(tty); 553 tty_ldisc_flush(tty);
540 return 0; 554 break;
541 555
542 case KDGKBMODE: 556 case KDGKBMODE:
543 ucval = ((kbd->kbdmode == VC_RAW) ? K_RAW : 557 ucval = ((kbd->kbdmode == VC_RAW) ? K_RAW :
@@ -557,28 +571,32 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
557 set_vc_kbd_mode(kbd, VC_META); 571 set_vc_kbd_mode(kbd, VC_META);
558 break; 572 break;
559 default: 573 default:
560 return -EINVAL; 574 ret = -EINVAL;
561 } 575 }
562 return 0; 576 break;
563 577
564 case KDGKBMETA: 578 case KDGKBMETA:
565 ucval = (vc_kbd_mode(kbd, VC_META) ? K_ESCPREFIX : K_METABIT); 579 ucval = (vc_kbd_mode(kbd, VC_META) ? K_ESCPREFIX : K_METABIT);
566 setint: 580 setint:
567 return put_user(ucval, (int __user *)arg); 581 ret = put_user(ucval, (int __user *)arg);
582 break;
568 583
569 case KDGETKEYCODE: 584 case KDGETKEYCODE:
570 case KDSETKEYCODE: 585 case KDSETKEYCODE:
571 if(!capable(CAP_SYS_TTY_CONFIG)) 586 if(!capable(CAP_SYS_TTY_CONFIG))
572 perm=0; 587 perm = 0;
573 return do_kbkeycode_ioctl(cmd, up, perm); 588 ret = do_kbkeycode_ioctl(cmd, up, perm);
589 break;
574 590
575 case KDGKBENT: 591 case KDGKBENT:
576 case KDSKBENT: 592 case KDSKBENT:
577 return do_kdsk_ioctl(cmd, up, perm, kbd); 593 ret = do_kdsk_ioctl(cmd, up, perm, kbd);
594 break;
578 595
579 case KDGKBSENT: 596 case KDGKBSENT:
580 case KDSKBSENT: 597 case KDSKBSENT:
581 return do_kdgkb_ioctl(cmd, up, perm); 598 ret = do_kdgkb_ioctl(cmd, up, perm);
599 break;
582 600
583 case KDGKBDIACR: 601 case KDGKBDIACR:
584 { 602 {
@@ -586,26 +604,31 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
586 struct kbdiacr diacr; 604 struct kbdiacr diacr;
587 int i; 605 int i;
588 606
589 if (put_user(accent_table_size, &a->kb_cnt)) 607 if (put_user(accent_table_size, &a->kb_cnt)) {
590 return -EFAULT; 608 ret = -EFAULT;
609 break;
610 }
591 for (i = 0; i < accent_table_size; i++) { 611 for (i = 0; i < accent_table_size; i++) {
592 diacr.diacr = conv_uni_to_8bit(accent_table[i].diacr); 612 diacr.diacr = conv_uni_to_8bit(accent_table[i].diacr);
593 diacr.base = conv_uni_to_8bit(accent_table[i].base); 613 diacr.base = conv_uni_to_8bit(accent_table[i].base);
594 diacr.result = conv_uni_to_8bit(accent_table[i].result); 614 diacr.result = conv_uni_to_8bit(accent_table[i].result);
595 if (copy_to_user(a->kbdiacr + i, &diacr, sizeof(struct kbdiacr))) 615 if (copy_to_user(a->kbdiacr + i, &diacr, sizeof(struct kbdiacr))) {
596 return -EFAULT; 616 ret = -EFAULT;
617 break;
618 }
597 } 619 }
598 return 0; 620 break;
599 } 621 }
600 case KDGKBDIACRUC: 622 case KDGKBDIACRUC:
601 { 623 {
602 struct kbdiacrsuc __user *a = up; 624 struct kbdiacrsuc __user *a = up;
603 625
604 if (put_user(accent_table_size, &a->kb_cnt)) 626 if (put_user(accent_table_size, &a->kb_cnt))
605 return -EFAULT; 627 ret = -EFAULT;
606 if (copy_to_user(a->kbdiacruc, accent_table, accent_table_size*sizeof(struct kbdiacruc))) 628 else if (copy_to_user(a->kbdiacruc, accent_table,
607 return -EFAULT; 629 accent_table_size*sizeof(struct kbdiacruc)))
608 return 0; 630 ret = -EFAULT;
631 break;
609 } 632 }
610 633
611 case KDSKBDIACR: 634 case KDSKBDIACR:
@@ -616,20 +639,26 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
616 int i; 639 int i;
617 640
618 if (!perm) 641 if (!perm)
619 return -EPERM; 642 goto eperm;
620 if (get_user(ct,&a->kb_cnt)) 643 if (get_user(ct,&a->kb_cnt)) {
621 return -EFAULT; 644 ret = -EFAULT;
622 if (ct >= MAX_DIACR) 645 break;
623 return -EINVAL; 646 }
647 if (ct >= MAX_DIACR) {
648 ret = -EINVAL;
649 break;
650 }
624 accent_table_size = ct; 651 accent_table_size = ct;
625 for (i = 0; i < ct; i++) { 652 for (i = 0; i < ct; i++) {
626 if (copy_from_user(&diacr, a->kbdiacr + i, sizeof(struct kbdiacr))) 653 if (copy_from_user(&diacr, a->kbdiacr + i, sizeof(struct kbdiacr))) {
627 return -EFAULT; 654 ret = -EFAULT;
655 break;
656 }
628 accent_table[i].diacr = conv_8bit_to_uni(diacr.diacr); 657 accent_table[i].diacr = conv_8bit_to_uni(diacr.diacr);
629 accent_table[i].base = conv_8bit_to_uni(diacr.base); 658 accent_table[i].base = conv_8bit_to_uni(diacr.base);
630 accent_table[i].result = conv_8bit_to_uni(diacr.result); 659 accent_table[i].result = conv_8bit_to_uni(diacr.result);
631 } 660 }
632 return 0; 661 break;
633 } 662 }
634 663
635 case KDSKBDIACRUC: 664 case KDSKBDIACRUC:
@@ -638,15 +667,19 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
638 unsigned int ct; 667 unsigned int ct;
639 668
640 if (!perm) 669 if (!perm)
641 return -EPERM; 670 goto eperm;
642 if (get_user(ct,&a->kb_cnt)) 671 if (get_user(ct,&a->kb_cnt)) {
643 return -EFAULT; 672 ret = -EFAULT;
644 if (ct >= MAX_DIACR) 673 break;
645 return -EINVAL; 674 }
675 if (ct >= MAX_DIACR) {
676 ret = -EINVAL;
677 break;
678 }
646 accent_table_size = ct; 679 accent_table_size = ct;
647 if (copy_from_user(accent_table, a->kbdiacruc, ct*sizeof(struct kbdiacruc))) 680 if (copy_from_user(accent_table, a->kbdiacruc, ct*sizeof(struct kbdiacruc)))
648 return -EFAULT; 681 ret = -EFAULT;
649 return 0; 682 break;
650 } 683 }
651 684
652 /* the ioctls below read/set the flags usually shown in the leds */ 685 /* the ioctls below read/set the flags usually shown in the leds */
@@ -657,26 +690,29 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
657 690
658 case KDSKBLED: 691 case KDSKBLED:
659 if (!perm) 692 if (!perm)
660 return -EPERM; 693 goto eperm;
661 if (arg & ~0x77) 694 if (arg & ~0x77) {
662 return -EINVAL; 695 ret = -EINVAL;
696 break;
697 }
663 kbd->ledflagstate = (arg & 7); 698 kbd->ledflagstate = (arg & 7);
664 kbd->default_ledflagstate = ((arg >> 4) & 7); 699 kbd->default_ledflagstate = ((arg >> 4) & 7);
665 set_leds(); 700 set_leds();
666 return 0; 701 break;
667 702
668 /* the ioctls below only set the lights, not the functions */ 703 /* the ioctls below only set the lights, not the functions */
669 /* for those, see KDGKBLED and KDSKBLED above */ 704 /* for those, see KDGKBLED and KDSKBLED above */
670 case KDGETLED: 705 case KDGETLED:
671 ucval = getledstate(); 706 ucval = getledstate();
672 setchar: 707 setchar:
673 return put_user(ucval, (char __user *)arg); 708 ret = put_user(ucval, (char __user *)arg);
709 break;
674 710
675 case KDSETLED: 711 case KDSETLED:
676 if (!perm) 712 if (!perm)
677 return -EPERM; 713 goto eperm;
678 setledstate(kbd, arg); 714 setledstate(kbd, arg);
679 return 0; 715 break;
680 716
681 /* 717 /*
682 * A process can indicate its willingness to accept signals 718 * A process can indicate its willingness to accept signals
@@ -688,16 +724,17 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
688 case KDSIGACCEPT: 724 case KDSIGACCEPT:
689 { 725 {
690 if (!perm || !capable(CAP_KILL)) 726 if (!perm || !capable(CAP_KILL))
691 return -EPERM; 727 goto eperm;
692 if (!valid_signal(arg) || arg < 1 || arg == SIGKILL) 728 if (!valid_signal(arg) || arg < 1 || arg == SIGKILL)
693 return -EINVAL; 729 ret = -EINVAL;
694 730 else {
695 spin_lock_irq(&vt_spawn_con.lock); 731 spin_lock_irq(&vt_spawn_con.lock);
696 put_pid(vt_spawn_con.pid); 732 put_pid(vt_spawn_con.pid);
697 vt_spawn_con.pid = get_pid(task_pid(current)); 733 vt_spawn_con.pid = get_pid(task_pid(current));
698 vt_spawn_con.sig = arg; 734 vt_spawn_con.sig = arg;
699 spin_unlock_irq(&vt_spawn_con.lock); 735 spin_unlock_irq(&vt_spawn_con.lock);
700 return 0; 736 }
737 break;
701 } 738 }
702 739
703 case VT_SETMODE: 740 case VT_SETMODE:
@@ -705,11 +742,15 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
705 struct vt_mode tmp; 742 struct vt_mode tmp;
706 743
707 if (!perm) 744 if (!perm)
708 return -EPERM; 745 goto eperm;
709 if (copy_from_user(&tmp, up, sizeof(struct vt_mode))) 746 if (copy_from_user(&tmp, up, sizeof(struct vt_mode))) {
710 return -EFAULT; 747 ret = -EFAULT;
711 if (tmp.mode != VT_AUTO && tmp.mode != VT_PROCESS) 748 goto out;
712 return -EINVAL; 749 }
750 if (tmp.mode != VT_AUTO && tmp.mode != VT_PROCESS) {
751 ret = -EINVAL;
752 goto out;
753 }
713 acquire_console_sem(); 754 acquire_console_sem();
714 vc->vt_mode = tmp; 755 vc->vt_mode = tmp;
715 /* the frsig is ignored, so we set it to 0 */ 756 /* the frsig is ignored, so we set it to 0 */
@@ -719,7 +760,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
719 /* no switch is required -- saw@shade.msu.ru */ 760 /* no switch is required -- saw@shade.msu.ru */
720 vc->vt_newvt = -1; 761 vc->vt_newvt = -1;
721 release_console_sem(); 762 release_console_sem();
722 return 0; 763 break;
723 } 764 }
724 765
725 case VT_GETMODE: 766 case VT_GETMODE:
@@ -732,7 +773,9 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
732 release_console_sem(); 773 release_console_sem();
733 774
734 rc = copy_to_user(up, &tmp, sizeof(struct vt_mode)); 775 rc = copy_to_user(up, &tmp, sizeof(struct vt_mode));
735 return rc ? -EFAULT : 0; 776 if (rc)
777 ret = -EFAULT;
778 break;
736 } 779 }
737 780
738 /* 781 /*
@@ -746,12 +789,16 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
746 unsigned short state, mask; 789 unsigned short state, mask;
747 790
748 if (put_user(fg_console + 1, &vtstat->v_active)) 791 if (put_user(fg_console + 1, &vtstat->v_active))
749 return -EFAULT; 792 ret = -EFAULT;
750 state = 1; /* /dev/tty0 is always open */ 793 else {
751 for (i = 0, mask = 2; i < MAX_NR_CONSOLES && mask; ++i, mask <<= 1) 794 state = 1; /* /dev/tty0 is always open */
752 if (VT_IS_IN_USE(i)) 795 for (i = 0, mask = 2; i < MAX_NR_CONSOLES && mask;
753 state |= mask; 796 ++i, mask <<= 1)
754 return put_user(state, &vtstat->v_state); 797 if (VT_IS_IN_USE(i))
798 state |= mask;
799 ret = put_user(state, &vtstat->v_state);
800 }
801 break;
755 } 802 }
756 803
757 /* 804 /*
@@ -771,27 +818,31 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
771 */ 818 */
772 case VT_ACTIVATE: 819 case VT_ACTIVATE:
773 if (!perm) 820 if (!perm)
774 return -EPERM; 821 goto eperm;
775 if (arg == 0 || arg > MAX_NR_CONSOLES) 822 if (arg == 0 || arg > MAX_NR_CONSOLES)
776 return -ENXIO; 823 ret = -ENXIO;
777 arg--; 824 else {
778 acquire_console_sem(); 825 arg--;
779 i = vc_allocate(arg); 826 acquire_console_sem();
780 release_console_sem(); 827 ret = vc_allocate(arg);
781 if (i) 828 release_console_sem();
782 return i; 829 if (ret)
783 set_console(arg); 830 break;
784 return 0; 831 set_console(arg);
832 }
833 break;
785 834
786 /* 835 /*
787 * wait until the specified VT has been activated 836 * wait until the specified VT has been activated
788 */ 837 */
789 case VT_WAITACTIVE: 838 case VT_WAITACTIVE:
790 if (!perm) 839 if (!perm)
791 return -EPERM; 840 goto eperm;
792 if (arg == 0 || arg > MAX_NR_CONSOLES) 841 if (arg == 0 || arg > MAX_NR_CONSOLES)
793 return -ENXIO; 842 ret = -ENXIO;
794 return vt_waitactive(arg-1); 843 else
844 ret = vt_waitactive(arg - 1);
845 break;
795 846
796 /* 847 /*
797 * If a vt is under process control, the kernel will not switch to it 848 * If a vt is under process control, the kernel will not switch to it
@@ -805,10 +856,12 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
805 */ 856 */
806 case VT_RELDISP: 857 case VT_RELDISP:
807 if (!perm) 858 if (!perm)
808 return -EPERM; 859 goto eperm;
809 if (vc->vt_mode.mode != VT_PROCESS)
810 return -EINVAL;
811 860
861 if (vc->vt_mode.mode != VT_PROCESS) {
862 ret = -EINVAL;
863 break;
864 }
812 /* 865 /*
813 * Switching-from response 866 * Switching-from response
814 */ 867 */
@@ -829,10 +882,10 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
829 int newvt; 882 int newvt;
830 newvt = vc->vt_newvt; 883 newvt = vc->vt_newvt;
831 vc->vt_newvt = -1; 884 vc->vt_newvt = -1;
832 i = vc_allocate(newvt); 885 ret = vc_allocate(newvt);
833 if (i) { 886 if (ret) {
834 release_console_sem(); 887 release_console_sem();
835 return i; 888 break;
836 } 889 }
837 /* 890 /*
838 * When we actually do the console switch, 891 * When we actually do the console switch,
@@ -841,31 +894,27 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
841 */ 894 */
842 complete_change_console(vc_cons[newvt].d); 895 complete_change_console(vc_cons[newvt].d);
843 } 896 }
844 } 897 } else {
845 898 /*
846 /* 899 * Switched-to response
847 * Switched-to response 900 */
848 */
849 else
850 {
851 /* 901 /*
852 * If it's just an ACK, ignore it 902 * If it's just an ACK, ignore it
853 */ 903 */
854 if (arg != VT_ACKACQ) { 904 if (arg != VT_ACKACQ)
855 release_console_sem(); 905 ret = -EINVAL;
856 return -EINVAL;
857 }
858 } 906 }
859 release_console_sem(); 907 release_console_sem();
860 908 break;
861 return 0;
862 909
863 /* 910 /*
864 * Disallocate memory associated to VT (but leave VT1) 911 * Disallocate memory associated to VT (but leave VT1)
865 */ 912 */
866 case VT_DISALLOCATE: 913 case VT_DISALLOCATE:
867 if (arg > MAX_NR_CONSOLES) 914 if (arg > MAX_NR_CONSOLES) {
868 return -ENXIO; 915 ret = -ENXIO;
916 break;
917 }
869 if (arg == 0) { 918 if (arg == 0) {
870 /* deallocate all unused consoles, but leave 0 */ 919 /* deallocate all unused consoles, but leave 0 */
871 acquire_console_sem(); 920 acquire_console_sem();
@@ -877,14 +926,14 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
877 /* deallocate a single console, if possible */ 926 /* deallocate a single console, if possible */
878 arg--; 927 arg--;
879 if (VT_BUSY(arg)) 928 if (VT_BUSY(arg))
880 return -EBUSY; 929 ret = -EBUSY;
881 if (arg) { /* leave 0 */ 930 else if (arg) { /* leave 0 */
882 acquire_console_sem(); 931 acquire_console_sem();
883 vc_deallocate(arg); 932 vc_deallocate(arg);
884 release_console_sem(); 933 release_console_sem();
885 } 934 }
886 } 935 }
887 return 0; 936 break;
888 937
889 case VT_RESIZE: 938 case VT_RESIZE:
890 { 939 {
@@ -893,21 +942,21 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
893 942
894 ushort ll,cc; 943 ushort ll,cc;
895 if (!perm) 944 if (!perm)
896 return -EPERM; 945 goto eperm;
897 if (get_user(ll, &vtsizes->v_rows) || 946 if (get_user(ll, &vtsizes->v_rows) ||
898 get_user(cc, &vtsizes->v_cols)) 947 get_user(cc, &vtsizes->v_cols))
899 return -EFAULT; 948 ret = -EFAULT;
900 949 else {
901 for (i = 0; i < MAX_NR_CONSOLES; i++) { 950 for (i = 0; i < MAX_NR_CONSOLES; i++) {
902 vc = vc_cons[i].d; 951 vc = vc_cons[i].d;
903 952
904 if (vc) { 953 if (vc) {
905 vc->vc_resize_user = 1; 954 vc->vc_resize_user = 1;
906 vc_lock_resize(vc_cons[i].d, cc, ll); 955 vc_lock_resize(vc_cons[i].d, cc, ll);
956 }
907 } 957 }
908 } 958 }
909 959 break;
910 return 0;
911 } 960 }
912 961
913 case VT_RESIZEX: 962 case VT_RESIZEX:
@@ -915,10 +964,13 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
915 struct vt_consize __user *vtconsize = up; 964 struct vt_consize __user *vtconsize = up;
916 ushort ll,cc,vlin,clin,vcol,ccol; 965 ushort ll,cc,vlin,clin,vcol,ccol;
917 if (!perm) 966 if (!perm)
918 return -EPERM; 967 goto eperm;
919 if (!access_ok(VERIFY_READ, vtconsize, 968 if (!access_ok(VERIFY_READ, vtconsize,
920 sizeof(struct vt_consize))) 969 sizeof(struct vt_consize))) {
921 return -EFAULT; 970 ret = -EFAULT;
971 break;
972 }
973 /* FIXME: Should check the copies properly */
922 __get_user(ll, &vtconsize->v_rows); 974 __get_user(ll, &vtconsize->v_rows);
923 __get_user(cc, &vtconsize->v_cols); 975 __get_user(cc, &vtconsize->v_cols);
924 __get_user(vlin, &vtconsize->v_vlin); 976 __get_user(vlin, &vtconsize->v_vlin);
@@ -928,21 +980,28 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
928 vlin = vlin ? vlin : vc->vc_scan_lines; 980 vlin = vlin ? vlin : vc->vc_scan_lines;
929 if (clin) { 981 if (clin) {
930 if (ll) { 982 if (ll) {
931 if (ll != vlin/clin) 983 if (ll != vlin/clin) {
932 return -EINVAL; /* Parameters don't add up */ 984 /* Parameters don't add up */
985 ret = -EINVAL;
986 break;
987 }
933 } else 988 } else
934 ll = vlin/clin; 989 ll = vlin/clin;
935 } 990 }
936 if (vcol && ccol) { 991 if (vcol && ccol) {
937 if (cc) { 992 if (cc) {
938 if (cc != vcol/ccol) 993 if (cc != vcol/ccol) {
939 return -EINVAL; 994 ret = -EINVAL;
995 break;
996 }
940 } else 997 } else
941 cc = vcol/ccol; 998 cc = vcol/ccol;
942 } 999 }
943 1000
944 if (clin > 32) 1001 if (clin > 32) {
945 return -EINVAL; 1002 ret = -EINVAL;
1003 break;
1004 }
946 1005
947 for (i = 0; i < MAX_NR_CONSOLES; i++) { 1006 for (i = 0; i < MAX_NR_CONSOLES; i++) {
948 if (!vc_cons[i].d) 1007 if (!vc_cons[i].d)
@@ -956,19 +1015,20 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
956 vc_resize(vc_cons[i].d, cc, ll); 1015 vc_resize(vc_cons[i].d, cc, ll);
957 release_console_sem(); 1016 release_console_sem();
958 } 1017 }
959 return 0; 1018 break;
960 } 1019 }
961 1020
962 case PIO_FONT: { 1021 case PIO_FONT: {
963 if (!perm) 1022 if (!perm)
964 return -EPERM; 1023 goto eperm;
965 op.op = KD_FONT_OP_SET; 1024 op.op = KD_FONT_OP_SET;
966 op.flags = KD_FONT_FLAG_OLD | KD_FONT_FLAG_DONT_RECALC; /* Compatibility */ 1025 op.flags = KD_FONT_FLAG_OLD | KD_FONT_FLAG_DONT_RECALC; /* Compatibility */
967 op.width = 8; 1026 op.width = 8;
968 op.height = 0; 1027 op.height = 0;
969 op.charcount = 256; 1028 op.charcount = 256;
970 op.data = up; 1029 op.data = up;
971 return con_font_op(vc_cons[fg_console].d, &op); 1030 ret = con_font_op(vc_cons[fg_console].d, &op);
1031 break;
972 } 1032 }
973 1033
974 case GIO_FONT: { 1034 case GIO_FONT: {
@@ -978,100 +1038,124 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
978 op.height = 32; 1038 op.height = 32;
979 op.charcount = 256; 1039 op.charcount = 256;
980 op.data = up; 1040 op.data = up;
981 return con_font_op(vc_cons[fg_console].d, &op); 1041 ret = con_font_op(vc_cons[fg_console].d, &op);
1042 break;
982 } 1043 }
983 1044
984 case PIO_CMAP: 1045 case PIO_CMAP:
985 if (!perm) 1046 if (!perm)
986 return -EPERM; 1047 ret = -EPERM;
987 return con_set_cmap(up); 1048 else
1049 ret = con_set_cmap(up);
1050 break;
988 1051
989 case GIO_CMAP: 1052 case GIO_CMAP:
990 return con_get_cmap(up); 1053 ret = con_get_cmap(up);
1054 break;
991 1055
992 case PIO_FONTX: 1056 case PIO_FONTX:
993 case GIO_FONTX: 1057 case GIO_FONTX:
994 return do_fontx_ioctl(cmd, up, perm, &op); 1058 ret = do_fontx_ioctl(cmd, up, perm, &op);
1059 break;
995 1060
996 case PIO_FONTRESET: 1061 case PIO_FONTRESET:
997 { 1062 {
998 if (!perm) 1063 if (!perm)
999 return -EPERM; 1064 goto eperm;
1000 1065
1001#ifdef BROKEN_GRAPHICS_PROGRAMS 1066#ifdef BROKEN_GRAPHICS_PROGRAMS
1002 /* With BROKEN_GRAPHICS_PROGRAMS defined, the default 1067 /* With BROKEN_GRAPHICS_PROGRAMS defined, the default
1003 font is not saved. */ 1068 font is not saved. */
1004 return -ENOSYS; 1069 ret = -ENOSYS;
1070 break;
1005#else 1071#else
1006 { 1072 {
1007 op.op = KD_FONT_OP_SET_DEFAULT; 1073 op.op = KD_FONT_OP_SET_DEFAULT;
1008 op.data = NULL; 1074 op.data = NULL;
1009 i = con_font_op(vc_cons[fg_console].d, &op); 1075 ret = con_font_op(vc_cons[fg_console].d, &op);
1010 if (i) 1076 if (ret)
1011 return i; 1077 break;
1012 con_set_default_unimap(vc_cons[fg_console].d); 1078 con_set_default_unimap(vc_cons[fg_console].d);
1013 return 0; 1079 break;
1014 } 1080 }
1015#endif 1081#endif
1016 } 1082 }
1017 1083
1018 case KDFONTOP: { 1084 case KDFONTOP: {
1019 if (copy_from_user(&op, up, sizeof(op))) 1085 if (copy_from_user(&op, up, sizeof(op))) {
1020 return -EFAULT; 1086 ret = -EFAULT;
1087 break;
1088 }
1021 if (!perm && op.op != KD_FONT_OP_GET) 1089 if (!perm && op.op != KD_FONT_OP_GET)
1022 return -EPERM; 1090 goto eperm;
1023 i = con_font_op(vc, &op); 1091 ret = con_font_op(vc, &op);
1024 if (i) return i; 1092 if (ret)
1093 break;
1025 if (copy_to_user(up, &op, sizeof(op))) 1094 if (copy_to_user(up, &op, sizeof(op)))
1026 return -EFAULT; 1095 ret = -EFAULT;
1027 return 0; 1096 break;
1028 } 1097 }
1029 1098
1030 case PIO_SCRNMAP: 1099 case PIO_SCRNMAP:
1031 if (!perm) 1100 if (!perm)
1032 return -EPERM; 1101 ret = -EPERM;
1033 return con_set_trans_old(up); 1102 else
1103 ret = con_set_trans_old(up);
1104 break;
1034 1105
1035 case GIO_SCRNMAP: 1106 case GIO_SCRNMAP:
1036 return con_get_trans_old(up); 1107 ret = con_get_trans_old(up);
1108 break;
1037 1109
1038 case PIO_UNISCRNMAP: 1110 case PIO_UNISCRNMAP:
1039 if (!perm) 1111 if (!perm)
1040 return -EPERM; 1112 ret = -EPERM;
1041 return con_set_trans_new(up); 1113 else
1114 ret = con_set_trans_new(up);
1115 break;
1042 1116
1043 case GIO_UNISCRNMAP: 1117 case GIO_UNISCRNMAP:
1044 return con_get_trans_new(up); 1118 ret = con_get_trans_new(up);
1119 break;
1045 1120
1046 case PIO_UNIMAPCLR: 1121 case PIO_UNIMAPCLR:
1047 { struct unimapinit ui; 1122 { struct unimapinit ui;
1048 if (!perm) 1123 if (!perm)
1049 return -EPERM; 1124 goto eperm;
1050 i = copy_from_user(&ui, up, sizeof(struct unimapinit)); 1125 ret = copy_from_user(&ui, up, sizeof(struct unimapinit));
1051 if (i) return -EFAULT; 1126 if (!ret)
1052 con_clear_unimap(vc, &ui); 1127 con_clear_unimap(vc, &ui);
1053 return 0; 1128 break;
1054 } 1129 }
1055 1130
1056 case PIO_UNIMAP: 1131 case PIO_UNIMAP:
1057 case GIO_UNIMAP: 1132 case GIO_UNIMAP:
1058 return do_unimap_ioctl(cmd, up, perm, vc); 1133 ret = do_unimap_ioctl(cmd, up, perm, vc);
1134 break;
1059 1135
1060 case VT_LOCKSWITCH: 1136 case VT_LOCKSWITCH:
1061 if (!capable(CAP_SYS_TTY_CONFIG)) 1137 if (!capable(CAP_SYS_TTY_CONFIG))
1062 return -EPERM; 1138 goto eperm;
1063 vt_dont_switch = 1; 1139 vt_dont_switch = 1;
1064 return 0; 1140 break;
1065 case VT_UNLOCKSWITCH: 1141 case VT_UNLOCKSWITCH:
1066 if (!capable(CAP_SYS_TTY_CONFIG)) 1142 if (!capable(CAP_SYS_TTY_CONFIG))
1067 return -EPERM; 1143 goto eperm;
1068 vt_dont_switch = 0; 1144 vt_dont_switch = 0;
1069 return 0; 1145 break;
1070 case VT_GETHIFONTMASK: 1146 case VT_GETHIFONTMASK:
1071 return put_user(vc->vc_hi_font_mask, (unsigned short __user *)arg); 1147 ret = put_user(vc->vc_hi_font_mask,
1148 (unsigned short __user *)arg);
1149 break;
1072 default: 1150 default:
1073 return -ENOIOCTLCMD; 1151 ret = -ENOIOCTLCMD;
1074 } 1152 }
1153out:
1154 unlock_kernel();
1155 return ret;
1156eperm:
1157 ret = -EPERM;
1158 goto out;
1075} 1159}
1076 1160
1077/* 1161/*
diff --git a/drivers/char/xilinx_hwicap/xilinx_hwicap.c b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
index dfe6907ae15b..3edf1fc12963 100644
--- a/drivers/char/xilinx_hwicap/xilinx_hwicap.c
+++ b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
@@ -623,8 +623,8 @@ static int __devinit hwicap_setup(struct device *dev, int id,
623 623
624 if (!request_mem_region(drvdata->mem_start, 624 if (!request_mem_region(drvdata->mem_start,
625 drvdata->mem_size, DRIVER_NAME)) { 625 drvdata->mem_size, DRIVER_NAME)) {
626 dev_err(dev, "Couldn't lock memory region at %p\n", 626 dev_err(dev, "Couldn't lock memory region at %Lx\n",
627 (void *)regs_res->start); 627 regs_res->start);
628 retval = -EBUSY; 628 retval = -EBUSY;
629 goto failed1; 629 goto failed1;
630 } 630 }
@@ -643,7 +643,7 @@ static int __devinit hwicap_setup(struct device *dev, int id,
643 mutex_init(&drvdata->sem); 643 mutex_init(&drvdata->sem);
644 drvdata->is_open = 0; 644 drvdata->is_open = 0;
645 645
646 dev_info(dev, "ioremap %lx to %p with size %x\n", 646 dev_info(dev, "ioremap %lx to %p with size %Lx\n",
647 (unsigned long int)drvdata->mem_start, 647 (unsigned long int)drvdata->mem_start,
648 drvdata->base_address, drvdata->mem_size); 648 drvdata->base_address, drvdata->mem_size);
649 649
diff --git a/drivers/edac/edac_core.h b/drivers/edac/edac_core.h
index a9aa845dbe74..b27b13c5eb5a 100644
--- a/drivers/edac/edac_core.h
+++ b/drivers/edac/edac_core.h
@@ -97,7 +97,7 @@ extern int edac_debug_level;
97#define PCI_VEND_DEV(vend, dev) PCI_VENDOR_ID_ ## vend, \ 97#define PCI_VEND_DEV(vend, dev) PCI_VENDOR_ID_ ## vend, \
98 PCI_DEVICE_ID_ ## vend ## _ ## dev 98 PCI_DEVICE_ID_ ## vend ## _ ## dev
99 99
100#define dev_name(dev) (dev)->dev_name 100#define edac_dev_name(dev) (dev)->dev_name
101 101
102/* memory devices */ 102/* memory devices */
103enum dev_type { 103enum dev_type {
diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
index 63372fa7ecfe..5fcd3d89c75d 100644
--- a/drivers/edac/edac_device.c
+++ b/drivers/edac/edac_device.c
@@ -333,7 +333,7 @@ static int add_edac_dev_to_global_list(struct edac_device_ctl_info *edac_dev)
333fail0: 333fail0:
334 edac_printk(KERN_WARNING, EDAC_MC, 334 edac_printk(KERN_WARNING, EDAC_MC,
335 "%s (%s) %s %s already assigned %d\n", 335 "%s (%s) %s %s already assigned %d\n",
336 rover->dev->bus_id, dev_name(rover), 336 rover->dev->bus_id, edac_dev_name(rover),
337 rover->mod_name, rover->ctl_name, rover->dev_idx); 337 rover->mod_name, rover->ctl_name, rover->dev_idx);
338 return 1; 338 return 1;
339 339
@@ -538,7 +538,7 @@ int edac_device_add_device(struct edac_device_ctl_info *edac_dev)
538 "'%s': DEV '%s' (%s)\n", 538 "'%s': DEV '%s' (%s)\n",
539 edac_dev->mod_name, 539 edac_dev->mod_name,
540 edac_dev->ctl_name, 540 edac_dev->ctl_name,
541 dev_name(edac_dev), 541 edac_dev_name(edac_dev),
542 edac_op_state_to_string(edac_dev->op_state)); 542 edac_op_state_to_string(edac_dev->op_state));
543 543
544 mutex_unlock(&device_ctls_mutex); 544 mutex_unlock(&device_ctls_mutex);
@@ -599,7 +599,7 @@ struct edac_device_ctl_info *edac_device_del_device(struct device *dev)
599 edac_printk(KERN_INFO, EDAC_MC, 599 edac_printk(KERN_INFO, EDAC_MC,
600 "Removed device %d for %s %s: DEV %s\n", 600 "Removed device %d for %s %s: DEV %s\n",
601 edac_dev->dev_idx, 601 edac_dev->dev_idx,
602 edac_dev->mod_name, edac_dev->ctl_name, dev_name(edac_dev)); 602 edac_dev->mod_name, edac_dev->ctl_name, edac_dev_name(edac_dev));
603 603
604 return edac_dev; 604 return edac_dev;
605} 605}
diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c
index a4cf1645f588..d110392d48f4 100644
--- a/drivers/edac/edac_mc.c
+++ b/drivers/edac/edac_mc.c
@@ -402,7 +402,7 @@ static int add_mc_to_global_list(struct mem_ctl_info *mci)
402fail0: 402fail0:
403 edac_printk(KERN_WARNING, EDAC_MC, 403 edac_printk(KERN_WARNING, EDAC_MC,
404 "%s (%s) %s %s already assigned %d\n", p->dev->bus_id, 404 "%s (%s) %s %s already assigned %d\n", p->dev->bus_id,
405 dev_name(mci), p->mod_name, p->ctl_name, p->mc_idx); 405 edac_dev_name(mci), p->mod_name, p->ctl_name, p->mc_idx);
406 return 1; 406 return 1;
407 407
408fail1: 408fail1:
@@ -517,7 +517,7 @@ int edac_mc_add_mc(struct mem_ctl_info *mci)
517 517
518 /* Report action taken */ 518 /* Report action taken */
519 edac_mc_printk(mci, KERN_INFO, "Giving out device to '%s' '%s':" 519 edac_mc_printk(mci, KERN_INFO, "Giving out device to '%s' '%s':"
520 " DEV %s\n", mci->mod_name, mci->ctl_name, dev_name(mci)); 520 " DEV %s\n", mci->mod_name, mci->ctl_name, edac_dev_name(mci));
521 521
522 mutex_unlock(&mem_ctls_mutex); 522 mutex_unlock(&mem_ctls_mutex);
523 return 0; 523 return 0;
@@ -565,7 +565,7 @@ struct mem_ctl_info *edac_mc_del_mc(struct device *dev)
565 565
566 edac_printk(KERN_INFO, EDAC_MC, 566 edac_printk(KERN_INFO, EDAC_MC,
567 "Removed device %d for %s %s: DEV %s\n", mci->mc_idx, 567 "Removed device %d for %s %s: DEV %s\n", mci->mc_idx,
568 mci->mod_name, mci->ctl_name, dev_name(mci)); 568 mci->mod_name, mci->ctl_name, edac_dev_name(mci));
569 569
570 return mci; 570 return mci;
571} 571}
diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
index 9b24340b52e1..22ec9d5d4312 100644
--- a/drivers/edac/edac_pci.c
+++ b/drivers/edac/edac_pci.c
@@ -150,7 +150,7 @@ static int add_edac_pci_to_global_list(struct edac_pci_ctl_info *pci)
150fail0: 150fail0:
151 edac_printk(KERN_WARNING, EDAC_PCI, 151 edac_printk(KERN_WARNING, EDAC_PCI,
152 "%s (%s) %s %s already assigned %d\n", 152 "%s (%s) %s %s already assigned %d\n",
153 rover->dev->bus_id, dev_name(rover), 153 rover->dev->bus_id, edac_dev_name(rover),
154 rover->mod_name, rover->ctl_name, rover->pci_idx); 154 rover->mod_name, rover->ctl_name, rover->pci_idx);
155 return 1; 155 return 1;
156 156
@@ -360,7 +360,7 @@ int edac_pci_add_device(struct edac_pci_ctl_info *pci, int edac_idx)
360 " DEV '%s' (%s)\n", 360 " DEV '%s' (%s)\n",
361 pci->mod_name, 361 pci->mod_name,
362 pci->ctl_name, 362 pci->ctl_name,
363 dev_name(pci), edac_op_state_to_string(pci->op_state)); 363 edac_dev_name(pci), edac_op_state_to_string(pci->op_state));
364 364
365 mutex_unlock(&edac_pci_ctls_mutex); 365 mutex_unlock(&edac_pci_ctls_mutex);
366 return 0; 366 return 0;
@@ -415,7 +415,7 @@ struct edac_pci_ctl_info *edac_pci_del_device(struct device *dev)
415 415
416 edac_printk(KERN_INFO, EDAC_PCI, 416 edac_printk(KERN_INFO, EDAC_PCI,
417 "Removed device %d for %s %s: DEV %s\n", 417 "Removed device %d for %s %s: DEV %s\n",
418 pci->pci_idx, pci->mod_name, pci->ctl_name, dev_name(pci)); 418 pci->pci_idx, pci->mod_name, pci->ctl_name, edac_dev_name(pci));
419 419
420 return pci; 420 return pci;
421} 421}
diff --git a/drivers/edac/pasemi_edac.c b/drivers/edac/pasemi_edac.c
index 3fd65a563848..8e6b91bd2e99 100644
--- a/drivers/edac/pasemi_edac.c
+++ b/drivers/edac/pasemi_edac.c
@@ -26,6 +26,7 @@
26#include <linux/pci.h> 26#include <linux/pci.h>
27#include <linux/pci_ids.h> 27#include <linux/pci_ids.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/edac.h>
29#include "edac_core.h" 30#include "edac_core.h"
30 31
31#define MODULE_NAME "pasemi_edac" 32#define MODULE_NAME "pasemi_edac"
diff --git a/drivers/firewire/fw-sbp2.c b/drivers/firewire/fw-sbp2.c
index 2a999373863e..b2458bb8e9ca 100644
--- a/drivers/firewire/fw-sbp2.c
+++ b/drivers/firewire/fw-sbp2.c
@@ -784,7 +784,7 @@ static void sbp2_release_target(struct kref *kref)
784 kfree(lu); 784 kfree(lu);
785 } 785 }
786 scsi_remove_host(shost); 786 scsi_remove_host(shost);
787 fw_notify("released %s\n", tgt->bus_id); 787 fw_notify("released %s, target %d:0:0\n", tgt->bus_id, shost->host_no);
788 788
789 fw_unit_put(tgt->unit); 789 fw_unit_put(tgt->unit);
790 scsi_host_put(shost); 790 scsi_host_put(shost);
@@ -1487,7 +1487,7 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
1487 if (scsi_sg_count(cmd) && sbp2_map_scatterlist(orb, device, lu) < 0) 1487 if (scsi_sg_count(cmd) && sbp2_map_scatterlist(orb, device, lu) < 0)
1488 goto out; 1488 goto out;
1489 1489
1490 memcpy(orb->request.command_block, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd)); 1490 memcpy(orb->request.command_block, cmd->cmnd, cmd->cmd_len);
1491 1491
1492 orb->base.callback = complete_command_orb; 1492 orb->base.callback = complete_command_orb;
1493 orb->base.request_bus = 1493 orb->base.request_bus =
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 24c62b848bf9..7f138c6195ff 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -382,7 +382,7 @@ fail:
382 spin_unlock_irqrestore(&gpio_lock, flags); 382 spin_unlock_irqrestore(&gpio_lock, flags);
383 if (status) 383 if (status)
384 pr_debug("%s: gpio-%d status %d\n", 384 pr_debug("%s: gpio-%d status %d\n",
385 __FUNCTION__, gpio, status); 385 __func__, gpio, status);
386 return status; 386 return status;
387} 387}
388EXPORT_SYMBOL_GPL(gpio_direction_input); 388EXPORT_SYMBOL_GPL(gpio_direction_input);
@@ -420,7 +420,7 @@ fail:
420 spin_unlock_irqrestore(&gpio_lock, flags); 420 spin_unlock_irqrestore(&gpio_lock, flags);
421 if (status) 421 if (status)
422 pr_debug("%s: gpio-%d status %d\n", 422 pr_debug("%s: gpio-%d status %d\n",
423 __FUNCTION__, gpio, status); 423 __func__, gpio, status);
424 return status; 424 return status;
425} 425}
426EXPORT_SYMBOL_GPL(gpio_direction_output); 426EXPORT_SYMBOL_GPL(gpio_direction_output);
diff --git a/drivers/gpio/pca953x.c b/drivers/gpio/pca953x.c
index 5a99e81d2784..93f916720b13 100644
--- a/drivers/gpio/pca953x.c
+++ b/drivers/gpio/pca953x.c
@@ -30,6 +30,8 @@ static const struct i2c_device_id pca953x_id[] = {
30 { "pca9537", 4, }, 30 { "pca9537", 4, },
31 { "pca9538", 8, }, 31 { "pca9538", 8, },
32 { "pca9539", 16, }, 32 { "pca9539", 16, },
33 { "pca9555", 16, },
34 { "pca9557", 8, },
33 /* REVISIT several pca955x parts should work here too */ 35 /* REVISIT several pca955x parts should work here too */
34 { } 36 { }
35}; 37};
@@ -193,7 +195,7 @@ static int __devinit pca953x_probe(struct i2c_client *client,
193{ 195{
194 struct pca953x_platform_data *pdata; 196 struct pca953x_platform_data *pdata;
195 struct pca953x_chip *chip; 197 struct pca953x_chip *chip;
196 int ret, i; 198 int ret;
197 199
198 pdata = client->dev.platform_data; 200 pdata = client->dev.platform_data;
199 if (pdata == NULL) 201 if (pdata == NULL)
diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c
index ed71a8bc70dc..5c8b6e0ff47c 100644
--- a/drivers/hwmon/ads7828.c
+++ b/drivers/hwmon/ads7828.c
@@ -224,7 +224,7 @@ static int ads7828_detect(struct i2c_adapter *adapter, int address, int kind)
224 if (in_data & 0xF000) { 224 if (in_data & 0xF000) {
225 printk(KERN_DEBUG 225 printk(KERN_DEBUG
226 "%s : Doesn't look like an ads7828 device\n", 226 "%s : Doesn't look like an ads7828 device\n",
227 __FUNCTION__); 227 __func__);
228 goto exit_free; 228 goto exit_free;
229 } 229 }
230 } 230 }
diff --git a/drivers/hwmon/adt7473.c b/drivers/hwmon/adt7473.c
index 9587869bdba0..c1009d6f9796 100644
--- a/drivers/hwmon/adt7473.c
+++ b/drivers/hwmon/adt7473.c
@@ -422,18 +422,14 @@ static ssize_t show_volt(struct device *dev, struct device_attribute *devattr,
422 * number in the range -128 to 127, or as an unsigned number that must 422 * number in the range -128 to 127, or as an unsigned number that must
423 * be offset by 64. 423 * be offset by 64.
424 */ 424 */
425static int decode_temp(struct adt7473_data *data, u8 raw) 425static int decode_temp(u8 twos_complement, u8 raw)
426{ 426{
427 if (data->temp_twos_complement) 427 return twos_complement ? (s8)raw : raw - 64;
428 return (s8)raw;
429 return raw - 64;
430} 428}
431 429
432static u8 encode_temp(struct adt7473_data *data, int cooked) 430static u8 encode_temp(u8 twos_complement, int cooked)
433{ 431{
434 if (data->temp_twos_complement) 432 return twos_complement ? cooked & 0xFF : cooked + 64;
435 return (cooked & 0xFF);
436 return cooked + 64;
437} 433}
438 434
439static ssize_t show_temp_min(struct device *dev, 435static ssize_t show_temp_min(struct device *dev,
@@ -442,8 +438,9 @@ static ssize_t show_temp_min(struct device *dev,
442{ 438{
443 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 439 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
444 struct adt7473_data *data = adt7473_update_device(dev); 440 struct adt7473_data *data = adt7473_update_device(dev);
445 return sprintf(buf, "%d\n", 441 return sprintf(buf, "%d\n", 1000 * decode_temp(
446 1000 * decode_temp(data, data->temp_min[attr->index])); 442 data->temp_twos_complement,
443 data->temp_min[attr->index]));
447} 444}
448 445
449static ssize_t set_temp_min(struct device *dev, 446static ssize_t set_temp_min(struct device *dev,
@@ -455,7 +452,7 @@ static ssize_t set_temp_min(struct device *dev,
455 struct i2c_client *client = to_i2c_client(dev); 452 struct i2c_client *client = to_i2c_client(dev);
456 struct adt7473_data *data = i2c_get_clientdata(client); 453 struct adt7473_data *data = i2c_get_clientdata(client);
457 int temp = simple_strtol(buf, NULL, 10) / 1000; 454 int temp = simple_strtol(buf, NULL, 10) / 1000;
458 temp = encode_temp(data, temp); 455 temp = encode_temp(data->temp_twos_complement, temp);
459 456
460 mutex_lock(&data->lock); 457 mutex_lock(&data->lock);
461 data->temp_min[attr->index] = temp; 458 data->temp_min[attr->index] = temp;
@@ -472,8 +469,9 @@ static ssize_t show_temp_max(struct device *dev,
472{ 469{
473 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 470 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
474 struct adt7473_data *data = adt7473_update_device(dev); 471 struct adt7473_data *data = adt7473_update_device(dev);
475 return sprintf(buf, "%d\n", 472 return sprintf(buf, "%d\n", 1000 * decode_temp(
476 1000 * decode_temp(data, data->temp_max[attr->index])); 473 data->temp_twos_complement,
474 data->temp_max[attr->index]));
477} 475}
478 476
479static ssize_t set_temp_max(struct device *dev, 477static ssize_t set_temp_max(struct device *dev,
@@ -485,7 +483,7 @@ static ssize_t set_temp_max(struct device *dev,
485 struct i2c_client *client = to_i2c_client(dev); 483 struct i2c_client *client = to_i2c_client(dev);
486 struct adt7473_data *data = i2c_get_clientdata(client); 484 struct adt7473_data *data = i2c_get_clientdata(client);
487 int temp = simple_strtol(buf, NULL, 10) / 1000; 485 int temp = simple_strtol(buf, NULL, 10) / 1000;
488 temp = encode_temp(data, temp); 486 temp = encode_temp(data->temp_twos_complement, temp);
489 487
490 mutex_lock(&data->lock); 488 mutex_lock(&data->lock);
491 data->temp_max[attr->index] = temp; 489 data->temp_max[attr->index] = temp;
@@ -501,8 +499,9 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
501{ 499{
502 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 500 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
503 struct adt7473_data *data = adt7473_update_device(dev); 501 struct adt7473_data *data = adt7473_update_device(dev);
504 return sprintf(buf, "%d\n", 502 return sprintf(buf, "%d\n", 1000 * decode_temp(
505 1000 * decode_temp(data, data->temp[attr->index])); 503 data->temp_twos_complement,
504 data->temp[attr->index]));
506} 505}
507 506
508static ssize_t show_fan_min(struct device *dev, 507static ssize_t show_fan_min(struct device *dev,
@@ -671,8 +670,9 @@ static ssize_t show_temp_tmax(struct device *dev,
671{ 670{
672 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 671 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
673 struct adt7473_data *data = adt7473_update_device(dev); 672 struct adt7473_data *data = adt7473_update_device(dev);
674 return sprintf(buf, "%d\n", 673 return sprintf(buf, "%d\n", 1000 * decode_temp(
675 1000 * decode_temp(data, data->temp_tmax[attr->index])); 674 data->temp_twos_complement,
675 data->temp_tmax[attr->index]));
676} 676}
677 677
678static ssize_t set_temp_tmax(struct device *dev, 678static ssize_t set_temp_tmax(struct device *dev,
@@ -684,7 +684,7 @@ static ssize_t set_temp_tmax(struct device *dev,
684 struct i2c_client *client = to_i2c_client(dev); 684 struct i2c_client *client = to_i2c_client(dev);
685 struct adt7473_data *data = i2c_get_clientdata(client); 685 struct adt7473_data *data = i2c_get_clientdata(client);
686 int temp = simple_strtol(buf, NULL, 10) / 1000; 686 int temp = simple_strtol(buf, NULL, 10) / 1000;
687 temp = encode_temp(data, temp); 687 temp = encode_temp(data->temp_twos_complement, temp);
688 688
689 mutex_lock(&data->lock); 689 mutex_lock(&data->lock);
690 data->temp_tmax[attr->index] = temp; 690 data->temp_tmax[attr->index] = temp;
@@ -701,8 +701,9 @@ static ssize_t show_temp_tmin(struct device *dev,
701{ 701{
702 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 702 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
703 struct adt7473_data *data = adt7473_update_device(dev); 703 struct adt7473_data *data = adt7473_update_device(dev);
704 return sprintf(buf, "%d\n", 704 return sprintf(buf, "%d\n", 1000 * decode_temp(
705 1000 * decode_temp(data, data->temp_tmin[attr->index])); 705 data->temp_twos_complement,
706 data->temp_tmin[attr->index]));
706} 707}
707 708
708static ssize_t set_temp_tmin(struct device *dev, 709static ssize_t set_temp_tmin(struct device *dev,
@@ -714,7 +715,7 @@ static ssize_t set_temp_tmin(struct device *dev,
714 struct i2c_client *client = to_i2c_client(dev); 715 struct i2c_client *client = to_i2c_client(dev);
715 struct adt7473_data *data = i2c_get_clientdata(client); 716 struct adt7473_data *data = i2c_get_clientdata(client);
716 int temp = simple_strtol(buf, NULL, 10) / 1000; 717 int temp = simple_strtol(buf, NULL, 10) / 1000;
717 temp = encode_temp(data, temp); 718 temp = encode_temp(data->temp_twos_complement, temp);
718 719
719 mutex_lock(&data->lock); 720 mutex_lock(&data->lock);
720 data->temp_tmin[attr->index] = temp; 721 data->temp_tmin[attr->index] = temp;
diff --git a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c
index 84712a22acea..fe2eea4d799b 100644
--- a/drivers/hwmon/asb100.c
+++ b/drivers/hwmon/asb100.c
@@ -953,12 +953,8 @@ static void asb100_write_value(struct i2c_client *client, u16 reg, u16 value)
953static void asb100_init_client(struct i2c_client *client) 953static void asb100_init_client(struct i2c_client *client)
954{ 954{
955 struct asb100_data *data = i2c_get_clientdata(client); 955 struct asb100_data *data = i2c_get_clientdata(client);
956 int vid = 0;
957 956
958 vid = asb100_read_value(client, ASB100_REG_VID_FANDIV) & 0x0f;
959 vid |= (asb100_read_value(client, ASB100_REG_CHIPID) & 0x01) << 4;
960 data->vrm = vid_which_vrm(); 957 data->vrm = vid_which_vrm();
961 vid = vid_from_reg(vid, data->vrm);
962 958
963 /* Start monitoring */ 959 /* Start monitoring */
964 asb100_write_value(client, ASB100_REG_CONFIG, 960 asb100_write_value(client, ASB100_REG_CONFIG,
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index 115f4090b98e..fa7696905154 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -248,7 +248,7 @@ static int lm75_detach_client(struct i2c_client *client)
248 248
249/* All registers are word-sized, except for the configuration register. 249/* All registers are word-sized, except for the configuration register.
250 LM75 uses a high-byte first convention, which is exactly opposite to 250 LM75 uses a high-byte first convention, which is exactly opposite to
251 the usual practice. */ 251 the SMBus standard. */
252static int lm75_read_value(struct i2c_client *client, u8 reg) 252static int lm75_read_value(struct i2c_client *client, u8 reg)
253{ 253{
254 if (reg == LM75_REG_CONF) 254 if (reg == LM75_REG_CONF)
@@ -257,9 +257,6 @@ static int lm75_read_value(struct i2c_client *client, u8 reg)
257 return swab16(i2c_smbus_read_word_data(client, reg)); 257 return swab16(i2c_smbus_read_word_data(client, reg));
258} 258}
259 259
260/* All registers are word-sized, except for the configuration register.
261 LM75 uses a high-byte first convention, which is exactly opposite to
262 the usual practice. */
263static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value) 260static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value)
264{ 261{
265 if (reg == LM75_REG_CONF) 262 if (reg == LM75_REG_CONF)
diff --git a/drivers/hwmon/smsc47b397.c b/drivers/hwmon/smsc47b397.c
index f61d8f4185b2..eb03544c731c 100644
--- a/drivers/hwmon/smsc47b397.c
+++ b/drivers/hwmon/smsc47b397.c
@@ -335,11 +335,23 @@ exit:
335static int __init smsc47b397_find(unsigned short *addr) 335static int __init smsc47b397_find(unsigned short *addr)
336{ 336{
337 u8 id, rev; 337 u8 id, rev;
338 char *name;
338 339
339 superio_enter(); 340 superio_enter();
340 id = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID); 341 id = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID);
341 342
342 if ((id != 0x6f) && (id != 0x81) && (id != 0x85)) { 343 switch(id) {
344 case 0x81:
345 name = "SCH5307-NS";
346 break;
347 case 0x6f:
348 name = "LPC47B397-NC";
349 break;
350 case 0x85:
351 case 0x8c:
352 name = "SCH5317";
353 break;
354 default:
343 superio_exit(); 355 superio_exit();
344 return -ENODEV; 356 return -ENODEV;
345 } 357 }
@@ -352,8 +364,7 @@ static int __init smsc47b397_find(unsigned short *addr)
352 364
353 printk(KERN_INFO DRVNAME ": found SMSC %s " 365 printk(KERN_INFO DRVNAME ": found SMSC %s "
354 "(base address 0x%04x, revision %u)\n", 366 "(base address 0x%04x, revision %u)\n",
355 id == 0x81 ? "SCH5307-NS" : id == 0x85 ? "SCH5317" : 367 name, *addr, rev);
356 "LPC47B397-NC", *addr, rev);
357 368
358 superio_exit(); 369 superio_exit();
359 return 0; 370 return 0;
diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
index ee35af93b574..ed3c019b78c7 100644
--- a/drivers/hwmon/w83793.c
+++ b/drivers/hwmon/w83793.c
@@ -1024,10 +1024,9 @@ static struct sensor_device_attribute_2 w83793_vid[] = {
1024 SENSOR_ATTR_2(cpu0_vid, S_IRUGO, show_vid, NULL, NOT_USED, 0), 1024 SENSOR_ATTR_2(cpu0_vid, S_IRUGO, show_vid, NULL, NOT_USED, 0),
1025 SENSOR_ATTR_2(cpu1_vid, S_IRUGO, show_vid, NULL, NOT_USED, 1), 1025 SENSOR_ATTR_2(cpu1_vid, S_IRUGO, show_vid, NULL, NOT_USED, 1),
1026}; 1026};
1027static DEVICE_ATTR(vrm, S_IWUSR | S_IRUGO, show_vrm, store_vrm);
1027 1028
1028static struct sensor_device_attribute_2 sda_single_files[] = { 1029static struct sensor_device_attribute_2 sda_single_files[] = {
1029 SENSOR_ATTR_2(vrm, S_IWUSR | S_IRUGO, show_vrm, store_vrm,
1030 NOT_USED, NOT_USED),
1031 SENSOR_ATTR_2(chassis, S_IWUSR | S_IRUGO, show_alarm_beep, 1030 SENSOR_ATTR_2(chassis, S_IWUSR | S_IRUGO, show_alarm_beep,
1032 store_chassis_clear, ALARM_STATUS, 30), 1031 store_chassis_clear, ALARM_STATUS, 30),
1033 SENSOR_ATTR_2(beep_enable, S_IWUSR | S_IRUGO, show_beep_enable, 1032 SENSOR_ATTR_2(beep_enable, S_IWUSR | S_IRUGO, show_beep_enable,
@@ -1080,6 +1079,7 @@ static int w83793_detach_client(struct i2c_client *client)
1080 1079
1081 for (i = 0; i < ARRAY_SIZE(w83793_vid); i++) 1080 for (i = 0; i < ARRAY_SIZE(w83793_vid); i++)
1082 device_remove_file(dev, &w83793_vid[i].dev_attr); 1081 device_remove_file(dev, &w83793_vid[i].dev_attr);
1082 device_remove_file(dev, &dev_attr_vrm);
1083 1083
1084 for (i = 0; i < ARRAY_SIZE(w83793_left_fan); i++) 1084 for (i = 0; i < ARRAY_SIZE(w83793_left_fan); i++)
1085 device_remove_file(dev, &w83793_left_fan[i].dev_attr); 1085 device_remove_file(dev, &w83793_left_fan[i].dev_attr);
@@ -1282,7 +1282,6 @@ static int w83793_detect(struct i2c_adapter *adapter, int address, int kind)
1282 /* Initialize the chip */ 1282 /* Initialize the chip */
1283 w83793_init_client(client); 1283 w83793_init_client(client);
1284 1284
1285 data->vrm = vid_which_vrm();
1286 /* 1285 /*
1287 Only fan 1-5 has their own input pins, 1286 Only fan 1-5 has their own input pins,
1288 Pwm 1-3 has their own pins 1287 Pwm 1-3 has their own pins
@@ -1293,7 +1292,9 @@ static int w83793_detect(struct i2c_adapter *adapter, int address, int kind)
1293 val = w83793_read_value(client, W83793_REG_FANIN_CTRL); 1292 val = w83793_read_value(client, W83793_REG_FANIN_CTRL);
1294 1293
1295 /* check the function of pins 49-56 */ 1294 /* check the function of pins 49-56 */
1296 if (!(tmp & 0x80)) { 1295 if (tmp & 0x80) {
1296 data->has_vid |= 0x2; /* has VIDB */
1297 } else {
1297 data->has_pwm |= 0x18; /* pwm 4,5 */ 1298 data->has_pwm |= 0x18; /* pwm 4,5 */
1298 if (val & 0x01) { /* fan 6 */ 1299 if (val & 0x01) { /* fan 6 */
1299 data->has_fan |= 0x20; 1300 data->has_fan |= 0x20;
@@ -1309,13 +1310,15 @@ static int w83793_detect(struct i2c_adapter *adapter, int address, int kind)
1309 } 1310 }
1310 } 1311 }
1311 1312
1313 /* check the function of pins 37-40 */
1314 if (!(tmp & 0x29))
1315 data->has_vid |= 0x1; /* has VIDA */
1312 if (0x08 == (tmp & 0x0c)) { 1316 if (0x08 == (tmp & 0x0c)) {
1313 if (val & 0x08) /* fan 9 */ 1317 if (val & 0x08) /* fan 9 */
1314 data->has_fan |= 0x100; 1318 data->has_fan |= 0x100;
1315 if (val & 0x10) /* fan 10 */ 1319 if (val & 0x10) /* fan 10 */
1316 data->has_fan |= 0x200; 1320 data->has_fan |= 0x200;
1317 } 1321 }
1318
1319 if (0x20 == (tmp & 0x30)) { 1322 if (0x20 == (tmp & 0x30)) {
1320 if (val & 0x20) /* fan 11 */ 1323 if (val & 0x20) /* fan 11 */
1321 data->has_fan |= 0x400; 1324 data->has_fan |= 0x400;
@@ -1359,13 +1362,6 @@ static int w83793_detect(struct i2c_adapter *adapter, int address, int kind)
1359 if (tmp & 0x02) 1362 if (tmp & 0x02)
1360 data->has_temp |= 0x20; 1363 data->has_temp |= 0x20;
1361 1364
1362 /* Detect the VID usage and ignore unused input */
1363 tmp = w83793_read_value(client, W83793_REG_MFC);
1364 if (!(tmp & 0x29))
1365 data->has_vid |= 0x1; /* has VIDA */
1366 if (tmp & 0x80)
1367 data->has_vid |= 0x2; /* has VIDB */
1368
1369 /* Register sysfs hooks */ 1365 /* Register sysfs hooks */
1370 for (i = 0; i < ARRAY_SIZE(w83793_sensor_attr_2); i++) { 1366 for (i = 0; i < ARRAY_SIZE(w83793_sensor_attr_2); i++) {
1371 err = device_create_file(dev, 1367 err = device_create_file(dev,
@@ -1381,6 +1377,12 @@ static int w83793_detect(struct i2c_adapter *adapter, int address, int kind)
1381 if (err) 1377 if (err)
1382 goto exit_remove; 1378 goto exit_remove;
1383 } 1379 }
1380 if (data->has_vid) {
1381 data->vrm = vid_which_vrm();
1382 err = device_create_file(dev, &dev_attr_vrm);
1383 if (err)
1384 goto exit_remove;
1385 }
1384 1386
1385 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) { 1387 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) {
1386 err = device_create_file(dev, &sda_single_files[i].dev_attr); 1388 err = device_create_file(dev, &sda_single_files[i].dev_attr);
diff --git a/drivers/hwmon/w83l785ts.c b/drivers/hwmon/w83l785ts.c
index 77f2d482888b..52e268e25dab 100644
--- a/drivers/hwmon/w83l785ts.c
+++ b/drivers/hwmon/w83l785ts.c
@@ -301,8 +301,8 @@ static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval)
301 msleep(i); 301 msleep(i);
302 } 302 }
303 303
304 dev_err(&client->dev, "Couldn't read value from register 0x%02x. " 304 dev_err(&client->dev, "Couldn't read value from register 0x%02x.\n",
305 "Please report.\n", reg); 305 reg);
306 return defval; 306 return defval;
307} 307}
308 308
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 099a0fe1745b..34b0d4f26b58 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -1347,19 +1347,14 @@ static void ide_init_port(ide_hwif_t *hwif, unsigned int port,
1347 (d->host_flags & IDE_HFLAG_FORCE_LEGACY_IRQS)) 1347 (d->host_flags & IDE_HFLAG_FORCE_LEGACY_IRQS))
1348 hwif->irq = port ? 15 : 14; 1348 hwif->irq = port ? 15 : 14;
1349 1349
1350 hwif->host_flags = d->host_flags; 1350 /* ->host_flags may be set by ->init_iops (or even earlier...) */
1351 hwif->host_flags |= d->host_flags;
1351 hwif->pio_mask = d->pio_mask; 1352 hwif->pio_mask = d->pio_mask;
1352 1353
1353 /* ->set_pio_mode for DTC2278 is currently limited to port 0 */ 1354 /* ->set_pio_mode for DTC2278 is currently limited to port 0 */
1354 if (hwif->chipset != ide_dtc2278 || hwif->channel == 0) 1355 if (hwif->chipset != ide_dtc2278 || hwif->channel == 0)
1355 hwif->port_ops = d->port_ops; 1356 hwif->port_ops = d->port_ops;
1356 1357
1357 if ((d->host_flags & IDE_HFLAG_SERIALIZE) ||
1358 ((d->host_flags & IDE_HFLAG_SERIALIZE_DMA) && hwif->dma_base)) {
1359 if (hwif->mate)
1360 hwif->mate->serialized = hwif->serialized = 1;
1361 }
1362
1363 hwif->swdma_mask = d->swdma_mask; 1358 hwif->swdma_mask = d->swdma_mask;
1364 hwif->mwdma_mask = d->mwdma_mask; 1359 hwif->mwdma_mask = d->mwdma_mask;
1365 hwif->ultra_mask = d->udma_mask; 1360 hwif->ultra_mask = d->udma_mask;
@@ -1381,6 +1376,12 @@ static void ide_init_port(ide_hwif_t *hwif, unsigned int port,
1381 hwif->dma_ops = d->dma_ops; 1376 hwif->dma_ops = d->dma_ops;
1382 } 1377 }
1383 1378
1379 if ((d->host_flags & IDE_HFLAG_SERIALIZE) ||
1380 ((d->host_flags & IDE_HFLAG_SERIALIZE_DMA) && hwif->dma_base)) {
1381 if (hwif->mate)
1382 hwif->mate->serialized = hwif->serialized = 1;
1383 }
1384
1384 if (d->host_flags & IDE_HFLAG_RQSIZE_256) 1385 if (d->host_flags & IDE_HFLAG_RQSIZE_256)
1385 hwif->rqsize = 256; 1386 hwif->rqsize = 256;
1386 1387
diff --git a/drivers/ide/legacy/falconide.c b/drivers/ide/legacy/falconide.c
index 83555ca513b5..9e449a0c623f 100644
--- a/drivers/ide/legacy/falconide.c
+++ b/drivers/ide/legacy/falconide.c
@@ -61,7 +61,7 @@ static void falconide_output_data(ide_drive_t *drive, struct request *rq,
61 unsigned long data_addr = drive->hwif->io_ports.data_addr; 61 unsigned long data_addr = drive->hwif->io_ports.data_addr;
62 62
63 if (drive->media == ide_disk && rq && rq->cmd_type == REQ_TYPE_FS) 63 if (drive->media == ide_disk && rq && rq->cmd_type == REQ_TYPE_FS)
64 return outsw(data_adr, buf, (len + 1) / 2); 64 return outsw(data_addr, buf, (len + 1) / 2);
65 65
66 outsw_swapw(data_addr, buf, (len + 1) / 2); 66 outsw_swapw(data_addr, buf, (len + 1) / 2);
67} 67}
diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c
index 29d833e71cbf..05710c7c1220 100644
--- a/drivers/ieee1394/nodemgr.c
+++ b/drivers/ieee1394/nodemgr.c
@@ -520,8 +520,11 @@ static ssize_t fw_show_drv_device_ids(struct device_driver *drv, char *buf)
520 char *scratch = buf; 520 char *scratch = buf;
521 521
522 driver = container_of(drv, struct hpsb_protocol_driver, driver); 522 driver = container_of(drv, struct hpsb_protocol_driver, driver);
523 id = driver->id_table;
524 if (!id)
525 return 0;
523 526
524 for (id = driver->id_table; id->match_flags != 0; id++) { 527 for (; id->match_flags != 0; id++) {
525 int need_coma = 0; 528 int need_coma = 0;
526 529
527 if (id->match_flags & IEEE1394_MATCH_VENDOR_ID) { 530 if (id->match_flags & IEEE1394_MATCH_VENDOR_ID) {
diff --git a/drivers/input/serio/hp_sdc.c b/drivers/input/serio/hp_sdc.c
index 02b3ad8c0826..edfedd9a166c 100644
--- a/drivers/input/serio/hp_sdc.c
+++ b/drivers/input/serio/hp_sdc.c
@@ -69,6 +69,7 @@
69#include <linux/time.h> 69#include <linux/time.h>
70#include <linux/slab.h> 70#include <linux/slab.h>
71#include <linux/hil.h> 71#include <linux/hil.h>
72#include <linux/semaphore.h>
72#include <asm/io.h> 73#include <asm/io.h>
73#include <asm/system.h> 74#include <asm/system.h>
74 75
diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c
index e1a3a79ab3f9..7ff71ba7b7c9 100644
--- a/drivers/input/serio/serport.c
+++ b/drivers/input/serio/serport.c
@@ -46,7 +46,7 @@ struct serport {
46static int serport_serio_write(struct serio *serio, unsigned char data) 46static int serport_serio_write(struct serio *serio, unsigned char data)
47{ 47{
48 struct serport *serport = serio->port_data; 48 struct serport *serport = serio->port_data;
49 return -(serport->tty->driver->write(serport->tty, &data, 1) != 1); 49 return -(serport->tty->ops->write(serport->tty, &data, 1) != 1);
50} 50}
51 51
52static int serport_serio_open(struct serio *serio) 52static int serport_serio_open(struct serio *serio)
diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index 24c6b7ca62be..6ca0bb949ad3 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1111,11 +1111,12 @@ static int capinc_tty_write(struct tty_struct * tty,
1111 return count; 1111 return count;
1112} 1112}
1113 1113
1114static void capinc_tty_put_char(struct tty_struct *tty, unsigned char ch) 1114static int capinc_tty_put_char(struct tty_struct *tty, unsigned char ch)
1115{ 1115{
1116 struct capiminor *mp = (struct capiminor *)tty->driver_data; 1116 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1117 struct sk_buff *skb; 1117 struct sk_buff *skb;
1118 unsigned long flags; 1118 unsigned long flags;
1119 int ret = 1;
1119 1120
1120#ifdef _DEBUG_TTYFUNCS 1121#ifdef _DEBUG_TTYFUNCS
1121 printk(KERN_DEBUG "capinc_put_char(%u)\n", ch); 1122 printk(KERN_DEBUG "capinc_put_char(%u)\n", ch);
@@ -1125,7 +1126,7 @@ static void capinc_tty_put_char(struct tty_struct *tty, unsigned char ch)
1125#ifdef _DEBUG_TTYFUNCS 1126#ifdef _DEBUG_TTYFUNCS
1126 printk(KERN_DEBUG "capinc_tty_put_char: mp or mp->ncci NULL\n"); 1127 printk(KERN_DEBUG "capinc_tty_put_char: mp or mp->ncci NULL\n");
1127#endif 1128#endif
1128 return; 1129 return 0;
1129 } 1130 }
1130 1131
1131 spin_lock_irqsave(&workaround_lock, flags); 1132 spin_lock_irqsave(&workaround_lock, flags);
@@ -1134,7 +1135,7 @@ static void capinc_tty_put_char(struct tty_struct *tty, unsigned char ch)
1134 if (skb_tailroom(skb) > 0) { 1135 if (skb_tailroom(skb) > 0) {
1135 *(skb_put(skb, 1)) = ch; 1136 *(skb_put(skb, 1)) = ch;
1136 spin_unlock_irqrestore(&workaround_lock, flags); 1137 spin_unlock_irqrestore(&workaround_lock, flags);
1137 return; 1138 return 1;
1138 } 1139 }
1139 mp->ttyskb = NULL; 1140 mp->ttyskb = NULL;
1140 skb_queue_tail(&mp->outqueue, skb); 1141 skb_queue_tail(&mp->outqueue, skb);
@@ -1148,8 +1149,10 @@ static void capinc_tty_put_char(struct tty_struct *tty, unsigned char ch)
1148 mp->ttyskb = skb; 1149 mp->ttyskb = skb;
1149 } else { 1150 } else {
1150 printk(KERN_ERR "capinc_put_char: char %u lost\n", ch); 1151 printk(KERN_ERR "capinc_put_char: char %u lost\n", ch);
1152 ret = 0;
1151 } 1153 }
1152 spin_unlock_irqrestore(&workaround_lock, flags); 1154 spin_unlock_irqrestore(&workaround_lock, flags);
1155 return ret;
1153} 1156}
1154 1157
1155static void capinc_tty_flush_chars(struct tty_struct *tty) 1158static void capinc_tty_flush_chars(struct tty_struct *tty)
diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
index fceeb1d57682..45d1ee93cd39 100644
--- a/drivers/isdn/gigaset/ser-gigaset.c
+++ b/drivers/isdn/gigaset/ser-gigaset.c
@@ -68,10 +68,10 @@ static int write_modem(struct cardstate *cs)
68 struct tty_struct *tty = cs->hw.ser->tty; 68 struct tty_struct *tty = cs->hw.ser->tty;
69 struct bc_state *bcs = &cs->bcs[0]; /* only one channel */ 69 struct bc_state *bcs = &cs->bcs[0]; /* only one channel */
70 struct sk_buff *skb = bcs->tx_skb; 70 struct sk_buff *skb = bcs->tx_skb;
71 int sent; 71 int sent = -EOPNOTSUPP;
72 72
73 if (!tty || !tty->driver || !skb) 73 if (!tty || !tty->driver || !skb)
74 return -EFAULT; 74 return -EINVAL;
75 75
76 if (!skb->len) { 76 if (!skb->len) {
77 dev_kfree_skb_any(skb); 77 dev_kfree_skb_any(skb);
@@ -80,7 +80,8 @@ static int write_modem(struct cardstate *cs)
80 } 80 }
81 81
82 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 82 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
83 sent = tty->driver->write(tty, skb->data, skb->len); 83 if (tty->ops->write)
84 sent = tty->ops->write(tty, skb->data, skb->len);
84 gig_dbg(DEBUG_OUTPUT, "write_modem: sent %d", sent); 85 gig_dbg(DEBUG_OUTPUT, "write_modem: sent %d", sent);
85 if (sent < 0) { 86 if (sent < 0) {
86 /* error */ 87 /* error */
@@ -120,7 +121,7 @@ static int send_cb(struct cardstate *cs)
120 121
121 if (cb->len) { 122 if (cb->len) {
122 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 123 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
123 sent = tty->driver->write(tty, cb->buf + cb->offset, cb->len); 124 sent = tty->ops->write(tty, cb->buf + cb->offset, cb->len);
124 if (sent < 0) { 125 if (sent < 0) {
125 /* error */ 126 /* error */
126 gig_dbg(DEBUG_OUTPUT, "send_cb: write error %d", sent); 127 gig_dbg(DEBUG_OUTPUT, "send_cb: write error %d", sent);
@@ -440,14 +441,14 @@ static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state, unsi
440 struct tty_struct *tty = cs->hw.ser->tty; 441 struct tty_struct *tty = cs->hw.ser->tty;
441 unsigned int set, clear; 442 unsigned int set, clear;
442 443
443 if (!tty || !tty->driver || !tty->driver->tiocmset) 444 if (!tty || !tty->driver || !tty->ops->tiocmset)
444 return -EFAULT; 445 return -EINVAL;
445 set = new_state & ~old_state; 446 set = new_state & ~old_state;
446 clear = old_state & ~new_state; 447 clear = old_state & ~new_state;
447 if (!set && !clear) 448 if (!set && !clear)
448 return 0; 449 return 0;
449 gig_dbg(DEBUG_IF, "tiocmset set %x clear %x", set, clear); 450 gig_dbg(DEBUG_IF, "tiocmset set %x clear %x", set, clear);
450 return tty->driver->tiocmset(tty, NULL, set, clear); 451 return tty->ops->tiocmset(tty, NULL, set, clear);
451} 452}
452 453
453static int gigaset_baud_rate(struct cardstate *cs, unsigned cflag) 454static int gigaset_baud_rate(struct cardstate *cs, unsigned cflag)
diff --git a/drivers/isdn/hysdn/hysdn_procconf.c b/drivers/isdn/hysdn/hysdn_procconf.c
index 877be9922c3d..15906d005b05 100644
--- a/drivers/isdn/hysdn/hysdn_procconf.c
+++ b/drivers/isdn/hysdn/hysdn_procconf.c
@@ -405,7 +405,8 @@ hysdn_procconf_init(void)
405 sprintf(conf_name, "%s%d", PROC_CONF_BASENAME, card->myid); 405 sprintf(conf_name, "%s%d", PROC_CONF_BASENAME, card->myid);
406 if ((card->procconf = (void *) proc_create(conf_name, 406 if ((card->procconf = (void *) proc_create(conf_name,
407 S_IFREG | S_IRUGO | S_IWUSR, 407 S_IFREG | S_IRUGO | S_IWUSR,
408 hysdn_proc_entry)) != NULL) { 408 hysdn_proc_entry,
409 &conf_fops)) != NULL) {
409 hysdn_proclog_init(card); /* init the log file entry */ 410 hysdn_proclog_init(card); /* init the log file entry */
410 } 411 }
411 card = card->next; /* next entry */ 412 card = card->next; /* next entry */
diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
index 8af0df1d5b8c..1a2222cbb805 100644
--- a/drivers/isdn/i4l/isdn_tty.c
+++ b/drivers/isdn/i4l/isdn_tty.c
@@ -1352,12 +1352,14 @@ isdn_tty_tiocmget(struct tty_struct *tty, struct file *file)
1352 if (tty->flags & (1 << TTY_IO_ERROR)) 1352 if (tty->flags & (1 << TTY_IO_ERROR))
1353 return -EIO; 1353 return -EIO;
1354 1354
1355 lock_kernel();
1355#ifdef ISDN_DEBUG_MODEM_IOCTL 1356#ifdef ISDN_DEBUG_MODEM_IOCTL
1356 printk(KERN_DEBUG "ttyI%d ioctl TIOCMGET\n", info->line); 1357 printk(KERN_DEBUG "ttyI%d ioctl TIOCMGET\n", info->line);
1357#endif 1358#endif
1358 1359
1359 control = info->mcr; 1360 control = info->mcr;
1360 status = info->msr; 1361 status = info->msr;
1362 unlock_kernel();
1361 return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0) 1363 return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
1362 | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0) 1364 | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
1363 | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0) 1365 | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0)
@@ -1381,6 +1383,7 @@ isdn_tty_tiocmset(struct tty_struct *tty, struct file *file,
1381 printk(KERN_DEBUG "ttyI%d ioctl TIOCMxxx: %x %x\n", info->line, set, clear); 1383 printk(KERN_DEBUG "ttyI%d ioctl TIOCMxxx: %x %x\n", info->line, set, clear);
1382#endif 1384#endif
1383 1385
1386 lock_kernel();
1384 if (set & TIOCM_RTS) 1387 if (set & TIOCM_RTS)
1385 info->mcr |= UART_MCR_RTS; 1388 info->mcr |= UART_MCR_RTS;
1386 if (set & TIOCM_DTR) { 1389 if (set & TIOCM_DTR) {
@@ -1402,6 +1405,7 @@ isdn_tty_tiocmset(struct tty_struct *tty, struct file *file,
1402 isdn_tty_modem_hup(info, 1); 1405 isdn_tty_modem_hup(info, 1);
1403 } 1406 }
1404 } 1407 }
1408 unlock_kernel();
1405 return 0; 1409 return 0;
1406} 1410}
1407 1411
@@ -1435,21 +1439,6 @@ isdn_tty_ioctl(struct tty_struct *tty, struct file *file,
1435 return retval; 1439 return retval;
1436 tty_wait_until_sent(tty, 0); 1440 tty_wait_until_sent(tty, 0);
1437 return 0; 1441 return 0;
1438 case TIOCGSOFTCAR:
1439#ifdef ISDN_DEBUG_MODEM_IOCTL
1440 printk(KERN_DEBUG "ttyI%d ioctl TIOCGSOFTCAR\n", info->line);
1441#endif
1442 return put_user(C_CLOCAL(tty) ? 1 : 0, (ulong __user *) arg);
1443 case TIOCSSOFTCAR:
1444#ifdef ISDN_DEBUG_MODEM_IOCTL
1445 printk(KERN_DEBUG "ttyI%d ioctl TIOCSSOFTCAR\n", info->line);
1446#endif
1447 if (get_user(arg, (ulong __user *) arg))
1448 return -EFAULT;
1449 tty->termios->c_cflag =
1450 ((tty->termios->c_cflag & ~CLOCAL) |
1451 (arg ? CLOCAL : 0));
1452 return 0;
1453 case TIOCSERGETLSR: /* Get line status register */ 1442 case TIOCSERGETLSR: /* Get line status register */
1454#ifdef ISDN_DEBUG_MODEM_IOCTL 1443#ifdef ISDN_DEBUG_MODEM_IOCTL
1455 printk(KERN_DEBUG "ttyI%d ioctl TIOCSERGETLSR\n", info->line); 1444 printk(KERN_DEBUG "ttyI%d ioctl TIOCSERGETLSR\n", info->line);
@@ -1472,13 +1461,14 @@ isdn_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1472 if (!old_termios) 1461 if (!old_termios)
1473 isdn_tty_change_speed(info); 1462 isdn_tty_change_speed(info);
1474 else { 1463 else {
1475 if (tty->termios->c_cflag == old_termios->c_cflag) 1464 if (tty->termios->c_cflag == old_termios->c_cflag &&
1465 tty->termios->c_ispeed == old_termios->c_ispeed &&
1466 tty->termios->c_ospeed == old_termios->c_ospeed)
1476 return; 1467 return;
1477 isdn_tty_change_speed(info); 1468 isdn_tty_change_speed(info);
1478 if ((old_termios->c_cflag & CRTSCTS) && 1469 if ((old_termios->c_cflag & CRTSCTS) &&
1479 !(tty->termios->c_cflag & CRTSCTS)) { 1470 !(tty->termios->c_cflag & CRTSCTS))
1480 tty->hw_stopped = 0; 1471 tty->hw_stopped = 0;
1481 }
1482 } 1472 }
1483} 1473}
1484 1474
@@ -1718,9 +1708,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
1718 } 1708 }
1719 dev->modempoll--; 1709 dev->modempoll--;
1720 isdn_tty_shutdown(info); 1710 isdn_tty_shutdown(info);
1721 1711 isdn_tty_flush_buffer(tty);
1722 if (tty->driver->flush_buffer)
1723 tty->driver->flush_buffer(tty);
1724 tty_ldisc_flush(tty); 1712 tty_ldisc_flush(tty);
1725 info->tty = NULL; 1713 info->tty = NULL;
1726 info->ncarrier = 0; 1714 info->ncarrier = 0;
diff --git a/drivers/lguest/lguest_device.c b/drivers/lguest/lguest_device.c
index 2bc9bf7e88e5..8080249957af 100644
--- a/drivers/lguest/lguest_device.c
+++ b/drivers/lguest/lguest_device.c
@@ -85,27 +85,34 @@ static unsigned desc_size(const struct lguest_device_desc *desc)
85 + desc->config_len; 85 + desc->config_len;
86} 86}
87 87
88/* This tests (and acknowleges) a feature bit. */ 88/* This gets the device's feature bits. */
89static bool lg_feature(struct virtio_device *vdev, unsigned fbit) 89static u32 lg_get_features(struct virtio_device *vdev)
90{ 90{
91 unsigned int i;
92 u32 features = 0;
91 struct lguest_device_desc *desc = to_lgdev(vdev)->desc; 93 struct lguest_device_desc *desc = to_lgdev(vdev)->desc;
92 u8 *features; 94 u8 *in_features = lg_features(desc);
93 95
94 /* Obviously if they ask for a feature off the end of our feature 96 /* We do this the slow but generic way. */
95 * bitmap, it's not set. */ 97 for (i = 0; i < min(desc->feature_len * 8, 32); i++)
96 if (fbit / 8 > desc->feature_len) 98 if (in_features[i / 8] & (1 << (i % 8)))
97 return false; 99 features |= (1 << i);
98 100
99 /* The feature bitmap comes after the virtqueues. */ 101 return features;
100 features = lg_features(desc); 102}
101 if (!(features[fbit / 8] & (1 << (fbit % 8)))) 103
102 return false; 104static void lg_set_features(struct virtio_device *vdev, u32 features)
103 105{
104 /* We set the matching bit in the other half of the bitmap to tell the 106 unsigned int i;
105 * Host we want to use this feature. We don't use this yet, but we 107 struct lguest_device_desc *desc = to_lgdev(vdev)->desc;
106 * could in future. */ 108 /* Second half of bitmap is features we accept. */
107 features[desc->feature_len + fbit / 8] |= (1 << (fbit % 8)); 109 u8 *out_features = lg_features(desc) + desc->feature_len;
108 return true; 110
111 memset(out_features, 0, desc->feature_len);
112 for (i = 0; i < min(desc->feature_len * 8, 32); i++) {
113 if (features & (1 << i))
114 out_features[i / 8] |= (1 << (i % 8));
115 }
109} 116}
110 117
111/* Once they've found a field, getting a copy of it is easy. */ 118/* Once they've found a field, getting a copy of it is easy. */
@@ -137,20 +144,26 @@ static u8 lg_get_status(struct virtio_device *vdev)
137 return to_lgdev(vdev)->desc->status; 144 return to_lgdev(vdev)->desc->status;
138} 145}
139 146
147/* To notify on status updates, we (ab)use the NOTIFY hypercall, with the
148 * descriptor address of the device. A zero status means "reset". */
149static void set_status(struct virtio_device *vdev, u8 status)
150{
151 unsigned long offset = (void *)to_lgdev(vdev)->desc - lguest_devices;
152
153 /* We set the status. */
154 to_lgdev(vdev)->desc->status = status;
155 hcall(LHCALL_NOTIFY, (max_pfn<<PAGE_SHIFT) + offset, 0, 0);
156}
157
140static void lg_set_status(struct virtio_device *vdev, u8 status) 158static void lg_set_status(struct virtio_device *vdev, u8 status)
141{ 159{
142 BUG_ON(!status); 160 BUG_ON(!status);
143 to_lgdev(vdev)->desc->status = status; 161 set_status(vdev, status);
144} 162}
145 163
146/* To reset the device, we (ab)use the NOTIFY hypercall, with the descriptor
147 * address of the device. The Host will zero the status and all the
148 * features. */
149static void lg_reset(struct virtio_device *vdev) 164static void lg_reset(struct virtio_device *vdev)
150{ 165{
151 unsigned long offset = (void *)to_lgdev(vdev)->desc - lguest_devices; 166 set_status(vdev, 0);
152
153 hcall(LHCALL_NOTIFY, (max_pfn<<PAGE_SHIFT) + offset, 0, 0);
154} 167}
155 168
156/* 169/*
@@ -286,7 +299,8 @@ static void lg_del_vq(struct virtqueue *vq)
286 299
287/* The ops structure which hooks everything together. */ 300/* The ops structure which hooks everything together. */
288static struct virtio_config_ops lguest_config_ops = { 301static struct virtio_config_ops lguest_config_ops = {
289 .feature = lg_feature, 302 .get_features = lg_get_features,
303 .set_features = lg_set_features,
290 .get = lg_get, 304 .get = lg_get,
291 .set = lg_set, 305 .set = lg_set,
292 .get_status = lg_get_status, 306 .get_status = lg_get_status,
diff --git a/drivers/lguest/lguest_user.c b/drivers/lguest/lguest_user.c
index 645e6e040bfb..e73a000473cc 100644
--- a/drivers/lguest/lguest_user.c
+++ b/drivers/lguest/lguest_user.c
@@ -102,7 +102,7 @@ static ssize_t read(struct file *file, char __user *user, size_t size,loff_t*o)
102static int lg_cpu_start(struct lg_cpu *cpu, unsigned id, unsigned long start_ip) 102static int lg_cpu_start(struct lg_cpu *cpu, unsigned id, unsigned long start_ip)
103{ 103{
104 /* We have a limited number the number of CPUs in the lguest struct. */ 104 /* We have a limited number the number of CPUs in the lguest struct. */
105 if (id >= NR_CPUS) 105 if (id >= ARRAY_SIZE(cpu->lg->cpus))
106 return -EINVAL; 106 return -EINVAL;
107 107
108 /* Set up this CPU's id, and pointer back to the lguest struct. */ 108 /* Set up this CPU's id, and pointer back to the lguest struct. */
@@ -251,8 +251,6 @@ static ssize_t write(struct file *file, const char __user *in,
251 if (!lg || (cpu_id >= lg->nr_cpus)) 251 if (!lg || (cpu_id >= lg->nr_cpus))
252 return -EINVAL; 252 return -EINVAL;
253 cpu = &lg->cpus[cpu_id]; 253 cpu = &lg->cpus[cpu_id];
254 if (!cpu)
255 return -EINVAL;
256 254
257 /* Once the Guest is dead, you can only read() why it died. */ 255 /* Once the Guest is dead, you can only read() why it died. */
258 if (lg->dead) 256 if (lg->dead)
diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c
index 20978205cd02..b8b9e44f7f4e 100644
--- a/drivers/macintosh/adb.c
+++ b/drivers/macintosh/adb.c
@@ -37,7 +37,7 @@
37#include <linux/device.h> 37#include <linux/device.h>
38#include <linux/kthread.h> 38#include <linux/kthread.h>
39#include <linux/platform_device.h> 39#include <linux/platform_device.h>
40#include <linux/semaphore.h> 40#include <linux/mutex.h>
41 41
42#include <asm/uaccess.h> 42#include <asm/uaccess.h>
43#ifdef CONFIG_PPC 43#ifdef CONFIG_PPC
@@ -102,7 +102,7 @@ static struct adb_handler {
102} adb_handler[16]; 102} adb_handler[16];
103 103
104/* 104/*
105 * The adb_handler_sem mutex protects all accesses to the original_address 105 * The adb_handler_mutex mutex protects all accesses to the original_address
106 * and handler_id fields of adb_handler[i] for all i, and changes to the 106 * and handler_id fields of adb_handler[i] for all i, and changes to the
107 * handler field. 107 * handler field.
108 * Accesses to the handler field are protected by the adb_handler_lock 108 * Accesses to the handler field are protected by the adb_handler_lock
@@ -110,7 +110,7 @@ static struct adb_handler {
110 * time adb_unregister returns, we know that the old handler isn't being 110 * time adb_unregister returns, we know that the old handler isn't being
111 * called. 111 * called.
112 */ 112 */
113static DECLARE_MUTEX(adb_handler_sem); 113static DEFINE_MUTEX(adb_handler_mutex);
114static DEFINE_RWLOCK(adb_handler_lock); 114static DEFINE_RWLOCK(adb_handler_lock);
115 115
116#if 0 116#if 0
@@ -355,7 +355,7 @@ do_adb_reset_bus(void)
355 msleep(500); 355 msleep(500);
356 } 356 }
357 357
358 down(&adb_handler_sem); 358 mutex_lock(&adb_handler_mutex);
359 write_lock_irq(&adb_handler_lock); 359 write_lock_irq(&adb_handler_lock);
360 memset(adb_handler, 0, sizeof(adb_handler)); 360 memset(adb_handler, 0, sizeof(adb_handler));
361 write_unlock_irq(&adb_handler_lock); 361 write_unlock_irq(&adb_handler_lock);
@@ -376,7 +376,7 @@ do_adb_reset_bus(void)
376 if (adb_controller->autopoll) 376 if (adb_controller->autopoll)
377 adb_controller->autopoll(autopoll_devs); 377 adb_controller->autopoll(autopoll_devs);
378 } 378 }
379 up(&adb_handler_sem); 379 mutex_unlock(&adb_handler_mutex);
380 380
381 blocking_notifier_call_chain(&adb_client_list, 381 blocking_notifier_call_chain(&adb_client_list,
382 ADB_MSG_POST_RESET, NULL); 382 ADB_MSG_POST_RESET, NULL);
@@ -454,7 +454,7 @@ adb_register(int default_id, int handler_id, struct adb_ids *ids,
454{ 454{
455 int i; 455 int i;
456 456
457 down(&adb_handler_sem); 457 mutex_lock(&adb_handler_mutex);
458 ids->nids = 0; 458 ids->nids = 0;
459 for (i = 1; i < 16; i++) { 459 for (i = 1; i < 16; i++) {
460 if ((adb_handler[i].original_address == default_id) && 460 if ((adb_handler[i].original_address == default_id) &&
@@ -472,7 +472,7 @@ adb_register(int default_id, int handler_id, struct adb_ids *ids,
472 ids->id[ids->nids++] = i; 472 ids->id[ids->nids++] = i;
473 } 473 }
474 } 474 }
475 up(&adb_handler_sem); 475 mutex_unlock(&adb_handler_mutex);
476 return ids->nids; 476 return ids->nids;
477} 477}
478 478
@@ -481,7 +481,7 @@ adb_unregister(int index)
481{ 481{
482 int ret = -ENODEV; 482 int ret = -ENODEV;
483 483
484 down(&adb_handler_sem); 484 mutex_lock(&adb_handler_mutex);
485 write_lock_irq(&adb_handler_lock); 485 write_lock_irq(&adb_handler_lock);
486 if (adb_handler[index].handler) { 486 if (adb_handler[index].handler) {
487 while(adb_handler[index].busy) { 487 while(adb_handler[index].busy) {
@@ -493,7 +493,7 @@ adb_unregister(int index)
493 adb_handler[index].handler = NULL; 493 adb_handler[index].handler = NULL;
494 } 494 }
495 write_unlock_irq(&adb_handler_lock); 495 write_unlock_irq(&adb_handler_lock);
496 up(&adb_handler_sem); 496 mutex_unlock(&adb_handler_mutex);
497 return ret; 497 return ret;
498} 498}
499 499
@@ -557,19 +557,19 @@ adb_try_handler_change(int address, int new_id)
557{ 557{
558 int ret; 558 int ret;
559 559
560 down(&adb_handler_sem); 560 mutex_lock(&adb_handler_mutex);
561 ret = try_handler_change(address, new_id); 561 ret = try_handler_change(address, new_id);
562 up(&adb_handler_sem); 562 mutex_unlock(&adb_handler_mutex);
563 return ret; 563 return ret;
564} 564}
565 565
566int 566int
567adb_get_infos(int address, int *original_address, int *handler_id) 567adb_get_infos(int address, int *original_address, int *handler_id)
568{ 568{
569 down(&adb_handler_sem); 569 mutex_lock(&adb_handler_mutex);
570 *original_address = adb_handler[address].original_address; 570 *original_address = adb_handler[address].original_address;
571 *handler_id = adb_handler[address].handler_id; 571 *handler_id = adb_handler[address].handler_id;
572 up(&adb_handler_sem); 572 mutex_unlock(&adb_handler_mutex);
573 573
574 return (*original_address != 0); 574 return (*original_address != 0);
575} 575}
@@ -628,10 +628,10 @@ do_adb_query(struct adb_request *req)
628 case ADB_QUERY_GETDEVINFO: 628 case ADB_QUERY_GETDEVINFO:
629 if (req->nbytes < 3) 629 if (req->nbytes < 3)
630 break; 630 break;
631 down(&adb_handler_sem); 631 mutex_lock(&adb_handler_mutex);
632 req->reply[0] = adb_handler[req->data[2]].original_address; 632 req->reply[0] = adb_handler[req->data[2]].original_address;
633 req->reply[1] = adb_handler[req->data[2]].handler_id; 633 req->reply[1] = adb_handler[req->data[2]].handler_id;
634 up(&adb_handler_sem); 634 mutex_unlock(&adb_handler_mutex);
635 req->complete = 1; 635 req->complete = 1;
636 req->reply_len = 2; 636 req->reply_len = 2;
637 adb_write_done(req); 637 adb_write_done(req);
diff --git a/drivers/macintosh/therm_pm72.c b/drivers/macintosh/therm_pm72.c
index 1e0a69a5e815..ddfb426a9abd 100644
--- a/drivers/macintosh/therm_pm72.c
+++ b/drivers/macintosh/therm_pm72.c
@@ -122,6 +122,7 @@
122#include <linux/kmod.h> 122#include <linux/kmod.h>
123#include <linux/i2c.h> 123#include <linux/i2c.h>
124#include <linux/kthread.h> 124#include <linux/kthread.h>
125#include <linux/mutex.h>
125#include <asm/prom.h> 126#include <asm/prom.h>
126#include <asm/machdep.h> 127#include <asm/machdep.h>
127#include <asm/io.h> 128#include <asm/io.h>
@@ -169,7 +170,7 @@ static int rackmac;
169static s32 dimm_output_clamp; 170static s32 dimm_output_clamp;
170static int fcu_rpm_shift; 171static int fcu_rpm_shift;
171static int fcu_tickle_ticks; 172static int fcu_tickle_ticks;
172static DECLARE_MUTEX(driver_lock); 173static DEFINE_MUTEX(driver_lock);
173 174
174/* 175/*
175 * We have 3 types of CPU PID control. One is "split" old style control 176 * We have 3 types of CPU PID control. One is "split" old style control
@@ -729,9 +730,9 @@ static void fetch_cpu_pumps_minmax(void)
729static ssize_t show_##name(struct device *dev, struct device_attribute *attr, char *buf) \ 730static ssize_t show_##name(struct device *dev, struct device_attribute *attr, char *buf) \
730{ \ 731{ \
731 ssize_t r; \ 732 ssize_t r; \
732 down(&driver_lock); \ 733 mutex_lock(&driver_lock); \
733 r = sprintf(buf, "%d.%03d", FIX32TOPRINT(data)); \ 734 r = sprintf(buf, "%d.%03d", FIX32TOPRINT(data)); \
734 up(&driver_lock); \ 735 mutex_unlock(&driver_lock); \
735 return r; \ 736 return r; \
736} 737}
737#define BUILD_SHOW_FUNC_INT(name, data) \ 738#define BUILD_SHOW_FUNC_INT(name, data) \
@@ -1803,11 +1804,11 @@ static int main_control_loop(void *x)
1803{ 1804{
1804 DBG("main_control_loop started\n"); 1805 DBG("main_control_loop started\n");
1805 1806
1806 down(&driver_lock); 1807 mutex_lock(&driver_lock);
1807 1808
1808 if (start_fcu() < 0) { 1809 if (start_fcu() < 0) {
1809 printk(KERN_ERR "kfand: failed to start FCU\n"); 1810 printk(KERN_ERR "kfand: failed to start FCU\n");
1810 up(&driver_lock); 1811 mutex_unlock(&driver_lock);
1811 goto out; 1812 goto out;
1812 } 1813 }
1813 1814
@@ -1822,14 +1823,14 @@ static int main_control_loop(void *x)
1822 1823
1823 fcu_tickle_ticks = FCU_TICKLE_TICKS; 1824 fcu_tickle_ticks = FCU_TICKLE_TICKS;
1824 1825
1825 up(&driver_lock); 1826 mutex_unlock(&driver_lock);
1826 1827
1827 while (state == state_attached) { 1828 while (state == state_attached) {
1828 unsigned long elapsed, start; 1829 unsigned long elapsed, start;
1829 1830
1830 start = jiffies; 1831 start = jiffies;
1831 1832
1832 down(&driver_lock); 1833 mutex_lock(&driver_lock);
1833 1834
1834 /* Tickle the FCU just in case */ 1835 /* Tickle the FCU just in case */
1835 if (--fcu_tickle_ticks < 0) { 1836 if (--fcu_tickle_ticks < 0) {
@@ -1861,7 +1862,7 @@ static int main_control_loop(void *x)
1861 do_monitor_slots(&slots_state); 1862 do_monitor_slots(&slots_state);
1862 else 1863 else
1863 do_monitor_drives(&drives_state); 1864 do_monitor_drives(&drives_state);
1864 up(&driver_lock); 1865 mutex_unlock(&driver_lock);
1865 1866
1866 if (critical_state == 1) { 1867 if (critical_state == 1) {
1867 printk(KERN_WARNING "Temperature control detected a critical condition\n"); 1868 printk(KERN_WARNING "Temperature control detected a critical condition\n");
@@ -2019,13 +2020,13 @@ static void detach_fcu(void)
2019 */ 2020 */
2020static int therm_pm72_attach(struct i2c_adapter *adapter) 2021static int therm_pm72_attach(struct i2c_adapter *adapter)
2021{ 2022{
2022 down(&driver_lock); 2023 mutex_lock(&driver_lock);
2023 2024
2024 /* Check state */ 2025 /* Check state */
2025 if (state == state_detached) 2026 if (state == state_detached)
2026 state = state_attaching; 2027 state = state_attaching;
2027 if (state != state_attaching) { 2028 if (state != state_attaching) {
2028 up(&driver_lock); 2029 mutex_unlock(&driver_lock);
2029 return 0; 2030 return 0;
2030 } 2031 }
2031 2032
@@ -2054,7 +2055,7 @@ static int therm_pm72_attach(struct i2c_adapter *adapter)
2054 state = state_attached; 2055 state = state_attached;
2055 start_control_loops(); 2056 start_control_loops();
2056 } 2057 }
2057 up(&driver_lock); 2058 mutex_unlock(&driver_lock);
2058 2059
2059 return 0; 2060 return 0;
2060} 2061}
@@ -2065,16 +2066,16 @@ static int therm_pm72_attach(struct i2c_adapter *adapter)
2065 */ 2066 */
2066static int therm_pm72_detach(struct i2c_adapter *adapter) 2067static int therm_pm72_detach(struct i2c_adapter *adapter)
2067{ 2068{
2068 down(&driver_lock); 2069 mutex_lock(&driver_lock);
2069 2070
2070 if (state != state_detached) 2071 if (state != state_detached)
2071 state = state_detaching; 2072 state = state_detaching;
2072 2073
2073 /* Stop control loops if any */ 2074 /* Stop control loops if any */
2074 DBG("stopping control loops\n"); 2075 DBG("stopping control loops\n");
2075 up(&driver_lock); 2076 mutex_unlock(&driver_lock);
2076 stop_control_loops(); 2077 stop_control_loops();
2077 down(&driver_lock); 2078 mutex_lock(&driver_lock);
2078 2079
2079 if (u3_0 != NULL && !strcmp(adapter->name, "u3 0")) { 2080 if (u3_0 != NULL && !strcmp(adapter->name, "u3 0")) {
2080 DBG("lost U3-0, disposing control loops\n"); 2081 DBG("lost U3-0, disposing control loops\n");
@@ -2090,7 +2091,7 @@ static int therm_pm72_detach(struct i2c_adapter *adapter)
2090 if (u3_0 == NULL && u3_1 == NULL) 2091 if (u3_0 == NULL && u3_1 == NULL)
2091 state = state_detached; 2092 state = state_detached;
2092 2093
2093 up(&driver_lock); 2094 mutex_unlock(&driver_lock);
2094 2095
2095 return 0; 2096 return 0;
2096} 2097}
diff --git a/drivers/macintosh/windfarm_smu_sat.c b/drivers/macintosh/windfarm_smu_sat.c
index 797918d0e59c..7f2be4baaeda 100644
--- a/drivers/macintosh/windfarm_smu_sat.c
+++ b/drivers/macintosh/windfarm_smu_sat.c
@@ -13,7 +13,7 @@
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/wait.h> 14#include <linux/wait.h>
15#include <linux/i2c.h> 15#include <linux/i2c.h>
16#include <linux/semaphore.h> 16#include <linux/mutex.h>
17#include <asm/prom.h> 17#include <asm/prom.h>
18#include <asm/smu.h> 18#include <asm/smu.h>
19#include <asm/pmac_low_i2c.h> 19#include <asm/pmac_low_i2c.h>
@@ -36,7 +36,7 @@
36struct wf_sat { 36struct wf_sat {
37 int nr; 37 int nr;
38 atomic_t refcnt; 38 atomic_t refcnt;
39 struct semaphore mutex; 39 struct mutex mutex;
40 unsigned long last_read; /* jiffies when cache last updated */ 40 unsigned long last_read; /* jiffies when cache last updated */
41 u8 cache[16]; 41 u8 cache[16];
42 struct i2c_client i2c; 42 struct i2c_client i2c;
@@ -163,7 +163,7 @@ static int wf_sat_get(struct wf_sensor *sr, s32 *value)
163 if (sat->i2c.adapter == NULL) 163 if (sat->i2c.adapter == NULL)
164 return -ENODEV; 164 return -ENODEV;
165 165
166 down(&sat->mutex); 166 mutex_lock(&sat->mutex);
167 if (time_after(jiffies, (sat->last_read + MAX_AGE))) { 167 if (time_after(jiffies, (sat->last_read + MAX_AGE))) {
168 err = wf_sat_read_cache(sat); 168 err = wf_sat_read_cache(sat);
169 if (err) 169 if (err)
@@ -182,7 +182,7 @@ static int wf_sat_get(struct wf_sensor *sr, s32 *value)
182 err = 0; 182 err = 0;
183 183
184 fail: 184 fail:
185 up(&sat->mutex); 185 mutex_unlock(&sat->mutex);
186 return err; 186 return err;
187} 187}
188 188
@@ -233,7 +233,7 @@ static void wf_sat_create(struct i2c_adapter *adapter, struct device_node *dev)
233 sat->nr = -1; 233 sat->nr = -1;
234 sat->node = of_node_get(dev); 234 sat->node = of_node_get(dev);
235 atomic_set(&sat->refcnt, 0); 235 atomic_set(&sat->refcnt, 0);
236 init_MUTEX(&sat->mutex); 236 mutex_init(&sat->mutex);
237 sat->i2c.addr = (addr >> 1) & 0x7f; 237 sat->i2c.addr = (addr >> 1) & 0x7f;
238 sat->i2c.adapter = adapter; 238 sat->i2c.adapter = adapter;
239 sat->i2c.driver = &wf_sat_driver; 239 sat->i2c.driver = &wf_sat_driver;
diff --git a/drivers/md/md.c b/drivers/md/md.c
index bb3e4b1cb773..83eb78b00137 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -276,6 +276,7 @@ static mddev_t * mddev_find(dev_t unit)
276 init_waitqueue_head(&new->sb_wait); 276 init_waitqueue_head(&new->sb_wait);
277 new->reshape_position = MaxSector; 277 new->reshape_position = MaxSector;
278 new->resync_max = MaxSector; 278 new->resync_max = MaxSector;
279 new->level = LEVEL_NONE;
279 280
280 new->queue = blk_alloc_queue(GFP_KERNEL); 281 new->queue = blk_alloc_queue(GFP_KERNEL);
281 if (!new->queue) { 282 if (!new->queue) {
@@ -1369,6 +1370,11 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
1369 MD_BUG(); 1370 MD_BUG();
1370 return -EINVAL; 1371 return -EINVAL;
1371 } 1372 }
1373
1374 /* prevent duplicates */
1375 if (find_rdev(mddev, rdev->bdev->bd_dev))
1376 return -EEXIST;
1377
1372 /* make sure rdev->size exceeds mddev->size */ 1378 /* make sure rdev->size exceeds mddev->size */
1373 if (rdev->size && (mddev->size == 0 || rdev->size < mddev->size)) { 1379 if (rdev->size && (mddev->size == 0 || rdev->size < mddev->size)) {
1374 if (mddev->pers) { 1380 if (mddev->pers) {
@@ -1652,6 +1658,8 @@ static void md_update_sb(mddev_t * mddev, int force_change)
1652 int sync_req; 1658 int sync_req;
1653 int nospares = 0; 1659 int nospares = 0;
1654 1660
1661 if (mddev->external)
1662 return;
1655repeat: 1663repeat:
1656 spin_lock_irq(&mddev->write_lock); 1664 spin_lock_irq(&mddev->write_lock);
1657 1665
@@ -1820,6 +1828,10 @@ state_show(mdk_rdev_t *rdev, char *page)
1820 len += sprintf(page+len, "%swrite_mostly",sep); 1828 len += sprintf(page+len, "%swrite_mostly",sep);
1821 sep = ","; 1829 sep = ",";
1822 } 1830 }
1831 if (test_bit(Blocked, &rdev->flags)) {
1832 len += sprintf(page+len, "%sblocked", sep);
1833 sep = ",";
1834 }
1823 if (!test_bit(Faulty, &rdev->flags) && 1835 if (!test_bit(Faulty, &rdev->flags) &&
1824 !test_bit(In_sync, &rdev->flags)) { 1836 !test_bit(In_sync, &rdev->flags)) {
1825 len += sprintf(page+len, "%sspare", sep); 1837 len += sprintf(page+len, "%sspare", sep);
@@ -1836,6 +1848,8 @@ state_store(mdk_rdev_t *rdev, const char *buf, size_t len)
1836 * remove - disconnects the device 1848 * remove - disconnects the device
1837 * writemostly - sets write_mostly 1849 * writemostly - sets write_mostly
1838 * -writemostly - clears write_mostly 1850 * -writemostly - clears write_mostly
1851 * blocked - sets the Blocked flag
1852 * -blocked - clears the Blocked flag
1839 */ 1853 */
1840 int err = -EINVAL; 1854 int err = -EINVAL;
1841 if (cmd_match(buf, "faulty") && rdev->mddev->pers) { 1855 if (cmd_match(buf, "faulty") && rdev->mddev->pers) {
@@ -1858,6 +1872,16 @@ state_store(mdk_rdev_t *rdev, const char *buf, size_t len)
1858 } else if (cmd_match(buf, "-writemostly")) { 1872 } else if (cmd_match(buf, "-writemostly")) {
1859 clear_bit(WriteMostly, &rdev->flags); 1873 clear_bit(WriteMostly, &rdev->flags);
1860 err = 0; 1874 err = 0;
1875 } else if (cmd_match(buf, "blocked")) {
1876 set_bit(Blocked, &rdev->flags);
1877 err = 0;
1878 } else if (cmd_match(buf, "-blocked")) {
1879 clear_bit(Blocked, &rdev->flags);
1880 wake_up(&rdev->blocked_wait);
1881 set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery);
1882 md_wakeup_thread(rdev->mddev->thread);
1883
1884 err = 0;
1861 } 1885 }
1862 return err ? err : len; 1886 return err ? err : len;
1863} 1887}
@@ -2097,7 +2121,7 @@ rdev_attr_store(struct kobject *kobj, struct attribute *attr,
2097 rv = -EBUSY; 2121 rv = -EBUSY;
2098 else 2122 else
2099 rv = entry->store(rdev, page, length); 2123 rv = entry->store(rdev, page, length);
2100 mddev_unlock(rdev->mddev); 2124 mddev_unlock(mddev);
2101 } 2125 }
2102 return rv; 2126 return rv;
2103} 2127}
@@ -2186,7 +2210,9 @@ static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_mi
2186 goto abort_free; 2210 goto abort_free;
2187 } 2211 }
2188 } 2212 }
2213
2189 INIT_LIST_HEAD(&rdev->same_set); 2214 INIT_LIST_HEAD(&rdev->same_set);
2215 init_waitqueue_head(&rdev->blocked_wait);
2190 2216
2191 return rdev; 2217 return rdev;
2192 2218
@@ -2457,7 +2483,6 @@ resync_start_show(mddev_t *mddev, char *page)
2457static ssize_t 2483static ssize_t
2458resync_start_store(mddev_t *mddev, const char *buf, size_t len) 2484resync_start_store(mddev_t *mddev, const char *buf, size_t len)
2459{ 2485{
2460 /* can only set chunk_size if array is not yet active */
2461 char *e; 2486 char *e;
2462 unsigned long long n = simple_strtoull(buf, &e, 10); 2487 unsigned long long n = simple_strtoull(buf, &e, 10);
2463 2488
@@ -2591,15 +2616,20 @@ array_state_store(mddev_t *mddev, const char *buf, size_t len)
2591 err = do_md_stop(mddev, 1); 2616 err = do_md_stop(mddev, 1);
2592 else { 2617 else {
2593 mddev->ro = 1; 2618 mddev->ro = 1;
2619 set_disk_ro(mddev->gendisk, 1);
2594 err = do_md_run(mddev); 2620 err = do_md_run(mddev);
2595 } 2621 }
2596 break; 2622 break;
2597 case read_auto: 2623 case read_auto:
2598 /* stopping an active array */
2599 if (mddev->pers) { 2624 if (mddev->pers) {
2600 err = do_md_stop(mddev, 1); 2625 if (mddev->ro != 1)
2601 if (err == 0) 2626 err = do_md_stop(mddev, 1);
2602 mddev->ro = 2; /* FIXME mark devices writable */ 2627 else
2628 err = restart_array(mddev);
2629 if (err == 0) {
2630 mddev->ro = 2;
2631 set_disk_ro(mddev->gendisk, 0);
2632 }
2603 } else { 2633 } else {
2604 mddev->ro = 2; 2634 mddev->ro = 2;
2605 err = do_md_run(mddev); 2635 err = do_md_run(mddev);
@@ -2612,6 +2642,8 @@ array_state_store(mddev_t *mddev, const char *buf, size_t len)
2612 if (atomic_read(&mddev->writes_pending) == 0) { 2642 if (atomic_read(&mddev->writes_pending) == 0) {
2613 if (mddev->in_sync == 0) { 2643 if (mddev->in_sync == 0) {
2614 mddev->in_sync = 1; 2644 mddev->in_sync = 1;
2645 if (mddev->safemode == 1)
2646 mddev->safemode = 0;
2615 if (mddev->persistent) 2647 if (mddev->persistent)
2616 set_bit(MD_CHANGE_CLEAN, 2648 set_bit(MD_CHANGE_CLEAN,
2617 &mddev->flags); 2649 &mddev->flags);
@@ -2635,6 +2667,7 @@ array_state_store(mddev_t *mddev, const char *buf, size_t len)
2635 err = 0; 2667 err = 0;
2636 } else { 2668 } else {
2637 mddev->ro = 0; 2669 mddev->ro = 0;
2670 set_disk_ro(mddev->gendisk, 0);
2638 err = do_md_run(mddev); 2671 err = do_md_run(mddev);
2639 } 2672 }
2640 break; 2673 break;
@@ -3712,6 +3745,30 @@ static int do_md_stop(mddev_t * mddev, int mode)
3712 mddev->reshape_position = MaxSector; 3745 mddev->reshape_position = MaxSector;
3713 mddev->external = 0; 3746 mddev->external = 0;
3714 mddev->persistent = 0; 3747 mddev->persistent = 0;
3748 mddev->level = LEVEL_NONE;
3749 mddev->clevel[0] = 0;
3750 mddev->flags = 0;
3751 mddev->ro = 0;
3752 mddev->metadata_type[0] = 0;
3753 mddev->chunk_size = 0;
3754 mddev->ctime = mddev->utime = 0;
3755 mddev->layout = 0;
3756 mddev->max_disks = 0;
3757 mddev->events = 0;
3758 mddev->delta_disks = 0;
3759 mddev->new_level = LEVEL_NONE;
3760 mddev->new_layout = 0;
3761 mddev->new_chunk = 0;
3762 mddev->curr_resync = 0;
3763 mddev->resync_mismatches = 0;
3764 mddev->suspend_lo = mddev->suspend_hi = 0;
3765 mddev->sync_speed_min = mddev->sync_speed_max = 0;
3766 mddev->recovery = 0;
3767 mddev->in_sync = 0;
3768 mddev->changed = 0;
3769 mddev->degraded = 0;
3770 mddev->barriers_work = 0;
3771 mddev->safemode = 0;
3715 3772
3716 } else if (mddev->pers) 3773 } else if (mddev->pers)
3717 printk(KERN_INFO "md: %s switched to read-only mode.\n", 3774 printk(KERN_INFO "md: %s switched to read-only mode.\n",
@@ -4919,6 +4976,9 @@ void md_error(mddev_t *mddev, mdk_rdev_t *rdev)
4919 4976
4920 if (!rdev || test_bit(Faulty, &rdev->flags)) 4977 if (!rdev || test_bit(Faulty, &rdev->flags))
4921 return; 4978 return;
4979
4980 if (mddev->external)
4981 set_bit(Blocked, &rdev->flags);
4922/* 4982/*
4923 dprintk("md_error dev:%s, rdev:(%d:%d), (caller: %p,%p,%p,%p).\n", 4983 dprintk("md_error dev:%s, rdev:(%d:%d), (caller: %p,%p,%p,%p).\n",
4924 mdname(mddev), 4984 mdname(mddev),
@@ -5365,6 +5425,8 @@ void md_write_start(mddev_t *mddev, struct bio *bi)
5365 md_wakeup_thread(mddev->sync_thread); 5425 md_wakeup_thread(mddev->sync_thread);
5366 } 5426 }
5367 atomic_inc(&mddev->writes_pending); 5427 atomic_inc(&mddev->writes_pending);
5428 if (mddev->safemode == 1)
5429 mddev->safemode = 0;
5368 if (mddev->in_sync) { 5430 if (mddev->in_sync) {
5369 spin_lock_irq(&mddev->write_lock); 5431 spin_lock_irq(&mddev->write_lock);
5370 if (mddev->in_sync) { 5432 if (mddev->in_sync) {
@@ -5719,7 +5781,7 @@ static int remove_and_add_spares(mddev_t *mddev)
5719 5781
5720 rdev_for_each(rdev, rtmp, mddev) 5782 rdev_for_each(rdev, rtmp, mddev)
5721 if (rdev->raid_disk >= 0 && 5783 if (rdev->raid_disk >= 0 &&
5722 !mddev->external && 5784 !test_bit(Blocked, &rdev->flags) &&
5723 (test_bit(Faulty, &rdev->flags) || 5785 (test_bit(Faulty, &rdev->flags) ||
5724 ! test_bit(In_sync, &rdev->flags)) && 5786 ! test_bit(In_sync, &rdev->flags)) &&
5725 atomic_read(&rdev->nr_pending)==0) { 5787 atomic_read(&rdev->nr_pending)==0) {
@@ -5789,7 +5851,7 @@ void md_check_recovery(mddev_t *mddev)
5789 return; 5851 return;
5790 5852
5791 if (signal_pending(current)) { 5853 if (signal_pending(current)) {
5792 if (mddev->pers->sync_request) { 5854 if (mddev->pers->sync_request && !mddev->external) {
5793 printk(KERN_INFO "md: %s in immediate safe mode\n", 5855 printk(KERN_INFO "md: %s in immediate safe mode\n",
5794 mdname(mddev)); 5856 mdname(mddev));
5795 mddev->safemode = 2; 5857 mddev->safemode = 2;
@@ -5801,7 +5863,7 @@ void md_check_recovery(mddev_t *mddev)
5801 (mddev->flags && !mddev->external) || 5863 (mddev->flags && !mddev->external) ||
5802 test_bit(MD_RECOVERY_NEEDED, &mddev->recovery) || 5864 test_bit(MD_RECOVERY_NEEDED, &mddev->recovery) ||
5803 test_bit(MD_RECOVERY_DONE, &mddev->recovery) || 5865 test_bit(MD_RECOVERY_DONE, &mddev->recovery) ||
5804 (mddev->safemode == 1) || 5866 (mddev->external == 0 && mddev->safemode == 1) ||
5805 (mddev->safemode == 2 && ! atomic_read(&mddev->writes_pending) 5867 (mddev->safemode == 2 && ! atomic_read(&mddev->writes_pending)
5806 && !mddev->in_sync && mddev->recovery_cp == MaxSector) 5868 && !mddev->in_sync && mddev->recovery_cp == MaxSector)
5807 )) 5869 ))
@@ -5810,16 +5872,20 @@ void md_check_recovery(mddev_t *mddev)
5810 if (mddev_trylock(mddev)) { 5872 if (mddev_trylock(mddev)) {
5811 int spares = 0; 5873 int spares = 0;
5812 5874
5813 spin_lock_irq(&mddev->write_lock); 5875 if (!mddev->external) {
5814 if (mddev->safemode && !atomic_read(&mddev->writes_pending) && 5876 spin_lock_irq(&mddev->write_lock);
5815 !mddev->in_sync && mddev->recovery_cp == MaxSector) { 5877 if (mddev->safemode &&
5816 mddev->in_sync = 1; 5878 !atomic_read(&mddev->writes_pending) &&
5817 if (mddev->persistent) 5879 !mddev->in_sync &&
5818 set_bit(MD_CHANGE_CLEAN, &mddev->flags); 5880 mddev->recovery_cp == MaxSector) {
5881 mddev->in_sync = 1;
5882 if (mddev->persistent)
5883 set_bit(MD_CHANGE_CLEAN, &mddev->flags);
5884 }
5885 if (mddev->safemode == 1)
5886 mddev->safemode = 0;
5887 spin_unlock_irq(&mddev->write_lock);
5819 } 5888 }
5820 if (mddev->safemode == 1)
5821 mddev->safemode = 0;
5822 spin_unlock_irq(&mddev->write_lock);
5823 5889
5824 if (mddev->flags) 5890 if (mddev->flags)
5825 md_update_sb(mddev, 0); 5891 md_update_sb(mddev, 0);
@@ -5914,6 +5980,16 @@ void md_check_recovery(mddev_t *mddev)
5914 } 5980 }
5915} 5981}
5916 5982
5983void md_wait_for_blocked_rdev(mdk_rdev_t *rdev, mddev_t *mddev)
5984{
5985 sysfs_notify(&rdev->kobj, NULL, "state");
5986 wait_event_timeout(rdev->blocked_wait,
5987 !test_bit(Blocked, &rdev->flags),
5988 msecs_to_jiffies(5000));
5989 rdev_dec_pending(rdev, mddev);
5990}
5991EXPORT_SYMBOL(md_wait_for_blocked_rdev);
5992
5917static int md_notify_reboot(struct notifier_block *this, 5993static int md_notify_reboot(struct notifier_block *this,
5918 unsigned long code, void *x) 5994 unsigned long code, void *x)
5919{ 5995{
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 9fd473a6dbf5..6778b7cb39bd 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -773,7 +773,6 @@ static int make_request(struct request_queue *q, struct bio * bio)
773 r1bio_t *r1_bio; 773 r1bio_t *r1_bio;
774 struct bio *read_bio; 774 struct bio *read_bio;
775 int i, targets = 0, disks; 775 int i, targets = 0, disks;
776 mdk_rdev_t *rdev;
777 struct bitmap *bitmap = mddev->bitmap; 776 struct bitmap *bitmap = mddev->bitmap;
778 unsigned long flags; 777 unsigned long flags;
779 struct bio_list bl; 778 struct bio_list bl;
@@ -781,6 +780,7 @@ static int make_request(struct request_queue *q, struct bio * bio)
781 const int rw = bio_data_dir(bio); 780 const int rw = bio_data_dir(bio);
782 const int do_sync = bio_sync(bio); 781 const int do_sync = bio_sync(bio);
783 int do_barriers; 782 int do_barriers;
783 mdk_rdev_t *blocked_rdev;
784 784
785 /* 785 /*
786 * Register the new request and wait if the reconstruction 786 * Register the new request and wait if the reconstruction
@@ -862,10 +862,17 @@ static int make_request(struct request_queue *q, struct bio * bio)
862 first = 0; 862 first = 0;
863 } 863 }
864#endif 864#endif
865 retry_write:
866 blocked_rdev = NULL;
865 rcu_read_lock(); 867 rcu_read_lock();
866 for (i = 0; i < disks; i++) { 868 for (i = 0; i < disks; i++) {
867 if ((rdev=rcu_dereference(conf->mirrors[i].rdev)) != NULL && 869 mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[i].rdev);
868 !test_bit(Faulty, &rdev->flags)) { 870 if (rdev && unlikely(test_bit(Blocked, &rdev->flags))) {
871 atomic_inc(&rdev->nr_pending);
872 blocked_rdev = rdev;
873 break;
874 }
875 if (rdev && !test_bit(Faulty, &rdev->flags)) {
869 atomic_inc(&rdev->nr_pending); 876 atomic_inc(&rdev->nr_pending);
870 if (test_bit(Faulty, &rdev->flags)) { 877 if (test_bit(Faulty, &rdev->flags)) {
871 rdev_dec_pending(rdev, mddev); 878 rdev_dec_pending(rdev, mddev);
@@ -878,6 +885,20 @@ static int make_request(struct request_queue *q, struct bio * bio)
878 } 885 }
879 rcu_read_unlock(); 886 rcu_read_unlock();
880 887
888 if (unlikely(blocked_rdev)) {
889 /* Wait for this device to become unblocked */
890 int j;
891
892 for (j = 0; j < i; j++)
893 if (r1_bio->bios[j])
894 rdev_dec_pending(conf->mirrors[j].rdev, mddev);
895
896 allow_barrier(conf);
897 md_wait_for_blocked_rdev(blocked_rdev, mddev);
898 wait_barrier(conf);
899 goto retry_write;
900 }
901
881 BUG_ON(targets == 0); /* we never fail the last device */ 902 BUG_ON(targets == 0); /* we never fail the last device */
882 903
883 if (targets < conf->raid_disks) { 904 if (targets < conf->raid_disks) {
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 1e96aa3ff513..5938fa962922 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -790,6 +790,7 @@ static int make_request(struct request_queue *q, struct bio * bio)
790 const int do_sync = bio_sync(bio); 790 const int do_sync = bio_sync(bio);
791 struct bio_list bl; 791 struct bio_list bl;
792 unsigned long flags; 792 unsigned long flags;
793 mdk_rdev_t *blocked_rdev;
793 794
794 if (unlikely(bio_barrier(bio))) { 795 if (unlikely(bio_barrier(bio))) {
795 bio_endio(bio, -EOPNOTSUPP); 796 bio_endio(bio, -EOPNOTSUPP);
@@ -879,17 +880,23 @@ static int make_request(struct request_queue *q, struct bio * bio)
879 /* 880 /*
880 * WRITE: 881 * WRITE:
881 */ 882 */
882 /* first select target devices under spinlock and 883 /* first select target devices under rcu_lock and
883 * inc refcount on their rdev. Record them by setting 884 * inc refcount on their rdev. Record them by setting
884 * bios[x] to bio 885 * bios[x] to bio
885 */ 886 */
886 raid10_find_phys(conf, r10_bio); 887 raid10_find_phys(conf, r10_bio);
888 retry_write:
889 blocked_rdev = 0;
887 rcu_read_lock(); 890 rcu_read_lock();
888 for (i = 0; i < conf->copies; i++) { 891 for (i = 0; i < conf->copies; i++) {
889 int d = r10_bio->devs[i].devnum; 892 int d = r10_bio->devs[i].devnum;
890 mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[d].rdev); 893 mdk_rdev_t *rdev = rcu_dereference(conf->mirrors[d].rdev);
891 if (rdev && 894 if (rdev && unlikely(test_bit(Blocked, &rdev->flags))) {
892 !test_bit(Faulty, &rdev->flags)) { 895 atomic_inc(&rdev->nr_pending);
896 blocked_rdev = rdev;
897 break;
898 }
899 if (rdev && !test_bit(Faulty, &rdev->flags)) {
893 atomic_inc(&rdev->nr_pending); 900 atomic_inc(&rdev->nr_pending);
894 r10_bio->devs[i].bio = bio; 901 r10_bio->devs[i].bio = bio;
895 } else { 902 } else {
@@ -899,6 +906,22 @@ static int make_request(struct request_queue *q, struct bio * bio)
899 } 906 }
900 rcu_read_unlock(); 907 rcu_read_unlock();
901 908
909 if (unlikely(blocked_rdev)) {
910 /* Have to wait for this device to get unblocked, then retry */
911 int j;
912 int d;
913
914 for (j = 0; j < i; j++)
915 if (r10_bio->devs[j].bio) {
916 d = r10_bio->devs[j].devnum;
917 rdev_dec_pending(conf->mirrors[d].rdev, mddev);
918 }
919 allow_barrier(conf);
920 md_wait_for_blocked_rdev(blocked_rdev, mddev);
921 wait_barrier(conf);
922 goto retry_write;
923 }
924
902 atomic_set(&r10_bio->remaining, 0); 925 atomic_set(&r10_bio->remaining, 0);
903 926
904 bio_list_init(&bl); 927 bio_list_init(&bl);
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 968dacaced6d..087eee0cb809 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -2607,6 +2607,7 @@ static void handle_stripe_expansion(raid5_conf_t *conf, struct stripe_head *sh,
2607 } 2607 }
2608} 2608}
2609 2609
2610
2610/* 2611/*
2611 * handle_stripe - do things to a stripe. 2612 * handle_stripe - do things to a stripe.
2612 * 2613 *
@@ -2632,6 +2633,7 @@ static void handle_stripe5(struct stripe_head *sh)
2632 struct stripe_head_state s; 2633 struct stripe_head_state s;
2633 struct r5dev *dev; 2634 struct r5dev *dev;
2634 unsigned long pending = 0; 2635 unsigned long pending = 0;
2636 mdk_rdev_t *blocked_rdev = NULL;
2635 2637
2636 memset(&s, 0, sizeof(s)); 2638 memset(&s, 0, sizeof(s));
2637 pr_debug("handling stripe %llu, state=%#lx cnt=%d, pd_idx=%d " 2639 pr_debug("handling stripe %llu, state=%#lx cnt=%d, pd_idx=%d "
@@ -2691,6 +2693,11 @@ static void handle_stripe5(struct stripe_head *sh)
2691 if (dev->written) 2693 if (dev->written)
2692 s.written++; 2694 s.written++;
2693 rdev = rcu_dereference(conf->disks[i].rdev); 2695 rdev = rcu_dereference(conf->disks[i].rdev);
2696 if (rdev && unlikely(test_bit(Blocked, &rdev->flags))) {
2697 blocked_rdev = rdev;
2698 atomic_inc(&rdev->nr_pending);
2699 break;
2700 }
2694 if (!rdev || !test_bit(In_sync, &rdev->flags)) { 2701 if (!rdev || !test_bit(In_sync, &rdev->flags)) {
2695 /* The ReadError flag will just be confusing now */ 2702 /* The ReadError flag will just be confusing now */
2696 clear_bit(R5_ReadError, &dev->flags); 2703 clear_bit(R5_ReadError, &dev->flags);
@@ -2705,6 +2712,11 @@ static void handle_stripe5(struct stripe_head *sh)
2705 } 2712 }
2706 rcu_read_unlock(); 2713 rcu_read_unlock();
2707 2714
2715 if (unlikely(blocked_rdev)) {
2716 set_bit(STRIPE_HANDLE, &sh->state);
2717 goto unlock;
2718 }
2719
2708 if (s.to_fill && !test_and_set_bit(STRIPE_OP_BIOFILL, &sh->ops.pending)) 2720 if (s.to_fill && !test_and_set_bit(STRIPE_OP_BIOFILL, &sh->ops.pending))
2709 sh->ops.count++; 2721 sh->ops.count++;
2710 2722
@@ -2894,8 +2906,13 @@ static void handle_stripe5(struct stripe_head *sh)
2894 if (sh->ops.count) 2906 if (sh->ops.count)
2895 pending = get_stripe_work(sh); 2907 pending = get_stripe_work(sh);
2896 2908
2909 unlock:
2897 spin_unlock(&sh->lock); 2910 spin_unlock(&sh->lock);
2898 2911
2912 /* wait for this device to become unblocked */
2913 if (unlikely(blocked_rdev))
2914 md_wait_for_blocked_rdev(blocked_rdev, conf->mddev);
2915
2899 if (pending) 2916 if (pending)
2900 raid5_run_ops(sh, pending); 2917 raid5_run_ops(sh, pending);
2901 2918
@@ -2912,6 +2929,7 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
2912 struct stripe_head_state s; 2929 struct stripe_head_state s;
2913 struct r6_state r6s; 2930 struct r6_state r6s;
2914 struct r5dev *dev, *pdev, *qdev; 2931 struct r5dev *dev, *pdev, *qdev;
2932 mdk_rdev_t *blocked_rdev = NULL;
2915 2933
2916 r6s.qd_idx = raid6_next_disk(pd_idx, disks); 2934 r6s.qd_idx = raid6_next_disk(pd_idx, disks);
2917 pr_debug("handling stripe %llu, state=%#lx cnt=%d, " 2935 pr_debug("handling stripe %llu, state=%#lx cnt=%d, "
@@ -2975,6 +2993,11 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
2975 if (dev->written) 2993 if (dev->written)
2976 s.written++; 2994 s.written++;
2977 rdev = rcu_dereference(conf->disks[i].rdev); 2995 rdev = rcu_dereference(conf->disks[i].rdev);
2996 if (rdev && unlikely(test_bit(Blocked, &rdev->flags))) {
2997 blocked_rdev = rdev;
2998 atomic_inc(&rdev->nr_pending);
2999 break;
3000 }
2978 if (!rdev || !test_bit(In_sync, &rdev->flags)) { 3001 if (!rdev || !test_bit(In_sync, &rdev->flags)) {
2979 /* The ReadError flag will just be confusing now */ 3002 /* The ReadError flag will just be confusing now */
2980 clear_bit(R5_ReadError, &dev->flags); 3003 clear_bit(R5_ReadError, &dev->flags);
@@ -2989,6 +3012,11 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
2989 set_bit(R5_Insync, &dev->flags); 3012 set_bit(R5_Insync, &dev->flags);
2990 } 3013 }
2991 rcu_read_unlock(); 3014 rcu_read_unlock();
3015
3016 if (unlikely(blocked_rdev)) {
3017 set_bit(STRIPE_HANDLE, &sh->state);
3018 goto unlock;
3019 }
2992 pr_debug("locked=%d uptodate=%d to_read=%d" 3020 pr_debug("locked=%d uptodate=%d to_read=%d"
2993 " to_write=%d failed=%d failed_num=%d,%d\n", 3021 " to_write=%d failed=%d failed_num=%d,%d\n",
2994 s.locked, s.uptodate, s.to_read, s.to_write, s.failed, 3022 s.locked, s.uptodate, s.to_read, s.to_write, s.failed,
@@ -3094,8 +3122,13 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
3094 !test_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending)) 3122 !test_bit(STRIPE_OP_COMPUTE_BLK, &sh->ops.pending))
3095 handle_stripe_expansion(conf, sh, &r6s); 3123 handle_stripe_expansion(conf, sh, &r6s);
3096 3124
3125 unlock:
3097 spin_unlock(&sh->lock); 3126 spin_unlock(&sh->lock);
3098 3127
3128 /* wait for this device to become unblocked */
3129 if (unlikely(blocked_rdev))
3130 md_wait_for_blocked_rdev(blocked_rdev, conf->mddev);
3131
3099 return_io(return_bi); 3132 return_io(return_bi);
3100 3133
3101 for (i=disks; i-- ;) { 3134 for (i=disks; i-- ;) {
diff --git a/drivers/media/common/Makefile b/drivers/media/common/Makefile
index 8e7448230643..351b98b9b302 100644
--- a/drivers/media/common/Makefile
+++ b/drivers/media/common/Makefile
@@ -2,6 +2,7 @@ saa7146-objs := saa7146_i2c.o saa7146_core.o
2saa7146_vv-objs := saa7146_fops.o saa7146_video.o saa7146_hlp.o saa7146_vbi.o 2saa7146_vv-objs := saa7146_fops.o saa7146_video.o saa7146_hlp.o saa7146_vbi.o
3ir-common-objs := ir-functions.o ir-keymaps.o 3ir-common-objs := ir-functions.o ir-keymaps.o
4 4
5obj-y += tuners/
5obj-$(CONFIG_VIDEO_SAA7146) += saa7146.o 6obj-$(CONFIG_VIDEO_SAA7146) += saa7146.o
6obj-$(CONFIG_VIDEO_SAA7146_VV) += saa7146_vv.o 7obj-$(CONFIG_VIDEO_SAA7146_VV) += saa7146_vv.o
7obj-$(CONFIG_VIDEO_IR) += ir-common.o 8obj-$(CONFIG_VIDEO_IR) += ir-common.o
diff --git a/drivers/media/common/tuners/Kconfig b/drivers/media/common/tuners/Kconfig
index 7b379e1ce01b..5be85ff53e12 100644
--- a/drivers/media/common/tuners/Kconfig
+++ b/drivers/media/common/tuners/Kconfig
@@ -1,12 +1,17 @@
1config MEDIA_ATTACH 1config MEDIA_ATTACH
2 bool "Load and attach frontend driver modules as needed" 2 bool "Load and attach frontend and tuner driver modules as needed"
3 depends on DVB_CORE 3 depends on DVB_CORE
4 depends on MODULES 4 depends on MODULES
5 help 5 help
6 Remove the static dependency of DVB card drivers on all 6 Remove the static dependency of DVB card drivers on all
7 frontend modules for all possible card variants. Instead, 7 frontend modules for all possible card variants. Instead,
8 allow the card drivers to only load the frontend modules 8 allow the card drivers to only load the frontend modules
9 they require. This saves several KBytes of memory. 9 they require.
10
11 Also, tuner module will automatically load a tuner driver
12 when needed, for analog mode.
13
14 This saves several KBytes of memory.
10 15
11 Note: You will need module-init-tools v3.2 or later for this feature. 16 Note: You will need module-init-tools v3.2 or later for this feature.
12 17
diff --git a/drivers/media/video/bt8xx/bttvp.h b/drivers/media/video/bt8xx/bttvp.h
index 03816b73f847..27da7b423275 100644
--- a/drivers/media/video/bt8xx/bttvp.h
+++ b/drivers/media/video/bt8xx/bttvp.h
@@ -81,8 +81,6 @@
81/* Limits scaled width, which must be a multiple of 4. */ 81/* Limits scaled width, which must be a multiple of 4. */
82#define MAX_HACTIVE (0x3FF & -4) 82#define MAX_HACTIVE (0x3FF & -4)
83 83
84#define clamp(x, low, high) min (max (low, x), high)
85
86#define BTTV_NORMS (\ 84#define BTTV_NORMS (\
87 V4L2_STD_PAL | V4L2_STD_PAL_N | \ 85 V4L2_STD_PAL | V4L2_STD_PAL_N | \
88 V4L2_STD_PAL_Nc | V4L2_STD_SECAM | \ 86 V4L2_STD_PAL_Nc | V4L2_STD_SECAM | \
diff --git a/drivers/media/video/cx18/Kconfig b/drivers/media/video/cx18/Kconfig
index be654a27bd3c..acc4b47f1d1d 100644
--- a/drivers/media/video/cx18/Kconfig
+++ b/drivers/media/video/cx18/Kconfig
@@ -4,7 +4,7 @@ config VIDEO_CX18
4 select I2C_ALGOBIT 4 select I2C_ALGOBIT
5 select FW_LOADER 5 select FW_LOADER
6 select VIDEO_IR 6 select VIDEO_IR
7 select VIDEO_TUNER 7 select MEDIA_TUNER
8 select VIDEO_TVEEPROM 8 select VIDEO_TVEEPROM
9 select VIDEO_CX2341X 9 select VIDEO_CX2341X
10 select VIDEO_CS5345 10 select VIDEO_CS5345
diff --git a/drivers/media/video/cx18/cx18-driver.c b/drivers/media/video/cx18/cx18-driver.c
index 9f31befc3139..8f5ed9b4bf83 100644
--- a/drivers/media/video/cx18/cx18-driver.c
+++ b/drivers/media/video/cx18/cx18-driver.c
@@ -567,7 +567,7 @@ static void cx18_load_and_init_modules(struct cx18 *cx)
567 int i; 567 int i;
568 568
569 /* load modules */ 569 /* load modules */
570#ifndef CONFIG_VIDEO_TUNER 570#ifndef CONFIG_MEDIA_TUNER
571 hw = cx18_request_module(cx, hw, "tuner", CX18_HW_TUNER); 571 hw = cx18_request_module(cx, hw, "tuner", CX18_HW_TUNER);
572#endif 572#endif
573#ifndef CONFIG_VIDEO_CS5345 573#ifndef CONFIG_VIDEO_CS5345
diff --git a/drivers/media/video/cx88/cx88-i2c.c b/drivers/media/video/cx88/cx88-i2c.c
index 00aa7a3f1105..cb6a096069c7 100644
--- a/drivers/media/video/cx88/cx88-i2c.c
+++ b/drivers/media/video/cx88/cx88-i2c.c
@@ -99,7 +99,6 @@ static int cx8800_bit_getsda(void *data)
99 99
100static int attach_inform(struct i2c_client *client) 100static int attach_inform(struct i2c_client *client)
101{ 101{
102 struct tuner_setup tun_setup;
103 struct cx88_core *core = i2c_get_adapdata(client->adapter); 102 struct cx88_core *core = i2c_get_adapdata(client->adapter);
104 103
105 dprintk(1, "%s i2c attach [addr=0x%x,client=%s]\n", 104 dprintk(1, "%s i2c attach [addr=0x%x,client=%s]\n",
diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
index 47b5649729df..ed020f722b05 100644
--- a/drivers/media/video/ivtv/ivtv-driver.c
+++ b/drivers/media/video/ivtv/ivtv-driver.c
@@ -1049,7 +1049,7 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
1049 IVTV_ENCODER_SIZE); 1049 IVTV_ENCODER_SIZE);
1050 if (!itv->enc_mem) { 1050 if (!itv->enc_mem) {
1051 IVTV_ERR("ioremap failed, perhaps increasing __VMALLOC_RESERVE in page.h\n"); 1051 IVTV_ERR("ioremap failed, perhaps increasing __VMALLOC_RESERVE in page.h\n");
1052 IVTV_ERR("or disabling CONFIG_HIMEM4G into the kernel would help\n"); 1052 IVTV_ERR("or disabling CONFIG_HIGHMEM4G into the kernel would help\n");
1053 retval = -ENOMEM; 1053 retval = -ENOMEM;
1054 goto free_mem; 1054 goto free_mem;
1055 } 1055 }
@@ -1061,7 +1061,7 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
1061 IVTV_DECODER_SIZE); 1061 IVTV_DECODER_SIZE);
1062 if (!itv->dec_mem) { 1062 if (!itv->dec_mem) {
1063 IVTV_ERR("ioremap failed, perhaps increasing __VMALLOC_RESERVE in page.h\n"); 1063 IVTV_ERR("ioremap failed, perhaps increasing __VMALLOC_RESERVE in page.h\n");
1064 IVTV_ERR("or disabling CONFIG_HIMEM4G into the kernel would help\n"); 1064 IVTV_ERR("or disabling CONFIG_HIGHMEM4G into the kernel would help\n");
1065 retval = -ENOMEM; 1065 retval = -ENOMEM;
1066 goto free_mem; 1066 goto free_mem;
1067 } 1067 }
@@ -1077,7 +1077,7 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
1077 ioremap_nocache(itv->base_addr + IVTV_REG_OFFSET, IVTV_REG_SIZE); 1077 ioremap_nocache(itv->base_addr + IVTV_REG_OFFSET, IVTV_REG_SIZE);
1078 if (!itv->reg_mem) { 1078 if (!itv->reg_mem) {
1079 IVTV_ERR("ioremap failed, perhaps increasing __VMALLOC_RESERVE in page.h\n"); 1079 IVTV_ERR("ioremap failed, perhaps increasing __VMALLOC_RESERVE in page.h\n");
1080 IVTV_ERR("or disabling CONFIG_HIMEM4G into the kernel would help\n"); 1080 IVTV_ERR("or disabling CONFIG_HIGHMEM4G into the kernel would help\n");
1081 retval = -ENOMEM; 1081 retval = -ENOMEM;
1082 goto free_io; 1082 goto free_io;
1083 } 1083 }
diff --git a/drivers/media/video/ivtv/ivtv-fileops.c b/drivers/media/video/ivtv/ivtv-fileops.c
index a7640c49f1d8..2b74b0ab1477 100644
--- a/drivers/media/video/ivtv/ivtv-fileops.c
+++ b/drivers/media/video/ivtv/ivtv-fileops.c
@@ -755,8 +755,10 @@ unsigned int ivtv_v4l2_enc_poll(struct file *filp, poll_table * wait)
755 IVTV_DEBUG_HI_FILE("Encoder poll\n"); 755 IVTV_DEBUG_HI_FILE("Encoder poll\n");
756 poll_wait(filp, &s->waitq, wait); 756 poll_wait(filp, &s->waitq, wait);
757 757
758 if (eof || s->q_full.length || s->q_io.length) 758 if (s->q_full.length || s->q_io.length)
759 return POLLIN | POLLRDNORM; 759 return POLLIN | POLLRDNORM;
760 if (eof)
761 return POLLHUP;
760 return 0; 762 return 0;
761} 763}
762 764
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index cc19c4abb467..6bf104ea051d 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -34,7 +34,7 @@
34#define PREFIX t->i2c->driver->driver.name 34#define PREFIX t->i2c->driver->driver.name
35 35
36/** This macro allows us to probe dynamically, avoiding static links */ 36/** This macro allows us to probe dynamically, avoiding static links */
37#ifdef CONFIG_DVB_CORE_ATTACH 37#ifdef CONFIG_MEDIA_ATTACH
38#define tuner_symbol_probe(FUNCTION, ARGS...) ({ \ 38#define tuner_symbol_probe(FUNCTION, ARGS...) ({ \
39 int __r = -EINVAL; \ 39 int __r = -EINVAL; \
40 typeof(&FUNCTION) __a = symbol_request(FUNCTION); \ 40 typeof(&FUNCTION) __a = symbol_request(FUNCTION); \
diff --git a/drivers/media/video/usbvideo/vicam.c b/drivers/media/video/usbvideo/vicam.c
index 64819353276a..17f542dfb366 100644
--- a/drivers/media/video/usbvideo/vicam.c
+++ b/drivers/media/video/usbvideo/vicam.c
@@ -70,12 +70,6 @@
70 70
71#define VICAM_HEADER_SIZE 64 71#define VICAM_HEADER_SIZE 64
72 72
73#define clamp( x, l, h ) max_t( __typeof__( x ), \
74 ( l ), \
75 min_t( __typeof__( x ), \
76 ( h ), \
77 ( x ) ) )
78
79/* Not sure what all the bytes in these char 73/* Not sure what all the bytes in these char
80 * arrays do, but they're necessary to make 74 * arrays do, but they're necessary to make
81 * the camera work. 75 * the camera work.
diff --git a/drivers/mfd/asic3.c b/drivers/mfd/asic3.c
index f6f2d960cadb..ef8a492766a7 100644
--- a/drivers/mfd/asic3.c
+++ b/drivers/mfd/asic3.c
@@ -132,7 +132,7 @@ static void asic3_irq_demux(unsigned int irq, struct irq_desc *desc)
132 132
133 if (iter >= MAX_ASIC_ISR_LOOPS) 133 if (iter >= MAX_ASIC_ISR_LOOPS)
134 printk(KERN_ERR "%s: interrupt processing overrun\n", 134 printk(KERN_ERR "%s: interrupt processing overrun\n",
135 __FUNCTION__); 135 __func__);
136} 136}
137 137
138static inline int asic3_irq_to_bank(struct asic3 *asic, int irq) 138static inline int asic3_irq_to_bank(struct asic3 *asic, int irq)
@@ -409,7 +409,7 @@ int asic3_gpio_get_value(struct asic3 *asic, unsigned gpio)
409 return asic3_get_gpio_d(asic, Status) & mask; 409 return asic3_get_gpio_d(asic, Status) & mask;
410 default: 410 default:
411 printk(KERN_ERR "%s: invalid GPIO value 0x%x", 411 printk(KERN_ERR "%s: invalid GPIO value 0x%x",
412 __FUNCTION__, gpio); 412 __func__, gpio);
413 return -EINVAL; 413 return -EINVAL;
414 } 414 }
415} 415}
@@ -437,7 +437,7 @@ void asic3_gpio_set_value(struct asic3 *asic, unsigned gpio, int val)
437 return; 437 return;
438 default: 438 default:
439 printk(KERN_ERR "%s: invalid GPIO value 0x%x", 439 printk(KERN_ERR "%s: invalid GPIO value 0x%x",
440 __FUNCTION__, gpio); 440 __func__, gpio);
441 return; 441 return;
442 } 442 }
443} 443}
diff --git a/drivers/mfd/sm501.c b/drivers/mfd/sm501.c
index 6e655b4c6682..2fe64734d8af 100644
--- a/drivers/mfd/sm501.c
+++ b/drivers/mfd/sm501.c
@@ -349,11 +349,11 @@ int sm501_unit_power(struct device *dev, unsigned int unit, unsigned int to)
349 mode &= 3; /* get current power mode */ 349 mode &= 3; /* get current power mode */
350 350
351 if (unit >= ARRAY_SIZE(sm->unit_power)) { 351 if (unit >= ARRAY_SIZE(sm->unit_power)) {
352 dev_err(dev, "%s: bad unit %d\n", __FUNCTION__, unit); 352 dev_err(dev, "%s: bad unit %d\n", __func__, unit);
353 goto already; 353 goto already;
354 } 354 }
355 355
356 dev_dbg(sm->dev, "%s: unit %d, cur %d, to %d\n", __FUNCTION__, unit, 356 dev_dbg(sm->dev, "%s: unit %d, cur %d, to %d\n", __func__, unit,
357 sm->unit_power[unit], to); 357 sm->unit_power[unit], to);
358 358
359 if (to == 0 && sm->unit_power[unit] == 0) { 359 if (to == 0 && sm->unit_power[unit] == 0) {
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 297a48f85446..636af2862308 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -140,6 +140,7 @@ config ACER_WMI
140 depends on EXPERIMENTAL 140 depends on EXPERIMENTAL
141 depends on ACPI 141 depends on ACPI
142 depends on LEDS_CLASS 142 depends on LEDS_CLASS
143 depends on NEW_LEDS
143 depends on BACKLIGHT_CLASS_DEVICE 144 depends on BACKLIGHT_CLASS_DEVICE
144 depends on SERIO_I8042 145 depends on SERIO_I8042
145 select ACPI_WMI 146 select ACPI_WMI
@@ -160,6 +161,7 @@ config ASUS_LAPTOP
160 depends on ACPI 161 depends on ACPI
161 depends on EXPERIMENTAL && !ACPI_ASUS 162 depends on EXPERIMENTAL && !ACPI_ASUS
162 depends on LEDS_CLASS 163 depends on LEDS_CLASS
164 depends on NEW_LEDS
163 depends on BACKLIGHT_CLASS_DEVICE 165 depends on BACKLIGHT_CLASS_DEVICE
164 ---help--- 166 ---help---
165 This is the new Linux driver for Asus laptops. It may also support some 167 This is the new Linux driver for Asus laptops. It may also support some
@@ -241,10 +243,13 @@ config SONYPI_COMPAT
241config THINKPAD_ACPI 243config THINKPAD_ACPI
242 tristate "ThinkPad ACPI Laptop Extras" 244 tristate "ThinkPad ACPI Laptop Extras"
243 depends on X86 && ACPI 245 depends on X86 && ACPI
246 select BACKLIGHT_LCD_SUPPORT
244 select BACKLIGHT_CLASS_DEVICE 247 select BACKLIGHT_CLASS_DEVICE
245 select HWMON 248 select HWMON
246 select NVRAM 249 select NVRAM
247 depends on INPUT 250 select INPUT
251 select NEW_LEDS
252 select LEDS_CLASS
248 ---help--- 253 ---help---
249 This is a driver for the IBM and Lenovo ThinkPad laptops. It adds 254 This is a driver for the IBM and Lenovo ThinkPad laptops. It adds
250 support for Fn-Fx key combinations, Bluetooth control, video 255 support for Fn-Fx key combinations, Bluetooth control, video
@@ -344,6 +349,7 @@ config ATMEL_SSC
344config INTEL_MENLOW 349config INTEL_MENLOW
345 tristate "Thermal Management driver for Intel menlow platform" 350 tristate "Thermal Management driver for Intel menlow platform"
346 depends on ACPI_THERMAL 351 depends on ACPI_THERMAL
352 select THERMAL
347 depends on X86 353 depends on X86
348 ---help--- 354 ---help---
349 ACPI thermal management enhancement driver on 355 ACPI thermal management enhancement driver on
@@ -351,6 +357,19 @@ config INTEL_MENLOW
351 357
352 If unsure, say N. 358 If unsure, say N.
353 359
360config EEEPC_LAPTOP
361 tristate "Eee PC Hotkey Driver (EXPERIMENTAL)"
362 depends on X86
363 depends on ACPI
364 depends on BACKLIGHT_CLASS_DEVICE
365 depends on HWMON
366 depends on EXPERIMENTAL
367 ---help---
368 This driver supports the Fn-Fx keys on Eee PC laptops.
369 It also adds the ability to switch camera/wlan on/off.
370
371 If you have an Eee PC laptop, say Y or M here.
372
354config ENCLOSURE_SERVICES 373config ENCLOSURE_SERVICES
355 tristate "Enclosure Services" 374 tristate "Enclosure Services"
356 default n 375 default n
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 5914da434854..1952875a272e 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -7,7 +7,8 @@ obj-$(CONFIG_IBM_ASM) += ibmasm/
7obj-$(CONFIG_HDPU_FEATURES) += hdpuftrs/ 7obj-$(CONFIG_HDPU_FEATURES) += hdpuftrs/
8obj-$(CONFIG_MSI_LAPTOP) += msi-laptop.o 8obj-$(CONFIG_MSI_LAPTOP) += msi-laptop.o
9obj-$(CONFIG_ACER_WMI) += acer-wmi.o 9obj-$(CONFIG_ACER_WMI) += acer-wmi.o
10obj-$(CONFIG_ASUS_LAPTOP) += asus-laptop.o 10obj-$(CONFIG_ASUS_LAPTOP) += asus-laptop.o
11obj-$(CONFIG_EEEPC_LAPTOP) += eeepc-laptop.o
11obj-$(CONFIG_ATMEL_PWM) += atmel_pwm.o 12obj-$(CONFIG_ATMEL_PWM) += atmel_pwm.o
12obj-$(CONFIG_ATMEL_SSC) += atmel-ssc.o 13obj-$(CONFIG_ATMEL_SSC) += atmel-ssc.o
13obj-$(CONFIG_ATMEL_TCLIB) += atmel_tclib.o 14obj-$(CONFIG_ATMEL_TCLIB) += atmel_tclib.o
diff --git a/drivers/misc/eeepc-laptop.c b/drivers/misc/eeepc-laptop.c
new file mode 100644
index 000000000000..6d727609097f
--- /dev/null
+++ b/drivers/misc/eeepc-laptop.c
@@ -0,0 +1,666 @@
1/*
2 * eepc-laptop.c - Asus Eee PC extras
3 *
4 * Based on asus_acpi.c as patched for the Eee PC by Asus:
5 * ftp://ftp.asus.com/pub/ASUS/EeePC/701/ASUS_ACPI_071126.rar
6 * Based on eee.c from eeepc-linux
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, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */
18
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/init.h>
22#include <linux/types.h>
23#include <linux/platform_device.h>
24#include <linux/backlight.h>
25#include <linux/fb.h>
26#include <linux/hwmon.h>
27#include <linux/hwmon-sysfs.h>
28#include <acpi/acpi_drivers.h>
29#include <acpi/acpi_bus.h>
30#include <linux/uaccess.h>
31
32#define EEEPC_LAPTOP_VERSION "0.1"
33
34#define EEEPC_HOTK_NAME "Eee PC Hotkey Driver"
35#define EEEPC_HOTK_FILE "eeepc"
36#define EEEPC_HOTK_CLASS "hotkey"
37#define EEEPC_HOTK_DEVICE_NAME "Hotkey"
38#define EEEPC_HOTK_HID "ASUS010"
39
40#define EEEPC_LOG EEEPC_HOTK_FILE ": "
41#define EEEPC_ERR KERN_ERR EEEPC_LOG
42#define EEEPC_WARNING KERN_WARNING EEEPC_LOG
43#define EEEPC_NOTICE KERN_NOTICE EEEPC_LOG
44#define EEEPC_INFO KERN_INFO EEEPC_LOG
45
46/*
47 * Definitions for Asus EeePC
48 */
49#define NOTIFY_WLAN_ON 0x10
50#define NOTIFY_BRN_MIN 0x20
51#define NOTIFY_BRN_MAX 0x2f
52
53enum {
54 DISABLE_ASL_WLAN = 0x0001,
55 DISABLE_ASL_BLUETOOTH = 0x0002,
56 DISABLE_ASL_IRDA = 0x0004,
57 DISABLE_ASL_CAMERA = 0x0008,
58 DISABLE_ASL_TV = 0x0010,
59 DISABLE_ASL_GPS = 0x0020,
60 DISABLE_ASL_DISPLAYSWITCH = 0x0040,
61 DISABLE_ASL_MODEM = 0x0080,
62 DISABLE_ASL_CARDREADER = 0x0100
63};
64
65enum {
66 CM_ASL_WLAN = 0,
67 CM_ASL_BLUETOOTH,
68 CM_ASL_IRDA,
69 CM_ASL_1394,
70 CM_ASL_CAMERA,
71 CM_ASL_TV,
72 CM_ASL_GPS,
73 CM_ASL_DVDROM,
74 CM_ASL_DISPLAYSWITCH,
75 CM_ASL_PANELBRIGHT,
76 CM_ASL_BIOSFLASH,
77 CM_ASL_ACPIFLASH,
78 CM_ASL_CPUFV,
79 CM_ASL_CPUTEMPERATURE,
80 CM_ASL_FANCPU,
81 CM_ASL_FANCHASSIS,
82 CM_ASL_USBPORT1,
83 CM_ASL_USBPORT2,
84 CM_ASL_USBPORT3,
85 CM_ASL_MODEM,
86 CM_ASL_CARDREADER,
87 CM_ASL_LID
88};
89
90const char *cm_getv[] = {
91 "WLDG", NULL, NULL, NULL,
92 "CAMG", NULL, NULL, NULL,
93 NULL, "PBLG", NULL, NULL,
94 "CFVG", NULL, NULL, NULL,
95 "USBG", NULL, NULL, "MODG",
96 "CRDG", "LIDG"
97};
98
99const char *cm_setv[] = {
100 "WLDS", NULL, NULL, NULL,
101 "CAMS", NULL, NULL, NULL,
102 "SDSP", "PBLS", "HDPS", NULL,
103 "CFVS", NULL, NULL, NULL,
104 "USBG", NULL, NULL, "MODS",
105 "CRDS", NULL
106};
107
108#define EEEPC_EC "\\_SB.PCI0.SBRG.EC0."
109
110#define EEEPC_EC_FAN_PWM EEEPC_EC "SC02" /* Fan PWM duty cycle (%) */
111#define EEEPC_EC_SC02 0x63
112#define EEEPC_EC_FAN_HRPM EEEPC_EC "SC05" /* High byte, fan speed (RPM) */
113#define EEEPC_EC_FAN_LRPM EEEPC_EC "SC06" /* Low byte, fan speed (RPM) */
114#define EEEPC_EC_FAN_CTRL EEEPC_EC "SFB3" /* Byte containing SF25 */
115#define EEEPC_EC_SFB3 0xD3
116
117/*
118 * This is the main structure, we can use it to store useful information
119 * about the hotk device
120 */
121struct eeepc_hotk {
122 struct acpi_device *device; /* the device we are in */
123 acpi_handle handle; /* the handle of the hotk device */
124 u32 cm_supported; /* the control methods supported
125 by this BIOS */
126 uint init_flag; /* Init flags */
127 u16 event_count[128]; /* count for each event */
128};
129
130/* The actual device the driver binds to */
131static struct eeepc_hotk *ehotk;
132
133/* Platform device/driver */
134static struct platform_driver platform_driver = {
135 .driver = {
136 .name = EEEPC_HOTK_FILE,
137 .owner = THIS_MODULE,
138 }
139};
140
141static struct platform_device *platform_device;
142
143/*
144 * The hotkey driver declaration
145 */
146static int eeepc_hotk_add(struct acpi_device *device);
147static int eeepc_hotk_remove(struct acpi_device *device, int type);
148
149static const struct acpi_device_id eeepc_device_ids[] = {
150 {EEEPC_HOTK_HID, 0},
151 {"", 0},
152};
153MODULE_DEVICE_TABLE(acpi, eeepc_device_ids);
154
155static struct acpi_driver eeepc_hotk_driver = {
156 .name = EEEPC_HOTK_NAME,
157 .class = EEEPC_HOTK_CLASS,
158 .ids = eeepc_device_ids,
159 .ops = {
160 .add = eeepc_hotk_add,
161 .remove = eeepc_hotk_remove,
162 },
163};
164
165/* The backlight device /sys/class/backlight */
166static struct backlight_device *eeepc_backlight_device;
167
168/* The hwmon device */
169static struct device *eeepc_hwmon_device;
170
171/*
172 * The backlight class declaration
173 */
174static int read_brightness(struct backlight_device *bd);
175static int update_bl_status(struct backlight_device *bd);
176static struct backlight_ops eeepcbl_ops = {
177 .get_brightness = read_brightness,
178 .update_status = update_bl_status,
179};
180
181MODULE_AUTHOR("Corentin Chary, Eric Cooper");
182MODULE_DESCRIPTION(EEEPC_HOTK_NAME);
183MODULE_LICENSE("GPL");
184
185/*
186 * ACPI Helpers
187 */
188static int write_acpi_int(acpi_handle handle, const char *method, int val,
189 struct acpi_buffer *output)
190{
191 struct acpi_object_list params;
192 union acpi_object in_obj;
193 acpi_status status;
194
195 params.count = 1;
196 params.pointer = &in_obj;
197 in_obj.type = ACPI_TYPE_INTEGER;
198 in_obj.integer.value = val;
199
200 status = acpi_evaluate_object(handle, (char *)method, &params, output);
201 return (status == AE_OK ? 0 : -1);
202}
203
204static int read_acpi_int(acpi_handle handle, const char *method, int *val)
205{
206 acpi_status status;
207 ulong result;
208
209 status = acpi_evaluate_integer(handle, (char *)method, NULL, &result);
210 if (ACPI_FAILURE(status)) {
211 *val = -1;
212 return -1;
213 } else {
214 *val = result;
215 return 0;
216 }
217}
218
219static int set_acpi(int cm, int value)
220{
221 if (ehotk->cm_supported & (0x1 << cm)) {
222 const char *method = cm_setv[cm];
223 if (method == NULL)
224 return -ENODEV;
225 if (write_acpi_int(ehotk->handle, method, value, NULL))
226 printk(EEEPC_WARNING "Error writing %s\n", method);
227 }
228 return 0;
229}
230
231static int get_acpi(int cm)
232{
233 int value = -1;
234 if ((ehotk->cm_supported & (0x1 << cm))) {
235 const char *method = cm_getv[cm];
236 if (method == NULL)
237 return -ENODEV;
238 if (read_acpi_int(ehotk->handle, method, &value))
239 printk(EEEPC_WARNING "Error reading %s\n", method);
240 }
241 return value;
242}
243
244/*
245 * Backlight
246 */
247static int read_brightness(struct backlight_device *bd)
248{
249 return get_acpi(CM_ASL_PANELBRIGHT);
250}
251
252static int set_brightness(struct backlight_device *bd, int value)
253{
254 value = max(0, min(15, value));
255 return set_acpi(CM_ASL_PANELBRIGHT, value);
256}
257
258static int update_bl_status(struct backlight_device *bd)
259{
260 return set_brightness(bd, bd->props.brightness);
261}
262
263/*
264 * Sys helpers
265 */
266static int parse_arg(const char *buf, unsigned long count, int *val)
267{
268 if (!count)
269 return 0;
270 if (sscanf(buf, "%i", val) != 1)
271 return -EINVAL;
272 return count;
273}
274
275static ssize_t store_sys_acpi(int cm, const char *buf, size_t count)
276{
277 int rv, value;
278
279 rv = parse_arg(buf, count, &value);
280 if (rv > 0)
281 set_acpi(cm, value);
282 return rv;
283}
284
285static ssize_t show_sys_acpi(int cm, char *buf)
286{
287 return sprintf(buf, "%d\n", get_acpi(cm));
288}
289
290#define EEEPC_CREATE_DEVICE_ATTR(_name, _cm) \
291 static ssize_t show_##_name(struct device *dev, \
292 struct device_attribute *attr, \
293 char *buf) \
294 { \
295 return show_sys_acpi(_cm, buf); \
296 } \
297 static ssize_t store_##_name(struct device *dev, \
298 struct device_attribute *attr, \
299 const char *buf, size_t count) \
300 { \
301 return store_sys_acpi(_cm, buf, count); \
302 } \
303 static struct device_attribute dev_attr_##_name = { \
304 .attr = { \
305 .name = __stringify(_name), \
306 .mode = 0644 }, \
307 .show = show_##_name, \
308 .store = store_##_name, \
309 }
310
311EEEPC_CREATE_DEVICE_ATTR(camera, CM_ASL_CAMERA);
312EEEPC_CREATE_DEVICE_ATTR(cardr, CM_ASL_CARDREADER);
313EEEPC_CREATE_DEVICE_ATTR(disp, CM_ASL_DISPLAYSWITCH);
314EEEPC_CREATE_DEVICE_ATTR(wlan, CM_ASL_WLAN);
315
316static struct attribute *platform_attributes[] = {
317 &dev_attr_camera.attr,
318 &dev_attr_cardr.attr,
319 &dev_attr_disp.attr,
320 &dev_attr_wlan.attr,
321 NULL
322};
323
324static struct attribute_group platform_attribute_group = {
325 .attrs = platform_attributes
326};
327
328/*
329 * Hotkey functions
330 */
331static int eeepc_hotk_check(void)
332{
333 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
334 int result;
335
336 result = acpi_bus_get_status(ehotk->device);
337 if (result)
338 return result;
339 if (ehotk->device->status.present) {
340 if (write_acpi_int(ehotk->handle, "INIT", ehotk->init_flag,
341 &buffer)) {
342 printk(EEEPC_ERR "Hotkey initialization failed\n");
343 return -ENODEV;
344 } else {
345 printk(EEEPC_NOTICE "Hotkey init flags 0x%x\n",
346 ehotk->init_flag);
347 }
348 /* get control methods supported */
349 if (read_acpi_int(ehotk->handle, "CMSG"
350 , &ehotk->cm_supported)) {
351 printk(EEEPC_ERR
352 "Get control methods supported failed\n");
353 return -ENODEV;
354 } else {
355 printk(EEEPC_INFO
356 "Get control methods supported: 0x%x\n",
357 ehotk->cm_supported);
358 }
359 } else {
360 printk(EEEPC_ERR "Hotkey device not present, aborting\n");
361 return -EINVAL;
362 }
363 return 0;
364}
365
366static void notify_wlan(u32 *event)
367{
368 /* if DISABLE_ASL_WLAN is set, the notify code for fn+f2
369 will always be 0x10 */
370 if (ehotk->cm_supported & (0x1 << CM_ASL_WLAN)) {
371 const char *method = cm_getv[CM_ASL_WLAN];
372 int value;
373 if (read_acpi_int(ehotk->handle, method, &value))
374 printk(EEEPC_WARNING "Error reading %s\n",
375 method);
376 else if (value == 1)
377 *event = 0x11;
378 }
379}
380
381static void notify_brn(void)
382{
383 struct backlight_device *bd = eeepc_backlight_device;
384 bd->props.brightness = read_brightness(bd);
385}
386
387static void eeepc_hotk_notify(acpi_handle handle, u32 event, void *data)
388{
389 if (!ehotk)
390 return;
391 if (event == NOTIFY_WLAN_ON && (DISABLE_ASL_WLAN & ehotk->init_flag))
392 notify_wlan(&event);
393 if (event >= NOTIFY_BRN_MIN && event <= NOTIFY_BRN_MAX)
394 notify_brn();
395 acpi_bus_generate_proc_event(ehotk->device, event,
396 ehotk->event_count[event % 128]++);
397}
398
399static int eeepc_hotk_add(struct acpi_device *device)
400{
401 acpi_status status = AE_OK;
402 int result;
403
404 if (!device)
405 return -EINVAL;
406 printk(EEEPC_NOTICE EEEPC_HOTK_NAME "\n");
407 ehotk = kzalloc(sizeof(struct eeepc_hotk), GFP_KERNEL);
408 if (!ehotk)
409 return -ENOMEM;
410 ehotk->init_flag = DISABLE_ASL_WLAN | DISABLE_ASL_DISPLAYSWITCH;
411 ehotk->handle = device->handle;
412 strcpy(acpi_device_name(device), EEEPC_HOTK_DEVICE_NAME);
413 strcpy(acpi_device_class(device), EEEPC_HOTK_CLASS);
414 acpi_driver_data(device) = ehotk;
415 ehotk->device = device;
416 result = eeepc_hotk_check();
417 if (result)
418 goto end;
419 status = acpi_install_notify_handler(ehotk->handle, ACPI_SYSTEM_NOTIFY,
420 eeepc_hotk_notify, ehotk);
421 if (ACPI_FAILURE(status))
422 printk(EEEPC_ERR "Error installing notify handler\n");
423 end:
424 if (result) {
425 kfree(ehotk);
426 ehotk = NULL;
427 }
428 return result;
429}
430
431static int eeepc_hotk_remove(struct acpi_device *device, int type)
432{
433 acpi_status status = 0;
434
435 if (!device || !acpi_driver_data(device))
436 return -EINVAL;
437 status = acpi_remove_notify_handler(ehotk->handle, ACPI_SYSTEM_NOTIFY,
438 eeepc_hotk_notify);
439 if (ACPI_FAILURE(status))
440 printk(EEEPC_ERR "Error removing notify handler\n");
441 kfree(ehotk);
442 return 0;
443}
444
445/*
446 * Hwmon
447 */
448static int eeepc_get_fan_pwm(void)
449{
450 int value = 0;
451
452 read_acpi_int(NULL, EEEPC_EC_FAN_PWM, &value);
453 return (value);
454}
455
456static void eeepc_set_fan_pwm(int value)
457{
458 value = SENSORS_LIMIT(value, 0, 100);
459 ec_write(EEEPC_EC_SC02, value);
460}
461
462static int eeepc_get_fan_rpm(void)
463{
464 int high = 0;
465 int low = 0;
466
467 read_acpi_int(NULL, EEEPC_EC_FAN_HRPM, &high);
468 read_acpi_int(NULL, EEEPC_EC_FAN_LRPM, &low);
469 return (high << 8 | low);
470}
471
472static int eeepc_get_fan_ctrl(void)
473{
474 int value = 0;
475
476 read_acpi_int(NULL, EEEPC_EC_FAN_CTRL, &value);
477 return ((value & 0x02 ? 1 : 0));
478}
479
480static void eeepc_set_fan_ctrl(int manual)
481{
482 int value = 0;
483
484 read_acpi_int(NULL, EEEPC_EC_FAN_CTRL, &value);
485 if (manual)
486 value |= 0x02;
487 else
488 value &= ~0x02;
489 ec_write(EEEPC_EC_SFB3, value);
490}
491
492static ssize_t store_sys_hwmon(void (*set)(int), const char *buf, size_t count)
493{
494 int rv, value;
495
496 rv = parse_arg(buf, count, &value);
497 if (rv > 0)
498 set(value);
499 return rv;
500}
501
502static ssize_t show_sys_hwmon(int (*get)(void), char *buf)
503{
504 return sprintf(buf, "%d\n", get());
505}
506
507#define EEEPC_CREATE_SENSOR_ATTR(_name, _mode, _set, _get) \
508 static ssize_t show_##_name(struct device *dev, \
509 struct device_attribute *attr, \
510 char *buf) \
511 { \
512 return show_sys_hwmon(_set, buf); \
513 } \
514 static ssize_t store_##_name(struct device *dev, \
515 struct device_attribute *attr, \
516 const char *buf, size_t count) \
517 { \
518 return store_sys_hwmon(_get, buf, count); \
519 } \
520 static SENSOR_DEVICE_ATTR(_name, _mode, show_##_name, store_##_name, 0);
521
522EEEPC_CREATE_SENSOR_ATTR(fan1_input, S_IRUGO, eeepc_get_fan_rpm, NULL);
523EEEPC_CREATE_SENSOR_ATTR(fan1_pwm, S_IRUGO | S_IWUSR,
524 eeepc_get_fan_pwm, eeepc_set_fan_pwm);
525EEEPC_CREATE_SENSOR_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
526 eeepc_get_fan_ctrl, eeepc_set_fan_ctrl);
527
528static struct attribute *hwmon_attributes[] = {
529 &sensor_dev_attr_fan1_pwm.dev_attr.attr,
530 &sensor_dev_attr_fan1_input.dev_attr.attr,
531 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
532 NULL
533};
534
535static struct attribute_group hwmon_attribute_group = {
536 .attrs = hwmon_attributes
537};
538
539/*
540 * exit/init
541 */
542static void eeepc_backlight_exit(void)
543{
544 if (eeepc_backlight_device)
545 backlight_device_unregister(eeepc_backlight_device);
546 eeepc_backlight_device = NULL;
547}
548
549static void eeepc_hwmon_exit(void)
550{
551 struct device *hwmon;
552
553 hwmon = eeepc_hwmon_device;
554 if (!hwmon)
555 return ;
556 hwmon_device_unregister(hwmon);
557 sysfs_remove_group(&hwmon->kobj,
558 &hwmon_attribute_group);
559 eeepc_hwmon_device = NULL;
560}
561
562static void __exit eeepc_laptop_exit(void)
563{
564 eeepc_backlight_exit();
565 eeepc_hwmon_exit();
566 acpi_bus_unregister_driver(&eeepc_hotk_driver);
567 sysfs_remove_group(&platform_device->dev.kobj,
568 &platform_attribute_group);
569 platform_device_unregister(platform_device);
570 platform_driver_unregister(&platform_driver);
571}
572
573static int eeepc_backlight_init(struct device *dev)
574{
575 struct backlight_device *bd;
576
577 bd = backlight_device_register(EEEPC_HOTK_FILE, dev,
578 NULL, &eeepcbl_ops);
579 if (IS_ERR(bd)) {
580 printk(EEEPC_ERR
581 "Could not register eeepc backlight device\n");
582 eeepc_backlight_device = NULL;
583 return PTR_ERR(bd);
584 }
585 eeepc_backlight_device = bd;
586 bd->props.max_brightness = 15;
587 bd->props.brightness = read_brightness(NULL);
588 bd->props.power = FB_BLANK_UNBLANK;
589 backlight_update_status(bd);
590 return 0;
591}
592
593static int eeepc_hwmon_init(struct device *dev)
594{
595 struct device *hwmon;
596 int result;
597
598 hwmon = hwmon_device_register(dev);
599 if (IS_ERR(hwmon)) {
600 printk(EEEPC_ERR
601 "Could not register eeepc hwmon device\n");
602 eeepc_hwmon_device = NULL;
603 return PTR_ERR(hwmon);
604 }
605 eeepc_hwmon_device = hwmon;
606 result = sysfs_create_group(&hwmon->kobj,
607 &hwmon_attribute_group);
608 if (result)
609 eeepc_hwmon_exit();
610 return result;
611}
612
613static int __init eeepc_laptop_init(void)
614{
615 struct device *dev;
616 int result;
617
618 if (acpi_disabled)
619 return -ENODEV;
620 result = acpi_bus_register_driver(&eeepc_hotk_driver);
621 if (result < 0)
622 return result;
623 if (!ehotk) {
624 acpi_bus_unregister_driver(&eeepc_hotk_driver);
625 return -ENODEV;
626 }
627 dev = acpi_get_physical_device(ehotk->device->handle);
628 result = eeepc_backlight_init(dev);
629 if (result)
630 goto fail_backlight;
631 result = eeepc_hwmon_init(dev);
632 if (result)
633 goto fail_hwmon;
634 /* Register platform stuff */
635 result = platform_driver_register(&platform_driver);
636 if (result)
637 goto fail_platform_driver;
638 platform_device = platform_device_alloc(EEEPC_HOTK_FILE, -1);
639 if (!platform_device) {
640 result = -ENOMEM;
641 goto fail_platform_device1;
642 }
643 result = platform_device_add(platform_device);
644 if (result)
645 goto fail_platform_device2;
646 result = sysfs_create_group(&platform_device->dev.kobj,
647 &platform_attribute_group);
648 if (result)
649 goto fail_sysfs;
650 return 0;
651fail_sysfs:
652 platform_device_del(platform_device);
653fail_platform_device2:
654 platform_device_put(platform_device);
655fail_platform_device1:
656 platform_driver_unregister(&platform_driver);
657fail_platform_driver:
658 eeepc_hwmon_exit();
659fail_hwmon:
660 eeepc_backlight_exit();
661fail_backlight:
662 return result;
663}
664
665module_init(eeepc_laptop_init);
666module_exit(eeepc_laptop_exit);
diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
index 6d6286c4eeac..fa394104339c 100644
--- a/drivers/misc/kgdbts.c
+++ b/drivers/misc/kgdbts.c
@@ -47,6 +47,7 @@
47 * to test the HW NMI watchdog 47 * to test the HW NMI watchdog
48 * F## = Break at do_fork for ## iterations 48 * F## = Break at do_fork for ## iterations
49 * S## = Break at sys_open for ## iterations 49 * S## = Break at sys_open for ## iterations
50 * I## = Run the single step test ## iterations
50 * 51 *
51 * NOTE: that the do_fork and sys_open tests are mutually exclusive. 52 * NOTE: that the do_fork and sys_open tests are mutually exclusive.
52 * 53 *
@@ -132,7 +133,7 @@ static int send_ack;
132static int final_ack; 133static int final_ack;
133static int hw_break_val; 134static int hw_break_val;
134static int hw_break_val2; 135static int hw_break_val2;
135#if defined(CONFIG_ARM) || defined(CONFIG_MIPS) 136#if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || defined(CONFIG_SPARC)
136static int arch_needs_sstep_emulation = 1; 137static int arch_needs_sstep_emulation = 1;
137#else 138#else
138static int arch_needs_sstep_emulation; 139static int arch_needs_sstep_emulation;
@@ -375,7 +376,7 @@ static void emul_sstep_get(char *arg)
375 break; 376 break;
376 case 1: 377 case 1:
377 /* set breakpoint */ 378 /* set breakpoint */
378 break_helper("Z0", 0, sstep_addr); 379 break_helper("Z0", NULL, sstep_addr);
379 break; 380 break;
380 case 2: 381 case 2:
381 /* Continue */ 382 /* Continue */
@@ -383,7 +384,7 @@ static void emul_sstep_get(char *arg)
383 break; 384 break;
384 case 3: 385 case 3:
385 /* Clear breakpoint */ 386 /* Clear breakpoint */
386 break_helper("z0", 0, sstep_addr); 387 break_helper("z0", NULL, sstep_addr);
387 break; 388 break;
388 default: 389 default:
389 eprintk("kgdbts: ERROR failed sstep get emulation\n"); 390 eprintk("kgdbts: ERROR failed sstep get emulation\n");
@@ -465,11 +466,11 @@ static struct test_struct sw_breakpoint_test[] = {
465 { "?", "S0*" }, /* Clear break points */ 466 { "?", "S0*" }, /* Clear break points */
466 { "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */ 467 { "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */
467 { "c", "T0*", }, /* Continue */ 468 { "c", "T0*", }, /* Continue */
468 { "g", "kgdbts_break_test", 0, check_and_rewind_pc }, 469 { "g", "kgdbts_break_test", NULL, check_and_rewind_pc },
469 { "write", "OK", write_regs }, 470 { "write", "OK", write_regs },
470 { "kgdbts_break_test", "OK", sw_rem_break }, /*remove breakpoint */ 471 { "kgdbts_break_test", "OK", sw_rem_break }, /*remove breakpoint */
471 { "D", "OK" }, /* Detach */ 472 { "D", "OK" }, /* Detach */
472 { "D", "OK", 0, got_break }, /* If the test worked we made it here */ 473 { "D", "OK", NULL, got_break }, /* On success we made it here */
473 { "", "" }, 474 { "", "" },
474}; 475};
475 476
@@ -499,14 +500,14 @@ static struct test_struct singlestep_break_test[] = {
499 { "?", "S0*" }, /* Clear break points */ 500 { "?", "S0*" }, /* Clear break points */
500 { "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */ 501 { "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */
501 { "c", "T0*", }, /* Continue */ 502 { "c", "T0*", }, /* Continue */
502 { "g", "kgdbts_break_test", 0, check_and_rewind_pc }, 503 { "g", "kgdbts_break_test", NULL, check_and_rewind_pc },
503 { "write", "OK", write_regs }, /* Write registers */ 504 { "write", "OK", write_regs }, /* Write registers */
504 { "kgdbts_break_test", "OK", sw_rem_break }, /*remove breakpoint */ 505 { "kgdbts_break_test", "OK", sw_rem_break }, /*remove breakpoint */
505 { "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */ 506 { "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */
506 { "g", "kgdbts_break_test", 0, check_single_step }, 507 { "g", "kgdbts_break_test", NULL, check_single_step },
507 { "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */ 508 { "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */
508 { "c", "T0*", }, /* Continue */ 509 { "c", "T0*", }, /* Continue */
509 { "g", "kgdbts_break_test", 0, check_and_rewind_pc }, 510 { "g", "kgdbts_break_test", NULL, check_and_rewind_pc },
510 { "write", "OK", write_regs }, /* Write registers */ 511 { "write", "OK", write_regs }, /* Write registers */
511 { "D", "OK" }, /* Remove all breakpoints and continues */ 512 { "D", "OK" }, /* Remove all breakpoints and continues */
512 { "", "" }, 513 { "", "" },
@@ -520,14 +521,14 @@ static struct test_struct do_fork_test[] = {
520 { "?", "S0*" }, /* Clear break points */ 521 { "?", "S0*" }, /* Clear break points */
521 { "do_fork", "OK", sw_break, }, /* set sw breakpoint */ 522 { "do_fork", "OK", sw_break, }, /* set sw breakpoint */
522 { "c", "T0*", }, /* Continue */ 523 { "c", "T0*", }, /* Continue */
523 { "g", "do_fork", 0, check_and_rewind_pc }, /* check location */ 524 { "g", "do_fork", NULL, check_and_rewind_pc }, /* check location */
524 { "write", "OK", write_regs }, /* Write registers */ 525 { "write", "OK", write_regs }, /* Write registers */
525 { "do_fork", "OK", sw_rem_break }, /*remove breakpoint */ 526 { "do_fork", "OK", sw_rem_break }, /*remove breakpoint */
526 { "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */ 527 { "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */
527 { "g", "do_fork", 0, check_single_step }, 528 { "g", "do_fork", NULL, check_single_step },
528 { "do_fork", "OK", sw_break, }, /* set sw breakpoint */ 529 { "do_fork", "OK", sw_break, }, /* set sw breakpoint */
529 { "7", "T0*", skip_back_repeat_test }, /* Loop based on repeat_test */ 530 { "7", "T0*", skip_back_repeat_test }, /* Loop based on repeat_test */
530 { "D", "OK", 0, final_ack_set }, /* detach and unregister I/O */ 531 { "D", "OK", NULL, final_ack_set }, /* detach and unregister I/O */
531 { "", "" }, 532 { "", "" },
532}; 533};
533 534
@@ -538,14 +539,14 @@ static struct test_struct sys_open_test[] = {
538 { "?", "S0*" }, /* Clear break points */ 539 { "?", "S0*" }, /* Clear break points */
539 { "sys_open", "OK", sw_break, }, /* set sw breakpoint */ 540 { "sys_open", "OK", sw_break, }, /* set sw breakpoint */
540 { "c", "T0*", }, /* Continue */ 541 { "c", "T0*", }, /* Continue */
541 { "g", "sys_open", 0, check_and_rewind_pc }, /* check location */ 542 { "g", "sys_open", NULL, check_and_rewind_pc }, /* check location */
542 { "write", "OK", write_regs }, /* Write registers */ 543 { "write", "OK", write_regs }, /* Write registers */
543 { "sys_open", "OK", sw_rem_break }, /*remove breakpoint */ 544 { "sys_open", "OK", sw_rem_break }, /*remove breakpoint */
544 { "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */ 545 { "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */
545 { "g", "sys_open", 0, check_single_step }, 546 { "g", "sys_open", NULL, check_single_step },
546 { "sys_open", "OK", sw_break, }, /* set sw breakpoint */ 547 { "sys_open", "OK", sw_break, }, /* set sw breakpoint */
547 { "7", "T0*", skip_back_repeat_test }, /* Loop based on repeat_test */ 548 { "7", "T0*", skip_back_repeat_test }, /* Loop based on repeat_test */
548 { "D", "OK", 0, final_ack_set }, /* detach and unregister I/O */ 549 { "D", "OK", NULL, final_ack_set }, /* detach and unregister I/O */
549 { "", "" }, 550 { "", "" },
550}; 551};
551 552
@@ -556,11 +557,11 @@ static struct test_struct hw_breakpoint_test[] = {
556 { "?", "S0*" }, /* Clear break points */ 557 { "?", "S0*" }, /* Clear break points */
557 { "kgdbts_break_test", "OK", hw_break, }, /* set hw breakpoint */ 558 { "kgdbts_break_test", "OK", hw_break, }, /* set hw breakpoint */
558 { "c", "T0*", }, /* Continue */ 559 { "c", "T0*", }, /* Continue */
559 { "g", "kgdbts_break_test", 0, check_and_rewind_pc }, 560 { "g", "kgdbts_break_test", NULL, check_and_rewind_pc },
560 { "write", "OK", write_regs }, 561 { "write", "OK", write_regs },
561 { "kgdbts_break_test", "OK", hw_rem_break }, /*remove breakpoint */ 562 { "kgdbts_break_test", "OK", hw_rem_break }, /*remove breakpoint */
562 { "D", "OK" }, /* Detach */ 563 { "D", "OK" }, /* Detach */
563 { "D", "OK", 0, got_break }, /* If the test worked we made it here */ 564 { "D", "OK", NULL, got_break }, /* On success we made it here */
564 { "", "" }, 565 { "", "" },
565}; 566};
566 567
@@ -570,12 +571,12 @@ static struct test_struct hw_breakpoint_test[] = {
570static struct test_struct hw_write_break_test[] = { 571static struct test_struct hw_write_break_test[] = {
571 { "?", "S0*" }, /* Clear break points */ 572 { "?", "S0*" }, /* Clear break points */
572 { "hw_break_val", "OK", hw_write_break, }, /* set hw breakpoint */ 573 { "hw_break_val", "OK", hw_write_break, }, /* set hw breakpoint */
573 { "c", "T0*", 0, got_break }, /* Continue */ 574 { "c", "T0*", NULL, got_break }, /* Continue */
574 { "g", "silent", 0, check_and_rewind_pc }, 575 { "g", "silent", NULL, check_and_rewind_pc },
575 { "write", "OK", write_regs }, 576 { "write", "OK", write_regs },
576 { "hw_break_val", "OK", hw_rem_write_break }, /*remove breakpoint */ 577 { "hw_break_val", "OK", hw_rem_write_break }, /*remove breakpoint */
577 { "D", "OK" }, /* Detach */ 578 { "D", "OK" }, /* Detach */
578 { "D", "OK", 0, got_break }, /* If the test worked we made it here */ 579 { "D", "OK", NULL, got_break }, /* On success we made it here */
579 { "", "" }, 580 { "", "" },
580}; 581};
581 582
@@ -585,12 +586,12 @@ static struct test_struct hw_write_break_test[] = {
585static struct test_struct hw_access_break_test[] = { 586static struct test_struct hw_access_break_test[] = {
586 { "?", "S0*" }, /* Clear break points */ 587 { "?", "S0*" }, /* Clear break points */
587 { "hw_break_val", "OK", hw_access_break, }, /* set hw breakpoint */ 588 { "hw_break_val", "OK", hw_access_break, }, /* set hw breakpoint */
588 { "c", "T0*", 0, got_break }, /* Continue */ 589 { "c", "T0*", NULL, got_break }, /* Continue */
589 { "g", "silent", 0, check_and_rewind_pc }, 590 { "g", "silent", NULL, check_and_rewind_pc },
590 { "write", "OK", write_regs }, 591 { "write", "OK", write_regs },
591 { "hw_break_val", "OK", hw_rem_access_break }, /*remove breakpoint */ 592 { "hw_break_val", "OK", hw_rem_access_break }, /*remove breakpoint */
592 { "D", "OK" }, /* Detach */ 593 { "D", "OK" }, /* Detach */
593 { "D", "OK", 0, got_break }, /* If the test worked we made it here */ 594 { "D", "OK", NULL, got_break }, /* On success we made it here */
594 { "", "" }, 595 { "", "" },
595}; 596};
596 597
@@ -599,9 +600,9 @@ static struct test_struct hw_access_break_test[] = {
599 */ 600 */
600static struct test_struct nmi_sleep_test[] = { 601static struct test_struct nmi_sleep_test[] = {
601 { "?", "S0*" }, /* Clear break points */ 602 { "?", "S0*" }, /* Clear break points */
602 { "c", "T0*", 0, got_break }, /* Continue */ 603 { "c", "T0*", NULL, got_break }, /* Continue */
603 { "D", "OK" }, /* Detach */ 604 { "D", "OK" }, /* Detach */
604 { "D", "OK", 0, got_break }, /* If the test worked we made it here */ 605 { "D", "OK", NULL, got_break }, /* On success we made it here */
605 { "", "" }, 606 { "", "" },
606}; 607};
607 608
@@ -874,18 +875,23 @@ static void kgdbts_run_tests(void)
874{ 875{
875 char *ptr; 876 char *ptr;
876 int fork_test = 0; 877 int fork_test = 0;
877 int sys_open_test = 0; 878 int do_sys_open_test = 0;
879 int sstep_test = 1000;
878 int nmi_sleep = 0; 880 int nmi_sleep = 0;
881 int i;
879 882
880 ptr = strstr(config, "F"); 883 ptr = strstr(config, "F");
881 if (ptr) 884 if (ptr)
882 fork_test = simple_strtol(ptr+1, NULL, 10); 885 fork_test = simple_strtol(ptr + 1, NULL, 10);
883 ptr = strstr(config, "S"); 886 ptr = strstr(config, "S");
884 if (ptr) 887 if (ptr)
885 sys_open_test = simple_strtol(ptr+1, NULL, 10); 888 do_sys_open_test = simple_strtol(ptr + 1, NULL, 10);
886 ptr = strstr(config, "N"); 889 ptr = strstr(config, "N");
887 if (ptr) 890 if (ptr)
888 nmi_sleep = simple_strtol(ptr+1, NULL, 10); 891 nmi_sleep = simple_strtol(ptr+1, NULL, 10);
892 ptr = strstr(config, "I");
893 if (ptr)
894 sstep_test = simple_strtol(ptr+1, NULL, 10);
889 895
890 /* required internal KGDB tests */ 896 /* required internal KGDB tests */
891 v1printk("kgdbts:RUN plant and detach test\n"); 897 v1printk("kgdbts:RUN plant and detach test\n");
@@ -894,8 +900,13 @@ static void kgdbts_run_tests(void)
894 run_breakpoint_test(0); 900 run_breakpoint_test(0);
895 v1printk("kgdbts:RUN bad memory access test\n"); 901 v1printk("kgdbts:RUN bad memory access test\n");
896 run_bad_read_test(); 902 run_bad_read_test();
897 v1printk("kgdbts:RUN singlestep breakpoint test\n"); 903 v1printk("kgdbts:RUN singlestep test %i iterations\n", sstep_test);
898 run_singlestep_break_test(); 904 for (i = 0; i < sstep_test; i++) {
905 run_singlestep_break_test();
906 if (i % 100 == 0)
907 v1printk("kgdbts:RUN singlestep [%i/%i]\n",
908 i, sstep_test);
909 }
899 910
900 /* ===Optional tests=== */ 911 /* ===Optional tests=== */
901 912
@@ -922,7 +933,7 @@ static void kgdbts_run_tests(void)
922 repeat_test = fork_test; 933 repeat_test = fork_test;
923 printk(KERN_INFO "kgdbts:RUN do_fork for %i breakpoints\n", 934 printk(KERN_INFO "kgdbts:RUN do_fork for %i breakpoints\n",
924 repeat_test); 935 repeat_test);
925 kthread_run(kgdbts_unreg_thread, 0, "kgdbts_unreg"); 936 kthread_run(kgdbts_unreg_thread, NULL, "kgdbts_unreg");
926 run_do_fork_test(); 937 run_do_fork_test();
927 return; 938 return;
928 } 939 }
@@ -931,11 +942,11 @@ static void kgdbts_run_tests(void)
931 * executed because a kernel thread will be spawned at the very 942 * executed because a kernel thread will be spawned at the very
932 * end to unregister the debug hooks. 943 * end to unregister the debug hooks.
933 */ 944 */
934 if (sys_open_test) { 945 if (do_sys_open_test) {
935 repeat_test = sys_open_test; 946 repeat_test = do_sys_open_test;
936 printk(KERN_INFO "kgdbts:RUN sys_open for %i breakpoints\n", 947 printk(KERN_INFO "kgdbts:RUN sys_open for %i breakpoints\n",
937 repeat_test); 948 repeat_test);
938 kthread_run(kgdbts_unreg_thread, 0, "kgdbts_unreg"); 949 kthread_run(kgdbts_unreg_thread, NULL, "kgdbts_unreg");
939 run_sys_open_test(); 950 run_sys_open_test();
940 return; 951 return;
941 } 952 }
diff --git a/drivers/misc/sgi-xp/xpc_partition.c b/drivers/misc/sgi-xp/xpc_partition.c
index 27e200ec5826..acd3fd4285d7 100644
--- a/drivers/misc/sgi-xp/xpc_partition.c
+++ b/drivers/misc/sgi-xp/xpc_partition.c
@@ -211,7 +211,7 @@ xpc_rsvd_page_init(void)
211 */ 211 */
212 amos_page = xpc_vars->amos_page; 212 amos_page = xpc_vars->amos_page;
213 if (amos_page == NULL) { 213 if (amos_page == NULL) {
214 amos_page = (AMO_t *)TO_AMO(uncached_alloc_page(0)); 214 amos_page = (AMO_t *)TO_AMO(uncached_alloc_page(0, 1));
215 if (amos_page == NULL) { 215 if (amos_page == NULL) {
216 dev_err(xpc_part, "can't allocate page of AMOs\n"); 216 dev_err(xpc_part, "can't allocate page of AMOs\n");
217 return NULL; 217 return NULL;
@@ -230,7 +230,7 @@ xpc_rsvd_page_init(void)
230 dev_err(xpc_part, "can't change memory " 230 dev_err(xpc_part, "can't change memory "
231 "protections\n"); 231 "protections\n");
232 uncached_free_page(__IA64_UNCACHED_OFFSET | 232 uncached_free_page(__IA64_UNCACHED_OFFSET |
233 TO_PHYS((u64)amos_page)); 233 TO_PHYS((u64)amos_page), 1);
234 return NULL; 234 return NULL;
235 } 235 }
236 } 236 }
diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c
index 6cb781262f94..3f28f6eabdbf 100644
--- a/drivers/misc/thinkpad_acpi.c
+++ b/drivers/misc/thinkpad_acpi.c
@@ -21,7 +21,7 @@
21 * 02110-1301, USA. 21 * 02110-1301, USA.
22 */ 22 */
23 23
24#define TPACPI_VERSION "0.19" 24#define TPACPI_VERSION "0.20"
25#define TPACPI_SYSFS_VERSION 0x020200 25#define TPACPI_SYSFS_VERSION 0x020200
26 26
27/* 27/*
@@ -67,6 +67,7 @@
67#include <linux/hwmon.h> 67#include <linux/hwmon.h>
68#include <linux/hwmon-sysfs.h> 68#include <linux/hwmon-sysfs.h>
69#include <linux/input.h> 69#include <linux/input.h>
70#include <linux/leds.h>
70#include <asm/uaccess.h> 71#include <asm/uaccess.h>
71 72
72#include <linux/dmi.h> 73#include <linux/dmi.h>
@@ -85,6 +86,8 @@
85#define TP_CMOS_VOLUME_MUTE 2 86#define TP_CMOS_VOLUME_MUTE 2
86#define TP_CMOS_BRIGHTNESS_UP 4 87#define TP_CMOS_BRIGHTNESS_UP 4
87#define TP_CMOS_BRIGHTNESS_DOWN 5 88#define TP_CMOS_BRIGHTNESS_DOWN 5
89#define TP_CMOS_THINKLIGHT_ON 12
90#define TP_CMOS_THINKLIGHT_OFF 13
88 91
89/* NVRAM Addresses */ 92/* NVRAM Addresses */
90enum tp_nvram_addr { 93enum tp_nvram_addr {
@@ -133,8 +136,12 @@ enum {
133#define TPACPI_PROC_DIR "ibm" 136#define TPACPI_PROC_DIR "ibm"
134#define TPACPI_ACPI_EVENT_PREFIX "ibm" 137#define TPACPI_ACPI_EVENT_PREFIX "ibm"
135#define TPACPI_DRVR_NAME TPACPI_FILE 138#define TPACPI_DRVR_NAME TPACPI_FILE
139#define TPACPI_DRVR_SHORTNAME "tpacpi"
136#define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon" 140#define TPACPI_HWMON_DRVR_NAME TPACPI_NAME "_hwmon"
137 141
142#define TPACPI_NVRAM_KTHREAD_NAME "ktpacpi_nvramd"
143#define TPACPI_WORKQUEUE_NAME "ktpacpid"
144
138#define TPACPI_MAX_ACPI_ARGS 3 145#define TPACPI_MAX_ACPI_ARGS 3
139 146
140/* Debugging */ 147/* Debugging */
@@ -225,6 +232,7 @@ static struct {
225 u32 light:1; 232 u32 light:1;
226 u32 light_status:1; 233 u32 light_status:1;
227 u32 bright_16levels:1; 234 u32 bright_16levels:1;
235 u32 bright_acpimode:1;
228 u32 wan:1; 236 u32 wan:1;
229 u32 fan_ctrl_status_undef:1; 237 u32 fan_ctrl_status_undef:1;
230 u32 input_device_registered:1; 238 u32 input_device_registered:1;
@@ -236,6 +244,11 @@ static struct {
236 u32 hotkey_poll_active:1; 244 u32 hotkey_poll_active:1;
237} tp_features; 245} tp_features;
238 246
247static struct {
248 u16 hotkey_mask_ff:1;
249 u16 bright_cmos_ec_unsync:1;
250} tp_warned;
251
239struct thinkpad_id_data { 252struct thinkpad_id_data {
240 unsigned int vendor; /* ThinkPad vendor: 253 unsigned int vendor; /* ThinkPad vendor:
241 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */ 254 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
@@ -246,7 +259,8 @@ struct thinkpad_id_data {
246 u16 bios_model; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */ 259 u16 bios_model; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */
247 u16 ec_model; 260 u16 ec_model;
248 261
249 char *model_str; 262 char *model_str; /* ThinkPad T43 */
263 char *nummodel_str; /* 9384A9C for a 9384-A9C model */
250}; 264};
251static struct thinkpad_id_data thinkpad_id; 265static struct thinkpad_id_data thinkpad_id;
252 266
@@ -259,6 +273,16 @@ static enum {
259static int experimental; 273static int experimental;
260static u32 dbg_level; 274static u32 dbg_level;
261 275
276static struct workqueue_struct *tpacpi_wq;
277
278/* Special LED class that can defer work */
279struct tpacpi_led_classdev {
280 struct led_classdev led_classdev;
281 struct work_struct work;
282 enum led_brightness new_brightness;
283 unsigned int led;
284};
285
262/**************************************************************************** 286/****************************************************************************
263 **************************************************************************** 287 ****************************************************************************
264 * 288 *
@@ -807,6 +831,80 @@ static int parse_strtoul(const char *buf,
807 return 0; 831 return 0;
808} 832}
809 833
834static int __init tpacpi_query_bcl_levels(acpi_handle handle)
835{
836 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
837 union acpi_object *obj;
838 int rc;
839
840 if (ACPI_SUCCESS(acpi_evaluate_object(handle, NULL, NULL, &buffer))) {
841 obj = (union acpi_object *)buffer.pointer;
842 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
843 printk(TPACPI_ERR "Unknown _BCL data, "
844 "please report this to %s\n", TPACPI_MAIL);
845 rc = 0;
846 } else {
847 rc = obj->package.count;
848 }
849 } else {
850 return 0;
851 }
852
853 kfree(buffer.pointer);
854 return rc;
855}
856
857static acpi_status __init tpacpi_acpi_walk_find_bcl(acpi_handle handle,
858 u32 lvl, void *context, void **rv)
859{
860 char name[ACPI_PATH_SEGMENT_LENGTH];
861 struct acpi_buffer buffer = { sizeof(name), &name };
862
863 if (ACPI_SUCCESS(acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer)) &&
864 !strncmp("_BCL", name, sizeof(name) - 1)) {
865 BUG_ON(!rv || !*rv);
866 **(int **)rv = tpacpi_query_bcl_levels(handle);
867 return AE_CTRL_TERMINATE;
868 } else {
869 return AE_OK;
870 }
871}
872
873/*
874 * Returns 0 (no ACPI _BCL or _BCL invalid), or size of brightness map
875 */
876static int __init tpacpi_check_std_acpi_brightness_support(void)
877{
878 int status;
879 int bcl_levels = 0;
880 void *bcl_ptr = &bcl_levels;
881
882 if (!vid_handle) {
883 TPACPI_ACPIHANDLE_INIT(vid);
884 }
885 if (!vid_handle)
886 return 0;
887
888 /*
889 * Search for a _BCL method, and execute it. This is safe on all
890 * ThinkPads, and as a side-effect, _BCL will place a Lenovo Vista
891 * BIOS in ACPI backlight control mode. We do NOT have to care
892 * about calling the _BCL method in an enabled video device, any
893 * will do for our purposes.
894 */
895
896 status = acpi_walk_namespace(ACPI_TYPE_METHOD, vid_handle, 3,
897 tpacpi_acpi_walk_find_bcl, NULL,
898 &bcl_ptr);
899
900 if (ACPI_SUCCESS(status) && bcl_levels > 2) {
901 tp_features.bright_acpimode = 1;
902 return (bcl_levels - 2);
903 }
904
905 return 0;
906}
907
810/************************************************************************* 908/*************************************************************************
811 * thinkpad-acpi driver attributes 909 * thinkpad-acpi driver attributes
812 */ 910 */
@@ -909,12 +1007,14 @@ static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm)
909 thinkpad_id.ec_version_str : "unknown"); 1007 thinkpad_id.ec_version_str : "unknown");
910 1008
911 if (thinkpad_id.vendor && thinkpad_id.model_str) 1009 if (thinkpad_id.vendor && thinkpad_id.model_str)
912 printk(TPACPI_INFO "%s %s\n", 1010 printk(TPACPI_INFO "%s %s, model %s\n",
913 (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ? 1011 (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ?
914 "IBM" : ((thinkpad_id.vendor == 1012 "IBM" : ((thinkpad_id.vendor ==
915 PCI_VENDOR_ID_LENOVO) ? 1013 PCI_VENDOR_ID_LENOVO) ?
916 "Lenovo" : "Unknown vendor"), 1014 "Lenovo" : "Unknown vendor"),
917 thinkpad_id.model_str); 1015 thinkpad_id.model_str,
1016 (thinkpad_id.nummodel_str) ?
1017 thinkpad_id.nummodel_str : "unknown");
918 1018
919 return 0; 1019 return 0;
920} 1020}
@@ -1107,6 +1207,19 @@ static int hotkey_mask_set(u32 mask)
1107 int rc = 0; 1207 int rc = 0;
1108 1208
1109 if (tp_features.hotkey_mask) { 1209 if (tp_features.hotkey_mask) {
1210 if (!tp_warned.hotkey_mask_ff &&
1211 (mask == 0xffff || mask == 0xffffff ||
1212 mask == 0xffffffff)) {
1213 tp_warned.hotkey_mask_ff = 1;
1214 printk(TPACPI_NOTICE
1215 "setting the hotkey mask to 0x%08x is likely "
1216 "not the best way to go about it\n", mask);
1217 printk(TPACPI_NOTICE
1218 "please consider using the driver defaults, "
1219 "and refer to up-to-date thinkpad-acpi "
1220 "documentation\n");
1221 }
1222
1110 HOTKEY_CONFIG_CRITICAL_START 1223 HOTKEY_CONFIG_CRITICAL_START
1111 for (i = 0; i < 32; i++) { 1224 for (i = 0; i < 32; i++) {
1112 u32 m = 1 << i; 1225 u32 m = 1 << i;
@@ -1427,8 +1540,7 @@ static void hotkey_poll_setup(int may_warn)
1427 (tpacpi_inputdev->users > 0 || hotkey_report_mode < 2)) { 1540 (tpacpi_inputdev->users > 0 || hotkey_report_mode < 2)) {
1428 if (!tpacpi_hotkey_task) { 1541 if (!tpacpi_hotkey_task) {
1429 tpacpi_hotkey_task = kthread_run(hotkey_kthread, 1542 tpacpi_hotkey_task = kthread_run(hotkey_kthread,
1430 NULL, 1543 NULL, TPACPI_NVRAM_KTHREAD_NAME);
1431 TPACPI_FILE "d");
1432 if (IS_ERR(tpacpi_hotkey_task)) { 1544 if (IS_ERR(tpacpi_hotkey_task)) {
1433 tpacpi_hotkey_task = NULL; 1545 tpacpi_hotkey_task = NULL;
1434 printk(TPACPI_ERR 1546 printk(TPACPI_ERR
@@ -1887,6 +1999,9 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
1887 KEY_UNKNOWN, /* 0x0D: FN+INSERT */ 1999 KEY_UNKNOWN, /* 0x0D: FN+INSERT */
1888 KEY_UNKNOWN, /* 0x0E: FN+DELETE */ 2000 KEY_UNKNOWN, /* 0x0E: FN+DELETE */
1889 2001
2002 /* These either have to go through ACPI video, or
2003 * act like in the IBM ThinkPads, so don't ever
2004 * enable them by default */
1890 KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ 2005 KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */
1891 KEY_RESERVED, /* 0x10: FN+END (brightness down) */ 2006 KEY_RESERVED, /* 0x10: FN+END (brightness down) */
1892 2007
@@ -2091,6 +2206,32 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
2091 set_bit(SW_TABLET_MODE, tpacpi_inputdev->swbit); 2206 set_bit(SW_TABLET_MODE, tpacpi_inputdev->swbit);
2092 } 2207 }
2093 2208
2209 /* Do not issue duplicate brightness change events to
2210 * userspace */
2211 if (!tp_features.bright_acpimode)
2212 /* update bright_acpimode... */
2213 tpacpi_check_std_acpi_brightness_support();
2214
2215 if (tp_features.bright_acpimode) {
2216 printk(TPACPI_INFO
2217 "This ThinkPad has standard ACPI backlight "
2218 "brightness control, supported by the ACPI "
2219 "video driver\n");
2220 printk(TPACPI_NOTICE
2221 "Disabling thinkpad-acpi brightness events "
2222 "by default...\n");
2223
2224 /* The hotkey_reserved_mask change below is not
2225 * necessary while the keys are at KEY_RESERVED in the
2226 * default map, but better safe than sorry, leave it
2227 * here as a marker of what we have to do, especially
2228 * when we finally become able to set this at runtime
2229 * on response to X.org requests */
2230 hotkey_reserved_mask |=
2231 (1 << TP_ACPI_HOTKEYSCAN_FNHOME)
2232 | (1 << TP_ACPI_HOTKEYSCAN_FNEND);
2233 }
2234
2094 dbg_printk(TPACPI_DBG_INIT, 2235 dbg_printk(TPACPI_DBG_INIT,
2095 "enabling hot key handling\n"); 2236 "enabling hot key handling\n");
2096 res = hotkey_status_set(1); 2237 res = hotkey_status_set(1);
@@ -3110,13 +3251,82 @@ static struct ibm_struct video_driver_data = {
3110TPACPI_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */ 3251TPACPI_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
3111TPACPI_HANDLE(ledb, ec, "LEDB"); /* G4x */ 3252TPACPI_HANDLE(ledb, ec, "LEDB"); /* G4x */
3112 3253
3254static int light_get_status(void)
3255{
3256 int status = 0;
3257
3258 if (tp_features.light_status) {
3259 if (!acpi_evalf(ec_handle, &status, "KBLT", "d"))
3260 return -EIO;
3261 return (!!status);
3262 }
3263
3264 return -ENXIO;
3265}
3266
3267static int light_set_status(int status)
3268{
3269 int rc;
3270
3271 if (tp_features.light) {
3272 if (cmos_handle) {
3273 rc = acpi_evalf(cmos_handle, NULL, NULL, "vd",
3274 (status)?
3275 TP_CMOS_THINKLIGHT_ON :
3276 TP_CMOS_THINKLIGHT_OFF);
3277 } else {
3278 rc = acpi_evalf(lght_handle, NULL, NULL, "vd",
3279 (status)? 1 : 0);
3280 }
3281 return (rc)? 0 : -EIO;
3282 }
3283
3284 return -ENXIO;
3285}
3286
3287static void light_set_status_worker(struct work_struct *work)
3288{
3289 struct tpacpi_led_classdev *data =
3290 container_of(work, struct tpacpi_led_classdev, work);
3291
3292 if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING))
3293 light_set_status((data->new_brightness != LED_OFF));
3294}
3295
3296static void light_sysfs_set(struct led_classdev *led_cdev,
3297 enum led_brightness brightness)
3298{
3299 struct tpacpi_led_classdev *data =
3300 container_of(led_cdev,
3301 struct tpacpi_led_classdev,
3302 led_classdev);
3303 data->new_brightness = brightness;
3304 queue_work(tpacpi_wq, &data->work);
3305}
3306
3307static enum led_brightness light_sysfs_get(struct led_classdev *led_cdev)
3308{
3309 return (light_get_status() == 1)? LED_FULL : LED_OFF;
3310}
3311
3312static struct tpacpi_led_classdev tpacpi_led_thinklight = {
3313 .led_classdev = {
3314 .name = "tpacpi::thinklight",
3315 .brightness_set = &light_sysfs_set,
3316 .brightness_get = &light_sysfs_get,
3317 }
3318};
3319
3113static int __init light_init(struct ibm_init_struct *iibm) 3320static int __init light_init(struct ibm_init_struct *iibm)
3114{ 3321{
3322 int rc = 0;
3323
3115 vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n"); 3324 vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n");
3116 3325
3117 TPACPI_ACPIHANDLE_INIT(ledb); 3326 TPACPI_ACPIHANDLE_INIT(ledb);
3118 TPACPI_ACPIHANDLE_INIT(lght); 3327 TPACPI_ACPIHANDLE_INIT(lght);
3119 TPACPI_ACPIHANDLE_INIT(cmos); 3328 TPACPI_ACPIHANDLE_INIT(cmos);
3329 INIT_WORK(&tpacpi_led_thinklight.work, light_set_status_worker);
3120 3330
3121 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */ 3331 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
3122 tp_features.light = (cmos_handle || lght_handle) && !ledb_handle; 3332 tp_features.light = (cmos_handle || lght_handle) && !ledb_handle;
@@ -3130,13 +3340,31 @@ static int __init light_init(struct ibm_init_struct *iibm)
3130 vdbg_printk(TPACPI_DBG_INIT, "light is %s\n", 3340 vdbg_printk(TPACPI_DBG_INIT, "light is %s\n",
3131 str_supported(tp_features.light)); 3341 str_supported(tp_features.light));
3132 3342
3133 return (tp_features.light)? 0 : 1; 3343 if (tp_features.light) {
3344 rc = led_classdev_register(&tpacpi_pdev->dev,
3345 &tpacpi_led_thinklight.led_classdev);
3346 }
3347
3348 if (rc < 0) {
3349 tp_features.light = 0;
3350 tp_features.light_status = 0;
3351 } else {
3352 rc = (tp_features.light)? 0 : 1;
3353 }
3354 return rc;
3355}
3356
3357static void light_exit(void)
3358{
3359 led_classdev_unregister(&tpacpi_led_thinklight.led_classdev);
3360 if (work_pending(&tpacpi_led_thinklight.work))
3361 flush_workqueue(tpacpi_wq);
3134} 3362}
3135 3363
3136static int light_read(char *p) 3364static int light_read(char *p)
3137{ 3365{
3138 int len = 0; 3366 int len = 0;
3139 int status = 0; 3367 int status;
3140 3368
3141 if (!tp_features.light) { 3369 if (!tp_features.light) {
3142 len += sprintf(p + len, "status:\t\tnot supported\n"); 3370 len += sprintf(p + len, "status:\t\tnot supported\n");
@@ -3144,8 +3372,9 @@ static int light_read(char *p)
3144 len += sprintf(p + len, "status:\t\tunknown\n"); 3372 len += sprintf(p + len, "status:\t\tunknown\n");
3145 len += sprintf(p + len, "commands:\ton, off\n"); 3373 len += sprintf(p + len, "commands:\ton, off\n");
3146 } else { 3374 } else {
3147 if (!acpi_evalf(ec_handle, &status, "KBLT", "d")) 3375 status = light_get_status();
3148 return -EIO; 3376 if (status < 0)
3377 return status;
3149 len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0)); 3378 len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0));
3150 len += sprintf(p + len, "commands:\ton, off\n"); 3379 len += sprintf(p + len, "commands:\ton, off\n");
3151 } 3380 }
@@ -3155,37 +3384,29 @@ static int light_read(char *p)
3155 3384
3156static int light_write(char *buf) 3385static int light_write(char *buf)
3157{ 3386{
3158 int cmos_cmd, lght_cmd;
3159 char *cmd; 3387 char *cmd;
3160 int success; 3388 int newstatus = 0;
3161 3389
3162 if (!tp_features.light) 3390 if (!tp_features.light)
3163 return -ENODEV; 3391 return -ENODEV;
3164 3392
3165 while ((cmd = next_cmd(&buf))) { 3393 while ((cmd = next_cmd(&buf))) {
3166 if (strlencmp(cmd, "on") == 0) { 3394 if (strlencmp(cmd, "on") == 0) {
3167 cmos_cmd = 0x0c; 3395 newstatus = 1;
3168 lght_cmd = 1;
3169 } else if (strlencmp(cmd, "off") == 0) { 3396 } else if (strlencmp(cmd, "off") == 0) {
3170 cmos_cmd = 0x0d; 3397 newstatus = 0;
3171 lght_cmd = 0;
3172 } else 3398 } else
3173 return -EINVAL; 3399 return -EINVAL;
3174
3175 success = cmos_handle ?
3176 acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) :
3177 acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd);
3178 if (!success)
3179 return -EIO;
3180 } 3400 }
3181 3401
3182 return 0; 3402 return light_set_status(newstatus);
3183} 3403}
3184 3404
3185static struct ibm_struct light_driver_data = { 3405static struct ibm_struct light_driver_data = {
3186 .name = "light", 3406 .name = "light",
3187 .read = light_read, 3407 .read = light_read,
3188 .write = light_write, 3408 .write = light_write,
3409 .exit = light_exit,
3189}; 3410};
3190 3411
3191/************************************************************************* 3412/*************************************************************************
@@ -3583,6 +3804,12 @@ enum { /* For TPACPI_LED_OLD */
3583 TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */ 3804 TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */
3584}; 3805};
3585 3806
3807enum led_status_t {
3808 TPACPI_LED_OFF = 0,
3809 TPACPI_LED_ON,
3810 TPACPI_LED_BLINK,
3811};
3812
3586static enum led_access_mode led_supported; 3813static enum led_access_mode led_supported;
3587 3814
3588TPACPI_HANDLE(led, ec, "SLED", /* 570 */ 3815TPACPI_HANDLE(led, ec, "SLED", /* 570 */
@@ -3591,8 +3818,174 @@ TPACPI_HANDLE(led, ec, "SLED", /* 570 */
3591 "LED", /* all others */ 3818 "LED", /* all others */
3592 ); /* R30, R31 */ 3819 ); /* R30, R31 */
3593 3820
3821#define TPACPI_LED_NUMLEDS 8
3822static struct tpacpi_led_classdev *tpacpi_leds;
3823static enum led_status_t tpacpi_led_state_cache[TPACPI_LED_NUMLEDS];
3824static const char const *tpacpi_led_names[TPACPI_LED_NUMLEDS] = {
3825 /* there's a limit of 19 chars + NULL before 2.6.26 */
3826 "tpacpi::power",
3827 "tpacpi:orange:batt",
3828 "tpacpi:green:batt",
3829 "tpacpi::dock_active",
3830 "tpacpi::bay_active",
3831 "tpacpi::dock_batt",
3832 "tpacpi::unknown_led",
3833 "tpacpi::standby",
3834};
3835
3836static int led_get_status(unsigned int led)
3837{
3838 int status;
3839 enum led_status_t led_s;
3840
3841 switch (led_supported) {
3842 case TPACPI_LED_570:
3843 if (!acpi_evalf(ec_handle,
3844 &status, "GLED", "dd", 1 << led))
3845 return -EIO;
3846 led_s = (status == 0)?
3847 TPACPI_LED_OFF :
3848 ((status == 1)?
3849 TPACPI_LED_ON :
3850 TPACPI_LED_BLINK);
3851 tpacpi_led_state_cache[led] = led_s;
3852 return led_s;
3853 default:
3854 return -ENXIO;
3855 }
3856
3857 /* not reached */
3858}
3859
3860static int led_set_status(unsigned int led, enum led_status_t ledstatus)
3861{
3862 /* off, on, blink. Index is led_status_t */
3863 static const int const led_sled_arg1[] = { 0, 1, 3 };
3864 static const int const led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */
3865 static const int const led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */
3866 static const int const led_led_arg1[] = { 0, 0x80, 0xc0 };
3867
3868 int rc = 0;
3869
3870 switch (led_supported) {
3871 case TPACPI_LED_570:
3872 /* 570 */
3873 led = 1 << led;
3874 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
3875 led, led_sled_arg1[ledstatus]))
3876 rc = -EIO;
3877 break;
3878 case TPACPI_LED_OLD:
3879 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
3880 led = 1 << led;
3881 rc = ec_write(TPACPI_LED_EC_HLMS, led);
3882 if (rc >= 0)
3883 rc = ec_write(TPACPI_LED_EC_HLBL,
3884 led * led_exp_hlbl[ledstatus]);
3885 if (rc >= 0)
3886 rc = ec_write(TPACPI_LED_EC_HLCL,
3887 led * led_exp_hlcl[ledstatus]);
3888 break;
3889 case TPACPI_LED_NEW:
3890 /* all others */
3891 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
3892 led, led_led_arg1[ledstatus]))
3893 rc = -EIO;
3894 break;
3895 default:
3896 rc = -ENXIO;
3897 }
3898
3899 if (!rc)
3900 tpacpi_led_state_cache[led] = ledstatus;
3901
3902 return rc;
3903}
3904
3905static void led_sysfs_set_status(unsigned int led,
3906 enum led_brightness brightness)
3907{
3908 led_set_status(led,
3909 (brightness == LED_OFF) ?
3910 TPACPI_LED_OFF :
3911 (tpacpi_led_state_cache[led] == TPACPI_LED_BLINK) ?
3912 TPACPI_LED_BLINK : TPACPI_LED_ON);
3913}
3914
3915static void led_set_status_worker(struct work_struct *work)
3916{
3917 struct tpacpi_led_classdev *data =
3918 container_of(work, struct tpacpi_led_classdev, work);
3919
3920 if (likely(tpacpi_lifecycle == TPACPI_LIFE_RUNNING))
3921 led_sysfs_set_status(data->led, data->new_brightness);
3922}
3923
3924static void led_sysfs_set(struct led_classdev *led_cdev,
3925 enum led_brightness brightness)
3926{
3927 struct tpacpi_led_classdev *data = container_of(led_cdev,
3928 struct tpacpi_led_classdev, led_classdev);
3929
3930 data->new_brightness = brightness;
3931 queue_work(tpacpi_wq, &data->work);
3932}
3933
3934static int led_sysfs_blink_set(struct led_classdev *led_cdev,
3935 unsigned long *delay_on, unsigned long *delay_off)
3936{
3937 struct tpacpi_led_classdev *data = container_of(led_cdev,
3938 struct tpacpi_led_classdev, led_classdev);
3939
3940 /* Can we choose the flash rate? */
3941 if (*delay_on == 0 && *delay_off == 0) {
3942 /* yes. set them to the hardware blink rate (1 Hz) */
3943 *delay_on = 500; /* ms */
3944 *delay_off = 500; /* ms */
3945 } else if ((*delay_on != 500) || (*delay_off != 500))
3946 return -EINVAL;
3947
3948 data->new_brightness = TPACPI_LED_BLINK;
3949 queue_work(tpacpi_wq, &data->work);
3950
3951 return 0;
3952}
3953
3954static enum led_brightness led_sysfs_get(struct led_classdev *led_cdev)
3955{
3956 int rc;
3957
3958 struct tpacpi_led_classdev *data = container_of(led_cdev,
3959 struct tpacpi_led_classdev, led_classdev);
3960
3961 rc = led_get_status(data->led);
3962
3963 if (rc == TPACPI_LED_OFF || rc < 0)
3964 rc = LED_OFF; /* no error handling in led class :( */
3965 else
3966 rc = LED_FULL;
3967
3968 return rc;
3969}
3970
3971static void led_exit(void)
3972{
3973 unsigned int i;
3974
3975 for (i = 0; i < TPACPI_LED_NUMLEDS; i++) {
3976 if (tpacpi_leds[i].led_classdev.name)
3977 led_classdev_unregister(&tpacpi_leds[i].led_classdev);
3978 }
3979
3980 kfree(tpacpi_leds);
3981 tpacpi_leds = NULL;
3982}
3983
3594static int __init led_init(struct ibm_init_struct *iibm) 3984static int __init led_init(struct ibm_init_struct *iibm)
3595{ 3985{
3986 unsigned int i;
3987 int rc;
3988
3596 vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n"); 3989 vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n");
3597 3990
3598 TPACPI_ACPIHANDLE_INIT(led); 3991 TPACPI_ACPIHANDLE_INIT(led);
@@ -3613,10 +4006,41 @@ static int __init led_init(struct ibm_init_struct *iibm)
3613 vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n", 4006 vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n",
3614 str_supported(led_supported), led_supported); 4007 str_supported(led_supported), led_supported);
3615 4008
4009 tpacpi_leds = kzalloc(sizeof(*tpacpi_leds) * TPACPI_LED_NUMLEDS,
4010 GFP_KERNEL);
4011 if (!tpacpi_leds) {
4012 printk(TPACPI_ERR "Out of memory for LED data\n");
4013 return -ENOMEM;
4014 }
4015
4016 for (i = 0; i < TPACPI_LED_NUMLEDS; i++) {
4017 tpacpi_leds[i].led = i;
4018
4019 tpacpi_leds[i].led_classdev.brightness_set = &led_sysfs_set;
4020 tpacpi_leds[i].led_classdev.blink_set = &led_sysfs_blink_set;
4021 if (led_supported == TPACPI_LED_570)
4022 tpacpi_leds[i].led_classdev.brightness_get =
4023 &led_sysfs_get;
4024
4025 tpacpi_leds[i].led_classdev.name = tpacpi_led_names[i];
4026
4027 INIT_WORK(&tpacpi_leds[i].work, led_set_status_worker);
4028
4029 rc = led_classdev_register(&tpacpi_pdev->dev,
4030 &tpacpi_leds[i].led_classdev);
4031 if (rc < 0) {
4032 tpacpi_leds[i].led_classdev.name = NULL;
4033 led_exit();
4034 return rc;
4035 }
4036 }
4037
3616 return (led_supported != TPACPI_LED_NONE)? 0 : 1; 4038 return (led_supported != TPACPI_LED_NONE)? 0 : 1;
3617} 4039}
3618 4040
3619#define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking")) 4041#define str_led_status(s) \
4042 ((s) == TPACPI_LED_OFF ? "off" : \
4043 ((s) == TPACPI_LED_ON ? "on" : "blinking"))
3620 4044
3621static int led_read(char *p) 4045static int led_read(char *p)
3622{ 4046{
@@ -3632,11 +4056,11 @@ static int led_read(char *p)
3632 /* 570 */ 4056 /* 570 */
3633 int i, status; 4057 int i, status;
3634 for (i = 0; i < 8; i++) { 4058 for (i = 0; i < 8; i++) {
3635 if (!acpi_evalf(ec_handle, 4059 status = led_get_status(i);
3636 &status, "GLED", "dd", 1 << i)) 4060 if (status < 0)
3637 return -EIO; 4061 return -EIO;
3638 len += sprintf(p + len, "%d:\t\t%s\n", 4062 len += sprintf(p + len, "%d:\t\t%s\n",
3639 i, led_status(status)); 4063 i, str_led_status(status));
3640 } 4064 }
3641 } 4065 }
3642 4066
@@ -3646,16 +4070,11 @@ static int led_read(char *p)
3646 return len; 4070 return len;
3647} 4071}
3648 4072
3649/* off, on, blink */
3650static const int led_sled_arg1[] = { 0, 1, 3 };
3651static const int led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */
3652static const int led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */
3653static const int led_led_arg1[] = { 0, 0x80, 0xc0 };
3654
3655static int led_write(char *buf) 4073static int led_write(char *buf)
3656{ 4074{
3657 char *cmd; 4075 char *cmd;
3658 int led, ind, ret; 4076 int led, rc;
4077 enum led_status_t s;
3659 4078
3660 if (!led_supported) 4079 if (!led_supported)
3661 return -ENODEV; 4080 return -ENODEV;
@@ -3665,38 +4084,18 @@ static int led_write(char *buf)
3665 return -EINVAL; 4084 return -EINVAL;
3666 4085
3667 if (strstr(cmd, "off")) { 4086 if (strstr(cmd, "off")) {
3668 ind = 0; 4087 s = TPACPI_LED_OFF;
3669 } else if (strstr(cmd, "on")) { 4088 } else if (strstr(cmd, "on")) {
3670 ind = 1; 4089 s = TPACPI_LED_ON;
3671 } else if (strstr(cmd, "blink")) { 4090 } else if (strstr(cmd, "blink")) {
3672 ind = 2; 4091 s = TPACPI_LED_BLINK;
3673 } else
3674 return -EINVAL;
3675
3676 if (led_supported == TPACPI_LED_570) {
3677 /* 570 */
3678 led = 1 << led;
3679 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
3680 led, led_sled_arg1[ind]))
3681 return -EIO;
3682 } else if (led_supported == TPACPI_LED_OLD) {
3683 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
3684 led = 1 << led;
3685 ret = ec_write(TPACPI_LED_EC_HLMS, led);
3686 if (ret >= 0)
3687 ret = ec_write(TPACPI_LED_EC_HLBL,
3688 led * led_exp_hlbl[ind]);
3689 if (ret >= 0)
3690 ret = ec_write(TPACPI_LED_EC_HLCL,
3691 led * led_exp_hlcl[ind]);
3692 if (ret < 0)
3693 return ret;
3694 } else { 4092 } else {
3695 /* all others */ 4093 return -EINVAL;
3696 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
3697 led, led_led_arg1[ind]))
3698 return -EIO;
3699 } 4094 }
4095
4096 rc = led_set_status(led, s);
4097 if (rc < 0)
4098 return rc;
3700 } 4099 }
3701 4100
3702 return 0; 4101 return 0;
@@ -3706,6 +4105,7 @@ static struct ibm_struct led_driver_data = {
3706 .name = "led", 4105 .name = "led",
3707 .read = led_read, 4106 .read = led_read,
3708 .write = led_write, 4107 .write = led_write,
4108 .exit = led_exit,
3709}; 4109};
3710 4110
3711/************************************************************************* 4111/*************************************************************************
@@ -4170,8 +4570,16 @@ static struct ibm_struct ecdump_driver_data = {
4170 4570
4171#define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen" 4571#define TPACPI_BACKLIGHT_DEV_NAME "thinkpad_screen"
4172 4572
4573enum {
4574 TP_EC_BACKLIGHT = 0x31,
4575
4576 /* TP_EC_BACKLIGHT bitmasks */
4577 TP_EC_BACKLIGHT_LVLMSK = 0x1F,
4578 TP_EC_BACKLIGHT_CMDMSK = 0xE0,
4579 TP_EC_BACKLIGHT_MAPSW = 0x20,
4580};
4581
4173static struct backlight_device *ibm_backlight_device; 4582static struct backlight_device *ibm_backlight_device;
4174static int brightness_offset = 0x31;
4175static int brightness_mode; 4583static int brightness_mode;
4176static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */ 4584static unsigned int brightness_enable = 2; /* 2 = auto, 0 = no, 1 = yes */
4177 4585
@@ -4180,16 +4588,24 @@ static struct mutex brightness_mutex;
4180/* 4588/*
4181 * ThinkPads can read brightness from two places: EC 0x31, or 4589 * ThinkPads can read brightness from two places: EC 0x31, or
4182 * CMOS NVRAM byte 0x5E, bits 0-3. 4590 * CMOS NVRAM byte 0x5E, bits 0-3.
4591 *
4592 * EC 0x31 has the following layout
4593 * Bit 7: unknown function
4594 * Bit 6: unknown function
4595 * Bit 5: Z: honour scale changes, NZ: ignore scale changes
4596 * Bit 4: must be set to zero to avoid problems
4597 * Bit 3-0: backlight brightness level
4598 *
4599 * brightness_get_raw returns status data in the EC 0x31 layout
4183 */ 4600 */
4184static int brightness_get(struct backlight_device *bd) 4601static int brightness_get_raw(int *status)
4185{ 4602{
4186 u8 lec = 0, lcmos = 0, level = 0; 4603 u8 lec = 0, lcmos = 0, level = 0;
4187 4604
4188 if (brightness_mode & 1) { 4605 if (brightness_mode & 1) {
4189 if (!acpi_ec_read(brightness_offset, &lec)) 4606 if (!acpi_ec_read(TP_EC_BACKLIGHT, &lec))
4190 return -EIO; 4607 return -EIO;
4191 lec &= (tp_features.bright_16levels)? 0x0f : 0x07; 4608 level = lec & TP_EC_BACKLIGHT_LVLMSK;
4192 level = lec;
4193 }; 4609 };
4194 if (brightness_mode & 2) { 4610 if (brightness_mode & 2) {
4195 lcmos = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS) 4611 lcmos = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS)
@@ -4199,16 +4615,27 @@ static int brightness_get(struct backlight_device *bd)
4199 level = lcmos; 4615 level = lcmos;
4200 } 4616 }
4201 4617
4202 if (brightness_mode == 3 && lec != lcmos) { 4618 if (brightness_mode == 3) {
4203 printk(TPACPI_ERR 4619 *status = lec; /* Prefer EC, CMOS is just a backing store */
4204 "CMOS NVRAM (%u) and EC (%u) do not agree " 4620 lec &= TP_EC_BACKLIGHT_LVLMSK;
4205 "on display brightness level\n", 4621 if (lec == lcmos)
4206 (unsigned int) lcmos, 4622 tp_warned.bright_cmos_ec_unsync = 0;
4207 (unsigned int) lec); 4623 else {
4208 return -EIO; 4624 if (!tp_warned.bright_cmos_ec_unsync) {
4625 printk(TPACPI_ERR
4626 "CMOS NVRAM (%u) and EC (%u) do not "
4627 "agree on display brightness level\n",
4628 (unsigned int) lcmos,
4629 (unsigned int) lec);
4630 tp_warned.bright_cmos_ec_unsync = 1;
4631 }
4632 return -EIO;
4633 }
4634 } else {
4635 *status = level;
4209 } 4636 }
4210 4637
4211 return level; 4638 return 0;
4212} 4639}
4213 4640
4214/* May return EINTR which can always be mapped to ERESTARTSYS */ 4641/* May return EINTR which can always be mapped to ERESTARTSYS */
@@ -4216,19 +4643,22 @@ static int brightness_set(int value)
4216{ 4643{
4217 int cmos_cmd, inc, i, res; 4644 int cmos_cmd, inc, i, res;
4218 int current_value; 4645 int current_value;
4646 int command_bits;
4219 4647
4220 if (value > ((tp_features.bright_16levels)? 15 : 7)) 4648 if (value > ((tp_features.bright_16levels)? 15 : 7) ||
4649 value < 0)
4221 return -EINVAL; 4650 return -EINVAL;
4222 4651
4223 res = mutex_lock_interruptible(&brightness_mutex); 4652 res = mutex_lock_interruptible(&brightness_mutex);
4224 if (res < 0) 4653 if (res < 0)
4225 return res; 4654 return res;
4226 4655
4227 current_value = brightness_get(NULL); 4656 res = brightness_get_raw(&current_value);
4228 if (current_value < 0) { 4657 if (res < 0)
4229 res = current_value;
4230 goto errout; 4658 goto errout;
4231 } 4659
4660 command_bits = current_value & TP_EC_BACKLIGHT_CMDMSK;
4661 current_value &= TP_EC_BACKLIGHT_LVLMSK;
4232 4662
4233 cmos_cmd = value > current_value ? 4663 cmos_cmd = value > current_value ?
4234 TP_CMOS_BRIGHTNESS_UP : 4664 TP_CMOS_BRIGHTNESS_UP :
@@ -4243,7 +4673,8 @@ static int brightness_set(int value)
4243 goto errout; 4673 goto errout;
4244 } 4674 }
4245 if ((brightness_mode & 1) && 4675 if ((brightness_mode & 1) &&
4246 !acpi_ec_write(brightness_offset, i + inc)) { 4676 !acpi_ec_write(TP_EC_BACKLIGHT,
4677 (i + inc) | command_bits)) {
4247 res = -EIO; 4678 res = -EIO;
4248 goto errout;; 4679 goto errout;;
4249 } 4680 }
@@ -4266,106 +4697,23 @@ static int brightness_update_status(struct backlight_device *bd)
4266 bd->props.brightness : 0); 4697 bd->props.brightness : 0);
4267} 4698}
4268 4699
4269static struct backlight_ops ibm_backlight_data = { 4700static int brightness_get(struct backlight_device *bd)
4270 .get_brightness = brightness_get,
4271 .update_status = brightness_update_status,
4272};
4273
4274/* --------------------------------------------------------------------- */
4275
4276static int __init tpacpi_query_bcll_levels(acpi_handle handle)
4277{
4278 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
4279 union acpi_object *obj;
4280 int rc;
4281
4282 if (ACPI_SUCCESS(acpi_evaluate_object(handle, NULL, NULL, &buffer))) {
4283 obj = (union acpi_object *)buffer.pointer;
4284 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
4285 printk(TPACPI_ERR "Unknown BCLL data, "
4286 "please report this to %s\n", TPACPI_MAIL);
4287 rc = 0;
4288 } else {
4289 rc = obj->package.count;
4290 }
4291 } else {
4292 return 0;
4293 }
4294
4295 kfree(buffer.pointer);
4296 return rc;
4297}
4298
4299static acpi_status __init brightness_find_bcll(acpi_handle handle, u32 lvl,
4300 void *context, void **rv)
4301{
4302 char name[ACPI_PATH_SEGMENT_LENGTH];
4303 struct acpi_buffer buffer = { sizeof(name), &name };
4304
4305 if (ACPI_SUCCESS(acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer)) &&
4306 !strncmp("BCLL", name, sizeof(name) - 1)) {
4307 if (tpacpi_query_bcll_levels(handle) == 16) {
4308 *rv = handle;
4309 return AE_CTRL_TERMINATE;
4310 } else {
4311 return AE_OK;
4312 }
4313 } else {
4314 return AE_OK;
4315 }
4316}
4317
4318static int __init brightness_check_levels(void)
4319{ 4701{
4320 int status; 4702 int status, res;
4321 void *found_node = NULL;
4322 4703
4323 if (!vid_handle) { 4704 res = brightness_get_raw(&status);
4324 TPACPI_ACPIHANDLE_INIT(vid); 4705 if (res < 0)
4325 } 4706 return 0; /* FIXME: teach backlight about error handling */
4326 if (!vid_handle)
4327 return 0;
4328
4329 /* Search for a BCLL package with 16 levels */
4330 status = acpi_walk_namespace(ACPI_TYPE_PACKAGE, vid_handle, 3,
4331 brightness_find_bcll, NULL,
4332 &found_node);
4333
4334 return (ACPI_SUCCESS(status) && found_node != NULL);
4335}
4336
4337static acpi_status __init brightness_find_bcl(acpi_handle handle, u32 lvl,
4338 void *context, void **rv)
4339{
4340 char name[ACPI_PATH_SEGMENT_LENGTH];
4341 struct acpi_buffer buffer = { sizeof(name), &name };
4342 4707
4343 if (ACPI_SUCCESS(acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer)) && 4708 return status & TP_EC_BACKLIGHT_LVLMSK;
4344 !strncmp("_BCL", name, sizeof(name) - 1)) {
4345 *rv = handle;
4346 return AE_CTRL_TERMINATE;
4347 } else {
4348 return AE_OK;
4349 }
4350} 4709}
4351 4710
4352static int __init brightness_check_std_acpi_support(void) 4711static struct backlight_ops ibm_backlight_data = {
4353{ 4712 .get_brightness = brightness_get,
4354 int status; 4713 .update_status = brightness_update_status,
4355 void *found_node = NULL; 4714};
4356
4357 if (!vid_handle) {
4358 TPACPI_ACPIHANDLE_INIT(vid);
4359 }
4360 if (!vid_handle)
4361 return 0;
4362
4363 /* Search for a _BCL method, but don't execute it */
4364 status = acpi_walk_namespace(ACPI_TYPE_METHOD, vid_handle, 3,
4365 brightness_find_bcl, NULL, &found_node);
4366 4715
4367 return (ACPI_SUCCESS(status) && found_node != NULL); 4716/* --------------------------------------------------------------------- */
4368}
4369 4717
4370static int __init brightness_init(struct ibm_init_struct *iibm) 4718static int __init brightness_init(struct ibm_init_struct *iibm)
4371{ 4719{
@@ -4375,13 +4723,19 @@ static int __init brightness_init(struct ibm_init_struct *iibm)
4375 4723
4376 mutex_init(&brightness_mutex); 4724 mutex_init(&brightness_mutex);
4377 4725
4378 if (!brightness_enable) { 4726 /*
4379 dbg_printk(TPACPI_DBG_INIT, 4727 * We always attempt to detect acpi support, so as to switch
4380 "brightness support disabled by " 4728 * Lenovo Vista BIOS to ACPI brightness mode even if we are not
4381 "module parameter\n"); 4729 * going to publish a backlight interface
4382 return 1; 4730 */
4383 } else if (brightness_enable > 1) { 4731 b = tpacpi_check_std_acpi_brightness_support();
4384 if (brightness_check_std_acpi_support()) { 4732 if (b > 0) {
4733 if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) {
4734 printk(TPACPI_NOTICE
4735 "Lenovo BIOS switched to ACPI backlight "
4736 "control mode\n");
4737 }
4738 if (brightness_enable > 1) {
4385 printk(TPACPI_NOTICE 4739 printk(TPACPI_NOTICE
4386 "standard ACPI backlight interface " 4740 "standard ACPI backlight interface "
4387 "available, not loading native one...\n"); 4741 "available, not loading native one...\n");
@@ -4389,6 +4743,22 @@ static int __init brightness_init(struct ibm_init_struct *iibm)
4389 } 4743 }
4390 } 4744 }
4391 4745
4746 if (!brightness_enable) {
4747 dbg_printk(TPACPI_DBG_INIT,
4748 "brightness support disabled by "
4749 "module parameter\n");
4750 return 1;
4751 }
4752
4753 if (b > 16) {
4754 printk(TPACPI_ERR
4755 "Unsupported brightness interface, "
4756 "please contact %s\n", TPACPI_MAIL);
4757 return 1;
4758 }
4759 if (b == 16)
4760 tp_features.bright_16levels = 1;
4761
4392 if (!brightness_mode) { 4762 if (!brightness_mode) {
4393 if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) 4763 if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO)
4394 brightness_mode = 2; 4764 brightness_mode = 2;
@@ -4402,12 +4772,7 @@ static int __init brightness_init(struct ibm_init_struct *iibm)
4402 if (brightness_mode > 3) 4772 if (brightness_mode > 3)
4403 return -EINVAL; 4773 return -EINVAL;
4404 4774
4405 tp_features.bright_16levels = 4775 if (brightness_get_raw(&b) < 0)
4406 thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO &&
4407 brightness_check_levels();
4408
4409 b = brightness_get(NULL);
4410 if (b < 0)
4411 return 1; 4776 return 1;
4412 4777
4413 if (tp_features.bright_16levels) 4778 if (tp_features.bright_16levels)
@@ -4425,7 +4790,7 @@ static int __init brightness_init(struct ibm_init_struct *iibm)
4425 4790
4426 ibm_backlight_device->props.max_brightness = 4791 ibm_backlight_device->props.max_brightness =
4427 (tp_features.bright_16levels)? 15 : 7; 4792 (tp_features.bright_16levels)? 15 : 7;
4428 ibm_backlight_device->props.brightness = b; 4793 ibm_backlight_device->props.brightness = b & TP_EC_BACKLIGHT_LVLMSK;
4429 backlight_update_status(ibm_backlight_device); 4794 backlight_update_status(ibm_backlight_device);
4430 4795
4431 return 0; 4796 return 0;
@@ -5046,11 +5411,11 @@ static void fan_watchdog_reset(void)
5046 if (fan_watchdog_maxinterval > 0 && 5411 if (fan_watchdog_maxinterval > 0 &&
5047 tpacpi_lifecycle != TPACPI_LIFE_EXITING) { 5412 tpacpi_lifecycle != TPACPI_LIFE_EXITING) {
5048 fan_watchdog_active = 1; 5413 fan_watchdog_active = 1;
5049 if (!schedule_delayed_work(&fan_watchdog_task, 5414 if (!queue_delayed_work(tpacpi_wq, &fan_watchdog_task,
5050 msecs_to_jiffies(fan_watchdog_maxinterval 5415 msecs_to_jiffies(fan_watchdog_maxinterval
5051 * 1000))) { 5416 * 1000))) {
5052 printk(TPACPI_ERR 5417 printk(TPACPI_ERR
5053 "failed to schedule the fan watchdog, " 5418 "failed to queue the fan watchdog, "
5054 "watchdog will not trigger\n"); 5419 "watchdog will not trigger\n");
5055 } 5420 }
5056 } else 5421 } else
@@ -5420,7 +5785,7 @@ static void fan_exit(void)
5420 &driver_attr_fan_watchdog); 5785 &driver_attr_fan_watchdog);
5421 5786
5422 cancel_delayed_work(&fan_watchdog_task); 5787 cancel_delayed_work(&fan_watchdog_task);
5423 flush_scheduled_work(); 5788 flush_workqueue(tpacpi_wq);
5424} 5789}
5425 5790
5426static int fan_read(char *p) 5791static int fan_read(char *p)
@@ -5826,10 +6191,13 @@ static void __init get_thinkpad_model_data(struct thinkpad_id_data *tp)
5826 6191
5827 tp->model_str = kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION), 6192 tp->model_str = kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION),
5828 GFP_KERNEL); 6193 GFP_KERNEL);
5829 if (strnicmp(tp->model_str, "ThinkPad", 8) != 0) { 6194 if (tp->model_str && strnicmp(tp->model_str, "ThinkPad", 8) != 0) {
5830 kfree(tp->model_str); 6195 kfree(tp->model_str);
5831 tp->model_str = NULL; 6196 tp->model_str = NULL;
5832 } 6197 }
6198
6199 tp->nummodel_str = kstrdup(dmi_get_system_info(DMI_PRODUCT_NAME),
6200 GFP_KERNEL);
5833} 6201}
5834 6202
5835static int __init probe_for_thinkpad(void) 6203static int __init probe_for_thinkpad(void)
@@ -6071,6 +6439,9 @@ static void thinkpad_acpi_module_exit(void)
6071 if (proc_dir) 6439 if (proc_dir)
6072 remove_proc_entry(TPACPI_PROC_DIR, acpi_root_dir); 6440 remove_proc_entry(TPACPI_PROC_DIR, acpi_root_dir);
6073 6441
6442 if (tpacpi_wq)
6443 destroy_workqueue(tpacpi_wq);
6444
6074 kfree(thinkpad_id.bios_version_str); 6445 kfree(thinkpad_id.bios_version_str);
6075 kfree(thinkpad_id.ec_version_str); 6446 kfree(thinkpad_id.ec_version_str);
6076 kfree(thinkpad_id.model_str); 6447 kfree(thinkpad_id.model_str);
@@ -6101,6 +6472,12 @@ static int __init thinkpad_acpi_module_init(void)
6101 TPACPI_ACPIHANDLE_INIT(ecrd); 6472 TPACPI_ACPIHANDLE_INIT(ecrd);
6102 TPACPI_ACPIHANDLE_INIT(ecwr); 6473 TPACPI_ACPIHANDLE_INIT(ecwr);
6103 6474
6475 tpacpi_wq = create_singlethread_workqueue(TPACPI_WORKQUEUE_NAME);
6476 if (!tpacpi_wq) {
6477 thinkpad_acpi_module_exit();
6478 return -ENOMEM;
6479 }
6480
6104 proc_dir = proc_mkdir(TPACPI_PROC_DIR, acpi_root_dir); 6481 proc_dir = proc_mkdir(TPACPI_PROC_DIR, acpi_root_dir);
6105 if (!proc_dir) { 6482 if (!proc_dir) {
6106 printk(TPACPI_ERR 6483 printk(TPACPI_ERR
@@ -6223,6 +6600,8 @@ static int __init thinkpad_acpi_module_init(void)
6223/* Please remove this in year 2009 */ 6600/* Please remove this in year 2009 */
6224MODULE_ALIAS("ibm_acpi"); 6601MODULE_ALIAS("ibm_acpi");
6225 6602
6603MODULE_ALIAS(TPACPI_DRVR_SHORTNAME);
6604
6226/* 6605/*
6227 * DMI matching for module autoloading 6606 * DMI matching for module autoloading
6228 * 6607 *
diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
index e812df607a5c..fcd1aeccdf93 100644
--- a/drivers/mtd/chips/cfi_cmdset_0001.c
+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
@@ -82,9 +82,8 @@ static struct mtd_info *cfi_intelext_setup (struct mtd_info *);
82static int cfi_intelext_partition_fixup(struct mtd_info *, struct cfi_private **); 82static int cfi_intelext_partition_fixup(struct mtd_info *, struct cfi_private **);
83 83
84static int cfi_intelext_point (struct mtd_info *mtd, loff_t from, size_t len, 84static int cfi_intelext_point (struct mtd_info *mtd, loff_t from, size_t len,
85 size_t *retlen, u_char **mtdbuf); 85 size_t *retlen, void **virt, resource_size_t *phys);
86static void cfi_intelext_unpoint (struct mtd_info *mtd, u_char *addr, loff_t from, 86static void cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len);
87 size_t len);
88 87
89static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long adr, int mode); 88static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long adr, int mode);
90static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr, int mode); 89static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr, int mode);
@@ -1240,7 +1239,8 @@ static int do_point_onechip (struct map_info *map, struct flchip *chip, loff_t a
1240 return ret; 1239 return ret;
1241} 1240}
1242 1241
1243static int cfi_intelext_point (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char **mtdbuf) 1242static int cfi_intelext_point(struct mtd_info *mtd, loff_t from, size_t len,
1243 size_t *retlen, void **virt, resource_size_t *phys)
1244{ 1244{
1245 struct map_info *map = mtd->priv; 1245 struct map_info *map = mtd->priv;
1246 struct cfi_private *cfi = map->fldrv_priv; 1246 struct cfi_private *cfi = map->fldrv_priv;
@@ -1257,8 +1257,10 @@ static int cfi_intelext_point (struct mtd_info *mtd, loff_t from, size_t len, si
1257 chipnum = (from >> cfi->chipshift); 1257 chipnum = (from >> cfi->chipshift);
1258 ofs = from - (chipnum << cfi->chipshift); 1258 ofs = from - (chipnum << cfi->chipshift);
1259 1259
1260 *mtdbuf = (void *)map->virt + cfi->chips[chipnum].start + ofs; 1260 *virt = map->virt + cfi->chips[chipnum].start + ofs;
1261 *retlen = 0; 1261 *retlen = 0;
1262 if (phys)
1263 *phys = map->phys + cfi->chips[chipnum].start + ofs;
1262 1264
1263 while (len) { 1265 while (len) {
1264 unsigned long thislen; 1266 unsigned long thislen;
@@ -1291,7 +1293,7 @@ static int cfi_intelext_point (struct mtd_info *mtd, loff_t from, size_t len, si
1291 return 0; 1293 return 0;
1292} 1294}
1293 1295
1294static void cfi_intelext_unpoint (struct mtd_info *mtd, u_char *addr, loff_t from, size_t len) 1296static void cfi_intelext_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
1295{ 1297{
1296 struct map_info *map = mtd->priv; 1298 struct map_info *map = mtd->priv;
1297 struct cfi_private *cfi = map->fldrv_priv; 1299 struct cfi_private *cfi = map->fldrv_priv;
diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c
index bf485ff49457..0399be178620 100644
--- a/drivers/mtd/devices/mtdram.c
+++ b/drivers/mtd/devices/mtdram.c
@@ -48,18 +48,21 @@ static int ram_erase(struct mtd_info *mtd, struct erase_info *instr)
48} 48}
49 49
50static int ram_point(struct mtd_info *mtd, loff_t from, size_t len, 50static int ram_point(struct mtd_info *mtd, loff_t from, size_t len,
51 size_t *retlen, u_char **mtdbuf) 51 size_t *retlen, void **virt, resource_size_t *phys)
52{ 52{
53 if (from + len > mtd->size) 53 if (from + len > mtd->size)
54 return -EINVAL; 54 return -EINVAL;
55 55
56 *mtdbuf = mtd->priv + from; 56 /* can we return a physical address with this driver? */
57 if (phys)
58 return -EINVAL;
59
60 *virt = mtd->priv + from;
57 *retlen = len; 61 *retlen = len;
58 return 0; 62 return 0;
59} 63}
60 64
61static void ram_unpoint(struct mtd_info *mtd, u_char * addr, loff_t from, 65static void ram_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
62 size_t len)
63{ 66{
64} 67}
65 68
diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c
index 5f960182da95..c7987b1c5e01 100644
--- a/drivers/mtd/devices/phram.c
+++ b/drivers/mtd/devices/phram.c
@@ -57,20 +57,21 @@ static int phram_erase(struct mtd_info *mtd, struct erase_info *instr)
57} 57}
58 58
59static int phram_point(struct mtd_info *mtd, loff_t from, size_t len, 59static int phram_point(struct mtd_info *mtd, loff_t from, size_t len,
60 size_t *retlen, u_char **mtdbuf) 60 size_t *retlen, void **virt, resource_size_t *phys)
61{ 61{
62 u_char *start = mtd->priv;
63
64 if (from + len > mtd->size) 62 if (from + len > mtd->size)
65 return -EINVAL; 63 return -EINVAL;
66 64
67 *mtdbuf = start + from; 65 /* can we return a physical address with this driver? */
66 if (phys)
67 return -EINVAL;
68
69 *virt = mtd->priv + from;
68 *retlen = len; 70 *retlen = len;
69 return 0; 71 return 0;
70} 72}
71 73
72static void phram_unpoint(struct mtd_info *mtd, u_char *addr, loff_t from, 74static void phram_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
73 size_t len)
74{ 75{
75} 76}
76 77
diff --git a/drivers/mtd/devices/pmc551.c b/drivers/mtd/devices/pmc551.c
index 7060a0895ce2..bc9981749064 100644
--- a/drivers/mtd/devices/pmc551.c
+++ b/drivers/mtd/devices/pmc551.c
@@ -134,7 +134,8 @@ static int pmc551_erase(struct mtd_info *mtd, struct erase_info *instr)
134 eoff_lo = end & (priv->asize - 1); 134 eoff_lo = end & (priv->asize - 1);
135 soff_lo = instr->addr & (priv->asize - 1); 135 soff_lo = instr->addr & (priv->asize - 1);
136 136
137 pmc551_point(mtd, instr->addr, instr->len, &retlen, &ptr); 137 pmc551_point(mtd, instr->addr, instr->len, &retlen,
138 (void **)&ptr, NULL);
138 139
139 if (soff_hi == eoff_hi || mtd->size == priv->asize) { 140 if (soff_hi == eoff_hi || mtd->size == priv->asize) {
140 /* The whole thing fits within one access, so just one shot 141 /* The whole thing fits within one access, so just one shot
@@ -154,7 +155,8 @@ static int pmc551_erase(struct mtd_info *mtd, struct erase_info *instr)
154 } 155 }
155 soff_hi += priv->asize; 156 soff_hi += priv->asize;
156 pmc551_point(mtd, (priv->base_map0 | soff_hi), 157 pmc551_point(mtd, (priv->base_map0 | soff_hi),
157 priv->asize, &retlen, &ptr); 158 priv->asize, &retlen,
159 (void **)&ptr, NULL);
158 } 160 }
159 memset(ptr, 0xff, eoff_lo); 161 memset(ptr, 0xff, eoff_lo);
160 } 162 }
@@ -170,7 +172,7 @@ static int pmc551_erase(struct mtd_info *mtd, struct erase_info *instr)
170} 172}
171 173
172static int pmc551_point(struct mtd_info *mtd, loff_t from, size_t len, 174static int pmc551_point(struct mtd_info *mtd, loff_t from, size_t len,
173 size_t * retlen, u_char ** mtdbuf) 175 size_t *retlen, void **virt, resource_size_t *phys)
174{ 176{
175 struct mypriv *priv = mtd->priv; 177 struct mypriv *priv = mtd->priv;
176 u32 soff_hi; 178 u32 soff_hi;
@@ -188,6 +190,10 @@ static int pmc551_point(struct mtd_info *mtd, loff_t from, size_t len,
188 return -EINVAL; 190 return -EINVAL;
189 } 191 }
190 192
193 /* can we return a physical address with this driver? */
194 if (phys)
195 return -EINVAL;
196
191 soff_hi = from & ~(priv->asize - 1); 197 soff_hi = from & ~(priv->asize - 1);
192 soff_lo = from & (priv->asize - 1); 198 soff_lo = from & (priv->asize - 1);
193 199
@@ -198,13 +204,12 @@ static int pmc551_point(struct mtd_info *mtd, loff_t from, size_t len,
198 priv->curr_map0 = soff_hi; 204 priv->curr_map0 = soff_hi;
199 } 205 }
200 206
201 *mtdbuf = priv->start + soff_lo; 207 *virt = priv->start + soff_lo;
202 *retlen = len; 208 *retlen = len;
203 return 0; 209 return 0;
204} 210}
205 211
206static void pmc551_unpoint(struct mtd_info *mtd, u_char * addr, loff_t from, 212static void pmc551_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
207 size_t len)
208{ 213{
209#ifdef CONFIG_MTD_PMC551_DEBUG 214#ifdef CONFIG_MTD_PMC551_DEBUG
210 printk(KERN_DEBUG "pmc551_unpoint()\n"); 215 printk(KERN_DEBUG "pmc551_unpoint()\n");
@@ -242,7 +247,7 @@ static int pmc551_read(struct mtd_info *mtd, loff_t from, size_t len,
242 soff_lo = from & (priv->asize - 1); 247 soff_lo = from & (priv->asize - 1);
243 eoff_lo = end & (priv->asize - 1); 248 eoff_lo = end & (priv->asize - 1);
244 249
245 pmc551_point(mtd, from, len, retlen, &ptr); 250 pmc551_point(mtd, from, len, retlen, (void **)&ptr, NULL);
246 251
247 if (soff_hi == eoff_hi) { 252 if (soff_hi == eoff_hi) {
248 /* The whole thing fits within one access, so just one shot 253 /* The whole thing fits within one access, so just one shot
@@ -263,7 +268,8 @@ static int pmc551_read(struct mtd_info *mtd, loff_t from, size_t len,
263 goto out; 268 goto out;
264 } 269 }
265 soff_hi += priv->asize; 270 soff_hi += priv->asize;
266 pmc551_point(mtd, soff_hi, priv->asize, retlen, &ptr); 271 pmc551_point(mtd, soff_hi, priv->asize, retlen,
272 (void **)&ptr, NULL);
267 } 273 }
268 memcpy(copyto, ptr, eoff_lo); 274 memcpy(copyto, ptr, eoff_lo);
269 copyto += eoff_lo; 275 copyto += eoff_lo;
@@ -308,7 +314,7 @@ static int pmc551_write(struct mtd_info *mtd, loff_t to, size_t len,
308 soff_lo = to & (priv->asize - 1); 314 soff_lo = to & (priv->asize - 1);
309 eoff_lo = end & (priv->asize - 1); 315 eoff_lo = end & (priv->asize - 1);
310 316
311 pmc551_point(mtd, to, len, retlen, &ptr); 317 pmc551_point(mtd, to, len, retlen, (void **)&ptr, NULL);
312 318
313 if (soff_hi == eoff_hi) { 319 if (soff_hi == eoff_hi) {
314 /* The whole thing fits within one access, so just one shot 320 /* The whole thing fits within one access, so just one shot
@@ -329,7 +335,8 @@ static int pmc551_write(struct mtd_info *mtd, loff_t to, size_t len,
329 goto out; 335 goto out;
330 } 336 }
331 soff_hi += priv->asize; 337 soff_hi += priv->asize;
332 pmc551_point(mtd, soff_hi, priv->asize, retlen, &ptr); 338 pmc551_point(mtd, soff_hi, priv->asize, retlen,
339 (void **)&ptr, NULL);
333 } 340 }
334 memcpy(ptr, copyfrom, eoff_lo); 341 memcpy(ptr, copyfrom, eoff_lo);
335 copyfrom += eoff_lo; 342 copyfrom += eoff_lo;
diff --git a/drivers/mtd/devices/slram.c b/drivers/mtd/devices/slram.c
index d293add1857c..cb86db746f28 100644
--- a/drivers/mtd/devices/slram.c
+++ b/drivers/mtd/devices/slram.c
@@ -76,8 +76,9 @@ static char *map;
76static slram_mtd_list_t *slram_mtdlist = NULL; 76static slram_mtd_list_t *slram_mtdlist = NULL;
77 77
78static int slram_erase(struct mtd_info *, struct erase_info *); 78static int slram_erase(struct mtd_info *, struct erase_info *);
79static int slram_point(struct mtd_info *, loff_t, size_t, size_t *, u_char **); 79static int slram_point(struct mtd_info *, loff_t, size_t, size_t *, void **,
80static void slram_unpoint(struct mtd_info *, u_char *, loff_t, size_t); 80 resource_size_t *);
81static void slram_unpoint(struct mtd_info *, loff_t, size_t);
81static int slram_read(struct mtd_info *, loff_t, size_t, size_t *, u_char *); 82static int slram_read(struct mtd_info *, loff_t, size_t, size_t *, u_char *);
82static int slram_write(struct mtd_info *, loff_t, size_t, size_t *, const u_char *); 83static int slram_write(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
83 84
@@ -104,19 +105,23 @@ static int slram_erase(struct mtd_info *mtd, struct erase_info *instr)
104} 105}
105 106
106static int slram_point(struct mtd_info *mtd, loff_t from, size_t len, 107static int slram_point(struct mtd_info *mtd, loff_t from, size_t len,
107 size_t *retlen, u_char **mtdbuf) 108 size_t *retlen, void **virt, resource_size_t *phys)
108{ 109{
109 slram_priv_t *priv = mtd->priv; 110 slram_priv_t *priv = mtd->priv;
110 111
112 /* can we return a physical address with this driver? */
113 if (phys)
114 return -EINVAL;
115
111 if (from + len > mtd->size) 116 if (from + len > mtd->size)
112 return -EINVAL; 117 return -EINVAL;
113 118
114 *mtdbuf = priv->start + from; 119 *virt = priv->start + from;
115 *retlen = len; 120 *retlen = len;
116 return(0); 121 return(0);
117} 122}
118 123
119static void slram_unpoint(struct mtd_info *mtd, u_char *addr, loff_t from, size_t len) 124static void slram_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
120{ 125{
121} 126}
122 127
diff --git a/drivers/mtd/maps/uclinux.c b/drivers/mtd/maps/uclinux.c
index 14ffb1a9302a..c42f4b83f686 100644
--- a/drivers/mtd/maps/uclinux.c
+++ b/drivers/mtd/maps/uclinux.c
@@ -40,10 +40,12 @@ struct mtd_partition uclinux_romfs[] = {
40/****************************************************************************/ 40/****************************************************************************/
41 41
42int uclinux_point(struct mtd_info *mtd, loff_t from, size_t len, 42int uclinux_point(struct mtd_info *mtd, loff_t from, size_t len,
43 size_t *retlen, u_char **mtdbuf) 43 size_t *retlen, void **virt, resource_size_t *phys)
44{ 44{
45 struct map_info *map = mtd->priv; 45 struct map_info *map = mtd->priv;
46 *mtdbuf = (u_char *) (map->virt + ((int) from)); 46 *virt = map->virt + from;
47 if (phys)
48 *phys = map->phys + from;
47 *retlen = len; 49 *retlen = len;
48 return(0); 50 return(0);
49} 51}
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index c66902df3171..07c701169344 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -68,7 +68,7 @@ static int part_read (struct mtd_info *mtd, loff_t from, size_t len,
68} 68}
69 69
70static int part_point (struct mtd_info *mtd, loff_t from, size_t len, 70static int part_point (struct mtd_info *mtd, loff_t from, size_t len,
71 size_t *retlen, u_char **buf) 71 size_t *retlen, void **virt, resource_size_t *phys)
72{ 72{
73 struct mtd_part *part = PART(mtd); 73 struct mtd_part *part = PART(mtd);
74 if (from >= mtd->size) 74 if (from >= mtd->size)
@@ -76,14 +76,14 @@ static int part_point (struct mtd_info *mtd, loff_t from, size_t len,
76 else if (from + len > mtd->size) 76 else if (from + len > mtd->size)
77 len = mtd->size - from; 77 len = mtd->size - from;
78 return part->master->point (part->master, from + part->offset, 78 return part->master->point (part->master, from + part->offset,
79 len, retlen, buf); 79 len, retlen, virt, phys);
80} 80}
81 81
82static void part_unpoint (struct mtd_info *mtd, u_char *addr, loff_t from, size_t len) 82static void part_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
83{ 83{
84 struct mtd_part *part = PART(mtd); 84 struct mtd_part *part = PART(mtd);
85 85
86 part->master->unpoint (part->master, addr, from + part->offset, len); 86 part->master->unpoint(part->master, from + part->offset, len);
87} 87}
88 88
89static int part_read_oob(struct mtd_info *mtd, loff_t from, 89static int part_read_oob(struct mtd_info *mtd, loff_t from,
diff --git a/drivers/mtd/nand/at91_nand.c b/drivers/mtd/nand/at91_nand.c
index 414ceaecdb3a..0adb287027a2 100644
--- a/drivers/mtd/nand/at91_nand.c
+++ b/drivers/mtd/nand/at91_nand.c
@@ -94,6 +94,24 @@ struct at91_nand_host {
94}; 94};
95 95
96/* 96/*
97 * Enable NAND.
98 */
99static void at91_nand_enable(struct at91_nand_host *host)
100{
101 if (host->board->enable_pin)
102 at91_set_gpio_value(host->board->enable_pin, 0);
103}
104
105/*
106 * Disable NAND.
107 */
108static void at91_nand_disable(struct at91_nand_host *host)
109{
110 if (host->board->enable_pin)
111 at91_set_gpio_value(host->board->enable_pin, 1);
112}
113
114/*
97 * Hardware specific access to control-lines 115 * Hardware specific access to control-lines
98 */ 116 */
99static void at91_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) 117static void at91_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
@@ -101,11 +119,11 @@ static void at91_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
101 struct nand_chip *nand_chip = mtd->priv; 119 struct nand_chip *nand_chip = mtd->priv;
102 struct at91_nand_host *host = nand_chip->priv; 120 struct at91_nand_host *host = nand_chip->priv;
103 121
104 if (host->board->enable_pin && (ctrl & NAND_CTRL_CHANGE)) { 122 if (ctrl & NAND_CTRL_CHANGE) {
105 if (ctrl & NAND_NCE) 123 if (ctrl & NAND_NCE)
106 at91_set_gpio_value(host->board->enable_pin, 0); 124 at91_nand_enable(host);
107 else 125 else
108 at91_set_gpio_value(host->board->enable_pin, 1); 126 at91_nand_disable(host);
109 } 127 }
110 if (cmd == NAND_CMD_NONE) 128 if (cmd == NAND_CMD_NONE)
111 return; 129 return;
@@ -128,24 +146,6 @@ static int at91_nand_device_ready(struct mtd_info *mtd)
128} 146}
129 147
130/* 148/*
131 * Enable NAND.
132 */
133static void at91_nand_enable(struct at91_nand_host *host)
134{
135 if (host->board->enable_pin)
136 at91_set_gpio_value(host->board->enable_pin, 0);
137}
138
139/*
140 * Disable NAND.
141 */
142static void at91_nand_disable(struct at91_nand_host *host)
143{
144 if (host->board->enable_pin)
145 at91_set_gpio_value(host->board->enable_pin, 1);
146}
147
148/*
149 * write oob for small pages 149 * write oob for small pages
150 */ 150 */
151static int at91_nand_write_oob_512(struct mtd_info *mtd, 151static int at91_nand_write_oob_512(struct mtd_info *mtd,
diff --git a/drivers/net/3c505.c b/drivers/net/3c505.c
index 9c6573419f5a..fdfb2b2cb734 100644
--- a/drivers/net/3c505.c
+++ b/drivers/net/3c505.c
@@ -670,7 +670,7 @@ static irqreturn_t elp_interrupt(int irq, void *dev_id)
670 memcpy(adapter->current_dma.target, adapter->dma_buffer, adapter->current_dma.length); 670 memcpy(adapter->current_dma.target, adapter->dma_buffer, adapter->current_dma.length);
671 } 671 }
672 skb->protocol = eth_type_trans(skb,dev); 672 skb->protocol = eth_type_trans(skb,dev);
673 adapter->stats.rx_bytes += skb->len; 673 dev->stats.rx_bytes += skb->len;
674 netif_rx(skb); 674 netif_rx(skb);
675 dev->last_rx = jiffies; 675 dev->last_rx = jiffies;
676 } 676 }
@@ -773,12 +773,12 @@ static irqreturn_t elp_interrupt(int irq, void *dev_id)
773 * received board statistics 773 * received board statistics
774 */ 774 */
775 case CMD_NETWORK_STATISTICS_RESPONSE: 775 case CMD_NETWORK_STATISTICS_RESPONSE:
776 adapter->stats.rx_packets += adapter->irx_pcb.data.netstat.tot_recv; 776 dev->stats.rx_packets += adapter->irx_pcb.data.netstat.tot_recv;
777 adapter->stats.tx_packets += adapter->irx_pcb.data.netstat.tot_xmit; 777 dev->stats.tx_packets += adapter->irx_pcb.data.netstat.tot_xmit;
778 adapter->stats.rx_crc_errors += adapter->irx_pcb.data.netstat.err_CRC; 778 dev->stats.rx_crc_errors += adapter->irx_pcb.data.netstat.err_CRC;
779 adapter->stats.rx_frame_errors += adapter->irx_pcb.data.netstat.err_align; 779 dev->stats.rx_frame_errors += adapter->irx_pcb.data.netstat.err_align;
780 adapter->stats.rx_fifo_errors += adapter->irx_pcb.data.netstat.err_ovrrun; 780 dev->stats.rx_fifo_errors += adapter->irx_pcb.data.netstat.err_ovrrun;
781 adapter->stats.rx_over_errors += adapter->irx_pcb.data.netstat.err_res; 781 dev->stats.rx_over_errors += adapter->irx_pcb.data.netstat.err_res;
782 adapter->got[CMD_NETWORK_STATISTICS] = 1; 782 adapter->got[CMD_NETWORK_STATISTICS] = 1;
783 if (elp_debug >= 3) 783 if (elp_debug >= 3)
784 printk(KERN_DEBUG "%s: interrupt - statistics response received\n", dev->name); 784 printk(KERN_DEBUG "%s: interrupt - statistics response received\n", dev->name);
@@ -794,11 +794,11 @@ static irqreturn_t elp_interrupt(int irq, void *dev_id)
794 break; 794 break;
795 switch (adapter->irx_pcb.data.xmit_resp.c_stat) { 795 switch (adapter->irx_pcb.data.xmit_resp.c_stat) {
796 case 0xffff: 796 case 0xffff:
797 adapter->stats.tx_aborted_errors++; 797 dev->stats.tx_aborted_errors++;
798 printk(KERN_INFO "%s: transmit timed out, network cable problem?\n", dev->name); 798 printk(KERN_INFO "%s: transmit timed out, network cable problem?\n", dev->name);
799 break; 799 break;
800 case 0xfffe: 800 case 0xfffe:
801 adapter->stats.tx_fifo_errors++; 801 dev->stats.tx_fifo_errors++;
802 printk(KERN_INFO "%s: transmit timed out, FIFO underrun\n", dev->name); 802 printk(KERN_INFO "%s: transmit timed out, FIFO underrun\n", dev->name);
803 break; 803 break;
804 } 804 }
@@ -986,7 +986,7 @@ static bool send_packet(struct net_device *dev, struct sk_buff *skb)
986 return false; 986 return false;
987 } 987 }
988 988
989 adapter->stats.tx_bytes += nlen; 989 dev->stats.tx_bytes += nlen;
990 990
991 /* 991 /*
992 * send the adapter a transmit packet command. Ignore segment and offset 992 * send the adapter a transmit packet command. Ignore segment and offset
@@ -1041,7 +1041,6 @@ static bool send_packet(struct net_device *dev, struct sk_buff *skb)
1041 1041
1042static void elp_timeout(struct net_device *dev) 1042static void elp_timeout(struct net_device *dev)
1043{ 1043{
1044 elp_device *adapter = dev->priv;
1045 int stat; 1044 int stat;
1046 1045
1047 stat = inb_status(dev->base_addr); 1046 stat = inb_status(dev->base_addr);
@@ -1049,7 +1048,7 @@ static void elp_timeout(struct net_device *dev)
1049 if (elp_debug >= 1) 1048 if (elp_debug >= 1)
1050 printk(KERN_DEBUG "%s: status %#02x\n", dev->name, stat); 1049 printk(KERN_DEBUG "%s: status %#02x\n", dev->name, stat);
1051 dev->trans_start = jiffies; 1050 dev->trans_start = jiffies;
1052 adapter->stats.tx_dropped++; 1051 dev->stats.tx_dropped++;
1053 netif_wake_queue(dev); 1052 netif_wake_queue(dev);
1054} 1053}
1055 1054
@@ -1113,7 +1112,7 @@ static struct net_device_stats *elp_get_stats(struct net_device *dev)
1113 /* If the device is closed, just return the latest stats we have, 1112 /* If the device is closed, just return the latest stats we have,
1114 - we cannot ask from the adapter without interrupts */ 1113 - we cannot ask from the adapter without interrupts */
1115 if (!netif_running(dev)) 1114 if (!netif_running(dev))
1116 return &adapter->stats; 1115 return &dev->stats;
1117 1116
1118 /* send a get statistics command to the board */ 1117 /* send a get statistics command to the board */
1119 adapter->tx_pcb.command = CMD_NETWORK_STATISTICS; 1118 adapter->tx_pcb.command = CMD_NETWORK_STATISTICS;
@@ -1126,12 +1125,12 @@ static struct net_device_stats *elp_get_stats(struct net_device *dev)
1126 while (adapter->got[CMD_NETWORK_STATISTICS] == 0 && time_before(jiffies, timeout)); 1125 while (adapter->got[CMD_NETWORK_STATISTICS] == 0 && time_before(jiffies, timeout));
1127 if (time_after_eq(jiffies, timeout)) { 1126 if (time_after_eq(jiffies, timeout)) {
1128 TIMEOUT_MSG(__LINE__); 1127 TIMEOUT_MSG(__LINE__);
1129 return &adapter->stats; 1128 return &dev->stats;
1130 } 1129 }
1131 } 1130 }
1132 1131
1133 /* statistics are now up to date */ 1132 /* statistics are now up to date */
1134 return &adapter->stats; 1133 return &dev->stats;
1135} 1134}
1136 1135
1137 1136
@@ -1571,7 +1570,6 @@ static int __init elplus_setup(struct net_device *dev)
1571 dev->set_multicast_list = elp_set_mc_list; /* local */ 1570 dev->set_multicast_list = elp_set_mc_list; /* local */
1572 dev->ethtool_ops = &netdev_ethtool_ops; /* local */ 1571 dev->ethtool_ops = &netdev_ethtool_ops; /* local */
1573 1572
1574 memset(&(adapter->stats), 0, sizeof(struct net_device_stats));
1575 dev->mem_start = dev->mem_end = 0; 1573 dev->mem_start = dev->mem_end = 0;
1576 1574
1577 err = register_netdev(dev); 1575 err = register_netdev(dev);
diff --git a/drivers/net/3c505.h b/drivers/net/3c505.h
index 1910cb1dc787..04df2a9002b6 100644
--- a/drivers/net/3c505.h
+++ b/drivers/net/3c505.h
@@ -264,7 +264,6 @@ typedef struct {
264 pcb_struct rx_pcb; /* PCB for foreground receiving */ 264 pcb_struct rx_pcb; /* PCB for foreground receiving */
265 pcb_struct itx_pcb; /* PCB for background sending */ 265 pcb_struct itx_pcb; /* PCB for background sending */
266 pcb_struct irx_pcb; /* PCB for background receiving */ 266 pcb_struct irx_pcb; /* PCB for background receiving */
267 struct net_device_stats stats;
268 267
269 void *dma_buffer; 268 void *dma_buffer;
270 269
diff --git a/drivers/net/3c509.c b/drivers/net/3c509.c
index 54dac0696d91..e6c545fe5f58 100644
--- a/drivers/net/3c509.c
+++ b/drivers/net/3c509.c
@@ -167,7 +167,6 @@ enum RxFilter {
167enum el3_cardtype { EL3_ISA, EL3_PNP, EL3_MCA, EL3_EISA }; 167enum el3_cardtype { EL3_ISA, EL3_PNP, EL3_MCA, EL3_EISA };
168 168
169struct el3_private { 169struct el3_private {
170 struct net_device_stats stats;
171 spinlock_t lock; 170 spinlock_t lock;
172 /* skb send-queue */ 171 /* skb send-queue */
173 int head, size; 172 int head, size;
@@ -794,7 +793,6 @@ el3_open(struct net_device *dev)
794static void 793static void
795el3_tx_timeout (struct net_device *dev) 794el3_tx_timeout (struct net_device *dev)
796{ 795{
797 struct el3_private *lp = netdev_priv(dev);
798 int ioaddr = dev->base_addr; 796 int ioaddr = dev->base_addr;
799 797
800 /* Transmitter timeout, serious problems. */ 798 /* Transmitter timeout, serious problems. */
@@ -802,7 +800,7 @@ el3_tx_timeout (struct net_device *dev)
802 "Tx FIFO room %d.\n", 800 "Tx FIFO room %d.\n",
803 dev->name, inb(ioaddr + TX_STATUS), inw(ioaddr + EL3_STATUS), 801 dev->name, inb(ioaddr + TX_STATUS), inw(ioaddr + EL3_STATUS),
804 inw(ioaddr + TX_FREE)); 802 inw(ioaddr + TX_FREE));
805 lp->stats.tx_errors++; 803 dev->stats.tx_errors++;
806 dev->trans_start = jiffies; 804 dev->trans_start = jiffies;
807 /* Issue TX_RESET and TX_START commands. */ 805 /* Issue TX_RESET and TX_START commands. */
808 outw(TxReset, ioaddr + EL3_CMD); 806 outw(TxReset, ioaddr + EL3_CMD);
@@ -820,7 +818,7 @@ el3_start_xmit(struct sk_buff *skb, struct net_device *dev)
820 818
821 netif_stop_queue (dev); 819 netif_stop_queue (dev);
822 820
823 lp->stats.tx_bytes += skb->len; 821 dev->stats.tx_bytes += skb->len;
824 822
825 if (el3_debug > 4) { 823 if (el3_debug > 4) {
826 printk(KERN_DEBUG "%s: el3_start_xmit(length = %u) called, status %4.4x.\n", 824 printk(KERN_DEBUG "%s: el3_start_xmit(length = %u) called, status %4.4x.\n",
@@ -881,7 +879,7 @@ el3_start_xmit(struct sk_buff *skb, struct net_device *dev)
881 int i = 4; 879 int i = 4;
882 880
883 while (--i > 0 && (tx_status = inb(ioaddr + TX_STATUS)) > 0) { 881 while (--i > 0 && (tx_status = inb(ioaddr + TX_STATUS)) > 0) {
884 if (tx_status & 0x38) lp->stats.tx_aborted_errors++; 882 if (tx_status & 0x38) dev->stats.tx_aborted_errors++;
885 if (tx_status & 0x30) outw(TxReset, ioaddr + EL3_CMD); 883 if (tx_status & 0x30) outw(TxReset, ioaddr + EL3_CMD);
886 if (tx_status & 0x3C) outw(TxEnable, ioaddr + EL3_CMD); 884 if (tx_status & 0x3C) outw(TxEnable, ioaddr + EL3_CMD);
887 outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */ 885 outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */
@@ -931,12 +929,11 @@ el3_interrupt(int irq, void *dev_id)
931 outw(AckIntr | RxEarly, ioaddr + EL3_CMD); 929 outw(AckIntr | RxEarly, ioaddr + EL3_CMD);
932 } 930 }
933 if (status & TxComplete) { /* Really Tx error. */ 931 if (status & TxComplete) { /* Really Tx error. */
934 struct el3_private *lp = netdev_priv(dev);
935 short tx_status; 932 short tx_status;
936 int i = 4; 933 int i = 4;
937 934
938 while (--i>0 && (tx_status = inb(ioaddr + TX_STATUS)) > 0) { 935 while (--i>0 && (tx_status = inb(ioaddr + TX_STATUS)) > 0) {
939 if (tx_status & 0x38) lp->stats.tx_aborted_errors++; 936 if (tx_status & 0x38) dev->stats.tx_aborted_errors++;
940 if (tx_status & 0x30) outw(TxReset, ioaddr + EL3_CMD); 937 if (tx_status & 0x30) outw(TxReset, ioaddr + EL3_CMD);
941 if (tx_status & 0x3C) outw(TxEnable, ioaddr + EL3_CMD); 938 if (tx_status & 0x3C) outw(TxEnable, ioaddr + EL3_CMD);
942 outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */ 939 outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */
@@ -1002,7 +999,7 @@ el3_get_stats(struct net_device *dev)
1002 spin_lock_irqsave(&lp->lock, flags); 999 spin_lock_irqsave(&lp->lock, flags);
1003 update_stats(dev); 1000 update_stats(dev);
1004 spin_unlock_irqrestore(&lp->lock, flags); 1001 spin_unlock_irqrestore(&lp->lock, flags);
1005 return &lp->stats; 1002 return &dev->stats;
1006} 1003}
1007 1004
1008/* Update statistics. We change to register window 6, so this should be run 1005/* Update statistics. We change to register window 6, so this should be run
@@ -1012,7 +1009,6 @@ el3_get_stats(struct net_device *dev)
1012 */ 1009 */
1013static void update_stats(struct net_device *dev) 1010static void update_stats(struct net_device *dev)
1014{ 1011{
1015 struct el3_private *lp = netdev_priv(dev);
1016 int ioaddr = dev->base_addr; 1012 int ioaddr = dev->base_addr;
1017 1013
1018 if (el3_debug > 5) 1014 if (el3_debug > 5)
@@ -1021,13 +1017,13 @@ static void update_stats(struct net_device *dev)
1021 outw(StatsDisable, ioaddr + EL3_CMD); 1017 outw(StatsDisable, ioaddr + EL3_CMD);
1022 /* Switch to the stats window, and read everything. */ 1018 /* Switch to the stats window, and read everything. */
1023 EL3WINDOW(6); 1019 EL3WINDOW(6);
1024 lp->stats.tx_carrier_errors += inb(ioaddr + 0); 1020 dev->stats.tx_carrier_errors += inb(ioaddr + 0);
1025 lp->stats.tx_heartbeat_errors += inb(ioaddr + 1); 1021 dev->stats.tx_heartbeat_errors += inb(ioaddr + 1);
1026 /* Multiple collisions. */ inb(ioaddr + 2); 1022 /* Multiple collisions. */ inb(ioaddr + 2);
1027 lp->stats.collisions += inb(ioaddr + 3); 1023 dev->stats.collisions += inb(ioaddr + 3);
1028 lp->stats.tx_window_errors += inb(ioaddr + 4); 1024 dev->stats.tx_window_errors += inb(ioaddr + 4);
1029 lp->stats.rx_fifo_errors += inb(ioaddr + 5); 1025 dev->stats.rx_fifo_errors += inb(ioaddr + 5);
1030 lp->stats.tx_packets += inb(ioaddr + 6); 1026 dev->stats.tx_packets += inb(ioaddr + 6);
1031 /* Rx packets */ inb(ioaddr + 7); 1027 /* Rx packets */ inb(ioaddr + 7);
1032 /* Tx deferrals */ inb(ioaddr + 8); 1028 /* Tx deferrals */ inb(ioaddr + 8);
1033 inw(ioaddr + 10); /* Total Rx and Tx octets. */ 1029 inw(ioaddr + 10); /* Total Rx and Tx octets. */
@@ -1042,7 +1038,6 @@ static void update_stats(struct net_device *dev)
1042static int 1038static int
1043el3_rx(struct net_device *dev) 1039el3_rx(struct net_device *dev)
1044{ 1040{
1045 struct el3_private *lp = netdev_priv(dev);
1046 int ioaddr = dev->base_addr; 1041 int ioaddr = dev->base_addr;
1047 short rx_status; 1042 short rx_status;
1048 1043
@@ -1054,21 +1049,21 @@ el3_rx(struct net_device *dev)
1054 short error = rx_status & 0x3800; 1049 short error = rx_status & 0x3800;
1055 1050
1056 outw(RxDiscard, ioaddr + EL3_CMD); 1051 outw(RxDiscard, ioaddr + EL3_CMD);
1057 lp->stats.rx_errors++; 1052 dev->stats.rx_errors++;
1058 switch (error) { 1053 switch (error) {
1059 case 0x0000: lp->stats.rx_over_errors++; break; 1054 case 0x0000: dev->stats.rx_over_errors++; break;
1060 case 0x0800: lp->stats.rx_length_errors++; break; 1055 case 0x0800: dev->stats.rx_length_errors++; break;
1061 case 0x1000: lp->stats.rx_frame_errors++; break; 1056 case 0x1000: dev->stats.rx_frame_errors++; break;
1062 case 0x1800: lp->stats.rx_length_errors++; break; 1057 case 0x1800: dev->stats.rx_length_errors++; break;
1063 case 0x2000: lp->stats.rx_frame_errors++; break; 1058 case 0x2000: dev->stats.rx_frame_errors++; break;
1064 case 0x2800: lp->stats.rx_crc_errors++; break; 1059 case 0x2800: dev->stats.rx_crc_errors++; break;
1065 } 1060 }
1066 } else { 1061 } else {
1067 short pkt_len = rx_status & 0x7ff; 1062 short pkt_len = rx_status & 0x7ff;
1068 struct sk_buff *skb; 1063 struct sk_buff *skb;
1069 1064
1070 skb = dev_alloc_skb(pkt_len+5); 1065 skb = dev_alloc_skb(pkt_len+5);
1071 lp->stats.rx_bytes += pkt_len; 1066 dev->stats.rx_bytes += pkt_len;
1072 if (el3_debug > 4) 1067 if (el3_debug > 4)
1073 printk("Receiving packet size %d status %4.4x.\n", 1068 printk("Receiving packet size %d status %4.4x.\n",
1074 pkt_len, rx_status); 1069 pkt_len, rx_status);
@@ -1083,11 +1078,11 @@ el3_rx(struct net_device *dev)
1083 skb->protocol = eth_type_trans(skb,dev); 1078 skb->protocol = eth_type_trans(skb,dev);
1084 netif_rx(skb); 1079 netif_rx(skb);
1085 dev->last_rx = jiffies; 1080 dev->last_rx = jiffies;
1086 lp->stats.rx_packets++; 1081 dev->stats.rx_packets++;
1087 continue; 1082 continue;
1088 } 1083 }
1089 outw(RxDiscard, ioaddr + EL3_CMD); 1084 outw(RxDiscard, ioaddr + EL3_CMD);
1090 lp->stats.rx_dropped++; 1085 dev->stats.rx_dropped++;
1091 if (el3_debug) 1086 if (el3_debug)
1092 printk("%s: Couldn't allocate a sk_buff of size %d.\n", 1087 printk("%s: Couldn't allocate a sk_buff of size %d.\n",
1093 dev->name, pkt_len); 1088 dev->name, pkt_len);
diff --git a/drivers/net/3c515.c b/drivers/net/3c515.c
index 6ab84b661d70..105a8c7ca7e9 100644
--- a/drivers/net/3c515.c
+++ b/drivers/net/3c515.c
@@ -310,7 +310,6 @@ struct corkscrew_private {
310 struct sk_buff *tx_skbuff[TX_RING_SIZE]; 310 struct sk_buff *tx_skbuff[TX_RING_SIZE];
311 unsigned int cur_rx, cur_tx; /* The next free ring entry */ 311 unsigned int cur_rx, cur_tx; /* The next free ring entry */
312 unsigned int dirty_rx, dirty_tx;/* The ring entries to be free()ed. */ 312 unsigned int dirty_rx, dirty_tx;/* The ring entries to be free()ed. */
313 struct net_device_stats stats;
314 struct sk_buff *tx_skb; /* Packet being eaten by bus master ctrl. */ 313 struct sk_buff *tx_skb; /* Packet being eaten by bus master ctrl. */
315 struct timer_list timer; /* Media selection timer. */ 314 struct timer_list timer; /* Media selection timer. */
316 int capabilities ; /* Adapter capabilities word. */ 315 int capabilities ; /* Adapter capabilities word. */
@@ -983,8 +982,8 @@ static void corkscrew_timeout(struct net_device *dev)
983 break; 982 break;
984 outw(TxEnable, ioaddr + EL3_CMD); 983 outw(TxEnable, ioaddr + EL3_CMD);
985 dev->trans_start = jiffies; 984 dev->trans_start = jiffies;
986 vp->stats.tx_errors++; 985 dev->stats.tx_errors++;
987 vp->stats.tx_dropped++; 986 dev->stats.tx_dropped++;
988 netif_wake_queue(dev); 987 netif_wake_queue(dev);
989} 988}
990 989
@@ -1050,7 +1049,7 @@ static int corkscrew_start_xmit(struct sk_buff *skb,
1050 } 1049 }
1051 /* Put out the doubleword header... */ 1050 /* Put out the doubleword header... */
1052 outl(skb->len, ioaddr + TX_FIFO); 1051 outl(skb->len, ioaddr + TX_FIFO);
1053 vp->stats.tx_bytes += skb->len; 1052 dev->stats.tx_bytes += skb->len;
1054#ifdef VORTEX_BUS_MASTER 1053#ifdef VORTEX_BUS_MASTER
1055 if (vp->bus_master) { 1054 if (vp->bus_master) {
1056 /* Set the bus-master controller to transfer the packet. */ 1055 /* Set the bus-master controller to transfer the packet. */
@@ -1094,9 +1093,9 @@ static int corkscrew_start_xmit(struct sk_buff *skb,
1094 printk("%s: Tx error, status %2.2x.\n", 1093 printk("%s: Tx error, status %2.2x.\n",
1095 dev->name, tx_status); 1094 dev->name, tx_status);
1096 if (tx_status & 0x04) 1095 if (tx_status & 0x04)
1097 vp->stats.tx_fifo_errors++; 1096 dev->stats.tx_fifo_errors++;
1098 if (tx_status & 0x38) 1097 if (tx_status & 0x38)
1099 vp->stats.tx_aborted_errors++; 1098 dev->stats.tx_aborted_errors++;
1100 if (tx_status & 0x30) { 1099 if (tx_status & 0x30) {
1101 int j; 1100 int j;
1102 outw(TxReset, ioaddr + EL3_CMD); 1101 outw(TxReset, ioaddr + EL3_CMD);
@@ -1257,7 +1256,6 @@ static irqreturn_t corkscrew_interrupt(int irq, void *dev_id)
1257 1256
1258static int corkscrew_rx(struct net_device *dev) 1257static int corkscrew_rx(struct net_device *dev)
1259{ 1258{
1260 struct corkscrew_private *vp = netdev_priv(dev);
1261 int ioaddr = dev->base_addr; 1259 int ioaddr = dev->base_addr;
1262 int i; 1260 int i;
1263 short rx_status; 1261 short rx_status;
@@ -1271,17 +1269,17 @@ static int corkscrew_rx(struct net_device *dev)
1271 if (corkscrew_debug > 2) 1269 if (corkscrew_debug > 2)
1272 printk(" Rx error: status %2.2x.\n", 1270 printk(" Rx error: status %2.2x.\n",
1273 rx_error); 1271 rx_error);
1274 vp->stats.rx_errors++; 1272 dev->stats.rx_errors++;
1275 if (rx_error & 0x01) 1273 if (rx_error & 0x01)
1276 vp->stats.rx_over_errors++; 1274 dev->stats.rx_over_errors++;
1277 if (rx_error & 0x02) 1275 if (rx_error & 0x02)
1278 vp->stats.rx_length_errors++; 1276 dev->stats.rx_length_errors++;
1279 if (rx_error & 0x04) 1277 if (rx_error & 0x04)
1280 vp->stats.rx_frame_errors++; 1278 dev->stats.rx_frame_errors++;
1281 if (rx_error & 0x08) 1279 if (rx_error & 0x08)
1282 vp->stats.rx_crc_errors++; 1280 dev->stats.rx_crc_errors++;
1283 if (rx_error & 0x10) 1281 if (rx_error & 0x10)
1284 vp->stats.rx_length_errors++; 1282 dev->stats.rx_length_errors++;
1285 } else { 1283 } else {
1286 /* The packet length: up to 4.5K!. */ 1284 /* The packet length: up to 4.5K!. */
1287 short pkt_len = rx_status & 0x1fff; 1285 short pkt_len = rx_status & 0x1fff;
@@ -1301,8 +1299,8 @@ static int corkscrew_rx(struct net_device *dev)
1301 skb->protocol = eth_type_trans(skb, dev); 1299 skb->protocol = eth_type_trans(skb, dev);
1302 netif_rx(skb); 1300 netif_rx(skb);
1303 dev->last_rx = jiffies; 1301 dev->last_rx = jiffies;
1304 vp->stats.rx_packets++; 1302 dev->stats.rx_packets++;
1305 vp->stats.rx_bytes += pkt_len; 1303 dev->stats.rx_bytes += pkt_len;
1306 /* Wait a limited time to go to next packet. */ 1304 /* Wait a limited time to go to next packet. */
1307 for (i = 200; i >= 0; i--) 1305 for (i = 200; i >= 0; i--)
1308 if (! (inw(ioaddr + EL3_STATUS) & CmdInProgress)) 1306 if (! (inw(ioaddr + EL3_STATUS) & CmdInProgress))
@@ -1312,7 +1310,7 @@ static int corkscrew_rx(struct net_device *dev)
1312 printk("%s: Couldn't allocate a sk_buff of size %d.\n", dev->name, pkt_len); 1310 printk("%s: Couldn't allocate a sk_buff of size %d.\n", dev->name, pkt_len);
1313 } 1311 }
1314 outw(RxDiscard, ioaddr + EL3_CMD); 1312 outw(RxDiscard, ioaddr + EL3_CMD);
1315 vp->stats.rx_dropped++; 1313 dev->stats.rx_dropped++;
1316 /* Wait a limited time to skip this packet. */ 1314 /* Wait a limited time to skip this packet. */
1317 for (i = 200; i >= 0; i--) 1315 for (i = 200; i >= 0; i--)
1318 if (!(inw(ioaddr + EL3_STATUS) & CmdInProgress)) 1316 if (!(inw(ioaddr + EL3_STATUS) & CmdInProgress))
@@ -1337,23 +1335,23 @@ static int boomerang_rx(struct net_device *dev)
1337 if (corkscrew_debug > 2) 1335 if (corkscrew_debug > 2)
1338 printk(" Rx error: status %2.2x.\n", 1336 printk(" Rx error: status %2.2x.\n",
1339 rx_error); 1337 rx_error);
1340 vp->stats.rx_errors++; 1338 dev->stats.rx_errors++;
1341 if (rx_error & 0x01) 1339 if (rx_error & 0x01)
1342 vp->stats.rx_over_errors++; 1340 dev->stats.rx_over_errors++;
1343 if (rx_error & 0x02) 1341 if (rx_error & 0x02)
1344 vp->stats.rx_length_errors++; 1342 dev->stats.rx_length_errors++;
1345 if (rx_error & 0x04) 1343 if (rx_error & 0x04)
1346 vp->stats.rx_frame_errors++; 1344 dev->stats.rx_frame_errors++;
1347 if (rx_error & 0x08) 1345 if (rx_error & 0x08)
1348 vp->stats.rx_crc_errors++; 1346 dev->stats.rx_crc_errors++;
1349 if (rx_error & 0x10) 1347 if (rx_error & 0x10)
1350 vp->stats.rx_length_errors++; 1348 dev->stats.rx_length_errors++;
1351 } else { 1349 } else {
1352 /* The packet length: up to 4.5K!. */ 1350 /* The packet length: up to 4.5K!. */
1353 short pkt_len = rx_status & 0x1fff; 1351 short pkt_len = rx_status & 0x1fff;
1354 struct sk_buff *skb; 1352 struct sk_buff *skb;
1355 1353
1356 vp->stats.rx_bytes += pkt_len; 1354 dev->stats.rx_bytes += pkt_len;
1357 if (corkscrew_debug > 4) 1355 if (corkscrew_debug > 4)
1358 printk("Receiving packet size %d status %4.4x.\n", 1356 printk("Receiving packet size %d status %4.4x.\n",
1359 pkt_len, rx_status); 1357 pkt_len, rx_status);
@@ -1388,7 +1386,7 @@ static int boomerang_rx(struct net_device *dev)
1388 skb->protocol = eth_type_trans(skb, dev); 1386 skb->protocol = eth_type_trans(skb, dev);
1389 netif_rx(skb); 1387 netif_rx(skb);
1390 dev->last_rx = jiffies; 1388 dev->last_rx = jiffies;
1391 vp->stats.rx_packets++; 1389 dev->stats.rx_packets++;
1392 } 1390 }
1393 entry = (++vp->cur_rx) % RX_RING_SIZE; 1391 entry = (++vp->cur_rx) % RX_RING_SIZE;
1394 } 1392 }
@@ -1475,7 +1473,7 @@ static struct net_device_stats *corkscrew_get_stats(struct net_device *dev)
1475 update_stats(dev->base_addr, dev); 1473 update_stats(dev->base_addr, dev);
1476 spin_unlock_irqrestore(&vp->lock, flags); 1474 spin_unlock_irqrestore(&vp->lock, flags);
1477 } 1475 }
1478 return &vp->stats; 1476 return &dev->stats;
1479} 1477}
1480 1478
1481/* Update statistics. 1479/* Update statistics.
@@ -1487,19 +1485,17 @@ static struct net_device_stats *corkscrew_get_stats(struct net_device *dev)
1487 */ 1485 */
1488static void update_stats(int ioaddr, struct net_device *dev) 1486static void update_stats(int ioaddr, struct net_device *dev)
1489{ 1487{
1490 struct corkscrew_private *vp = netdev_priv(dev);
1491
1492 /* Unlike the 3c5x9 we need not turn off stats updates while reading. */ 1488 /* Unlike the 3c5x9 we need not turn off stats updates while reading. */
1493 /* Switch to the stats window, and read everything. */ 1489 /* Switch to the stats window, and read everything. */
1494 EL3WINDOW(6); 1490 EL3WINDOW(6);
1495 vp->stats.tx_carrier_errors += inb(ioaddr + 0); 1491 dev->stats.tx_carrier_errors += inb(ioaddr + 0);
1496 vp->stats.tx_heartbeat_errors += inb(ioaddr + 1); 1492 dev->stats.tx_heartbeat_errors += inb(ioaddr + 1);
1497 /* Multiple collisions. */ inb(ioaddr + 2); 1493 /* Multiple collisions. */ inb(ioaddr + 2);
1498 vp->stats.collisions += inb(ioaddr + 3); 1494 dev->stats.collisions += inb(ioaddr + 3);
1499 vp->stats.tx_window_errors += inb(ioaddr + 4); 1495 dev->stats.tx_window_errors += inb(ioaddr + 4);
1500 vp->stats.rx_fifo_errors += inb(ioaddr + 5); 1496 dev->stats.rx_fifo_errors += inb(ioaddr + 5);
1501 vp->stats.tx_packets += inb(ioaddr + 6); 1497 dev->stats.tx_packets += inb(ioaddr + 6);
1502 vp->stats.tx_packets += (inb(ioaddr + 9) & 0x30) << 4; 1498 dev->stats.tx_packets += (inb(ioaddr + 9) & 0x30) << 4;
1503 /* Rx packets */ inb(ioaddr + 7); 1499 /* Rx packets */ inb(ioaddr + 7);
1504 /* Must read to clear */ 1500 /* Must read to clear */
1505 /* Tx deferrals */ inb(ioaddr + 8); 1501 /* Tx deferrals */ inb(ioaddr + 8);
diff --git a/drivers/net/8390.c b/drivers/net/8390.c
index a499e867f0f4..dc5d2584bd0c 100644
--- a/drivers/net/8390.c
+++ b/drivers/net/8390.c
@@ -34,7 +34,7 @@ struct net_device *__alloc_ei_netdev(int size)
34 34
35void NS8390_init(struct net_device *dev, int startp) 35void NS8390_init(struct net_device *dev, int startp)
36{ 36{
37 return __NS8390_init(dev, startp); 37 __NS8390_init(dev, startp);
38} 38}
39 39
40EXPORT_SYMBOL(ei_open); 40EXPORT_SYMBOL(ei_open);
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index f90a86ba7e2f..af46341827f2 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -2593,6 +2593,7 @@ config BNX2X
2593 To compile this driver as a module, choose M here: the module 2593 To compile this driver as a module, choose M here: the module
2594 will be called bnx2x. This is recommended. 2594 will be called bnx2x. This is recommended.
2595 2595
2596source "drivers/net/sfc/Kconfig"
2596 2597
2597endif # NETDEV_10000 2598endif # NETDEV_10000
2598 2599
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index 2f1f3f2739fd..dcbfe8421154 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -253,3 +253,5 @@ obj-$(CONFIG_FS_ENET) += fs_enet/
253obj-$(CONFIG_NETXEN_NIC) += netxen/ 253obj-$(CONFIG_NETXEN_NIC) += netxen/
254obj-$(CONFIG_NIU) += niu.o 254obj-$(CONFIG_NIU) += niu.o
255obj-$(CONFIG_VIRTIO_NET) += virtio_net.o 255obj-$(CONFIG_VIRTIO_NET) += virtio_net.o
256obj-$(CONFIG_SFC) += sfc/
257
diff --git a/drivers/net/arm/Kconfig b/drivers/net/arm/Kconfig
index f9cc2b621fe2..8eda6eeb43b7 100644
--- a/drivers/net/arm/Kconfig
+++ b/drivers/net/arm/Kconfig
@@ -47,3 +47,11 @@ config EP93XX_ETH
47 help 47 help
48 This is a driver for the ethernet hardware included in EP93xx CPUs. 48 This is a driver for the ethernet hardware included in EP93xx CPUs.
49 Say Y if you are building a kernel for EP93xx based devices. 49 Say Y if you are building a kernel for EP93xx based devices.
50
51config IXP4XX_ETH
52 tristate "Intel IXP4xx Ethernet support"
53 depends on ARM && ARCH_IXP4XX && IXP4XX_NPE && IXP4XX_QMGR
54 select MII
55 help
56 Say Y here if you want to use built-in Ethernet ports
57 on IXP4xx processor.
diff --git a/drivers/net/arm/Makefile b/drivers/net/arm/Makefile
index a4c868278e11..7c812ac2b6a5 100644
--- a/drivers/net/arm/Makefile
+++ b/drivers/net/arm/Makefile
@@ -9,3 +9,4 @@ obj-$(CONFIG_ARM_ETHER3) += ether3.o
9obj-$(CONFIG_ARM_ETHER1) += ether1.o 9obj-$(CONFIG_ARM_ETHER1) += ether1.o
10obj-$(CONFIG_ARM_AT91_ETHER) += at91_ether.o 10obj-$(CONFIG_ARM_AT91_ETHER) += at91_ether.o
11obj-$(CONFIG_EP93XX_ETH) += ep93xx_eth.o 11obj-$(CONFIG_EP93XX_ETH) += ep93xx_eth.o
12obj-$(CONFIG_IXP4XX_ETH) += ixp4xx_eth.o
diff --git a/drivers/net/arm/ixp4xx_eth.c b/drivers/net/arm/ixp4xx_eth.c
new file mode 100644
index 000000000000..c617b64c288e
--- /dev/null
+++ b/drivers/net/arm/ixp4xx_eth.c
@@ -0,0 +1,1265 @@
1/*
2 * Intel IXP4xx Ethernet driver for Linux
3 *
4 * Copyright (C) 2007 Krzysztof Halasa <khc@pm.waw.pl>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License
8 * as published by the Free Software Foundation.
9 *
10 * Ethernet port config (0x00 is not present on IXP42X):
11 *
12 * logical port 0x00 0x10 0x20
13 * NPE 0 (NPE-A) 1 (NPE-B) 2 (NPE-C)
14 * physical PortId 2 0 1
15 * TX queue 23 24 25
16 * RX-free queue 26 27 28
17 * TX-done queue is always 31, per-port RX and TX-ready queues are configurable
18 *
19 *
20 * Queue entries:
21 * bits 0 -> 1 - NPE ID (RX and TX-done)
22 * bits 0 -> 2 - priority (TX, per 802.1D)
23 * bits 3 -> 4 - port ID (user-set?)
24 * bits 5 -> 31 - physical descriptor address
25 */
26
27#include <linux/delay.h>
28#include <linux/dma-mapping.h>
29#include <linux/dmapool.h>
30#include <linux/etherdevice.h>
31#include <linux/io.h>
32#include <linux/kernel.h>
33#include <linux/mii.h>
34#include <linux/platform_device.h>
35#include <asm/arch/npe.h>
36#include <asm/arch/qmgr.h>
37
38#define DEBUG_QUEUES 0
39#define DEBUG_DESC 0
40#define DEBUG_RX 0
41#define DEBUG_TX 0
42#define DEBUG_PKT_BYTES 0
43#define DEBUG_MDIO 0
44#define DEBUG_CLOSE 0
45
46#define DRV_NAME "ixp4xx_eth"
47
48#define MAX_NPES 3
49
50#define RX_DESCS 64 /* also length of all RX queues */
51#define TX_DESCS 16 /* also length of all TX queues */
52#define TXDONE_QUEUE_LEN 64 /* dwords */
53
54#define POOL_ALLOC_SIZE (sizeof(struct desc) * (RX_DESCS + TX_DESCS))
55#define REGS_SIZE 0x1000
56#define MAX_MRU 1536 /* 0x600 */
57#define RX_BUFF_SIZE ALIGN((NET_IP_ALIGN) + MAX_MRU, 4)
58
59#define NAPI_WEIGHT 16
60#define MDIO_INTERVAL (3 * HZ)
61#define MAX_MDIO_RETRIES 100 /* microseconds, typically 30 cycles */
62#define MAX_MII_RESET_RETRIES 100 /* mdio_read() cycles, typically 4 */
63#define MAX_CLOSE_WAIT 1000 /* microseconds, typically 2-3 cycles */
64
65#define NPE_ID(port_id) ((port_id) >> 4)
66#define PHYSICAL_ID(port_id) ((NPE_ID(port_id) + 2) % 3)
67#define TX_QUEUE(port_id) (NPE_ID(port_id) + 23)
68#define RXFREE_QUEUE(port_id) (NPE_ID(port_id) + 26)
69#define TXDONE_QUEUE 31
70
71/* TX Control Registers */
72#define TX_CNTRL0_TX_EN 0x01
73#define TX_CNTRL0_HALFDUPLEX 0x02
74#define TX_CNTRL0_RETRY 0x04
75#define TX_CNTRL0_PAD_EN 0x08
76#define TX_CNTRL0_APPEND_FCS 0x10
77#define TX_CNTRL0_2DEFER 0x20
78#define TX_CNTRL0_RMII 0x40 /* reduced MII */
79#define TX_CNTRL1_RETRIES 0x0F /* 4 bits */
80
81/* RX Control Registers */
82#define RX_CNTRL0_RX_EN 0x01
83#define RX_CNTRL0_PADSTRIP_EN 0x02
84#define RX_CNTRL0_SEND_FCS 0x04
85#define RX_CNTRL0_PAUSE_EN 0x08
86#define RX_CNTRL0_LOOP_EN 0x10
87#define RX_CNTRL0_ADDR_FLTR_EN 0x20
88#define RX_CNTRL0_RX_RUNT_EN 0x40
89#define RX_CNTRL0_BCAST_DIS 0x80
90#define RX_CNTRL1_DEFER_EN 0x01
91
92/* Core Control Register */
93#define CORE_RESET 0x01
94#define CORE_RX_FIFO_FLUSH 0x02
95#define CORE_TX_FIFO_FLUSH 0x04
96#define CORE_SEND_JAM 0x08
97#define CORE_MDC_EN 0x10 /* MDIO using NPE-B ETH-0 only */
98
99#define DEFAULT_TX_CNTRL0 (TX_CNTRL0_TX_EN | TX_CNTRL0_RETRY | \
100 TX_CNTRL0_PAD_EN | TX_CNTRL0_APPEND_FCS | \
101 TX_CNTRL0_2DEFER)
102#define DEFAULT_RX_CNTRL0 RX_CNTRL0_RX_EN
103#define DEFAULT_CORE_CNTRL CORE_MDC_EN
104
105
106/* NPE message codes */
107#define NPE_GETSTATUS 0x00
108#define NPE_EDB_SETPORTADDRESS 0x01
109#define NPE_EDB_GETMACADDRESSDATABASE 0x02
110#define NPE_EDB_SETMACADDRESSSDATABASE 0x03
111#define NPE_GETSTATS 0x04
112#define NPE_RESETSTATS 0x05
113#define NPE_SETMAXFRAMELENGTHS 0x06
114#define NPE_VLAN_SETRXTAGMODE 0x07
115#define NPE_VLAN_SETDEFAULTRXVID 0x08
116#define NPE_VLAN_SETPORTVLANTABLEENTRY 0x09
117#define NPE_VLAN_SETPORTVLANTABLERANGE 0x0A
118#define NPE_VLAN_SETRXQOSENTRY 0x0B
119#define NPE_VLAN_SETPORTIDEXTRACTIONMODE 0x0C
120#define NPE_STP_SETBLOCKINGSTATE 0x0D
121#define NPE_FW_SETFIREWALLMODE 0x0E
122#define NPE_PC_SETFRAMECONTROLDURATIONID 0x0F
123#define NPE_PC_SETAPMACTABLE 0x11
124#define NPE_SETLOOPBACK_MODE 0x12
125#define NPE_PC_SETBSSIDTABLE 0x13
126#define NPE_ADDRESS_FILTER_CONFIG 0x14
127#define NPE_APPENDFCSCONFIG 0x15
128#define NPE_NOTIFY_MAC_RECOVERY_DONE 0x16
129#define NPE_MAC_RECOVERY_START 0x17
130
131
132#ifdef __ARMEB__
133typedef struct sk_buff buffer_t;
134#define free_buffer dev_kfree_skb
135#define free_buffer_irq dev_kfree_skb_irq
136#else
137typedef void buffer_t;
138#define free_buffer kfree
139#define free_buffer_irq kfree
140#endif
141
142struct eth_regs {
143 u32 tx_control[2], __res1[2]; /* 000 */
144 u32 rx_control[2], __res2[2]; /* 010 */
145 u32 random_seed, __res3[3]; /* 020 */
146 u32 partial_empty_threshold, __res4; /* 030 */
147 u32 partial_full_threshold, __res5; /* 038 */
148 u32 tx_start_bytes, __res6[3]; /* 040 */
149 u32 tx_deferral, rx_deferral, __res7[2];/* 050 */
150 u32 tx_2part_deferral[2], __res8[2]; /* 060 */
151 u32 slot_time, __res9[3]; /* 070 */
152 u32 mdio_command[4]; /* 080 */
153 u32 mdio_status[4]; /* 090 */
154 u32 mcast_mask[6], __res10[2]; /* 0A0 */
155 u32 mcast_addr[6], __res11[2]; /* 0C0 */
156 u32 int_clock_threshold, __res12[3]; /* 0E0 */
157 u32 hw_addr[6], __res13[61]; /* 0F0 */
158 u32 core_control; /* 1FC */
159};
160
161struct port {
162 struct resource *mem_res;
163 struct eth_regs __iomem *regs;
164 struct npe *npe;
165 struct net_device *netdev;
166 struct napi_struct napi;
167 struct net_device_stats stat;
168 struct mii_if_info mii;
169 struct delayed_work mdio_thread;
170 struct eth_plat_info *plat;
171 buffer_t *rx_buff_tab[RX_DESCS], *tx_buff_tab[TX_DESCS];
172 struct desc *desc_tab; /* coherent */
173 u32 desc_tab_phys;
174 int id; /* logical port ID */
175 u16 mii_bmcr;
176};
177
178/* NPE message structure */
179struct msg {
180#ifdef __ARMEB__
181 u8 cmd, eth_id, byte2, byte3;
182 u8 byte4, byte5, byte6, byte7;
183#else
184 u8 byte3, byte2, eth_id, cmd;
185 u8 byte7, byte6, byte5, byte4;
186#endif
187};
188
189/* Ethernet packet descriptor */
190struct desc {
191 u32 next; /* pointer to next buffer, unused */
192
193#ifdef __ARMEB__
194 u16 buf_len; /* buffer length */
195 u16 pkt_len; /* packet length */
196 u32 data; /* pointer to data buffer in RAM */
197 u8 dest_id;
198 u8 src_id;
199 u16 flags;
200 u8 qos;
201 u8 padlen;
202 u16 vlan_tci;
203#else
204 u16 pkt_len; /* packet length */
205 u16 buf_len; /* buffer length */
206 u32 data; /* pointer to data buffer in RAM */
207 u16 flags;
208 u8 src_id;
209 u8 dest_id;
210 u16 vlan_tci;
211 u8 padlen;
212 u8 qos;
213#endif
214
215#ifdef __ARMEB__
216 u8 dst_mac_0, dst_mac_1, dst_mac_2, dst_mac_3;
217 u8 dst_mac_4, dst_mac_5, src_mac_0, src_mac_1;
218 u8 src_mac_2, src_mac_3, src_mac_4, src_mac_5;
219#else
220 u8 dst_mac_3, dst_mac_2, dst_mac_1, dst_mac_0;
221 u8 src_mac_1, src_mac_0, dst_mac_5, dst_mac_4;
222 u8 src_mac_5, src_mac_4, src_mac_3, src_mac_2;
223#endif
224};
225
226
227#define rx_desc_phys(port, n) ((port)->desc_tab_phys + \
228 (n) * sizeof(struct desc))
229#define rx_desc_ptr(port, n) (&(port)->desc_tab[n])
230
231#define tx_desc_phys(port, n) ((port)->desc_tab_phys + \
232 ((n) + RX_DESCS) * sizeof(struct desc))
233#define tx_desc_ptr(port, n) (&(port)->desc_tab[(n) + RX_DESCS])
234
235#ifndef __ARMEB__
236static inline void memcpy_swab32(u32 *dest, u32 *src, int cnt)
237{
238 int i;
239 for (i = 0; i < cnt; i++)
240 dest[i] = swab32(src[i]);
241}
242#endif
243
244static spinlock_t mdio_lock;
245static struct eth_regs __iomem *mdio_regs; /* mdio command and status only */
246static int ports_open;
247static struct port *npe_port_tab[MAX_NPES];
248static struct dma_pool *dma_pool;
249
250
251static u16 mdio_cmd(struct net_device *dev, int phy_id, int location,
252 int write, u16 cmd)
253{
254 int cycles = 0;
255
256 if (__raw_readl(&mdio_regs->mdio_command[3]) & 0x80) {
257 printk(KERN_ERR "%s: MII not ready to transmit\n", dev->name);
258 return 0;
259 }
260
261 if (write) {
262 __raw_writel(cmd & 0xFF, &mdio_regs->mdio_command[0]);
263 __raw_writel(cmd >> 8, &mdio_regs->mdio_command[1]);
264 }
265 __raw_writel(((phy_id << 5) | location) & 0xFF,
266 &mdio_regs->mdio_command[2]);
267 __raw_writel((phy_id >> 3) | (write << 2) | 0x80 /* GO */,
268 &mdio_regs->mdio_command[3]);
269
270 while ((cycles < MAX_MDIO_RETRIES) &&
271 (__raw_readl(&mdio_regs->mdio_command[3]) & 0x80)) {
272 udelay(1);
273 cycles++;
274 }
275
276 if (cycles == MAX_MDIO_RETRIES) {
277 printk(KERN_ERR "%s: MII write failed\n", dev->name);
278 return 0;
279 }
280
281#if DEBUG_MDIO
282 printk(KERN_DEBUG "%s: mdio_cmd() took %i cycles\n", dev->name,
283 cycles);
284#endif
285
286 if (write)
287 return 0;
288
289 if (__raw_readl(&mdio_regs->mdio_status[3]) & 0x80) {
290 printk(KERN_ERR "%s: MII read failed\n", dev->name);
291 return 0;
292 }
293
294 return (__raw_readl(&mdio_regs->mdio_status[0]) & 0xFF) |
295 (__raw_readl(&mdio_regs->mdio_status[1]) << 8);
296}
297
298static int mdio_read(struct net_device *dev, int phy_id, int location)
299{
300 unsigned long flags;
301 u16 val;
302
303 spin_lock_irqsave(&mdio_lock, flags);
304 val = mdio_cmd(dev, phy_id, location, 0, 0);
305 spin_unlock_irqrestore(&mdio_lock, flags);
306 return val;
307}
308
309static void mdio_write(struct net_device *dev, int phy_id, int location,
310 int val)
311{
312 unsigned long flags;
313
314 spin_lock_irqsave(&mdio_lock, flags);
315 mdio_cmd(dev, phy_id, location, 1, val);
316 spin_unlock_irqrestore(&mdio_lock, flags);
317}
318
319static void phy_reset(struct net_device *dev, int phy_id)
320{
321 struct port *port = netdev_priv(dev);
322 int cycles = 0;
323
324 mdio_write(dev, phy_id, MII_BMCR, port->mii_bmcr | BMCR_RESET);
325
326 while (cycles < MAX_MII_RESET_RETRIES) {
327 if (!(mdio_read(dev, phy_id, MII_BMCR) & BMCR_RESET)) {
328#if DEBUG_MDIO
329 printk(KERN_DEBUG "%s: phy_reset() took %i cycles\n",
330 dev->name, cycles);
331#endif
332 return;
333 }
334 udelay(1);
335 cycles++;
336 }
337
338 printk(KERN_ERR "%s: MII reset failed\n", dev->name);
339}
340
341static void eth_set_duplex(struct port *port)
342{
343 if (port->mii.full_duplex)
344 __raw_writel(DEFAULT_TX_CNTRL0 & ~TX_CNTRL0_HALFDUPLEX,
345 &port->regs->tx_control[0]);
346 else
347 __raw_writel(DEFAULT_TX_CNTRL0 | TX_CNTRL0_HALFDUPLEX,
348 &port->regs->tx_control[0]);
349}
350
351
352static void phy_check_media(struct port *port, int init)
353{
354 if (mii_check_media(&port->mii, 1, init))
355 eth_set_duplex(port);
356 if (port->mii.force_media) { /* mii_check_media() doesn't work */
357 struct net_device *dev = port->netdev;
358 int cur_link = mii_link_ok(&port->mii);
359 int prev_link = netif_carrier_ok(dev);
360
361 if (!prev_link && cur_link) {
362 printk(KERN_INFO "%s: link up\n", dev->name);
363 netif_carrier_on(dev);
364 } else if (prev_link && !cur_link) {
365 printk(KERN_INFO "%s: link down\n", dev->name);
366 netif_carrier_off(dev);
367 }
368 }
369}
370
371
372static void mdio_thread(struct work_struct *work)
373{
374 struct port *port = container_of(work, struct port, mdio_thread.work);
375
376 phy_check_media(port, 0);
377 schedule_delayed_work(&port->mdio_thread, MDIO_INTERVAL);
378}
379
380
381static inline void debug_pkt(struct net_device *dev, const char *func,
382 u8 *data, int len)
383{
384#if DEBUG_PKT_BYTES
385 int i;
386
387 printk(KERN_DEBUG "%s: %s(%i) ", dev->name, func, len);
388 for (i = 0; i < len; i++) {
389 if (i >= DEBUG_PKT_BYTES)
390 break;
391 printk("%s%02X",
392 ((i == 6) || (i == 12) || (i >= 14)) ? " " : "",
393 data[i]);
394 }
395 printk("\n");
396#endif
397}
398
399
400static inline void debug_desc(u32 phys, struct desc *desc)
401{
402#if DEBUG_DESC
403 printk(KERN_DEBUG "%X: %X %3X %3X %08X %2X < %2X %4X %X"
404 " %X %X %02X%02X%02X%02X%02X%02X < %02X%02X%02X%02X%02X%02X\n",
405 phys, desc->next, desc->buf_len, desc->pkt_len,
406 desc->data, desc->dest_id, desc->src_id, desc->flags,
407 desc->qos, desc->padlen, desc->vlan_tci,
408 desc->dst_mac_0, desc->dst_mac_1, desc->dst_mac_2,
409 desc->dst_mac_3, desc->dst_mac_4, desc->dst_mac_5,
410 desc->src_mac_0, desc->src_mac_1, desc->src_mac_2,
411 desc->src_mac_3, desc->src_mac_4, desc->src_mac_5);
412#endif
413}
414
415static inline void debug_queue(unsigned int queue, int is_get, u32 phys)
416{
417#if DEBUG_QUEUES
418 static struct {
419 int queue;
420 char *name;
421 } names[] = {
422 { TX_QUEUE(0x10), "TX#0 " },
423 { TX_QUEUE(0x20), "TX#1 " },
424 { TX_QUEUE(0x00), "TX#2 " },
425 { RXFREE_QUEUE(0x10), "RX-free#0 " },
426 { RXFREE_QUEUE(0x20), "RX-free#1 " },
427 { RXFREE_QUEUE(0x00), "RX-free#2 " },
428 { TXDONE_QUEUE, "TX-done " },
429 };
430 int i;
431
432 for (i = 0; i < ARRAY_SIZE(names); i++)
433 if (names[i].queue == queue)
434 break;
435
436 printk(KERN_DEBUG "Queue %i %s%s %X\n", queue,
437 i < ARRAY_SIZE(names) ? names[i].name : "",
438 is_get ? "->" : "<-", phys);
439#endif
440}
441
442static inline u32 queue_get_entry(unsigned int queue)
443{
444 u32 phys = qmgr_get_entry(queue);
445 debug_queue(queue, 1, phys);
446 return phys;
447}
448
449static inline int queue_get_desc(unsigned int queue, struct port *port,
450 int is_tx)
451{
452 u32 phys, tab_phys, n_desc;
453 struct desc *tab;
454
455 if (!(phys = queue_get_entry(queue)))
456 return -1;
457
458 phys &= ~0x1F; /* mask out non-address bits */
459 tab_phys = is_tx ? tx_desc_phys(port, 0) : rx_desc_phys(port, 0);
460 tab = is_tx ? tx_desc_ptr(port, 0) : rx_desc_ptr(port, 0);
461 n_desc = (phys - tab_phys) / sizeof(struct desc);
462 BUG_ON(n_desc >= (is_tx ? TX_DESCS : RX_DESCS));
463 debug_desc(phys, &tab[n_desc]);
464 BUG_ON(tab[n_desc].next);
465 return n_desc;
466}
467
468static inline void queue_put_desc(unsigned int queue, u32 phys,
469 struct desc *desc)
470{
471 debug_queue(queue, 0, phys);
472 debug_desc(phys, desc);
473 BUG_ON(phys & 0x1F);
474 qmgr_put_entry(queue, phys);
475 BUG_ON(qmgr_stat_overflow(queue));
476}
477
478
479static inline void dma_unmap_tx(struct port *port, struct desc *desc)
480{
481#ifdef __ARMEB__
482 dma_unmap_single(&port->netdev->dev, desc->data,
483 desc->buf_len, DMA_TO_DEVICE);
484#else
485 dma_unmap_single(&port->netdev->dev, desc->data & ~3,
486 ALIGN((desc->data & 3) + desc->buf_len, 4),
487 DMA_TO_DEVICE);
488#endif
489}
490
491
492static void eth_rx_irq(void *pdev)
493{
494 struct net_device *dev = pdev;
495 struct port *port = netdev_priv(dev);
496
497#if DEBUG_RX
498 printk(KERN_DEBUG "%s: eth_rx_irq\n", dev->name);
499#endif
500 qmgr_disable_irq(port->plat->rxq);
501 netif_rx_schedule(dev, &port->napi);
502}
503
504static int eth_poll(struct napi_struct *napi, int budget)
505{
506 struct port *port = container_of(napi, struct port, napi);
507 struct net_device *dev = port->netdev;
508 unsigned int rxq = port->plat->rxq, rxfreeq = RXFREE_QUEUE(port->id);
509 int received = 0;
510
511#if DEBUG_RX
512 printk(KERN_DEBUG "%s: eth_poll\n", dev->name);
513#endif
514
515 while (received < budget) {
516 struct sk_buff *skb;
517 struct desc *desc;
518 int n;
519#ifdef __ARMEB__
520 struct sk_buff *temp;
521 u32 phys;
522#endif
523
524 if ((n = queue_get_desc(rxq, port, 0)) < 0) {
525 received = 0; /* No packet received */
526#if DEBUG_RX
527 printk(KERN_DEBUG "%s: eth_poll netif_rx_complete\n",
528 dev->name);
529#endif
530 netif_rx_complete(dev, napi);
531 qmgr_enable_irq(rxq);
532 if (!qmgr_stat_empty(rxq) &&
533 netif_rx_reschedule(dev, napi)) {
534#if DEBUG_RX
535 printk(KERN_DEBUG "%s: eth_poll"
536 " netif_rx_reschedule successed\n",
537 dev->name);
538#endif
539 qmgr_disable_irq(rxq);
540 continue;
541 }
542#if DEBUG_RX
543 printk(KERN_DEBUG "%s: eth_poll all done\n",
544 dev->name);
545#endif
546 return 0; /* all work done */
547 }
548
549 desc = rx_desc_ptr(port, n);
550
551#ifdef __ARMEB__
552 if ((skb = netdev_alloc_skb(dev, RX_BUFF_SIZE))) {
553 phys = dma_map_single(&dev->dev, skb->data,
554 RX_BUFF_SIZE, DMA_FROM_DEVICE);
555 if (dma_mapping_error(phys)) {
556 dev_kfree_skb(skb);
557 skb = NULL;
558 }
559 }
560#else
561 skb = netdev_alloc_skb(dev,
562 ALIGN(NET_IP_ALIGN + desc->pkt_len, 4));
563#endif
564
565 if (!skb) {
566 port->stat.rx_dropped++;
567 /* put the desc back on RX-ready queue */
568 desc->buf_len = MAX_MRU;
569 desc->pkt_len = 0;
570 queue_put_desc(rxfreeq, rx_desc_phys(port, n), desc);
571 continue;
572 }
573
574 /* process received frame */
575#ifdef __ARMEB__
576 temp = skb;
577 skb = port->rx_buff_tab[n];
578 dma_unmap_single(&dev->dev, desc->data - NET_IP_ALIGN,
579 RX_BUFF_SIZE, DMA_FROM_DEVICE);
580#else
581 dma_sync_single(&dev->dev, desc->data - NET_IP_ALIGN,
582 RX_BUFF_SIZE, DMA_FROM_DEVICE);
583 memcpy_swab32((u32 *)skb->data, (u32 *)port->rx_buff_tab[n],
584 ALIGN(NET_IP_ALIGN + desc->pkt_len, 4) / 4);
585#endif
586 skb_reserve(skb, NET_IP_ALIGN);
587 skb_put(skb, desc->pkt_len);
588
589 debug_pkt(dev, "eth_poll", skb->data, skb->len);
590
591 skb->protocol = eth_type_trans(skb, dev);
592 dev->last_rx = jiffies;
593 port->stat.rx_packets++;
594 port->stat.rx_bytes += skb->len;
595 netif_receive_skb(skb);
596
597 /* put the new buffer on RX-free queue */
598#ifdef __ARMEB__
599 port->rx_buff_tab[n] = temp;
600 desc->data = phys + NET_IP_ALIGN;
601#endif
602 desc->buf_len = MAX_MRU;
603 desc->pkt_len = 0;
604 queue_put_desc(rxfreeq, rx_desc_phys(port, n), desc);
605 received++;
606 }
607
608#if DEBUG_RX
609 printk(KERN_DEBUG "eth_poll(): end, not all work done\n");
610#endif
611 return received; /* not all work done */
612}
613
614
615static void eth_txdone_irq(void *unused)
616{
617 u32 phys;
618
619#if DEBUG_TX
620 printk(KERN_DEBUG DRV_NAME ": eth_txdone_irq\n");
621#endif
622 while ((phys = queue_get_entry(TXDONE_QUEUE)) != 0) {
623 u32 npe_id, n_desc;
624 struct port *port;
625 struct desc *desc;
626 int start;
627
628 npe_id = phys & 3;
629 BUG_ON(npe_id >= MAX_NPES);
630 port = npe_port_tab[npe_id];
631 BUG_ON(!port);
632 phys &= ~0x1F; /* mask out non-address bits */
633 n_desc = (phys - tx_desc_phys(port, 0)) / sizeof(struct desc);
634 BUG_ON(n_desc >= TX_DESCS);
635 desc = tx_desc_ptr(port, n_desc);
636 debug_desc(phys, desc);
637
638 if (port->tx_buff_tab[n_desc]) { /* not the draining packet */
639 port->stat.tx_packets++;
640 port->stat.tx_bytes += desc->pkt_len;
641
642 dma_unmap_tx(port, desc);
643#if DEBUG_TX
644 printk(KERN_DEBUG "%s: eth_txdone_irq free %p\n",
645 port->netdev->name, port->tx_buff_tab[n_desc]);
646#endif
647 free_buffer_irq(port->tx_buff_tab[n_desc]);
648 port->tx_buff_tab[n_desc] = NULL;
649 }
650
651 start = qmgr_stat_empty(port->plat->txreadyq);
652 queue_put_desc(port->plat->txreadyq, phys, desc);
653 if (start) {
654#if DEBUG_TX
655 printk(KERN_DEBUG "%s: eth_txdone_irq xmit ready\n",
656 port->netdev->name);
657#endif
658 netif_wake_queue(port->netdev);
659 }
660 }
661}
662
663static int eth_xmit(struct sk_buff *skb, struct net_device *dev)
664{
665 struct port *port = netdev_priv(dev);
666 unsigned int txreadyq = port->plat->txreadyq;
667 int len, offset, bytes, n;
668 void *mem;
669 u32 phys;
670 struct desc *desc;
671
672#if DEBUG_TX
673 printk(KERN_DEBUG "%s: eth_xmit\n", dev->name);
674#endif
675
676 if (unlikely(skb->len > MAX_MRU)) {
677 dev_kfree_skb(skb);
678 port->stat.tx_errors++;
679 return NETDEV_TX_OK;
680 }
681
682 debug_pkt(dev, "eth_xmit", skb->data, skb->len);
683
684 len = skb->len;
685#ifdef __ARMEB__
686 offset = 0; /* no need to keep alignment */
687 bytes = len;
688 mem = skb->data;
689#else
690 offset = (int)skb->data & 3; /* keep 32-bit alignment */
691 bytes = ALIGN(offset + len, 4);
692 if (!(mem = kmalloc(bytes, GFP_ATOMIC))) {
693 dev_kfree_skb(skb);
694 port->stat.tx_dropped++;
695 return NETDEV_TX_OK;
696 }
697 memcpy_swab32(mem, (u32 *)((int)skb->data & ~3), bytes / 4);
698 dev_kfree_skb(skb);
699#endif
700
701 phys = dma_map_single(&dev->dev, mem, bytes, DMA_TO_DEVICE);
702 if (dma_mapping_error(phys)) {
703#ifdef __ARMEB__
704 dev_kfree_skb(skb);
705#else
706 kfree(mem);
707#endif
708 port->stat.tx_dropped++;
709 return NETDEV_TX_OK;
710 }
711
712 n = queue_get_desc(txreadyq, port, 1);
713 BUG_ON(n < 0);
714 desc = tx_desc_ptr(port, n);
715
716#ifdef __ARMEB__
717 port->tx_buff_tab[n] = skb;
718#else
719 port->tx_buff_tab[n] = mem;
720#endif
721 desc->data = phys + offset;
722 desc->buf_len = desc->pkt_len = len;
723
724 /* NPE firmware pads short frames with zeros internally */
725 wmb();
726 queue_put_desc(TX_QUEUE(port->id), tx_desc_phys(port, n), desc);
727 dev->trans_start = jiffies;
728
729 if (qmgr_stat_empty(txreadyq)) {
730#if DEBUG_TX
731 printk(KERN_DEBUG "%s: eth_xmit queue full\n", dev->name);
732#endif
733 netif_stop_queue(dev);
734 /* we could miss TX ready interrupt */
735 if (!qmgr_stat_empty(txreadyq)) {
736#if DEBUG_TX
737 printk(KERN_DEBUG "%s: eth_xmit ready again\n",
738 dev->name);
739#endif
740 netif_wake_queue(dev);
741 }
742 }
743
744#if DEBUG_TX
745 printk(KERN_DEBUG "%s: eth_xmit end\n", dev->name);
746#endif
747 return NETDEV_TX_OK;
748}
749
750
751static struct net_device_stats *eth_stats(struct net_device *dev)
752{
753 struct port *port = netdev_priv(dev);
754 return &port->stat;
755}
756
757static void eth_set_mcast_list(struct net_device *dev)
758{
759 struct port *port = netdev_priv(dev);
760 struct dev_mc_list *mclist = dev->mc_list;
761 u8 diffs[ETH_ALEN], *addr;
762 int cnt = dev->mc_count, i;
763
764 if ((dev->flags & IFF_PROMISC) || !mclist || !cnt) {
765 __raw_writel(DEFAULT_RX_CNTRL0 & ~RX_CNTRL0_ADDR_FLTR_EN,
766 &port->regs->rx_control[0]);
767 return;
768 }
769
770 memset(diffs, 0, ETH_ALEN);
771 addr = mclist->dmi_addr; /* first MAC address */
772
773 while (--cnt && (mclist = mclist->next))
774 for (i = 0; i < ETH_ALEN; i++)
775 diffs[i] |= addr[i] ^ mclist->dmi_addr[i];
776
777 for (i = 0; i < ETH_ALEN; i++) {
778 __raw_writel(addr[i], &port->regs->mcast_addr[i]);
779 __raw_writel(~diffs[i], &port->regs->mcast_mask[i]);
780 }
781
782 __raw_writel(DEFAULT_RX_CNTRL0 | RX_CNTRL0_ADDR_FLTR_EN,
783 &port->regs->rx_control[0]);
784}
785
786
787static int eth_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
788{
789 struct port *port = netdev_priv(dev);
790 unsigned int duplex_chg;
791 int err;
792
793 if (!netif_running(dev))
794 return -EINVAL;
795 err = generic_mii_ioctl(&port->mii, if_mii(req), cmd, &duplex_chg);
796 if (duplex_chg)
797 eth_set_duplex(port);
798 return err;
799}
800
801
802static int request_queues(struct port *port)
803{
804 int err;
805
806 err = qmgr_request_queue(RXFREE_QUEUE(port->id), RX_DESCS, 0, 0);
807 if (err)
808 return err;
809
810 err = qmgr_request_queue(port->plat->rxq, RX_DESCS, 0, 0);
811 if (err)
812 goto rel_rxfree;
813
814 err = qmgr_request_queue(TX_QUEUE(port->id), TX_DESCS, 0, 0);
815 if (err)
816 goto rel_rx;
817
818 err = qmgr_request_queue(port->plat->txreadyq, TX_DESCS, 0, 0);
819 if (err)
820 goto rel_tx;
821
822 /* TX-done queue handles skbs sent out by the NPEs */
823 if (!ports_open) {
824 err = qmgr_request_queue(TXDONE_QUEUE, TXDONE_QUEUE_LEN, 0, 0);
825 if (err)
826 goto rel_txready;
827 }
828 return 0;
829
830rel_txready:
831 qmgr_release_queue(port->plat->txreadyq);
832rel_tx:
833 qmgr_release_queue(TX_QUEUE(port->id));
834rel_rx:
835 qmgr_release_queue(port->plat->rxq);
836rel_rxfree:
837 qmgr_release_queue(RXFREE_QUEUE(port->id));
838 printk(KERN_DEBUG "%s: unable to request hardware queues\n",
839 port->netdev->name);
840 return err;
841}
842
843static void release_queues(struct port *port)
844{
845 qmgr_release_queue(RXFREE_QUEUE(port->id));
846 qmgr_release_queue(port->plat->rxq);
847 qmgr_release_queue(TX_QUEUE(port->id));
848 qmgr_release_queue(port->plat->txreadyq);
849
850 if (!ports_open)
851 qmgr_release_queue(TXDONE_QUEUE);
852}
853
854static int init_queues(struct port *port)
855{
856 int i;
857
858 if (!ports_open)
859 if (!(dma_pool = dma_pool_create(DRV_NAME, NULL,
860 POOL_ALLOC_SIZE, 32, 0)))
861 return -ENOMEM;
862
863 if (!(port->desc_tab = dma_pool_alloc(dma_pool, GFP_KERNEL,
864 &port->desc_tab_phys)))
865 return -ENOMEM;
866 memset(port->desc_tab, 0, POOL_ALLOC_SIZE);
867 memset(port->rx_buff_tab, 0, sizeof(port->rx_buff_tab)); /* tables */
868 memset(port->tx_buff_tab, 0, sizeof(port->tx_buff_tab));
869
870 /* Setup RX buffers */
871 for (i = 0; i < RX_DESCS; i++) {
872 struct desc *desc = rx_desc_ptr(port, i);
873 buffer_t *buff; /* skb or kmalloc()ated memory */
874 void *data;
875#ifdef __ARMEB__
876 if (!(buff = netdev_alloc_skb(port->netdev, RX_BUFF_SIZE)))
877 return -ENOMEM;
878 data = buff->data;
879#else
880 if (!(buff = kmalloc(RX_BUFF_SIZE, GFP_KERNEL)))
881 return -ENOMEM;
882 data = buff;
883#endif
884 desc->buf_len = MAX_MRU;
885 desc->data = dma_map_single(&port->netdev->dev, data,
886 RX_BUFF_SIZE, DMA_FROM_DEVICE);
887 if (dma_mapping_error(desc->data)) {
888 free_buffer(buff);
889 return -EIO;
890 }
891 desc->data += NET_IP_ALIGN;
892 port->rx_buff_tab[i] = buff;
893 }
894
895 return 0;
896}
897
898static void destroy_queues(struct port *port)
899{
900 int i;
901
902 if (port->desc_tab) {
903 for (i = 0; i < RX_DESCS; i++) {
904 struct desc *desc = rx_desc_ptr(port, i);
905 buffer_t *buff = port->rx_buff_tab[i];
906 if (buff) {
907 dma_unmap_single(&port->netdev->dev,
908 desc->data - NET_IP_ALIGN,
909 RX_BUFF_SIZE, DMA_FROM_DEVICE);
910 free_buffer(buff);
911 }
912 }
913 for (i = 0; i < TX_DESCS; i++) {
914 struct desc *desc = tx_desc_ptr(port, i);
915 buffer_t *buff = port->tx_buff_tab[i];
916 if (buff) {
917 dma_unmap_tx(port, desc);
918 free_buffer(buff);
919 }
920 }
921 dma_pool_free(dma_pool, port->desc_tab, port->desc_tab_phys);
922 port->desc_tab = NULL;
923 }
924
925 if (!ports_open && dma_pool) {
926 dma_pool_destroy(dma_pool);
927 dma_pool = NULL;
928 }
929}
930
931static int eth_open(struct net_device *dev)
932{
933 struct port *port = netdev_priv(dev);
934 struct npe *npe = port->npe;
935 struct msg msg;
936 int i, err;
937
938 if (!npe_running(npe)) {
939 err = npe_load_firmware(npe, npe_name(npe), &dev->dev);
940 if (err)
941 return err;
942
943 if (npe_recv_message(npe, &msg, "ETH_GET_STATUS")) {
944 printk(KERN_ERR "%s: %s not responding\n", dev->name,
945 npe_name(npe));
946 return -EIO;
947 }
948 }
949
950 mdio_write(dev, port->plat->phy, MII_BMCR, port->mii_bmcr);
951
952 memset(&msg, 0, sizeof(msg));
953 msg.cmd = NPE_VLAN_SETRXQOSENTRY;
954 msg.eth_id = port->id;
955 msg.byte5 = port->plat->rxq | 0x80;
956 msg.byte7 = port->plat->rxq << 4;
957 for (i = 0; i < 8; i++) {
958 msg.byte3 = i;
959 if (npe_send_recv_message(port->npe, &msg, "ETH_SET_RXQ"))
960 return -EIO;
961 }
962
963 msg.cmd = NPE_EDB_SETPORTADDRESS;
964 msg.eth_id = PHYSICAL_ID(port->id);
965 msg.byte2 = dev->dev_addr[0];
966 msg.byte3 = dev->dev_addr[1];
967 msg.byte4 = dev->dev_addr[2];
968 msg.byte5 = dev->dev_addr[3];
969 msg.byte6 = dev->dev_addr[4];
970 msg.byte7 = dev->dev_addr[5];
971 if (npe_send_recv_message(port->npe, &msg, "ETH_SET_MAC"))
972 return -EIO;
973
974 memset(&msg, 0, sizeof(msg));
975 msg.cmd = NPE_FW_SETFIREWALLMODE;
976 msg.eth_id = port->id;
977 if (npe_send_recv_message(port->npe, &msg, "ETH_SET_FIREWALL_MODE"))
978 return -EIO;
979
980 if ((err = request_queues(port)) != 0)
981 return err;
982
983 if ((err = init_queues(port)) != 0) {
984 destroy_queues(port);
985 release_queues(port);
986 return err;
987 }
988
989 for (i = 0; i < ETH_ALEN; i++)
990 __raw_writel(dev->dev_addr[i], &port->regs->hw_addr[i]);
991 __raw_writel(0x08, &port->regs->random_seed);
992 __raw_writel(0x12, &port->regs->partial_empty_threshold);
993 __raw_writel(0x30, &port->regs->partial_full_threshold);
994 __raw_writel(0x08, &port->regs->tx_start_bytes);
995 __raw_writel(0x15, &port->regs->tx_deferral);
996 __raw_writel(0x08, &port->regs->tx_2part_deferral[0]);
997 __raw_writel(0x07, &port->regs->tx_2part_deferral[1]);
998 __raw_writel(0x80, &port->regs->slot_time);
999 __raw_writel(0x01, &port->regs->int_clock_threshold);
1000
1001 /* Populate queues with buffers, no failure after this point */
1002 for (i = 0; i < TX_DESCS; i++)
1003 queue_put_desc(port->plat->txreadyq,
1004 tx_desc_phys(port, i), tx_desc_ptr(port, i));
1005
1006 for (i = 0; i < RX_DESCS; i++)
1007 queue_put_desc(RXFREE_QUEUE(port->id),
1008 rx_desc_phys(port, i), rx_desc_ptr(port, i));
1009
1010 __raw_writel(TX_CNTRL1_RETRIES, &port->regs->tx_control[1]);
1011 __raw_writel(DEFAULT_TX_CNTRL0, &port->regs->tx_control[0]);
1012 __raw_writel(0, &port->regs->rx_control[1]);
1013 __raw_writel(DEFAULT_RX_CNTRL0, &port->regs->rx_control[0]);
1014
1015 napi_enable(&port->napi);
1016 phy_check_media(port, 1);
1017 eth_set_mcast_list(dev);
1018 netif_start_queue(dev);
1019 schedule_delayed_work(&port->mdio_thread, MDIO_INTERVAL);
1020
1021 qmgr_set_irq(port->plat->rxq, QUEUE_IRQ_SRC_NOT_EMPTY,
1022 eth_rx_irq, dev);
1023 if (!ports_open) {
1024 qmgr_set_irq(TXDONE_QUEUE, QUEUE_IRQ_SRC_NOT_EMPTY,
1025 eth_txdone_irq, NULL);
1026 qmgr_enable_irq(TXDONE_QUEUE);
1027 }
1028 ports_open++;
1029 /* we may already have RX data, enables IRQ */
1030 netif_rx_schedule(dev, &port->napi);
1031 return 0;
1032}
1033
1034static int eth_close(struct net_device *dev)
1035{
1036 struct port *port = netdev_priv(dev);
1037 struct msg msg;
1038 int buffs = RX_DESCS; /* allocated RX buffers */
1039 int i;
1040
1041 ports_open--;
1042 qmgr_disable_irq(port->plat->rxq);
1043 napi_disable(&port->napi);
1044 netif_stop_queue(dev);
1045
1046 while (queue_get_desc(RXFREE_QUEUE(port->id), port, 0) >= 0)
1047 buffs--;
1048
1049 memset(&msg, 0, sizeof(msg));
1050 msg.cmd = NPE_SETLOOPBACK_MODE;
1051 msg.eth_id = port->id;
1052 msg.byte3 = 1;
1053 if (npe_send_recv_message(port->npe, &msg, "ETH_ENABLE_LOOPBACK"))
1054 printk(KERN_CRIT "%s: unable to enable loopback\n", dev->name);
1055
1056 i = 0;
1057 do { /* drain RX buffers */
1058 while (queue_get_desc(port->plat->rxq, port, 0) >= 0)
1059 buffs--;
1060 if (!buffs)
1061 break;
1062 if (qmgr_stat_empty(TX_QUEUE(port->id))) {
1063 /* we have to inject some packet */
1064 struct desc *desc;
1065 u32 phys;
1066 int n = queue_get_desc(port->plat->txreadyq, port, 1);
1067 BUG_ON(n < 0);
1068 desc = tx_desc_ptr(port, n);
1069 phys = tx_desc_phys(port, n);
1070 desc->buf_len = desc->pkt_len = 1;
1071 wmb();
1072 queue_put_desc(TX_QUEUE(port->id), phys, desc);
1073 }
1074 udelay(1);
1075 } while (++i < MAX_CLOSE_WAIT);
1076
1077 if (buffs)
1078 printk(KERN_CRIT "%s: unable to drain RX queue, %i buffer(s)"
1079 " left in NPE\n", dev->name, buffs);
1080#if DEBUG_CLOSE
1081 if (!buffs)
1082 printk(KERN_DEBUG "Draining RX queue took %i cycles\n", i);
1083#endif
1084
1085 buffs = TX_DESCS;
1086 while (queue_get_desc(TX_QUEUE(port->id), port, 1) >= 0)
1087 buffs--; /* cancel TX */
1088
1089 i = 0;
1090 do {
1091 while (queue_get_desc(port->plat->txreadyq, port, 1) >= 0)
1092 buffs--;
1093 if (!buffs)
1094 break;
1095 } while (++i < MAX_CLOSE_WAIT);
1096
1097 if (buffs)
1098 printk(KERN_CRIT "%s: unable to drain TX queue, %i buffer(s) "
1099 "left in NPE\n", dev->name, buffs);
1100#if DEBUG_CLOSE
1101 if (!buffs)
1102 printk(KERN_DEBUG "Draining TX queues took %i cycles\n", i);
1103#endif
1104
1105 msg.byte3 = 0;
1106 if (npe_send_recv_message(port->npe, &msg, "ETH_DISABLE_LOOPBACK"))
1107 printk(KERN_CRIT "%s: unable to disable loopback\n",
1108 dev->name);
1109
1110 port->mii_bmcr = mdio_read(dev, port->plat->phy, MII_BMCR) &
1111 ~(BMCR_RESET | BMCR_PDOWN); /* may have been altered */
1112 mdio_write(dev, port->plat->phy, MII_BMCR,
1113 port->mii_bmcr | BMCR_PDOWN);
1114
1115 if (!ports_open)
1116 qmgr_disable_irq(TXDONE_QUEUE);
1117 cancel_rearming_delayed_work(&port->mdio_thread);
1118 destroy_queues(port);
1119 release_queues(port);
1120 return 0;
1121}
1122
1123static int __devinit eth_init_one(struct platform_device *pdev)
1124{
1125 struct port *port;
1126 struct net_device *dev;
1127 struct eth_plat_info *plat = pdev->dev.platform_data;
1128 u32 regs_phys;
1129 int err;
1130
1131 if (!(dev = alloc_etherdev(sizeof(struct port))))
1132 return -ENOMEM;
1133
1134 SET_NETDEV_DEV(dev, &pdev->dev);
1135 port = netdev_priv(dev);
1136 port->netdev = dev;
1137 port->id = pdev->id;
1138
1139 switch (port->id) {
1140 case IXP4XX_ETH_NPEA:
1141 port->regs = (struct eth_regs __iomem *)IXP4XX_EthA_BASE_VIRT;
1142 regs_phys = IXP4XX_EthA_BASE_PHYS;
1143 break;
1144 case IXP4XX_ETH_NPEB:
1145 port->regs = (struct eth_regs __iomem *)IXP4XX_EthB_BASE_VIRT;
1146 regs_phys = IXP4XX_EthB_BASE_PHYS;
1147 break;
1148 case IXP4XX_ETH_NPEC:
1149 port->regs = (struct eth_regs __iomem *)IXP4XX_EthC_BASE_VIRT;
1150 regs_phys = IXP4XX_EthC_BASE_PHYS;
1151 break;
1152 default:
1153 err = -ENOSYS;
1154 goto err_free;
1155 }
1156
1157 dev->open = eth_open;
1158 dev->hard_start_xmit = eth_xmit;
1159 dev->stop = eth_close;
1160 dev->get_stats = eth_stats;
1161 dev->do_ioctl = eth_ioctl;
1162 dev->set_multicast_list = eth_set_mcast_list;
1163 dev->tx_queue_len = 100;
1164
1165 netif_napi_add(dev, &port->napi, eth_poll, NAPI_WEIGHT);
1166
1167 if (!(port->npe = npe_request(NPE_ID(port->id)))) {
1168 err = -EIO;
1169 goto err_free;
1170 }
1171
1172 if (register_netdev(dev)) {
1173 err = -EIO;
1174 goto err_npe_rel;
1175 }
1176
1177 port->mem_res = request_mem_region(regs_phys, REGS_SIZE, dev->name);
1178 if (!port->mem_res) {
1179 err = -EBUSY;
1180 goto err_unreg;
1181 }
1182
1183 port->plat = plat;
1184 npe_port_tab[NPE_ID(port->id)] = port;
1185 memcpy(dev->dev_addr, plat->hwaddr, ETH_ALEN);
1186
1187 platform_set_drvdata(pdev, dev);
1188
1189 __raw_writel(DEFAULT_CORE_CNTRL | CORE_RESET,
1190 &port->regs->core_control);
1191 udelay(50);
1192 __raw_writel(DEFAULT_CORE_CNTRL, &port->regs->core_control);
1193 udelay(50);
1194
1195 port->mii.dev = dev;
1196 port->mii.mdio_read = mdio_read;
1197 port->mii.mdio_write = mdio_write;
1198 port->mii.phy_id = plat->phy;
1199 port->mii.phy_id_mask = 0x1F;
1200 port->mii.reg_num_mask = 0x1F;
1201
1202 printk(KERN_INFO "%s: MII PHY %i on %s\n", dev->name, plat->phy,
1203 npe_name(port->npe));
1204
1205 phy_reset(dev, plat->phy);
1206 port->mii_bmcr = mdio_read(dev, plat->phy, MII_BMCR) &
1207 ~(BMCR_RESET | BMCR_PDOWN);
1208 mdio_write(dev, plat->phy, MII_BMCR, port->mii_bmcr | BMCR_PDOWN);
1209
1210 INIT_DELAYED_WORK(&port->mdio_thread, mdio_thread);
1211 return 0;
1212
1213err_unreg:
1214 unregister_netdev(dev);
1215err_npe_rel:
1216 npe_release(port->npe);
1217err_free:
1218 free_netdev(dev);
1219 return err;
1220}
1221
1222static int __devexit eth_remove_one(struct platform_device *pdev)
1223{
1224 struct net_device *dev = platform_get_drvdata(pdev);
1225 struct port *port = netdev_priv(dev);
1226
1227 unregister_netdev(dev);
1228 npe_port_tab[NPE_ID(port->id)] = NULL;
1229 platform_set_drvdata(pdev, NULL);
1230 npe_release(port->npe);
1231 release_resource(port->mem_res);
1232 free_netdev(dev);
1233 return 0;
1234}
1235
1236static struct platform_driver drv = {
1237 .driver.name = DRV_NAME,
1238 .probe = eth_init_one,
1239 .remove = eth_remove_one,
1240};
1241
1242static int __init eth_init_module(void)
1243{
1244 if (!(ixp4xx_read_feature_bits() & IXP4XX_FEATURE_NPEB_ETH0))
1245 return -ENOSYS;
1246
1247 /* All MII PHY accesses use NPE-B Ethernet registers */
1248 spin_lock_init(&mdio_lock);
1249 mdio_regs = (struct eth_regs __iomem *)IXP4XX_EthB_BASE_VIRT;
1250 __raw_writel(DEFAULT_CORE_CNTRL, &mdio_regs->core_control);
1251
1252 return platform_driver_register(&drv);
1253}
1254
1255static void __exit eth_cleanup_module(void)
1256{
1257 platform_driver_unregister(&drv);
1258}
1259
1260MODULE_AUTHOR("Krzysztof Halasa");
1261MODULE_DESCRIPTION("Intel IXP4xx Ethernet driver");
1262MODULE_LICENSE("GPL v2");
1263MODULE_ALIAS("platform:ixp4xx_eth");
1264module_init(eth_init_module);
1265module_exit(eth_cleanup_module);
diff --git a/drivers/net/bfin_mac.c b/drivers/net/bfin_mac.c
index 4fec8581bfd7..89c0018132ec 100644
--- a/drivers/net/bfin_mac.c
+++ b/drivers/net/bfin_mac.c
@@ -27,6 +27,7 @@
27#include <linux/phy.h> 27#include <linux/phy.h>
28#include <linux/netdevice.h> 28#include <linux/netdevice.h>
29#include <linux/etherdevice.h> 29#include <linux/etherdevice.h>
30#include <linux/ethtool.h>
30#include <linux/skbuff.h> 31#include <linux/skbuff.h>
31#include <linux/platform_device.h> 32#include <linux/platform_device.h>
32 33
@@ -42,7 +43,7 @@
42#define DRV_NAME "bfin_mac" 43#define DRV_NAME "bfin_mac"
43#define DRV_VERSION "1.1" 44#define DRV_VERSION "1.1"
44#define DRV_AUTHOR "Bryan Wu, Luke Yang" 45#define DRV_AUTHOR "Bryan Wu, Luke Yang"
45#define DRV_DESC "Blackfin BF53[67] BF527 on-chip Ethernet MAC driver" 46#define DRV_DESC "Blackfin on-chip Ethernet MAC driver"
46 47
47MODULE_AUTHOR(DRV_AUTHOR); 48MODULE_AUTHOR(DRV_AUTHOR);
48MODULE_LICENSE("GPL"); 49MODULE_LICENSE("GPL");
@@ -73,8 +74,14 @@ static struct net_dma_desc_tx *current_tx_ptr;
73static struct net_dma_desc_tx *tx_desc; 74static struct net_dma_desc_tx *tx_desc;
74static struct net_dma_desc_rx *rx_desc; 75static struct net_dma_desc_rx *rx_desc;
75 76
76static void bf537mac_disable(void); 77#if defined(CONFIG_BFIN_MAC_RMII)
77static void bf537mac_enable(void); 78static u16 pin_req[] = P_RMII0;
79#else
80static u16 pin_req[] = P_MII0;
81#endif
82
83static void bfin_mac_disable(void);
84static void bfin_mac_enable(void);
78 85
79static void desc_list_free(void) 86static void desc_list_free(void)
80{ 87{
@@ -243,27 +250,6 @@ init_error:
243 250
244/*---PHY CONTROL AND CONFIGURATION-----------------------------------------*/ 251/*---PHY CONTROL AND CONFIGURATION-----------------------------------------*/
245 252
246/* Set FER regs to MUX in Ethernet pins */
247static int setup_pin_mux(int action)
248{
249#if defined(CONFIG_BFIN_MAC_RMII)
250 u16 pin_req[] = P_RMII0;
251#else
252 u16 pin_req[] = P_MII0;
253#endif
254
255 if (action) {
256 if (peripheral_request_list(pin_req, DRV_NAME)) {
257 printk(KERN_ERR DRV_NAME
258 ": Requesting Peripherals failed\n");
259 return -EFAULT;
260 }
261 } else
262 peripheral_free_list(pin_req);
263
264 return 0;
265}
266
267/* 253/*
268 * MII operations 254 * MII operations
269 */ 255 */
@@ -322,9 +308,9 @@ static int mdiobus_reset(struct mii_bus *bus)
322 return 0; 308 return 0;
323} 309}
324 310
325static void bf537_adjust_link(struct net_device *dev) 311static void bfin_mac_adjust_link(struct net_device *dev)
326{ 312{
327 struct bf537mac_local *lp = netdev_priv(dev); 313 struct bfin_mac_local *lp = netdev_priv(dev);
328 struct phy_device *phydev = lp->phydev; 314 struct phy_device *phydev = lp->phydev;
329 unsigned long flags; 315 unsigned long flags;
330 int new_state = 0; 316 int new_state = 0;
@@ -395,7 +381,7 @@ static void bf537_adjust_link(struct net_device *dev)
395 381
396static int mii_probe(struct net_device *dev) 382static int mii_probe(struct net_device *dev)
397{ 383{
398 struct bf537mac_local *lp = netdev_priv(dev); 384 struct bfin_mac_local *lp = netdev_priv(dev);
399 struct phy_device *phydev = NULL; 385 struct phy_device *phydev = NULL;
400 unsigned short sysctl; 386 unsigned short sysctl;
401 int i; 387 int i;
@@ -431,10 +417,10 @@ static int mii_probe(struct net_device *dev)
431 } 417 }
432 418
433#if defined(CONFIG_BFIN_MAC_RMII) 419#if defined(CONFIG_BFIN_MAC_RMII)
434 phydev = phy_connect(dev, phydev->dev.bus_id, &bf537_adjust_link, 0, 420 phydev = phy_connect(dev, phydev->dev.bus_id, &bfin_mac_adjust_link, 0,
435 PHY_INTERFACE_MODE_RMII); 421 PHY_INTERFACE_MODE_RMII);
436#else 422#else
437 phydev = phy_connect(dev, phydev->dev.bus_id, &bf537_adjust_link, 0, 423 phydev = phy_connect(dev, phydev->dev.bus_id, &bfin_mac_adjust_link, 0,
438 PHY_INTERFACE_MODE_MII); 424 PHY_INTERFACE_MODE_MII);
439#endif 425#endif
440 426
@@ -469,6 +455,51 @@ static int mii_probe(struct net_device *dev)
469 return 0; 455 return 0;
470} 456}
471 457
458/*
459 * Ethtool support
460 */
461
462static int
463bfin_mac_ethtool_getsettings(struct net_device *dev, struct ethtool_cmd *cmd)
464{
465 struct bfin_mac_local *lp = netdev_priv(dev);
466
467 if (lp->phydev)
468 return phy_ethtool_gset(lp->phydev, cmd);
469
470 return -EINVAL;
471}
472
473static int
474bfin_mac_ethtool_setsettings(struct net_device *dev, struct ethtool_cmd *cmd)
475{
476 struct bfin_mac_local *lp = netdev_priv(dev);
477
478 if (!capable(CAP_NET_ADMIN))
479 return -EPERM;
480
481 if (lp->phydev)
482 return phy_ethtool_sset(lp->phydev, cmd);
483
484 return -EINVAL;
485}
486
487static void bfin_mac_ethtool_getdrvinfo(struct net_device *dev,
488 struct ethtool_drvinfo *info)
489{
490 strcpy(info->driver, DRV_NAME);
491 strcpy(info->version, DRV_VERSION);
492 strcpy(info->fw_version, "N/A");
493 strcpy(info->bus_info, dev->dev.bus_id);
494}
495
496static struct ethtool_ops bfin_mac_ethtool_ops = {
497 .get_settings = bfin_mac_ethtool_getsettings,
498 .set_settings = bfin_mac_ethtool_setsettings,
499 .get_link = ethtool_op_get_link,
500 .get_drvinfo = bfin_mac_ethtool_getdrvinfo,
501};
502
472/**************************************************************************/ 503/**************************************************************************/
473void setup_system_regs(struct net_device *dev) 504void setup_system_regs(struct net_device *dev)
474{ 505{
@@ -511,7 +542,7 @@ static void setup_mac_addr(u8 *mac_addr)
511 bfin_write_EMAC_ADDRHI(addr_hi); 542 bfin_write_EMAC_ADDRHI(addr_hi);
512} 543}
513 544
514static int bf537mac_set_mac_address(struct net_device *dev, void *p) 545static int bfin_mac_set_mac_address(struct net_device *dev, void *p)
515{ 546{
516 struct sockaddr *addr = p; 547 struct sockaddr *addr = p;
517 if (netif_running(dev)) 548 if (netif_running(dev))
@@ -573,7 +604,7 @@ adjust_head:
573 604
574} 605}
575 606
576static int bf537mac_hard_start_xmit(struct sk_buff *skb, 607static int bfin_mac_hard_start_xmit(struct sk_buff *skb,
577 struct net_device *dev) 608 struct net_device *dev)
578{ 609{
579 unsigned int data; 610 unsigned int data;
@@ -631,7 +662,7 @@ out:
631 return 0; 662 return 0;
632} 663}
633 664
634static void bf537mac_rx(struct net_device *dev) 665static void bfin_mac_rx(struct net_device *dev)
635{ 666{
636 struct sk_buff *skb, *new_skb; 667 struct sk_buff *skb, *new_skb;
637 unsigned short len; 668 unsigned short len;
@@ -680,7 +711,7 @@ out:
680} 711}
681 712
682/* interrupt routine to handle rx and error signal */ 713/* interrupt routine to handle rx and error signal */
683static irqreturn_t bf537mac_interrupt(int irq, void *dev_id) 714static irqreturn_t bfin_mac_interrupt(int irq, void *dev_id)
684{ 715{
685 struct net_device *dev = dev_id; 716 struct net_device *dev = dev_id;
686 int number = 0; 717 int number = 0;
@@ -700,21 +731,21 @@ get_one_packet:
700 } 731 }
701 732
702real_rx: 733real_rx:
703 bf537mac_rx(dev); 734 bfin_mac_rx(dev);
704 number++; 735 number++;
705 goto get_one_packet; 736 goto get_one_packet;
706} 737}
707 738
708#ifdef CONFIG_NET_POLL_CONTROLLER 739#ifdef CONFIG_NET_POLL_CONTROLLER
709static void bf537mac_poll(struct net_device *dev) 740static void bfin_mac_poll(struct net_device *dev)
710{ 741{
711 disable_irq(IRQ_MAC_RX); 742 disable_irq(IRQ_MAC_RX);
712 bf537mac_interrupt(IRQ_MAC_RX, dev); 743 bfin_mac_interrupt(IRQ_MAC_RX, dev);
713 enable_irq(IRQ_MAC_RX); 744 enable_irq(IRQ_MAC_RX);
714} 745}
715#endif /* CONFIG_NET_POLL_CONTROLLER */ 746#endif /* CONFIG_NET_POLL_CONTROLLER */
716 747
717static void bf537mac_disable(void) 748static void bfin_mac_disable(void)
718{ 749{
719 unsigned int opmode; 750 unsigned int opmode;
720 751
@@ -728,7 +759,7 @@ static void bf537mac_disable(void)
728/* 759/*
729 * Enable Interrupts, Receive, and Transmit 760 * Enable Interrupts, Receive, and Transmit
730 */ 761 */
731static void bf537mac_enable(void) 762static void bfin_mac_enable(void)
732{ 763{
733 u32 opmode; 764 u32 opmode;
734 765
@@ -766,23 +797,23 @@ static void bf537mac_enable(void)
766} 797}
767 798
768/* Our watchdog timed out. Called by the networking layer */ 799/* Our watchdog timed out. Called by the networking layer */
769static void bf537mac_timeout(struct net_device *dev) 800static void bfin_mac_timeout(struct net_device *dev)
770{ 801{
771 pr_debug("%s: %s\n", dev->name, __FUNCTION__); 802 pr_debug("%s: %s\n", dev->name, __FUNCTION__);
772 803
773 bf537mac_disable(); 804 bfin_mac_disable();
774 805
775 /* reset tx queue */ 806 /* reset tx queue */
776 tx_list_tail = tx_list_head->next; 807 tx_list_tail = tx_list_head->next;
777 808
778 bf537mac_enable(); 809 bfin_mac_enable();
779 810
780 /* We can accept TX packets again */ 811 /* We can accept TX packets again */
781 dev->trans_start = jiffies; 812 dev->trans_start = jiffies;
782 netif_wake_queue(dev); 813 netif_wake_queue(dev);
783} 814}
784 815
785static void bf537mac_multicast_hash(struct net_device *dev) 816static void bfin_mac_multicast_hash(struct net_device *dev)
786{ 817{
787 u32 emac_hashhi, emac_hashlo; 818 u32 emac_hashhi, emac_hashlo;
788 struct dev_mc_list *dmi = dev->mc_list; 819 struct dev_mc_list *dmi = dev->mc_list;
@@ -821,7 +852,7 @@ static void bf537mac_multicast_hash(struct net_device *dev)
821 * promiscuous mode (for TCPDUMP and cousins) or accept 852 * promiscuous mode (for TCPDUMP and cousins) or accept
822 * a select set of multicast packets 853 * a select set of multicast packets
823 */ 854 */
824static void bf537mac_set_multicast_list(struct net_device *dev) 855static void bfin_mac_set_multicast_list(struct net_device *dev)
825{ 856{
826 u32 sysctl; 857 u32 sysctl;
827 858
@@ -840,7 +871,7 @@ static void bf537mac_set_multicast_list(struct net_device *dev)
840 sysctl = bfin_read_EMAC_OPMODE(); 871 sysctl = bfin_read_EMAC_OPMODE();
841 sysctl |= HM; 872 sysctl |= HM;
842 bfin_write_EMAC_OPMODE(sysctl); 873 bfin_write_EMAC_OPMODE(sysctl);
843 bf537mac_multicast_hash(dev); 874 bfin_mac_multicast_hash(dev);
844 } else { 875 } else {
845 /* clear promisc or multicast mode */ 876 /* clear promisc or multicast mode */
846 sysctl = bfin_read_EMAC_OPMODE(); 877 sysctl = bfin_read_EMAC_OPMODE();
@@ -852,7 +883,7 @@ static void bf537mac_set_multicast_list(struct net_device *dev)
852/* 883/*
853 * this puts the device in an inactive state 884 * this puts the device in an inactive state
854 */ 885 */
855static void bf537mac_shutdown(struct net_device *dev) 886static void bfin_mac_shutdown(struct net_device *dev)
856{ 887{
857 /* Turn off the EMAC */ 888 /* Turn off the EMAC */
858 bfin_write_EMAC_OPMODE(0x00000000); 889 bfin_write_EMAC_OPMODE(0x00000000);
@@ -866,9 +897,9 @@ static void bf537mac_shutdown(struct net_device *dev)
866 * 897 *
867 * Set up everything, reset the card, etc.. 898 * Set up everything, reset the card, etc..
868 */ 899 */
869static int bf537mac_open(struct net_device *dev) 900static int bfin_mac_open(struct net_device *dev)
870{ 901{
871 struct bf537mac_local *lp = netdev_priv(dev); 902 struct bfin_mac_local *lp = netdev_priv(dev);
872 int retval; 903 int retval;
873 pr_debug("%s: %s\n", dev->name, __FUNCTION__); 904 pr_debug("%s: %s\n", dev->name, __FUNCTION__);
874 905
@@ -891,8 +922,8 @@ static int bf537mac_open(struct net_device *dev)
891 phy_start(lp->phydev); 922 phy_start(lp->phydev);
892 phy_write(lp->phydev, MII_BMCR, BMCR_RESET); 923 phy_write(lp->phydev, MII_BMCR, BMCR_RESET);
893 setup_system_regs(dev); 924 setup_system_regs(dev);
894 bf537mac_disable(); 925 bfin_mac_disable();
895 bf537mac_enable(); 926 bfin_mac_enable();
896 pr_debug("hardware init finished\n"); 927 pr_debug("hardware init finished\n");
897 netif_start_queue(dev); 928 netif_start_queue(dev);
898 netif_carrier_on(dev); 929 netif_carrier_on(dev);
@@ -906,9 +937,9 @@ static int bf537mac_open(struct net_device *dev)
906 * and not talk to the outside world. Caused by 937 * and not talk to the outside world. Caused by
907 * an 'ifconfig ethX down' 938 * an 'ifconfig ethX down'
908 */ 939 */
909static int bf537mac_close(struct net_device *dev) 940static int bfin_mac_close(struct net_device *dev)
910{ 941{
911 struct bf537mac_local *lp = netdev_priv(dev); 942 struct bfin_mac_local *lp = netdev_priv(dev);
912 pr_debug("%s: %s\n", dev->name, __FUNCTION__); 943 pr_debug("%s: %s\n", dev->name, __FUNCTION__);
913 944
914 netif_stop_queue(dev); 945 netif_stop_queue(dev);
@@ -918,7 +949,7 @@ static int bf537mac_close(struct net_device *dev)
918 phy_write(lp->phydev, MII_BMCR, BMCR_PDOWN); 949 phy_write(lp->phydev, MII_BMCR, BMCR_PDOWN);
919 950
920 /* clear everything */ 951 /* clear everything */
921 bf537mac_shutdown(dev); 952 bfin_mac_shutdown(dev);
922 953
923 /* free the rx/tx buffers */ 954 /* free the rx/tx buffers */
924 desc_list_free(); 955 desc_list_free();
@@ -926,46 +957,59 @@ static int bf537mac_close(struct net_device *dev)
926 return 0; 957 return 0;
927} 958}
928 959
929static int __init bf537mac_probe(struct net_device *dev) 960static int __init bfin_mac_probe(struct platform_device *pdev)
930{ 961{
931 struct bf537mac_local *lp = netdev_priv(dev); 962 struct net_device *ndev;
932 int retval; 963 struct bfin_mac_local *lp;
933 int i; 964 int rc, i;
965
966 ndev = alloc_etherdev(sizeof(struct bfin_mac_local));
967 if (!ndev) {
968 dev_err(&pdev->dev, "Cannot allocate net device!\n");
969 return -ENOMEM;
970 }
971
972 SET_NETDEV_DEV(ndev, &pdev->dev);
973 platform_set_drvdata(pdev, ndev);
974 lp = netdev_priv(ndev);
934 975
935 /* Grab the MAC address in the MAC */ 976 /* Grab the MAC address in the MAC */
936 *(__le32 *) (&(dev->dev_addr[0])) = cpu_to_le32(bfin_read_EMAC_ADDRLO()); 977 *(__le32 *) (&(ndev->dev_addr[0])) = cpu_to_le32(bfin_read_EMAC_ADDRLO());
937 *(__le16 *) (&(dev->dev_addr[4])) = cpu_to_le16((u16) bfin_read_EMAC_ADDRHI()); 978 *(__le16 *) (&(ndev->dev_addr[4])) = cpu_to_le16((u16) bfin_read_EMAC_ADDRHI());
938 979
939 /* probe mac */ 980 /* probe mac */
940 /*todo: how to proble? which is revision_register */ 981 /*todo: how to proble? which is revision_register */
941 bfin_write_EMAC_ADDRLO(0x12345678); 982 bfin_write_EMAC_ADDRLO(0x12345678);
942 if (bfin_read_EMAC_ADDRLO() != 0x12345678) { 983 if (bfin_read_EMAC_ADDRLO() != 0x12345678) {
943 pr_debug("can't detect bf537 mac!\n"); 984 dev_err(&pdev->dev, "Cannot detect Blackfin on-chip ethernet MAC controller!\n");
944 retval = -ENODEV; 985 rc = -ENODEV;
945 goto err_out; 986 goto out_err_probe_mac;
946 } 987 }
947 988
948 /* set the GPIO pins to Ethernet mode */ 989 /* set the GPIO pins to Ethernet mode */
949 retval = setup_pin_mux(1); 990 rc = peripheral_request_list(pin_req, DRV_NAME);
950 if (retval) 991 if (rc) {
951 return retval; 992 dev_err(&pdev->dev, "Requesting peripherals failed!\n");
952 993 rc = -EFAULT;
953 /*Is it valid? (Did bootloader initialize it?) */ 994 goto out_err_setup_pin_mux;
954 if (!is_valid_ether_addr(dev->dev_addr)) {
955 /* Grab the MAC from the board somehow - this is done in the
956 arch/blackfin/mach-bf537/boards/eth_mac.c */
957 bfin_get_ether_addr(dev->dev_addr);
958 } 995 }
959 996
997 /*
998 * Is it valid? (Did bootloader initialize it?)
999 * Grab the MAC from the board somehow
1000 * this is done in the arch/blackfin/mach-bfxxx/boards/eth_mac.c
1001 */
1002 if (!is_valid_ether_addr(ndev->dev_addr))
1003 bfin_get_ether_addr(ndev->dev_addr);
1004
960 /* If still not valid, get a random one */ 1005 /* If still not valid, get a random one */
961 if (!is_valid_ether_addr(dev->dev_addr)) { 1006 if (!is_valid_ether_addr(ndev->dev_addr))
962 random_ether_addr(dev->dev_addr); 1007 random_ether_addr(ndev->dev_addr);
963 }
964 1008
965 setup_mac_addr(dev->dev_addr); 1009 setup_mac_addr(ndev->dev_addr);
966 1010
967 /* MDIO bus initial */ 1011 /* MDIO bus initial */
968 lp->mii_bus.priv = dev; 1012 lp->mii_bus.priv = ndev;
969 lp->mii_bus.read = mdiobus_read; 1013 lp->mii_bus.read = mdiobus_read;
970 lp->mii_bus.write = mdiobus_write; 1014 lp->mii_bus.write = mdiobus_write;
971 lp->mii_bus.reset = mdiobus_reset; 1015 lp->mii_bus.reset = mdiobus_reset;
@@ -975,86 +1019,86 @@ static int __init bf537mac_probe(struct net_device *dev)
975 for (i = 0; i < PHY_MAX_ADDR; ++i) 1019 for (i = 0; i < PHY_MAX_ADDR; ++i)
976 lp->mii_bus.irq[i] = PHY_POLL; 1020 lp->mii_bus.irq[i] = PHY_POLL;
977 1021
978 mdiobus_register(&lp->mii_bus); 1022 rc = mdiobus_register(&lp->mii_bus);
1023 if (rc) {
1024 dev_err(&pdev->dev, "Cannot register MDIO bus!\n");
1025 goto out_err_mdiobus_register;
1026 }
979 1027
980 retval = mii_probe(dev); 1028 rc = mii_probe(ndev);
981 if (retval) 1029 if (rc) {
982 return retval; 1030 dev_err(&pdev->dev, "MII Probe failed!\n");
1031 goto out_err_mii_probe;
1032 }
983 1033
984 /* Fill in the fields of the device structure with ethernet values. */ 1034 /* Fill in the fields of the device structure with ethernet values. */
985 ether_setup(dev); 1035 ether_setup(ndev);
986 1036
987 dev->open = bf537mac_open; 1037 ndev->open = bfin_mac_open;
988 dev->stop = bf537mac_close; 1038 ndev->stop = bfin_mac_close;
989 dev->hard_start_xmit = bf537mac_hard_start_xmit; 1039 ndev->hard_start_xmit = bfin_mac_hard_start_xmit;
990 dev->set_mac_address = bf537mac_set_mac_address; 1040 ndev->set_mac_address = bfin_mac_set_mac_address;
991 dev->tx_timeout = bf537mac_timeout; 1041 ndev->tx_timeout = bfin_mac_timeout;
992 dev->set_multicast_list = bf537mac_set_multicast_list; 1042 ndev->set_multicast_list = bfin_mac_set_multicast_list;
993#ifdef CONFIG_NET_POLL_CONTROLLER 1043#ifdef CONFIG_NET_POLL_CONTROLLER
994 dev->poll_controller = bf537mac_poll; 1044 ndev->poll_controller = bfin_mac_poll;
995#endif 1045#endif
1046 ndev->ethtool_ops = &bfin_mac_ethtool_ops;
996 1047
997 spin_lock_init(&lp->lock); 1048 spin_lock_init(&lp->lock);
998 1049
999 /* now, enable interrupts */ 1050 /* now, enable interrupts */
1000 /* register irq handler */ 1051 /* register irq handler */
1001 if (request_irq 1052 rc = request_irq(IRQ_MAC_RX, bfin_mac_interrupt,
1002 (IRQ_MAC_RX, bf537mac_interrupt, IRQF_DISABLED | IRQF_SHARED, 1053 IRQF_DISABLED | IRQF_SHARED, "EMAC_RX", ndev);
1003 "EMAC_RX", dev)) { 1054 if (rc) {
1004 printk(KERN_WARNING DRV_NAME 1055 dev_err(&pdev->dev, "Cannot request Blackfin MAC RX IRQ!\n");
1005 ": Unable to attach BlackFin MAC RX interrupt\n"); 1056 rc = -EBUSY;
1006 return -EBUSY; 1057 goto out_err_request_irq;
1007 } 1058 }
1008 1059
1009 1060 rc = register_netdev(ndev);
1010 retval = register_netdev(dev); 1061 if (rc) {
1011 if (retval == 0) { 1062 dev_err(&pdev->dev, "Cannot register net device!\n");
1012 /* now, print out the card info, in a short format.. */ 1063 goto out_err_reg_ndev;
1013 printk(KERN_INFO "%s: Version %s, %s\n",
1014 DRV_NAME, DRV_VERSION, DRV_DESC);
1015 }
1016
1017err_out:
1018 return retval;
1019}
1020
1021static int bfin_mac_probe(struct platform_device *pdev)
1022{
1023 struct net_device *ndev;
1024
1025 ndev = alloc_etherdev(sizeof(struct bf537mac_local));
1026 if (!ndev) {
1027 printk(KERN_WARNING DRV_NAME ": could not allocate device\n");
1028 return -ENOMEM;
1029 } 1064 }
1030 1065
1031 SET_NETDEV_DEV(ndev, &pdev->dev); 1066 /* now, print out the card info, in a short format.. */
1067 dev_info(&pdev->dev, "%s, Version %s\n", DRV_DESC, DRV_VERSION);
1032 1068
1033 platform_set_drvdata(pdev, ndev); 1069 return 0;
1034 1070
1035 if (bf537mac_probe(ndev) != 0) { 1071out_err_reg_ndev:
1036 platform_set_drvdata(pdev, NULL); 1072 free_irq(IRQ_MAC_RX, ndev);
1037 free_netdev(ndev); 1073out_err_request_irq:
1038 printk(KERN_WARNING DRV_NAME ": not found\n"); 1074out_err_mii_probe:
1039 return -ENODEV; 1075 mdiobus_unregister(&lp->mii_bus);
1040 } 1076out_err_mdiobus_register:
1077 peripheral_free_list(pin_req);
1078out_err_setup_pin_mux:
1079out_err_probe_mac:
1080 platform_set_drvdata(pdev, NULL);
1081 free_netdev(ndev);
1041 1082
1042 return 0; 1083 return rc;
1043} 1084}
1044 1085
1045static int bfin_mac_remove(struct platform_device *pdev) 1086static int bfin_mac_remove(struct platform_device *pdev)
1046{ 1087{
1047 struct net_device *ndev = platform_get_drvdata(pdev); 1088 struct net_device *ndev = platform_get_drvdata(pdev);
1089 struct bfin_mac_local *lp = netdev_priv(ndev);
1048 1090
1049 platform_set_drvdata(pdev, NULL); 1091 platform_set_drvdata(pdev, NULL);
1050 1092
1093 mdiobus_unregister(&lp->mii_bus);
1094
1051 unregister_netdev(ndev); 1095 unregister_netdev(ndev);
1052 1096
1053 free_irq(IRQ_MAC_RX, ndev); 1097 free_irq(IRQ_MAC_RX, ndev);
1054 1098
1055 free_netdev(ndev); 1099 free_netdev(ndev);
1056 1100
1057 setup_pin_mux(0); 1101 peripheral_free_list(pin_req);
1058 1102
1059 return 0; 1103 return 0;
1060} 1104}
@@ -1065,7 +1109,7 @@ static int bfin_mac_suspend(struct platform_device *pdev, pm_message_t mesg)
1065 struct net_device *net_dev = platform_get_drvdata(pdev); 1109 struct net_device *net_dev = platform_get_drvdata(pdev);
1066 1110
1067 if (netif_running(net_dev)) 1111 if (netif_running(net_dev))
1068 bf537mac_close(net_dev); 1112 bfin_mac_close(net_dev);
1069 1113
1070 return 0; 1114 return 0;
1071} 1115}
@@ -1075,7 +1119,7 @@ static int bfin_mac_resume(struct platform_device *pdev)
1075 struct net_device *net_dev = platform_get_drvdata(pdev); 1119 struct net_device *net_dev = platform_get_drvdata(pdev);
1076 1120
1077 if (netif_running(net_dev)) 1121 if (netif_running(net_dev))
1078 bf537mac_open(net_dev); 1122 bfin_mac_open(net_dev);
1079 1123
1080 return 0; 1124 return 0;
1081} 1125}
diff --git a/drivers/net/bfin_mac.h b/drivers/net/bfin_mac.h
index f774d5a36942..beff51064ff4 100644
--- a/drivers/net/bfin_mac.h
+++ b/drivers/net/bfin_mac.h
@@ -49,7 +49,7 @@ struct net_dma_desc_tx {
49 struct status_area_tx status; 49 struct status_area_tx status;
50}; 50};
51 51
52struct bf537mac_local { 52struct bfin_mac_local {
53 /* 53 /*
54 * these are things that the kernel wants me to keep, so users 54 * these are things that the kernel wants me to keep, so users
55 * can find out semi-useless statistics of how well the card is 55 * can find out semi-useless statistics of how well the card is
diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index 15853be4680a..4b46e68183e0 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -56,8 +56,8 @@
56 56
57#define DRV_MODULE_NAME "bnx2" 57#define DRV_MODULE_NAME "bnx2"
58#define PFX DRV_MODULE_NAME ": " 58#define PFX DRV_MODULE_NAME ": "
59#define DRV_MODULE_VERSION "1.7.4" 59#define DRV_MODULE_VERSION "1.7.5"
60#define DRV_MODULE_RELDATE "February 18, 2008" 60#define DRV_MODULE_RELDATE "April 29, 2008"
61 61
62#define RUN_AT(x) (jiffies + (x)) 62#define RUN_AT(x) (jiffies + (x))
63 63
@@ -1631,8 +1631,10 @@ bnx2_set_default_remote_link(struct bnx2 *bp)
1631static void 1631static void
1632bnx2_set_default_link(struct bnx2 *bp) 1632bnx2_set_default_link(struct bnx2 *bp)
1633{ 1633{
1634 if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP) 1634 if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP) {
1635 return bnx2_set_default_remote_link(bp); 1635 bnx2_set_default_remote_link(bp);
1636 return;
1637 }
1636 1638
1637 bp->autoneg = AUTONEG_SPEED | AUTONEG_FLOW_CTRL; 1639 bp->autoneg = AUTONEG_SPEED | AUTONEG_FLOW_CTRL;
1638 bp->req_line_speed = 0; 1640 bp->req_line_speed = 0;
@@ -1715,7 +1717,6 @@ bnx2_remote_phy_event(struct bnx2 *bp)
1715 break; 1717 break;
1716 } 1718 }
1717 1719
1718 spin_lock(&bp->phy_lock);
1719 bp->flow_ctrl = 0; 1720 bp->flow_ctrl = 0;
1720 if ((bp->autoneg & (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) != 1721 if ((bp->autoneg & (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) !=
1721 (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) { 1722 (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) {
@@ -1737,7 +1738,6 @@ bnx2_remote_phy_event(struct bnx2 *bp)
1737 if (old_port != bp->phy_port) 1738 if (old_port != bp->phy_port)
1738 bnx2_set_default_link(bp); 1739 bnx2_set_default_link(bp);
1739 1740
1740 spin_unlock(&bp->phy_lock);
1741 } 1741 }
1742 if (bp->link_up != link_up) 1742 if (bp->link_up != link_up)
1743 bnx2_report_link(bp); 1743 bnx2_report_link(bp);
@@ -2222,6 +2222,11 @@ bnx2_init_5709_context(struct bnx2 *bp)
2222 for (i = 0; i < bp->ctx_pages; i++) { 2222 for (i = 0; i < bp->ctx_pages; i++) {
2223 int j; 2223 int j;
2224 2224
2225 if (bp->ctx_blk[i])
2226 memset(bp->ctx_blk[i], 0, BCM_PAGE_SIZE);
2227 else
2228 return -ENOMEM;
2229
2225 REG_WR(bp, BNX2_CTX_HOST_PAGE_TBL_DATA0, 2230 REG_WR(bp, BNX2_CTX_HOST_PAGE_TBL_DATA0,
2226 (bp->ctx_blk_mapping[i] & 0xffffffff) | 2231 (bp->ctx_blk_mapping[i] & 0xffffffff) |
2227 BNX2_CTX_HOST_PAGE_TBL_DATA0_VALID); 2232 BNX2_CTX_HOST_PAGE_TBL_DATA0_VALID);
@@ -2445,14 +2450,15 @@ bnx2_phy_event_is_set(struct bnx2 *bp, struct bnx2_napi *bnapi, u32 event)
2445static void 2450static void
2446bnx2_phy_int(struct bnx2 *bp, struct bnx2_napi *bnapi) 2451bnx2_phy_int(struct bnx2 *bp, struct bnx2_napi *bnapi)
2447{ 2452{
2448 if (bnx2_phy_event_is_set(bp, bnapi, STATUS_ATTN_BITS_LINK_STATE)) { 2453 spin_lock(&bp->phy_lock);
2449 spin_lock(&bp->phy_lock); 2454
2455 if (bnx2_phy_event_is_set(bp, bnapi, STATUS_ATTN_BITS_LINK_STATE))
2450 bnx2_set_link(bp); 2456 bnx2_set_link(bp);
2451 spin_unlock(&bp->phy_lock);
2452 }
2453 if (bnx2_phy_event_is_set(bp, bnapi, STATUS_ATTN_BITS_TIMER_ABORT)) 2457 if (bnx2_phy_event_is_set(bp, bnapi, STATUS_ATTN_BITS_TIMER_ABORT))
2454 bnx2_set_remote_link(bp); 2458 bnx2_set_remote_link(bp);
2455 2459
2460 spin_unlock(&bp->phy_lock);
2461
2456} 2462}
2457 2463
2458static inline u16 2464static inline u16
@@ -3174,6 +3180,12 @@ load_rv2p_fw(struct bnx2 *bp, __le32 *rv2p_code, u32 rv2p_code_len,
3174 int i; 3180 int i;
3175 u32 val; 3181 u32 val;
3176 3182
3183 if (rv2p_proc == RV2P_PROC2 && CHIP_NUM(bp) == CHIP_NUM_5709) {
3184 val = le32_to_cpu(rv2p_code[XI_RV2P_PROC2_MAX_BD_PAGE_LOC]);
3185 val &= ~XI_RV2P_PROC2_BD_PAGE_SIZE_MSK;
3186 val |= XI_RV2P_PROC2_BD_PAGE_SIZE;
3187 rv2p_code[XI_RV2P_PROC2_MAX_BD_PAGE_LOC] = cpu_to_le32(val);
3188 }
3177 3189
3178 for (i = 0; i < rv2p_code_len; i += 8) { 3190 for (i = 0; i < rv2p_code_len; i += 8) {
3179 REG_WR(bp, BNX2_RV2P_INSTR_HIGH, le32_to_cpu(*rv2p_code)); 3191 REG_WR(bp, BNX2_RV2P_INSTR_HIGH, le32_to_cpu(*rv2p_code));
@@ -4215,13 +4227,6 @@ bnx2_init_remote_phy(struct bnx2 *bp)
4215 if (netif_running(bp->dev)) { 4227 if (netif_running(bp->dev)) {
4216 u32 sig; 4228 u32 sig;
4217 4229
4218 if (val & BNX2_LINK_STATUS_LINK_UP) {
4219 bp->link_up = 1;
4220 netif_carrier_on(bp->dev);
4221 } else {
4222 bp->link_up = 0;
4223 netif_carrier_off(bp->dev);
4224 }
4225 sig = BNX2_DRV_ACK_CAP_SIGNATURE | 4230 sig = BNX2_DRV_ACK_CAP_SIGNATURE |
4226 BNX2_FW_CAP_REMOTE_PHY_CAPABLE; 4231 BNX2_FW_CAP_REMOTE_PHY_CAPABLE;
4227 bnx2_shmem_wr(bp, BNX2_DRV_ACK_CAP_MB, sig); 4232 bnx2_shmem_wr(bp, BNX2_DRV_ACK_CAP_MB, sig);
@@ -4878,6 +4883,8 @@ bnx2_init_nic(struct bnx2 *bp)
4878 spin_lock_bh(&bp->phy_lock); 4883 spin_lock_bh(&bp->phy_lock);
4879 bnx2_init_phy(bp); 4884 bnx2_init_phy(bp);
4880 bnx2_set_link(bp); 4885 bnx2_set_link(bp);
4886 if (bp->phy_flags & BNX2_PHY_FLAG_REMOTE_PHY_CAP)
4887 bnx2_remote_phy_event(bp);
4881 spin_unlock_bh(&bp->phy_lock); 4888 spin_unlock_bh(&bp->phy_lock);
4882 return 0; 4889 return 0;
4883} 4890}
@@ -4920,7 +4927,7 @@ bnx2_test_registers(struct bnx2 *bp)
4920 { 0x0c08, BNX2_FL_NOT_5709, 0x0f0ff073, 0x00000000 }, 4927 { 0x0c08, BNX2_FL_NOT_5709, 0x0f0ff073, 0x00000000 },
4921 4928
4922 { 0x1000, 0, 0x00000000, 0x00000001 }, 4929 { 0x1000, 0, 0x00000000, 0x00000001 },
4923 { 0x1004, 0, 0x00000000, 0x000f0001 }, 4930 { 0x1004, BNX2_FL_NOT_5709, 0x00000000, 0x000f0001 },
4924 4931
4925 { 0x1408, 0, 0x01c00800, 0x00000000 }, 4932 { 0x1408, 0, 0x01c00800, 0x00000000 },
4926 { 0x149c, 0, 0x8000ffff, 0x00000000 }, 4933 { 0x149c, 0, 0x8000ffff, 0x00000000 },
diff --git a/drivers/net/bnx2_fw2.h b/drivers/net/bnx2_fw2.h
index e6ffa2769f3d..ed0514cba0ee 100644
--- a/drivers/net/bnx2_fw2.h
+++ b/drivers/net/bnx2_fw2.h
@@ -3173,251 +3173,267 @@ static struct fw_info bnx2_rxp_fw_09 = {
3173}; 3173};
3174 3174
3175static u8 bnx2_xi_rv2p_proc1[] = { 3175static u8 bnx2_xi_rv2p_proc1[] = {
3176 /* Date: 01/14/2008 15:44 */ 3176 /* Date: 04/25/2008 22:02 */
3177 0xc5, 0x56, 0xcd, 0x6b, 0x13, 0x51, 0x10, 0x9f, 0xdd, 0x7c, 0x6c, 0x9a, 3177 0xbd, 0x56, 0x4f, 0x68, 0x1c, 0x55, 0x18, 0xff, 0x76, 0x76, 0x77, 0x66,
3178 0x6c, 0xb2, 0xa1, 0x6a, 0x09, 0x35, 0xd2, 0x58, 0x7a, 0x30, 0x6d, 0xc4, 3178 0x33, 0x3b, 0xbb, 0xb3, 0xd8, 0x34, 0x4c, 0xb7, 0x2b, 0x59, 0x83, 0x97,
3179 0x56, 0x3d, 0x78, 0x28, 0x54, 0x7a, 0x11, 0xac, 0xa7, 0x1e, 0x44, 0xc4, 3179 0xdd, 0x6c, 0x69, 0xa2, 0x15, 0x04, 0x53, 0x5a, 0x72, 0x09, 0xd8, 0x9e,
3180 0xcf, 0x20, 0x05, 0xf5, 0x8f, 0x70, 0x51, 0xab, 0x20, 0x78, 0x28, 0x68, 3180 0x02, 0xb5, 0x52, 0x84, 0xb6, 0x8b, 0xf4, 0x52, 0x5a, 0x28, 0x78, 0x11,
3181 0xb4, 0x7e, 0xa0, 0x27, 0x15, 0xf1, 0x90, 0x1c, 0x04, 0x05, 0x45, 0x50, 3181 0x84, 0x0e, 0x6d, 0x93, 0x82, 0xe8, 0x61, 0xc1, 0x06, 0x12, 0x44, 0xa3,
3182 0xf0, 0xa4, 0x37, 0x41, 0xbd, 0x54, 0xc5, 0x0f, 0xf0, 0xe2, 0x45, 0x8f, 3182 0x07, 0x95, 0x60, 0x61, 0x07, 0x3c, 0x78, 0x10, 0x14, 0x15, 0x11, 0x6c,
3183 0xda, 0xf8, 0xde, 0xcc, 0xef, 0xd9, 0xdd, 0x4d, 0xd2, 0x14, 0x0f, 0x1a, 3183 0x0f, 0x85, 0x88, 0xf6, 0xd2, 0x54, 0x4b, 0x0b, 0x1e, 0x5b, 0x3c, 0xd6,
3184 0x68, 0x7f, 0xec, 0xdb, 0xdf, 0x9b, 0x37, 0xf3, 0x9b, 0x79, 0x33, 0x9b, 3184 0x8c, 0xef, 0xfb, 0xf3, 0x92, 0x99, 0x97, 0x9d, 0x24, 0xa7, 0x2e, 0xb4,
3185 0x27, 0x22, 0x9b, 0xfc, 0xc6, 0x80, 0x42, 0x72, 0xad, 0x58, 0x4a, 0x81, 3185 0x3f, 0xbe, 0x37, 0xdf, 0xbf, 0xf7, 0xfd, 0xf9, 0xbd, 0xd4, 0x00, 0xc0,
3186 0x45, 0x74, 0xcf, 0x65, 0xf4, 0x37, 0x91, 0xfc, 0x46, 0x04, 0xfc, 0x91, 3186 0x82, 0x30, 0x1a, 0x55, 0x08, 0x65, 0x2b, 0x5f, 0x52, 0x90, 0x03, 0xf8,
3187 0xbc, 0xfa, 0xff, 0x9d, 0x26, 0x4a, 0x1a, 0x63, 0x34, 0xb1, 0x5e, 0xe3, 3187 0x1a, 0xf8, 0x57, 0xf4, 0x48, 0x0e, 0x0f, 0x8a, 0x3c, 0xce, 0x10, 0x8e,
3188 0x24, 0x3d, 0x29, 0x15, 0x14, 0xfe, 0x6a, 0x92, 0xaf, 0x9f, 0x87, 0xea, 3188 0xd7, 0xd4, 0xff, 0x17, 0xe0, 0x48, 0x13, 0x31, 0x0f, 0x47, 0x5e, 0x40,
3189 0x0f, 0x1a, 0x19, 0xb6, 0xfb, 0x0e, 0xfb, 0xdf, 0xc4, 0x04, 0xb7, 0x55, 3189 0x3c, 0x0c, 0xdf, 0x37, 0x03, 0x85, 0xff, 0xc5, 0x10, 0xa2, 0x3c, 0xdc,
3190 0x52, 0x62, 0x07, 0x48, 0x1b, 0xf3, 0x0c, 0xaf, 0xe6, 0xf4, 0x73, 0xd1, 3190 0xff, 0x36, 0x2a, 0x93, 0xff, 0x35, 0xb1, 0xff, 0x33, 0xcf, 0xf8, 0x6a,
3191 0xf2, 0x37, 0xe2, 0x7c, 0x5b, 0xd6, 0x17, 0xe6, 0x3c, 0xbd, 0x4e, 0xef, 3191 0xa7, 0xc4, 0x7e, 0x04, 0xe1, 0x40, 0x8d, 0x60, 0xb5, 0x87, 0xf2, 0x89,
3192 0x27, 0xf5, 0xb3, 0x97, 0x3e, 0xdd, 0x48, 0xb1, 0x5d, 0x79, 0xdf, 0x9b, 3192 0x13, 0x60, 0xa3, 0x9f, 0x4f, 0x94, 0x02, 0xca, 0x8d, 0x5c, 0x78, 0x40,
3193 0x3e, 0xcd, 0xfb, 0x5c, 0x4b, 0xec, 0xa9, 0x3f, 0xde, 0xbf, 0x55, 0xd9, 3193 0xf2, 0xb2, 0x58, 0xef, 0x5e, 0xcf, 0xc7, 0x73, 0xb8, 0x3f, 0x8d, 0xf2,
3194 0x81, 0xdf, 0x24, 0x76, 0x0e, 0x96, 0xf4, 0xfa, 0x76, 0xf0, 0xc6, 0xc1, 3194 0x3e, 0xf7, 0x5a, 0x0f, 0x31, 0x80, 0x73, 0x25, 0x8f, 0xef, 0x33, 0xca,
3195 0x2b, 0xb6, 0xf0, 0x16, 0xe6, 0x34, 0x3a, 0x54, 0xad, 0xe8, 0x78, 0x06, 3195 0x6e, 0xd7, 0xda, 0x68, 0xa7, 0x74, 0xdb, 0xe2, 0xb7, 0x88, 0x7e, 0xff,
3196 0x49, 0xe2, 0x49, 0xd0, 0x4c, 0xca, 0x15, 0x9d, 0x06, 0x84, 0xfd, 0x6e, 3196 0x89, 0xd9, 0x2f, 0xfa, 0x4b, 0xfa, 0x69, 0x28, 0x3f, 0x78, 0x6e, 0x4b,
3197 0x58, 0xef, 0x57, 0xbe, 0x0d, 0x6b, 0xde, 0x82, 0x8a, 0xdb, 0xc4, 0x1b, 3197 0x5e, 0xb6, 0x91, 0x97, 0xad, 0xf2, 0x90, 0x3a, 0x80, 0xce, 0x03, 0x71,
3198 0xe6, 0x39, 0x15, 0x63, 0x57, 0xf3, 0xde, 0x2a, 0x9e, 0x89, 0x2f, 0x18, 3198 0xaf, 0x8a, 0x8b, 0x7e, 0x1f, 0xcb, 0xbd, 0x01, 0x4e, 0x37, 0xc5, 0x7f,
3199 0x57, 0x26, 0x10, 0x57, 0x24, 0xde, 0x96, 0xf8, 0x82, 0x7a, 0xa5, 0xda, 3199 0x84, 0xe8, 0xe5, 0xd8, 0x9f, 0xfa, 0x27, 0xf7, 0xd8, 0xea, 0x47, 0xd7,
3200 0xf8, 0xaf, 0xcf, 0x51, 0xbe, 0xf0, 0x39, 0x49, 0xe8, 0x9c, 0x8c, 0xec, 3200 0x29, 0x9d, 0xbf, 0xd3, 0xd1, 0xdf, 0x75, 0x3f, 0x30, 0xce, 0x1d, 0x15,
3201 0x4b, 0x76, 0x88, 0xfb, 0x93, 0x35, 0xb3, 0x21, 0xec, 0x3f, 0x91, 0xb6, 3201 0x27, 0xa9, 0x0f, 0x3b, 0xe8, 0xff, 0xa6, 0xf4, 0xd3, 0x7e, 0xf9, 0xfc,
3202 0xf7, 0x54, 0xf9, 0x8d, 0xf5, 0x72, 0x3b, 0x1d, 0x12, 0xd0, 0xe1, 0x31, 3202 0xd7, 0xcd, 0xf3, 0xd6, 0xa0, 0xba, 0x15, 0x8d, 0xba, 0xfd, 0x28, 0x75,
3203 0xe2, 0x9b, 0xa2, 0x21, 0xbb, 0xc0, 0xef, 0xe3, 0xbc, 0x7f, 0xad, 0xf2, 3203 0x9b, 0x81, 0x17, 0xad, 0x80, 0xf4, 0x0a, 0x80, 0xb8, 0x5f, 0x25, 0x80,
3204 0x47, 0xe3, 0x3a, 0xe0, 0x7a, 0xe0, 0x01, 0xe0, 0x7e, 0xe0, 0x1a, 0xe0, 3204 0xf8, 0xbc, 0xe0, 0x45, 0xc1, 0xcf, 0x04, 0x97, 0x05, 0xf7, 0x0a, 0x0e,
3205 0x6a, 0xe0, 0x2a, 0x60, 0x2f, 0xf0, 0x32, 0x30, 0x0f, 0xf4, 0x80, 0x39, 3205 0x0b, 0xee, 0x11, 0x7c, 0x4e, 0xf0, 0x6f, 0xc1, 0x9a, 0xa0, 0x2f, 0x58,
3206 0xe0, 0x05, 0xa0, 0x0b, 0xcc, 0x00, 0x6b, 0xc0, 0xab, 0xc0, 0x14, 0xf0, 3206 0x15, 0xbc, 0x27, 0xe8, 0x09, 0x96, 0x0d, 0x7f, 0x75, 0xc1, 0x92, 0x60,
3207 0x28, 0xf0, 0x21, 0xf0, 0x31, 0xf0, 0x0b, 0xf0, 0x1c, 0xd0, 0xb1, 0x60, 3207 0x24, 0xf8, 0x9a, 0x61, 0xef, 0xe6, 0x18, 0x57, 0x45, 0x3e, 0x28, 0xf2,
3208 0x0f, 0xa8, 0x7e, 0x3e, 0xee, 0x47, 0x48, 0xa7, 0xeb, 0xa8, 0x7f, 0xad, 3208 0x49, 0x91, 0xb1, 0xa0, 0x32, 0xf7, 0xa9, 0x7a, 0x7d, 0xbe, 0xd1, 0xdf,
3209 0x33, 0xde, 0x97, 0x0d, 0x0f, 0xf9, 0x65, 0x9d, 0x2e, 0x83, 0xd7, 0x5b, 3209 0xd5, 0x9e, 0x7c, 0x6f, 0x69, 0xbd, 0x12, 0xd5, 0x0f, 0xda, 0x49, 0xfd,
3210 0xbf, 0x19, 0xb9, 0x27, 0xa5, 0xae, 0xf7, 0x23, 0x9a, 0x37, 0x8f, 0xe3, 3210 0x8f, 0xb7, 0xd1, 0x67, 0xb5, 0xe9, 0xd6, 0x20, 0xbb, 0x1b, 0x31, 0xe7,
3211 0x39, 0xb4, 0xc3, 0xe3, 0x73, 0x72, 0x49, 0x59, 0x37, 0x6e, 0xed, 0xf1, 3211 0xf1, 0x91, 0xd8, 0x07, 0xfd, 0xef, 0x32, 0xf6, 0x68, 0xaa, 0x63, 0xce,
3212 0x04, 0x8f, 0xa4, 0x05, 0x3f, 0xa7, 0x7b, 0xd4, 0xff, 0x66, 0x73, 0x26, 3212 0xd7, 0xa0, 0x3d, 0x7a, 0x45, 0xf6, 0xe8, 0xd0, 0x96, 0xf9, 0xe5, 0x39,
3213 0x23, 0xcf, 0x87, 0xb3, 0x46, 0x67, 0x63, 0xc7, 0xf8, 0xd3, 0xcd, 0x8f, 3213 0x3d, 0x2a, 0xf6, 0x53, 0x32, 0x9f, 0x8d, 0x0c, 0xbd, 0x30, 0xb1, 0xaf,
3214 0x4e, 0xe7, 0x19, 0xbf, 0xba, 0x9d, 0x2b, 0x58, 0xb5, 0xc3, 0xf1, 0x5f, 3214 0x14, 0x2f, 0x63, 0x1f, 0x6e, 0xe6, 0xba, 0x1d, 0x8c, 0x5b, 0x94, 0xb8,
3215 0x19, 0x15, 0x8c, 0x8f, 0x31, 0x54, 0xdc, 0x64, 0x5c, 0xe3, 0x56, 0xf7, 3215 0x59, 0xf9, 0xa1, 0xbd, 0xcc, 0x6f, 0x4b, 0xcf, 0x71, 0x7a, 0x7e, 0x79,
3216 0xb9, 0x39, 0x47, 0xa3, 0x5b, 0xa8, 0xf1, 0x7d, 0x89, 0x53, 0x2d, 0xa9, 3216 0x0e, 0x6d, 0x63, 0x0e, 0x2f, 0xed, 0xd0, 0x87, 0xb2, 0x51, 0xcf, 0xf3,
3217 0xed, 0xfe, 0x6c, 0x9e, 0x17, 0x5e, 0xff, 0xe1, 0x97, 0x8c, 0x85, 0x2b, 3217 0x4a, 0x9f, 0x45, 0xcb, 0x62, 0x5c, 0x62, 0xec, 0x78, 0x76, 0x01, 0xf1,
3218 0x2f, 0x84, 0xff, 0xba, 0xe4, 0x32, 0xee, 0x1e, 0xa1, 0xc8, 0xcf, 0xbc, 3218 0x90, 0xf7, 0x0b, 0xfb, 0x1b, 0xa5, 0x7b, 0x78, 0xc1, 0x02, 0xed, 0x6d,
3219 0x97, 0xfb, 0xe8, 0xb3, 0xdf, 0x3f, 0x2c, 0xbf, 0x61, 0xce, 0xc1, 0xbe, 3219 0x01, 0x16, 0xec, 0x21, 0x85, 0x4f, 0xe3, 0x0f, 0x59, 0xaf, 0x5e, 0xbc,
3220 0xe3, 0x26, 0x8f, 0x79, 0xf6, 0x73, 0x90, 0xe4, 0x79, 0xba, 0x2c, 0xef, 3220 0x4d, 0x18, 0x2c, 0xdd, 0x62, 0xfd, 0x3f, 0x9a, 0x9c, 0xf7, 0x1b, 0xe3,
3221 0xa7, 0xcb, 0xb8, 0xcf, 0x83, 0xe1, 0x7a, 0x90, 0x7b, 0x11, 0x43, 0xbe, 3221 0x60, 0xfc, 0xf4, 0x77, 0xd9, 0x77, 0x1f, 0xe5, 0x7f, 0x73, 0x61, 0xa4,
3222 0xf7, 0xe2, 0x5e, 0x44, 0xef, 0x71, 0xaa, 0x7e, 0x73, 0x2e, 0x58, 0x2f, 3222 0xe3, 0x88, 0xdd, 0x79, 0xbd, 0x47, 0xfc, 0xbb, 0x62, 0xd7, 0xa8, 0x6e,
3223 0x05, 0xaa, 0x8e, 0xc1, 0x9f, 0x96, 0x3c, 0x9b, 0xbe, 0x6c, 0xea, 0x9d, 3223 0xef, 0x47, 0x24, 0x0e, 0x7b, 0xf3, 0xcc, 0xaf, 0x1f, 0x44, 0xfa, 0x3e,
3224 0x97, 0xeb, 0x7e, 0x2c, 0xa4, 0xdf, 0x76, 0xaa, 0x04, 0xf3, 0x64, 0xb5, 3224 0xc2, 0x2b, 0x6d, 0xb6, 0xab, 0x50, 0x9c, 0x3d, 0xfd, 0x65, 0x63, 0x3e,
3225 0xa9, 0x97, 0x6e, 0xe7, 0x84, 0xec, 0xe5, 0x54, 0x06, 0xa8, 0xb5, 0x8e, 3225 0x9a, 0xbb, 0xe2, 0xd7, 0x27, 0xf1, 0x26, 0xbf, 0x26, 0xef, 0xaf, 0xf9,
3226 0x1d, 0xc4, 0x35, 0x81, 0x3a, 0x5e, 0xdb, 0x52, 0xc7, 0xa6, 0xdf, 0x4b, 3226 0xb5, 0x04, 0x67, 0x66, 0x7c, 0x8a, 0x57, 0xb5, 0xd9, 0xcd, 0x9b, 0x3e,
3227 0x3d, 0x77, 0xea, 0x5f, 0x7f, 0xdf, 0xa7, 0x85, 0xe7, 0x07, 0xea, 0xd3, 3227 0xe3, 0xdb, 0x2e, 0xe3, 0x43, 0x17, 0xeb, 0x13, 0xc7, 0xe7, 0xca, 0x2c,
3228 0xf4, 0x43, 0xe8, 0xe4, 0x30, 0xaf, 0xb8, 0x70, 0x5f, 0xf2, 0x26, 0xfd, 3228 0x9f, 0xad, 0xe8, 0xbd, 0xd6, 0xf6, 0x3a, 0xaf, 0xed, 0xf2, 0xc1, 0xf8,
3229 0x5c, 0x15, 0xa3, 0x1f, 0xf6, 0xd3, 0x31, 0xf1, 0x0d, 0x04, 0xfb, 0xe7, 3229 0x3a, 0x8e, 0xce, 0x43, 0xc7, 0x4b, 0xcf, 0x43, 0x76, 0x5c, 0xc6, 0xae,
3230 0x50, 0x87, 0x7c, 0x05, 0xfb, 0x6e, 0x54, 0x97, 0x70, 0xdd, 0x4b, 0xfe, 3230 0x95, 0xae, 0xc3, 0xd2, 0x04, 0x63, 0x61, 0x12, 0xf3, 0xfa, 0x21, 0xde,
3231 0xd3, 0xd0, 0xa9, 0xbf, 0x4b, 0x5f, 0xe8, 0x01, 0x6f, 0xcd, 0x32, 0x3c, 3231 0xd8, 0xeb, 0x56, 0x8d, 0xf4, 0xc6, 0x80, 0xe5, 0x59, 0x99, 0xbf, 0x59,
3232 0xb1, 0x3b, 0x59, 0x0e, 0xf6, 0x11, 0xaf, 0x89, 0xfe, 0x87, 0x7d, 0x7d, 3232 0xda, 0x47, 0xc5, 0x37, 0x16, 0x62, 0x1d, 0x42, 0x7a, 0x6f, 0x2c, 0xf7,
3233 0xf5, 0x47, 0x1d, 0xf2, 0x30, 0xfe, 0x7f, 0xf3, 0x80, 0xf9, 0x52, 0xb4, 3233 0x67, 0x9a, 0x87, 0xbc, 0x9c, 0xab, 0xfa, 0x8f, 0xa5, 0xf7, 0x78, 0x8d,
3234 0x24, 0x0f, 0x09, 0x5a, 0x99, 0xbe, 0x84, 0xf8, 0xa9, 0x83, 0xbe, 0x49, 3234 0xe7, 0xad, 0x94, 0x9e, 0xd3, 0x46, 0x3c, 0x78, 0xfe, 0xdd, 0xfe, 0x72,
3235 0xe8, 0xf0, 0x6d, 0x71, 0x79, 0x7d, 0x33, 0xe0, 0x7d, 0x0d, 0xf0, 0xb8, 3235 0x6f, 0x50, 0x3f, 0x74, 0x7e, 0x01, 0x74, 0x27, 0xb3, 0xde, 0x09, 0xfd,
3236 0x2e, 0xc6, 0xe5, 0xfe, 0x39, 0xd5, 0x2f, 0x11, 0xdd, 0xc6, 0x2a, 0xba, 3236 0x3e, 0x6b, 0x9e, 0xa4, 0xe3, 0x7e, 0x98, 0x4f, 0xdd, 0xfb, 0x28, 0x74,
3237 0xaf, 0x9c, 0xa0, 0x06, 0xe2, 0x7a, 0x1b, 0x8a, 0x2f, 0xab, 0xfc, 0x93, 3237 0x06, 0xf9, 0xff, 0x46, 0xbf, 0x7b, 0x03, 0xf6, 0x76, 0xa7, 0xb8, 0x29,
3238 0xef, 0x84, 0x3b, 0x0d, 0xa3, 0x83, 0xbc, 0x2e, 0x55, 0x04, 0x6f, 0x33, 3238 0xff, 0x55, 0xb5, 0x39, 0xb0, 0x75, 0xef, 0x1c, 0x63, 0x4f, 0x9f, 0xae,
3239 0x3f, 0x1f, 0xd0, 0x23, 0xac, 0x9b, 0xe8, 0x91, 0xa7, 0x5b, 0x7f, 0xfa, 3239 0xf3, 0x9e, 0x36, 0xb6, 0xcc, 0xa7, 0xe6, 0xaf, 0xe6, 0xb6, 0xfc, 0xf5,
3240 0x8d, 0xc7, 0xf6, 0x46, 0xd1, 0xaf, 0x0f, 0xa1, 0x6f, 0x7e, 0x48, 0x4b, 3240 0xac, 0xf8, 0xca, 0x02, 0xe6, 0x2b, 0x7c, 0x4f, 0xd2, 0x79, 0x3a, 0xfa,
3241 0x5f, 0xae, 0x4e, 0x71, 0xff, 0xa4, 0x3e, 0xf4, 0xcf, 0x6a, 0x56, 0x9e, 3241 0x9e, 0x06, 0x2f, 0xf1, 0xfd, 0xee, 0xaf, 0xef, 0x8e, 0xdf, 0x92, 0x75,
3242 0xfb, 0xb3, 0xf2, 0x1d, 0x36, 0xea, 0xb8, 0xcc, 0xeb, 0xcf, 0x0a, 0xf6, 3242 0x1a, 0xc4, 0x6f, 0xae, 0xc1, 0x57, 0xbf, 0xaf, 0x6f, 0xf2, 0x1b, 0x7e,
3243 0x65, 0xf4, 0xbe, 0x02, 0x7d, 0xdc, 0xc5, 0xf4, 0xca, 0xbc, 0x2b, 0x7d, 3243 0x5f, 0x59, 0xe1, 0xfe, 0xbd, 0x97, 0x98, 0xdf, 0x64, 0xdd, 0x87, 0xa4,
3244 0x74, 0xfe, 0x05, 0xfa, 0xba, 0x67, 0x74, 0x42, 0xbc, 0x5b, 0xf4, 0x7a, 3244 0xee, 0x4a, 0x8f, 0xec, 0x6f, 0x1b, 0xf6, 0xba, 0xff, 0xef, 0x08, 0x6f,
3245 0x1f, 0x7f, 0xf2, 0x2c, 0xe9, 0xab, 0x38, 0xc3, 0xe2, 0xdf, 0x0d, 0x78, 3245 0x5a, 0x53, 0x3c, 0x7f, 0x4e, 0xf7, 0x91, 0xd1, 0x97, 0xc9, 0x0e, 0xee,
3246 0x5f, 0x32, 0xfb, 0x06, 0xb4, 0x9e, 0x4f, 0x16, 0xcd, 0xdc, 0x18, 0xdc, 3246 0xd5, 0x65, 0x88, 0xa4, 0x6e, 0x77, 0x53, 0xf5, 0xab, 0x08, 0x4f, 0x38,
3247 0xa1, 0xfd, 0xf1, 0x28, 0xe7, 0x48, 0x3e, 0x05, 0x15, 0xcf, 0x76, 0xf4, 3247 0xf0, 0x55, 0xa4, 0xeb, 0xac, 0xfb, 0xc8, 0xf8, 0x25, 0xe9, 0xd7, 0x76,
3248 0xb6, 0xe2, 0xac, 0x2d, 0xcf, 0xb3, 0x27, 0xd9, 0xcc, 0xae, 0x59, 0xb3, 3248 0xa8, 0x77, 0x0d, 0xbe, 0xd8, 0xe0, 0x41, 0x9f, 0xfc, 0x4d, 0x08, 0xaf,
3249 0x3e, 0xc9, 0x05, 0x3a, 0x7d, 0xf7, 0x19, 0xaf, 0xe7, 0x1a, 0x31, 0x59, 3249 0x9c, 0x91, 0xfd, 0xfe, 0xcb, 0x65, 0xfe, 0xe8, 0x1e, 0xa3, 0x3d, 0x87,
3250 0x77, 0xa6, 0x8c, 0x1e, 0x1e, 0xc7, 0x57, 0x13, 0x3d, 0xf6, 0x5d, 0x14, 3250 0x11, 0xd9, 0xf3, 0x6e, 0x85, 0xe5, 0x7a, 0x85, 0x79, 0x71, 0xc2, 0xf1,
3251 0xdc, 0x4b, 0x3b, 0x19, 0xd3, 0x35, 0x57, 0xe6, 0xca, 0xbc, 0x9b, 0x62, 3251 0x48, 0xaf, 0x5e, 0x61, 0x1c, 0x29, 0xa3, 0x5d, 0x00, 0x0f, 0x8e, 0x93,
3252 0x24, 0xd6, 0xc3, 0xde, 0x2c, 0xf3, 0x21, 0x81, 0xbe, 0xde, 0x13, 0xc8, 3252 0x7a, 0x67, 0xd1, 0x63, 0x7e, 0x5f, 0xbc, 0x25, 0xfc, 0xe3, 0xeb, 0xfa,
3253 0x53, 0x74, 0xde, 0xae, 0x34, 0x5f, 0xc1, 0x39, 0x60, 0xe6, 0x43, 0xb4, 3253 0xc9, 0x7d, 0x5f, 0xc6, 0xf3, 0x11, 0xb5, 0xcf, 0xc9, 0x7e, 0x28, 0x9d,
3254 0xdf, 0x67, 0x51, 0x67, 0xd7, 0xba, 0xd4, 0xa3, 0xe9, 0x9f, 0x97, 0x16, 3254 0x36, 0xe7, 0xf7, 0xa9, 0x64, 0xdf, 0xf4, 0x93, 0xf5, 0xd6, 0xf3, 0xbd,
3255 0xe5, 0x1e, 0xb4, 0x9b, 0xb3, 0x1a, 0x73, 0x1d, 0xbe, 0x0f, 0x8a, 0xa8, 3255 0x9c, 0xd1, 0xa7, 0x99, 0x58, 0xf3, 0xdf, 0xd8, 0x0c, 0xe6, 0xeb, 0x43,
3256 0x3f, 0x33, 0x0f, 0xdb, 0x7d, 0x07, 0x08, 0x7f, 0x65, 0xf3, 0x3f, 0xdf, 3256 0xd5, 0xe1, 0xf9, 0x60, 0x54, 0x7e, 0x2c, 0x07, 0xcd, 0x1a, 0x73, 0xc2,
3257 0x61, 0xfe, 0xff, 0xb3, 0x39, 0x5f, 0x58, 0xca, 0xa3, 0xa9, 0xd3, 0x60, 3257 0x27, 0x73, 0x57, 0xc8, 0xcd, 0xf1, 0x39, 0x7d, 0x3e, 0x4d, 0x0b, 0x32,
3258 0x1e, 0x83, 0xf5, 0x1a, 0x9d, 0xc3, 0xcb, 0xcd, 0xdf, 0x1c, 0x74, 0x3e, 3258 0xbb, 0xf2, 0x13, 0x9d, 0x57, 0xa3, 0x3c, 0x9f, 0x3b, 0xc7, 0x74, 0xbd,
3259 0x06, 0x9d, 0xe3, 0x94, 0x88, 0xb1, 0x30, 0x6e, 0xfc, 0x14, 0xdb, 0xb5, 3259 0x7c, 0xba, 0xff, 0x02, 0xd7, 0xeb, 0xad, 0x1b, 0x8c, 0xa7, 0xe0, 0x75,
3260 0x67, 0x6d, 0xa6, 0xbb, 0x89, 0x33, 0x96, 0xc6, 0x9c, 0x7b, 0x46, 0x78, 3260 0x42, 0x77, 0xc1, 0x63, 0x7e, 0x5c, 0xf4, 0x4a, 0x84, 0x40, 0xf5, 0xb2,
3261 0x71, 0x59, 0x2f, 0x18, 0x3c, 0x7b, 0x4a, 0xbe, 0xfb, 0x6c, 0xfa, 0x0d, 3261 0x5e, 0xe2, 0x77, 0xad, 0x28, 0xef, 0xd1, 0x50, 0xa2, 0x8f, 0xe6, 0xfb,
3262 0x6d, 0x29, 0x98, 0xe1, 0x30, 0x0d, 0x00, 0x00, 0x00 }; 3262 0xb1, 0xdb, 0x7e, 0x26, 0xf9, 0x54, 0xbf, 0x6b, 0x39, 0xe3, 0xef, 0xc8,
3263 0x8a, 0x31, 0x9f, 0xef, 0x66, 0xcc, 0x67, 0x33, 0x63, 0xbe, 0x4d, 0x5e,
3264 0xb9, 0x24, 0x7b, 0x57, 0x80, 0x62, 0x9e, 0x1e, 0x26, 0xaf, 0x70, 0x95,
3265 0xfa, 0x6b, 0xcd, 0xf1, 0xbb, 0xee, 0x15, 0xe7, 0x73, 0x54, 0x37, 0x6f,
3266 0x9e, 0xf5, 0x0a, 0x7c, 0x1e, 0x68, 0xbc, 0x7e, 0x95, 0xdf, 0x4f, 0x0b,
3267 0xfe, 0x07, 0x89, 0x6e, 0x1e, 0x13, 0x00, 0x0d, 0x00, 0x00, 0x00 };
3263 3268
3264static u8 bnx2_xi_rv2p_proc2[] = { 3269static u8 bnx2_xi_rv2p_proc2[] = {
3265 /* Date: 01/14/2008 15:44 */ 3270 /* Date: 04/25/2008 22:02 */
3266 0xad, 0x58, 0x5d, 0x6c, 0xd3, 0x55, 0x14, 0xbf, 0xfd, 0x58, 0xdb, 0x75, 3271#define XI_RV2P_PROC2_MAX_BD_PAGE_LOC 5
3267 0xff, 0xb6, 0x63, 0x9b, 0xdd, 0xa7, 0x6e, 0x6e, 0x61, 0x6c, 0xd8, 0xcd, 3272#define XI_RV2P_PROC2_BD_PAGE_SIZE_MSK 0xffff
3268 0xd1, 0x8d, 0x4f, 0x4d, 0x5c, 0x86, 0x19, 0x20, 0x26, 0x8c, 0x61, 0xd4, 3273#define XI_RV2P_PROC2_BD_PAGE_SIZE ((PAGE_SIZE / 16) - 1)
3269 0x37, 0xd8, 0x90, 0xb2, 0xb2, 0x8d, 0x2c, 0x8c, 0xf0, 0xc0, 0x8b, 0x0d, 3274 0xad, 0x58, 0x5b, 0x6c, 0x54, 0x55, 0x14, 0x3d, 0xf3, 0xe8, 0xcc, 0xed,
3270 0xd3, 0xf1, 0xd2, 0x07, 0x47, 0xb2, 0x0d, 0x8d, 0xc1, 0x45, 0x7d, 0x40, 3275 0xcc, 0x9d, 0x99, 0xd2, 0xd6, 0xe9, 0x8b, 0x48, 0x69, 0xa5, 0x74, 0x70,
3271 0x9f, 0xec, 0x83, 0x52, 0x30, 0xc6, 0xc4, 0xe8, 0x42, 0xf0, 0x01, 0x48, 3276 0x0a, 0x65, 0x5a, 0x1e, 0x3e, 0x12, 0x49, 0xd1, 0x02, 0x3e, 0x42, 0xa9,
3272 0x30, 0xc6, 0x68, 0x48, 0x08, 0xea, 0x32, 0x10, 0x75, 0x0c, 0xfb, 0x64, 3277 0x86, 0x98, 0x18, 0x03, 0x9d, 0x4a, 0xe9, 0x40, 0x4b, 0x2a, 0x25, 0x7c,
3273 0x98, 0xf7, 0x9e, 0xdf, 0xb9, 0xff, 0xfe, 0xff, 0x5d, 0x27, 0x18, 0xec, 3278 0xf0, 0xe3, 0x84, 0x62, 0xf9, 0x99, 0x44, 0x4b, 0x80, 0x16, 0x63, 0x48,
3274 0x43, 0x4f, 0xef, 0xbd, 0xe7, 0x9e, 0x7b, 0x3e, 0x7e, 0xe7, 0x9c, 0x7b, 3279 0x23, 0x3f, 0xc4, 0xbf, 0x26, 0x28, 0x45, 0x3f, 0x4c, 0x88, 0x36, 0x04,
3275 0x5b, 0x2c, 0x84, 0x70, 0x8a, 0x44, 0xaa, 0x56, 0x52, 0x61, 0x38, 0x5c, 3280 0x3e, 0xc0, 0x44, 0x63, 0xfc, 0x21, 0x12, 0xc4, 0x5a, 0xa0, 0xc1, 0x82,
3276 0x02, 0x9f, 0xb5, 0xc5, 0x44, 0xae, 0xa5, 0x7c, 0xf2, 0xbb, 0x40, 0xbc, 3281 0x36, 0xc6, 0x48, 0xeb, 0x3d, 0x7b, 0xed, 0x73, 0xe7, 0xde, 0xe9, 0x2d,
3277 0xe4, 0xac, 0xa0, 0xb1, 0x5b, 0x28, 0x1a, 0x12, 0x22, 0x61, 0xa5, 0xa5, 3282 0x8f, 0x48, 0x3f, 0x58, 0x9c, 0x73, 0xf7, 0x39, 0x67, 0xef, 0xb5, 0x1f,
3278 0x4c, 0xaf, 0x32, 0xfd, 0x9d, 0xe9, 0xe3, 0x0e, 0xd0, 0x2b, 0x3c, 0xde, 3283 0x67, 0x9f, 0x29, 0x10, 0x42, 0x78, 0x45, 0x7a, 0x64, 0x91, 0x81, 0x22,
3279 0xc2, 0xe3, 0x6b, 0x3c, 0xfe, 0x91, 0xe9, 0x46, 0x9e, 0xdf, 0xcc, 0x34, 3284 0xe8, 0xf6, 0x68, 0x06, 0xcc, 0x0a, 0x91, 0x57, 0x2a, 0xc7, 0xc2, 0x2d,
3280 0xc9, 0x74, 0x3b, 0xaf, 0xa7, 0x99, 0xca, 0x4f, 0xc2, 0x90, 0x5f, 0x72, 3285 0xf8, 0x6f, 0x59, 0x01, 0xc1, 0x0f, 0x23, 0xf2, 0xbb, 0x5f, 0xbc, 0xe5,
3281 0xb9, 0x59, 0xeb, 0x69, 0x60, 0xba, 0x19, 0xfa, 0xee, 0xa9, 0x53, 0x7c, 3286 0xc6, 0x77, 0xaf, 0x90, 0x18, 0x11, 0x22, 0x2d, 0xb1, 0x80, 0x31, 0xc6,
3282 0xf3, 0x4b, 0x59, 0x3e, 0xcc, 0x5f, 0x9f, 0x00, 0xad, 0xc5, 0xae, 0x8f, 3287 0xe8, 0x72, 0x01, 0x4b, 0x18, 0x5f, 0x61, 0x14, 0x8c, 0xba, 0x1b, 0xe8,
3283 0x13, 0x4f, 0xeb, 0xfd, 0x20, 0x7d, 0x01, 0xd0, 0x7e, 0xb6, 0xbf, 0x33, 3288 0x66, 0xf4, 0xaa, 0x79, 0x5e, 0xaf, 0xf1, 0x7c, 0x3b, 0xe3, 0x76, 0x9e,
3284 0x42, 0x24, 0xb9, 0xdf, 0x89, 0x71, 0x77, 0xa3, 0xf2, 0x43, 0x89, 0x70, 3289 0xff, 0xdd, 0x40, 0xa5, 0x97, 0x1c, 0x4f, 0xce, 0x8a, 0xb4, 0x8e, 0x6d,
3285 0x3b, 0x95, 0x9c, 0x56, 0x9f, 0xe7, 0x3c, 0xe6, 0x5f, 0x0d, 0x81, 0xbe, 3290 0x63, 0x6a, 0x5e, 0x27, 0x48, 0xc7, 0xa0, 0xf7, 0x9b, 0x95, 0xb4, 0xce,
3286 0xe6, 0x07, 0xfd, 0xc5, 0x5f, 0x28, 0xbf, 0x97, 0x96, 0x62, 0x45, 0x2c, 3291 0x41, 0x4e, 0xce, 0xdf, 0x98, 0x55, 0xfb, 0x1d, 0xf4, 0xc8, 0xf1, 0x2f,
3287 0xdf, 0x60, 0xb5, 0x8b, 0xb0, 0x7f, 0xd6, 0x80, 0x1e, 0x2f, 0xd7, 0x41, 3292 0xc6, 0xd8, 0x25, 0x87, 0xc5, 0x51, 0x6c, 0x53, 0x5c, 0x9a, 0x91, 0xfb,
3288 0xbf, 0xef, 0x9f, 0x52, 0xf3, 0x2e, 0x91, 0x60, 0x39, 0x42, 0x68, 0x3d, 3293 0x78, 0xc4, 0xd0, 0x80, 0x46, 0xac, 0x1c, 0xd7, 0x31, 0x4e, 0x13, 0x1f,
3289 0x79, 0x7d, 0x10, 0xfb, 0x56, 0xad, 0xc1, 0xea, 0x5b, 0x31, 0x8c, 0xab, 3294 0x2e, 0x63, 0xcc, 0xfb, 0x31, 0x96, 0x85, 0x70, 0xee, 0xd6, 0x4a, 0x9c,
3290 0x3f, 0x28, 0xa6, 0xb8, 0x9c, 0x4e, 0x69, 0xfe, 0x7c, 0x72, 0xdd, 0x52, 3295 0xf7, 0xd3, 0xb3, 0x90, 0x4b, 0x47, 0x14, 0xa1, 0xf8, 0xbe, 0x48, 0xf0,
3291 0x2e, 0xe4, 0x8b, 0x7a, 0x1f, 0x29, 0x93, 0x88, 0x80, 0x8a, 0x96, 0xdc, 3296 0xf7, 0xdd, 0x72, 0x3c, 0xe5, 0x2a, 0x72, 0x81, 0x57, 0xbf, 0x50, 0x7a,
3292 0x73, 0x20, 0x7f, 0x6a, 0xb5, 0x9a, 0x77, 0x8a, 0x5e, 0x97, 0x9a, 0xf7, 3297 0x42, 0xee, 0xea, 0x40, 0xae, 0x3c, 0x0d, 0x3f, 0x4f, 0xaf, 0x50, 0x76,
3293 0x88, 0xde, 0xb8, 0xf6, 0x2f, 0xd6, 0x63, 0x1e, 0x22, 0x15, 0x7d, 0xe3, 3298 0x00, 0xda, 0x42, 0xc0, 0xa4, 0x07, 0xb8, 0x2e, 0x4e, 0x90, 0x69, 0x67,
3294 0xca, 0xce, 0x90, 0xd8, 0xe7, 0x0c, 0x11, 0x3f, 0xfc, 0xe2, 0xf2, 0x19, 3299 0x47, 0x36, 0xd7, 0x48, 0x3d, 0x0a, 0x85, 0xd7, 0x2d, 0xf7, 0x5b, 0xa1,
3295 0x9f, 0x81, 0xff, 0xcb, 0x5a, 0x83, 0x6c, 0x89, 0xb5, 0x63, 0x5f, 0x59, 3300 0xf9, 0xce, 0x61, 0xfe, 0x6d, 0xd6, 0xeb, 0xbd, 0x00, 0xf0, 0x46, 0x20,
3296 0x14, 0x74, 0x32, 0x5a, 0xa0, 0x48, 0x24, 0x36, 0x4a, 0xc3, 0xd6, 0x9b, 3301 0xdf, 0xf8, 0x77, 0x76, 0xb6, 0x23, 0x68, 0xb7, 0x2b, 0x1d, 0xc4, 0xfa,
3297 0xeb, 0x7c, 0xc4, 0x97, 0x68, 0xd1, 0xf1, 0xd3, 0xf1, 0x52, 0x71, 0xfc, 3302 0x31, 0xdd, 0xc9, 0x3e, 0xcf, 0x03, 0xec, 0xc3, 0xba, 0x05, 0x4b, 0xf1,
3298 0x44, 0xc6, 0x91, 0xdd, 0xd2, 0x00, 0xbf, 0xfe, 0xba, 0x5a, 0xf1, 0x4b, 3303 0xf5, 0xe3, 0x0e, 0x8c, 0x2b, 0x4e, 0x49, 0x39, 0x9f, 0x18, 0x1a, 0x71,
3299 0xe7, 0xd6, 0xe3, 0x9c, 0xac, 0x7e, 0xd6, 0xf8, 0x7f, 0xf4, 0x1f, 0xe2, 3304 0xe2, 0x23, 0x77, 0x7f, 0x23, 0x4e, 0x23, 0x38, 0x47, 0x54, 0x69, 0xa4,
3300 0xaf, 0xe4, 0x75, 0xb2, 0x5f, 0xea, 0xa4, 0x5f, 0x14, 0xad, 0x71, 0x24, 3305 0x54, 0x3a, 0x0e, 0x14, 0x75, 0x8e, 0xfc, 0x88, 0xe3, 0x4b, 0xe4, 0xbc,
3301 0x5a, 0xec, 0xf1, 0xb8, 0x3e, 0x11, 0xa2, 0xdf, 0xb7, 0xba, 0x8a, 0xc9, 3306 0x5b, 0xb4, 0x7a, 0x74, 0x3a, 0xa7, 0x35, 0xa5, 0xe2, 0x02, 0xdf, 0x3b,
3302 0xaf, 0xbb, 0x30, 0x7f, 0xaa, 0xfb, 0x1c, 0xe2, 0xb1, 0x83, 0xec, 0x17, 3307 0x7c, 0x04, 0xa5, 0x6d, 0xfd, 0xd2, 0xde, 0x88, 0xd8, 0xee, 0x8e, 0x90,
3303 0xfe, 0x37, 0x3e, 0xc5, 0xae, 0xbe, 0x80, 0x1a, 0xbf, 0xd2, 0x11, 0xbb, 3308 0x3c, 0xf8, 0xf1, 0x68, 0xfa, 0x97, 0x90, 0xff, 0x66, 0x91, 0x4e, 0x36,
3304 0x80, 0xf5, 0x82, 0x31, 0xf8, 0x75, 0x17, 0x4b, 0xdd, 0xe1, 0x72, 0x28, 3309 0x75, 0x34, 0x60, 0x5d, 0x71, 0x02, 0x78, 0x2c, 0x91, 0x27, 0x21, 0xde,
3305 0x92, 0xf4, 0x8c, 0xd1, 0xd0, 0x98, 0xa5, 0x75, 0x43, 0x9c, 0x4c, 0x61, 3310 0xd1, 0x4b, 0xc3, 0xe5, 0xd7, 0x57, 0x6a, 0x24, 0x97, 0xae, 0x53, 0x71,
3306 0xfd, 0x70, 0x91, 0x1a, 0xef, 0x8a, 0xcc, 0x63, 0x1c, 0x89, 0x8f, 0xf3, 3311 0xa7, 0xfc, 0x27, 0xfd, 0x3a, 0x64, 0xc6, 0x99, 0xa8, 0x06, 0xbf, 0xbf,
3307 0x46, 0x27, 0xfc, 0x70, 0xcb, 0x09, 0x79, 0x0c, 0x2f, 0xbf, 0x9b, 0xe2, 3312 0x2d, 0x91, 0xf2, 0x06, 0xc9, 0x55, 0x38, 0x27, 0xab, 0x9f, 0x35, 0x6e,
3308 0xe0, 0x10, 0x46, 0x37, 0xe8, 0x9b, 0xb4, 0xfe, 0xb7, 0x23, 0x49, 0x76, 3313 0x07, 0x2c, 0x71, 0xfb, 0x78, 0xf1, 0xb0, 0x8e, 0xf8, 0x59, 0xc7, 0x3c,
3309 0x77, 0x07, 0xdd, 0xe7, 0xc0, 0xc8, 0xb8, 0x36, 0x71, 0xab, 0x71, 0xff, 3314 0x55, 0x1a, 0x3c, 0x49, 0x5c, 0xe8, 0x4a, 0xd7, 0xd9, 0xfd, 0x74, 0x75,
3310 0xb0, 0xf8, 0x1d, 0x37, 0x34, 0x5e, 0xd9, 0xff, 0xec, 0xdf, 0xf7, 0x44, 3315 0x20, 0x42, 0xff, 0xbf, 0xd9, 0x54, 0x40, 0x3c, 0x6f, 0xc6, 0xfc, 0x91,
3311 0x2e, 0x4e, 0x41, 0xbb, 0x1b, 0x41, 0x3d, 0x0d, 0xb9, 0x78, 0xd5, 0xf8, 3316 0xe6, 0xb3, 0xf0, 0xd3, 0x26, 0xe2, 0x43, 0x04, 0x0e, 0x7d, 0x81, 0x55,
3312 0xb4, 0xfb, 0x99, 0xe3, 0x63, 0xc1, 0x0b, 0x11, 0x89, 0x13, 0x1b, 0x6e, 3317 0x6d, 0x14, 0xdf, 0xdd, 0x8d, 0x1d, 0x5f, 0x61, 0x9c, 0xf4, 0xc8, 0xf1,
3313 0x18, 0xa7, 0x95, 0xd2, 0x5f, 0x3a, 0xfe, 0x4a, 0x90, 0x57, 0x0c, 0xb2, 3318 0x6e, 0xbd, 0x7d, 0x14, 0xf2, 0x79, 0x7d, 0xe0, 0x7d, 0x33, 0x9f, 0xb2,
3314 0xbc, 0x38, 0xdb, 0x35, 0xc4, 0x76, 0xdd, 0xf1, 0x6b, 0xbf, 0x6a, 0x7b, 3319 0xc9, 0x43, 0xf9, 0x94, 0xf1, 0xf5, 0xd1, 0x50, 0x1f, 0xa3, 0xef, 0x05,
3315 0x40, 0x4f, 0xda, 0xec, 0x71, 0x48, 0x3c, 0xd9, 0x71, 0xc8, 0xfa, 0x24, 3320 0xe2, 0xf0, 0x08, 0xbe, 0xef, 0x09, 0x4a, 0x3b, 0xdf, 0x37, 0xf3, 0x2e,
3316 0xbf, 0xa9, 0xc7, 0x8f, 0xea, 0x06, 0x50, 0xd3, 0xce, 0x46, 0xc5, 0xe7, 3321 0xe5, 0xc3, 0xfa, 0xcc, 0x00, 0xf2, 0x66, 0xe2, 0x8c, 0x1c, 0x6f, 0x8b,
3317 0x89, 0x4e, 0xa7, 0xec, 0x38, 0xd4, 0xf9, 0xb8, 0xa7, 0x4e, 0xcb, 0x57, 3322 0x4f, 0x40, 0x3e, 0x9e, 0xea, 0xe7, 0x8d, 0xdd, 0xe0, 0xf1, 0xa6, 0x1b,
3318 0xb8, 0xcc, 0x48, 0x5c, 0x22, 0x6e, 0xa7, 0x53, 0xd6, 0xfc, 0xac, 0xca, 3323 0xf2, 0x1c, 0xa6, 0x01, 0x2f, 0xf9, 0xd1, 0x25, 0xf4, 0x66, 0xe0, 0x87,
3319 0x93, 0x9f, 0xf6, 0xbc, 0xd0, 0x7e, 0x39, 0x1c, 0xa0, 0x02, 0xd5, 0x71, 3324 0xf4, 0xfd, 0x5f, 0x57, 0x86, 0x78, 0xdb, 0x1a, 0xf6, 0x9e, 0x55, 0xfc,
3320 0x79, 0xce, 0x7e, 0x1e, 0xf0, 0xed, 0x35, 0xf1, 0x53, 0xb6, 0x81, 0xfd, 3325 0x30, 0x46, 0x94, 0x5d, 0xc0, 0x47, 0xcd, 0x83, 0xfe, 0x79, 0xf3, 0x80,
3321 0xc7, 0x34, 0xbc, 0x51, 0xc9, 0xeb, 0x61, 0xf9, 0x6d, 0x2c, 0xdf, 0xb0, 3326 0xfd, 0x19, 0x7b, 0x58, 0x1e, 0x00, 0x9b, 0x6b, 0x80, 0xbe, 0x6a, 0x29,
3322 0xe4, 0x9d, 0xd2, 0xaf, 0xcb, 0xcc, 0x37, 0x1d, 0xb7, 0x6c, 0xde, 0x69, 3327 0x9f, 0xff, 0x18, 0xf9, 0xc0, 0x7a, 0xcd, 0xc9, 0x37, 0xcc, 0x66, 0xe3,
3323 0xff, 0xd1, 0xf9, 0x91, 0xcb, 0x73, 0x6a, 0x7f, 0xf5, 0x03, 0xf2, 0x70, 3328 0x94, 0xc0, 0x88, 0x4f, 0x5b, 0xbc, 0x72, 0x7e, 0x2c, 0x36, 0xfc, 0xa0,
3324 0x93, 0x29, 0xef, 0x3b, 0x33, 0xdf, 0xd4, 0x7a, 0x91, 0x78, 0x8e, 0x87, 3329 0xe2, 0x4e, 0x6e, 0xe8, 0x17, 0xbb, 0x79, 0xdf, 0x14, 0xf3, 0xd1, 0xc5,
3325 0xf6, 0x7a, 0xf2, 0xa7, 0xac, 0x27, 0x64, 0x87, 0xcf, 0x38, 0xc7, 0xf5, 3330 0x7c, 0x4c, 0x32, 0xee, 0x09, 0x2a, 0x1e, 0x80, 0x87, 0x75, 0x9c, 0xdb,
3326 0x63, 0x54, 0x9d, 0x53, 0xc1, 0x7a, 0x57, 0xb0, 0xde, 0xb2, 0x5f, 0xb5, 3331 0x9a, 0x92, 0x7e, 0x5c, 0xeb, 0x50, 0x3f, 0x55, 0x9d, 0x84, 0x9f, 0x86,
3327 0x70, 0x9d, 0xd9, 0x6b, 0xad, 0x17, 0x6b, 0x2d, 0x79, 0xaf, 0xc6, 0x4d, 3332 0xd8, 0xaf, 0x27, 0xcc, 0x7a, 0xa9, 0xf8, 0x9d, 0xaf, 0x6e, 0xda, 0xf3,
3328 0x4b, 0xcb, 0xfb, 0x85, 0xcd, 0x9f, 0x09, 0x41, 0xfe, 0xf7, 0x72, 0x7c, 3333 0x29, 0xc7, 0xce, 0xcc, 0x77, 0x55, 0x58, 0x5e, 0x58, 0x0d, 0x34, 0xf9,
3329 0x3c, 0x79, 0xfa, 0x8b, 0xe6, 0x07, 0xbe, 0xb6, 0x11, 0xbf, 0xcf, 0xc4, 3334 0xad, 0xa1, 0x3c, 0x0e, 0x97, 0x8c, 0x2a, 0xfb, 0xa4, 0x7e, 0xb7, 0x55,
3330 0xbf, 0xdd, 0xde, 0xaa, 0x3c, 0x75, 0x27, 0xd7, 0x7e, 0xf8, 0xb3, 0xcf, 3335 0x1e, 0x86, 0x07, 0x0f, 0x12, 0x06, 0x0a, 0x4f, 0xc9, 0x73, 0xca, 0x1d,
3331 0x19, 0x20, 0xbe, 0x1b, 0x23, 0x6a, 0xdf, 0x49, 0x87, 0xf6, 0x53, 0x27, 3336 0xea, 0x8a, 0x3d, 0x9f, 0x73, 0xf9, 0xdd, 0x13, 0xa2, 0x42, 0xdb, 0x78,
3332 0xea, 0x90, 0x03, 0xf6, 0xd6, 0xb0, 0xbd, 0x72, 0xb9, 0x85, 0xf0, 0xef, 3337 0x79, 0xdc, 0x9e, 0xb7, 0xc8, 0x4f, 0xbf, 0x19, 0xdf, 0xc5, 0xab, 0xd9,
3333 0xbb, 0x31, 0x62, 0xb5, 0xd7, 0xf8, 0x97, 0xf3, 0xec, 0xb8, 0x19, 0xe1, 3338 0x0f, 0x8c, 0xd1, 0x35, 0x72, 0xdf, 0x16, 0x3e, 0xa7, 0x9e, 0xcf, 0xd1,
3334 0x3e, 0xd6, 0x8f, 0xbc, 0xf0, 0xed, 0xff, 0x5c, 0xeb, 0xc3, 0xe7, 0x86, 3339 0x2d, 0x75, 0x43, 0xea, 0x59, 0x68, 0xd6, 0x0b, 0x15, 0x1f, 0xd9, 0xba,
3335 0xf4, 0xf9, 0x4a, 0x5e, 0xb5, 0x98, 0x1b, 0x55, 0xfb, 0x1f, 0x13, 0x0c, 3340 0xa1, 0xfc, 0x40, 0xe7, 0xc7, 0x2f, 0x8f, 0xcb, 0xf5, 0x15, 0x0f, 0xa9,
3336 0x33, 0x31, 0xdc, 0x84, 0xfa, 0x77, 0xe7, 0x00, 0xf4, 0x1f, 0x6e, 0xd4, 3341 0x23, 0x9a, 0xb9, 0xdf, 0x8f, 0x66, 0x9d, 0x90, 0xdf, 0x83, 0xe2, 0x25,
3337 0x7d, 0x1c, 0x38, 0x16, 0x5c, 0xff, 0xbf, 0x9e, 0xc8, 0xe7, 0x97, 0x41, 3342 0x1e, 0xda, 0xeb, 0xe1, 0x1f, 0x46, 0x3d, 0x24, 0x3b, 0x34, 0xfd, 0x2c,
3338 0x07, 0xf8, 0xca, 0xd8, 0xae, 0x62, 0xb6, 0x2b, 0x22, 0x72, 0xeb, 0xec, 3343 0xd7, 0xbf, 0x5e, 0x79, 0x4e, 0x29, 0xeb, 0x5d, 0xca, 0x7a, 0x1b, 0xd7,
3339 0x5e, 0xca, 0x97, 0x4e, 0xe6, 0x7b, 0x56, 0xd7, 0xe3, 0x65, 0x7c, 0xb0, 3344 0x73, 0x1d, 0xd7, 0xc9, 0x6d, 0xd6, 0x7a, 0xf7, 0xcf, 0x4c, 0xb6, 0x6e,
3340 0xbf, 0x80, 0xcf, 0xcf, 0xe7, 0xaf, 0x7c, 0x72, 0xd3, 0x8c, 0xa3, 0x01, 3345 0xc9, 0xf1, 0xdf, 0x33, 0x73, 0xef, 0x5f, 0x47, 0x5e, 0xd3, 0x22, 0x82,
3341 0xe6, 0x73, 0xe7, 0xa9, 0xf3, 0x18, 0x65, 0xd6, 0x50, 0x9d, 0x3f, 0x73, 3346 0x3e, 0x23, 0x1d, 0x51, 0x7d, 0x41, 0x6e, 0xfd, 0xcb, 0xb5, 0x03, 0xbc,
3342 0x3c, 0xad, 0xf8, 0x02, 0x26, 0xce, 0xed, 0x76, 0xfd, 0x74, 0xff, 0xd1, 3347 0xb4, 0xb9, 0x43, 0x24, 0x77, 0xad, 0xc7, 0xde, 0x27, 0xa0, 0x0e, 0x56,
3343 0xfd, 0xaf, 0xf8, 0xc2, 0xe2, 0x60, 0x70, 0x25, 0x3f, 0xbb, 0xd5, 0xf4, 3348 0xba, 0xa0, 0xf7, 0x42, 0xd6, 0xdb, 0xd8, 0xaf, 0x8e, 0xf2, 0x41, 0xbb,
3344 0xcc, 0x42, 0x5a, 0xc7, 0xc9, 0x20, 0x3b, 0xe7, 0x46, 0xd5, 0xf9, 0x1f, 3349 0xd6, 0x63, 0xd5, 0xfb, 0xfa, 0xcc, 0xfc, 0xe7, 0x39, 0xc7, 0x41, 0x0f,
3345 0xe6, 0xf8, 0xdf, 0x69, 0xf1, 0x3f, 0xf8, 0x9f, 0x88, 0x3c, 0xaa, 0xdf, 3350 0xdf, 0xaf, 0x49, 0xc4, 0xb1, 0xd6, 0xfe, 0xb5, 0xd2, 0x8b, 0xcf, 0x8f,
3346 0xf3, 0xf5, 0xe5, 0x2f, 0xee, 0x2f, 0xcf, 0x13, 0x35, 0x7f, 0xe1, 0xa1, 3351 0x28, 0x3d, 0x74, 0xf2, 0xd3, 0x78, 0xaf, 0xdc, 0xa7, 0x48, 0x70, 0xd8,
3347 0xfd, 0xb1, 0xbb, 0xdd, 0x6a, 0x7f, 0x83, 0x98, 0x4d, 0x21, 0xbf, 0x7a, 3352 0x88, 0xee, 0x5a, 0xd4, 0xdf, 0xc9, 0x1d, 0xb0, 0xa3, 0xbb, 0x46, 0xea,
3348 0x18, 0x87, 0xfb, 0xb8, 0x5e, 0xdf, 0xf0, 0xab, 0x09, 0x9f, 0xe8, 0xdf, 3353 0x61, 0x78, 0x25, 0x8d, 0x3c, 0x17, 0x7c, 0x1f, 0x7d, 0x3b, 0xe0, 0xe4,
3349 0x49, 0xfe, 0x10, 0xe1, 0x22, 0xf8, 0xa7, 0xff, 0x45, 0xed, 0x4f, 0xcc, 3354 0xd7, 0x4b, 0x2c, 0x57, 0xcc, 0xf6, 0x15, 0xb0, 0x7d, 0x71, 0x91, 0x5b,
3350 0x57, 0x51, 0xbf, 0x75, 0x89, 0x1e, 0xaf, 0x41, 0xfc, 0x55, 0x01, 0xd0, 3355 0xe7, 0xb7, 0x55, 0xd2, 0x7d, 0xc0, 0x72, 0x2f, 0xaa, 0xfb, 0xc0, 0x90,
3351 0x30, 0xd7, 0xf9, 0x59, 0xb3, 0x8f, 0x81, 0x9e, 0xf6, 0xe8, 0xba, 0x8c, 3356 0x93, 0xfb, 0xe4, 0xf1, 0x3e, 0x4e, 0x3c, 0x39, 0xed, 0x33, 0xca, 0x71,
3352 0x7e, 0xfe, 0x95, 0x47, 0x31, 0xc8, 0x20, 0x35, 0xa3, 0x3e, 0x77, 0x35, 3357 0xd0, 0xc9, 0x72, 0x5e, 0x87, 0x7b, 0x05, 0xa3, 0xe9, 0xa5, 0x74, 0xaf,
3353 0x1a, 0xb4, 0xde, 0xdb, 0x0c, 0x3c, 0x89, 0x7a, 0xdd, 0xe7, 0xf0, 0xe1, 3358 0x9c, 0x3c, 0x40, 0xf7, 0x43, 0xc8, 0x8c, 0x53, 0xbb, 0x1d, 0x67, 0x9e,
3354 0x3e, 0x50, 0x95, 0xed, 0x77, 0xd6, 0x7e, 0x58, 0x68, 0xe9, 0x07, 0xfa, 3359 0x20, 0xef, 0x52, 0x3e, 0x2a, 0x76, 0x86, 0xe7, 0xe3, 0xd7, 0x2b, 0xa7,
3355 0x3c, 0xed, 0x47, 0x2d, 0x97, 0x86, 0xb2, 0xaf, 0x58, 0xfb, 0xa1, 0xee, 3360 0x87, 0xa7, 0x46, 0x95, 0x7f, 0x74, 0xb2, 0x77, 0xbc, 0x57, 0xf5, 0xb1,
3356 0x13, 0x8b, 0xdc, 0x27, 0x4a, 0xc5, 0xc5, 0x14, 0xec, 0x9a, 0x4d, 0xe5, 3361 0x56, 0xde, 0xdd, 0x16, 0xde, 0x21, 0xff, 0x74, 0xfc, 0xff, 0xf2, 0xed,
3357 0xe2, 0x4f, 0x9f, 0xa7, 0xe5, 0x41, 0x6f, 0x6d, 0x47, 0x56, 0x3e, 0xce, 3362 0xd4, 0x1f, 0x1c, 0x9d, 0x31, 0xfb, 0x50, 0x9f, 0x53, 0xfd, 0x5f, 0x61,
3358 0x3f, 0xc0, 0x7a, 0xfe, 0x4c, 0xf7, 0xd8, 0x30, 0xdb, 0xa3, 0xe4, 0x62, 3363 0xc6, 0xcb, 0x5e, 0xee, 0xef, 0xa6, 0x75, 0xfa, 0x4f, 0x62, 0x32, 0x43,
3359 0x7e, 0x3b, 0xf7, 0xe7, 0x84, 0x39, 0xb6, 0xf7, 0xd5, 0x1e, 0xd2, 0xab, 3364 0x43, 0xbd, 0xec, 0xb4, 0x94, 0x5b, 0x96, 0xd8, 0xcb, 0x76, 0x5d, 0xf4,
3360 0x84, 0xf1, 0x16, 0xb6, 0xe4, 0x03, 0xf8, 0xcb, 0xda, 0x40, 0x27, 0xdb, 3365 0xc0, 0xee, 0xce, 0x1d, 0x18, 0x5f, 0xe6, 0x7a, 0x7d, 0x97, 0xeb, 0xe3,
3361 0x74, 0x1c, 0x74, 0xbc, 0x74, 0x7c, 0x10, 0xc7, 0xf0, 0x3a, 0x62, 0xeb, 3366 0x16, 0x0d, 0x38, 0x59, 0x4b, 0x7c, 0x24, 0xf6, 0x9e, 0x53, 0xfb, 0xd3,
3362 0xe8, 0x5f, 0x47, 0x7d, 0xa4, 0xad, 0x7f, 0x41, 0xe3, 0x0f, 0xfb, 0x77, 3367 0xbe, 0xfa, 0x34, 0xf3, 0xf9, 0xb2, 0x87, 0xed, 0xac, 0x22, 0x3f, 0x26,
3363 0x47, 0x14, 0xff, 0xeb, 0xe2, 0x2a, 0xe1, 0x50, 0x88, 0x1f, 0x98, 0x66, 3368 0xee, 0x50, 0x3d, 0xf0, 0x8a, 0xa6, 0xc5, 0x12, 0xcb, 0x0c, 0xde, 0x58,
3364 0xfb, 0x15, 0x07, 0xc0, 0xcc, 0x57, 0x8e, 0x5f, 0x01, 0x4f, 0xb7, 0xeb, 3369 0x9f, 0x17, 0x80, 0xad, 0x7e, 0xa6, 0x21, 0x96, 0xeb, 0x67, 0x4c, 0xfb,
3365 0x7a, 0xae, 0xe3, 0x65, 0xcd, 0xd7, 0xd8, 0x32, 0xdc, 0x66, 0xeb, 0xb2, 3370 0xaa, 0x78, 0x7d, 0x1b, 0xc6, 0x7e, 0xae, 0x67, 0x83, 0xac, 0xd7, 0xd1,
3366 0xb6, 0x53, 0xf1, 0x47, 0x18, 0x8f, 0x3e, 0xd1, 0xb5, 0x0d, 0xf7, 0xdc, 3371 0x5a, 0x60, 0x38, 0x86, 0x3e, 0x61, 0x9c, 0xee, 0x85, 0x48, 0xa2, 0x77,
3367 0xa0, 0x17, 0x75, 0x3f, 0xe8, 0xb5, 0xc6, 0x4b, 0xe2, 0xa2, 0xd0, 0xab, 3372 0x14, 0xf6, 0x74, 0xad, 0x87, 0xbd, 0xf7, 0x98, 0x07, 0xc6, 0xf0, 0x89,
3368 0x86, 0x35, 0x25, 0x85, 0x64, 0xcf, 0xa9, 0x4b, 0xdf, 0xd2, 0xf2, 0xfb, 3373 0x3e, 0xba, 0x77, 0xc2, 0xfd, 0xe8, 0x33, 0xc2, 0xbe, 0x3e, 0xd8, 0xd1,
3369 0xd3, 0x45, 0x98, 0x2f, 0xdf, 0x19, 0x22, 0x7f, 0x4c, 0x01, 0xcf, 0xef, 3374 0x35, 0x8d, 0xf1, 0xbd, 0xe7, 0x80, 0x7f, 0x3d, 0x8f, 0x75, 0xfb, 0x0e,
3370 0x4e, 0x82, 0xbe, 0x23, 0x5e, 0xc0, 0xfe, 0x92, 0x13, 0x74, 0x0f, 0xf4, 3375 0x30, 0x3f, 0xeb, 0x9d, 0xd7, 0x75, 0xfe, 0x09, 0xb9, 0xee, 0x5a, 0x79,
3371 0x95, 0x33, 0x3e, 0x2b, 0x50, 0x27, 0x92, 0xd3, 0x74, 0x2f, 0x59, 0x5a, 3376 0xfe, 0xbb, 0xc3, 0xdc, 0x7f, 0x88, 0x14, 0xf5, 0x3b, 0xef, 0xe8, 0xd3,
3372 0x12, 0x01, 0x45, 0x3d, 0x66, 0xbf, 0x01, 0x3e, 0xdd, 0x96, 0x38, 0x3f, 3377 0x3c, 0xde, 0xc5, 0xf7, 0xe2, 0x2d, 0xee, 0x17, 0xba, 0x72, 0xfa, 0x85,
3373 0x08, 0xaf, 0x74, 0xaf, 0x94, 0x78, 0xc4, 0x76, 0xc6, 0xad, 0x2f, 0x17, 3378 0x09, 0xd4, 0xe9, 0xe1, 0xe9, 0x8c, 0x9c, 0x30, 0xea, 0x65, 0xbe, 0x93,
3374 0xb7, 0xda, 0x1f, 0x15, 0xce, 0xbc, 0x38, 0xdd, 0x60, 0xc7, 0xa9, 0x87, 3379 0x7f, 0xf5, 0x44, 0x09, 0xfb, 0xad, 0x78, 0x15, 0xf0, 0xd8, 0x2a, 0xdc,
3375 0x71, 0x7a, 0xcf, 0xec, 0xef, 0xcb, 0xe5, 0xa2, 0xcf, 0x5f, 0xfc, 0xdf, 3380 0xd7, 0x5d, 0xfb, 0x99, 0x9f, 0x46, 0xf2, 0xd3, 0xf2, 0xa9, 0xd1, 0xdc,
3376 0x70, 0x0b, 0xba, 0xbd, 0x41, 0x9d, 0x5f, 0xbe, 0xac, 0x1e, 0xd7, 0xda, 3381 0xf5, 0x32, 0x7e, 0x3a, 0x8d, 0xf8, 0x51, 0xe7, 0x40, 0x3e, 0x19, 0x92,
3377 0xe2, 0xdc, 0x7c, 0x5f, 0xeb, 0x75, 0xc2, 0x63, 0x5d, 0x6f, 0x31, 0xfb, 3382 0xf3, 0xf7, 0xcc, 0xba, 0x3f, 0x41, 0x7a, 0x57, 0x0c, 0x4f, 0xd3, 0xfa,
3378 0xd9, 0x11, 0x7e, 0xe7, 0x65, 0x0c, 0xfa, 0x11, 0xbd, 0x93, 0xa4, 0xa1, 3383 0x72, 0x51, 0x44, 0xf1, 0x57, 0x16, 0x9e, 0x82, 0x1d, 0x89, 0x41, 0xb6,
3379 0x51, 0x79, 0x56, 0xf1, 0x35, 0x45, 0x8f, 0x70, 0xbd, 0xbd, 0xe4, 0x42, 3384 0xbf, 0x67, 0x2d, 0x70, 0x3f, 0xfb, 0x5f, 0xf9, 0xf5, 0xca, 0x1a, 0x9d,
3380 0xbd, 0x19, 0x38, 0x80, 0xf1, 0x65, 0xae, 0x1f, 0x77, 0xd7, 0x50, 0x5d, 3385 0xd6, 0x8d, 0xf7, 0xe2, 0x1c, 0x95, 0x3f, 0xb9, 0xfd, 0xb0, 0x8a, 0x87,
3381 0x8e, 0x1e, 0x39, 0xaf, 0xe5, 0x91, 0x1c, 0x23, 0xc3, 0x75, 0xfd, 0x79, 3386 0xb2, 0x06, 0x1a, 0x8b, 0xce, 0x7d, 0xf2, 0x9c, 0x90, 0xe1, 0x47, 0x19,
3382 0x17, 0xd7, 0x5b, 0xf2, 0x9b, 0x3b, 0xfa, 0x07, 0xdd, 0x67, 0xdc, 0xa2, 3387 0x47, 0x06, 0x47, 0x7c, 0x5f, 0xdb, 0xe3, 0x44, 0xc6, 0x91, 0x8a, 0x57,
3383 0xeb, 0x49, 0x45, 0x2b, 0x65, 0xfd, 0xe6, 0xf3, 0x9f, 0x01, 0xed, 0xf5, 3388 0x6b, 0x7c, 0x59, 0xe3, 0xc7, 0x1e, 0x37, 0x61, 0xba, 0x57, 0x8c, 0x22,
3384 0x82, 0x8a, 0x66, 0x7b, 0x3c, 0x84, 0x69, 0x17, 0x46, 0x9e, 0x7a, 0x96, 3389 0x90, 0xa6, 0x77, 0x44, 0x62, 0x70, 0xe0, 0xc1, 0xfc, 0x9d, 0x00, 0x7f,
3385 0xd3, 0x87, 0xb1, 0x97, 0xef, 0x65, 0xd3, 0xec, 0xa7, 0x20, 0xf9, 0xa3, 3390 0x09, 0xd6, 0x5b, 0x4f, 0x51, 0x1f, 0xfa, 0x94, 0xe8, 0x67, 0x3f, 0x4e,
3386 0x58, 0xda, 0xa9, 0x68, 0x28, 0x3a, 0x9a, 0x86, 0xfe, 0x43, 0x5b, 0x61, 3391 0xd4, 0x72, 0xde, 0x57, 0xc1, 0x8f, 0x3d, 0xcf, 0x40, 0x9f, 0x1e, 0xce,
3387 0xdf, 0x22, 0xdb, 0xcd, 0x34, 0xf8, 0xf6, 0x18, 0xe1, 0x2f, 0x38, 0x8e, 3392 0x9f, 0xdb, 0xdc, 0x5f, 0xc0, 0xff, 0x7e, 0xbd, 0x63, 0x94, 0xfd, 0xcd,
3388 0x77, 0x48, 0xd0, 0x33, 0x06, 0x3b, 0x86, 0x32, 0x18, 0x2f, 0x6e, 0x06, 3393 0x71, 0xb8, 0x8b, 0x79, 0xb8, 0x05, 0x1e, 0x74, 0xc5, 0x43, 0xca, 0xe4,
3389 0xfd, 0x6b, 0x0b, 0xf6, 0x1d, 0x3d, 0xce, 0xfe, 0xd8, 0x9a, 0x7f, 0xdf, 3394 0x41, 0xd5, 0x19, 0xeb, 0x3e, 0x85, 0x46, 0x1c, 0x49, 0x5c, 0xa0, 0x5f,
3390 0xc0, 0x3d, 0xf0, 0x0d, 0x37, 0xa9, 0xf3, 0x07, 0x67, 0xf8, 0xfd, 0x22, 3395 0xa1, 0x3e, 0x2c, 0x8f, 0xed, 0x36, 0xe4, 0x1a, 0xa4, 0x7d, 0x61, 0xb6,
3391 0xe2, 0x2e, 0x35, 0x8e, 0x1b, 0x19, 0x1e, 0x1f, 0xe2, 0xfa, 0x7e, 0x9b, 3396 0x2f, 0x24, 0x76, 0x2e, 0xb7, 0xae, 0x0b, 0xf2, 0xba, 0x80, 0xb1, 0x0e,
3392 0xdf, 0x1b, 0x43, 0x39, 0xef, 0x8d, 0x79, 0xdc, 0x33, 0x67, 0x32, 0x49, 3397 0xf3, 0xc8, 0x53, 0x7d, 0x1e, 0x7e, 0x25, 0x8f, 0x6a, 0xdf, 0xdc, 0x7c,
3393 0xe0, 0x22, 0x51, 0x98, 0xfb, 0x5e, 0x55, 0xe3, 0x9a, 0x68, 0x39, 0xc7, 3398 0xb4, 0xf2, 0x49, 0x15, 0x9a, 0xfe, 0x50, 0x87, 0x0c, 0xbf, 0x51, 0xbd,
3394 0xa9, 0x6c, 0x3d, 0xe8, 0xe4, 0x7a, 0xbc, 0x13, 0x86, 0x8e, 0xb1, 0x5f, 3399 0xd2, 0xcd, 0xfa, 0x73, 0x97, 0xea, 0x79, 0xe0, 0x64, 0x37, 0xea, 0xc5,
3395 0x3a, 0x28, 0x4e, 0xad, 0x0b, 0xe9, 0x95, 0xde, 0xc9, 0xe0, 0x9b, 0xe2, 3400 0xc9, 0xee, 0xd3, 0x7c, 0xff, 0x32, 0x2f, 0x2d, 0xf4, 0x6e, 0x30, 0xb8,
3396 0x73, 0xc3, 0xdc, 0x4f, 0xc2, 0xc8, 0x3f, 0x51, 0x91, 0xe4, 0x77, 0xcb, 3401 0xab, 0xb2, 0xd7, 0x1f, 0xbb, 0x1e, 0x15, 0x16, 0x3d, 0xd4, 0xb9, 0x0f,
3397 0x04, 0xee, 0x9d, 0x53, 0x06, 0x68, 0x38, 0xa0, 0xf5, 0x45, 0x3e, 0x26, 3402 0xeb, 0x0f, 0xd0, 0x9f, 0x6e, 0xa0, 0xfe, 0x40, 0x33, 0xfb, 0x6c, 0xfb,
3398 0x52, 0xc8, 0x3b, 0xac, 0x3b, 0x2c, 0xeb, 0x7c, 0x1f, 0x59, 0xf6, 0xce, 3403 0x3d, 0x72, 0xeb, 0xfe, 0xe3, 0xde, 0x23, 0x5b, 0x1a, 0xac, 0xe7, 0xc5,
3399 0x51, 0x74, 0xd1, 0x51, 0xea, 0xd0, 0x76, 0x62, 0xb5, 0x3f, 0xa0, 0xf0, 3404 0xc4, 0xd8, 0x08, 0xce, 0x69, 0xe1, 0x7b, 0x7b, 0x3b, 0xe7, 0xf7, 0xb5,
3400 0x7b, 0xd3, 0xcc, 0xab, 0x79, 0xf2, 0x5b, 0xf5, 0x4c, 0x86, 0xf4, 0xaf, 3405 0x40, 0x84, 0xce, 0x4d, 0xbe, 0x46, 0xf6, 0x8a, 0x68, 0x10, 0xf6, 0x25,
3401 0x12, 0xa5, 0xd4, 0x87, 0x2b, 0x83, 0x0b, 0xf0, 0x63, 0x74, 0x9a, 0xfd, 3406 0x5f, 0xc7, 0xf7, 0x64, 0x08, 0xf3, 0xe5, 0x21, 0xfc, 0x3e, 0xd0, 0xe2,
3402 0x3f, 0xb2, 0x09, 0xf4, 0x18, 0xe3, 0x4f, 0xe3, 0xea, 0xca, 0x46, 0x83, 3407 0xd7, 0x49, 0xbe, 0x3c, 0x04, 0x8c, 0x72, 0x5d, 0x18, 0x33, 0xdf, 0x11,
3403 0xf6, 0xcd, 0x8d, 0xe2, 0x1c, 0x7d, 0x8f, 0xc8, 0x7d, 0x8f, 0x6b, 0x3c, 3408 0xc0, 0x21, 0xdf, 0x7c, 0xef, 0x08, 0xbc, 0xc7, 0xce, 0xfb, 0x50, 0x37,
3404 0x56, 0xb6, 0xa3, 0x90, 0x0e, 0x1c, 0x55, 0xe7, 0x04, 0x24, 0x8e, 0x94, 3409 0x44, 0x0c, 0xfd, 0x73, 0x53, 0x8d, 0x4e, 0xdf, 0x5b, 0x63, 0xb8, 0x9f,
3405 0xfe, 0xd2, 0x27, 0x9c, 0x8f, 0x76, 0x9c, 0x2a, 0x1c, 0xeb, 0xfc, 0xb0, 3410 0x51, 0x97, 0xe7, 0xda, 0x55, 0x81, 0x78, 0x2d, 0xcf, 0xbe, 0x37, 0xac,
3406 0xe2, 0x3b, 0x37, 0xdf, 0xb3, 0x78, 0x0d, 0xd2, 0xbd, 0x5c, 0x16, 0xb9, 3411 0xef, 0x12, 0x3d, 0x31, 0x68, 0xf6, 0xfd, 0x76, 0x3d, 0x90, 0x67, 0x72,
3407 0x04, 0xbf, 0x9b, 0xf8, 0x7e, 0xb0, 0x52, 0xfc, 0xde, 0x46, 0xfc, 0xa2, 3412 0x7f, 0x1a, 0x1a, 0xfd, 0xf5, 0xa3, 0xbc, 0x47, 0x3c, 0xdc, 0xaf, 0xdd,
3408 0xac, 0xb7, 0x11, 0x1f, 0x43, 0x5f, 0x1c, 0x67, 0x1c, 0xcd, 0x37, 0xf1, 3413 0x99, 0x45, 0xbc, 0x16, 0x89, 0x0b, 0x23, 0xe0, 0x61, 0x6c, 0xc4, 0x29,
3409 0xfd, 0x87, 0xf5, 0xfb, 0x8d, 0xdf, 0x67, 0xc0, 0x9b, 0xd7, 0x88, 0xa5, 3414 0x8f, 0xa5, 0x1e, 0xea, 0x1c, 0xd8, 0xa5, 0xec, 0xcc, 0x9e, 0x0b, 0xbd,
3410 0x19, 0x5f, 0x8c, 0xfb, 0x43, 0x6c, 0xf7, 0x6d, 0xd8, 0x6d, 0x68, 0xbb, 3415 0x76, 0xb0, 0xfe, 0xbf, 0xd2, 0xef, 0x17, 0x51, 0xb6, 0x57, 0xee, 0x8b,
3411 0xe3, 0xa6, 0xdd, 0xfa, 0x7e, 0x65, 0x95, 0x53, 0x22, 0x71, 0xab, 0xe8, 3416 0xf9, 0x8d, 0xf4, 0x6e, 0xca, 0x13, 0x69, 0x73, 0x6c, 0x7f, 0xcf, 0xb4,
3412 0x2a, 0xe3, 0x0a, 0xd5, 0xb3, 0x02, 0xb6, 0x53, 0xf2, 0xb5, 0x2b, 0x7b, 3417 0x90, 0x5e, 0x85, 0x7c, 0xaf, 0x47, 0x2d, 0xfd, 0x07, 0xe4, 0x8b, 0xeb,
3413 0x82, 0x6c, 0x4f, 0x40, 0x1c, 0x6c, 0xb5, 0xee, 0x2b, 0xe2, 0x7d, 0x7e, 3418 0x81, 0xc7, 0xea, 0x95, 0xdf, 0x94, 0x7f, 0x95, 0x3f, 0xe1, 0xf7, 0xe8,
3414 0xb9, 0x0f, 0xf3, 0xa8, 0x0b, 0xc6, 0x0a, 0xfe, 0x54, 0x7e, 0xd3, 0x72, 3419 0x4a, 0x12, 0x6b, 0x4c, 0xae, 0xa4, 0x84, 0xaf, 0x4f, 0x4e, 0xa9, 0x7b,
3415 0x73, 0xf3, 0xde, 0xea, 0x3f, 0xba, 0x91, 0xd2, 0x07, 0xf5, 0x4d, 0xc6, 3420 0x1e, 0xeb, 0xb7, 0xc4, 0xa5, 0xfc, 0x07, 0xe2, 0xfb, 0x38, 0x2e, 0xd6,
3416 0xa9, 0x05, 0xff, 0x1f, 0xe8, 0xfa, 0x76, 0x97, 0xee, 0xaf, 0xfe, 0x33, 3421 0x9f, 0x19, 0xb3, 0xfd, 0xbd, 0xe0, 0x3f, 0xeb, 0x3b, 0xc1, 0x23, 0xce,
3417 0xc3, 0xa8, 0x4f, 0x67, 0x86, 0xcf, 0xf2, 0xbb, 0x83, 0xfd, 0xd2, 0x43, 3422 0xe7, 0xf1, 0x74, 0x83, 0xea, 0x7b, 0xe7, 0x7b, 0xef, 0x48, 0x3b, 0x3e,
3418 0xff, 0x5b, 0xc8, 0xd8, 0xd5, 0xdb, 0xeb, 0x9b, 0x5d, 0x8f, 0x6a, 0x8b, 3423 0xba, 0x9f, 0xdb, 0x47, 0x67, 0xfb, 0x60, 0x65, 0xaf, 0x5c, 0x57, 0xcf,
3419 0x1e, 0xfa, 0xdc, 0x7f, 0x00, 0x5a, 0x33, 0xe6, 0xc0, 0x30, 0x14, 0x00, 3424 0x71, 0xac, 0x89, 0xa6, 0x0d, 0xf8, 0x7d, 0x23, 0xec, 0x47, 0xde, 0x84,
3420 0x00, 0x00 }; 3425 0xfd, 0x4e, 0xef, 0x52, 0x23, 0x8e, 0xf2, 0xa9, 0x60, 0x2c, 0x2c, 0xcc,
3426 0x27, 0xfb, 0x8e, 0x5c, 0xbc, 0x44, 0x62, 0x9f, 0x0d, 0x06, 0x31, 0x5f,
3427 0xd2, 0x84, 0x63, 0xbc, 0x14, 0xf7, 0x1e, 0x71, 0x08, 0x79, 0xf1, 0xe9,
3428 0x31, 0xe0, 0x27, 0xe2, 0x55, 0xec, 0x53, 0x78, 0x90, 0xee, 0x53, 0xad,
3429 0x04, 0x34, 0x67, 0x06, 0x39, 0xde, 0x4b, 0xdd, 0xf4, 0xfb, 0xe2, 0xac,
3430 0x08, 0x49, 0xf4, 0x99, 0xf9, 0x8b, 0xb8, 0xf6, 0x5a, 0xfc, 0xff, 0xa8,
3431 0x71, 0x4e, 0xf5, 0xc9, 0x88, 0x63, 0x6c, 0xc3, 0xf1, 0xae, 0xe5, 0xc6,
3432 0xbb, 0xe2, 0xa9, 0xd4, 0xed, 0x18, 0xdf, 0xab, 0xe7, 0xc6, 0xb7, 0xd2,
3433 0x4f, 0xf2, 0x7d, 0xd7, 0xbc, 0x3f, 0xe7, 0xee, 0x8f, 0xf7, 0xd3, 0x85,
3434 0x27, 0x16, 0xdf, 0xc0, 0x8d, 0xd5, 0xf2, 0xfc, 0x92, 0x39, 0x7d, 0x72,
3435 0x6e, 0xfe, 0xa1, 0xde, 0xbd, 0x61, 0xc4, 0xc3, 0x7f, 0x69, 0x4a, 0x77,
3436 0x8f, 0xc8, 0x15, 0x00, 0x00, 0x00 };
3421 3437
3422static u8 bnx2_TPAT_b09FwText[] = { 3438static u8 bnx2_TPAT_b09FwText[] = {
3423 0xbd, 0x58, 0x5d, 0x6c, 0x1c, 0xd5, 0x15, 0x3e, 0x73, 0x67, 0xd6, 0x3b, 3439 0xbd, 0x58, 0x5d, 0x6c, 0x1c, 0xd5, 0x15, 0x3e, 0x73, 0x67, 0xd6, 0x3b,
diff --git a/drivers/net/eepro.c b/drivers/net/eepro.c
index 83bda6ccde98..56f50491a453 100644
--- a/drivers/net/eepro.c
+++ b/drivers/net/eepro.c
@@ -633,7 +633,7 @@ static void __init printEEPROMInfo(struct net_device *dev)
633 printk(KERN_DEBUG " PC: %d\n", GetBit(Word,ee_PC)); 633 printk(KERN_DEBUG " PC: %d\n", GetBit(Word,ee_PC));
634 printk(KERN_DEBUG " TPE/AUI: %d\n", GetBit(Word,ee_TPE_AUI)); 634 printk(KERN_DEBUG " TPE/AUI: %d\n", GetBit(Word,ee_TPE_AUI));
635 printk(KERN_DEBUG " Jabber: %d\n", GetBit(Word,ee_Jabber)); 635 printk(KERN_DEBUG " Jabber: %d\n", GetBit(Word,ee_Jabber));
636 printk(KERN_DEBUG " AutoPort: %d\n", GetBit(!Word,ee_Jabber)); 636 printk(KERN_DEBUG " AutoPort: %d\n", !GetBit(Word,ee_AutoPort));
637 printk(KERN_DEBUG " Duplex: %d\n", GetBit(Word,ee_Duplex)); 637 printk(KERN_DEBUG " Duplex: %d\n", GetBit(Word,ee_Duplex));
638 } 638 }
639 639
diff --git a/drivers/net/fec.c b/drivers/net/fec.c
index d7a3ea88eddb..32a4f17d35fc 100644
--- a/drivers/net/fec.c
+++ b/drivers/net/fec.c
@@ -67,6 +67,10 @@
67#define FEC_MAX_PORTS 1 67#define FEC_MAX_PORTS 1
68#endif 68#endif
69 69
70#if defined(CONFIG_FADS) || defined(CONFIG_RPXCLASSIC) || defined(CONFIG_M5272)
71#define HAVE_mii_link_interrupt
72#endif
73
70/* 74/*
71 * Define the fixed address of the FEC hardware. 75 * Define the fixed address of the FEC hardware.
72 */ 76 */
@@ -205,7 +209,10 @@ struct fec_enet_private {
205 cbd_t *cur_rx, *cur_tx; /* The next free ring entry */ 209 cbd_t *cur_rx, *cur_tx; /* The next free ring entry */
206 cbd_t *dirty_tx; /* The ring entries to be free()ed. */ 210 cbd_t *dirty_tx; /* The ring entries to be free()ed. */
207 uint tx_full; 211 uint tx_full;
208 spinlock_t lock; 212 /* hold while accessing the HW like ringbuffer for tx/rx but not MAC */
213 spinlock_t hw_lock;
214 /* hold while accessing the mii_list_t() elements */
215 spinlock_t mii_lock;
209 216
210 uint phy_id; 217 uint phy_id;
211 uint phy_id_done; 218 uint phy_id_done;
@@ -309,6 +316,7 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
309 volatile fec_t *fecp; 316 volatile fec_t *fecp;
310 volatile cbd_t *bdp; 317 volatile cbd_t *bdp;
311 unsigned short status; 318 unsigned short status;
319 unsigned long flags;
312 320
313 fep = netdev_priv(dev); 321 fep = netdev_priv(dev);
314 fecp = (volatile fec_t*)dev->base_addr; 322 fecp = (volatile fec_t*)dev->base_addr;
@@ -318,6 +326,7 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
318 return 1; 326 return 1;
319 } 327 }
320 328
329 spin_lock_irqsave(&fep->hw_lock, flags);
321 /* Fill in a Tx ring entry */ 330 /* Fill in a Tx ring entry */
322 bdp = fep->cur_tx; 331 bdp = fep->cur_tx;
323 332
@@ -328,6 +337,7 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
328 * This should not happen, since dev->tbusy should be set. 337 * This should not happen, since dev->tbusy should be set.
329 */ 338 */
330 printk("%s: tx queue full!.\n", dev->name); 339 printk("%s: tx queue full!.\n", dev->name);
340 spin_unlock_irqrestore(&fep->hw_lock, flags);
331 return 1; 341 return 1;
332 } 342 }
333#endif 343#endif
@@ -366,8 +376,6 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
366 flush_dcache_range((unsigned long)skb->data, 376 flush_dcache_range((unsigned long)skb->data,
367 (unsigned long)skb->data + skb->len); 377 (unsigned long)skb->data + skb->len);
368 378
369 spin_lock_irq(&fep->lock);
370
371 /* Send it on its way. Tell FEC it's ready, interrupt when done, 379 /* Send it on its way. Tell FEC it's ready, interrupt when done,
372 * it's the last BD of the frame, and to put the CRC on the end. 380 * it's the last BD of the frame, and to put the CRC on the end.
373 */ 381 */
@@ -396,7 +404,7 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
396 404
397 fep->cur_tx = (cbd_t *)bdp; 405 fep->cur_tx = (cbd_t *)bdp;
398 406
399 spin_unlock_irq(&fep->lock); 407 spin_unlock_irqrestore(&fep->hw_lock, flags);
400 408
401 return 0; 409 return 0;
402} 410}
@@ -454,19 +462,20 @@ fec_enet_interrupt(int irq, void * dev_id)
454 struct net_device *dev = dev_id; 462 struct net_device *dev = dev_id;
455 volatile fec_t *fecp; 463 volatile fec_t *fecp;
456 uint int_events; 464 uint int_events;
457 int handled = 0; 465 irqreturn_t ret = IRQ_NONE;
458 466
459 fecp = (volatile fec_t*)dev->base_addr; 467 fecp = (volatile fec_t*)dev->base_addr;
460 468
461 /* Get the interrupt events that caused us to be here. 469 /* Get the interrupt events that caused us to be here.
462 */ 470 */
463 while ((int_events = fecp->fec_ievent) != 0) { 471 do {
472 int_events = fecp->fec_ievent;
464 fecp->fec_ievent = int_events; 473 fecp->fec_ievent = int_events;
465 474
466 /* Handle receive event in its own function. 475 /* Handle receive event in its own function.
467 */ 476 */
468 if (int_events & FEC_ENET_RXF) { 477 if (int_events & FEC_ENET_RXF) {
469 handled = 1; 478 ret = IRQ_HANDLED;
470 fec_enet_rx(dev); 479 fec_enet_rx(dev);
471 } 480 }
472 481
@@ -475,17 +484,18 @@ fec_enet_interrupt(int irq, void * dev_id)
475 them as part of the transmit process. 484 them as part of the transmit process.
476 */ 485 */
477 if (int_events & FEC_ENET_TXF) { 486 if (int_events & FEC_ENET_TXF) {
478 handled = 1; 487 ret = IRQ_HANDLED;
479 fec_enet_tx(dev); 488 fec_enet_tx(dev);
480 } 489 }
481 490
482 if (int_events & FEC_ENET_MII) { 491 if (int_events & FEC_ENET_MII) {
483 handled = 1; 492 ret = IRQ_HANDLED;
484 fec_enet_mii(dev); 493 fec_enet_mii(dev);
485 } 494 }
486 495
487 } 496 } while (int_events);
488 return IRQ_RETVAL(handled); 497
498 return ret;
489} 499}
490 500
491 501
@@ -498,7 +508,7 @@ fec_enet_tx(struct net_device *dev)
498 struct sk_buff *skb; 508 struct sk_buff *skb;
499 509
500 fep = netdev_priv(dev); 510 fep = netdev_priv(dev);
501 spin_lock(&fep->lock); 511 spin_lock_irq(&fep->hw_lock);
502 bdp = fep->dirty_tx; 512 bdp = fep->dirty_tx;
503 513
504 while (((status = bdp->cbd_sc) & BD_ENET_TX_READY) == 0) { 514 while (((status = bdp->cbd_sc) & BD_ENET_TX_READY) == 0) {
@@ -557,7 +567,7 @@ fec_enet_tx(struct net_device *dev)
557 } 567 }
558 } 568 }
559 fep->dirty_tx = (cbd_t *)bdp; 569 fep->dirty_tx = (cbd_t *)bdp;
560 spin_unlock(&fep->lock); 570 spin_unlock_irq(&fep->hw_lock);
561} 571}
562 572
563 573
@@ -584,6 +594,8 @@ fec_enet_rx(struct net_device *dev)
584 fep = netdev_priv(dev); 594 fep = netdev_priv(dev);
585 fecp = (volatile fec_t*)dev->base_addr; 595 fecp = (volatile fec_t*)dev->base_addr;
586 596
597 spin_lock_irq(&fep->hw_lock);
598
587 /* First, grab all of the stats for the incoming packet. 599 /* First, grab all of the stats for the incoming packet.
588 * These get messed up if we get called due to a busy condition. 600 * These get messed up if we get called due to a busy condition.
589 */ 601 */
@@ -689,6 +701,8 @@ while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) {
689 */ 701 */
690 fecp->fec_r_des_active = 0; 702 fecp->fec_r_des_active = 0;
691#endif 703#endif
704
705 spin_unlock_irq(&fep->hw_lock);
692} 706}
693 707
694 708
@@ -702,11 +716,11 @@ fec_enet_mii(struct net_device *dev)
702 uint mii_reg; 716 uint mii_reg;
703 717
704 fep = netdev_priv(dev); 718 fep = netdev_priv(dev);
719 spin_lock_irq(&fep->mii_lock);
720
705 ep = fep->hwp; 721 ep = fep->hwp;
706 mii_reg = ep->fec_mii_data; 722 mii_reg = ep->fec_mii_data;
707 723
708 spin_lock(&fep->lock);
709
710 if ((mip = mii_head) == NULL) { 724 if ((mip = mii_head) == NULL) {
711 printk("MII and no head!\n"); 725 printk("MII and no head!\n");
712 goto unlock; 726 goto unlock;
@@ -723,7 +737,7 @@ fec_enet_mii(struct net_device *dev)
723 ep->fec_mii_data = mip->mii_regval; 737 ep->fec_mii_data = mip->mii_regval;
724 738
725unlock: 739unlock:
726 spin_unlock(&fep->lock); 740 spin_unlock_irq(&fep->mii_lock);
727} 741}
728 742
729static int 743static int
@@ -737,12 +751,11 @@ mii_queue(struct net_device *dev, int regval, void (*func)(uint, struct net_devi
737 /* Add PHY address to register command. 751 /* Add PHY address to register command.
738 */ 752 */
739 fep = netdev_priv(dev); 753 fep = netdev_priv(dev);
740 regval |= fep->phy_addr << 23; 754 spin_lock_irqsave(&fep->mii_lock, flags);
741 755
756 regval |= fep->phy_addr << 23;
742 retval = 0; 757 retval = 0;
743 758
744 spin_lock_irqsave(&fep->lock,flags);
745
746 if ((mip = mii_free) != NULL) { 759 if ((mip = mii_free) != NULL) {
747 mii_free = mip->mii_next; 760 mii_free = mip->mii_next;
748 mip->mii_regval = regval; 761 mip->mii_regval = regval;
@@ -759,9 +772,8 @@ mii_queue(struct net_device *dev, int regval, void (*func)(uint, struct net_devi
759 retval = 1; 772 retval = 1;
760 } 773 }
761 774
762 spin_unlock_irqrestore(&fep->lock,flags); 775 spin_unlock_irqrestore(&fep->mii_lock, flags);
763 776 return retval;
764 return(retval);
765} 777}
766 778
767static void mii_do_cmd(struct net_device *dev, const phy_cmd_t *c) 779static void mii_do_cmd(struct net_device *dev, const phy_cmd_t *c)
@@ -1222,7 +1234,7 @@ static phy_info_t const * const phy_info[] = {
1222}; 1234};
1223 1235
1224/* ------------------------------------------------------------------------- */ 1236/* ------------------------------------------------------------------------- */
1225#if !defined(CONFIG_M532x) 1237#ifdef HAVE_mii_link_interrupt
1226#ifdef CONFIG_RPXCLASSIC 1238#ifdef CONFIG_RPXCLASSIC
1227static void 1239static void
1228mii_link_interrupt(void *dev_id); 1240mii_link_interrupt(void *dev_id);
@@ -1362,18 +1374,8 @@ static void __inline__ fec_request_intrs(struct net_device *dev)
1362 unsigned short irq; 1374 unsigned short irq;
1363 } *idp, id[] = { 1375 } *idp, id[] = {
1364 { "fec(TXF)", 23 }, 1376 { "fec(TXF)", 23 },
1365 { "fec(TXB)", 24 },
1366 { "fec(TXFIFO)", 25 },
1367 { "fec(TXCR)", 26 },
1368 { "fec(RXF)", 27 }, 1377 { "fec(RXF)", 27 },
1369 { "fec(RXB)", 28 },
1370 { "fec(MII)", 29 }, 1378 { "fec(MII)", 29 },
1371 { "fec(LC)", 30 },
1372 { "fec(HBERR)", 31 },
1373 { "fec(GRA)", 32 },
1374 { "fec(EBERR)", 33 },
1375 { "fec(BABT)", 34 },
1376 { "fec(BABR)", 35 },
1377 { NULL }, 1379 { NULL },
1378 }; 1380 };
1379 1381
@@ -1533,18 +1535,8 @@ static void __inline__ fec_request_intrs(struct net_device *dev)
1533 unsigned short irq; 1535 unsigned short irq;
1534 } *idp, id[] = { 1536 } *idp, id[] = {
1535 { "fec(TXF)", 23 }, 1537 { "fec(TXF)", 23 },
1536 { "fec(TXB)", 24 },
1537 { "fec(TXFIFO)", 25 },
1538 { "fec(TXCR)", 26 },
1539 { "fec(RXF)", 27 }, 1538 { "fec(RXF)", 27 },
1540 { "fec(RXB)", 28 },
1541 { "fec(MII)", 29 }, 1539 { "fec(MII)", 29 },
1542 { "fec(LC)", 30 },
1543 { "fec(HBERR)", 31 },
1544 { "fec(GRA)", 32 },
1545 { "fec(EBERR)", 33 },
1546 { "fec(BABT)", 34 },
1547 { "fec(BABR)", 35 },
1548 { NULL }, 1540 { NULL },
1549 }; 1541 };
1550 1542
@@ -1660,18 +1652,8 @@ static void __inline__ fec_request_intrs(struct net_device *dev)
1660 unsigned short irq; 1652 unsigned short irq;
1661 } *idp, id[] = { 1653 } *idp, id[] = {
1662 { "fec(TXF)", 36 }, 1654 { "fec(TXF)", 36 },
1663 { "fec(TXB)", 37 },
1664 { "fec(TXFIFO)", 38 },
1665 { "fec(TXCR)", 39 },
1666 { "fec(RXF)", 40 }, 1655 { "fec(RXF)", 40 },
1667 { "fec(RXB)", 41 },
1668 { "fec(MII)", 42 }, 1656 { "fec(MII)", 42 },
1669 { "fec(LC)", 43 },
1670 { "fec(HBERR)", 44 },
1671 { "fec(GRA)", 45 },
1672 { "fec(EBERR)", 46 },
1673 { "fec(BABT)", 47 },
1674 { "fec(BABR)", 48 },
1675 { NULL }, 1657 { NULL },
1676 }; 1658 };
1677 1659
@@ -2126,6 +2108,7 @@ mii_discover_phy(uint mii_reg, struct net_device *dev)
2126 2108
2127/* This interrupt occurs when the PHY detects a link change. 2109/* This interrupt occurs when the PHY detects a link change.
2128*/ 2110*/
2111#ifdef HAVE_mii_link_interrupt
2129#ifdef CONFIG_RPXCLASSIC 2112#ifdef CONFIG_RPXCLASSIC
2130static void 2113static void
2131mii_link_interrupt(void *dev_id) 2114mii_link_interrupt(void *dev_id)
@@ -2148,6 +2131,7 @@ mii_link_interrupt(int irq, void * dev_id)
2148 2131
2149 return IRQ_HANDLED; 2132 return IRQ_HANDLED;
2150} 2133}
2134#endif
2151 2135
2152static int 2136static int
2153fec_enet_open(struct net_device *dev) 2137fec_enet_open(struct net_device *dev)
@@ -2243,13 +2227,13 @@ static void set_multicast_list(struct net_device *dev)
2243 /* Catch all multicast addresses, so set the 2227 /* Catch all multicast addresses, so set the
2244 * filter to all 1's. 2228 * filter to all 1's.
2245 */ 2229 */
2246 ep->fec_hash_table_high = 0xffffffff; 2230 ep->fec_grp_hash_table_high = 0xffffffff;
2247 ep->fec_hash_table_low = 0xffffffff; 2231 ep->fec_grp_hash_table_low = 0xffffffff;
2248 } else { 2232 } else {
2249 /* Clear filter and add the addresses in hash register. 2233 /* Clear filter and add the addresses in hash register.
2250 */ 2234 */
2251 ep->fec_hash_table_high = 0; 2235 ep->fec_grp_hash_table_high = 0;
2252 ep->fec_hash_table_low = 0; 2236 ep->fec_grp_hash_table_low = 0;
2253 2237
2254 dmi = dev->mc_list; 2238 dmi = dev->mc_list;
2255 2239
@@ -2280,9 +2264,9 @@ static void set_multicast_list(struct net_device *dev)
2280 hash = (crc >> (32 - HASH_BITS)) & 0x3f; 2264 hash = (crc >> (32 - HASH_BITS)) & 0x3f;
2281 2265
2282 if (hash > 31) 2266 if (hash > 31)
2283 ep->fec_hash_table_high |= 1 << (hash - 32); 2267 ep->fec_grp_hash_table_high |= 1 << (hash - 32);
2284 else 2268 else
2285 ep->fec_hash_table_low |= 1 << hash; 2269 ep->fec_grp_hash_table_low |= 1 << hash;
2286 } 2270 }
2287 } 2271 }
2288 } 2272 }
@@ -2332,6 +2316,9 @@ int __init fec_enet_init(struct net_device *dev)
2332 return -ENOMEM; 2316 return -ENOMEM;
2333 } 2317 }
2334 2318
2319 spin_lock_init(&fep->hw_lock);
2320 spin_lock_init(&fep->mii_lock);
2321
2335 /* Create an Ethernet device instance. 2322 /* Create an Ethernet device instance.
2336 */ 2323 */
2337 fecp = (volatile fec_t *) fec_hw[index]; 2324 fecp = (volatile fec_t *) fec_hw[index];
@@ -2430,11 +2417,15 @@ int __init fec_enet_init(struct net_device *dev)
2430 */ 2417 */
2431 fec_request_intrs(dev); 2418 fec_request_intrs(dev);
2432 2419
2433 fecp->fec_hash_table_high = 0; 2420 fecp->fec_grp_hash_table_high = 0;
2434 fecp->fec_hash_table_low = 0; 2421 fecp->fec_grp_hash_table_low = 0;
2435 fecp->fec_r_buff_size = PKT_MAXBLR_SIZE; 2422 fecp->fec_r_buff_size = PKT_MAXBLR_SIZE;
2436 fecp->fec_ecntrl = 2; 2423 fecp->fec_ecntrl = 2;
2437 fecp->fec_r_des_active = 0; 2424 fecp->fec_r_des_active = 0;
2425#ifndef CONFIG_M5272
2426 fecp->fec_hash_table_high = 0;
2427 fecp->fec_hash_table_low = 0;
2428#endif
2438 2429
2439 dev->base_addr = (unsigned long)fecp; 2430 dev->base_addr = (unsigned long)fecp;
2440 2431
@@ -2455,8 +2446,7 @@ int __init fec_enet_init(struct net_device *dev)
2455 2446
2456 /* Clear and enable interrupts */ 2447 /* Clear and enable interrupts */
2457 fecp->fec_ievent = 0xffc00000; 2448 fecp->fec_ievent = 0xffc00000;
2458 fecp->fec_imask = (FEC_ENET_TXF | FEC_ENET_TXB | 2449 fecp->fec_imask = (FEC_ENET_TXF | FEC_ENET_RXF | FEC_ENET_MII);
2459 FEC_ENET_RXF | FEC_ENET_RXB | FEC_ENET_MII);
2460 2450
2461 /* Queue up command to detect the PHY and initialize the 2451 /* Queue up command to detect the PHY and initialize the
2462 * remainder of the interface. 2452 * remainder of the interface.
@@ -2500,8 +2490,8 @@ fec_restart(struct net_device *dev, int duplex)
2500 2490
2501 /* Reset all multicast. 2491 /* Reset all multicast.
2502 */ 2492 */
2503 fecp->fec_hash_table_high = 0; 2493 fecp->fec_grp_hash_table_high = 0;
2504 fecp->fec_hash_table_low = 0; 2494 fecp->fec_grp_hash_table_low = 0;
2505 2495
2506 /* Set maximum receive buffer size. 2496 /* Set maximum receive buffer size.
2507 */ 2497 */
@@ -2583,8 +2573,7 @@ fec_restart(struct net_device *dev, int duplex)
2583 2573
2584 /* Enable interrupts we wish to service. 2574 /* Enable interrupts we wish to service.
2585 */ 2575 */
2586 fecp->fec_imask = (FEC_ENET_TXF | FEC_ENET_TXB | 2576 fecp->fec_imask = (FEC_ENET_TXF | FEC_ENET_RXF | FEC_ENET_MII);
2587 FEC_ENET_RXF | FEC_ENET_RXB | FEC_ENET_MII);
2588} 2577}
2589 2578
2590static void 2579static void
@@ -2624,7 +2613,7 @@ fec_stop(struct net_device *dev)
2624static int __init fec_enet_module_init(void) 2613static int __init fec_enet_module_init(void)
2625{ 2614{
2626 struct net_device *dev; 2615 struct net_device *dev;
2627 int i, j, err; 2616 int i, err;
2628 DECLARE_MAC_BUF(mac); 2617 DECLARE_MAC_BUF(mac);
2629 2618
2630 printk("FEC ENET Version 0.2\n"); 2619 printk("FEC ENET Version 0.2\n");
diff --git a/drivers/net/fec.h b/drivers/net/fec.h
index 1d421606984f..292719daceff 100644
--- a/drivers/net/fec.h
+++ b/drivers/net/fec.h
@@ -88,8 +88,8 @@ typedef struct fec {
88 unsigned long fec_reserved7[158]; 88 unsigned long fec_reserved7[158];
89 unsigned long fec_addr_low; /* Low 32bits MAC address */ 89 unsigned long fec_addr_low; /* Low 32bits MAC address */
90 unsigned long fec_addr_high; /* High 16bits MAC address */ 90 unsigned long fec_addr_high; /* High 16bits MAC address */
91 unsigned long fec_hash_table_high; /* High 32bits hash table */ 91 unsigned long fec_grp_hash_table_high;/* High 32bits hash table */
92 unsigned long fec_hash_table_low; /* Low 32bits hash table */ 92 unsigned long fec_grp_hash_table_low; /* Low 32bits hash table */
93 unsigned long fec_r_des_start; /* Receive descriptor ring */ 93 unsigned long fec_r_des_start; /* Receive descriptor ring */
94 unsigned long fec_x_des_start; /* Transmit descriptor ring */ 94 unsigned long fec_x_des_start; /* Transmit descriptor ring */
95 unsigned long fec_r_buff_size; /* Maximum receive buff size */ 95 unsigned long fec_r_buff_size; /* Maximum receive buff size */
diff --git a/drivers/net/fec_mpc52xx.c b/drivers/net/fec_mpc52xx.c
index e5e6352556fa..5f9c42e7a7f1 100644
--- a/drivers/net/fec_mpc52xx.c
+++ b/drivers/net/fec_mpc52xx.c
@@ -43,6 +43,29 @@
43 43
44#define DRIVER_NAME "mpc52xx-fec" 44#define DRIVER_NAME "mpc52xx-fec"
45 45
46#define FEC5200_PHYADDR_NONE (-1)
47#define FEC5200_PHYADDR_7WIRE (-2)
48
49/* Private driver data structure */
50struct mpc52xx_fec_priv {
51 int duplex;
52 int speed;
53 int r_irq;
54 int t_irq;
55 struct mpc52xx_fec __iomem *fec;
56 struct bcom_task *rx_dmatsk;
57 struct bcom_task *tx_dmatsk;
58 spinlock_t lock;
59 int msg_enable;
60
61 /* MDIO link details */
62 int phy_addr;
63 unsigned int phy_speed;
64 struct phy_device *phydev;
65 enum phy_state link;
66};
67
68
46static irqreturn_t mpc52xx_fec_interrupt(int, void *); 69static irqreturn_t mpc52xx_fec_interrupt(int, void *);
47static irqreturn_t mpc52xx_fec_rx_interrupt(int, void *); 70static irqreturn_t mpc52xx_fec_rx_interrupt(int, void *);
48static irqreturn_t mpc52xx_fec_tx_interrupt(int, void *); 71static irqreturn_t mpc52xx_fec_tx_interrupt(int, void *);
@@ -223,7 +246,7 @@ static int mpc52xx_fec_phy_start(struct net_device *dev)
223 struct mpc52xx_fec_priv *priv = netdev_priv(dev); 246 struct mpc52xx_fec_priv *priv = netdev_priv(dev);
224 int err; 247 int err;
225 248
226 if (!priv->has_phy) 249 if (priv->phy_addr < 0)
227 return 0; 250 return 0;
228 251
229 err = mpc52xx_fec_init_phy(dev); 252 err = mpc52xx_fec_init_phy(dev);
@@ -243,7 +266,7 @@ static void mpc52xx_fec_phy_stop(struct net_device *dev)
243{ 266{
244 struct mpc52xx_fec_priv *priv = netdev_priv(dev); 267 struct mpc52xx_fec_priv *priv = netdev_priv(dev);
245 268
246 if (!priv->has_phy) 269 if (!priv->phydev)
247 return; 270 return;
248 271
249 phy_disconnect(priv->phydev); 272 phy_disconnect(priv->phydev);
@@ -255,7 +278,7 @@ static void mpc52xx_fec_phy_stop(struct net_device *dev)
255static int mpc52xx_fec_phy_mii_ioctl(struct mpc52xx_fec_priv *priv, 278static int mpc52xx_fec_phy_mii_ioctl(struct mpc52xx_fec_priv *priv,
256 struct mii_ioctl_data *mii_data, int cmd) 279 struct mii_ioctl_data *mii_data, int cmd)
257{ 280{
258 if (!priv->has_phy) 281 if (!priv->phydev)
259 return -ENOTSUPP; 282 return -ENOTSUPP;
260 283
261 return phy_mii_ioctl(priv->phydev, mii_data, cmd); 284 return phy_mii_ioctl(priv->phydev, mii_data, cmd);
@@ -265,7 +288,7 @@ static void mpc52xx_fec_phy_hw_init(struct mpc52xx_fec_priv *priv)
265{ 288{
266 struct mpc52xx_fec __iomem *fec = priv->fec; 289 struct mpc52xx_fec __iomem *fec = priv->fec;
267 290
268 if (!priv->has_phy) 291 if (priv->phydev)
269 return; 292 return;
270 293
271 out_be32(&fec->mii_speed, priv->phy_speed); 294 out_be32(&fec->mii_speed, priv->phy_speed);
@@ -491,20 +514,23 @@ static irqreturn_t mpc52xx_fec_interrupt(int irq, void *dev_id)
491 514
492 out_be32(&fec->ievent, ievent); /* clear pending events */ 515 out_be32(&fec->ievent, ievent); /* clear pending events */
493 516
494 if (ievent & ~(FEC_IEVENT_RFIFO_ERROR | FEC_IEVENT_XFIFO_ERROR)) { 517 /* on fifo error, soft-reset fec */
495 if (ievent & ~FEC_IEVENT_TFINT) 518 if (ievent & (FEC_IEVENT_RFIFO_ERROR | FEC_IEVENT_XFIFO_ERROR)) {
496 dev_dbg(&dev->dev, "ievent: %08x\n", ievent); 519
520 if (net_ratelimit() && (ievent & FEC_IEVENT_RFIFO_ERROR))
521 dev_warn(&dev->dev, "FEC_IEVENT_RFIFO_ERROR\n");
522 if (net_ratelimit() && (ievent & FEC_IEVENT_XFIFO_ERROR))
523 dev_warn(&dev->dev, "FEC_IEVENT_XFIFO_ERROR\n");
524
525 mpc52xx_fec_reset(dev);
526
527 netif_wake_queue(dev);
497 return IRQ_HANDLED; 528 return IRQ_HANDLED;
498 } 529 }
499 530
500 if (net_ratelimit() && (ievent & FEC_IEVENT_RFIFO_ERROR)) 531 if (ievent & ~FEC_IEVENT_TFINT)
501 dev_warn(&dev->dev, "FEC_IEVENT_RFIFO_ERROR\n"); 532 dev_dbg(&dev->dev, "ievent: %08x\n", ievent);
502 if (net_ratelimit() && (ievent & FEC_IEVENT_XFIFO_ERROR))
503 dev_warn(&dev->dev, "FEC_IEVENT_XFIFO_ERROR\n");
504
505 mpc52xx_fec_reset(dev);
506 533
507 netif_wake_queue(dev);
508 return IRQ_HANDLED; 534 return IRQ_HANDLED;
509} 535}
510 536
@@ -701,7 +727,7 @@ static void mpc52xx_fec_start(struct net_device *dev)
701 rcntrl = FEC_RX_BUFFER_SIZE << 16; /* max frame length */ 727 rcntrl = FEC_RX_BUFFER_SIZE << 16; /* max frame length */
702 rcntrl |= FEC_RCNTRL_FCE; 728 rcntrl |= FEC_RCNTRL_FCE;
703 729
704 if (priv->has_phy) 730 if (priv->phy_addr != FEC5200_PHYADDR_7WIRE)
705 rcntrl |= FEC_RCNTRL_MII_MODE; 731 rcntrl |= FEC_RCNTRL_MII_MODE;
706 732
707 if (priv->duplex == DUPLEX_FULL) 733 if (priv->duplex == DUPLEX_FULL)
@@ -861,7 +887,10 @@ mpc52xx_fec_probe(struct of_device *op, const struct of_device_id *match)
861 struct net_device *ndev; 887 struct net_device *ndev;
862 struct mpc52xx_fec_priv *priv = NULL; 888 struct mpc52xx_fec_priv *priv = NULL;
863 struct resource mem; 889 struct resource mem;
864 const phandle *ph; 890 struct device_node *phy_node;
891 const phandle *phy_handle;
892 const u32 *prop;
893 int prop_size;
865 894
866 phys_addr_t rx_fifo; 895 phys_addr_t rx_fifo;
867 phys_addr_t tx_fifo; 896 phys_addr_t tx_fifo;
@@ -945,26 +974,37 @@ mpc52xx_fec_probe(struct of_device *op, const struct of_device_id *match)
945 mpc52xx_fec_get_paddr(ndev, ndev->dev_addr); 974 mpc52xx_fec_get_paddr(ndev, ndev->dev_addr);
946 975
947 priv->msg_enable = netif_msg_init(debug, MPC52xx_MESSAGES_DEFAULT); 976 priv->msg_enable = netif_msg_init(debug, MPC52xx_MESSAGES_DEFAULT);
948 priv->duplex = DUPLEX_FULL;
949 977
950 /* is the phy present in device tree? */ 978 /*
951 ph = of_get_property(op->node, "phy-handle", NULL); 979 * Link mode configuration
952 if (ph) { 980 */
953 const unsigned int *prop;
954 struct device_node *phy_dn;
955 priv->has_phy = 1;
956
957 phy_dn = of_find_node_by_phandle(*ph);
958 prop = of_get_property(phy_dn, "reg", NULL);
959 priv->phy_addr = *prop;
960 981
961 of_node_put(phy_dn); 982 /* Start with safe defaults for link connection */
983 priv->phy_addr = FEC5200_PHYADDR_NONE;
984 priv->speed = 100;
985 priv->duplex = DUPLEX_HALF;
986 priv->phy_speed = ((mpc52xx_find_ipb_freq(op->node) >> 20) / 5) << 1;
987
988 /* the 7-wire property means don't use MII mode */
989 if (of_find_property(op->node, "fsl,7-wire-mode", NULL))
990 priv->phy_addr = FEC5200_PHYADDR_7WIRE;
991
992 /* The current speed preconfigures the speed of the MII link */
993 prop = of_get_property(op->node, "current-speed", &prop_size);
994 if (prop && (prop_size >= sizeof(u32) * 2)) {
995 priv->speed = prop[0];
996 priv->duplex = prop[1] ? DUPLEX_FULL : DUPLEX_HALF;
997 }
962 998
963 /* Phy speed */ 999 /* If there is a phy handle, setup link to that phy */
964 priv->phy_speed = ((mpc52xx_find_ipb_freq(op->node) >> 20) / 5) << 1; 1000 phy_handle = of_get_property(op->node, "phy-handle", &prop_size);
965 } else { 1001 if (phy_handle && (prop_size >= sizeof(phandle))) {
966 dev_info(&ndev->dev, "can't find \"phy-handle\" in device" 1002 phy_node = of_find_node_by_phandle(*phy_handle);
967 " tree, using 7-wire mode\n"); 1003 prop = of_get_property(phy_node, "reg", &prop_size);
1004 if (prop && (prop_size >= sizeof(u32)))
1005 if ((*prop >= 0) && (*prop < PHY_MAX_ADDR))
1006 priv->phy_addr = *prop;
1007 of_node_put(phy_node);
968 } 1008 }
969 1009
970 /* Hardware init */ 1010 /* Hardware init */
@@ -979,6 +1019,20 @@ mpc52xx_fec_probe(struct of_device *op, const struct of_device_id *match)
979 if (rv < 0) 1019 if (rv < 0)
980 goto probe_error; 1020 goto probe_error;
981 1021
1022 /* Now report the link setup */
1023 switch (priv->phy_addr) {
1024 case FEC5200_PHYADDR_NONE:
1025 dev_info(&ndev->dev, "Fixed speed MII link: %i%cD\n",
1026 priv->speed, priv->duplex ? 'F' : 'H');
1027 break;
1028 case FEC5200_PHYADDR_7WIRE:
1029 dev_info(&ndev->dev, "using 7-wire PHY mode\n");
1030 break;
1031 default:
1032 dev_info(&ndev->dev, "Using PHY at MDIO address %i\n",
1033 priv->phy_addr);
1034 }
1035
982 /* We're done ! */ 1036 /* We're done ! */
983 dev_set_drvdata(&op->dev, ndev); 1037 dev_set_drvdata(&op->dev, ndev);
984 1038
diff --git a/drivers/net/fec_mpc52xx.h b/drivers/net/fec_mpc52xx.h
index 8b1f75397b9a..a227a525bdbb 100644
--- a/drivers/net/fec_mpc52xx.h
+++ b/drivers/net/fec_mpc52xx.h
@@ -26,25 +26,6 @@
26 26
27#define FEC_WATCHDOG_TIMEOUT ((400*HZ)/1000) 27#define FEC_WATCHDOG_TIMEOUT ((400*HZ)/1000)
28 28
29struct mpc52xx_fec_priv {
30 int duplex;
31 int r_irq;
32 int t_irq;
33 struct mpc52xx_fec __iomem *fec;
34 struct bcom_task *rx_dmatsk;
35 struct bcom_task *tx_dmatsk;
36 spinlock_t lock;
37 int msg_enable;
38
39 int has_phy;
40 unsigned int phy_speed;
41 unsigned int phy_addr;
42 struct phy_device *phydev;
43 enum phy_state link;
44 int speed;
45};
46
47
48/* ======================================================================== */ 29/* ======================================================================== */
49/* Hardware register sets & bits */ 30/* Hardware register sets & bits */
50/* ======================================================================== */ 31/* ======================================================================== */
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index 99a4b990939f..587afe7be689 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -131,8 +131,6 @@ static void free_skb_resources(struct gfar_private *priv);
131static void gfar_set_multi(struct net_device *dev); 131static void gfar_set_multi(struct net_device *dev);
132static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr); 132static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr);
133static void gfar_configure_serdes(struct net_device *dev); 133static void gfar_configure_serdes(struct net_device *dev);
134extern int gfar_local_mdio_write(struct gfar_mii __iomem *regs, int mii_id, int regnum, u16 value);
135extern int gfar_local_mdio_read(struct gfar_mii __iomem *regs, int mii_id, int regnum);
136#ifdef CONFIG_GFAR_NAPI 134#ifdef CONFIG_GFAR_NAPI
137static int gfar_poll(struct napi_struct *napi, int budget); 135static int gfar_poll(struct napi_struct *napi, int budget);
138#endif 136#endif
@@ -477,24 +475,30 @@ static int init_phy(struct net_device *dev)
477 return 0; 475 return 0;
478} 476}
479 477
478/*
479 * Initialize TBI PHY interface for communicating with the
480 * SERDES lynx PHY on the chip. We communicate with this PHY
481 * through the MDIO bus on each controller, treating it as a
482 * "normal" PHY at the address found in the TBIPA register. We assume
483 * that the TBIPA register is valid. Either the MDIO bus code will set
484 * it to a value that doesn't conflict with other PHYs on the bus, or the
485 * value doesn't matter, as there are no other PHYs on the bus.
486 */
480static void gfar_configure_serdes(struct net_device *dev) 487static void gfar_configure_serdes(struct net_device *dev)
481{ 488{
482 struct gfar_private *priv = netdev_priv(dev); 489 struct gfar_private *priv = netdev_priv(dev);
483 struct gfar_mii __iomem *regs = 490 struct gfar_mii __iomem *regs =
484 (void __iomem *)&priv->regs->gfar_mii_regs; 491 (void __iomem *)&priv->regs->gfar_mii_regs;
492 int tbipa = gfar_read(&priv->regs->tbipa);
485 493
486 /* Initialise TBI i/f to communicate with serdes (lynx phy) */ 494 /* Single clk mode, mii mode off(for serdes communication) */
495 gfar_local_mdio_write(regs, tbipa, MII_TBICON, TBICON_CLK_SELECT);
487 496
488 /* Single clk mode, mii mode off(for aerdes communication) */ 497 gfar_local_mdio_write(regs, tbipa, MII_ADVERTISE,
489 gfar_local_mdio_write(regs, TBIPA_VALUE, MII_TBICON, TBICON_CLK_SELECT);
490
491 /* Supported pause and full-duplex, no half-duplex */
492 gfar_local_mdio_write(regs, TBIPA_VALUE, MII_ADVERTISE,
493 ADVERTISE_1000XFULL | ADVERTISE_1000XPAUSE | 498 ADVERTISE_1000XFULL | ADVERTISE_1000XPAUSE |
494 ADVERTISE_1000XPSE_ASYM); 499 ADVERTISE_1000XPSE_ASYM);
495 500
496 /* ANEG enable, restart ANEG, full duplex mode, speed[1] set */ 501 gfar_local_mdio_write(regs, tbipa, MII_BMCR, BMCR_ANENABLE |
497 gfar_local_mdio_write(regs, TBIPA_VALUE, MII_BMCR, BMCR_ANENABLE |
498 BMCR_ANRESTART | BMCR_FULLDPLX | BMCR_SPEED1000); 502 BMCR_ANRESTART | BMCR_FULLDPLX | BMCR_SPEED1000);
499} 503}
500 504
@@ -541,9 +545,6 @@ static void init_registers(struct net_device *dev)
541 545
542 /* Initialize the Minimum Frame Length Register */ 546 /* Initialize the Minimum Frame Length Register */
543 gfar_write(&priv->regs->minflr, MINFLR_INIT_SETTINGS); 547 gfar_write(&priv->regs->minflr, MINFLR_INIT_SETTINGS);
544
545 /* Assign the TBI an address which won't conflict with the PHYs */
546 gfar_write(&priv->regs->tbipa, TBIPA_VALUE);
547} 548}
548 549
549 550
diff --git a/drivers/net/gianfar.h b/drivers/net/gianfar.h
index 0d0883609469..fd487be3993e 100644
--- a/drivers/net/gianfar.h
+++ b/drivers/net/gianfar.h
@@ -137,7 +137,6 @@ extern const char gfar_driver_version[];
137#define DEFAULT_RXCOUNT 0 137#define DEFAULT_RXCOUNT 0
138#endif /* CONFIG_GFAR_NAPI */ 138#endif /* CONFIG_GFAR_NAPI */
139 139
140#define TBIPA_VALUE 0x1f
141#define MIIMCFG_INIT_VALUE 0x00000007 140#define MIIMCFG_INIT_VALUE 0x00000007
142#define MIIMCFG_RESET 0x80000000 141#define MIIMCFG_RESET 0x80000000
143#define MIIMIND_BUSY 0x00000001 142#define MIIMIND_BUSY 0x00000001
diff --git a/drivers/net/gianfar_mii.c b/drivers/net/gianfar_mii.c
index b8898927236a..ebcfb27a904e 100644
--- a/drivers/net/gianfar_mii.c
+++ b/drivers/net/gianfar_mii.c
@@ -78,7 +78,6 @@ int gfar_local_mdio_write(struct gfar_mii __iomem *regs, int mii_id,
78 * same as system mdio bus, used for controlling the external PHYs, for eg. 78 * same as system mdio bus, used for controlling the external PHYs, for eg.
79 */ 79 */
80int gfar_local_mdio_read(struct gfar_mii __iomem *regs, int mii_id, int regnum) 80int gfar_local_mdio_read(struct gfar_mii __iomem *regs, int mii_id, int regnum)
81
82{ 81{
83 u16 value; 82 u16 value;
84 83
@@ -122,7 +121,7 @@ int gfar_mdio_read(struct mii_bus *bus, int mii_id, int regnum)
122} 121}
123 122
124/* Reset the MIIM registers, and wait for the bus to free */ 123/* Reset the MIIM registers, and wait for the bus to free */
125int gfar_mdio_reset(struct mii_bus *bus) 124static int gfar_mdio_reset(struct mii_bus *bus)
126{ 125{
127 struct gfar_mii __iomem *regs = (void __iomem *)bus->priv; 126 struct gfar_mii __iomem *regs = (void __iomem *)bus->priv;
128 unsigned int timeout = PHY_INIT_TIMEOUT; 127 unsigned int timeout = PHY_INIT_TIMEOUT;
@@ -152,14 +151,15 @@ int gfar_mdio_reset(struct mii_bus *bus)
152} 151}
153 152
154 153
155int gfar_mdio_probe(struct device *dev) 154static int gfar_mdio_probe(struct device *dev)
156{ 155{
157 struct platform_device *pdev = to_platform_device(dev); 156 struct platform_device *pdev = to_platform_device(dev);
158 struct gianfar_mdio_data *pdata; 157 struct gianfar_mdio_data *pdata;
159 struct gfar_mii __iomem *regs; 158 struct gfar_mii __iomem *regs;
159 struct gfar __iomem *enet_regs;
160 struct mii_bus *new_bus; 160 struct mii_bus *new_bus;
161 struct resource *r; 161 struct resource *r;
162 int err = 0; 162 int i, err = 0;
163 163
164 if (NULL == dev) 164 if (NULL == dev)
165 return -EINVAL; 165 return -EINVAL;
@@ -199,6 +199,34 @@ int gfar_mdio_probe(struct device *dev)
199 new_bus->dev = dev; 199 new_bus->dev = dev;
200 dev_set_drvdata(dev, new_bus); 200 dev_set_drvdata(dev, new_bus);
201 201
202 /*
203 * This is mildly evil, but so is our hardware for doing this.
204 * Also, we have to cast back to struct gfar_mii because of
205 * definition weirdness done in gianfar.h.
206 */
207 enet_regs = (struct gfar __iomem *)
208 ((char *)regs - offsetof(struct gfar, gfar_mii_regs));
209
210 /* Scan the bus, looking for an empty spot for TBIPA */
211 gfar_write(&enet_regs->tbipa, 0);
212 for (i = PHY_MAX_ADDR; i > 0; i--) {
213 u32 phy_id;
214 int r;
215
216 r = get_phy_id(new_bus, i, &phy_id);
217 if (r)
218 return r;
219
220 if (phy_id == 0xffffffff)
221 break;
222 }
223
224 /* The bus is full. We don't support using 31 PHYs, sorry */
225 if (i == 0)
226 return -EBUSY;
227
228 gfar_write(&enet_regs->tbipa, i);
229
202 err = mdiobus_register(new_bus); 230 err = mdiobus_register(new_bus);
203 231
204 if (0 != err) { 232 if (0 != err) {
@@ -218,7 +246,7 @@ reg_map_fail:
218} 246}
219 247
220 248
221int gfar_mdio_remove(struct device *dev) 249static int gfar_mdio_remove(struct device *dev)
222{ 250{
223 struct mii_bus *bus = dev_get_drvdata(dev); 251 struct mii_bus *bus = dev_get_drvdata(dev);
224 252
diff --git a/drivers/net/gianfar_mii.h b/drivers/net/gianfar_mii.h
index b373091c7031..2af28b16a0e2 100644
--- a/drivers/net/gianfar_mii.h
+++ b/drivers/net/gianfar_mii.h
@@ -41,6 +41,9 @@ struct gfar_mii {
41 41
42int gfar_mdio_read(struct mii_bus *bus, int mii_id, int regnum); 42int gfar_mdio_read(struct mii_bus *bus, int mii_id, int regnum);
43int gfar_mdio_write(struct mii_bus *bus, int mii_id, int regnum, u16 value); 43int gfar_mdio_write(struct mii_bus *bus, int mii_id, int regnum, u16 value);
44int gfar_local_mdio_write(struct gfar_mii __iomem *regs, int mii_id,
45 int regnum, u16 value);
46int gfar_local_mdio_read(struct gfar_mii __iomem *regs, int mii_id, int regnum);
44int __init gfar_mdio_init(void); 47int __init gfar_mdio_init(void);
45void gfar_mdio_exit(void); 48void gfar_mdio_exit(void);
46#endif /* GIANFAR_PHY_H */ 49#endif /* GIANFAR_PHY_H */
diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
index 1da55dd2a5a0..9d5721287d6f 100644
--- a/drivers/net/hamradio/6pack.c
+++ b/drivers/net/hamradio/6pack.c
@@ -148,13 +148,13 @@ static void sp_xmit_on_air(unsigned long channel)
148 148
149 if (((sp->status1 & SIXP_DCD_MASK) == 0) && (random < sp->persistence)) { 149 if (((sp->status1 & SIXP_DCD_MASK) == 0) && (random < sp->persistence)) {
150 sp->led_state = 0x70; 150 sp->led_state = 0x70;
151 sp->tty->driver->write(sp->tty, &sp->led_state, 1); 151 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
152 sp->tx_enable = 1; 152 sp->tx_enable = 1;
153 actual = sp->tty->driver->write(sp->tty, sp->xbuff, sp->status2); 153 actual = sp->tty->ops->write(sp->tty, sp->xbuff, sp->status2);
154 sp->xleft -= actual; 154 sp->xleft -= actual;
155 sp->xhead += actual; 155 sp->xhead += actual;
156 sp->led_state = 0x60; 156 sp->led_state = 0x60;
157 sp->tty->driver->write(sp->tty, &sp->led_state, 1); 157 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
158 sp->status2 = 0; 158 sp->status2 = 0;
159 } else 159 } else
160 mod_timer(&sp->tx_t, jiffies + ((when + 1) * HZ) / 100); 160 mod_timer(&sp->tx_t, jiffies + ((when + 1) * HZ) / 100);
@@ -220,13 +220,13 @@ static void sp_encaps(struct sixpack *sp, unsigned char *icp, int len)
220 */ 220 */
221 if (sp->duplex == 1) { 221 if (sp->duplex == 1) {
222 sp->led_state = 0x70; 222 sp->led_state = 0x70;
223 sp->tty->driver->write(sp->tty, &sp->led_state, 1); 223 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
224 sp->tx_enable = 1; 224 sp->tx_enable = 1;
225 actual = sp->tty->driver->write(sp->tty, sp->xbuff, count); 225 actual = sp->tty->ops->write(sp->tty, sp->xbuff, count);
226 sp->xleft = count - actual; 226 sp->xleft = count - actual;
227 sp->xhead = sp->xbuff + actual; 227 sp->xhead = sp->xbuff + actual;
228 sp->led_state = 0x60; 228 sp->led_state = 0x60;
229 sp->tty->driver->write(sp->tty, &sp->led_state, 1); 229 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
230 } else { 230 } else {
231 sp->xleft = count; 231 sp->xleft = count;
232 sp->xhead = sp->xbuff; 232 sp->xhead = sp->xbuff;
@@ -444,7 +444,7 @@ static void sixpack_write_wakeup(struct tty_struct *tty)
444 } 444 }
445 445
446 if (sp->tx_enable) { 446 if (sp->tx_enable) {
447 actual = tty->driver->write(tty, sp->xhead, sp->xleft); 447 actual = tty->ops->write(tty, sp->xhead, sp->xleft);
448 sp->xleft -= actual; 448 sp->xleft -= actual;
449 sp->xhead += actual; 449 sp->xhead += actual;
450 } 450 }
@@ -491,9 +491,7 @@ static void sixpack_receive_buf(struct tty_struct *tty,
491 sixpack_decode(sp, buf, count1); 491 sixpack_decode(sp, buf, count1);
492 492
493 sp_put(sp); 493 sp_put(sp);
494 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) 494 tty_unthrottle(tty);
495 && tty->driver->unthrottle)
496 tty->driver->unthrottle(tty);
497} 495}
498 496
499/* 497/*
@@ -554,8 +552,8 @@ static void resync_tnc(unsigned long channel)
554 /* resync the TNC */ 552 /* resync the TNC */
555 553
556 sp->led_state = 0x60; 554 sp->led_state = 0x60;
557 sp->tty->driver->write(sp->tty, &sp->led_state, 1); 555 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
558 sp->tty->driver->write(sp->tty, &resync_cmd, 1); 556 sp->tty->ops->write(sp->tty, &resync_cmd, 1);
559 557
560 558
561 /* Start resync timer again -- the TNC might be still absent */ 559 /* Start resync timer again -- the TNC might be still absent */
@@ -573,7 +571,7 @@ static inline int tnc_init(struct sixpack *sp)
573 571
574 tnc_set_sync_state(sp, TNC_UNSYNC_STARTUP); 572 tnc_set_sync_state(sp, TNC_UNSYNC_STARTUP);
575 573
576 sp->tty->driver->write(sp->tty, &inbyte, 1); 574 sp->tty->ops->write(sp->tty, &inbyte, 1);
577 575
578 del_timer(&sp->resync_t); 576 del_timer(&sp->resync_t);
579 sp->resync_t.data = (unsigned long) sp; 577 sp->resync_t.data = (unsigned long) sp;
@@ -601,6 +599,8 @@ static int sixpack_open(struct tty_struct *tty)
601 599
602 if (!capable(CAP_NET_ADMIN)) 600 if (!capable(CAP_NET_ADMIN))
603 return -EPERM; 601 return -EPERM;
602 if (tty->ops->write == NULL)
603 return -EOPNOTSUPP;
604 604
605 dev = alloc_netdev(sizeof(struct sixpack), "sp%d", sp_setup); 605 dev = alloc_netdev(sizeof(struct sixpack), "sp%d", sp_setup);
606 if (!dev) { 606 if (!dev) {
@@ -914,9 +914,9 @@ static void decode_prio_command(struct sixpack *sp, unsigned char cmd)
914 } else { /* output watchdog char if idle */ 914 } else { /* output watchdog char if idle */
915 if ((sp->status2 != 0) && (sp->duplex == 1)) { 915 if ((sp->status2 != 0) && (sp->duplex == 1)) {
916 sp->led_state = 0x70; 916 sp->led_state = 0x70;
917 sp->tty->driver->write(sp->tty, &sp->led_state, 1); 917 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
918 sp->tx_enable = 1; 918 sp->tx_enable = 1;
919 actual = sp->tty->driver->write(sp->tty, sp->xbuff, sp->status2); 919 actual = sp->tty->ops->write(sp->tty, sp->xbuff, sp->status2);
920 sp->xleft -= actual; 920 sp->xleft -= actual;
921 sp->xhead += actual; 921 sp->xhead += actual;
922 sp->led_state = 0x60; 922 sp->led_state = 0x60;
@@ -926,7 +926,7 @@ static void decode_prio_command(struct sixpack *sp, unsigned char cmd)
926 } 926 }
927 927
928 /* needed to trigger the TNC watchdog */ 928 /* needed to trigger the TNC watchdog */
929 sp->tty->driver->write(sp->tty, &sp->led_state, 1); 929 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
930 930
931 /* if the state byte has been received, the TNC is present, 931 /* if the state byte has been received, the TNC is present,
932 so the resync timer can be reset. */ 932 so the resync timer can be reset. */
@@ -956,12 +956,12 @@ static void decode_std_command(struct sixpack *sp, unsigned char cmd)
956 if ((sp->status & SIXP_RX_DCD_MASK) == 956 if ((sp->status & SIXP_RX_DCD_MASK) ==
957 SIXP_RX_DCD_MASK) { 957 SIXP_RX_DCD_MASK) {
958 sp->led_state = 0x68; 958 sp->led_state = 0x68;
959 sp->tty->driver->write(sp->tty, &sp->led_state, 1); 959 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
960 } 960 }
961 } else { 961 } else {
962 sp->led_state = 0x60; 962 sp->led_state = 0x60;
963 /* fill trailing bytes with zeroes */ 963 /* fill trailing bytes with zeroes */
964 sp->tty->driver->write(sp->tty, &sp->led_state, 1); 964 sp->tty->ops->write(sp->tty, &sp->led_state, 1);
965 rest = sp->rx_count; 965 rest = sp->rx_count;
966 if (rest != 0) 966 if (rest != 0)
967 for (i = rest; i <= 3; i++) 967 for (i = rest; i <= 3; i++)
diff --git a/drivers/net/hamradio/mkiss.c b/drivers/net/hamradio/mkiss.c
index 30c9b3b0d131..65166035aca0 100644
--- a/drivers/net/hamradio/mkiss.c
+++ b/drivers/net/hamradio/mkiss.c
@@ -516,7 +516,7 @@ static void ax_encaps(struct net_device *dev, unsigned char *icp, int len)
516 spin_unlock_bh(&ax->buflock); 516 spin_unlock_bh(&ax->buflock);
517 517
518 set_bit(TTY_DO_WRITE_WAKEUP, &ax->tty->flags); 518 set_bit(TTY_DO_WRITE_WAKEUP, &ax->tty->flags);
519 actual = ax->tty->driver->write(ax->tty, ax->xbuff, count); 519 actual = ax->tty->ops->write(ax->tty, ax->xbuff, count);
520 ax->stats.tx_packets++; 520 ax->stats.tx_packets++;
521 ax->stats.tx_bytes += actual; 521 ax->stats.tx_bytes += actual;
522 522
@@ -546,7 +546,7 @@ static int ax_xmit(struct sk_buff *skb, struct net_device *dev)
546 } 546 }
547 547
548 printk(KERN_ERR "mkiss: %s: transmit timed out, %s?\n", dev->name, 548 printk(KERN_ERR "mkiss: %s: transmit timed out, %s?\n", dev->name,
549 (ax->tty->driver->chars_in_buffer(ax->tty) || ax->xleft) ? 549 (ax->tty->ops->chars_in_buffer(ax->tty) || ax->xleft) ?
550 "bad line quality" : "driver error"); 550 "bad line quality" : "driver error");
551 551
552 ax->xleft = 0; 552 ax->xleft = 0;
@@ -736,6 +736,8 @@ static int mkiss_open(struct tty_struct *tty)
736 736
737 if (!capable(CAP_NET_ADMIN)) 737 if (!capable(CAP_NET_ADMIN))
738 return -EPERM; 738 return -EPERM;
739 if (tty->ops->write == NULL)
740 return -EOPNOTSUPP;
739 741
740 dev = alloc_netdev(sizeof(struct mkiss), "ax%d", ax_setup); 742 dev = alloc_netdev(sizeof(struct mkiss), "ax%d", ax_setup);
741 if (!dev) { 743 if (!dev) {
@@ -754,8 +756,7 @@ static int mkiss_open(struct tty_struct *tty)
754 tty->disc_data = ax; 756 tty->disc_data = ax;
755 tty->receive_room = 65535; 757 tty->receive_room = 65535;
756 758
757 if (tty->driver->flush_buffer) 759 tty_driver_flush_buffer(tty);
758 tty->driver->flush_buffer(tty);
759 760
760 /* Restore default settings */ 761 /* Restore default settings */
761 dev->type = ARPHRD_AX25; 762 dev->type = ARPHRD_AX25;
@@ -935,9 +936,7 @@ static void mkiss_receive_buf(struct tty_struct *tty, const unsigned char *cp,
935 } 936 }
936 937
937 mkiss_put(ax); 938 mkiss_put(ax);
938 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) 939 tty_unthrottle(tty);
939 && tty->driver->unthrottle)
940 tty->driver->unthrottle(tty);
941} 940}
942 941
943/* 942/*
@@ -962,7 +961,7 @@ static void mkiss_write_wakeup(struct tty_struct *tty)
962 goto out; 961 goto out;
963 } 962 }
964 963
965 actual = tty->driver->write(tty, ax->xhead, ax->xleft); 964 actual = tty->ops->write(tty, ax->xhead, ax->xleft);
966 ax->xleft -= actual; 965 ax->xleft -= actual;
967 ax->xhead += actual; 966 ax->xhead += actual;
968 967
diff --git a/drivers/net/irda/irtty-sir.c b/drivers/net/irda/irtty-sir.c
index fc753d7f674e..e6f40b7f9041 100644
--- a/drivers/net/irda/irtty-sir.c
+++ b/drivers/net/irda/irtty-sir.c
@@ -64,7 +64,7 @@ static int irtty_chars_in_buffer(struct sir_dev *dev)
64 IRDA_ASSERT(priv != NULL, return -1;); 64 IRDA_ASSERT(priv != NULL, return -1;);
65 IRDA_ASSERT(priv->magic == IRTTY_MAGIC, return -1;); 65 IRDA_ASSERT(priv->magic == IRTTY_MAGIC, return -1;);
66 66
67 return priv->tty->driver->chars_in_buffer(priv->tty); 67 return tty_chars_in_buffer(priv->tty);
68} 68}
69 69
70/* Wait (sleep) until underlaying hardware finished transmission 70/* Wait (sleep) until underlaying hardware finished transmission
@@ -93,10 +93,8 @@ static void irtty_wait_until_sent(struct sir_dev *dev)
93 IRDA_ASSERT(priv->magic == IRTTY_MAGIC, return;); 93 IRDA_ASSERT(priv->magic == IRTTY_MAGIC, return;);
94 94
95 tty = priv->tty; 95 tty = priv->tty;
96 if (tty->driver->wait_until_sent) { 96 if (tty->ops->wait_until_sent) {
97 lock_kernel(); 97 tty->ops->wait_until_sent(tty, msecs_to_jiffies(100));
98 tty->driver->wait_until_sent(tty, msecs_to_jiffies(100));
99 unlock_kernel();
100 } 98 }
101 else { 99 else {
102 msleep(USBSERIAL_TX_DONE_DELAY); 100 msleep(USBSERIAL_TX_DONE_DELAY);
@@ -125,48 +123,14 @@ static int irtty_change_speed(struct sir_dev *dev, unsigned speed)
125 123
126 tty = priv->tty; 124 tty = priv->tty;
127 125
128 lock_kernel(); 126 mutex_lock(&tty->termios_mutex);
129 old_termios = *(tty->termios); 127 old_termios = *(tty->termios);
130 cflag = tty->termios->c_cflag; 128 cflag = tty->termios->c_cflag;
131 129 tty_encode_baud_rate(tty, speed, speed);
132 cflag &= ~CBAUD; 130 if (tty->ops->set_termios)
133 131 tty->ops->set_termios(tty, &old_termios);
134 IRDA_DEBUG(2, "%s(), Setting speed to %d\n", __FUNCTION__, speed);
135
136 switch (speed) {
137 case 1200:
138 cflag |= B1200;
139 break;
140 case 2400:
141 cflag |= B2400;
142 break;
143 case 4800:
144 cflag |= B4800;
145 break;
146 case 19200:
147 cflag |= B19200;
148 break;
149 case 38400:
150 cflag |= B38400;
151 break;
152 case 57600:
153 cflag |= B57600;
154 break;
155 case 115200:
156 cflag |= B115200;
157 break;
158 case 9600:
159 default:
160 cflag |= B9600;
161 break;
162 }
163
164 tty->termios->c_cflag = cflag;
165 if (tty->driver->set_termios)
166 tty->driver->set_termios(tty, &old_termios);
167 unlock_kernel();
168
169 priv->io.speed = speed; 132 priv->io.speed = speed;
133 mutex_unlock(&tty->termios_mutex);
170 134
171 return 0; 135 return 0;
172} 136}
@@ -202,8 +166,8 @@ static int irtty_set_dtr_rts(struct sir_dev *dev, int dtr, int rts)
202 * This function is not yet defined for all tty driver, so 166 * This function is not yet defined for all tty driver, so
203 * let's be careful... Jean II 167 * let's be careful... Jean II
204 */ 168 */
205 IRDA_ASSERT(priv->tty->driver->tiocmset != NULL, return -1;); 169 IRDA_ASSERT(priv->tty->ops->tiocmset != NULL, return -1;);
206 priv->tty->driver->tiocmset(priv->tty, NULL, set, clear); 170 priv->tty->ops->tiocmset(priv->tty, NULL, set, clear);
207 171
208 return 0; 172 return 0;
209} 173}
@@ -225,17 +189,13 @@ static int irtty_do_write(struct sir_dev *dev, const unsigned char *ptr, size_t
225 IRDA_ASSERT(priv->magic == IRTTY_MAGIC, return -1;); 189 IRDA_ASSERT(priv->magic == IRTTY_MAGIC, return -1;);
226 190
227 tty = priv->tty; 191 tty = priv->tty;
228 if (!tty->driver->write) 192 if (!tty->ops->write)
229 return 0; 193 return 0;
230 tty->flags |= (1 << TTY_DO_WRITE_WAKEUP); 194 tty->flags |= (1 << TTY_DO_WRITE_WAKEUP);
231 if (tty->driver->write_room) { 195 writelen = tty_write_room(tty);
232 writelen = tty->driver->write_room(tty); 196 if (writelen > len)
233 if (writelen > len)
234 writelen = len;
235 }
236 else
237 writelen = len; 197 writelen = len;
238 return tty->driver->write(tty, ptr, writelen); 198 return tty->ops->write(tty, ptr, writelen);
239} 199}
240 200
241/* ------------------------------------------------------- */ 201/* ------------------------------------------------------- */
@@ -321,7 +281,7 @@ static inline void irtty_stop_receiver(struct tty_struct *tty, int stop)
321 struct ktermios old_termios; 281 struct ktermios old_termios;
322 int cflag; 282 int cflag;
323 283
324 lock_kernel(); 284 mutex_lock(&tty->termios_mutex);
325 old_termios = *(tty->termios); 285 old_termios = *(tty->termios);
326 cflag = tty->termios->c_cflag; 286 cflag = tty->termios->c_cflag;
327 287
@@ -331,9 +291,9 @@ static inline void irtty_stop_receiver(struct tty_struct *tty, int stop)
331 cflag |= CREAD; 291 cflag |= CREAD;
332 292
333 tty->termios->c_cflag = cflag; 293 tty->termios->c_cflag = cflag;
334 if (tty->driver->set_termios) 294 if (tty->ops->set_termios)
335 tty->driver->set_termios(tty, &old_termios); 295 tty->ops->set_termios(tty, &old_termios);
336 unlock_kernel(); 296 mutex_unlock(&tty->termios_mutex);
337} 297}
338 298
339/*****************************************************************/ 299/*****************************************************************/
@@ -359,8 +319,8 @@ static int irtty_start_dev(struct sir_dev *dev)
359 319
360 tty = priv->tty; 320 tty = priv->tty;
361 321
362 if (tty->driver->start) 322 if (tty->ops->start)
363 tty->driver->start(tty); 323 tty->ops->start(tty);
364 /* Make sure we can receive more data */ 324 /* Make sure we can receive more data */
365 irtty_stop_receiver(tty, FALSE); 325 irtty_stop_receiver(tty, FALSE);
366 326
@@ -388,8 +348,8 @@ static int irtty_stop_dev(struct sir_dev *dev)
388 348
389 /* Make sure we don't receive more data */ 349 /* Make sure we don't receive more data */
390 irtty_stop_receiver(tty, TRUE); 350 irtty_stop_receiver(tty, TRUE);
391 if (tty->driver->stop) 351 if (tty->ops->stop)
392 tty->driver->stop(tty); 352 tty->ops->stop(tty);
393 353
394 mutex_unlock(&irtty_mutex); 354 mutex_unlock(&irtty_mutex);
395 355
@@ -483,11 +443,10 @@ static int irtty_open(struct tty_struct *tty)
483 443
484 /* stop the underlying driver */ 444 /* stop the underlying driver */
485 irtty_stop_receiver(tty, TRUE); 445 irtty_stop_receiver(tty, TRUE);
486 if (tty->driver->stop) 446 if (tty->ops->stop)
487 tty->driver->stop(tty); 447 tty->ops->stop(tty);
488 448
489 if (tty->driver->flush_buffer) 449 tty_driver_flush_buffer(tty);
490 tty->driver->flush_buffer(tty);
491 450
492 /* apply mtt override */ 451 /* apply mtt override */
493 sir_tty_drv.qos_mtt_bits = qos_mtt_bits; 452 sir_tty_drv.qos_mtt_bits = qos_mtt_bits;
@@ -564,8 +523,8 @@ static void irtty_close(struct tty_struct *tty)
564 /* Stop tty */ 523 /* Stop tty */
565 irtty_stop_receiver(tty, TRUE); 524 irtty_stop_receiver(tty, TRUE);
566 tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP); 525 tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
567 if (tty->driver->stop) 526 if (tty->ops->stop)
568 tty->driver->stop(tty); 527 tty->ops->stop(tty);
569 528
570 kfree(priv); 529 kfree(priv);
571 530
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index 3ac8529bb92c..6bf9e76b0a00 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -48,7 +48,7 @@ config VITESSE_PHY
48config SMSC_PHY 48config SMSC_PHY
49 tristate "Drivers for SMSC PHYs" 49 tristate "Drivers for SMSC PHYs"
50 ---help--- 50 ---help---
51 Currently supports the LAN83C185 PHY 51 Currently supports the LAN83C185, LAN8187 and LAN8700 PHYs
52 52
53config BROADCOM_PHY 53config BROADCOM_PHY
54 tristate "Drivers for Broadcom PHYs" 54 tristate "Drivers for Broadcom PHYs"
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index ddf8d51832a6..ac3c01d28fdf 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -256,7 +256,7 @@ void phy_prepare_link(struct phy_device *phydev,
256/** 256/**
257 * phy_connect - connect an ethernet device to a PHY device 257 * phy_connect - connect an ethernet device to a PHY device
258 * @dev: the network device to connect 258 * @dev: the network device to connect
259 * @phy_id: the PHY device to connect 259 * @bus_id: the id string of the PHY device to connect
260 * @handler: callback function for state change notifications 260 * @handler: callback function for state change notifications
261 * @flags: PHY device's dev_flags 261 * @flags: PHY device's dev_flags
262 * @interface: PHY device's interface 262 * @interface: PHY device's interface
diff --git a/drivers/net/phy/smsc.c b/drivers/net/phy/smsc.c
index b1d8ed40ad98..73baa7a3bb0e 100644
--- a/drivers/net/phy/smsc.c
+++ b/drivers/net/phy/smsc.c
@@ -12,6 +12,8 @@
12 * Free Software Foundation; either version 2 of the License, or (at your 12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version. 13 * option) any later version.
14 * 14 *
15 * Support added for SMSC LAN8187 and LAN8700 by steve.glendinning@smsc.com
16 *
15 */ 17 */
16 18
17#include <linux/kernel.h> 19#include <linux/kernel.h>
@@ -38,7 +40,7 @@
38 (MII_LAN83C185_ISF_INT6 | MII_LAN83C185_ISF_INT4) 40 (MII_LAN83C185_ISF_INT6 | MII_LAN83C185_ISF_INT4)
39 41
40 42
41static int lan83c185_config_intr(struct phy_device *phydev) 43static int smsc_phy_config_intr(struct phy_device *phydev)
42{ 44{
43 int rc = phy_write (phydev, MII_LAN83C185_IM, 45 int rc = phy_write (phydev, MII_LAN83C185_IM,
44 ((PHY_INTERRUPT_ENABLED == phydev->interrupts) 46 ((PHY_INTERRUPT_ENABLED == phydev->interrupts)
@@ -48,16 +50,16 @@ static int lan83c185_config_intr(struct phy_device *phydev)
48 return rc < 0 ? rc : 0; 50 return rc < 0 ? rc : 0;
49} 51}
50 52
51static int lan83c185_ack_interrupt(struct phy_device *phydev) 53static int smsc_phy_ack_interrupt(struct phy_device *phydev)
52{ 54{
53 int rc = phy_read (phydev, MII_LAN83C185_ISF); 55 int rc = phy_read (phydev, MII_LAN83C185_ISF);
54 56
55 return rc < 0 ? rc : 0; 57 return rc < 0 ? rc : 0;
56} 58}
57 59
58static int lan83c185_config_init(struct phy_device *phydev) 60static int smsc_phy_config_init(struct phy_device *phydev)
59{ 61{
60 return lan83c185_ack_interrupt (phydev); 62 return smsc_phy_ack_interrupt (phydev);
61} 63}
62 64
63 65
@@ -73,22 +75,87 @@ static struct phy_driver lan83c185_driver = {
73 /* basic functions */ 75 /* basic functions */
74 .config_aneg = genphy_config_aneg, 76 .config_aneg = genphy_config_aneg,
75 .read_status = genphy_read_status, 77 .read_status = genphy_read_status,
76 .config_init = lan83c185_config_init, 78 .config_init = smsc_phy_config_init,
77 79
78 /* IRQ related */ 80 /* IRQ related */
79 .ack_interrupt = lan83c185_ack_interrupt, 81 .ack_interrupt = smsc_phy_ack_interrupt,
80 .config_intr = lan83c185_config_intr, 82 .config_intr = smsc_phy_config_intr,
83
84 .driver = { .owner = THIS_MODULE, }
85};
86
87static struct phy_driver lan8187_driver = {
88 .phy_id = 0x0007c0b0, /* OUI=0x00800f, Model#=0x0b */
89 .phy_id_mask = 0xfffffff0,
90 .name = "SMSC LAN8187",
91
92 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
93 | SUPPORTED_Asym_Pause),
94 .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
95
96 /* basic functions */
97 .config_aneg = genphy_config_aneg,
98 .read_status = genphy_read_status,
99 .config_init = smsc_phy_config_init,
100
101 /* IRQ related */
102 .ack_interrupt = smsc_phy_ack_interrupt,
103 .config_intr = smsc_phy_config_intr,
104
105 .driver = { .owner = THIS_MODULE, }
106};
107
108static struct phy_driver lan8700_driver = {
109 .phy_id = 0x0007c0c0, /* OUI=0x00800f, Model#=0x0c */
110 .phy_id_mask = 0xfffffff0,
111 .name = "SMSC LAN8700",
112
113 .features = (PHY_BASIC_FEATURES | SUPPORTED_Pause
114 | SUPPORTED_Asym_Pause),
115 .flags = PHY_HAS_INTERRUPT | PHY_HAS_MAGICANEG,
116
117 /* basic functions */
118 .config_aneg = genphy_config_aneg,
119 .read_status = genphy_read_status,
120 .config_init = smsc_phy_config_init,
121
122 /* IRQ related */
123 .ack_interrupt = smsc_phy_ack_interrupt,
124 .config_intr = smsc_phy_config_intr,
81 125
82 .driver = { .owner = THIS_MODULE, } 126 .driver = { .owner = THIS_MODULE, }
83}; 127};
84 128
85static int __init smsc_init(void) 129static int __init smsc_init(void)
86{ 130{
87 return phy_driver_register (&lan83c185_driver); 131 int ret;
132
133 ret = phy_driver_register (&lan83c185_driver);
134 if (ret)
135 goto err1;
136
137 ret = phy_driver_register (&lan8187_driver);
138 if (ret)
139 goto err2;
140
141 ret = phy_driver_register (&lan8700_driver);
142 if (ret)
143 goto err3;
144
145 return 0;
146
147err3:
148 phy_driver_unregister (&lan8187_driver);
149err2:
150 phy_driver_unregister (&lan83c185_driver);
151err1:
152 return ret;
88} 153}
89 154
90static void __exit smsc_exit(void) 155static void __exit smsc_exit(void)
91{ 156{
157 phy_driver_unregister (&lan8700_driver);
158 phy_driver_unregister (&lan8187_driver);
92 phy_driver_unregister (&lan83c185_driver); 159 phy_driver_unregister (&lan83c185_driver);
93} 160}
94 161
diff --git a/drivers/net/ppp_async.c b/drivers/net/ppp_async.c
index f023d5b67e6e..f1a52def1241 100644
--- a/drivers/net/ppp_async.c
+++ b/drivers/net/ppp_async.c
@@ -158,6 +158,9 @@ ppp_asynctty_open(struct tty_struct *tty)
158 struct asyncppp *ap; 158 struct asyncppp *ap;
159 int err; 159 int err;
160 160
161 if (tty->ops->write == NULL)
162 return -EOPNOTSUPP;
163
161 err = -ENOMEM; 164 err = -ENOMEM;
162 ap = kzalloc(sizeof(*ap), GFP_KERNEL); 165 ap = kzalloc(sizeof(*ap), GFP_KERNEL);
163 if (!ap) 166 if (!ap)
@@ -358,9 +361,7 @@ ppp_asynctty_receive(struct tty_struct *tty, const unsigned char *buf,
358 if (!skb_queue_empty(&ap->rqueue)) 361 if (!skb_queue_empty(&ap->rqueue))
359 tasklet_schedule(&ap->tsk); 362 tasklet_schedule(&ap->tsk);
360 ap_put(ap); 363 ap_put(ap);
361 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) 364 tty_unthrottle(tty);
362 && tty->driver->unthrottle)
363 tty->driver->unthrottle(tty);
364} 365}
365 366
366static void 367static void
@@ -676,7 +677,7 @@ ppp_async_push(struct asyncppp *ap)
676 if (!tty_stuffed && ap->optr < ap->olim) { 677 if (!tty_stuffed && ap->optr < ap->olim) {
677 avail = ap->olim - ap->optr; 678 avail = ap->olim - ap->optr;
678 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 679 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
679 sent = tty->driver->write(tty, ap->optr, avail); 680 sent = tty->ops->write(tty, ap->optr, avail);
680 if (sent < 0) 681 if (sent < 0)
681 goto flush; /* error, e.g. loss of CD */ 682 goto flush; /* error, e.g. loss of CD */
682 ap->optr += sent; 683 ap->optr += sent;
diff --git a/drivers/net/ppp_synctty.c b/drivers/net/ppp_synctty.c
index 0d80fa546719..b8f0369a71e7 100644
--- a/drivers/net/ppp_synctty.c
+++ b/drivers/net/ppp_synctty.c
@@ -207,6 +207,9 @@ ppp_sync_open(struct tty_struct *tty)
207 struct syncppp *ap; 207 struct syncppp *ap;
208 int err; 208 int err;
209 209
210 if (tty->ops->write == NULL)
211 return -EOPNOTSUPP;
212
210 ap = kzalloc(sizeof(*ap), GFP_KERNEL); 213 ap = kzalloc(sizeof(*ap), GFP_KERNEL);
211 err = -ENOMEM; 214 err = -ENOMEM;
212 if (!ap) 215 if (!ap)
@@ -398,9 +401,7 @@ ppp_sync_receive(struct tty_struct *tty, const unsigned char *buf,
398 if (!skb_queue_empty(&ap->rqueue)) 401 if (!skb_queue_empty(&ap->rqueue))
399 tasklet_schedule(&ap->tsk); 402 tasklet_schedule(&ap->tsk);
400 sp_put(ap); 403 sp_put(ap);
401 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) 404 tty_unthrottle(tty);
402 && tty->driver->unthrottle)
403 tty->driver->unthrottle(tty);
404} 405}
405 406
406static void 407static void
@@ -653,7 +654,7 @@ ppp_sync_push(struct syncppp *ap)
653 tty_stuffed = 0; 654 tty_stuffed = 0;
654 if (!tty_stuffed && ap->tpkt) { 655 if (!tty_stuffed && ap->tpkt) {
655 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 656 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
656 sent = tty->driver->write(tty, ap->tpkt->data, ap->tpkt->len); 657 sent = tty->ops->write(tty, ap->tpkt->data, ap->tpkt->len);
657 if (sent < 0) 658 if (sent < 0)
658 goto flush; /* error, e.g. loss of CD */ 659 goto flush; /* error, e.g. loss of CD */
659 if (sent < ap->tpkt->len) { 660 if (sent < ap->tpkt->len) {
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index 3acfeeabdee1..657242504621 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -1617,6 +1617,7 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1617 SET_NETDEV_DEV(dev, &pdev->dev); 1617 SET_NETDEV_DEV(dev, &pdev->dev);
1618 tp = netdev_priv(dev); 1618 tp = netdev_priv(dev);
1619 tp->dev = dev; 1619 tp->dev = dev;
1620 tp->pci_dev = pdev;
1620 tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT); 1621 tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT);
1621 1622
1622 /* enable device (incl. PCI PM wakeup and hotplug setup) */ 1623 /* enable device (incl. PCI PM wakeup and hotplug setup) */
@@ -1705,18 +1706,18 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1705 1706
1706 rtl8169_print_mac_version(tp); 1707 rtl8169_print_mac_version(tp);
1707 1708
1708 for (i = ARRAY_SIZE(rtl_chip_info) - 1; i >= 0; i--) { 1709 for (i = 0; i < ARRAY_SIZE(rtl_chip_info); i++) {
1709 if (tp->mac_version == rtl_chip_info[i].mac_version) 1710 if (tp->mac_version == rtl_chip_info[i].mac_version)
1710 break; 1711 break;
1711 } 1712 }
1712 if (i < 0) { 1713 if (i == ARRAY_SIZE(rtl_chip_info)) {
1713 /* Unknown chip: assume array element #0, original RTL-8169 */ 1714 /* Unknown chip: assume array element #0, original RTL-8169 */
1714 if (netif_msg_probe(tp)) { 1715 if (netif_msg_probe(tp)) {
1715 dev_printk(KERN_DEBUG, &pdev->dev, 1716 dev_printk(KERN_DEBUG, &pdev->dev,
1716 "unknown chip version, assuming %s\n", 1717 "unknown chip version, assuming %s\n",
1717 rtl_chip_info[0].name); 1718 rtl_chip_info[0].name);
1718 } 1719 }
1719 i++; 1720 i = 0;
1720 } 1721 }
1721 tp->chipset = i; 1722 tp->chipset = i;
1722 1723
@@ -1777,7 +1778,6 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1777#endif 1778#endif
1778 1779
1779 tp->intr_mask = 0xffff; 1780 tp->intr_mask = 0xffff;
1780 tp->pci_dev = pdev;
1781 tp->mmio_addr = ioaddr; 1781 tp->mmio_addr = ioaddr;
1782 tp->align = cfg->align; 1782 tp->align = cfg->align;
1783 tp->hw_start = cfg->hw_start; 1783 tp->hw_start = cfg->hw_start;
diff --git a/drivers/net/s2io.c b/drivers/net/s2io.c
index 157fd932e951..523478ebfd69 100644
--- a/drivers/net/s2io.c
+++ b/drivers/net/s2io.c
@@ -86,7 +86,7 @@
86#include "s2io.h" 86#include "s2io.h"
87#include "s2io-regs.h" 87#include "s2io-regs.h"
88 88
89#define DRV_VERSION "2.0.26.22" 89#define DRV_VERSION "2.0.26.23"
90 90
91/* S2io Driver name & version. */ 91/* S2io Driver name & version. */
92static char s2io_driver_name[] = "Neterion"; 92static char s2io_driver_name[] = "Neterion";
@@ -809,6 +809,7 @@ static int init_shared_mem(struct s2io_nic *nic)
809 config->rx_cfg[i].num_rxd - 1; 809 config->rx_cfg[i].num_rxd - 1;
810 mac_control->rings[i].nic = nic; 810 mac_control->rings[i].nic = nic;
811 mac_control->rings[i].ring_no = i; 811 mac_control->rings[i].ring_no = i;
812 mac_control->rings[i].lro = lro_enable;
812 813
813 blk_cnt = config->rx_cfg[i].num_rxd / 814 blk_cnt = config->rx_cfg[i].num_rxd /
814 (rxd_count[nic->rxd_mode] + 1); 815 (rxd_count[nic->rxd_mode] + 1);
@@ -1560,113 +1561,112 @@ static int init_nic(struct s2io_nic *nic)
1560 writeq(val64, &bar0->tx_fifo_partition_0); 1561 writeq(val64, &bar0->tx_fifo_partition_0);
1561 1562
1562 /* Filling the Rx round robin registers as per the 1563 /* Filling the Rx round robin registers as per the
1563 * number of Rings and steering based on QoS. 1564 * number of Rings and steering based on QoS with
1564 */ 1565 * equal priority.
1566 */
1565 switch (config->rx_ring_num) { 1567 switch (config->rx_ring_num) {
1566 case 1: 1568 case 1:
1569 val64 = 0x0;
1570 writeq(val64, &bar0->rx_w_round_robin_0);
1571 writeq(val64, &bar0->rx_w_round_robin_1);
1572 writeq(val64, &bar0->rx_w_round_robin_2);
1573 writeq(val64, &bar0->rx_w_round_robin_3);
1574 writeq(val64, &bar0->rx_w_round_robin_4);
1575
1567 val64 = 0x8080808080808080ULL; 1576 val64 = 0x8080808080808080ULL;
1568 writeq(val64, &bar0->rts_qos_steering); 1577 writeq(val64, &bar0->rts_qos_steering);
1569 break; 1578 break;
1570 case 2: 1579 case 2:
1571 val64 = 0x0000010000010000ULL; 1580 val64 = 0x0001000100010001ULL;
1572 writeq(val64, &bar0->rx_w_round_robin_0); 1581 writeq(val64, &bar0->rx_w_round_robin_0);
1573 val64 = 0x0100000100000100ULL;
1574 writeq(val64, &bar0->rx_w_round_robin_1); 1582 writeq(val64, &bar0->rx_w_round_robin_1);
1575 val64 = 0x0001000001000001ULL;
1576 writeq(val64, &bar0->rx_w_round_robin_2); 1583 writeq(val64, &bar0->rx_w_round_robin_2);
1577 val64 = 0x0000010000010000ULL;
1578 writeq(val64, &bar0->rx_w_round_robin_3); 1584 writeq(val64, &bar0->rx_w_round_robin_3);
1579 val64 = 0x0100000000000000ULL; 1585 val64 = 0x0001000100000000ULL;
1580 writeq(val64, &bar0->rx_w_round_robin_4); 1586 writeq(val64, &bar0->rx_w_round_robin_4);
1581 1587
1582 val64 = 0x8080808040404040ULL; 1588 val64 = 0x8080808040404040ULL;
1583 writeq(val64, &bar0->rts_qos_steering); 1589 writeq(val64, &bar0->rts_qos_steering);
1584 break; 1590 break;
1585 case 3: 1591 case 3:
1586 val64 = 0x0001000102000001ULL; 1592 val64 = 0x0001020001020001ULL;
1587 writeq(val64, &bar0->rx_w_round_robin_0); 1593 writeq(val64, &bar0->rx_w_round_robin_0);
1588 val64 = 0x0001020000010001ULL; 1594 val64 = 0x0200010200010200ULL;
1589 writeq(val64, &bar0->rx_w_round_robin_1); 1595 writeq(val64, &bar0->rx_w_round_robin_1);
1590 val64 = 0x0200000100010200ULL; 1596 val64 = 0x0102000102000102ULL;
1591 writeq(val64, &bar0->rx_w_round_robin_2); 1597 writeq(val64, &bar0->rx_w_round_robin_2);
1592 val64 = 0x0001000102000001ULL; 1598 val64 = 0x0001020001020001ULL;
1593 writeq(val64, &bar0->rx_w_round_robin_3); 1599 writeq(val64, &bar0->rx_w_round_robin_3);
1594 val64 = 0x0001020000000000ULL; 1600 val64 = 0x0200010200000000ULL;
1595 writeq(val64, &bar0->rx_w_round_robin_4); 1601 writeq(val64, &bar0->rx_w_round_robin_4);
1596 1602
1597 val64 = 0x8080804040402020ULL; 1603 val64 = 0x8080804040402020ULL;
1598 writeq(val64, &bar0->rts_qos_steering); 1604 writeq(val64, &bar0->rts_qos_steering);
1599 break; 1605 break;
1600 case 4: 1606 case 4:
1601 val64 = 0x0001020300010200ULL; 1607 val64 = 0x0001020300010203ULL;
1602 writeq(val64, &bar0->rx_w_round_robin_0); 1608 writeq(val64, &bar0->rx_w_round_robin_0);
1603 val64 = 0x0100000102030001ULL;
1604 writeq(val64, &bar0->rx_w_round_robin_1); 1609 writeq(val64, &bar0->rx_w_round_robin_1);
1605 val64 = 0x0200010000010203ULL;
1606 writeq(val64, &bar0->rx_w_round_robin_2); 1610 writeq(val64, &bar0->rx_w_round_robin_2);
1607 val64 = 0x0001020001000001ULL;
1608 writeq(val64, &bar0->rx_w_round_robin_3); 1611 writeq(val64, &bar0->rx_w_round_robin_3);
1609 val64 = 0x0203000100000000ULL; 1612 val64 = 0x0001020300000000ULL;
1610 writeq(val64, &bar0->rx_w_round_robin_4); 1613 writeq(val64, &bar0->rx_w_round_robin_4);
1611 1614
1612 val64 = 0x8080404020201010ULL; 1615 val64 = 0x8080404020201010ULL;
1613 writeq(val64, &bar0->rts_qos_steering); 1616 writeq(val64, &bar0->rts_qos_steering);
1614 break; 1617 break;
1615 case 5: 1618 case 5:
1616 val64 = 0x0001000203000102ULL; 1619 val64 = 0x0001020304000102ULL;
1617 writeq(val64, &bar0->rx_w_round_robin_0); 1620 writeq(val64, &bar0->rx_w_round_robin_0);
1618 val64 = 0x0001020001030004ULL; 1621 val64 = 0x0304000102030400ULL;
1619 writeq(val64, &bar0->rx_w_round_robin_1); 1622 writeq(val64, &bar0->rx_w_round_robin_1);
1620 val64 = 0x0001000203000102ULL; 1623 val64 = 0x0102030400010203ULL;
1621 writeq(val64, &bar0->rx_w_round_robin_2); 1624 writeq(val64, &bar0->rx_w_round_robin_2);
1622 val64 = 0x0001020001030004ULL; 1625 val64 = 0x0400010203040001ULL;
1623 writeq(val64, &bar0->rx_w_round_robin_3); 1626 writeq(val64, &bar0->rx_w_round_robin_3);
1624 val64 = 0x0001000000000000ULL; 1627 val64 = 0x0203040000000000ULL;
1625 writeq(val64, &bar0->rx_w_round_robin_4); 1628 writeq(val64, &bar0->rx_w_round_robin_4);
1626 1629
1627 val64 = 0x8080404020201008ULL; 1630 val64 = 0x8080404020201008ULL;
1628 writeq(val64, &bar0->rts_qos_steering); 1631 writeq(val64, &bar0->rts_qos_steering);
1629 break; 1632 break;
1630 case 6: 1633 case 6:
1631 val64 = 0x0001020304000102ULL; 1634 val64 = 0x0001020304050001ULL;
1632 writeq(val64, &bar0->rx_w_round_robin_0); 1635 writeq(val64, &bar0->rx_w_round_robin_0);
1633 val64 = 0x0304050001020001ULL; 1636 val64 = 0x0203040500010203ULL;
1634 writeq(val64, &bar0->rx_w_round_robin_1); 1637 writeq(val64, &bar0->rx_w_round_robin_1);
1635 val64 = 0x0203000100000102ULL; 1638 val64 = 0x0405000102030405ULL;
1636 writeq(val64, &bar0->rx_w_round_robin_2); 1639 writeq(val64, &bar0->rx_w_round_robin_2);
1637 val64 = 0x0304000102030405ULL; 1640 val64 = 0x0001020304050001ULL;
1638 writeq(val64, &bar0->rx_w_round_robin_3); 1641 writeq(val64, &bar0->rx_w_round_robin_3);
1639 val64 = 0x0001000200000000ULL; 1642 val64 = 0x0203040500000000ULL;
1640 writeq(val64, &bar0->rx_w_round_robin_4); 1643 writeq(val64, &bar0->rx_w_round_robin_4);
1641 1644
1642 val64 = 0x8080404020100804ULL; 1645 val64 = 0x8080404020100804ULL;
1643 writeq(val64, &bar0->rts_qos_steering); 1646 writeq(val64, &bar0->rts_qos_steering);
1644 break; 1647 break;
1645 case 7: 1648 case 7:
1646 val64 = 0x0001020001020300ULL; 1649 val64 = 0x0001020304050600ULL;
1647 writeq(val64, &bar0->rx_w_round_robin_0); 1650 writeq(val64, &bar0->rx_w_round_robin_0);
1648 val64 = 0x0102030400010203ULL; 1651 val64 = 0x0102030405060001ULL;
1649 writeq(val64, &bar0->rx_w_round_robin_1); 1652 writeq(val64, &bar0->rx_w_round_robin_1);
1650 val64 = 0x0405060001020001ULL; 1653 val64 = 0x0203040506000102ULL;
1651 writeq(val64, &bar0->rx_w_round_robin_2); 1654 writeq(val64, &bar0->rx_w_round_robin_2);
1652 val64 = 0x0304050000010200ULL; 1655 val64 = 0x0304050600010203ULL;
1653 writeq(val64, &bar0->rx_w_round_robin_3); 1656 writeq(val64, &bar0->rx_w_round_robin_3);
1654 val64 = 0x0102030000000000ULL; 1657 val64 = 0x0405060000000000ULL;
1655 writeq(val64, &bar0->rx_w_round_robin_4); 1658 writeq(val64, &bar0->rx_w_round_robin_4);
1656 1659
1657 val64 = 0x8080402010080402ULL; 1660 val64 = 0x8080402010080402ULL;
1658 writeq(val64, &bar0->rts_qos_steering); 1661 writeq(val64, &bar0->rts_qos_steering);
1659 break; 1662 break;
1660 case 8: 1663 case 8:
1661 val64 = 0x0001020300040105ULL; 1664 val64 = 0x0001020304050607ULL;
1662 writeq(val64, &bar0->rx_w_round_robin_0); 1665 writeq(val64, &bar0->rx_w_round_robin_0);
1663 val64 = 0x0200030106000204ULL;
1664 writeq(val64, &bar0->rx_w_round_robin_1); 1666 writeq(val64, &bar0->rx_w_round_robin_1);
1665 val64 = 0x0103000502010007ULL;
1666 writeq(val64, &bar0->rx_w_round_robin_2); 1667 writeq(val64, &bar0->rx_w_round_robin_2);
1667 val64 = 0x0304010002060500ULL;
1668 writeq(val64, &bar0->rx_w_round_robin_3); 1668 writeq(val64, &bar0->rx_w_round_robin_3);
1669 val64 = 0x0103020400000000ULL; 1669 val64 = 0x0001020300000000ULL;
1670 writeq(val64, &bar0->rx_w_round_robin_4); 1670 writeq(val64, &bar0->rx_w_round_robin_4);
1671 1671
1672 val64 = 0x8040201008040201ULL; 1672 val64 = 0x8040201008040201ULL;
@@ -2499,8 +2499,7 @@ static void stop_nic(struct s2io_nic *nic)
2499 2499
2500/** 2500/**
2501 * fill_rx_buffers - Allocates the Rx side skbs 2501 * fill_rx_buffers - Allocates the Rx side skbs
2502 * @nic: device private variable 2502 * @ring_info: per ring structure
2503 * @ring_no: ring number
2504 * Description: 2503 * Description:
2505 * The function allocates Rx side skbs and puts the physical 2504 * The function allocates Rx side skbs and puts the physical
2506 * address of these buffers into the RxD buffer pointers, so that the NIC 2505 * address of these buffers into the RxD buffer pointers, so that the NIC
@@ -2518,103 +2517,94 @@ static void stop_nic(struct s2io_nic *nic)
2518 * SUCCESS on success or an appropriate -ve value on failure. 2517 * SUCCESS on success or an appropriate -ve value on failure.
2519 */ 2518 */
2520 2519
2521static int fill_rx_buffers(struct s2io_nic *nic, int ring_no) 2520static int fill_rx_buffers(struct ring_info *ring)
2522{ 2521{
2523 struct net_device *dev = nic->dev;
2524 struct sk_buff *skb; 2522 struct sk_buff *skb;
2525 struct RxD_t *rxdp; 2523 struct RxD_t *rxdp;
2526 int off, off1, size, block_no, block_no1; 2524 int off, size, block_no, block_no1;
2527 u32 alloc_tab = 0; 2525 u32 alloc_tab = 0;
2528 u32 alloc_cnt; 2526 u32 alloc_cnt;
2529 struct mac_info *mac_control;
2530 struct config_param *config;
2531 u64 tmp; 2527 u64 tmp;
2532 struct buffAdd *ba; 2528 struct buffAdd *ba;
2533 struct RxD_t *first_rxdp = NULL; 2529 struct RxD_t *first_rxdp = NULL;
2534 u64 Buffer0_ptr = 0, Buffer1_ptr = 0; 2530 u64 Buffer0_ptr = 0, Buffer1_ptr = 0;
2531 int rxd_index = 0;
2535 struct RxD1 *rxdp1; 2532 struct RxD1 *rxdp1;
2536 struct RxD3 *rxdp3; 2533 struct RxD3 *rxdp3;
2537 struct swStat *stats = &nic->mac_control.stats_info->sw_stat; 2534 struct swStat *stats = &ring->nic->mac_control.stats_info->sw_stat;
2538 2535
2539 mac_control = &nic->mac_control; 2536 alloc_cnt = ring->pkt_cnt - ring->rx_bufs_left;
2540 config = &nic->config;
2541 alloc_cnt = mac_control->rings[ring_no].pkt_cnt -
2542 atomic_read(&nic->rx_bufs_left[ring_no]);
2543 2537
2544 block_no1 = mac_control->rings[ring_no].rx_curr_get_info.block_index; 2538 block_no1 = ring->rx_curr_get_info.block_index;
2545 off1 = mac_control->rings[ring_no].rx_curr_get_info.offset;
2546 while (alloc_tab < alloc_cnt) { 2539 while (alloc_tab < alloc_cnt) {
2547 block_no = mac_control->rings[ring_no].rx_curr_put_info. 2540 block_no = ring->rx_curr_put_info.block_index;
2548 block_index;
2549 off = mac_control->rings[ring_no].rx_curr_put_info.offset;
2550 2541
2551 rxdp = mac_control->rings[ring_no]. 2542 off = ring->rx_curr_put_info.offset;
2552 rx_blocks[block_no].rxds[off].virt_addr; 2543
2544 rxdp = ring->rx_blocks[block_no].rxds[off].virt_addr;
2545
2546 rxd_index = off + 1;
2547 if (block_no)
2548 rxd_index += (block_no * ring->rxd_count);
2553 2549
2554 if ((block_no == block_no1) && (off == off1) && 2550 if ((block_no == block_no1) &&
2555 (rxdp->Host_Control)) { 2551 (off == ring->rx_curr_get_info.offset) &&
2552 (rxdp->Host_Control)) {
2556 DBG_PRINT(INTR_DBG, "%s: Get and Put", 2553 DBG_PRINT(INTR_DBG, "%s: Get and Put",
2557 dev->name); 2554 ring->dev->name);
2558 DBG_PRINT(INTR_DBG, " info equated\n"); 2555 DBG_PRINT(INTR_DBG, " info equated\n");
2559 goto end; 2556 goto end;
2560 } 2557 }
2561 if (off && (off == rxd_count[nic->rxd_mode])) { 2558 if (off && (off == ring->rxd_count)) {
2562 mac_control->rings[ring_no].rx_curr_put_info. 2559 ring->rx_curr_put_info.block_index++;
2563 block_index++; 2560 if (ring->rx_curr_put_info.block_index ==
2564 if (mac_control->rings[ring_no].rx_curr_put_info. 2561 ring->block_count)
2565 block_index == mac_control->rings[ring_no]. 2562 ring->rx_curr_put_info.block_index = 0;
2566 block_count) 2563 block_no = ring->rx_curr_put_info.block_index;
2567 mac_control->rings[ring_no].rx_curr_put_info. 2564 off = 0;
2568 block_index = 0; 2565 ring->rx_curr_put_info.offset = off;
2569 block_no = mac_control->rings[ring_no]. 2566 rxdp = ring->rx_blocks[block_no].block_virt_addr;
2570 rx_curr_put_info.block_index;
2571 if (off == rxd_count[nic->rxd_mode])
2572 off = 0;
2573 mac_control->rings[ring_no].rx_curr_put_info.
2574 offset = off;
2575 rxdp = mac_control->rings[ring_no].
2576 rx_blocks[block_no].block_virt_addr;
2577 DBG_PRINT(INTR_DBG, "%s: Next block at: %p\n", 2567 DBG_PRINT(INTR_DBG, "%s: Next block at: %p\n",
2578 dev->name, rxdp); 2568 ring->dev->name, rxdp);
2569
2579 } 2570 }
2580 2571
2581 if ((rxdp->Control_1 & RXD_OWN_XENA) && 2572 if ((rxdp->Control_1 & RXD_OWN_XENA) &&
2582 ((nic->rxd_mode == RXD_MODE_3B) && 2573 ((ring->rxd_mode == RXD_MODE_3B) &&
2583 (rxdp->Control_2 & s2BIT(0)))) { 2574 (rxdp->Control_2 & s2BIT(0)))) {
2584 mac_control->rings[ring_no].rx_curr_put_info. 2575 ring->rx_curr_put_info.offset = off;
2585 offset = off;
2586 goto end; 2576 goto end;
2587 } 2577 }
2588 /* calculate size of skb based on ring mode */ 2578 /* calculate size of skb based on ring mode */
2589 size = dev->mtu + HEADER_ETHERNET_II_802_3_SIZE + 2579 size = ring->mtu + HEADER_ETHERNET_II_802_3_SIZE +
2590 HEADER_802_2_SIZE + HEADER_SNAP_SIZE; 2580 HEADER_802_2_SIZE + HEADER_SNAP_SIZE;
2591 if (nic->rxd_mode == RXD_MODE_1) 2581 if (ring->rxd_mode == RXD_MODE_1)
2592 size += NET_IP_ALIGN; 2582 size += NET_IP_ALIGN;
2593 else 2583 else
2594 size = dev->mtu + ALIGN_SIZE + BUF0_LEN + 4; 2584 size = ring->mtu + ALIGN_SIZE + BUF0_LEN + 4;
2595 2585
2596 /* allocate skb */ 2586 /* allocate skb */
2597 skb = dev_alloc_skb(size); 2587 skb = dev_alloc_skb(size);
2598 if(!skb) { 2588 if(!skb) {
2599 DBG_PRINT(INFO_DBG, "%s: Out of ", dev->name); 2589 DBG_PRINT(INFO_DBG, "%s: Out of ", ring->dev->name);
2600 DBG_PRINT(INFO_DBG, "memory to allocate SKBs\n"); 2590 DBG_PRINT(INFO_DBG, "memory to allocate SKBs\n");
2601 if (first_rxdp) { 2591 if (first_rxdp) {
2602 wmb(); 2592 wmb();
2603 first_rxdp->Control_1 |= RXD_OWN_XENA; 2593 first_rxdp->Control_1 |= RXD_OWN_XENA;
2604 } 2594 }
2605 nic->mac_control.stats_info->sw_stat. \ 2595 stats->mem_alloc_fail_cnt++;
2606 mem_alloc_fail_cnt++; 2596
2607 return -ENOMEM ; 2597 return -ENOMEM ;
2608 } 2598 }
2609 nic->mac_control.stats_info->sw_stat.mem_allocated 2599 stats->mem_allocated += skb->truesize;
2610 += skb->truesize; 2600
2611 if (nic->rxd_mode == RXD_MODE_1) { 2601 if (ring->rxd_mode == RXD_MODE_1) {
2612 /* 1 buffer mode - normal operation mode */ 2602 /* 1 buffer mode - normal operation mode */
2613 rxdp1 = (struct RxD1*)rxdp; 2603 rxdp1 = (struct RxD1*)rxdp;
2614 memset(rxdp, 0, sizeof(struct RxD1)); 2604 memset(rxdp, 0, sizeof(struct RxD1));
2615 skb_reserve(skb, NET_IP_ALIGN); 2605 skb_reserve(skb, NET_IP_ALIGN);
2616 rxdp1->Buffer0_ptr = pci_map_single 2606 rxdp1->Buffer0_ptr = pci_map_single
2617 (nic->pdev, skb->data, size - NET_IP_ALIGN, 2607 (ring->pdev, skb->data, size - NET_IP_ALIGN,
2618 PCI_DMA_FROMDEVICE); 2608 PCI_DMA_FROMDEVICE);
2619 if( (rxdp1->Buffer0_ptr == 0) || 2609 if( (rxdp1->Buffer0_ptr == 0) ||
2620 (rxdp1->Buffer0_ptr == 2610 (rxdp1->Buffer0_ptr ==
@@ -2623,8 +2613,8 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
2623 2613
2624 rxdp->Control_2 = 2614 rxdp->Control_2 =
2625 SET_BUFFER0_SIZE_1(size - NET_IP_ALIGN); 2615 SET_BUFFER0_SIZE_1(size - NET_IP_ALIGN);
2626 2616 rxdp->Host_Control = (unsigned long) (skb);
2627 } else if (nic->rxd_mode == RXD_MODE_3B) { 2617 } else if (ring->rxd_mode == RXD_MODE_3B) {
2628 /* 2618 /*
2629 * 2 buffer mode - 2619 * 2 buffer mode -
2630 * 2 buffer mode provides 128 2620 * 2 buffer mode provides 128
@@ -2640,7 +2630,7 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
2640 rxdp3->Buffer0_ptr = Buffer0_ptr; 2630 rxdp3->Buffer0_ptr = Buffer0_ptr;
2641 rxdp3->Buffer1_ptr = Buffer1_ptr; 2631 rxdp3->Buffer1_ptr = Buffer1_ptr;
2642 2632
2643 ba = &mac_control->rings[ring_no].ba[block_no][off]; 2633 ba = &ring->ba[block_no][off];
2644 skb_reserve(skb, BUF0_LEN); 2634 skb_reserve(skb, BUF0_LEN);
2645 tmp = (u64)(unsigned long) skb->data; 2635 tmp = (u64)(unsigned long) skb->data;
2646 tmp += ALIGN_SIZE; 2636 tmp += ALIGN_SIZE;
@@ -2650,10 +2640,10 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
2650 2640
2651 if (!(rxdp3->Buffer0_ptr)) 2641 if (!(rxdp3->Buffer0_ptr))
2652 rxdp3->Buffer0_ptr = 2642 rxdp3->Buffer0_ptr =
2653 pci_map_single(nic->pdev, ba->ba_0, BUF0_LEN, 2643 pci_map_single(ring->pdev, ba->ba_0,
2654 PCI_DMA_FROMDEVICE); 2644 BUF0_LEN, PCI_DMA_FROMDEVICE);
2655 else 2645 else
2656 pci_dma_sync_single_for_device(nic->pdev, 2646 pci_dma_sync_single_for_device(ring->pdev,
2657 (dma_addr_t) rxdp3->Buffer0_ptr, 2647 (dma_addr_t) rxdp3->Buffer0_ptr,
2658 BUF0_LEN, PCI_DMA_FROMDEVICE); 2648 BUF0_LEN, PCI_DMA_FROMDEVICE);
2659 if( (rxdp3->Buffer0_ptr == 0) || 2649 if( (rxdp3->Buffer0_ptr == 0) ||
@@ -2661,7 +2651,7 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
2661 goto pci_map_failed; 2651 goto pci_map_failed;
2662 2652
2663 rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN); 2653 rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN);
2664 if (nic->rxd_mode == RXD_MODE_3B) { 2654 if (ring->rxd_mode == RXD_MODE_3B) {
2665 /* Two buffer mode */ 2655 /* Two buffer mode */
2666 2656
2667 /* 2657 /*
@@ -2669,39 +2659,42 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
2669 * L4 payload 2659 * L4 payload
2670 */ 2660 */
2671 rxdp3->Buffer2_ptr = pci_map_single 2661 rxdp3->Buffer2_ptr = pci_map_single
2672 (nic->pdev, skb->data, dev->mtu + 4, 2662 (ring->pdev, skb->data, ring->mtu + 4,
2673 PCI_DMA_FROMDEVICE); 2663 PCI_DMA_FROMDEVICE);
2674 2664
2675 if( (rxdp3->Buffer2_ptr == 0) || 2665 if( (rxdp3->Buffer2_ptr == 0) ||
2676 (rxdp3->Buffer2_ptr == DMA_ERROR_CODE)) 2666 (rxdp3->Buffer2_ptr == DMA_ERROR_CODE))
2677 goto pci_map_failed; 2667 goto pci_map_failed;
2678 2668
2679 rxdp3->Buffer1_ptr = 2669 if (!rxdp3->Buffer1_ptr)
2680 pci_map_single(nic->pdev, 2670 rxdp3->Buffer1_ptr =
2671 pci_map_single(ring->pdev,
2681 ba->ba_1, BUF1_LEN, 2672 ba->ba_1, BUF1_LEN,
2682 PCI_DMA_FROMDEVICE); 2673 PCI_DMA_FROMDEVICE);
2674
2683 if( (rxdp3->Buffer1_ptr == 0) || 2675 if( (rxdp3->Buffer1_ptr == 0) ||
2684 (rxdp3->Buffer1_ptr == DMA_ERROR_CODE)) { 2676 (rxdp3->Buffer1_ptr == DMA_ERROR_CODE)) {
2685 pci_unmap_single 2677 pci_unmap_single
2686 (nic->pdev, 2678 (ring->pdev,
2687 (dma_addr_t)rxdp3->Buffer2_ptr, 2679 (dma_addr_t)(unsigned long)
2688 dev->mtu + 4, 2680 skb->data,
2681 ring->mtu + 4,
2689 PCI_DMA_FROMDEVICE); 2682 PCI_DMA_FROMDEVICE);
2690 goto pci_map_failed; 2683 goto pci_map_failed;
2691 } 2684 }
2692 rxdp->Control_2 |= SET_BUFFER1_SIZE_3(1); 2685 rxdp->Control_2 |= SET_BUFFER1_SIZE_3(1);
2693 rxdp->Control_2 |= SET_BUFFER2_SIZE_3 2686 rxdp->Control_2 |= SET_BUFFER2_SIZE_3
2694 (dev->mtu + 4); 2687 (ring->mtu + 4);
2695 } 2688 }
2696 rxdp->Control_2 |= s2BIT(0); 2689 rxdp->Control_2 |= s2BIT(0);
2690 rxdp->Host_Control = (unsigned long) (skb);
2697 } 2691 }
2698 rxdp->Host_Control = (unsigned long) (skb);
2699 if (alloc_tab & ((1 << rxsync_frequency) - 1)) 2692 if (alloc_tab & ((1 << rxsync_frequency) - 1))
2700 rxdp->Control_1 |= RXD_OWN_XENA; 2693 rxdp->Control_1 |= RXD_OWN_XENA;
2701 off++; 2694 off++;
2702 if (off == (rxd_count[nic->rxd_mode] + 1)) 2695 if (off == (ring->rxd_count + 1))
2703 off = 0; 2696 off = 0;
2704 mac_control->rings[ring_no].rx_curr_put_info.offset = off; 2697 ring->rx_curr_put_info.offset = off;
2705 2698
2706 rxdp->Control_2 |= SET_RXD_MARKER; 2699 rxdp->Control_2 |= SET_RXD_MARKER;
2707 if (!(alloc_tab & ((1 << rxsync_frequency) - 1))) { 2700 if (!(alloc_tab & ((1 << rxsync_frequency) - 1))) {
@@ -2711,7 +2704,7 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
2711 } 2704 }
2712 first_rxdp = rxdp; 2705 first_rxdp = rxdp;
2713 } 2706 }
2714 atomic_inc(&nic->rx_bufs_left[ring_no]); 2707 ring->rx_bufs_left += 1;
2715 alloc_tab++; 2708 alloc_tab++;
2716 } 2709 }
2717 2710
@@ -2783,7 +2776,7 @@ static void free_rxd_blk(struct s2io_nic *sp, int ring_no, int blk)
2783 } 2776 }
2784 sp->mac_control.stats_info->sw_stat.mem_freed += skb->truesize; 2777 sp->mac_control.stats_info->sw_stat.mem_freed += skb->truesize;
2785 dev_kfree_skb(skb); 2778 dev_kfree_skb(skb);
2786 atomic_dec(&sp->rx_bufs_left[ring_no]); 2779 mac_control->rings[ring_no].rx_bufs_left -= 1;
2787 } 2780 }
2788} 2781}
2789 2782
@@ -2814,7 +2807,7 @@ static void free_rx_buffers(struct s2io_nic *sp)
2814 mac_control->rings[i].rx_curr_get_info.block_index = 0; 2807 mac_control->rings[i].rx_curr_get_info.block_index = 0;
2815 mac_control->rings[i].rx_curr_put_info.offset = 0; 2808 mac_control->rings[i].rx_curr_put_info.offset = 0;
2816 mac_control->rings[i].rx_curr_get_info.offset = 0; 2809 mac_control->rings[i].rx_curr_get_info.offset = 0;
2817 atomic_set(&sp->rx_bufs_left[i], 0); 2810 mac_control->rings[i].rx_bufs_left = 0;
2818 DBG_PRINT(INIT_DBG, "%s:Freed 0x%x Rx Buffers on ring%d\n", 2811 DBG_PRINT(INIT_DBG, "%s:Freed 0x%x Rx Buffers on ring%d\n",
2819 dev->name, buf_cnt, i); 2812 dev->name, buf_cnt, i);
2820 } 2813 }
@@ -2864,7 +2857,7 @@ static int s2io_poll(struct napi_struct *napi, int budget)
2864 netif_rx_complete(dev, napi); 2857 netif_rx_complete(dev, napi);
2865 2858
2866 for (i = 0; i < config->rx_ring_num; i++) { 2859 for (i = 0; i < config->rx_ring_num; i++) {
2867 if (fill_rx_buffers(nic, i) == -ENOMEM) { 2860 if (fill_rx_buffers(&mac_control->rings[i]) == -ENOMEM) {
2868 DBG_PRINT(INFO_DBG, "%s:Out of memory", dev->name); 2861 DBG_PRINT(INFO_DBG, "%s:Out of memory", dev->name);
2869 DBG_PRINT(INFO_DBG, " in Rx Poll!!\n"); 2862 DBG_PRINT(INFO_DBG, " in Rx Poll!!\n");
2870 break; 2863 break;
@@ -2877,7 +2870,7 @@ static int s2io_poll(struct napi_struct *napi, int budget)
2877 2870
2878no_rx: 2871no_rx:
2879 for (i = 0; i < config->rx_ring_num; i++) { 2872 for (i = 0; i < config->rx_ring_num; i++) {
2880 if (fill_rx_buffers(nic, i) == -ENOMEM) { 2873 if (fill_rx_buffers(&mac_control->rings[i]) == -ENOMEM) {
2881 DBG_PRINT(INFO_DBG, "%s:Out of memory", dev->name); 2874 DBG_PRINT(INFO_DBG, "%s:Out of memory", dev->name);
2882 DBG_PRINT(INFO_DBG, " in Rx Poll!!\n"); 2875 DBG_PRINT(INFO_DBG, " in Rx Poll!!\n");
2883 break; 2876 break;
@@ -2928,7 +2921,7 @@ static void s2io_netpoll(struct net_device *dev)
2928 rx_intr_handler(&mac_control->rings[i]); 2921 rx_intr_handler(&mac_control->rings[i]);
2929 2922
2930 for (i = 0; i < config->rx_ring_num; i++) { 2923 for (i = 0; i < config->rx_ring_num; i++) {
2931 if (fill_rx_buffers(nic, i) == -ENOMEM) { 2924 if (fill_rx_buffers(&mac_control->rings[i]) == -ENOMEM) {
2932 DBG_PRINT(INFO_DBG, "%s:Out of memory", dev->name); 2925 DBG_PRINT(INFO_DBG, "%s:Out of memory", dev->name);
2933 DBG_PRINT(INFO_DBG, " in Rx Netpoll!!\n"); 2926 DBG_PRINT(INFO_DBG, " in Rx Netpoll!!\n");
2934 break; 2927 break;
@@ -2953,8 +2946,6 @@ static void s2io_netpoll(struct net_device *dev)
2953 */ 2946 */
2954static void rx_intr_handler(struct ring_info *ring_data) 2947static void rx_intr_handler(struct ring_info *ring_data)
2955{ 2948{
2956 struct s2io_nic *nic = ring_data->nic;
2957 struct net_device *dev = (struct net_device *) nic->dev;
2958 int get_block, put_block; 2949 int get_block, put_block;
2959 struct rx_curr_get_info get_info, put_info; 2950 struct rx_curr_get_info get_info, put_info;
2960 struct RxD_t *rxdp; 2951 struct RxD_t *rxdp;
@@ -2977,33 +2968,34 @@ static void rx_intr_handler(struct ring_info *ring_data)
2977 */ 2968 */
2978 if ((get_block == put_block) && 2969 if ((get_block == put_block) &&
2979 (get_info.offset + 1) == put_info.offset) { 2970 (get_info.offset + 1) == put_info.offset) {
2980 DBG_PRINT(INTR_DBG, "%s: Ring Full\n",dev->name); 2971 DBG_PRINT(INTR_DBG, "%s: Ring Full\n",
2972 ring_data->dev->name);
2981 break; 2973 break;
2982 } 2974 }
2983 skb = (struct sk_buff *) ((unsigned long)rxdp->Host_Control); 2975 skb = (struct sk_buff *) ((unsigned long)rxdp->Host_Control);
2984 if (skb == NULL) { 2976 if (skb == NULL) {
2985 DBG_PRINT(ERR_DBG, "%s: The skb is ", 2977 DBG_PRINT(ERR_DBG, "%s: The skb is ",
2986 dev->name); 2978 ring_data->dev->name);
2987 DBG_PRINT(ERR_DBG, "Null in Rx Intr\n"); 2979 DBG_PRINT(ERR_DBG, "Null in Rx Intr\n");
2988 return; 2980 return;
2989 } 2981 }
2990 if (nic->rxd_mode == RXD_MODE_1) { 2982 if (ring_data->rxd_mode == RXD_MODE_1) {
2991 rxdp1 = (struct RxD1*)rxdp; 2983 rxdp1 = (struct RxD1*)rxdp;
2992 pci_unmap_single(nic->pdev, (dma_addr_t) 2984 pci_unmap_single(ring_data->pdev, (dma_addr_t)
2993 rxdp1->Buffer0_ptr, 2985 rxdp1->Buffer0_ptr,
2994 dev->mtu + 2986 ring_data->mtu +
2995 HEADER_ETHERNET_II_802_3_SIZE + 2987 HEADER_ETHERNET_II_802_3_SIZE +
2996 HEADER_802_2_SIZE + 2988 HEADER_802_2_SIZE +
2997 HEADER_SNAP_SIZE, 2989 HEADER_SNAP_SIZE,
2998 PCI_DMA_FROMDEVICE); 2990 PCI_DMA_FROMDEVICE);
2999 } else if (nic->rxd_mode == RXD_MODE_3B) { 2991 } else if (ring_data->rxd_mode == RXD_MODE_3B) {
3000 rxdp3 = (struct RxD3*)rxdp; 2992 rxdp3 = (struct RxD3*)rxdp;
3001 pci_dma_sync_single_for_cpu(nic->pdev, (dma_addr_t) 2993 pci_dma_sync_single_for_cpu(ring_data->pdev, (dma_addr_t)
3002 rxdp3->Buffer0_ptr, 2994 rxdp3->Buffer0_ptr,
3003 BUF0_LEN, PCI_DMA_FROMDEVICE); 2995 BUF0_LEN, PCI_DMA_FROMDEVICE);
3004 pci_unmap_single(nic->pdev, (dma_addr_t) 2996 pci_unmap_single(ring_data->pdev, (dma_addr_t)
3005 rxdp3->Buffer2_ptr, 2997 rxdp3->Buffer2_ptr,
3006 dev->mtu + 4, 2998 ring_data->mtu + 4,
3007 PCI_DMA_FROMDEVICE); 2999 PCI_DMA_FROMDEVICE);
3008 } 3000 }
3009 prefetch(skb->data); 3001 prefetch(skb->data);
@@ -3012,7 +3004,7 @@ static void rx_intr_handler(struct ring_info *ring_data)
3012 ring_data->rx_curr_get_info.offset = get_info.offset; 3004 ring_data->rx_curr_get_info.offset = get_info.offset;
3013 rxdp = ring_data->rx_blocks[get_block]. 3005 rxdp = ring_data->rx_blocks[get_block].
3014 rxds[get_info.offset].virt_addr; 3006 rxds[get_info.offset].virt_addr;
3015 if (get_info.offset == rxd_count[nic->rxd_mode]) { 3007 if (get_info.offset == rxd_count[ring_data->rxd_mode]) {
3016 get_info.offset = 0; 3008 get_info.offset = 0;
3017 ring_data->rx_curr_get_info.offset = get_info.offset; 3009 ring_data->rx_curr_get_info.offset = get_info.offset;
3018 get_block++; 3010 get_block++;
@@ -3022,19 +3014,21 @@ static void rx_intr_handler(struct ring_info *ring_data)
3022 rxdp = ring_data->rx_blocks[get_block].block_virt_addr; 3014 rxdp = ring_data->rx_blocks[get_block].block_virt_addr;
3023 } 3015 }
3024 3016
3025 nic->pkts_to_process -= 1; 3017 if(ring_data->nic->config.napi){
3026 if ((napi) && (!nic->pkts_to_process)) 3018 ring_data->nic->pkts_to_process -= 1;
3027 break; 3019 if (!ring_data->nic->pkts_to_process)
3020 break;
3021 }
3028 pkt_cnt++; 3022 pkt_cnt++;
3029 if ((indicate_max_pkts) && (pkt_cnt > indicate_max_pkts)) 3023 if ((indicate_max_pkts) && (pkt_cnt > indicate_max_pkts))
3030 break; 3024 break;
3031 } 3025 }
3032 if (nic->lro) { 3026 if (ring_data->lro) {
3033 /* Clear all LRO sessions before exiting */ 3027 /* Clear all LRO sessions before exiting */
3034 for (i=0; i<MAX_LRO_SESSIONS; i++) { 3028 for (i=0; i<MAX_LRO_SESSIONS; i++) {
3035 struct lro *lro = &nic->lro0_n[i]; 3029 struct lro *lro = &ring_data->lro0_n[i];
3036 if (lro->in_use) { 3030 if (lro->in_use) {
3037 update_L3L4_header(nic, lro); 3031 update_L3L4_header(ring_data->nic, lro);
3038 queue_rx_frame(lro->parent, lro->vlan_tag); 3032 queue_rx_frame(lro->parent, lro->vlan_tag);
3039 clear_lro_session(lro); 3033 clear_lro_session(lro);
3040 } 3034 }
@@ -4333,10 +4327,10 @@ s2io_alarm_handle(unsigned long data)
4333 mod_timer(&sp->alarm_timer, jiffies + HZ / 2); 4327 mod_timer(&sp->alarm_timer, jiffies + HZ / 2);
4334} 4328}
4335 4329
4336static int s2io_chk_rx_buffers(struct s2io_nic *sp, int rng_n) 4330static int s2io_chk_rx_buffers(struct ring_info *ring)
4337{ 4331{
4338 if (fill_rx_buffers(sp, rng_n) == -ENOMEM) { 4332 if (fill_rx_buffers(ring) == -ENOMEM) {
4339 DBG_PRINT(INFO_DBG, "%s:Out of memory", sp->dev->name); 4333 DBG_PRINT(INFO_DBG, "%s:Out of memory", ring->dev->name);
4340 DBG_PRINT(INFO_DBG, " in Rx Intr!!\n"); 4334 DBG_PRINT(INFO_DBG, " in Rx Intr!!\n");
4341 } 4335 }
4342 return 0; 4336 return 0;
@@ -4351,7 +4345,7 @@ static irqreturn_t s2io_msix_ring_handle(int irq, void *dev_id)
4351 return IRQ_HANDLED; 4345 return IRQ_HANDLED;
4352 4346
4353 rx_intr_handler(ring); 4347 rx_intr_handler(ring);
4354 s2io_chk_rx_buffers(sp, ring->ring_no); 4348 s2io_chk_rx_buffers(ring);
4355 4349
4356 return IRQ_HANDLED; 4350 return IRQ_HANDLED;
4357} 4351}
@@ -4809,7 +4803,7 @@ static irqreturn_t s2io_isr(int irq, void *dev_id)
4809 */ 4803 */
4810 if (!config->napi) { 4804 if (!config->napi) {
4811 for (i = 0; i < config->rx_ring_num; i++) 4805 for (i = 0; i < config->rx_ring_num; i++)
4812 s2io_chk_rx_buffers(sp, i); 4806 s2io_chk_rx_buffers(&mac_control->rings[i]);
4813 } 4807 }
4814 writeq(sp->general_int_mask, &bar0->general_int_mask); 4808 writeq(sp->general_int_mask, &bar0->general_int_mask);
4815 readl(&bar0->general_int_status); 4809 readl(&bar0->general_int_status);
@@ -4866,6 +4860,7 @@ static struct net_device_stats *s2io_get_stats(struct net_device *dev)
4866 struct s2io_nic *sp = dev->priv; 4860 struct s2io_nic *sp = dev->priv;
4867 struct mac_info *mac_control; 4861 struct mac_info *mac_control;
4868 struct config_param *config; 4862 struct config_param *config;
4863 int i;
4869 4864
4870 4865
4871 mac_control = &sp->mac_control; 4866 mac_control = &sp->mac_control;
@@ -4885,6 +4880,13 @@ static struct net_device_stats *s2io_get_stats(struct net_device *dev)
4885 sp->stats.rx_length_errors = 4880 sp->stats.rx_length_errors =
4886 le64_to_cpu(mac_control->stats_info->rmac_long_frms); 4881 le64_to_cpu(mac_control->stats_info->rmac_long_frms);
4887 4882
4883 /* collect per-ring rx_packets and rx_bytes */
4884 sp->stats.rx_packets = sp->stats.rx_bytes = 0;
4885 for (i = 0; i < config->rx_ring_num; i++) {
4886 sp->stats.rx_packets += mac_control->rings[i].rx_packets;
4887 sp->stats.rx_bytes += mac_control->rings[i].rx_bytes;
4888 }
4889
4888 return (&sp->stats); 4890 return (&sp->stats);
4889} 4891}
4890 4892
@@ -7157,7 +7159,9 @@ static int s2io_card_up(struct s2io_nic * sp)
7157 config = &sp->config; 7159 config = &sp->config;
7158 7160
7159 for (i = 0; i < config->rx_ring_num; i++) { 7161 for (i = 0; i < config->rx_ring_num; i++) {
7160 if ((ret = fill_rx_buffers(sp, i))) { 7162 mac_control->rings[i].mtu = dev->mtu;
7163 ret = fill_rx_buffers(&mac_control->rings[i]);
7164 if (ret) {
7161 DBG_PRINT(ERR_DBG, "%s: Out of memory in Open\n", 7165 DBG_PRINT(ERR_DBG, "%s: Out of memory in Open\n",
7162 dev->name); 7166 dev->name);
7163 s2io_reset(sp); 7167 s2io_reset(sp);
@@ -7165,7 +7169,7 @@ static int s2io_card_up(struct s2io_nic * sp)
7165 return -ENOMEM; 7169 return -ENOMEM;
7166 } 7170 }
7167 DBG_PRINT(INFO_DBG, "Buf in ring:%d is %d:\n", i, 7171 DBG_PRINT(INFO_DBG, "Buf in ring:%d is %d:\n", i,
7168 atomic_read(&sp->rx_bufs_left[i])); 7172 mac_control->rings[i].rx_bufs_left);
7169 } 7173 }
7170 7174
7171 /* Initialise napi */ 7175 /* Initialise napi */
@@ -7300,7 +7304,7 @@ static void s2io_tx_watchdog(struct net_device *dev)
7300static int rx_osm_handler(struct ring_info *ring_data, struct RxD_t * rxdp) 7304static int rx_osm_handler(struct ring_info *ring_data, struct RxD_t * rxdp)
7301{ 7305{
7302 struct s2io_nic *sp = ring_data->nic; 7306 struct s2io_nic *sp = ring_data->nic;
7303 struct net_device *dev = (struct net_device *) sp->dev; 7307 struct net_device *dev = (struct net_device *) ring_data->dev;
7304 struct sk_buff *skb = (struct sk_buff *) 7308 struct sk_buff *skb = (struct sk_buff *)
7305 ((unsigned long) rxdp->Host_Control); 7309 ((unsigned long) rxdp->Host_Control);
7306 int ring_no = ring_data->ring_no; 7310 int ring_no = ring_data->ring_no;
@@ -7377,19 +7381,19 @@ static int rx_osm_handler(struct ring_info *ring_data, struct RxD_t * rxdp)
7377 sp->mac_control.stats_info->sw_stat.mem_freed 7381 sp->mac_control.stats_info->sw_stat.mem_freed
7378 += skb->truesize; 7382 += skb->truesize;
7379 dev_kfree_skb(skb); 7383 dev_kfree_skb(skb);
7380 atomic_dec(&sp->rx_bufs_left[ring_no]); 7384 ring_data->rx_bufs_left -= 1;
7381 rxdp->Host_Control = 0; 7385 rxdp->Host_Control = 0;
7382 return 0; 7386 return 0;
7383 } 7387 }
7384 } 7388 }
7385 7389
7386 /* Updating statistics */ 7390 /* Updating statistics */
7387 sp->stats.rx_packets++; 7391 ring_data->rx_packets++;
7388 rxdp->Host_Control = 0; 7392 rxdp->Host_Control = 0;
7389 if (sp->rxd_mode == RXD_MODE_1) { 7393 if (sp->rxd_mode == RXD_MODE_1) {
7390 int len = RXD_GET_BUFFER0_SIZE_1(rxdp->Control_2); 7394 int len = RXD_GET_BUFFER0_SIZE_1(rxdp->Control_2);
7391 7395
7392 sp->stats.rx_bytes += len; 7396 ring_data->rx_bytes += len;
7393 skb_put(skb, len); 7397 skb_put(skb, len);
7394 7398
7395 } else if (sp->rxd_mode == RXD_MODE_3B) { 7399 } else if (sp->rxd_mode == RXD_MODE_3B) {
@@ -7400,13 +7404,13 @@ static int rx_osm_handler(struct ring_info *ring_data, struct RxD_t * rxdp)
7400 unsigned char *buff = skb_push(skb, buf0_len); 7404 unsigned char *buff = skb_push(skb, buf0_len);
7401 7405
7402 struct buffAdd *ba = &ring_data->ba[get_block][get_off]; 7406 struct buffAdd *ba = &ring_data->ba[get_block][get_off];
7403 sp->stats.rx_bytes += buf0_len + buf2_len; 7407 ring_data->rx_bytes += buf0_len + buf2_len;
7404 memcpy(buff, ba->ba_0, buf0_len); 7408 memcpy(buff, ba->ba_0, buf0_len);
7405 skb_put(skb, buf2_len); 7409 skb_put(skb, buf2_len);
7406 } 7410 }
7407 7411
7408 if ((rxdp->Control_1 & TCP_OR_UDP_FRAME) && ((!sp->lro) || 7412 if ((rxdp->Control_1 & TCP_OR_UDP_FRAME) && ((!ring_data->lro) ||
7409 (sp->lro && (!(rxdp->Control_1 & RXD_FRAME_IP_FRAG)))) && 7413 (ring_data->lro && (!(rxdp->Control_1 & RXD_FRAME_IP_FRAG)))) &&
7410 (sp->rx_csum)) { 7414 (sp->rx_csum)) {
7411 l3_csum = RXD_GET_L3_CKSUM(rxdp->Control_1); 7415 l3_csum = RXD_GET_L3_CKSUM(rxdp->Control_1);
7412 l4_csum = RXD_GET_L4_CKSUM(rxdp->Control_1); 7416 l4_csum = RXD_GET_L4_CKSUM(rxdp->Control_1);
@@ -7417,14 +7421,14 @@ static int rx_osm_handler(struct ring_info *ring_data, struct RxD_t * rxdp)
7417 * a flag in the RxD. 7421 * a flag in the RxD.
7418 */ 7422 */
7419 skb->ip_summed = CHECKSUM_UNNECESSARY; 7423 skb->ip_summed = CHECKSUM_UNNECESSARY;
7420 if (sp->lro) { 7424 if (ring_data->lro) {
7421 u32 tcp_len; 7425 u32 tcp_len;
7422 u8 *tcp; 7426 u8 *tcp;
7423 int ret = 0; 7427 int ret = 0;
7424 7428
7425 ret = s2io_club_tcp_session(skb->data, &tcp, 7429 ret = s2io_club_tcp_session(ring_data,
7426 &tcp_len, &lro, 7430 skb->data, &tcp, &tcp_len, &lro,
7427 rxdp, sp); 7431 rxdp, sp);
7428 switch (ret) { 7432 switch (ret) {
7429 case 3: /* Begin anew */ 7433 case 3: /* Begin anew */
7430 lro->parent = skb; 7434 lro->parent = skb;
@@ -7486,7 +7490,7 @@ send_up:
7486 queue_rx_frame(skb, RXD_GET_VLAN_TAG(rxdp->Control_2)); 7490 queue_rx_frame(skb, RXD_GET_VLAN_TAG(rxdp->Control_2));
7487 dev->last_rx = jiffies; 7491 dev->last_rx = jiffies;
7488aggregate: 7492aggregate:
7489 atomic_dec(&sp->rx_bufs_left[ring_no]); 7493 sp->mac_control.rings[ring_no].rx_bufs_left -= 1;
7490 return SUCCESS; 7494 return SUCCESS;
7491} 7495}
7492 7496
@@ -7603,12 +7607,14 @@ static int s2io_verify_parm(struct pci_dev *pdev, u8 *dev_intr_type,
7603 tx_steering_type = NO_STEERING; 7607 tx_steering_type = NO_STEERING;
7604 } 7608 }
7605 7609
7606 if ( rx_ring_num > 8) { 7610 if (rx_ring_num > MAX_RX_RINGS) {
7607 DBG_PRINT(ERR_DBG, "s2io: Requested number of Rx rings not " 7611 DBG_PRINT(ERR_DBG, "s2io: Requested number of rx rings not "
7608 "supported\n"); 7612 "supported\n");
7609 DBG_PRINT(ERR_DBG, "s2io: Default to 8 Rx rings\n"); 7613 DBG_PRINT(ERR_DBG, "s2io: Default to %d rx rings\n",
7610 rx_ring_num = 8; 7614 MAX_RX_RINGS);
7615 rx_ring_num = MAX_RX_RINGS;
7611 } 7616 }
7617
7612 if (*dev_intr_type != INTA) 7618 if (*dev_intr_type != INTA)
7613 napi = 0; 7619 napi = 0;
7614 7620
@@ -7836,10 +7842,15 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
7836 7842
7837 /* Rx side parameters. */ 7843 /* Rx side parameters. */
7838 config->rx_ring_num = rx_ring_num; 7844 config->rx_ring_num = rx_ring_num;
7839 for (i = 0; i < MAX_RX_RINGS; i++) { 7845 for (i = 0; i < config->rx_ring_num; i++) {
7840 config->rx_cfg[i].num_rxd = rx_ring_sz[i] * 7846 config->rx_cfg[i].num_rxd = rx_ring_sz[i] *
7841 (rxd_count[sp->rxd_mode] + 1); 7847 (rxd_count[sp->rxd_mode] + 1);
7842 config->rx_cfg[i].ring_priority = i; 7848 config->rx_cfg[i].ring_priority = i;
7849 mac_control->rings[i].rx_bufs_left = 0;
7850 mac_control->rings[i].rxd_mode = sp->rxd_mode;
7851 mac_control->rings[i].rxd_count = rxd_count[sp->rxd_mode];
7852 mac_control->rings[i].pdev = sp->pdev;
7853 mac_control->rings[i].dev = sp->dev;
7843 } 7854 }
7844 7855
7845 for (i = 0; i < rx_ring_num; i++) { 7856 for (i = 0; i < rx_ring_num; i++) {
@@ -7854,10 +7865,6 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
7854 mac_control->mc_pause_threshold_q4q7 = mc_pause_threshold_q4q7; 7865 mac_control->mc_pause_threshold_q4q7 = mc_pause_threshold_q4q7;
7855 7866
7856 7867
7857 /* Initialize Ring buffer parameters. */
7858 for (i = 0; i < config->rx_ring_num; i++)
7859 atomic_set(&sp->rx_bufs_left[i], 0);
7860
7861 /* initialize the shared memory used by the NIC and the host */ 7868 /* initialize the shared memory used by the NIC and the host */
7862 if (init_shared_mem(sp)) { 7869 if (init_shared_mem(sp)) {
7863 DBG_PRINT(ERR_DBG, "%s: Memory allocation failed\n", 7870 DBG_PRINT(ERR_DBG, "%s: Memory allocation failed\n",
@@ -8077,6 +8084,9 @@ s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
8077 DBG_PRINT(ERR_DBG, "%s: Using %d Tx fifo(s)\n", dev->name, 8084 DBG_PRINT(ERR_DBG, "%s: Using %d Tx fifo(s)\n", dev->name,
8078 sp->config.tx_fifo_num); 8085 sp->config.tx_fifo_num);
8079 8086
8087 DBG_PRINT(ERR_DBG, "%s: Using %d Rx ring(s)\n", dev->name,
8088 sp->config.rx_ring_num);
8089
8080 switch(sp->config.intr_type) { 8090 switch(sp->config.intr_type) {
8081 case INTA: 8091 case INTA:
8082 DBG_PRINT(ERR_DBG, "%s: Interrupt type INTA\n", dev->name); 8092 DBG_PRINT(ERR_DBG, "%s: Interrupt type INTA\n", dev->name);
@@ -8391,8 +8401,9 @@ static int verify_l3_l4_lro_capable(struct lro *l_lro, struct iphdr *ip,
8391} 8401}
8392 8402
8393static int 8403static int
8394s2io_club_tcp_session(u8 *buffer, u8 **tcp, u32 *tcp_len, struct lro **lro, 8404s2io_club_tcp_session(struct ring_info *ring_data, u8 *buffer, u8 **tcp,
8395 struct RxD_t *rxdp, struct s2io_nic *sp) 8405 u32 *tcp_len, struct lro **lro, struct RxD_t *rxdp,
8406 struct s2io_nic *sp)
8396{ 8407{
8397 struct iphdr *ip; 8408 struct iphdr *ip;
8398 struct tcphdr *tcph; 8409 struct tcphdr *tcph;
@@ -8410,7 +8421,7 @@ s2io_club_tcp_session(u8 *buffer, u8 **tcp, u32 *tcp_len, struct lro **lro,
8410 tcph = (struct tcphdr *)*tcp; 8421 tcph = (struct tcphdr *)*tcp;
8411 *tcp_len = get_l4_pyld_length(ip, tcph); 8422 *tcp_len = get_l4_pyld_length(ip, tcph);
8412 for (i=0; i<MAX_LRO_SESSIONS; i++) { 8423 for (i=0; i<MAX_LRO_SESSIONS; i++) {
8413 struct lro *l_lro = &sp->lro0_n[i]; 8424 struct lro *l_lro = &ring_data->lro0_n[i];
8414 if (l_lro->in_use) { 8425 if (l_lro->in_use) {
8415 if (check_for_socket_match(l_lro, ip, tcph)) 8426 if (check_for_socket_match(l_lro, ip, tcph))
8416 continue; 8427 continue;
@@ -8448,7 +8459,7 @@ s2io_club_tcp_session(u8 *buffer, u8 **tcp, u32 *tcp_len, struct lro **lro,
8448 } 8459 }
8449 8460
8450 for (i=0; i<MAX_LRO_SESSIONS; i++) { 8461 for (i=0; i<MAX_LRO_SESSIONS; i++) {
8451 struct lro *l_lro = &sp->lro0_n[i]; 8462 struct lro *l_lro = &ring_data->lro0_n[i];
8452 if (!(l_lro->in_use)) { 8463 if (!(l_lro->in_use)) {
8453 *lro = l_lro; 8464 *lro = l_lro;
8454 ret = 3; /* Begin anew */ 8465 ret = 3; /* Begin anew */
diff --git a/drivers/net/s2io.h b/drivers/net/s2io.h
index ce53a02105f2..0709ebae9139 100644
--- a/drivers/net/s2io.h
+++ b/drivers/net/s2io.h
@@ -678,11 +678,53 @@ struct rx_block_info {
678 struct rxd_info *rxds; 678 struct rxd_info *rxds;
679}; 679};
680 680
681/* Data structure to represent a LRO session */
682struct lro {
683 struct sk_buff *parent;
684 struct sk_buff *last_frag;
685 u8 *l2h;
686 struct iphdr *iph;
687 struct tcphdr *tcph;
688 u32 tcp_next_seq;
689 __be32 tcp_ack;
690 int total_len;
691 int frags_len;
692 int sg_num;
693 int in_use;
694 __be16 window;
695 u16 vlan_tag;
696 u32 cur_tsval;
697 __be32 cur_tsecr;
698 u8 saw_ts;
699} ____cacheline_aligned;
700
681/* Ring specific structure */ 701/* Ring specific structure */
682struct ring_info { 702struct ring_info {
683 /* The ring number */ 703 /* The ring number */
684 int ring_no; 704 int ring_no;
685 705
706 /* per-ring buffer counter */
707 u32 rx_bufs_left;
708
709 #define MAX_LRO_SESSIONS 32
710 struct lro lro0_n[MAX_LRO_SESSIONS];
711 u8 lro;
712
713 /* copy of sp->rxd_mode flag */
714 int rxd_mode;
715
716 /* Number of rxds per block for the rxd_mode */
717 int rxd_count;
718
719 /* copy of sp pointer */
720 struct s2io_nic *nic;
721
722 /* copy of sp->dev pointer */
723 struct net_device *dev;
724
725 /* copy of sp->pdev pointer */
726 struct pci_dev *pdev;
727
686 /* 728 /*
687 * Place holders for the virtual and physical addresses of 729 * Place holders for the virtual and physical addresses of
688 * all the Rx Blocks 730 * all the Rx Blocks
@@ -703,10 +745,16 @@ struct ring_info {
703 */ 745 */
704 struct rx_curr_get_info rx_curr_get_info; 746 struct rx_curr_get_info rx_curr_get_info;
705 747
748 /* interface MTU value */
749 unsigned mtu;
750
706 /* Buffer Address store. */ 751 /* Buffer Address store. */
707 struct buffAdd **ba; 752 struct buffAdd **ba;
708 struct s2io_nic *nic; 753
709}; 754 /* per-Ring statistics */
755 unsigned long rx_packets;
756 unsigned long rx_bytes;
757} ____cacheline_aligned;
710 758
711/* Fifo specific structure */ 759/* Fifo specific structure */
712struct fifo_info { 760struct fifo_info {
@@ -813,26 +861,6 @@ struct msix_info_st {
813 u64 data; 861 u64 data;
814}; 862};
815 863
816/* Data structure to represent a LRO session */
817struct lro {
818 struct sk_buff *parent;
819 struct sk_buff *last_frag;
820 u8 *l2h;
821 struct iphdr *iph;
822 struct tcphdr *tcph;
823 u32 tcp_next_seq;
824 __be32 tcp_ack;
825 int total_len;
826 int frags_len;
827 int sg_num;
828 int in_use;
829 __be16 window;
830 u16 vlan_tag;
831 u32 cur_tsval;
832 __be32 cur_tsecr;
833 u8 saw_ts;
834} ____cacheline_aligned;
835
836/* These flags represent the devices temporary state */ 864/* These flags represent the devices temporary state */
837enum s2io_device_state_t 865enum s2io_device_state_t
838{ 866{
@@ -872,8 +900,6 @@ struct s2io_nic {
872 /* Space to back up the PCI config space */ 900 /* Space to back up the PCI config space */
873 u32 config_space[256 / sizeof(u32)]; 901 u32 config_space[256 / sizeof(u32)];
874 902
875 atomic_t rx_bufs_left[MAX_RX_RINGS];
876
877#define PROMISC 1 903#define PROMISC 1
878#define ALL_MULTI 2 904#define ALL_MULTI 2
879 905
@@ -950,8 +976,6 @@ struct s2io_nic {
950#define XFRAME_II_DEVICE 2 976#define XFRAME_II_DEVICE 2
951 u8 device_type; 977 u8 device_type;
952 978
953#define MAX_LRO_SESSIONS 32
954 struct lro lro0_n[MAX_LRO_SESSIONS];
955 unsigned long clubbed_frms_cnt; 979 unsigned long clubbed_frms_cnt;
956 unsigned long sending_both; 980 unsigned long sending_both;
957 u8 lro; 981 u8 lro;
@@ -1118,9 +1142,9 @@ static int do_s2io_add_mc(struct s2io_nic *sp, u8 *addr);
1118static int do_s2io_add_mac(struct s2io_nic *sp, u64 addr, int offset); 1142static int do_s2io_add_mac(struct s2io_nic *sp, u64 addr, int offset);
1119static int do_s2io_delete_unicast_mc(struct s2io_nic *sp, u64 addr); 1143static int do_s2io_delete_unicast_mc(struct s2io_nic *sp, u64 addr);
1120 1144
1121static int 1145static int s2io_club_tcp_session(struct ring_info *ring_data, u8 *buffer,
1122s2io_club_tcp_session(u8 *buffer, u8 **tcp, u32 *tcp_len, struct lro **lro, 1146 u8 **tcp, u32 *tcp_len, struct lro **lro, struct RxD_t *rxdp,
1123 struct RxD_t *rxdp, struct s2io_nic *sp); 1147 struct s2io_nic *sp);
1124static void clear_lro_session(struct lro *lro); 1148static void clear_lro_session(struct lro *lro);
1125static void queue_rx_frame(struct sk_buff *skb, u16 vlan_tag); 1149static void queue_rx_frame(struct sk_buff *skb, u16 vlan_tag);
1126static void update_L3L4_header(struct s2io_nic *sp, struct lro *lro); 1150static void update_L3L4_header(struct s2io_nic *sp, struct lro *lro);
diff --git a/drivers/net/sfc/Kconfig b/drivers/net/sfc/Kconfig
new file mode 100644
index 000000000000..dbad95c295bd
--- /dev/null
+++ b/drivers/net/sfc/Kconfig
@@ -0,0 +1,12 @@
1config SFC
2 tristate "Solarflare Solarstorm SFC4000 support"
3 depends on PCI && INET
4 select MII
5 select INET_LRO
6 select CRC32
7 help
8 This driver supports 10-gigabit Ethernet cards based on
9 the Solarflare Communications Solarstorm SFC4000 controller.
10
11 To compile this driver as a module, choose M here. The module
12 will be called sfc.
diff --git a/drivers/net/sfc/Makefile b/drivers/net/sfc/Makefile
new file mode 100644
index 000000000000..0f023447eafd
--- /dev/null
+++ b/drivers/net/sfc/Makefile
@@ -0,0 +1,5 @@
1sfc-y += efx.o falcon.o tx.o rx.o falcon_xmac.o \
2 i2c-direct.o ethtool.o xfp_phy.o mdio_10g.o \
3 tenxpress.o boards.o sfe4001.o
4
5obj-$(CONFIG_SFC) += sfc.o
diff --git a/drivers/net/sfc/bitfield.h b/drivers/net/sfc/bitfield.h
new file mode 100644
index 000000000000..2806201644cc
--- /dev/null
+++ b/drivers/net/sfc/bitfield.h
@@ -0,0 +1,508 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2006-2008 Solarflare Communications Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
11#ifndef EFX_BITFIELD_H
12#define EFX_BITFIELD_H
13
14/*
15 * Efx bitfield access
16 *
17 * Efx NICs make extensive use of bitfields up to 128 bits
18 * wide. Since there is no native 128-bit datatype on most systems,
19 * and since 64-bit datatypes are inefficient on 32-bit systems and
20 * vice versa, we wrap accesses in a way that uses the most efficient
21 * datatype.
22 *
23 * The NICs are PCI devices and therefore little-endian. Since most
24 * of the quantities that we deal with are DMAed to/from host memory,
25 * we define our datatypes (efx_oword_t, efx_qword_t and
26 * efx_dword_t) to be little-endian.
27 */
28
29/* Lowest bit numbers and widths */
30#define EFX_DUMMY_FIELD_LBN 0
31#define EFX_DUMMY_FIELD_WIDTH 0
32#define EFX_DWORD_0_LBN 0
33#define EFX_DWORD_0_WIDTH 32
34#define EFX_DWORD_1_LBN 32
35#define EFX_DWORD_1_WIDTH 32
36#define EFX_DWORD_2_LBN 64
37#define EFX_DWORD_2_WIDTH 32
38#define EFX_DWORD_3_LBN 96
39#define EFX_DWORD_3_WIDTH 32
40
41/* Specified attribute (e.g. LBN) of the specified field */
42#define EFX_VAL(field, attribute) field ## _ ## attribute
43/* Low bit number of the specified field */
44#define EFX_LOW_BIT(field) EFX_VAL(field, LBN)
45/* Bit width of the specified field */
46#define EFX_WIDTH(field) EFX_VAL(field, WIDTH)
47/* High bit number of the specified field */
48#define EFX_HIGH_BIT(field) (EFX_LOW_BIT(field) + EFX_WIDTH(field) - 1)
49/* Mask equal in width to the specified field.
50 *
51 * For example, a field with width 5 would have a mask of 0x1f.
52 *
53 * The maximum width mask that can be generated is 64 bits.
54 */
55#define EFX_MASK64(field) \
56 (EFX_WIDTH(field) == 64 ? ~((u64) 0) : \
57 (((((u64) 1) << EFX_WIDTH(field))) - 1))
58
59/* Mask equal in width to the specified field.
60 *
61 * For example, a field with width 5 would have a mask of 0x1f.
62 *
63 * The maximum width mask that can be generated is 32 bits. Use
64 * EFX_MASK64 for higher width fields.
65 */
66#define EFX_MASK32(field) \
67 (EFX_WIDTH(field) == 32 ? ~((u32) 0) : \
68 (((((u32) 1) << EFX_WIDTH(field))) - 1))
69
70/* A doubleword (i.e. 4 byte) datatype - little-endian in HW */
71typedef union efx_dword {
72 __le32 u32[1];
73} efx_dword_t;
74
75/* A quadword (i.e. 8 byte) datatype - little-endian in HW */
76typedef union efx_qword {
77 __le64 u64[1];
78 __le32 u32[2];
79 efx_dword_t dword[2];
80} efx_qword_t;
81
82/* An octword (eight-word, i.e. 16 byte) datatype - little-endian in HW */
83typedef union efx_oword {
84 __le64 u64[2];
85 efx_qword_t qword[2];
86 __le32 u32[4];
87 efx_dword_t dword[4];
88} efx_oword_t;
89
90/* Format string and value expanders for printk */
91#define EFX_DWORD_FMT "%08x"
92#define EFX_QWORD_FMT "%08x:%08x"
93#define EFX_OWORD_FMT "%08x:%08x:%08x:%08x"
94#define EFX_DWORD_VAL(dword) \
95 ((unsigned int) le32_to_cpu((dword).u32[0]))
96#define EFX_QWORD_VAL(qword) \
97 ((unsigned int) le32_to_cpu((qword).u32[1])), \
98 ((unsigned int) le32_to_cpu((qword).u32[0]))
99#define EFX_OWORD_VAL(oword) \
100 ((unsigned int) le32_to_cpu((oword).u32[3])), \
101 ((unsigned int) le32_to_cpu((oword).u32[2])), \
102 ((unsigned int) le32_to_cpu((oword).u32[1])), \
103 ((unsigned int) le32_to_cpu((oword).u32[0]))
104
105/*
106 * Extract bit field portion [low,high) from the native-endian element
107 * which contains bits [min,max).
108 *
109 * For example, suppose "element" represents the high 32 bits of a
110 * 64-bit value, and we wish to extract the bits belonging to the bit
111 * field occupying bits 28-45 of this 64-bit value.
112 *
113 * Then EFX_EXTRACT ( element, 32, 63, 28, 45 ) would give
114 *
115 * ( element ) << 4
116 *
117 * The result will contain the relevant bits filled in in the range
118 * [0,high-low), with garbage in bits [high-low+1,...).
119 */
120#define EFX_EXTRACT_NATIVE(native_element, min, max, low, high) \
121 (((low > max) || (high < min)) ? 0 : \
122 ((low > min) ? \
123 ((native_element) >> (low - min)) : \
124 ((native_element) << (min - low))))
125
126/*
127 * Extract bit field portion [low,high) from the 64-bit little-endian
128 * element which contains bits [min,max)
129 */
130#define EFX_EXTRACT64(element, min, max, low, high) \
131 EFX_EXTRACT_NATIVE(le64_to_cpu(element), min, max, low, high)
132
133/*
134 * Extract bit field portion [low,high) from the 32-bit little-endian
135 * element which contains bits [min,max)
136 */
137#define EFX_EXTRACT32(element, min, max, low, high) \
138 EFX_EXTRACT_NATIVE(le32_to_cpu(element), min, max, low, high)
139
140#define EFX_EXTRACT_OWORD64(oword, low, high) \
141 (EFX_EXTRACT64((oword).u64[0], 0, 63, low, high) | \
142 EFX_EXTRACT64((oword).u64[1], 64, 127, low, high))
143
144#define EFX_EXTRACT_QWORD64(qword, low, high) \
145 EFX_EXTRACT64((qword).u64[0], 0, 63, low, high)
146
147#define EFX_EXTRACT_OWORD32(oword, low, high) \
148 (EFX_EXTRACT32((oword).u32[0], 0, 31, low, high) | \
149 EFX_EXTRACT32((oword).u32[1], 32, 63, low, high) | \
150 EFX_EXTRACT32((oword).u32[2], 64, 95, low, high) | \
151 EFX_EXTRACT32((oword).u32[3], 96, 127, low, high))
152
153#define EFX_EXTRACT_QWORD32(qword, low, high) \
154 (EFX_EXTRACT32((qword).u32[0], 0, 31, low, high) | \
155 EFX_EXTRACT32((qword).u32[1], 32, 63, low, high))
156
157#define EFX_EXTRACT_DWORD(dword, low, high) \
158 EFX_EXTRACT32((dword).u32[0], 0, 31, low, high)
159
160#define EFX_OWORD_FIELD64(oword, field) \
161 (EFX_EXTRACT_OWORD64(oword, EFX_LOW_BIT(field), EFX_HIGH_BIT(field)) \
162 & EFX_MASK64(field))
163
164#define EFX_QWORD_FIELD64(qword, field) \
165 (EFX_EXTRACT_QWORD64(qword, EFX_LOW_BIT(field), EFX_HIGH_BIT(field)) \
166 & EFX_MASK64(field))
167
168#define EFX_OWORD_FIELD32(oword, field) \
169 (EFX_EXTRACT_OWORD32(oword, EFX_LOW_BIT(field), EFX_HIGH_BIT(field)) \
170 & EFX_MASK32(field))
171
172#define EFX_QWORD_FIELD32(qword, field) \
173 (EFX_EXTRACT_QWORD32(qword, EFX_LOW_BIT(field), EFX_HIGH_BIT(field)) \
174 & EFX_MASK32(field))
175
176#define EFX_DWORD_FIELD(dword, field) \
177 (EFX_EXTRACT_DWORD(dword, EFX_LOW_BIT(field), EFX_HIGH_BIT(field)) \
178 & EFX_MASK32(field))
179
180#define EFX_OWORD_IS_ZERO64(oword) \
181 (((oword).u64[0] | (oword).u64[1]) == (__force __le64) 0)
182
183#define EFX_QWORD_IS_ZERO64(qword) \
184 (((qword).u64[0]) == (__force __le64) 0)
185
186#define EFX_OWORD_IS_ZERO32(oword) \
187 (((oword).u32[0] | (oword).u32[1] | (oword).u32[2] | (oword).u32[3]) \
188 == (__force __le32) 0)
189
190#define EFX_QWORD_IS_ZERO32(qword) \
191 (((qword).u32[0] | (qword).u32[1]) == (__force __le32) 0)
192
193#define EFX_DWORD_IS_ZERO(dword) \
194 (((dword).u32[0]) == (__force __le32) 0)
195
196#define EFX_OWORD_IS_ALL_ONES64(oword) \
197 (((oword).u64[0] & (oword).u64[1]) == ~((__force __le64) 0))
198
199#define EFX_QWORD_IS_ALL_ONES64(qword) \
200 ((qword).u64[0] == ~((__force __le64) 0))
201
202#define EFX_OWORD_IS_ALL_ONES32(oword) \
203 (((oword).u32[0] & (oword).u32[1] & (oword).u32[2] & (oword).u32[3]) \
204 == ~((__force __le32) 0))
205
206#define EFX_QWORD_IS_ALL_ONES32(qword) \
207 (((qword).u32[0] & (qword).u32[1]) == ~((__force __le32) 0))
208
209#define EFX_DWORD_IS_ALL_ONES(dword) \
210 ((dword).u32[0] == ~((__force __le32) 0))
211
212#if BITS_PER_LONG == 64
213#define EFX_OWORD_FIELD EFX_OWORD_FIELD64
214#define EFX_QWORD_FIELD EFX_QWORD_FIELD64
215#define EFX_OWORD_IS_ZERO EFX_OWORD_IS_ZERO64
216#define EFX_QWORD_IS_ZERO EFX_QWORD_IS_ZERO64
217#define EFX_OWORD_IS_ALL_ONES EFX_OWORD_IS_ALL_ONES64
218#define EFX_QWORD_IS_ALL_ONES EFX_QWORD_IS_ALL_ONES64
219#else
220#define EFX_OWORD_FIELD EFX_OWORD_FIELD32
221#define EFX_QWORD_FIELD EFX_QWORD_FIELD32
222#define EFX_OWORD_IS_ZERO EFX_OWORD_IS_ZERO32
223#define EFX_QWORD_IS_ZERO EFX_QWORD_IS_ZERO32
224#define EFX_OWORD_IS_ALL_ONES EFX_OWORD_IS_ALL_ONES32
225#define EFX_QWORD_IS_ALL_ONES EFX_QWORD_IS_ALL_ONES32
226#endif
227
228/*
229 * Construct bit field portion
230 *
231 * Creates the portion of the bit field [low,high) that lies within
232 * the range [min,max).
233 */
234#define EFX_INSERT_NATIVE64(min, max, low, high, value) \
235 (((low > max) || (high < min)) ? 0 : \
236 ((low > min) ? \
237 (((u64) (value)) << (low - min)) : \
238 (((u64) (value)) >> (min - low))))
239
240#define EFX_INSERT_NATIVE32(min, max, low, high, value) \
241 (((low > max) || (high < min)) ? 0 : \
242 ((low > min) ? \
243 (((u32) (value)) << (low - min)) : \
244 (((u32) (value)) >> (min - low))))
245
246#define EFX_INSERT_NATIVE(min, max, low, high, value) \
247 ((((max - min) >= 32) || ((high - low) >= 32)) ? \
248 EFX_INSERT_NATIVE64(min, max, low, high, value) : \
249 EFX_INSERT_NATIVE32(min, max, low, high, value))
250
251/*
252 * Construct bit field portion
253 *
254 * Creates the portion of the named bit field that lies within the
255 * range [min,max).
256 */
257#define EFX_INSERT_FIELD_NATIVE(min, max, field, value) \
258 EFX_INSERT_NATIVE(min, max, EFX_LOW_BIT(field), \
259 EFX_HIGH_BIT(field), value)
260
261/*
262 * Construct bit field
263 *
264 * Creates the portion of the named bit fields that lie within the
265 * range [min,max).
266 */
267#define EFX_INSERT_FIELDS_NATIVE(min, max, \
268 field1, value1, \
269 field2, value2, \
270 field3, value3, \
271 field4, value4, \
272 field5, value5, \
273 field6, value6, \
274 field7, value7, \
275 field8, value8, \
276 field9, value9, \
277 field10, value10) \
278 (EFX_INSERT_FIELD_NATIVE((min), (max), field1, (value1)) | \
279 EFX_INSERT_FIELD_NATIVE((min), (max), field2, (value2)) | \
280 EFX_INSERT_FIELD_NATIVE((min), (max), field3, (value3)) | \
281 EFX_INSERT_FIELD_NATIVE((min), (max), field4, (value4)) | \
282 EFX_INSERT_FIELD_NATIVE((min), (max), field5, (value5)) | \
283 EFX_INSERT_FIELD_NATIVE((min), (max), field6, (value6)) | \
284 EFX_INSERT_FIELD_NATIVE((min), (max), field7, (value7)) | \
285 EFX_INSERT_FIELD_NATIVE((min), (max), field8, (value8)) | \
286 EFX_INSERT_FIELD_NATIVE((min), (max), field9, (value9)) | \
287 EFX_INSERT_FIELD_NATIVE((min), (max), field10, (value10)))
288
289#define EFX_INSERT_FIELDS64(...) \
290 cpu_to_le64(EFX_INSERT_FIELDS_NATIVE(__VA_ARGS__))
291
292#define EFX_INSERT_FIELDS32(...) \
293 cpu_to_le32(EFX_INSERT_FIELDS_NATIVE(__VA_ARGS__))
294
295#define EFX_POPULATE_OWORD64(oword, ...) do { \
296 (oword).u64[0] = EFX_INSERT_FIELDS64(0, 63, __VA_ARGS__); \
297 (oword).u64[1] = EFX_INSERT_FIELDS64(64, 127, __VA_ARGS__); \
298 } while (0)
299
300#define EFX_POPULATE_QWORD64(qword, ...) do { \
301 (qword).u64[0] = EFX_INSERT_FIELDS64(0, 63, __VA_ARGS__); \
302 } while (0)
303
304#define EFX_POPULATE_OWORD32(oword, ...) do { \
305 (oword).u32[0] = EFX_INSERT_FIELDS32(0, 31, __VA_ARGS__); \
306 (oword).u32[1] = EFX_INSERT_FIELDS32(32, 63, __VA_ARGS__); \
307 (oword).u32[2] = EFX_INSERT_FIELDS32(64, 95, __VA_ARGS__); \
308 (oword).u32[3] = EFX_INSERT_FIELDS32(96, 127, __VA_ARGS__); \
309 } while (0)
310
311#define EFX_POPULATE_QWORD32(qword, ...) do { \
312 (qword).u32[0] = EFX_INSERT_FIELDS32(0, 31, __VA_ARGS__); \
313 (qword).u32[1] = EFX_INSERT_FIELDS32(32, 63, __VA_ARGS__); \
314 } while (0)
315
316#define EFX_POPULATE_DWORD(dword, ...) do { \
317 (dword).u32[0] = EFX_INSERT_FIELDS32(0, 31, __VA_ARGS__); \
318 } while (0)
319
320#if BITS_PER_LONG == 64
321#define EFX_POPULATE_OWORD EFX_POPULATE_OWORD64
322#define EFX_POPULATE_QWORD EFX_POPULATE_QWORD64
323#else
324#define EFX_POPULATE_OWORD EFX_POPULATE_OWORD32
325#define EFX_POPULATE_QWORD EFX_POPULATE_QWORD32
326#endif
327
328/* Populate an octword field with various numbers of arguments */
329#define EFX_POPULATE_OWORD_10 EFX_POPULATE_OWORD
330#define EFX_POPULATE_OWORD_9(oword, ...) \
331 EFX_POPULATE_OWORD_10(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
332#define EFX_POPULATE_OWORD_8(oword, ...) \
333 EFX_POPULATE_OWORD_9(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
334#define EFX_POPULATE_OWORD_7(oword, ...) \
335 EFX_POPULATE_OWORD_8(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
336#define EFX_POPULATE_OWORD_6(oword, ...) \
337 EFX_POPULATE_OWORD_7(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
338#define EFX_POPULATE_OWORD_5(oword, ...) \
339 EFX_POPULATE_OWORD_6(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
340#define EFX_POPULATE_OWORD_4(oword, ...) \
341 EFX_POPULATE_OWORD_5(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
342#define EFX_POPULATE_OWORD_3(oword, ...) \
343 EFX_POPULATE_OWORD_4(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
344#define EFX_POPULATE_OWORD_2(oword, ...) \
345 EFX_POPULATE_OWORD_3(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
346#define EFX_POPULATE_OWORD_1(oword, ...) \
347 EFX_POPULATE_OWORD_2(oword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
348#define EFX_ZERO_OWORD(oword) \
349 EFX_POPULATE_OWORD_1(oword, EFX_DUMMY_FIELD, 0)
350#define EFX_SET_OWORD(oword) \
351 EFX_POPULATE_OWORD_4(oword, \
352 EFX_DWORD_0, 0xffffffff, \
353 EFX_DWORD_1, 0xffffffff, \
354 EFX_DWORD_2, 0xffffffff, \
355 EFX_DWORD_3, 0xffffffff)
356
357/* Populate a quadword field with various numbers of arguments */
358#define EFX_POPULATE_QWORD_10 EFX_POPULATE_QWORD
359#define EFX_POPULATE_QWORD_9(qword, ...) \
360 EFX_POPULATE_QWORD_10(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
361#define EFX_POPULATE_QWORD_8(qword, ...) \
362 EFX_POPULATE_QWORD_9(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
363#define EFX_POPULATE_QWORD_7(qword, ...) \
364 EFX_POPULATE_QWORD_8(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
365#define EFX_POPULATE_QWORD_6(qword, ...) \
366 EFX_POPULATE_QWORD_7(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
367#define EFX_POPULATE_QWORD_5(qword, ...) \
368 EFX_POPULATE_QWORD_6(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
369#define EFX_POPULATE_QWORD_4(qword, ...) \
370 EFX_POPULATE_QWORD_5(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
371#define EFX_POPULATE_QWORD_3(qword, ...) \
372 EFX_POPULATE_QWORD_4(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
373#define EFX_POPULATE_QWORD_2(qword, ...) \
374 EFX_POPULATE_QWORD_3(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
375#define EFX_POPULATE_QWORD_1(qword, ...) \
376 EFX_POPULATE_QWORD_2(qword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
377#define EFX_ZERO_QWORD(qword) \
378 EFX_POPULATE_QWORD_1(qword, EFX_DUMMY_FIELD, 0)
379#define EFX_SET_QWORD(qword) \
380 EFX_POPULATE_QWORD_2(qword, \
381 EFX_DWORD_0, 0xffffffff, \
382 EFX_DWORD_1, 0xffffffff)
383
384/* Populate a dword field with various numbers of arguments */
385#define EFX_POPULATE_DWORD_10 EFX_POPULATE_DWORD
386#define EFX_POPULATE_DWORD_9(dword, ...) \
387 EFX_POPULATE_DWORD_10(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
388#define EFX_POPULATE_DWORD_8(dword, ...) \
389 EFX_POPULATE_DWORD_9(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
390#define EFX_POPULATE_DWORD_7(dword, ...) \
391 EFX_POPULATE_DWORD_8(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
392#define EFX_POPULATE_DWORD_6(dword, ...) \
393 EFX_POPULATE_DWORD_7(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
394#define EFX_POPULATE_DWORD_5(dword, ...) \
395 EFX_POPULATE_DWORD_6(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
396#define EFX_POPULATE_DWORD_4(dword, ...) \
397 EFX_POPULATE_DWORD_5(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
398#define EFX_POPULATE_DWORD_3(dword, ...) \
399 EFX_POPULATE_DWORD_4(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
400#define EFX_POPULATE_DWORD_2(dword, ...) \
401 EFX_POPULATE_DWORD_3(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
402#define EFX_POPULATE_DWORD_1(dword, ...) \
403 EFX_POPULATE_DWORD_2(dword, EFX_DUMMY_FIELD, 0, __VA_ARGS__)
404#define EFX_ZERO_DWORD(dword) \
405 EFX_POPULATE_DWORD_1(dword, EFX_DUMMY_FIELD, 0)
406#define EFX_SET_DWORD(dword) \
407 EFX_POPULATE_DWORD_1(dword, EFX_DWORD_0, 0xffffffff)
408
409/*
410 * Modify a named field within an already-populated structure. Used
411 * for read-modify-write operations.
412 *
413 */
414
415#define EFX_INVERT_OWORD(oword) do { \
416 (oword).u64[0] = ~((oword).u64[0]); \
417 (oword).u64[1] = ~((oword).u64[1]); \
418 } while (0)
419
420#define EFX_INSERT_FIELD64(...) \
421 cpu_to_le64(EFX_INSERT_FIELD_NATIVE(__VA_ARGS__))
422
423#define EFX_INSERT_FIELD32(...) \
424 cpu_to_le32(EFX_INSERT_FIELD_NATIVE(__VA_ARGS__))
425
426#define EFX_INPLACE_MASK64(min, max, field) \
427 EFX_INSERT_FIELD64(min, max, field, EFX_MASK64(field))
428
429#define EFX_INPLACE_MASK32(min, max, field) \
430 EFX_INSERT_FIELD32(min, max, field, EFX_MASK32(field))
431
432#define EFX_SET_OWORD_FIELD64(oword, field, value) do { \
433 (oword).u64[0] = (((oword).u64[0] \
434 & ~EFX_INPLACE_MASK64(0, 63, field)) \
435 | EFX_INSERT_FIELD64(0, 63, field, value)); \
436 (oword).u64[1] = (((oword).u64[1] \
437 & ~EFX_INPLACE_MASK64(64, 127, field)) \
438 | EFX_INSERT_FIELD64(64, 127, field, value)); \
439 } while (0)
440
441#define EFX_SET_QWORD_FIELD64(qword, field, value) do { \
442 (qword).u64[0] = (((qword).u64[0] \
443 & ~EFX_INPLACE_MASK64(0, 63, field)) \
444 | EFX_INSERT_FIELD64(0, 63, field, value)); \
445 } while (0)
446
447#define EFX_SET_OWORD_FIELD32(oword, field, value) do { \
448 (oword).u32[0] = (((oword).u32[0] \
449 & ~EFX_INPLACE_MASK32(0, 31, field)) \
450 | EFX_INSERT_FIELD32(0, 31, field, value)); \
451 (oword).u32[1] = (((oword).u32[1] \
452 & ~EFX_INPLACE_MASK32(32, 63, field)) \
453 | EFX_INSERT_FIELD32(32, 63, field, value)); \
454 (oword).u32[2] = (((oword).u32[2] \
455 & ~EFX_INPLACE_MASK32(64, 95, field)) \
456 | EFX_INSERT_FIELD32(64, 95, field, value)); \
457 (oword).u32[3] = (((oword).u32[3] \
458 & ~EFX_INPLACE_MASK32(96, 127, field)) \
459 | EFX_INSERT_FIELD32(96, 127, field, value)); \
460 } while (0)
461
462#define EFX_SET_QWORD_FIELD32(qword, field, value) do { \
463 (qword).u32[0] = (((qword).u32[0] \
464 & ~EFX_INPLACE_MASK32(0, 31, field)) \
465 | EFX_INSERT_FIELD32(0, 31, field, value)); \
466 (qword).u32[1] = (((qword).u32[1] \
467 & ~EFX_INPLACE_MASK32(32, 63, field)) \
468 | EFX_INSERT_FIELD32(32, 63, field, value)); \
469 } while (0)
470
471#define EFX_SET_DWORD_FIELD(dword, field, value) do { \
472 (dword).u32[0] = (((dword).u32[0] \
473 & ~EFX_INPLACE_MASK32(0, 31, field)) \
474 | EFX_INSERT_FIELD32(0, 31, field, value)); \
475 } while (0)
476
477#if BITS_PER_LONG == 64
478#define EFX_SET_OWORD_FIELD EFX_SET_OWORD_FIELD64
479#define EFX_SET_QWORD_FIELD EFX_SET_QWORD_FIELD64
480#else
481#define EFX_SET_OWORD_FIELD EFX_SET_OWORD_FIELD32
482#define EFX_SET_QWORD_FIELD EFX_SET_QWORD_FIELD32
483#endif
484
485#define EFX_SET_OWORD_FIELD_VER(efx, oword, field, value) do { \
486 if (FALCON_REV(efx) >= FALCON_REV_B0) { \
487 EFX_SET_OWORD_FIELD((oword), field##_B0, (value)); \
488 } else { \
489 EFX_SET_OWORD_FIELD((oword), field##_A1, (value)); \
490 } \
491} while (0)
492
493#define EFX_QWORD_FIELD_VER(efx, qword, field) \
494 (FALCON_REV(efx) >= FALCON_REV_B0 ? \
495 EFX_QWORD_FIELD((qword), field##_B0) : \
496 EFX_QWORD_FIELD((qword), field##_A1))
497
498/* Used to avoid compiler warnings about shift range exceeding width
499 * of the data types when dma_addr_t is only 32 bits wide.
500 */
501#define DMA_ADDR_T_WIDTH (8 * sizeof(dma_addr_t))
502#define EFX_DMA_TYPE_WIDTH(width) \
503 (((width) < DMA_ADDR_T_WIDTH) ? (width) : DMA_ADDR_T_WIDTH)
504#define EFX_DMA_MAX_MASK ((DMA_ADDR_T_WIDTH == 64) ? \
505 ~((u64) 0) : ~((u32) 0))
506#define EFX_DMA_MASK(mask) ((mask) & EFX_DMA_MAX_MASK)
507
508#endif /* EFX_BITFIELD_H */
diff --git a/drivers/net/sfc/boards.c b/drivers/net/sfc/boards.c
new file mode 100644
index 000000000000..eecaa6d58584
--- /dev/null
+++ b/drivers/net/sfc/boards.c
@@ -0,0 +1,167 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2007 Solarflare Communications Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, incorporated herein by reference.
8 */
9
10#include "net_driver.h"
11#include "phy.h"
12#include "boards.h"
13#include "efx.h"
14
15/* Macros for unpacking the board revision */
16/* The revision info is in host byte order. */
17#define BOARD_TYPE(_rev) (_rev >> 8)
18#define BOARD_MAJOR(_rev) ((_rev >> 4) & 0xf)
19#define BOARD_MINOR(_rev) (_rev & 0xf)
20
21/* Blink support. If the PHY has no auto-blink mode so we hang it off a timer */
22#define BLINK_INTERVAL (HZ/2)
23
24static void blink_led_timer(unsigned long context)
25{
26 struct efx_nic *efx = (struct efx_nic *)context;
27 struct efx_blinker *bl = &efx->board_info.blinker;
28 efx->board_info.set_fault_led(efx, bl->state);
29 bl->state = !bl->state;
30 if (bl->resubmit) {
31 bl->timer.expires = jiffies + BLINK_INTERVAL;
32 add_timer(&bl->timer);
33 }
34}
35
36static void board_blink(struct efx_nic *efx, int blink)
37{
38 struct efx_blinker *blinker = &efx->board_info.blinker;
39
40 /* The rtnl mutex serialises all ethtool ioctls, so
41 * nothing special needs doing here. */
42 if (blink) {
43 blinker->resubmit = 1;
44 blinker->state = 0;
45 setup_timer(&blinker->timer, blink_led_timer,
46 (unsigned long)efx);
47 blinker->timer.expires = jiffies + BLINK_INTERVAL;
48 add_timer(&blinker->timer);
49 } else {
50 blinker->resubmit = 0;
51 if (blinker->timer.function)
52 del_timer_sync(&blinker->timer);
53 efx->board_info.set_fault_led(efx, 0);
54 }
55}
56
57/*****************************************************************************
58 * Support for the SFE4002
59 *
60 */
61/****************************************************************************/
62/* LED allocations. Note that on rev A0 boards the schematic and the reality
63 * differ: red and green are swapped. Below is the fixed (A1) layout (there
64 * are only 3 A0 boards in existence, so no real reason to make this
65 * conditional).
66 */
67#define SFE4002_FAULT_LED (2) /* Red */
68#define SFE4002_RX_LED (0) /* Green */
69#define SFE4002_TX_LED (1) /* Amber */
70
71static int sfe4002_init_leds(struct efx_nic *efx)
72{
73 /* Set the TX and RX LEDs to reflect status and activity, and the
74 * fault LED off */
75 xfp_set_led(efx, SFE4002_TX_LED,
76 QUAKE_LED_TXLINK | QUAKE_LED_LINK_ACTSTAT);
77 xfp_set_led(efx, SFE4002_RX_LED,
78 QUAKE_LED_RXLINK | QUAKE_LED_LINK_ACTSTAT);
79 xfp_set_led(efx, SFE4002_FAULT_LED, QUAKE_LED_OFF);
80 efx->board_info.blinker.led_num = SFE4002_FAULT_LED;
81 return 0;
82}
83
84static void sfe4002_fault_led(struct efx_nic *efx, int state)
85{
86 xfp_set_led(efx, SFE4002_FAULT_LED, state ? QUAKE_LED_ON :
87 QUAKE_LED_OFF);
88}
89
90static int sfe4002_init(struct efx_nic *efx)
91{
92 efx->board_info.init_leds = sfe4002_init_leds;
93 efx->board_info.set_fault_led = sfe4002_fault_led;
94 efx->board_info.blink = board_blink;
95 return 0;
96}
97
98/* This will get expanded as board-specific details get moved out of the
99 * PHY drivers. */
100struct efx_board_data {
101 const char *ref_model;
102 const char *gen_type;
103 int (*init) (struct efx_nic *nic);
104};
105
106static int dummy_init(struct efx_nic *nic)
107{
108 return 0;
109}
110
111static struct efx_board_data board_data[] = {
112 [EFX_BOARD_INVALID] =
113 {NULL, NULL, dummy_init},
114 [EFX_BOARD_SFE4001] =
115 {"SFE4001", "10GBASE-T adapter", sfe4001_poweron},
116 [EFX_BOARD_SFE4002] =
117 {"SFE4002", "XFP adapter", sfe4002_init},
118};
119
120int efx_set_board_info(struct efx_nic *efx, u16 revision_info)
121{
122 int rc = 0;
123 struct efx_board_data *data;
124
125 if (BOARD_TYPE(revision_info) >= EFX_BOARD_MAX) {
126 EFX_ERR(efx, "squashing unknown board type %d\n",
127 BOARD_TYPE(revision_info));
128 revision_info = 0;
129 }
130
131 if (BOARD_TYPE(revision_info) == 0) {
132 efx->board_info.major = 0;
133 efx->board_info.minor = 0;
134 /* For early boards that don't have revision info. there is
135 * only 1 board for each PHY type, so we can work it out, with
136 * the exception of the PHY-less boards. */
137 switch (efx->phy_type) {
138 case PHY_TYPE_10XPRESS:
139 efx->board_info.type = EFX_BOARD_SFE4001;
140 break;
141 case PHY_TYPE_XFP:
142 efx->board_info.type = EFX_BOARD_SFE4002;
143 break;
144 default:
145 efx->board_info.type = 0;
146 break;
147 }
148 } else {
149 efx->board_info.type = BOARD_TYPE(revision_info);
150 efx->board_info.major = BOARD_MAJOR(revision_info);
151 efx->board_info.minor = BOARD_MINOR(revision_info);
152 }
153
154 data = &board_data[efx->board_info.type];
155
156 /* Report the board model number or generic type for recognisable
157 * boards. */
158 if (efx->board_info.type != 0)
159 EFX_INFO(efx, "board is %s rev %c%d\n",
160 (efx->pci_dev->subsystem_vendor == EFX_VENDID_SFC)
161 ? data->ref_model : data->gen_type,
162 'A' + efx->board_info.major, efx->board_info.minor);
163
164 efx->board_info.init = data->init;
165
166 return rc;
167}
diff --git a/drivers/net/sfc/boards.h b/drivers/net/sfc/boards.h
new file mode 100644
index 000000000000..f56341d428e1
--- /dev/null
+++ b/drivers/net/sfc/boards.h
@@ -0,0 +1,26 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2007 Solarflare Communications Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, incorporated herein by reference.
8 */
9
10#ifndef EFX_BOARDS_H
11#define EFX_BOARDS_H
12
13/* Board IDs (must fit in 8 bits) */
14enum efx_board_type {
15 EFX_BOARD_INVALID = 0,
16 EFX_BOARD_SFE4001 = 1, /* SFE4001 (10GBASE-T) */
17 EFX_BOARD_SFE4002 = 2,
18 /* Insert new types before here */
19 EFX_BOARD_MAX
20};
21
22extern int efx_set_board_info(struct efx_nic *efx, u16 revision_info);
23extern int sfe4001_poweron(struct efx_nic *efx);
24extern void sfe4001_poweroff(struct efx_nic *efx);
25
26#endif
diff --git a/drivers/net/sfc/efx.c b/drivers/net/sfc/efx.c
new file mode 100644
index 000000000000..59edcf793c19
--- /dev/null
+++ b/drivers/net/sfc/efx.c
@@ -0,0 +1,2208 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2005-2008 Solarflare Communications Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
11#include <linux/module.h>
12#include <linux/pci.h>
13#include <linux/netdevice.h>
14#include <linux/etherdevice.h>
15#include <linux/delay.h>
16#include <linux/notifier.h>
17#include <linux/ip.h>
18#include <linux/tcp.h>
19#include <linux/in.h>
20#include <linux/crc32.h>
21#include <linux/ethtool.h>
22#include "net_driver.h"
23#include "gmii.h"
24#include "ethtool.h"
25#include "tx.h"
26#include "rx.h"
27#include "efx.h"
28#include "mdio_10g.h"
29#include "falcon.h"
30#include "workarounds.h"
31#include "mac.h"
32
33#define EFX_MAX_MTU (9 * 1024)
34
35/* RX slow fill workqueue. If memory allocation fails in the fast path,
36 * a work item is pushed onto this work queue to retry the allocation later,
37 * to avoid the NIC being starved of RX buffers. Since this is a per cpu
38 * workqueue, there is nothing to be gained in making it per NIC
39 */
40static struct workqueue_struct *refill_workqueue;
41
42/**************************************************************************
43 *
44 * Configurable values
45 *
46 *************************************************************************/
47
48/*
49 * Enable large receive offload (LRO) aka soft segment reassembly (SSR)
50 *
51 * This sets the default for new devices. It can be controlled later
52 * using ethtool.
53 */
54static int lro = 1;
55module_param(lro, int, 0644);
56MODULE_PARM_DESC(lro, "Large receive offload acceleration");
57
58/*
59 * Use separate channels for TX and RX events
60 *
61 * Set this to 1 to use separate channels for TX and RX. It allows us to
62 * apply a higher level of interrupt moderation to TX events.
63 *
64 * This is forced to 0 for MSI interrupt mode as the interrupt vector
65 * is not written
66 */
67static unsigned int separate_tx_and_rx_channels = 1;
68
69/* This is the weight assigned to each of the (per-channel) virtual
70 * NAPI devices.
71 */
72static int napi_weight = 64;
73
74/* This is the time (in jiffies) between invocations of the hardware
75 * monitor, which checks for known hardware bugs and resets the
76 * hardware and driver as necessary.
77 */
78unsigned int efx_monitor_interval = 1 * HZ;
79
80/* This controls whether or not the hardware monitor will trigger a
81 * reset when it detects an error condition.
82 */
83static unsigned int monitor_reset = 1;
84
85/* This controls whether or not the driver will initialise devices
86 * with invalid MAC addresses stored in the EEPROM or flash. If true,
87 * such devices will be initialised with a random locally-generated
88 * MAC address. This allows for loading the sfc_mtd driver to
89 * reprogram the flash, even if the flash contents (including the MAC
90 * address) have previously been erased.
91 */
92static unsigned int allow_bad_hwaddr;
93
94/* Initial interrupt moderation settings. They can be modified after
95 * module load with ethtool.
96 *
97 * The default for RX should strike a balance between increasing the
98 * round-trip latency and reducing overhead.
99 */
100static unsigned int rx_irq_mod_usec = 60;
101
102/* Initial interrupt moderation settings. They can be modified after
103 * module load with ethtool.
104 *
105 * This default is chosen to ensure that a 10G link does not go idle
106 * while a TX queue is stopped after it has become full. A queue is
107 * restarted when it drops below half full. The time this takes (assuming
108 * worst case 3 descriptors per packet and 1024 descriptors) is
109 * 512 / 3 * 1.2 = 205 usec.
110 */
111static unsigned int tx_irq_mod_usec = 150;
112
113/* This is the first interrupt mode to try out of:
114 * 0 => MSI-X
115 * 1 => MSI
116 * 2 => legacy
117 */
118static unsigned int interrupt_mode;
119
120/* This is the requested number of CPUs to use for Receive-Side Scaling (RSS),
121 * i.e. the number of CPUs among which we may distribute simultaneous
122 * interrupt handling.
123 *
124 * Cards without MSI-X will only target one CPU via legacy or MSI interrupt.
125 * The default (0) means to assign an interrupt to each package (level II cache)
126 */
127static unsigned int rss_cpus;
128module_param(rss_cpus, uint, 0444);
129MODULE_PARM_DESC(rss_cpus, "Number of CPUs to use for Receive-Side Scaling");
130
131/**************************************************************************
132 *
133 * Utility functions and prototypes
134 *
135 *************************************************************************/
136static void efx_remove_channel(struct efx_channel *channel);
137static void efx_remove_port(struct efx_nic *efx);
138static void efx_fini_napi(struct efx_nic *efx);
139static void efx_fini_channels(struct efx_nic *efx);
140
141#define EFX_ASSERT_RESET_SERIALISED(efx) \
142 do { \
143 if ((efx->state == STATE_RUNNING) || \
144 (efx->state == STATE_RESETTING)) \
145 ASSERT_RTNL(); \
146 } while (0)
147
148/**************************************************************************
149 *
150 * Event queue processing
151 *
152 *************************************************************************/
153
154/* Process channel's event queue
155 *
156 * This function is responsible for processing the event queue of a
157 * single channel. The caller must guarantee that this function will
158 * never be concurrently called more than once on the same channel,
159 * though different channels may be being processed concurrently.
160 */
161static inline int efx_process_channel(struct efx_channel *channel, int rx_quota)
162{
163 int rxdmaqs;
164 struct efx_rx_queue *rx_queue;
165
166 if (unlikely(channel->efx->reset_pending != RESET_TYPE_NONE ||
167 !channel->enabled))
168 return rx_quota;
169
170 rxdmaqs = falcon_process_eventq(channel, &rx_quota);
171
172 /* Deliver last RX packet. */
173 if (channel->rx_pkt) {
174 __efx_rx_packet(channel, channel->rx_pkt,
175 channel->rx_pkt_csummed);
176 channel->rx_pkt = NULL;
177 }
178
179 efx_flush_lro(channel);
180 efx_rx_strategy(channel);
181
182 /* Refill descriptor rings as necessary */
183 rx_queue = &channel->efx->rx_queue[0];
184 while (rxdmaqs) {
185 if (rxdmaqs & 0x01)
186 efx_fast_push_rx_descriptors(rx_queue);
187 rx_queue++;
188 rxdmaqs >>= 1;
189 }
190
191 return rx_quota;
192}
193
194/* Mark channel as finished processing
195 *
196 * Note that since we will not receive further interrupts for this
197 * channel before we finish processing and call the eventq_read_ack()
198 * method, there is no need to use the interrupt hold-off timers.
199 */
200static inline void efx_channel_processed(struct efx_channel *channel)
201{
202 /* Write to EVQ_RPTR_REG. If a new event arrived in a race
203 * with finishing processing, a new interrupt will be raised.
204 */
205 channel->work_pending = 0;
206 smp_wmb(); /* Ensure channel updated before any new interrupt. */
207 falcon_eventq_read_ack(channel);
208}
209
210/* NAPI poll handler
211 *
212 * NAPI guarantees serialisation of polls of the same device, which
213 * provides the guarantee required by efx_process_channel().
214 */
215static int efx_poll(struct napi_struct *napi, int budget)
216{
217 struct efx_channel *channel =
218 container_of(napi, struct efx_channel, napi_str);
219 struct net_device *napi_dev = channel->napi_dev;
220 int unused;
221 int rx_packets;
222
223 EFX_TRACE(channel->efx, "channel %d NAPI poll executing on CPU %d\n",
224 channel->channel, raw_smp_processor_id());
225
226 unused = efx_process_channel(channel, budget);
227 rx_packets = (budget - unused);
228
229 if (rx_packets < budget) {
230 /* There is no race here; although napi_disable() will
231 * only wait for netif_rx_complete(), this isn't a problem
232 * since efx_channel_processed() will have no effect if
233 * interrupts have already been disabled.
234 */
235 netif_rx_complete(napi_dev, napi);
236 efx_channel_processed(channel);
237 }
238
239 return rx_packets;
240}
241
242/* Process the eventq of the specified channel immediately on this CPU
243 *
244 * Disable hardware generated interrupts, wait for any existing
245 * processing to finish, then directly poll (and ack ) the eventq.
246 * Finally reenable NAPI and interrupts.
247 *
248 * Since we are touching interrupts the caller should hold the suspend lock
249 */
250void efx_process_channel_now(struct efx_channel *channel)
251{
252 struct efx_nic *efx = channel->efx;
253
254 BUG_ON(!channel->used_flags);
255 BUG_ON(!channel->enabled);
256
257 /* Disable interrupts and wait for ISRs to complete */
258 falcon_disable_interrupts(efx);
259 if (efx->legacy_irq)
260 synchronize_irq(efx->legacy_irq);
261 if (channel->has_interrupt && channel->irq)
262 synchronize_irq(channel->irq);
263
264 /* Wait for any NAPI processing to complete */
265 napi_disable(&channel->napi_str);
266
267 /* Poll the channel */
268 (void) efx_process_channel(channel, efx->type->evq_size);
269
270 /* Ack the eventq. This may cause an interrupt to be generated
271 * when they are reenabled */
272 efx_channel_processed(channel);
273
274 napi_enable(&channel->napi_str);
275 falcon_enable_interrupts(efx);
276}
277
278/* Create event queue
279 * Event queue memory allocations are done only once. If the channel
280 * is reset, the memory buffer will be reused; this guards against
281 * errors during channel reset and also simplifies interrupt handling.
282 */
283static int efx_probe_eventq(struct efx_channel *channel)
284{
285 EFX_LOG(channel->efx, "chan %d create event queue\n", channel->channel);
286
287 return falcon_probe_eventq(channel);
288}
289
290/* Prepare channel's event queue */
291static int efx_init_eventq(struct efx_channel *channel)
292{
293 EFX_LOG(channel->efx, "chan %d init event queue\n", channel->channel);
294
295 channel->eventq_read_ptr = 0;
296
297 return falcon_init_eventq(channel);
298}
299
300static void efx_fini_eventq(struct efx_channel *channel)
301{
302 EFX_LOG(channel->efx, "chan %d fini event queue\n", channel->channel);
303
304 falcon_fini_eventq(channel);
305}
306
307static void efx_remove_eventq(struct efx_channel *channel)
308{
309 EFX_LOG(channel->efx, "chan %d remove event queue\n", channel->channel);
310
311 falcon_remove_eventq(channel);
312}
313
314/**************************************************************************
315 *
316 * Channel handling
317 *
318 *************************************************************************/
319
320/* Setup per-NIC RX buffer parameters.
321 * Calculate the rx buffer allocation parameters required to support
322 * the current MTU, including padding for header alignment and overruns.
323 */
324static void efx_calc_rx_buffer_params(struct efx_nic *efx)
325{
326 unsigned int order, len;
327
328 len = (max(EFX_PAGE_IP_ALIGN, NET_IP_ALIGN) +
329 EFX_MAX_FRAME_LEN(efx->net_dev->mtu) +
330 efx->type->rx_buffer_padding);
331
332 /* Calculate page-order */
333 for (order = 0; ((1u << order) * PAGE_SIZE) < len; ++order)
334 ;
335
336 efx->rx_buffer_len = len;
337 efx->rx_buffer_order = order;
338}
339
340static int efx_probe_channel(struct efx_channel *channel)
341{
342 struct efx_tx_queue *tx_queue;
343 struct efx_rx_queue *rx_queue;
344 int rc;
345
346 EFX_LOG(channel->efx, "creating channel %d\n", channel->channel);
347
348 rc = efx_probe_eventq(channel);
349 if (rc)
350 goto fail1;
351
352 efx_for_each_channel_tx_queue(tx_queue, channel) {
353 rc = efx_probe_tx_queue(tx_queue);
354 if (rc)
355 goto fail2;
356 }
357
358 efx_for_each_channel_rx_queue(rx_queue, channel) {
359 rc = efx_probe_rx_queue(rx_queue);
360 if (rc)
361 goto fail3;
362 }
363
364 channel->n_rx_frm_trunc = 0;
365
366 return 0;
367
368 fail3:
369 efx_for_each_channel_rx_queue(rx_queue, channel)
370 efx_remove_rx_queue(rx_queue);
371 fail2:
372 efx_for_each_channel_tx_queue(tx_queue, channel)
373 efx_remove_tx_queue(tx_queue);
374 fail1:
375 return rc;
376}
377
378
379/* Channels are shutdown and reinitialised whilst the NIC is running
380 * to propagate configuration changes (mtu, checksum offload), or
381 * to clear hardware error conditions
382 */
383static int efx_init_channels(struct efx_nic *efx)
384{
385 struct efx_tx_queue *tx_queue;
386 struct efx_rx_queue *rx_queue;
387 struct efx_channel *channel;
388 int rc = 0;
389
390 efx_calc_rx_buffer_params(efx);
391
392 /* Initialise the channels */
393 efx_for_each_channel(channel, efx) {
394 EFX_LOG(channel->efx, "init chan %d\n", channel->channel);
395
396 rc = efx_init_eventq(channel);
397 if (rc)
398 goto err;
399
400 efx_for_each_channel_tx_queue(tx_queue, channel) {
401 rc = efx_init_tx_queue(tx_queue);
402 if (rc)
403 goto err;
404 }
405
406 /* The rx buffer allocation strategy is MTU dependent */
407 efx_rx_strategy(channel);
408
409 efx_for_each_channel_rx_queue(rx_queue, channel) {
410 rc = efx_init_rx_queue(rx_queue);
411 if (rc)
412 goto err;
413 }
414
415 WARN_ON(channel->rx_pkt != NULL);
416 efx_rx_strategy(channel);
417 }
418
419 return 0;
420
421 err:
422 EFX_ERR(efx, "failed to initialise channel %d\n",
423 channel ? channel->channel : -1);
424 efx_fini_channels(efx);
425 return rc;
426}
427
428/* This enables event queue processing and packet transmission.
429 *
430 * Note that this function is not allowed to fail, since that would
431 * introduce too much complexity into the suspend/resume path.
432 */
433static void efx_start_channel(struct efx_channel *channel)
434{
435 struct efx_rx_queue *rx_queue;
436
437 EFX_LOG(channel->efx, "starting chan %d\n", channel->channel);
438
439 if (!(channel->efx->net_dev->flags & IFF_UP))
440 netif_napi_add(channel->napi_dev, &channel->napi_str,
441 efx_poll, napi_weight);
442
443 channel->work_pending = 0;
444 channel->enabled = 1;
445 smp_wmb(); /* ensure channel updated before first interrupt */
446
447 napi_enable(&channel->napi_str);
448
449 /* Load up RX descriptors */
450 efx_for_each_channel_rx_queue(rx_queue, channel)
451 efx_fast_push_rx_descriptors(rx_queue);
452}
453
454/* This disables event queue processing and packet transmission.
455 * This function does not guarantee that all queue processing
456 * (e.g. RX refill) is complete.
457 */
458static void efx_stop_channel(struct efx_channel *channel)
459{
460 struct efx_rx_queue *rx_queue;
461
462 if (!channel->enabled)
463 return;
464
465 EFX_LOG(channel->efx, "stop chan %d\n", channel->channel);
466
467 channel->enabled = 0;
468 napi_disable(&channel->napi_str);
469
470 /* Ensure that any worker threads have exited or will be no-ops */
471 efx_for_each_channel_rx_queue(rx_queue, channel) {
472 spin_lock_bh(&rx_queue->add_lock);
473 spin_unlock_bh(&rx_queue->add_lock);
474 }
475}
476
477static void efx_fini_channels(struct efx_nic *efx)
478{
479 struct efx_channel *channel;
480 struct efx_tx_queue *tx_queue;
481 struct efx_rx_queue *rx_queue;
482
483 EFX_ASSERT_RESET_SERIALISED(efx);
484 BUG_ON(efx->port_enabled);
485
486 efx_for_each_channel(channel, efx) {
487 EFX_LOG(channel->efx, "shut down chan %d\n", channel->channel);
488
489 efx_for_each_channel_rx_queue(rx_queue, channel)
490 efx_fini_rx_queue(rx_queue);
491 efx_for_each_channel_tx_queue(tx_queue, channel)
492 efx_fini_tx_queue(tx_queue);
493 }
494
495 /* Do the event queues last so that we can handle flush events
496 * for all DMA queues. */
497 efx_for_each_channel(channel, efx) {
498 EFX_LOG(channel->efx, "shut down evq %d\n", channel->channel);
499
500 efx_fini_eventq(channel);
501 }
502}
503
504static void efx_remove_channel(struct efx_channel *channel)
505{
506 struct efx_tx_queue *tx_queue;
507 struct efx_rx_queue *rx_queue;
508
509 EFX_LOG(channel->efx, "destroy chan %d\n", channel->channel);
510
511 efx_for_each_channel_rx_queue(rx_queue, channel)
512 efx_remove_rx_queue(rx_queue);
513 efx_for_each_channel_tx_queue(tx_queue, channel)
514 efx_remove_tx_queue(tx_queue);
515 efx_remove_eventq(channel);
516
517 channel->used_flags = 0;
518}
519
520void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue, int delay)
521{
522 queue_delayed_work(refill_workqueue, &rx_queue->work, delay);
523}
524
525/**************************************************************************
526 *
527 * Port handling
528 *
529 **************************************************************************/
530
531/* This ensures that the kernel is kept informed (via
532 * netif_carrier_on/off) of the link status, and also maintains the
533 * link status's stop on the port's TX queue.
534 */
535static void efx_link_status_changed(struct efx_nic *efx)
536{
537 int carrier_ok;
538
539 /* SFC Bug 5356: A net_dev notifier is registered, so we must ensure
540 * that no events are triggered between unregister_netdev() and the
541 * driver unloading. A more general condition is that NETDEV_CHANGE
542 * can only be generated between NETDEV_UP and NETDEV_DOWN */
543 if (!netif_running(efx->net_dev))
544 return;
545
546 carrier_ok = netif_carrier_ok(efx->net_dev) ? 1 : 0;
547 if (efx->link_up != carrier_ok) {
548 efx->n_link_state_changes++;
549
550 if (efx->link_up)
551 netif_carrier_on(efx->net_dev);
552 else
553 netif_carrier_off(efx->net_dev);
554 }
555
556 /* Status message for kernel log */
557 if (efx->link_up) {
558 struct mii_if_info *gmii = &efx->mii;
559 unsigned adv, lpa;
560 /* NONE here means direct XAUI from the controller, with no
561 * MDIO-attached device we can query. */
562 if (efx->phy_type != PHY_TYPE_NONE) {
563 adv = gmii_advertised(gmii);
564 lpa = gmii_lpa(gmii);
565 } else {
566 lpa = GM_LPA_10000 | LPA_DUPLEX;
567 adv = lpa;
568 }
569 EFX_INFO(efx, "link up at %dMbps %s-duplex "
570 "(adv %04x lpa %04x) (MTU %d)%s\n",
571 (efx->link_options & GM_LPA_10000 ? 10000 :
572 (efx->link_options & GM_LPA_1000 ? 1000 :
573 (efx->link_options & GM_LPA_100 ? 100 :
574 10))),
575 (efx->link_options & GM_LPA_DUPLEX ?
576 "full" : "half"),
577 adv, lpa,
578 efx->net_dev->mtu,
579 (efx->promiscuous ? " [PROMISC]" : ""));
580 } else {
581 EFX_INFO(efx, "link down\n");
582 }
583
584}
585
586/* This call reinitialises the MAC to pick up new PHY settings. The
587 * caller must hold the mac_lock */
588static void __efx_reconfigure_port(struct efx_nic *efx)
589{
590 WARN_ON(!mutex_is_locked(&efx->mac_lock));
591
592 EFX_LOG(efx, "reconfiguring MAC from PHY settings on CPU %d\n",
593 raw_smp_processor_id());
594
595 falcon_reconfigure_xmac(efx);
596
597 /* Inform kernel of loss/gain of carrier */
598 efx_link_status_changed(efx);
599}
600
601/* Reinitialise the MAC to pick up new PHY settings, even if the port is
602 * disabled. */
603void efx_reconfigure_port(struct efx_nic *efx)
604{
605 EFX_ASSERT_RESET_SERIALISED(efx);
606
607 mutex_lock(&efx->mac_lock);
608 __efx_reconfigure_port(efx);
609 mutex_unlock(&efx->mac_lock);
610}
611
612/* Asynchronous efx_reconfigure_port work item. To speed up efx_flush_all()
613 * we don't efx_reconfigure_port() if the port is disabled. Care is taken
614 * in efx_stop_all() and efx_start_port() to prevent PHY events being lost */
615static void efx_reconfigure_work(struct work_struct *data)
616{
617 struct efx_nic *efx = container_of(data, struct efx_nic,
618 reconfigure_work);
619
620 mutex_lock(&efx->mac_lock);
621 if (efx->port_enabled)
622 __efx_reconfigure_port(efx);
623 mutex_unlock(&efx->mac_lock);
624}
625
626static int efx_probe_port(struct efx_nic *efx)
627{
628 int rc;
629
630 EFX_LOG(efx, "create port\n");
631
632 /* Connect up MAC/PHY operations table and read MAC address */
633 rc = falcon_probe_port(efx);
634 if (rc)
635 goto err;
636
637 /* Sanity check MAC address */
638 if (is_valid_ether_addr(efx->mac_address)) {
639 memcpy(efx->net_dev->dev_addr, efx->mac_address, ETH_ALEN);
640 } else {
641 DECLARE_MAC_BUF(mac);
642
643 EFX_ERR(efx, "invalid MAC address %s\n",
644 print_mac(mac, efx->mac_address));
645 if (!allow_bad_hwaddr) {
646 rc = -EINVAL;
647 goto err;
648 }
649 random_ether_addr(efx->net_dev->dev_addr);
650 EFX_INFO(efx, "using locally-generated MAC %s\n",
651 print_mac(mac, efx->net_dev->dev_addr));
652 }
653
654 return 0;
655
656 err:
657 efx_remove_port(efx);
658 return rc;
659}
660
661static int efx_init_port(struct efx_nic *efx)
662{
663 int rc;
664
665 EFX_LOG(efx, "init port\n");
666
667 /* Initialise the MAC and PHY */
668 rc = falcon_init_xmac(efx);
669 if (rc)
670 return rc;
671
672 efx->port_initialized = 1;
673
674 /* Reconfigure port to program MAC registers */
675 falcon_reconfigure_xmac(efx);
676
677 return 0;
678}
679
680/* Allow efx_reconfigure_port() to be scheduled, and close the window
681 * between efx_stop_port and efx_flush_all whereby a previously scheduled
682 * efx_reconfigure_port() may have been cancelled */
683static void efx_start_port(struct efx_nic *efx)
684{
685 EFX_LOG(efx, "start port\n");
686 BUG_ON(efx->port_enabled);
687
688 mutex_lock(&efx->mac_lock);
689 efx->port_enabled = 1;
690 __efx_reconfigure_port(efx);
691 mutex_unlock(&efx->mac_lock);
692}
693
694/* Prevent efx_reconfigure_work and efx_monitor() from executing, and
695 * efx_set_multicast_list() from scheduling efx_reconfigure_work.
696 * efx_reconfigure_work can still be scheduled via NAPI processing
697 * until efx_flush_all() is called */
698static void efx_stop_port(struct efx_nic *efx)
699{
700 EFX_LOG(efx, "stop port\n");
701
702 mutex_lock(&efx->mac_lock);
703 efx->port_enabled = 0;
704 mutex_unlock(&efx->mac_lock);
705
706 /* Serialise against efx_set_multicast_list() */
707 if (NET_DEV_REGISTERED(efx)) {
708 netif_tx_lock_bh(efx->net_dev);
709 netif_tx_unlock_bh(efx->net_dev);
710 }
711}
712
713static void efx_fini_port(struct efx_nic *efx)
714{
715 EFX_LOG(efx, "shut down port\n");
716
717 if (!efx->port_initialized)
718 return;
719
720 falcon_fini_xmac(efx);
721 efx->port_initialized = 0;
722
723 efx->link_up = 0;
724 efx_link_status_changed(efx);
725}
726
727static void efx_remove_port(struct efx_nic *efx)
728{
729 EFX_LOG(efx, "destroying port\n");
730
731 falcon_remove_port(efx);
732}
733
734/**************************************************************************
735 *
736 * NIC handling
737 *
738 **************************************************************************/
739
740/* This configures the PCI device to enable I/O and DMA. */
741static int efx_init_io(struct efx_nic *efx)
742{
743 struct pci_dev *pci_dev = efx->pci_dev;
744 dma_addr_t dma_mask = efx->type->max_dma_mask;
745 int rc;
746
747 EFX_LOG(efx, "initialising I/O\n");
748
749 rc = pci_enable_device(pci_dev);
750 if (rc) {
751 EFX_ERR(efx, "failed to enable PCI device\n");
752 goto fail1;
753 }
754
755 pci_set_master(pci_dev);
756
757 /* Set the PCI DMA mask. Try all possibilities from our
758 * genuine mask down to 32 bits, because some architectures
759 * (e.g. x86_64 with iommu_sac_force set) will allow 40 bit
760 * masks event though they reject 46 bit masks.
761 */
762 while (dma_mask > 0x7fffffffUL) {
763 if (pci_dma_supported(pci_dev, dma_mask) &&
764 ((rc = pci_set_dma_mask(pci_dev, dma_mask)) == 0))
765 break;
766 dma_mask >>= 1;
767 }
768 if (rc) {
769 EFX_ERR(efx, "could not find a suitable DMA mask\n");
770 goto fail2;
771 }
772 EFX_LOG(efx, "using DMA mask %llx\n", (unsigned long long) dma_mask);
773 rc = pci_set_consistent_dma_mask(pci_dev, dma_mask);
774 if (rc) {
775 /* pci_set_consistent_dma_mask() is not *allowed* to
776 * fail with a mask that pci_set_dma_mask() accepted,
777 * but just in case...
778 */
779 EFX_ERR(efx, "failed to set consistent DMA mask\n");
780 goto fail2;
781 }
782
783 efx->membase_phys = pci_resource_start(efx->pci_dev,
784 efx->type->mem_bar);
785 rc = pci_request_region(pci_dev, efx->type->mem_bar, "sfc");
786 if (rc) {
787 EFX_ERR(efx, "request for memory BAR failed\n");
788 rc = -EIO;
789 goto fail3;
790 }
791 efx->membase = ioremap_nocache(efx->membase_phys,
792 efx->type->mem_map_size);
793 if (!efx->membase) {
794 EFX_ERR(efx, "could not map memory BAR %d at %lx+%x\n",
795 efx->type->mem_bar, efx->membase_phys,
796 efx->type->mem_map_size);
797 rc = -ENOMEM;
798 goto fail4;
799 }
800 EFX_LOG(efx, "memory BAR %u at %lx+%x (virtual %p)\n",
801 efx->type->mem_bar, efx->membase_phys, efx->type->mem_map_size,
802 efx->membase);
803
804 return 0;
805
806 fail4:
807 release_mem_region(efx->membase_phys, efx->type->mem_map_size);
808 fail3:
809 efx->membase_phys = 0UL;
810 fail2:
811 pci_disable_device(efx->pci_dev);
812 fail1:
813 return rc;
814}
815
816static void efx_fini_io(struct efx_nic *efx)
817{
818 EFX_LOG(efx, "shutting down I/O\n");
819
820 if (efx->membase) {
821 iounmap(efx->membase);
822 efx->membase = NULL;
823 }
824
825 if (efx->membase_phys) {
826 pci_release_region(efx->pci_dev, efx->type->mem_bar);
827 efx->membase_phys = 0UL;
828 }
829
830 pci_disable_device(efx->pci_dev);
831}
832
833/* Probe the number and type of interrupts we are able to obtain. */
834static void efx_probe_interrupts(struct efx_nic *efx)
835{
836 int max_channel = efx->type->phys_addr_channels - 1;
837 struct msix_entry xentries[EFX_MAX_CHANNELS];
838 int rc, i;
839
840 if (efx->interrupt_mode == EFX_INT_MODE_MSIX) {
841 BUG_ON(!pci_find_capability(efx->pci_dev, PCI_CAP_ID_MSIX));
842
843 efx->rss_queues = rss_cpus ? rss_cpus : num_online_cpus();
844 efx->rss_queues = min(efx->rss_queues, max_channel + 1);
845 efx->rss_queues = min(efx->rss_queues, EFX_MAX_CHANNELS);
846
847 /* Request maximum number of MSI interrupts, and fill out
848 * the channel interrupt information the allowed allocation */
849 for (i = 0; i < efx->rss_queues; i++)
850 xentries[i].entry = i;
851 rc = pci_enable_msix(efx->pci_dev, xentries, efx->rss_queues);
852 if (rc > 0) {
853 EFX_BUG_ON_PARANOID(rc >= efx->rss_queues);
854 efx->rss_queues = rc;
855 rc = pci_enable_msix(efx->pci_dev, xentries,
856 efx->rss_queues);
857 }
858
859 if (rc == 0) {
860 for (i = 0; i < efx->rss_queues; i++) {
861 efx->channel[i].has_interrupt = 1;
862 efx->channel[i].irq = xentries[i].vector;
863 }
864 } else {
865 /* Fall back to single channel MSI */
866 efx->interrupt_mode = EFX_INT_MODE_MSI;
867 EFX_ERR(efx, "could not enable MSI-X\n");
868 }
869 }
870
871 /* Try single interrupt MSI */
872 if (efx->interrupt_mode == EFX_INT_MODE_MSI) {
873 efx->rss_queues = 1;
874 rc = pci_enable_msi(efx->pci_dev);
875 if (rc == 0) {
876 efx->channel[0].irq = efx->pci_dev->irq;
877 efx->channel[0].has_interrupt = 1;
878 } else {
879 EFX_ERR(efx, "could not enable MSI\n");
880 efx->interrupt_mode = EFX_INT_MODE_LEGACY;
881 }
882 }
883
884 /* Assume legacy interrupts */
885 if (efx->interrupt_mode == EFX_INT_MODE_LEGACY) {
886 efx->rss_queues = 1;
887 /* Every channel is interruptible */
888 for (i = 0; i < EFX_MAX_CHANNELS; i++)
889 efx->channel[i].has_interrupt = 1;
890 efx->legacy_irq = efx->pci_dev->irq;
891 }
892}
893
894static void efx_remove_interrupts(struct efx_nic *efx)
895{
896 struct efx_channel *channel;
897
898 /* Remove MSI/MSI-X interrupts */
899 efx_for_each_channel_with_interrupt(channel, efx)
900 channel->irq = 0;
901 pci_disable_msi(efx->pci_dev);
902 pci_disable_msix(efx->pci_dev);
903
904 /* Remove legacy interrupt */
905 efx->legacy_irq = 0;
906}
907
908/* Select number of used resources
909 * Should be called after probe_interrupts()
910 */
911static void efx_select_used(struct efx_nic *efx)
912{
913 struct efx_tx_queue *tx_queue;
914 struct efx_rx_queue *rx_queue;
915 int i;
916
917 /* TX queues. One per port per channel with TX capability
918 * (more than one per port won't work on Linux, due to out
919 * of order issues... but will be fine on Solaris)
920 */
921 tx_queue = &efx->tx_queue[0];
922
923 /* Perform this for each channel with TX capabilities.
924 * At the moment, we only support a single TX queue
925 */
926 tx_queue->used = 1;
927 if ((!EFX_INT_MODE_USE_MSI(efx)) && separate_tx_and_rx_channels)
928 tx_queue->channel = &efx->channel[1];
929 else
930 tx_queue->channel = &efx->channel[0];
931 tx_queue->channel->used_flags |= EFX_USED_BY_TX;
932 tx_queue++;
933
934 /* RX queues. Each has a dedicated channel. */
935 for (i = 0; i < EFX_MAX_RX_QUEUES; i++) {
936 rx_queue = &efx->rx_queue[i];
937
938 if (i < efx->rss_queues) {
939 rx_queue->used = 1;
940 /* If we allow multiple RX queues per channel
941 * we need to decide that here
942 */
943 rx_queue->channel = &efx->channel[rx_queue->queue];
944 rx_queue->channel->used_flags |= EFX_USED_BY_RX;
945 rx_queue++;
946 }
947 }
948}
949
950static int efx_probe_nic(struct efx_nic *efx)
951{
952 int rc;
953
954 EFX_LOG(efx, "creating NIC\n");
955
956 /* Carry out hardware-type specific initialisation */
957 rc = falcon_probe_nic(efx);
958 if (rc)
959 return rc;
960
961 /* Determine the number of channels and RX queues by trying to hook
962 * in MSI-X interrupts. */
963 efx_probe_interrupts(efx);
964
965 /* Determine number of RX queues and TX queues */
966 efx_select_used(efx);
967
968 /* Initialise the interrupt moderation settings */
969 efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec);
970
971 return 0;
972}
973
974static void efx_remove_nic(struct efx_nic *efx)
975{
976 EFX_LOG(efx, "destroying NIC\n");
977
978 efx_remove_interrupts(efx);
979 falcon_remove_nic(efx);
980}
981
982/**************************************************************************
983 *
984 * NIC startup/shutdown
985 *
986 *************************************************************************/
987
988static int efx_probe_all(struct efx_nic *efx)
989{
990 struct efx_channel *channel;
991 int rc;
992
993 /* Create NIC */
994 rc = efx_probe_nic(efx);
995 if (rc) {
996 EFX_ERR(efx, "failed to create NIC\n");
997 goto fail1;
998 }
999
1000 /* Create port */
1001 rc = efx_probe_port(efx);
1002 if (rc) {
1003 EFX_ERR(efx, "failed to create port\n");
1004 goto fail2;
1005 }
1006
1007 /* Create channels */
1008 efx_for_each_channel(channel, efx) {
1009 rc = efx_probe_channel(channel);
1010 if (rc) {
1011 EFX_ERR(efx, "failed to create channel %d\n",
1012 channel->channel);
1013 goto fail3;
1014 }
1015 }
1016
1017 return 0;
1018
1019 fail3:
1020 efx_for_each_channel(channel, efx)
1021 efx_remove_channel(channel);
1022 efx_remove_port(efx);
1023 fail2:
1024 efx_remove_nic(efx);
1025 fail1:
1026 return rc;
1027}
1028
1029/* Called after previous invocation(s) of efx_stop_all, restarts the
1030 * port, kernel transmit queue, NAPI processing and hardware interrupts,
1031 * and ensures that the port is scheduled to be reconfigured.
1032 * This function is safe to call multiple times when the NIC is in any
1033 * state. */
1034static void efx_start_all(struct efx_nic *efx)
1035{
1036 struct efx_channel *channel;
1037
1038 EFX_ASSERT_RESET_SERIALISED(efx);
1039
1040 /* Check that it is appropriate to restart the interface. All
1041 * of these flags are safe to read under just the rtnl lock */
1042 if (efx->port_enabled)
1043 return;
1044 if ((efx->state != STATE_RUNNING) && (efx->state != STATE_INIT))
1045 return;
1046 if (NET_DEV_REGISTERED(efx) && !netif_running(efx->net_dev))
1047 return;
1048
1049 /* Mark the port as enabled so port reconfigurations can start, then
1050 * restart the transmit interface early so the watchdog timer stops */
1051 efx_start_port(efx);
1052 efx_wake_queue(efx);
1053
1054 efx_for_each_channel(channel, efx)
1055 efx_start_channel(channel);
1056
1057 falcon_enable_interrupts(efx);
1058
1059 /* Start hardware monitor if we're in RUNNING */
1060 if (efx->state == STATE_RUNNING)
1061 queue_delayed_work(efx->workqueue, &efx->monitor_work,
1062 efx_monitor_interval);
1063}
1064
1065/* Flush all delayed work. Should only be called when no more delayed work
1066 * will be scheduled. This doesn't flush pending online resets (efx_reset),
1067 * since we're holding the rtnl_lock at this point. */
1068static void efx_flush_all(struct efx_nic *efx)
1069{
1070 struct efx_rx_queue *rx_queue;
1071
1072 /* Make sure the hardware monitor is stopped */
1073 cancel_delayed_work_sync(&efx->monitor_work);
1074
1075 /* Ensure that all RX slow refills are complete. */
1076 efx_for_each_rx_queue(rx_queue, efx) {
1077 cancel_delayed_work_sync(&rx_queue->work);
1078 }
1079
1080 /* Stop scheduled port reconfigurations */
1081 cancel_work_sync(&efx->reconfigure_work);
1082
1083}
1084
1085/* Quiesce hardware and software without bringing the link down.
1086 * Safe to call multiple times, when the nic and interface is in any
1087 * state. The caller is guaranteed to subsequently be in a position
1088 * to modify any hardware and software state they see fit without
1089 * taking locks. */
1090static void efx_stop_all(struct efx_nic *efx)
1091{
1092 struct efx_channel *channel;
1093
1094 EFX_ASSERT_RESET_SERIALISED(efx);
1095
1096 /* port_enabled can be read safely under the rtnl lock */
1097 if (!efx->port_enabled)
1098 return;
1099
1100 /* Disable interrupts and wait for ISR to complete */
1101 falcon_disable_interrupts(efx);
1102 if (efx->legacy_irq)
1103 synchronize_irq(efx->legacy_irq);
1104 efx_for_each_channel_with_interrupt(channel, efx)
1105 if (channel->irq)
1106 synchronize_irq(channel->irq);
1107
1108 /* Stop all NAPI processing and synchronous rx refills */
1109 efx_for_each_channel(channel, efx)
1110 efx_stop_channel(channel);
1111
1112 /* Stop all asynchronous port reconfigurations. Since all
1113 * event processing has already been stopped, there is no
1114 * window to loose phy events */
1115 efx_stop_port(efx);
1116
1117 /* Flush reconfigure_work, refill_workqueue, monitor_work */
1118 efx_flush_all(efx);
1119
1120 /* Isolate the MAC from the TX and RX engines, so that queue
1121 * flushes will complete in a timely fashion. */
1122 falcon_deconfigure_mac_wrapper(efx);
1123 falcon_drain_tx_fifo(efx);
1124
1125 /* Stop the kernel transmit interface late, so the watchdog
1126 * timer isn't ticking over the flush */
1127 efx_stop_queue(efx);
1128 if (NET_DEV_REGISTERED(efx)) {
1129 netif_tx_lock_bh(efx->net_dev);
1130 netif_tx_unlock_bh(efx->net_dev);
1131 }
1132}
1133
1134static void efx_remove_all(struct efx_nic *efx)
1135{
1136 struct efx_channel *channel;
1137
1138 efx_for_each_channel(channel, efx)
1139 efx_remove_channel(channel);
1140 efx_remove_port(efx);
1141 efx_remove_nic(efx);
1142}
1143
1144/* A convinience function to safely flush all the queues */
1145int efx_flush_queues(struct efx_nic *efx)
1146{
1147 int rc;
1148
1149 EFX_ASSERT_RESET_SERIALISED(efx);
1150
1151 efx_stop_all(efx);
1152
1153 efx_fini_channels(efx);
1154 rc = efx_init_channels(efx);
1155 if (rc) {
1156 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
1157 return rc;
1158 }
1159
1160 efx_start_all(efx);
1161
1162 return 0;
1163}
1164
1165/**************************************************************************
1166 *
1167 * Interrupt moderation
1168 *
1169 **************************************************************************/
1170
1171/* Set interrupt moderation parameters */
1172void efx_init_irq_moderation(struct efx_nic *efx, int tx_usecs, int rx_usecs)
1173{
1174 struct efx_tx_queue *tx_queue;
1175 struct efx_rx_queue *rx_queue;
1176
1177 EFX_ASSERT_RESET_SERIALISED(efx);
1178
1179 efx_for_each_tx_queue(tx_queue, efx)
1180 tx_queue->channel->irq_moderation = tx_usecs;
1181
1182 efx_for_each_rx_queue(rx_queue, efx)
1183 rx_queue->channel->irq_moderation = rx_usecs;
1184}
1185
1186/**************************************************************************
1187 *
1188 * Hardware monitor
1189 *
1190 **************************************************************************/
1191
1192/* Run periodically off the general workqueue. Serialised against
1193 * efx_reconfigure_port via the mac_lock */
1194static void efx_monitor(struct work_struct *data)
1195{
1196 struct efx_nic *efx = container_of(data, struct efx_nic,
1197 monitor_work.work);
1198 int rc = 0;
1199
1200 EFX_TRACE(efx, "hardware monitor executing on CPU %d\n",
1201 raw_smp_processor_id());
1202
1203
1204 /* If the mac_lock is already held then it is likely a port
1205 * reconfiguration is already in place, which will likely do
1206 * most of the work of check_hw() anyway. */
1207 if (!mutex_trylock(&efx->mac_lock)) {
1208 queue_delayed_work(efx->workqueue, &efx->monitor_work,
1209 efx_monitor_interval);
1210 return;
1211 }
1212
1213 if (efx->port_enabled)
1214 rc = falcon_check_xmac(efx);
1215 mutex_unlock(&efx->mac_lock);
1216
1217 if (rc) {
1218 if (monitor_reset) {
1219 EFX_ERR(efx, "hardware monitor detected a fault: "
1220 "triggering reset\n");
1221 efx_schedule_reset(efx, RESET_TYPE_MONITOR);
1222 } else {
1223 EFX_ERR(efx, "hardware monitor detected a fault, "
1224 "skipping reset\n");
1225 }
1226 }
1227
1228 queue_delayed_work(efx->workqueue, &efx->monitor_work,
1229 efx_monitor_interval);
1230}
1231
1232/**************************************************************************
1233 *
1234 * ioctls
1235 *
1236 *************************************************************************/
1237
1238/* Net device ioctl
1239 * Context: process, rtnl_lock() held.
1240 */
1241static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
1242{
1243 struct efx_nic *efx = net_dev->priv;
1244
1245 EFX_ASSERT_RESET_SERIALISED(efx);
1246
1247 return generic_mii_ioctl(&efx->mii, if_mii(ifr), cmd, NULL);
1248}
1249
1250/**************************************************************************
1251 *
1252 * NAPI interface
1253 *
1254 **************************************************************************/
1255
1256static int efx_init_napi(struct efx_nic *efx)
1257{
1258 struct efx_channel *channel;
1259 int rc;
1260
1261 efx_for_each_channel(channel, efx) {
1262 channel->napi_dev = efx->net_dev;
1263 rc = efx_lro_init(&channel->lro_mgr, efx);
1264 if (rc)
1265 goto err;
1266 }
1267 return 0;
1268 err:
1269 efx_fini_napi(efx);
1270 return rc;
1271}
1272
1273static void efx_fini_napi(struct efx_nic *efx)
1274{
1275 struct efx_channel *channel;
1276
1277 efx_for_each_channel(channel, efx) {
1278 efx_lro_fini(&channel->lro_mgr);
1279 channel->napi_dev = NULL;
1280 }
1281}
1282
1283/**************************************************************************
1284 *
1285 * Kernel netpoll interface
1286 *
1287 *************************************************************************/
1288
1289#ifdef CONFIG_NET_POLL_CONTROLLER
1290
1291/* Although in the common case interrupts will be disabled, this is not
1292 * guaranteed. However, all our work happens inside the NAPI callback,
1293 * so no locking is required.
1294 */
1295static void efx_netpoll(struct net_device *net_dev)
1296{
1297 struct efx_nic *efx = net_dev->priv;
1298 struct efx_channel *channel;
1299
1300 efx_for_each_channel_with_interrupt(channel, efx)
1301 efx_schedule_channel(channel);
1302}
1303
1304#endif
1305
1306/**************************************************************************
1307 *
1308 * Kernel net device interface
1309 *
1310 *************************************************************************/
1311
1312/* Context: process, rtnl_lock() held. */
1313static int efx_net_open(struct net_device *net_dev)
1314{
1315 struct efx_nic *efx = net_dev->priv;
1316 EFX_ASSERT_RESET_SERIALISED(efx);
1317
1318 EFX_LOG(efx, "opening device %s on CPU %d\n", net_dev->name,
1319 raw_smp_processor_id());
1320
1321 efx_start_all(efx);
1322 return 0;
1323}
1324
1325/* Context: process, rtnl_lock() held.
1326 * Note that the kernel will ignore our return code; this method
1327 * should really be a void.
1328 */
1329static int efx_net_stop(struct net_device *net_dev)
1330{
1331 struct efx_nic *efx = net_dev->priv;
1332 int rc;
1333
1334 EFX_LOG(efx, "closing %s on CPU %d\n", net_dev->name,
1335 raw_smp_processor_id());
1336
1337 /* Stop the device and flush all the channels */
1338 efx_stop_all(efx);
1339 efx_fini_channels(efx);
1340 rc = efx_init_channels(efx);
1341 if (rc)
1342 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
1343
1344 return 0;
1345}
1346
1347/* Context: process, dev_base_lock held, non-blocking. */
1348static struct net_device_stats *efx_net_stats(struct net_device *net_dev)
1349{
1350 struct efx_nic *efx = net_dev->priv;
1351 struct efx_mac_stats *mac_stats = &efx->mac_stats;
1352 struct net_device_stats *stats = &net_dev->stats;
1353
1354 if (!spin_trylock(&efx->stats_lock))
1355 return stats;
1356 if (efx->state == STATE_RUNNING) {
1357 falcon_update_stats_xmac(efx);
1358 falcon_update_nic_stats(efx);
1359 }
1360 spin_unlock(&efx->stats_lock);
1361
1362 stats->rx_packets = mac_stats->rx_packets;
1363 stats->tx_packets = mac_stats->tx_packets;
1364 stats->rx_bytes = mac_stats->rx_bytes;
1365 stats->tx_bytes = mac_stats->tx_bytes;
1366 stats->multicast = mac_stats->rx_multicast;
1367 stats->collisions = mac_stats->tx_collision;
1368 stats->rx_length_errors = (mac_stats->rx_gtjumbo +
1369 mac_stats->rx_length_error);
1370 stats->rx_over_errors = efx->n_rx_nodesc_drop_cnt;
1371 stats->rx_crc_errors = mac_stats->rx_bad;
1372 stats->rx_frame_errors = mac_stats->rx_align_error;
1373 stats->rx_fifo_errors = mac_stats->rx_overflow;
1374 stats->rx_missed_errors = mac_stats->rx_missed;
1375 stats->tx_window_errors = mac_stats->tx_late_collision;
1376
1377 stats->rx_errors = (stats->rx_length_errors +
1378 stats->rx_over_errors +
1379 stats->rx_crc_errors +
1380 stats->rx_frame_errors +
1381 stats->rx_fifo_errors +
1382 stats->rx_missed_errors +
1383 mac_stats->rx_symbol_error);
1384 stats->tx_errors = (stats->tx_window_errors +
1385 mac_stats->tx_bad);
1386
1387 return stats;
1388}
1389
1390/* Context: netif_tx_lock held, BHs disabled. */
1391static void efx_watchdog(struct net_device *net_dev)
1392{
1393 struct efx_nic *efx = net_dev->priv;
1394
1395 EFX_ERR(efx, "TX stuck with stop_count=%d port_enabled=%d: %s\n",
1396 atomic_read(&efx->netif_stop_count), efx->port_enabled,
1397 monitor_reset ? "resetting channels" : "skipping reset");
1398
1399 if (monitor_reset)
1400 efx_schedule_reset(efx, RESET_TYPE_MONITOR);
1401}
1402
1403
1404/* Context: process, rtnl_lock() held. */
1405static int efx_change_mtu(struct net_device *net_dev, int new_mtu)
1406{
1407 struct efx_nic *efx = net_dev->priv;
1408 int rc = 0;
1409
1410 EFX_ASSERT_RESET_SERIALISED(efx);
1411
1412 if (new_mtu > EFX_MAX_MTU)
1413 return -EINVAL;
1414
1415 efx_stop_all(efx);
1416
1417 EFX_LOG(efx, "changing MTU to %d\n", new_mtu);
1418
1419 efx_fini_channels(efx);
1420 net_dev->mtu = new_mtu;
1421 rc = efx_init_channels(efx);
1422 if (rc)
1423 goto fail;
1424
1425 efx_start_all(efx);
1426 return rc;
1427
1428 fail:
1429 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
1430 return rc;
1431}
1432
1433static int efx_set_mac_address(struct net_device *net_dev, void *data)
1434{
1435 struct efx_nic *efx = net_dev->priv;
1436 struct sockaddr *addr = data;
1437 char *new_addr = addr->sa_data;
1438
1439 EFX_ASSERT_RESET_SERIALISED(efx);
1440
1441 if (!is_valid_ether_addr(new_addr)) {
1442 DECLARE_MAC_BUF(mac);
1443 EFX_ERR(efx, "invalid ethernet MAC address requested: %s\n",
1444 print_mac(mac, new_addr));
1445 return -EINVAL;
1446 }
1447
1448 memcpy(net_dev->dev_addr, new_addr, net_dev->addr_len);
1449
1450 /* Reconfigure the MAC */
1451 efx_reconfigure_port(efx);
1452
1453 return 0;
1454}
1455
1456/* Context: netif_tx_lock held, BHs disabled. */
1457static void efx_set_multicast_list(struct net_device *net_dev)
1458{
1459 struct efx_nic *efx = net_dev->priv;
1460 struct dev_mc_list *mc_list = net_dev->mc_list;
1461 union efx_multicast_hash *mc_hash = &efx->multicast_hash;
1462 int promiscuous;
1463 u32 crc;
1464 int bit;
1465 int i;
1466
1467 /* Set per-MAC promiscuity flag and reconfigure MAC if necessary */
1468 promiscuous = (net_dev->flags & IFF_PROMISC) ? 1 : 0;
1469 if (efx->promiscuous != promiscuous) {
1470 efx->promiscuous = promiscuous;
1471 /* Close the window between efx_stop_port() and efx_flush_all()
1472 * by only queuing work when the port is enabled. */
1473 if (efx->port_enabled)
1474 queue_work(efx->workqueue, &efx->reconfigure_work);
1475 }
1476
1477 /* Build multicast hash table */
1478 if (promiscuous || (net_dev->flags & IFF_ALLMULTI)) {
1479 memset(mc_hash, 0xff, sizeof(*mc_hash));
1480 } else {
1481 memset(mc_hash, 0x00, sizeof(*mc_hash));
1482 for (i = 0; i < net_dev->mc_count; i++) {
1483 crc = ether_crc_le(ETH_ALEN, mc_list->dmi_addr);
1484 bit = crc & (EFX_MCAST_HASH_ENTRIES - 1);
1485 set_bit_le(bit, mc_hash->byte);
1486 mc_list = mc_list->next;
1487 }
1488 }
1489
1490 /* Create and activate new global multicast hash table */
1491 falcon_set_multicast_hash(efx);
1492}
1493
1494static int efx_netdev_event(struct notifier_block *this,
1495 unsigned long event, void *ptr)
1496{
1497 struct net_device *net_dev = (struct net_device *)ptr;
1498
1499 if (net_dev->open == efx_net_open && event == NETDEV_CHANGENAME) {
1500 struct efx_nic *efx = net_dev->priv;
1501
1502 strcpy(efx->name, net_dev->name);
1503 }
1504
1505 return NOTIFY_DONE;
1506}
1507
1508static struct notifier_block efx_netdev_notifier = {
1509 .notifier_call = efx_netdev_event,
1510};
1511
1512static int efx_register_netdev(struct efx_nic *efx)
1513{
1514 struct net_device *net_dev = efx->net_dev;
1515 int rc;
1516
1517 net_dev->watchdog_timeo = 5 * HZ;
1518 net_dev->irq = efx->pci_dev->irq;
1519 net_dev->open = efx_net_open;
1520 net_dev->stop = efx_net_stop;
1521 net_dev->get_stats = efx_net_stats;
1522 net_dev->tx_timeout = &efx_watchdog;
1523 net_dev->hard_start_xmit = efx_hard_start_xmit;
1524 net_dev->do_ioctl = efx_ioctl;
1525 net_dev->change_mtu = efx_change_mtu;
1526 net_dev->set_mac_address = efx_set_mac_address;
1527 net_dev->set_multicast_list = efx_set_multicast_list;
1528#ifdef CONFIG_NET_POLL_CONTROLLER
1529 net_dev->poll_controller = efx_netpoll;
1530#endif
1531 SET_NETDEV_DEV(net_dev, &efx->pci_dev->dev);
1532 SET_ETHTOOL_OPS(net_dev, &efx_ethtool_ops);
1533
1534 /* Always start with carrier off; PHY events will detect the link */
1535 netif_carrier_off(efx->net_dev);
1536
1537 /* Clear MAC statistics */
1538 falcon_update_stats_xmac(efx);
1539 memset(&efx->mac_stats, 0, sizeof(efx->mac_stats));
1540
1541 rc = register_netdev(net_dev);
1542 if (rc) {
1543 EFX_ERR(efx, "could not register net dev\n");
1544 return rc;
1545 }
1546 strcpy(efx->name, net_dev->name);
1547
1548 return 0;
1549}
1550
1551static void efx_unregister_netdev(struct efx_nic *efx)
1552{
1553 struct efx_tx_queue *tx_queue;
1554
1555 if (!efx->net_dev)
1556 return;
1557
1558 BUG_ON(efx->net_dev->priv != efx);
1559
1560 /* Free up any skbs still remaining. This has to happen before
1561 * we try to unregister the netdev as running their destructors
1562 * may be needed to get the device ref. count to 0. */
1563 efx_for_each_tx_queue(tx_queue, efx)
1564 efx_release_tx_buffers(tx_queue);
1565
1566 if (NET_DEV_REGISTERED(efx)) {
1567 strlcpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name));
1568 unregister_netdev(efx->net_dev);
1569 }
1570}
1571
1572/**************************************************************************
1573 *
1574 * Device reset and suspend
1575 *
1576 **************************************************************************/
1577
1578/* The final hardware and software finalisation before reset. */
1579static int efx_reset_down(struct efx_nic *efx, struct ethtool_cmd *ecmd)
1580{
1581 int rc;
1582
1583 EFX_ASSERT_RESET_SERIALISED(efx);
1584
1585 rc = falcon_xmac_get_settings(efx, ecmd);
1586 if (rc) {
1587 EFX_ERR(efx, "could not back up PHY settings\n");
1588 goto fail;
1589 }
1590
1591 efx_fini_channels(efx);
1592 return 0;
1593
1594 fail:
1595 return rc;
1596}
1597
1598/* The first part of software initialisation after a hardware reset
1599 * This function does not handle serialisation with the kernel, it
1600 * assumes the caller has done this */
1601static int efx_reset_up(struct efx_nic *efx, struct ethtool_cmd *ecmd)
1602{
1603 int rc;
1604
1605 rc = efx_init_channels(efx);
1606 if (rc)
1607 goto fail1;
1608
1609 /* Restore MAC and PHY settings. */
1610 rc = falcon_xmac_set_settings(efx, ecmd);
1611 if (rc) {
1612 EFX_ERR(efx, "could not restore PHY settings\n");
1613 goto fail2;
1614 }
1615
1616 return 0;
1617
1618 fail2:
1619 efx_fini_channels(efx);
1620 fail1:
1621 return rc;
1622}
1623
1624/* Reset the NIC as transparently as possible. Do not reset the PHY
1625 * Note that the reset may fail, in which case the card will be left
1626 * in a most-probably-unusable state.
1627 *
1628 * This function will sleep. You cannot reset from within an atomic
1629 * state; use efx_schedule_reset() instead.
1630 *
1631 * Grabs the rtnl_lock.
1632 */
1633static int efx_reset(struct efx_nic *efx)
1634{
1635 struct ethtool_cmd ecmd;
1636 enum reset_type method = efx->reset_pending;
1637 int rc;
1638
1639 /* Serialise with kernel interfaces */
1640 rtnl_lock();
1641
1642 /* If we're not RUNNING then don't reset. Leave the reset_pending
1643 * flag set so that efx_pci_probe_main will be retried */
1644 if (efx->state != STATE_RUNNING) {
1645 EFX_INFO(efx, "scheduled reset quenched. NIC not RUNNING\n");
1646 goto unlock_rtnl;
1647 }
1648
1649 efx->state = STATE_RESETTING;
1650 EFX_INFO(efx, "resetting (%d)\n", method);
1651
1652 /* The net_dev->get_stats handler is quite slow, and will fail
1653 * if a fetch is pending over reset. Serialise against it. */
1654 spin_lock(&efx->stats_lock);
1655 spin_unlock(&efx->stats_lock);
1656
1657 efx_stop_all(efx);
1658 mutex_lock(&efx->mac_lock);
1659
1660 rc = efx_reset_down(efx, &ecmd);
1661 if (rc)
1662 goto fail1;
1663
1664 rc = falcon_reset_hw(efx, method);
1665 if (rc) {
1666 EFX_ERR(efx, "failed to reset hardware\n");
1667 goto fail2;
1668 }
1669
1670 /* Allow resets to be rescheduled. */
1671 efx->reset_pending = RESET_TYPE_NONE;
1672
1673 /* Reinitialise bus-mastering, which may have been turned off before
1674 * the reset was scheduled. This is still appropriate, even in the
1675 * RESET_TYPE_DISABLE since this driver generally assumes the hardware
1676 * can respond to requests. */
1677 pci_set_master(efx->pci_dev);
1678
1679 /* Reinitialise device. This is appropriate in the RESET_TYPE_DISABLE
1680 * case so the driver can talk to external SRAM */
1681 rc = falcon_init_nic(efx);
1682 if (rc) {
1683 EFX_ERR(efx, "failed to initialise NIC\n");
1684 goto fail3;
1685 }
1686
1687 /* Leave device stopped if necessary */
1688 if (method == RESET_TYPE_DISABLE) {
1689 /* Reinitialise the device anyway so the driver unload sequence
1690 * can talk to the external SRAM */
1691 (void) falcon_init_nic(efx);
1692 rc = -EIO;
1693 goto fail4;
1694 }
1695
1696 rc = efx_reset_up(efx, &ecmd);
1697 if (rc)
1698 goto fail5;
1699
1700 mutex_unlock(&efx->mac_lock);
1701 EFX_LOG(efx, "reset complete\n");
1702
1703 efx->state = STATE_RUNNING;
1704 efx_start_all(efx);
1705
1706 unlock_rtnl:
1707 rtnl_unlock();
1708 return 0;
1709
1710 fail5:
1711 fail4:
1712 fail3:
1713 fail2:
1714 fail1:
1715 EFX_ERR(efx, "has been disabled\n");
1716 efx->state = STATE_DISABLED;
1717
1718 mutex_unlock(&efx->mac_lock);
1719 rtnl_unlock();
1720 efx_unregister_netdev(efx);
1721 efx_fini_port(efx);
1722 return rc;
1723}
1724
1725/* The worker thread exists so that code that cannot sleep can
1726 * schedule a reset for later.
1727 */
1728static void efx_reset_work(struct work_struct *data)
1729{
1730 struct efx_nic *nic = container_of(data, struct efx_nic, reset_work);
1731
1732 efx_reset(nic);
1733}
1734
1735void efx_schedule_reset(struct efx_nic *efx, enum reset_type type)
1736{
1737 enum reset_type method;
1738
1739 if (efx->reset_pending != RESET_TYPE_NONE) {
1740 EFX_INFO(efx, "quenching already scheduled reset\n");
1741 return;
1742 }
1743
1744 switch (type) {
1745 case RESET_TYPE_INVISIBLE:
1746 case RESET_TYPE_ALL:
1747 case RESET_TYPE_WORLD:
1748 case RESET_TYPE_DISABLE:
1749 method = type;
1750 break;
1751 case RESET_TYPE_RX_RECOVERY:
1752 case RESET_TYPE_RX_DESC_FETCH:
1753 case RESET_TYPE_TX_DESC_FETCH:
1754 case RESET_TYPE_TX_SKIP:
1755 method = RESET_TYPE_INVISIBLE;
1756 break;
1757 default:
1758 method = RESET_TYPE_ALL;
1759 break;
1760 }
1761
1762 if (method != type)
1763 EFX_LOG(efx, "scheduling reset (%d:%d)\n", type, method);
1764 else
1765 EFX_LOG(efx, "scheduling reset (%d)\n", method);
1766
1767 efx->reset_pending = method;
1768
1769 queue_work(efx->workqueue, &efx->reset_work);
1770}
1771
1772/**************************************************************************
1773 *
1774 * List of NICs we support
1775 *
1776 **************************************************************************/
1777
1778/* PCI device ID table */
1779static struct pci_device_id efx_pci_table[] __devinitdata = {
1780 {PCI_DEVICE(EFX_VENDID_SFC, FALCON_A_P_DEVID),
1781 .driver_data = (unsigned long) &falcon_a_nic_type},
1782 {PCI_DEVICE(EFX_VENDID_SFC, FALCON_B_P_DEVID),
1783 .driver_data = (unsigned long) &falcon_b_nic_type},
1784 {0} /* end of list */
1785};
1786
1787/**************************************************************************
1788 *
1789 * Dummy PHY/MAC/Board operations
1790 *
1791 * Can be used where the MAC does not implement this operation
1792 * Needed so all function pointers are valid and do not have to be tested
1793 * before use
1794 *
1795 **************************************************************************/
1796int efx_port_dummy_op_int(struct efx_nic *efx)
1797{
1798 return 0;
1799}
1800void efx_port_dummy_op_void(struct efx_nic *efx) {}
1801void efx_port_dummy_op_blink(struct efx_nic *efx, int blink) {}
1802
1803static struct efx_phy_operations efx_dummy_phy_operations = {
1804 .init = efx_port_dummy_op_int,
1805 .reconfigure = efx_port_dummy_op_void,
1806 .check_hw = efx_port_dummy_op_int,
1807 .fini = efx_port_dummy_op_void,
1808 .clear_interrupt = efx_port_dummy_op_void,
1809 .reset_xaui = efx_port_dummy_op_void,
1810};
1811
1812/* Dummy board operations */
1813static int efx_nic_dummy_op_int(struct efx_nic *nic)
1814{
1815 return 0;
1816}
1817
1818static struct efx_board efx_dummy_board_info = {
1819 .init = efx_nic_dummy_op_int,
1820 .init_leds = efx_port_dummy_op_int,
1821 .set_fault_led = efx_port_dummy_op_blink,
1822};
1823
1824/**************************************************************************
1825 *
1826 * Data housekeeping
1827 *
1828 **************************************************************************/
1829
1830/* This zeroes out and then fills in the invariants in a struct
1831 * efx_nic (including all sub-structures).
1832 */
1833static int efx_init_struct(struct efx_nic *efx, struct efx_nic_type *type,
1834 struct pci_dev *pci_dev, struct net_device *net_dev)
1835{
1836 struct efx_channel *channel;
1837 struct efx_tx_queue *tx_queue;
1838 struct efx_rx_queue *rx_queue;
1839 int i, rc;
1840
1841 /* Initialise common structures */
1842 memset(efx, 0, sizeof(*efx));
1843 spin_lock_init(&efx->biu_lock);
1844 spin_lock_init(&efx->phy_lock);
1845 INIT_WORK(&efx->reset_work, efx_reset_work);
1846 INIT_DELAYED_WORK(&efx->monitor_work, efx_monitor);
1847 efx->pci_dev = pci_dev;
1848 efx->state = STATE_INIT;
1849 efx->reset_pending = RESET_TYPE_NONE;
1850 strlcpy(efx->name, pci_name(pci_dev), sizeof(efx->name));
1851 efx->board_info = efx_dummy_board_info;
1852
1853 efx->net_dev = net_dev;
1854 efx->rx_checksum_enabled = 1;
1855 spin_lock_init(&efx->netif_stop_lock);
1856 spin_lock_init(&efx->stats_lock);
1857 mutex_init(&efx->mac_lock);
1858 efx->phy_op = &efx_dummy_phy_operations;
1859 efx->mii.dev = net_dev;
1860 INIT_WORK(&efx->reconfigure_work, efx_reconfigure_work);
1861 atomic_set(&efx->netif_stop_count, 1);
1862
1863 for (i = 0; i < EFX_MAX_CHANNELS; i++) {
1864 channel = &efx->channel[i];
1865 channel->efx = efx;
1866 channel->channel = i;
1867 channel->evqnum = i;
1868 channel->work_pending = 0;
1869 }
1870 for (i = 0; i < EFX_MAX_TX_QUEUES; i++) {
1871 tx_queue = &efx->tx_queue[i];
1872 tx_queue->efx = efx;
1873 tx_queue->queue = i;
1874 tx_queue->buffer = NULL;
1875 tx_queue->channel = &efx->channel[0]; /* for safety */
1876 }
1877 for (i = 0; i < EFX_MAX_RX_QUEUES; i++) {
1878 rx_queue = &efx->rx_queue[i];
1879 rx_queue->efx = efx;
1880 rx_queue->queue = i;
1881 rx_queue->channel = &efx->channel[0]; /* for safety */
1882 rx_queue->buffer = NULL;
1883 spin_lock_init(&rx_queue->add_lock);
1884 INIT_DELAYED_WORK(&rx_queue->work, efx_rx_work);
1885 }
1886
1887 efx->type = type;
1888
1889 /* Sanity-check NIC type */
1890 EFX_BUG_ON_PARANOID(efx->type->txd_ring_mask &
1891 (efx->type->txd_ring_mask + 1));
1892 EFX_BUG_ON_PARANOID(efx->type->rxd_ring_mask &
1893 (efx->type->rxd_ring_mask + 1));
1894 EFX_BUG_ON_PARANOID(efx->type->evq_size &
1895 (efx->type->evq_size - 1));
1896 /* As close as we can get to guaranteeing that we don't overflow */
1897 EFX_BUG_ON_PARANOID(efx->type->evq_size <
1898 (efx->type->txd_ring_mask + 1 +
1899 efx->type->rxd_ring_mask + 1));
1900 EFX_BUG_ON_PARANOID(efx->type->phys_addr_channels > EFX_MAX_CHANNELS);
1901
1902 /* Higher numbered interrupt modes are less capable! */
1903 efx->interrupt_mode = max(efx->type->max_interrupt_mode,
1904 interrupt_mode);
1905
1906 efx->workqueue = create_singlethread_workqueue("sfc_work");
1907 if (!efx->workqueue) {
1908 rc = -ENOMEM;
1909 goto fail1;
1910 }
1911
1912 return 0;
1913
1914 fail1:
1915 return rc;
1916}
1917
1918static void efx_fini_struct(struct efx_nic *efx)
1919{
1920 if (efx->workqueue) {
1921 destroy_workqueue(efx->workqueue);
1922 efx->workqueue = NULL;
1923 }
1924}
1925
1926/**************************************************************************
1927 *
1928 * PCI interface
1929 *
1930 **************************************************************************/
1931
1932/* Main body of final NIC shutdown code
1933 * This is called only at module unload (or hotplug removal).
1934 */
1935static void efx_pci_remove_main(struct efx_nic *efx)
1936{
1937 EFX_ASSERT_RESET_SERIALISED(efx);
1938
1939 /* Skip everything if we never obtained a valid membase */
1940 if (!efx->membase)
1941 return;
1942
1943 efx_fini_channels(efx);
1944 efx_fini_port(efx);
1945
1946 /* Shutdown the board, then the NIC and board state */
1947 falcon_fini_interrupt(efx);
1948
1949 efx_fini_napi(efx);
1950 efx_remove_all(efx);
1951}
1952
1953/* Final NIC shutdown
1954 * This is called only at module unload (or hotplug removal).
1955 */
1956static void efx_pci_remove(struct pci_dev *pci_dev)
1957{
1958 struct efx_nic *efx;
1959
1960 efx = pci_get_drvdata(pci_dev);
1961 if (!efx)
1962 return;
1963
1964 /* Mark the NIC as fini, then stop the interface */
1965 rtnl_lock();
1966 efx->state = STATE_FINI;
1967 dev_close(efx->net_dev);
1968
1969 /* Allow any queued efx_resets() to complete */
1970 rtnl_unlock();
1971
1972 if (efx->membase == NULL)
1973 goto out;
1974
1975 efx_unregister_netdev(efx);
1976
1977 /* Wait for any scheduled resets to complete. No more will be
1978 * scheduled from this point because efx_stop_all() has been
1979 * called, we are no longer registered with driverlink, and
1980 * the net_device's have been removed. */
1981 flush_workqueue(efx->workqueue);
1982
1983 efx_pci_remove_main(efx);
1984
1985out:
1986 efx_fini_io(efx);
1987 EFX_LOG(efx, "shutdown successful\n");
1988
1989 pci_set_drvdata(pci_dev, NULL);
1990 efx_fini_struct(efx);
1991 free_netdev(efx->net_dev);
1992};
1993
1994/* Main body of NIC initialisation
1995 * This is called at module load (or hotplug insertion, theoretically).
1996 */
1997static int efx_pci_probe_main(struct efx_nic *efx)
1998{
1999 int rc;
2000
2001 /* Do start-of-day initialisation */
2002 rc = efx_probe_all(efx);
2003 if (rc)
2004 goto fail1;
2005
2006 rc = efx_init_napi(efx);
2007 if (rc)
2008 goto fail2;
2009
2010 /* Initialise the board */
2011 rc = efx->board_info.init(efx);
2012 if (rc) {
2013 EFX_ERR(efx, "failed to initialise board\n");
2014 goto fail3;
2015 }
2016
2017 rc = falcon_init_nic(efx);
2018 if (rc) {
2019 EFX_ERR(efx, "failed to initialise NIC\n");
2020 goto fail4;
2021 }
2022
2023 rc = efx_init_port(efx);
2024 if (rc) {
2025 EFX_ERR(efx, "failed to initialise port\n");
2026 goto fail5;
2027 }
2028
2029 rc = efx_init_channels(efx);
2030 if (rc)
2031 goto fail6;
2032
2033 rc = falcon_init_interrupt(efx);
2034 if (rc)
2035 goto fail7;
2036
2037 return 0;
2038
2039 fail7:
2040 efx_fini_channels(efx);
2041 fail6:
2042 efx_fini_port(efx);
2043 fail5:
2044 fail4:
2045 fail3:
2046 efx_fini_napi(efx);
2047 fail2:
2048 efx_remove_all(efx);
2049 fail1:
2050 return rc;
2051}
2052
2053/* NIC initialisation
2054 *
2055 * This is called at module load (or hotplug insertion,
2056 * theoretically). It sets up PCI mappings, tests and resets the NIC,
2057 * sets up and registers the network devices with the kernel and hooks
2058 * the interrupt service routine. It does not prepare the device for
2059 * transmission; this is left to the first time one of the network
2060 * interfaces is brought up (i.e. efx_net_open).
2061 */
2062static int __devinit efx_pci_probe(struct pci_dev *pci_dev,
2063 const struct pci_device_id *entry)
2064{
2065 struct efx_nic_type *type = (struct efx_nic_type *) entry->driver_data;
2066 struct net_device *net_dev;
2067 struct efx_nic *efx;
2068 int i, rc;
2069
2070 /* Allocate and initialise a struct net_device and struct efx_nic */
2071 net_dev = alloc_etherdev(sizeof(*efx));
2072 if (!net_dev)
2073 return -ENOMEM;
2074 net_dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG | NETIF_F_HIGHDMA;
2075 if (lro)
2076 net_dev->features |= NETIF_F_LRO;
2077 efx = net_dev->priv;
2078 pci_set_drvdata(pci_dev, efx);
2079 rc = efx_init_struct(efx, type, pci_dev, net_dev);
2080 if (rc)
2081 goto fail1;
2082
2083 EFX_INFO(efx, "Solarflare Communications NIC detected\n");
2084
2085 /* Set up basic I/O (BAR mappings etc) */
2086 rc = efx_init_io(efx);
2087 if (rc)
2088 goto fail2;
2089
2090 /* No serialisation is required with the reset path because
2091 * we're in STATE_INIT. */
2092 for (i = 0; i < 5; i++) {
2093 rc = efx_pci_probe_main(efx);
2094 if (rc == 0)
2095 break;
2096
2097 /* Serialise against efx_reset(). No more resets will be
2098 * scheduled since efx_stop_all() has been called, and we
2099 * have not and never have been registered with either
2100 * the rtnetlink or driverlink layers. */
2101 cancel_work_sync(&efx->reset_work);
2102
2103 /* Retry if a recoverably reset event has been scheduled */
2104 if ((efx->reset_pending != RESET_TYPE_INVISIBLE) &&
2105 (efx->reset_pending != RESET_TYPE_ALL))
2106 goto fail3;
2107
2108 efx->reset_pending = RESET_TYPE_NONE;
2109 }
2110
2111 if (rc) {
2112 EFX_ERR(efx, "Could not reset NIC\n");
2113 goto fail4;
2114 }
2115
2116 /* Switch to the running state before we expose the device to
2117 * the OS. This is to ensure that the initial gathering of
2118 * MAC stats succeeds. */
2119 rtnl_lock();
2120 efx->state = STATE_RUNNING;
2121 rtnl_unlock();
2122
2123 rc = efx_register_netdev(efx);
2124 if (rc)
2125 goto fail5;
2126
2127 EFX_LOG(efx, "initialisation successful\n");
2128
2129 return 0;
2130
2131 fail5:
2132 efx_pci_remove_main(efx);
2133 fail4:
2134 fail3:
2135 efx_fini_io(efx);
2136 fail2:
2137 efx_fini_struct(efx);
2138 fail1:
2139 EFX_LOG(efx, "initialisation failed. rc=%d\n", rc);
2140 free_netdev(net_dev);
2141 return rc;
2142}
2143
2144static struct pci_driver efx_pci_driver = {
2145 .name = EFX_DRIVER_NAME,
2146 .id_table = efx_pci_table,
2147 .probe = efx_pci_probe,
2148 .remove = efx_pci_remove,
2149};
2150
2151/**************************************************************************
2152 *
2153 * Kernel module interface
2154 *
2155 *************************************************************************/
2156
2157module_param(interrupt_mode, uint, 0444);
2158MODULE_PARM_DESC(interrupt_mode,
2159 "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)");
2160
2161static int __init efx_init_module(void)
2162{
2163 int rc;
2164
2165 printk(KERN_INFO "Solarflare NET driver v" EFX_DRIVER_VERSION "\n");
2166
2167 rc = register_netdevice_notifier(&efx_netdev_notifier);
2168 if (rc)
2169 goto err_notifier;
2170
2171 refill_workqueue = create_workqueue("sfc_refill");
2172 if (!refill_workqueue) {
2173 rc = -ENOMEM;
2174 goto err_refill;
2175 }
2176
2177 rc = pci_register_driver(&efx_pci_driver);
2178 if (rc < 0)
2179 goto err_pci;
2180
2181 return 0;
2182
2183 err_pci:
2184 destroy_workqueue(refill_workqueue);
2185 err_refill:
2186 unregister_netdevice_notifier(&efx_netdev_notifier);
2187 err_notifier:
2188 return rc;
2189}
2190
2191static void __exit efx_exit_module(void)
2192{
2193 printk(KERN_INFO "Solarflare NET driver unloading\n");
2194
2195 pci_unregister_driver(&efx_pci_driver);
2196 destroy_workqueue(refill_workqueue);
2197 unregister_netdevice_notifier(&efx_netdev_notifier);
2198
2199}
2200
2201module_init(efx_init_module);
2202module_exit(efx_exit_module);
2203
2204MODULE_AUTHOR("Michael Brown <mbrown@fensystems.co.uk> and "
2205 "Solarflare Communications");
2206MODULE_DESCRIPTION("Solarflare Communications network driver");
2207MODULE_LICENSE("GPL");
2208MODULE_DEVICE_TABLE(pci, efx_pci_table);
diff --git a/drivers/net/sfc/efx.h b/drivers/net/sfc/efx.h
new file mode 100644
index 000000000000..3b2f69f4a9ab
--- /dev/null
+++ b/drivers/net/sfc/efx.h
@@ -0,0 +1,67 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2006-2008 Solarflare Communications Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
11#ifndef EFX_EFX_H
12#define EFX_EFX_H
13
14#include "net_driver.h"
15
16/* PCI IDs */
17#define EFX_VENDID_SFC 0x1924
18#define FALCON_A_P_DEVID 0x0703
19#define FALCON_A_S_DEVID 0x6703
20#define FALCON_B_P_DEVID 0x0710
21
22/* TX */
23extern int efx_xmit(struct efx_nic *efx,
24 struct efx_tx_queue *tx_queue, struct sk_buff *skb);
25extern void efx_stop_queue(struct efx_nic *efx);
26extern void efx_wake_queue(struct efx_nic *efx);
27
28/* RX */
29extern void efx_xmit_done(struct efx_tx_queue *tx_queue, unsigned int index);
30extern void efx_rx_packet(struct efx_rx_queue *rx_queue, unsigned int index,
31 unsigned int len, int checksummed, int discard);
32extern void efx_schedule_slow_fill(struct efx_rx_queue *rx_queue, int delay);
33
34/* Channels */
35extern void efx_process_channel_now(struct efx_channel *channel);
36extern int efx_flush_queues(struct efx_nic *efx);
37
38/* Ports */
39extern void efx_reconfigure_port(struct efx_nic *efx);
40
41/* Global */
42extern void efx_schedule_reset(struct efx_nic *efx, enum reset_type type);
43extern void efx_suspend(struct efx_nic *efx);
44extern void efx_resume(struct efx_nic *efx);
45extern void efx_init_irq_moderation(struct efx_nic *efx, int tx_usecs,
46 int rx_usecs);
47extern int efx_request_power(struct efx_nic *efx, int mw, const char *name);
48extern void efx_hex_dump(const u8 *, unsigned int, const char *);
49
50/* Dummy PHY ops for PHY drivers */
51extern int efx_port_dummy_op_int(struct efx_nic *efx);
52extern void efx_port_dummy_op_void(struct efx_nic *efx);
53extern void efx_port_dummy_op_blink(struct efx_nic *efx, int blink);
54
55
56extern unsigned int efx_monitor_interval;
57
58static inline void efx_schedule_channel(struct efx_channel *channel)
59{
60 EFX_TRACE(channel->efx, "channel %d scheduling NAPI poll on CPU%d\n",
61 channel->channel, raw_smp_processor_id());
62 channel->work_pending = 1;
63
64 netif_rx_schedule(channel->napi_dev, &channel->napi_str);
65}
66
67#endif /* EFX_EFX_H */
diff --git a/drivers/net/sfc/enum.h b/drivers/net/sfc/enum.h
new file mode 100644
index 000000000000..43663a4619da
--- /dev/null
+++ b/drivers/net/sfc/enum.h
@@ -0,0 +1,50 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2007 Solarflare Communications Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, incorporated herein by reference.
8 */
9
10#ifndef EFX_ENUM_H
11#define EFX_ENUM_H
12
13/*****************************************************************************/
14
15/**
16 * enum reset_type - reset types
17 *
18 * %RESET_TYPE_INVSIBLE, %RESET_TYPE_ALL, %RESET_TYPE_WORLD and
19 * %RESET_TYPE_DISABLE specify the method/scope of the reset. The
20 * other valuesspecify reasons, which efx_schedule_reset() will choose
21 * a method for.
22 *
23 * @RESET_TYPE_INVISIBLE: don't reset the PHYs or interrupts
24 * @RESET_TYPE_ALL: reset everything but PCI core blocks
25 * @RESET_TYPE_WORLD: reset everything, save & restore PCI config
26 * @RESET_TYPE_DISABLE: disable NIC
27 * @RESET_TYPE_MONITOR: reset due to hardware monitor
28 * @RESET_TYPE_INT_ERROR: reset due to internal error
29 * @RESET_TYPE_RX_RECOVERY: reset to recover from RX datapath errors
30 * @RESET_TYPE_RX_DESC_FETCH: pcie error during rx descriptor fetch
31 * @RESET_TYPE_TX_DESC_FETCH: pcie error during tx descriptor fetch
32 * @RESET_TYPE_TX_SKIP: hardware completed empty tx descriptors
33 */
34enum reset_type {
35 RESET_TYPE_NONE = -1,
36 RESET_TYPE_INVISIBLE = 0,
37 RESET_TYPE_ALL = 1,
38 RESET_TYPE_WORLD = 2,
39 RESET_TYPE_DISABLE = 3,
40 RESET_TYPE_MAX_METHOD,
41 RESET_TYPE_MONITOR,
42 RESET_TYPE_INT_ERROR,
43 RESET_TYPE_RX_RECOVERY,
44 RESET_TYPE_RX_DESC_FETCH,
45 RESET_TYPE_TX_DESC_FETCH,
46 RESET_TYPE_TX_SKIP,
47 RESET_TYPE_MAX,
48};
49
50#endif /* EFX_ENUM_H */
diff --git a/drivers/net/sfc/ethtool.c b/drivers/net/sfc/ethtool.c
new file mode 100644
index 000000000000..ad541badbd98
--- /dev/null
+++ b/drivers/net/sfc/ethtool.c
@@ -0,0 +1,460 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2006-2008 Solarflare Communications Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
11#include <linux/netdevice.h>
12#include <linux/ethtool.h>
13#include <linux/rtnetlink.h>
14#include "net_driver.h"
15#include "efx.h"
16#include "ethtool.h"
17#include "falcon.h"
18#include "gmii.h"
19#include "mac.h"
20
21static int efx_ethtool_set_tx_csum(struct net_device *net_dev, u32 enable);
22
23struct ethtool_string {
24 char name[ETH_GSTRING_LEN];
25};
26
27struct efx_ethtool_stat {
28 const char *name;
29 enum {
30 EFX_ETHTOOL_STAT_SOURCE_mac_stats,
31 EFX_ETHTOOL_STAT_SOURCE_nic,
32 EFX_ETHTOOL_STAT_SOURCE_channel
33 } source;
34 unsigned offset;
35 u64(*get_stat) (void *field); /* Reader function */
36};
37
38/* Initialiser for a struct #efx_ethtool_stat with type-checking */
39#define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
40 get_stat_function) { \
41 .name = #stat_name, \
42 .source = EFX_ETHTOOL_STAT_SOURCE_##source_name, \
43 .offset = ((((field_type *) 0) == \
44 &((struct efx_##source_name *)0)->field) ? \
45 offsetof(struct efx_##source_name, field) : \
46 offsetof(struct efx_##source_name, field)), \
47 .get_stat = get_stat_function, \
48}
49
50static u64 efx_get_uint_stat(void *field)
51{
52 return *(unsigned int *)field;
53}
54
55static u64 efx_get_ulong_stat(void *field)
56{
57 return *(unsigned long *)field;
58}
59
60static u64 efx_get_u64_stat(void *field)
61{
62 return *(u64 *) field;
63}
64
65static u64 efx_get_atomic_stat(void *field)
66{
67 return atomic_read((atomic_t *) field);
68}
69
70#define EFX_ETHTOOL_ULONG_MAC_STAT(field) \
71 EFX_ETHTOOL_STAT(field, mac_stats, field, \
72 unsigned long, efx_get_ulong_stat)
73
74#define EFX_ETHTOOL_U64_MAC_STAT(field) \
75 EFX_ETHTOOL_STAT(field, mac_stats, field, \
76 u64, efx_get_u64_stat)
77
78#define EFX_ETHTOOL_UINT_NIC_STAT(name) \
79 EFX_ETHTOOL_STAT(name, nic, n_##name, \
80 unsigned int, efx_get_uint_stat)
81
82#define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \
83 EFX_ETHTOOL_STAT(field, nic, field, \
84 atomic_t, efx_get_atomic_stat)
85
86#define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \
87 EFX_ETHTOOL_STAT(field, channel, n_##field, \
88 unsigned int, efx_get_uint_stat)
89
90static struct efx_ethtool_stat efx_ethtool_stats[] = {
91 EFX_ETHTOOL_U64_MAC_STAT(tx_bytes),
92 EFX_ETHTOOL_U64_MAC_STAT(tx_good_bytes),
93 EFX_ETHTOOL_U64_MAC_STAT(tx_bad_bytes),
94 EFX_ETHTOOL_ULONG_MAC_STAT(tx_packets),
95 EFX_ETHTOOL_ULONG_MAC_STAT(tx_bad),
96 EFX_ETHTOOL_ULONG_MAC_STAT(tx_pause),
97 EFX_ETHTOOL_ULONG_MAC_STAT(tx_control),
98 EFX_ETHTOOL_ULONG_MAC_STAT(tx_unicast),
99 EFX_ETHTOOL_ULONG_MAC_STAT(tx_multicast),
100 EFX_ETHTOOL_ULONG_MAC_STAT(tx_broadcast),
101 EFX_ETHTOOL_ULONG_MAC_STAT(tx_lt64),
102 EFX_ETHTOOL_ULONG_MAC_STAT(tx_64),
103 EFX_ETHTOOL_ULONG_MAC_STAT(tx_65_to_127),
104 EFX_ETHTOOL_ULONG_MAC_STAT(tx_128_to_255),
105 EFX_ETHTOOL_ULONG_MAC_STAT(tx_256_to_511),
106 EFX_ETHTOOL_ULONG_MAC_STAT(tx_512_to_1023),
107 EFX_ETHTOOL_ULONG_MAC_STAT(tx_1024_to_15xx),
108 EFX_ETHTOOL_ULONG_MAC_STAT(tx_15xx_to_jumbo),
109 EFX_ETHTOOL_ULONG_MAC_STAT(tx_gtjumbo),
110 EFX_ETHTOOL_ULONG_MAC_STAT(tx_collision),
111 EFX_ETHTOOL_ULONG_MAC_STAT(tx_single_collision),
112 EFX_ETHTOOL_ULONG_MAC_STAT(tx_multiple_collision),
113 EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_collision),
114 EFX_ETHTOOL_ULONG_MAC_STAT(tx_deferred),
115 EFX_ETHTOOL_ULONG_MAC_STAT(tx_late_collision),
116 EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_deferred),
117 EFX_ETHTOOL_ULONG_MAC_STAT(tx_non_tcpudp),
118 EFX_ETHTOOL_ULONG_MAC_STAT(tx_mac_src_error),
119 EFX_ETHTOOL_ULONG_MAC_STAT(tx_ip_src_error),
120 EFX_ETHTOOL_U64_MAC_STAT(rx_bytes),
121 EFX_ETHTOOL_U64_MAC_STAT(rx_good_bytes),
122 EFX_ETHTOOL_U64_MAC_STAT(rx_bad_bytes),
123 EFX_ETHTOOL_ULONG_MAC_STAT(rx_packets),
124 EFX_ETHTOOL_ULONG_MAC_STAT(rx_good),
125 EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad),
126 EFX_ETHTOOL_ULONG_MAC_STAT(rx_pause),
127 EFX_ETHTOOL_ULONG_MAC_STAT(rx_control),
128 EFX_ETHTOOL_ULONG_MAC_STAT(rx_unicast),
129 EFX_ETHTOOL_ULONG_MAC_STAT(rx_multicast),
130 EFX_ETHTOOL_ULONG_MAC_STAT(rx_broadcast),
131 EFX_ETHTOOL_ULONG_MAC_STAT(rx_lt64),
132 EFX_ETHTOOL_ULONG_MAC_STAT(rx_64),
133 EFX_ETHTOOL_ULONG_MAC_STAT(rx_65_to_127),
134 EFX_ETHTOOL_ULONG_MAC_STAT(rx_128_to_255),
135 EFX_ETHTOOL_ULONG_MAC_STAT(rx_256_to_511),
136 EFX_ETHTOOL_ULONG_MAC_STAT(rx_512_to_1023),
137 EFX_ETHTOOL_ULONG_MAC_STAT(rx_1024_to_15xx),
138 EFX_ETHTOOL_ULONG_MAC_STAT(rx_15xx_to_jumbo),
139 EFX_ETHTOOL_ULONG_MAC_STAT(rx_gtjumbo),
140 EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_lt64),
141 EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_64_to_15xx),
142 EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_15xx_to_jumbo),
143 EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_gtjumbo),
144 EFX_ETHTOOL_ULONG_MAC_STAT(rx_overflow),
145 EFX_ETHTOOL_ULONG_MAC_STAT(rx_missed),
146 EFX_ETHTOOL_ULONG_MAC_STAT(rx_false_carrier),
147 EFX_ETHTOOL_ULONG_MAC_STAT(rx_symbol_error),
148 EFX_ETHTOOL_ULONG_MAC_STAT(rx_align_error),
149 EFX_ETHTOOL_ULONG_MAC_STAT(rx_length_error),
150 EFX_ETHTOOL_ULONG_MAC_STAT(rx_internal_error),
151 EFX_ETHTOOL_UINT_NIC_STAT(rx_nodesc_drop_cnt),
152 EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
153 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
154 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
155 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
156 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
157};
158
159/* Number of ethtool statistics */
160#define EFX_ETHTOOL_NUM_STATS ARRAY_SIZE(efx_ethtool_stats)
161
162/**************************************************************************
163 *
164 * Ethtool operations
165 *
166 **************************************************************************
167 */
168
169/* Identify device by flashing LEDs */
170static int efx_ethtool_phys_id(struct net_device *net_dev, u32 seconds)
171{
172 struct efx_nic *efx = net_dev->priv;
173
174 efx->board_info.blink(efx, 1);
175 schedule_timeout_interruptible(seconds * HZ);
176 efx->board_info.blink(efx, 0);
177 return 0;
178}
179
180/* This must be called with rtnl_lock held. */
181int efx_ethtool_get_settings(struct net_device *net_dev,
182 struct ethtool_cmd *ecmd)
183{
184 struct efx_nic *efx = net_dev->priv;
185 int rc;
186
187 mutex_lock(&efx->mac_lock);
188 rc = falcon_xmac_get_settings(efx, ecmd);
189 mutex_unlock(&efx->mac_lock);
190
191 return rc;
192}
193
194/* This must be called with rtnl_lock held. */
195int efx_ethtool_set_settings(struct net_device *net_dev,
196 struct ethtool_cmd *ecmd)
197{
198 struct efx_nic *efx = net_dev->priv;
199 int rc;
200
201 mutex_lock(&efx->mac_lock);
202 rc = falcon_xmac_set_settings(efx, ecmd);
203 mutex_unlock(&efx->mac_lock);
204 if (!rc)
205 efx_reconfigure_port(efx);
206
207 return rc;
208}
209
210static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
211 struct ethtool_drvinfo *info)
212{
213 struct efx_nic *efx = net_dev->priv;
214
215 strlcpy(info->driver, EFX_DRIVER_NAME, sizeof(info->driver));
216 strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
217 strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
218}
219
220static int efx_ethtool_get_stats_count(struct net_device *net_dev)
221{
222 return EFX_ETHTOOL_NUM_STATS;
223}
224
225static void efx_ethtool_get_strings(struct net_device *net_dev,
226 u32 string_set, u8 *strings)
227{
228 struct ethtool_string *ethtool_strings =
229 (struct ethtool_string *)strings;
230 int i;
231
232 if (string_set == ETH_SS_STATS)
233 for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++)
234 strncpy(ethtool_strings[i].name,
235 efx_ethtool_stats[i].name,
236 sizeof(ethtool_strings[i].name));
237}
238
239static void efx_ethtool_get_stats(struct net_device *net_dev,
240 struct ethtool_stats *stats,
241 u64 *data)
242{
243 struct efx_nic *efx = net_dev->priv;
244 struct efx_mac_stats *mac_stats = &efx->mac_stats;
245 struct efx_ethtool_stat *stat;
246 struct efx_channel *channel;
247 int i;
248
249 EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS);
250
251 /* Update MAC and NIC statistics */
252 net_dev->get_stats(net_dev);
253
254 /* Fill detailed statistics buffer */
255 for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) {
256 stat = &efx_ethtool_stats[i];
257 switch (stat->source) {
258 case EFX_ETHTOOL_STAT_SOURCE_mac_stats:
259 data[i] = stat->get_stat((void *)mac_stats +
260 stat->offset);
261 break;
262 case EFX_ETHTOOL_STAT_SOURCE_nic:
263 data[i] = stat->get_stat((void *)efx + stat->offset);
264 break;
265 case EFX_ETHTOOL_STAT_SOURCE_channel:
266 data[i] = 0;
267 efx_for_each_channel(channel, efx)
268 data[i] += stat->get_stat((void *)channel +
269 stat->offset);
270 break;
271 }
272 }
273}
274
275static int efx_ethtool_set_tx_csum(struct net_device *net_dev, u32 enable)
276{
277 struct efx_nic *efx = net_dev->priv;
278 int rc;
279
280 rc = ethtool_op_set_tx_csum(net_dev, enable);
281 if (rc)
282 return rc;
283
284 efx_flush_queues(efx);
285
286 return 0;
287}
288
289static int efx_ethtool_set_rx_csum(struct net_device *net_dev, u32 enable)
290{
291 struct efx_nic *efx = net_dev->priv;
292
293 /* No way to stop the hardware doing the checks; we just
294 * ignore the result.
295 */
296 efx->rx_checksum_enabled = (enable ? 1 : 0);
297
298 return 0;
299}
300
301static u32 efx_ethtool_get_rx_csum(struct net_device *net_dev)
302{
303 struct efx_nic *efx = net_dev->priv;
304
305 return efx->rx_checksum_enabled;
306}
307
308/* Restart autonegotiation */
309static int efx_ethtool_nway_reset(struct net_device *net_dev)
310{
311 struct efx_nic *efx = net_dev->priv;
312
313 return mii_nway_restart(&efx->mii);
314}
315
316static u32 efx_ethtool_get_link(struct net_device *net_dev)
317{
318 struct efx_nic *efx = net_dev->priv;
319
320 return efx->link_up;
321}
322
323static int efx_ethtool_get_coalesce(struct net_device *net_dev,
324 struct ethtool_coalesce *coalesce)
325{
326 struct efx_nic *efx = net_dev->priv;
327 struct efx_tx_queue *tx_queue;
328 struct efx_rx_queue *rx_queue;
329 struct efx_channel *channel;
330
331 memset(coalesce, 0, sizeof(*coalesce));
332
333 /* Find lowest IRQ moderation across all used TX queues */
334 coalesce->tx_coalesce_usecs_irq = ~((u32) 0);
335 efx_for_each_tx_queue(tx_queue, efx) {
336 channel = tx_queue->channel;
337 if (channel->irq_moderation < coalesce->tx_coalesce_usecs_irq) {
338 if (channel->used_flags != EFX_USED_BY_RX_TX)
339 coalesce->tx_coalesce_usecs_irq =
340 channel->irq_moderation;
341 else
342 coalesce->tx_coalesce_usecs_irq = 0;
343 }
344 }
345
346 /* Find lowest IRQ moderation across all used RX queues */
347 coalesce->rx_coalesce_usecs_irq = ~((u32) 0);
348 efx_for_each_rx_queue(rx_queue, efx) {
349 channel = rx_queue->channel;
350 if (channel->irq_moderation < coalesce->rx_coalesce_usecs_irq)
351 coalesce->rx_coalesce_usecs_irq =
352 channel->irq_moderation;
353 }
354
355 return 0;
356}
357
358/* Set coalescing parameters
359 * The difficulties occur for shared channels
360 */
361static int efx_ethtool_set_coalesce(struct net_device *net_dev,
362 struct ethtool_coalesce *coalesce)
363{
364 struct efx_nic *efx = net_dev->priv;
365 struct efx_channel *channel;
366 struct efx_tx_queue *tx_queue;
367 unsigned tx_usecs, rx_usecs;
368
369 if (coalesce->use_adaptive_rx_coalesce ||
370 coalesce->use_adaptive_tx_coalesce)
371 return -EOPNOTSUPP;
372
373 if (coalesce->rx_coalesce_usecs || coalesce->tx_coalesce_usecs) {
374 EFX_ERR(efx, "invalid coalescing setting. "
375 "Only rx/tx_coalesce_usecs_irq are supported\n");
376 return -EOPNOTSUPP;
377 }
378
379 rx_usecs = coalesce->rx_coalesce_usecs_irq;
380 tx_usecs = coalesce->tx_coalesce_usecs_irq;
381
382 /* If the channel is shared only allow RX parameters to be set */
383 efx_for_each_tx_queue(tx_queue, efx) {
384 if ((tx_queue->channel->used_flags == EFX_USED_BY_RX_TX) &&
385 tx_usecs) {
386 EFX_ERR(efx, "Channel is shared. "
387 "Only RX coalescing may be set\n");
388 return -EOPNOTSUPP;
389 }
390 }
391
392 efx_init_irq_moderation(efx, tx_usecs, rx_usecs);
393
394 /* Reset channel to pick up new moderation value. Note that
395 * this may change the value of the irq_moderation field
396 * (e.g. to allow for hardware timer granularity).
397 */
398 efx_for_each_channel(channel, efx)
399 falcon_set_int_moderation(channel);
400
401 return 0;
402}
403
404static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
405 struct ethtool_pauseparam *pause)
406{
407 struct efx_nic *efx = net_dev->priv;
408 enum efx_fc_type flow_control = efx->flow_control;
409 int rc;
410
411 flow_control &= ~(EFX_FC_RX | EFX_FC_TX | EFX_FC_AUTO);
412 flow_control |= pause->rx_pause ? EFX_FC_RX : 0;
413 flow_control |= pause->tx_pause ? EFX_FC_TX : 0;
414 flow_control |= pause->autoneg ? EFX_FC_AUTO : 0;
415
416 /* Try to push the pause parameters */
417 mutex_lock(&efx->mac_lock);
418 rc = falcon_xmac_set_pause(efx, flow_control);
419 mutex_unlock(&efx->mac_lock);
420
421 if (!rc)
422 efx_reconfigure_port(efx);
423
424 return rc;
425}
426
427static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
428 struct ethtool_pauseparam *pause)
429{
430 struct efx_nic *efx = net_dev->priv;
431
432 pause->rx_pause = (efx->flow_control & EFX_FC_RX) ? 1 : 0;
433 pause->tx_pause = (efx->flow_control & EFX_FC_TX) ? 1 : 0;
434 pause->autoneg = (efx->flow_control & EFX_FC_AUTO) ? 1 : 0;
435}
436
437
438struct ethtool_ops efx_ethtool_ops = {
439 .get_settings = efx_ethtool_get_settings,
440 .set_settings = efx_ethtool_set_settings,
441 .get_drvinfo = efx_ethtool_get_drvinfo,
442 .nway_reset = efx_ethtool_nway_reset,
443 .get_link = efx_ethtool_get_link,
444 .get_coalesce = efx_ethtool_get_coalesce,
445 .set_coalesce = efx_ethtool_set_coalesce,
446 .get_pauseparam = efx_ethtool_get_pauseparam,
447 .set_pauseparam = efx_ethtool_set_pauseparam,
448 .get_rx_csum = efx_ethtool_get_rx_csum,
449 .set_rx_csum = efx_ethtool_set_rx_csum,
450 .get_tx_csum = ethtool_op_get_tx_csum,
451 .set_tx_csum = efx_ethtool_set_tx_csum,
452 .get_sg = ethtool_op_get_sg,
453 .set_sg = ethtool_op_set_sg,
454 .get_flags = ethtool_op_get_flags,
455 .set_flags = ethtool_op_set_flags,
456 .get_strings = efx_ethtool_get_strings,
457 .phys_id = efx_ethtool_phys_id,
458 .get_stats_count = efx_ethtool_get_stats_count,
459 .get_ethtool_stats = efx_ethtool_get_stats,
460};
diff --git a/drivers/net/sfc/ethtool.h b/drivers/net/sfc/ethtool.h
new file mode 100644
index 000000000000..3628e43df14d
--- /dev/null
+++ b/drivers/net/sfc/ethtool.h
@@ -0,0 +1,27 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005 Fen Systems Ltd.
4 * Copyright 2006 Solarflare Communications Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
11#ifndef EFX_ETHTOOL_H
12#define EFX_ETHTOOL_H
13
14#include "net_driver.h"
15
16/*
17 * Ethtool support
18 */
19
20extern int efx_ethtool_get_settings(struct net_device *net_dev,
21 struct ethtool_cmd *ecmd);
22extern int efx_ethtool_set_settings(struct net_device *net_dev,
23 struct ethtool_cmd *ecmd);
24
25extern struct ethtool_ops efx_ethtool_ops;
26
27#endif /* EFX_ETHTOOL_H */
diff --git a/drivers/net/sfc/falcon.c b/drivers/net/sfc/falcon.c
new file mode 100644
index 000000000000..46db549ce580
--- /dev/null
+++ b/drivers/net/sfc/falcon.c
@@ -0,0 +1,2722 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2006-2008 Solarflare Communications Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
11#include <linux/bitops.h>
12#include <linux/delay.h>
13#include <linux/pci.h>
14#include <linux/module.h>
15#include <linux/seq_file.h>
16#include "net_driver.h"
17#include "bitfield.h"
18#include "efx.h"
19#include "mac.h"
20#include "gmii.h"
21#include "spi.h"
22#include "falcon.h"
23#include "falcon_hwdefs.h"
24#include "falcon_io.h"
25#include "mdio_10g.h"
26#include "phy.h"
27#include "boards.h"
28#include "workarounds.h"
29
30/* Falcon hardware control.
31 * Falcon is the internal codename for the SFC4000 controller that is
32 * present in SFE400X evaluation boards
33 */
34
35/**
36 * struct falcon_nic_data - Falcon NIC state
37 * @next_buffer_table: First available buffer table id
38 * @pci_dev2: The secondary PCI device if present
39 */
40struct falcon_nic_data {
41 unsigned next_buffer_table;
42 struct pci_dev *pci_dev2;
43};
44
45/**************************************************************************
46 *
47 * Configurable values
48 *
49 **************************************************************************
50 */
51
52static int disable_dma_stats;
53
54/* This is set to 16 for a good reason. In summary, if larger than
55 * 16, the descriptor cache holds more than a default socket
56 * buffer's worth of packets (for UDP we can only have at most one
57 * socket buffer's worth outstanding). This combined with the fact
58 * that we only get 1 TX event per descriptor cache means the NIC
59 * goes idle.
60 */
61#define TX_DC_ENTRIES 16
62#define TX_DC_ENTRIES_ORDER 0
63#define TX_DC_BASE 0x130000
64
65#define RX_DC_ENTRIES 64
66#define RX_DC_ENTRIES_ORDER 2
67#define RX_DC_BASE 0x100000
68
69/* RX FIFO XOFF watermark
70 *
71 * When the amount of the RX FIFO increases used increases past this
72 * watermark send XOFF. Only used if RX flow control is enabled (ethtool -A)
73 * This also has an effect on RX/TX arbitration
74 */
75static int rx_xoff_thresh_bytes = -1;
76module_param(rx_xoff_thresh_bytes, int, 0644);
77MODULE_PARM_DESC(rx_xoff_thresh_bytes, "RX fifo XOFF threshold");
78
79/* RX FIFO XON watermark
80 *
81 * When the amount of the RX FIFO used decreases below this
82 * watermark send XON. Only used if TX flow control is enabled (ethtool -A)
83 * This also has an effect on RX/TX arbitration
84 */
85static int rx_xon_thresh_bytes = -1;
86module_param(rx_xon_thresh_bytes, int, 0644);
87MODULE_PARM_DESC(rx_xon_thresh_bytes, "RX fifo XON threshold");
88
89/* TX descriptor ring size - min 512 max 4k */
90#define FALCON_TXD_RING_ORDER TX_DESCQ_SIZE_1K
91#define FALCON_TXD_RING_SIZE 1024
92#define FALCON_TXD_RING_MASK (FALCON_TXD_RING_SIZE - 1)
93
94/* RX descriptor ring size - min 512 max 4k */
95#define FALCON_RXD_RING_ORDER RX_DESCQ_SIZE_1K
96#define FALCON_RXD_RING_SIZE 1024
97#define FALCON_RXD_RING_MASK (FALCON_RXD_RING_SIZE - 1)
98
99/* Event queue size - max 32k */
100#define FALCON_EVQ_ORDER EVQ_SIZE_4K
101#define FALCON_EVQ_SIZE 4096
102#define FALCON_EVQ_MASK (FALCON_EVQ_SIZE - 1)
103
104/* Max number of internal errors. After this resets will not be performed */
105#define FALCON_MAX_INT_ERRORS 4
106
107/* Maximum period that we wait for flush events. If the flush event
108 * doesn't arrive in this period of time then we check if the queue
109 * was disabled anyway. */
110#define FALCON_FLUSH_TIMEOUT 10 /* 10ms */
111
112/**************************************************************************
113 *
114 * Falcon constants
115 *
116 **************************************************************************
117 */
118
119/* DMA address mask (up to 46-bit, avoiding compiler warnings)
120 *
121 * Note that it is possible to have a platform with 64-bit longs and
122 * 32-bit DMA addresses, or vice versa. EFX_DMA_MASK takes care of the
123 * platform DMA mask.
124 */
125#if BITS_PER_LONG == 64
126#define FALCON_DMA_MASK EFX_DMA_MASK(0x00003fffffffffffUL)
127#else
128#define FALCON_DMA_MASK EFX_DMA_MASK(0x00003fffffffffffULL)
129#endif
130
131/* TX DMA length mask (13-bit) */
132#define FALCON_TX_DMA_MASK (4096 - 1)
133
134/* Size and alignment of special buffers (4KB) */
135#define FALCON_BUF_SIZE 4096
136
137/* Dummy SRAM size code */
138#define SRM_NB_BSZ_ONCHIP_ONLY (-1)
139
140/* Be nice if these (or equiv.) were in linux/pci_regs.h, but they're not. */
141#define PCI_EXP_DEVCAP_PWR_VAL_LBN 18
142#define PCI_EXP_DEVCAP_PWR_SCL_LBN 26
143#define PCI_EXP_DEVCTL_PAYLOAD_LBN 5
144#define PCI_EXP_LNKSTA_LNK_WID 0x3f0
145#define PCI_EXP_LNKSTA_LNK_WID_LBN 4
146
147#define FALCON_IS_DUAL_FUNC(efx) \
148 (FALCON_REV(efx) < FALCON_REV_B0)
149
150/**************************************************************************
151 *
152 * Falcon hardware access
153 *
154 **************************************************************************/
155
156/* Read the current event from the event queue */
157static inline efx_qword_t *falcon_event(struct efx_channel *channel,
158 unsigned int index)
159{
160 return (((efx_qword_t *) (channel->eventq.addr)) + index);
161}
162
163/* See if an event is present
164 *
165 * We check both the high and low dword of the event for all ones. We
166 * wrote all ones when we cleared the event, and no valid event can
167 * have all ones in either its high or low dwords. This approach is
168 * robust against reordering.
169 *
170 * Note that using a single 64-bit comparison is incorrect; even
171 * though the CPU read will be atomic, the DMA write may not be.
172 */
173static inline int falcon_event_present(efx_qword_t *event)
174{
175 return (!(EFX_DWORD_IS_ALL_ONES(event->dword[0]) |
176 EFX_DWORD_IS_ALL_ONES(event->dword[1])));
177}
178
179/**************************************************************************
180 *
181 * I2C bus - this is a bit-bashing interface using GPIO pins
182 * Note that it uses the output enables to tristate the outputs
183 * SDA is the data pin and SCL is the clock
184 *
185 **************************************************************************
186 */
187static void falcon_setsdascl(struct efx_i2c_interface *i2c)
188{
189 efx_oword_t reg;
190
191 falcon_read(i2c->efx, &reg, GPIO_CTL_REG_KER);
192 EFX_SET_OWORD_FIELD(reg, GPIO0_OEN, (i2c->scl ? 0 : 1));
193 EFX_SET_OWORD_FIELD(reg, GPIO3_OEN, (i2c->sda ? 0 : 1));
194 falcon_write(i2c->efx, &reg, GPIO_CTL_REG_KER);
195}
196
197static int falcon_getsda(struct efx_i2c_interface *i2c)
198{
199 efx_oword_t reg;
200
201 falcon_read(i2c->efx, &reg, GPIO_CTL_REG_KER);
202 return EFX_OWORD_FIELD(reg, GPIO3_IN);
203}
204
205static int falcon_getscl(struct efx_i2c_interface *i2c)
206{
207 efx_oword_t reg;
208
209 falcon_read(i2c->efx, &reg, GPIO_CTL_REG_KER);
210 return EFX_DWORD_FIELD(reg, GPIO0_IN);
211}
212
213static struct efx_i2c_bit_operations falcon_i2c_bit_operations = {
214 .setsda = falcon_setsdascl,
215 .setscl = falcon_setsdascl,
216 .getsda = falcon_getsda,
217 .getscl = falcon_getscl,
218 .udelay = 100,
219 .mdelay = 10,
220};
221
222/**************************************************************************
223 *
224 * Falcon special buffer handling
225 * Special buffers are used for event queues and the TX and RX
226 * descriptor rings.
227 *
228 *************************************************************************/
229
230/*
231 * Initialise a Falcon special buffer
232 *
233 * This will define a buffer (previously allocated via
234 * falcon_alloc_special_buffer()) in Falcon's buffer table, allowing
235 * it to be used for event queues, descriptor rings etc.
236 */
237static int
238falcon_init_special_buffer(struct efx_nic *efx,
239 struct efx_special_buffer *buffer)
240{
241 efx_qword_t buf_desc;
242 int index;
243 dma_addr_t dma_addr;
244 int i;
245
246 EFX_BUG_ON_PARANOID(!buffer->addr);
247
248 /* Write buffer descriptors to NIC */
249 for (i = 0; i < buffer->entries; i++) {
250 index = buffer->index + i;
251 dma_addr = buffer->dma_addr + (i * 4096);
252 EFX_LOG(efx, "mapping special buffer %d at %llx\n",
253 index, (unsigned long long)dma_addr);
254 EFX_POPULATE_QWORD_4(buf_desc,
255 IP_DAT_BUF_SIZE, IP_DAT_BUF_SIZE_4K,
256 BUF_ADR_REGION, 0,
257 BUF_ADR_FBUF, (dma_addr >> 12),
258 BUF_OWNER_ID_FBUF, 0);
259 falcon_write_sram(efx, &buf_desc, index);
260 }
261
262 return 0;
263}
264
265/* Unmaps a buffer from Falcon and clears the buffer table entries */
266static void
267falcon_fini_special_buffer(struct efx_nic *efx,
268 struct efx_special_buffer *buffer)
269{
270 efx_oword_t buf_tbl_upd;
271 unsigned int start = buffer->index;
272 unsigned int end = (buffer->index + buffer->entries - 1);
273
274 if (!buffer->entries)
275 return;
276
277 EFX_LOG(efx, "unmapping special buffers %d-%d\n",
278 buffer->index, buffer->index + buffer->entries - 1);
279
280 EFX_POPULATE_OWORD_4(buf_tbl_upd,
281 BUF_UPD_CMD, 0,
282 BUF_CLR_CMD, 1,
283 BUF_CLR_END_ID, end,
284 BUF_CLR_START_ID, start);
285 falcon_write(efx, &buf_tbl_upd, BUF_TBL_UPD_REG_KER);
286}
287
288/*
289 * Allocate a new Falcon special buffer
290 *
291 * This allocates memory for a new buffer, clears it and allocates a
292 * new buffer ID range. It does not write into Falcon's buffer table.
293 *
294 * This call will allocate 4KB buffers, since Falcon can't use 8KB
295 * buffers for event queues and descriptor rings.
296 */
297static int falcon_alloc_special_buffer(struct efx_nic *efx,
298 struct efx_special_buffer *buffer,
299 unsigned int len)
300{
301 struct falcon_nic_data *nic_data = efx->nic_data;
302
303 len = ALIGN(len, FALCON_BUF_SIZE);
304
305 buffer->addr = pci_alloc_consistent(efx->pci_dev, len,
306 &buffer->dma_addr);
307 if (!buffer->addr)
308 return -ENOMEM;
309 buffer->len = len;
310 buffer->entries = len / FALCON_BUF_SIZE;
311 BUG_ON(buffer->dma_addr & (FALCON_BUF_SIZE - 1));
312
313 /* All zeros is a potentially valid event so memset to 0xff */
314 memset(buffer->addr, 0xff, len);
315
316 /* Select new buffer ID */
317 buffer->index = nic_data->next_buffer_table;
318 nic_data->next_buffer_table += buffer->entries;
319
320 EFX_LOG(efx, "allocating special buffers %d-%d at %llx+%x "
321 "(virt %p phys %lx)\n", buffer->index,
322 buffer->index + buffer->entries - 1,
323 (unsigned long long)buffer->dma_addr, len,
324 buffer->addr, virt_to_phys(buffer->addr));
325
326 return 0;
327}
328
329static void falcon_free_special_buffer(struct efx_nic *efx,
330 struct efx_special_buffer *buffer)
331{
332 if (!buffer->addr)
333 return;
334
335 EFX_LOG(efx, "deallocating special buffers %d-%d at %llx+%x "
336 "(virt %p phys %lx)\n", buffer->index,
337 buffer->index + buffer->entries - 1,
338 (unsigned long long)buffer->dma_addr, buffer->len,
339 buffer->addr, virt_to_phys(buffer->addr));
340
341 pci_free_consistent(efx->pci_dev, buffer->len, buffer->addr,
342 buffer->dma_addr);
343 buffer->addr = NULL;
344 buffer->entries = 0;
345}
346
347/**************************************************************************
348 *
349 * Falcon generic buffer handling
350 * These buffers are used for interrupt status and MAC stats
351 *
352 **************************************************************************/
353
354static int falcon_alloc_buffer(struct efx_nic *efx,
355 struct efx_buffer *buffer, unsigned int len)
356{
357 buffer->addr = pci_alloc_consistent(efx->pci_dev, len,
358 &buffer->dma_addr);
359 if (!buffer->addr)
360 return -ENOMEM;
361 buffer->len = len;
362 memset(buffer->addr, 0, len);
363 return 0;
364}
365
366static void falcon_free_buffer(struct efx_nic *efx, struct efx_buffer *buffer)
367{
368 if (buffer->addr) {
369 pci_free_consistent(efx->pci_dev, buffer->len,
370 buffer->addr, buffer->dma_addr);
371 buffer->addr = NULL;
372 }
373}
374
375/**************************************************************************
376 *
377 * Falcon TX path
378 *
379 **************************************************************************/
380
381/* Returns a pointer to the specified transmit descriptor in the TX
382 * descriptor queue belonging to the specified channel.
383 */
384static inline efx_qword_t *falcon_tx_desc(struct efx_tx_queue *tx_queue,
385 unsigned int index)
386{
387 return (((efx_qword_t *) (tx_queue->txd.addr)) + index);
388}
389
390/* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */
391static inline void falcon_notify_tx_desc(struct efx_tx_queue *tx_queue)
392{
393 unsigned write_ptr;
394 efx_dword_t reg;
395
396 write_ptr = tx_queue->write_count & FALCON_TXD_RING_MASK;
397 EFX_POPULATE_DWORD_1(reg, TX_DESC_WPTR_DWORD, write_ptr);
398 falcon_writel_page(tx_queue->efx, &reg,
399 TX_DESC_UPD_REG_KER_DWORD, tx_queue->queue);
400}
401
402
403/* For each entry inserted into the software descriptor ring, create a
404 * descriptor in the hardware TX descriptor ring (in host memory), and
405 * write a doorbell.
406 */
407void falcon_push_buffers(struct efx_tx_queue *tx_queue)
408{
409
410 struct efx_tx_buffer *buffer;
411 efx_qword_t *txd;
412 unsigned write_ptr;
413
414 BUG_ON(tx_queue->write_count == tx_queue->insert_count);
415
416 do {
417 write_ptr = tx_queue->write_count & FALCON_TXD_RING_MASK;
418 buffer = &tx_queue->buffer[write_ptr];
419 txd = falcon_tx_desc(tx_queue, write_ptr);
420 ++tx_queue->write_count;
421
422 /* Create TX descriptor ring entry */
423 EFX_POPULATE_QWORD_5(*txd,
424 TX_KER_PORT, 0,
425 TX_KER_CONT, buffer->continuation,
426 TX_KER_BYTE_CNT, buffer->len,
427 TX_KER_BUF_REGION, 0,
428 TX_KER_BUF_ADR, buffer->dma_addr);
429 } while (tx_queue->write_count != tx_queue->insert_count);
430
431 wmb(); /* Ensure descriptors are written before they are fetched */
432 falcon_notify_tx_desc(tx_queue);
433}
434
435/* Allocate hardware resources for a TX queue */
436int falcon_probe_tx(struct efx_tx_queue *tx_queue)
437{
438 struct efx_nic *efx = tx_queue->efx;
439 return falcon_alloc_special_buffer(efx, &tx_queue->txd,
440 FALCON_TXD_RING_SIZE *
441 sizeof(efx_qword_t));
442}
443
444int falcon_init_tx(struct efx_tx_queue *tx_queue)
445{
446 efx_oword_t tx_desc_ptr;
447 struct efx_nic *efx = tx_queue->efx;
448 int rc;
449
450 /* Pin TX descriptor ring */
451 rc = falcon_init_special_buffer(efx, &tx_queue->txd);
452 if (rc)
453 return rc;
454
455 /* Push TX descriptor ring to card */
456 EFX_POPULATE_OWORD_10(tx_desc_ptr,
457 TX_DESCQ_EN, 1,
458 TX_ISCSI_DDIG_EN, 0,
459 TX_ISCSI_HDIG_EN, 0,
460 TX_DESCQ_BUF_BASE_ID, tx_queue->txd.index,
461 TX_DESCQ_EVQ_ID, tx_queue->channel->evqnum,
462 TX_DESCQ_OWNER_ID, 0,
463 TX_DESCQ_LABEL, tx_queue->queue,
464 TX_DESCQ_SIZE, FALCON_TXD_RING_ORDER,
465 TX_DESCQ_TYPE, 0,
466 TX_NON_IP_DROP_DIS_B0, 1);
467
468 if (FALCON_REV(efx) >= FALCON_REV_B0) {
469 int csum = !(efx->net_dev->features & NETIF_F_IP_CSUM);
470 EFX_SET_OWORD_FIELD(tx_desc_ptr, TX_IP_CHKSM_DIS_B0, csum);
471 EFX_SET_OWORD_FIELD(tx_desc_ptr, TX_TCP_CHKSM_DIS_B0, csum);
472 }
473
474 falcon_write_table(efx, &tx_desc_ptr, efx->type->txd_ptr_tbl_base,
475 tx_queue->queue);
476
477 if (FALCON_REV(efx) < FALCON_REV_B0) {
478 efx_oword_t reg;
479
480 BUG_ON(tx_queue->queue >= 128); /* HW limit */
481
482 falcon_read(efx, &reg, TX_CHKSM_CFG_REG_KER_A1);
483 if (efx->net_dev->features & NETIF_F_IP_CSUM)
484 clear_bit_le(tx_queue->queue, (void *)&reg);
485 else
486 set_bit_le(tx_queue->queue, (void *)&reg);
487 falcon_write(efx, &reg, TX_CHKSM_CFG_REG_KER_A1);
488 }
489
490 return 0;
491}
492
493static int falcon_flush_tx_queue(struct efx_tx_queue *tx_queue)
494{
495 struct efx_nic *efx = tx_queue->efx;
496 struct efx_channel *channel = &efx->channel[0];
497 efx_oword_t tx_flush_descq;
498 unsigned int read_ptr, i;
499
500 /* Post a flush command */
501 EFX_POPULATE_OWORD_2(tx_flush_descq,
502 TX_FLUSH_DESCQ_CMD, 1,
503 TX_FLUSH_DESCQ, tx_queue->queue);
504 falcon_write(efx, &tx_flush_descq, TX_FLUSH_DESCQ_REG_KER);
505 msleep(FALCON_FLUSH_TIMEOUT);
506
507 if (EFX_WORKAROUND_7803(efx))
508 return 0;
509
510 /* Look for a flush completed event */
511 read_ptr = channel->eventq_read_ptr;
512 for (i = 0; i < FALCON_EVQ_SIZE; ++i) {
513 efx_qword_t *event = falcon_event(channel, read_ptr);
514 int ev_code, ev_sub_code, ev_queue;
515 if (!falcon_event_present(event))
516 break;
517
518 ev_code = EFX_QWORD_FIELD(*event, EV_CODE);
519 ev_sub_code = EFX_QWORD_FIELD(*event, DRIVER_EV_SUB_CODE);
520 ev_queue = EFX_QWORD_FIELD(*event, DRIVER_EV_TX_DESCQ_ID);
521 if ((ev_sub_code == TX_DESCQ_FLS_DONE_EV_DECODE) &&
522 (ev_queue == tx_queue->queue)) {
523 EFX_LOG(efx, "tx queue %d flush command succesful\n",
524 tx_queue->queue);
525 return 0;
526 }
527
528 read_ptr = (read_ptr + 1) & FALCON_EVQ_MASK;
529 }
530
531 if (EFX_WORKAROUND_11557(efx)) {
532 efx_oword_t reg;
533 int enabled;
534
535 falcon_read_table(efx, &reg, efx->type->txd_ptr_tbl_base,
536 tx_queue->queue);
537 enabled = EFX_OWORD_FIELD(reg, TX_DESCQ_EN);
538 if (!enabled) {
539 EFX_LOG(efx, "tx queue %d disabled without a "
540 "flush event seen\n", tx_queue->queue);
541 return 0;
542 }
543 }
544
545 EFX_ERR(efx, "tx queue %d flush command timed out\n", tx_queue->queue);
546 return -ETIMEDOUT;
547}
548
549void falcon_fini_tx(struct efx_tx_queue *tx_queue)
550{
551 struct efx_nic *efx = tx_queue->efx;
552 efx_oword_t tx_desc_ptr;
553
554 /* Stop the hardware using the queue */
555 if (falcon_flush_tx_queue(tx_queue))
556 EFX_ERR(efx, "failed to flush tx queue %d\n", tx_queue->queue);
557
558 /* Remove TX descriptor ring from card */
559 EFX_ZERO_OWORD(tx_desc_ptr);
560 falcon_write_table(efx, &tx_desc_ptr, efx->type->txd_ptr_tbl_base,
561 tx_queue->queue);
562
563 /* Unpin TX descriptor ring */
564 falcon_fini_special_buffer(efx, &tx_queue->txd);
565}
566
567/* Free buffers backing TX queue */
568void falcon_remove_tx(struct efx_tx_queue *tx_queue)
569{
570 falcon_free_special_buffer(tx_queue->efx, &tx_queue->txd);
571}
572
573/**************************************************************************
574 *
575 * Falcon RX path
576 *
577 **************************************************************************/
578
579/* Returns a pointer to the specified descriptor in the RX descriptor queue */
580static inline efx_qword_t *falcon_rx_desc(struct efx_rx_queue *rx_queue,
581 unsigned int index)
582{
583 return (((efx_qword_t *) (rx_queue->rxd.addr)) + index);
584}
585
586/* This creates an entry in the RX descriptor queue */
587static inline void falcon_build_rx_desc(struct efx_rx_queue *rx_queue,
588 unsigned index)
589{
590 struct efx_rx_buffer *rx_buf;
591 efx_qword_t *rxd;
592
593 rxd = falcon_rx_desc(rx_queue, index);
594 rx_buf = efx_rx_buffer(rx_queue, index);
595 EFX_POPULATE_QWORD_3(*rxd,
596 RX_KER_BUF_SIZE,
597 rx_buf->len -
598 rx_queue->efx->type->rx_buffer_padding,
599 RX_KER_BUF_REGION, 0,
600 RX_KER_BUF_ADR, rx_buf->dma_addr);
601}
602
603/* This writes to the RX_DESC_WPTR register for the specified receive
604 * descriptor ring.
605 */
606void falcon_notify_rx_desc(struct efx_rx_queue *rx_queue)
607{
608 efx_dword_t reg;
609 unsigned write_ptr;
610
611 while (rx_queue->notified_count != rx_queue->added_count) {
612 falcon_build_rx_desc(rx_queue,
613 rx_queue->notified_count &
614 FALCON_RXD_RING_MASK);
615 ++rx_queue->notified_count;
616 }
617
618 wmb();
619 write_ptr = rx_queue->added_count & FALCON_RXD_RING_MASK;
620 EFX_POPULATE_DWORD_1(reg, RX_DESC_WPTR_DWORD, write_ptr);
621 falcon_writel_page(rx_queue->efx, &reg,
622 RX_DESC_UPD_REG_KER_DWORD, rx_queue->queue);
623}
624
625int falcon_probe_rx(struct efx_rx_queue *rx_queue)
626{
627 struct efx_nic *efx = rx_queue->efx;
628 return falcon_alloc_special_buffer(efx, &rx_queue->rxd,
629 FALCON_RXD_RING_SIZE *
630 sizeof(efx_qword_t));
631}
632
633int falcon_init_rx(struct efx_rx_queue *rx_queue)
634{
635 efx_oword_t rx_desc_ptr;
636 struct efx_nic *efx = rx_queue->efx;
637 int rc;
638 int is_b0 = FALCON_REV(efx) >= FALCON_REV_B0;
639 int iscsi_digest_en = is_b0;
640
641 EFX_LOG(efx, "RX queue %d ring in special buffers %d-%d\n",
642 rx_queue->queue, rx_queue->rxd.index,
643 rx_queue->rxd.index + rx_queue->rxd.entries - 1);
644
645 /* Pin RX descriptor ring */
646 rc = falcon_init_special_buffer(efx, &rx_queue->rxd);
647 if (rc)
648 return rc;
649
650 /* Push RX descriptor ring to card */
651 EFX_POPULATE_OWORD_10(rx_desc_ptr,
652 RX_ISCSI_DDIG_EN, iscsi_digest_en,
653 RX_ISCSI_HDIG_EN, iscsi_digest_en,
654 RX_DESCQ_BUF_BASE_ID, rx_queue->rxd.index,
655 RX_DESCQ_EVQ_ID, rx_queue->channel->evqnum,
656 RX_DESCQ_OWNER_ID, 0,
657 RX_DESCQ_LABEL, rx_queue->queue,
658 RX_DESCQ_SIZE, FALCON_RXD_RING_ORDER,
659 RX_DESCQ_TYPE, 0 /* kernel queue */ ,
660 /* For >=B0 this is scatter so disable */
661 RX_DESCQ_JUMBO, !is_b0,
662 RX_DESCQ_EN, 1);
663 falcon_write_table(efx, &rx_desc_ptr, efx->type->rxd_ptr_tbl_base,
664 rx_queue->queue);
665 return 0;
666}
667
668static int falcon_flush_rx_queue(struct efx_rx_queue *rx_queue)
669{
670 struct efx_nic *efx = rx_queue->efx;
671 struct efx_channel *channel = &efx->channel[0];
672 unsigned int read_ptr, i;
673 efx_oword_t rx_flush_descq;
674
675 /* Post a flush command */
676 EFX_POPULATE_OWORD_2(rx_flush_descq,
677 RX_FLUSH_DESCQ_CMD, 1,
678 RX_FLUSH_DESCQ, rx_queue->queue);
679 falcon_write(efx, &rx_flush_descq, RX_FLUSH_DESCQ_REG_KER);
680 msleep(FALCON_FLUSH_TIMEOUT);
681
682 if (EFX_WORKAROUND_7803(efx))
683 return 0;
684
685 /* Look for a flush completed event */
686 read_ptr = channel->eventq_read_ptr;
687 for (i = 0; i < FALCON_EVQ_SIZE; ++i) {
688 efx_qword_t *event = falcon_event(channel, read_ptr);
689 int ev_code, ev_sub_code, ev_queue, ev_failed;
690 if (!falcon_event_present(event))
691 break;
692
693 ev_code = EFX_QWORD_FIELD(*event, EV_CODE);
694 ev_sub_code = EFX_QWORD_FIELD(*event, DRIVER_EV_SUB_CODE);
695 ev_queue = EFX_QWORD_FIELD(*event, DRIVER_EV_RX_DESCQ_ID);
696 ev_failed = EFX_QWORD_FIELD(*event, DRIVER_EV_RX_FLUSH_FAIL);
697
698 if ((ev_sub_code == RX_DESCQ_FLS_DONE_EV_DECODE) &&
699 (ev_queue == rx_queue->queue)) {
700 if (ev_failed) {
701 EFX_INFO(efx, "rx queue %d flush command "
702 "failed\n", rx_queue->queue);
703 return -EAGAIN;
704 } else {
705 EFX_LOG(efx, "rx queue %d flush command "
706 "succesful\n", rx_queue->queue);
707 return 0;
708 }
709 }
710
711 read_ptr = (read_ptr + 1) & FALCON_EVQ_MASK;
712 }
713
714 if (EFX_WORKAROUND_11557(efx)) {
715 efx_oword_t reg;
716 int enabled;
717
718 falcon_read_table(efx, &reg, efx->type->rxd_ptr_tbl_base,
719 rx_queue->queue);
720 enabled = EFX_OWORD_FIELD(reg, RX_DESCQ_EN);
721 if (!enabled) {
722 EFX_LOG(efx, "rx queue %d disabled without a "
723 "flush event seen\n", rx_queue->queue);
724 return 0;
725 }
726 }
727
728 EFX_ERR(efx, "rx queue %d flush command timed out\n", rx_queue->queue);
729 return -ETIMEDOUT;
730}
731
732void falcon_fini_rx(struct efx_rx_queue *rx_queue)
733{
734 efx_oword_t rx_desc_ptr;
735 struct efx_nic *efx = rx_queue->efx;
736 int i, rc;
737
738 /* Try and flush the rx queue. This may need to be repeated */
739 for (i = 0; i < 5; i++) {
740 rc = falcon_flush_rx_queue(rx_queue);
741 if (rc == -EAGAIN)
742 continue;
743 break;
744 }
745 if (rc)
746 EFX_ERR(efx, "failed to flush rx queue %d\n", rx_queue->queue);
747
748 /* Remove RX descriptor ring from card */
749 EFX_ZERO_OWORD(rx_desc_ptr);
750 falcon_write_table(efx, &rx_desc_ptr, efx->type->rxd_ptr_tbl_base,
751 rx_queue->queue);
752
753 /* Unpin RX descriptor ring */
754 falcon_fini_special_buffer(efx, &rx_queue->rxd);
755}
756
757/* Free buffers backing RX queue */
758void falcon_remove_rx(struct efx_rx_queue *rx_queue)
759{
760 falcon_free_special_buffer(rx_queue->efx, &rx_queue->rxd);
761}
762
763/**************************************************************************
764 *
765 * Falcon event queue processing
766 * Event queues are processed by per-channel tasklets.
767 *
768 **************************************************************************/
769
770/* Update a channel's event queue's read pointer (RPTR) register
771 *
772 * This writes the EVQ_RPTR_REG register for the specified channel's
773 * event queue.
774 *
775 * Note that EVQ_RPTR_REG contains the index of the "last read" event,
776 * whereas channel->eventq_read_ptr contains the index of the "next to
777 * read" event.
778 */
779void falcon_eventq_read_ack(struct efx_channel *channel)
780{
781 efx_dword_t reg;
782 struct efx_nic *efx = channel->efx;
783
784 EFX_POPULATE_DWORD_1(reg, EVQ_RPTR_DWORD, channel->eventq_read_ptr);
785 falcon_writel_table(efx, &reg, efx->type->evq_rptr_tbl_base,
786 channel->evqnum);
787}
788
789/* Use HW to insert a SW defined event */
790void falcon_generate_event(struct efx_channel *channel, efx_qword_t *event)
791{
792 efx_oword_t drv_ev_reg;
793
794 EFX_POPULATE_OWORD_2(drv_ev_reg,
795 DRV_EV_QID, channel->evqnum,
796 DRV_EV_DATA,
797 EFX_QWORD_FIELD64(*event, WHOLE_EVENT));
798 falcon_write(channel->efx, &drv_ev_reg, DRV_EV_REG_KER);
799}
800
801/* Handle a transmit completion event
802 *
803 * Falcon batches TX completion events; the message we receive is of
804 * the form "complete all TX events up to this index".
805 */
806static inline void falcon_handle_tx_event(struct efx_channel *channel,
807 efx_qword_t *event)
808{
809 unsigned int tx_ev_desc_ptr;
810 unsigned int tx_ev_q_label;
811 struct efx_tx_queue *tx_queue;
812 struct efx_nic *efx = channel->efx;
813
814 if (likely(EFX_QWORD_FIELD(*event, TX_EV_COMP))) {
815 /* Transmit completion */
816 tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, TX_EV_DESC_PTR);
817 tx_ev_q_label = EFX_QWORD_FIELD(*event, TX_EV_Q_LABEL);
818 tx_queue = &efx->tx_queue[tx_ev_q_label];
819 efx_xmit_done(tx_queue, tx_ev_desc_ptr);
820 } else if (EFX_QWORD_FIELD(*event, TX_EV_WQ_FF_FULL)) {
821 /* Rewrite the FIFO write pointer */
822 tx_ev_q_label = EFX_QWORD_FIELD(*event, TX_EV_Q_LABEL);
823 tx_queue = &efx->tx_queue[tx_ev_q_label];
824
825 if (NET_DEV_REGISTERED(efx))
826 netif_tx_lock(efx->net_dev);
827 falcon_notify_tx_desc(tx_queue);
828 if (NET_DEV_REGISTERED(efx))
829 netif_tx_unlock(efx->net_dev);
830 } else if (EFX_QWORD_FIELD(*event, TX_EV_PKT_ERR) &&
831 EFX_WORKAROUND_10727(efx)) {
832 efx_schedule_reset(efx, RESET_TYPE_TX_DESC_FETCH);
833 } else {
834 EFX_ERR(efx, "channel %d unexpected TX event "
835 EFX_QWORD_FMT"\n", channel->channel,
836 EFX_QWORD_VAL(*event));
837 }
838}
839
840/* Check received packet's destination MAC address. */
841static int check_dest_mac(struct efx_rx_queue *rx_queue,
842 const efx_qword_t *event)
843{
844 struct efx_rx_buffer *rx_buf;
845 struct efx_nic *efx = rx_queue->efx;
846 int rx_ev_desc_ptr;
847 struct ethhdr *eh;
848
849 if (efx->promiscuous)
850 return 1;
851
852 rx_ev_desc_ptr = EFX_QWORD_FIELD(*event, RX_EV_DESC_PTR);
853 rx_buf = efx_rx_buffer(rx_queue, rx_ev_desc_ptr);
854 eh = (struct ethhdr *)rx_buf->data;
855 if (memcmp(eh->h_dest, efx->net_dev->dev_addr, ETH_ALEN))
856 return 0;
857 return 1;
858}
859
860/* Detect errors included in the rx_evt_pkt_ok bit. */
861static void falcon_handle_rx_not_ok(struct efx_rx_queue *rx_queue,
862 const efx_qword_t *event,
863 unsigned *rx_ev_pkt_ok,
864 int *discard, int byte_count)
865{
866 struct efx_nic *efx = rx_queue->efx;
867 unsigned rx_ev_buf_owner_id_err, rx_ev_ip_hdr_chksum_err;
868 unsigned rx_ev_tcp_udp_chksum_err, rx_ev_eth_crc_err;
869 unsigned rx_ev_frm_trunc, rx_ev_drib_nib, rx_ev_tobe_disc;
870 unsigned rx_ev_pkt_type, rx_ev_other_err, rx_ev_pause_frm;
871 unsigned rx_ev_ip_frag_err, rx_ev_hdr_type, rx_ev_mcast_pkt;
872 int snap, non_ip;
873
874 rx_ev_hdr_type = EFX_QWORD_FIELD(*event, RX_EV_HDR_TYPE);
875 rx_ev_mcast_pkt = EFX_QWORD_FIELD(*event, RX_EV_MCAST_PKT);
876 rx_ev_tobe_disc = EFX_QWORD_FIELD(*event, RX_EV_TOBE_DISC);
877 rx_ev_pkt_type = EFX_QWORD_FIELD(*event, RX_EV_PKT_TYPE);
878 rx_ev_buf_owner_id_err = EFX_QWORD_FIELD(*event,
879 RX_EV_BUF_OWNER_ID_ERR);
880 rx_ev_ip_frag_err = EFX_QWORD_FIELD(*event, RX_EV_IF_FRAG_ERR);
881 rx_ev_ip_hdr_chksum_err = EFX_QWORD_FIELD(*event,
882 RX_EV_IP_HDR_CHKSUM_ERR);
883 rx_ev_tcp_udp_chksum_err = EFX_QWORD_FIELD(*event,
884 RX_EV_TCP_UDP_CHKSUM_ERR);
885 rx_ev_eth_crc_err = EFX_QWORD_FIELD(*event, RX_EV_ETH_CRC_ERR);
886 rx_ev_frm_trunc = EFX_QWORD_FIELD(*event, RX_EV_FRM_TRUNC);
887 rx_ev_drib_nib = ((FALCON_REV(efx) >= FALCON_REV_B0) ?
888 0 : EFX_QWORD_FIELD(*event, RX_EV_DRIB_NIB));
889 rx_ev_pause_frm = EFX_QWORD_FIELD(*event, RX_EV_PAUSE_FRM_ERR);
890
891 /* Every error apart from tobe_disc and pause_frm */
892 rx_ev_other_err = (rx_ev_drib_nib | rx_ev_tcp_udp_chksum_err |
893 rx_ev_buf_owner_id_err | rx_ev_eth_crc_err |
894 rx_ev_frm_trunc | rx_ev_ip_hdr_chksum_err);
895
896 snap = (rx_ev_pkt_type == RX_EV_PKT_TYPE_LLC_DECODE) ||
897 (rx_ev_pkt_type == RX_EV_PKT_TYPE_VLAN_LLC_DECODE);
898 non_ip = (rx_ev_hdr_type == RX_EV_HDR_TYPE_NON_IP_DECODE);
899
900 /* SFC bug 5475/8970: The Falcon XMAC incorrectly calculates the
901 * length field of an LLC frame, which sets TOBE_DISC. We could set
902 * PASS_LEN_ERR, but we want the MAC to filter out short frames (to
903 * protect the RX block).
904 *
905 * bug5475 - LLC/SNAP: Falcon identifies SNAP packets.
906 * bug8970 - LLC/noSNAP: Falcon does not provide an LLC flag.
907 * LLC can't encapsulate IP, so by definition
908 * these packets are NON_IP.
909 *
910 * Unicast mismatch will also cause TOBE_DISC, so the driver needs
911 * to check this.
912 */
913 if (EFX_WORKAROUND_5475(efx) && rx_ev_tobe_disc && (snap || non_ip)) {
914 /* If all the other flags are zero then we can state the
915 * entire packet is ok, which will flag to the kernel not
916 * to recalculate checksums.
917 */
918 if (!(non_ip | rx_ev_other_err | rx_ev_pause_frm))
919 *rx_ev_pkt_ok = 1;
920
921 rx_ev_tobe_disc = 0;
922
923 /* TOBE_DISC is set for unicast mismatch. But given that
924 * we can't trust TOBE_DISC here, we must validate the dest
925 * MAC address ourselves.
926 */
927 if (!rx_ev_mcast_pkt && !check_dest_mac(rx_queue, event))
928 rx_ev_tobe_disc = 1;
929 }
930
931 /* Count errors that are not in MAC stats. */
932 if (rx_ev_frm_trunc)
933 ++rx_queue->channel->n_rx_frm_trunc;
934 else if (rx_ev_tobe_disc)
935 ++rx_queue->channel->n_rx_tobe_disc;
936 else if (rx_ev_ip_hdr_chksum_err)
937 ++rx_queue->channel->n_rx_ip_hdr_chksum_err;
938 else if (rx_ev_tcp_udp_chksum_err)
939 ++rx_queue->channel->n_rx_tcp_udp_chksum_err;
940 if (rx_ev_ip_frag_err)
941 ++rx_queue->channel->n_rx_ip_frag_err;
942
943 /* The frame must be discarded if any of these are true. */
944 *discard = (rx_ev_eth_crc_err | rx_ev_frm_trunc | rx_ev_drib_nib |
945 rx_ev_tobe_disc | rx_ev_pause_frm);
946
947 /* TOBE_DISC is expected on unicast mismatches; don't print out an
948 * error message. FRM_TRUNC indicates RXDP dropped the packet due
949 * to a FIFO overflow.
950 */
951#ifdef EFX_ENABLE_DEBUG
952 if (rx_ev_other_err) {
953 EFX_INFO_RL(efx, " RX queue %d unexpected RX event "
954 EFX_QWORD_FMT "%s%s%s%s%s%s%s%s%s\n",
955 rx_queue->queue, EFX_QWORD_VAL(*event),
956 rx_ev_buf_owner_id_err ? " [OWNER_ID_ERR]" : "",
957 rx_ev_ip_hdr_chksum_err ?
958 " [IP_HDR_CHKSUM_ERR]" : "",
959 rx_ev_tcp_udp_chksum_err ?
960 " [TCP_UDP_CHKSUM_ERR]" : "",
961 rx_ev_eth_crc_err ? " [ETH_CRC_ERR]" : "",
962 rx_ev_frm_trunc ? " [FRM_TRUNC]" : "",
963 rx_ev_drib_nib ? " [DRIB_NIB]" : "",
964 rx_ev_tobe_disc ? " [TOBE_DISC]" : "",
965 rx_ev_pause_frm ? " [PAUSE]" : "",
966 snap ? " [SNAP/LLC]" : "");
967 }
968#endif
969
970 if (unlikely(rx_ev_eth_crc_err && EFX_WORKAROUND_10750(efx) &&
971 efx->phy_type == PHY_TYPE_10XPRESS))
972 tenxpress_crc_err(efx);
973}
974
975/* Handle receive events that are not in-order. */
976static void falcon_handle_rx_bad_index(struct efx_rx_queue *rx_queue,
977 unsigned index)
978{
979 struct efx_nic *efx = rx_queue->efx;
980 unsigned expected, dropped;
981
982 expected = rx_queue->removed_count & FALCON_RXD_RING_MASK;
983 dropped = ((index + FALCON_RXD_RING_SIZE - expected) &
984 FALCON_RXD_RING_MASK);
985 EFX_INFO(efx, "dropped %d events (index=%d expected=%d)\n",
986 dropped, index, expected);
987
988 efx_schedule_reset(efx, EFX_WORKAROUND_5676(efx) ?
989 RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE);
990}
991
992/* Handle a packet received event
993 *
994 * Falcon silicon gives a "discard" flag if it's a unicast packet with the
995 * wrong destination address
996 * Also "is multicast" and "matches multicast filter" flags can be used to
997 * discard non-matching multicast packets.
998 */
999static inline int falcon_handle_rx_event(struct efx_channel *channel,
1000 const efx_qword_t *event)
1001{
1002 unsigned int rx_ev_q_label, rx_ev_desc_ptr, rx_ev_byte_cnt;
1003 unsigned int rx_ev_pkt_ok, rx_ev_hdr_type, rx_ev_mcast_pkt;
1004 unsigned expected_ptr;
1005 int discard = 0, checksummed;
1006 struct efx_rx_queue *rx_queue;
1007 struct efx_nic *efx = channel->efx;
1008
1009 /* Basic packet information */
1010 rx_ev_byte_cnt = EFX_QWORD_FIELD(*event, RX_EV_BYTE_CNT);
1011 rx_ev_pkt_ok = EFX_QWORD_FIELD(*event, RX_EV_PKT_OK);
1012 rx_ev_hdr_type = EFX_QWORD_FIELD(*event, RX_EV_HDR_TYPE);
1013 WARN_ON(EFX_QWORD_FIELD(*event, RX_EV_JUMBO_CONT));
1014 WARN_ON(EFX_QWORD_FIELD(*event, RX_EV_SOP) != 1);
1015
1016 rx_ev_q_label = EFX_QWORD_FIELD(*event, RX_EV_Q_LABEL);
1017 rx_queue = &efx->rx_queue[rx_ev_q_label];
1018
1019 rx_ev_desc_ptr = EFX_QWORD_FIELD(*event, RX_EV_DESC_PTR);
1020 expected_ptr = rx_queue->removed_count & FALCON_RXD_RING_MASK;
1021 if (unlikely(rx_ev_desc_ptr != expected_ptr)) {
1022 falcon_handle_rx_bad_index(rx_queue, rx_ev_desc_ptr);
1023 return rx_ev_q_label;
1024 }
1025
1026 if (likely(rx_ev_pkt_ok)) {
1027 /* If packet is marked as OK and packet type is TCP/IPv4 or
1028 * UDP/IPv4, then we can rely on the hardware checksum.
1029 */
1030 checksummed = RX_EV_HDR_TYPE_HAS_CHECKSUMS(rx_ev_hdr_type);
1031 } else {
1032 falcon_handle_rx_not_ok(rx_queue, event, &rx_ev_pkt_ok,
1033 &discard, rx_ev_byte_cnt);
1034 checksummed = 0;
1035 }
1036
1037 /* Detect multicast packets that didn't match the filter */
1038 rx_ev_mcast_pkt = EFX_QWORD_FIELD(*event, RX_EV_MCAST_PKT);
1039 if (rx_ev_mcast_pkt) {
1040 unsigned int rx_ev_mcast_hash_match =
1041 EFX_QWORD_FIELD(*event, RX_EV_MCAST_HASH_MATCH);
1042
1043 if (unlikely(!rx_ev_mcast_hash_match))
1044 discard = 1;
1045 }
1046
1047 /* Handle received packet */
1048 efx_rx_packet(rx_queue, rx_ev_desc_ptr, rx_ev_byte_cnt,
1049 checksummed, discard);
1050
1051 return rx_ev_q_label;
1052}
1053
1054/* Global events are basically PHY events */
1055static void falcon_handle_global_event(struct efx_channel *channel,
1056 efx_qword_t *event)
1057{
1058 struct efx_nic *efx = channel->efx;
1059 int is_phy_event = 0, handled = 0;
1060
1061 /* Check for interrupt on either port. Some boards have a
1062 * single PHY wired to the interrupt line for port 1. */
1063 if (EFX_QWORD_FIELD(*event, G_PHY0_INTR) ||
1064 EFX_QWORD_FIELD(*event, G_PHY1_INTR) ||
1065 EFX_QWORD_FIELD(*event, XG_PHY_INTR))
1066 is_phy_event = 1;
1067
1068 if ((FALCON_REV(efx) >= FALCON_REV_B0) &&
1069 EFX_OWORD_FIELD(*event, XG_MNT_INTR_B0))
1070 is_phy_event = 1;
1071
1072 if (is_phy_event) {
1073 efx->phy_op->clear_interrupt(efx);
1074 queue_work(efx->workqueue, &efx->reconfigure_work);
1075 handled = 1;
1076 }
1077
1078 if (EFX_QWORD_FIELD_VER(efx, *event, RX_RECOVERY)) {
1079 EFX_ERR(efx, "channel %d seen global RX_RESET "
1080 "event. Resetting.\n", channel->channel);
1081
1082 atomic_inc(&efx->rx_reset);
1083 efx_schedule_reset(efx, EFX_WORKAROUND_6555(efx) ?
1084 RESET_TYPE_RX_RECOVERY : RESET_TYPE_DISABLE);
1085 handled = 1;
1086 }
1087
1088 if (!handled)
1089 EFX_ERR(efx, "channel %d unknown global event "
1090 EFX_QWORD_FMT "\n", channel->channel,
1091 EFX_QWORD_VAL(*event));
1092}
1093
1094static void falcon_handle_driver_event(struct efx_channel *channel,
1095 efx_qword_t *event)
1096{
1097 struct efx_nic *efx = channel->efx;
1098 unsigned int ev_sub_code;
1099 unsigned int ev_sub_data;
1100
1101 ev_sub_code = EFX_QWORD_FIELD(*event, DRIVER_EV_SUB_CODE);
1102 ev_sub_data = EFX_QWORD_FIELD(*event, DRIVER_EV_SUB_DATA);
1103
1104 switch (ev_sub_code) {
1105 case TX_DESCQ_FLS_DONE_EV_DECODE:
1106 EFX_TRACE(efx, "channel %d TXQ %d flushed\n",
1107 channel->channel, ev_sub_data);
1108 break;
1109 case RX_DESCQ_FLS_DONE_EV_DECODE:
1110 EFX_TRACE(efx, "channel %d RXQ %d flushed\n",
1111 channel->channel, ev_sub_data);
1112 break;
1113 case EVQ_INIT_DONE_EV_DECODE:
1114 EFX_LOG(efx, "channel %d EVQ %d initialised\n",
1115 channel->channel, ev_sub_data);
1116 break;
1117 case SRM_UPD_DONE_EV_DECODE:
1118 EFX_TRACE(efx, "channel %d SRAM update done\n",
1119 channel->channel);
1120 break;
1121 case WAKE_UP_EV_DECODE:
1122 EFX_TRACE(efx, "channel %d RXQ %d wakeup event\n",
1123 channel->channel, ev_sub_data);
1124 break;
1125 case TIMER_EV_DECODE:
1126 EFX_TRACE(efx, "channel %d RX queue %d timer expired\n",
1127 channel->channel, ev_sub_data);
1128 break;
1129 case RX_RECOVERY_EV_DECODE:
1130 EFX_ERR(efx, "channel %d seen DRIVER RX_RESET event. "
1131 "Resetting.\n", channel->channel);
1132 efx_schedule_reset(efx,
1133 EFX_WORKAROUND_6555(efx) ?
1134 RESET_TYPE_RX_RECOVERY :
1135 RESET_TYPE_DISABLE);
1136 break;
1137 case RX_DSC_ERROR_EV_DECODE:
1138 EFX_ERR(efx, "RX DMA Q %d reports descriptor fetch error."
1139 " RX Q %d is disabled.\n", ev_sub_data, ev_sub_data);
1140 efx_schedule_reset(efx, RESET_TYPE_RX_DESC_FETCH);
1141 break;
1142 case TX_DSC_ERROR_EV_DECODE:
1143 EFX_ERR(efx, "TX DMA Q %d reports descriptor fetch error."
1144 " TX Q %d is disabled.\n", ev_sub_data, ev_sub_data);
1145 efx_schedule_reset(efx, RESET_TYPE_TX_DESC_FETCH);
1146 break;
1147 default:
1148 EFX_TRACE(efx, "channel %d unknown driver event code %d "
1149 "data %04x\n", channel->channel, ev_sub_code,
1150 ev_sub_data);
1151 break;
1152 }
1153}
1154
1155int falcon_process_eventq(struct efx_channel *channel, int *rx_quota)
1156{
1157 unsigned int read_ptr;
1158 efx_qword_t event, *p_event;
1159 int ev_code;
1160 int rxq;
1161 int rxdmaqs = 0;
1162
1163 read_ptr = channel->eventq_read_ptr;
1164
1165 do {
1166 p_event = falcon_event(channel, read_ptr);
1167 event = *p_event;
1168
1169 if (!falcon_event_present(&event))
1170 /* End of events */
1171 break;
1172
1173 EFX_TRACE(channel->efx, "channel %d event is "EFX_QWORD_FMT"\n",
1174 channel->channel, EFX_QWORD_VAL(event));
1175
1176 /* Clear this event by marking it all ones */
1177 EFX_SET_QWORD(*p_event);
1178
1179 ev_code = EFX_QWORD_FIELD(event, EV_CODE);
1180
1181 switch (ev_code) {
1182 case RX_IP_EV_DECODE:
1183 rxq = falcon_handle_rx_event(channel, &event);
1184 rxdmaqs |= (1 << rxq);
1185 (*rx_quota)--;
1186 break;
1187 case TX_IP_EV_DECODE:
1188 falcon_handle_tx_event(channel, &event);
1189 break;
1190 case DRV_GEN_EV_DECODE:
1191 channel->eventq_magic
1192 = EFX_QWORD_FIELD(event, EVQ_MAGIC);
1193 EFX_LOG(channel->efx, "channel %d received generated "
1194 "event "EFX_QWORD_FMT"\n", channel->channel,
1195 EFX_QWORD_VAL(event));
1196 break;
1197 case GLOBAL_EV_DECODE:
1198 falcon_handle_global_event(channel, &event);
1199 break;
1200 case DRIVER_EV_DECODE:
1201 falcon_handle_driver_event(channel, &event);
1202 break;
1203 default:
1204 EFX_ERR(channel->efx, "channel %d unknown event type %d"
1205 " (data " EFX_QWORD_FMT ")\n", channel->channel,
1206 ev_code, EFX_QWORD_VAL(event));
1207 }
1208
1209 /* Increment read pointer */
1210 read_ptr = (read_ptr + 1) & FALCON_EVQ_MASK;
1211
1212 } while (*rx_quota);
1213
1214 channel->eventq_read_ptr = read_ptr;
1215 return rxdmaqs;
1216}
1217
1218void falcon_set_int_moderation(struct efx_channel *channel)
1219{
1220 efx_dword_t timer_cmd;
1221 struct efx_nic *efx = channel->efx;
1222
1223 /* Set timer register */
1224 if (channel->irq_moderation) {
1225 /* Round to resolution supported by hardware. The value we
1226 * program is based at 0. So actual interrupt moderation
1227 * achieved is ((x + 1) * res).
1228 */
1229 unsigned int res = 5;
1230 channel->irq_moderation -= (channel->irq_moderation % res);
1231 if (channel->irq_moderation < res)
1232 channel->irq_moderation = res;
1233 EFX_POPULATE_DWORD_2(timer_cmd,
1234 TIMER_MODE, TIMER_MODE_INT_HLDOFF,
1235 TIMER_VAL,
1236 (channel->irq_moderation / res) - 1);
1237 } else {
1238 EFX_POPULATE_DWORD_2(timer_cmd,
1239 TIMER_MODE, TIMER_MODE_DIS,
1240 TIMER_VAL, 0);
1241 }
1242 falcon_writel_page_locked(efx, &timer_cmd, TIMER_CMD_REG_KER,
1243 channel->evqnum);
1244
1245}
1246
1247/* Allocate buffer table entries for event queue */
1248int falcon_probe_eventq(struct efx_channel *channel)
1249{
1250 struct efx_nic *efx = channel->efx;
1251 unsigned int evq_size;
1252
1253 evq_size = FALCON_EVQ_SIZE * sizeof(efx_qword_t);
1254 return falcon_alloc_special_buffer(efx, &channel->eventq, evq_size);
1255}
1256
1257int falcon_init_eventq(struct efx_channel *channel)
1258{
1259 efx_oword_t evq_ptr;
1260 struct efx_nic *efx = channel->efx;
1261 int rc;
1262
1263 EFX_LOG(efx, "channel %d event queue in special buffers %d-%d\n",
1264 channel->channel, channel->eventq.index,
1265 channel->eventq.index + channel->eventq.entries - 1);
1266
1267 /* Pin event queue buffer */
1268 rc = falcon_init_special_buffer(efx, &channel->eventq);
1269 if (rc)
1270 return rc;
1271
1272 /* Fill event queue with all ones (i.e. empty events) */
1273 memset(channel->eventq.addr, 0xff, channel->eventq.len);
1274
1275 /* Push event queue to card */
1276 EFX_POPULATE_OWORD_3(evq_ptr,
1277 EVQ_EN, 1,
1278 EVQ_SIZE, FALCON_EVQ_ORDER,
1279 EVQ_BUF_BASE_ID, channel->eventq.index);
1280 falcon_write_table(efx, &evq_ptr, efx->type->evq_ptr_tbl_base,
1281 channel->evqnum);
1282
1283 falcon_set_int_moderation(channel);
1284
1285 return 0;
1286}
1287
1288void falcon_fini_eventq(struct efx_channel *channel)
1289{
1290 efx_oword_t eventq_ptr;
1291 struct efx_nic *efx = channel->efx;
1292
1293 /* Remove event queue from card */
1294 EFX_ZERO_OWORD(eventq_ptr);
1295 falcon_write_table(efx, &eventq_ptr, efx->type->evq_ptr_tbl_base,
1296 channel->evqnum);
1297
1298 /* Unpin event queue */
1299 falcon_fini_special_buffer(efx, &channel->eventq);
1300}
1301
1302/* Free buffers backing event queue */
1303void falcon_remove_eventq(struct efx_channel *channel)
1304{
1305 falcon_free_special_buffer(channel->efx, &channel->eventq);
1306}
1307
1308
1309/* Generates a test event on the event queue. A subsequent call to
1310 * process_eventq() should pick up the event and place the value of
1311 * "magic" into channel->eventq_magic;
1312 */
1313void falcon_generate_test_event(struct efx_channel *channel, unsigned int magic)
1314{
1315 efx_qword_t test_event;
1316
1317 EFX_POPULATE_QWORD_2(test_event,
1318 EV_CODE, DRV_GEN_EV_DECODE,
1319 EVQ_MAGIC, magic);
1320 falcon_generate_event(channel, &test_event);
1321}
1322
1323
1324/**************************************************************************
1325 *
1326 * Falcon hardware interrupts
1327 * The hardware interrupt handler does very little work; all the event
1328 * queue processing is carried out by per-channel tasklets.
1329 *
1330 **************************************************************************/
1331
1332/* Enable/disable/generate Falcon interrupts */
1333static inline void falcon_interrupts(struct efx_nic *efx, int enabled,
1334 int force)
1335{
1336 efx_oword_t int_en_reg_ker;
1337
1338 EFX_POPULATE_OWORD_2(int_en_reg_ker,
1339 KER_INT_KER, force,
1340 DRV_INT_EN_KER, enabled);
1341 falcon_write(efx, &int_en_reg_ker, INT_EN_REG_KER);
1342}
1343
1344void falcon_enable_interrupts(struct efx_nic *efx)
1345{
1346 efx_oword_t int_adr_reg_ker;
1347 struct efx_channel *channel;
1348
1349 EFX_ZERO_OWORD(*((efx_oword_t *) efx->irq_status.addr));
1350 wmb(); /* Ensure interrupt vector is clear before interrupts enabled */
1351
1352 /* Program address */
1353 EFX_POPULATE_OWORD_2(int_adr_reg_ker,
1354 NORM_INT_VEC_DIS_KER, EFX_INT_MODE_USE_MSI(efx),
1355 INT_ADR_KER, efx->irq_status.dma_addr);
1356 falcon_write(efx, &int_adr_reg_ker, INT_ADR_REG_KER);
1357
1358 /* Enable interrupts */
1359 falcon_interrupts(efx, 1, 0);
1360
1361 /* Force processing of all the channels to get the EVQ RPTRs up to
1362 date */
1363 efx_for_each_channel_with_interrupt(channel, efx)
1364 efx_schedule_channel(channel);
1365}
1366
1367void falcon_disable_interrupts(struct efx_nic *efx)
1368{
1369 /* Disable interrupts */
1370 falcon_interrupts(efx, 0, 0);
1371}
1372
1373/* Generate a Falcon test interrupt
1374 * Interrupt must already have been enabled, otherwise nasty things
1375 * may happen.
1376 */
1377void falcon_generate_interrupt(struct efx_nic *efx)
1378{
1379 falcon_interrupts(efx, 1, 1);
1380}
1381
1382/* Acknowledge a legacy interrupt from Falcon
1383 *
1384 * This acknowledges a legacy (not MSI) interrupt via INT_ACK_KER_REG.
1385 *
1386 * Due to SFC bug 3706 (silicon revision <=A1) reads can be duplicated in the
1387 * BIU. Interrupt acknowledge is read sensitive so must write instead
1388 * (then read to ensure the BIU collector is flushed)
1389 *
1390 * NB most hardware supports MSI interrupts
1391 */
1392static inline void falcon_irq_ack_a1(struct efx_nic *efx)
1393{
1394 efx_dword_t reg;
1395
1396 EFX_POPULATE_DWORD_1(reg, INT_ACK_DUMMY_DATA, 0xb7eb7e);
1397 falcon_writel(efx, &reg, INT_ACK_REG_KER_A1);
1398 falcon_readl(efx, &reg, WORK_AROUND_BROKEN_PCI_READS_REG_KER_A1);
1399}
1400
1401/* Process a fatal interrupt
1402 * Disable bus mastering ASAP and schedule a reset
1403 */
1404static irqreturn_t falcon_fatal_interrupt(struct efx_nic *efx)
1405{
1406 struct falcon_nic_data *nic_data = efx->nic_data;
1407 efx_oword_t *int_ker = (efx_oword_t *) efx->irq_status.addr;
1408 efx_oword_t fatal_intr;
1409 int error, mem_perr;
1410 static int n_int_errors;
1411
1412 falcon_read(efx, &fatal_intr, FATAL_INTR_REG_KER);
1413 error = EFX_OWORD_FIELD(fatal_intr, INT_KER_ERROR);
1414
1415 EFX_ERR(efx, "SYSTEM ERROR " EFX_OWORD_FMT " status "
1416 EFX_OWORD_FMT ": %s\n", EFX_OWORD_VAL(*int_ker),
1417 EFX_OWORD_VAL(fatal_intr),
1418 error ? "disabling bus mastering" : "no recognised error");
1419 if (error == 0)
1420 goto out;
1421
1422 /* If this is a memory parity error dump which blocks are offending */
1423 mem_perr = EFX_OWORD_FIELD(fatal_intr, MEM_PERR_INT_KER);
1424 if (mem_perr) {
1425 efx_oword_t reg;
1426 falcon_read(efx, &reg, MEM_STAT_REG_KER);
1427 EFX_ERR(efx, "SYSTEM ERROR: memory parity error "
1428 EFX_OWORD_FMT "\n", EFX_OWORD_VAL(reg));
1429 }
1430
1431 /* Disable DMA bus mastering on both devices */
1432 pci_disable_device(efx->pci_dev);
1433 if (FALCON_IS_DUAL_FUNC(efx))
1434 pci_disable_device(nic_data->pci_dev2);
1435
1436 if (++n_int_errors < FALCON_MAX_INT_ERRORS) {
1437 EFX_ERR(efx, "SYSTEM ERROR - reset scheduled\n");
1438 efx_schedule_reset(efx, RESET_TYPE_INT_ERROR);
1439 } else {
1440 EFX_ERR(efx, "SYSTEM ERROR - max number of errors seen."
1441 "NIC will be disabled\n");
1442 efx_schedule_reset(efx, RESET_TYPE_DISABLE);
1443 }
1444out:
1445 return IRQ_HANDLED;
1446}
1447
1448/* Handle a legacy interrupt from Falcon
1449 * Acknowledges the interrupt and schedule event queue processing.
1450 */
1451static irqreturn_t falcon_legacy_interrupt_b0(int irq, void *dev_id)
1452{
1453 struct efx_nic *efx = (struct efx_nic *)dev_id;
1454 efx_oword_t *int_ker = (efx_oword_t *) efx->irq_status.addr;
1455 struct efx_channel *channel;
1456 efx_dword_t reg;
1457 u32 queues;
1458 int syserr;
1459
1460 /* Read the ISR which also ACKs the interrupts */
1461 falcon_readl(efx, &reg, INT_ISR0_B0);
1462 queues = EFX_EXTRACT_DWORD(reg, 0, 31);
1463
1464 /* Check to see if we have a serious error condition */
1465 syserr = EFX_OWORD_FIELD(*int_ker, FATAL_INT);
1466 if (unlikely(syserr))
1467 return falcon_fatal_interrupt(efx);
1468
1469 if (queues == 0)
1470 return IRQ_NONE;
1471
1472 efx->last_irq_cpu = raw_smp_processor_id();
1473 EFX_TRACE(efx, "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n",
1474 irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg));
1475
1476 /* Schedule processing of any interrupting queues */
1477 channel = &efx->channel[0];
1478 while (queues) {
1479 if (queues & 0x01)
1480 efx_schedule_channel(channel);
1481 channel++;
1482 queues >>= 1;
1483 }
1484
1485 return IRQ_HANDLED;
1486}
1487
1488
1489static irqreturn_t falcon_legacy_interrupt_a1(int irq, void *dev_id)
1490{
1491 struct efx_nic *efx = (struct efx_nic *)dev_id;
1492 efx_oword_t *int_ker = (efx_oword_t *) efx->irq_status.addr;
1493 struct efx_channel *channel;
1494 int syserr;
1495 int queues;
1496
1497 /* Check to see if this is our interrupt. If it isn't, we
1498 * exit without having touched the hardware.
1499 */
1500 if (unlikely(EFX_OWORD_IS_ZERO(*int_ker))) {
1501 EFX_TRACE(efx, "IRQ %d on CPU %d not for me\n", irq,
1502 raw_smp_processor_id());
1503 return IRQ_NONE;
1504 }
1505 efx->last_irq_cpu = raw_smp_processor_id();
1506 EFX_TRACE(efx, "IRQ %d on CPU %d status " EFX_OWORD_FMT "\n",
1507 irq, raw_smp_processor_id(), EFX_OWORD_VAL(*int_ker));
1508
1509 /* Check to see if we have a serious error condition */
1510 syserr = EFX_OWORD_FIELD(*int_ker, FATAL_INT);
1511 if (unlikely(syserr))
1512 return falcon_fatal_interrupt(efx);
1513
1514 /* Determine interrupting queues, clear interrupt status
1515 * register and acknowledge the device interrupt.
1516 */
1517 BUILD_BUG_ON(INT_EVQS_WIDTH > EFX_MAX_CHANNELS);
1518 queues = EFX_OWORD_FIELD(*int_ker, INT_EVQS);
1519 EFX_ZERO_OWORD(*int_ker);
1520 wmb(); /* Ensure the vector is cleared before interrupt ack */
1521 falcon_irq_ack_a1(efx);
1522
1523 /* Schedule processing of any interrupting queues */
1524 channel = &efx->channel[0];
1525 while (queues) {
1526 if (queues & 0x01)
1527 efx_schedule_channel(channel);
1528 channel++;
1529 queues >>= 1;
1530 }
1531
1532 return IRQ_HANDLED;
1533}
1534
1535/* Handle an MSI interrupt from Falcon
1536 *
1537 * Handle an MSI hardware interrupt. This routine schedules event
1538 * queue processing. No interrupt acknowledgement cycle is necessary.
1539 * Also, we never need to check that the interrupt is for us, since
1540 * MSI interrupts cannot be shared.
1541 */
1542static irqreturn_t falcon_msi_interrupt(int irq, void *dev_id)
1543{
1544 struct efx_channel *channel = (struct efx_channel *)dev_id;
1545 struct efx_nic *efx = channel->efx;
1546 efx_oword_t *int_ker = (efx_oword_t *) efx->irq_status.addr;
1547 int syserr;
1548
1549 efx->last_irq_cpu = raw_smp_processor_id();
1550 EFX_TRACE(efx, "IRQ %d on CPU %d status " EFX_OWORD_FMT "\n",
1551 irq, raw_smp_processor_id(), EFX_OWORD_VAL(*int_ker));
1552
1553 /* Check to see if we have a serious error condition */
1554 syserr = EFX_OWORD_FIELD(*int_ker, FATAL_INT);
1555 if (unlikely(syserr))
1556 return falcon_fatal_interrupt(efx);
1557
1558 /* Schedule processing of the channel */
1559 efx_schedule_channel(channel);
1560
1561 return IRQ_HANDLED;
1562}
1563
1564
1565/* Setup RSS indirection table.
1566 * This maps from the hash value of the packet to RXQ
1567 */
1568static void falcon_setup_rss_indir_table(struct efx_nic *efx)
1569{
1570 int i = 0;
1571 unsigned long offset;
1572 efx_dword_t dword;
1573
1574 if (FALCON_REV(efx) < FALCON_REV_B0)
1575 return;
1576
1577 for (offset = RX_RSS_INDIR_TBL_B0;
1578 offset < RX_RSS_INDIR_TBL_B0 + 0x800;
1579 offset += 0x10) {
1580 EFX_POPULATE_DWORD_1(dword, RX_RSS_INDIR_ENT_B0,
1581 i % efx->rss_queues);
1582 falcon_writel(efx, &dword, offset);
1583 i++;
1584 }
1585}
1586
1587/* Hook interrupt handler(s)
1588 * Try MSI and then legacy interrupts.
1589 */
1590int falcon_init_interrupt(struct efx_nic *efx)
1591{
1592 struct efx_channel *channel;
1593 int rc;
1594
1595 if (!EFX_INT_MODE_USE_MSI(efx)) {
1596 irq_handler_t handler;
1597 if (FALCON_REV(efx) >= FALCON_REV_B0)
1598 handler = falcon_legacy_interrupt_b0;
1599 else
1600 handler = falcon_legacy_interrupt_a1;
1601
1602 rc = request_irq(efx->legacy_irq, handler, IRQF_SHARED,
1603 efx->name, efx);
1604 if (rc) {
1605 EFX_ERR(efx, "failed to hook legacy IRQ %d\n",
1606 efx->pci_dev->irq);
1607 goto fail1;
1608 }
1609 return 0;
1610 }
1611
1612 /* Hook MSI or MSI-X interrupt */
1613 efx_for_each_channel_with_interrupt(channel, efx) {
1614 rc = request_irq(channel->irq, falcon_msi_interrupt,
1615 IRQF_PROBE_SHARED, /* Not shared */
1616 efx->name, channel);
1617 if (rc) {
1618 EFX_ERR(efx, "failed to hook IRQ %d\n", channel->irq);
1619 goto fail2;
1620 }
1621 }
1622
1623 return 0;
1624
1625 fail2:
1626 efx_for_each_channel_with_interrupt(channel, efx)
1627 free_irq(channel->irq, channel);
1628 fail1:
1629 return rc;
1630}
1631
1632void falcon_fini_interrupt(struct efx_nic *efx)
1633{
1634 struct efx_channel *channel;
1635 efx_oword_t reg;
1636
1637 /* Disable MSI/MSI-X interrupts */
1638 efx_for_each_channel_with_interrupt(channel, efx)
1639 if (channel->irq)
1640 free_irq(channel->irq, channel);
1641
1642 /* ACK legacy interrupt */
1643 if (FALCON_REV(efx) >= FALCON_REV_B0)
1644 falcon_read(efx, &reg, INT_ISR0_B0);
1645 else
1646 falcon_irq_ack_a1(efx);
1647
1648 /* Disable legacy interrupt */
1649 if (efx->legacy_irq)
1650 free_irq(efx->legacy_irq, efx);
1651}
1652
1653/**************************************************************************
1654 *
1655 * EEPROM/flash
1656 *
1657 **************************************************************************
1658 */
1659
1660#define FALCON_SPI_MAX_LEN sizeof(efx_oword_t)
1661
1662/* Wait for SPI command completion */
1663static int falcon_spi_wait(struct efx_nic *efx)
1664{
1665 efx_oword_t reg;
1666 int cmd_en, timer_active;
1667 int count;
1668
1669 count = 0;
1670 do {
1671 falcon_read(efx, &reg, EE_SPI_HCMD_REG_KER);
1672 cmd_en = EFX_OWORD_FIELD(reg, EE_SPI_HCMD_CMD_EN);
1673 timer_active = EFX_OWORD_FIELD(reg, EE_WR_TIMER_ACTIVE);
1674 if (!cmd_en && !timer_active)
1675 return 0;
1676 udelay(10);
1677 } while (++count < 10000); /* wait upto 100msec */
1678 EFX_ERR(efx, "timed out waiting for SPI\n");
1679 return -ETIMEDOUT;
1680}
1681
1682static int
1683falcon_spi_read(struct efx_nic *efx, int device_id, unsigned int command,
1684 unsigned int address, unsigned int addr_len,
1685 void *data, unsigned int len)
1686{
1687 efx_oword_t reg;
1688 int rc;
1689
1690 BUG_ON(len > FALCON_SPI_MAX_LEN);
1691
1692 /* Check SPI not currently being accessed */
1693 rc = falcon_spi_wait(efx);
1694 if (rc)
1695 return rc;
1696
1697 /* Program address register */
1698 EFX_POPULATE_OWORD_1(reg, EE_SPI_HADR_ADR, address);
1699 falcon_write(efx, &reg, EE_SPI_HADR_REG_KER);
1700
1701 /* Issue read command */
1702 EFX_POPULATE_OWORD_7(reg,
1703 EE_SPI_HCMD_CMD_EN, 1,
1704 EE_SPI_HCMD_SF_SEL, device_id,
1705 EE_SPI_HCMD_DABCNT, len,
1706 EE_SPI_HCMD_READ, EE_SPI_READ,
1707 EE_SPI_HCMD_DUBCNT, 0,
1708 EE_SPI_HCMD_ADBCNT, addr_len,
1709 EE_SPI_HCMD_ENC, command);
1710 falcon_write(efx, &reg, EE_SPI_HCMD_REG_KER);
1711
1712 /* Wait for read to complete */
1713 rc = falcon_spi_wait(efx);
1714 if (rc)
1715 return rc;
1716
1717 /* Read data */
1718 falcon_read(efx, &reg, EE_SPI_HDATA_REG_KER);
1719 memcpy(data, &reg, len);
1720 return 0;
1721}
1722
1723/**************************************************************************
1724 *
1725 * MAC wrapper
1726 *
1727 **************************************************************************
1728 */
1729void falcon_drain_tx_fifo(struct efx_nic *efx)
1730{
1731 efx_oword_t temp;
1732 int count;
1733
1734 if (FALCON_REV(efx) < FALCON_REV_B0)
1735 return;
1736
1737 falcon_read(efx, &temp, MAC0_CTRL_REG_KER);
1738 /* There is no point in draining more than once */
1739 if (EFX_OWORD_FIELD(temp, TXFIFO_DRAIN_EN_B0))
1740 return;
1741
1742 /* MAC stats will fail whilst the TX fifo is draining. Serialise
1743 * the drain sequence with the statistics fetch */
1744 spin_lock(&efx->stats_lock);
1745
1746 EFX_SET_OWORD_FIELD(temp, TXFIFO_DRAIN_EN_B0, 1);
1747 falcon_write(efx, &temp, MAC0_CTRL_REG_KER);
1748
1749 /* Reset the MAC and EM block. */
1750 falcon_read(efx, &temp, GLB_CTL_REG_KER);
1751 EFX_SET_OWORD_FIELD(temp, RST_XGTX, 1);
1752 EFX_SET_OWORD_FIELD(temp, RST_XGRX, 1);
1753 EFX_SET_OWORD_FIELD(temp, RST_EM, 1);
1754 falcon_write(efx, &temp, GLB_CTL_REG_KER);
1755
1756 count = 0;
1757 while (1) {
1758 falcon_read(efx, &temp, GLB_CTL_REG_KER);
1759 if (!EFX_OWORD_FIELD(temp, RST_XGTX) &&
1760 !EFX_OWORD_FIELD(temp, RST_XGRX) &&
1761 !EFX_OWORD_FIELD(temp, RST_EM)) {
1762 EFX_LOG(efx, "Completed MAC reset after %d loops\n",
1763 count);
1764 break;
1765 }
1766 if (count > 20) {
1767 EFX_ERR(efx, "MAC reset failed\n");
1768 break;
1769 }
1770 count++;
1771 udelay(10);
1772 }
1773
1774 spin_unlock(&efx->stats_lock);
1775
1776 /* If we've reset the EM block and the link is up, then
1777 * we'll have to kick the XAUI link so the PHY can recover */
1778 if (efx->link_up && EFX_WORKAROUND_5147(efx))
1779 falcon_reset_xaui(efx);
1780}
1781
1782void falcon_deconfigure_mac_wrapper(struct efx_nic *efx)
1783{
1784 efx_oword_t temp;
1785
1786 if (FALCON_REV(efx) < FALCON_REV_B0)
1787 return;
1788
1789 /* Isolate the MAC -> RX */
1790 falcon_read(efx, &temp, RX_CFG_REG_KER);
1791 EFX_SET_OWORD_FIELD(temp, RX_INGR_EN_B0, 0);
1792 falcon_write(efx, &temp, RX_CFG_REG_KER);
1793
1794 if (!efx->link_up)
1795 falcon_drain_tx_fifo(efx);
1796}
1797
1798void falcon_reconfigure_mac_wrapper(struct efx_nic *efx)
1799{
1800 efx_oword_t reg;
1801 int link_speed;
1802 unsigned int tx_fc;
1803
1804 if (efx->link_options & GM_LPA_10000)
1805 link_speed = 0x3;
1806 else if (efx->link_options & GM_LPA_1000)
1807 link_speed = 0x2;
1808 else if (efx->link_options & GM_LPA_100)
1809 link_speed = 0x1;
1810 else
1811 link_speed = 0x0;
1812 /* MAC_LINK_STATUS controls MAC backpressure but doesn't work
1813 * as advertised. Disable to ensure packets are not
1814 * indefinitely held and TX queue can be flushed at any point
1815 * while the link is down. */
1816 EFX_POPULATE_OWORD_5(reg,
1817 MAC_XOFF_VAL, 0xffff /* max pause time */,
1818 MAC_BCAD_ACPT, 1,
1819 MAC_UC_PROM, efx->promiscuous,
1820 MAC_LINK_STATUS, 1, /* always set */
1821 MAC_SPEED, link_speed);
1822 /* On B0, MAC backpressure can be disabled and packets get
1823 * discarded. */
1824 if (FALCON_REV(efx) >= FALCON_REV_B0) {
1825 EFX_SET_OWORD_FIELD(reg, TXFIFO_DRAIN_EN_B0,
1826 !efx->link_up);
1827 }
1828
1829 falcon_write(efx, &reg, MAC0_CTRL_REG_KER);
1830
1831 /* Restore the multicast hash registers. */
1832 falcon_set_multicast_hash(efx);
1833
1834 /* Transmission of pause frames when RX crosses the threshold is
1835 * covered by RX_XOFF_MAC_EN and XM_TX_CFG_REG:XM_FCNTL.
1836 * Action on receipt of pause frames is controller by XM_DIS_FCNTL */
1837 tx_fc = (efx->flow_control & EFX_FC_TX) ? 1 : 0;
1838 falcon_read(efx, &reg, RX_CFG_REG_KER);
1839 EFX_SET_OWORD_FIELD_VER(efx, reg, RX_XOFF_MAC_EN, tx_fc);
1840
1841 /* Unisolate the MAC -> RX */
1842 if (FALCON_REV(efx) >= FALCON_REV_B0)
1843 EFX_SET_OWORD_FIELD(reg, RX_INGR_EN_B0, 1);
1844 falcon_write(efx, &reg, RX_CFG_REG_KER);
1845}
1846
1847int falcon_dma_stats(struct efx_nic *efx, unsigned int done_offset)
1848{
1849 efx_oword_t reg;
1850 u32 *dma_done;
1851 int i;
1852
1853 if (disable_dma_stats)
1854 return 0;
1855
1856 /* Statistics fetch will fail if the MAC is in TX drain */
1857 if (FALCON_REV(efx) >= FALCON_REV_B0) {
1858 efx_oword_t temp;
1859 falcon_read(efx, &temp, MAC0_CTRL_REG_KER);
1860 if (EFX_OWORD_FIELD(temp, TXFIFO_DRAIN_EN_B0))
1861 return 0;
1862 }
1863
1864 dma_done = (efx->stats_buffer.addr + done_offset);
1865 *dma_done = FALCON_STATS_NOT_DONE;
1866 wmb(); /* ensure done flag is clear */
1867
1868 /* Initiate DMA transfer of stats */
1869 EFX_POPULATE_OWORD_2(reg,
1870 MAC_STAT_DMA_CMD, 1,
1871 MAC_STAT_DMA_ADR,
1872 efx->stats_buffer.dma_addr);
1873 falcon_write(efx, &reg, MAC0_STAT_DMA_REG_KER);
1874
1875 /* Wait for transfer to complete */
1876 for (i = 0; i < 400; i++) {
1877 if (*(volatile u32 *)dma_done == FALCON_STATS_DONE)
1878 return 0;
1879 udelay(10);
1880 }
1881
1882 EFX_ERR(efx, "timed out waiting for statistics\n");
1883 return -ETIMEDOUT;
1884}
1885
1886/**************************************************************************
1887 *
1888 * PHY access via GMII
1889 *
1890 **************************************************************************
1891 */
1892
1893/* Use the top bit of the MII PHY id to indicate the PHY type
1894 * (1G/10G), with the remaining bits as the actual PHY id.
1895 *
1896 * This allows us to avoid leaking information from the mii_if_info
1897 * structure into other data structures.
1898 */
1899#define FALCON_PHY_ID_ID_WIDTH EFX_WIDTH(MD_PRT_DEV_ADR)
1900#define FALCON_PHY_ID_ID_MASK ((1 << FALCON_PHY_ID_ID_WIDTH) - 1)
1901#define FALCON_PHY_ID_WIDTH (FALCON_PHY_ID_ID_WIDTH + 1)
1902#define FALCON_PHY_ID_MASK ((1 << FALCON_PHY_ID_WIDTH) - 1)
1903#define FALCON_PHY_ID_10G (1 << (FALCON_PHY_ID_WIDTH - 1))
1904
1905
1906/* Packing the clause 45 port and device fields into a single value */
1907#define MD_PRT_ADR_COMP_LBN (MD_PRT_ADR_LBN - MD_DEV_ADR_LBN)
1908#define MD_PRT_ADR_COMP_WIDTH MD_PRT_ADR_WIDTH
1909#define MD_DEV_ADR_COMP_LBN 0
1910#define MD_DEV_ADR_COMP_WIDTH MD_DEV_ADR_WIDTH
1911
1912
1913/* Wait for GMII access to complete */
1914static int falcon_gmii_wait(struct efx_nic *efx)
1915{
1916 efx_dword_t md_stat;
1917 int count;
1918
1919 for (count = 0; count < 1000; count++) { /* wait upto 10ms */
1920 falcon_readl(efx, &md_stat, MD_STAT_REG_KER);
1921 if (EFX_DWORD_FIELD(md_stat, MD_BSY) == 0) {
1922 if (EFX_DWORD_FIELD(md_stat, MD_LNFL) != 0 ||
1923 EFX_DWORD_FIELD(md_stat, MD_BSERR) != 0) {
1924 EFX_ERR(efx, "error from GMII access "
1925 EFX_DWORD_FMT"\n",
1926 EFX_DWORD_VAL(md_stat));
1927 return -EIO;
1928 }
1929 return 0;
1930 }
1931 udelay(10);
1932 }
1933 EFX_ERR(efx, "timed out waiting for GMII\n");
1934 return -ETIMEDOUT;
1935}
1936
1937/* Writes a GMII register of a PHY connected to Falcon using MDIO. */
1938static void falcon_mdio_write(struct net_device *net_dev, int phy_id,
1939 int addr, int value)
1940{
1941 struct efx_nic *efx = (struct efx_nic *)net_dev->priv;
1942 unsigned int phy_id2 = phy_id & FALCON_PHY_ID_ID_MASK;
1943 efx_oword_t reg;
1944
1945 /* The 'generic' prt/dev packing in mdio_10g.h is conveniently
1946 * chosen so that the only current user, Falcon, can take the
1947 * packed value and use them directly.
1948 * Fail to build if this assumption is broken.
1949 */
1950 BUILD_BUG_ON(FALCON_PHY_ID_10G != MDIO45_XPRT_ID_IS10G);
1951 BUILD_BUG_ON(FALCON_PHY_ID_ID_WIDTH != MDIO45_PRT_DEV_WIDTH);
1952 BUILD_BUG_ON(MD_PRT_ADR_COMP_LBN != MDIO45_PRT_ID_COMP_LBN);
1953 BUILD_BUG_ON(MD_DEV_ADR_COMP_LBN != MDIO45_DEV_ID_COMP_LBN);
1954
1955 if (phy_id2 == PHY_ADDR_INVALID)
1956 return;
1957
1958 /* See falcon_mdio_read for an explanation. */
1959 if (!(phy_id & FALCON_PHY_ID_10G)) {
1960 int mmd = ffs(efx->phy_op->mmds) - 1;
1961 EFX_TRACE(efx, "Fixing erroneous clause22 write\n");
1962 phy_id2 = mdio_clause45_pack(phy_id2, mmd)
1963 & FALCON_PHY_ID_ID_MASK;
1964 }
1965
1966 EFX_REGDUMP(efx, "writing GMII %d register %02x with %04x\n", phy_id,
1967 addr, value);
1968
1969 spin_lock_bh(&efx->phy_lock);
1970
1971 /* Check MII not currently being accessed */
1972 if (falcon_gmii_wait(efx) != 0)
1973 goto out;
1974
1975 /* Write the address/ID register */
1976 EFX_POPULATE_OWORD_1(reg, MD_PHY_ADR, addr);
1977 falcon_write(efx, &reg, MD_PHY_ADR_REG_KER);
1978
1979 EFX_POPULATE_OWORD_1(reg, MD_PRT_DEV_ADR, phy_id2);
1980 falcon_write(efx, &reg, MD_ID_REG_KER);
1981
1982 /* Write data */
1983 EFX_POPULATE_OWORD_1(reg, MD_TXD, value);
1984 falcon_write(efx, &reg, MD_TXD_REG_KER);
1985
1986 EFX_POPULATE_OWORD_2(reg,
1987 MD_WRC, 1,
1988 MD_GC, 0);
1989 falcon_write(efx, &reg, MD_CS_REG_KER);
1990
1991 /* Wait for data to be written */
1992 if (falcon_gmii_wait(efx) != 0) {
1993 /* Abort the write operation */
1994 EFX_POPULATE_OWORD_2(reg,
1995 MD_WRC, 0,
1996 MD_GC, 1);
1997 falcon_write(efx, &reg, MD_CS_REG_KER);
1998 udelay(10);
1999 }
2000
2001 out:
2002 spin_unlock_bh(&efx->phy_lock);
2003}
2004
2005/* Reads a GMII register from a PHY connected to Falcon. If no value
2006 * could be read, -1 will be returned. */
2007static int falcon_mdio_read(struct net_device *net_dev, int phy_id, int addr)
2008{
2009 struct efx_nic *efx = (struct efx_nic *)net_dev->priv;
2010 unsigned int phy_addr = phy_id & FALCON_PHY_ID_ID_MASK;
2011 efx_oword_t reg;
2012 int value = -1;
2013
2014 if (phy_addr == PHY_ADDR_INVALID)
2015 return -1;
2016
2017 /* Our PHY code knows whether it needs to talk clause 22(1G) or 45(10G)
2018 * but the generic Linux code does not make any distinction or have
2019 * any state for this.
2020 * We spot the case where someone tried to talk 22 to a 45 PHY and
2021 * redirect the request to the lowest numbered MMD as a clause45
2022 * request. This is enough to allow simple queries like id and link
2023 * state to succeed. TODO: We may need to do more in future.
2024 */
2025 if (!(phy_id & FALCON_PHY_ID_10G)) {
2026 int mmd = ffs(efx->phy_op->mmds) - 1;
2027 EFX_TRACE(efx, "Fixing erroneous clause22 read\n");
2028 phy_addr = mdio_clause45_pack(phy_addr, mmd)
2029 & FALCON_PHY_ID_ID_MASK;
2030 }
2031
2032 spin_lock_bh(&efx->phy_lock);
2033
2034 /* Check MII not currently being accessed */
2035 if (falcon_gmii_wait(efx) != 0)
2036 goto out;
2037
2038 EFX_POPULATE_OWORD_1(reg, MD_PHY_ADR, addr);
2039 falcon_write(efx, &reg, MD_PHY_ADR_REG_KER);
2040
2041 EFX_POPULATE_OWORD_1(reg, MD_PRT_DEV_ADR, phy_addr);
2042 falcon_write(efx, &reg, MD_ID_REG_KER);
2043
2044 /* Request data to be read */
2045 EFX_POPULATE_OWORD_2(reg, MD_RDC, 1, MD_GC, 0);
2046 falcon_write(efx, &reg, MD_CS_REG_KER);
2047
2048 /* Wait for data to become available */
2049 value = falcon_gmii_wait(efx);
2050 if (value == 0) {
2051 falcon_read(efx, &reg, MD_RXD_REG_KER);
2052 value = EFX_OWORD_FIELD(reg, MD_RXD);
2053 EFX_REGDUMP(efx, "read from GMII %d register %02x, got %04x\n",
2054 phy_id, addr, value);
2055 } else {
2056 /* Abort the read operation */
2057 EFX_POPULATE_OWORD_2(reg,
2058 MD_RIC, 0,
2059 MD_GC, 1);
2060 falcon_write(efx, &reg, MD_CS_REG_KER);
2061
2062 EFX_LOG(efx, "read from GMII 0x%x register %02x, got "
2063 "error %d\n", phy_id, addr, value);
2064 }
2065
2066 out:
2067 spin_unlock_bh(&efx->phy_lock);
2068
2069 return value;
2070}
2071
2072static void falcon_init_mdio(struct mii_if_info *gmii)
2073{
2074 gmii->mdio_read = falcon_mdio_read;
2075 gmii->mdio_write = falcon_mdio_write;
2076 gmii->phy_id_mask = FALCON_PHY_ID_MASK;
2077 gmii->reg_num_mask = ((1 << EFX_WIDTH(MD_PHY_ADR)) - 1);
2078}
2079
2080static int falcon_probe_phy(struct efx_nic *efx)
2081{
2082 switch (efx->phy_type) {
2083 case PHY_TYPE_10XPRESS:
2084 efx->phy_op = &falcon_tenxpress_phy_ops;
2085 break;
2086 case PHY_TYPE_XFP:
2087 efx->phy_op = &falcon_xfp_phy_ops;
2088 break;
2089 default:
2090 EFX_ERR(efx, "Unknown PHY type %d\n",
2091 efx->phy_type);
2092 return -1;
2093 }
2094 return 0;
2095}
2096
2097/* This call is responsible for hooking in the MAC and PHY operations */
2098int falcon_probe_port(struct efx_nic *efx)
2099{
2100 int rc;
2101
2102 /* Hook in PHY operations table */
2103 rc = falcon_probe_phy(efx);
2104 if (rc)
2105 return rc;
2106
2107 /* Set up GMII structure for PHY */
2108 efx->mii.supports_gmii = 1;
2109 falcon_init_mdio(&efx->mii);
2110
2111 /* Hardware flow ctrl. FalconA RX FIFO too small for pause generation */
2112 if (FALCON_REV(efx) >= FALCON_REV_B0)
2113 efx->flow_control = EFX_FC_RX | EFX_FC_TX;
2114 else
2115 efx->flow_control = EFX_FC_RX;
2116
2117 /* Allocate buffer for stats */
2118 rc = falcon_alloc_buffer(efx, &efx->stats_buffer,
2119 FALCON_MAC_STATS_SIZE);
2120 if (rc)
2121 return rc;
2122 EFX_LOG(efx, "stats buffer at %llx (virt %p phys %lx)\n",
2123 (unsigned long long)efx->stats_buffer.dma_addr,
2124 efx->stats_buffer.addr,
2125 virt_to_phys(efx->stats_buffer.addr));
2126
2127 return 0;
2128}
2129
2130void falcon_remove_port(struct efx_nic *efx)
2131{
2132 falcon_free_buffer(efx, &efx->stats_buffer);
2133}
2134
2135/**************************************************************************
2136 *
2137 * Multicast filtering
2138 *
2139 **************************************************************************
2140 */
2141
2142void falcon_set_multicast_hash(struct efx_nic *efx)
2143{
2144 union efx_multicast_hash *mc_hash = &efx->multicast_hash;
2145
2146 /* Broadcast packets go through the multicast hash filter.
2147 * ether_crc_le() of the broadcast address is 0xbe2612ff
2148 * so we always add bit 0xff to the mask.
2149 */
2150 set_bit_le(0xff, mc_hash->byte);
2151
2152 falcon_write(efx, &mc_hash->oword[0], MAC_MCAST_HASH_REG0_KER);
2153 falcon_write(efx, &mc_hash->oword[1], MAC_MCAST_HASH_REG1_KER);
2154}
2155
2156/**************************************************************************
2157 *
2158 * Device reset
2159 *
2160 **************************************************************************
2161 */
2162
2163/* Resets NIC to known state. This routine must be called in process
2164 * context and is allowed to sleep. */
2165int falcon_reset_hw(struct efx_nic *efx, enum reset_type method)
2166{
2167 struct falcon_nic_data *nic_data = efx->nic_data;
2168 efx_oword_t glb_ctl_reg_ker;
2169 int rc;
2170
2171 EFX_LOG(efx, "performing hardware reset (%d)\n", method);
2172
2173 /* Initiate device reset */
2174 if (method == RESET_TYPE_WORLD) {
2175 rc = pci_save_state(efx->pci_dev);
2176 if (rc) {
2177 EFX_ERR(efx, "failed to backup PCI state of primary "
2178 "function prior to hardware reset\n");
2179 goto fail1;
2180 }
2181 if (FALCON_IS_DUAL_FUNC(efx)) {
2182 rc = pci_save_state(nic_data->pci_dev2);
2183 if (rc) {
2184 EFX_ERR(efx, "failed to backup PCI state of "
2185 "secondary function prior to "
2186 "hardware reset\n");
2187 goto fail2;
2188 }
2189 }
2190
2191 EFX_POPULATE_OWORD_2(glb_ctl_reg_ker,
2192 EXT_PHY_RST_DUR, 0x7,
2193 SWRST, 1);
2194 } else {
2195 int reset_phy = (method == RESET_TYPE_INVISIBLE ?
2196 EXCLUDE_FROM_RESET : 0);
2197
2198 EFX_POPULATE_OWORD_7(glb_ctl_reg_ker,
2199 EXT_PHY_RST_CTL, reset_phy,
2200 PCIE_CORE_RST_CTL, EXCLUDE_FROM_RESET,
2201 PCIE_NSTCK_RST_CTL, EXCLUDE_FROM_RESET,
2202 PCIE_SD_RST_CTL, EXCLUDE_FROM_RESET,
2203 EE_RST_CTL, EXCLUDE_FROM_RESET,
2204 EXT_PHY_RST_DUR, 0x7 /* 10ms */,
2205 SWRST, 1);
2206 }
2207 falcon_write(efx, &glb_ctl_reg_ker, GLB_CTL_REG_KER);
2208
2209 EFX_LOG(efx, "waiting for hardware reset\n");
2210 schedule_timeout_uninterruptible(HZ / 20);
2211
2212 /* Restore PCI configuration if needed */
2213 if (method == RESET_TYPE_WORLD) {
2214 if (FALCON_IS_DUAL_FUNC(efx)) {
2215 rc = pci_restore_state(nic_data->pci_dev2);
2216 if (rc) {
2217 EFX_ERR(efx, "failed to restore PCI config for "
2218 "the secondary function\n");
2219 goto fail3;
2220 }
2221 }
2222 rc = pci_restore_state(efx->pci_dev);
2223 if (rc) {
2224 EFX_ERR(efx, "failed to restore PCI config for the "
2225 "primary function\n");
2226 goto fail4;
2227 }
2228 EFX_LOG(efx, "successfully restored PCI config\n");
2229 }
2230
2231 /* Assert that reset complete */
2232 falcon_read(efx, &glb_ctl_reg_ker, GLB_CTL_REG_KER);
2233 if (EFX_OWORD_FIELD(glb_ctl_reg_ker, SWRST) != 0) {
2234 rc = -ETIMEDOUT;
2235 EFX_ERR(efx, "timed out waiting for hardware reset\n");
2236 goto fail5;
2237 }
2238 EFX_LOG(efx, "hardware reset complete\n");
2239
2240 return 0;
2241
2242 /* pci_save_state() and pci_restore_state() MUST be called in pairs */
2243fail2:
2244fail3:
2245 pci_restore_state(efx->pci_dev);
2246fail1:
2247fail4:
2248fail5:
2249 return rc;
2250}
2251
2252/* Zeroes out the SRAM contents. This routine must be called in
2253 * process context and is allowed to sleep.
2254 */
2255static int falcon_reset_sram(struct efx_nic *efx)
2256{
2257 efx_oword_t srm_cfg_reg_ker, gpio_cfg_reg_ker;
2258 int count;
2259
2260 /* Set the SRAM wake/sleep GPIO appropriately. */
2261 falcon_read(efx, &gpio_cfg_reg_ker, GPIO_CTL_REG_KER);
2262 EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, GPIO1_OEN, 1);
2263 EFX_SET_OWORD_FIELD(gpio_cfg_reg_ker, GPIO1_OUT, 1);
2264 falcon_write(efx, &gpio_cfg_reg_ker, GPIO_CTL_REG_KER);
2265
2266 /* Initiate SRAM reset */
2267 EFX_POPULATE_OWORD_2(srm_cfg_reg_ker,
2268 SRAM_OOB_BT_INIT_EN, 1,
2269 SRM_NUM_BANKS_AND_BANK_SIZE, 0);
2270 falcon_write(efx, &srm_cfg_reg_ker, SRM_CFG_REG_KER);
2271
2272 /* Wait for SRAM reset to complete */
2273 count = 0;
2274 do {
2275 EFX_LOG(efx, "waiting for SRAM reset (attempt %d)...\n", count);
2276
2277 /* SRAM reset is slow; expect around 16ms */
2278 schedule_timeout_uninterruptible(HZ / 50);
2279
2280 /* Check for reset complete */
2281 falcon_read(efx, &srm_cfg_reg_ker, SRM_CFG_REG_KER);
2282 if (!EFX_OWORD_FIELD(srm_cfg_reg_ker, SRAM_OOB_BT_INIT_EN)) {
2283 EFX_LOG(efx, "SRAM reset complete\n");
2284
2285 return 0;
2286 }
2287 } while (++count < 20); /* wait upto 0.4 sec */
2288
2289 EFX_ERR(efx, "timed out waiting for SRAM reset\n");
2290 return -ETIMEDOUT;
2291}
2292
2293/* Extract non-volatile configuration */
2294static int falcon_probe_nvconfig(struct efx_nic *efx)
2295{
2296 struct falcon_nvconfig *nvconfig;
2297 efx_oword_t nic_stat;
2298 int device_id;
2299 unsigned addr_len;
2300 size_t offset, len;
2301 int magic_num, struct_ver, board_rev;
2302 int rc;
2303
2304 /* Find the boot device. */
2305 falcon_read(efx, &nic_stat, NIC_STAT_REG);
2306 if (EFX_OWORD_FIELD(nic_stat, SF_PRST)) {
2307 device_id = EE_SPI_FLASH;
2308 addr_len = 3;
2309 } else if (EFX_OWORD_FIELD(nic_stat, EE_PRST)) {
2310 device_id = EE_SPI_EEPROM;
2311 addr_len = 2;
2312 } else {
2313 return -ENODEV;
2314 }
2315
2316 nvconfig = kmalloc(sizeof(*nvconfig), GFP_KERNEL);
2317
2318 /* Read the whole configuration structure into memory. */
2319 for (offset = 0; offset < sizeof(*nvconfig); offset += len) {
2320 len = min(sizeof(*nvconfig) - offset,
2321 (size_t) FALCON_SPI_MAX_LEN);
2322 rc = falcon_spi_read(efx, device_id, SPI_READ,
2323 NVCONFIG_BASE + offset, addr_len,
2324 (char *)nvconfig + offset, len);
2325 if (rc)
2326 goto out;
2327 }
2328
2329 /* Read the MAC addresses */
2330 memcpy(efx->mac_address, nvconfig->mac_address[0], ETH_ALEN);
2331
2332 /* Read the board configuration. */
2333 magic_num = le16_to_cpu(nvconfig->board_magic_num);
2334 struct_ver = le16_to_cpu(nvconfig->board_struct_ver);
2335
2336 if (magic_num != NVCONFIG_BOARD_MAGIC_NUM || struct_ver < 2) {
2337 EFX_ERR(efx, "Non volatile memory bad magic=%x ver=%x "
2338 "therefore using defaults\n", magic_num, struct_ver);
2339 efx->phy_type = PHY_TYPE_NONE;
2340 efx->mii.phy_id = PHY_ADDR_INVALID;
2341 board_rev = 0;
2342 } else {
2343 struct falcon_nvconfig_board_v2 *v2 = &nvconfig->board_v2;
2344
2345 efx->phy_type = v2->port0_phy_type;
2346 efx->mii.phy_id = v2->port0_phy_addr;
2347 board_rev = le16_to_cpu(v2->board_revision);
2348 }
2349
2350 EFX_LOG(efx, "PHY is %d phy_id %d\n", efx->phy_type, efx->mii.phy_id);
2351
2352 efx_set_board_info(efx, board_rev);
2353
2354 out:
2355 kfree(nvconfig);
2356 return rc;
2357}
2358
2359/* Probe the NIC variant (revision, ASIC vs FPGA, function count, port
2360 * count, port speed). Set workaround and feature flags accordingly.
2361 */
2362static int falcon_probe_nic_variant(struct efx_nic *efx)
2363{
2364 efx_oword_t altera_build;
2365
2366 falcon_read(efx, &altera_build, ALTERA_BUILD_REG_KER);
2367 if (EFX_OWORD_FIELD(altera_build, VER_ALL)) {
2368 EFX_ERR(efx, "Falcon FPGA not supported\n");
2369 return -ENODEV;
2370 }
2371
2372 switch (FALCON_REV(efx)) {
2373 case FALCON_REV_A0:
2374 case 0xff:
2375 EFX_ERR(efx, "Falcon rev A0 not supported\n");
2376 return -ENODEV;
2377
2378 case FALCON_REV_A1:{
2379 efx_oword_t nic_stat;
2380
2381 falcon_read(efx, &nic_stat, NIC_STAT_REG);
2382
2383 if (EFX_OWORD_FIELD(nic_stat, STRAP_PCIE) == 0) {
2384 EFX_ERR(efx, "Falcon rev A1 PCI-X not supported\n");
2385 return -ENODEV;
2386 }
2387 if (!EFX_OWORD_FIELD(nic_stat, STRAP_10G)) {
2388 EFX_ERR(efx, "1G mode not supported\n");
2389 return -ENODEV;
2390 }
2391 break;
2392 }
2393
2394 case FALCON_REV_B0:
2395 break;
2396
2397 default:
2398 EFX_ERR(efx, "Unknown Falcon rev %d\n", FALCON_REV(efx));
2399 return -ENODEV;
2400 }
2401
2402 return 0;
2403}
2404
2405int falcon_probe_nic(struct efx_nic *efx)
2406{
2407 struct falcon_nic_data *nic_data;
2408 int rc;
2409
2410 /* Initialise I2C interface state */
2411 efx->i2c.efx = efx;
2412 efx->i2c.op = &falcon_i2c_bit_operations;
2413 efx->i2c.sda = 1;
2414 efx->i2c.scl = 1;
2415
2416 /* Allocate storage for hardware specific data */
2417 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
2418 efx->nic_data = (void *) nic_data;
2419
2420 /* Determine number of ports etc. */
2421 rc = falcon_probe_nic_variant(efx);
2422 if (rc)
2423 goto fail1;
2424
2425 /* Probe secondary function if expected */
2426 if (FALCON_IS_DUAL_FUNC(efx)) {
2427 struct pci_dev *dev = pci_dev_get(efx->pci_dev);
2428
2429 while ((dev = pci_get_device(EFX_VENDID_SFC, FALCON_A_S_DEVID,
2430 dev))) {
2431 if (dev->bus == efx->pci_dev->bus &&
2432 dev->devfn == efx->pci_dev->devfn + 1) {
2433 nic_data->pci_dev2 = dev;
2434 break;
2435 }
2436 }
2437 if (!nic_data->pci_dev2) {
2438 EFX_ERR(efx, "failed to find secondary function\n");
2439 rc = -ENODEV;
2440 goto fail2;
2441 }
2442 }
2443
2444 /* Now we can reset the NIC */
2445 rc = falcon_reset_hw(efx, RESET_TYPE_ALL);
2446 if (rc) {
2447 EFX_ERR(efx, "failed to reset NIC\n");
2448 goto fail3;
2449 }
2450
2451 /* Allocate memory for INT_KER */
2452 rc = falcon_alloc_buffer(efx, &efx->irq_status, sizeof(efx_oword_t));
2453 if (rc)
2454 goto fail4;
2455 BUG_ON(efx->irq_status.dma_addr & 0x0f);
2456
2457 EFX_LOG(efx, "INT_KER at %llx (virt %p phys %lx)\n",
2458 (unsigned long long)efx->irq_status.dma_addr,
2459 efx->irq_status.addr, virt_to_phys(efx->irq_status.addr));
2460
2461 /* Read in the non-volatile configuration */
2462 rc = falcon_probe_nvconfig(efx);
2463 if (rc)
2464 goto fail5;
2465
2466 return 0;
2467
2468 fail5:
2469 falcon_free_buffer(efx, &efx->irq_status);
2470 fail4:
2471 /* fall-thru */
2472 fail3:
2473 if (nic_data->pci_dev2) {
2474 pci_dev_put(nic_data->pci_dev2);
2475 nic_data->pci_dev2 = NULL;
2476 }
2477 fail2:
2478 /* fall-thru */
2479 fail1:
2480 kfree(efx->nic_data);
2481 return rc;
2482}
2483
2484/* This call performs hardware-specific global initialisation, such as
2485 * defining the descriptor cache sizes and number of RSS channels.
2486 * It does not set up any buffers, descriptor rings or event queues.
2487 */
2488int falcon_init_nic(struct efx_nic *efx)
2489{
2490 struct falcon_nic_data *data;
2491 efx_oword_t temp;
2492 unsigned thresh;
2493 int rc;
2494
2495 data = (struct falcon_nic_data *)efx->nic_data;
2496
2497 /* Set up the address region register. This is only needed
2498 * for the B0 FPGA, but since we are just pushing in the
2499 * reset defaults this may as well be unconditional. */
2500 EFX_POPULATE_OWORD_4(temp, ADR_REGION0, 0,
2501 ADR_REGION1, (1 << 16),
2502 ADR_REGION2, (2 << 16),
2503 ADR_REGION3, (3 << 16));
2504 falcon_write(efx, &temp, ADR_REGION_REG_KER);
2505
2506 /* Use on-chip SRAM */
2507 falcon_read(efx, &temp, NIC_STAT_REG);
2508 EFX_SET_OWORD_FIELD(temp, ONCHIP_SRAM, 1);
2509 falcon_write(efx, &temp, NIC_STAT_REG);
2510
2511 /* Set buffer table mode */
2512 EFX_POPULATE_OWORD_1(temp, BUF_TBL_MODE, BUF_TBL_MODE_FULL);
2513 falcon_write(efx, &temp, BUF_TBL_CFG_REG_KER);
2514
2515 rc = falcon_reset_sram(efx);
2516 if (rc)
2517 return rc;
2518
2519 /* Set positions of descriptor caches in SRAM. */
2520 EFX_POPULATE_OWORD_1(temp, SRM_TX_DC_BASE_ADR, TX_DC_BASE / 8);
2521 falcon_write(efx, &temp, SRM_TX_DC_CFG_REG_KER);
2522 EFX_POPULATE_OWORD_1(temp, SRM_RX_DC_BASE_ADR, RX_DC_BASE / 8);
2523 falcon_write(efx, &temp, SRM_RX_DC_CFG_REG_KER);
2524
2525 /* Set TX descriptor cache size. */
2526 BUILD_BUG_ON(TX_DC_ENTRIES != (16 << TX_DC_ENTRIES_ORDER));
2527 EFX_POPULATE_OWORD_1(temp, TX_DC_SIZE, TX_DC_ENTRIES_ORDER);
2528 falcon_write(efx, &temp, TX_DC_CFG_REG_KER);
2529
2530 /* Set RX descriptor cache size. Set low watermark to size-8, as
2531 * this allows most efficient prefetching.
2532 */
2533 BUILD_BUG_ON(RX_DC_ENTRIES != (16 << RX_DC_ENTRIES_ORDER));
2534 EFX_POPULATE_OWORD_1(temp, RX_DC_SIZE, RX_DC_ENTRIES_ORDER);
2535 falcon_write(efx, &temp, RX_DC_CFG_REG_KER);
2536 EFX_POPULATE_OWORD_1(temp, RX_DC_PF_LWM, RX_DC_ENTRIES - 8);
2537 falcon_write(efx, &temp, RX_DC_PF_WM_REG_KER);
2538
2539 /* Clear the parity enables on the TX data fifos as
2540 * they produce false parity errors because of timing issues
2541 */
2542 if (EFX_WORKAROUND_5129(efx)) {
2543 falcon_read(efx, &temp, SPARE_REG_KER);
2544 EFX_SET_OWORD_FIELD(temp, MEM_PERR_EN_TX_DATA, 0);
2545 falcon_write(efx, &temp, SPARE_REG_KER);
2546 }
2547
2548 /* Enable all the genuinely fatal interrupts. (They are still
2549 * masked by the overall interrupt mask, controlled by
2550 * falcon_interrupts()).
2551 *
2552 * Note: All other fatal interrupts are enabled
2553 */
2554 EFX_POPULATE_OWORD_3(temp,
2555 ILL_ADR_INT_KER_EN, 1,
2556 RBUF_OWN_INT_KER_EN, 1,
2557 TBUF_OWN_INT_KER_EN, 1);
2558 EFX_INVERT_OWORD(temp);
2559 falcon_write(efx, &temp, FATAL_INTR_REG_KER);
2560
2561 /* Set number of RSS queues for receive path. */
2562 falcon_read(efx, &temp, RX_FILTER_CTL_REG);
2563 if (FALCON_REV(efx) >= FALCON_REV_B0)
2564 EFX_SET_OWORD_FIELD(temp, NUM_KER, 0);
2565 else
2566 EFX_SET_OWORD_FIELD(temp, NUM_KER, efx->rss_queues - 1);
2567 if (EFX_WORKAROUND_7244(efx)) {
2568 EFX_SET_OWORD_FIELD(temp, UDP_FULL_SRCH_LIMIT, 8);
2569 EFX_SET_OWORD_FIELD(temp, UDP_WILD_SRCH_LIMIT, 8);
2570 EFX_SET_OWORD_FIELD(temp, TCP_FULL_SRCH_LIMIT, 8);
2571 EFX_SET_OWORD_FIELD(temp, TCP_WILD_SRCH_LIMIT, 8);
2572 }
2573 falcon_write(efx, &temp, RX_FILTER_CTL_REG);
2574
2575 falcon_setup_rss_indir_table(efx);
2576
2577 /* Setup RX. Wait for descriptor is broken and must
2578 * be disabled. RXDP recovery shouldn't be needed, but is.
2579 */
2580 falcon_read(efx, &temp, RX_SELF_RST_REG_KER);
2581 EFX_SET_OWORD_FIELD(temp, RX_NODESC_WAIT_DIS, 1);
2582 EFX_SET_OWORD_FIELD(temp, RX_RECOVERY_EN, 1);
2583 if (EFX_WORKAROUND_5583(efx))
2584 EFX_SET_OWORD_FIELD(temp, RX_ISCSI_DIS, 1);
2585 falcon_write(efx, &temp, RX_SELF_RST_REG_KER);
2586
2587 /* Disable the ugly timer-based TX DMA backoff and allow TX DMA to be
2588 * controlled by the RX FIFO fill level. Set arbitration to one pkt/Q.
2589 */
2590 falcon_read(efx, &temp, TX_CFG2_REG_KER);
2591 EFX_SET_OWORD_FIELD(temp, TX_RX_SPACER, 0xfe);
2592 EFX_SET_OWORD_FIELD(temp, TX_RX_SPACER_EN, 1);
2593 EFX_SET_OWORD_FIELD(temp, TX_ONE_PKT_PER_Q, 1);
2594 EFX_SET_OWORD_FIELD(temp, TX_CSR_PUSH_EN, 0);
2595 EFX_SET_OWORD_FIELD(temp, TX_DIS_NON_IP_EV, 1);
2596 /* Enable SW_EV to inherit in char driver - assume harmless here */
2597 EFX_SET_OWORD_FIELD(temp, TX_SW_EV_EN, 1);
2598 /* Prefetch threshold 2 => fetch when descriptor cache half empty */
2599 EFX_SET_OWORD_FIELD(temp, TX_PREF_THRESHOLD, 2);
2600 /* Squash TX of packets of 16 bytes or less */
2601 if (FALCON_REV(efx) >= FALCON_REV_B0 && EFX_WORKAROUND_9141(efx))
2602 EFX_SET_OWORD_FIELD(temp, TX_FLUSH_MIN_LEN_EN_B0, 1);
2603 falcon_write(efx, &temp, TX_CFG2_REG_KER);
2604
2605 /* Do not enable TX_NO_EOP_DISC_EN, since it limits packets to 16
2606 * descriptors (which is bad).
2607 */
2608 falcon_read(efx, &temp, TX_CFG_REG_KER);
2609 EFX_SET_OWORD_FIELD(temp, TX_NO_EOP_DISC_EN, 0);
2610 falcon_write(efx, &temp, TX_CFG_REG_KER);
2611
2612 /* RX config */
2613 falcon_read(efx, &temp, RX_CFG_REG_KER);
2614 EFX_SET_OWORD_FIELD_VER(efx, temp, RX_DESC_PUSH_EN, 0);
2615 if (EFX_WORKAROUND_7575(efx))
2616 EFX_SET_OWORD_FIELD_VER(efx, temp, RX_USR_BUF_SIZE,
2617 (3 * 4096) / 32);
2618 if (FALCON_REV(efx) >= FALCON_REV_B0)
2619 EFX_SET_OWORD_FIELD(temp, RX_INGR_EN_B0, 1);
2620
2621 /* RX FIFO flow control thresholds */
2622 thresh = ((rx_xon_thresh_bytes >= 0) ?
2623 rx_xon_thresh_bytes : efx->type->rx_xon_thresh);
2624 EFX_SET_OWORD_FIELD_VER(efx, temp, RX_XON_MAC_TH, thresh / 256);
2625 thresh = ((rx_xoff_thresh_bytes >= 0) ?
2626 rx_xoff_thresh_bytes : efx->type->rx_xoff_thresh);
2627 EFX_SET_OWORD_FIELD_VER(efx, temp, RX_XOFF_MAC_TH, thresh / 256);
2628 /* RX control FIFO thresholds [32 entries] */
2629 EFX_SET_OWORD_FIELD_VER(efx, temp, RX_XON_TX_TH, 25);
2630 EFX_SET_OWORD_FIELD_VER(efx, temp, RX_XOFF_TX_TH, 20);
2631 falcon_write(efx, &temp, RX_CFG_REG_KER);
2632
2633 /* Set destination of both TX and RX Flush events */
2634 if (FALCON_REV(efx) >= FALCON_REV_B0) {
2635 EFX_POPULATE_OWORD_1(temp, FLS_EVQ_ID, 0);
2636 falcon_write(efx, &temp, DP_CTRL_REG);
2637 }
2638
2639 return 0;
2640}
2641
2642void falcon_remove_nic(struct efx_nic *efx)
2643{
2644 struct falcon_nic_data *nic_data = efx->nic_data;
2645
2646 falcon_free_buffer(efx, &efx->irq_status);
2647
2648 (void) falcon_reset_hw(efx, RESET_TYPE_ALL);
2649
2650 /* Release the second function after the reset */
2651 if (nic_data->pci_dev2) {
2652 pci_dev_put(nic_data->pci_dev2);
2653 nic_data->pci_dev2 = NULL;
2654 }
2655
2656 /* Tear down the private nic state */
2657 kfree(efx->nic_data);
2658 efx->nic_data = NULL;
2659}
2660
2661void falcon_update_nic_stats(struct efx_nic *efx)
2662{
2663 efx_oword_t cnt;
2664
2665 falcon_read(efx, &cnt, RX_NODESC_DROP_REG_KER);
2666 efx->n_rx_nodesc_drop_cnt += EFX_OWORD_FIELD(cnt, RX_NODESC_DROP_CNT);
2667}
2668
2669/**************************************************************************
2670 *
2671 * Revision-dependent attributes used by efx.c
2672 *
2673 **************************************************************************
2674 */
2675
2676struct efx_nic_type falcon_a_nic_type = {
2677 .mem_bar = 2,
2678 .mem_map_size = 0x20000,
2679 .txd_ptr_tbl_base = TX_DESC_PTR_TBL_KER_A1,
2680 .rxd_ptr_tbl_base = RX_DESC_PTR_TBL_KER_A1,
2681 .buf_tbl_base = BUF_TBL_KER_A1,
2682 .evq_ptr_tbl_base = EVQ_PTR_TBL_KER_A1,
2683 .evq_rptr_tbl_base = EVQ_RPTR_REG_KER_A1,
2684 .txd_ring_mask = FALCON_TXD_RING_MASK,
2685 .rxd_ring_mask = FALCON_RXD_RING_MASK,
2686 .evq_size = FALCON_EVQ_SIZE,
2687 .max_dma_mask = FALCON_DMA_MASK,
2688 .tx_dma_mask = FALCON_TX_DMA_MASK,
2689 .bug5391_mask = 0xf,
2690 .rx_xoff_thresh = 2048,
2691 .rx_xon_thresh = 512,
2692 .rx_buffer_padding = 0x24,
2693 .max_interrupt_mode = EFX_INT_MODE_MSI,
2694 .phys_addr_channels = 4,
2695};
2696
2697struct efx_nic_type falcon_b_nic_type = {
2698 .mem_bar = 2,
2699 /* Map everything up to and including the RSS indirection
2700 * table. Don't map MSI-X table, MSI-X PBA since Linux
2701 * requires that they not be mapped. */
2702 .mem_map_size = RX_RSS_INDIR_TBL_B0 + 0x800,
2703 .txd_ptr_tbl_base = TX_DESC_PTR_TBL_KER_B0,
2704 .rxd_ptr_tbl_base = RX_DESC_PTR_TBL_KER_B0,
2705 .buf_tbl_base = BUF_TBL_KER_B0,
2706 .evq_ptr_tbl_base = EVQ_PTR_TBL_KER_B0,
2707 .evq_rptr_tbl_base = EVQ_RPTR_REG_KER_B0,
2708 .txd_ring_mask = FALCON_TXD_RING_MASK,
2709 .rxd_ring_mask = FALCON_RXD_RING_MASK,
2710 .evq_size = FALCON_EVQ_SIZE,
2711 .max_dma_mask = FALCON_DMA_MASK,
2712 .tx_dma_mask = FALCON_TX_DMA_MASK,
2713 .bug5391_mask = 0,
2714 .rx_xoff_thresh = 54272, /* ~80Kb - 3*max MTU */
2715 .rx_xon_thresh = 27648, /* ~3*max MTU */
2716 .rx_buffer_padding = 0,
2717 .max_interrupt_mode = EFX_INT_MODE_MSIX,
2718 .phys_addr_channels = 32, /* Hardware limit is 64, but the legacy
2719 * interrupt handler only supports 32
2720 * channels */
2721};
2722
diff --git a/drivers/net/sfc/falcon.h b/drivers/net/sfc/falcon.h
new file mode 100644
index 000000000000..6117403b0c03
--- /dev/null
+++ b/drivers/net/sfc/falcon.h
@@ -0,0 +1,130 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2006-2008 Solarflare Communications Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
11#ifndef EFX_FALCON_H
12#define EFX_FALCON_H
13
14#include "net_driver.h"
15
16/*
17 * Falcon hardware control
18 */
19
20enum falcon_revision {
21 FALCON_REV_A0 = 0,
22 FALCON_REV_A1 = 1,
23 FALCON_REV_B0 = 2,
24};
25
26#define FALCON_REV(efx) ((efx)->pci_dev->revision)
27
28extern struct efx_nic_type falcon_a_nic_type;
29extern struct efx_nic_type falcon_b_nic_type;
30
31/**************************************************************************
32 *
33 * Externs
34 *
35 **************************************************************************
36 */
37
38/* TX data path */
39extern int falcon_probe_tx(struct efx_tx_queue *tx_queue);
40extern int falcon_init_tx(struct efx_tx_queue *tx_queue);
41extern void falcon_fini_tx(struct efx_tx_queue *tx_queue);
42extern void falcon_remove_tx(struct efx_tx_queue *tx_queue);
43extern void falcon_push_buffers(struct efx_tx_queue *tx_queue);
44
45/* RX data path */
46extern int falcon_probe_rx(struct efx_rx_queue *rx_queue);
47extern int falcon_init_rx(struct efx_rx_queue *rx_queue);
48extern void falcon_fini_rx(struct efx_rx_queue *rx_queue);
49extern void falcon_remove_rx(struct efx_rx_queue *rx_queue);
50extern void falcon_notify_rx_desc(struct efx_rx_queue *rx_queue);
51
52/* Event data path */
53extern int falcon_probe_eventq(struct efx_channel *channel);
54extern int falcon_init_eventq(struct efx_channel *channel);
55extern void falcon_fini_eventq(struct efx_channel *channel);
56extern void falcon_remove_eventq(struct efx_channel *channel);
57extern int falcon_process_eventq(struct efx_channel *channel, int *rx_quota);
58extern void falcon_eventq_read_ack(struct efx_channel *channel);
59
60/* Ports */
61extern int falcon_probe_port(struct efx_nic *efx);
62extern void falcon_remove_port(struct efx_nic *efx);
63
64/* MAC/PHY */
65extern int falcon_xaui_link_ok(struct efx_nic *efx);
66extern int falcon_dma_stats(struct efx_nic *efx,
67 unsigned int done_offset);
68extern void falcon_drain_tx_fifo(struct efx_nic *efx);
69extern void falcon_deconfigure_mac_wrapper(struct efx_nic *efx);
70extern void falcon_reconfigure_mac_wrapper(struct efx_nic *efx);
71
72/* Interrupts and test events */
73extern int falcon_init_interrupt(struct efx_nic *efx);
74extern void falcon_enable_interrupts(struct efx_nic *efx);
75extern void falcon_generate_test_event(struct efx_channel *channel,
76 unsigned int magic);
77extern void falcon_generate_interrupt(struct efx_nic *efx);
78extern void falcon_set_int_moderation(struct efx_channel *channel);
79extern void falcon_disable_interrupts(struct efx_nic *efx);
80extern void falcon_fini_interrupt(struct efx_nic *efx);
81
82/* Global Resources */
83extern int falcon_probe_nic(struct efx_nic *efx);
84extern int falcon_probe_resources(struct efx_nic *efx);
85extern int falcon_init_nic(struct efx_nic *efx);
86extern int falcon_reset_hw(struct efx_nic *efx, enum reset_type method);
87extern void falcon_remove_resources(struct efx_nic *efx);
88extern void falcon_remove_nic(struct efx_nic *efx);
89extern void falcon_update_nic_stats(struct efx_nic *efx);
90extern void falcon_set_multicast_hash(struct efx_nic *efx);
91extern int falcon_reset_xaui(struct efx_nic *efx);
92
93/**************************************************************************
94 *
95 * Falcon MAC stats
96 *
97 **************************************************************************
98 */
99
100#define FALCON_STAT_OFFSET(falcon_stat) EFX_VAL(falcon_stat, offset)
101#define FALCON_STAT_WIDTH(falcon_stat) EFX_VAL(falcon_stat, WIDTH)
102
103/* Retrieve statistic from statistics block */
104#define FALCON_STAT(efx, falcon_stat, efx_stat) do { \
105 if (FALCON_STAT_WIDTH(falcon_stat) == 16) \
106 (efx)->mac_stats.efx_stat += le16_to_cpu( \
107 *((__force __le16 *) \
108 (efx->stats_buffer.addr + \
109 FALCON_STAT_OFFSET(falcon_stat)))); \
110 else if (FALCON_STAT_WIDTH(falcon_stat) == 32) \
111 (efx)->mac_stats.efx_stat += le32_to_cpu( \
112 *((__force __le32 *) \
113 (efx->stats_buffer.addr + \
114 FALCON_STAT_OFFSET(falcon_stat)))); \
115 else \
116 (efx)->mac_stats.efx_stat += le64_to_cpu( \
117 *((__force __le64 *) \
118 (efx->stats_buffer.addr + \
119 FALCON_STAT_OFFSET(falcon_stat)))); \
120 } while (0)
121
122#define FALCON_MAC_STATS_SIZE 0x100
123
124#define MAC_DATA_LBN 0
125#define MAC_DATA_WIDTH 32
126
127extern void falcon_generate_event(struct efx_channel *channel,
128 efx_qword_t *event);
129
130#endif /* EFX_FALCON_H */
diff --git a/drivers/net/sfc/falcon_hwdefs.h b/drivers/net/sfc/falcon_hwdefs.h
new file mode 100644
index 000000000000..0485a63eaff6
--- /dev/null
+++ b/drivers/net/sfc/falcon_hwdefs.h
@@ -0,0 +1,1135 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2006-2008 Solarflare Communications Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
11#ifndef EFX_FALCON_HWDEFS_H
12#define EFX_FALCON_HWDEFS_H
13
14/*
15 * Falcon hardware value definitions.
16 * Falcon is the internal codename for the SFC4000 controller that is
17 * present in SFE400X evaluation boards
18 */
19
20/**************************************************************************
21 *
22 * Falcon registers
23 *
24 **************************************************************************
25 */
26
27/* Address region register */
28#define ADR_REGION_REG_KER 0x00
29#define ADR_REGION0_LBN 0
30#define ADR_REGION0_WIDTH 18
31#define ADR_REGION1_LBN 32
32#define ADR_REGION1_WIDTH 18
33#define ADR_REGION2_LBN 64
34#define ADR_REGION2_WIDTH 18
35#define ADR_REGION3_LBN 96
36#define ADR_REGION3_WIDTH 18
37
38/* Interrupt enable register */
39#define INT_EN_REG_KER 0x0010
40#define KER_INT_KER_LBN 3
41#define KER_INT_KER_WIDTH 1
42#define DRV_INT_EN_KER_LBN 0
43#define DRV_INT_EN_KER_WIDTH 1
44
45/* Interrupt status address register */
46#define INT_ADR_REG_KER 0x0030
47#define NORM_INT_VEC_DIS_KER_LBN 64
48#define NORM_INT_VEC_DIS_KER_WIDTH 1
49#define INT_ADR_KER_LBN 0
50#define INT_ADR_KER_WIDTH EFX_DMA_TYPE_WIDTH(64) /* not 46 for this one */
51
52/* Interrupt status register (B0 only) */
53#define INT_ISR0_B0 0x90
54#define INT_ISR1_B0 0xA0
55
56/* Interrupt acknowledge register (A0/A1 only) */
57#define INT_ACK_REG_KER_A1 0x0050
58#define INT_ACK_DUMMY_DATA_LBN 0
59#define INT_ACK_DUMMY_DATA_WIDTH 32
60
61/* Interrupt acknowledge work-around register (A0/A1 only )*/
62#define WORK_AROUND_BROKEN_PCI_READS_REG_KER_A1 0x0070
63
64/* SPI host command register */
65#define EE_SPI_HCMD_REG_KER 0x0100
66#define EE_SPI_HCMD_CMD_EN_LBN 31
67#define EE_SPI_HCMD_CMD_EN_WIDTH 1
68#define EE_WR_TIMER_ACTIVE_LBN 28
69#define EE_WR_TIMER_ACTIVE_WIDTH 1
70#define EE_SPI_HCMD_SF_SEL_LBN 24
71#define EE_SPI_HCMD_SF_SEL_WIDTH 1
72#define EE_SPI_EEPROM 0
73#define EE_SPI_FLASH 1
74#define EE_SPI_HCMD_DABCNT_LBN 16
75#define EE_SPI_HCMD_DABCNT_WIDTH 5
76#define EE_SPI_HCMD_READ_LBN 15
77#define EE_SPI_HCMD_READ_WIDTH 1
78#define EE_SPI_READ 1
79#define EE_SPI_WRITE 0
80#define EE_SPI_HCMD_DUBCNT_LBN 12
81#define EE_SPI_HCMD_DUBCNT_WIDTH 2
82#define EE_SPI_HCMD_ADBCNT_LBN 8
83#define EE_SPI_HCMD_ADBCNT_WIDTH 2
84#define EE_SPI_HCMD_ENC_LBN 0
85#define EE_SPI_HCMD_ENC_WIDTH 8
86
87/* SPI host address register */
88#define EE_SPI_HADR_REG_KER 0x0110
89#define EE_SPI_HADR_ADR_LBN 0
90#define EE_SPI_HADR_ADR_WIDTH 24
91
92/* SPI host data register */
93#define EE_SPI_HDATA_REG_KER 0x0120
94
95/* PCIE CORE ACCESS REG */
96#define PCIE_CORE_ADDR_PCIE_DEVICE_CTRL_STAT 0x68
97#define PCIE_CORE_ADDR_PCIE_LINK_CTRL_STAT 0x70
98#define PCIE_CORE_ADDR_ACK_RPL_TIMER 0x700
99#define PCIE_CORE_ADDR_ACK_FREQ 0x70C
100
101/* NIC status register */
102#define NIC_STAT_REG 0x0200
103#define ONCHIP_SRAM_LBN 16
104#define ONCHIP_SRAM_WIDTH 1
105#define SF_PRST_LBN 9
106#define SF_PRST_WIDTH 1
107#define EE_PRST_LBN 8
108#define EE_PRST_WIDTH 1
109/* See pic_mode_t for decoding of this field */
110/* These bit definitions are extrapolated from the list of numerical
111 * values for STRAP_PINS.
112 */
113#define STRAP_10G_LBN 2
114#define STRAP_10G_WIDTH 1
115#define STRAP_PCIE_LBN 0
116#define STRAP_PCIE_WIDTH 1
117
118/* GPIO control register */
119#define GPIO_CTL_REG_KER 0x0210
120#define GPIO_OUTPUTS_LBN (16)
121#define GPIO_OUTPUTS_WIDTH (4)
122#define GPIO_INPUTS_LBN (8)
123#define GPIO_DIRECTION_LBN (24)
124#define GPIO_DIRECTION_WIDTH (4)
125#define GPIO_DIRECTION_OUT (1)
126#define GPIO_SRAM_SLEEP (1 << 1)
127
128#define GPIO3_OEN_LBN (GPIO_DIRECTION_LBN + 3)
129#define GPIO3_OEN_WIDTH 1
130#define GPIO2_OEN_LBN (GPIO_DIRECTION_LBN + 2)
131#define GPIO2_OEN_WIDTH 1
132#define GPIO1_OEN_LBN (GPIO_DIRECTION_LBN + 1)
133#define GPIO1_OEN_WIDTH 1
134#define GPIO0_OEN_LBN (GPIO_DIRECTION_LBN + 0)
135#define GPIO0_OEN_WIDTH 1
136
137#define GPIO3_OUT_LBN (GPIO_OUTPUTS_LBN + 3)
138#define GPIO3_OUT_WIDTH 1
139#define GPIO2_OUT_LBN (GPIO_OUTPUTS_LBN + 2)
140#define GPIO2_OUT_WIDTH 1
141#define GPIO1_OUT_LBN (GPIO_OUTPUTS_LBN + 1)
142#define GPIO1_OUT_WIDTH 1
143#define GPIO0_OUT_LBN (GPIO_OUTPUTS_LBN + 0)
144#define GPIO0_OUT_WIDTH 1
145
146#define GPIO3_IN_LBN (GPIO_INPUTS_LBN + 3)
147#define GPIO3_IN_WIDTH 1
148#define GPIO2_IN_WIDTH 1
149#define GPIO1_IN_WIDTH 1
150#define GPIO0_IN_LBN (GPIO_INPUTS_LBN + 0)
151#define GPIO0_IN_WIDTH 1
152
153/* Global control register */
154#define GLB_CTL_REG_KER 0x0220
155#define EXT_PHY_RST_CTL_LBN 63
156#define EXT_PHY_RST_CTL_WIDTH 1
157#define PCIE_SD_RST_CTL_LBN 61
158#define PCIE_SD_RST_CTL_WIDTH 1
159
160#define PCIE_NSTCK_RST_CTL_LBN 58
161#define PCIE_NSTCK_RST_CTL_WIDTH 1
162#define PCIE_CORE_RST_CTL_LBN 57
163#define PCIE_CORE_RST_CTL_WIDTH 1
164#define EE_RST_CTL_LBN 49
165#define EE_RST_CTL_WIDTH 1
166#define RST_XGRX_LBN 24
167#define RST_XGRX_WIDTH 1
168#define RST_XGTX_LBN 23
169#define RST_XGTX_WIDTH 1
170#define RST_EM_LBN 22
171#define RST_EM_WIDTH 1
172#define EXT_PHY_RST_DUR_LBN 1
173#define EXT_PHY_RST_DUR_WIDTH 3
174#define SWRST_LBN 0
175#define SWRST_WIDTH 1
176#define INCLUDE_IN_RESET 0
177#define EXCLUDE_FROM_RESET 1
178
179/* Fatal interrupt register */
180#define FATAL_INTR_REG_KER 0x0230
181#define RBUF_OWN_INT_KER_EN_LBN 39
182#define RBUF_OWN_INT_KER_EN_WIDTH 1
183#define TBUF_OWN_INT_KER_EN_LBN 38
184#define TBUF_OWN_INT_KER_EN_WIDTH 1
185#define ILL_ADR_INT_KER_EN_LBN 33
186#define ILL_ADR_INT_KER_EN_WIDTH 1
187#define MEM_PERR_INT_KER_LBN 8
188#define MEM_PERR_INT_KER_WIDTH 1
189#define INT_KER_ERROR_LBN 0
190#define INT_KER_ERROR_WIDTH 12
191
192#define DP_CTRL_REG 0x250
193#define FLS_EVQ_ID_LBN 0
194#define FLS_EVQ_ID_WIDTH 11
195
196#define MEM_STAT_REG_KER 0x260
197
198/* Debug probe register */
199#define DEBUG_BLK_SEL_MISC 7
200#define DEBUG_BLK_SEL_SERDES 6
201#define DEBUG_BLK_SEL_EM 5
202#define DEBUG_BLK_SEL_SR 4
203#define DEBUG_BLK_SEL_EV 3
204#define DEBUG_BLK_SEL_RX 2
205#define DEBUG_BLK_SEL_TX 1
206#define DEBUG_BLK_SEL_BIU 0
207
208/* FPGA build version */
209#define ALTERA_BUILD_REG_KER 0x0300
210#define VER_ALL_LBN 0
211#define VER_ALL_WIDTH 32
212
213/* Spare EEPROM bits register (flash 0x390) */
214#define SPARE_REG_KER 0x310
215#define MEM_PERR_EN_TX_DATA_LBN 72
216#define MEM_PERR_EN_TX_DATA_WIDTH 2
217
218/* Timer table for kernel access */
219#define TIMER_CMD_REG_KER 0x420
220#define TIMER_MODE_LBN 12
221#define TIMER_MODE_WIDTH 2
222#define TIMER_MODE_DIS 0
223#define TIMER_MODE_INT_HLDOFF 2
224#define TIMER_VAL_LBN 0
225#define TIMER_VAL_WIDTH 12
226
227/* Driver generated event register */
228#define DRV_EV_REG_KER 0x440
229#define DRV_EV_QID_LBN 64
230#define DRV_EV_QID_WIDTH 12
231#define DRV_EV_DATA_LBN 0
232#define DRV_EV_DATA_WIDTH 64
233
234/* Buffer table configuration register */
235#define BUF_TBL_CFG_REG_KER 0x600
236#define BUF_TBL_MODE_LBN 3
237#define BUF_TBL_MODE_WIDTH 1
238#define BUF_TBL_MODE_HALF 0
239#define BUF_TBL_MODE_FULL 1
240
241/* SRAM receive descriptor cache configuration register */
242#define SRM_RX_DC_CFG_REG_KER 0x610
243#define SRM_RX_DC_BASE_ADR_LBN 0
244#define SRM_RX_DC_BASE_ADR_WIDTH 21
245
246/* SRAM transmit descriptor cache configuration register */
247#define SRM_TX_DC_CFG_REG_KER 0x620
248#define SRM_TX_DC_BASE_ADR_LBN 0
249#define SRM_TX_DC_BASE_ADR_WIDTH 21
250
251/* SRAM configuration register */
252#define SRM_CFG_REG_KER 0x630
253#define SRAM_OOB_BT_INIT_EN_LBN 3
254#define SRAM_OOB_BT_INIT_EN_WIDTH 1
255#define SRM_NUM_BANKS_AND_BANK_SIZE_LBN 0
256#define SRM_NUM_BANKS_AND_BANK_SIZE_WIDTH 3
257#define SRM_NB_BSZ_1BANKS_2M 0
258#define SRM_NB_BSZ_1BANKS_4M 1
259#define SRM_NB_BSZ_1BANKS_8M 2
260#define SRM_NB_BSZ_DEFAULT 3 /* char driver will set the default */
261#define SRM_NB_BSZ_2BANKS_4M 4
262#define SRM_NB_BSZ_2BANKS_8M 5
263#define SRM_NB_BSZ_2BANKS_16M 6
264#define SRM_NB_BSZ_RESERVED 7
265
266/* Special buffer table update register */
267#define BUF_TBL_UPD_REG_KER 0x0650
268#define BUF_UPD_CMD_LBN 63
269#define BUF_UPD_CMD_WIDTH 1
270#define BUF_CLR_CMD_LBN 62
271#define BUF_CLR_CMD_WIDTH 1
272#define BUF_CLR_END_ID_LBN 32
273#define BUF_CLR_END_ID_WIDTH 20
274#define BUF_CLR_START_ID_LBN 0
275#define BUF_CLR_START_ID_WIDTH 20
276
277/* Receive configuration register */
278#define RX_CFG_REG_KER 0x800
279
280/* B0 */
281#define RX_INGR_EN_B0_LBN 47
282#define RX_INGR_EN_B0_WIDTH 1
283#define RX_DESC_PUSH_EN_B0_LBN 43
284#define RX_DESC_PUSH_EN_B0_WIDTH 1
285#define RX_XON_TX_TH_B0_LBN 33
286#define RX_XON_TX_TH_B0_WIDTH 5
287#define RX_XOFF_TX_TH_B0_LBN 28
288#define RX_XOFF_TX_TH_B0_WIDTH 5
289#define RX_USR_BUF_SIZE_B0_LBN 19
290#define RX_USR_BUF_SIZE_B0_WIDTH 9
291#define RX_XON_MAC_TH_B0_LBN 10
292#define RX_XON_MAC_TH_B0_WIDTH 9
293#define RX_XOFF_MAC_TH_B0_LBN 1
294#define RX_XOFF_MAC_TH_B0_WIDTH 9
295#define RX_XOFF_MAC_EN_B0_LBN 0
296#define RX_XOFF_MAC_EN_B0_WIDTH 1
297
298/* A1 */
299#define RX_DESC_PUSH_EN_A1_LBN 35
300#define RX_DESC_PUSH_EN_A1_WIDTH 1
301#define RX_XON_TX_TH_A1_LBN 25
302#define RX_XON_TX_TH_A1_WIDTH 5
303#define RX_XOFF_TX_TH_A1_LBN 20
304#define RX_XOFF_TX_TH_A1_WIDTH 5
305#define RX_USR_BUF_SIZE_A1_LBN 11
306#define RX_USR_BUF_SIZE_A1_WIDTH 9
307#define RX_XON_MAC_TH_A1_LBN 6
308#define RX_XON_MAC_TH_A1_WIDTH 5
309#define RX_XOFF_MAC_TH_A1_LBN 1
310#define RX_XOFF_MAC_TH_A1_WIDTH 5
311#define RX_XOFF_MAC_EN_A1_LBN 0
312#define RX_XOFF_MAC_EN_A1_WIDTH 1
313
314/* Receive filter control register */
315#define RX_FILTER_CTL_REG 0x810
316#define UDP_FULL_SRCH_LIMIT_LBN 32
317#define UDP_FULL_SRCH_LIMIT_WIDTH 8
318#define NUM_KER_LBN 24
319#define NUM_KER_WIDTH 2
320#define UDP_WILD_SRCH_LIMIT_LBN 16
321#define UDP_WILD_SRCH_LIMIT_WIDTH 8
322#define TCP_WILD_SRCH_LIMIT_LBN 8
323#define TCP_WILD_SRCH_LIMIT_WIDTH 8
324#define TCP_FULL_SRCH_LIMIT_LBN 0
325#define TCP_FULL_SRCH_LIMIT_WIDTH 8
326
327/* RX queue flush register */
328#define RX_FLUSH_DESCQ_REG_KER 0x0820
329#define RX_FLUSH_DESCQ_CMD_LBN 24
330#define RX_FLUSH_DESCQ_CMD_WIDTH 1
331#define RX_FLUSH_DESCQ_LBN 0
332#define RX_FLUSH_DESCQ_WIDTH 12
333
334/* Receive descriptor update register */
335#define RX_DESC_UPD_REG_KER_DWORD (0x830 + 12)
336#define RX_DESC_WPTR_DWORD_LBN 0
337#define RX_DESC_WPTR_DWORD_WIDTH 12
338
339/* Receive descriptor cache configuration register */
340#define RX_DC_CFG_REG_KER 0x840
341#define RX_DC_SIZE_LBN 0
342#define RX_DC_SIZE_WIDTH 2
343
344#define RX_DC_PF_WM_REG_KER 0x850
345#define RX_DC_PF_LWM_LBN 0
346#define RX_DC_PF_LWM_WIDTH 6
347
348/* RX no descriptor drop counter */
349#define RX_NODESC_DROP_REG_KER 0x880
350#define RX_NODESC_DROP_CNT_LBN 0
351#define RX_NODESC_DROP_CNT_WIDTH 16
352
353/* RX black magic register */
354#define RX_SELF_RST_REG_KER 0x890
355#define RX_ISCSI_DIS_LBN 17
356#define RX_ISCSI_DIS_WIDTH 1
357#define RX_NODESC_WAIT_DIS_LBN 9
358#define RX_NODESC_WAIT_DIS_WIDTH 1
359#define RX_RECOVERY_EN_LBN 8
360#define RX_RECOVERY_EN_WIDTH 1
361
362/* TX queue flush register */
363#define TX_FLUSH_DESCQ_REG_KER 0x0a00
364#define TX_FLUSH_DESCQ_CMD_LBN 12
365#define TX_FLUSH_DESCQ_CMD_WIDTH 1
366#define TX_FLUSH_DESCQ_LBN 0
367#define TX_FLUSH_DESCQ_WIDTH 12
368
369/* Transmit descriptor update register */
370#define TX_DESC_UPD_REG_KER_DWORD (0xa10 + 12)
371#define TX_DESC_WPTR_DWORD_LBN 0
372#define TX_DESC_WPTR_DWORD_WIDTH 12
373
374/* Transmit descriptor cache configuration register */
375#define TX_DC_CFG_REG_KER 0xa20
376#define TX_DC_SIZE_LBN 0
377#define TX_DC_SIZE_WIDTH 2
378
379/* Transmit checksum configuration register (A0/A1 only) */
380#define TX_CHKSM_CFG_REG_KER_A1 0xa30
381
382/* Transmit configuration register */
383#define TX_CFG_REG_KER 0xa50
384#define TX_NO_EOP_DISC_EN_LBN 5
385#define TX_NO_EOP_DISC_EN_WIDTH 1
386
387/* Transmit configuration register 2 */
388#define TX_CFG2_REG_KER 0xa80
389#define TX_CSR_PUSH_EN_LBN 89
390#define TX_CSR_PUSH_EN_WIDTH 1
391#define TX_RX_SPACER_LBN 64
392#define TX_RX_SPACER_WIDTH 8
393#define TX_SW_EV_EN_LBN 59
394#define TX_SW_EV_EN_WIDTH 1
395#define TX_RX_SPACER_EN_LBN 57
396#define TX_RX_SPACER_EN_WIDTH 1
397#define TX_PREF_THRESHOLD_LBN 19
398#define TX_PREF_THRESHOLD_WIDTH 2
399#define TX_ONE_PKT_PER_Q_LBN 18
400#define TX_ONE_PKT_PER_Q_WIDTH 1
401#define TX_DIS_NON_IP_EV_LBN 17
402#define TX_DIS_NON_IP_EV_WIDTH 1
403#define TX_FLUSH_MIN_LEN_EN_B0_LBN 7
404#define TX_FLUSH_MIN_LEN_EN_B0_WIDTH 1
405
406/* PHY management transmit data register */
407#define MD_TXD_REG_KER 0xc00
408#define MD_TXD_LBN 0
409#define MD_TXD_WIDTH 16
410
411/* PHY management receive data register */
412#define MD_RXD_REG_KER 0xc10
413#define MD_RXD_LBN 0
414#define MD_RXD_WIDTH 16
415
416/* PHY management configuration & status register */
417#define MD_CS_REG_KER 0xc20
418#define MD_GC_LBN 4
419#define MD_GC_WIDTH 1
420#define MD_RIC_LBN 2
421#define MD_RIC_WIDTH 1
422#define MD_RDC_LBN 1
423#define MD_RDC_WIDTH 1
424#define MD_WRC_LBN 0
425#define MD_WRC_WIDTH 1
426
427/* PHY management PHY address register */
428#define MD_PHY_ADR_REG_KER 0xc30
429#define MD_PHY_ADR_LBN 0
430#define MD_PHY_ADR_WIDTH 16
431
432/* PHY management ID register */
433#define MD_ID_REG_KER 0xc40
434#define MD_PRT_ADR_LBN 11
435#define MD_PRT_ADR_WIDTH 5
436#define MD_DEV_ADR_LBN 6
437#define MD_DEV_ADR_WIDTH 5
438/* Used for writing both at once */
439#define MD_PRT_DEV_ADR_LBN 6
440#define MD_PRT_DEV_ADR_WIDTH 10
441
442/* PHY management status & mask register (DWORD read only) */
443#define MD_STAT_REG_KER 0xc50
444#define MD_BSERR_LBN 2
445#define MD_BSERR_WIDTH 1
446#define MD_LNFL_LBN 1
447#define MD_LNFL_WIDTH 1
448#define MD_BSY_LBN 0
449#define MD_BSY_WIDTH 1
450
451/* Port 0 and 1 MAC stats registers */
452#define MAC0_STAT_DMA_REG_KER 0xc60
453#define MAC_STAT_DMA_CMD_LBN 48
454#define MAC_STAT_DMA_CMD_WIDTH 1
455#define MAC_STAT_DMA_ADR_LBN 0
456#define MAC_STAT_DMA_ADR_WIDTH EFX_DMA_TYPE_WIDTH(46)
457
458/* Port 0 and 1 MAC control registers */
459#define MAC0_CTRL_REG_KER 0xc80
460#define MAC_XOFF_VAL_LBN 16
461#define MAC_XOFF_VAL_WIDTH 16
462#define TXFIFO_DRAIN_EN_B0_LBN 7
463#define TXFIFO_DRAIN_EN_B0_WIDTH 1
464#define MAC_BCAD_ACPT_LBN 4
465#define MAC_BCAD_ACPT_WIDTH 1
466#define MAC_UC_PROM_LBN 3
467#define MAC_UC_PROM_WIDTH 1
468#define MAC_LINK_STATUS_LBN 2
469#define MAC_LINK_STATUS_WIDTH 1
470#define MAC_SPEED_LBN 0
471#define MAC_SPEED_WIDTH 2
472
473/* 10G XAUI XGXS default values */
474#define XX_TXDRV_DEQ_DEFAULT 0xe /* deq=.6 */
475#define XX_TXDRV_DTX_DEFAULT 0x5 /* 1.25 */
476#define XX_SD_CTL_DRV_DEFAULT 0 /* 20mA */
477
478/* Multicast address hash table */
479#define MAC_MCAST_HASH_REG0_KER 0xca0
480#define MAC_MCAST_HASH_REG1_KER 0xcb0
481
482/* GMAC registers */
483#define FALCON_GMAC_REGBANK 0xe00
484#define FALCON_GMAC_REGBANK_SIZE 0x200
485#define FALCON_GMAC_REG_SIZE 0x10
486
487/* XMAC registers */
488#define FALCON_XMAC_REGBANK 0x1200
489#define FALCON_XMAC_REGBANK_SIZE 0x200
490#define FALCON_XMAC_REG_SIZE 0x10
491
492/* XGMAC address register low */
493#define XM_ADR_LO_REG_MAC 0x00
494#define XM_ADR_3_LBN 24
495#define XM_ADR_3_WIDTH 8
496#define XM_ADR_2_LBN 16
497#define XM_ADR_2_WIDTH 8
498#define XM_ADR_1_LBN 8
499#define XM_ADR_1_WIDTH 8
500#define XM_ADR_0_LBN 0
501#define XM_ADR_0_WIDTH 8
502
503/* XGMAC address register high */
504#define XM_ADR_HI_REG_MAC 0x01
505#define XM_ADR_5_LBN 8
506#define XM_ADR_5_WIDTH 8
507#define XM_ADR_4_LBN 0
508#define XM_ADR_4_WIDTH 8
509
510/* XGMAC global configuration */
511#define XM_GLB_CFG_REG_MAC 0x02
512#define XM_RX_STAT_EN_LBN 11
513#define XM_RX_STAT_EN_WIDTH 1
514#define XM_TX_STAT_EN_LBN 10
515#define XM_TX_STAT_EN_WIDTH 1
516#define XM_RX_JUMBO_MODE_LBN 6
517#define XM_RX_JUMBO_MODE_WIDTH 1
518#define XM_INTCLR_MODE_LBN 3
519#define XM_INTCLR_MODE_WIDTH 1
520#define XM_CORE_RST_LBN 0
521#define XM_CORE_RST_WIDTH 1
522
523/* XGMAC transmit configuration */
524#define XM_TX_CFG_REG_MAC 0x03
525#define XM_IPG_LBN 16
526#define XM_IPG_WIDTH 4
527#define XM_FCNTL_LBN 10
528#define XM_FCNTL_WIDTH 1
529#define XM_TXCRC_LBN 8
530#define XM_TXCRC_WIDTH 1
531#define XM_AUTO_PAD_LBN 5
532#define XM_AUTO_PAD_WIDTH 1
533#define XM_TX_PRMBL_LBN 2
534#define XM_TX_PRMBL_WIDTH 1
535#define XM_TXEN_LBN 1
536#define XM_TXEN_WIDTH 1
537
538/* XGMAC receive configuration */
539#define XM_RX_CFG_REG_MAC 0x04
540#define XM_PASS_CRC_ERR_LBN 25
541#define XM_PASS_CRC_ERR_WIDTH 1
542#define XM_ACPT_ALL_MCAST_LBN 11
543#define XM_ACPT_ALL_MCAST_WIDTH 1
544#define XM_ACPT_ALL_UCAST_LBN 9
545#define XM_ACPT_ALL_UCAST_WIDTH 1
546#define XM_AUTO_DEPAD_LBN 8
547#define XM_AUTO_DEPAD_WIDTH 1
548#define XM_RXEN_LBN 1
549#define XM_RXEN_WIDTH 1
550
551/* XGMAC management interrupt mask register */
552#define XM_MGT_INT_MSK_REG_MAC_B0 0x5
553#define XM_MSK_PRMBLE_ERR_LBN 2
554#define XM_MSK_PRMBLE_ERR_WIDTH 1
555#define XM_MSK_RMTFLT_LBN 1
556#define XM_MSK_RMTFLT_WIDTH 1
557#define XM_MSK_LCLFLT_LBN 0
558#define XM_MSK_LCLFLT_WIDTH 1
559
560/* XGMAC flow control register */
561#define XM_FC_REG_MAC 0x7
562#define XM_PAUSE_TIME_LBN 16
563#define XM_PAUSE_TIME_WIDTH 16
564#define XM_DIS_FCNTL_LBN 0
565#define XM_DIS_FCNTL_WIDTH 1
566
567/* XGMAC pause time count register */
568#define XM_PAUSE_TIME_REG_MAC 0x9
569
570/* XGMAC transmit parameter register */
571#define XM_TX_PARAM_REG_MAC 0x0d
572#define XM_TX_JUMBO_MODE_LBN 31
573#define XM_TX_JUMBO_MODE_WIDTH 1
574#define XM_MAX_TX_FRM_SIZE_LBN 16
575#define XM_MAX_TX_FRM_SIZE_WIDTH 14
576
577/* XGMAC receive parameter register */
578#define XM_RX_PARAM_REG_MAC 0x0e
579#define XM_MAX_RX_FRM_SIZE_LBN 0
580#define XM_MAX_RX_FRM_SIZE_WIDTH 14
581
582/* XGMAC management interrupt status register */
583#define XM_MGT_INT_REG_MAC_B0 0x0f
584#define XM_PRMBLE_ERR 2
585#define XM_PRMBLE_WIDTH 1
586#define XM_RMTFLT_LBN 1
587#define XM_RMTFLT_WIDTH 1
588#define XM_LCLFLT_LBN 0
589#define XM_LCLFLT_WIDTH 1
590
591/* XGXS/XAUI powerdown/reset register */
592#define XX_PWR_RST_REG_MAC 0x10
593
594#define XX_PWRDND_EN_LBN 15
595#define XX_PWRDND_EN_WIDTH 1
596#define XX_PWRDNC_EN_LBN 14
597#define XX_PWRDNC_EN_WIDTH 1
598#define XX_PWRDNB_EN_LBN 13
599#define XX_PWRDNB_EN_WIDTH 1
600#define XX_PWRDNA_EN_LBN 12
601#define XX_PWRDNA_EN_WIDTH 1
602#define XX_RSTPLLCD_EN_LBN 9
603#define XX_RSTPLLCD_EN_WIDTH 1
604#define XX_RSTPLLAB_EN_LBN 8
605#define XX_RSTPLLAB_EN_WIDTH 1
606#define XX_RESETD_EN_LBN 7
607#define XX_RESETD_EN_WIDTH 1
608#define XX_RESETC_EN_LBN 6
609#define XX_RESETC_EN_WIDTH 1
610#define XX_RESETB_EN_LBN 5
611#define XX_RESETB_EN_WIDTH 1
612#define XX_RESETA_EN_LBN 4
613#define XX_RESETA_EN_WIDTH 1
614#define XX_RSTXGXSRX_EN_LBN 2
615#define XX_RSTXGXSRX_EN_WIDTH 1
616#define XX_RSTXGXSTX_EN_LBN 1
617#define XX_RSTXGXSTX_EN_WIDTH 1
618#define XX_RST_XX_EN_LBN 0
619#define XX_RST_XX_EN_WIDTH 1
620
621/* XGXS/XAUI powerdown/reset control register */
622#define XX_SD_CTL_REG_MAC 0x11
623#define XX_HIDRVD_LBN 15
624#define XX_HIDRVD_WIDTH 1
625#define XX_LODRVD_LBN 14
626#define XX_LODRVD_WIDTH 1
627#define XX_HIDRVC_LBN 13
628#define XX_HIDRVC_WIDTH 1
629#define XX_LODRVC_LBN 12
630#define XX_LODRVC_WIDTH 1
631#define XX_HIDRVB_LBN 11
632#define XX_HIDRVB_WIDTH 1
633#define XX_LODRVB_LBN 10
634#define XX_LODRVB_WIDTH 1
635#define XX_HIDRVA_LBN 9
636#define XX_HIDRVA_WIDTH 1
637#define XX_LODRVA_LBN 8
638#define XX_LODRVA_WIDTH 1
639
640#define XX_TXDRV_CTL_REG_MAC 0x12
641#define XX_DEQD_LBN 28
642#define XX_DEQD_WIDTH 4
643#define XX_DEQC_LBN 24
644#define XX_DEQC_WIDTH 4
645#define XX_DEQB_LBN 20
646#define XX_DEQB_WIDTH 4
647#define XX_DEQA_LBN 16
648#define XX_DEQA_WIDTH 4
649#define XX_DTXD_LBN 12
650#define XX_DTXD_WIDTH 4
651#define XX_DTXC_LBN 8
652#define XX_DTXC_WIDTH 4
653#define XX_DTXB_LBN 4
654#define XX_DTXB_WIDTH 4
655#define XX_DTXA_LBN 0
656#define XX_DTXA_WIDTH 4
657
658/* XAUI XGXS core status register */
659#define XX_FORCE_SIG_DECODE_FORCED 0xff
660#define XX_CORE_STAT_REG_MAC 0x16
661#define XX_ALIGN_DONE_LBN 20
662#define XX_ALIGN_DONE_WIDTH 1
663#define XX_SYNC_STAT_LBN 16
664#define XX_SYNC_STAT_WIDTH 4
665#define XX_SYNC_STAT_DECODE_SYNCED 0xf
666#define XX_COMMA_DET_LBN 12
667#define XX_COMMA_DET_WIDTH 4
668#define XX_COMMA_DET_DECODE_DETECTED 0xf
669#define XX_COMMA_DET_RESET 0xf
670#define XX_CHARERR_LBN 4
671#define XX_CHARERR_WIDTH 4
672#define XX_CHARERR_RESET 0xf
673#define XX_DISPERR_LBN 0
674#define XX_DISPERR_WIDTH 4
675#define XX_DISPERR_RESET 0xf
676
677/* Receive filter table */
678#define RX_FILTER_TBL0 0xF00000
679
680/* Receive descriptor pointer table */
681#define RX_DESC_PTR_TBL_KER_A1 0x11800
682#define RX_DESC_PTR_TBL_KER_B0 0xF40000
683#define RX_DESC_PTR_TBL_KER_P0 0x900
684#define RX_ISCSI_DDIG_EN_LBN 88
685#define RX_ISCSI_DDIG_EN_WIDTH 1
686#define RX_ISCSI_HDIG_EN_LBN 87
687#define RX_ISCSI_HDIG_EN_WIDTH 1
688#define RX_DESCQ_BUF_BASE_ID_LBN 36
689#define RX_DESCQ_BUF_BASE_ID_WIDTH 20
690#define RX_DESCQ_EVQ_ID_LBN 24
691#define RX_DESCQ_EVQ_ID_WIDTH 12
692#define RX_DESCQ_OWNER_ID_LBN 10
693#define RX_DESCQ_OWNER_ID_WIDTH 14
694#define RX_DESCQ_LABEL_LBN 5
695#define RX_DESCQ_LABEL_WIDTH 5
696#define RX_DESCQ_SIZE_LBN 3
697#define RX_DESCQ_SIZE_WIDTH 2
698#define RX_DESCQ_SIZE_4K 3
699#define RX_DESCQ_SIZE_2K 2
700#define RX_DESCQ_SIZE_1K 1
701#define RX_DESCQ_SIZE_512 0
702#define RX_DESCQ_TYPE_LBN 2
703#define RX_DESCQ_TYPE_WIDTH 1
704#define RX_DESCQ_JUMBO_LBN 1
705#define RX_DESCQ_JUMBO_WIDTH 1
706#define RX_DESCQ_EN_LBN 0
707#define RX_DESCQ_EN_WIDTH 1
708
709/* Transmit descriptor pointer table */
710#define TX_DESC_PTR_TBL_KER_A1 0x11900
711#define TX_DESC_PTR_TBL_KER_B0 0xF50000
712#define TX_DESC_PTR_TBL_KER_P0 0xa40
713#define TX_NON_IP_DROP_DIS_B0_LBN 91
714#define TX_NON_IP_DROP_DIS_B0_WIDTH 1
715#define TX_IP_CHKSM_DIS_B0_LBN 90
716#define TX_IP_CHKSM_DIS_B0_WIDTH 1
717#define TX_TCP_CHKSM_DIS_B0_LBN 89
718#define TX_TCP_CHKSM_DIS_B0_WIDTH 1
719#define TX_DESCQ_EN_LBN 88
720#define TX_DESCQ_EN_WIDTH 1
721#define TX_ISCSI_DDIG_EN_LBN 87
722#define TX_ISCSI_DDIG_EN_WIDTH 1
723#define TX_ISCSI_HDIG_EN_LBN 86
724#define TX_ISCSI_HDIG_EN_WIDTH 1
725#define TX_DESCQ_BUF_BASE_ID_LBN 36
726#define TX_DESCQ_BUF_BASE_ID_WIDTH 20
727#define TX_DESCQ_EVQ_ID_LBN 24
728#define TX_DESCQ_EVQ_ID_WIDTH 12
729#define TX_DESCQ_OWNER_ID_LBN 10
730#define TX_DESCQ_OWNER_ID_WIDTH 14
731#define TX_DESCQ_LABEL_LBN 5
732#define TX_DESCQ_LABEL_WIDTH 5
733#define TX_DESCQ_SIZE_LBN 3
734#define TX_DESCQ_SIZE_WIDTH 2
735#define TX_DESCQ_SIZE_4K 3
736#define TX_DESCQ_SIZE_2K 2
737#define TX_DESCQ_SIZE_1K 1
738#define TX_DESCQ_SIZE_512 0
739#define TX_DESCQ_TYPE_LBN 1
740#define TX_DESCQ_TYPE_WIDTH 2
741
742/* Event queue pointer */
743#define EVQ_PTR_TBL_KER_A1 0x11a00
744#define EVQ_PTR_TBL_KER_B0 0xf60000
745#define EVQ_PTR_TBL_KER_P0 0x500
746#define EVQ_EN_LBN 23
747#define EVQ_EN_WIDTH 1
748#define EVQ_SIZE_LBN 20
749#define EVQ_SIZE_WIDTH 3
750#define EVQ_SIZE_32K 6
751#define EVQ_SIZE_16K 5
752#define EVQ_SIZE_8K 4
753#define EVQ_SIZE_4K 3
754#define EVQ_SIZE_2K 2
755#define EVQ_SIZE_1K 1
756#define EVQ_SIZE_512 0
757#define EVQ_BUF_BASE_ID_LBN 0
758#define EVQ_BUF_BASE_ID_WIDTH 20
759
760/* Event queue read pointer */
761#define EVQ_RPTR_REG_KER_A1 0x11b00
762#define EVQ_RPTR_REG_KER_B0 0xfa0000
763#define EVQ_RPTR_REG_KER_DWORD (EVQ_RPTR_REG_KER + 0)
764#define EVQ_RPTR_DWORD_LBN 0
765#define EVQ_RPTR_DWORD_WIDTH 14
766
767/* RSS indirection table */
768#define RX_RSS_INDIR_TBL_B0 0xFB0000
769#define RX_RSS_INDIR_ENT_B0_LBN 0
770#define RX_RSS_INDIR_ENT_B0_WIDTH 6
771
772/* Special buffer descriptors (full-mode) */
773#define BUF_FULL_TBL_KER_A1 0x8000
774#define BUF_FULL_TBL_KER_B0 0x800000
775#define IP_DAT_BUF_SIZE_LBN 50
776#define IP_DAT_BUF_SIZE_WIDTH 1
777#define IP_DAT_BUF_SIZE_8K 1
778#define IP_DAT_BUF_SIZE_4K 0
779#define BUF_ADR_REGION_LBN 48
780#define BUF_ADR_REGION_WIDTH 2
781#define BUF_ADR_FBUF_LBN 14
782#define BUF_ADR_FBUF_WIDTH 34
783#define BUF_OWNER_ID_FBUF_LBN 0
784#define BUF_OWNER_ID_FBUF_WIDTH 14
785
786/* Transmit descriptor */
787#define TX_KER_PORT_LBN 63
788#define TX_KER_PORT_WIDTH 1
789#define TX_KER_CONT_LBN 62
790#define TX_KER_CONT_WIDTH 1
791#define TX_KER_BYTE_CNT_LBN 48
792#define TX_KER_BYTE_CNT_WIDTH 14
793#define TX_KER_BUF_REGION_LBN 46
794#define TX_KER_BUF_REGION_WIDTH 2
795#define TX_KER_BUF_REGION0_DECODE 0
796#define TX_KER_BUF_REGION1_DECODE 1
797#define TX_KER_BUF_REGION2_DECODE 2
798#define TX_KER_BUF_REGION3_DECODE 3
799#define TX_KER_BUF_ADR_LBN 0
800#define TX_KER_BUF_ADR_WIDTH EFX_DMA_TYPE_WIDTH(46)
801
802/* Receive descriptor */
803#define RX_KER_BUF_SIZE_LBN 48
804#define RX_KER_BUF_SIZE_WIDTH 14
805#define RX_KER_BUF_REGION_LBN 46
806#define RX_KER_BUF_REGION_WIDTH 2
807#define RX_KER_BUF_REGION0_DECODE 0
808#define RX_KER_BUF_REGION1_DECODE 1
809#define RX_KER_BUF_REGION2_DECODE 2
810#define RX_KER_BUF_REGION3_DECODE 3
811#define RX_KER_BUF_ADR_LBN 0
812#define RX_KER_BUF_ADR_WIDTH EFX_DMA_TYPE_WIDTH(46)
813
814/**************************************************************************
815 *
816 * Falcon events
817 *
818 **************************************************************************
819 */
820
821/* Event queue entries */
822#define EV_CODE_LBN 60
823#define EV_CODE_WIDTH 4
824#define RX_IP_EV_DECODE 0
825#define TX_IP_EV_DECODE 2
826#define DRIVER_EV_DECODE 5
827#define GLOBAL_EV_DECODE 6
828#define DRV_GEN_EV_DECODE 7
829#define WHOLE_EVENT_LBN 0
830#define WHOLE_EVENT_WIDTH 64
831
832/* Receive events */
833#define RX_EV_PKT_OK_LBN 56
834#define RX_EV_PKT_OK_WIDTH 1
835#define RX_EV_PAUSE_FRM_ERR_LBN 55
836#define RX_EV_PAUSE_FRM_ERR_WIDTH 1
837#define RX_EV_BUF_OWNER_ID_ERR_LBN 54
838#define RX_EV_BUF_OWNER_ID_ERR_WIDTH 1
839#define RX_EV_IF_FRAG_ERR_LBN 53
840#define RX_EV_IF_FRAG_ERR_WIDTH 1
841#define RX_EV_IP_HDR_CHKSUM_ERR_LBN 52
842#define RX_EV_IP_HDR_CHKSUM_ERR_WIDTH 1
843#define RX_EV_TCP_UDP_CHKSUM_ERR_LBN 51
844#define RX_EV_TCP_UDP_CHKSUM_ERR_WIDTH 1
845#define RX_EV_ETH_CRC_ERR_LBN 50
846#define RX_EV_ETH_CRC_ERR_WIDTH 1
847#define RX_EV_FRM_TRUNC_LBN 49
848#define RX_EV_FRM_TRUNC_WIDTH 1
849#define RX_EV_DRIB_NIB_LBN 48
850#define RX_EV_DRIB_NIB_WIDTH 1
851#define RX_EV_TOBE_DISC_LBN 47
852#define RX_EV_TOBE_DISC_WIDTH 1
853#define RX_EV_PKT_TYPE_LBN 44
854#define RX_EV_PKT_TYPE_WIDTH 3
855#define RX_EV_PKT_TYPE_ETH_DECODE 0
856#define RX_EV_PKT_TYPE_LLC_DECODE 1
857#define RX_EV_PKT_TYPE_JUMBO_DECODE 2
858#define RX_EV_PKT_TYPE_VLAN_DECODE 3
859#define RX_EV_PKT_TYPE_VLAN_LLC_DECODE 4
860#define RX_EV_PKT_TYPE_VLAN_JUMBO_DECODE 5
861#define RX_EV_HDR_TYPE_LBN 42
862#define RX_EV_HDR_TYPE_WIDTH 2
863#define RX_EV_HDR_TYPE_TCP_IPV4_DECODE 0
864#define RX_EV_HDR_TYPE_UDP_IPV4_DECODE 1
865#define RX_EV_HDR_TYPE_OTHER_IP_DECODE 2
866#define RX_EV_HDR_TYPE_NON_IP_DECODE 3
867#define RX_EV_HDR_TYPE_HAS_CHECKSUMS(hdr_type) \
868 ((hdr_type) <= RX_EV_HDR_TYPE_UDP_IPV4_DECODE)
869#define RX_EV_MCAST_HASH_MATCH_LBN 40
870#define RX_EV_MCAST_HASH_MATCH_WIDTH 1
871#define RX_EV_MCAST_PKT_LBN 39
872#define RX_EV_MCAST_PKT_WIDTH 1
873#define RX_EV_Q_LABEL_LBN 32
874#define RX_EV_Q_LABEL_WIDTH 5
875#define RX_EV_JUMBO_CONT_LBN 31
876#define RX_EV_JUMBO_CONT_WIDTH 1
877#define RX_EV_BYTE_CNT_LBN 16
878#define RX_EV_BYTE_CNT_WIDTH 14
879#define RX_EV_SOP_LBN 15
880#define RX_EV_SOP_WIDTH 1
881#define RX_EV_DESC_PTR_LBN 0
882#define RX_EV_DESC_PTR_WIDTH 12
883
884/* Transmit events */
885#define TX_EV_PKT_ERR_LBN 38
886#define TX_EV_PKT_ERR_WIDTH 1
887#define TX_EV_Q_LABEL_LBN 32
888#define TX_EV_Q_LABEL_WIDTH 5
889#define TX_EV_WQ_FF_FULL_LBN 15
890#define TX_EV_WQ_FF_FULL_WIDTH 1
891#define TX_EV_COMP_LBN 12
892#define TX_EV_COMP_WIDTH 1
893#define TX_EV_DESC_PTR_LBN 0
894#define TX_EV_DESC_PTR_WIDTH 12
895
896/* Driver events */
897#define DRIVER_EV_SUB_CODE_LBN 56
898#define DRIVER_EV_SUB_CODE_WIDTH 4
899#define DRIVER_EV_SUB_DATA_LBN 0
900#define DRIVER_EV_SUB_DATA_WIDTH 14
901#define TX_DESCQ_FLS_DONE_EV_DECODE 0
902#define RX_DESCQ_FLS_DONE_EV_DECODE 1
903#define EVQ_INIT_DONE_EV_DECODE 2
904#define EVQ_NOT_EN_EV_DECODE 3
905#define RX_DESCQ_FLSFF_OVFL_EV_DECODE 4
906#define SRM_UPD_DONE_EV_DECODE 5
907#define WAKE_UP_EV_DECODE 6
908#define TX_PKT_NON_TCP_UDP_DECODE 9
909#define TIMER_EV_DECODE 10
910#define RX_RECOVERY_EV_DECODE 11
911#define RX_DSC_ERROR_EV_DECODE 14
912#define TX_DSC_ERROR_EV_DECODE 15
913#define DRIVER_EV_TX_DESCQ_ID_LBN 0
914#define DRIVER_EV_TX_DESCQ_ID_WIDTH 12
915#define DRIVER_EV_RX_FLUSH_FAIL_LBN 12
916#define DRIVER_EV_RX_FLUSH_FAIL_WIDTH 1
917#define DRIVER_EV_RX_DESCQ_ID_LBN 0
918#define DRIVER_EV_RX_DESCQ_ID_WIDTH 12
919#define SRM_CLR_EV_DECODE 0
920#define SRM_UPD_EV_DECODE 1
921#define SRM_ILLCLR_EV_DECODE 2
922
923/* Global events */
924#define RX_RECOVERY_B0_LBN 12
925#define RX_RECOVERY_B0_WIDTH 1
926#define XG_MNT_INTR_B0_LBN 11
927#define XG_MNT_INTR_B0_WIDTH 1
928#define RX_RECOVERY_A1_LBN 11
929#define RX_RECOVERY_A1_WIDTH 1
930#define XG_PHY_INTR_LBN 9
931#define XG_PHY_INTR_WIDTH 1
932#define G_PHY1_INTR_LBN 8
933#define G_PHY1_INTR_WIDTH 1
934#define G_PHY0_INTR_LBN 7
935#define G_PHY0_INTR_WIDTH 1
936
937/* Driver-generated test events */
938#define EVQ_MAGIC_LBN 0
939#define EVQ_MAGIC_WIDTH 32
940
941/**************************************************************************
942 *
943 * Falcon MAC stats
944 *
945 **************************************************************************
946 *
947 */
948#define GRxGoodOct_offset 0x0
949#define GRxBadOct_offset 0x8
950#define GRxMissPkt_offset 0x10
951#define GRxFalseCRS_offset 0x14
952#define GRxPausePkt_offset 0x18
953#define GRxBadPkt_offset 0x1C
954#define GRxUcastPkt_offset 0x20
955#define GRxMcastPkt_offset 0x24
956#define GRxBcastPkt_offset 0x28
957#define GRxGoodLt64Pkt_offset 0x2C
958#define GRxBadLt64Pkt_offset 0x30
959#define GRx64Pkt_offset 0x34
960#define GRx65to127Pkt_offset 0x38
961#define GRx128to255Pkt_offset 0x3C
962#define GRx256to511Pkt_offset 0x40
963#define GRx512to1023Pkt_offset 0x44
964#define GRx1024to15xxPkt_offset 0x48
965#define GRx15xxtoJumboPkt_offset 0x4C
966#define GRxGtJumboPkt_offset 0x50
967#define GRxFcsErr64to15xxPkt_offset 0x54
968#define GRxFcsErr15xxtoJumboPkt_offset 0x58
969#define GRxFcsErrGtJumboPkt_offset 0x5C
970#define GTxGoodBadOct_offset 0x80
971#define GTxGoodOct_offset 0x88
972#define GTxSglColPkt_offset 0x90
973#define GTxMultColPkt_offset 0x94
974#define GTxExColPkt_offset 0x98
975#define GTxDefPkt_offset 0x9C
976#define GTxLateCol_offset 0xA0
977#define GTxExDefPkt_offset 0xA4
978#define GTxPausePkt_offset 0xA8
979#define GTxBadPkt_offset 0xAC
980#define GTxUcastPkt_offset 0xB0
981#define GTxMcastPkt_offset 0xB4
982#define GTxBcastPkt_offset 0xB8
983#define GTxLt64Pkt_offset 0xBC
984#define GTx64Pkt_offset 0xC0
985#define GTx65to127Pkt_offset 0xC4
986#define GTx128to255Pkt_offset 0xC8
987#define GTx256to511Pkt_offset 0xCC
988#define GTx512to1023Pkt_offset 0xD0
989#define GTx1024to15xxPkt_offset 0xD4
990#define GTx15xxtoJumboPkt_offset 0xD8
991#define GTxGtJumboPkt_offset 0xDC
992#define GTxNonTcpUdpPkt_offset 0xE0
993#define GTxMacSrcErrPkt_offset 0xE4
994#define GTxIpSrcErrPkt_offset 0xE8
995#define GDmaDone_offset 0xEC
996
997#define XgRxOctets_offset 0x0
998#define XgRxOctets_WIDTH 48
999#define XgRxOctetsOK_offset 0x8
1000#define XgRxOctetsOK_WIDTH 48
1001#define XgRxPkts_offset 0x10
1002#define XgRxPkts_WIDTH 32
1003#define XgRxPktsOK_offset 0x14
1004#define XgRxPktsOK_WIDTH 32
1005#define XgRxBroadcastPkts_offset 0x18
1006#define XgRxBroadcastPkts_WIDTH 32
1007#define XgRxMulticastPkts_offset 0x1C
1008#define XgRxMulticastPkts_WIDTH 32
1009#define XgRxUnicastPkts_offset 0x20
1010#define XgRxUnicastPkts_WIDTH 32
1011#define XgRxUndersizePkts_offset 0x24
1012#define XgRxUndersizePkts_WIDTH 32
1013#define XgRxOversizePkts_offset 0x28
1014#define XgRxOversizePkts_WIDTH 32
1015#define XgRxJabberPkts_offset 0x2C
1016#define XgRxJabberPkts_WIDTH 32
1017#define XgRxUndersizeFCSerrorPkts_offset 0x30
1018#define XgRxUndersizeFCSerrorPkts_WIDTH 32
1019#define XgRxDropEvents_offset 0x34
1020#define XgRxDropEvents_WIDTH 32
1021#define XgRxFCSerrorPkts_offset 0x38
1022#define XgRxFCSerrorPkts_WIDTH 32
1023#define XgRxAlignError_offset 0x3C
1024#define XgRxAlignError_WIDTH 32
1025#define XgRxSymbolError_offset 0x40
1026#define XgRxSymbolError_WIDTH 32
1027#define XgRxInternalMACError_offset 0x44
1028#define XgRxInternalMACError_WIDTH 32
1029#define XgRxControlPkts_offset 0x48
1030#define XgRxControlPkts_WIDTH 32
1031#define XgRxPausePkts_offset 0x4C
1032#define XgRxPausePkts_WIDTH 32
1033#define XgRxPkts64Octets_offset 0x50
1034#define XgRxPkts64Octets_WIDTH 32
1035#define XgRxPkts65to127Octets_offset 0x54
1036#define XgRxPkts65to127Octets_WIDTH 32
1037#define XgRxPkts128to255Octets_offset 0x58
1038#define XgRxPkts128to255Octets_WIDTH 32
1039#define XgRxPkts256to511Octets_offset 0x5C
1040#define XgRxPkts256to511Octets_WIDTH 32
1041#define XgRxPkts512to1023Octets_offset 0x60
1042#define XgRxPkts512to1023Octets_WIDTH 32
1043#define XgRxPkts1024to15xxOctets_offset 0x64
1044#define XgRxPkts1024to15xxOctets_WIDTH 32
1045#define XgRxPkts15xxtoMaxOctets_offset 0x68
1046#define XgRxPkts15xxtoMaxOctets_WIDTH 32
1047#define XgRxLengthError_offset 0x6C
1048#define XgRxLengthError_WIDTH 32
1049#define XgTxPkts_offset 0x80
1050#define XgTxPkts_WIDTH 32
1051#define XgTxOctets_offset 0x88
1052#define XgTxOctets_WIDTH 48
1053#define XgTxMulticastPkts_offset 0x90
1054#define XgTxMulticastPkts_WIDTH 32
1055#define XgTxBroadcastPkts_offset 0x94
1056#define XgTxBroadcastPkts_WIDTH 32
1057#define XgTxUnicastPkts_offset 0x98
1058#define XgTxUnicastPkts_WIDTH 32
1059#define XgTxControlPkts_offset 0x9C
1060#define XgTxControlPkts_WIDTH 32
1061#define XgTxPausePkts_offset 0xA0
1062#define XgTxPausePkts_WIDTH 32
1063#define XgTxPkts64Octets_offset 0xA4
1064#define XgTxPkts64Octets_WIDTH 32
1065#define XgTxPkts65to127Octets_offset 0xA8
1066#define XgTxPkts65to127Octets_WIDTH 32
1067#define XgTxPkts128to255Octets_offset 0xAC
1068#define XgTxPkts128to255Octets_WIDTH 32
1069#define XgTxPkts256to511Octets_offset 0xB0
1070#define XgTxPkts256to511Octets_WIDTH 32
1071#define XgTxPkts512to1023Octets_offset 0xB4
1072#define XgTxPkts512to1023Octets_WIDTH 32
1073#define XgTxPkts1024to15xxOctets_offset 0xB8
1074#define XgTxPkts1024to15xxOctets_WIDTH 32
1075#define XgTxPkts1519toMaxOctets_offset 0xBC
1076#define XgTxPkts1519toMaxOctets_WIDTH 32
1077#define XgTxUndersizePkts_offset 0xC0
1078#define XgTxUndersizePkts_WIDTH 32
1079#define XgTxOversizePkts_offset 0xC4
1080#define XgTxOversizePkts_WIDTH 32
1081#define XgTxNonTcpUdpPkt_offset 0xC8
1082#define XgTxNonTcpUdpPkt_WIDTH 16
1083#define XgTxMacSrcErrPkt_offset 0xCC
1084#define XgTxMacSrcErrPkt_WIDTH 16
1085#define XgTxIpSrcErrPkt_offset 0xD0
1086#define XgTxIpSrcErrPkt_WIDTH 16
1087#define XgDmaDone_offset 0xD4
1088
1089#define FALCON_STATS_NOT_DONE 0x00000000
1090#define FALCON_STATS_DONE 0xffffffff
1091
1092/* Interrupt status register bits */
1093#define FATAL_INT_LBN 64
1094#define FATAL_INT_WIDTH 1
1095#define INT_EVQS_LBN 40
1096#define INT_EVQS_WIDTH 4
1097
1098/**************************************************************************
1099 *
1100 * Falcon non-volatile configuration
1101 *
1102 **************************************************************************
1103 */
1104
1105/* Board configuration v2 (v1 is obsolete; later versions are compatible) */
1106struct falcon_nvconfig_board_v2 {
1107 __le16 nports;
1108 u8 port0_phy_addr;
1109 u8 port0_phy_type;
1110 u8 port1_phy_addr;
1111 u8 port1_phy_type;
1112 __le16 asic_sub_revision;
1113 __le16 board_revision;
1114} __attribute__ ((packed));
1115
1116#define NVCONFIG_BASE 0x300
1117#define NVCONFIG_BOARD_MAGIC_NUM 0xFA1C
1118struct falcon_nvconfig {
1119 efx_oword_t ee_vpd_cfg_reg; /* 0x300 */
1120 u8 mac_address[2][8]; /* 0x310 */
1121 efx_oword_t pcie_sd_ctl0123_reg; /* 0x320 */
1122 efx_oword_t pcie_sd_ctl45_reg; /* 0x330 */
1123 efx_oword_t pcie_pcs_ctl_stat_reg; /* 0x340 */
1124 efx_oword_t hw_init_reg; /* 0x350 */
1125 efx_oword_t nic_stat_reg; /* 0x360 */
1126 efx_oword_t glb_ctl_reg; /* 0x370 */
1127 efx_oword_t srm_cfg_reg; /* 0x380 */
1128 efx_oword_t spare_reg; /* 0x390 */
1129 __le16 board_magic_num; /* 0x3A0 */
1130 __le16 board_struct_ver;
1131 __le16 board_checksum;
1132 struct falcon_nvconfig_board_v2 board_v2;
1133} __attribute__ ((packed));
1134
1135#endif /* EFX_FALCON_HWDEFS_H */
diff --git a/drivers/net/sfc/falcon_io.h b/drivers/net/sfc/falcon_io.h
new file mode 100644
index 000000000000..ea08184ddfa9
--- /dev/null
+++ b/drivers/net/sfc/falcon_io.h
@@ -0,0 +1,243 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2006-2008 Solarflare Communications Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
11#ifndef EFX_FALCON_IO_H
12#define EFX_FALCON_IO_H
13
14#include <linux/io.h>
15#include <linux/spinlock.h>
16#include "net_driver.h"
17
18/**************************************************************************
19 *
20 * Falcon hardware access
21 *
22 **************************************************************************
23 *
24 * Notes on locking strategy:
25 *
26 * Most Falcon registers require 16-byte (or 8-byte, for SRAM
27 * registers) atomic writes which necessitates locking.
28 * Under normal operation few writes to the Falcon BAR are made and these
29 * registers (EVQ_RPTR_REG, RX_DESC_UPD_REG and TX_DESC_UPD_REG) are special
30 * cased to allow 4-byte (hence lockless) accesses.
31 *
32 * It *is* safe to write to these 4-byte registers in the middle of an
33 * access to an 8-byte or 16-byte register. We therefore use a
34 * spinlock to protect accesses to the larger registers, but no locks
35 * for the 4-byte registers.
36 *
37 * A write barrier is needed to ensure that DW3 is written after DW0/1/2
38 * due to the way the 16byte registers are "collected" in the Falcon BIU
39 *
40 * We also lock when carrying out reads, to ensure consistency of the
41 * data (made possible since the BIU reads all 128 bits into a cache).
42 * Reads are very rare, so this isn't a significant performance
43 * impact. (Most data transferred from NIC to host is DMAed directly
44 * into host memory).
45 *
46 * I/O BAR access uses locks for both reads and writes (but is only provided
47 * for testing purposes).
48 */
49
50/* Special buffer descriptors (Falcon SRAM) */
51#define BUF_TBL_KER_A1 0x18000
52#define BUF_TBL_KER_B0 0x800000
53
54
55#if BITS_PER_LONG == 64
56#define FALCON_USE_QWORD_IO 1
57#endif
58
59#define _falcon_writeq(efx, value, reg) \
60 __raw_writeq((__force u64) (value), (efx)->membase + (reg))
61#define _falcon_writel(efx, value, reg) \
62 __raw_writel((__force u32) (value), (efx)->membase + (reg))
63#define _falcon_readq(efx, reg) \
64 ((__force __le64) __raw_readq((efx)->membase + (reg)))
65#define _falcon_readl(efx, reg) \
66 ((__force __le32) __raw_readl((efx)->membase + (reg)))
67
68/* Writes to a normal 16-byte Falcon register, locking as appropriate. */
69static inline void falcon_write(struct efx_nic *efx, efx_oword_t *value,
70 unsigned int reg)
71{
72 unsigned long flags;
73
74 EFX_REGDUMP(efx, "writing register %x with " EFX_OWORD_FMT "\n", reg,
75 EFX_OWORD_VAL(*value));
76
77 spin_lock_irqsave(&efx->biu_lock, flags);
78#ifdef FALCON_USE_QWORD_IO
79 _falcon_writeq(efx, value->u64[0], reg + 0);
80 wmb();
81 _falcon_writeq(efx, value->u64[1], reg + 8);
82#else
83 _falcon_writel(efx, value->u32[0], reg + 0);
84 _falcon_writel(efx, value->u32[1], reg + 4);
85 _falcon_writel(efx, value->u32[2], reg + 8);
86 wmb();
87 _falcon_writel(efx, value->u32[3], reg + 12);
88#endif
89 mmiowb();
90 spin_unlock_irqrestore(&efx->biu_lock, flags);
91}
92
93/* Writes to an 8-byte Falcon SRAM register, locking as appropriate. */
94static inline void falcon_write_sram(struct efx_nic *efx, efx_qword_t *value,
95 unsigned int index)
96{
97 unsigned int reg = efx->type->buf_tbl_base + (index * sizeof(*value));
98 unsigned long flags;
99
100 EFX_REGDUMP(efx, "writing SRAM register %x with " EFX_QWORD_FMT "\n",
101 reg, EFX_QWORD_VAL(*value));
102
103 spin_lock_irqsave(&efx->biu_lock, flags);
104#ifdef FALCON_USE_QWORD_IO
105 _falcon_writeq(efx, value->u64[0], reg + 0);
106#else
107 _falcon_writel(efx, value->u32[0], reg + 0);
108 wmb();
109 _falcon_writel(efx, value->u32[1], reg + 4);
110#endif
111 mmiowb();
112 spin_unlock_irqrestore(&efx->biu_lock, flags);
113}
114
115/* Write dword to Falcon register that allows partial writes
116 *
117 * Some Falcon registers (EVQ_RPTR_REG, RX_DESC_UPD_REG and
118 * TX_DESC_UPD_REG) can be written to as a single dword. This allows
119 * for lockless writes.
120 */
121static inline void falcon_writel(struct efx_nic *efx, efx_dword_t *value,
122 unsigned int reg)
123{
124 EFX_REGDUMP(efx, "writing partial register %x with "EFX_DWORD_FMT"\n",
125 reg, EFX_DWORD_VAL(*value));
126
127 /* No lock required */
128 _falcon_writel(efx, value->u32[0], reg);
129}
130
131/* Read from a Falcon register
132 *
133 * This reads an entire 16-byte Falcon register in one go, locking as
134 * appropriate. It is essential to read the first dword first, as this
135 * prompts Falcon to load the current value into the shadow register.
136 */
137static inline void falcon_read(struct efx_nic *efx, efx_oword_t *value,
138 unsigned int reg)
139{
140 unsigned long flags;
141
142 spin_lock_irqsave(&efx->biu_lock, flags);
143 value->u32[0] = _falcon_readl(efx, reg + 0);
144 rmb();
145 value->u32[1] = _falcon_readl(efx, reg + 4);
146 value->u32[2] = _falcon_readl(efx, reg + 8);
147 value->u32[3] = _falcon_readl(efx, reg + 12);
148 spin_unlock_irqrestore(&efx->biu_lock, flags);
149
150 EFX_REGDUMP(efx, "read from register %x, got " EFX_OWORD_FMT "\n", reg,
151 EFX_OWORD_VAL(*value));
152}
153
154/* This reads an 8-byte Falcon SRAM entry in one go. */
155static inline void falcon_read_sram(struct efx_nic *efx, efx_qword_t *value,
156 unsigned int index)
157{
158 unsigned int reg = efx->type->buf_tbl_base + (index * sizeof(*value));
159 unsigned long flags;
160
161 spin_lock_irqsave(&efx->biu_lock, flags);
162#ifdef FALCON_USE_QWORD_IO
163 value->u64[0] = _falcon_readq(efx, reg + 0);
164#else
165 value->u32[0] = _falcon_readl(efx, reg + 0);
166 rmb();
167 value->u32[1] = _falcon_readl(efx, reg + 4);
168#endif
169 spin_unlock_irqrestore(&efx->biu_lock, flags);
170
171 EFX_REGDUMP(efx, "read from SRAM register %x, got "EFX_QWORD_FMT"\n",
172 reg, EFX_QWORD_VAL(*value));
173}
174
175/* Read dword from Falcon register that allows partial writes (sic) */
176static inline void falcon_readl(struct efx_nic *efx, efx_dword_t *value,
177 unsigned int reg)
178{
179 value->u32[0] = _falcon_readl(efx, reg);
180 EFX_REGDUMP(efx, "read from register %x, got "EFX_DWORD_FMT"\n",
181 reg, EFX_DWORD_VAL(*value));
182}
183
184/* Write to a register forming part of a table */
185static inline void falcon_write_table(struct efx_nic *efx, efx_oword_t *value,
186 unsigned int reg, unsigned int index)
187{
188 falcon_write(efx, value, reg + index * sizeof(efx_oword_t));
189}
190
191/* Read to a register forming part of a table */
192static inline void falcon_read_table(struct efx_nic *efx, efx_oword_t *value,
193 unsigned int reg, unsigned int index)
194{
195 falcon_read(efx, value, reg + index * sizeof(efx_oword_t));
196}
197
198/* Write to a dword register forming part of a table */
199static inline void falcon_writel_table(struct efx_nic *efx, efx_dword_t *value,
200 unsigned int reg, unsigned int index)
201{
202 falcon_writel(efx, value, reg + index * sizeof(efx_oword_t));
203}
204
205/* Page-mapped register block size */
206#define FALCON_PAGE_BLOCK_SIZE 0x2000
207
208/* Calculate offset to page-mapped register block */
209#define FALCON_PAGED_REG(page, reg) \
210 ((page) * FALCON_PAGE_BLOCK_SIZE + (reg))
211
212/* As for falcon_write(), but for a page-mapped register. */
213static inline void falcon_write_page(struct efx_nic *efx, efx_oword_t *value,
214 unsigned int reg, unsigned int page)
215{
216 falcon_write(efx, value, FALCON_PAGED_REG(page, reg));
217}
218
219/* As for falcon_writel(), but for a page-mapped register. */
220static inline void falcon_writel_page(struct efx_nic *efx, efx_dword_t *value,
221 unsigned int reg, unsigned int page)
222{
223 falcon_writel(efx, value, FALCON_PAGED_REG(page, reg));
224}
225
226/* Write dword to Falcon page-mapped register with an extra lock.
227 *
228 * As for falcon_writel_page(), but for a register that suffers from
229 * SFC bug 3181. Take out a lock so the BIU collector cannot be
230 * confused. */
231static inline void falcon_writel_page_locked(struct efx_nic *efx,
232 efx_dword_t *value,
233 unsigned int reg,
234 unsigned int page)
235{
236 unsigned long flags;
237
238 spin_lock_irqsave(&efx->biu_lock, flags);
239 falcon_writel(efx, value, FALCON_PAGED_REG(page, reg));
240 spin_unlock_irqrestore(&efx->biu_lock, flags);
241}
242
243#endif /* EFX_FALCON_IO_H */
diff --git a/drivers/net/sfc/falcon_xmac.c b/drivers/net/sfc/falcon_xmac.c
new file mode 100644
index 000000000000..aa7521b24a5d
--- /dev/null
+++ b/drivers/net/sfc/falcon_xmac.c
@@ -0,0 +1,585 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2006-2008 Solarflare Communications Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
11#include <linux/delay.h>
12#include "net_driver.h"
13#include "efx.h"
14#include "falcon.h"
15#include "falcon_hwdefs.h"
16#include "falcon_io.h"
17#include "mac.h"
18#include "gmii.h"
19#include "mdio_10g.h"
20#include "phy.h"
21#include "boards.h"
22#include "workarounds.h"
23
24/**************************************************************************
25 *
26 * MAC register access
27 *
28 **************************************************************************/
29
30/* Offset of an XMAC register within Falcon */
31#define FALCON_XMAC_REG(mac_reg) \
32 (FALCON_XMAC_REGBANK + ((mac_reg) * FALCON_XMAC_REG_SIZE))
33
34void falcon_xmac_writel(struct efx_nic *efx,
35 efx_dword_t *value, unsigned int mac_reg)
36{
37 efx_oword_t temp;
38
39 EFX_POPULATE_OWORD_1(temp, MAC_DATA, EFX_DWORD_FIELD(*value, MAC_DATA));
40 falcon_write(efx, &temp, FALCON_XMAC_REG(mac_reg));
41}
42
43void falcon_xmac_readl(struct efx_nic *efx,
44 efx_dword_t *value, unsigned int mac_reg)
45{
46 efx_oword_t temp;
47
48 falcon_read(efx, &temp, FALCON_XMAC_REG(mac_reg));
49 EFX_POPULATE_DWORD_1(*value, MAC_DATA, EFX_OWORD_FIELD(temp, MAC_DATA));
50}
51
52/**************************************************************************
53 *
54 * MAC operations
55 *
56 *************************************************************************/
57static int falcon_reset_xmac(struct efx_nic *efx)
58{
59 efx_dword_t reg;
60 int count;
61
62 EFX_POPULATE_DWORD_1(reg, XM_CORE_RST, 1);
63 falcon_xmac_writel(efx, &reg, XM_GLB_CFG_REG_MAC);
64
65 for (count = 0; count < 10000; count++) { /* wait upto 100ms */
66 falcon_xmac_readl(efx, &reg, XM_GLB_CFG_REG_MAC);
67 if (EFX_DWORD_FIELD(reg, XM_CORE_RST) == 0)
68 return 0;
69 udelay(10);
70 }
71
72 EFX_ERR(efx, "timed out waiting for XMAC core reset\n");
73 return -ETIMEDOUT;
74}
75
76/* Configure the XAUI driver that is an output from Falcon */
77static void falcon_setup_xaui(struct efx_nic *efx)
78{
79 efx_dword_t sdctl, txdrv;
80
81 /* Move the XAUI into low power, unless there is no PHY, in
82 * which case the XAUI will have to drive a cable. */
83 if (efx->phy_type == PHY_TYPE_NONE)
84 return;
85
86 falcon_xmac_readl(efx, &sdctl, XX_SD_CTL_REG_MAC);
87 EFX_SET_DWORD_FIELD(sdctl, XX_HIDRVD, XX_SD_CTL_DRV_DEFAULT);
88 EFX_SET_DWORD_FIELD(sdctl, XX_LODRVD, XX_SD_CTL_DRV_DEFAULT);
89 EFX_SET_DWORD_FIELD(sdctl, XX_HIDRVC, XX_SD_CTL_DRV_DEFAULT);
90 EFX_SET_DWORD_FIELD(sdctl, XX_LODRVC, XX_SD_CTL_DRV_DEFAULT);
91 EFX_SET_DWORD_FIELD(sdctl, XX_HIDRVB, XX_SD_CTL_DRV_DEFAULT);
92 EFX_SET_DWORD_FIELD(sdctl, XX_LODRVB, XX_SD_CTL_DRV_DEFAULT);
93 EFX_SET_DWORD_FIELD(sdctl, XX_HIDRVA, XX_SD_CTL_DRV_DEFAULT);
94 EFX_SET_DWORD_FIELD(sdctl, XX_LODRVA, XX_SD_CTL_DRV_DEFAULT);
95 falcon_xmac_writel(efx, &sdctl, XX_SD_CTL_REG_MAC);
96
97 EFX_POPULATE_DWORD_8(txdrv,
98 XX_DEQD, XX_TXDRV_DEQ_DEFAULT,
99 XX_DEQC, XX_TXDRV_DEQ_DEFAULT,
100 XX_DEQB, XX_TXDRV_DEQ_DEFAULT,
101 XX_DEQA, XX_TXDRV_DEQ_DEFAULT,
102 XX_DTXD, XX_TXDRV_DTX_DEFAULT,
103 XX_DTXC, XX_TXDRV_DTX_DEFAULT,
104 XX_DTXB, XX_TXDRV_DTX_DEFAULT,
105 XX_DTXA, XX_TXDRV_DTX_DEFAULT);
106 falcon_xmac_writel(efx, &txdrv, XX_TXDRV_CTL_REG_MAC);
107}
108
109static void falcon_hold_xaui_in_rst(struct efx_nic *efx)
110{
111 efx_dword_t reg;
112
113 EFX_ZERO_DWORD(reg);
114 EFX_SET_DWORD_FIELD(reg, XX_PWRDNA_EN, 1);
115 EFX_SET_DWORD_FIELD(reg, XX_PWRDNB_EN, 1);
116 EFX_SET_DWORD_FIELD(reg, XX_PWRDNC_EN, 1);
117 EFX_SET_DWORD_FIELD(reg, XX_PWRDND_EN, 1);
118 EFX_SET_DWORD_FIELD(reg, XX_RSTPLLAB_EN, 1);
119 EFX_SET_DWORD_FIELD(reg, XX_RSTPLLCD_EN, 1);
120 EFX_SET_DWORD_FIELD(reg, XX_RESETA_EN, 1);
121 EFX_SET_DWORD_FIELD(reg, XX_RESETB_EN, 1);
122 EFX_SET_DWORD_FIELD(reg, XX_RESETC_EN, 1);
123 EFX_SET_DWORD_FIELD(reg, XX_RESETD_EN, 1);
124 EFX_SET_DWORD_FIELD(reg, XX_RSTXGXSRX_EN, 1);
125 EFX_SET_DWORD_FIELD(reg, XX_RSTXGXSTX_EN, 1);
126 falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
127 udelay(10);
128}
129
130static int _falcon_reset_xaui_a(struct efx_nic *efx)
131{
132 efx_dword_t reg;
133
134 falcon_hold_xaui_in_rst(efx);
135 falcon_xmac_readl(efx, &reg, XX_PWR_RST_REG_MAC);
136
137 /* Follow the RAMBUS XAUI data reset sequencing
138 * Channels A and B first: power down, reset PLL, reset, clear
139 */
140 EFX_SET_DWORD_FIELD(reg, XX_PWRDNA_EN, 0);
141 EFX_SET_DWORD_FIELD(reg, XX_PWRDNB_EN, 0);
142 falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
143 udelay(10);
144
145 EFX_SET_DWORD_FIELD(reg, XX_RSTPLLAB_EN, 0);
146 falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
147 udelay(10);
148
149 EFX_SET_DWORD_FIELD(reg, XX_RESETA_EN, 0);
150 EFX_SET_DWORD_FIELD(reg, XX_RESETB_EN, 0);
151 falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
152 udelay(10);
153
154 /* Channels C and D: power down, reset PLL, reset, clear */
155 EFX_SET_DWORD_FIELD(reg, XX_PWRDNC_EN, 0);
156 EFX_SET_DWORD_FIELD(reg, XX_PWRDND_EN, 0);
157 falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
158 udelay(10);
159
160 EFX_SET_DWORD_FIELD(reg, XX_RSTPLLCD_EN, 0);
161 falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
162 udelay(10);
163
164 EFX_SET_DWORD_FIELD(reg, XX_RESETC_EN, 0);
165 EFX_SET_DWORD_FIELD(reg, XX_RESETD_EN, 0);
166 falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
167 udelay(10);
168
169 /* Setup XAUI */
170 falcon_setup_xaui(efx);
171 udelay(10);
172
173 /* Take XGXS out of reset */
174 EFX_ZERO_DWORD(reg);
175 falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
176 udelay(10);
177
178 return 0;
179}
180
181static int _falcon_reset_xaui_b(struct efx_nic *efx)
182{
183 efx_dword_t reg;
184 int count;
185
186 EFX_POPULATE_DWORD_1(reg, XX_RST_XX_EN, 1);
187 falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
188
189 /* Give some time for the link to establish */
190 for (count = 0; count < 1000; count++) { /* wait upto 10ms */
191 falcon_xmac_readl(efx, &reg, XX_PWR_RST_REG_MAC);
192 if (EFX_DWORD_FIELD(reg, XX_RST_XX_EN) == 0) {
193 falcon_setup_xaui(efx);
194 return 0;
195 }
196 udelay(10);
197 }
198 EFX_ERR(efx, "timed out waiting for XAUI/XGXS reset\n");
199 return -ETIMEDOUT;
200}
201
202int falcon_reset_xaui(struct efx_nic *efx)
203{
204 int rc;
205
206 if (EFX_WORKAROUND_9388(efx)) {
207 falcon_hold_xaui_in_rst(efx);
208 efx->phy_op->reset_xaui(efx);
209 rc = _falcon_reset_xaui_a(efx);
210 } else {
211 rc = _falcon_reset_xaui_b(efx);
212 }
213 return rc;
214}
215
216static int falcon_xgmii_status(struct efx_nic *efx)
217{
218 efx_dword_t reg;
219
220 if (FALCON_REV(efx) < FALCON_REV_B0)
221 return 1;
222
223 /* The ISR latches, so clear it and re-read */
224 falcon_xmac_readl(efx, &reg, XM_MGT_INT_REG_MAC_B0);
225 falcon_xmac_readl(efx, &reg, XM_MGT_INT_REG_MAC_B0);
226
227 if (EFX_DWORD_FIELD(reg, XM_LCLFLT) ||
228 EFX_DWORD_FIELD(reg, XM_RMTFLT)) {
229 EFX_INFO(efx, "MGT_INT: "EFX_DWORD_FMT"\n", EFX_DWORD_VAL(reg));
230 return 0;
231 }
232
233 return 1;
234}
235
236static void falcon_mask_status_intr(struct efx_nic *efx, int enable)
237{
238 efx_dword_t reg;
239
240 if (FALCON_REV(efx) < FALCON_REV_B0)
241 return;
242
243 /* Flush the ISR */
244 if (enable)
245 falcon_xmac_readl(efx, &reg, XM_MGT_INT_REG_MAC_B0);
246
247 EFX_POPULATE_DWORD_2(reg,
248 XM_MSK_RMTFLT, !enable,
249 XM_MSK_LCLFLT, !enable);
250 falcon_xmac_writel(efx, &reg, XM_MGT_INT_MSK_REG_MAC_B0);
251}
252
253int falcon_init_xmac(struct efx_nic *efx)
254{
255 int rc;
256
257 /* Initialize the PHY first so the clock is around */
258 rc = efx->phy_op->init(efx);
259 if (rc)
260 goto fail1;
261
262 rc = falcon_reset_xaui(efx);
263 if (rc)
264 goto fail2;
265
266 /* Wait again. Give the PHY and MAC time to come back */
267 schedule_timeout_uninterruptible(HZ / 10);
268
269 rc = falcon_reset_xmac(efx);
270 if (rc)
271 goto fail2;
272
273 falcon_mask_status_intr(efx, 1);
274 return 0;
275
276 fail2:
277 efx->phy_op->fini(efx);
278 fail1:
279 return rc;
280}
281
282int falcon_xaui_link_ok(struct efx_nic *efx)
283{
284 efx_dword_t reg;
285 int align_done, sync_status, link_ok = 0;
286
287 /* Read link status */
288 falcon_xmac_readl(efx, &reg, XX_CORE_STAT_REG_MAC);
289
290 align_done = EFX_DWORD_FIELD(reg, XX_ALIGN_DONE);
291 sync_status = EFX_DWORD_FIELD(reg, XX_SYNC_STAT);
292 if (align_done && (sync_status == XX_SYNC_STAT_DECODE_SYNCED))
293 link_ok = 1;
294
295 /* Clear link status ready for next read */
296 EFX_SET_DWORD_FIELD(reg, XX_COMMA_DET, XX_COMMA_DET_RESET);
297 EFX_SET_DWORD_FIELD(reg, XX_CHARERR, XX_CHARERR_RESET);
298 EFX_SET_DWORD_FIELD(reg, XX_DISPERR, XX_DISPERR_RESET);
299 falcon_xmac_writel(efx, &reg, XX_CORE_STAT_REG_MAC);
300
301 /* If the link is up, then check the phy side of the xaui link
302 * (error conditions from the wire side propoagate back through
303 * the phy to the xaui side). */
304 if (efx->link_up && link_ok) {
305 int has_phyxs = efx->phy_op->mmds & (1 << MDIO_MMD_PHYXS);
306 if (has_phyxs)
307 link_ok = mdio_clause45_phyxgxs_lane_sync(efx);
308 }
309
310 /* If the PHY and XAUI links are up, then check the mac's xgmii
311 * fault state */
312 if (efx->link_up && link_ok)
313 link_ok = falcon_xgmii_status(efx);
314
315 return link_ok;
316}
317
318static void falcon_reconfigure_xmac_core(struct efx_nic *efx)
319{
320 unsigned int max_frame_len;
321 efx_dword_t reg;
322 int rx_fc = (efx->flow_control & EFX_FC_RX) ? 1 : 0;
323
324 /* Configure MAC - cut-thru mode is hard wired on */
325 EFX_POPULATE_DWORD_3(reg,
326 XM_RX_JUMBO_MODE, 1,
327 XM_TX_STAT_EN, 1,
328 XM_RX_STAT_EN, 1);
329 falcon_xmac_writel(efx, &reg, XM_GLB_CFG_REG_MAC);
330
331 /* Configure TX */
332 EFX_POPULATE_DWORD_6(reg,
333 XM_TXEN, 1,
334 XM_TX_PRMBL, 1,
335 XM_AUTO_PAD, 1,
336 XM_TXCRC, 1,
337 XM_FCNTL, 1,
338 XM_IPG, 0x3);
339 falcon_xmac_writel(efx, &reg, XM_TX_CFG_REG_MAC);
340
341 /* Configure RX */
342 EFX_POPULATE_DWORD_5(reg,
343 XM_RXEN, 1,
344 XM_AUTO_DEPAD, 0,
345 XM_ACPT_ALL_MCAST, 1,
346 XM_ACPT_ALL_UCAST, efx->promiscuous,
347 XM_PASS_CRC_ERR, 1);
348 falcon_xmac_writel(efx, &reg, XM_RX_CFG_REG_MAC);
349
350 /* Set frame length */
351 max_frame_len = EFX_MAX_FRAME_LEN(efx->net_dev->mtu);
352 EFX_POPULATE_DWORD_1(reg, XM_MAX_RX_FRM_SIZE, max_frame_len);
353 falcon_xmac_writel(efx, &reg, XM_RX_PARAM_REG_MAC);
354 EFX_POPULATE_DWORD_2(reg,
355 XM_MAX_TX_FRM_SIZE, max_frame_len,
356 XM_TX_JUMBO_MODE, 1);
357 falcon_xmac_writel(efx, &reg, XM_TX_PARAM_REG_MAC);
358
359 EFX_POPULATE_DWORD_2(reg,
360 XM_PAUSE_TIME, 0xfffe, /* MAX PAUSE TIME */
361 XM_DIS_FCNTL, rx_fc ? 0 : 1);
362 falcon_xmac_writel(efx, &reg, XM_FC_REG_MAC);
363
364 /* Set MAC address */
365 EFX_POPULATE_DWORD_4(reg,
366 XM_ADR_0, efx->net_dev->dev_addr[0],
367 XM_ADR_1, efx->net_dev->dev_addr[1],
368 XM_ADR_2, efx->net_dev->dev_addr[2],
369 XM_ADR_3, efx->net_dev->dev_addr[3]);
370 falcon_xmac_writel(efx, &reg, XM_ADR_LO_REG_MAC);
371 EFX_POPULATE_DWORD_2(reg,
372 XM_ADR_4, efx->net_dev->dev_addr[4],
373 XM_ADR_5, efx->net_dev->dev_addr[5]);
374 falcon_xmac_writel(efx, &reg, XM_ADR_HI_REG_MAC);
375}
376
377/* Try and bring the Falcon side of the Falcon-Phy XAUI link fails
378 * to come back up. Bash it until it comes back up */
379static int falcon_check_xaui_link_up(struct efx_nic *efx)
380{
381 int max_tries, tries;
382 tries = EFX_WORKAROUND_5147(efx) ? 5 : 1;
383 max_tries = tries;
384
385 if (efx->phy_type == PHY_TYPE_NONE)
386 return 0;
387
388 while (tries) {
389 if (falcon_xaui_link_ok(efx))
390 return 1;
391
392 EFX_LOG(efx, "%s Clobbering XAUI (%d tries left).\n",
393 __func__, tries);
394 (void) falcon_reset_xaui(efx);
395 udelay(200);
396 tries--;
397 }
398
399 EFX_ERR(efx, "Failed to bring XAUI link back up in %d tries!\n",
400 max_tries);
401 return 0;
402}
403
404void falcon_reconfigure_xmac(struct efx_nic *efx)
405{
406 int xaui_link_ok;
407
408 falcon_mask_status_intr(efx, 0);
409
410 falcon_deconfigure_mac_wrapper(efx);
411 efx->phy_op->reconfigure(efx);
412 falcon_reconfigure_xmac_core(efx);
413 falcon_reconfigure_mac_wrapper(efx);
414
415 /* Ensure XAUI link is up */
416 xaui_link_ok = falcon_check_xaui_link_up(efx);
417
418 if (xaui_link_ok && efx->link_up)
419 falcon_mask_status_intr(efx, 1);
420}
421
422void falcon_fini_xmac(struct efx_nic *efx)
423{
424 /* Isolate the MAC - PHY */
425 falcon_deconfigure_mac_wrapper(efx);
426
427 /* Potentially power down the PHY */
428 efx->phy_op->fini(efx);
429}
430
431void falcon_update_stats_xmac(struct efx_nic *efx)
432{
433 struct efx_mac_stats *mac_stats = &efx->mac_stats;
434 int rc;
435
436 rc = falcon_dma_stats(efx, XgDmaDone_offset);
437 if (rc)
438 return;
439
440 /* Update MAC stats from DMAed values */
441 FALCON_STAT(efx, XgRxOctets, rx_bytes);
442 FALCON_STAT(efx, XgRxOctetsOK, rx_good_bytes);
443 FALCON_STAT(efx, XgRxPkts, rx_packets);
444 FALCON_STAT(efx, XgRxPktsOK, rx_good);
445 FALCON_STAT(efx, XgRxBroadcastPkts, rx_broadcast);
446 FALCON_STAT(efx, XgRxMulticastPkts, rx_multicast);
447 FALCON_STAT(efx, XgRxUnicastPkts, rx_unicast);
448 FALCON_STAT(efx, XgRxUndersizePkts, rx_lt64);
449 FALCON_STAT(efx, XgRxOversizePkts, rx_gtjumbo);
450 FALCON_STAT(efx, XgRxJabberPkts, rx_bad_gtjumbo);
451 FALCON_STAT(efx, XgRxUndersizeFCSerrorPkts, rx_bad_lt64);
452 FALCON_STAT(efx, XgRxDropEvents, rx_overflow);
453 FALCON_STAT(efx, XgRxFCSerrorPkts, rx_bad);
454 FALCON_STAT(efx, XgRxAlignError, rx_align_error);
455 FALCON_STAT(efx, XgRxSymbolError, rx_symbol_error);
456 FALCON_STAT(efx, XgRxInternalMACError, rx_internal_error);
457 FALCON_STAT(efx, XgRxControlPkts, rx_control);
458 FALCON_STAT(efx, XgRxPausePkts, rx_pause);
459 FALCON_STAT(efx, XgRxPkts64Octets, rx_64);
460 FALCON_STAT(efx, XgRxPkts65to127Octets, rx_65_to_127);
461 FALCON_STAT(efx, XgRxPkts128to255Octets, rx_128_to_255);
462 FALCON_STAT(efx, XgRxPkts256to511Octets, rx_256_to_511);
463 FALCON_STAT(efx, XgRxPkts512to1023Octets, rx_512_to_1023);
464 FALCON_STAT(efx, XgRxPkts1024to15xxOctets, rx_1024_to_15xx);
465 FALCON_STAT(efx, XgRxPkts15xxtoMaxOctets, rx_15xx_to_jumbo);
466 FALCON_STAT(efx, XgRxLengthError, rx_length_error);
467 FALCON_STAT(efx, XgTxPkts, tx_packets);
468 FALCON_STAT(efx, XgTxOctets, tx_bytes);
469 FALCON_STAT(efx, XgTxMulticastPkts, tx_multicast);
470 FALCON_STAT(efx, XgTxBroadcastPkts, tx_broadcast);
471 FALCON_STAT(efx, XgTxUnicastPkts, tx_unicast);
472 FALCON_STAT(efx, XgTxControlPkts, tx_control);
473 FALCON_STAT(efx, XgTxPausePkts, tx_pause);
474 FALCON_STAT(efx, XgTxPkts64Octets, tx_64);
475 FALCON_STAT(efx, XgTxPkts65to127Octets, tx_65_to_127);
476 FALCON_STAT(efx, XgTxPkts128to255Octets, tx_128_to_255);
477 FALCON_STAT(efx, XgTxPkts256to511Octets, tx_256_to_511);
478 FALCON_STAT(efx, XgTxPkts512to1023Octets, tx_512_to_1023);
479 FALCON_STAT(efx, XgTxPkts1024to15xxOctets, tx_1024_to_15xx);
480 FALCON_STAT(efx, XgTxPkts1519toMaxOctets, tx_15xx_to_jumbo);
481 FALCON_STAT(efx, XgTxUndersizePkts, tx_lt64);
482 FALCON_STAT(efx, XgTxOversizePkts, tx_gtjumbo);
483 FALCON_STAT(efx, XgTxNonTcpUdpPkt, tx_non_tcpudp);
484 FALCON_STAT(efx, XgTxMacSrcErrPkt, tx_mac_src_error);
485 FALCON_STAT(efx, XgTxIpSrcErrPkt, tx_ip_src_error);
486
487 /* Update derived statistics */
488 mac_stats->tx_good_bytes =
489 (mac_stats->tx_bytes - mac_stats->tx_bad_bytes);
490 mac_stats->rx_bad_bytes =
491 (mac_stats->rx_bytes - mac_stats->rx_good_bytes);
492}
493
494#define EFX_XAUI_RETRAIN_MAX 8
495
496int falcon_check_xmac(struct efx_nic *efx)
497{
498 unsigned xaui_link_ok;
499 int rc;
500
501 falcon_mask_status_intr(efx, 0);
502 xaui_link_ok = falcon_xaui_link_ok(efx);
503
504 if (EFX_WORKAROUND_5147(efx) && !xaui_link_ok)
505 (void) falcon_reset_xaui(efx);
506
507 /* Call the PHY check_hw routine */
508 rc = efx->phy_op->check_hw(efx);
509
510 /* Unmask interrupt if everything was (and still is) ok */
511 if (xaui_link_ok && efx->link_up)
512 falcon_mask_status_intr(efx, 1);
513
514 return rc;
515}
516
517/* Simulate a PHY event */
518void falcon_xmac_sim_phy_event(struct efx_nic *efx)
519{
520 efx_qword_t phy_event;
521
522 EFX_POPULATE_QWORD_2(phy_event,
523 EV_CODE, GLOBAL_EV_DECODE,
524 XG_PHY_INTR, 1);
525 falcon_generate_event(&efx->channel[0], &phy_event);
526}
527
528int falcon_xmac_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
529{
530 mdio_clause45_get_settings(efx, ecmd);
531 ecmd->transceiver = XCVR_INTERNAL;
532 ecmd->phy_address = efx->mii.phy_id;
533 ecmd->autoneg = AUTONEG_DISABLE;
534 ecmd->duplex = DUPLEX_FULL;
535 return 0;
536}
537
538int falcon_xmac_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
539{
540 if (ecmd->transceiver != XCVR_INTERNAL)
541 return -EINVAL;
542 if (ecmd->autoneg != AUTONEG_DISABLE)
543 return -EINVAL;
544 if (ecmd->duplex != DUPLEX_FULL)
545 return -EINVAL;
546
547 return mdio_clause45_set_settings(efx, ecmd);
548}
549
550
551int falcon_xmac_set_pause(struct efx_nic *efx, enum efx_fc_type flow_control)
552{
553 int reset;
554
555 if (flow_control & EFX_FC_AUTO) {
556 EFX_LOG(efx, "10G does not support flow control "
557 "autonegotiation\n");
558 return -EINVAL;
559 }
560
561 if ((flow_control & EFX_FC_TX) && !(flow_control & EFX_FC_RX))
562 return -EINVAL;
563
564 /* TX flow control may automatically turn itself off if the
565 * link partner (intermittently) stops responding to pause
566 * frames. There isn't any indication that this has happened,
567 * so the best we do is leave it up to the user to spot this
568 * and fix it be cycling transmit flow control on this end. */
569 reset = ((flow_control & EFX_FC_TX) &&
570 !(efx->flow_control & EFX_FC_TX));
571 if (EFX_WORKAROUND_11482(efx) && reset) {
572 if (FALCON_REV(efx) >= FALCON_REV_B0) {
573 /* Recover by resetting the EM block */
574 if (efx->link_up)
575 falcon_drain_tx_fifo(efx);
576 } else {
577 /* Schedule a reset to recover */
578 efx_schedule_reset(efx, RESET_TYPE_INVISIBLE);
579 }
580 }
581
582 efx->flow_control = flow_control;
583
584 return 0;
585}
diff --git a/drivers/net/sfc/gmii.h b/drivers/net/sfc/gmii.h
new file mode 100644
index 000000000000..d25bbd1297f4
--- /dev/null
+++ b/drivers/net/sfc/gmii.h
@@ -0,0 +1,195 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2006 Solarflare Communications Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
11#ifndef EFX_GMII_H
12#define EFX_GMII_H
13
14/*
15 * GMII interface
16 */
17
18#include <linux/mii.h>
19
20/* GMII registers, excluding registers already defined as MII
21 * registers in mii.h
22 */
23#define GMII_IER 0x12 /* Interrupt enable register */
24#define GMII_ISR 0x13 /* Interrupt status register */
25
26/* Interrupt enable register */
27#define IER_ANEG_ERR 0x8000 /* Bit 15 - autonegotiation error */
28#define IER_SPEED_CHG 0x4000 /* Bit 14 - speed changed */
29#define IER_DUPLEX_CHG 0x2000 /* Bit 13 - duplex changed */
30#define IER_PAGE_RCVD 0x1000 /* Bit 12 - page received */
31#define IER_ANEG_DONE 0x0800 /* Bit 11 - autonegotiation complete */
32#define IER_LINK_CHG 0x0400 /* Bit 10 - link status changed */
33#define IER_SYM_ERR 0x0200 /* Bit 9 - symbol error */
34#define IER_FALSE_CARRIER 0x0100 /* Bit 8 - false carrier */
35#define IER_FIFO_ERR 0x0080 /* Bit 7 - FIFO over/underflow */
36#define IER_MDIX_CHG 0x0040 /* Bit 6 - MDI crossover changed */
37#define IER_DOWNSHIFT 0x0020 /* Bit 5 - downshift */
38#define IER_ENERGY 0x0010 /* Bit 4 - energy detect */
39#define IER_DTE_POWER 0x0004 /* Bit 2 - DTE power detect */
40#define IER_POLARITY_CHG 0x0002 /* Bit 1 - polarity changed */
41#define IER_JABBER 0x0001 /* Bit 0 - jabber */
42
43/* Interrupt status register */
44#define ISR_ANEG_ERR 0x8000 /* Bit 15 - autonegotiation error */
45#define ISR_SPEED_CHG 0x4000 /* Bit 14 - speed changed */
46#define ISR_DUPLEX_CHG 0x2000 /* Bit 13 - duplex changed */
47#define ISR_PAGE_RCVD 0x1000 /* Bit 12 - page received */
48#define ISR_ANEG_DONE 0x0800 /* Bit 11 - autonegotiation complete */
49#define ISR_LINK_CHG 0x0400 /* Bit 10 - link status changed */
50#define ISR_SYM_ERR 0x0200 /* Bit 9 - symbol error */
51#define ISR_FALSE_CARRIER 0x0100 /* Bit 8 - false carrier */
52#define ISR_FIFO_ERR 0x0080 /* Bit 7 - FIFO over/underflow */
53#define ISR_MDIX_CHG 0x0040 /* Bit 6 - MDI crossover changed */
54#define ISR_DOWNSHIFT 0x0020 /* Bit 5 - downshift */
55#define ISR_ENERGY 0x0010 /* Bit 4 - energy detect */
56#define ISR_DTE_POWER 0x0004 /* Bit 2 - DTE power detect */
57#define ISR_POLARITY_CHG 0x0002 /* Bit 1 - polarity changed */
58#define ISR_JABBER 0x0001 /* Bit 0 - jabber */
59
60/* Logically extended advertisement register */
61#define GM_ADVERTISE_SLCT ADVERTISE_SLCT
62#define GM_ADVERTISE_CSMA ADVERTISE_CSMA
63#define GM_ADVERTISE_10HALF ADVERTISE_10HALF
64#define GM_ADVERTISE_1000XFULL ADVERTISE_1000XFULL
65#define GM_ADVERTISE_10FULL ADVERTISE_10FULL
66#define GM_ADVERTISE_1000XHALF ADVERTISE_1000XHALF
67#define GM_ADVERTISE_100HALF ADVERTISE_100HALF
68#define GM_ADVERTISE_1000XPAUSE ADVERTISE_1000XPAUSE
69#define GM_ADVERTISE_100FULL ADVERTISE_100FULL
70#define GM_ADVERTISE_1000XPSE_ASYM ADVERTISE_1000XPSE_ASYM
71#define GM_ADVERTISE_100BASE4 ADVERTISE_100BASE4
72#define GM_ADVERTISE_PAUSE_CAP ADVERTISE_PAUSE_CAP
73#define GM_ADVERTISE_PAUSE_ASYM ADVERTISE_PAUSE_ASYM
74#define GM_ADVERTISE_RESV ADVERTISE_RESV
75#define GM_ADVERTISE_RFAULT ADVERTISE_RFAULT
76#define GM_ADVERTISE_LPACK ADVERTISE_LPACK
77#define GM_ADVERTISE_NPAGE ADVERTISE_NPAGE
78#define GM_ADVERTISE_1000FULL (ADVERTISE_1000FULL << 8)
79#define GM_ADVERTISE_1000HALF (ADVERTISE_1000HALF << 8)
80#define GM_ADVERTISE_1000 (GM_ADVERTISE_1000FULL | \
81 GM_ADVERTISE_1000HALF)
82#define GM_ADVERTISE_FULL (GM_ADVERTISE_1000FULL | \
83 ADVERTISE_FULL)
84#define GM_ADVERTISE_ALL (GM_ADVERTISE_1000FULL | \
85 GM_ADVERTISE_1000HALF | \
86 ADVERTISE_ALL)
87
88/* Logically extended link partner ability register */
89#define GM_LPA_SLCT LPA_SLCT
90#define GM_LPA_10HALF LPA_10HALF
91#define GM_LPA_1000XFULL LPA_1000XFULL
92#define GM_LPA_10FULL LPA_10FULL
93#define GM_LPA_1000XHALF LPA_1000XHALF
94#define GM_LPA_100HALF LPA_100HALF
95#define GM_LPA_1000XPAUSE LPA_1000XPAUSE
96#define GM_LPA_100FULL LPA_100FULL
97#define GM_LPA_1000XPAUSE_ASYM LPA_1000XPAUSE_ASYM
98#define GM_LPA_100BASE4 LPA_100BASE4
99#define GM_LPA_PAUSE_CAP LPA_PAUSE_CAP
100#define GM_LPA_PAUSE_ASYM LPA_PAUSE_ASYM
101#define GM_LPA_RESV LPA_RESV
102#define GM_LPA_RFAULT LPA_RFAULT
103#define GM_LPA_LPACK LPA_LPACK
104#define GM_LPA_NPAGE LPA_NPAGE
105#define GM_LPA_1000FULL (LPA_1000FULL << 6)
106#define GM_LPA_1000HALF (LPA_1000HALF << 6)
107#define GM_LPA_10000FULL 0x00040000
108#define GM_LPA_10000HALF 0x00080000
109#define GM_LPA_DUPLEX (GM_LPA_1000FULL | GM_LPA_10000FULL \
110 | LPA_DUPLEX)
111#define GM_LPA_10 (LPA_10FULL | LPA_10HALF)
112#define GM_LPA_100 LPA_100
113#define GM_LPA_1000 (GM_LPA_1000FULL | GM_LPA_1000HALF)
114#define GM_LPA_10000 (GM_LPA_10000FULL | GM_LPA_10000HALF)
115
116/* Retrieve GMII autonegotiation advertised abilities
117 *
118 * The MII advertisment register (MII_ADVERTISE) is logically extended
119 * to include advertisement bits ADVERTISE_1000FULL and
120 * ADVERTISE_1000HALF from MII_CTRL1000. The result can be tested
121 * against the GM_ADVERTISE_xxx constants.
122 */
123static inline unsigned int gmii_advertised(struct mii_if_info *gmii)
124{
125 unsigned int advertise;
126 unsigned int ctrl1000;
127
128 advertise = gmii->mdio_read(gmii->dev, gmii->phy_id, MII_ADVERTISE);
129 ctrl1000 = gmii->mdio_read(gmii->dev, gmii->phy_id, MII_CTRL1000);
130 return (((ctrl1000 << 8) & GM_ADVERTISE_1000) | advertise);
131}
132
133/* Retrieve GMII autonegotiation link partner abilities
134 *
135 * The MII link partner ability register (MII_LPA) is logically
136 * extended by adding bits LPA_1000HALF and LPA_1000FULL from
137 * MII_STAT1000. The result can be tested against the GM_LPA_xxx
138 * constants.
139 */
140static inline unsigned int gmii_lpa(struct mii_if_info *gmii)
141{
142 unsigned int lpa;
143 unsigned int stat1000;
144
145 lpa = gmii->mdio_read(gmii->dev, gmii->phy_id, MII_LPA);
146 stat1000 = gmii->mdio_read(gmii->dev, gmii->phy_id, MII_STAT1000);
147 return (((stat1000 << 6) & GM_LPA_1000) | lpa);
148}
149
150/* Calculate GMII autonegotiated link technology
151 *
152 * "negotiated" should be the result of gmii_advertised() logically
153 * ANDed with the result of gmii_lpa().
154 *
155 * "tech" will be negotiated with the unused bits masked out. For
156 * example, if both ends of the link are capable of both
157 * GM_LPA_1000FULL and GM_LPA_100FULL, GM_LPA_100FULL will be masked
158 * out.
159 */
160static inline unsigned int gmii_nway_result(unsigned int negotiated)
161{
162 unsigned int other_bits;
163
164 /* Mask out the speed and duplexity bits */
165 other_bits = negotiated & ~(GM_LPA_10 | GM_LPA_100 | GM_LPA_1000);
166
167 if (negotiated & GM_LPA_1000FULL)
168 return (other_bits | GM_LPA_1000FULL);
169 else if (negotiated & GM_LPA_1000HALF)
170 return (other_bits | GM_LPA_1000HALF);
171 else
172 return (other_bits | mii_nway_result(negotiated));
173}
174
175/* Calculate GMII non-autonegotiated link technology
176 *
177 * This provides an equivalent to gmii_nway_result for the case when
178 * autonegotiation is disabled.
179 */
180static inline unsigned int gmii_forced_result(unsigned int bmcr)
181{
182 unsigned int result;
183 int full_duplex;
184
185 full_duplex = bmcr & BMCR_FULLDPLX;
186 if (bmcr & BMCR_SPEED1000)
187 result = full_duplex ? GM_LPA_1000FULL : GM_LPA_1000HALF;
188 else if (bmcr & BMCR_SPEED100)
189 result = full_duplex ? GM_LPA_100FULL : GM_LPA_100HALF;
190 else
191 result = full_duplex ? GM_LPA_10FULL : GM_LPA_10HALF;
192 return result;
193}
194
195#endif /* EFX_GMII_H */
diff --git a/drivers/net/sfc/i2c-direct.c b/drivers/net/sfc/i2c-direct.c
new file mode 100644
index 000000000000..b6c62d0ed9c2
--- /dev/null
+++ b/drivers/net/sfc/i2c-direct.c
@@ -0,0 +1,381 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005 Fen Systems Ltd.
4 * Copyright 2006-2008 Solarflare Communications Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
11#include <linux/delay.h>
12#include "net_driver.h"
13#include "i2c-direct.h"
14
15/*
16 * I2C data (SDA) and clock (SCL) line read/writes with appropriate
17 * delays.
18 */
19
20static inline void setsda(struct efx_i2c_interface *i2c, int state)
21{
22 udelay(i2c->op->udelay);
23 i2c->sda = state;
24 i2c->op->setsda(i2c);
25 udelay(i2c->op->udelay);
26}
27
28static inline void setscl(struct efx_i2c_interface *i2c, int state)
29{
30 udelay(i2c->op->udelay);
31 i2c->scl = state;
32 i2c->op->setscl(i2c);
33 udelay(i2c->op->udelay);
34}
35
36static inline int getsda(struct efx_i2c_interface *i2c)
37{
38 int sda;
39
40 udelay(i2c->op->udelay);
41 sda = i2c->op->getsda(i2c);
42 udelay(i2c->op->udelay);
43 return sda;
44}
45
46static inline int getscl(struct efx_i2c_interface *i2c)
47{
48 int scl;
49
50 udelay(i2c->op->udelay);
51 scl = i2c->op->getscl(i2c);
52 udelay(i2c->op->udelay);
53 return scl;
54}
55
56/*
57 * I2C low-level protocol operations
58 *
59 */
60
61static inline void i2c_release(struct efx_i2c_interface *i2c)
62{
63 EFX_WARN_ON_PARANOID(!i2c->scl);
64 EFX_WARN_ON_PARANOID(!i2c->sda);
65 /* Devices may time out if operations do not end */
66 setscl(i2c, 1);
67 setsda(i2c, 1);
68 EFX_BUG_ON_PARANOID(getsda(i2c) != 1);
69 EFX_BUG_ON_PARANOID(getscl(i2c) != 1);
70}
71
72static inline void i2c_start(struct efx_i2c_interface *i2c)
73{
74 /* We may be restarting immediately after a {send,recv}_bit,
75 * so SCL will not necessarily already be high.
76 */
77 EFX_WARN_ON_PARANOID(!i2c->sda);
78 setscl(i2c, 1);
79 setsda(i2c, 0);
80 setscl(i2c, 0);
81 setsda(i2c, 1);
82}
83
84static inline void i2c_send_bit(struct efx_i2c_interface *i2c, int bit)
85{
86 EFX_WARN_ON_PARANOID(i2c->scl != 0);
87 setsda(i2c, bit);
88 setscl(i2c, 1);
89 setscl(i2c, 0);
90 setsda(i2c, 1);
91}
92
93static inline int i2c_recv_bit(struct efx_i2c_interface *i2c)
94{
95 int bit;
96
97 EFX_WARN_ON_PARANOID(i2c->scl != 0);
98 EFX_WARN_ON_PARANOID(!i2c->sda);
99 setscl(i2c, 1);
100 bit = getsda(i2c);
101 setscl(i2c, 0);
102 return bit;
103}
104
105static inline void i2c_stop(struct efx_i2c_interface *i2c)
106{
107 EFX_WARN_ON_PARANOID(i2c->scl != 0);
108 setsda(i2c, 0);
109 setscl(i2c, 1);
110 setsda(i2c, 1);
111}
112
113/*
114 * I2C mid-level protocol operations
115 *
116 */
117
118/* Sends a byte via the I2C bus and checks for an acknowledgement from
119 * the slave device.
120 */
121static int i2c_send_byte(struct efx_i2c_interface *i2c, u8 byte)
122{
123 int i;
124
125 /* Send byte */
126 for (i = 0; i < 8; i++) {
127 i2c_send_bit(i2c, !!(byte & 0x80));
128 byte <<= 1;
129 }
130
131 /* Check for acknowledgement from slave */
132 return (i2c_recv_bit(i2c) == 0 ? 0 : -EIO);
133}
134
135/* Receives a byte via the I2C bus and sends ACK/NACK to the slave device. */
136static u8 i2c_recv_byte(struct efx_i2c_interface *i2c, int ack)
137{
138 u8 value = 0;
139 int i;
140
141 /* Receive byte */
142 for (i = 0; i < 8; i++)
143 value = (value << 1) | i2c_recv_bit(i2c);
144
145 /* Send ACK/NACK */
146 i2c_send_bit(i2c, (ack ? 0 : 1));
147
148 return value;
149}
150
151/* Calculate command byte for a read operation */
152static inline u8 i2c_read_cmd(u8 device_id)
153{
154 return ((device_id << 1) | 1);
155}
156
157/* Calculate command byte for a write operation */
158static inline u8 i2c_write_cmd(u8 device_id)
159{
160 return ((device_id << 1) | 0);
161}
162
163int efx_i2c_check_presence(struct efx_i2c_interface *i2c, u8 device_id)
164{
165 int rc;
166
167 /* If someone is driving the bus low we just give up. */
168 if (getsda(i2c) == 0 || getscl(i2c) == 0) {
169 EFX_ERR(i2c->efx, "%s someone is holding the I2C bus low."
170 " Giving up.\n", __func__);
171 return -EFAULT;
172 }
173
174 /* Pretend to initiate a device write */
175 i2c_start(i2c);
176 rc = i2c_send_byte(i2c, i2c_write_cmd(device_id));
177 if (rc)
178 goto out;
179
180 out:
181 i2c_stop(i2c);
182 i2c_release(i2c);
183
184 return rc;
185}
186
187/* This performs a fast read of one or more consecutive bytes from an
188 * I2C device. Not all devices support consecutive reads of more than
189 * one byte; for these devices use efx_i2c_read() instead.
190 */
191int efx_i2c_fast_read(struct efx_i2c_interface *i2c,
192 u8 device_id, u8 offset, u8 *data, unsigned int len)
193{
194 int i;
195 int rc;
196
197 EFX_WARN_ON_PARANOID(getsda(i2c) != 1);
198 EFX_WARN_ON_PARANOID(getscl(i2c) != 1);
199 EFX_WARN_ON_PARANOID(data == NULL);
200 EFX_WARN_ON_PARANOID(len < 1);
201
202 /* Select device and starting offset */
203 i2c_start(i2c);
204 rc = i2c_send_byte(i2c, i2c_write_cmd(device_id));
205 if (rc)
206 goto out;
207 rc = i2c_send_byte(i2c, offset);
208 if (rc)
209 goto out;
210
211 /* Read data from device */
212 i2c_start(i2c);
213 rc = i2c_send_byte(i2c, i2c_read_cmd(device_id));
214 if (rc)
215 goto out;
216 for (i = 0; i < (len - 1); i++)
217 /* Read and acknowledge all but the last byte */
218 data[i] = i2c_recv_byte(i2c, 1);
219 /* Read last byte with no acknowledgement */
220 data[i] = i2c_recv_byte(i2c, 0);
221
222 out:
223 i2c_stop(i2c);
224 i2c_release(i2c);
225
226 return rc;
227}
228
229/* This performs a fast write of one or more consecutive bytes to an
230 * I2C device. Not all devices support consecutive writes of more
231 * than one byte; for these devices use efx_i2c_write() instead.
232 */
233int efx_i2c_fast_write(struct efx_i2c_interface *i2c,
234 u8 device_id, u8 offset,
235 const u8 *data, unsigned int len)
236{
237 int i;
238 int rc;
239
240 EFX_WARN_ON_PARANOID(getsda(i2c) != 1);
241 EFX_WARN_ON_PARANOID(getscl(i2c) != 1);
242 EFX_WARN_ON_PARANOID(len < 1);
243
244 /* Select device and starting offset */
245 i2c_start(i2c);
246 rc = i2c_send_byte(i2c, i2c_write_cmd(device_id));
247 if (rc)
248 goto out;
249 rc = i2c_send_byte(i2c, offset);
250 if (rc)
251 goto out;
252
253 /* Write data to device */
254 for (i = 0; i < len; i++) {
255 rc = i2c_send_byte(i2c, data[i]);
256 if (rc)
257 goto out;
258 }
259
260 out:
261 i2c_stop(i2c);
262 i2c_release(i2c);
263
264 return rc;
265}
266
267/* I2C byte-by-byte read */
268int efx_i2c_read(struct efx_i2c_interface *i2c,
269 u8 device_id, u8 offset, u8 *data, unsigned int len)
270{
271 int rc;
272
273 /* i2c_fast_read with length 1 is a single byte read */
274 for (; len > 0; offset++, data++, len--) {
275 rc = efx_i2c_fast_read(i2c, device_id, offset, data, 1);
276 if (rc)
277 return rc;
278 }
279
280 return 0;
281}
282
283/* I2C byte-by-byte write */
284int efx_i2c_write(struct efx_i2c_interface *i2c,
285 u8 device_id, u8 offset, const u8 *data, unsigned int len)
286{
287 int rc;
288
289 /* i2c_fast_write with length 1 is a single byte write */
290 for (; len > 0; offset++, data++, len--) {
291 rc = efx_i2c_fast_write(i2c, device_id, offset, data, 1);
292 if (rc)
293 return rc;
294 mdelay(i2c->op->mdelay);
295 }
296
297 return 0;
298}
299
300
301/* This is just a slightly neater wrapper round efx_i2c_fast_write
302 * in the case where the target doesn't take an offset
303 */
304int efx_i2c_send_bytes(struct efx_i2c_interface *i2c,
305 u8 device_id, const u8 *data, unsigned int len)
306{
307 return efx_i2c_fast_write(i2c, device_id, data[0], data + 1, len - 1);
308}
309
310/* I2C receiving of bytes - does not send an offset byte */
311int efx_i2c_recv_bytes(struct efx_i2c_interface *i2c, u8 device_id,
312 u8 *bytes, unsigned int len)
313{
314 int i;
315 int rc;
316
317 EFX_WARN_ON_PARANOID(getsda(i2c) != 1);
318 EFX_WARN_ON_PARANOID(getscl(i2c) != 1);
319 EFX_WARN_ON_PARANOID(len < 1);
320
321 /* Select device */
322 i2c_start(i2c);
323
324 /* Read data from device */
325 rc = i2c_send_byte(i2c, i2c_read_cmd(device_id));
326 if (rc)
327 goto out;
328
329 for (i = 0; i < (len - 1); i++)
330 /* Read and acknowledge all but the last byte */
331 bytes[i] = i2c_recv_byte(i2c, 1);
332 /* Read last byte with no acknowledgement */
333 bytes[i] = i2c_recv_byte(i2c, 0);
334
335 out:
336 i2c_stop(i2c);
337 i2c_release(i2c);
338
339 return rc;
340}
341
342/* SMBus and some I2C devices will time out if the I2C clock is
343 * held low for too long. This is most likely to happen in virtualised
344 * systems (when the entire domain is descheduled) but could in
345 * principle happen due to preemption on any busy system (and given the
346 * potential length of an I2C operation turning preemption off is not
347 * a sensible option). The following functions deal with the failure by
348 * retrying up to a fixed number of times.
349 */
350
351#define I2C_MAX_RETRIES (10)
352
353/* The timeout problem will result in -EIO. If the wrapped function
354 * returns any other error, pass this up and do not retry. */
355#define RETRY_WRAPPER(_f) \
356 int retries = I2C_MAX_RETRIES; \
357 int rc; \
358 while (retries) { \
359 rc = _f; \
360 if (rc != -EIO) \
361 return rc; \
362 retries--; \
363 } \
364 return rc; \
365
366int efx_i2c_check_presence_retry(struct efx_i2c_interface *i2c, u8 device_id)
367{
368 RETRY_WRAPPER(efx_i2c_check_presence(i2c, device_id))
369}
370
371int efx_i2c_read_retry(struct efx_i2c_interface *i2c,
372 u8 device_id, u8 offset, u8 *data, unsigned int len)
373{
374 RETRY_WRAPPER(efx_i2c_read(i2c, device_id, offset, data, len))
375}
376
377int efx_i2c_write_retry(struct efx_i2c_interface *i2c,
378 u8 device_id, u8 offset, const u8 *data, unsigned int len)
379{
380 RETRY_WRAPPER(efx_i2c_write(i2c, device_id, offset, data, len))
381}
diff --git a/drivers/net/sfc/i2c-direct.h b/drivers/net/sfc/i2c-direct.h
new file mode 100644
index 000000000000..291e561071f5
--- /dev/null
+++ b/drivers/net/sfc/i2c-direct.h
@@ -0,0 +1,91 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005 Fen Systems Ltd.
4 * Copyright 2006 Solarflare Communications Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
11#ifndef EFX_I2C_DIRECT_H
12#define EFX_I2C_DIRECT_H
13
14#include "net_driver.h"
15
16/*
17 * Direct control of an I2C bus
18 */
19
20struct efx_i2c_interface;
21
22/**
23 * struct efx_i2c_bit_operations - I2C bus direct control methods
24 *
25 * I2C bus direct control methods.
26 *
27 * @setsda: Set state of SDA line
28 * @setscl: Set state of SCL line
29 * @getsda: Get state of SDA line
30 * @getscl: Get state of SCL line
31 * @udelay: Delay between each bit operation
32 * @mdelay: Delay between each byte write
33 */
34struct efx_i2c_bit_operations {
35 void (*setsda) (struct efx_i2c_interface *i2c);
36 void (*setscl) (struct efx_i2c_interface *i2c);
37 int (*getsda) (struct efx_i2c_interface *i2c);
38 int (*getscl) (struct efx_i2c_interface *i2c);
39 unsigned int udelay;
40 unsigned int mdelay;
41};
42
43/**
44 * struct efx_i2c_interface - an I2C interface
45 *
46 * An I2C interface.
47 *
48 * @efx: Attached Efx NIC
49 * @op: I2C bus control methods
50 * @sda: Current output state of SDA line
51 * @scl: Current output state of SCL line
52 */
53struct efx_i2c_interface {
54 struct efx_nic *efx;
55 struct efx_i2c_bit_operations *op;
56 unsigned int sda:1;
57 unsigned int scl:1;
58};
59
60extern int efx_i2c_check_presence(struct efx_i2c_interface *i2c, u8 device_id);
61extern int efx_i2c_fast_read(struct efx_i2c_interface *i2c,
62 u8 device_id, u8 offset,
63 u8 *data, unsigned int len);
64extern int efx_i2c_fast_write(struct efx_i2c_interface *i2c,
65 u8 device_id, u8 offset,
66 const u8 *data, unsigned int len);
67extern int efx_i2c_read(struct efx_i2c_interface *i2c,
68 u8 device_id, u8 offset, u8 *data, unsigned int len);
69extern int efx_i2c_write(struct efx_i2c_interface *i2c,
70 u8 device_id, u8 offset,
71 const u8 *data, unsigned int len);
72
73extern int efx_i2c_send_bytes(struct efx_i2c_interface *i2c, u8 device_id,
74 const u8 *bytes, unsigned int len);
75
76extern int efx_i2c_recv_bytes(struct efx_i2c_interface *i2c, u8 device_id,
77 u8 *bytes, unsigned int len);
78
79
80/* Versions of the API that retry on failure. */
81extern int efx_i2c_check_presence_retry(struct efx_i2c_interface *i2c,
82 u8 device_id);
83
84extern int efx_i2c_read_retry(struct efx_i2c_interface *i2c,
85 u8 device_id, u8 offset, u8 *data, unsigned int len);
86
87extern int efx_i2c_write_retry(struct efx_i2c_interface *i2c,
88 u8 device_id, u8 offset,
89 const u8 *data, unsigned int len);
90
91#endif /* EFX_I2C_DIRECT_H */
diff --git a/drivers/net/sfc/mac.h b/drivers/net/sfc/mac.h
new file mode 100644
index 000000000000..edd07d4dee18
--- /dev/null
+++ b/drivers/net/sfc/mac.h
@@ -0,0 +1,33 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2006-2007 Solarflare Communications Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
11#ifndef EFX_MAC_H
12#define EFX_MAC_H
13
14#include "net_driver.h"
15
16extern void falcon_xmac_writel(struct efx_nic *efx,
17 efx_dword_t *value, unsigned int mac_reg);
18extern void falcon_xmac_readl(struct efx_nic *efx,
19 efx_dword_t *value, unsigned int mac_reg);
20extern int falcon_init_xmac(struct efx_nic *efx);
21extern void falcon_reconfigure_xmac(struct efx_nic *efx);
22extern void falcon_update_stats_xmac(struct efx_nic *efx);
23extern void falcon_fini_xmac(struct efx_nic *efx);
24extern int falcon_check_xmac(struct efx_nic *efx);
25extern void falcon_xmac_sim_phy_event(struct efx_nic *efx);
26extern int falcon_xmac_get_settings(struct efx_nic *efx,
27 struct ethtool_cmd *ecmd);
28extern int falcon_xmac_set_settings(struct efx_nic *efx,
29 struct ethtool_cmd *ecmd);
30extern int falcon_xmac_set_pause(struct efx_nic *efx,
31 enum efx_fc_type pause_params);
32
33#endif
diff --git a/drivers/net/sfc/mdio_10g.c b/drivers/net/sfc/mdio_10g.c
new file mode 100644
index 000000000000..dc06bb0aa575
--- /dev/null
+++ b/drivers/net/sfc/mdio_10g.c
@@ -0,0 +1,282 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2006-2008 Solarflare Communications Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, incorporated herein by reference.
8 */
9/*
10 * Useful functions for working with MDIO clause 45 PHYs
11 */
12#include <linux/types.h>
13#include <linux/ethtool.h>
14#include <linux/delay.h>
15#include "net_driver.h"
16#include "mdio_10g.h"
17#include "boards.h"
18
19int mdio_clause45_reset_mmd(struct efx_nic *port, int mmd,
20 int spins, int spintime)
21{
22 u32 ctrl;
23 int phy_id = port->mii.phy_id;
24
25 /* Catch callers passing values in the wrong units (or just silly) */
26 EFX_BUG_ON_PARANOID(spins * spintime >= 5000);
27
28 mdio_clause45_write(port, phy_id, mmd, MDIO_MMDREG_CTRL1,
29 (1 << MDIO_MMDREG_CTRL1_RESET_LBN));
30 /* Wait for the reset bit to clear. */
31 do {
32 msleep(spintime);
33 ctrl = mdio_clause45_read(port, phy_id, mmd, MDIO_MMDREG_CTRL1);
34 spins--;
35
36 } while (spins && (ctrl & (1 << MDIO_MMDREG_CTRL1_RESET_LBN)));
37
38 return spins ? spins : -ETIMEDOUT;
39}
40
41static int mdio_clause45_check_mmd(struct efx_nic *efx, int mmd,
42 int fault_fatal)
43{
44 int status;
45 int phy_id = efx->mii.phy_id;
46
47 /* Read MMD STATUS2 to check it is responding. */
48 status = mdio_clause45_read(efx, phy_id, mmd, MDIO_MMDREG_STAT2);
49 if (((status >> MDIO_MMDREG_STAT2_PRESENT_LBN) &
50 ((1 << MDIO_MMDREG_STAT2_PRESENT_WIDTH) - 1)) !=
51 MDIO_MMDREG_STAT2_PRESENT_VAL) {
52 EFX_ERR(efx, "PHY MMD %d not responding.\n", mmd);
53 return -EIO;
54 }
55
56 /* Read MMD STATUS 1 to check for fault. */
57 status = mdio_clause45_read(efx, phy_id, mmd, MDIO_MMDREG_STAT1);
58 if ((status & (1 << MDIO_MMDREG_STAT1_FAULT_LBN)) != 0) {
59 if (fault_fatal) {
60 EFX_ERR(efx, "PHY MMD %d reporting fatal"
61 " fault: status %x\n", mmd, status);
62 return -EIO;
63 } else {
64 EFX_LOG(efx, "PHY MMD %d reporting status"
65 " %x (expected)\n", mmd, status);
66 }
67 }
68 return 0;
69}
70
71/* This ought to be ridiculous overkill. We expect it to fail rarely */
72#define MDIO45_RESET_TIME 1000 /* ms */
73#define MDIO45_RESET_ITERS 100
74
75int mdio_clause45_wait_reset_mmds(struct efx_nic *efx,
76 unsigned int mmd_mask)
77{
78 const int spintime = MDIO45_RESET_TIME / MDIO45_RESET_ITERS;
79 int tries = MDIO45_RESET_ITERS;
80 int rc = 0;
81 int in_reset;
82
83 while (tries) {
84 int mask = mmd_mask;
85 int mmd = 0;
86 int stat;
87 in_reset = 0;
88 while (mask) {
89 if (mask & 1) {
90 stat = mdio_clause45_read(efx,
91 efx->mii.phy_id,
92 mmd,
93 MDIO_MMDREG_CTRL1);
94 if (stat < 0) {
95 EFX_ERR(efx, "failed to read status of"
96 " MMD %d\n", mmd);
97 return -EIO;
98 }
99 if (stat & (1 << MDIO_MMDREG_CTRL1_RESET_LBN))
100 in_reset |= (1 << mmd);
101 }
102 mask = mask >> 1;
103 mmd++;
104 }
105 if (!in_reset)
106 break;
107 tries--;
108 msleep(spintime);
109 }
110 if (in_reset != 0) {
111 EFX_ERR(efx, "not all MMDs came out of reset in time."
112 " MMDs still in reset: %x\n", in_reset);
113 rc = -ETIMEDOUT;
114 }
115 return rc;
116}
117
118int mdio_clause45_check_mmds(struct efx_nic *efx,
119 unsigned int mmd_mask, unsigned int fatal_mask)
120{
121 int devices, mmd = 0;
122 int probe_mmd;
123
124 /* Historically we have probed the PHYXS to find out what devices are
125 * present,but that doesn't work so well if the PHYXS isn't expected
126 * to exist, if so just find the first item in the list supplied. */
127 probe_mmd = (mmd_mask & MDIO_MMDREG_DEVS0_PHYXS) ? MDIO_MMD_PHYXS :
128 __ffs(mmd_mask);
129 devices = mdio_clause45_read(efx, efx->mii.phy_id,
130 probe_mmd, MDIO_MMDREG_DEVS0);
131
132 /* Check all the expected MMDs are present */
133 if (devices < 0) {
134 EFX_ERR(efx, "failed to read devices present\n");
135 return -EIO;
136 }
137 if ((devices & mmd_mask) != mmd_mask) {
138 EFX_ERR(efx, "required MMDs not present: got %x, "
139 "wanted %x\n", devices, mmd_mask);
140 return -ENODEV;
141 }
142 EFX_TRACE(efx, "Devices present: %x\n", devices);
143
144 /* Check all required MMDs are responding and happy. */
145 while (mmd_mask) {
146 if (mmd_mask & 1) {
147 int fault_fatal = fatal_mask & 1;
148 if (mdio_clause45_check_mmd(efx, mmd, fault_fatal))
149 return -EIO;
150 }
151 mmd_mask = mmd_mask >> 1;
152 fatal_mask = fatal_mask >> 1;
153 mmd++;
154 }
155
156 return 0;
157}
158
159int mdio_clause45_links_ok(struct efx_nic *efx, unsigned int mmd_mask)
160{
161 int phy_id = efx->mii.phy_id;
162 int status;
163 int ok = 1;
164 int mmd = 0;
165 int good;
166
167 while (mmd_mask) {
168 if (mmd_mask & 1) {
169 /* Double reads because link state is latched, and a
170 * read moves the current state into the register */
171 status = mdio_clause45_read(efx, phy_id,
172 mmd, MDIO_MMDREG_STAT1);
173 status = mdio_clause45_read(efx, phy_id,
174 mmd, MDIO_MMDREG_STAT1);
175
176 good = status & (1 << MDIO_MMDREG_STAT1_LINK_LBN);
177 ok = ok && good;
178 }
179 mmd_mask = (mmd_mask >> 1);
180 mmd++;
181 }
182 return ok;
183}
184
185/**
186 * mdio_clause45_get_settings - Read (some of) the PHY settings over MDIO.
187 * @efx: Efx NIC
188 * @ecmd: Buffer for settings
189 *
190 * On return the 'port', 'speed', 'supported' and 'advertising' fields of
191 * ecmd have been filled out based on the PMA type.
192 */
193void mdio_clause45_get_settings(struct efx_nic *efx,
194 struct ethtool_cmd *ecmd)
195{
196 int pma_type;
197
198 /* If no PMA is present we are presumably talking something XAUI-ish
199 * like CX4. Which we report as FIBRE (see below) */
200 if ((efx->phy_op->mmds & DEV_PRESENT_BIT(MDIO_MMD_PMAPMD)) == 0) {
201 ecmd->speed = SPEED_10000;
202 ecmd->port = PORT_FIBRE;
203 ecmd->supported = SUPPORTED_FIBRE;
204 ecmd->advertising = ADVERTISED_FIBRE;
205 return;
206 }
207
208 pma_type = mdio_clause45_read(efx, efx->mii.phy_id,
209 MDIO_MMD_PMAPMD, MDIO_MMDREG_CTRL2);
210 pma_type &= MDIO_PMAPMD_CTRL2_TYPE_MASK;
211
212 switch (pma_type) {
213 /* We represent CX4 as fibre in the absence of anything
214 better. */
215 case MDIO_PMAPMD_CTRL2_10G_CX4:
216 ecmd->speed = SPEED_10000;
217 ecmd->port = PORT_FIBRE;
218 ecmd->supported = SUPPORTED_FIBRE;
219 ecmd->advertising = ADVERTISED_FIBRE;
220 break;
221 /* 10G Base-T */
222 case MDIO_PMAPMD_CTRL2_10G_BT:
223 ecmd->speed = SPEED_10000;
224 ecmd->port = PORT_TP;
225 ecmd->supported = SUPPORTED_TP | SUPPORTED_10000baseT_Full;
226 ecmd->advertising = (ADVERTISED_FIBRE
227 | ADVERTISED_10000baseT_Full);
228 break;
229 case MDIO_PMAPMD_CTRL2_1G_BT:
230 ecmd->speed = SPEED_1000;
231 ecmd->port = PORT_TP;
232 ecmd->supported = SUPPORTED_TP | SUPPORTED_1000baseT_Full;
233 ecmd->advertising = (ADVERTISED_FIBRE
234 | ADVERTISED_1000baseT_Full);
235 break;
236 case MDIO_PMAPMD_CTRL2_100_BT:
237 ecmd->speed = SPEED_100;
238 ecmd->port = PORT_TP;
239 ecmd->supported = SUPPORTED_TP | SUPPORTED_100baseT_Full;
240 ecmd->advertising = (ADVERTISED_FIBRE
241 | ADVERTISED_100baseT_Full);
242 break;
243 case MDIO_PMAPMD_CTRL2_10_BT:
244 ecmd->speed = SPEED_10;
245 ecmd->port = PORT_TP;
246 ecmd->supported = SUPPORTED_TP | SUPPORTED_10baseT_Full;
247 ecmd->advertising = ADVERTISED_FIBRE | ADVERTISED_10baseT_Full;
248 break;
249 /* All the other defined modes are flavours of
250 * 10G optical */
251 default:
252 ecmd->speed = SPEED_10000;
253 ecmd->port = PORT_FIBRE;
254 ecmd->supported = SUPPORTED_FIBRE;
255 ecmd->advertising = ADVERTISED_FIBRE;
256 break;
257 }
258}
259
260/**
261 * mdio_clause45_set_settings - Set (some of) the PHY settings over MDIO.
262 * @efx: Efx NIC
263 * @ecmd: New settings
264 *
265 * Currently this just enforces that we are _not_ changing the
266 * 'port', 'speed', 'supported' or 'advertising' settings as these
267 * cannot be changed on any currently supported PHY.
268 */
269int mdio_clause45_set_settings(struct efx_nic *efx,
270 struct ethtool_cmd *ecmd)
271{
272 struct ethtool_cmd tmpcmd;
273 mdio_clause45_get_settings(efx, &tmpcmd);
274 /* None of the current PHYs support more than one mode
275 * of operation (and only 10GBT ever will), so keep things
276 * simple for now */
277 if ((ecmd->speed == tmpcmd.speed) && (ecmd->port == tmpcmd.port) &&
278 (ecmd->supported == tmpcmd.supported) &&
279 (ecmd->advertising == tmpcmd.advertising))
280 return 0;
281 return -EOPNOTSUPP;
282}
diff --git a/drivers/net/sfc/mdio_10g.h b/drivers/net/sfc/mdio_10g.h
new file mode 100644
index 000000000000..2214b6d820a7
--- /dev/null
+++ b/drivers/net/sfc/mdio_10g.h
@@ -0,0 +1,232 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2006-2008 Solarflare Communications Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, incorporated herein by reference.
8 */
9
10#ifndef EFX_MDIO_10G_H
11#define EFX_MDIO_10G_H
12
13/*
14 * Definitions needed for doing 10G MDIO as specified in clause 45
15 * MDIO, which do not appear in Linux yet. Also some helper functions.
16 */
17
18#include "efx.h"
19#include "boards.h"
20
21/* Numbering of the MDIO Manageable Devices (MMDs) */
22/* Physical Medium Attachment/ Physical Medium Dependent sublayer */
23#define MDIO_MMD_PMAPMD (1)
24/* WAN Interface Sublayer */
25#define MDIO_MMD_WIS (2)
26/* Physical Coding Sublayer */
27#define MDIO_MMD_PCS (3)
28/* PHY Extender Sublayer */
29#define MDIO_MMD_PHYXS (4)
30/* Extender Sublayer */
31#define MDIO_MMD_DTEXS (5)
32/* Transmission convergence */
33#define MDIO_MMD_TC (6)
34/* Auto negotiation */
35#define MDIO_MMD_AN (7)
36
37/* Generic register locations */
38#define MDIO_MMDREG_CTRL1 (0)
39#define MDIO_MMDREG_STAT1 (1)
40#define MDIO_MMDREG_IDHI (2)
41#define MDIO_MMDREG_IDLOW (3)
42#define MDIO_MMDREG_SPEED (4)
43#define MDIO_MMDREG_DEVS0 (5)
44#define MDIO_MMDREG_DEVS1 (6)
45#define MDIO_MMDREG_CTRL2 (7)
46#define MDIO_MMDREG_STAT2 (8)
47
48/* Bits in MMDREG_CTRL1 */
49/* Reset */
50#define MDIO_MMDREG_CTRL1_RESET_LBN (15)
51#define MDIO_MMDREG_CTRL1_RESET_WIDTH (1)
52
53/* Bits in MMDREG_STAT1 */
54#define MDIO_MMDREG_STAT1_FAULT_LBN (7)
55#define MDIO_MMDREG_STAT1_FAULT_WIDTH (1)
56/* Link state */
57#define MDIO_MMDREG_STAT1_LINK_LBN (2)
58#define MDIO_MMDREG_STAT1_LINK_WIDTH (1)
59
60/* Bits in ID reg */
61#define MDIO_ID_REV(_id32) (_id32 & 0xf)
62#define MDIO_ID_MODEL(_id32) ((_id32 >> 4) & 0x3f)
63#define MDIO_ID_OUI(_id32) (_id32 >> 10)
64
65/* Bits in MMDREG_DEVS0. Someone thoughtfully layed things out
66 * so the 'bit present' bit number of an MMD is the number of
67 * that MMD */
68#define DEV_PRESENT_BIT(_b) (1 << _b)
69
70#define MDIO_MMDREG_DEVS0_PHYXS DEV_PRESENT_BIT(MDIO_MMD_PHYXS)
71#define MDIO_MMDREG_DEVS0_PCS DEV_PRESENT_BIT(MDIO_MMD_PCS)
72#define MDIO_MMDREG_DEVS0_PMAPMD DEV_PRESENT_BIT(MDIO_MMD_PMAPMD)
73
74/* Bits in MMDREG_STAT2 */
75#define MDIO_MMDREG_STAT2_PRESENT_VAL (2)
76#define MDIO_MMDREG_STAT2_PRESENT_LBN (14)
77#define MDIO_MMDREG_STAT2_PRESENT_WIDTH (2)
78
79/* PMA type (4 bits) */
80#define MDIO_PMAPMD_CTRL2_10G_CX4 (0x0)
81#define MDIO_PMAPMD_CTRL2_10G_EW (0x1)
82#define MDIO_PMAPMD_CTRL2_10G_LW (0x2)
83#define MDIO_PMAPMD_CTRL2_10G_SW (0x3)
84#define MDIO_PMAPMD_CTRL2_10G_LX4 (0x4)
85#define MDIO_PMAPMD_CTRL2_10G_ER (0x5)
86#define MDIO_PMAPMD_CTRL2_10G_LR (0x6)
87#define MDIO_PMAPMD_CTRL2_10G_SR (0x7)
88/* Reserved */
89#define MDIO_PMAPMD_CTRL2_10G_BT (0x9)
90/* Reserved */
91/* Reserved */
92#define MDIO_PMAPMD_CTRL2_1G_BT (0xc)
93/* Reserved */
94#define MDIO_PMAPMD_CTRL2_100_BT (0xe)
95#define MDIO_PMAPMD_CTRL2_10_BT (0xf)
96#define MDIO_PMAPMD_CTRL2_TYPE_MASK (0xf)
97
98/* /\* PHY XGXS lane state *\/ */
99#define MDIO_PHYXS_LANE_STATE (0x18)
100#define MDIO_PHYXS_LANE_ALIGNED_LBN (12)
101
102/* AN registers */
103#define MDIO_AN_STATUS (1)
104#define MDIO_AN_STATUS_XNP_LBN (7)
105#define MDIO_AN_STATUS_PAGE_LBN (6)
106#define MDIO_AN_STATUS_AN_DONE_LBN (5)
107#define MDIO_AN_STATUS_LP_AN_CAP_LBN (0)
108
109#define MDIO_AN_10GBT_STATUS (33)
110#define MDIO_AN_10GBT_STATUS_MS_FLT_LBN (15) /* MASTER/SLAVE config fault */
111#define MDIO_AN_10GBT_STATUS_MS_LBN (14) /* MASTER/SLAVE config */
112#define MDIO_AN_10GBT_STATUS_LOC_OK_LBN (13) /* Local OK */
113#define MDIO_AN_10GBT_STATUS_REM_OK_LBN (12) /* Remote OK */
114#define MDIO_AN_10GBT_STATUS_LP_10G_LBN (11) /* Link partner is 10GBT capable */
115#define MDIO_AN_10GBT_STATUS_LP_LTA_LBN (10) /* LP loop timing ability */
116#define MDIO_AN_10GBT_STATUS_LP_TRR_LBN (9) /* LP Training Reset Request */
117
118
119/* Packing of the prt and dev arguments of clause 45 style MDIO into a
120 * single int so they can be passed into the mdio_read/write functions
121 * that currently exist. Note that as Falcon is the only current user,
122 * the packed form is chosen to match what Falcon needs to write into
123 * a register. This is checked at compile-time so do not change it. If
124 * your target chip needs things layed out differently you will need
125 * to unpack the arguments in your chip-specific mdio functions.
126 */
127 /* These are defined by the standard. */
128#define MDIO45_PRT_ID_WIDTH (5)
129#define MDIO45_DEV_ID_WIDTH (5)
130
131/* The prt ID is just packed in immediately to the left of the dev ID */
132#define MDIO45_PRT_DEV_WIDTH (MDIO45_PRT_ID_WIDTH + MDIO45_DEV_ID_WIDTH)
133
134#define MDIO45_PRT_ID_MASK ((1 << MDIO45_PRT_DEV_WIDTH) - 1)
135/* This is the prt + dev extended by 1 bit to hold the 'is clause 45' flag. */
136#define MDIO45_XPRT_ID_WIDTH (MDIO45_PRT_DEV_WIDTH + 1)
137#define MDIO45_XPRT_ID_MASK ((1 << MDIO45_XPRT_ID_WIDTH) - 1)
138#define MDIO45_XPRT_ID_IS10G (1 << (MDIO45_XPRT_ID_WIDTH - 1))
139
140
141#define MDIO45_PRT_ID_COMP_LBN MDIO45_DEV_ID_WIDTH
142#define MDIO45_PRT_ID_COMP_WIDTH MDIO45_PRT_ID_WIDTH
143#define MDIO45_DEV_ID_COMP_LBN 0
144#define MDIO45_DEV_ID_COMP_WIDTH MDIO45_DEV_ID_WIDTH
145
146/* Compose port and device into a phy_id */
147static inline int mdio_clause45_pack(u8 prt, u8 dev)
148{
149 efx_dword_t phy_id;
150 EFX_POPULATE_DWORD_2(phy_id, MDIO45_PRT_ID_COMP, prt,
151 MDIO45_DEV_ID_COMP, dev);
152 return MDIO45_XPRT_ID_IS10G | EFX_DWORD_VAL(phy_id);
153}
154
155static inline void mdio_clause45_unpack(u32 val, u8 *prt, u8 *dev)
156{
157 efx_dword_t phy_id;
158 EFX_POPULATE_DWORD_1(phy_id, EFX_DWORD_0, val);
159 *prt = EFX_DWORD_FIELD(phy_id, MDIO45_PRT_ID_COMP);
160 *dev = EFX_DWORD_FIELD(phy_id, MDIO45_DEV_ID_COMP);
161}
162
163static inline int mdio_clause45_read(struct efx_nic *efx,
164 u8 prt, u8 dev, u16 addr)
165{
166 return efx->mii.mdio_read(efx->net_dev,
167 mdio_clause45_pack(prt, dev), addr);
168}
169
170static inline void mdio_clause45_write(struct efx_nic *efx,
171 u8 prt, u8 dev, u16 addr, int value)
172{
173 efx->mii.mdio_write(efx->net_dev,
174 mdio_clause45_pack(prt, dev), addr, value);
175}
176
177
178static inline u32 mdio_clause45_read_id(struct efx_nic *efx, int mmd)
179{
180 int phy_id = efx->mii.phy_id;
181 u16 id_low = mdio_clause45_read(efx, phy_id, mmd, MDIO_MMDREG_IDLOW);
182 u16 id_hi = mdio_clause45_read(efx, phy_id, mmd, MDIO_MMDREG_IDHI);
183 return (id_hi << 16) | (id_low);
184}
185
186static inline int mdio_clause45_phyxgxs_lane_sync(struct efx_nic *efx)
187{
188 int i, sync, lane_status;
189
190 for (i = 0; i < 2; ++i)
191 lane_status = mdio_clause45_read(efx, efx->mii.phy_id,
192 MDIO_MMD_PHYXS,
193 MDIO_PHYXS_LANE_STATE);
194
195 sync = (lane_status & (1 << MDIO_PHYXS_LANE_ALIGNED_LBN)) != 0;
196 if (!sync)
197 EFX_INFO(efx, "XGXS lane status: %x\n", lane_status);
198 return sync;
199}
200
201extern const char *mdio_clause45_mmd_name(int mmd);
202
203/*
204 * Reset a specific MMD and wait for reset to clear.
205 * Return number of spins left (>0) on success, -%ETIMEDOUT on failure.
206 *
207 * This function will sleep
208 */
209extern int mdio_clause45_reset_mmd(struct efx_nic *efx, int mmd,
210 int spins, int spintime);
211
212/* As mdio_clause45_check_mmd but for multiple MMDs */
213int mdio_clause45_check_mmds(struct efx_nic *efx,
214 unsigned int mmd_mask, unsigned int fatal_mask);
215
216/* Check the link status of specified mmds in bit mask */
217extern int mdio_clause45_links_ok(struct efx_nic *efx,
218 unsigned int mmd_mask);
219
220/* Read (some of) the PHY settings over MDIO */
221extern void mdio_clause45_get_settings(struct efx_nic *efx,
222 struct ethtool_cmd *ecmd);
223
224/* Set (some of) the PHY settings over MDIO */
225extern int mdio_clause45_set_settings(struct efx_nic *efx,
226 struct ethtool_cmd *ecmd);
227
228/* Wait for specified MMDs to exit reset within a timeout */
229extern int mdio_clause45_wait_reset_mmds(struct efx_nic *efx,
230 unsigned int mmd_mask);
231
232#endif /* EFX_MDIO_10G_H */
diff --git a/drivers/net/sfc/net_driver.h b/drivers/net/sfc/net_driver.h
new file mode 100644
index 000000000000..c505482c2520
--- /dev/null
+++ b/drivers/net/sfc/net_driver.h
@@ -0,0 +1,883 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2005-2008 Solarflare Communications Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
11/* Common definitions for all Efx net driver code */
12
13#ifndef EFX_NET_DRIVER_H
14#define EFX_NET_DRIVER_H
15
16#include <linux/version.h>
17#include <linux/netdevice.h>
18#include <linux/etherdevice.h>
19#include <linux/ethtool.h>
20#include <linux/if_vlan.h>
21#include <linux/timer.h>
22#include <linux/mii.h>
23#include <linux/list.h>
24#include <linux/pci.h>
25#include <linux/device.h>
26#include <linux/highmem.h>
27#include <linux/workqueue.h>
28#include <linux/inet_lro.h>
29
30#include "enum.h"
31#include "bitfield.h"
32#include "i2c-direct.h"
33
34#define EFX_MAX_LRO_DESCRIPTORS 8
35#define EFX_MAX_LRO_AGGR MAX_SKB_FRAGS
36
37/**************************************************************************
38 *
39 * Build definitions
40 *
41 **************************************************************************/
42#ifndef EFX_DRIVER_NAME
43#define EFX_DRIVER_NAME "sfc"
44#endif
45#define EFX_DRIVER_VERSION "2.2.0136"
46
47#ifdef EFX_ENABLE_DEBUG
48#define EFX_BUG_ON_PARANOID(x) BUG_ON(x)
49#define EFX_WARN_ON_PARANOID(x) WARN_ON(x)
50#else
51#define EFX_BUG_ON_PARANOID(x) do {} while (0)
52#define EFX_WARN_ON_PARANOID(x) do {} while (0)
53#endif
54
55#define NET_DEV_REGISTERED(efx) \
56 ((efx)->net_dev->reg_state == NETREG_REGISTERED)
57
58/* Include net device name in log messages if it has been registered.
59 * Use efx->name not efx->net_dev->name so that races with (un)registration
60 * are harmless.
61 */
62#define NET_DEV_NAME(efx) (NET_DEV_REGISTERED(efx) ? (efx)->name : "")
63
64/* Un-rate-limited logging */
65#define EFX_ERR(efx, fmt, args...) \
66dev_err(&((efx)->pci_dev->dev), "ERR: %s " fmt, NET_DEV_NAME(efx), ##args)
67
68#define EFX_INFO(efx, fmt, args...) \
69dev_info(&((efx)->pci_dev->dev), "INFO: %s " fmt, NET_DEV_NAME(efx), ##args)
70
71#ifdef EFX_ENABLE_DEBUG
72#define EFX_LOG(efx, fmt, args...) \
73dev_info(&((efx)->pci_dev->dev), "DBG: %s " fmt, NET_DEV_NAME(efx), ##args)
74#else
75#define EFX_LOG(efx, fmt, args...) \
76dev_dbg(&((efx)->pci_dev->dev), "DBG: %s " fmt, NET_DEV_NAME(efx), ##args)
77#endif
78
79#define EFX_TRACE(efx, fmt, args...) do {} while (0)
80
81#define EFX_REGDUMP(efx, fmt, args...) do {} while (0)
82
83/* Rate-limited logging */
84#define EFX_ERR_RL(efx, fmt, args...) \
85do {if (net_ratelimit()) EFX_ERR(efx, fmt, ##args); } while (0)
86
87#define EFX_INFO_RL(efx, fmt, args...) \
88do {if (net_ratelimit()) EFX_INFO(efx, fmt, ##args); } while (0)
89
90#define EFX_LOG_RL(efx, fmt, args...) \
91do {if (net_ratelimit()) EFX_LOG(efx, fmt, ##args); } while (0)
92
93/* Kernel headers may redefine inline anyway */
94#ifndef inline
95#define inline inline __attribute__ ((always_inline))
96#endif
97
98/**************************************************************************
99 *
100 * Efx data structures
101 *
102 **************************************************************************/
103
104#define EFX_MAX_CHANNELS 32
105#define EFX_MAX_TX_QUEUES 1
106#define EFX_MAX_RX_QUEUES EFX_MAX_CHANNELS
107
108/**
109 * struct efx_special_buffer - An Efx special buffer
110 * @addr: CPU base address of the buffer
111 * @dma_addr: DMA base address of the buffer
112 * @len: Buffer length, in bytes
113 * @index: Buffer index within controller;s buffer table
114 * @entries: Number of buffer table entries
115 *
116 * Special buffers are used for the event queues and the TX and RX
117 * descriptor queues for each channel. They are *not* used for the
118 * actual transmit and receive buffers.
119 *
120 * Note that for Falcon, TX and RX descriptor queues live in host memory.
121 * Allocation and freeing procedures must take this into account.
122 */
123struct efx_special_buffer {
124 void *addr;
125 dma_addr_t dma_addr;
126 unsigned int len;
127 int index;
128 int entries;
129};
130
131/**
132 * struct efx_tx_buffer - An Efx TX buffer
133 * @skb: The associated socket buffer.
134 * Set only on the final fragment of a packet; %NULL for all other
135 * fragments. When this fragment completes, then we can free this
136 * skb.
137 * @dma_addr: DMA address of the fragment.
138 * @len: Length of this fragment.
139 * This field is zero when the queue slot is empty.
140 * @continuation: True if this fragment is not the end of a packet.
141 * @unmap_single: True if pci_unmap_single should be used.
142 * @unmap_addr: DMA address to unmap
143 * @unmap_len: Length of this fragment to unmap
144 */
145struct efx_tx_buffer {
146 const struct sk_buff *skb;
147 dma_addr_t dma_addr;
148 unsigned short len;
149 unsigned char continuation;
150 unsigned char unmap_single;
151 dma_addr_t unmap_addr;
152 unsigned short unmap_len;
153};
154
155/**
156 * struct efx_tx_queue - An Efx TX queue
157 *
158 * This is a ring buffer of TX fragments.
159 * Since the TX completion path always executes on the same
160 * CPU and the xmit path can operate on different CPUs,
161 * performance is increased by ensuring that the completion
162 * path and the xmit path operate on different cache lines.
163 * This is particularly important if the xmit path is always
164 * executing on one CPU which is different from the completion
165 * path. There is also a cache line for members which are
166 * read but not written on the fast path.
167 *
168 * @efx: The associated Efx NIC
169 * @queue: DMA queue number
170 * @used: Queue is used by net driver
171 * @channel: The associated channel
172 * @buffer: The software buffer ring
173 * @txd: The hardware descriptor ring
174 * @read_count: Current read pointer.
175 * This is the number of buffers that have been removed from both rings.
176 * @stopped: Stopped flag.
177 * Set if this TX queue is currently stopping its port.
178 * @insert_count: Current insert pointer
179 * This is the number of buffers that have been added to the
180 * software ring.
181 * @write_count: Current write pointer
182 * This is the number of buffers that have been added to the
183 * hardware ring.
184 * @old_read_count: The value of read_count when last checked.
185 * This is here for performance reasons. The xmit path will
186 * only get the up-to-date value of read_count if this
187 * variable indicates that the queue is full. This is to
188 * avoid cache-line ping-pong between the xmit path and the
189 * completion path.
190 */
191struct efx_tx_queue {
192 /* Members which don't change on the fast path */
193 struct efx_nic *efx ____cacheline_aligned_in_smp;
194 int queue;
195 int used;
196 struct efx_channel *channel;
197 struct efx_nic *nic;
198 struct efx_tx_buffer *buffer;
199 struct efx_special_buffer txd;
200
201 /* Members used mainly on the completion path */
202 unsigned int read_count ____cacheline_aligned_in_smp;
203 int stopped;
204
205 /* Members used only on the xmit path */
206 unsigned int insert_count ____cacheline_aligned_in_smp;
207 unsigned int write_count;
208 unsigned int old_read_count;
209};
210
211/**
212 * struct efx_rx_buffer - An Efx RX data buffer
213 * @dma_addr: DMA base address of the buffer
214 * @skb: The associated socket buffer, if any.
215 * If both this and page are %NULL, the buffer slot is currently free.
216 * @page: The associated page buffer, if any.
217 * If both this and skb are %NULL, the buffer slot is currently free.
218 * @data: Pointer to ethernet header
219 * @len: Buffer length, in bytes.
220 * @unmap_addr: DMA address to unmap
221 */
222struct efx_rx_buffer {
223 dma_addr_t dma_addr;
224 struct sk_buff *skb;
225 struct page *page;
226 char *data;
227 unsigned int len;
228 dma_addr_t unmap_addr;
229};
230
231/**
232 * struct efx_rx_queue - An Efx RX queue
233 * @efx: The associated Efx NIC
234 * @queue: DMA queue number
235 * @used: Queue is used by net driver
236 * @channel: The associated channel
237 * @buffer: The software buffer ring
238 * @rxd: The hardware descriptor ring
239 * @added_count: Number of buffers added to the receive queue.
240 * @notified_count: Number of buffers given to NIC (<= @added_count).
241 * @removed_count: Number of buffers removed from the receive queue.
242 * @add_lock: Receive queue descriptor add spin lock.
243 * This lock must be held in order to add buffers to the RX
244 * descriptor ring (rxd and buffer) and to update added_count (but
245 * not removed_count).
246 * @max_fill: RX descriptor maximum fill level (<= ring size)
247 * @fast_fill_trigger: RX descriptor fill level that will trigger a fast fill
248 * (<= @max_fill)
249 * @fast_fill_limit: The level to which a fast fill will fill
250 * (@fast_fill_trigger <= @fast_fill_limit <= @max_fill)
251 * @min_fill: RX descriptor minimum non-zero fill level.
252 * This records the minimum fill level observed when a ring
253 * refill was triggered.
254 * @min_overfill: RX descriptor minimum overflow fill level.
255 * This records the minimum fill level at which RX queue
256 * overflow was observed. It should never be set.
257 * @alloc_page_count: RX allocation strategy counter.
258 * @alloc_skb_count: RX allocation strategy counter.
259 * @work: Descriptor push work thread
260 * @buf_page: Page for next RX buffer.
261 * We can use a single page for multiple RX buffers. This tracks
262 * the remaining space in the allocation.
263 * @buf_dma_addr: Page's DMA address.
264 * @buf_data: Page's host address.
265 */
266struct efx_rx_queue {
267 struct efx_nic *efx;
268 int queue;
269 int used;
270 struct efx_channel *channel;
271 struct efx_rx_buffer *buffer;
272 struct efx_special_buffer rxd;
273
274 int added_count;
275 int notified_count;
276 int removed_count;
277 spinlock_t add_lock;
278 unsigned int max_fill;
279 unsigned int fast_fill_trigger;
280 unsigned int fast_fill_limit;
281 unsigned int min_fill;
282 unsigned int min_overfill;
283 unsigned int alloc_page_count;
284 unsigned int alloc_skb_count;
285 struct delayed_work work;
286 unsigned int slow_fill_count;
287
288 struct page *buf_page;
289 dma_addr_t buf_dma_addr;
290 char *buf_data;
291};
292
293/**
294 * struct efx_buffer - An Efx general-purpose buffer
295 * @addr: host base address of the buffer
296 * @dma_addr: DMA base address of the buffer
297 * @len: Buffer length, in bytes
298 *
299 * Falcon uses these buffers for its interrupt status registers and
300 * MAC stats dumps.
301 */
302struct efx_buffer {
303 void *addr;
304 dma_addr_t dma_addr;
305 unsigned int len;
306};
307
308
309/* Flags for channel->used_flags */
310#define EFX_USED_BY_RX 1
311#define EFX_USED_BY_TX 2
312#define EFX_USED_BY_RX_TX (EFX_USED_BY_RX | EFX_USED_BY_TX)
313
314enum efx_rx_alloc_method {
315 RX_ALLOC_METHOD_AUTO = 0,
316 RX_ALLOC_METHOD_SKB = 1,
317 RX_ALLOC_METHOD_PAGE = 2,
318};
319
320/**
321 * struct efx_channel - An Efx channel
322 *
323 * A channel comprises an event queue, at least one TX queue, at least
324 * one RX queue, and an associated tasklet for processing the event
325 * queue.
326 *
327 * @efx: Associated Efx NIC
328 * @evqnum: Event queue number
329 * @channel: Channel instance number
330 * @used_flags: Channel is used by net driver
331 * @enabled: Channel enabled indicator
332 * @irq: IRQ number (MSI and MSI-X only)
333 * @has_interrupt: Channel has an interrupt
334 * @irq_moderation: IRQ moderation value (in us)
335 * @napi_dev: Net device used with NAPI
336 * @napi_str: NAPI control structure
337 * @reset_work: Scheduled reset work thread
338 * @work_pending: Is work pending via NAPI?
339 * @eventq: Event queue buffer
340 * @eventq_read_ptr: Event queue read pointer
341 * @last_eventq_read_ptr: Last event queue read pointer value.
342 * @eventq_magic: Event queue magic value for driver-generated test events
343 * @lro_mgr: LRO state
344 * @rx_alloc_level: Watermark based heuristic counter for pushing descriptors
345 * and diagnostic counters
346 * @rx_alloc_push_pages: RX allocation method currently in use for pushing
347 * descriptors
348 * @rx_alloc_pop_pages: RX allocation method currently in use for popping
349 * descriptors
350 * @n_rx_tobe_disc: Count of RX_TOBE_DISC errors
351 * @n_rx_ip_frag_err: Count of RX IP fragment errors
352 * @n_rx_ip_hdr_chksum_err: Count of RX IP header checksum errors
353 * @n_rx_tcp_udp_chksum_err: Count of RX TCP and UDP checksum errors
354 * @n_rx_frm_trunc: Count of RX_FRM_TRUNC errors
355 * @n_rx_overlength: Count of RX_OVERLENGTH errors
356 * @n_skbuff_leaks: Count of skbuffs leaked due to RX overrun
357 */
358struct efx_channel {
359 struct efx_nic *efx;
360 int evqnum;
361 int channel;
362 int used_flags;
363 int enabled;
364 int irq;
365 unsigned int has_interrupt;
366 unsigned int irq_moderation;
367 struct net_device *napi_dev;
368 struct napi_struct napi_str;
369 struct work_struct reset_work;
370 int work_pending;
371 struct efx_special_buffer eventq;
372 unsigned int eventq_read_ptr;
373 unsigned int last_eventq_read_ptr;
374 unsigned int eventq_magic;
375
376 struct net_lro_mgr lro_mgr;
377 int rx_alloc_level;
378 int rx_alloc_push_pages;
379 int rx_alloc_pop_pages;
380
381 unsigned n_rx_tobe_disc;
382 unsigned n_rx_ip_frag_err;
383 unsigned n_rx_ip_hdr_chksum_err;
384 unsigned n_rx_tcp_udp_chksum_err;
385 unsigned n_rx_frm_trunc;
386 unsigned n_rx_overlength;
387 unsigned n_skbuff_leaks;
388
389 /* Used to pipeline received packets in order to optimise memory
390 * access with prefetches.
391 */
392 struct efx_rx_buffer *rx_pkt;
393 int rx_pkt_csummed;
394
395};
396
397/**
398 * struct efx_blinker - S/W LED blinking context
399 * @led_num: LED ID (board-specific meaning)
400 * @state: Current state - on or off
401 * @resubmit: Timer resubmission flag
402 * @timer: Control timer for blinking
403 */
404struct efx_blinker {
405 int led_num;
406 int state;
407 int resubmit;
408 struct timer_list timer;
409};
410
411
412/**
413 * struct efx_board - board information
414 * @type: Board model type
415 * @major: Major rev. ('A', 'B' ...)
416 * @minor: Minor rev. (0, 1, ...)
417 * @init: Initialisation function
418 * @init_leds: Sets up board LEDs
419 * @set_fault_led: Turns the fault LED on or off
420 * @blink: Starts/stops blinking
421 * @blinker: used to blink LEDs in software
422 */
423struct efx_board {
424 int type;
425 int major;
426 int minor;
427 int (*init) (struct efx_nic *nic);
428 /* As the LEDs are typically attached to the PHY, LEDs
429 * have a separate init callback that happens later than
430 * board init. */
431 int (*init_leds)(struct efx_nic *efx);
432 void (*set_fault_led) (struct efx_nic *efx, int state);
433 void (*blink) (struct efx_nic *efx, int start);
434 struct efx_blinker blinker;
435};
436
437enum efx_int_mode {
438 /* Be careful if altering to correct macro below */
439 EFX_INT_MODE_MSIX = 0,
440 EFX_INT_MODE_MSI = 1,
441 EFX_INT_MODE_LEGACY = 2,
442 EFX_INT_MODE_MAX /* Insert any new items before this */
443};
444#define EFX_INT_MODE_USE_MSI(x) (((x)->interrupt_mode) <= EFX_INT_MODE_MSI)
445
446enum phy_type {
447 PHY_TYPE_NONE = 0,
448 PHY_TYPE_CX4_RTMR = 1,
449 PHY_TYPE_1G_ALASKA = 2,
450 PHY_TYPE_10XPRESS = 3,
451 PHY_TYPE_XFP = 4,
452 PHY_TYPE_PM8358 = 6,
453 PHY_TYPE_MAX /* Insert any new items before this */
454};
455
456#define PHY_ADDR_INVALID 0xff
457
458enum nic_state {
459 STATE_INIT = 0,
460 STATE_RUNNING = 1,
461 STATE_FINI = 2,
462 STATE_RESETTING = 3, /* rtnl_lock always held */
463 STATE_DISABLED = 4,
464 STATE_MAX,
465};
466
467/*
468 * Alignment of page-allocated RX buffers
469 *
470 * Controls the number of bytes inserted at the start of an RX buffer.
471 * This is the equivalent of NET_IP_ALIGN [which controls the alignment
472 * of the skb->head for hardware DMA].
473 */
474#if defined(__i386__) || defined(__x86_64__)
475#define EFX_PAGE_IP_ALIGN 0
476#else
477#define EFX_PAGE_IP_ALIGN NET_IP_ALIGN
478#endif
479
480/*
481 * Alignment of the skb->head which wraps a page-allocated RX buffer
482 *
483 * The skb allocated to wrap an rx_buffer can have this alignment. Since
484 * the data is memcpy'd from the rx_buf, it does not need to be equal to
485 * EFX_PAGE_IP_ALIGN.
486 */
487#define EFX_PAGE_SKB_ALIGN 2
488
489/* Forward declaration */
490struct efx_nic;
491
492/* Pseudo bit-mask flow control field */
493enum efx_fc_type {
494 EFX_FC_RX = 1,
495 EFX_FC_TX = 2,
496 EFX_FC_AUTO = 4,
497};
498
499/**
500 * struct efx_phy_operations - Efx PHY operations table
501 * @init: Initialise PHY
502 * @fini: Shut down PHY
503 * @reconfigure: Reconfigure PHY (e.g. for new link parameters)
504 * @clear_interrupt: Clear down interrupt
505 * @blink: Blink LEDs
506 * @check_hw: Check hardware
507 * @reset_xaui: Reset XAUI side of PHY for (software sequenced reset)
508 * @mmds: MMD presence mask
509 */
510struct efx_phy_operations {
511 int (*init) (struct efx_nic *efx);
512 void (*fini) (struct efx_nic *efx);
513 void (*reconfigure) (struct efx_nic *efx);
514 void (*clear_interrupt) (struct efx_nic *efx);
515 int (*check_hw) (struct efx_nic *efx);
516 void (*reset_xaui) (struct efx_nic *efx);
517 int mmds;
518};
519
520/*
521 * Efx extended statistics
522 *
523 * Not all statistics are provided by all supported MACs. The purpose
524 * is this structure is to contain the raw statistics provided by each
525 * MAC.
526 */
527struct efx_mac_stats {
528 u64 tx_bytes;
529 u64 tx_good_bytes;
530 u64 tx_bad_bytes;
531 unsigned long tx_packets;
532 unsigned long tx_bad;
533 unsigned long tx_pause;
534 unsigned long tx_control;
535 unsigned long tx_unicast;
536 unsigned long tx_multicast;
537 unsigned long tx_broadcast;
538 unsigned long tx_lt64;
539 unsigned long tx_64;
540 unsigned long tx_65_to_127;
541 unsigned long tx_128_to_255;
542 unsigned long tx_256_to_511;
543 unsigned long tx_512_to_1023;
544 unsigned long tx_1024_to_15xx;
545 unsigned long tx_15xx_to_jumbo;
546 unsigned long tx_gtjumbo;
547 unsigned long tx_collision;
548 unsigned long tx_single_collision;
549 unsigned long tx_multiple_collision;
550 unsigned long tx_excessive_collision;
551 unsigned long tx_deferred;
552 unsigned long tx_late_collision;
553 unsigned long tx_excessive_deferred;
554 unsigned long tx_non_tcpudp;
555 unsigned long tx_mac_src_error;
556 unsigned long tx_ip_src_error;
557 u64 rx_bytes;
558 u64 rx_good_bytes;
559 u64 rx_bad_bytes;
560 unsigned long rx_packets;
561 unsigned long rx_good;
562 unsigned long rx_bad;
563 unsigned long rx_pause;
564 unsigned long rx_control;
565 unsigned long rx_unicast;
566 unsigned long rx_multicast;
567 unsigned long rx_broadcast;
568 unsigned long rx_lt64;
569 unsigned long rx_64;
570 unsigned long rx_65_to_127;
571 unsigned long rx_128_to_255;
572 unsigned long rx_256_to_511;
573 unsigned long rx_512_to_1023;
574 unsigned long rx_1024_to_15xx;
575 unsigned long rx_15xx_to_jumbo;
576 unsigned long rx_gtjumbo;
577 unsigned long rx_bad_lt64;
578 unsigned long rx_bad_64_to_15xx;
579 unsigned long rx_bad_15xx_to_jumbo;
580 unsigned long rx_bad_gtjumbo;
581 unsigned long rx_overflow;
582 unsigned long rx_missed;
583 unsigned long rx_false_carrier;
584 unsigned long rx_symbol_error;
585 unsigned long rx_align_error;
586 unsigned long rx_length_error;
587 unsigned long rx_internal_error;
588 unsigned long rx_good_lt64;
589};
590
591/* Number of bits used in a multicast filter hash address */
592#define EFX_MCAST_HASH_BITS 8
593
594/* Number of (single-bit) entries in a multicast filter hash */
595#define EFX_MCAST_HASH_ENTRIES (1 << EFX_MCAST_HASH_BITS)
596
597/* An Efx multicast filter hash */
598union efx_multicast_hash {
599 u8 byte[EFX_MCAST_HASH_ENTRIES / 8];
600 efx_oword_t oword[EFX_MCAST_HASH_ENTRIES / sizeof(efx_oword_t) / 8];
601};
602
603/**
604 * struct efx_nic - an Efx NIC
605 * @name: Device name (net device name or bus id before net device registered)
606 * @pci_dev: The PCI device
607 * @type: Controller type attributes
608 * @legacy_irq: IRQ number
609 * @workqueue: Workqueue for resets, port reconfigures and the HW monitor
610 * @reset_work: Scheduled reset workitem
611 * @monitor_work: Hardware monitor workitem
612 * @membase_phys: Memory BAR value as physical address
613 * @membase: Memory BAR value
614 * @biu_lock: BIU (bus interface unit) lock
615 * @interrupt_mode: Interrupt mode
616 * @i2c: I2C interface
617 * @board_info: Board-level information
618 * @state: Device state flag. Serialised by the rtnl_lock.
619 * @reset_pending: Pending reset method (normally RESET_TYPE_NONE)
620 * @tx_queue: TX DMA queues
621 * @rx_queue: RX DMA queues
622 * @channel: Channels
623 * @rss_queues: Number of RSS queues
624 * @rx_buffer_len: RX buffer length
625 * @rx_buffer_order: Order (log2) of number of pages for each RX buffer
626 * @irq_status: Interrupt status buffer
627 * @last_irq_cpu: Last CPU to handle interrupt.
628 * This register is written with the SMP processor ID whenever an
629 * interrupt is handled. It is used by falcon_test_interrupt()
630 * to verify that an interrupt has occurred.
631 * @n_rx_nodesc_drop_cnt: RX no descriptor drop count
632 * @nic_data: Hardware dependant state
633 * @mac_lock: MAC access lock. Protects @port_enabled, efx_monitor() and
634 * efx_reconfigure_port()
635 * @port_enabled: Port enabled indicator.
636 * Serialises efx_stop_all(), efx_start_all() and efx_monitor() and
637 * efx_reconfigure_work with kernel interfaces. Safe to read under any
638 * one of the rtnl_lock, mac_lock, or netif_tx_lock, but all three must
639 * be held to modify it.
640 * @port_initialized: Port initialized?
641 * @net_dev: Operating system network device. Consider holding the rtnl lock
642 * @rx_checksum_enabled: RX checksumming enabled
643 * @netif_stop_count: Port stop count
644 * @netif_stop_lock: Port stop lock
645 * @mac_stats: MAC statistics. These include all statistics the MACs
646 * can provide. Generic code converts these into a standard
647 * &struct net_device_stats.
648 * @stats_buffer: DMA buffer for statistics
649 * @stats_lock: Statistics update lock
650 * @mac_address: Permanent MAC address
651 * @phy_type: PHY type
652 * @phy_lock: PHY access lock
653 * @phy_op: PHY interface
654 * @phy_data: PHY private data (including PHY-specific stats)
655 * @mii: PHY interface
656 * @phy_powered: PHY power state
657 * @tx_disabled: PHY transmitter turned off
658 * @link_up: Link status
659 * @link_options: Link options (MII/GMII format)
660 * @n_link_state_changes: Number of times the link has changed state
661 * @promiscuous: Promiscuous flag. Protected by netif_tx_lock.
662 * @multicast_hash: Multicast hash table
663 * @flow_control: Flow control flags - separate RX/TX so can't use link_options
664 * @reconfigure_work: work item for dealing with PHY events
665 *
666 * The @priv field of the corresponding &struct net_device points to
667 * this.
668 */
669struct efx_nic {
670 char name[IFNAMSIZ];
671 struct pci_dev *pci_dev;
672 const struct efx_nic_type *type;
673 int legacy_irq;
674 struct workqueue_struct *workqueue;
675 struct work_struct reset_work;
676 struct delayed_work monitor_work;
677 unsigned long membase_phys;
678 void __iomem *membase;
679 spinlock_t biu_lock;
680 enum efx_int_mode interrupt_mode;
681
682 struct efx_i2c_interface i2c;
683 struct efx_board board_info;
684
685 enum nic_state state;
686 enum reset_type reset_pending;
687
688 struct efx_tx_queue tx_queue[EFX_MAX_TX_QUEUES];
689 struct efx_rx_queue rx_queue[EFX_MAX_RX_QUEUES];
690 struct efx_channel channel[EFX_MAX_CHANNELS];
691
692 int rss_queues;
693 unsigned int rx_buffer_len;
694 unsigned int rx_buffer_order;
695
696 struct efx_buffer irq_status;
697 volatile signed int last_irq_cpu;
698
699 unsigned n_rx_nodesc_drop_cnt;
700
701 void *nic_data;
702
703 struct mutex mac_lock;
704 int port_enabled;
705
706 int port_initialized;
707 struct net_device *net_dev;
708 int rx_checksum_enabled;
709
710 atomic_t netif_stop_count;
711 spinlock_t netif_stop_lock;
712
713 struct efx_mac_stats mac_stats;
714 struct efx_buffer stats_buffer;
715 spinlock_t stats_lock;
716
717 unsigned char mac_address[ETH_ALEN];
718
719 enum phy_type phy_type;
720 spinlock_t phy_lock;
721 struct efx_phy_operations *phy_op;
722 void *phy_data;
723 struct mii_if_info mii;
724
725 int link_up;
726 unsigned int link_options;
727 unsigned int n_link_state_changes;
728
729 int promiscuous;
730 union efx_multicast_hash multicast_hash;
731 enum efx_fc_type flow_control;
732 struct work_struct reconfigure_work;
733
734 atomic_t rx_reset;
735};
736
737/**
738 * struct efx_nic_type - Efx device type definition
739 * @mem_bar: Memory BAR number
740 * @mem_map_size: Memory BAR mapped size
741 * @txd_ptr_tbl_base: TX descriptor ring base address
742 * @rxd_ptr_tbl_base: RX descriptor ring base address
743 * @buf_tbl_base: Buffer table base address
744 * @evq_ptr_tbl_base: Event queue pointer table base address
745 * @evq_rptr_tbl_base: Event queue read-pointer table base address
746 * @txd_ring_mask: TX descriptor ring size - 1 (must be a power of two - 1)
747 * @rxd_ring_mask: RX descriptor ring size - 1 (must be a power of two - 1)
748 * @evq_size: Event queue size (must be a power of two)
749 * @max_dma_mask: Maximum possible DMA mask
750 * @tx_dma_mask: TX DMA mask
751 * @bug5391_mask: Address mask for bug 5391 workaround
752 * @rx_xoff_thresh: RX FIFO XOFF watermark (bytes)
753 * @rx_xon_thresh: RX FIFO XON watermark (bytes)
754 * @rx_buffer_padding: Padding added to each RX buffer
755 * @max_interrupt_mode: Highest capability interrupt mode supported
756 * from &enum efx_init_mode.
757 * @phys_addr_channels: Number of channels with physically addressed
758 * descriptors
759 */
760struct efx_nic_type {
761 unsigned int mem_bar;
762 unsigned int mem_map_size;
763 unsigned int txd_ptr_tbl_base;
764 unsigned int rxd_ptr_tbl_base;
765 unsigned int buf_tbl_base;
766 unsigned int evq_ptr_tbl_base;
767 unsigned int evq_rptr_tbl_base;
768
769 unsigned int txd_ring_mask;
770 unsigned int rxd_ring_mask;
771 unsigned int evq_size;
772 dma_addr_t max_dma_mask;
773 unsigned int tx_dma_mask;
774 unsigned bug5391_mask;
775
776 int rx_xoff_thresh;
777 int rx_xon_thresh;
778 unsigned int rx_buffer_padding;
779 unsigned int max_interrupt_mode;
780 unsigned int phys_addr_channels;
781};
782
783/**************************************************************************
784 *
785 * Prototypes and inline functions
786 *
787 *************************************************************************/
788
789/* Iterate over all used channels */
790#define efx_for_each_channel(_channel, _efx) \
791 for (_channel = &_efx->channel[0]; \
792 _channel < &_efx->channel[EFX_MAX_CHANNELS]; \
793 _channel++) \
794 if (!_channel->used_flags) \
795 continue; \
796 else
797
798/* Iterate over all used channels with interrupts */
799#define efx_for_each_channel_with_interrupt(_channel, _efx) \
800 for (_channel = &_efx->channel[0]; \
801 _channel < &_efx->channel[EFX_MAX_CHANNELS]; \
802 _channel++) \
803 if (!(_channel->used_flags && _channel->has_interrupt)) \
804 continue; \
805 else
806
807/* Iterate over all used TX queues */
808#define efx_for_each_tx_queue(_tx_queue, _efx) \
809 for (_tx_queue = &_efx->tx_queue[0]; \
810 _tx_queue < &_efx->tx_queue[EFX_MAX_TX_QUEUES]; \
811 _tx_queue++) \
812 if (!_tx_queue->used) \
813 continue; \
814 else
815
816/* Iterate over all TX queues belonging to a channel */
817#define efx_for_each_channel_tx_queue(_tx_queue, _channel) \
818 for (_tx_queue = &_channel->efx->tx_queue[0]; \
819 _tx_queue < &_channel->efx->tx_queue[EFX_MAX_TX_QUEUES]; \
820 _tx_queue++) \
821 if ((!_tx_queue->used) || \
822 (_tx_queue->channel != _channel)) \
823 continue; \
824 else
825
826/* Iterate over all used RX queues */
827#define efx_for_each_rx_queue(_rx_queue, _efx) \
828 for (_rx_queue = &_efx->rx_queue[0]; \
829 _rx_queue < &_efx->rx_queue[EFX_MAX_RX_QUEUES]; \
830 _rx_queue++) \
831 if (!_rx_queue->used) \
832 continue; \
833 else
834
835/* Iterate over all RX queues belonging to a channel */
836#define efx_for_each_channel_rx_queue(_rx_queue, _channel) \
837 for (_rx_queue = &_channel->efx->rx_queue[0]; \
838 _rx_queue < &_channel->efx->rx_queue[EFX_MAX_RX_QUEUES]; \
839 _rx_queue++) \
840 if ((!_rx_queue->used) || \
841 (_rx_queue->channel != _channel)) \
842 continue; \
843 else
844
845/* Returns a pointer to the specified receive buffer in the RX
846 * descriptor queue.
847 */
848static inline struct efx_rx_buffer *efx_rx_buffer(struct efx_rx_queue *rx_queue,
849 unsigned int index)
850{
851 return (&rx_queue->buffer[index]);
852}
853
854/* Set bit in a little-endian bitfield */
855static inline void set_bit_le(int nr, unsigned char *addr)
856{
857 addr[nr / 8] |= (1 << (nr % 8));
858}
859
860/* Clear bit in a little-endian bitfield */
861static inline void clear_bit_le(int nr, unsigned char *addr)
862{
863 addr[nr / 8] &= ~(1 << (nr % 8));
864}
865
866
867/**
868 * EFX_MAX_FRAME_LEN - calculate maximum frame length
869 *
870 * This calculates the maximum frame length that will be used for a
871 * given MTU. The frame length will be equal to the MTU plus a
872 * constant amount of header space and padding. This is the quantity
873 * that the net driver will program into the MAC as the maximum frame
874 * length.
875 *
876 * The 10G MAC used in Falcon requires 8-byte alignment on the frame
877 * length, so we round up to the nearest 8.
878 */
879#define EFX_MAX_FRAME_LEN(mtu) \
880 ((((mtu) + ETH_HLEN + VLAN_HLEN + 4/* FCS */) + 7) & ~7)
881
882
883#endif /* EFX_NET_DRIVER_H */
diff --git a/drivers/net/sfc/phy.h b/drivers/net/sfc/phy.h
new file mode 100644
index 000000000000..9d02c84e6b2d
--- /dev/null
+++ b/drivers/net/sfc/phy.h
@@ -0,0 +1,48 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2007 Solarflare Communications Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, incorporated herein by reference.
8 */
9
10#ifndef EFX_PHY_H
11#define EFX_PHY_H
12
13/****************************************************************************
14 * 10Xpress (SFX7101) PHY
15 */
16extern struct efx_phy_operations falcon_tenxpress_phy_ops;
17
18enum tenxpress_state {
19 TENXPRESS_STATUS_OFF = 0,
20 TENXPRESS_STATUS_OTEMP = 1,
21 TENXPRESS_STATUS_NORMAL = 2,
22};
23
24extern void tenxpress_set_state(struct efx_nic *efx,
25 enum tenxpress_state state);
26extern void tenxpress_phy_blink(struct efx_nic *efx, int blink);
27extern void tenxpress_crc_err(struct efx_nic *efx);
28
29/****************************************************************************
30 * Exported functions from the driver for XFP optical PHYs
31 */
32extern struct efx_phy_operations falcon_xfp_phy_ops;
33
34/* The QUAKE XFP PHY provides various H/W control states for LEDs */
35#define QUAKE_LED_LINK_INVAL (0)
36#define QUAKE_LED_LINK_STAT (1)
37#define QUAKE_LED_LINK_ACT (2)
38#define QUAKE_LED_LINK_ACTSTAT (3)
39#define QUAKE_LED_OFF (4)
40#define QUAKE_LED_ON (5)
41#define QUAKE_LED_LINK_INPUT (6) /* Pin is an input. */
42/* What link the LED tracks */
43#define QUAKE_LED_TXLINK (0)
44#define QUAKE_LED_RXLINK (8)
45
46extern void xfp_set_led(struct efx_nic *p, int led, int state);
47
48#endif
diff --git a/drivers/net/sfc/rx.c b/drivers/net/sfc/rx.c
new file mode 100644
index 000000000000..551299b462ae
--- /dev/null
+++ b/drivers/net/sfc/rx.c
@@ -0,0 +1,875 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2005-2008 Solarflare Communications Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
11#include <linux/socket.h>
12#include <linux/in.h>
13#include <linux/ip.h>
14#include <linux/tcp.h>
15#include <linux/udp.h>
16#include <net/ip.h>
17#include <net/checksum.h>
18#include "net_driver.h"
19#include "rx.h"
20#include "efx.h"
21#include "falcon.h"
22#include "workarounds.h"
23
24/* Number of RX descriptors pushed at once. */
25#define EFX_RX_BATCH 8
26
27/* Size of buffer allocated for skb header area. */
28#define EFX_SKB_HEADERS 64u
29
30/*
31 * rx_alloc_method - RX buffer allocation method
32 *
33 * This driver supports two methods for allocating and using RX buffers:
34 * each RX buffer may be backed by an skb or by an order-n page.
35 *
36 * When LRO is in use then the second method has a lower overhead,
37 * since we don't have to allocate then free skbs on reassembled frames.
38 *
39 * Values:
40 * - RX_ALLOC_METHOD_AUTO = 0
41 * - RX_ALLOC_METHOD_SKB = 1
42 * - RX_ALLOC_METHOD_PAGE = 2
43 *
44 * The heuristic for %RX_ALLOC_METHOD_AUTO is a simple hysteresis count
45 * controlled by the parameters below.
46 *
47 * - Since pushing and popping descriptors are separated by the rx_queue
48 * size, so the watermarks should be ~rxd_size.
49 * - The performance win by using page-based allocation for LRO is less
50 * than the performance hit of using page-based allocation of non-LRO,
51 * so the watermarks should reflect this.
52 *
53 * Per channel we maintain a single variable, updated by each channel:
54 *
55 * rx_alloc_level += (lro_performed ? RX_ALLOC_FACTOR_LRO :
56 * RX_ALLOC_FACTOR_SKB)
57 * Per NAPI poll interval, we constrain rx_alloc_level to 0..MAX (which
58 * limits the hysteresis), and update the allocation strategy:
59 *
60 * rx_alloc_method = (rx_alloc_level > RX_ALLOC_LEVEL_LRO ?
61 * RX_ALLOC_METHOD_PAGE : RX_ALLOC_METHOD_SKB)
62 */
63static int rx_alloc_method = RX_ALLOC_METHOD_PAGE;
64
65#define RX_ALLOC_LEVEL_LRO 0x2000
66#define RX_ALLOC_LEVEL_MAX 0x3000
67#define RX_ALLOC_FACTOR_LRO 1
68#define RX_ALLOC_FACTOR_SKB (-2)
69
70/* This is the percentage fill level below which new RX descriptors
71 * will be added to the RX descriptor ring.
72 */
73static unsigned int rx_refill_threshold = 90;
74
75/* This is the percentage fill level to which an RX queue will be refilled
76 * when the "RX refill threshold" is reached.
77 */
78static unsigned int rx_refill_limit = 95;
79
80/*
81 * RX maximum head room required.
82 *
83 * This must be at least 1 to prevent overflow and at least 2 to allow
84 * pipelined receives.
85 */
86#define EFX_RXD_HEAD_ROOM 2
87
88/* Macros for zero-order pages (potentially) containing multiple RX buffers */
89#define RX_DATA_OFFSET(_data) \
90 (((unsigned long) (_data)) & (PAGE_SIZE-1))
91#define RX_BUF_OFFSET(_rx_buf) \
92 RX_DATA_OFFSET((_rx_buf)->data)
93
94#define RX_PAGE_SIZE(_efx) \
95 (PAGE_SIZE * (1u << (_efx)->rx_buffer_order))
96
97
98/**************************************************************************
99 *
100 * Linux generic LRO handling
101 *
102 **************************************************************************
103 */
104
105static int efx_lro_get_skb_hdr(struct sk_buff *skb, void **ip_hdr,
106 void **tcpudp_hdr, u64 *hdr_flags, void *priv)
107{
108 struct efx_channel *channel = (struct efx_channel *)priv;
109 struct iphdr *iph;
110 struct tcphdr *th;
111
112 iph = (struct iphdr *)skb->data;
113 if (skb->protocol != htons(ETH_P_IP) || iph->protocol != IPPROTO_TCP)
114 goto fail;
115
116 th = (struct tcphdr *)(skb->data + iph->ihl * 4);
117
118 *tcpudp_hdr = th;
119 *ip_hdr = iph;
120 *hdr_flags = LRO_IPV4 | LRO_TCP;
121
122 channel->rx_alloc_level += RX_ALLOC_FACTOR_LRO;
123 return 0;
124fail:
125 channel->rx_alloc_level += RX_ALLOC_FACTOR_SKB;
126 return -1;
127}
128
129static int efx_get_frag_hdr(struct skb_frag_struct *frag, void **mac_hdr,
130 void **ip_hdr, void **tcpudp_hdr, u64 *hdr_flags,
131 void *priv)
132{
133 struct efx_channel *channel = (struct efx_channel *)priv;
134 struct ethhdr *eh;
135 struct iphdr *iph;
136
137 /* We support EtherII and VLAN encapsulated IPv4 */
138 eh = (struct ethhdr *)(page_address(frag->page) + frag->page_offset);
139 *mac_hdr = eh;
140
141 if (eh->h_proto == htons(ETH_P_IP)) {
142 iph = (struct iphdr *)(eh + 1);
143 } else {
144 struct vlan_ethhdr *veh = (struct vlan_ethhdr *)eh;
145 if (veh->h_vlan_encapsulated_proto != htons(ETH_P_IP))
146 goto fail;
147
148 iph = (struct iphdr *)(veh + 1);
149 }
150 *ip_hdr = iph;
151
152 /* We can only do LRO over TCP */
153 if (iph->protocol != IPPROTO_TCP)
154 goto fail;
155
156 *hdr_flags = LRO_IPV4 | LRO_TCP;
157 *tcpudp_hdr = (struct tcphdr *)((u8 *) iph + iph->ihl * 4);
158
159 channel->rx_alloc_level += RX_ALLOC_FACTOR_LRO;
160 return 0;
161 fail:
162 channel->rx_alloc_level += RX_ALLOC_FACTOR_SKB;
163 return -1;
164}
165
166int efx_lro_init(struct net_lro_mgr *lro_mgr, struct efx_nic *efx)
167{
168 size_t s = sizeof(struct net_lro_desc) * EFX_MAX_LRO_DESCRIPTORS;
169 struct net_lro_desc *lro_arr;
170
171 /* Allocate the LRO descriptors structure */
172 lro_arr = kzalloc(s, GFP_KERNEL);
173 if (lro_arr == NULL)
174 return -ENOMEM;
175
176 lro_mgr->lro_arr = lro_arr;
177 lro_mgr->max_desc = EFX_MAX_LRO_DESCRIPTORS;
178 lro_mgr->max_aggr = EFX_MAX_LRO_AGGR;
179 lro_mgr->frag_align_pad = EFX_PAGE_SKB_ALIGN;
180
181 lro_mgr->get_skb_header = efx_lro_get_skb_hdr;
182 lro_mgr->get_frag_header = efx_get_frag_hdr;
183 lro_mgr->dev = efx->net_dev;
184
185 lro_mgr->features = LRO_F_NAPI;
186
187 /* We can pass packets up with the checksum intact */
188 lro_mgr->ip_summed = CHECKSUM_UNNECESSARY;
189
190 lro_mgr->ip_summed_aggr = CHECKSUM_UNNECESSARY;
191
192 return 0;
193}
194
195void efx_lro_fini(struct net_lro_mgr *lro_mgr)
196{
197 kfree(lro_mgr->lro_arr);
198 lro_mgr->lro_arr = NULL;
199}
200
201/**
202 * efx_init_rx_buffer_skb - create new RX buffer using skb-based allocation
203 *
204 * @rx_queue: Efx RX queue
205 * @rx_buf: RX buffer structure to populate
206 *
207 * This allocates memory for a new receive buffer, maps it for DMA,
208 * and populates a struct efx_rx_buffer with the relevant
209 * information. Return a negative error code or 0 on success.
210 */
211static inline int efx_init_rx_buffer_skb(struct efx_rx_queue *rx_queue,
212 struct efx_rx_buffer *rx_buf)
213{
214 struct efx_nic *efx = rx_queue->efx;
215 struct net_device *net_dev = efx->net_dev;
216 int skb_len = efx->rx_buffer_len;
217
218 rx_buf->skb = netdev_alloc_skb(net_dev, skb_len);
219 if (unlikely(!rx_buf->skb))
220 return -ENOMEM;
221
222 /* Adjust the SKB for padding and checksum */
223 skb_reserve(rx_buf->skb, NET_IP_ALIGN);
224 rx_buf->len = skb_len - NET_IP_ALIGN;
225 rx_buf->data = (char *)rx_buf->skb->data;
226 rx_buf->skb->ip_summed = CHECKSUM_UNNECESSARY;
227
228 rx_buf->dma_addr = pci_map_single(efx->pci_dev,
229 rx_buf->data, rx_buf->len,
230 PCI_DMA_FROMDEVICE);
231
232 if (unlikely(pci_dma_mapping_error(rx_buf->dma_addr))) {
233 dev_kfree_skb_any(rx_buf->skb);
234 rx_buf->skb = NULL;
235 return -EIO;
236 }
237
238 return 0;
239}
240
241/**
242 * efx_init_rx_buffer_page - create new RX buffer using page-based allocation
243 *
244 * @rx_queue: Efx RX queue
245 * @rx_buf: RX buffer structure to populate
246 *
247 * This allocates memory for a new receive buffer, maps it for DMA,
248 * and populates a struct efx_rx_buffer with the relevant
249 * information. Return a negative error code or 0 on success.
250 */
251static inline int efx_init_rx_buffer_page(struct efx_rx_queue *rx_queue,
252 struct efx_rx_buffer *rx_buf)
253{
254 struct efx_nic *efx = rx_queue->efx;
255 int bytes, space, offset;
256
257 bytes = efx->rx_buffer_len - EFX_PAGE_IP_ALIGN;
258
259 /* If there is space left in the previously allocated page,
260 * then use it. Otherwise allocate a new one */
261 rx_buf->page = rx_queue->buf_page;
262 if (rx_buf->page == NULL) {
263 dma_addr_t dma_addr;
264
265 rx_buf->page = alloc_pages(__GFP_COLD | __GFP_COMP | GFP_ATOMIC,
266 efx->rx_buffer_order);
267 if (unlikely(rx_buf->page == NULL))
268 return -ENOMEM;
269
270 dma_addr = pci_map_page(efx->pci_dev, rx_buf->page,
271 0, RX_PAGE_SIZE(efx),
272 PCI_DMA_FROMDEVICE);
273
274 if (unlikely(pci_dma_mapping_error(dma_addr))) {
275 __free_pages(rx_buf->page, efx->rx_buffer_order);
276 rx_buf->page = NULL;
277 return -EIO;
278 }
279
280 rx_queue->buf_page = rx_buf->page;
281 rx_queue->buf_dma_addr = dma_addr;
282 rx_queue->buf_data = ((char *) page_address(rx_buf->page) +
283 EFX_PAGE_IP_ALIGN);
284 }
285
286 offset = RX_DATA_OFFSET(rx_queue->buf_data);
287 rx_buf->len = bytes;
288 rx_buf->dma_addr = rx_queue->buf_dma_addr + offset;
289 rx_buf->data = rx_queue->buf_data;
290
291 /* Try to pack multiple buffers per page */
292 if (efx->rx_buffer_order == 0) {
293 /* The next buffer starts on the next 512 byte boundary */
294 rx_queue->buf_data += ((bytes + 0x1ff) & ~0x1ff);
295 offset += ((bytes + 0x1ff) & ~0x1ff);
296
297 space = RX_PAGE_SIZE(efx) - offset;
298 if (space >= bytes) {
299 /* Refs dropped on kernel releasing each skb */
300 get_page(rx_queue->buf_page);
301 goto out;
302 }
303 }
304
305 /* This is the final RX buffer for this page, so mark it for
306 * unmapping */
307 rx_queue->buf_page = NULL;
308 rx_buf->unmap_addr = rx_queue->buf_dma_addr;
309
310 out:
311 return 0;
312}
313
314/* This allocates memory for a new receive buffer, maps it for DMA,
315 * and populates a struct efx_rx_buffer with the relevant
316 * information.
317 */
318static inline int efx_init_rx_buffer(struct efx_rx_queue *rx_queue,
319 struct efx_rx_buffer *new_rx_buf)
320{
321 int rc = 0;
322
323 if (rx_queue->channel->rx_alloc_push_pages) {
324 new_rx_buf->skb = NULL;
325 rc = efx_init_rx_buffer_page(rx_queue, new_rx_buf);
326 rx_queue->alloc_page_count++;
327 } else {
328 new_rx_buf->page = NULL;
329 rc = efx_init_rx_buffer_skb(rx_queue, new_rx_buf);
330 rx_queue->alloc_skb_count++;
331 }
332
333 if (unlikely(rc < 0))
334 EFX_LOG_RL(rx_queue->efx, "%s RXQ[%d] =%d\n", __func__,
335 rx_queue->queue, rc);
336 return rc;
337}
338
339static inline void efx_unmap_rx_buffer(struct efx_nic *efx,
340 struct efx_rx_buffer *rx_buf)
341{
342 if (rx_buf->page) {
343 EFX_BUG_ON_PARANOID(rx_buf->skb);
344 if (rx_buf->unmap_addr) {
345 pci_unmap_page(efx->pci_dev, rx_buf->unmap_addr,
346 RX_PAGE_SIZE(efx), PCI_DMA_FROMDEVICE);
347 rx_buf->unmap_addr = 0;
348 }
349 } else if (likely(rx_buf->skb)) {
350 pci_unmap_single(efx->pci_dev, rx_buf->dma_addr,
351 rx_buf->len, PCI_DMA_FROMDEVICE);
352 }
353}
354
355static inline void efx_free_rx_buffer(struct efx_nic *efx,
356 struct efx_rx_buffer *rx_buf)
357{
358 if (rx_buf->page) {
359 __free_pages(rx_buf->page, efx->rx_buffer_order);
360 rx_buf->page = NULL;
361 } else if (likely(rx_buf->skb)) {
362 dev_kfree_skb_any(rx_buf->skb);
363 rx_buf->skb = NULL;
364 }
365}
366
367static inline void efx_fini_rx_buffer(struct efx_rx_queue *rx_queue,
368 struct efx_rx_buffer *rx_buf)
369{
370 efx_unmap_rx_buffer(rx_queue->efx, rx_buf);
371 efx_free_rx_buffer(rx_queue->efx, rx_buf);
372}
373
374/**
375 * efx_fast_push_rx_descriptors - push new RX descriptors quickly
376 * @rx_queue: RX descriptor queue
377 * @retry: Recheck the fill level
378 * This will aim to fill the RX descriptor queue up to
379 * @rx_queue->@fast_fill_limit. If there is insufficient atomic
380 * memory to do so, the caller should retry.
381 */
382static int __efx_fast_push_rx_descriptors(struct efx_rx_queue *rx_queue,
383 int retry)
384{
385 struct efx_rx_buffer *rx_buf;
386 unsigned fill_level, index;
387 int i, space, rc = 0;
388
389 /* Calculate current fill level. Do this outside the lock,
390 * because most of the time we'll end up not wanting to do the
391 * fill anyway.
392 */
393 fill_level = (rx_queue->added_count - rx_queue->removed_count);
394 EFX_BUG_ON_PARANOID(fill_level >
395 rx_queue->efx->type->rxd_ring_mask + 1);
396
397 /* Don't fill if we don't need to */
398 if (fill_level >= rx_queue->fast_fill_trigger)
399 return 0;
400
401 /* Record minimum fill level */
402 if (unlikely(fill_level < rx_queue->min_fill))
403 if (fill_level)
404 rx_queue->min_fill = fill_level;
405
406 /* Acquire RX add lock. If this lock is contended, then a fast
407 * fill must already be in progress (e.g. in the refill
408 * tasklet), so we don't need to do anything
409 */
410 if (!spin_trylock_bh(&rx_queue->add_lock))
411 return -1;
412
413 retry:
414 /* Recalculate current fill level now that we have the lock */
415 fill_level = (rx_queue->added_count - rx_queue->removed_count);
416 EFX_BUG_ON_PARANOID(fill_level >
417 rx_queue->efx->type->rxd_ring_mask + 1);
418 space = rx_queue->fast_fill_limit - fill_level;
419 if (space < EFX_RX_BATCH)
420 goto out_unlock;
421
422 EFX_TRACE(rx_queue->efx, "RX queue %d fast-filling descriptor ring from"
423 " level %d to level %d using %s allocation\n",
424 rx_queue->queue, fill_level, rx_queue->fast_fill_limit,
425 rx_queue->channel->rx_alloc_push_pages ? "page" : "skb");
426
427 do {
428 for (i = 0; i < EFX_RX_BATCH; ++i) {
429 index = (rx_queue->added_count &
430 rx_queue->efx->type->rxd_ring_mask);
431 rx_buf = efx_rx_buffer(rx_queue, index);
432 rc = efx_init_rx_buffer(rx_queue, rx_buf);
433 if (unlikely(rc))
434 goto out;
435 ++rx_queue->added_count;
436 }
437 } while ((space -= EFX_RX_BATCH) >= EFX_RX_BATCH);
438
439 EFX_TRACE(rx_queue->efx, "RX queue %d fast-filled descriptor ring "
440 "to level %d\n", rx_queue->queue,
441 rx_queue->added_count - rx_queue->removed_count);
442
443 out:
444 /* Send write pointer to card. */
445 falcon_notify_rx_desc(rx_queue);
446
447 /* If the fast fill is running inside from the refill tasklet, then
448 * for SMP systems it may be running on a different CPU to
449 * RX event processing, which means that the fill level may now be
450 * out of date. */
451 if (unlikely(retry && (rc == 0)))
452 goto retry;
453
454 out_unlock:
455 spin_unlock_bh(&rx_queue->add_lock);
456
457 return rc;
458}
459
460/**
461 * efx_fast_push_rx_descriptors - push new RX descriptors quickly
462 * @rx_queue: RX descriptor queue
463 *
464 * This will aim to fill the RX descriptor queue up to
465 * @rx_queue->@fast_fill_limit. If there is insufficient memory to do so,
466 * it will schedule a work item to immediately continue the fast fill
467 */
468void efx_fast_push_rx_descriptors(struct efx_rx_queue *rx_queue)
469{
470 int rc;
471
472 rc = __efx_fast_push_rx_descriptors(rx_queue, 0);
473 if (unlikely(rc)) {
474 /* Schedule the work item to run immediately. The hope is
475 * that work is immediately pending to free some memory
476 * (e.g. an RX event or TX completion)
477 */
478 efx_schedule_slow_fill(rx_queue, 0);
479 }
480}
481
482void efx_rx_work(struct work_struct *data)
483{
484 struct efx_rx_queue *rx_queue;
485 int rc;
486
487 rx_queue = container_of(data, struct efx_rx_queue, work.work);
488
489 if (unlikely(!rx_queue->channel->enabled))
490 return;
491
492 EFX_TRACE(rx_queue->efx, "RX queue %d worker thread executing on CPU "
493 "%d\n", rx_queue->queue, raw_smp_processor_id());
494
495 ++rx_queue->slow_fill_count;
496 /* Push new RX descriptors, allowing at least 1 jiffy for
497 * the kernel to free some more memory. */
498 rc = __efx_fast_push_rx_descriptors(rx_queue, 1);
499 if (rc)
500 efx_schedule_slow_fill(rx_queue, 1);
501}
502
503static inline void efx_rx_packet__check_len(struct efx_rx_queue *rx_queue,
504 struct efx_rx_buffer *rx_buf,
505 int len, int *discard,
506 int *leak_packet)
507{
508 struct efx_nic *efx = rx_queue->efx;
509 unsigned max_len = rx_buf->len - efx->type->rx_buffer_padding;
510
511 if (likely(len <= max_len))
512 return;
513
514 /* The packet must be discarded, but this is only a fatal error
515 * if the caller indicated it was
516 */
517 *discard = 1;
518
519 if ((len > rx_buf->len) && EFX_WORKAROUND_8071(efx)) {
520 EFX_ERR_RL(efx, " RX queue %d seriously overlength "
521 "RX event (0x%x > 0x%x+0x%x). Leaking\n",
522 rx_queue->queue, len, max_len,
523 efx->type->rx_buffer_padding);
524 /* If this buffer was skb-allocated, then the meta
525 * data at the end of the skb will be trashed. So
526 * we have no choice but to leak the fragment.
527 */
528 *leak_packet = (rx_buf->skb != NULL);
529 efx_schedule_reset(efx, RESET_TYPE_RX_RECOVERY);
530 } else {
531 EFX_ERR_RL(efx, " RX queue %d overlength RX event "
532 "(0x%x > 0x%x)\n", rx_queue->queue, len, max_len);
533 }
534
535 rx_queue->channel->n_rx_overlength++;
536}
537
538/* Pass a received packet up through the generic LRO stack
539 *
540 * Handles driverlink veto, and passes the fragment up via
541 * the appropriate LRO method
542 */
543static inline void efx_rx_packet_lro(struct efx_channel *channel,
544 struct efx_rx_buffer *rx_buf)
545{
546 struct net_lro_mgr *lro_mgr = &channel->lro_mgr;
547 void *priv = channel;
548
549 /* Pass the skb/page into the LRO engine */
550 if (rx_buf->page) {
551 struct skb_frag_struct frags;
552
553 frags.page = rx_buf->page;
554 frags.page_offset = RX_BUF_OFFSET(rx_buf);
555 frags.size = rx_buf->len;
556
557 lro_receive_frags(lro_mgr, &frags, rx_buf->len,
558 rx_buf->len, priv, 0);
559
560 EFX_BUG_ON_PARANOID(rx_buf->skb);
561 rx_buf->page = NULL;
562 } else {
563 EFX_BUG_ON_PARANOID(!rx_buf->skb);
564
565 lro_receive_skb(lro_mgr, rx_buf->skb, priv);
566 rx_buf->skb = NULL;
567 }
568}
569
570/* Allocate and construct an SKB around a struct page.*/
571static inline struct sk_buff *efx_rx_mk_skb(struct efx_rx_buffer *rx_buf,
572 struct efx_nic *efx,
573 int hdr_len)
574{
575 struct sk_buff *skb;
576
577 /* Allocate an SKB to store the headers */
578 skb = netdev_alloc_skb(efx->net_dev, hdr_len + EFX_PAGE_SKB_ALIGN);
579 if (unlikely(skb == NULL)) {
580 EFX_ERR_RL(efx, "RX out of memory for skb\n");
581 return NULL;
582 }
583
584 EFX_BUG_ON_PARANOID(skb_shinfo(skb)->nr_frags);
585 EFX_BUG_ON_PARANOID(rx_buf->len < hdr_len);
586
587 skb->ip_summed = CHECKSUM_UNNECESSARY;
588 skb_reserve(skb, EFX_PAGE_SKB_ALIGN);
589
590 skb->len = rx_buf->len;
591 skb->truesize = rx_buf->len + sizeof(struct sk_buff);
592 memcpy(skb->data, rx_buf->data, hdr_len);
593 skb->tail += hdr_len;
594
595 /* Append the remaining page onto the frag list */
596 if (unlikely(rx_buf->len > hdr_len)) {
597 struct skb_frag_struct *frag = skb_shinfo(skb)->frags;
598 frag->page = rx_buf->page;
599 frag->page_offset = RX_BUF_OFFSET(rx_buf) + hdr_len;
600 frag->size = skb->len - hdr_len;
601 skb_shinfo(skb)->nr_frags = 1;
602 skb->data_len = frag->size;
603 } else {
604 __free_pages(rx_buf->page, efx->rx_buffer_order);
605 skb->data_len = 0;
606 }
607
608 /* Ownership has transferred from the rx_buf to skb */
609 rx_buf->page = NULL;
610
611 /* Move past the ethernet header */
612 skb->protocol = eth_type_trans(skb, efx->net_dev);
613
614 return skb;
615}
616
617void efx_rx_packet(struct efx_rx_queue *rx_queue, unsigned int index,
618 unsigned int len, int checksummed, int discard)
619{
620 struct efx_nic *efx = rx_queue->efx;
621 struct efx_rx_buffer *rx_buf;
622 int leak_packet = 0;
623
624 rx_buf = efx_rx_buffer(rx_queue, index);
625 EFX_BUG_ON_PARANOID(!rx_buf->data);
626 EFX_BUG_ON_PARANOID(rx_buf->skb && rx_buf->page);
627 EFX_BUG_ON_PARANOID(!(rx_buf->skb || rx_buf->page));
628
629 /* This allows the refill path to post another buffer.
630 * EFX_RXD_HEAD_ROOM ensures that the slot we are using
631 * isn't overwritten yet.
632 */
633 rx_queue->removed_count++;
634
635 /* Validate the length encoded in the event vs the descriptor pushed */
636 efx_rx_packet__check_len(rx_queue, rx_buf, len,
637 &discard, &leak_packet);
638
639 EFX_TRACE(efx, "RX queue %d received id %x at %llx+%x %s%s\n",
640 rx_queue->queue, index,
641 (unsigned long long)rx_buf->dma_addr, len,
642 (checksummed ? " [SUMMED]" : ""),
643 (discard ? " [DISCARD]" : ""));
644
645 /* Discard packet, if instructed to do so */
646 if (unlikely(discard)) {
647 if (unlikely(leak_packet))
648 rx_queue->channel->n_skbuff_leaks++;
649 else
650 /* We haven't called efx_unmap_rx_buffer yet,
651 * so fini the entire rx_buffer here */
652 efx_fini_rx_buffer(rx_queue, rx_buf);
653 return;
654 }
655
656 /* Release card resources - assumes all RX buffers consumed in-order
657 * per RX queue
658 */
659 efx_unmap_rx_buffer(efx, rx_buf);
660
661 /* Prefetch nice and early so data will (hopefully) be in cache by
662 * the time we look at it.
663 */
664 prefetch(rx_buf->data);
665
666 /* Pipeline receives so that we give time for packet headers to be
667 * prefetched into cache.
668 */
669 rx_buf->len = len;
670 if (rx_queue->channel->rx_pkt)
671 __efx_rx_packet(rx_queue->channel,
672 rx_queue->channel->rx_pkt,
673 rx_queue->channel->rx_pkt_csummed);
674 rx_queue->channel->rx_pkt = rx_buf;
675 rx_queue->channel->rx_pkt_csummed = checksummed;
676}
677
678/* Handle a received packet. Second half: Touches packet payload. */
679void __efx_rx_packet(struct efx_channel *channel,
680 struct efx_rx_buffer *rx_buf, int checksummed)
681{
682 struct efx_nic *efx = channel->efx;
683 struct sk_buff *skb;
684 int lro = efx->net_dev->features & NETIF_F_LRO;
685
686 if (rx_buf->skb) {
687 prefetch(skb_shinfo(rx_buf->skb));
688
689 skb_put(rx_buf->skb, rx_buf->len);
690
691 /* Move past the ethernet header. rx_buf->data still points
692 * at the ethernet header */
693 rx_buf->skb->protocol = eth_type_trans(rx_buf->skb,
694 efx->net_dev);
695 }
696
697 /* Both our generic-LRO and SFC-SSR support skb and page based
698 * allocation, but neither support switching from one to the
699 * other on the fly. If we spot that the allocation mode has
700 * changed, then flush the LRO state.
701 */
702 if (unlikely(channel->rx_alloc_pop_pages != (rx_buf->page != NULL))) {
703 efx_flush_lro(channel);
704 channel->rx_alloc_pop_pages = (rx_buf->page != NULL);
705 }
706 if (likely(checksummed && lro)) {
707 efx_rx_packet_lro(channel, rx_buf);
708 goto done;
709 }
710
711 /* Form an skb if required */
712 if (rx_buf->page) {
713 int hdr_len = min(rx_buf->len, EFX_SKB_HEADERS);
714 skb = efx_rx_mk_skb(rx_buf, efx, hdr_len);
715 if (unlikely(skb == NULL)) {
716 efx_free_rx_buffer(efx, rx_buf);
717 goto done;
718 }
719 } else {
720 /* We now own the SKB */
721 skb = rx_buf->skb;
722 rx_buf->skb = NULL;
723 }
724
725 EFX_BUG_ON_PARANOID(rx_buf->page);
726 EFX_BUG_ON_PARANOID(rx_buf->skb);
727 EFX_BUG_ON_PARANOID(!skb);
728
729 /* Set the SKB flags */
730 if (unlikely(!checksummed || !efx->rx_checksum_enabled))
731 skb->ip_summed = CHECKSUM_NONE;
732
733 /* Pass the packet up */
734 netif_receive_skb(skb);
735
736 /* Update allocation strategy method */
737 channel->rx_alloc_level += RX_ALLOC_FACTOR_SKB;
738
739 /* fall-thru */
740done:
741 efx->net_dev->last_rx = jiffies;
742}
743
744void efx_rx_strategy(struct efx_channel *channel)
745{
746 enum efx_rx_alloc_method method = rx_alloc_method;
747
748 /* Only makes sense to use page based allocation if LRO is enabled */
749 if (!(channel->efx->net_dev->features & NETIF_F_LRO)) {
750 method = RX_ALLOC_METHOD_SKB;
751 } else if (method == RX_ALLOC_METHOD_AUTO) {
752 /* Constrain the rx_alloc_level */
753 if (channel->rx_alloc_level < 0)
754 channel->rx_alloc_level = 0;
755 else if (channel->rx_alloc_level > RX_ALLOC_LEVEL_MAX)
756 channel->rx_alloc_level = RX_ALLOC_LEVEL_MAX;
757
758 /* Decide on the allocation method */
759 method = ((channel->rx_alloc_level > RX_ALLOC_LEVEL_LRO) ?
760 RX_ALLOC_METHOD_PAGE : RX_ALLOC_METHOD_SKB);
761 }
762
763 /* Push the option */
764 channel->rx_alloc_push_pages = (method == RX_ALLOC_METHOD_PAGE);
765}
766
767int efx_probe_rx_queue(struct efx_rx_queue *rx_queue)
768{
769 struct efx_nic *efx = rx_queue->efx;
770 unsigned int rxq_size;
771 int rc;
772
773 EFX_LOG(efx, "creating RX queue %d\n", rx_queue->queue);
774
775 /* Allocate RX buffers */
776 rxq_size = (efx->type->rxd_ring_mask + 1) * sizeof(*rx_queue->buffer);
777 rx_queue->buffer = kzalloc(rxq_size, GFP_KERNEL);
778 if (!rx_queue->buffer) {
779 rc = -ENOMEM;
780 goto fail1;
781 }
782
783 rc = falcon_probe_rx(rx_queue);
784 if (rc)
785 goto fail2;
786
787 return 0;
788
789 fail2:
790 kfree(rx_queue->buffer);
791 rx_queue->buffer = NULL;
792 fail1:
793 rx_queue->used = 0;
794
795 return rc;
796}
797
798int efx_init_rx_queue(struct efx_rx_queue *rx_queue)
799{
800 struct efx_nic *efx = rx_queue->efx;
801 unsigned int max_fill, trigger, limit;
802
803 EFX_LOG(rx_queue->efx, "initialising RX queue %d\n", rx_queue->queue);
804
805 /* Initialise ptr fields */
806 rx_queue->added_count = 0;
807 rx_queue->notified_count = 0;
808 rx_queue->removed_count = 0;
809 rx_queue->min_fill = -1U;
810 rx_queue->min_overfill = -1U;
811
812 /* Initialise limit fields */
813 max_fill = efx->type->rxd_ring_mask + 1 - EFX_RXD_HEAD_ROOM;
814 trigger = max_fill * min(rx_refill_threshold, 100U) / 100U;
815 limit = max_fill * min(rx_refill_limit, 100U) / 100U;
816
817 rx_queue->max_fill = max_fill;
818 rx_queue->fast_fill_trigger = trigger;
819 rx_queue->fast_fill_limit = limit;
820
821 /* Set up RX descriptor ring */
822 return falcon_init_rx(rx_queue);
823}
824
825void efx_fini_rx_queue(struct efx_rx_queue *rx_queue)
826{
827 int i;
828 struct efx_rx_buffer *rx_buf;
829
830 EFX_LOG(rx_queue->efx, "shutting down RX queue %d\n", rx_queue->queue);
831
832 falcon_fini_rx(rx_queue);
833
834 /* Release RX buffers NB start at index 0 not current HW ptr */
835 if (rx_queue->buffer) {
836 for (i = 0; i <= rx_queue->efx->type->rxd_ring_mask; i++) {
837 rx_buf = efx_rx_buffer(rx_queue, i);
838 efx_fini_rx_buffer(rx_queue, rx_buf);
839 }
840 }
841
842 /* For a page that is part-way through splitting into RX buffers */
843 if (rx_queue->buf_page != NULL) {
844 pci_unmap_page(rx_queue->efx->pci_dev, rx_queue->buf_dma_addr,
845 RX_PAGE_SIZE(rx_queue->efx), PCI_DMA_FROMDEVICE);
846 __free_pages(rx_queue->buf_page,
847 rx_queue->efx->rx_buffer_order);
848 rx_queue->buf_page = NULL;
849 }
850}
851
852void efx_remove_rx_queue(struct efx_rx_queue *rx_queue)
853{
854 EFX_LOG(rx_queue->efx, "destroying RX queue %d\n", rx_queue->queue);
855
856 falcon_remove_rx(rx_queue);
857
858 kfree(rx_queue->buffer);
859 rx_queue->buffer = NULL;
860 rx_queue->used = 0;
861}
862
863void efx_flush_lro(struct efx_channel *channel)
864{
865 lro_flush_all(&channel->lro_mgr);
866}
867
868
869module_param(rx_alloc_method, int, 0644);
870MODULE_PARM_DESC(rx_alloc_method, "Allocation method used for RX buffers");
871
872module_param(rx_refill_threshold, uint, 0444);
873MODULE_PARM_DESC(rx_refill_threshold,
874 "RX descriptor ring fast/slow fill threshold (%)");
875
diff --git a/drivers/net/sfc/rx.h b/drivers/net/sfc/rx.h
new file mode 100644
index 000000000000..f35e377bfc5f
--- /dev/null
+++ b/drivers/net/sfc/rx.h
@@ -0,0 +1,29 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2006 Solarflare Communications Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, incorporated herein by reference.
8 */
9
10#ifndef EFX_RX_H
11#define EFX_RX_H
12
13#include "net_driver.h"
14
15int efx_probe_rx_queue(struct efx_rx_queue *rx_queue);
16void efx_remove_rx_queue(struct efx_rx_queue *rx_queue);
17int efx_init_rx_queue(struct efx_rx_queue *rx_queue);
18void efx_fini_rx_queue(struct efx_rx_queue *rx_queue);
19
20int efx_lro_init(struct net_lro_mgr *lro_mgr, struct efx_nic *efx);
21void efx_lro_fini(struct net_lro_mgr *lro_mgr);
22void efx_flush_lro(struct efx_channel *channel);
23void efx_rx_strategy(struct efx_channel *channel);
24void efx_fast_push_rx_descriptors(struct efx_rx_queue *rx_queue);
25void efx_rx_work(struct work_struct *data);
26void __efx_rx_packet(struct efx_channel *channel,
27 struct efx_rx_buffer *rx_buf, int checksummed);
28
29#endif /* EFX_RX_H */
diff --git a/drivers/net/sfc/sfe4001.c b/drivers/net/sfc/sfe4001.c
new file mode 100644
index 000000000000..11fa9fb8f48b
--- /dev/null
+++ b/drivers/net/sfc/sfe4001.c
@@ -0,0 +1,252 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2007 Solarflare Communications Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, incorporated herein by reference.
8 */
9
10/*****************************************************************************
11 * Support for the SFE4001 NIC: driver code for the PCA9539 I/O expander that
12 * controls the PHY power rails, and for the MAX6647 temp. sensor used to check
13 * the PHY
14 */
15#include <linux/delay.h>
16#include "efx.h"
17#include "phy.h"
18#include "boards.h"
19#include "falcon.h"
20#include "falcon_hwdefs.h"
21#include "mac.h"
22
23/**************************************************************************
24 *
25 * I2C IO Expander device
26 *
27 **************************************************************************/
28#define PCA9539 0x74
29
30#define P0_IN 0x00
31#define P0_OUT 0x02
32#define P0_INVERT 0x04
33#define P0_CONFIG 0x06
34
35#define P0_EN_1V0X_LBN 0
36#define P0_EN_1V0X_WIDTH 1
37#define P0_EN_1V2_LBN 1
38#define P0_EN_1V2_WIDTH 1
39#define P0_EN_2V5_LBN 2
40#define P0_EN_2V5_WIDTH 1
41#define P0_EN_3V3X_LBN 3
42#define P0_EN_3V3X_WIDTH 1
43#define P0_EN_5V_LBN 4
44#define P0_EN_5V_WIDTH 1
45#define P0_SHORTEN_JTAG_LBN 5
46#define P0_SHORTEN_JTAG_WIDTH 1
47#define P0_X_TRST_LBN 6
48#define P0_X_TRST_WIDTH 1
49#define P0_DSP_RESET_LBN 7
50#define P0_DSP_RESET_WIDTH 1
51
52#define P1_IN 0x01
53#define P1_OUT 0x03
54#define P1_INVERT 0x05
55#define P1_CONFIG 0x07
56
57#define P1_AFE_PWD_LBN 0
58#define P1_AFE_PWD_WIDTH 1
59#define P1_DSP_PWD25_LBN 1
60#define P1_DSP_PWD25_WIDTH 1
61#define P1_RESERVED_LBN 2
62#define P1_RESERVED_WIDTH 2
63#define P1_SPARE_LBN 4
64#define P1_SPARE_WIDTH 4
65
66
67/**************************************************************************
68 *
69 * Temperature Sensor
70 *
71 **************************************************************************/
72#define MAX6647 0x4e
73
74#define RLTS 0x00
75#define RLTE 0x01
76#define RSL 0x02
77#define RCL 0x03
78#define RCRA 0x04
79#define RLHN 0x05
80#define RLLI 0x06
81#define RRHI 0x07
82#define RRLS 0x08
83#define WCRW 0x0a
84#define WLHO 0x0b
85#define WRHA 0x0c
86#define WRLN 0x0e
87#define OSHT 0x0f
88#define REET 0x10
89#define RIET 0x11
90#define RWOE 0x19
91#define RWOI 0x20
92#define HYS 0x21
93#define QUEUE 0x22
94#define MFID 0xfe
95#define REVID 0xff
96
97/* Status bits */
98#define MAX6647_BUSY (1 << 7) /* ADC is converting */
99#define MAX6647_LHIGH (1 << 6) /* Local high temp. alarm */
100#define MAX6647_LLOW (1 << 5) /* Local low temp. alarm */
101#define MAX6647_RHIGH (1 << 4) /* Remote high temp. alarm */
102#define MAX6647_RLOW (1 << 3) /* Remote low temp. alarm */
103#define MAX6647_FAULT (1 << 2) /* DXN/DXP short/open circuit */
104#define MAX6647_EOT (1 << 1) /* Remote junction overtemp. */
105#define MAX6647_IOT (1 << 0) /* Local junction overtemp. */
106
107static const u8 xgphy_max_temperature = 90;
108
109void sfe4001_poweroff(struct efx_nic *efx)
110{
111 struct efx_i2c_interface *i2c = &efx->i2c;
112
113 u8 cfg, out, in;
114
115 EFX_INFO(efx, "%s\n", __func__);
116
117 /* Turn off all power rails */
118 out = 0xff;
119 (void) efx_i2c_write(i2c, PCA9539, P0_OUT, &out, 1);
120
121 /* Disable port 1 outputs on IO expander */
122 cfg = 0xff;
123 (void) efx_i2c_write(i2c, PCA9539, P1_CONFIG, &cfg, 1);
124
125 /* Disable port 0 outputs on IO expander */
126 cfg = 0xff;
127 (void) efx_i2c_write(i2c, PCA9539, P0_CONFIG, &cfg, 1);
128
129 /* Clear any over-temperature alert */
130 (void) efx_i2c_read(i2c, MAX6647, RSL, &in, 1);
131}
132
133/* This board uses an I2C expander to provider power to the PHY, which needs to
134 * be turned on before the PHY can be used.
135 * Context: Process context, rtnl lock held
136 */
137int sfe4001_poweron(struct efx_nic *efx)
138{
139 struct efx_i2c_interface *i2c = &efx->i2c;
140 unsigned int count;
141 int rc;
142 u8 out, in, cfg;
143 efx_dword_t reg;
144
145 /* 10Xpress has fixed-function LED pins, so there is no board-specific
146 * blink code. */
147 efx->board_info.blink = tenxpress_phy_blink;
148
149 /* Ensure that XGXS and XAUI SerDes are held in reset */
150 EFX_POPULATE_DWORD_7(reg, XX_PWRDNA_EN, 1,
151 XX_PWRDNB_EN, 1,
152 XX_RSTPLLAB_EN, 1,
153 XX_RESETA_EN, 1,
154 XX_RESETB_EN, 1,
155 XX_RSTXGXSRX_EN, 1,
156 XX_RSTXGXSTX_EN, 1);
157 falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
158 udelay(10);
159
160 /* Set DSP over-temperature alert threshold */
161 EFX_INFO(efx, "DSP cut-out at %dC\n", xgphy_max_temperature);
162 rc = efx_i2c_write(i2c, MAX6647, WLHO,
163 &xgphy_max_temperature, 1);
164 if (rc)
165 goto fail1;
166
167 /* Read it back and verify */
168 rc = efx_i2c_read(i2c, MAX6647, RLHN, &in, 1);
169 if (rc)
170 goto fail1;
171 if (in != xgphy_max_temperature) {
172 rc = -EFAULT;
173 goto fail1;
174 }
175
176 /* Clear any previous over-temperature alert */
177 rc = efx_i2c_read(i2c, MAX6647, RSL, &in, 1);
178 if (rc)
179 goto fail1;
180
181 /* Enable port 0 and port 1 outputs on IO expander */
182 cfg = 0x00;
183 rc = efx_i2c_write(i2c, PCA9539, P0_CONFIG, &cfg, 1);
184 if (rc)
185 goto fail1;
186 cfg = 0xff & ~(1 << P1_SPARE_LBN);
187 rc = efx_i2c_write(i2c, PCA9539, P1_CONFIG, &cfg, 1);
188 if (rc)
189 goto fail2;
190
191 /* Turn all power off then wait 1 sec. This ensures PHY is reset */
192 out = 0xff & ~((0 << P0_EN_1V2_LBN) | (0 << P0_EN_2V5_LBN) |
193 (0 << P0_EN_3V3X_LBN) | (0 << P0_EN_5V_LBN) |
194 (0 << P0_EN_1V0X_LBN));
195 rc = efx_i2c_write(i2c, PCA9539, P0_OUT, &out, 1);
196 if (rc)
197 goto fail3;
198
199 schedule_timeout_uninterruptible(HZ);
200 count = 0;
201 do {
202 /* Turn on 1.2V, 2.5V, 3.3V and 5V power rails */
203 out = 0xff & ~((1 << P0_EN_1V2_LBN) | (1 << P0_EN_2V5_LBN) |
204 (1 << P0_EN_3V3X_LBN) | (1 << P0_EN_5V_LBN) |
205 (1 << P0_X_TRST_LBN));
206
207 rc = efx_i2c_write(i2c, PCA9539, P0_OUT, &out, 1);
208 if (rc)
209 goto fail3;
210 msleep(10);
211
212 /* Turn on 1V power rail */
213 out &= ~(1 << P0_EN_1V0X_LBN);
214 rc = efx_i2c_write(i2c, PCA9539, P0_OUT, &out, 1);
215 if (rc)
216 goto fail3;
217
218 EFX_INFO(efx, "waiting for power (attempt %d)...\n", count);
219
220 schedule_timeout_uninterruptible(HZ);
221
222 /* Check DSP is powered */
223 rc = efx_i2c_read(i2c, PCA9539, P1_IN, &in, 1);
224 if (rc)
225 goto fail3;
226 if (in & (1 << P1_AFE_PWD_LBN))
227 goto done;
228
229 } while (++count < 20);
230
231 EFX_INFO(efx, "timed out waiting for power\n");
232 rc = -ETIMEDOUT;
233 goto fail3;
234
235done:
236 EFX_INFO(efx, "PHY is powered on\n");
237 return 0;
238
239fail3:
240 /* Turn off all power rails */
241 out = 0xff;
242 (void) efx_i2c_write(i2c, PCA9539, P0_OUT, &out, 1);
243 /* Disable port 1 outputs on IO expander */
244 out = 0xff;
245 (void) efx_i2c_write(i2c, PCA9539, P1_CONFIG, &out, 1);
246fail2:
247 /* Disable port 0 outputs on IO expander */
248 out = 0xff;
249 (void) efx_i2c_write(i2c, PCA9539, P0_CONFIG, &out, 1);
250fail1:
251 return rc;
252}
diff --git a/drivers/net/sfc/spi.h b/drivers/net/sfc/spi.h
new file mode 100644
index 000000000000..34412f3d41c9
--- /dev/null
+++ b/drivers/net/sfc/spi.h
@@ -0,0 +1,71 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005 Fen Systems Ltd.
4 * Copyright 2006 Solarflare Communications Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
11#ifndef EFX_SPI_H
12#define EFX_SPI_H
13
14#include "net_driver.h"
15
16/**************************************************************************
17 *
18 * Basic SPI command set and bit definitions
19 *
20 *************************************************************************/
21
22/*
23 * Commands common to all known devices.
24 *
25 */
26
27/* Write status register */
28#define SPI_WRSR 0x01
29
30/* Write data to memory array */
31#define SPI_WRITE 0x02
32
33/* Read data from memory array */
34#define SPI_READ 0x03
35
36/* Reset write enable latch */
37#define SPI_WRDI 0x04
38
39/* Read status register */
40#define SPI_RDSR 0x05
41
42/* Set write enable latch */
43#define SPI_WREN 0x06
44
45/* SST: Enable write to status register */
46#define SPI_SST_EWSR 0x50
47
48/*
49 * Status register bits. Not all bits are supported on all devices.
50 *
51 */
52
53/* Write-protect pin enabled */
54#define SPI_STATUS_WPEN 0x80
55
56/* Block protection bit 2 */
57#define SPI_STATUS_BP2 0x10
58
59/* Block protection bit 1 */
60#define SPI_STATUS_BP1 0x08
61
62/* Block protection bit 0 */
63#define SPI_STATUS_BP0 0x04
64
65/* State of the write enable latch */
66#define SPI_STATUS_WEN 0x02
67
68/* Device busy flag */
69#define SPI_STATUS_NRDY 0x01
70
71#endif /* EFX_SPI_H */
diff --git a/drivers/net/sfc/tenxpress.c b/drivers/net/sfc/tenxpress.c
new file mode 100644
index 000000000000..a2e9f79e47b1
--- /dev/null
+++ b/drivers/net/sfc/tenxpress.c
@@ -0,0 +1,434 @@
1/****************************************************************************
2 * Driver for Solarflare 802.3an compliant PHY
3 * Copyright 2007 Solarflare Communications Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, incorporated herein by reference.
8 */
9
10#include <linux/delay.h>
11#include <linux/seq_file.h>
12#include "efx.h"
13#include "gmii.h"
14#include "mdio_10g.h"
15#include "falcon.h"
16#include "phy.h"
17#include "falcon_hwdefs.h"
18#include "boards.h"
19#include "mac.h"
20
21/* We expect these MMDs to be in the package */
22/* AN not here as mdio_check_mmds() requires STAT2 support */
23#define TENXPRESS_REQUIRED_DEVS (MDIO_MMDREG_DEVS0_PMAPMD | \
24 MDIO_MMDREG_DEVS0_PCS | \
25 MDIO_MMDREG_DEVS0_PHYXS)
26
27/* We complain if we fail to see the link partner as 10G capable this many
28 * times in a row (must be > 1 as sampling the autoneg. registers is racy)
29 */
30#define MAX_BAD_LP_TRIES (5)
31
32/* Extended control register */
33#define PMA_PMD_XCONTROL_REG 0xc000
34#define PMA_PMD_LNPGA_POWERDOWN_LBN 8
35#define PMA_PMD_LNPGA_POWERDOWN_WIDTH 1
36
37/* extended status register */
38#define PMA_PMD_XSTATUS_REG 0xc001
39#define PMA_PMD_XSTAT_FLP_LBN (12)
40
41/* LED control register */
42#define PMA_PMD_LED_CTRL_REG (0xc007)
43#define PMA_PMA_LED_ACTIVITY_LBN (3)
44
45/* LED function override register */
46#define PMA_PMD_LED_OVERR_REG (0xc009)
47/* Bit positions for different LEDs (there are more but not wired on SFE4001)*/
48#define PMA_PMD_LED_LINK_LBN (0)
49#define PMA_PMD_LED_SPEED_LBN (2)
50#define PMA_PMD_LED_TX_LBN (4)
51#define PMA_PMD_LED_RX_LBN (6)
52/* Override settings */
53#define PMA_PMD_LED_AUTO (0) /* H/W control */
54#define PMA_PMD_LED_ON (1)
55#define PMA_PMD_LED_OFF (2)
56#define PMA_PMD_LED_FLASH (3)
57/* All LEDs under hardware control */
58#define PMA_PMD_LED_FULL_AUTO (0)
59/* Green and Amber under hardware control, Red off */
60#define PMA_PMD_LED_DEFAULT (PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN)
61
62
63/* Self test (BIST) control register */
64#define PMA_PMD_BIST_CTRL_REG (0xc014)
65#define PMA_PMD_BIST_BER_LBN (2) /* Run BER test */
66#define PMA_PMD_BIST_CONT_LBN (1) /* Run continuous BIST until cleared */
67#define PMA_PMD_BIST_SINGLE_LBN (0) /* Run 1 BIST iteration (self clears) */
68/* Self test status register */
69#define PMA_PMD_BIST_STAT_REG (0xc015)
70#define PMA_PMD_BIST_ENX_LBN (3)
71#define PMA_PMD_BIST_PMA_LBN (2)
72#define PMA_PMD_BIST_RXD_LBN (1)
73#define PMA_PMD_BIST_AFE_LBN (0)
74
75#define BIST_MAX_DELAY (1000)
76#define BIST_POLL_DELAY (10)
77
78/* Misc register defines */
79#define PCS_CLOCK_CTRL_REG 0xd801
80#define PLL312_RST_N_LBN 2
81
82#define PCS_SOFT_RST2_REG 0xd806
83#define SERDES_RST_N_LBN 13
84#define XGXS_RST_N_LBN 12
85
86#define PCS_TEST_SELECT_REG 0xd807 /* PRM 10.5.8 */
87#define CLK312_EN_LBN 3
88
89/* Boot status register */
90#define PCS_BOOT_STATUS_REG (0xd000)
91#define PCS_BOOT_FATAL_ERR_LBN (0)
92#define PCS_BOOT_PROGRESS_LBN (1)
93#define PCS_BOOT_PROGRESS_WIDTH (2)
94#define PCS_BOOT_COMPLETE_LBN (3)
95#define PCS_BOOT_MAX_DELAY (100)
96#define PCS_BOOT_POLL_DELAY (10)
97
98/* Time to wait between powering down the LNPGA and turning off the power
99 * rails */
100#define LNPGA_PDOWN_WAIT (HZ / 5)
101
102static int crc_error_reset_threshold = 100;
103module_param(crc_error_reset_threshold, int, 0644);
104MODULE_PARM_DESC(crc_error_reset_threshold,
105 "Max number of CRC errors before XAUI reset");
106
107struct tenxpress_phy_data {
108 enum tenxpress_state state;
109 atomic_t bad_crc_count;
110 int bad_lp_tries;
111};
112
113static int tenxpress_state_is(struct efx_nic *efx, int state)
114{
115 struct tenxpress_phy_data *phy_data = efx->phy_data;
116 return (phy_data != NULL) && (state == phy_data->state);
117}
118
119void tenxpress_set_state(struct efx_nic *efx,
120 enum tenxpress_state state)
121{
122 struct tenxpress_phy_data *phy_data = efx->phy_data;
123 if (phy_data != NULL)
124 phy_data->state = state;
125}
126
127void tenxpress_crc_err(struct efx_nic *efx)
128{
129 struct tenxpress_phy_data *phy_data = efx->phy_data;
130 if (phy_data != NULL)
131 atomic_inc(&phy_data->bad_crc_count);
132}
133
134/* Check that the C166 has booted successfully */
135static int tenxpress_phy_check(struct efx_nic *efx)
136{
137 int phy_id = efx->mii.phy_id;
138 int count = PCS_BOOT_MAX_DELAY / PCS_BOOT_POLL_DELAY;
139 int boot_stat;
140
141 /* Wait for the boot to complete (or not) */
142 while (count) {
143 boot_stat = mdio_clause45_read(efx, phy_id,
144 MDIO_MMD_PCS,
145 PCS_BOOT_STATUS_REG);
146 if (boot_stat & (1 << PCS_BOOT_COMPLETE_LBN))
147 break;
148 count--;
149 udelay(PCS_BOOT_POLL_DELAY);
150 }
151
152 if (!count) {
153 EFX_ERR(efx, "%s: PHY boot timed out. Last status "
154 "%x\n", __func__,
155 (boot_stat >> PCS_BOOT_PROGRESS_LBN) &
156 ((1 << PCS_BOOT_PROGRESS_WIDTH) - 1));
157 return -ETIMEDOUT;
158 }
159
160 return 0;
161}
162
163static void tenxpress_reset_xaui(struct efx_nic *efx);
164
165static int tenxpress_init(struct efx_nic *efx)
166{
167 int rc, reg;
168
169 /* Turn on the clock */
170 reg = (1 << CLK312_EN_LBN);
171 mdio_clause45_write(efx, efx->mii.phy_id,
172 MDIO_MMD_PCS, PCS_TEST_SELECT_REG, reg);
173
174 rc = tenxpress_phy_check(efx);
175 if (rc < 0)
176 return rc;
177
178 /* Set the LEDs up as: Green = Link, Amber = Link/Act, Red = Off */
179 reg = mdio_clause45_read(efx, efx->mii.phy_id,
180 MDIO_MMD_PMAPMD, PMA_PMD_LED_CTRL_REG);
181 reg |= (1 << PMA_PMA_LED_ACTIVITY_LBN);
182 mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
183 PMA_PMD_LED_CTRL_REG, reg);
184
185 reg = PMA_PMD_LED_DEFAULT;
186 mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
187 PMA_PMD_LED_OVERR_REG, reg);
188
189 return rc;
190}
191
192static int tenxpress_phy_init(struct efx_nic *efx)
193{
194 struct tenxpress_phy_data *phy_data;
195 int rc = 0;
196
197 phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL);
198 efx->phy_data = phy_data;
199
200 tenxpress_set_state(efx, TENXPRESS_STATUS_NORMAL);
201
202 rc = mdio_clause45_wait_reset_mmds(efx,
203 TENXPRESS_REQUIRED_DEVS);
204 if (rc < 0)
205 goto fail;
206
207 rc = mdio_clause45_check_mmds(efx, TENXPRESS_REQUIRED_DEVS, 0);
208 if (rc < 0)
209 goto fail;
210
211 rc = tenxpress_init(efx);
212 if (rc < 0)
213 goto fail;
214
215 schedule_timeout_uninterruptible(HZ / 5); /* 200ms */
216
217 /* Let XGXS and SerDes out of reset and resets 10XPress */
218 falcon_reset_xaui(efx);
219
220 return 0;
221
222 fail:
223 kfree(efx->phy_data);
224 efx->phy_data = NULL;
225 return rc;
226}
227
228static void tenxpress_set_bad_lp(struct efx_nic *efx, int bad_lp)
229{
230 struct tenxpress_phy_data *pd = efx->phy_data;
231 int reg;
232
233 /* Nothing to do if all is well and was previously so. */
234 if (!(bad_lp || pd->bad_lp_tries))
235 return;
236
237 reg = mdio_clause45_read(efx, efx->mii.phy_id,
238 MDIO_MMD_PMAPMD, PMA_PMD_LED_OVERR_REG);
239
240 if (bad_lp)
241 pd->bad_lp_tries++;
242 else
243 pd->bad_lp_tries = 0;
244
245 if (pd->bad_lp_tries == MAX_BAD_LP_TRIES) {
246 pd->bad_lp_tries = 0; /* Restart count */
247 reg &= ~(PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN);
248 reg |= (PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN);
249 EFX_ERR(efx, "This NIC appears to be plugged into"
250 " a port that is not 10GBASE-T capable.\n"
251 " This PHY is 10GBASE-T ONLY, so no link can"
252 " be established.\n");
253 } else {
254 reg |= (PMA_PMD_LED_OFF << PMA_PMD_LED_RX_LBN);
255 }
256 mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
257 PMA_PMD_LED_OVERR_REG, reg);
258}
259
260/* Check link status and return a boolean OK value. If the link is NOT
261 * OK we have a quick rummage round to see if we appear to be plugged
262 * into a non-10GBT port and if so warn the user that they won't get
263 * link any time soon as we are 10GBT only, unless caller specified
264 * not to do this check (it isn't useful in loopback) */
265static int tenxpress_link_ok(struct efx_nic *efx, int check_lp)
266{
267 int ok = mdio_clause45_links_ok(efx, TENXPRESS_REQUIRED_DEVS);
268
269 if (ok) {
270 tenxpress_set_bad_lp(efx, 0);
271 } else if (check_lp) {
272 /* Are we plugged into the wrong sort of link? */
273 int bad_lp = 0;
274 int phy_id = efx->mii.phy_id;
275 int an_stat = mdio_clause45_read(efx, phy_id, MDIO_MMD_AN,
276 MDIO_AN_STATUS);
277 int xphy_stat = mdio_clause45_read(efx, phy_id,
278 MDIO_MMD_PMAPMD,
279 PMA_PMD_XSTATUS_REG);
280 /* Are we plugged into anything that sends FLPs? If
281 * not we can't distinguish between not being plugged
282 * in and being plugged into a non-AN antique. The FLP
283 * bit has the advantage of not clearing when autoneg
284 * restarts. */
285 if (!(xphy_stat & (1 << PMA_PMD_XSTAT_FLP_LBN))) {
286 tenxpress_set_bad_lp(efx, 0);
287 return ok;
288 }
289
290 /* If it can do 10GBT it must be XNP capable */
291 bad_lp = !(an_stat & (1 << MDIO_AN_STATUS_XNP_LBN));
292 if (!bad_lp && (an_stat & (1 << MDIO_AN_STATUS_PAGE_LBN))) {
293 bad_lp = !(mdio_clause45_read(efx, phy_id,
294 MDIO_MMD_AN, MDIO_AN_10GBT_STATUS) &
295 (1 << MDIO_AN_10GBT_STATUS_LP_10G_LBN));
296 }
297 tenxpress_set_bad_lp(efx, bad_lp);
298 }
299 return ok;
300}
301
302static void tenxpress_phy_reconfigure(struct efx_nic *efx)
303{
304 if (!tenxpress_state_is(efx, TENXPRESS_STATUS_NORMAL))
305 return;
306
307 efx->link_up = tenxpress_link_ok(efx, 0);
308 efx->link_options = GM_LPA_10000FULL;
309}
310
311static void tenxpress_phy_clear_interrupt(struct efx_nic *efx)
312{
313 /* Nothing done here - LASI interrupts aren't reliable so poll */
314}
315
316
317/* Poll PHY for interrupt */
318static int tenxpress_phy_check_hw(struct efx_nic *efx)
319{
320 struct tenxpress_phy_data *phy_data = efx->phy_data;
321 int phy_up = tenxpress_state_is(efx, TENXPRESS_STATUS_NORMAL);
322 int link_ok;
323
324 link_ok = phy_up && tenxpress_link_ok(efx, 1);
325
326 if (link_ok != efx->link_up)
327 falcon_xmac_sim_phy_event(efx);
328
329 /* Nothing to check if we've already shut down the PHY */
330 if (!phy_up)
331 return 0;
332
333 if (atomic_read(&phy_data->bad_crc_count) > crc_error_reset_threshold) {
334 EFX_ERR(efx, "Resetting XAUI due to too many CRC errors\n");
335 falcon_reset_xaui(efx);
336 atomic_set(&phy_data->bad_crc_count, 0);
337 }
338
339 return 0;
340}
341
342static void tenxpress_phy_fini(struct efx_nic *efx)
343{
344 int reg;
345
346 /* Power down the LNPGA */
347 reg = (1 << PMA_PMD_LNPGA_POWERDOWN_LBN);
348 mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
349 PMA_PMD_XCONTROL_REG, reg);
350
351 /* Waiting here ensures that the board fini, which can turn off the
352 * power to the PHY, won't get run until the LNPGA powerdown has been
353 * given long enough to complete. */
354 schedule_timeout_uninterruptible(LNPGA_PDOWN_WAIT); /* 200 ms */
355
356 kfree(efx->phy_data);
357 efx->phy_data = NULL;
358}
359
360
361/* Set the RX and TX LEDs and Link LED flashing. The other LEDs
362 * (which probably aren't wired anyway) are left in AUTO mode */
363void tenxpress_phy_blink(struct efx_nic *efx, int blink)
364{
365 int reg;
366
367 if (blink)
368 reg = (PMA_PMD_LED_FLASH << PMA_PMD_LED_TX_LBN) |
369 (PMA_PMD_LED_FLASH << PMA_PMD_LED_RX_LBN) |
370 (PMA_PMD_LED_FLASH << PMA_PMD_LED_LINK_LBN);
371 else
372 reg = PMA_PMD_LED_DEFAULT;
373
374 mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
375 PMA_PMD_LED_OVERR_REG, reg);
376}
377
378static void tenxpress_reset_xaui(struct efx_nic *efx)
379{
380 int phy = efx->mii.phy_id;
381 int clk_ctrl, test_select, soft_rst2;
382
383 /* Real work is done on clock_ctrl other resets are thought to be
384 * optional but make the reset more reliable
385 */
386
387 /* Read */
388 clk_ctrl = mdio_clause45_read(efx, phy, MDIO_MMD_PCS,
389 PCS_CLOCK_CTRL_REG);
390 test_select = mdio_clause45_read(efx, phy, MDIO_MMD_PCS,
391 PCS_TEST_SELECT_REG);
392 soft_rst2 = mdio_clause45_read(efx, phy, MDIO_MMD_PCS,
393 PCS_SOFT_RST2_REG);
394
395 /* Put in reset */
396 test_select &= ~(1 << CLK312_EN_LBN);
397 mdio_clause45_write(efx, phy, MDIO_MMD_PCS,
398 PCS_TEST_SELECT_REG, test_select);
399
400 soft_rst2 &= ~((1 << XGXS_RST_N_LBN) | (1 << SERDES_RST_N_LBN));
401 mdio_clause45_write(efx, phy, MDIO_MMD_PCS,
402 PCS_SOFT_RST2_REG, soft_rst2);
403
404 clk_ctrl &= ~(1 << PLL312_RST_N_LBN);
405 mdio_clause45_write(efx, phy, MDIO_MMD_PCS,
406 PCS_CLOCK_CTRL_REG, clk_ctrl);
407 udelay(10);
408
409 /* Remove reset */
410 clk_ctrl |= (1 << PLL312_RST_N_LBN);
411 mdio_clause45_write(efx, phy, MDIO_MMD_PCS,
412 PCS_CLOCK_CTRL_REG, clk_ctrl);
413 udelay(10);
414
415 soft_rst2 |= ((1 << XGXS_RST_N_LBN) | (1 << SERDES_RST_N_LBN));
416 mdio_clause45_write(efx, phy, MDIO_MMD_PCS,
417 PCS_SOFT_RST2_REG, soft_rst2);
418 udelay(10);
419
420 test_select |= (1 << CLK312_EN_LBN);
421 mdio_clause45_write(efx, phy, MDIO_MMD_PCS,
422 PCS_TEST_SELECT_REG, test_select);
423 udelay(10);
424}
425
426struct efx_phy_operations falcon_tenxpress_phy_ops = {
427 .init = tenxpress_phy_init,
428 .reconfigure = tenxpress_phy_reconfigure,
429 .check_hw = tenxpress_phy_check_hw,
430 .fini = tenxpress_phy_fini,
431 .clear_interrupt = tenxpress_phy_clear_interrupt,
432 .reset_xaui = tenxpress_reset_xaui,
433 .mmds = TENXPRESS_REQUIRED_DEVS,
434};
diff --git a/drivers/net/sfc/tx.c b/drivers/net/sfc/tx.c
new file mode 100644
index 000000000000..fbb866b2185e
--- /dev/null
+++ b/drivers/net/sfc/tx.c
@@ -0,0 +1,452 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2005-2008 Solarflare Communications Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
11#include <linux/pci.h>
12#include <linux/tcp.h>
13#include <linux/ip.h>
14#include <linux/in.h>
15#include <linux/if_ether.h>
16#include <linux/highmem.h>
17#include "net_driver.h"
18#include "tx.h"
19#include "efx.h"
20#include "falcon.h"
21#include "workarounds.h"
22
23/*
24 * TX descriptor ring full threshold
25 *
26 * The tx_queue descriptor ring fill-level must fall below this value
27 * before we restart the netif queue
28 */
29#define EFX_NETDEV_TX_THRESHOLD(_tx_queue) \
30 (_tx_queue->efx->type->txd_ring_mask / 2u)
31
32/* We want to be able to nest calls to netif_stop_queue(), since each
33 * channel can have an individual stop on the queue.
34 */
35void efx_stop_queue(struct efx_nic *efx)
36{
37 spin_lock_bh(&efx->netif_stop_lock);
38 EFX_TRACE(efx, "stop TX queue\n");
39
40 atomic_inc(&efx->netif_stop_count);
41 netif_stop_queue(efx->net_dev);
42
43 spin_unlock_bh(&efx->netif_stop_lock);
44}
45
46/* Wake netif's TX queue
47 * We want to be able to nest calls to netif_stop_queue(), since each
48 * channel can have an individual stop on the queue.
49 */
50inline void efx_wake_queue(struct efx_nic *efx)
51{
52 local_bh_disable();
53 if (atomic_dec_and_lock(&efx->netif_stop_count,
54 &efx->netif_stop_lock)) {
55 EFX_TRACE(efx, "waking TX queue\n");
56 netif_wake_queue(efx->net_dev);
57 spin_unlock(&efx->netif_stop_lock);
58 }
59 local_bh_enable();
60}
61
62static inline void efx_dequeue_buffer(struct efx_tx_queue *tx_queue,
63 struct efx_tx_buffer *buffer)
64{
65 if (buffer->unmap_len) {
66 struct pci_dev *pci_dev = tx_queue->efx->pci_dev;
67 if (buffer->unmap_single)
68 pci_unmap_single(pci_dev, buffer->unmap_addr,
69 buffer->unmap_len, PCI_DMA_TODEVICE);
70 else
71 pci_unmap_page(pci_dev, buffer->unmap_addr,
72 buffer->unmap_len, PCI_DMA_TODEVICE);
73 buffer->unmap_len = 0;
74 buffer->unmap_single = 0;
75 }
76
77 if (buffer->skb) {
78 dev_kfree_skb_any((struct sk_buff *) buffer->skb);
79 buffer->skb = NULL;
80 EFX_TRACE(tx_queue->efx, "TX queue %d transmission id %x "
81 "complete\n", tx_queue->queue, read_ptr);
82 }
83}
84
85
86/*
87 * Add a socket buffer to a TX queue
88 *
89 * This maps all fragments of a socket buffer for DMA and adds them to
90 * the TX queue. The queue's insert pointer will be incremented by
91 * the number of fragments in the socket buffer.
92 *
93 * If any DMA mapping fails, any mapped fragments will be unmapped,
94 * the queue's insert pointer will be restored to its original value.
95 *
96 * Returns NETDEV_TX_OK or NETDEV_TX_BUSY
97 * You must hold netif_tx_lock() to call this function.
98 */
99static inline int efx_enqueue_skb(struct efx_tx_queue *tx_queue,
100 const struct sk_buff *skb)
101{
102 struct efx_nic *efx = tx_queue->efx;
103 struct pci_dev *pci_dev = efx->pci_dev;
104 struct efx_tx_buffer *buffer;
105 skb_frag_t *fragment;
106 struct page *page;
107 int page_offset;
108 unsigned int len, unmap_len = 0, fill_level, insert_ptr, misalign;
109 dma_addr_t dma_addr, unmap_addr = 0;
110 unsigned int dma_len;
111 unsigned unmap_single;
112 int q_space, i = 0;
113 int rc = NETDEV_TX_OK;
114
115 EFX_BUG_ON_PARANOID(tx_queue->write_count != tx_queue->insert_count);
116
117 /* Get size of the initial fragment */
118 len = skb_headlen(skb);
119
120 fill_level = tx_queue->insert_count - tx_queue->old_read_count;
121 q_space = efx->type->txd_ring_mask - 1 - fill_level;
122
123 /* Map for DMA. Use pci_map_single rather than pci_map_page
124 * since this is more efficient on machines with sparse
125 * memory.
126 */
127 unmap_single = 1;
128 dma_addr = pci_map_single(pci_dev, skb->data, len, PCI_DMA_TODEVICE);
129
130 /* Process all fragments */
131 while (1) {
132 if (unlikely(pci_dma_mapping_error(dma_addr)))
133 goto pci_err;
134
135 /* Store fields for marking in the per-fragment final
136 * descriptor */
137 unmap_len = len;
138 unmap_addr = dma_addr;
139
140 /* Add to TX queue, splitting across DMA boundaries */
141 do {
142 if (unlikely(q_space-- <= 0)) {
143 /* It might be that completions have
144 * happened since the xmit path last
145 * checked. Update the xmit path's
146 * copy of read_count.
147 */
148 ++tx_queue->stopped;
149 /* This memory barrier protects the
150 * change of stopped from the access
151 * of read_count. */
152 smp_mb();
153 tx_queue->old_read_count =
154 *(volatile unsigned *)
155 &tx_queue->read_count;
156 fill_level = (tx_queue->insert_count
157 - tx_queue->old_read_count);
158 q_space = (efx->type->txd_ring_mask - 1 -
159 fill_level);
160 if (unlikely(q_space-- <= 0))
161 goto stop;
162 smp_mb();
163 --tx_queue->stopped;
164 }
165
166 insert_ptr = (tx_queue->insert_count &
167 efx->type->txd_ring_mask);
168 buffer = &tx_queue->buffer[insert_ptr];
169 EFX_BUG_ON_PARANOID(buffer->skb);
170 EFX_BUG_ON_PARANOID(buffer->len);
171 EFX_BUG_ON_PARANOID(buffer->continuation != 1);
172 EFX_BUG_ON_PARANOID(buffer->unmap_len);
173
174 dma_len = (((~dma_addr) & efx->type->tx_dma_mask) + 1);
175 if (likely(dma_len > len))
176 dma_len = len;
177
178 misalign = (unsigned)dma_addr & efx->type->bug5391_mask;
179 if (misalign && dma_len + misalign > 512)
180 dma_len = 512 - misalign;
181
182 /* Fill out per descriptor fields */
183 buffer->len = dma_len;
184 buffer->dma_addr = dma_addr;
185 len -= dma_len;
186 dma_addr += dma_len;
187 ++tx_queue->insert_count;
188 } while (len);
189
190 /* Transfer ownership of the unmapping to the final buffer */
191 buffer->unmap_addr = unmap_addr;
192 buffer->unmap_single = unmap_single;
193 buffer->unmap_len = unmap_len;
194 unmap_len = 0;
195
196 /* Get address and size of next fragment */
197 if (i >= skb_shinfo(skb)->nr_frags)
198 break;
199 fragment = &skb_shinfo(skb)->frags[i];
200 len = fragment->size;
201 page = fragment->page;
202 page_offset = fragment->page_offset;
203 i++;
204 /* Map for DMA */
205 unmap_single = 0;
206 dma_addr = pci_map_page(pci_dev, page, page_offset, len,
207 PCI_DMA_TODEVICE);
208 }
209
210 /* Transfer ownership of the skb to the final buffer */
211 buffer->skb = skb;
212 buffer->continuation = 0;
213
214 /* Pass off to hardware */
215 falcon_push_buffers(tx_queue);
216
217 return NETDEV_TX_OK;
218
219 pci_err:
220 EFX_ERR_RL(efx, " TX queue %d could not map skb with %d bytes %d "
221 "fragments for DMA\n", tx_queue->queue, skb->len,
222 skb_shinfo(skb)->nr_frags + 1);
223
224 /* Mark the packet as transmitted, and free the SKB ourselves */
225 dev_kfree_skb_any((struct sk_buff *)skb);
226 goto unwind;
227
228 stop:
229 rc = NETDEV_TX_BUSY;
230
231 if (tx_queue->stopped == 1)
232 efx_stop_queue(efx);
233
234 unwind:
235 /* Work backwards until we hit the original insert pointer value */
236 while (tx_queue->insert_count != tx_queue->write_count) {
237 --tx_queue->insert_count;
238 insert_ptr = tx_queue->insert_count & efx->type->txd_ring_mask;
239 buffer = &tx_queue->buffer[insert_ptr];
240 efx_dequeue_buffer(tx_queue, buffer);
241 buffer->len = 0;
242 }
243
244 /* Free the fragment we were mid-way through pushing */
245 if (unmap_len)
246 pci_unmap_page(pci_dev, unmap_addr, unmap_len,
247 PCI_DMA_TODEVICE);
248
249 return rc;
250}
251
252/* Remove packets from the TX queue
253 *
254 * This removes packets from the TX queue, up to and including the
255 * specified index.
256 */
257static inline void efx_dequeue_buffers(struct efx_tx_queue *tx_queue,
258 unsigned int index)
259{
260 struct efx_nic *efx = tx_queue->efx;
261 unsigned int stop_index, read_ptr;
262 unsigned int mask = tx_queue->efx->type->txd_ring_mask;
263
264 stop_index = (index + 1) & mask;
265 read_ptr = tx_queue->read_count & mask;
266
267 while (read_ptr != stop_index) {
268 struct efx_tx_buffer *buffer = &tx_queue->buffer[read_ptr];
269 if (unlikely(buffer->len == 0)) {
270 EFX_ERR(tx_queue->efx, "TX queue %d spurious TX "
271 "completion id %x\n", tx_queue->queue,
272 read_ptr);
273 efx_schedule_reset(efx, RESET_TYPE_TX_SKIP);
274 return;
275 }
276
277 efx_dequeue_buffer(tx_queue, buffer);
278 buffer->continuation = 1;
279 buffer->len = 0;
280
281 ++tx_queue->read_count;
282 read_ptr = tx_queue->read_count & mask;
283 }
284}
285
286/* Initiate a packet transmission on the specified TX queue.
287 * Note that returning anything other than NETDEV_TX_OK will cause the
288 * OS to free the skb.
289 *
290 * This function is split out from efx_hard_start_xmit to allow the
291 * loopback test to direct packets via specific TX queues. It is
292 * therefore a non-static inline, so as not to penalise performance
293 * for non-loopback transmissions.
294 *
295 * Context: netif_tx_lock held
296 */
297inline int efx_xmit(struct efx_nic *efx,
298 struct efx_tx_queue *tx_queue, struct sk_buff *skb)
299{
300 int rc;
301
302 /* Map fragments for DMA and add to TX queue */
303 rc = efx_enqueue_skb(tx_queue, skb);
304 if (unlikely(rc != NETDEV_TX_OK))
305 goto out;
306
307 /* Update last TX timer */
308 efx->net_dev->trans_start = jiffies;
309
310 out:
311 return rc;
312}
313
314/* Initiate a packet transmission. We use one channel per CPU
315 * (sharing when we have more CPUs than channels). On Falcon, the TX
316 * completion events will be directed back to the CPU that transmitted
317 * the packet, which should be cache-efficient.
318 *
319 * Context: non-blocking.
320 * Note that returning anything other than NETDEV_TX_OK will cause the
321 * OS to free the skb.
322 */
323int efx_hard_start_xmit(struct sk_buff *skb, struct net_device *net_dev)
324{
325 struct efx_nic *efx = net_dev->priv;
326 return efx_xmit(efx, &efx->tx_queue[0], skb);
327}
328
329void efx_xmit_done(struct efx_tx_queue *tx_queue, unsigned int index)
330{
331 unsigned fill_level;
332 struct efx_nic *efx = tx_queue->efx;
333
334 EFX_BUG_ON_PARANOID(index > efx->type->txd_ring_mask);
335
336 efx_dequeue_buffers(tx_queue, index);
337
338 /* See if we need to restart the netif queue. This barrier
339 * separates the update of read_count from the test of
340 * stopped. */
341 smp_mb();
342 if (unlikely(tx_queue->stopped)) {
343 fill_level = tx_queue->insert_count - tx_queue->read_count;
344 if (fill_level < EFX_NETDEV_TX_THRESHOLD(tx_queue)) {
345 EFX_BUG_ON_PARANOID(!NET_DEV_REGISTERED(efx));
346
347 /* Do this under netif_tx_lock(), to avoid racing
348 * with efx_xmit(). */
349 netif_tx_lock(efx->net_dev);
350 if (tx_queue->stopped) {
351 tx_queue->stopped = 0;
352 efx_wake_queue(efx);
353 }
354 netif_tx_unlock(efx->net_dev);
355 }
356 }
357}
358
359int efx_probe_tx_queue(struct efx_tx_queue *tx_queue)
360{
361 struct efx_nic *efx = tx_queue->efx;
362 unsigned int txq_size;
363 int i, rc;
364
365 EFX_LOG(efx, "creating TX queue %d\n", tx_queue->queue);
366
367 /* Allocate software ring */
368 txq_size = (efx->type->txd_ring_mask + 1) * sizeof(*tx_queue->buffer);
369 tx_queue->buffer = kzalloc(txq_size, GFP_KERNEL);
370 if (!tx_queue->buffer) {
371 rc = -ENOMEM;
372 goto fail1;
373 }
374 for (i = 0; i <= efx->type->txd_ring_mask; ++i)
375 tx_queue->buffer[i].continuation = 1;
376
377 /* Allocate hardware ring */
378 rc = falcon_probe_tx(tx_queue);
379 if (rc)
380 goto fail2;
381
382 return 0;
383
384 fail2:
385 kfree(tx_queue->buffer);
386 tx_queue->buffer = NULL;
387 fail1:
388 tx_queue->used = 0;
389
390 return rc;
391}
392
393int efx_init_tx_queue(struct efx_tx_queue *tx_queue)
394{
395 EFX_LOG(tx_queue->efx, "initialising TX queue %d\n", tx_queue->queue);
396
397 tx_queue->insert_count = 0;
398 tx_queue->write_count = 0;
399 tx_queue->read_count = 0;
400 tx_queue->old_read_count = 0;
401 BUG_ON(tx_queue->stopped);
402
403 /* Set up TX descriptor ring */
404 return falcon_init_tx(tx_queue);
405}
406
407void efx_release_tx_buffers(struct efx_tx_queue *tx_queue)
408{
409 struct efx_tx_buffer *buffer;
410
411 if (!tx_queue->buffer)
412 return;
413
414 /* Free any buffers left in the ring */
415 while (tx_queue->read_count != tx_queue->write_count) {
416 buffer = &tx_queue->buffer[tx_queue->read_count &
417 tx_queue->efx->type->txd_ring_mask];
418 efx_dequeue_buffer(tx_queue, buffer);
419 buffer->continuation = 1;
420 buffer->len = 0;
421
422 ++tx_queue->read_count;
423 }
424}
425
426void efx_fini_tx_queue(struct efx_tx_queue *tx_queue)
427{
428 EFX_LOG(tx_queue->efx, "shutting down TX queue %d\n", tx_queue->queue);
429
430 /* Flush TX queue, remove descriptor ring */
431 falcon_fini_tx(tx_queue);
432
433 efx_release_tx_buffers(tx_queue);
434
435 /* Release queue's stop on port, if any */
436 if (tx_queue->stopped) {
437 tx_queue->stopped = 0;
438 efx_wake_queue(tx_queue->efx);
439 }
440}
441
442void efx_remove_tx_queue(struct efx_tx_queue *tx_queue)
443{
444 EFX_LOG(tx_queue->efx, "destroying TX queue %d\n", tx_queue->queue);
445 falcon_remove_tx(tx_queue);
446
447 kfree(tx_queue->buffer);
448 tx_queue->buffer = NULL;
449 tx_queue->used = 0;
450}
451
452
diff --git a/drivers/net/sfc/tx.h b/drivers/net/sfc/tx.h
new file mode 100644
index 000000000000..1526a73b4b51
--- /dev/null
+++ b/drivers/net/sfc/tx.h
@@ -0,0 +1,24 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2006 Fen Systems Ltd.
4 * Copyright 2006-2008 Solarflare Communications Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
9 */
10
11#ifndef EFX_TX_H
12#define EFX_TX_H
13
14#include "net_driver.h"
15
16int efx_probe_tx_queue(struct efx_tx_queue *tx_queue);
17void efx_remove_tx_queue(struct efx_tx_queue *tx_queue);
18int efx_init_tx_queue(struct efx_tx_queue *tx_queue);
19void efx_fini_tx_queue(struct efx_tx_queue *tx_queue);
20
21int efx_hard_start_xmit(struct sk_buff *skb, struct net_device *net_dev);
22void efx_release_tx_buffers(struct efx_tx_queue *tx_queue);
23
24#endif /* EFX_TX_H */
diff --git a/drivers/net/sfc/workarounds.h b/drivers/net/sfc/workarounds.h
new file mode 100644
index 000000000000..dca62f190198
--- /dev/null
+++ b/drivers/net/sfc/workarounds.h
@@ -0,0 +1,56 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2006-2008 Solarflare Communications Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, incorporated herein by reference.
8 */
9
10#ifndef EFX_WORKAROUNDS_H
11#define EFX_WORKAROUNDS_H
12
13/*
14 * Hardware workarounds.
15 * Bug numbers are from Solarflare's Bugzilla.
16 */
17
18#define EFX_WORKAROUND_ALWAYS(efx) 1
19#define EFX_WORKAROUND_FALCON_A(efx) (FALCON_REV(efx) <= FALCON_REV_A1)
20
21/* XAUI resets if link not detected */
22#define EFX_WORKAROUND_5147 EFX_WORKAROUND_ALWAYS
23/* SNAP frames have TOBE_DISC set */
24#define EFX_WORKAROUND_5475 EFX_WORKAROUND_ALWAYS
25/* RX PCIe double split performance issue */
26#define EFX_WORKAROUND_7575 EFX_WORKAROUND_ALWAYS
27/* TX pkt parser problem with <= 16 byte TXes */
28#define EFX_WORKAROUND_9141 EFX_WORKAROUND_ALWAYS
29/* XGXS and XAUI reset sequencing in SW */
30#define EFX_WORKAROUND_9388 EFX_WORKAROUND_ALWAYS
31/* Low rate CRC errors require XAUI reset */
32#define EFX_WORKAROUND_10750 EFX_WORKAROUND_ALWAYS
33/* TX_EV_PKT_ERR can be caused by a dangling TX descriptor
34 * or a PCIe error (bug 11028) */
35#define EFX_WORKAROUND_10727 EFX_WORKAROUND_ALWAYS
36/* Transmit flow control may get disabled */
37#define EFX_WORKAROUND_11482 EFX_WORKAROUND_ALWAYS
38/* Flush events can take a very long time to appear */
39#define EFX_WORKAROUND_11557 EFX_WORKAROUND_ALWAYS
40
41/* Spurious parity errors in TSORT buffers */
42#define EFX_WORKAROUND_5129 EFX_WORKAROUND_FALCON_A
43/* iSCSI parsing errors */
44#define EFX_WORKAROUND_5583 EFX_WORKAROUND_FALCON_A
45/* RX events go missing */
46#define EFX_WORKAROUND_5676 EFX_WORKAROUND_FALCON_A
47/* RX_RESET on A1 */
48#define EFX_WORKAROUND_6555 EFX_WORKAROUND_FALCON_A
49/* Increase filter depth to avoid RX_RESET */
50#define EFX_WORKAROUND_7244 EFX_WORKAROUND_FALCON_A
51/* Flushes may never complete */
52#define EFX_WORKAROUND_7803 EFX_WORKAROUND_FALCON_A
53/* Leak overlength packets rather than free */
54#define EFX_WORKAROUND_8071 EFX_WORKAROUND_FALCON_A
55
56#endif /* EFX_WORKAROUNDS_H */
diff --git a/drivers/net/sfc/xenpack.h b/drivers/net/sfc/xenpack.h
new file mode 100644
index 000000000000..b0d1f225b70a
--- /dev/null
+++ b/drivers/net/sfc/xenpack.h
@@ -0,0 +1,62 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2006 Solarflare Communications Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, incorporated herein by reference.
8 */
9
10#ifndef EFX_XENPACK_H
11#define EFX_XENPACK_H
12
13/* Exported functions from Xenpack standard PHY control */
14
15#include "mdio_10g.h"
16
17/****************************************************************************/
18/* XENPACK MDIO register extensions */
19#define MDIO_XP_LASI_RX_CTRL (0x9000)
20#define MDIO_XP_LASI_TX_CTRL (0x9001)
21#define MDIO_XP_LASI_CTRL (0x9002)
22#define MDIO_XP_LASI_RX_STAT (0x9003)
23#define MDIO_XP_LASI_TX_STAT (0x9004)
24#define MDIO_XP_LASI_STAT (0x9005)
25
26/* Control/Status bits */
27#define XP_LASI_LS_ALARM (1 << 0)
28#define XP_LASI_TX_ALARM (1 << 1)
29#define XP_LASI_RX_ALARM (1 << 2)
30/* These two are Quake vendor extensions to the standard XENPACK defines */
31#define XP_LASI_LS_INTB (1 << 3)
32#define XP_LASI_TEST (1 << 7)
33
34/* Enable LASI interrupts for PHY */
35static inline void xenpack_enable_lasi_irqs(struct efx_nic *efx)
36{
37 int reg;
38 int phy_id = efx->mii.phy_id;
39 /* Read to clear LASI status register */
40 reg = mdio_clause45_read(efx, phy_id, MDIO_MMD_PMAPMD,
41 MDIO_XP_LASI_STAT);
42
43 mdio_clause45_write(efx, phy_id, MDIO_MMD_PMAPMD,
44 MDIO_XP_LASI_CTRL, XP_LASI_LS_ALARM);
45}
46
47/* Read the LASI interrupt status to clear the interrupt. */
48static inline int xenpack_clear_lasi_irqs(struct efx_nic *efx)
49{
50 /* Read to clear link status alarm */
51 return mdio_clause45_read(efx, efx->mii.phy_id,
52 MDIO_MMD_PMAPMD, MDIO_XP_LASI_STAT);
53}
54
55/* Turn off LASI interrupts */
56static inline void xenpack_disable_lasi_irqs(struct efx_nic *efx)
57{
58 mdio_clause45_write(efx, efx->mii.phy_id, MDIO_MMD_PMAPMD,
59 MDIO_XP_LASI_CTRL, 0);
60}
61
62#endif /* EFX_XENPACK_H */
diff --git a/drivers/net/sfc/xfp_phy.c b/drivers/net/sfc/xfp_phy.c
new file mode 100644
index 000000000000..66dd5bf1eaa9
--- /dev/null
+++ b/drivers/net/sfc/xfp_phy.c
@@ -0,0 +1,132 @@
1/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2006-2008 Solarflare Communications Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation, incorporated herein by reference.
8 */
9/*
10 * Driver for XFP optical PHYs (plus some support specific to the Quake 2032)
11 * See www.amcc.com for details (search for qt2032)
12 */
13
14#include <linux/timer.h>
15#include <linux/delay.h>
16#include "efx.h"
17#include "gmii.h"
18#include "mdio_10g.h"
19#include "xenpack.h"
20#include "phy.h"
21#include "mac.h"
22
23#define XFP_REQUIRED_DEVS (MDIO_MMDREG_DEVS0_PCS | \
24 MDIO_MMDREG_DEVS0_PMAPMD | \
25 MDIO_MMDREG_DEVS0_PHYXS)
26
27/****************************************************************************/
28/* Quake-specific MDIO registers */
29#define MDIO_QUAKE_LED0_REG (0xD006)
30
31void xfp_set_led(struct efx_nic *p, int led, int mode)
32{
33 int addr = MDIO_QUAKE_LED0_REG + led;
34 mdio_clause45_write(p, p->mii.phy_id, MDIO_MMD_PMAPMD, addr,
35 mode);
36}
37
38#define XFP_MAX_RESET_TIME 500
39#define XFP_RESET_WAIT 10
40
41/* Reset the PHYXS MMD. This is documented (for the Quake PHY) as doing
42 * a complete soft reset.
43 */
44static int xfp_reset_phy(struct efx_nic *efx)
45{
46 int rc;
47
48 rc = mdio_clause45_reset_mmd(efx, MDIO_MMD_PHYXS,
49 XFP_MAX_RESET_TIME / XFP_RESET_WAIT,
50 XFP_RESET_WAIT);
51 if (rc < 0)
52 goto fail;
53
54 /* Wait 250ms for the PHY to complete bootup */
55 msleep(250);
56
57 /* Check that all the MMDs we expect are present and responding. We
58 * expect faults on some if the link is down, but not on the PHY XS */
59 rc = mdio_clause45_check_mmds(efx, XFP_REQUIRED_DEVS,
60 MDIO_MMDREG_DEVS0_PHYXS);
61 if (rc < 0)
62 goto fail;
63
64 efx->board_info.init_leds(efx);
65
66 return rc;
67
68 fail:
69 EFX_ERR(efx, "XFP: reset timed out!\n");
70 return rc;
71}
72
73static int xfp_phy_init(struct efx_nic *efx)
74{
75 u32 devid = mdio_clause45_read_id(efx, MDIO_MMD_PHYXS);
76 int rc;
77
78 EFX_INFO(efx, "XFP: PHY ID reg %x (OUI %x model %x revision"
79 " %x)\n", devid, MDIO_ID_OUI(devid), MDIO_ID_MODEL(devid),
80 MDIO_ID_REV(devid));
81
82 rc = xfp_reset_phy(efx);
83
84 EFX_INFO(efx, "XFP: PHY init %s.\n",
85 rc ? "failed" : "successful");
86
87 return rc;
88}
89
90static void xfp_phy_clear_interrupt(struct efx_nic *efx)
91{
92 xenpack_clear_lasi_irqs(efx);
93}
94
95static int xfp_link_ok(struct efx_nic *efx)
96{
97 return mdio_clause45_links_ok(efx, XFP_REQUIRED_DEVS);
98}
99
100static int xfp_phy_check_hw(struct efx_nic *efx)
101{
102 int rc = 0;
103 int link_up = xfp_link_ok(efx);
104 /* Simulate a PHY event if link state has changed */
105 if (link_up != efx->link_up)
106 falcon_xmac_sim_phy_event(efx);
107
108 return rc;
109}
110
111static void xfp_phy_reconfigure(struct efx_nic *efx)
112{
113 efx->link_up = xfp_link_ok(efx);
114 efx->link_options = GM_LPA_10000FULL;
115}
116
117
118static void xfp_phy_fini(struct efx_nic *efx)
119{
120 /* Clobber the LED if it was blinking */
121 efx->board_info.blink(efx, 0);
122}
123
124struct efx_phy_operations falcon_xfp_phy_ops = {
125 .init = xfp_phy_init,
126 .reconfigure = xfp_phy_reconfigure,
127 .check_hw = xfp_phy_check_hw,
128 .fini = xfp_phy_fini,
129 .clear_interrupt = xfp_phy_clear_interrupt,
130 .reset_xaui = efx_port_dummy_op_void,
131 .mmds = XFP_REQUIRED_DEVS,
132};
diff --git a/drivers/net/sis190.c b/drivers/net/sis190.c
index 20745fd4e973..abc63b0663be 100644
--- a/drivers/net/sis190.c
+++ b/drivers/net/sis190.c
@@ -212,6 +212,12 @@ enum _DescStatusBit {
212 THOL2 = 0x20000000, 212 THOL2 = 0x20000000,
213 THOL1 = 0x10000000, 213 THOL1 = 0x10000000,
214 THOL0 = 0x00000000, 214 THOL0 = 0x00000000,
215
216 WND = 0x00080000,
217 TABRT = 0x00040000,
218 FIFO = 0x00020000,
219 LINK = 0x00010000,
220 ColCountMask = 0x0000ffff,
215 /* RxDesc.status */ 221 /* RxDesc.status */
216 IPON = 0x20000000, 222 IPON = 0x20000000,
217 TCPON = 0x10000000, 223 TCPON = 0x10000000,
@@ -480,30 +486,23 @@ static inline void sis190_make_unusable_by_asic(struct RxDesc *desc)
480 desc->status = 0x0; 486 desc->status = 0x0;
481} 487}
482 488
483static int sis190_alloc_rx_skb(struct pci_dev *pdev, struct sk_buff **sk_buff, 489static struct sk_buff *sis190_alloc_rx_skb(struct sis190_private *tp,
484 struct RxDesc *desc, u32 rx_buf_sz) 490 struct RxDesc *desc)
485{ 491{
492 u32 rx_buf_sz = tp->rx_buf_sz;
486 struct sk_buff *skb; 493 struct sk_buff *skb;
487 dma_addr_t mapping;
488 int ret = 0;
489
490 skb = dev_alloc_skb(rx_buf_sz);
491 if (!skb)
492 goto err_out;
493
494 *sk_buff = skb;
495 494
496 mapping = pci_map_single(pdev, skb->data, rx_buf_sz, 495 skb = netdev_alloc_skb(tp->dev, rx_buf_sz);
497 PCI_DMA_FROMDEVICE); 496 if (likely(skb)) {
497 dma_addr_t mapping;
498 498
499 sis190_map_to_asic(desc, mapping, rx_buf_sz); 499 mapping = pci_map_single(tp->pci_dev, skb->data, tp->rx_buf_sz,
500out: 500 PCI_DMA_FROMDEVICE);
501 return ret; 501 sis190_map_to_asic(desc, mapping, rx_buf_sz);
502 } else
503 sis190_make_unusable_by_asic(desc);
502 504
503err_out: 505 return skb;
504 ret = -ENOMEM;
505 sis190_make_unusable_by_asic(desc);
506 goto out;
507} 506}
508 507
509static u32 sis190_rx_fill(struct sis190_private *tp, struct net_device *dev, 508static u32 sis190_rx_fill(struct sis190_private *tp, struct net_device *dev,
@@ -512,37 +511,41 @@ static u32 sis190_rx_fill(struct sis190_private *tp, struct net_device *dev,
512 u32 cur; 511 u32 cur;
513 512
514 for (cur = start; cur < end; cur++) { 513 for (cur = start; cur < end; cur++) {
515 int ret, i = cur % NUM_RX_DESC; 514 unsigned int i = cur % NUM_RX_DESC;
516 515
517 if (tp->Rx_skbuff[i]) 516 if (tp->Rx_skbuff[i])
518 continue; 517 continue;
519 518
520 ret = sis190_alloc_rx_skb(tp->pci_dev, tp->Rx_skbuff + i, 519 tp->Rx_skbuff[i] = sis190_alloc_rx_skb(tp, tp->RxDescRing + i);
521 tp->RxDescRing + i, tp->rx_buf_sz); 520
522 if (ret < 0) 521 if (!tp->Rx_skbuff[i])
523 break; 522 break;
524 } 523 }
525 return cur - start; 524 return cur - start;
526} 525}
527 526
528static inline int sis190_try_rx_copy(struct sk_buff **sk_buff, int pkt_size, 527static bool sis190_try_rx_copy(struct sis190_private *tp,
529 struct RxDesc *desc, int rx_buf_sz) 528 struct sk_buff **sk_buff, int pkt_size,
529 dma_addr_t addr)
530{ 530{
531 int ret = -1; 531 struct sk_buff *skb;
532 bool done = false;
532 533
533 if (pkt_size < rx_copybreak) { 534 if (pkt_size >= rx_copybreak)
534 struct sk_buff *skb; 535 goto out;
535 536
536 skb = dev_alloc_skb(pkt_size + NET_IP_ALIGN); 537 skb = netdev_alloc_skb(tp->dev, pkt_size + 2);
537 if (skb) { 538 if (!skb)
538 skb_reserve(skb, NET_IP_ALIGN); 539 goto out;
539 skb_copy_to_linear_data(skb, sk_buff[0]->data, pkt_size); 540
540 *sk_buff = skb; 541 pci_dma_sync_single_for_device(tp->pci_dev, addr, pkt_size,
541 sis190_give_to_asic(desc, rx_buf_sz); 542 PCI_DMA_FROMDEVICE);
542 ret = 0; 543 skb_reserve(skb, 2);
543 } 544 skb_copy_to_linear_data(skb, sk_buff[0]->data, pkt_size);
544 } 545 *sk_buff = skb;
545 return ret; 546 done = true;
547out:
548 return done;
546} 549}
547 550
548static inline int sis190_rx_pkt_err(u32 status, struct net_device_stats *stats) 551static inline int sis190_rx_pkt_err(u32 status, struct net_device_stats *stats)
@@ -592,9 +595,9 @@ static int sis190_rx_interrupt(struct net_device *dev,
592 sis190_give_to_asic(desc, tp->rx_buf_sz); 595 sis190_give_to_asic(desc, tp->rx_buf_sz);
593 else { 596 else {
594 struct sk_buff *skb = tp->Rx_skbuff[entry]; 597 struct sk_buff *skb = tp->Rx_skbuff[entry];
598 dma_addr_t addr = le32_to_cpu(desc->addr);
595 int pkt_size = (status & RxSizeMask) - 4; 599 int pkt_size = (status & RxSizeMask) - 4;
596 void (*pci_action)(struct pci_dev *, dma_addr_t, 600 struct pci_dev *pdev = tp->pci_dev;
597 size_t, int) = pci_dma_sync_single_for_device;
598 601
599 if (unlikely(pkt_size > tp->rx_buf_sz)) { 602 if (unlikely(pkt_size > tp->rx_buf_sz)) {
600 net_intr(tp, KERN_INFO 603 net_intr(tp, KERN_INFO
@@ -606,20 +609,18 @@ static int sis190_rx_interrupt(struct net_device *dev,
606 continue; 609 continue;
607 } 610 }
608 611
609 pci_dma_sync_single_for_cpu(tp->pci_dev,
610 le32_to_cpu(desc->addr), tp->rx_buf_sz,
611 PCI_DMA_FROMDEVICE);
612 612
613 if (sis190_try_rx_copy(&skb, pkt_size, desc, 613 if (sis190_try_rx_copy(tp, &skb, pkt_size, addr)) {
614 tp->rx_buf_sz)) { 614 pci_dma_sync_single_for_device(pdev, addr,
615 pci_action = pci_unmap_single; 615 tp->rx_buf_sz, PCI_DMA_FROMDEVICE);
616 sis190_give_to_asic(desc, tp->rx_buf_sz);
617 } else {
618 pci_unmap_single(pdev, addr, tp->rx_buf_sz,
619 PCI_DMA_FROMDEVICE);
616 tp->Rx_skbuff[entry] = NULL; 620 tp->Rx_skbuff[entry] = NULL;
617 sis190_make_unusable_by_asic(desc); 621 sis190_make_unusable_by_asic(desc);
618 } 622 }
619 623
620 pci_action(tp->pci_dev, le32_to_cpu(desc->addr),
621 tp->rx_buf_sz, PCI_DMA_FROMDEVICE);
622
623 skb_put(skb, pkt_size); 624 skb_put(skb, pkt_size);
624 skb->protocol = eth_type_trans(skb, dev); 625 skb->protocol = eth_type_trans(skb, dev);
625 626
@@ -658,9 +659,31 @@ static void sis190_unmap_tx_skb(struct pci_dev *pdev, struct sk_buff *skb,
658 memset(desc, 0x00, sizeof(*desc)); 659 memset(desc, 0x00, sizeof(*desc));
659} 660}
660 661
662static inline int sis190_tx_pkt_err(u32 status, struct net_device_stats *stats)
663{
664#define TxErrMask (WND | TABRT | FIFO | LINK)
665
666 if (!unlikely(status & TxErrMask))
667 return 0;
668
669 if (status & WND)
670 stats->tx_window_errors++;
671 if (status & TABRT)
672 stats->tx_aborted_errors++;
673 if (status & FIFO)
674 stats->tx_fifo_errors++;
675 if (status & LINK)
676 stats->tx_carrier_errors++;
677
678 stats->tx_errors++;
679
680 return -1;
681}
682
661static void sis190_tx_interrupt(struct net_device *dev, 683static void sis190_tx_interrupt(struct net_device *dev,
662 struct sis190_private *tp, void __iomem *ioaddr) 684 struct sis190_private *tp, void __iomem *ioaddr)
663{ 685{
686 struct net_device_stats *stats = &dev->stats;
664 u32 pending, dirty_tx = tp->dirty_tx; 687 u32 pending, dirty_tx = tp->dirty_tx;
665 /* 688 /*
666 * It would not be needed if queueing was allowed to be enabled 689 * It would not be needed if queueing was allowed to be enabled
@@ -675,15 +698,19 @@ static void sis190_tx_interrupt(struct net_device *dev,
675 for (; pending; pending--, dirty_tx++) { 698 for (; pending; pending--, dirty_tx++) {
676 unsigned int entry = dirty_tx % NUM_TX_DESC; 699 unsigned int entry = dirty_tx % NUM_TX_DESC;
677 struct TxDesc *txd = tp->TxDescRing + entry; 700 struct TxDesc *txd = tp->TxDescRing + entry;
701 u32 status = le32_to_cpu(txd->status);
678 struct sk_buff *skb; 702 struct sk_buff *skb;
679 703
680 if (le32_to_cpu(txd->status) & OWNbit) 704 if (status & OWNbit)
681 break; 705 break;
682 706
683 skb = tp->Tx_skbuff[entry]; 707 skb = tp->Tx_skbuff[entry];
684 708
685 dev->stats.tx_packets++; 709 if (likely(sis190_tx_pkt_err(status, stats) == 0)) {
686 dev->stats.tx_bytes += skb->len; 710 stats->tx_packets++;
711 stats->tx_bytes += skb->len;
712 stats->collisions += ((status & ColCountMask) - 1);
713 }
687 714
688 sis190_unmap_tx_skb(tp->pci_dev, skb, txd); 715 sis190_unmap_tx_skb(tp->pci_dev, skb, txd);
689 tp->Tx_skbuff[entry] = NULL; 716 tp->Tx_skbuff[entry] = NULL;
@@ -904,10 +931,9 @@ static void sis190_phy_task(struct work_struct *work)
904 mod_timer(&tp->timer, jiffies + HZ/10); 931 mod_timer(&tp->timer, jiffies + HZ/10);
905 } else if (!(mdio_read_latched(ioaddr, phy_id, MII_BMSR) & 932 } else if (!(mdio_read_latched(ioaddr, phy_id, MII_BMSR) &
906 BMSR_ANEGCOMPLETE)) { 933 BMSR_ANEGCOMPLETE)) {
907 net_link(tp, KERN_WARNING "%s: PHY reset until link up.\n",
908 dev->name);
909 netif_carrier_off(dev); 934 netif_carrier_off(dev);
910 mdio_write(ioaddr, phy_id, MII_BMCR, val | BMCR_RESET); 935 net_link(tp, KERN_WARNING "%s: auto-negotiating...\n",
936 dev->name);
911 mod_timer(&tp->timer, jiffies + SIS190_PHY_TIMEOUT); 937 mod_timer(&tp->timer, jiffies + SIS190_PHY_TIMEOUT);
912 } else { 938 } else {
913 /* Rejoice ! */ 939 /* Rejoice ! */
diff --git a/drivers/net/slip.c b/drivers/net/slip.c
index 5a55ede352f4..84af68fdb6c2 100644
--- a/drivers/net/slip.c
+++ b/drivers/net/slip.c
@@ -396,14 +396,14 @@ static void sl_encaps(struct slip *sl, unsigned char *icp, int len)
396 396
397 /* Order of next two lines is *very* important. 397 /* Order of next two lines is *very* important.
398 * When we are sending a little amount of data, 398 * When we are sending a little amount of data,
399 * the transfer may be completed inside driver.write() 399 * the transfer may be completed inside the ops->write()
400 * routine, because it's running with interrupts enabled. 400 * routine, because it's running with interrupts enabled.
401 * In this case we *never* got WRITE_WAKEUP event, 401 * In this case we *never* got WRITE_WAKEUP event,
402 * if we did not request it before write operation. 402 * if we did not request it before write operation.
403 * 14 Oct 1994 Dmitry Gorodchanin. 403 * 14 Oct 1994 Dmitry Gorodchanin.
404 */ 404 */
405 sl->tty->flags |= (1 << TTY_DO_WRITE_WAKEUP); 405 sl->tty->flags |= (1 << TTY_DO_WRITE_WAKEUP);
406 actual = sl->tty->driver->write(sl->tty, sl->xbuff, count); 406 actual = sl->tty->ops->write(sl->tty, sl->xbuff, count);
407#ifdef SL_CHECK_TRANSMIT 407#ifdef SL_CHECK_TRANSMIT
408 sl->dev->trans_start = jiffies; 408 sl->dev->trans_start = jiffies;
409#endif 409#endif
@@ -437,7 +437,7 @@ static void slip_write_wakeup(struct tty_struct *tty)
437 return; 437 return;
438 } 438 }
439 439
440 actual = tty->driver->write(tty, sl->xhead, sl->xleft); 440 actual = tty->ops->write(tty, sl->xhead, sl->xleft);
441 sl->xleft -= actual; 441 sl->xleft -= actual;
442 sl->xhead += actual; 442 sl->xhead += actual;
443} 443}
@@ -462,7 +462,7 @@ static void sl_tx_timeout(struct net_device *dev)
462 } 462 }
463 printk(KERN_WARNING "%s: transmit timed out, %s?\n", 463 printk(KERN_WARNING "%s: transmit timed out, %s?\n",
464 dev->name, 464 dev->name,
465 (sl->tty->driver->chars_in_buffer(sl->tty) || sl->xleft) ? 465 (tty_chars_in_buffer(sl->tty) || sl->xleft) ?
466 "bad line quality" : "driver error"); 466 "bad line quality" : "driver error");
467 sl->xleft = 0; 467 sl->xleft = 0;
468 sl->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP); 468 sl->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
@@ -830,6 +830,9 @@ static int slip_open(struct tty_struct *tty)
830 if (!capable(CAP_NET_ADMIN)) 830 if (!capable(CAP_NET_ADMIN))
831 return -EPERM; 831 return -EPERM;
832 832
833 if (tty->ops->write == NULL)
834 return -EOPNOTSUPP;
835
833 /* RTnetlink lock is misused here to serialize concurrent 836 /* RTnetlink lock is misused here to serialize concurrent
834 opens of slip channels. There are better ways, but it is 837 opens of slip channels. There are better ways, but it is
835 the simplest one. 838 the simplest one.
@@ -1432,7 +1435,7 @@ static void sl_outfill(unsigned long sls)
1432 /* put END into tty queue. Is it right ??? */ 1435 /* put END into tty queue. Is it right ??? */
1433 if (!netif_queue_stopped(sl->dev)) { 1436 if (!netif_queue_stopped(sl->dev)) {
1434 /* if device busy no outfill */ 1437 /* if device busy no outfill */
1435 sl->tty->driver->write(sl->tty, &s, 1); 1438 sl->tty->ops->write(sl->tty, &s, 1);
1436 } 1439 }
1437 } else 1440 } else
1438 set_bit(SLF_OUTWAIT, &sl->flags); 1441 set_bit(SLF_OUTWAIT, &sl->flags);
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index b66c75e3b8a1..07b3f77e7626 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -64,8 +64,8 @@
64 64
65#define DRV_MODULE_NAME "tg3" 65#define DRV_MODULE_NAME "tg3"
66#define PFX DRV_MODULE_NAME ": " 66#define PFX DRV_MODULE_NAME ": "
67#define DRV_MODULE_VERSION "3.91" 67#define DRV_MODULE_VERSION "3.92"
68#define DRV_MODULE_RELDATE "April 18, 2008" 68#define DRV_MODULE_RELDATE "May 2, 2008"
69 69
70#define TG3_DEF_MAC_MODE 0 70#define TG3_DEF_MAC_MODE 0
71#define TG3_DEF_RX_MODE 0 71#define TG3_DEF_RX_MODE 0
@@ -1656,12 +1656,76 @@ static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
1656 return 0; 1656 return 0;
1657} 1657}
1658 1658
1659/* tp->lock is held. */
1660static void tg3_wait_for_event_ack(struct tg3 *tp)
1661{
1662 int i;
1663
1664 /* Wait for up to 2.5 milliseconds */
1665 for (i = 0; i < 250000; i++) {
1666 if (!(tr32(GRC_RX_CPU_EVENT) & GRC_RX_CPU_DRIVER_EVENT))
1667 break;
1668 udelay(10);
1669 }
1670}
1671
1672/* tp->lock is held. */
1673static void tg3_ump_link_report(struct tg3 *tp)
1674{
1675 u32 reg;
1676 u32 val;
1677
1678 if (!(tp->tg3_flags2 & TG3_FLG2_5780_CLASS) ||
1679 !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
1680 return;
1681
1682 tg3_wait_for_event_ack(tp);
1683
1684 tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_LINK_UPDATE);
1685
1686 tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 14);
1687
1688 val = 0;
1689 if (!tg3_readphy(tp, MII_BMCR, &reg))
1690 val = reg << 16;
1691 if (!tg3_readphy(tp, MII_BMSR, &reg))
1692 val |= (reg & 0xffff);
1693 tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, val);
1694
1695 val = 0;
1696 if (!tg3_readphy(tp, MII_ADVERTISE, &reg))
1697 val = reg << 16;
1698 if (!tg3_readphy(tp, MII_LPA, &reg))
1699 val |= (reg & 0xffff);
1700 tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 4, val);
1701
1702 val = 0;
1703 if (!(tp->tg3_flags2 & TG3_FLG2_MII_SERDES)) {
1704 if (!tg3_readphy(tp, MII_CTRL1000, &reg))
1705 val = reg << 16;
1706 if (!tg3_readphy(tp, MII_STAT1000, &reg))
1707 val |= (reg & 0xffff);
1708 }
1709 tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 8, val);
1710
1711 if (!tg3_readphy(tp, MII_PHYADDR, &reg))
1712 val = reg << 16;
1713 else
1714 val = 0;
1715 tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 12, val);
1716
1717 val = tr32(GRC_RX_CPU_EVENT);
1718 val |= GRC_RX_CPU_DRIVER_EVENT;
1719 tw32_f(GRC_RX_CPU_EVENT, val);
1720}
1721
1659static void tg3_link_report(struct tg3 *tp) 1722static void tg3_link_report(struct tg3 *tp)
1660{ 1723{
1661 if (!netif_carrier_ok(tp->dev)) { 1724 if (!netif_carrier_ok(tp->dev)) {
1662 if (netif_msg_link(tp)) 1725 if (netif_msg_link(tp))
1663 printk(KERN_INFO PFX "%s: Link is down.\n", 1726 printk(KERN_INFO PFX "%s: Link is down.\n",
1664 tp->dev->name); 1727 tp->dev->name);
1728 tg3_ump_link_report(tp);
1665 } else if (netif_msg_link(tp)) { 1729 } else if (netif_msg_link(tp)) {
1666 printk(KERN_INFO PFX "%s: Link is up at %d Mbps, %s duplex.\n", 1730 printk(KERN_INFO PFX "%s: Link is up at %d Mbps, %s duplex.\n",
1667 tp->dev->name, 1731 tp->dev->name,
@@ -1679,6 +1743,7 @@ static void tg3_link_report(struct tg3 *tp)
1679 "on" : "off", 1743 "on" : "off",
1680 (tp->link_config.active_flowctrl & TG3_FLOW_CTRL_RX) ? 1744 (tp->link_config.active_flowctrl & TG3_FLOW_CTRL_RX) ?
1681 "on" : "off"); 1745 "on" : "off");
1746 tg3_ump_link_report(tp);
1682 } 1747 }
1683} 1748}
1684 1749
@@ -2097,9 +2162,11 @@ static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset)
2097 MAC_STATUS_LNKSTATE_CHANGED)); 2162 MAC_STATUS_LNKSTATE_CHANGED));
2098 udelay(40); 2163 udelay(40);
2099 2164
2100 tp->mi_mode = MAC_MI_MODE_BASE; 2165 if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) {
2101 tw32_f(MAC_MI_MODE, tp->mi_mode); 2166 tw32_f(MAC_MI_MODE,
2102 udelay(80); 2167 (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL));
2168 udelay(80);
2169 }
2103 2170
2104 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x02); 2171 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x02);
2105 2172
@@ -5498,19 +5565,17 @@ static void tg3_stop_fw(struct tg3 *tp)
5498 if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) && 5565 if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) &&
5499 !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) { 5566 !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) {
5500 u32 val; 5567 u32 val;
5501 int i; 5568
5569 /* Wait for RX cpu to ACK the previous event. */
5570 tg3_wait_for_event_ack(tp);
5502 5571
5503 tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW); 5572 tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW);
5504 val = tr32(GRC_RX_CPU_EVENT); 5573 val = tr32(GRC_RX_CPU_EVENT);
5505 val |= (1 << 14); 5574 val |= GRC_RX_CPU_DRIVER_EVENT;
5506 tw32(GRC_RX_CPU_EVENT, val); 5575 tw32(GRC_RX_CPU_EVENT, val);
5507 5576
5508 /* Wait for RX cpu to ACK the event. */ 5577 /* Wait for RX cpu to ACK this event. */
5509 for (i = 0; i < 100; i++) { 5578 tg3_wait_for_event_ack(tp);
5510 if (!(tr32(GRC_RX_CPU_EVENT) & (1 << 14)))
5511 break;
5512 udelay(1);
5513 }
5514 } 5579 }
5515} 5580}
5516 5581
@@ -7102,7 +7167,7 @@ static int tg3_reset_hw(struct tg3 *tp, int reset_phy)
7102 tp->link_config.autoneg = tp->link_config.orig_autoneg; 7167 tp->link_config.autoneg = tp->link_config.orig_autoneg;
7103 } 7168 }
7104 7169
7105 tp->mi_mode = MAC_MI_MODE_BASE; 7170 tp->mi_mode &= ~MAC_MI_MODE_AUTO_POLL;
7106 tw32_f(MAC_MI_MODE, tp->mi_mode); 7171 tw32_f(MAC_MI_MODE, tp->mi_mode);
7107 udelay(80); 7172 udelay(80);
7108 7173
@@ -7400,14 +7465,16 @@ static void tg3_timer(unsigned long __opaque)
7400 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) { 7465 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
7401 u32 val; 7466 u32 val;
7402 7467
7468 tg3_wait_for_event_ack(tp);
7469
7403 tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, 7470 tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX,
7404 FWCMD_NICDRV_ALIVE3); 7471 FWCMD_NICDRV_ALIVE3);
7405 tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4); 7472 tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4);
7406 /* 5 seconds timeout */ 7473 /* 5 seconds timeout */
7407 tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 5); 7474 tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 5);
7408 val = tr32(GRC_RX_CPU_EVENT); 7475 val = tr32(GRC_RX_CPU_EVENT);
7409 val |= (1 << 14); 7476 val |= GRC_RX_CPU_DRIVER_EVENT;
7410 tw32(GRC_RX_CPU_EVENT, val); 7477 tw32_f(GRC_RX_CPU_EVENT, val);
7411 } 7478 }
7412 tp->asf_counter = tp->asf_multiplier; 7479 tp->asf_counter = tp->asf_multiplier;
7413 } 7480 }
@@ -9568,14 +9635,9 @@ static int tg3_test_loopback(struct tg3 *tp)
9568 9635
9569 /* Turn off link-based power management. */ 9636 /* Turn off link-based power management. */
9570 cpmuctrl = tr32(TG3_CPMU_CTRL); 9637 cpmuctrl = tr32(TG3_CPMU_CTRL);
9571 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || 9638 tw32(TG3_CPMU_CTRL,
9572 GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) 9639 cpmuctrl & ~(CPMU_CTRL_LINK_SPEED_MODE |
9573 tw32(TG3_CPMU_CTRL, 9640 CPMU_CTRL_LINK_AWARE_MODE));
9574 cpmuctrl & ~(CPMU_CTRL_LINK_SPEED_MODE |
9575 CPMU_CTRL_LINK_AWARE_MODE));
9576 else
9577 tw32(TG3_CPMU_CTRL,
9578 cpmuctrl & ~CPMU_CTRL_LINK_AWARE_MODE);
9579 } 9641 }
9580 9642
9581 if (tg3_run_loopback(tp, TG3_MAC_LOOPBACK)) 9643 if (tg3_run_loopback(tp, TG3_MAC_LOOPBACK))
@@ -9892,7 +9954,7 @@ static void __devinit tg3_get_nvram_size(struct tg3 *tp)
9892 return; 9954 return;
9893 } 9955 }
9894 } 9956 }
9895 tp->nvram_size = 0x80000; 9957 tp->nvram_size = TG3_NVRAM_SIZE_512KB;
9896} 9958}
9897 9959
9898static void __devinit tg3_get_nvram_info(struct tg3 *tp) 9960static void __devinit tg3_get_nvram_info(struct tg3 *tp)
@@ -10033,11 +10095,14 @@ static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp)
10033 tp->nvram_pagesize = 264; 10095 tp->nvram_pagesize = 264;
10034 if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1 || 10096 if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1 ||
10035 nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_5) 10097 nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_5)
10036 tp->nvram_size = (protect ? 0x3e200 : 0x80000); 10098 tp->nvram_size = (protect ? 0x3e200 :
10099 TG3_NVRAM_SIZE_512KB);
10037 else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2) 10100 else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2)
10038 tp->nvram_size = (protect ? 0x1f200 : 0x40000); 10101 tp->nvram_size = (protect ? 0x1f200 :
10102 TG3_NVRAM_SIZE_256KB);
10039 else 10103 else
10040 tp->nvram_size = (protect ? 0x1f200 : 0x20000); 10104 tp->nvram_size = (protect ? 0x1f200 :
10105 TG3_NVRAM_SIZE_128KB);
10041 break; 10106 break;
10042 case FLASH_5752VENDOR_ST_M45PE10: 10107 case FLASH_5752VENDOR_ST_M45PE10:
10043 case FLASH_5752VENDOR_ST_M45PE20: 10108 case FLASH_5752VENDOR_ST_M45PE20:
@@ -10047,11 +10112,17 @@ static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp)
10047 tp->tg3_flags2 |= TG3_FLG2_FLASH; 10112 tp->tg3_flags2 |= TG3_FLG2_FLASH;
10048 tp->nvram_pagesize = 256; 10113 tp->nvram_pagesize = 256;
10049 if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE10) 10114 if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE10)
10050 tp->nvram_size = (protect ? 0x10000 : 0x20000); 10115 tp->nvram_size = (protect ?
10116 TG3_NVRAM_SIZE_64KB :
10117 TG3_NVRAM_SIZE_128KB);
10051 else if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE20) 10118 else if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE20)
10052 tp->nvram_size = (protect ? 0x10000 : 0x40000); 10119 tp->nvram_size = (protect ?
10120 TG3_NVRAM_SIZE_64KB :
10121 TG3_NVRAM_SIZE_256KB);
10053 else 10122 else
10054 tp->nvram_size = (protect ? 0x20000 : 0x80000); 10123 tp->nvram_size = (protect ?
10124 TG3_NVRAM_SIZE_128KB :
10125 TG3_NVRAM_SIZE_512KB);
10055 break; 10126 break;
10056 } 10127 }
10057} 10128}
@@ -10145,25 +10216,25 @@ static void __devinit tg3_get_5761_nvram_info(struct tg3 *tp)
10145 case FLASH_5761VENDOR_ATMEL_MDB161D: 10216 case FLASH_5761VENDOR_ATMEL_MDB161D:
10146 case FLASH_5761VENDOR_ST_A_M45PE16: 10217 case FLASH_5761VENDOR_ST_A_M45PE16:
10147 case FLASH_5761VENDOR_ST_M_M45PE16: 10218 case FLASH_5761VENDOR_ST_M_M45PE16:
10148 tp->nvram_size = 0x100000; 10219 tp->nvram_size = TG3_NVRAM_SIZE_2MB;
10149 break; 10220 break;
10150 case FLASH_5761VENDOR_ATMEL_ADB081D: 10221 case FLASH_5761VENDOR_ATMEL_ADB081D:
10151 case FLASH_5761VENDOR_ATMEL_MDB081D: 10222 case FLASH_5761VENDOR_ATMEL_MDB081D:
10152 case FLASH_5761VENDOR_ST_A_M45PE80: 10223 case FLASH_5761VENDOR_ST_A_M45PE80:
10153 case FLASH_5761VENDOR_ST_M_M45PE80: 10224 case FLASH_5761VENDOR_ST_M_M45PE80:
10154 tp->nvram_size = 0x80000; 10225 tp->nvram_size = TG3_NVRAM_SIZE_1MB;
10155 break; 10226 break;
10156 case FLASH_5761VENDOR_ATMEL_ADB041D: 10227 case FLASH_5761VENDOR_ATMEL_ADB041D:
10157 case FLASH_5761VENDOR_ATMEL_MDB041D: 10228 case FLASH_5761VENDOR_ATMEL_MDB041D:
10158 case FLASH_5761VENDOR_ST_A_M45PE40: 10229 case FLASH_5761VENDOR_ST_A_M45PE40:
10159 case FLASH_5761VENDOR_ST_M_M45PE40: 10230 case FLASH_5761VENDOR_ST_M_M45PE40:
10160 tp->nvram_size = 0x40000; 10231 tp->nvram_size = TG3_NVRAM_SIZE_512KB;
10161 break; 10232 break;
10162 case FLASH_5761VENDOR_ATMEL_ADB021D: 10233 case FLASH_5761VENDOR_ATMEL_ADB021D:
10163 case FLASH_5761VENDOR_ATMEL_MDB021D: 10234 case FLASH_5761VENDOR_ATMEL_MDB021D:
10164 case FLASH_5761VENDOR_ST_A_M45PE20: 10235 case FLASH_5761VENDOR_ST_A_M45PE20:
10165 case FLASH_5761VENDOR_ST_M_M45PE20: 10236 case FLASH_5761VENDOR_ST_M_M45PE20:
10166 tp->nvram_size = 0x20000; 10237 tp->nvram_size = TG3_NVRAM_SIZE_256KB;
10167 break; 10238 break;
10168 } 10239 }
10169 } 10240 }
@@ -11764,6 +11835,12 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
11764 tp->phy_otp = TG3_OTP_DEFAULT; 11835 tp->phy_otp = TG3_OTP_DEFAULT;
11765 } 11836 }
11766 11837
11838 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 ||
11839 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761)
11840 tp->mi_mode = MAC_MI_MODE_500KHZ_CONST;
11841 else
11842 tp->mi_mode = MAC_MI_MODE_BASE;
11843
11767 tp->coalesce_mode = 0; 11844 tp->coalesce_mode = 0;
11768 if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX && 11845 if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX &&
11769 GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX) 11846 GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX)
@@ -12692,7 +12769,7 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
12692 tp->mac_mode = TG3_DEF_MAC_MODE; 12769 tp->mac_mode = TG3_DEF_MAC_MODE;
12693 tp->rx_mode = TG3_DEF_RX_MODE; 12770 tp->rx_mode = TG3_DEF_RX_MODE;
12694 tp->tx_mode = TG3_DEF_TX_MODE; 12771 tp->tx_mode = TG3_DEF_TX_MODE;
12695 tp->mi_mode = MAC_MI_MODE_BASE; 12772
12696 if (tg3_debug > 0) 12773 if (tg3_debug > 0)
12697 tp->msg_enable = tg3_debug; 12774 tp->msg_enable = tg3_debug;
12698 else 12775 else
diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
index c688c3ac5035..0404f93baa29 100644
--- a/drivers/net/tg3.h
+++ b/drivers/net/tg3.h
@@ -415,7 +415,7 @@
415#define MAC_MI_MODE_CLK_10MHZ 0x00000001 415#define MAC_MI_MODE_CLK_10MHZ 0x00000001
416#define MAC_MI_MODE_SHORT_PREAMBLE 0x00000002 416#define MAC_MI_MODE_SHORT_PREAMBLE 0x00000002
417#define MAC_MI_MODE_AUTO_POLL 0x00000010 417#define MAC_MI_MODE_AUTO_POLL 0x00000010
418#define MAC_MI_MODE_CORE_CLK_62MHZ 0x00008000 418#define MAC_MI_MODE_500KHZ_CONST 0x00008000
419#define MAC_MI_MODE_BASE 0x000c0000 /* XXX magic values XXX */ 419#define MAC_MI_MODE_BASE 0x000c0000 /* XXX magic values XXX */
420#define MAC_AUTO_POLL_STATUS 0x00000458 420#define MAC_AUTO_POLL_STATUS 0x00000458
421#define MAC_AUTO_POLL_ERROR 0x00000001 421#define MAC_AUTO_POLL_ERROR 0x00000001
@@ -1429,6 +1429,7 @@
1429#define GRC_LCLCTRL_AUTO_SEEPROM 0x01000000 1429#define GRC_LCLCTRL_AUTO_SEEPROM 0x01000000
1430#define GRC_TIMER 0x0000680c 1430#define GRC_TIMER 0x0000680c
1431#define GRC_RX_CPU_EVENT 0x00006810 1431#define GRC_RX_CPU_EVENT 0x00006810
1432#define GRC_RX_CPU_DRIVER_EVENT 0x00004000
1432#define GRC_RX_TIMER_REF 0x00006814 1433#define GRC_RX_TIMER_REF 0x00006814
1433#define GRC_RX_CPU_SEM 0x00006818 1434#define GRC_RX_CPU_SEM 0x00006818
1434#define GRC_REMOTE_RX_CPU_ATTN 0x0000681c 1435#define GRC_REMOTE_RX_CPU_ATTN 0x0000681c
@@ -1676,6 +1677,7 @@
1676#define FWCMD_NICDRV_IPV6ADDR_CHG 0x00000004 1677#define FWCMD_NICDRV_IPV6ADDR_CHG 0x00000004
1677#define FWCMD_NICDRV_FIX_DMAR 0x00000005 1678#define FWCMD_NICDRV_FIX_DMAR 0x00000005
1678#define FWCMD_NICDRV_FIX_DMAW 0x00000006 1679#define FWCMD_NICDRV_FIX_DMAW 0x00000006
1680#define FWCMD_NICDRV_LINK_UPDATE 0x0000000c
1679#define FWCMD_NICDRV_ALIVE2 0x0000000d 1681#define FWCMD_NICDRV_ALIVE2 0x0000000d
1680#define FWCMD_NICDRV_ALIVE3 0x0000000e 1682#define FWCMD_NICDRV_ALIVE3 0x0000000e
1681#define NIC_SRAM_FW_CMD_LEN_MBOX 0x00000b7c 1683#define NIC_SRAM_FW_CMD_LEN_MBOX 0x00000b7c
@@ -2576,6 +2578,13 @@ struct tg3 {
2576 2578
2577 int nvram_lock_cnt; 2579 int nvram_lock_cnt;
2578 u32 nvram_size; 2580 u32 nvram_size;
2581#define TG3_NVRAM_SIZE_64KB 0x00010000
2582#define TG3_NVRAM_SIZE_128KB 0x00020000
2583#define TG3_NVRAM_SIZE_256KB 0x00040000
2584#define TG3_NVRAM_SIZE_512KB 0x00080000
2585#define TG3_NVRAM_SIZE_1MB 0x00100000
2586#define TG3_NVRAM_SIZE_2MB 0x00200000
2587
2579 u32 nvram_pagesize; 2588 u32 nvram_pagesize;
2580 u32 nvram_jedecnum; 2589 u32 nvram_jedecnum;
2581 2590
@@ -2584,10 +2593,10 @@ struct tg3 {
2584#define JEDEC_SAIFUN 0x4f 2593#define JEDEC_SAIFUN 0x4f
2585#define JEDEC_SST 0xbf 2594#define JEDEC_SST 0xbf
2586 2595
2587#define ATMEL_AT24C64_CHIP_SIZE (64 * 1024) 2596#define ATMEL_AT24C64_CHIP_SIZE TG3_NVRAM_SIZE_64KB
2588#define ATMEL_AT24C64_PAGE_SIZE (32) 2597#define ATMEL_AT24C64_PAGE_SIZE (32)
2589 2598
2590#define ATMEL_AT24C512_CHIP_SIZE (512 * 1024) 2599#define ATMEL_AT24C512_CHIP_SIZE TG3_NVRAM_SIZE_512KB
2591#define ATMEL_AT24C512_PAGE_SIZE (128) 2600#define ATMEL_AT24C512_PAGE_SIZE (128)
2592 2601
2593#define ATMEL_AT45DB0X1B_PAGE_POS 9 2602#define ATMEL_AT45DB0X1B_PAGE_POS 9
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 555b70c8b863..f926b5ab3d09 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -41,6 +41,9 @@ struct virtnet_info
41 struct net_device *dev; 41 struct net_device *dev;
42 struct napi_struct napi; 42 struct napi_struct napi;
43 43
44 /* The skb we couldn't send because buffers were full. */
45 struct sk_buff *last_xmit_skb;
46
44 /* Number of input buffers, and max we've ever had. */ 47 /* Number of input buffers, and max we've ever had. */
45 unsigned int num, max; 48 unsigned int num, max;
46 49
@@ -142,10 +145,10 @@ drop:
142static void try_fill_recv(struct virtnet_info *vi) 145static void try_fill_recv(struct virtnet_info *vi)
143{ 146{
144 struct sk_buff *skb; 147 struct sk_buff *skb;
145 struct scatterlist sg[1+MAX_SKB_FRAGS]; 148 struct scatterlist sg[2+MAX_SKB_FRAGS];
146 int num, err; 149 int num, err;
147 150
148 sg_init_table(sg, 1+MAX_SKB_FRAGS); 151 sg_init_table(sg, 2+MAX_SKB_FRAGS);
149 for (;;) { 152 for (;;) {
150 skb = netdev_alloc_skb(vi->dev, MAX_PACKET_LEN); 153 skb = netdev_alloc_skb(vi->dev, MAX_PACKET_LEN);
151 if (unlikely(!skb)) 154 if (unlikely(!skb))
@@ -221,23 +224,22 @@ static void free_old_xmit_skbs(struct virtnet_info *vi)
221 while ((skb = vi->svq->vq_ops->get_buf(vi->svq, &len)) != NULL) { 224 while ((skb = vi->svq->vq_ops->get_buf(vi->svq, &len)) != NULL) {
222 pr_debug("Sent skb %p\n", skb); 225 pr_debug("Sent skb %p\n", skb);
223 __skb_unlink(skb, &vi->send); 226 __skb_unlink(skb, &vi->send);
224 vi->dev->stats.tx_bytes += len; 227 vi->dev->stats.tx_bytes += skb->len;
225 vi->dev->stats.tx_packets++; 228 vi->dev->stats.tx_packets++;
226 kfree_skb(skb); 229 kfree_skb(skb);
227 } 230 }
228} 231}
229 232
230static int start_xmit(struct sk_buff *skb, struct net_device *dev) 233static int xmit_skb(struct virtnet_info *vi, struct sk_buff *skb)
231{ 234{
232 struct virtnet_info *vi = netdev_priv(dev); 235 int num;
233 int num, err; 236 struct scatterlist sg[2+MAX_SKB_FRAGS];
234 struct scatterlist sg[1+MAX_SKB_FRAGS];
235 struct virtio_net_hdr *hdr; 237 struct virtio_net_hdr *hdr;
236 const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest; 238 const unsigned char *dest = ((struct ethhdr *)skb->data)->h_dest;
237 239
238 sg_init_table(sg, 1+MAX_SKB_FRAGS); 240 sg_init_table(sg, 2+MAX_SKB_FRAGS);
239 241
240 pr_debug("%s: xmit %p " MAC_FMT "\n", dev->name, skb, 242 pr_debug("%s: xmit %p " MAC_FMT "\n", vi->dev->name, skb,
241 dest[0], dest[1], dest[2], 243 dest[0], dest[1], dest[2],
242 dest[3], dest[4], dest[5]); 244 dest[3], dest[4], dest[5]);
243 245
@@ -272,30 +274,51 @@ static int start_xmit(struct sk_buff *skb, struct net_device *dev)
272 274
273 vnet_hdr_to_sg(sg, skb); 275 vnet_hdr_to_sg(sg, skb);
274 num = skb_to_sgvec(skb, sg+1, 0, skb->len) + 1; 276 num = skb_to_sgvec(skb, sg+1, 0, skb->len) + 1;
275 __skb_queue_head(&vi->send, skb); 277
278 return vi->svq->vq_ops->add_buf(vi->svq, sg, num, 0, skb);
279}
280
281static int start_xmit(struct sk_buff *skb, struct net_device *dev)
282{
283 struct virtnet_info *vi = netdev_priv(dev);
276 284
277again: 285again:
278 /* Free up any pending old buffers before queueing new ones. */ 286 /* Free up any pending old buffers before queueing new ones. */
279 free_old_xmit_skbs(vi); 287 free_old_xmit_skbs(vi);
280 err = vi->svq->vq_ops->add_buf(vi->svq, sg, num, 0, skb); 288
281 if (err) { 289 /* If we has a buffer left over from last time, send it now. */
282 pr_debug("%s: virtio not prepared to send\n", dev->name); 290 if (vi->last_xmit_skb) {
283 netif_stop_queue(dev); 291 if (xmit_skb(vi, vi->last_xmit_skb) != 0) {
284 292 /* Drop this skb: we only queue one. */
285 /* Activate callback for using skbs: if this returns false it 293 vi->dev->stats.tx_dropped++;
286 * means some were used in the meantime. */ 294 kfree_skb(skb);
287 if (unlikely(!vi->svq->vq_ops->enable_cb(vi->svq))) { 295 goto stop_queue;
288 vi->svq->vq_ops->disable_cb(vi->svq);
289 netif_start_queue(dev);
290 goto again;
291 } 296 }
292 __skb_unlink(skb, &vi->send); 297 vi->last_xmit_skb = NULL;
298 }
293 299
294 return NETDEV_TX_BUSY; 300 /* Put new one in send queue and do transmit */
301 __skb_queue_head(&vi->send, skb);
302 if (xmit_skb(vi, skb) != 0) {
303 vi->last_xmit_skb = skb;
304 goto stop_queue;
295 } 305 }
306done:
296 vi->svq->vq_ops->kick(vi->svq); 307 vi->svq->vq_ops->kick(vi->svq);
297 308 return NETDEV_TX_OK;
298 return 0; 309
310stop_queue:
311 pr_debug("%s: virtio not prepared to send\n", dev->name);
312 netif_stop_queue(dev);
313
314 /* Activate callback for using skbs: if this returns false it
315 * means some were used in the meantime. */
316 if (unlikely(!vi->svq->vq_ops->enable_cb(vi->svq))) {
317 vi->svq->vq_ops->disable_cb(vi->svq);
318 netif_start_queue(dev);
319 goto again;
320 }
321 goto done;
299} 322}
300 323
301#ifdef CONFIG_NET_POLL_CONTROLLER 324#ifdef CONFIG_NET_POLL_CONTROLLER
@@ -355,17 +378,26 @@ static int virtnet_probe(struct virtio_device *vdev)
355 SET_NETDEV_DEV(dev, &vdev->dev); 378 SET_NETDEV_DEV(dev, &vdev->dev);
356 379
357 /* Do we support "hardware" checksums? */ 380 /* Do we support "hardware" checksums? */
358 if (csum && vdev->config->feature(vdev, VIRTIO_NET_F_CSUM)) { 381 if (csum && virtio_has_feature(vdev, VIRTIO_NET_F_CSUM)) {
359 /* This opens up the world of extra features. */ 382 /* This opens up the world of extra features. */
360 dev->features |= NETIF_F_HW_CSUM|NETIF_F_SG|NETIF_F_FRAGLIST; 383 dev->features |= NETIF_F_HW_CSUM|NETIF_F_SG|NETIF_F_FRAGLIST;
361 if (gso && vdev->config->feature(vdev, VIRTIO_NET_F_GSO)) { 384 if (gso && virtio_has_feature(vdev, VIRTIO_NET_F_GSO)) {
362 dev->features |= NETIF_F_TSO | NETIF_F_UFO 385 dev->features |= NETIF_F_TSO | NETIF_F_UFO
363 | NETIF_F_TSO_ECN | NETIF_F_TSO6; 386 | NETIF_F_TSO_ECN | NETIF_F_TSO6;
364 } 387 }
388 /* Individual feature bits: what can host handle? */
389 if (gso && virtio_has_feature(vdev, VIRTIO_NET_F_HOST_TSO4))
390 dev->features |= NETIF_F_TSO;
391 if (gso && virtio_has_feature(vdev, VIRTIO_NET_F_HOST_TSO6))
392 dev->features |= NETIF_F_TSO6;
393 if (gso && virtio_has_feature(vdev, VIRTIO_NET_F_HOST_ECN))
394 dev->features |= NETIF_F_TSO_ECN;
395 if (gso && virtio_has_feature(vdev, VIRTIO_NET_F_HOST_UFO))
396 dev->features |= NETIF_F_UFO;
365 } 397 }
366 398
367 /* Configuration may specify what MAC to use. Otherwise random. */ 399 /* Configuration may specify what MAC to use. Otherwise random. */
368 if (vdev->config->feature(vdev, VIRTIO_NET_F_MAC)) { 400 if (virtio_has_feature(vdev, VIRTIO_NET_F_MAC)) {
369 vdev->config->get(vdev, 401 vdev->config->get(vdev,
370 offsetof(struct virtio_net_config, mac), 402 offsetof(struct virtio_net_config, mac),
371 dev->dev_addr, dev->addr_len); 403 dev->dev_addr, dev->addr_len);
@@ -454,7 +486,15 @@ static struct virtio_device_id id_table[] = {
454 { 0 }, 486 { 0 },
455}; 487};
456 488
489static unsigned int features[] = {
490 VIRTIO_NET_F_CSUM, VIRTIO_NET_F_GSO, VIRTIO_NET_F_MAC,
491 VIRTIO_NET_F_HOST_TSO4, VIRTIO_NET_F_HOST_UFO, VIRTIO_NET_F_HOST_TSO6,
492 VIRTIO_NET_F_HOST_ECN,
493};
494
457static struct virtio_driver virtio_net = { 495static struct virtio_driver virtio_net = {
496 .feature_table = features,
497 .feature_table_size = ARRAY_SIZE(features),
458 .driver.name = KBUILD_MODNAME, 498 .driver.name = KBUILD_MODNAME,
459 .driver.owner = THIS_MODULE, 499 .driver.owner = THIS_MODULE,
460 .id_table = id_table, 500 .id_table = id_table,
diff --git a/drivers/net/wan/pc300_tty.c b/drivers/net/wan/pc300_tty.c
index 63abfd72542d..e03eef2f2282 100644
--- a/drivers/net/wan/pc300_tty.c
+++ b/drivers/net/wan/pc300_tty.c
@@ -178,6 +178,20 @@ static void cpc_tty_signal_on(pc300dev_t *pc300dev, unsigned char signal)
178 CPC_TTY_UNLOCK(card,flags); 178 CPC_TTY_UNLOCK(card,flags);
179} 179}
180 180
181
182static const struct tty_operations pc300_ops = {
183 .open = cpc_tty_open,
184 .close = cpc_tty_close,
185 .write = cpc_tty_write,
186 .write_room = cpc_tty_write_room,
187 .chars_in_buffer = cpc_tty_chars_in_buffer,
188 .tiocmset = pc300_tiocmset,
189 .tiocmget = pc300_tiocmget,
190 .flush_buffer = cpc_tty_flush_buffer,
191 .hangup = cpc_tty_hangup,
192};
193
194
181/* 195/*
182 * PC300 TTY initialization routine 196 * PC300 TTY initialization routine
183 * 197 *
@@ -225,15 +239,7 @@ void cpc_tty_init(pc300dev_t *pc300dev)
225 serial_drv.flags = TTY_DRIVER_REAL_RAW; 239 serial_drv.flags = TTY_DRIVER_REAL_RAW;
226 240
227 /* interface routines from the upper tty layer to the tty driver */ 241 /* interface routines from the upper tty layer to the tty driver */
228 serial_drv.open = cpc_tty_open; 242 tty_set_operations(&serial_drv, &pc300_ops);
229 serial_drv.close = cpc_tty_close;
230 serial_drv.write = cpc_tty_write;
231 serial_drv.write_room = cpc_tty_write_room;
232 serial_drv.chars_in_buffer = cpc_tty_chars_in_buffer;
233 serial_drv.tiocmset = pc300_tiocmset;
234 serial_drv.tiocmget = pc300_tiocmget;
235 serial_drv.flush_buffer = cpc_tty_flush_buffer;
236 serial_drv.hangup = cpc_tty_hangup;
237 243
238 /* register the TTY driver */ 244 /* register the TTY driver */
239 if (tty_register_driver(&serial_drv)) { 245 if (tty_register_driver(&serial_drv)) {
diff --git a/drivers/net/wan/x25_asy.c b/drivers/net/wan/x25_asy.c
index 0f8aca8a4d43..249e18053d5f 100644
--- a/drivers/net/wan/x25_asy.c
+++ b/drivers/net/wan/x25_asy.c
@@ -17,7 +17,7 @@
17#include <linux/module.h> 17#include <linux/module.h>
18 18
19#include <asm/system.h> 19#include <asm/system.h>
20#include <asm/uaccess.h> 20#include <linux/uaccess.h>
21#include <linux/bitops.h> 21#include <linux/bitops.h>
22#include <linux/string.h> 22#include <linux/string.h>
23#include <linux/mm.h> 23#include <linux/mm.h>
@@ -95,7 +95,7 @@ static struct x25_asy *x25_asy_alloc(void)
95 x25_asy_devs[i] = dev; 95 x25_asy_devs[i] = dev;
96 return sl; 96 return sl;
97 } else { 97 } else {
98 printk("x25_asy_alloc() - register_netdev() failure.\n"); 98 printk(KERN_WARNING "x25_asy_alloc() - register_netdev() failure.\n");
99 free_netdev(dev); 99 free_netdev(dev);
100 } 100 }
101 } 101 }
@@ -112,23 +112,22 @@ static void x25_asy_free(struct x25_asy *sl)
112 kfree(sl->xbuff); 112 kfree(sl->xbuff);
113 sl->xbuff = NULL; 113 sl->xbuff = NULL;
114 114
115 if (!test_and_clear_bit(SLF_INUSE, &sl->flags)) { 115 if (!test_and_clear_bit(SLF_INUSE, &sl->flags))
116 printk("%s: x25_asy_free for already free unit.\n", sl->dev->name); 116 printk(KERN_ERR "%s: x25_asy_free for already free unit.\n",
117 } 117 sl->dev->name);
118} 118}
119 119
120static int x25_asy_change_mtu(struct net_device *dev, int newmtu) 120static int x25_asy_change_mtu(struct net_device *dev, int newmtu)
121{ 121{
122 struct x25_asy *sl = dev->priv; 122 struct x25_asy *sl = dev->priv;
123 unsigned char *xbuff, *rbuff; 123 unsigned char *xbuff, *rbuff;
124 int len = 2* newmtu; 124 int len = 2 * newmtu;
125 125
126 xbuff = kmalloc(len + 4, GFP_ATOMIC); 126 xbuff = kmalloc(len + 4, GFP_ATOMIC);
127 rbuff = kmalloc(len + 4, GFP_ATOMIC); 127 rbuff = kmalloc(len + 4, GFP_ATOMIC);
128 128
129 if (xbuff == NULL || rbuff == NULL) 129 if (xbuff == NULL || rbuff == NULL) {
130 { 130 printk(KERN_WARNING "%s: unable to grow X.25 buffers, MTU change cancelled.\n",
131 printk("%s: unable to grow X.25 buffers, MTU change cancelled.\n",
132 dev->name); 131 dev->name);
133 kfree(xbuff); 132 kfree(xbuff);
134 kfree(rbuff); 133 kfree(rbuff);
@@ -193,25 +192,23 @@ static void x25_asy_bump(struct x25_asy *sl)
193 int err; 192 int err;
194 193
195 count = sl->rcount; 194 count = sl->rcount;
196 sl->stats.rx_bytes+=count; 195 sl->stats.rx_bytes += count;
197 196
198 skb = dev_alloc_skb(count+1); 197 skb = dev_alloc_skb(count+1);
199 if (skb == NULL) 198 if (skb == NULL) {
200 { 199 printk(KERN_WARNING "%s: memory squeeze, dropping packet.\n",
201 printk("%s: memory squeeze, dropping packet.\n", sl->dev->name); 200 sl->dev->name);
202 sl->stats.rx_dropped++; 201 sl->stats.rx_dropped++;
203 return; 202 return;
204 } 203 }
205 skb_push(skb,1); /* LAPB internal control */ 204 skb_push(skb, 1); /* LAPB internal control */
206 memcpy(skb_put(skb,count), sl->rbuff, count); 205 memcpy(skb_put(skb, count), sl->rbuff, count);
207 skb->protocol = x25_type_trans(skb, sl->dev); 206 skb->protocol = x25_type_trans(skb, sl->dev);
208 if((err=lapb_data_received(skb->dev, skb))!=LAPB_OK) 207 err = lapb_data_received(skb->dev, skb);
209 { 208 if (err != LAPB_OK) {
210 kfree_skb(skb); 209 kfree_skb(skb);
211 printk(KERN_DEBUG "x25_asy: data received err - %d\n",err); 210 printk(KERN_DEBUG "x25_asy: data received err - %d\n", err);
212 } 211 } else {
213 else
214 {
215 netif_rx(skb); 212 netif_rx(skb);
216 sl->dev->last_rx = jiffies; 213 sl->dev->last_rx = jiffies;
217 sl->stats.rx_packets++; 214 sl->stats.rx_packets++;
@@ -224,10 +221,11 @@ static void x25_asy_encaps(struct x25_asy *sl, unsigned char *icp, int len)
224 unsigned char *p; 221 unsigned char *p;
225 int actual, count, mtu = sl->dev->mtu; 222 int actual, count, mtu = sl->dev->mtu;
226 223
227 if (len > mtu) 224 if (len > mtu) {
228 { /* Sigh, shouldn't occur BUT ... */ 225 /* Sigh, shouldn't occur BUT ... */
229 len = mtu; 226 len = mtu;
230 printk ("%s: truncating oversized transmit packet!\n", sl->dev->name); 227 printk(KERN_DEBUG "%s: truncating oversized transmit packet!\n",
228 sl->dev->name);
231 sl->stats.tx_dropped++; 229 sl->stats.tx_dropped++;
232 x25_asy_unlock(sl); 230 x25_asy_unlock(sl);
233 return; 231 return;
@@ -245,7 +243,7 @@ static void x25_asy_encaps(struct x25_asy *sl, unsigned char *icp, int len)
245 * 14 Oct 1994 Dmitry Gorodchanin. 243 * 14 Oct 1994 Dmitry Gorodchanin.
246 */ 244 */
247 sl->tty->flags |= (1 << TTY_DO_WRITE_WAKEUP); 245 sl->tty->flags |= (1 << TTY_DO_WRITE_WAKEUP);
248 actual = sl->tty->driver->write(sl->tty, sl->xbuff, count); 246 actual = sl->tty->ops->write(sl->tty, sl->xbuff, count);
249 sl->xleft = count - actual; 247 sl->xleft = count - actual;
250 sl->xhead = sl->xbuff + actual; 248 sl->xhead = sl->xbuff + actual;
251 /* VSV */ 249 /* VSV */
@@ -265,8 +263,7 @@ static void x25_asy_write_wakeup(struct tty_struct *tty)
265 if (!sl || sl->magic != X25_ASY_MAGIC || !netif_running(sl->dev)) 263 if (!sl || sl->magic != X25_ASY_MAGIC || !netif_running(sl->dev))
266 return; 264 return;
267 265
268 if (sl->xleft <= 0) 266 if (sl->xleft <= 0) {
269 {
270 /* Now serial buffer is almost free & we can start 267 /* Now serial buffer is almost free & we can start
271 * transmission of another packet */ 268 * transmission of another packet */
272 sl->stats.tx_packets++; 269 sl->stats.tx_packets++;
@@ -275,14 +272,14 @@ static void x25_asy_write_wakeup(struct tty_struct *tty)
275 return; 272 return;
276 } 273 }
277 274
278 actual = tty->driver->write(tty, sl->xhead, sl->xleft); 275 actual = tty->ops->write(tty, sl->xhead, sl->xleft);
279 sl->xleft -= actual; 276 sl->xleft -= actual;
280 sl->xhead += actual; 277 sl->xhead += actual;
281} 278}
282 279
283static void x25_asy_timeout(struct net_device *dev) 280static void x25_asy_timeout(struct net_device *dev)
284{ 281{
285 struct x25_asy *sl = (struct x25_asy*)(dev->priv); 282 struct x25_asy *sl = dev->priv;
286 283
287 spin_lock(&sl->lock); 284 spin_lock(&sl->lock);
288 if (netif_queue_stopped(dev)) { 285 if (netif_queue_stopped(dev)) {
@@ -290,7 +287,7 @@ static void x25_asy_timeout(struct net_device *dev)
290 * 14 Oct 1994 Dmitry Gorodchanin. 287 * 14 Oct 1994 Dmitry Gorodchanin.
291 */ 288 */
292 printk(KERN_WARNING "%s: transmit timed out, %s?\n", dev->name, 289 printk(KERN_WARNING "%s: transmit timed out, %s?\n", dev->name,
293 (sl->tty->driver->chars_in_buffer(sl->tty) || sl->xleft) ? 290 (tty_chars_in_buffer(sl->tty) || sl->xleft) ?
294 "bad line quality" : "driver error"); 291 "bad line quality" : "driver error");
295 sl->xleft = 0; 292 sl->xleft = 0;
296 sl->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP); 293 sl->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
@@ -303,31 +300,34 @@ static void x25_asy_timeout(struct net_device *dev)
303 300
304static int x25_asy_xmit(struct sk_buff *skb, struct net_device *dev) 301static int x25_asy_xmit(struct sk_buff *skb, struct net_device *dev)
305{ 302{
306 struct x25_asy *sl = (struct x25_asy*)(dev->priv); 303 struct x25_asy *sl = dev->priv;
307 int err; 304 int err;
308 305
309 if (!netif_running(sl->dev)) { 306 if (!netif_running(sl->dev)) {
310 printk("%s: xmit call when iface is down\n", dev->name); 307 printk(KERN_ERR "%s: xmit call when iface is down\n",
308 dev->name);
311 kfree_skb(skb); 309 kfree_skb(skb);
312 return 0; 310 return 0;
313 } 311 }
314 312
315 switch(skb->data[0]) 313 switch (skb->data[0]) {
316 { 314 case 0x00:
317 case 0x00:break; 315 break;
318 case 0x01: /* Connection request .. do nothing */ 316 case 0x01: /* Connection request .. do nothing */
319 if((err=lapb_connect_request(dev))!=LAPB_OK) 317 err = lapb_connect_request(dev);
320 printk(KERN_ERR "x25_asy: lapb_connect_request error - %d\n", err); 318 if (err != LAPB_OK)
321 kfree_skb(skb); 319 printk(KERN_ERR "x25_asy: lapb_connect_request error - %d\n", err);
322 return 0; 320 kfree_skb(skb);
323 case 0x02: /* Disconnect request .. do nothing - hang up ?? */ 321 return 0;
324 if((err=lapb_disconnect_request(dev))!=LAPB_OK) 322 case 0x02: /* Disconnect request .. do nothing - hang up ?? */
325 printk(KERN_ERR "x25_asy: lapb_disconnect_request error - %d\n", err); 323 err = lapb_disconnect_request(dev);
326 default: 324 if (err != LAPB_OK)
327 kfree_skb(skb); 325 printk(KERN_ERR "x25_asy: lapb_disconnect_request error - %d\n", err);
328 return 0; 326 default:
327 kfree_skb(skb);
328 return 0;
329 } 329 }
330 skb_pull(skb,1); /* Remove control byte */ 330 skb_pull(skb, 1); /* Remove control byte */
331 /* 331 /*
332 * If we are busy already- too bad. We ought to be able 332 * If we are busy already- too bad. We ought to be able
333 * to queue things at this point, to allow for a little 333 * to queue things at this point, to allow for a little
@@ -338,10 +338,10 @@ static int x25_asy_xmit(struct sk_buff *skb, struct net_device *dev)
338 * So, no queues ! 338 * So, no queues !
339 * 14 Oct 1994 Dmitry Gorodchanin. 339 * 14 Oct 1994 Dmitry Gorodchanin.
340 */ 340 */
341 341
342 if((err=lapb_data_request(dev,skb))!=LAPB_OK) 342 err = lapb_data_request(dev, skb);
343 { 343 if (err != LAPB_OK) {
344 printk(KERN_ERR "lapbeth: lapb_data_request error - %d\n", err); 344 printk(KERN_ERR "x25_asy: lapb_data_request error - %d\n", err);
345 kfree_skb(skb); 345 kfree_skb(skb);
346 return 0; 346 return 0;
347 } 347 }
@@ -357,7 +357,7 @@ static int x25_asy_xmit(struct sk_buff *skb, struct net_device *dev)
357 * Called when I frame data arrives. We did the work above - throw it 357 * Called when I frame data arrives. We did the work above - throw it
358 * at the net layer. 358 * at the net layer.
359 */ 359 */
360 360
361static int x25_asy_data_indication(struct net_device *dev, struct sk_buff *skb) 361static int x25_asy_data_indication(struct net_device *dev, struct sk_buff *skb)
362{ 362{
363 skb->dev->last_rx = jiffies; 363 skb->dev->last_rx = jiffies;
@@ -369,24 +369,22 @@ static int x25_asy_data_indication(struct net_device *dev, struct sk_buff *skb)
369 * busy cases too well. Its tricky to see how to do this nicely - 369 * busy cases too well. Its tricky to see how to do this nicely -
370 * perhaps lapb should allow us to bounce this ? 370 * perhaps lapb should allow us to bounce this ?
371 */ 371 */
372 372
373static void x25_asy_data_transmit(struct net_device *dev, struct sk_buff *skb) 373static void x25_asy_data_transmit(struct net_device *dev, struct sk_buff *skb)
374{ 374{
375 struct x25_asy *sl=dev->priv; 375 struct x25_asy *sl = dev->priv;
376 376
377 spin_lock(&sl->lock); 377 spin_lock(&sl->lock);
378 if (netif_queue_stopped(sl->dev) || sl->tty == NULL) 378 if (netif_queue_stopped(sl->dev) || sl->tty == NULL) {
379 {
380 spin_unlock(&sl->lock); 379 spin_unlock(&sl->lock);
381 printk(KERN_ERR "x25_asy: tbusy drop\n"); 380 printk(KERN_ERR "x25_asy: tbusy drop\n");
382 kfree_skb(skb); 381 kfree_skb(skb);
383 return; 382 return;
384 } 383 }
385 /* We were not busy, so we are now... :-) */ 384 /* We were not busy, so we are now... :-) */
386 if (skb != NULL) 385 if (skb != NULL) {
387 {
388 x25_asy_lock(sl); 386 x25_asy_lock(sl);
389 sl->stats.tx_bytes+=skb->len; 387 sl->stats.tx_bytes += skb->len;
390 x25_asy_encaps(sl, skb->data, skb->len); 388 x25_asy_encaps(sl, skb->data, skb->len);
391 dev_kfree_skb(skb); 389 dev_kfree_skb(skb);
392 } 390 }
@@ -396,15 +394,16 @@ static void x25_asy_data_transmit(struct net_device *dev, struct sk_buff *skb)
396/* 394/*
397 * LAPB connection establish/down information. 395 * LAPB connection establish/down information.
398 */ 396 */
399 397
400static void x25_asy_connected(struct net_device *dev, int reason) 398static void x25_asy_connected(struct net_device *dev, int reason)
401{ 399{
402 struct x25_asy *sl = dev->priv; 400 struct x25_asy *sl = dev->priv;
403 struct sk_buff *skb; 401 struct sk_buff *skb;
404 unsigned char *ptr; 402 unsigned char *ptr;
405 403
406 if ((skb = dev_alloc_skb(1)) == NULL) { 404 skb = dev_alloc_skb(1);
407 printk(KERN_ERR "lapbeth: out of memory\n"); 405 if (skb == NULL) {
406 printk(KERN_ERR "x25_asy: out of memory\n");
408 return; 407 return;
409 } 408 }
410 409
@@ -422,7 +421,8 @@ static void x25_asy_disconnected(struct net_device *dev, int reason)
422 struct sk_buff *skb; 421 struct sk_buff *skb;
423 unsigned char *ptr; 422 unsigned char *ptr;
424 423
425 if ((skb = dev_alloc_skb(1)) == NULL) { 424 skb = dev_alloc_skb(1);
425 if (skb == NULL) {
426 printk(KERN_ERR "x25_asy: out of memory\n"); 426 printk(KERN_ERR "x25_asy: out of memory\n");
427 return; 427 return;
428 } 428 }
@@ -449,7 +449,7 @@ static struct lapb_register_struct x25_asy_callbacks = {
449/* Open the low-level part of the X.25 channel. Easy! */ 449/* Open the low-level part of the X.25 channel. Easy! */
450static int x25_asy_open(struct net_device *dev) 450static int x25_asy_open(struct net_device *dev)
451{ 451{
452 struct x25_asy *sl = (struct x25_asy*)(dev->priv); 452 struct x25_asy *sl = dev->priv;
453 unsigned long len; 453 unsigned long len;
454 int err; 454 int err;
455 455
@@ -466,13 +466,11 @@ static int x25_asy_open(struct net_device *dev)
466 len = dev->mtu * 2; 466 len = dev->mtu * 2;
467 467
468 sl->rbuff = kmalloc(len + 4, GFP_KERNEL); 468 sl->rbuff = kmalloc(len + 4, GFP_KERNEL);
469 if (sl->rbuff == NULL) { 469 if (sl->rbuff == NULL)
470 goto norbuff; 470 goto norbuff;
471 }
472 sl->xbuff = kmalloc(len + 4, GFP_KERNEL); 471 sl->xbuff = kmalloc(len + 4, GFP_KERNEL);
473 if (sl->xbuff == NULL) { 472 if (sl->xbuff == NULL)
474 goto noxbuff; 473 goto noxbuff;
475 }
476 474
477 sl->buffsize = len; 475 sl->buffsize = len;
478 sl->rcount = 0; 476 sl->rcount = 0;
@@ -480,11 +478,12 @@ static int x25_asy_open(struct net_device *dev)
480 sl->flags &= (1 << SLF_INUSE); /* Clear ESCAPE & ERROR flags */ 478 sl->flags &= (1 << SLF_INUSE); /* Clear ESCAPE & ERROR flags */
481 479
482 netif_start_queue(dev); 480 netif_start_queue(dev);
483 481
484 /* 482 /*
485 * Now attach LAPB 483 * Now attach LAPB
486 */ 484 */
487 if((err=lapb_register(dev, &x25_asy_callbacks))==LAPB_OK) 485 err = lapb_register(dev, &x25_asy_callbacks);
486 if (err == LAPB_OK)
488 return 0; 487 return 0;
489 488
490 /* Cleanup */ 489 /* Cleanup */
@@ -499,18 +498,20 @@ norbuff:
499/* Close the low-level part of the X.25 channel. Easy! */ 498/* Close the low-level part of the X.25 channel. Easy! */
500static int x25_asy_close(struct net_device *dev) 499static int x25_asy_close(struct net_device *dev)
501{ 500{
502 struct x25_asy *sl = (struct x25_asy*)(dev->priv); 501 struct x25_asy *sl = dev->priv;
503 int err; 502 int err;
504 503
505 spin_lock(&sl->lock); 504 spin_lock(&sl->lock);
506 if (sl->tty) 505 if (sl->tty)
507 sl->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP); 506 sl->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
508 507
509 netif_stop_queue(dev); 508 netif_stop_queue(dev);
510 sl->rcount = 0; 509 sl->rcount = 0;
511 sl->xleft = 0; 510 sl->xleft = 0;
512 if((err=lapb_unregister(dev))!=LAPB_OK) 511 err = lapb_unregister(dev);
513 printk(KERN_ERR "x25_asy_close: lapb_unregister error -%d\n",err); 512 if (err != LAPB_OK)
513 printk(KERN_ERR "x25_asy_close: lapb_unregister error -%d\n",
514 err);
514 spin_unlock(&sl->lock); 515 spin_unlock(&sl->lock);
515 return 0; 516 return 0;
516} 517}
@@ -521,8 +522,9 @@ static int x25_asy_close(struct net_device *dev)
521 * a block of X.25 data has been received, which can now be decapsulated 522 * a block of X.25 data has been received, which can now be decapsulated
522 * and sent on to some IP layer for further processing. 523 * and sent on to some IP layer for further processing.
523 */ 524 */
524 525
525static void x25_asy_receive_buf(struct tty_struct *tty, const unsigned char *cp, char *fp, int count) 526static void x25_asy_receive_buf(struct tty_struct *tty,
527 const unsigned char *cp, char *fp, int count)
526{ 528{
527 struct x25_asy *sl = (struct x25_asy *) tty->disc_data; 529 struct x25_asy *sl = (struct x25_asy *) tty->disc_data;
528 530
@@ -533,9 +535,8 @@ static void x25_asy_receive_buf(struct tty_struct *tty, const unsigned char *cp,
533 /* Read the characters out of the buffer */ 535 /* Read the characters out of the buffer */
534 while (count--) { 536 while (count--) {
535 if (fp && *fp++) { 537 if (fp && *fp++) {
536 if (!test_and_set_bit(SLF_ERROR, &sl->flags)) { 538 if (!test_and_set_bit(SLF_ERROR, &sl->flags))
537 sl->stats.rx_errors++; 539 sl->stats.rx_errors++;
538 }
539 cp++; 540 cp++;
540 continue; 541 continue;
541 } 542 }
@@ -556,31 +557,31 @@ static int x25_asy_open_tty(struct tty_struct *tty)
556 struct x25_asy *sl = (struct x25_asy *) tty->disc_data; 557 struct x25_asy *sl = (struct x25_asy *) tty->disc_data;
557 int err; 558 int err;
558 559
560 if (tty->ops->write == NULL)
561 return -EOPNOTSUPP;
562
559 /* First make sure we're not already connected. */ 563 /* First make sure we're not already connected. */
560 if (sl && sl->magic == X25_ASY_MAGIC) { 564 if (sl && sl->magic == X25_ASY_MAGIC)
561 return -EEXIST; 565 return -EEXIST;
562 }
563 566
564 /* OK. Find a free X.25 channel to use. */ 567 /* OK. Find a free X.25 channel to use. */
565 if ((sl = x25_asy_alloc()) == NULL) { 568 sl = x25_asy_alloc();
569 if (sl == NULL)
566 return -ENFILE; 570 return -ENFILE;
567 }
568 571
569 sl->tty = tty; 572 sl->tty = tty;
570 tty->disc_data = sl; 573 tty->disc_data = sl;
571 tty->receive_room = 65536; 574 tty->receive_room = 65536;
572 if (tty->driver->flush_buffer) { 575 tty_driver_flush_buffer(tty);
573 tty->driver->flush_buffer(tty);
574 }
575 tty_ldisc_flush(tty); 576 tty_ldisc_flush(tty);
576 577
577 /* Restore default settings */ 578 /* Restore default settings */
578 sl->dev->type = ARPHRD_X25; 579 sl->dev->type = ARPHRD_X25;
579 580
580 /* Perform the low-level X.25 async init */ 581 /* Perform the low-level X.25 async init */
581 if ((err = x25_asy_open(sl->dev))) 582 err = x25_asy_open(sl->dev);
583 if (err)
582 return err; 584 return err;
583
584 /* Done. We have linked the TTY line to a channel. */ 585 /* Done. We have linked the TTY line to a channel. */
585 return sl->dev->base_addr; 586 return sl->dev->base_addr;
586} 587}
@@ -601,9 +602,7 @@ static void x25_asy_close_tty(struct tty_struct *tty)
601 return; 602 return;
602 603
603 if (sl->dev->flags & IFF_UP) 604 if (sl->dev->flags & IFF_UP)
604 { 605 dev_close(sl->dev);
605 (void) dev_close(sl->dev);
606 }
607 606
608 tty->disc_data = NULL; 607 tty->disc_data = NULL;
609 sl->tty = NULL; 608 sl->tty = NULL;
@@ -613,8 +612,7 @@ static void x25_asy_close_tty(struct tty_struct *tty)
613 612
614static struct net_device_stats *x25_asy_get_stats(struct net_device *dev) 613static struct net_device_stats *x25_asy_get_stats(struct net_device *dev)
615{ 614{
616 struct x25_asy *sl = (struct x25_asy*)(dev->priv); 615 struct x25_asy *sl = dev->priv;
617
618 return &sl->stats; 616 return &sl->stats;
619} 617}
620 618
@@ -641,21 +639,19 @@ int x25_asy_esc(unsigned char *s, unsigned char *d, int len)
641 * character sequence, according to the X.25 protocol. 639 * character sequence, according to the X.25 protocol.
642 */ 640 */
643 641
644 while (len-- > 0) 642 while (len-- > 0) {
645 { 643 switch (c = *s++) {
646 switch(c = *s++) 644 case X25_END:
647 { 645 *ptr++ = X25_ESC;
648 case X25_END: 646 *ptr++ = X25_ESCAPE(X25_END);
649 *ptr++ = X25_ESC; 647 break;
650 *ptr++ = X25_ESCAPE(X25_END); 648 case X25_ESC:
651 break; 649 *ptr++ = X25_ESC;
652 case X25_ESC: 650 *ptr++ = X25_ESCAPE(X25_ESC);
653 *ptr++ = X25_ESC; 651 break;
654 *ptr++ = X25_ESCAPE(X25_ESC); 652 default:
655 break; 653 *ptr++ = c;
656 default: 654 break;
657 *ptr++ = c;
658 break;
659 } 655 }
660 } 656 }
661 *ptr++ = X25_END; 657 *ptr++ = X25_END;
@@ -665,31 +661,25 @@ int x25_asy_esc(unsigned char *s, unsigned char *d, int len)
665static void x25_asy_unesc(struct x25_asy *sl, unsigned char s) 661static void x25_asy_unesc(struct x25_asy *sl, unsigned char s)
666{ 662{
667 663
668 switch(s) 664 switch (s) {
669 { 665 case X25_END:
670 case X25_END: 666 if (!test_and_clear_bit(SLF_ERROR, &sl->flags)
671 if (!test_and_clear_bit(SLF_ERROR, &sl->flags) && (sl->rcount > 2)) 667 && sl->rcount > 2)
672 { 668 x25_asy_bump(sl);
673 x25_asy_bump(sl); 669 clear_bit(SLF_ESCAPE, &sl->flags);
674 } 670 sl->rcount = 0;
675 clear_bit(SLF_ESCAPE, &sl->flags); 671 return;
676 sl->rcount = 0; 672 case X25_ESC:
677 return; 673 set_bit(SLF_ESCAPE, &sl->flags);
678 674 return;
679 case X25_ESC: 675 case X25_ESCAPE(X25_ESC):
680 set_bit(SLF_ESCAPE, &sl->flags); 676 case X25_ESCAPE(X25_END):
681 return; 677 if (test_and_clear_bit(SLF_ESCAPE, &sl->flags))
682 678 s = X25_UNESCAPE(s);
683 case X25_ESCAPE(X25_ESC): 679 break;
684 case X25_ESCAPE(X25_END): 680 }
685 if (test_and_clear_bit(SLF_ESCAPE, &sl->flags)) 681 if (!test_bit(SLF_ERROR, &sl->flags)) {
686 s = X25_UNESCAPE(s); 682 if (sl->rcount < sl->buffsize) {
687 break;
688 }
689 if (!test_bit(SLF_ERROR, &sl->flags))
690 {
691 if (sl->rcount < sl->buffsize)
692 {
693 sl->rbuff[sl->rcount++] = s; 683 sl->rbuff[sl->rcount++] = s;
694 return; 684 return;
695 } 685 }
@@ -709,7 +699,7 @@ static int x25_asy_ioctl(struct tty_struct *tty, struct file *file,
709 if (!sl || sl->magic != X25_ASY_MAGIC) 699 if (!sl || sl->magic != X25_ASY_MAGIC)
710 return -EINVAL; 700 return -EINVAL;
711 701
712 switch(cmd) { 702 switch (cmd) {
713 case SIOCGIFNAME: 703 case SIOCGIFNAME:
714 if (copy_to_user((void __user *)arg, sl->dev->name, 704 if (copy_to_user((void __user *)arg, sl->dev->name,
715 strlen(sl->dev->name) + 1)) 705 strlen(sl->dev->name) + 1))
@@ -724,8 +714,8 @@ static int x25_asy_ioctl(struct tty_struct *tty, struct file *file,
724 714
725static int x25_asy_open_dev(struct net_device *dev) 715static int x25_asy_open_dev(struct net_device *dev)
726{ 716{
727 struct x25_asy *sl = (struct x25_asy*)(dev->priv); 717 struct x25_asy *sl = dev->priv;
728 if(sl->tty==NULL) 718 if (sl->tty == NULL)
729 return -ENODEV; 719 return -ENODEV;
730 return 0; 720 return 0;
731} 721}
@@ -741,9 +731,9 @@ static void x25_asy_setup(struct net_device *dev)
741 set_bit(SLF_INUSE, &sl->flags); 731 set_bit(SLF_INUSE, &sl->flags);
742 732
743 /* 733 /*
744 * Finish setting up the DEVICE info. 734 * Finish setting up the DEVICE info.
745 */ 735 */
746 736
747 dev->mtu = SL_MTU; 737 dev->mtu = SL_MTU;
748 dev->hard_start_xmit = x25_asy_xmit; 738 dev->hard_start_xmit = x25_asy_xmit;
749 dev->tx_timeout = x25_asy_timeout; 739 dev->tx_timeout = x25_asy_timeout;
@@ -778,9 +768,10 @@ static int __init init_x25_asy(void)
778 x25_asy_maxdev = 4; /* Sanity */ 768 x25_asy_maxdev = 4; /* Sanity */
779 769
780 printk(KERN_INFO "X.25 async: version 0.00 ALPHA " 770 printk(KERN_INFO "X.25 async: version 0.00 ALPHA "
781 "(dynamic channels, max=%d).\n", x25_asy_maxdev ); 771 "(dynamic channels, max=%d).\n", x25_asy_maxdev);
782 772
783 x25_asy_devs = kcalloc(x25_asy_maxdev, sizeof(struct net_device*), GFP_KERNEL); 773 x25_asy_devs = kcalloc(x25_asy_maxdev, sizeof(struct net_device *),
774 GFP_KERNEL);
784 if (!x25_asy_devs) { 775 if (!x25_asy_devs) {
785 printk(KERN_WARNING "X25 async: Can't allocate x25_asy_ctrls[] " 776 printk(KERN_WARNING "X25 async: Can't allocate x25_asy_ctrls[] "
786 "array! Uaargh! (-> No X.25 available)\n"); 777 "array! Uaargh! (-> No X.25 available)\n");
@@ -802,7 +793,7 @@ static void __exit exit_x25_asy(void)
802 struct x25_asy *sl = dev->priv; 793 struct x25_asy *sl = dev->priv;
803 794
804 spin_lock_bh(&sl->lock); 795 spin_lock_bh(&sl->lock);
805 if (sl->tty) 796 if (sl->tty)
806 tty_hangup(sl->tty); 797 tty_hangup(sl->tty);
807 798
808 spin_unlock_bh(&sl->lock); 799 spin_unlock_bh(&sl->lock);
diff --git a/drivers/net/wireless/b43/b43.h b/drivers/net/wireless/b43/b43.h
index eff2a158a411..37783cdd301a 100644
--- a/drivers/net/wireless/b43/b43.h
+++ b/drivers/net/wireless/b43/b43.h
@@ -691,6 +691,10 @@ struct b43_wl {
691 691
692 struct mutex mutex; 692 struct mutex mutex;
693 spinlock_t irq_lock; 693 spinlock_t irq_lock;
694 /* R/W lock for data transmission.
695 * Transmissions on 2+ queues can run concurrently, but somebody else
696 * might sync with TX by write_lock_irqsave()'ing. */
697 rwlock_t tx_lock;
694 /* Lock for LEDs access. */ 698 /* Lock for LEDs access. */
695 spinlock_t leds_lock; 699 spinlock_t leds_lock;
696 /* Lock for SHM access. */ 700 /* Lock for SHM access. */
diff --git a/drivers/net/wireless/b43/main.c b/drivers/net/wireless/b43/main.c
index 8c24cd72aaca..8fdba9415c04 100644
--- a/drivers/net/wireless/b43/main.c
+++ b/drivers/net/wireless/b43/main.c
@@ -729,6 +729,7 @@ static void b43_synchronize_irq(struct b43_wldev *dev)
729 */ 729 */
730void b43_dummy_transmission(struct b43_wldev *dev) 730void b43_dummy_transmission(struct b43_wldev *dev)
731{ 731{
732 struct b43_wl *wl = dev->wl;
732 struct b43_phy *phy = &dev->phy; 733 struct b43_phy *phy = &dev->phy;
733 unsigned int i, max_loop; 734 unsigned int i, max_loop;
734 u16 value; 735 u16 value;
@@ -755,6 +756,9 @@ void b43_dummy_transmission(struct b43_wldev *dev)
755 return; 756 return;
756 } 757 }
757 758
759 spin_lock_irq(&wl->irq_lock);
760 write_lock(&wl->tx_lock);
761
758 for (i = 0; i < 5; i++) 762 for (i = 0; i < 5; i++)
759 b43_ram_write(dev, i * 4, buffer[i]); 763 b43_ram_write(dev, i * 4, buffer[i]);
760 764
@@ -795,6 +799,9 @@ void b43_dummy_transmission(struct b43_wldev *dev)
795 } 799 }
796 if (phy->radio_ver == 0x2050 && phy->radio_rev <= 0x5) 800 if (phy->radio_ver == 0x2050 && phy->radio_rev <= 0x5)
797 b43_radio_write16(dev, 0x0051, 0x0037); 801 b43_radio_write16(dev, 0x0051, 0x0037);
802
803 write_unlock(&wl->tx_lock);
804 spin_unlock_irq(&wl->irq_lock);
798} 805}
799 806
800static void key_write(struct b43_wldev *dev, 807static void key_write(struct b43_wldev *dev,
@@ -2840,24 +2847,31 @@ static int b43_op_tx(struct ieee80211_hw *hw,
2840{ 2847{
2841 struct b43_wl *wl = hw_to_b43_wl(hw); 2848 struct b43_wl *wl = hw_to_b43_wl(hw);
2842 struct b43_wldev *dev = wl->current_dev; 2849 struct b43_wldev *dev = wl->current_dev;
2843 int err = -ENODEV; 2850 unsigned long flags;
2851 int err;
2844 2852
2845 if (unlikely(skb->len < 2 + 2 + 6)) { 2853 if (unlikely(skb->len < 2 + 2 + 6)) {
2846 /* Too short, this can't be a valid frame. */ 2854 /* Too short, this can't be a valid frame. */
2847 return -EINVAL; 2855 dev_kfree_skb_any(skb);
2856 return NETDEV_TX_OK;
2848 } 2857 }
2849 B43_WARN_ON(skb_shinfo(skb)->nr_frags); 2858 B43_WARN_ON(skb_shinfo(skb)->nr_frags);
2850
2851 if (unlikely(!dev)) 2859 if (unlikely(!dev))
2852 goto out; 2860 return NETDEV_TX_BUSY;
2853 if (unlikely(b43_status(dev) < B43_STAT_STARTED)) 2861
2854 goto out; 2862 /* Transmissions on seperate queues can run concurrently. */
2855 /* TX is done without a global lock. */ 2863 read_lock_irqsave(&wl->tx_lock, flags);
2856 if (b43_using_pio_transfers(dev)) 2864
2857 err = b43_pio_tx(dev, skb, ctl); 2865 err = -ENODEV;
2858 else 2866 if (likely(b43_status(dev) >= B43_STAT_STARTED)) {
2859 err = b43_dma_tx(dev, skb, ctl); 2867 if (b43_using_pio_transfers(dev))
2860out: 2868 err = b43_pio_tx(dev, skb, ctl);
2869 else
2870 err = b43_dma_tx(dev, skb, ctl);
2871 }
2872
2873 read_unlock_irqrestore(&wl->tx_lock, flags);
2874
2861 if (unlikely(err)) 2875 if (unlikely(err))
2862 return NETDEV_TX_BUSY; 2876 return NETDEV_TX_BUSY;
2863 return NETDEV_TX_OK; 2877 return NETDEV_TX_OK;
@@ -3476,7 +3490,9 @@ static void b43_wireless_core_stop(struct b43_wldev *dev)
3476 spin_unlock_irqrestore(&wl->irq_lock, flags); 3490 spin_unlock_irqrestore(&wl->irq_lock, flags);
3477 b43_synchronize_irq(dev); 3491 b43_synchronize_irq(dev);
3478 3492
3493 write_lock_irqsave(&wl->tx_lock, flags);
3479 b43_set_status(dev, B43_STAT_INITIALIZED); 3494 b43_set_status(dev, B43_STAT_INITIALIZED);
3495 write_unlock_irqrestore(&wl->tx_lock, flags);
3480 3496
3481 b43_pio_stop(dev); 3497 b43_pio_stop(dev);
3482 mutex_unlock(&wl->mutex); 3498 mutex_unlock(&wl->mutex);
@@ -3485,8 +3501,6 @@ static void b43_wireless_core_stop(struct b43_wldev *dev)
3485 cancel_delayed_work_sync(&dev->periodic_work); 3501 cancel_delayed_work_sync(&dev->periodic_work);
3486 mutex_lock(&wl->mutex); 3502 mutex_lock(&wl->mutex);
3487 3503
3488 ieee80211_stop_queues(wl->hw); //FIXME this could cause a deadlock, as mac80211 seems buggy.
3489
3490 b43_mac_suspend(dev); 3504 b43_mac_suspend(dev);
3491 free_irq(dev->dev->irq, dev); 3505 free_irq(dev->dev->irq, dev);
3492 b43dbg(wl, "Wireless interface stopped\n"); 3506 b43dbg(wl, "Wireless interface stopped\n");
@@ -4326,6 +4340,14 @@ static int b43_wireless_core_attach(struct b43_wldev *dev)
4326 err = -EOPNOTSUPP; 4340 err = -EOPNOTSUPP;
4327 goto err_powerdown; 4341 goto err_powerdown;
4328 } 4342 }
4343 if (1 /* disable A-PHY */) {
4344 /* FIXME: For now we disable the A-PHY on multi-PHY devices. */
4345 if (dev->phy.type != B43_PHYTYPE_N) {
4346 have_2ghz_phy = 1;
4347 have_5ghz_phy = 0;
4348 }
4349 }
4350
4329 dev->phy.gmode = have_2ghz_phy; 4351 dev->phy.gmode = have_2ghz_phy;
4330 tmp = dev->phy.gmode ? B43_TMSLOW_GMODE : 0; 4352 tmp = dev->phy.gmode ? B43_TMSLOW_GMODE : 0;
4331 b43_wireless_core_reset(dev, tmp); 4353 b43_wireless_core_reset(dev, tmp);
@@ -4490,6 +4512,7 @@ static int b43_wireless_init(struct ssb_device *dev)
4490 memset(wl, 0, sizeof(*wl)); 4512 memset(wl, 0, sizeof(*wl));
4491 wl->hw = hw; 4513 wl->hw = hw;
4492 spin_lock_init(&wl->irq_lock); 4514 spin_lock_init(&wl->irq_lock);
4515 rwlock_init(&wl->tx_lock);
4493 spin_lock_init(&wl->leds_lock); 4516 spin_lock_init(&wl->leds_lock);
4494 spin_lock_init(&wl->shm_lock); 4517 spin_lock_init(&wl->shm_lock);
4495 mutex_init(&wl->mutex); 4518 mutex_init(&wl->mutex);
diff --git a/drivers/net/wireless/iwlwifi/Kconfig b/drivers/net/wireless/iwlwifi/Kconfig
index 9a25f550fd16..d5b7a76fcaad 100644
--- a/drivers/net/wireless/iwlwifi/Kconfig
+++ b/drivers/net/wireless/iwlwifi/Kconfig
@@ -6,6 +6,10 @@ config IWLCORE
6 tristate "Intel Wireless Wifi Core" 6 tristate "Intel Wireless Wifi Core"
7 depends on PCI && MAC80211 && WLAN_80211 && EXPERIMENTAL 7 depends on PCI && MAC80211 && WLAN_80211 && EXPERIMENTAL
8 select IWLWIFI 8 select IWLWIFI
9 select MAC80211_LEDS if IWLWIFI_LEDS
10 select LEDS_CLASS if IWLWIFI_LEDS
11 select RFKILL if IWLWIFI_RFKILL
12 select RFKILL_INPUT if IWLWIFI_RFKILL
9 13
10config IWLWIFI_LEDS 14config IWLWIFI_LEDS
11 bool 15 bool
@@ -14,8 +18,6 @@ config IWLWIFI_LEDS
14config IWLWIFI_RFKILL 18config IWLWIFI_RFKILL
15 boolean "IWLWIFI RF kill support" 19 boolean "IWLWIFI RF kill support"
16 depends on IWLCORE 20 depends on IWLCORE
17 select RFKILL
18 select RFKILL_INPUT
19 21
20config IWL4965 22config IWL4965
21 tristate "Intel Wireless WiFi 4965AGN" 23 tristate "Intel Wireless WiFi 4965AGN"
@@ -55,8 +57,6 @@ config IWL4965_HT
55config IWL4965_LEDS 57config IWL4965_LEDS
56 bool "Enable LEDS features in iwl4965 driver" 58 bool "Enable LEDS features in iwl4965 driver"
57 depends on IWL4965 59 depends on IWL4965
58 select MAC80211_LEDS
59 select LEDS_CLASS
60 select IWLWIFI_LEDS 60 select IWLWIFI_LEDS
61 ---help--- 61 ---help---
62 This option enables LEDS for the iwlwifi drivers 62 This option enables LEDS for the iwlwifi drivers
@@ -112,6 +112,8 @@ config IWL3945
112 depends on PCI && MAC80211 && WLAN_80211 && EXPERIMENTAL 112 depends on PCI && MAC80211 && WLAN_80211 && EXPERIMENTAL
113 select FW_LOADER 113 select FW_LOADER
114 select IWLWIFI 114 select IWLWIFI
115 select MAC80211_LEDS if IWL3945_LEDS
116 select LEDS_CLASS if IWL3945_LEDS
115 ---help--- 117 ---help---
116 Select to build the driver supporting the: 118 Select to build the driver supporting the:
117 119
@@ -143,8 +145,6 @@ config IWL3945_SPECTRUM_MEASUREMENT
143config IWL3945_LEDS 145config IWL3945_LEDS
144 bool "Enable LEDS features in iwl3945 driver" 146 bool "Enable LEDS features in iwl3945 driver"
145 depends on IWL3945 147 depends on IWL3945
146 select MAC80211_LEDS
147 select LEDS_CLASS
148 ---help--- 148 ---help---
149 This option enables LEDS for the iwl3945 driver. 149 This option enables LEDS for the iwl3945 driver.
150 150
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.h b/drivers/net/wireless/iwlwifi/iwl-3945.h
index 45c1c5533bf0..c7695a215a39 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.h
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.h
@@ -742,7 +742,6 @@ struct iwl3945_priv {
742 u8 direct_ssid_len; 742 u8 direct_ssid_len;
743 u8 direct_ssid[IW_ESSID_MAX_SIZE]; 743 u8 direct_ssid[IW_ESSID_MAX_SIZE];
744 struct iwl3945_scan_cmd *scan; 744 struct iwl3945_scan_cmd *scan;
745 u8 only_active_channel;
746 745
747 /* spinlock */ 746 /* spinlock */
748 spinlock_t lock; /* protect general shared data */ 747 spinlock_t lock; /* protect general shared data */
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.h b/drivers/net/wireless/iwlwifi/iwl-4965.h
index 9ed13cb0a2a9..581b98556c86 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965.h
+++ b/drivers/net/wireless/iwlwifi/iwl-4965.h
@@ -996,7 +996,6 @@ struct iwl_priv {
996 u8 direct_ssid_len; 996 u8 direct_ssid_len;
997 u8 direct_ssid[IW_ESSID_MAX_SIZE]; 997 u8 direct_ssid[IW_ESSID_MAX_SIZE];
998 struct iwl4965_scan_cmd *scan; 998 struct iwl4965_scan_cmd *scan;
999 u8 only_active_channel;
1000 999
1001 /* spinlock */ 1000 /* spinlock */
1002 spinlock_t lock; /* protect general shared data */ 1001 spinlock_t lock; /* protect general shared data */
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index a1a0b3c581f1..13925b627e3b 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -4968,17 +4968,6 @@ static int iwl3945_get_channels_for_scan(struct iwl3945_priv *priv,
4968 if (channels[i].flags & IEEE80211_CHAN_DISABLED) 4968 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
4969 continue; 4969 continue;
4970 4970
4971 if (channels[i].hw_value ==
4972 le16_to_cpu(priv->active_rxon.channel)) {
4973 if (iwl3945_is_associated(priv)) {
4974 IWL_DEBUG_SCAN
4975 ("Skipping current channel %d\n",
4976 le16_to_cpu(priv->active_rxon.channel));
4977 continue;
4978 }
4979 } else if (priv->only_active_channel)
4980 continue;
4981
4982 scan_ch->channel = channels[i].hw_value; 4971 scan_ch->channel = channels[i].hw_value;
4983 4972
4984 ch_info = iwl3945_get_channel_info(priv, band, scan_ch->channel); 4973 ch_info = iwl3945_get_channel_info(priv, band, scan_ch->channel);
@@ -6303,12 +6292,17 @@ static void iwl3945_bg_request_scan(struct work_struct *data)
6303 priv->direct_ssid, priv->direct_ssid_len); 6292 priv->direct_ssid, priv->direct_ssid_len);
6304 direct_mask = 1; 6293 direct_mask = 1;
6305 } else if (!iwl3945_is_associated(priv) && priv->essid_len) { 6294 } else if (!iwl3945_is_associated(priv) && priv->essid_len) {
6295 IWL_DEBUG_SCAN
6296 ("Kicking off one direct scan for '%s' when not associated\n",
6297 iwl3945_escape_essid(priv->essid, priv->essid_len));
6306 scan->direct_scan[0].id = WLAN_EID_SSID; 6298 scan->direct_scan[0].id = WLAN_EID_SSID;
6307 scan->direct_scan[0].len = priv->essid_len; 6299 scan->direct_scan[0].len = priv->essid_len;
6308 memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len); 6300 memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
6309 direct_mask = 1; 6301 direct_mask = 1;
6310 } else 6302 } else {
6303 IWL_DEBUG_SCAN("Kicking off one indirect scan.\n");
6311 direct_mask = 0; 6304 direct_mask = 0;
6305 }
6312 6306
6313 /* We don't build a direct scan probe request; the uCode will do 6307 /* We don't build a direct scan probe request; the uCode will do
6314 * that based on the direct_mask added to each channel entry */ 6308 * that based on the direct_mask added to each channel entry */
@@ -6346,23 +6340,18 @@ static void iwl3945_bg_request_scan(struct work_struct *data)
6346 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) 6340 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR)
6347 scan->filter_flags = RXON_FILTER_PROMISC_MSK; 6341 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
6348 6342
6349 if (direct_mask) { 6343 if (direct_mask)
6350 IWL_DEBUG_SCAN
6351 ("Initiating direct scan for %s.\n",
6352 iwl3945_escape_essid(priv->essid, priv->essid_len));
6353 scan->channel_count = 6344 scan->channel_count =
6354 iwl3945_get_channels_for_scan( 6345 iwl3945_get_channels_for_scan(
6355 priv, band, 1, /* active */ 6346 priv, band, 1, /* active */
6356 direct_mask, 6347 direct_mask,
6357 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); 6348 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
6358 } else { 6349 else
6359 IWL_DEBUG_SCAN("Initiating indirect scan.\n");
6360 scan->channel_count = 6350 scan->channel_count =
6361 iwl3945_get_channels_for_scan( 6351 iwl3945_get_channels_for_scan(
6362 priv, band, 0, /* passive */ 6352 priv, band, 0, /* passive */
6363 direct_mask, 6353 direct_mask,
6364 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); 6354 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
6365 }
6366 6355
6367 cmd.len += le16_to_cpu(scan->tx_cmd.len) + 6356 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
6368 scan->channel_count * sizeof(struct iwl3945_scan_channel); 6357 scan->channel_count * sizeof(struct iwl3945_scan_channel);
@@ -7314,8 +7303,6 @@ static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
7314 return; 7303 return;
7315 } 7304 }
7316 7305
7317 priv->only_active_channel = 0;
7318
7319 iwl3945_set_rate(priv); 7306 iwl3945_set_rate(priv);
7320 7307
7321 mutex_unlock(&priv->mutex); 7308 mutex_unlock(&priv->mutex);
diff --git a/drivers/net/wireless/iwlwifi/iwl4965-base.c b/drivers/net/wireless/iwlwifi/iwl4965-base.c
index d0bbcaaeb94c..883b42f7e998 100644
--- a/drivers/net/wireless/iwlwifi/iwl4965-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl4965-base.c
@@ -4633,17 +4633,6 @@ static int iwl4965_get_channels_for_scan(struct iwl_priv *priv,
4633 if (channels[i].flags & IEEE80211_CHAN_DISABLED) 4633 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
4634 continue; 4634 continue;
4635 4635
4636 if (ieee80211_frequency_to_channel(channels[i].center_freq) ==
4637 le16_to_cpu(priv->active_rxon.channel)) {
4638 if (iwl_is_associated(priv)) {
4639 IWL_DEBUG_SCAN
4640 ("Skipping current channel %d\n",
4641 le16_to_cpu(priv->active_rxon.channel));
4642 continue;
4643 }
4644 } else if (priv->only_active_channel)
4645 continue;
4646
4647 scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq); 4636 scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq);
4648 4637
4649 ch_info = iwl_get_channel_info(priv, band, 4638 ch_info = iwl_get_channel_info(priv, band,
@@ -5824,11 +5813,15 @@ static void iwl4965_bg_request_scan(struct work_struct *data)
5824 priv->direct_ssid, priv->direct_ssid_len); 5813 priv->direct_ssid, priv->direct_ssid_len);
5825 direct_mask = 1; 5814 direct_mask = 1;
5826 } else if (!iwl_is_associated(priv) && priv->essid_len) { 5815 } else if (!iwl_is_associated(priv) && priv->essid_len) {
5816 IWL_DEBUG_SCAN
5817 ("Kicking off one direct scan for '%s' when not associated\n",
5818 iwl4965_escape_essid(priv->essid, priv->essid_len));
5827 scan->direct_scan[0].id = WLAN_EID_SSID; 5819 scan->direct_scan[0].id = WLAN_EID_SSID;
5828 scan->direct_scan[0].len = priv->essid_len; 5820 scan->direct_scan[0].len = priv->essid_len;
5829 memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len); 5821 memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
5830 direct_mask = 1; 5822 direct_mask = 1;
5831 } else { 5823 } else {
5824 IWL_DEBUG_SCAN("Kicking off one indirect scan.\n");
5832 direct_mask = 0; 5825 direct_mask = 0;
5833 } 5826 }
5834 5827
@@ -5881,23 +5874,18 @@ static void iwl4965_bg_request_scan(struct work_struct *data)
5881 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) 5874 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR)
5882 scan->filter_flags = RXON_FILTER_PROMISC_MSK; 5875 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
5883 5876
5884 if (direct_mask) { 5877 if (direct_mask)
5885 IWL_DEBUG_SCAN
5886 ("Initiating direct scan for %s.\n",
5887 iwl4965_escape_essid(priv->essid, priv->essid_len));
5888 scan->channel_count = 5878 scan->channel_count =
5889 iwl4965_get_channels_for_scan( 5879 iwl4965_get_channels_for_scan(
5890 priv, band, 1, /* active */ 5880 priv, band, 1, /* active */
5891 direct_mask, 5881 direct_mask,
5892 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); 5882 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
5893 } else { 5883 else
5894 IWL_DEBUG_SCAN("Initiating indirect scan.\n");
5895 scan->channel_count = 5884 scan->channel_count =
5896 iwl4965_get_channels_for_scan( 5885 iwl4965_get_channels_for_scan(
5897 priv, band, 0, /* passive */ 5886 priv, band, 0, /* passive */
5898 direct_mask, 5887 direct_mask,
5899 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); 5888 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
5900 }
5901 5889
5902 cmd.len += le16_to_cpu(scan->tx_cmd.len) + 5890 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
5903 scan->channel_count * sizeof(struct iwl4965_scan_channel); 5891 scan->channel_count * sizeof(struct iwl4965_scan_channel);
@@ -7061,8 +7049,6 @@ static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
7061 return; 7049 return;
7062 } 7050 }
7063 7051
7064 priv->only_active_channel = 0;
7065
7066 iwl4965_set_rate(priv); 7052 iwl4965_set_rate(priv);
7067 7053
7068 mutex_unlock(&priv->mutex); 7054 mutex_unlock(&priv->mutex);
diff --git a/drivers/net/wireless/libertas/scan.c b/drivers/net/wireless/libertas/scan.c
index 1a409fcc80d3..d448c9702a0f 100644
--- a/drivers/net/wireless/libertas/scan.c
+++ b/drivers/net/wireless/libertas/scan.c
@@ -298,7 +298,8 @@ static int lbs_do_scan(struct lbs_private *priv, uint8_t bsstype,
298 uint8_t *tlv; /* pointer into our current, growing TLV storage area */ 298 uint8_t *tlv; /* pointer into our current, growing TLV storage area */
299 299
300 lbs_deb_enter_args(LBS_DEB_SCAN, "bsstype %d, chanlist[].chan %d, chan_count %d", 300 lbs_deb_enter_args(LBS_DEB_SCAN, "bsstype %d, chanlist[].chan %d, chan_count %d",
301 bsstype, chan_list[0].channumber, chan_count); 301 bsstype, chan_list ? chan_list[0].channumber : -1,
302 chan_count);
302 303
303 /* create the fixed part for scan command */ 304 /* create the fixed part for scan command */
304 scan_cmd = kzalloc(MAX_SCAN_CFG_ALLOC, GFP_KERNEL); 305 scan_cmd = kzalloc(MAX_SCAN_CFG_ALLOC, GFP_KERNEL);
diff --git a/drivers/net/wireless/rt2x00/rt2400pci.c b/drivers/net/wireless/rt2x00/rt2400pci.c
index b41187af1306..560b9c73c0b9 100644
--- a/drivers/net/wireless/rt2x00/rt2400pci.c
+++ b/drivers/net/wireless/rt2x00/rt2400pci.c
@@ -363,7 +363,7 @@ static void rt2400pci_config_erp(struct rt2x00_dev *rt2x00dev,
363 rt2x00pci_register_write(rt2x00dev, TXCSR1, reg); 363 rt2x00pci_register_write(rt2x00dev, TXCSR1, reg);
364 364
365 rt2x00pci_register_read(rt2x00dev, ARCSR2, &reg); 365 rt2x00pci_register_read(rt2x00dev, ARCSR2, &reg);
366 rt2x00_set_field32(&reg, ARCSR2_SIGNAL, 0x00 | preamble_mask); 366 rt2x00_set_field32(&reg, ARCSR2_SIGNAL, 0x00);
367 rt2x00_set_field32(&reg, ARCSR2_SERVICE, 0x04); 367 rt2x00_set_field32(&reg, ARCSR2_SERVICE, 0x04);
368 rt2x00_set_field32(&reg, ARCSR2_LENGTH, get_duration(ACK_SIZE, 10)); 368 rt2x00_set_field32(&reg, ARCSR2_LENGTH, get_duration(ACK_SIZE, 10));
369 rt2x00pci_register_write(rt2x00dev, ARCSR2, reg); 369 rt2x00pci_register_write(rt2x00dev, ARCSR2, reg);
@@ -1308,7 +1308,7 @@ static int rt2400pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
1308 1308
1309 if (value == LED_MODE_TXRX_ACTIVITY) { 1309 if (value == LED_MODE_TXRX_ACTIVITY) {
1310 rt2x00dev->led_qual.rt2x00dev = rt2x00dev; 1310 rt2x00dev->led_qual.rt2x00dev = rt2x00dev;
1311 rt2x00dev->led_radio.type = LED_TYPE_ACTIVITY; 1311 rt2x00dev->led_qual.type = LED_TYPE_ACTIVITY;
1312 rt2x00dev->led_qual.led_dev.brightness_set = 1312 rt2x00dev->led_qual.led_dev.brightness_set =
1313 rt2400pci_brightness_set; 1313 rt2400pci_brightness_set;
1314 rt2x00dev->led_qual.led_dev.blink_set = 1314 rt2x00dev->led_qual.led_dev.blink_set =
diff --git a/drivers/net/wireless/rt2x00/rt2500pci.c b/drivers/net/wireless/rt2x00/rt2500pci.c
index 5ade097ed45e..a5ed54b69262 100644
--- a/drivers/net/wireless/rt2x00/rt2500pci.c
+++ b/drivers/net/wireless/rt2x00/rt2500pci.c
@@ -370,7 +370,7 @@ static void rt2500pci_config_erp(struct rt2x00_dev *rt2x00dev,
370 rt2x00pci_register_write(rt2x00dev, TXCSR1, reg); 370 rt2x00pci_register_write(rt2x00dev, TXCSR1, reg);
371 371
372 rt2x00pci_register_read(rt2x00dev, ARCSR2, &reg); 372 rt2x00pci_register_read(rt2x00dev, ARCSR2, &reg);
373 rt2x00_set_field32(&reg, ARCSR2_SIGNAL, 0x00 | preamble_mask); 373 rt2x00_set_field32(&reg, ARCSR2_SIGNAL, 0x00);
374 rt2x00_set_field32(&reg, ARCSR2_SERVICE, 0x04); 374 rt2x00_set_field32(&reg, ARCSR2_SERVICE, 0x04);
375 rt2x00_set_field32(&reg, ARCSR2_LENGTH, get_duration(ACK_SIZE, 10)); 375 rt2x00_set_field32(&reg, ARCSR2_LENGTH, get_duration(ACK_SIZE, 10));
376 rt2x00pci_register_write(rt2x00dev, ARCSR2, reg); 376 rt2x00pci_register_write(rt2x00dev, ARCSR2, reg);
@@ -1485,7 +1485,7 @@ static int rt2500pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
1485 1485
1486 if (value == LED_MODE_TXRX_ACTIVITY) { 1486 if (value == LED_MODE_TXRX_ACTIVITY) {
1487 rt2x00dev->led_qual.rt2x00dev = rt2x00dev; 1487 rt2x00dev->led_qual.rt2x00dev = rt2x00dev;
1488 rt2x00dev->led_radio.type = LED_TYPE_ACTIVITY; 1488 rt2x00dev->led_qual.type = LED_TYPE_ACTIVITY;
1489 rt2x00dev->led_qual.led_dev.brightness_set = 1489 rt2x00dev->led_qual.led_dev.brightness_set =
1490 rt2500pci_brightness_set; 1490 rt2500pci_brightness_set;
1491 rt2x00dev->led_qual.led_dev.blink_set = 1491 rt2x00dev->led_qual.led_dev.blink_set =
diff --git a/drivers/net/wireless/rt2x00/rt2500usb.c b/drivers/net/wireless/rt2x00/rt2500usb.c
index 6bb07b339325..fdbd0ef2be4b 100644
--- a/drivers/net/wireless/rt2x00/rt2500usb.c
+++ b/drivers/net/wireless/rt2x00/rt2500usb.c
@@ -1394,7 +1394,7 @@ static int rt2500usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
1394 1394
1395 if (value == LED_MODE_TXRX_ACTIVITY) { 1395 if (value == LED_MODE_TXRX_ACTIVITY) {
1396 rt2x00dev->led_qual.rt2x00dev = rt2x00dev; 1396 rt2x00dev->led_qual.rt2x00dev = rt2x00dev;
1397 rt2x00dev->led_radio.type = LED_TYPE_ACTIVITY; 1397 rt2x00dev->led_qual.type = LED_TYPE_ACTIVITY;
1398 rt2x00dev->led_qual.led_dev.brightness_set = 1398 rt2x00dev->led_qual.led_dev.brightness_set =
1399 rt2500usb_brightness_set; 1399 rt2500usb_brightness_set;
1400 rt2x00dev->led_qual.led_dev.blink_set = 1400 rt2x00dev->led_qual.led_dev.blink_set =
diff --git a/drivers/net/wireless/rt2x00/rt2x00dev.c b/drivers/net/wireless/rt2x00/rt2x00dev.c
index f8fe7a139a8a..8d8657fb64dd 100644
--- a/drivers/net/wireless/rt2x00/rt2x00dev.c
+++ b/drivers/net/wireless/rt2x00/rt2x00dev.c
@@ -114,6 +114,7 @@ int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev)
114 return status; 114 return status;
115 115
116 rt2x00leds_led_radio(rt2x00dev, true); 116 rt2x00leds_led_radio(rt2x00dev, true);
117 rt2x00led_led_activity(rt2x00dev, true);
117 118
118 __set_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags); 119 __set_bit(DEVICE_ENABLED_RADIO, &rt2x00dev->flags);
119 120
@@ -157,6 +158,7 @@ void rt2x00lib_disable_radio(struct rt2x00_dev *rt2x00dev)
157 * Disable radio. 158 * Disable radio.
158 */ 159 */
159 rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_OFF); 160 rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_OFF);
161 rt2x00led_led_activity(rt2x00dev, false);
160 rt2x00leds_led_radio(rt2x00dev, false); 162 rt2x00leds_led_radio(rt2x00dev, false);
161} 163}
162 164
diff --git a/drivers/net/wireless/rt2x00/rt2x00leds.c b/drivers/net/wireless/rt2x00/rt2x00leds.c
index 40c1f5c1b805..b362a1cf3f8d 100644
--- a/drivers/net/wireless/rt2x00/rt2x00leds.c
+++ b/drivers/net/wireless/rt2x00/rt2x00leds.c
@@ -72,6 +72,21 @@ void rt2x00leds_led_quality(struct rt2x00_dev *rt2x00dev, int rssi)
72 } 72 }
73} 73}
74 74
75void rt2x00led_led_activity(struct rt2x00_dev *rt2x00dev, bool enabled)
76{
77 struct rt2x00_led *led = &rt2x00dev->led_qual;
78 unsigned int brightness;
79
80 if ((led->type != LED_TYPE_ACTIVITY) || !(led->flags & LED_REGISTERED))
81 return;
82
83 brightness = enabled ? LED_FULL : LED_OFF;
84 if (brightness != led->led_dev.brightness) {
85 led->led_dev.brightness_set(&led->led_dev, brightness);
86 led->led_dev.brightness = brightness;
87 }
88}
89
75void rt2x00leds_led_assoc(struct rt2x00_dev *rt2x00dev, bool enabled) 90void rt2x00leds_led_assoc(struct rt2x00_dev *rt2x00dev, bool enabled)
76{ 91{
77 struct rt2x00_led *led = &rt2x00dev->led_assoc; 92 struct rt2x00_led *led = &rt2x00dev->led_assoc;
diff --git a/drivers/net/wireless/rt2x00/rt2x00lib.h b/drivers/net/wireless/rt2x00/rt2x00lib.h
index 5be32fffc74c..41ee02cd2825 100644
--- a/drivers/net/wireless/rt2x00/rt2x00lib.h
+++ b/drivers/net/wireless/rt2x00/rt2x00lib.h
@@ -185,6 +185,7 @@ static inline void rt2x00rfkill_resume(struct rt2x00_dev *rt2x00dev)
185 */ 185 */
186#ifdef CONFIG_RT2X00_LIB_LEDS 186#ifdef CONFIG_RT2X00_LIB_LEDS
187void rt2x00leds_led_quality(struct rt2x00_dev *rt2x00dev, int rssi); 187void rt2x00leds_led_quality(struct rt2x00_dev *rt2x00dev, int rssi);
188void rt2x00led_led_activity(struct rt2x00_dev *rt2x00dev, bool enabled);
188void rt2x00leds_led_assoc(struct rt2x00_dev *rt2x00dev, bool enabled); 189void rt2x00leds_led_assoc(struct rt2x00_dev *rt2x00dev, bool enabled);
189void rt2x00leds_led_radio(struct rt2x00_dev *rt2x00dev, bool enabled); 190void rt2x00leds_led_radio(struct rt2x00_dev *rt2x00dev, bool enabled);
190void rt2x00leds_register(struct rt2x00_dev *rt2x00dev); 191void rt2x00leds_register(struct rt2x00_dev *rt2x00dev);
@@ -197,6 +198,11 @@ static inline void rt2x00leds_led_quality(struct rt2x00_dev *rt2x00dev,
197{ 198{
198} 199}
199 200
201static inline void rt2x00led_led_activity(struct rt2x00_dev *rt2x00dev,
202 bool enabled)
203{
204}
205
200static inline void rt2x00leds_led_assoc(struct rt2x00_dev *rt2x00dev, 206static inline void rt2x00leds_led_assoc(struct rt2x00_dev *rt2x00dev,
201 bool enabled) 207 bool enabled)
202{ 208{
diff --git a/drivers/net/wireless/rt2x00/rt61pci.c b/drivers/net/wireless/rt2x00/rt61pci.c
index 468a31c8c113..ae12dcdd3c24 100644
--- a/drivers/net/wireless/rt2x00/rt61pci.c
+++ b/drivers/net/wireless/rt2x00/rt61pci.c
@@ -2087,7 +2087,7 @@ static int rt61pci_init_eeprom(struct rt2x00_dev *rt2x00dev)
2087 2087
2088 if (value == LED_MODE_SIGNAL_STRENGTH) { 2088 if (value == LED_MODE_SIGNAL_STRENGTH) {
2089 rt2x00dev->led_qual.rt2x00dev = rt2x00dev; 2089 rt2x00dev->led_qual.rt2x00dev = rt2x00dev;
2090 rt2x00dev->led_radio.type = LED_TYPE_QUALITY; 2090 rt2x00dev->led_qual.type = LED_TYPE_QUALITY;
2091 rt2x00dev->led_qual.led_dev.brightness_set = 2091 rt2x00dev->led_qual.led_dev.brightness_set =
2092 rt61pci_brightness_set; 2092 rt61pci_brightness_set;
2093 rt2x00dev->led_qual.led_dev.blink_set = 2093 rt2x00dev->led_qual.led_dev.blink_set =
diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c
index a9efe25f1ea7..da19a3a91f4d 100644
--- a/drivers/net/wireless/rt2x00/rt73usb.c
+++ b/drivers/net/wireless/rt2x00/rt73usb.c
@@ -1647,7 +1647,7 @@ static int rt73usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
1647 1647
1648 if (value == LED_MODE_SIGNAL_STRENGTH) { 1648 if (value == LED_MODE_SIGNAL_STRENGTH) {
1649 rt2x00dev->led_qual.rt2x00dev = rt2x00dev; 1649 rt2x00dev->led_qual.rt2x00dev = rt2x00dev;
1650 rt2x00dev->led_radio.type = LED_TYPE_QUALITY; 1650 rt2x00dev->led_qual.type = LED_TYPE_QUALITY;
1651 rt2x00dev->led_qual.led_dev.brightness_set = 1651 rt2x00dev->led_qual.led_dev.brightness_set =
1652 rt73usb_brightness_set; 1652 rt73usb_brightness_set;
1653 rt2x00dev->led_qual.led_dev.blink_set = 1653 rt2x00dev->led_qual.led_dev.blink_set =
diff --git a/drivers/net/wireless/strip.c b/drivers/net/wireless/strip.c
index bced3fe1cf8a..5dd23c93497d 100644
--- a/drivers/net/wireless/strip.c
+++ b/drivers/net/wireless/strip.c
@@ -768,41 +768,17 @@ static __u8 *UnStuffData(__u8 * src, __u8 * end, __u8 * dst,
768/* General routines for STRIP */ 768/* General routines for STRIP */
769 769
770/* 770/*
771 * get_baud returns the current baud rate, as one of the constants defined in
772 * termbits.h
773 * If the user has issued a baud rate override using the 'setserial' command
774 * and the logical current rate is set to 38.4, then the true baud rate
775 * currently in effect (57.6 or 115.2) is returned.
776 */
777static unsigned int get_baud(struct tty_struct *tty)
778{
779 if (!tty || !tty->termios)
780 return (0);
781 if ((tty->termios->c_cflag & CBAUD) == B38400 && tty->driver_data) {
782 struct async_struct *info =
783 (struct async_struct *) tty->driver_data;
784 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
785 return (B57600);
786 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
787 return (B115200);
788 }
789 return (tty->termios->c_cflag & CBAUD);
790}
791
792/*
793 * set_baud sets the baud rate to the rate defined by baudcode 771 * set_baud sets the baud rate to the rate defined by baudcode
794 * Note: The rate B38400 should be avoided, because the user may have
795 * issued a 'setserial' speed override to map that to a different speed.
796 * We could achieve a true rate of 38400 if we needed to by cancelling
797 * any user speed override that is in place, but that might annoy the
798 * user, so it is simplest to just avoid using 38400.
799 */ 772 */
800static void set_baud(struct tty_struct *tty, unsigned int baudcode) 773static void set_baud(struct tty_struct *tty, speed_t baudrate)
801{ 774{
802 struct ktermios old_termios = *(tty->termios); 775 struct ktermios old_termios;
803 tty->termios->c_cflag &= ~CBAUD; /* Clear the old baud setting */ 776
804 tty->termios->c_cflag |= baudcode; /* Set the new baud setting */ 777 mutex_lock(&tty->termios_mutex);
805 tty->driver->set_termios(tty, &old_termios); 778 old_termios =*(tty->termios);
779 tty_encode_baud_rate(tty, baudrate, baudrate);
780 tty->ops->set_termios(tty, &old_termios);
781 mutex_unlock(&tty->termios_mutex);
806} 782}
807 783
808/* 784/*
@@ -1217,7 +1193,7 @@ static void ResetRadio(struct strip *strip_info)
1217 strip_info->watchdog_doreset = jiffies + 1 * HZ; 1193 strip_info->watchdog_doreset = jiffies + 1 * HZ;
1218 1194
1219 /* If the user has selected a baud rate above 38.4 see what magic we have to do */ 1195 /* If the user has selected a baud rate above 38.4 see what magic we have to do */
1220 if (strip_info->user_baud > B38400) { 1196 if (strip_info->user_baud > 38400) {
1221 /* 1197 /*
1222 * Subtle stuff: Pay attention :-) 1198 * Subtle stuff: Pay attention :-)
1223 * If the serial port is currently at the user's selected (>38.4) rate, 1199 * If the serial port is currently at the user's selected (>38.4) rate,
@@ -1227,17 +1203,17 @@ static void ResetRadio(struct strip *strip_info)
1227 * issued the ATS304 command last time through, so this time we restore 1203 * issued the ATS304 command last time through, so this time we restore
1228 * the user's selected rate and issue the normal starmode reset string. 1204 * the user's selected rate and issue the normal starmode reset string.
1229 */ 1205 */
1230 if (strip_info->user_baud == get_baud(tty)) { 1206 if (strip_info->user_baud == tty_get_baud_rate(tty)) {
1231 static const char b0[] = "ate0q1s304=57600\r"; 1207 static const char b0[] = "ate0q1s304=57600\r";
1232 static const char b1[] = "ate0q1s304=115200\r"; 1208 static const char b1[] = "ate0q1s304=115200\r";
1233 static const StringDescriptor baudstring[2] = 1209 static const StringDescriptor baudstring[2] =
1234 { {b0, sizeof(b0) - 1} 1210 { {b0, sizeof(b0) - 1}
1235 , {b1, sizeof(b1) - 1} 1211 , {b1, sizeof(b1) - 1}
1236 }; 1212 };
1237 set_baud(tty, B19200); 1213 set_baud(tty, 19200);
1238 if (strip_info->user_baud == B57600) 1214 if (strip_info->user_baud == 57600)
1239 s = baudstring[0]; 1215 s = baudstring[0];
1240 else if (strip_info->user_baud == B115200) 1216 else if (strip_info->user_baud == 115200)
1241 s = baudstring[1]; 1217 s = baudstring[1];
1242 else 1218 else
1243 s = baudstring[1]; /* For now */ 1219 s = baudstring[1]; /* For now */
@@ -1245,7 +1221,7 @@ static void ResetRadio(struct strip *strip_info)
1245 set_baud(tty, strip_info->user_baud); 1221 set_baud(tty, strip_info->user_baud);
1246 } 1222 }
1247 1223
1248 tty->driver->write(tty, s.string, s.length); 1224 tty->ops->write(tty, s.string, s.length);
1249#ifdef EXT_COUNTERS 1225#ifdef EXT_COUNTERS
1250 strip_info->tx_ebytes += s.length; 1226 strip_info->tx_ebytes += s.length;
1251#endif 1227#endif
@@ -1267,7 +1243,7 @@ static void strip_write_some_more(struct tty_struct *tty)
1267 1243
1268 if (strip_info->tx_left > 0) { 1244 if (strip_info->tx_left > 0) {
1269 int num_written = 1245 int num_written =
1270 tty->driver->write(tty, strip_info->tx_head, 1246 tty->ops->write(tty, strip_info->tx_head,
1271 strip_info->tx_left); 1247 strip_info->tx_left);
1272 strip_info->tx_left -= num_written; 1248 strip_info->tx_left -= num_written;
1273 strip_info->tx_head += num_written; 1249 strip_info->tx_head += num_written;
@@ -2457,7 +2433,7 @@ static int strip_open_low(struct net_device *dev)
2457 strip_info->working = FALSE; 2433 strip_info->working = FALSE;
2458 strip_info->firmware_level = NoStructure; 2434 strip_info->firmware_level = NoStructure;
2459 strip_info->next_command = CompatibilityCommand; 2435 strip_info->next_command = CompatibilityCommand;
2460 strip_info->user_baud = get_baud(strip_info->tty); 2436 strip_info->user_baud = tty_get_baud_rate(strip_info->tty);
2461 2437
2462 printk(KERN_INFO "%s: Initializing Radio.\n", 2438 printk(KERN_INFO "%s: Initializing Radio.\n",
2463 strip_info->dev->name); 2439 strip_info->dev->name);
@@ -2632,6 +2608,13 @@ static int strip_open(struct tty_struct *tty)
2632 return -EEXIST; 2608 return -EEXIST;
2633 2609
2634 /* 2610 /*
2611 * We need a write method.
2612 */
2613
2614 if (tty->ops->write == NULL)
2615 return -EOPNOTSUPP;
2616
2617 /*
2635 * OK. Find a free STRIP channel to use. 2618 * OK. Find a free STRIP channel to use.
2636 */ 2619 */
2637 if ((strip_info = strip_alloc()) == NULL) 2620 if ((strip_info = strip_alloc()) == NULL)
@@ -2652,8 +2635,7 @@ static int strip_open(struct tty_struct *tty)
2652 tty->disc_data = strip_info; 2635 tty->disc_data = strip_info;
2653 tty->receive_room = 65536; 2636 tty->receive_room = 65536;
2654 2637
2655 if (tty->driver->flush_buffer) 2638 tty_driver_flush_buffer(tty);
2656 tty->driver->flush_buffer(tty);
2657 2639
2658 /* 2640 /*
2659 * Restore default settings 2641 * Restore default settings
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index e62018a36133..8bddff150c70 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -1803,7 +1803,7 @@ static void __exit netif_exit(void)
1803 if (is_initial_xendomain()) 1803 if (is_initial_xendomain())
1804 return; 1804 return;
1805 1805
1806 return xenbus_unregister_driver(&netfront); 1806 xenbus_unregister_driver(&netfront);
1807} 1807}
1808module_exit(netif_exit); 1808module_exit(netif_exit);
1809 1809
diff --git a/drivers/parport/ieee1284.c b/drivers/parport/ieee1284.c
index 54a6ef72906e..0338b0912674 100644
--- a/drivers/parport/ieee1284.c
+++ b/drivers/parport/ieee1284.c
@@ -76,7 +76,7 @@ int parport_wait_event (struct parport *port, signed long timeout)
76 semaphore. */ 76 semaphore. */
77 return 1; 77 return 1;
78 78
79 init_timer (&timer); 79 init_timer_on_stack(&timer);
80 timer.expires = jiffies + timeout; 80 timer.expires = jiffies + timeout;
81 timer.function = timeout_waiting_on_port; 81 timer.function = timeout_waiting_on_port;
82 port_from_cookie[port->number % PARPORT_MAX] = port; 82 port_from_cookie[port->number % PARPORT_MAX] = port;
@@ -88,6 +88,8 @@ int parport_wait_event (struct parport *port, signed long timeout)
88 /* Timed out. */ 88 /* Timed out. */
89 ret = 1; 89 ret = 1;
90 90
91 destroy_timer_on_stack(&timer);
92
91 return ret; 93 return ret;
92} 94}
93 95
diff --git a/drivers/parport/parport_gsc.c b/drivers/parport/parport_gsc.c
index 0e77ae2b71a0..e6a7e847ee80 100644
--- a/drivers/parport/parport_gsc.c
+++ b/drivers/parport/parport_gsc.c
@@ -365,11 +365,11 @@ static int __devinit parport_init_chip(struct parisc_device *dev)
365 if (boot_cpu_data.cpu_type > pcxt && !pdc_add_valid(port+4)) { 365 if (boot_cpu_data.cpu_type > pcxt && !pdc_add_valid(port+4)) {
366 366
367 /* Initialize bidirectional-mode (0x10) & data-tranfer-mode #1 (0x20) */ 367 /* Initialize bidirectional-mode (0x10) & data-tranfer-mode #1 (0x20) */
368 printk("%s: initialize bidirectional-mode.\n", __FUNCTION__); 368 printk("%s: initialize bidirectional-mode.\n", __func__);
369 parport_writeb ( (0x10 + 0x20), port + 4); 369 parport_writeb ( (0x10 + 0x20), port + 4);
370 370
371 } else { 371 } else {
372 printk("%s: enhanced parport-modes not supported.\n", __FUNCTION__); 372 printk("%s: enhanced parport-modes not supported.\n", __func__);
373 } 373 }
374 374
375 p = parport_gsc_probe_port(port, 0, dev->irq, 375 p = parport_gsc_probe_port(port, 0, dev->irq,
diff --git a/drivers/parport/parport_pc.c b/drivers/parport/parport_pc.c
index e71092e80288..e0c2a4584ec6 100644
--- a/drivers/parport/parport_pc.c
+++ b/drivers/parport/parport_pc.c
@@ -1415,7 +1415,7 @@ static void __devinit winbond_check(int io, int key)
1415{ 1415{
1416 int devid,devrev,oldid,x_devid,x_devrev,x_oldid; 1416 int devid,devrev,oldid,x_devid,x_devrev,x_oldid;
1417 1417
1418 if (!request_region(io, 3, __FUNCTION__)) 1418 if (!request_region(io, 3, __func__))
1419 return; 1419 return;
1420 1420
1421 /* First probe without key */ 1421 /* First probe without key */
@@ -1449,7 +1449,7 @@ static void __devinit winbond_check2(int io,int key)
1449{ 1449{
1450 int devid,devrev,oldid,x_devid,x_devrev,x_oldid; 1450 int devid,devrev,oldid,x_devid,x_devrev,x_oldid;
1451 1451
1452 if (!request_region(io, 3, __FUNCTION__)) 1452 if (!request_region(io, 3, __func__))
1453 return; 1453 return;
1454 1454
1455 /* First probe without the key */ 1455 /* First probe without the key */
@@ -1482,7 +1482,7 @@ static void __devinit smsc_check(int io, int key)
1482{ 1482{
1483 int id,rev,oldid,oldrev,x_id,x_rev,x_oldid,x_oldrev; 1483 int id,rev,oldid,oldrev,x_id,x_rev,x_oldid,x_oldrev;
1484 1484
1485 if (!request_region(io, 3, __FUNCTION__)) 1485 if (!request_region(io, 3, __func__))
1486 return; 1486 return;
1487 1487
1488 /* First probe without the key */ 1488 /* First probe without the key */
@@ -1547,7 +1547,7 @@ static void __devinit detect_and_report_it87(void)
1547 u8 r; 1547 u8 r;
1548 if (verbose_probing) 1548 if (verbose_probing)
1549 printk(KERN_DEBUG "IT8705 Super-IO detection, now testing port 2E ...\n"); 1549 printk(KERN_DEBUG "IT8705 Super-IO detection, now testing port 2E ...\n");
1550 if (!request_region(0x2e, 1, __FUNCTION__)) 1550 if (!request_region(0x2e, 1, __func__))
1551 return; 1551 return;
1552 outb(0x87, 0x2e); 1552 outb(0x87, 0x2e);
1553 outb(0x01, 0x2e); 1553 outb(0x01, 0x2e);
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 4a55bf380957..3706ce7972dd 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -842,13 +842,25 @@ static void set_pcie_port_type(struct pci_dev *pdev)
842 * reading the dword at 0x100 which must either be 0 or a valid extended 842 * reading the dword at 0x100 which must either be 0 or a valid extended
843 * capability header. 843 * capability header.
844 */ 844 */
845int pci_cfg_space_size_ext(struct pci_dev *dev, unsigned check_exp_pcix) 845int pci_cfg_space_size_ext(struct pci_dev *dev)
846{ 846{
847 int pos;
848 u32 status; 847 u32 status;
849 848
850 if (!check_exp_pcix) 849 if (pci_read_config_dword(dev, 256, &status) != PCIBIOS_SUCCESSFUL)
851 goto skip; 850 goto fail;
851 if (status == 0xffffffff)
852 goto fail;
853
854 return PCI_CFG_SPACE_EXP_SIZE;
855
856 fail:
857 return PCI_CFG_SPACE_SIZE;
858}
859
860int pci_cfg_space_size(struct pci_dev *dev)
861{
862 int pos;
863 u32 status;
852 864
853 pos = pci_find_capability(dev, PCI_CAP_ID_EXP); 865 pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
854 if (!pos) { 866 if (!pos) {
@@ -861,23 +873,12 @@ int pci_cfg_space_size_ext(struct pci_dev *dev, unsigned check_exp_pcix)
861 goto fail; 873 goto fail;
862 } 874 }
863 875
864 skip: 876 return pci_cfg_space_size_ext(dev);
865 if (pci_read_config_dword(dev, 256, &status) != PCIBIOS_SUCCESSFUL)
866 goto fail;
867 if (status == 0xffffffff)
868 goto fail;
869
870 return PCI_CFG_SPACE_EXP_SIZE;
871 877
872 fail: 878 fail:
873 return PCI_CFG_SPACE_SIZE; 879 return PCI_CFG_SPACE_SIZE;
874} 880}
875 881
876int pci_cfg_space_size(struct pci_dev *dev)
877{
878 return pci_cfg_space_size_ext(dev, 1);
879}
880
881static void pci_release_bus_bridge_dev(struct device *dev) 882static void pci_release_bus_bridge_dev(struct device *dev)
882{ 883{
883 kfree(dev); 884 kfree(dev);
diff --git a/drivers/pcmcia/au1000_db1x00.c b/drivers/pcmcia/au1000_db1x00.c
index 74e051535d6c..c78d77fd7e3b 100644
--- a/drivers/pcmcia/au1000_db1x00.c
+++ b/drivers/pcmcia/au1000_db1x00.c
@@ -194,7 +194,7 @@ db1x00_pcmcia_configure_socket(struct au1000_pcmcia_socket *skt, struct socket_s
194 default: 194 default:
195 pwr |= SET_VCC_VPP(0,0,sock); 195 pwr |= SET_VCC_VPP(0,0,sock);
196 printk("%s: bad Vcc/Vpp (%d:%d)\n", 196 printk("%s: bad Vcc/Vpp (%d:%d)\n",
197 __FUNCTION__, 197 __func__,
198 state->Vcc, 198 state->Vcc,
199 state->Vpp); 199 state->Vpp);
200 break; 200 break;
@@ -215,7 +215,7 @@ db1x00_pcmcia_configure_socket(struct au1000_pcmcia_socket *skt, struct socket_s
215 default: 215 default:
216 pwr |= SET_VCC_VPP(0,0,sock); 216 pwr |= SET_VCC_VPP(0,0,sock);
217 printk("%s: bad Vcc/Vpp (%d:%d)\n", 217 printk("%s: bad Vcc/Vpp (%d:%d)\n",
218 __FUNCTION__, 218 __func__,
219 state->Vcc, 219 state->Vcc,
220 state->Vpp); 220 state->Vpp);
221 break; 221 break;
@@ -224,7 +224,7 @@ db1x00_pcmcia_configure_socket(struct au1000_pcmcia_socket *skt, struct socket_s
224 default: /* what's this ? */ 224 default: /* what's this ? */
225 pwr |= SET_VCC_VPP(0,0,sock); 225 pwr |= SET_VCC_VPP(0,0,sock);
226 printk(KERN_ERR "%s: bad Vcc %d\n", 226 printk(KERN_ERR "%s: bad Vcc %d\n",
227 __FUNCTION__, state->Vcc); 227 __func__, state->Vcc);
228 break; 228 break;
229 } 229 }
230 230
diff --git a/drivers/pcmcia/au1000_generic.c b/drivers/pcmcia/au1000_generic.c
index b693367d38cd..75e8f8505e47 100644
--- a/drivers/pcmcia/au1000_generic.c
+++ b/drivers/pcmcia/au1000_generic.c
@@ -41,6 +41,7 @@
41#include <linux/notifier.h> 41#include <linux/notifier.h>
42#include <linux/interrupt.h> 42#include <linux/interrupt.h>
43#include <linux/spinlock.h> 43#include <linux/spinlock.h>
44#include <linux/mutex.h>
44#include <linux/platform_device.h> 45#include <linux/platform_device.h>
45 46
46#include <asm/io.h> 47#include <asm/io.h>
@@ -71,7 +72,7 @@ extern struct au1000_pcmcia_socket au1000_pcmcia_socket[];
71u32 *pcmcia_base_vaddrs[2]; 72u32 *pcmcia_base_vaddrs[2];
72extern const unsigned long mips_io_port_base; 73extern const unsigned long mips_io_port_base;
73 74
74DECLARE_MUTEX(pcmcia_sockets_lock); 75static DEFINE_MUTEX(pcmcia_sockets_lock);
75 76
76static int (*au1x00_pcmcia_hw_init[])(struct device *dev) = { 77static int (*au1x00_pcmcia_hw_init[])(struct device *dev) = {
77 au1x_board_init, 78 au1x_board_init,
@@ -472,7 +473,7 @@ int au1x00_drv_pcmcia_remove(struct device *dev)
472 struct skt_dev_info *sinfo = dev_get_drvdata(dev); 473 struct skt_dev_info *sinfo = dev_get_drvdata(dev);
473 int i; 474 int i;
474 475
475 down(&pcmcia_sockets_lock); 476 mutex_lock(&pcmcia_sockets_lock);
476 dev_set_drvdata(dev, NULL); 477 dev_set_drvdata(dev, NULL);
477 478
478 for (i = 0; i < sinfo->nskt; i++) { 479 for (i = 0; i < sinfo->nskt; i++) {
@@ -488,7 +489,7 @@ int au1x00_drv_pcmcia_remove(struct device *dev)
488 } 489 }
489 490
490 kfree(sinfo); 491 kfree(sinfo);
491 up(&pcmcia_sockets_lock); 492 mutex_unlock(&pcmcia_sockets_lock);
492 return 0; 493 return 0;
493} 494}
494 495
@@ -501,13 +502,13 @@ static int au1x00_drv_pcmcia_probe(struct device *dev)
501{ 502{
502 int i, ret = -ENODEV; 503 int i, ret = -ENODEV;
503 504
504 down(&pcmcia_sockets_lock); 505 mutex_lock(&pcmcia_sockets_lock);
505 for (i=0; i < ARRAY_SIZE(au1x00_pcmcia_hw_init); i++) { 506 for (i=0; i < ARRAY_SIZE(au1x00_pcmcia_hw_init); i++) {
506 ret = au1x00_pcmcia_hw_init[i](dev); 507 ret = au1x00_pcmcia_hw_init[i](dev);
507 if (ret == 0) 508 if (ret == 0)
508 break; 509 break;
509 } 510 }
510 up(&pcmcia_sockets_lock); 511 mutex_unlock(&pcmcia_sockets_lock);
511 return ret; 512 return ret;
512} 513}
513 514
diff --git a/drivers/pcmcia/au1000_pb1x00.c b/drivers/pcmcia/au1000_pb1x00.c
index 86c0808d6a05..157e41423a0a 100644
--- a/drivers/pcmcia/au1000_pb1x00.c
+++ b/drivers/pcmcia/au1000_pb1x00.c
@@ -244,7 +244,7 @@ pb1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure)
244 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ, 244 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
245 configure->sock); 245 configure->sock);
246 printk("%s: bad Vcc/Vpp (%d:%d)\n", 246 printk("%s: bad Vcc/Vpp (%d:%d)\n",
247 __FUNCTION__, 247 __func__,
248 configure->vcc, 248 configure->vcc,
249 configure->vpp); 249 configure->vpp);
250 break; 250 break;
@@ -272,7 +272,7 @@ pb1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure)
272 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ, 272 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
273 configure->sock); 273 configure->sock);
274 printk("%s: bad Vcc/Vpp (%d:%d)\n", 274 printk("%s: bad Vcc/Vpp (%d:%d)\n",
275 __FUNCTION__, 275 __func__,
276 configure->vcc, 276 configure->vcc,
277 configure->vpp); 277 configure->vpp);
278 break; 278 break;
@@ -300,7 +300,7 @@ pb1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure)
300 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ, 300 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
301 configure->sock); 301 configure->sock);
302 printk("%s: bad Vcc/Vpp (%d:%d)\n", 302 printk("%s: bad Vcc/Vpp (%d:%d)\n",
303 __FUNCTION__, 303 __func__,
304 configure->vcc, 304 configure->vcc,
305 configure->vpp); 305 configure->vpp);
306 break; 306 break;
@@ -309,7 +309,7 @@ pb1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure)
309 default: /* what's this ? */ 309 default: /* what's this ? */
310 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,configure->sock); 310 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,configure->sock);
311 printk(KERN_ERR "%s: bad Vcc %d\n", 311 printk(KERN_ERR "%s: bad Vcc %d\n",
312 __FUNCTION__, configure->vcc); 312 __func__, configure->vcc);
313 break; 313 break;
314 } 314 }
315 315
@@ -353,7 +353,7 @@ pb1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure)
353 default: 353 default:
354 pcr |= SET_VCC_VPP(0,0); 354 pcr |= SET_VCC_VPP(0,0);
355 printk("%s: bad Vcc/Vpp (%d:%d)\n", 355 printk("%s: bad Vcc/Vpp (%d:%d)\n",
356 __FUNCTION__, 356 __func__,
357 configure->vcc, 357 configure->vcc,
358 configure->vpp); 358 configure->vpp);
359 break; 359 break;
@@ -374,7 +374,7 @@ pb1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure)
374 default: 374 default:
375 pcr |= SET_VCC_VPP(0,0); 375 pcr |= SET_VCC_VPP(0,0);
376 printk("%s: bad Vcc/Vpp (%d:%d)\n", 376 printk("%s: bad Vcc/Vpp (%d:%d)\n",
377 __FUNCTION__, 377 __func__,
378 configure->vcc, 378 configure->vcc,
379 configure->vpp); 379 configure->vpp);
380 break; 380 break;
@@ -383,7 +383,7 @@ pb1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure)
383 default: /* what's this ? */ 383 default: /* what's this ? */
384 pcr |= SET_VCC_VPP(0,0); 384 pcr |= SET_VCC_VPP(0,0);
385 printk(KERN_ERR "%s: bad Vcc %d\n", 385 printk(KERN_ERR "%s: bad Vcc %d\n",
386 __FUNCTION__, configure->vcc); 386 __func__, configure->vcc);
387 break; 387 break;
388 } 388 }
389 389
diff --git a/drivers/pcmcia/au1000_xxs1500.c b/drivers/pcmcia/au1000_xxs1500.c
index ce9d5c44a7b5..c78ed5347510 100644
--- a/drivers/pcmcia/au1000_xxs1500.c
+++ b/drivers/pcmcia/au1000_xxs1500.c
@@ -56,7 +56,7 @@
56#define PCMCIA_IRQ AU1000_GPIO_4 56#define PCMCIA_IRQ AU1000_GPIO_4
57 57
58#if 0 58#if 0
59#define DEBUG(x,args...) printk(__FUNCTION__ ": " x,##args) 59#define DEBUG(x, args...) printk(__func__ ": " x, ##args)
60#else 60#else
61#define DEBUG(x,args...) 61#define DEBUG(x,args...)
62#endif 62#endif
diff --git a/drivers/pcmcia/cardbus.c b/drivers/pcmcia/cardbus.c
index 714baaeb6da1..fb2f38dc92c5 100644
--- a/drivers/pcmcia/cardbus.c
+++ b/drivers/pcmcia/cardbus.c
@@ -209,7 +209,7 @@ static void cardbus_assign_irqs(struct pci_bus *bus, int irq)
209 } 209 }
210} 210}
211 211
212int cb_alloc(struct pcmcia_socket * s) 212int __ref cb_alloc(struct pcmcia_socket * s)
213{ 213{
214 struct pci_bus *bus = s->cb_dev->subordinate; 214 struct pci_bus *bus = s->cb_dev->subordinate;
215 struct pci_dev *dev; 215 struct pci_dev *dev;
diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c
index 56230dbd347a..29276bd28295 100644
--- a/drivers/pcmcia/cs.c
+++ b/drivers/pcmcia/cs.c
@@ -652,6 +652,9 @@ static int pccardd(void *__skt)
652 complete(&skt->thread_done); 652 complete(&skt->thread_done);
653 return 0; 653 return 0;
654 } 654 }
655 ret = pccard_sysfs_add_socket(&skt->dev);
656 if (ret)
657 dev_warn(&skt->dev, "err %d adding socket attributes\n", ret);
655 658
656 add_wait_queue(&skt->thread_wait, &wait); 659 add_wait_queue(&skt->thread_wait, &wait);
657 complete(&skt->thread_done); 660 complete(&skt->thread_done);
@@ -694,6 +697,7 @@ static int pccardd(void *__skt)
694 remove_wait_queue(&skt->thread_wait, &wait); 697 remove_wait_queue(&skt->thread_wait, &wait);
695 698
696 /* remove from the device core */ 699 /* remove from the device core */
700 pccard_sysfs_remove_socket(&skt->dev);
697 device_unregister(&skt->dev); 701 device_unregister(&skt->dev);
698 702
699 return 0; 703 return 0;
@@ -940,20 +944,13 @@ EXPORT_SYMBOL(pcmcia_socket_class);
940 944
941static int __init init_pcmcia_cs(void) 945static int __init init_pcmcia_cs(void)
942{ 946{
943 int ret;
944
945 init_completion(&pcmcia_unload); 947 init_completion(&pcmcia_unload);
946 ret = class_register(&pcmcia_socket_class); 948 return class_register(&pcmcia_socket_class);
947 if (ret)
948 return (ret);
949 return class_interface_register(&pccard_sysfs_interface);
950} 949}
951 950
952static void __exit exit_pcmcia_cs(void) 951static void __exit exit_pcmcia_cs(void)
953{ 952{
954 class_interface_unregister(&pccard_sysfs_interface);
955 class_unregister(&pcmcia_socket_class); 953 class_unregister(&pcmcia_socket_class);
956
957 wait_for_completion(&pcmcia_unload); 954 wait_for_completion(&pcmcia_unload);
958} 955}
959 956
diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h
index 9fa207e3c7b3..e7d5d141f24d 100644
--- a/drivers/pcmcia/cs_internal.h
+++ b/drivers/pcmcia/cs_internal.h
@@ -121,7 +121,8 @@ struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align,
121void release_resource_db(struct pcmcia_socket *s); 121void release_resource_db(struct pcmcia_socket *s);
122 122
123/* In socket_sysfs.c */ 123/* In socket_sysfs.c */
124extern struct class_interface pccard_sysfs_interface; 124extern int pccard_sysfs_add_socket(struct device *dev);
125extern void pccard_sysfs_remove_socket(struct device *dev);
125 126
126/* In cs.c */ 127/* In cs.c */
127extern struct rw_semaphore pcmcia_socket_list_rwsem; 128extern struct rw_semaphore pcmcia_socket_list_rwsem;
diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c
index 5a85871f5ee9..e40775443d04 100644
--- a/drivers/pcmcia/ds.c
+++ b/drivers/pcmcia/ds.c
@@ -1520,7 +1520,7 @@ static void pcmcia_bus_remove_socket(struct device *dev,
1520 1520
1521 1521
1522/* the pcmcia_bus_interface is used to handle pcmcia socket devices */ 1522/* the pcmcia_bus_interface is used to handle pcmcia socket devices */
1523static struct class_interface pcmcia_bus_interface = { 1523static struct class_interface pcmcia_bus_interface __refdata = {
1524 .class = &pcmcia_socket_class, 1524 .class = &pcmcia_socket_class,
1525 .add_dev = &pcmcia_bus_add_socket, 1525 .add_dev = &pcmcia_bus_add_socket,
1526 .remove_dev = &pcmcia_bus_remove_socket, 1526 .remove_dev = &pcmcia_bus_remove_socket,
diff --git a/drivers/pcmcia/i82092.c b/drivers/pcmcia/i82092.c
index e54ecc580d9e..e13618656ff7 100644
--- a/drivers/pcmcia/i82092.c
+++ b/drivers/pcmcia/i82092.c
@@ -53,7 +53,7 @@ static int i82092aa_socket_resume (struct pci_dev *dev)
53} 53}
54#endif 54#endif
55 55
56static struct pci_driver i82092aa_pci_drv = { 56static struct pci_driver i82092aa_pci_driver = {
57 .name = "i82092aa", 57 .name = "i82092aa",
58 .id_table = i82092aa_pci_ids, 58 .id_table = i82092aa_pci_ids,
59 .probe = i82092aa_pci_probe, 59 .probe = i82092aa_pci_probe,
@@ -714,13 +714,13 @@ static int i82092aa_set_mem_map(struct pcmcia_socket *socket, struct pccard_mem_
714 714
715static int i82092aa_module_init(void) 715static int i82092aa_module_init(void)
716{ 716{
717 return pci_register_driver(&i82092aa_pci_drv); 717 return pci_register_driver(&i82092aa_pci_driver);
718} 718}
719 719
720static void i82092aa_module_exit(void) 720static void i82092aa_module_exit(void)
721{ 721{
722 enter("i82092aa_module_exit"); 722 enter("i82092aa_module_exit");
723 pci_unregister_driver(&i82092aa_pci_drv); 723 pci_unregister_driver(&i82092aa_pci_driver);
724 if (sockets[0].io_base>0) 724 if (sockets[0].io_base>0)
725 release_region(sockets[0].io_base, 2); 725 release_region(sockets[0].io_base, 2);
726 leave("i82092aa_module_exit"); 726 leave("i82092aa_module_exit");
diff --git a/drivers/pcmcia/omap_cf.c b/drivers/pcmcia/omap_cf.c
index bb6db3a582b2..46314b420765 100644
--- a/drivers/pcmcia/omap_cf.c
+++ b/drivers/pcmcia/omap_cf.c
@@ -153,7 +153,7 @@ omap_cf_set_socket(struct pcmcia_socket *sock, struct socket_state_t *s)
153 153
154static int omap_cf_ss_suspend(struct pcmcia_socket *s) 154static int omap_cf_ss_suspend(struct pcmcia_socket *s)
155{ 155{
156 pr_debug("%s: %s\n", driver_name, __FUNCTION__); 156 pr_debug("%s: %s\n", driver_name, __func__);
157 return omap_cf_set_socket(s, &dead_socket); 157 return omap_cf_set_socket(s, &dead_socket);
158} 158}
159 159
diff --git a/drivers/pcmcia/pd6729.c b/drivers/pcmcia/pd6729.c
index abc10fe49bd8..8bed1dab9039 100644
--- a/drivers/pcmcia/pd6729.c
+++ b/drivers/pcmcia/pd6729.c
@@ -778,7 +778,7 @@ static struct pci_device_id pd6729_pci_ids[] = {
778}; 778};
779MODULE_DEVICE_TABLE(pci, pd6729_pci_ids); 779MODULE_DEVICE_TABLE(pci, pd6729_pci_ids);
780 780
781static struct pci_driver pd6729_pci_drv = { 781static struct pci_driver pd6729_pci_driver = {
782 .name = "pd6729", 782 .name = "pd6729",
783 .id_table = pd6729_pci_ids, 783 .id_table = pd6729_pci_ids,
784 .probe = pd6729_pci_probe, 784 .probe = pd6729_pci_probe,
@@ -791,12 +791,12 @@ static struct pci_driver pd6729_pci_drv = {
791 791
792static int pd6729_module_init(void) 792static int pd6729_module_init(void)
793{ 793{
794 return pci_register_driver(&pd6729_pci_drv); 794 return pci_register_driver(&pd6729_pci_driver);
795} 795}
796 796
797static void pd6729_module_exit(void) 797static void pd6729_module_exit(void)
798{ 798{
799 pci_unregister_driver(&pd6729_pci_drv); 799 pci_unregister_driver(&pd6729_pci_driver);
800} 800}
801 801
802module_init(pd6729_module_init); 802module_init(pd6729_module_init);
diff --git a/drivers/pcmcia/pxa2xx_lubbock.c b/drivers/pcmcia/pxa2xx_lubbock.c
index 4a05802213c8..881ec8a8e389 100644
--- a/drivers/pcmcia/pxa2xx_lubbock.c
+++ b/drivers/pcmcia/pxa2xx_lubbock.c
@@ -87,7 +87,7 @@ lubbock_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
87 87
88 default: 88 default:
89 printk(KERN_ERR "%s(): unrecognized Vcc %u\n", 89 printk(KERN_ERR "%s(): unrecognized Vcc %u\n",
90 __FUNCTION__, state->Vcc); 90 __func__, state->Vcc);
91 ret = -1; 91 ret = -1;
92 } 92 }
93 93
@@ -104,7 +104,7 @@ lubbock_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
104 pa_dwr_set |= GPIO_A0; 104 pa_dwr_set |= GPIO_A0;
105 else { 105 else {
106 printk(KERN_ERR "%s(): unrecognized Vpp %u\n", 106 printk(KERN_ERR "%s(): unrecognized Vpp %u\n",
107 __FUNCTION__, state->Vpp); 107 __func__, state->Vpp);
108 ret = -1; 108 ret = -1;
109 break; 109 break;
110 } 110 }
@@ -128,14 +128,14 @@ lubbock_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
128 128
129 default: 129 default:
130 printk(KERN_ERR "%s(): unrecognized Vcc %u\n", 130 printk(KERN_ERR "%s(): unrecognized Vcc %u\n",
131 __FUNCTION__, state->Vcc); 131 __func__, state->Vcc);
132 ret = -1; 132 ret = -1;
133 break; 133 break;
134 } 134 }
135 135
136 if (state->Vpp != state->Vcc && state->Vpp != 0) { 136 if (state->Vpp != state->Vcc && state->Vpp != 0) {
137 printk(KERN_ERR "%s(): CF slot cannot support Vpp %u\n", 137 printk(KERN_ERR "%s(): CF slot cannot support Vpp %u\n",
138 __FUNCTION__, state->Vpp); 138 __func__, state->Vpp);
139 ret = -1; 139 ret = -1;
140 break; 140 break;
141 } 141 }
diff --git a/drivers/pcmcia/pxa2xx_mainstone.c b/drivers/pcmcia/pxa2xx_mainstone.c
index 6fa5eaaab8af..145b85e0f02c 100644
--- a/drivers/pcmcia/pxa2xx_mainstone.c
+++ b/drivers/pcmcia/pxa2xx_mainstone.c
@@ -99,7 +99,7 @@ static int mst_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
99 case 50: power |= MST_PCMCIA_PWR_VCC_50; break; 99 case 50: power |= MST_PCMCIA_PWR_VCC_50; break;
100 default: 100 default:
101 printk(KERN_ERR "%s(): bad Vcc %u\n", 101 printk(KERN_ERR "%s(): bad Vcc %u\n",
102 __FUNCTION__, state->Vcc); 102 __func__, state->Vcc);
103 ret = -1; 103 ret = -1;
104 } 104 }
105 105
@@ -111,7 +111,7 @@ static int mst_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
111 power |= MST_PCMCIA_PWR_VPP_VCC; 111 power |= MST_PCMCIA_PWR_VPP_VCC;
112 } else { 112 } else {
113 printk(KERN_ERR "%s(): bad Vpp %u\n", 113 printk(KERN_ERR "%s(): bad Vpp %u\n",
114 __FUNCTION__, state->Vpp); 114 __func__, state->Vpp);
115 ret = -1; 115 ret = -1;
116 } 116 }
117 } 117 }
diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c
index a8d100707721..0fcf763b9175 100644
--- a/drivers/pcmcia/rsrc_nonstatic.c
+++ b/drivers/pcmcia/rsrc_nonstatic.c
@@ -1045,7 +1045,7 @@ static void __devexit pccard_sysfs_remove_rsrc(struct device *dev,
1045 device_remove_file(dev, *attr); 1045 device_remove_file(dev, *attr);
1046} 1046}
1047 1047
1048static struct class_interface pccard_rsrc_interface = { 1048static struct class_interface pccard_rsrc_interface __refdata = {
1049 .class = &pcmcia_socket_class, 1049 .class = &pcmcia_socket_class,
1050 .add_dev = &pccard_sysfs_add_rsrc, 1050 .add_dev = &pccard_sysfs_add_rsrc,
1051 .remove_dev = __devexit_p(&pccard_sysfs_remove_rsrc), 1051 .remove_dev = __devexit_p(&pccard_sysfs_remove_rsrc),
diff --git a/drivers/pcmcia/sa1100_assabet.c b/drivers/pcmcia/sa1100_assabet.c
index 7c57fdd3c8d7..ce133ce81c10 100644
--- a/drivers/pcmcia/sa1100_assabet.c
+++ b/drivers/pcmcia/sa1100_assabet.c
@@ -66,14 +66,14 @@ assabet_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_stat
66 66
67 case 50: 67 case 50:
68 printk(KERN_WARNING "%s(): CS asked for 5V, applying 3.3V...\n", 68 printk(KERN_WARNING "%s(): CS asked for 5V, applying 3.3V...\n",
69 __FUNCTION__); 69 __func__);
70 70
71 case 33: /* Can only apply 3.3V to the CF slot. */ 71 case 33: /* Can only apply 3.3V to the CF slot. */
72 mask = ASSABET_BCR_CF_PWR; 72 mask = ASSABET_BCR_CF_PWR;
73 break; 73 break;
74 74
75 default: 75 default:
76 printk(KERN_ERR "%s(): unrecognized Vcc %u\n", __FUNCTION__, 76 printk(KERN_ERR "%s(): unrecognized Vcc %u\n", __func__,
77 state->Vcc); 77 state->Vcc);
78 return -1; 78 return -1;
79 } 79 }
diff --git a/drivers/pcmcia/sa1100_badge4.c b/drivers/pcmcia/sa1100_badge4.c
index 62bfc7566ec2..607c3f326eca 100644
--- a/drivers/pcmcia/sa1100_badge4.c
+++ b/drivers/pcmcia/sa1100_badge4.c
@@ -82,14 +82,14 @@ badge4_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state
82 case 0: 82 case 0:
83 if ((state->Vcc != 0) && 83 if ((state->Vcc != 0) &&
84 (state->Vcc != badge4_pcmvcc)) { 84 (state->Vcc != badge4_pcmvcc)) {
85 complain_about_jumpering(__FUNCTION__, "pcmvcc", 85 complain_about_jumpering(__func__, "pcmvcc",
86 badge4_pcmvcc, state->Vcc); 86 badge4_pcmvcc, state->Vcc);
87 // Apply power regardless of the jumpering. 87 // Apply power regardless of the jumpering.
88 // return -1; 88 // return -1;
89 } 89 }
90 if ((state->Vpp != 0) && 90 if ((state->Vpp != 0) &&
91 (state->Vpp != badge4_pcmvpp)) { 91 (state->Vpp != badge4_pcmvpp)) {
92 complain_about_jumpering(__FUNCTION__, "pcmvpp", 92 complain_about_jumpering(__func__, "pcmvpp",
93 badge4_pcmvpp, state->Vpp); 93 badge4_pcmvpp, state->Vpp);
94 return -1; 94 return -1;
95 } 95 }
@@ -98,7 +98,7 @@ badge4_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state
98 case 1: 98 case 1:
99 if ((state->Vcc != 0) && 99 if ((state->Vcc != 0) &&
100 (state->Vcc != badge4_cfvcc)) { 100 (state->Vcc != badge4_cfvcc)) {
101 complain_about_jumpering(__FUNCTION__, "cfvcc", 101 complain_about_jumpering(__func__, "cfvcc",
102 badge4_cfvcc, state->Vcc); 102 badge4_cfvcc, state->Vcc);
103 return -1; 103 return -1;
104 } 104 }
@@ -143,7 +143,7 @@ int pcmcia_badge4_init(struct device *dev)
143 if (machine_is_badge4()) { 143 if (machine_is_badge4()) {
144 printk(KERN_INFO 144 printk(KERN_INFO
145 "%s: badge4_pcmvcc=%d, badge4_pcmvpp=%d, badge4_cfvcc=%d\n", 145 "%s: badge4_pcmvcc=%d, badge4_pcmvpp=%d, badge4_cfvcc=%d\n",
146 __FUNCTION__, 146 __func__,
147 badge4_pcmvcc, badge4_pcmvpp, badge4_cfvcc); 147 badge4_pcmvcc, badge4_pcmvpp, badge4_cfvcc);
148 148
149 ret = sa11xx_drv_pcmcia_probe(dev, &badge4_pcmcia_ops, 0, 2); 149 ret = sa11xx_drv_pcmcia_probe(dev, &badge4_pcmcia_ops, 0, 2);
diff --git a/drivers/pcmcia/sa1100_cerf.c b/drivers/pcmcia/sa1100_cerf.c
index 549a1529fe35..7c3951a2675d 100644
--- a/drivers/pcmcia/sa1100_cerf.c
+++ b/drivers/pcmcia/sa1100_cerf.c
@@ -63,7 +63,7 @@ cerf_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
63 63
64 default: 64 default:
65 printk(KERN_ERR "%s(): unrecognized Vcc %u\n", 65 printk(KERN_ERR "%s(): unrecognized Vcc %u\n",
66 __FUNCTION__, state->Vcc); 66 __func__, state->Vcc);
67 return -1; 67 return -1;
68 } 68 }
69 69
diff --git a/drivers/pcmcia/sa1100_jornada720.c b/drivers/pcmcia/sa1100_jornada720.c
index 6284c35dabc6..2167e6714d2d 100644
--- a/drivers/pcmcia/sa1100_jornada720.c
+++ b/drivers/pcmcia/sa1100_jornada720.c
@@ -42,7 +42,7 @@ jornada720_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_s
42 unsigned int pa_dwr_mask, pa_dwr_set; 42 unsigned int pa_dwr_mask, pa_dwr_set;
43 int ret; 43 int ret;
44 44
45printk("%s(): config socket %d vcc %d vpp %d\n", __FUNCTION__, 45printk("%s(): config socket %d vcc %d vpp %d\n", __func__,
46 skt->nr, state->Vcc, state->Vpp); 46 skt->nr, state->Vcc, state->Vpp);
47 47
48 switch (skt->nr) { 48 switch (skt->nr) {
@@ -74,7 +74,7 @@ printk("%s(): config socket %d vcc %d vpp %d\n", __FUNCTION__,
74 74
75 if (state->Vpp != state->Vcc && state->Vpp != 0) { 75 if (state->Vpp != state->Vcc && state->Vpp != 0) {
76 printk(KERN_ERR "%s(): slot cannot support VPP %u\n", 76 printk(KERN_ERR "%s(): slot cannot support VPP %u\n",
77 __FUNCTION__, state->Vpp); 77 __func__, state->Vpp);
78 return -1; 78 return -1;
79 } 79 }
80 80
diff --git a/drivers/pcmcia/sa1100_neponset.c b/drivers/pcmcia/sa1100_neponset.c
index 5bc9e9532b9d..687492fcd5b4 100644
--- a/drivers/pcmcia/sa1100_neponset.c
+++ b/drivers/pcmcia/sa1100_neponset.c
@@ -59,7 +59,7 @@ neponset_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_sta
59 ncr_set = NCR_A0VPP; 59 ncr_set = NCR_A0VPP;
60 else { 60 else {
61 printk(KERN_ERR "%s(): unrecognized VPP %u\n", 61 printk(KERN_ERR "%s(): unrecognized VPP %u\n",
62 __FUNCTION__, state->Vpp); 62 __func__, state->Vpp);
63 return -1; 63 return -1;
64 } 64 }
65 break; 65 break;
@@ -71,7 +71,7 @@ neponset_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_sta
71 71
72 if (state->Vpp != state->Vcc && state->Vpp != 0) { 72 if (state->Vpp != state->Vcc && state->Vpp != 0) {
73 printk(KERN_ERR "%s(): CF slot cannot support VPP %u\n", 73 printk(KERN_ERR "%s(): CF slot cannot support VPP %u\n",
74 __FUNCTION__, state->Vpp); 74 __func__, state->Vpp);
75 return -1; 75 return -1;
76 } 76 }
77 break; 77 break;
diff --git a/drivers/pcmcia/sa1100_shannon.c b/drivers/pcmcia/sa1100_shannon.c
index 9456f5478d09..494912fccc0d 100644
--- a/drivers/pcmcia/sa1100_shannon.c
+++ b/drivers/pcmcia/sa1100_shannon.c
@@ -73,19 +73,19 @@ shannon_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
73{ 73{
74 switch (state->Vcc) { 74 switch (state->Vcc) {
75 case 0: /* power off */ 75 case 0: /* power off */
76 printk(KERN_WARNING "%s(): CS asked for 0V, still applying 3.3V..\n", __FUNCTION__); 76 printk(KERN_WARNING "%s(): CS asked for 0V, still applying 3.3V..\n", __func__);
77 break; 77 break;
78 case 50: 78 case 50:
79 printk(KERN_WARNING "%s(): CS asked for 5V, applying 3.3V..\n", __FUNCTION__); 79 printk(KERN_WARNING "%s(): CS asked for 5V, applying 3.3V..\n", __func__);
80 case 33: 80 case 33:
81 break; 81 break;
82 default: 82 default:
83 printk(KERN_ERR "%s(): unrecognized Vcc %u\n", 83 printk(KERN_ERR "%s(): unrecognized Vcc %u\n",
84 __FUNCTION__, state->Vcc); 84 __func__, state->Vcc);
85 return -1; 85 return -1;
86 } 86 }
87 87
88 printk(KERN_WARNING "%s(): Warning, Can't perform reset\n", __FUNCTION__); 88 printk(KERN_WARNING "%s(): Warning, Can't perform reset\n", __func__);
89 89
90 /* Silently ignore Vpp, output enable, speaker enable. */ 90 /* Silently ignore Vpp, output enable, speaker enable. */
91 91
diff --git a/drivers/pcmcia/sa1100_simpad.c b/drivers/pcmcia/sa1100_simpad.c
index 04d6f7f75f78..42567de894b9 100644
--- a/drivers/pcmcia/sa1100_simpad.c
+++ b/drivers/pcmcia/sa1100_simpad.c
@@ -90,7 +90,7 @@ simpad_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
90 90
91 default: 91 default:
92 printk(KERN_ERR "%s(): unrecognized Vcc %u\n", 92 printk(KERN_ERR "%s(): unrecognized Vcc %u\n",
93 __FUNCTION__, state->Vcc); 93 __func__, state->Vcc);
94 clear_cs3_bit(VCC_3V_EN|VCC_5V_EN|EN0|EN1); 94 clear_cs3_bit(VCC_3V_EN|VCC_5V_EN|EN0|EN1);
95 local_irq_restore(flags); 95 local_irq_restore(flags);
96 return -1; 96 return -1;
diff --git a/drivers/pcmcia/soc_common.c b/drivers/pcmcia/soc_common.c
index aa7779d89752..420a77540f41 100644
--- a/drivers/pcmcia/soc_common.c
+++ b/drivers/pcmcia/soc_common.c
@@ -37,6 +37,7 @@
37#include <linux/kernel.h> 37#include <linux/kernel.h>
38#include <linux/timer.h> 38#include <linux/timer.h>
39#include <linux/mm.h> 39#include <linux/mm.h>
40#include <linux/mutex.h>
40#include <linux/interrupt.h> 41#include <linux/interrupt.h>
41#include <linux/irq.h> 42#include <linux/irq.h>
42#include <linux/spinlock.h> 43#include <linux/spinlock.h>
@@ -353,7 +354,7 @@ soc_common_pcmcia_set_io_map(struct pcmcia_socket *sock, struct pccard_io_map *m
353 (map->flags&MAP_PREFETCH)?"PREFETCH ":""); 354 (map->flags&MAP_PREFETCH)?"PREFETCH ":"");
354 355
355 if (map->map >= MAX_IO_WIN) { 356 if (map->map >= MAX_IO_WIN) {
356 printk(KERN_ERR "%s(): map (%d) out of range\n", __FUNCTION__, 357 printk(KERN_ERR "%s(): map (%d) out of range\n", __func__,
357 map->map); 358 map->map);
358 return -1; 359 return -1;
359 } 360 }
@@ -578,7 +579,7 @@ EXPORT_SYMBOL(soc_pcmcia_enable_irqs);
578 579
579 580
580LIST_HEAD(soc_pcmcia_sockets); 581LIST_HEAD(soc_pcmcia_sockets);
581DECLARE_MUTEX(soc_pcmcia_sockets_lock); 582static DEFINE_MUTEX(soc_pcmcia_sockets_lock);
582 583
583static const char *skt_names[] = { 584static const char *skt_names[] = {
584 "PCMCIA socket 0", 585 "PCMCIA socket 0",
@@ -601,11 +602,11 @@ soc_pcmcia_notifier(struct notifier_block *nb, unsigned long val, void *data)
601 struct cpufreq_freqs *freqs = data; 602 struct cpufreq_freqs *freqs = data;
602 int ret = 0; 603 int ret = 0;
603 604
604 down(&soc_pcmcia_sockets_lock); 605 mutex_lock(&soc_pcmcia_sockets_lock);
605 list_for_each_entry(skt, &soc_pcmcia_sockets, node) 606 list_for_each_entry(skt, &soc_pcmcia_sockets, node)
606 if ( skt->ops->frequency_change ) 607 if ( skt->ops->frequency_change )
607 ret += skt->ops->frequency_change(skt, val, freqs); 608 ret += skt->ops->frequency_change(skt, val, freqs);
608 up(&soc_pcmcia_sockets_lock); 609 mutex_unlock(&soc_pcmcia_sockets_lock);
609 610
610 return ret; 611 return ret;
611} 612}
@@ -642,7 +643,7 @@ int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops
642 struct soc_pcmcia_socket *skt; 643 struct soc_pcmcia_socket *skt;
643 int ret, i; 644 int ret, i;
644 645
645 down(&soc_pcmcia_sockets_lock); 646 mutex_lock(&soc_pcmcia_sockets_lock);
646 647
647 sinfo = kzalloc(SKT_DEV_INFO_SIZE(nr), GFP_KERNEL); 648 sinfo = kzalloc(SKT_DEV_INFO_SIZE(nr), GFP_KERNEL);
648 if (!sinfo) { 649 if (!sinfo) {
@@ -782,7 +783,7 @@ int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops
782 kfree(sinfo); 783 kfree(sinfo);
783 784
784 out: 785 out:
785 up(&soc_pcmcia_sockets_lock); 786 mutex_unlock(&soc_pcmcia_sockets_lock);
786 return ret; 787 return ret;
787} 788}
788 789
@@ -793,7 +794,7 @@ int soc_common_drv_pcmcia_remove(struct device *dev)
793 794
794 dev_set_drvdata(dev, NULL); 795 dev_set_drvdata(dev, NULL);
795 796
796 down(&soc_pcmcia_sockets_lock); 797 mutex_lock(&soc_pcmcia_sockets_lock);
797 for (i = 0; i < sinfo->nskt; i++) { 798 for (i = 0; i < sinfo->nskt; i++) {
798 struct soc_pcmcia_socket *skt = &sinfo->skt[i]; 799 struct soc_pcmcia_socket *skt = &sinfo->skt[i];
799 800
@@ -818,7 +819,7 @@ int soc_common_drv_pcmcia_remove(struct device *dev)
818 if (list_empty(&soc_pcmcia_sockets)) 819 if (list_empty(&soc_pcmcia_sockets))
819 soc_pcmcia_cpufreq_unregister(); 820 soc_pcmcia_cpufreq_unregister();
820 821
821 up(&soc_pcmcia_sockets_lock); 822 mutex_unlock(&soc_pcmcia_sockets_lock);
822 823
823 kfree(sinfo); 824 kfree(sinfo);
824 825
diff --git a/drivers/pcmcia/soc_common.h b/drivers/pcmcia/soc_common.h
index 6f14126889b3..1edc1da9d353 100644
--- a/drivers/pcmcia/soc_common.h
+++ b/drivers/pcmcia/soc_common.h
@@ -133,7 +133,6 @@ extern void soc_common_pcmcia_get_timing(struct soc_pcmcia_socket *, struct soc_
133 133
134 134
135extern struct list_head soc_pcmcia_sockets; 135extern struct list_head soc_pcmcia_sockets;
136extern struct semaphore soc_pcmcia_sockets_lock;
137 136
138extern int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops, int first, int nr); 137extern int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops, int first, int nr);
139extern int soc_common_drv_pcmcia_remove(struct device *dev); 138extern int soc_common_drv_pcmcia_remove(struct device *dev);
diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c
index b4409002b7f8..562384d6f321 100644
--- a/drivers/pcmcia/socket_sysfs.c
+++ b/drivers/pcmcia/socket_sysfs.c
@@ -356,19 +356,23 @@ static ssize_t pccard_store_cis(struct kobject *kobj,
356} 356}
357 357
358 358
359static struct device_attribute *pccard_socket_attributes[] = { 359static struct attribute *pccard_socket_attributes[] = {
360 &dev_attr_card_type, 360 &dev_attr_card_type.attr,
361 &dev_attr_card_voltage, 361 &dev_attr_card_voltage.attr,
362 &dev_attr_card_vpp, 362 &dev_attr_card_vpp.attr,
363 &dev_attr_card_vcc, 363 &dev_attr_card_vcc.attr,
364 &dev_attr_card_insert, 364 &dev_attr_card_insert.attr,
365 &dev_attr_card_pm_state, 365 &dev_attr_card_pm_state.attr,
366 &dev_attr_card_eject, 366 &dev_attr_card_eject.attr,
367 &dev_attr_card_irq_mask, 367 &dev_attr_card_irq_mask.attr,
368 &dev_attr_available_resources_setup_done, 368 &dev_attr_available_resources_setup_done.attr,
369 NULL, 369 NULL,
370}; 370};
371 371
372static const struct attribute_group socket_attrs = {
373 .attrs = pccard_socket_attributes,
374};
375
372static struct bin_attribute pccard_cis_attr = { 376static struct bin_attribute pccard_cis_attr = {
373 .attr = { .name = "cis", .mode = S_IRUGO | S_IWUSR }, 377 .attr = { .name = "cis", .mode = S_IRUGO | S_IWUSR },
374 .size = 0x200, 378 .size = 0x200,
@@ -376,35 +380,21 @@ static struct bin_attribute pccard_cis_attr = {
376 .write = pccard_store_cis, 380 .write = pccard_store_cis,
377}; 381};
378 382
379static int __devinit pccard_sysfs_add_socket(struct device *dev, 383int pccard_sysfs_add_socket(struct device *dev)
380 struct class_interface *class_intf)
381{ 384{
382 struct device_attribute **attr;
383 int ret = 0; 385 int ret = 0;
384 386
385 for (attr = pccard_socket_attributes; *attr; attr++) { 387 ret = sysfs_create_group(&dev->kobj, &socket_attrs);
386 ret = device_create_file(dev, *attr); 388 if (!ret) {
389 ret = sysfs_create_bin_file(&dev->kobj, &pccard_cis_attr);
387 if (ret) 390 if (ret)
388 break; 391 sysfs_remove_group(&dev->kobj, &socket_attrs);
389 } 392 }
390 if (!ret)
391 ret = sysfs_create_bin_file(&dev->kobj, &pccard_cis_attr);
392
393 return ret; 393 return ret;
394} 394}
395 395
396static void __devexit pccard_sysfs_remove_socket(struct device *dev, 396void pccard_sysfs_remove_socket(struct device *dev)
397 struct class_interface *class_intf)
398{ 397{
399 struct device_attribute **attr;
400
401 sysfs_remove_bin_file(&dev->kobj, &pccard_cis_attr); 398 sysfs_remove_bin_file(&dev->kobj, &pccard_cis_attr);
402 for (attr = pccard_socket_attributes; *attr; attr++) 399 sysfs_remove_group(&dev->kobj, &socket_attrs);
403 device_remove_file(dev, *attr);
404} 400}
405
406struct class_interface pccard_sysfs_interface = {
407 .class = &pcmcia_socket_class,
408 .add_dev = &pccard_sysfs_add_socket,
409 .remove_dev = __devexit_p(&pccard_sysfs_remove_socket),
410};
diff --git a/drivers/pnp/base.h b/drivers/pnp/base.h
index 31a633f65547..4fe7c58f57e9 100644
--- a/drivers/pnp/base.h
+++ b/drivers/pnp/base.h
@@ -1,12 +1,78 @@
1extern spinlock_t pnp_lock; 1extern spinlock_t pnp_lock;
2void *pnp_alloc(long size); 2void *pnp_alloc(long size);
3
4int pnp_register_protocol(struct pnp_protocol *protocol);
5void pnp_unregister_protocol(struct pnp_protocol *protocol);
6
7#define PNP_EISA_ID_MASK 0x7fffffff
8void pnp_eisa_id_to_string(u32 id, char *str);
9struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *, int id, char *pnpid);
10struct pnp_card *pnp_alloc_card(struct pnp_protocol *, int id, char *pnpid);
11
12int pnp_add_device(struct pnp_dev *dev);
13struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id);
3int pnp_interface_attach_device(struct pnp_dev *dev); 14int pnp_interface_attach_device(struct pnp_dev *dev);
15
16int pnp_add_card(struct pnp_card *card);
17struct pnp_id *pnp_add_card_id(struct pnp_card *card, char *id);
18void pnp_remove_card(struct pnp_card *card);
19int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev);
20void pnp_remove_card_device(struct pnp_dev *dev);
21
22struct pnp_option *pnp_register_independent_option(struct pnp_dev *dev);
23struct pnp_option *pnp_register_dependent_option(struct pnp_dev *dev,
24 int priority);
25int pnp_register_irq_resource(struct pnp_dev *dev, struct pnp_option *option,
26 struct pnp_irq *data);
27int pnp_register_dma_resource(struct pnp_dev *dev, struct pnp_option *option,
28 struct pnp_dma *data);
29int pnp_register_port_resource(struct pnp_dev *dev, struct pnp_option *option,
30 struct pnp_port *data);
31int pnp_register_mem_resource(struct pnp_dev *dev, struct pnp_option *option,
32 struct pnp_mem *data);
33void pnp_init_resources(struct pnp_dev *dev);
34
4void pnp_fixup_device(struct pnp_dev *dev); 35void pnp_fixup_device(struct pnp_dev *dev);
5void pnp_free_option(struct pnp_option *option); 36void pnp_free_option(struct pnp_option *option);
6int __pnp_add_device(struct pnp_dev *dev); 37int __pnp_add_device(struct pnp_dev *dev);
7void __pnp_remove_device(struct pnp_dev *dev); 38void __pnp_remove_device(struct pnp_dev *dev);
8 39
9int pnp_check_port(struct pnp_dev * dev, int idx); 40int pnp_check_port(struct pnp_dev *dev, struct resource *res);
10int pnp_check_mem(struct pnp_dev * dev, int idx); 41int pnp_check_mem(struct pnp_dev *dev, struct resource *res);
11int pnp_check_irq(struct pnp_dev * dev, int idx); 42int pnp_check_irq(struct pnp_dev *dev, struct resource *res);
12int pnp_check_dma(struct pnp_dev * dev, int idx); 43int pnp_check_dma(struct pnp_dev *dev, struct resource *res);
44
45void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc);
46
47void pnp_init_resource(struct resource *res);
48
49struct pnp_resource *pnp_get_pnp_resource(struct pnp_dev *dev,
50 unsigned int type, unsigned int num);
51
52#define PNP_MAX_PORT 40
53#define PNP_MAX_MEM 24
54#define PNP_MAX_IRQ 2
55#define PNP_MAX_DMA 2
56
57struct pnp_resource {
58 struct resource res;
59 unsigned int index; /* ISAPNP config register index */
60};
61
62struct pnp_resource_table {
63 struct pnp_resource port[PNP_MAX_PORT];
64 struct pnp_resource mem[PNP_MAX_MEM];
65 struct pnp_resource dma[PNP_MAX_DMA];
66 struct pnp_resource irq[PNP_MAX_IRQ];
67};
68
69struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
70 int flags);
71struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma,
72 int flags);
73struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev,
74 resource_size_t start,
75 resource_size_t end, int flags);
76struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev,
77 resource_size_t start,
78 resource_size_t end, int flags);
diff --git a/drivers/pnp/card.c b/drivers/pnp/card.c
index da1c9909eb44..a762a4176736 100644
--- a/drivers/pnp/card.c
+++ b/drivers/pnp/card.c
@@ -5,6 +5,7 @@
5 */ 5 */
6 6
7#include <linux/module.h> 7#include <linux/module.h>
8#include <linux/ctype.h>
8#include <linux/slab.h> 9#include <linux/slab.h>
9#include <linux/pnp.h> 10#include <linux/pnp.h>
10#include "base.h" 11#include "base.h"
@@ -100,19 +101,33 @@ static int card_probe(struct pnp_card *card, struct pnp_card_driver *drv)
100 * @id: pointer to a pnp_id structure 101 * @id: pointer to a pnp_id structure
101 * @card: pointer to the desired card 102 * @card: pointer to the desired card
102 */ 103 */
103int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card) 104struct pnp_id *pnp_add_card_id(struct pnp_card *card, char *id)
104{ 105{
105 struct pnp_id *ptr; 106 struct pnp_id *dev_id, *ptr;
106 107
107 id->next = NULL; 108 dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
109 if (!dev_id)
110 return NULL;
111
112 dev_id->id[0] = id[0];
113 dev_id->id[1] = id[1];
114 dev_id->id[2] = id[2];
115 dev_id->id[3] = tolower(id[3]);
116 dev_id->id[4] = tolower(id[4]);
117 dev_id->id[5] = tolower(id[5]);
118 dev_id->id[6] = tolower(id[6]);
119 dev_id->id[7] = '\0';
120
121 dev_id->next = NULL;
108 ptr = card->id; 122 ptr = card->id;
109 while (ptr && ptr->next) 123 while (ptr && ptr->next)
110 ptr = ptr->next; 124 ptr = ptr->next;
111 if (ptr) 125 if (ptr)
112 ptr->next = id; 126 ptr->next = dev_id;
113 else 127 else
114 card->id = id; 128 card->id = dev_id;
115 return 0; 129
130 return dev_id;
116} 131}
117 132
118static void pnp_free_card_ids(struct pnp_card *card) 133static void pnp_free_card_ids(struct pnp_card *card)
@@ -136,6 +151,31 @@ static void pnp_release_card(struct device *dmdev)
136 kfree(card); 151 kfree(card);
137} 152}
138 153
154struct pnp_card *pnp_alloc_card(struct pnp_protocol *protocol, int id, char *pnpid)
155{
156 struct pnp_card *card;
157 struct pnp_id *dev_id;
158
159 card = kzalloc(sizeof(struct pnp_card), GFP_KERNEL);
160 if (!card)
161 return NULL;
162
163 card->protocol = protocol;
164 card->number = id;
165
166 card->dev.parent = &card->protocol->dev;
167 sprintf(card->dev.bus_id, "%02x:%02x", card->protocol->number,
168 card->number);
169
170 dev_id = pnp_add_card_id(card, pnpid);
171 if (!dev_id) {
172 kfree(card);
173 return NULL;
174 }
175
176 return card;
177}
178
139static ssize_t pnp_show_card_name(struct device *dmdev, 179static ssize_t pnp_show_card_name(struct device *dmdev,
140 struct device_attribute *attr, char *buf) 180 struct device_attribute *attr, char *buf)
141{ 181{
@@ -191,9 +231,6 @@ int pnp_add_card(struct pnp_card *card)
191 int error; 231 int error;
192 struct list_head *pos, *temp; 232 struct list_head *pos, *temp;
193 233
194 sprintf(card->dev.bus_id, "%02x:%02x", card->protocol->number,
195 card->number);
196 card->dev.parent = &card->protocol->dev;
197 card->dev.bus = NULL; 234 card->dev.bus = NULL;
198 card->dev.release = &pnp_release_card; 235 card->dev.release = &pnp_release_card;
199 error = device_register(&card->dev); 236 error = device_register(&card->dev);
diff --git a/drivers/pnp/core.c b/drivers/pnp/core.c
index 7d366ca672d3..20771b7d4482 100644
--- a/drivers/pnp/core.c
+++ b/drivers/pnp/core.c
@@ -106,18 +106,53 @@ static void pnp_release_device(struct device *dmdev)
106 pnp_free_option(dev->independent); 106 pnp_free_option(dev->independent);
107 pnp_free_option(dev->dependent); 107 pnp_free_option(dev->dependent);
108 pnp_free_ids(dev); 108 pnp_free_ids(dev);
109 kfree(dev->res);
109 kfree(dev); 110 kfree(dev);
110} 111}
111 112
112int __pnp_add_device(struct pnp_dev *dev) 113struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id, char *pnpid)
113{ 114{
114 int ret; 115 struct pnp_dev *dev;
116 struct pnp_id *dev_id;
115 117
116 pnp_fixup_device(dev); 118 dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
119 if (!dev)
120 return NULL;
121
122 dev->res = kzalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
123 if (!dev->res) {
124 kfree(dev);
125 return NULL;
126 }
127
128 dev->protocol = protocol;
129 dev->number = id;
130 dev->dma_mask = DMA_24BIT_MASK;
131
132 dev->dev.parent = &dev->protocol->dev;
117 dev->dev.bus = &pnp_bus_type; 133 dev->dev.bus = &pnp_bus_type;
118 dev->dev.dma_mask = &dev->dma_mask; 134 dev->dev.dma_mask = &dev->dma_mask;
119 dev->dma_mask = dev->dev.coherent_dma_mask = DMA_24BIT_MASK; 135 dev->dev.coherent_dma_mask = dev->dma_mask;
120 dev->dev.release = &pnp_release_device; 136 dev->dev.release = &pnp_release_device;
137
138 sprintf(dev->dev.bus_id, "%02x:%02x", dev->protocol->number,
139 dev->number);
140
141 dev_id = pnp_add_id(dev, pnpid);
142 if (!dev_id) {
143 kfree(dev->res);
144 kfree(dev);
145 return NULL;
146 }
147
148 return dev;
149}
150
151int __pnp_add_device(struct pnp_dev *dev)
152{
153 int ret;
154
155 pnp_fixup_device(dev);
121 dev->status = PNP_READY; 156 dev->status = PNP_READY;
122 spin_lock(&pnp_lock); 157 spin_lock(&pnp_lock);
123 list_add_tail(&dev->global_list, &pnp_global); 158 list_add_tail(&dev->global_list, &pnp_global);
@@ -145,9 +180,6 @@ int pnp_add_device(struct pnp_dev *dev)
145 if (dev->card) 180 if (dev->card)
146 return -EINVAL; 181 return -EINVAL;
147 182
148 dev->dev.parent = &dev->protocol->dev;
149 sprintf(dev->dev.bus_id, "%02x:%02x", dev->protocol->number,
150 dev->number);
151 ret = __pnp_add_device(dev); 183 ret = __pnp_add_device(dev);
152 if (ret) 184 if (ret)
153 return ret; 185 return ret;
diff --git a/drivers/pnp/driver.c b/drivers/pnp/driver.c
index e85cbf116db1..d3f869ee1d92 100644
--- a/drivers/pnp/driver.c
+++ b/drivers/pnp/driver.c
@@ -226,22 +226,36 @@ void pnp_unregister_driver(struct pnp_driver *drv)
226 226
227/** 227/**
228 * pnp_add_id - adds an EISA id to the specified device 228 * pnp_add_id - adds an EISA id to the specified device
229 * @id: pointer to a pnp_id structure
230 * @dev: pointer to the desired device 229 * @dev: pointer to the desired device
230 * @id: pointer to an EISA id string
231 */ 231 */
232int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev) 232struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id)
233{ 233{
234 struct pnp_id *ptr; 234 struct pnp_id *dev_id, *ptr;
235 235
236 id->next = NULL; 236 dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
237 if (!dev_id)
238 return NULL;
239
240 dev_id->id[0] = id[0];
241 dev_id->id[1] = id[1];
242 dev_id->id[2] = id[2];
243 dev_id->id[3] = tolower(id[3]);
244 dev_id->id[4] = tolower(id[4]);
245 dev_id->id[5] = tolower(id[5]);
246 dev_id->id[6] = tolower(id[6]);
247 dev_id->id[7] = '\0';
248
249 dev_id->next = NULL;
237 ptr = dev->id; 250 ptr = dev->id;
238 while (ptr && ptr->next) 251 while (ptr && ptr->next)
239 ptr = ptr->next; 252 ptr = ptr->next;
240 if (ptr) 253 if (ptr)
241 ptr->next = id; 254 ptr->next = dev_id;
242 else 255 else
243 dev->id = id; 256 dev->id = dev_id;
244 return 0; 257
258 return dev_id;
245} 259}
246 260
247EXPORT_SYMBOL(pnp_register_driver); 261EXPORT_SYMBOL(pnp_register_driver);
diff --git a/drivers/pnp/interface.c b/drivers/pnp/interface.c
index 982658477a58..5d9301de1778 100644
--- a/drivers/pnp/interface.c
+++ b/drivers/pnp/interface.c
@@ -248,6 +248,7 @@ static ssize_t pnp_show_current_resources(struct device *dmdev,
248 char *buf) 248 char *buf)
249{ 249{
250 struct pnp_dev *dev = to_pnp_dev(dmdev); 250 struct pnp_dev *dev = to_pnp_dev(dmdev);
251 struct resource *res;
251 int i, ret; 252 int i, ret;
252 pnp_info_buffer_t *buffer; 253 pnp_info_buffer_t *buffer;
253 254
@@ -267,50 +268,46 @@ static ssize_t pnp_show_current_resources(struct device *dmdev,
267 else 268 else
268 pnp_printf(buffer, "disabled\n"); 269 pnp_printf(buffer, "disabled\n");
269 270
270 for (i = 0; i < PNP_MAX_PORT; i++) { 271 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) {
271 if (pnp_port_valid(dev, i)) { 272 if (pnp_resource_valid(res)) {
272 pnp_printf(buffer, "io"); 273 pnp_printf(buffer, "io");
273 if (pnp_port_flags(dev, i) & IORESOURCE_DISABLED) 274 if (res->flags & IORESOURCE_DISABLED)
274 pnp_printf(buffer, " disabled\n"); 275 pnp_printf(buffer, " disabled\n");
275 else 276 else
276 pnp_printf(buffer, " 0x%llx-0x%llx\n", 277 pnp_printf(buffer, " 0x%llx-0x%llx\n",
277 (unsigned long long) 278 (unsigned long long) res->start,
278 pnp_port_start(dev, i), 279 (unsigned long long) res->end);
279 (unsigned long long)pnp_port_end(dev,
280 i));
281 } 280 }
282 } 281 }
283 for (i = 0; i < PNP_MAX_MEM; i++) { 282 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) {
284 if (pnp_mem_valid(dev, i)) { 283 if (pnp_resource_valid(res)) {
285 pnp_printf(buffer, "mem"); 284 pnp_printf(buffer, "mem");
286 if (pnp_mem_flags(dev, i) & IORESOURCE_DISABLED) 285 if (res->flags & IORESOURCE_DISABLED)
287 pnp_printf(buffer, " disabled\n"); 286 pnp_printf(buffer, " disabled\n");
288 else 287 else
289 pnp_printf(buffer, " 0x%llx-0x%llx\n", 288 pnp_printf(buffer, " 0x%llx-0x%llx\n",
290 (unsigned long long) 289 (unsigned long long) res->start,
291 pnp_mem_start(dev, i), 290 (unsigned long long) res->end);
292 (unsigned long long)pnp_mem_end(dev,
293 i));
294 } 291 }
295 } 292 }
296 for (i = 0; i < PNP_MAX_IRQ; i++) { 293 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IRQ, i)); i++) {
297 if (pnp_irq_valid(dev, i)) { 294 if (pnp_resource_valid(res)) {
298 pnp_printf(buffer, "irq"); 295 pnp_printf(buffer, "irq");
299 if (pnp_irq_flags(dev, i) & IORESOURCE_DISABLED) 296 if (res->flags & IORESOURCE_DISABLED)
300 pnp_printf(buffer, " disabled\n"); 297 pnp_printf(buffer, " disabled\n");
301 else 298 else
302 pnp_printf(buffer, " %lld\n", 299 pnp_printf(buffer, " %lld\n",
303 (unsigned long long)pnp_irq(dev, i)); 300 (unsigned long long) res->start);
304 } 301 }
305 } 302 }
306 for (i = 0; i < PNP_MAX_DMA; i++) { 303 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_DMA, i)); i++) {
307 if (pnp_dma_valid(dev, i)) { 304 if (pnp_resource_valid(res)) {
308 pnp_printf(buffer, "dma"); 305 pnp_printf(buffer, "dma");
309 if (pnp_dma_flags(dev, i) & IORESOURCE_DISABLED) 306 if (res->flags & IORESOURCE_DISABLED)
310 pnp_printf(buffer, " disabled\n"); 307 pnp_printf(buffer, " disabled\n");
311 else 308 else
312 pnp_printf(buffer, " %lld\n", 309 pnp_printf(buffer, " %lld\n",
313 (unsigned long long)pnp_dma(dev, i)); 310 (unsigned long long) res->start);
314 } 311 }
315 } 312 }
316 ret = (buffer->curr - buf); 313 ret = (buffer->curr - buf);
@@ -323,8 +320,10 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
323 const char *ubuf, size_t count) 320 const char *ubuf, size_t count)
324{ 321{
325 struct pnp_dev *dev = to_pnp_dev(dmdev); 322 struct pnp_dev *dev = to_pnp_dev(dmdev);
323 struct pnp_resource *pnp_res;
326 char *buf = (void *)ubuf; 324 char *buf = (void *)ubuf;
327 int retval = 0; 325 int retval = 0;
326 resource_size_t start, end;
328 327
329 if (dev->status & PNP_ATTACHED) { 328 if (dev->status & PNP_ATTACHED) {
330 retval = -EBUSY; 329 retval = -EBUSY;
@@ -351,20 +350,20 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
351 if (!strnicmp(buf, "auto", 4)) { 350 if (!strnicmp(buf, "auto", 4)) {
352 if (dev->active) 351 if (dev->active)
353 goto done; 352 goto done;
354 pnp_init_resource_table(&dev->res); 353 pnp_init_resources(dev);
355 retval = pnp_auto_config_dev(dev); 354 retval = pnp_auto_config_dev(dev);
356 goto done; 355 goto done;
357 } 356 }
358 if (!strnicmp(buf, "clear", 5)) { 357 if (!strnicmp(buf, "clear", 5)) {
359 if (dev->active) 358 if (dev->active)
360 goto done; 359 goto done;
361 pnp_init_resource_table(&dev->res); 360 pnp_init_resources(dev);
362 goto done; 361 goto done;
363 } 362 }
364 if (!strnicmp(buf, "get", 3)) { 363 if (!strnicmp(buf, "get", 3)) {
365 mutex_lock(&pnp_res_mutex); 364 mutex_lock(&pnp_res_mutex);
366 if (pnp_can_read(dev)) 365 if (pnp_can_read(dev))
367 dev->protocol->get(dev, &dev->res); 366 dev->protocol->get(dev);
368 mutex_unlock(&pnp_res_mutex); 367 mutex_unlock(&pnp_res_mutex);
369 goto done; 368 goto done;
370 } 369 }
@@ -373,7 +372,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
373 if (dev->active) 372 if (dev->active)
374 goto done; 373 goto done;
375 buf += 3; 374 buf += 3;
376 pnp_init_resource_table(&dev->res); 375 pnp_init_resources(dev);
377 mutex_lock(&pnp_res_mutex); 376 mutex_lock(&pnp_res_mutex);
378 while (1) { 377 while (1) {
379 while (isspace(*buf)) 378 while (isspace(*buf))
@@ -382,76 +381,60 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
382 buf += 2; 381 buf += 2;
383 while (isspace(*buf)) 382 while (isspace(*buf))
384 ++buf; 383 ++buf;
385 dev->res.port_resource[nport].start = 384 start = simple_strtoul(buf, &buf, 0);
386 simple_strtoul(buf, &buf, 0);
387 while (isspace(*buf)) 385 while (isspace(*buf))
388 ++buf; 386 ++buf;
389 if (*buf == '-') { 387 if (*buf == '-') {
390 buf += 1; 388 buf += 1;
391 while (isspace(*buf)) 389 while (isspace(*buf))
392 ++buf; 390 ++buf;
393 dev->res.port_resource[nport].end = 391 end = simple_strtoul(buf, &buf, 0);
394 simple_strtoul(buf, &buf, 0);
395 } else 392 } else
396 dev->res.port_resource[nport].end = 393 end = start;
397 dev->res.port_resource[nport].start; 394 pnp_res = pnp_add_io_resource(dev, start, end,
398 dev->res.port_resource[nport].flags = 395 0);
399 IORESOURCE_IO; 396 if (pnp_res)
400 nport++; 397 pnp_res->index = nport++;
401 if (nport >= PNP_MAX_PORT)
402 break;
403 continue; 398 continue;
404 } 399 }
405 if (!strnicmp(buf, "mem", 3)) { 400 if (!strnicmp(buf, "mem", 3)) {
406 buf += 3; 401 buf += 3;
407 while (isspace(*buf)) 402 while (isspace(*buf))
408 ++buf; 403 ++buf;
409 dev->res.mem_resource[nmem].start = 404 start = simple_strtoul(buf, &buf, 0);
410 simple_strtoul(buf, &buf, 0);
411 while (isspace(*buf)) 405 while (isspace(*buf))
412 ++buf; 406 ++buf;
413 if (*buf == '-') { 407 if (*buf == '-') {
414 buf += 1; 408 buf += 1;
415 while (isspace(*buf)) 409 while (isspace(*buf))
416 ++buf; 410 ++buf;
417 dev->res.mem_resource[nmem].end = 411 end = simple_strtoul(buf, &buf, 0);
418 simple_strtoul(buf, &buf, 0);
419 } else 412 } else
420 dev->res.mem_resource[nmem].end = 413 end = start;
421 dev->res.mem_resource[nmem].start; 414 pnp_res = pnp_add_mem_resource(dev, start, end,
422 dev->res.mem_resource[nmem].flags = 415 0);
423 IORESOURCE_MEM; 416 if (pnp_res)
424 nmem++; 417 pnp_res->index = nmem++;
425 if (nmem >= PNP_MAX_MEM)
426 break;
427 continue; 418 continue;
428 } 419 }
429 if (!strnicmp(buf, "irq", 3)) { 420 if (!strnicmp(buf, "irq", 3)) {
430 buf += 3; 421 buf += 3;
431 while (isspace(*buf)) 422 while (isspace(*buf))
432 ++buf; 423 ++buf;
433 dev->res.irq_resource[nirq].start = 424 start = simple_strtoul(buf, &buf, 0);
434 dev->res.irq_resource[nirq].end = 425 pnp_res = pnp_add_irq_resource(dev, start, 0);
435 simple_strtoul(buf, &buf, 0); 426 if (pnp_res)
436 dev->res.irq_resource[nirq].flags = 427 nirq++;
437 IORESOURCE_IRQ;
438 nirq++;
439 if (nirq >= PNP_MAX_IRQ)
440 break;
441 continue; 428 continue;
442 } 429 }
443 if (!strnicmp(buf, "dma", 3)) { 430 if (!strnicmp(buf, "dma", 3)) {
444 buf += 3; 431 buf += 3;
445 while (isspace(*buf)) 432 while (isspace(*buf))
446 ++buf; 433 ++buf;
447 dev->res.dma_resource[ndma].start = 434 start = simple_strtoul(buf, &buf, 0);
448 dev->res.dma_resource[ndma].end = 435 pnp_res = pnp_add_dma_resource(dev, start, 0);
449 simple_strtoul(buf, &buf, 0); 436 if (pnp_res)
450 dev->res.dma_resource[ndma].flags = 437 pnp_res->index = ndma++;
451 IORESOURCE_DMA;
452 ndma++;
453 if (ndma >= PNP_MAX_DMA)
454 break;
455 continue; 438 continue;
456 } 439 }
457 break; 440 break;
diff --git a/drivers/pnp/isapnp/Makefile b/drivers/pnp/isapnp/Makefile
index cac18bbfb817..3e38f06f8d78 100644
--- a/drivers/pnp/isapnp/Makefile
+++ b/drivers/pnp/isapnp/Makefile
@@ -5,3 +5,7 @@
5isapnp-proc-$(CONFIG_PROC_FS) = proc.o 5isapnp-proc-$(CONFIG_PROC_FS) = proc.o
6 6
7obj-y := core.o compat.o $(isapnp-proc-y) 7obj-y := core.o compat.o $(isapnp-proc-y)
8
9ifeq ($(CONFIG_PNP_DEBUG),y)
10EXTRA_CFLAGS += -DDEBUG
11endif
diff --git a/drivers/pnp/isapnp/core.c b/drivers/pnp/isapnp/core.c
index 257f5d827d83..f1bccdbdeb08 100644
--- a/drivers/pnp/isapnp/core.c
+++ b/drivers/pnp/isapnp/core.c
@@ -44,6 +44,8 @@
44#include <linux/mutex.h> 44#include <linux/mutex.h>
45#include <asm/io.h> 45#include <asm/io.h>
46 46
47#include "../base.h"
48
47#if 0 49#if 0
48#define ISAPNP_REGION_OK 50#define ISAPNP_REGION_OK
49#endif 51#endif
@@ -88,6 +90,14 @@ MODULE_LICENSE("GPL");
88#define _LTAG_MEM32RANGE 0x85 90#define _LTAG_MEM32RANGE 0x85
89#define _LTAG_FIXEDMEM32RANGE 0x86 91#define _LTAG_FIXEDMEM32RANGE 0x86
90 92
93/* Logical device control and configuration registers */
94
95#define ISAPNP_CFG_ACTIVATE 0x30 /* byte */
96#define ISAPNP_CFG_MEM 0x40 /* 4 * dword */
97#define ISAPNP_CFG_PORT 0x60 /* 8 * word */
98#define ISAPNP_CFG_IRQ 0x70 /* 2 * word */
99#define ISAPNP_CFG_DMA 0x74 /* 2 * byte */
100
91/* 101/*
92 * Sizes of ISAPNP logical device configuration register sets. 102 * Sizes of ISAPNP logical device configuration register sets.
93 * See PNP-ISA-v1.0a.pdf, Appendix A. 103 * See PNP-ISA-v1.0a.pdf, Appendix A.
@@ -388,28 +398,6 @@ static void __init isapnp_skip_bytes(int count)
388} 398}
389 399
390/* 400/*
391 * Parse EISA id.
392 */
393static void isapnp_parse_id(struct pnp_dev *dev, unsigned short vendor,
394 unsigned short device)
395{
396 struct pnp_id *id;
397
398 if (!dev)
399 return;
400 id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
401 if (!id)
402 return;
403 sprintf(id->id, "%c%c%c%x%x%x%x",
404 'A' + ((vendor >> 2) & 0x3f) - 1,
405 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
406 'A' + ((vendor >> 8) & 0x1f) - 1,
407 (device >> 4) & 0x0f,
408 device & 0x0f, (device >> 12) & 0x0f, (device >> 8) & 0x0f);
409 pnp_add_id(id, dev);
410}
411
412/*
413 * Parse logical device tag. 401 * Parse logical device tag.
414 */ 402 */
415static struct pnp_dev *__init isapnp_parse_device(struct pnp_card *card, 403static struct pnp_dev *__init isapnp_parse_device(struct pnp_card *card,
@@ -417,30 +405,31 @@ static struct pnp_dev *__init isapnp_parse_device(struct pnp_card *card,
417{ 405{
418 unsigned char tmp[6]; 406 unsigned char tmp[6];
419 struct pnp_dev *dev; 407 struct pnp_dev *dev;
408 u32 eisa_id;
409 char id[8];
420 410
421 isapnp_peek(tmp, size); 411 isapnp_peek(tmp, size);
422 dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL); 412 eisa_id = tmp[0] | tmp[1] << 8 | tmp[2] << 16 | tmp[3] << 24;
413 pnp_eisa_id_to_string(eisa_id, id);
414
415 dev = pnp_alloc_dev(&isapnp_protocol, number, id);
423 if (!dev) 416 if (!dev)
424 return NULL; 417 return NULL;
425 dev->number = number; 418
426 isapnp_parse_id(dev, (tmp[1] << 8) | tmp[0], (tmp[3] << 8) | tmp[2]);
427 dev->regs = tmp[4];
428 dev->card = card; 419 dev->card = card;
429 if (size > 5)
430 dev->regs |= tmp[5] << 8;
431 dev->protocol = &isapnp_protocol;
432 dev->capabilities |= PNP_CONFIGURABLE; 420 dev->capabilities |= PNP_CONFIGURABLE;
433 dev->capabilities |= PNP_READ; 421 dev->capabilities |= PNP_READ;
434 dev->capabilities |= PNP_WRITE; 422 dev->capabilities |= PNP_WRITE;
435 dev->capabilities |= PNP_DISABLE; 423 dev->capabilities |= PNP_DISABLE;
436 pnp_init_resource_table(&dev->res); 424 pnp_init_resources(dev);
437 return dev; 425 return dev;
438} 426}
439 427
440/* 428/*
441 * Add IRQ resource to resources list. 429 * Add IRQ resource to resources list.
442 */ 430 */
443static void __init isapnp_parse_irq_resource(struct pnp_option *option, 431static void __init isapnp_parse_irq_resource(struct pnp_dev *dev,
432 struct pnp_option *option,
444 int size) 433 int size)
445{ 434{
446 unsigned char tmp[3]; 435 unsigned char tmp[3];
@@ -457,13 +446,14 @@ static void __init isapnp_parse_irq_resource(struct pnp_option *option,
457 irq->flags = tmp[2]; 446 irq->flags = tmp[2];
458 else 447 else
459 irq->flags = IORESOURCE_IRQ_HIGHEDGE; 448 irq->flags = IORESOURCE_IRQ_HIGHEDGE;
460 pnp_register_irq_resource(option, irq); 449 pnp_register_irq_resource(dev, option, irq);
461} 450}
462 451
463/* 452/*
464 * Add DMA resource to resources list. 453 * Add DMA resource to resources list.
465 */ 454 */
466static void __init isapnp_parse_dma_resource(struct pnp_option *option, 455static void __init isapnp_parse_dma_resource(struct pnp_dev *dev,
456 struct pnp_option *option,
467 int size) 457 int size)
468{ 458{
469 unsigned char tmp[2]; 459 unsigned char tmp[2];
@@ -475,13 +465,14 @@ static void __init isapnp_parse_dma_resource(struct pnp_option *option,
475 return; 465 return;
476 dma->map = tmp[0]; 466 dma->map = tmp[0];
477 dma->flags = tmp[1]; 467 dma->flags = tmp[1];
478 pnp_register_dma_resource(option, dma); 468 pnp_register_dma_resource(dev, option, dma);
479} 469}
480 470
481/* 471/*
482 * Add port resource to resources list. 472 * Add port resource to resources list.
483 */ 473 */
484static void __init isapnp_parse_port_resource(struct pnp_option *option, 474static void __init isapnp_parse_port_resource(struct pnp_dev *dev,
475 struct pnp_option *option,
485 int size) 476 int size)
486{ 477{
487 unsigned char tmp[7]; 478 unsigned char tmp[7];
@@ -496,13 +487,14 @@ static void __init isapnp_parse_port_resource(struct pnp_option *option,
496 port->align = tmp[5]; 487 port->align = tmp[5];
497 port->size = tmp[6]; 488 port->size = tmp[6];
498 port->flags = tmp[0] ? PNP_PORT_FLAG_16BITADDR : 0; 489 port->flags = tmp[0] ? PNP_PORT_FLAG_16BITADDR : 0;
499 pnp_register_port_resource(option, port); 490 pnp_register_port_resource(dev, option, port);
500} 491}
501 492
502/* 493/*
503 * Add fixed port resource to resources list. 494 * Add fixed port resource to resources list.
504 */ 495 */
505static void __init isapnp_parse_fixed_port_resource(struct pnp_option *option, 496static void __init isapnp_parse_fixed_port_resource(struct pnp_dev *dev,
497 struct pnp_option *option,
506 int size) 498 int size)
507{ 499{
508 unsigned char tmp[3]; 500 unsigned char tmp[3];
@@ -516,13 +508,14 @@ static void __init isapnp_parse_fixed_port_resource(struct pnp_option *option,
516 port->size = tmp[2]; 508 port->size = tmp[2];
517 port->align = 0; 509 port->align = 0;
518 port->flags = PNP_PORT_FLAG_FIXED; 510 port->flags = PNP_PORT_FLAG_FIXED;
519 pnp_register_port_resource(option, port); 511 pnp_register_port_resource(dev, option, port);
520} 512}
521 513
522/* 514/*
523 * Add memory resource to resources list. 515 * Add memory resource to resources list.
524 */ 516 */
525static void __init isapnp_parse_mem_resource(struct pnp_option *option, 517static void __init isapnp_parse_mem_resource(struct pnp_dev *dev,
518 struct pnp_option *option,
526 int size) 519 int size)
527{ 520{
528 unsigned char tmp[9]; 521 unsigned char tmp[9];
@@ -537,13 +530,14 @@ static void __init isapnp_parse_mem_resource(struct pnp_option *option,
537 mem->align = (tmp[6] << 8) | tmp[5]; 530 mem->align = (tmp[6] << 8) | tmp[5];
538 mem->size = ((tmp[8] << 8) | tmp[7]) << 8; 531 mem->size = ((tmp[8] << 8) | tmp[7]) << 8;
539 mem->flags = tmp[0]; 532 mem->flags = tmp[0];
540 pnp_register_mem_resource(option, mem); 533 pnp_register_mem_resource(dev, option, mem);
541} 534}
542 535
543/* 536/*
544 * Add 32-bit memory resource to resources list. 537 * Add 32-bit memory resource to resources list.
545 */ 538 */
546static void __init isapnp_parse_mem32_resource(struct pnp_option *option, 539static void __init isapnp_parse_mem32_resource(struct pnp_dev *dev,
540 struct pnp_option *option,
547 int size) 541 int size)
548{ 542{
549 unsigned char tmp[17]; 543 unsigned char tmp[17];
@@ -560,13 +554,14 @@ static void __init isapnp_parse_mem32_resource(struct pnp_option *option,
560 mem->size = 554 mem->size =
561 (tmp[16] << 24) | (tmp[15] << 16) | (tmp[14] << 8) | tmp[13]; 555 (tmp[16] << 24) | (tmp[15] << 16) | (tmp[14] << 8) | tmp[13];
562 mem->flags = tmp[0]; 556 mem->flags = tmp[0];
563 pnp_register_mem_resource(option, mem); 557 pnp_register_mem_resource(dev, option, mem);
564} 558}
565 559
566/* 560/*
567 * Add 32-bit fixed memory resource to resources list. 561 * Add 32-bit fixed memory resource to resources list.
568 */ 562 */
569static void __init isapnp_parse_fixed_mem32_resource(struct pnp_option *option, 563static void __init isapnp_parse_fixed_mem32_resource(struct pnp_dev *dev,
564 struct pnp_option *option,
570 int size) 565 int size)
571{ 566{
572 unsigned char tmp[9]; 567 unsigned char tmp[9];
@@ -581,7 +576,7 @@ static void __init isapnp_parse_fixed_mem32_resource(struct pnp_option *option,
581 mem->size = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5]; 576 mem->size = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5];
582 mem->align = 0; 577 mem->align = 0;
583 mem->flags = tmp[0]; 578 mem->flags = tmp[0];
584 pnp_register_mem_resource(option, mem); 579 pnp_register_mem_resource(dev, option, mem);
585} 580}
586 581
587/* 582/*
@@ -613,6 +608,8 @@ static int __init isapnp_create_device(struct pnp_card *card,
613 unsigned char type, tmp[17]; 608 unsigned char type, tmp[17];
614 struct pnp_option *option; 609 struct pnp_option *option;
615 struct pnp_dev *dev; 610 struct pnp_dev *dev;
611 u32 eisa_id;
612 char id[8];
616 613
617 if ((dev = isapnp_parse_device(card, size, number++)) == NULL) 614 if ((dev = isapnp_parse_device(card, size, number++)) == NULL)
618 return 1; 615 return 1;
@@ -652,8 +649,10 @@ static int __init isapnp_create_device(struct pnp_card *card,
652 case _STAG_COMPATDEVID: 649 case _STAG_COMPATDEVID:
653 if (size == 4 && compat < DEVICE_COUNT_COMPATIBLE) { 650 if (size == 4 && compat < DEVICE_COUNT_COMPATIBLE) {
654 isapnp_peek(tmp, 4); 651 isapnp_peek(tmp, 4);
655 isapnp_parse_id(dev, (tmp[1] << 8) | tmp[0], 652 eisa_id = tmp[0] | tmp[1] << 8 |
656 (tmp[3] << 8) | tmp[2]); 653 tmp[2] << 16 | tmp[3] << 24;
654 pnp_eisa_id_to_string(eisa_id, id);
655 pnp_add_id(dev, id);
657 compat++; 656 compat++;
658 size = 0; 657 size = 0;
659 } 658 }
@@ -661,13 +660,13 @@ static int __init isapnp_create_device(struct pnp_card *card,
661 case _STAG_IRQ: 660 case _STAG_IRQ:
662 if (size < 2 || size > 3) 661 if (size < 2 || size > 3)
663 goto __skip; 662 goto __skip;
664 isapnp_parse_irq_resource(option, size); 663 isapnp_parse_irq_resource(dev, option, size);
665 size = 0; 664 size = 0;
666 break; 665 break;
667 case _STAG_DMA: 666 case _STAG_DMA:
668 if (size != 2) 667 if (size != 2)
669 goto __skip; 668 goto __skip;
670 isapnp_parse_dma_resource(option, size); 669 isapnp_parse_dma_resource(dev, option, size);
671 size = 0; 670 size = 0;
672 break; 671 break;
673 case _STAG_STARTDEP: 672 case _STAG_STARTDEP:
@@ -687,17 +686,18 @@ static int __init isapnp_create_device(struct pnp_card *card,
687 if (size != 0) 686 if (size != 0)
688 goto __skip; 687 goto __skip;
689 priority = 0; 688 priority = 0;
689 dev_dbg(&dev->dev, "end dependent options\n");
690 break; 690 break;
691 case _STAG_IOPORT: 691 case _STAG_IOPORT:
692 if (size != 7) 692 if (size != 7)
693 goto __skip; 693 goto __skip;
694 isapnp_parse_port_resource(option, size); 694 isapnp_parse_port_resource(dev, option, size);
695 size = 0; 695 size = 0;
696 break; 696 break;
697 case _STAG_FIXEDIO: 697 case _STAG_FIXEDIO:
698 if (size != 3) 698 if (size != 3)
699 goto __skip; 699 goto __skip;
700 isapnp_parse_fixed_port_resource(option, size); 700 isapnp_parse_fixed_port_resource(dev, option, size);
701 size = 0; 701 size = 0;
702 break; 702 break;
703 case _STAG_VENDOR: 703 case _STAG_VENDOR:
@@ -705,7 +705,7 @@ static int __init isapnp_create_device(struct pnp_card *card,
705 case _LTAG_MEMRANGE: 705 case _LTAG_MEMRANGE:
706 if (size != 9) 706 if (size != 9)
707 goto __skip; 707 goto __skip;
708 isapnp_parse_mem_resource(option, size); 708 isapnp_parse_mem_resource(dev, option, size);
709 size = 0; 709 size = 0;
710 break; 710 break;
711 case _LTAG_ANSISTR: 711 case _LTAG_ANSISTR:
@@ -720,13 +720,13 @@ static int __init isapnp_create_device(struct pnp_card *card,
720 case _LTAG_MEM32RANGE: 720 case _LTAG_MEM32RANGE:
721 if (size != 17) 721 if (size != 17)
722 goto __skip; 722 goto __skip;
723 isapnp_parse_mem32_resource(option, size); 723 isapnp_parse_mem32_resource(dev, option, size);
724 size = 0; 724 size = 0;
725 break; 725 break;
726 case _LTAG_FIXEDMEM32RANGE: 726 case _LTAG_FIXEDMEM32RANGE:
727 if (size != 9) 727 if (size != 9)
728 goto __skip; 728 goto __skip;
729 isapnp_parse_fixed_mem32_resource(option, size); 729 isapnp_parse_fixed_mem32_resource(dev, option, size);
730 size = 0; 730 size = 0;
731 break; 731 break;
732 case _STAG_END: 732 case _STAG_END:
@@ -734,9 +734,8 @@ static int __init isapnp_create_device(struct pnp_card *card,
734 isapnp_skip_bytes(size); 734 isapnp_skip_bytes(size);
735 return 1; 735 return 1;
736 default: 736 default:
737 printk(KERN_ERR 737 dev_err(&dev->dev, "unknown tag %#x (card %i), "
738 "isapnp: unexpected or unknown tag type 0x%x for logical device %i (device %i), ignored\n", 738 "ignored\n", type, card->number);
739 type, dev->number, card->number);
740 } 739 }
741__skip: 740__skip:
742 if (size > 0) 741 if (size > 0)
@@ -789,9 +788,8 @@ static void __init isapnp_parse_resource_map(struct pnp_card *card)
789 isapnp_skip_bytes(size); 788 isapnp_skip_bytes(size);
790 return; 789 return;
791 default: 790 default:
792 printk(KERN_ERR 791 dev_err(&card->dev, "unknown tag %#x, ignored\n",
793 "isapnp: unexpected or unknown tag type 0x%x for device %i, ignored\n", 792 type);
794 type, card->number);
795 } 793 }
796__skip: 794__skip:
797 if (size > 0) 795 if (size > 0)
@@ -822,25 +820,6 @@ static unsigned char __init isapnp_checksum(unsigned char *data)
822} 820}
823 821
824/* 822/*
825 * Parse EISA id for ISA PnP card.
826 */
827static void isapnp_parse_card_id(struct pnp_card *card, unsigned short vendor,
828 unsigned short device)
829{
830 struct pnp_id *id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
831
832 if (!id)
833 return;
834 sprintf(id->id, "%c%c%c%x%x%x%x",
835 'A' + ((vendor >> 2) & 0x3f) - 1,
836 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
837 'A' + ((vendor >> 8) & 0x1f) - 1,
838 (device >> 4) & 0x0f,
839 device & 0x0f, (device >> 12) & 0x0f, (device >> 8) & 0x0f);
840 pnp_add_card_id(id, card);
841}
842
843/*
844 * Build device list for all present ISA PnP devices. 823 * Build device list for all present ISA PnP devices.
845 */ 824 */
846static int __init isapnp_build_device_list(void) 825static int __init isapnp_build_device_list(void)
@@ -848,6 +827,8 @@ static int __init isapnp_build_device_list(void)
848 int csn; 827 int csn;
849 unsigned char header[9], checksum; 828 unsigned char header[9], checksum;
850 struct pnp_card *card; 829 struct pnp_card *card;
830 u32 eisa_id;
831 char id[8];
851 832
852 isapnp_wait(); 833 isapnp_wait();
853 isapnp_key(); 834 isapnp_key();
@@ -855,32 +836,30 @@ static int __init isapnp_build_device_list(void)
855 isapnp_wake(csn); 836 isapnp_wake(csn);
856 isapnp_peek(header, 9); 837 isapnp_peek(header, 9);
857 checksum = isapnp_checksum(header); 838 checksum = isapnp_checksum(header);
839 eisa_id = header[0] | header[1] << 8 |
840 header[2] << 16 | header[3] << 24;
841 pnp_eisa_id_to_string(eisa_id, id);
842 card = pnp_alloc_card(&isapnp_protocol, csn, id);
843 if (!card)
844 continue;
845
858#if 0 846#if 0
859 printk(KERN_DEBUG 847 dev_info(&card->dev,
860 "vendor: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", 848 "vendor: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
861 header[0], header[1], header[2], header[3], header[4], 849 header[0], header[1], header[2], header[3], header[4],
862 header[5], header[6], header[7], header[8]); 850 header[5], header[6], header[7], header[8]);
863 printk(KERN_DEBUG "checksum = 0x%x\n", checksum); 851 dev_info(&card->dev, "checksum = %#x\n", checksum);
864#endif 852#endif
865 if ((card =
866 kzalloc(sizeof(struct pnp_card), GFP_KERNEL)) == NULL)
867 continue;
868
869 card->number = csn;
870 INIT_LIST_HEAD(&card->devices); 853 INIT_LIST_HEAD(&card->devices);
871 isapnp_parse_card_id(card, (header[1] << 8) | header[0],
872 (header[3] << 8) | header[2]);
873 card->serial = 854 card->serial =
874 (header[7] << 24) | (header[6] << 16) | (header[5] << 8) | 855 (header[7] << 24) | (header[6] << 16) | (header[5] << 8) |
875 header[4]; 856 header[4];
876 isapnp_checksum_value = 0x00; 857 isapnp_checksum_value = 0x00;
877 isapnp_parse_resource_map(card); 858 isapnp_parse_resource_map(card);
878 if (isapnp_checksum_value != 0x00) 859 if (isapnp_checksum_value != 0x00)
879 printk(KERN_ERR 860 dev_err(&card->dev, "invalid checksum %#x\n",
880 "isapnp: checksum for device %i is not valid (0x%x)\n", 861 isapnp_checksum_value);
881 csn, isapnp_checksum_value);
882 card->checksum = isapnp_checksum_value; 862 card->checksum = isapnp_checksum_value;
883 card->protocol = &isapnp_protocol;
884 863
885 pnp_add_card(card); 864 pnp_add_card(card);
886 } 865 }
@@ -947,100 +926,117 @@ EXPORT_SYMBOL(isapnp_cfg_begin);
947EXPORT_SYMBOL(isapnp_cfg_end); 926EXPORT_SYMBOL(isapnp_cfg_end);
948EXPORT_SYMBOL(isapnp_write_byte); 927EXPORT_SYMBOL(isapnp_write_byte);
949 928
950static int isapnp_read_resources(struct pnp_dev *dev, 929static int isapnp_get_resources(struct pnp_dev *dev)
951 struct pnp_resource_table *res)
952{ 930{
953 int tmp, ret; 931 struct pnp_resource *pnp_res;
932 int i, ret;
954 933
934 dev_dbg(&dev->dev, "get resources\n");
935 pnp_init_resources(dev);
936 isapnp_cfg_begin(dev->card->number, dev->number);
955 dev->active = isapnp_read_byte(ISAPNP_CFG_ACTIVATE); 937 dev->active = isapnp_read_byte(ISAPNP_CFG_ACTIVATE);
956 if (dev->active) { 938 if (!dev->active)
957 for (tmp = 0; tmp < ISAPNP_MAX_PORT; tmp++) { 939 goto __end;
958 ret = isapnp_read_word(ISAPNP_CFG_PORT + (tmp << 1)); 940
959 if (!ret) 941 for (i = 0; i < ISAPNP_MAX_PORT; i++) {
960 continue; 942 ret = isapnp_read_word(ISAPNP_CFG_PORT + (i << 1));
961 res->port_resource[tmp].start = ret; 943 if (ret) {
962 res->port_resource[tmp].flags = IORESOURCE_IO; 944 pnp_res = pnp_add_io_resource(dev, ret, ret, 0);
945 if (pnp_res)
946 pnp_res->index = i;
963 } 947 }
964 for (tmp = 0; tmp < ISAPNP_MAX_MEM; tmp++) { 948 }
965 ret = 949 for (i = 0; i < ISAPNP_MAX_MEM; i++) {
966 isapnp_read_word(ISAPNP_CFG_MEM + (tmp << 3)) << 8; 950 ret = isapnp_read_word(ISAPNP_CFG_MEM + (i << 3)) << 8;
967 if (!ret) 951 if (ret) {
968 continue; 952 pnp_res = pnp_add_mem_resource(dev, ret, ret, 0);
969 res->mem_resource[tmp].start = ret; 953 if (pnp_res)
970 res->mem_resource[tmp].flags = IORESOURCE_MEM; 954 pnp_res->index = i;
971 } 955 }
972 for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) { 956 }
973 ret = 957 for (i = 0; i < ISAPNP_MAX_IRQ; i++) {
974 (isapnp_read_word(ISAPNP_CFG_IRQ + (tmp << 1)) >> 958 ret = isapnp_read_word(ISAPNP_CFG_IRQ + (i << 1)) >> 8;
975 8); 959 if (ret) {
976 if (!ret) 960 pnp_res = pnp_add_irq_resource(dev, ret, 0);
977 continue; 961 if (pnp_res)
978 res->irq_resource[tmp].start = 962 pnp_res->index = i;
979 res->irq_resource[tmp].end = ret;
980 res->irq_resource[tmp].flags = IORESOURCE_IRQ;
981 } 963 }
982 for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) { 964 }
983 ret = isapnp_read_byte(ISAPNP_CFG_DMA + tmp); 965 for (i = 0; i < ISAPNP_MAX_DMA; i++) {
984 if (ret == 4) 966 ret = isapnp_read_byte(ISAPNP_CFG_DMA + i);
985 continue; 967 if (ret != 4) {
986 res->dma_resource[tmp].start = 968 pnp_res = pnp_add_dma_resource(dev, ret, 0);
987 res->dma_resource[tmp].end = ret; 969 if (pnp_res)
988 res->dma_resource[tmp].flags = IORESOURCE_DMA; 970 pnp_res->index = i;
989 } 971 }
990 } 972 }
991 return 0;
992}
993
994static int isapnp_get_resources(struct pnp_dev *dev,
995 struct pnp_resource_table *res)
996{
997 int ret;
998 973
999 pnp_init_resource_table(res); 974__end:
1000 isapnp_cfg_begin(dev->card->number, dev->number);
1001 ret = isapnp_read_resources(dev, res);
1002 isapnp_cfg_end(); 975 isapnp_cfg_end();
1003 return ret; 976 return 0;
1004} 977}
1005 978
1006static int isapnp_set_resources(struct pnp_dev *dev, 979static int isapnp_set_resources(struct pnp_dev *dev)
1007 struct pnp_resource_table *res)
1008{ 980{
1009 int tmp; 981 struct pnp_resource *pnp_res;
982 struct resource *res;
983 int tmp, index;
1010 984
985 dev_dbg(&dev->dev, "set resources\n");
1011 isapnp_cfg_begin(dev->card->number, dev->number); 986 isapnp_cfg_begin(dev->card->number, dev->number);
1012 dev->active = 1; 987 dev->active = 1;
1013 for (tmp = 0; 988 for (tmp = 0; tmp < ISAPNP_MAX_PORT; tmp++) {
1014 tmp < ISAPNP_MAX_PORT 989 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IO, tmp);
1015 && (res->port_resource[tmp]. 990 if (!pnp_res)
1016 flags & (IORESOURCE_IO | IORESOURCE_UNSET)) == IORESOURCE_IO; 991 continue;
1017 tmp++) 992 res = &pnp_res->res;
1018 isapnp_write_word(ISAPNP_CFG_PORT + (tmp << 1), 993 if (pnp_resource_valid(res)) {
1019 res->port_resource[tmp].start); 994 index = pnp_res->index;
1020 for (tmp = 0; 995 dev_dbg(&dev->dev, " set io %d to %#llx\n",
1021 tmp < ISAPNP_MAX_IRQ 996 index, (unsigned long long) res->start);
1022 && (res->irq_resource[tmp]. 997 isapnp_write_word(ISAPNP_CFG_PORT + (index << 1),
1023 flags & (IORESOURCE_IRQ | IORESOURCE_UNSET)) == IORESOURCE_IRQ; 998 res->start);
1024 tmp++) { 999 }
1025 int irq = res->irq_resource[tmp].start; 1000 }
1026 if (irq == 2) 1001 for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) {
1027 irq = 9; 1002 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IRQ, tmp);
1028 isapnp_write_byte(ISAPNP_CFG_IRQ + (tmp << 1), irq); 1003 if (!pnp_res)
1004 continue;
1005 res = &pnp_res->res;
1006 if (pnp_resource_valid(res)) {
1007 int irq = res->start;
1008 if (irq == 2)
1009 irq = 9;
1010 index = pnp_res->index;
1011 dev_dbg(&dev->dev, " set irq %d to %d\n", index, irq);
1012 isapnp_write_byte(ISAPNP_CFG_IRQ + (index << 1), irq);
1013 }
1014 }
1015 for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) {
1016 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_DMA, tmp);
1017 if (!pnp_res)
1018 continue;
1019 res = &pnp_res->res;
1020 if (pnp_resource_valid(res)) {
1021 index = pnp_res->index;
1022 dev_dbg(&dev->dev, " set dma %d to %lld\n",
1023 index, (unsigned long long) res->start);
1024 isapnp_write_byte(ISAPNP_CFG_DMA + index, res->start);
1025 }
1026 }
1027 for (tmp = 0; tmp < ISAPNP_MAX_MEM; tmp++) {
1028 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_MEM, tmp);
1029 if (!pnp_res)
1030 continue;
1031 res = &pnp_res->res;
1032 if (pnp_resource_valid(res)) {
1033 index = pnp_res->index;
1034 dev_dbg(&dev->dev, " set mem %d to %#llx\n",
1035 index, (unsigned long long) res->start);
1036 isapnp_write_word(ISAPNP_CFG_MEM + (index << 3),
1037 (res->start >> 8) & 0xffff);
1038 }
1029 } 1039 }
1030 for (tmp = 0;
1031 tmp < ISAPNP_MAX_DMA
1032 && (res->dma_resource[tmp].
1033 flags & (IORESOURCE_DMA | IORESOURCE_UNSET)) == IORESOURCE_DMA;
1034 tmp++)
1035 isapnp_write_byte(ISAPNP_CFG_DMA + tmp,
1036 res->dma_resource[tmp].start);
1037 for (tmp = 0;
1038 tmp < ISAPNP_MAX_MEM
1039 && (res->mem_resource[tmp].
1040 flags & (IORESOURCE_MEM | IORESOURCE_UNSET)) == IORESOURCE_MEM;
1041 tmp++)
1042 isapnp_write_word(ISAPNP_CFG_MEM + (tmp << 3),
1043 (res->mem_resource[tmp].start >> 8) & 0xffff);
1044 /* FIXME: We aren't handling 32bit mems properly here */ 1040 /* FIXME: We aren't handling 32bit mems properly here */
1045 isapnp_activate(dev->number); 1041 isapnp_activate(dev->number);
1046 isapnp_cfg_end(); 1042 isapnp_cfg_end();
@@ -1138,13 +1134,13 @@ static int __init isapnp_init(void)
1138 protocol_for_each_card(&isapnp_protocol, card) { 1134 protocol_for_each_card(&isapnp_protocol, card) {
1139 cards++; 1135 cards++;
1140 if (isapnp_verbose) { 1136 if (isapnp_verbose) {
1141 printk(KERN_INFO "isapnp: Card '%s'\n", 1137 dev_info(&card->dev, "card '%s'\n",
1142 card->name[0] ? card->name : "Unknown"); 1138 card->name[0] ? card->name : "unknown");
1143 if (isapnp_verbose < 2) 1139 if (isapnp_verbose < 2)
1144 continue; 1140 continue;
1145 card_for_each_dev(card, dev) { 1141 card_for_each_dev(card, dev) {
1146 printk(KERN_INFO "isapnp: Device '%s'\n", 1142 dev_info(&card->dev, "device '%s'\n",
1147 dev->name[0] ? dev->name : "Unknown"); 1143 dev->name[0] ? dev->name : "unknown");
1148 } 1144 }
1149 } 1145 }
1150 } 1146 }
diff --git a/drivers/pnp/manager.c b/drivers/pnp/manager.c
index c28caf272c11..bea0914ff947 100644
--- a/drivers/pnp/manager.c
+++ b/drivers/pnp/manager.c
@@ -19,100 +19,118 @@ DEFINE_MUTEX(pnp_res_mutex);
19 19
20static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx) 20static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx)
21{ 21{
22 resource_size_t *start, *end; 22 struct pnp_resource *pnp_res;
23 unsigned long *flags; 23 struct resource *res;
24 24
25 if (idx >= PNP_MAX_PORT) { 25 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IO, idx);
26 if (!pnp_res) {
26 dev_err(&dev->dev, "too many I/O port resources\n"); 27 dev_err(&dev->dev, "too many I/O port resources\n");
27 /* pretend we were successful so at least the manager won't try again */ 28 /* pretend we were successful so at least the manager won't try again */
28 return 1; 29 return 1;
29 } 30 }
30 31
32 res = &pnp_res->res;
33
31 /* check if this resource has been manually set, if so skip */ 34 /* check if this resource has been manually set, if so skip */
32 if (!(dev->res.port_resource[idx].flags & IORESOURCE_AUTO)) 35 if (!(res->flags & IORESOURCE_AUTO)) {
36 dev_dbg(&dev->dev, " io %d already set to %#llx-%#llx "
37 "flags %#lx\n", idx, (unsigned long long) res->start,
38 (unsigned long long) res->end, res->flags);
33 return 1; 39 return 1;
34 40 }
35 start = &dev->res.port_resource[idx].start;
36 end = &dev->res.port_resource[idx].end;
37 flags = &dev->res.port_resource[idx].flags;
38 41
39 /* set the initial values */ 42 /* set the initial values */
40 *flags |= rule->flags | IORESOURCE_IO; 43 pnp_res->index = idx;
41 *flags &= ~IORESOURCE_UNSET; 44 res->flags |= rule->flags | IORESOURCE_IO;
45 res->flags &= ~IORESOURCE_UNSET;
42 46
43 if (!rule->size) { 47 if (!rule->size) {
44 *flags |= IORESOURCE_DISABLED; 48 res->flags |= IORESOURCE_DISABLED;
49 dev_dbg(&dev->dev, " io %d disabled\n", idx);
45 return 1; /* skip disabled resource requests */ 50 return 1; /* skip disabled resource requests */
46 } 51 }
47 52
48 *start = rule->min; 53 res->start = rule->min;
49 *end = *start + rule->size - 1; 54 res->end = res->start + rule->size - 1;
50 55
51 /* run through until pnp_check_port is happy */ 56 /* run through until pnp_check_port is happy */
52 while (!pnp_check_port(dev, idx)) { 57 while (!pnp_check_port(dev, res)) {
53 *start += rule->align; 58 res->start += rule->align;
54 *end = *start + rule->size - 1; 59 res->end = res->start + rule->size - 1;
55 if (*start > rule->max || !rule->align) 60 if (res->start > rule->max || !rule->align) {
61 dev_dbg(&dev->dev, " couldn't assign io %d\n", idx);
56 return 0; 62 return 0;
63 }
57 } 64 }
65 dev_dbg(&dev->dev, " assign io %d %#llx-%#llx\n", idx,
66 (unsigned long long) res->start, (unsigned long long) res->end);
58 return 1; 67 return 1;
59} 68}
60 69
61static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx) 70static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx)
62{ 71{
63 resource_size_t *start, *end; 72 struct pnp_resource *pnp_res;
64 unsigned long *flags; 73 struct resource *res;
65 74
66 if (idx >= PNP_MAX_MEM) { 75 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_MEM, idx);
76 if (!pnp_res) {
67 dev_err(&dev->dev, "too many memory resources\n"); 77 dev_err(&dev->dev, "too many memory resources\n");
68 /* pretend we were successful so at least the manager won't try again */ 78 /* pretend we were successful so at least the manager won't try again */
69 return 1; 79 return 1;
70 } 80 }
71 81
82 res = &pnp_res->res;
83
72 /* check if this resource has been manually set, if so skip */ 84 /* check if this resource has been manually set, if so skip */
73 if (!(dev->res.mem_resource[idx].flags & IORESOURCE_AUTO)) 85 if (!(res->flags & IORESOURCE_AUTO)) {
86 dev_dbg(&dev->dev, " mem %d already set to %#llx-%#llx "
87 "flags %#lx\n", idx, (unsigned long long) res->start,
88 (unsigned long long) res->end, res->flags);
74 return 1; 89 return 1;
75 90 }
76 start = &dev->res.mem_resource[idx].start;
77 end = &dev->res.mem_resource[idx].end;
78 flags = &dev->res.mem_resource[idx].flags;
79 91
80 /* set the initial values */ 92 /* set the initial values */
81 *flags |= rule->flags | IORESOURCE_MEM; 93 pnp_res->index = idx;
82 *flags &= ~IORESOURCE_UNSET; 94 res->flags |= rule->flags | IORESOURCE_MEM;
95 res->flags &= ~IORESOURCE_UNSET;
83 96
84 /* convert pnp flags to standard Linux flags */ 97 /* convert pnp flags to standard Linux flags */
85 if (!(rule->flags & IORESOURCE_MEM_WRITEABLE)) 98 if (!(rule->flags & IORESOURCE_MEM_WRITEABLE))
86 *flags |= IORESOURCE_READONLY; 99 res->flags |= IORESOURCE_READONLY;
87 if (rule->flags & IORESOURCE_MEM_CACHEABLE) 100 if (rule->flags & IORESOURCE_MEM_CACHEABLE)
88 *flags |= IORESOURCE_CACHEABLE; 101 res->flags |= IORESOURCE_CACHEABLE;
89 if (rule->flags & IORESOURCE_MEM_RANGELENGTH) 102 if (rule->flags & IORESOURCE_MEM_RANGELENGTH)
90 *flags |= IORESOURCE_RANGELENGTH; 103 res->flags |= IORESOURCE_RANGELENGTH;
91 if (rule->flags & IORESOURCE_MEM_SHADOWABLE) 104 if (rule->flags & IORESOURCE_MEM_SHADOWABLE)
92 *flags |= IORESOURCE_SHADOWABLE; 105 res->flags |= IORESOURCE_SHADOWABLE;
93 106
94 if (!rule->size) { 107 if (!rule->size) {
95 *flags |= IORESOURCE_DISABLED; 108 res->flags |= IORESOURCE_DISABLED;
109 dev_dbg(&dev->dev, " mem %d disabled\n", idx);
96 return 1; /* skip disabled resource requests */ 110 return 1; /* skip disabled resource requests */
97 } 111 }
98 112
99 *start = rule->min; 113 res->start = rule->min;
100 *end = *start + rule->size - 1; 114 res->end = res->start + rule->size - 1;
101 115
102 /* run through until pnp_check_mem is happy */ 116 /* run through until pnp_check_mem is happy */
103 while (!pnp_check_mem(dev, idx)) { 117 while (!pnp_check_mem(dev, res)) {
104 *start += rule->align; 118 res->start += rule->align;
105 *end = *start + rule->size - 1; 119 res->end = res->start + rule->size - 1;
106 if (*start > rule->max || !rule->align) 120 if (res->start > rule->max || !rule->align) {
121 dev_dbg(&dev->dev, " couldn't assign mem %d\n", idx);
107 return 0; 122 return 0;
123 }
108 } 124 }
125 dev_dbg(&dev->dev, " assign mem %d %#llx-%#llx\n", idx,
126 (unsigned long long) res->start, (unsigned long long) res->end);
109 return 1; 127 return 1;
110} 128}
111 129
112static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx) 130static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx)
113{ 131{
114 resource_size_t *start, *end; 132 struct pnp_resource *pnp_res;
115 unsigned long *flags; 133 struct resource *res;
116 int i; 134 int i;
117 135
118 /* IRQ priority: this table is good for i386 */ 136 /* IRQ priority: this table is good for i386 */
@@ -120,49 +138,59 @@ static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx)
120 5, 10, 11, 12, 9, 14, 15, 7, 3, 4, 13, 0, 1, 6, 8, 2 138 5, 10, 11, 12, 9, 14, 15, 7, 3, 4, 13, 0, 1, 6, 8, 2
121 }; 139 };
122 140
123 if (idx >= PNP_MAX_IRQ) { 141 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IRQ, idx);
142 if (!pnp_res) {
124 dev_err(&dev->dev, "too many IRQ resources\n"); 143 dev_err(&dev->dev, "too many IRQ resources\n");
125 /* pretend we were successful so at least the manager won't try again */ 144 /* pretend we were successful so at least the manager won't try again */
126 return 1; 145 return 1;
127 } 146 }
128 147
148 res = &pnp_res->res;
149
129 /* check if this resource has been manually set, if so skip */ 150 /* check if this resource has been manually set, if so skip */
130 if (!(dev->res.irq_resource[idx].flags & IORESOURCE_AUTO)) 151 if (!(res->flags & IORESOURCE_AUTO)) {
152 dev_dbg(&dev->dev, " irq %d already set to %d flags %#lx\n",
153 idx, (int) res->start, res->flags);
131 return 1; 154 return 1;
132 155 }
133 start = &dev->res.irq_resource[idx].start;
134 end = &dev->res.irq_resource[idx].end;
135 flags = &dev->res.irq_resource[idx].flags;
136 156
137 /* set the initial values */ 157 /* set the initial values */
138 *flags |= rule->flags | IORESOURCE_IRQ; 158 pnp_res->index = idx;
139 *flags &= ~IORESOURCE_UNSET; 159 res->flags |= rule->flags | IORESOURCE_IRQ;
160 res->flags &= ~IORESOURCE_UNSET;
140 161
141 if (bitmap_empty(rule->map, PNP_IRQ_NR)) { 162 if (bitmap_empty(rule->map, PNP_IRQ_NR)) {
142 *flags |= IORESOURCE_DISABLED; 163 res->flags |= IORESOURCE_DISABLED;
164 dev_dbg(&dev->dev, " irq %d disabled\n", idx);
143 return 1; /* skip disabled resource requests */ 165 return 1; /* skip disabled resource requests */
144 } 166 }
145 167
146 /* TBD: need check for >16 IRQ */ 168 /* TBD: need check for >16 IRQ */
147 *start = find_next_bit(rule->map, PNP_IRQ_NR, 16); 169 res->start = find_next_bit(rule->map, PNP_IRQ_NR, 16);
148 if (*start < PNP_IRQ_NR) { 170 if (res->start < PNP_IRQ_NR) {
149 *end = *start; 171 res->end = res->start;
172 dev_dbg(&dev->dev, " assign irq %d %d\n", idx,
173 (int) res->start);
150 return 1; 174 return 1;
151 } 175 }
152 for (i = 0; i < 16; i++) { 176 for (i = 0; i < 16; i++) {
153 if (test_bit(xtab[i], rule->map)) { 177 if (test_bit(xtab[i], rule->map)) {
154 *start = *end = xtab[i]; 178 res->start = res->end = xtab[i];
155 if (pnp_check_irq(dev, idx)) 179 if (pnp_check_irq(dev, res)) {
180 dev_dbg(&dev->dev, " assign irq %d %d\n", idx,
181 (int) res->start);
156 return 1; 182 return 1;
183 }
157 } 184 }
158 } 185 }
186 dev_dbg(&dev->dev, " couldn't assign irq %d\n", idx);
159 return 0; 187 return 0;
160} 188}
161 189
162static void pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx) 190static void pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)
163{ 191{
164 resource_size_t *start, *end; 192 struct pnp_resource *pnp_res;
165 unsigned long *flags; 193 struct resource *res;
166 int i; 194 int i;
167 195
168 /* DMA priority: this table is good for i386 */ 196 /* DMA priority: this table is good for i386 */
@@ -170,71 +198,89 @@ static void pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)
170 1, 3, 5, 6, 7, 0, 2, 4 198 1, 3, 5, 6, 7, 0, 2, 4
171 }; 199 };
172 200
173 if (idx >= PNP_MAX_DMA) { 201 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_DMA, idx);
202 if (!pnp_res) {
174 dev_err(&dev->dev, "too many DMA resources\n"); 203 dev_err(&dev->dev, "too many DMA resources\n");
175 return; 204 return;
176 } 205 }
177 206
207 res = &pnp_res->res;
208
178 /* check if this resource has been manually set, if so skip */ 209 /* check if this resource has been manually set, if so skip */
179 if (!(dev->res.dma_resource[idx].flags & IORESOURCE_AUTO)) 210 if (!(res->flags & IORESOURCE_AUTO)) {
211 dev_dbg(&dev->dev, " dma %d already set to %d flags %#lx\n",
212 idx, (int) res->start, res->flags);
180 return; 213 return;
181 214 }
182 start = &dev->res.dma_resource[idx].start;
183 end = &dev->res.dma_resource[idx].end;
184 flags = &dev->res.dma_resource[idx].flags;
185 215
186 /* set the initial values */ 216 /* set the initial values */
187 *flags |= rule->flags | IORESOURCE_DMA; 217 pnp_res->index = idx;
188 *flags &= ~IORESOURCE_UNSET; 218 res->flags |= rule->flags | IORESOURCE_DMA;
219 res->flags &= ~IORESOURCE_UNSET;
189 220
190 for (i = 0; i < 8; i++) { 221 for (i = 0; i < 8; i++) {
191 if (rule->map & (1 << xtab[i])) { 222 if (rule->map & (1 << xtab[i])) {
192 *start = *end = xtab[i]; 223 res->start = res->end = xtab[i];
193 if (pnp_check_dma(dev, idx)) 224 if (pnp_check_dma(dev, res)) {
225 dev_dbg(&dev->dev, " assign dma %d %d\n", idx,
226 (int) res->start);
194 return; 227 return;
228 }
195 } 229 }
196 } 230 }
197#ifdef MAX_DMA_CHANNELS 231#ifdef MAX_DMA_CHANNELS
198 *start = *end = MAX_DMA_CHANNELS; 232 res->start = res->end = MAX_DMA_CHANNELS;
199#endif 233#endif
200 *flags |= IORESOURCE_UNSET | IORESOURCE_DISABLED; 234 res->flags |= IORESOURCE_UNSET | IORESOURCE_DISABLED;
235 dev_dbg(&dev->dev, " disable dma %d\n", idx);
236}
237
238void pnp_init_resource(struct resource *res)
239{
240 unsigned long type;
241
242 type = res->flags & (IORESOURCE_IO | IORESOURCE_MEM |
243 IORESOURCE_IRQ | IORESOURCE_DMA);
244
245 res->name = NULL;
246 res->flags = type | IORESOURCE_AUTO | IORESOURCE_UNSET;
247 if (type == IORESOURCE_IRQ || type == IORESOURCE_DMA) {
248 res->start = -1;
249 res->end = -1;
250 } else {
251 res->start = 0;
252 res->end = 0;
253 }
201} 254}
202 255
203/** 256/**
204 * pnp_init_resources - Resets a resource table to default values. 257 * pnp_init_resources - Resets a resource table to default values.
205 * @table: pointer to the desired resource table 258 * @table: pointer to the desired resource table
206 */ 259 */
207void pnp_init_resource_table(struct pnp_resource_table *table) 260void pnp_init_resources(struct pnp_dev *dev)
208{ 261{
262 struct resource *res;
209 int idx; 263 int idx;
210 264
211 for (idx = 0; idx < PNP_MAX_IRQ; idx++) { 265 for (idx = 0; idx < PNP_MAX_IRQ; idx++) {
212 table->irq_resource[idx].name = NULL; 266 res = &dev->res->irq[idx].res;
213 table->irq_resource[idx].start = -1; 267 res->flags = IORESOURCE_IRQ;
214 table->irq_resource[idx].end = -1; 268 pnp_init_resource(res);
215 table->irq_resource[idx].flags =
216 IORESOURCE_IRQ | IORESOURCE_AUTO | IORESOURCE_UNSET;
217 } 269 }
218 for (idx = 0; idx < PNP_MAX_DMA; idx++) { 270 for (idx = 0; idx < PNP_MAX_DMA; idx++) {
219 table->dma_resource[idx].name = NULL; 271 res = &dev->res->dma[idx].res;
220 table->dma_resource[idx].start = -1; 272 res->flags = IORESOURCE_DMA;
221 table->dma_resource[idx].end = -1; 273 pnp_init_resource(res);
222 table->dma_resource[idx].flags =
223 IORESOURCE_DMA | IORESOURCE_AUTO | IORESOURCE_UNSET;
224 } 274 }
225 for (idx = 0; idx < PNP_MAX_PORT; idx++) { 275 for (idx = 0; idx < PNP_MAX_PORT; idx++) {
226 table->port_resource[idx].name = NULL; 276 res = &dev->res->port[idx].res;
227 table->port_resource[idx].start = 0; 277 res->flags = IORESOURCE_IO;
228 table->port_resource[idx].end = 0; 278 pnp_init_resource(res);
229 table->port_resource[idx].flags =
230 IORESOURCE_IO | IORESOURCE_AUTO | IORESOURCE_UNSET;
231 } 279 }
232 for (idx = 0; idx < PNP_MAX_MEM; idx++) { 280 for (idx = 0; idx < PNP_MAX_MEM; idx++) {
233 table->mem_resource[idx].name = NULL; 281 res = &dev->res->mem[idx].res;
234 table->mem_resource[idx].start = 0; 282 res->flags = IORESOURCE_MEM;
235 table->mem_resource[idx].end = 0; 283 pnp_init_resource(res);
236 table->mem_resource[idx].flags =
237 IORESOURCE_MEM | IORESOURCE_AUTO | IORESOURCE_UNSET;
238 } 284 }
239} 285}
240 286
@@ -242,41 +288,38 @@ void pnp_init_resource_table(struct pnp_resource_table *table)
242 * pnp_clean_resources - clears resources that were not manually set 288 * pnp_clean_resources - clears resources that were not manually set
243 * @res: the resources to clean 289 * @res: the resources to clean
244 */ 290 */
245static void pnp_clean_resource_table(struct pnp_resource_table *res) 291static void pnp_clean_resource_table(struct pnp_dev *dev)
246{ 292{
293 struct resource *res;
247 int idx; 294 int idx;
248 295
249 for (idx = 0; idx < PNP_MAX_IRQ; idx++) { 296 for (idx = 0; idx < PNP_MAX_IRQ; idx++) {
250 if (!(res->irq_resource[idx].flags & IORESOURCE_AUTO)) 297 res = &dev->res->irq[idx].res;
251 continue; 298 if (res->flags & IORESOURCE_AUTO) {
252 res->irq_resource[idx].start = -1; 299 res->flags = IORESOURCE_IRQ;
253 res->irq_resource[idx].end = -1; 300 pnp_init_resource(res);
254 res->irq_resource[idx].flags = 301 }
255 IORESOURCE_IRQ | IORESOURCE_AUTO | IORESOURCE_UNSET;
256 } 302 }
257 for (idx = 0; idx < PNP_MAX_DMA; idx++) { 303 for (idx = 0; idx < PNP_MAX_DMA; idx++) {
258 if (!(res->dma_resource[idx].flags & IORESOURCE_AUTO)) 304 res = &dev->res->dma[idx].res;
259 continue; 305 if (res->flags & IORESOURCE_AUTO) {
260 res->dma_resource[idx].start = -1; 306 res->flags = IORESOURCE_DMA;
261 res->dma_resource[idx].end = -1; 307 pnp_init_resource(res);
262 res->dma_resource[idx].flags = 308 }
263 IORESOURCE_DMA | IORESOURCE_AUTO | IORESOURCE_UNSET;
264 } 309 }
265 for (idx = 0; idx < PNP_MAX_PORT; idx++) { 310 for (idx = 0; idx < PNP_MAX_PORT; idx++) {
266 if (!(res->port_resource[idx].flags & IORESOURCE_AUTO)) 311 res = &dev->res->port[idx].res;
267 continue; 312 if (res->flags & IORESOURCE_AUTO) {
268 res->port_resource[idx].start = 0; 313 res->flags = IORESOURCE_IO;
269 res->port_resource[idx].end = 0; 314 pnp_init_resource(res);
270 res->port_resource[idx].flags = 315 }
271 IORESOURCE_IO | IORESOURCE_AUTO | IORESOURCE_UNSET;
272 } 316 }
273 for (idx = 0; idx < PNP_MAX_MEM; idx++) { 317 for (idx = 0; idx < PNP_MAX_MEM; idx++) {
274 if (!(res->mem_resource[idx].flags & IORESOURCE_AUTO)) 318 res = &dev->res->mem[idx].res;
275 continue; 319 if (res->flags & IORESOURCE_AUTO) {
276 res->mem_resource[idx].start = 0; 320 res->flags = IORESOURCE_MEM;
277 res->mem_resource[idx].end = 0; 321 pnp_init_resource(res);
278 res->mem_resource[idx].flags = 322 }
279 IORESOURCE_MEM | IORESOURCE_AUTO | IORESOURCE_UNSET;
280 } 323 }
281} 324}
282 325
@@ -298,9 +341,11 @@ static int pnp_assign_resources(struct pnp_dev *dev, int depnum)
298 if (!pnp_can_configure(dev)) 341 if (!pnp_can_configure(dev))
299 return -ENODEV; 342 return -ENODEV;
300 343
344 dbg_pnp_show_resources(dev, "before pnp_assign_resources");
301 mutex_lock(&pnp_res_mutex); 345 mutex_lock(&pnp_res_mutex);
302 pnp_clean_resource_table(&dev->res); /* start with a fresh slate */ 346 pnp_clean_resource_table(dev);
303 if (dev->independent) { 347 if (dev->independent) {
348 dev_dbg(&dev->dev, "assigning independent options\n");
304 port = dev->independent->port; 349 port = dev->independent->port;
305 mem = dev->independent->mem; 350 mem = dev->independent->mem;
306 irq = dev->independent->irq; 351 irq = dev->independent->irq;
@@ -333,6 +378,8 @@ static int pnp_assign_resources(struct pnp_dev *dev, int depnum)
333 if (depnum) { 378 if (depnum) {
334 struct pnp_option *dep; 379 struct pnp_option *dep;
335 int i; 380 int i;
381
382 dev_dbg(&dev->dev, "assigning dependent option %d\n", depnum);
336 for (i = 1, dep = dev->dependent; i < depnum; 383 for (i = 1, dep = dev->dependent; i < depnum;
337 i++, dep = dep->next) 384 i++, dep = dep->next)
338 if (!dep) 385 if (!dep)
@@ -368,68 +415,17 @@ static int pnp_assign_resources(struct pnp_dev *dev, int depnum)
368 goto fail; 415 goto fail;
369 416
370 mutex_unlock(&pnp_res_mutex); 417 mutex_unlock(&pnp_res_mutex);
418 dbg_pnp_show_resources(dev, "after pnp_assign_resources");
371 return 1; 419 return 1;
372 420
373fail: 421fail:
374 pnp_clean_resource_table(&dev->res); 422 pnp_clean_resource_table(dev);
375 mutex_unlock(&pnp_res_mutex); 423 mutex_unlock(&pnp_res_mutex);
424 dbg_pnp_show_resources(dev, "after pnp_assign_resources (failed)");
376 return 0; 425 return 0;
377} 426}
378 427
379/** 428/**
380 * pnp_manual_config_dev - Disables Auto Config and Manually sets the resource table
381 * @dev: pointer to the desired device
382 * @res: pointer to the new resource config
383 * @mode: 0 or PNP_CONFIG_FORCE
384 *
385 * This function can be used by drivers that want to manually set thier resources.
386 */
387int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res,
388 int mode)
389{
390 int i;
391 struct pnp_resource_table *bak;
392
393 if (!pnp_can_configure(dev))
394 return -ENODEV;
395 bak = pnp_alloc(sizeof(struct pnp_resource_table));
396 if (!bak)
397 return -ENOMEM;
398 *bak = dev->res;
399
400 mutex_lock(&pnp_res_mutex);
401 dev->res = *res;
402 if (!(mode & PNP_CONFIG_FORCE)) {
403 for (i = 0; i < PNP_MAX_PORT; i++) {
404 if (!pnp_check_port(dev, i))
405 goto fail;
406 }
407 for (i = 0; i < PNP_MAX_MEM; i++) {
408 if (!pnp_check_mem(dev, i))
409 goto fail;
410 }
411 for (i = 0; i < PNP_MAX_IRQ; i++) {
412 if (!pnp_check_irq(dev, i))
413 goto fail;
414 }
415 for (i = 0; i < PNP_MAX_DMA; i++) {
416 if (!pnp_check_dma(dev, i))
417 goto fail;
418 }
419 }
420 mutex_unlock(&pnp_res_mutex);
421
422 kfree(bak);
423 return 0;
424
425fail:
426 dev->res = *bak;
427 mutex_unlock(&pnp_res_mutex);
428 kfree(bak);
429 return -EINVAL;
430}
431
432/**
433 * pnp_auto_config_dev - automatically assigns resources to a device 429 * pnp_auto_config_dev - automatically assigns resources to a device
434 * @dev: pointer to the desired device 430 * @dev: pointer to the desired device
435 */ 431 */
@@ -473,7 +469,8 @@ int pnp_start_dev(struct pnp_dev *dev)
473 return -EINVAL; 469 return -EINVAL;
474 } 470 }
475 471
476 if (dev->protocol->set(dev, &dev->res) < 0) { 472 dbg_pnp_show_resources(dev, "pnp_start_dev");
473 if (dev->protocol->set(dev) < 0) {
477 dev_err(&dev->dev, "activation failed\n"); 474 dev_err(&dev->dev, "activation failed\n");
478 return -EIO; 475 return -EIO;
479 } 476 }
@@ -549,30 +546,13 @@ int pnp_disable_dev(struct pnp_dev *dev)
549 546
550 /* release the resources so that other devices can use them */ 547 /* release the resources so that other devices can use them */
551 mutex_lock(&pnp_res_mutex); 548 mutex_lock(&pnp_res_mutex);
552 pnp_clean_resource_table(&dev->res); 549 pnp_clean_resource_table(dev);
553 mutex_unlock(&pnp_res_mutex); 550 mutex_unlock(&pnp_res_mutex);
554 551
555 return 0; 552 return 0;
556} 553}
557 554
558/**
559 * pnp_resource_change - change one resource
560 * @resource: pointer to resource to be changed
561 * @start: start of region
562 * @size: size of region
563 */
564void pnp_resource_change(struct resource *resource, resource_size_t start,
565 resource_size_t size)
566{
567 resource->flags &= ~(IORESOURCE_AUTO | IORESOURCE_UNSET);
568 resource->start = start;
569 resource->end = start + size - 1;
570}
571
572EXPORT_SYMBOL(pnp_manual_config_dev);
573EXPORT_SYMBOL(pnp_start_dev); 555EXPORT_SYMBOL(pnp_start_dev);
574EXPORT_SYMBOL(pnp_stop_dev); 556EXPORT_SYMBOL(pnp_stop_dev);
575EXPORT_SYMBOL(pnp_activate_dev); 557EXPORT_SYMBOL(pnp_activate_dev);
576EXPORT_SYMBOL(pnp_disable_dev); 558EXPORT_SYMBOL(pnp_disable_dev);
577EXPORT_SYMBOL(pnp_resource_change);
578EXPORT_SYMBOL(pnp_init_resource_table);
diff --git a/drivers/pnp/pnpacpi/Makefile b/drivers/pnp/pnpacpi/Makefile
index 905326fcca85..2d7a1e6908be 100644
--- a/drivers/pnp/pnpacpi/Makefile
+++ b/drivers/pnp/pnpacpi/Makefile
@@ -3,3 +3,7 @@
3# 3#
4 4
5obj-y := core.o rsparser.o 5obj-y := core.o rsparser.o
6
7ifeq ($(CONFIG_PNP_DEBUG),y)
8EXTRA_CFLAGS += -DDEBUG
9endif
diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c
index c283a9a70d83..50902773beaf 100644
--- a/drivers/pnp/pnpacpi/core.c
+++ b/drivers/pnp/pnpacpi/core.c
@@ -25,6 +25,7 @@
25#include <acpi/acpi_bus.h> 25#include <acpi/acpi_bus.h>
26#include <acpi/actypes.h> 26#include <acpi/actypes.h>
27 27
28#include "../base.h"
28#include "pnpacpi.h" 29#include "pnpacpi.h"
29 30
30static int num = 0; 31static int num = 0;
@@ -44,7 +45,7 @@ static struct acpi_device_id excluded_id_list[] __initdata = {
44 {"", 0}, 45 {"", 0},
45}; 46};
46 47
47static inline int is_exclusive_device(struct acpi_device *dev) 48static inline int __init is_exclusive_device(struct acpi_device *dev)
48{ 49{
49 return (!acpi_match_device_ids(dev, excluded_id_list)); 50 return (!acpi_match_device_ids(dev, excluded_id_list));
50} 51}
@@ -72,40 +73,24 @@ static int __init ispnpidacpi(char *id)
72 return 1; 73 return 1;
73} 74}
74 75
75static void __init pnpidacpi_to_pnpid(char *id, char *str) 76static int pnpacpi_get_resources(struct pnp_dev *dev)
76{ 77{
77 str[0] = id[0]; 78 dev_dbg(&dev->dev, "get resources\n");
78 str[1] = id[1]; 79 return pnpacpi_parse_allocated_resource(dev);
79 str[2] = id[2];
80 str[3] = tolower(id[3]);
81 str[4] = tolower(id[4]);
82 str[5] = tolower(id[5]);
83 str[6] = tolower(id[6]);
84 str[7] = '\0';
85} 80}
86 81
87static int pnpacpi_get_resources(struct pnp_dev *dev, 82static int pnpacpi_set_resources(struct pnp_dev *dev)
88 struct pnp_resource_table *res)
89{
90 acpi_status status;
91
92 status = pnpacpi_parse_allocated_resource((acpi_handle) dev->data,
93 &dev->res);
94 return ACPI_FAILURE(status) ? -ENODEV : 0;
95}
96
97static int pnpacpi_set_resources(struct pnp_dev *dev,
98 struct pnp_resource_table *res)
99{ 83{
100 acpi_handle handle = dev->data; 84 acpi_handle handle = dev->data;
101 struct acpi_buffer buffer; 85 struct acpi_buffer buffer;
102 int ret = 0; 86 int ret;
103 acpi_status status; 87 acpi_status status;
104 88
105 ret = pnpacpi_build_resource_template(handle, &buffer); 89 dev_dbg(&dev->dev, "set resources\n");
90 ret = pnpacpi_build_resource_template(dev, &buffer);
106 if (ret) 91 if (ret)
107 return ret; 92 return ret;
108 ret = pnpacpi_encode_resources(res, &buffer); 93 ret = pnpacpi_encode_resources(dev, &buffer);
109 if (ret) { 94 if (ret) {
110 kfree(buffer.pointer); 95 kfree(buffer.pointer);
111 return ret; 96 return ret;
@@ -163,7 +148,6 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
163{ 148{
164 acpi_handle temp = NULL; 149 acpi_handle temp = NULL;
165 acpi_status status; 150 acpi_status status;
166 struct pnp_id *dev_id;
167 struct pnp_dev *dev; 151 struct pnp_dev *dev;
168 152
169 status = acpi_get_handle(device->handle, "_CRS", &temp); 153 status = acpi_get_handle(device->handle, "_CRS", &temp);
@@ -171,11 +155,10 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
171 is_exclusive_device(device)) 155 is_exclusive_device(device))
172 return 0; 156 return 0;
173 157
174 dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL); 158 dev = pnp_alloc_dev(&pnpacpi_protocol, num, acpi_device_hid(device));
175 if (!dev) { 159 if (!dev)
176 pnp_err("Out of memory");
177 return -ENOMEM; 160 return -ENOMEM;
178 } 161
179 dev->data = device->handle; 162 dev->data = device->handle;
180 /* .enabled means the device can decode the resources */ 163 /* .enabled means the device can decode the resources */
181 dev->active = device->status.enabled; 164 dev->active = device->status.enabled;
@@ -191,44 +174,17 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
191 if (ACPI_SUCCESS(status)) 174 if (ACPI_SUCCESS(status))
192 dev->capabilities |= PNP_DISABLE; 175 dev->capabilities |= PNP_DISABLE;
193 176
194 dev->protocol = &pnpacpi_protocol;
195
196 if (strlen(acpi_device_name(device))) 177 if (strlen(acpi_device_name(device)))
197 strncpy(dev->name, acpi_device_name(device), sizeof(dev->name)); 178 strncpy(dev->name, acpi_device_name(device), sizeof(dev->name));
198 else 179 else
199 strncpy(dev->name, acpi_device_bid(device), sizeof(dev->name)); 180 strncpy(dev->name, acpi_device_bid(device), sizeof(dev->name));
200 181
201 dev->number = num; 182 if (dev->active)
202 183 pnpacpi_parse_allocated_resource(dev);
203 /* set the initial values for the PnP device */
204 dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
205 if (!dev_id)
206 goto err;
207 pnpidacpi_to_pnpid(acpi_device_hid(device), dev_id->id);
208 pnp_add_id(dev_id, dev);
209
210 if (dev->active) {
211 /* parse allocated resource */
212 status = pnpacpi_parse_allocated_resource(device->handle,
213 &dev->res);
214 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
215 pnp_err("PnPACPI: METHOD_NAME__CRS failure for %s",
216 dev_id->id);
217 goto err1;
218 }
219 }
220 184
221 if (dev->capabilities & PNP_CONFIGURABLE) { 185 if (dev->capabilities & PNP_CONFIGURABLE)
222 status = pnpacpi_parse_resource_option_data(device->handle, 186 pnpacpi_parse_resource_option_data(dev);
223 dev);
224 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
225 pnp_err("PnPACPI: METHOD_NAME__PRS failure for %s",
226 dev_id->id);
227 goto err1;
228 }
229 }
230 187
231 /* parse compatible ids */
232 if (device->flags.compatible_ids) { 188 if (device->flags.compatible_ids) {
233 struct acpi_compatible_id_list *cid_list = device->pnp.cid_list; 189 struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
234 int i; 190 int i;
@@ -236,27 +192,17 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
236 for (i = 0; i < cid_list->count; i++) { 192 for (i = 0; i < cid_list->count; i++) {
237 if (!ispnpidacpi(cid_list->id[i].value)) 193 if (!ispnpidacpi(cid_list->id[i].value))
238 continue; 194 continue;
239 dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL); 195 pnp_add_id(dev, cid_list->id[i].value);
240 if (!dev_id)
241 continue;
242
243 pnpidacpi_to_pnpid(cid_list->id[i].value, dev_id->id);
244 pnp_add_id(dev_id, dev);
245 } 196 }
246 } 197 }
247 198
248 /* clear out the damaged flags */ 199 /* clear out the damaged flags */
249 if (!dev->active) 200 if (!dev->active)
250 pnp_init_resource_table(&dev->res); 201 pnp_init_resources(dev);
251 pnp_add_device(dev); 202 pnp_add_device(dev);
252 num++; 203 num++;
253 204
254 return AE_OK; 205 return AE_OK;
255err1:
256 kfree(dev_id);
257err:
258 kfree(dev);
259 return -EINVAL;
260} 206}
261 207
262static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle, 208static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle,
diff --git a/drivers/pnp/pnpacpi/pnpacpi.h b/drivers/pnp/pnpacpi/pnpacpi.h
index f28e2ed66fa3..3e60225b0227 100644
--- a/drivers/pnp/pnpacpi/pnpacpi.h
+++ b/drivers/pnp/pnpacpi/pnpacpi.h
@@ -5,8 +5,8 @@
5#include <linux/acpi.h> 5#include <linux/acpi.h>
6#include <linux/pnp.h> 6#include <linux/pnp.h>
7 7
8acpi_status pnpacpi_parse_allocated_resource(acpi_handle, struct pnp_resource_table*); 8int pnpacpi_parse_allocated_resource(struct pnp_dev *);
9acpi_status pnpacpi_parse_resource_option_data(acpi_handle, struct pnp_dev*); 9int pnpacpi_parse_resource_option_data(struct pnp_dev *);
10int pnpacpi_encode_resources(struct pnp_resource_table *, struct acpi_buffer *); 10int pnpacpi_encode_resources(struct pnp_dev *, struct acpi_buffer *);
11int pnpacpi_build_resource_template(acpi_handle, struct acpi_buffer*); 11int pnpacpi_build_resource_template(struct pnp_dev *, struct acpi_buffer *);
12#endif 12#endif
diff --git a/drivers/pnp/pnpacpi/rsparser.c b/drivers/pnp/pnpacpi/rsparser.c
index 98cbc9f18eed..0201c8adfda7 100644
--- a/drivers/pnp/pnpacpi/rsparser.c
+++ b/drivers/pnp/pnpacpi/rsparser.c
@@ -21,6 +21,8 @@
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/acpi.h> 22#include <linux/acpi.h>
23#include <linux/pci.h> 23#include <linux/pci.h>
24#include <linux/pnp.h>
25#include "../base.h"
24#include "pnpacpi.h" 26#include "pnpacpi.h"
25 27
26#ifdef CONFIG_IA64 28#ifdef CONFIG_IA64
@@ -32,19 +34,26 @@
32/* 34/*
33 * Allocated Resources 35 * Allocated Resources
34 */ 36 */
35static int irq_flags(int triggering, int polarity) 37static int irq_flags(int triggering, int polarity, int shareable)
36{ 38{
39 int flags;
40
37 if (triggering == ACPI_LEVEL_SENSITIVE) { 41 if (triggering == ACPI_LEVEL_SENSITIVE) {
38 if (polarity == ACPI_ACTIVE_LOW) 42 if (polarity == ACPI_ACTIVE_LOW)
39 return IORESOURCE_IRQ_LOWLEVEL; 43 flags = IORESOURCE_IRQ_LOWLEVEL;
40 else 44 else
41 return IORESOURCE_IRQ_HIGHLEVEL; 45 flags = IORESOURCE_IRQ_HIGHLEVEL;
42 } else { 46 } else {
43 if (polarity == ACPI_ACTIVE_LOW) 47 if (polarity == ACPI_ACTIVE_LOW)
44 return IORESOURCE_IRQ_LOWEDGE; 48 flags = IORESOURCE_IRQ_LOWEDGE;
45 else 49 else
46 return IORESOURCE_IRQ_HIGHEDGE; 50 flags = IORESOURCE_IRQ_HIGHEDGE;
47 } 51 }
52
53 if (shareable)
54 flags |= IORESOURCE_IRQ_SHAREABLE;
55
56 return flags;
48} 57}
49 58
50static void decode_irq_flags(int flag, int *triggering, int *polarity) 59static void decode_irq_flags(int flag, int *triggering, int *polarity)
@@ -69,29 +78,16 @@ static void decode_irq_flags(int flag, int *triggering, int *polarity)
69 } 78 }
70} 79}
71 80
72static void pnpacpi_parse_allocated_irqresource(struct pnp_resource_table *res, 81static void pnpacpi_parse_allocated_irqresource(struct pnp_dev *dev,
73 u32 gsi, int triggering, 82 u32 gsi, int triggering,
74 int polarity, int shareable) 83 int polarity, int shareable)
75{ 84{
76 int i = 0; 85 int irq, flags;
77 int irq;
78 int p, t; 86 int p, t;
79 static unsigned char warned;
80 87
81 if (!valid_IRQ(gsi)) 88 if (!valid_IRQ(gsi))
82 return; 89 return;
83 90
84 while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) &&
85 i < PNP_MAX_IRQ)
86 i++;
87 if (i >= PNP_MAX_IRQ) {
88 if (!warned) {
89 printk(KERN_WARNING "pnpacpi: exceeded the max number"
90 " of IRQ resources: %d\n", PNP_MAX_IRQ);
91 warned = 1;
92 }
93 return;
94 }
95 /* 91 /*
96 * in IO-APIC mode, use overrided attribute. Two reasons: 92 * in IO-APIC mode, use overrided attribute. Two reasons:
97 * 1. BIOS bug in DSDT 93 * 1. BIOS bug in DSDT
@@ -102,27 +98,21 @@ static void pnpacpi_parse_allocated_irqresource(struct pnp_resource_table *res,
102 p = p ? ACPI_ACTIVE_LOW : ACPI_ACTIVE_HIGH; 98 p = p ? ACPI_ACTIVE_LOW : ACPI_ACTIVE_HIGH;
103 99
104 if (triggering != t || polarity != p) { 100 if (triggering != t || polarity != p) {
105 pnp_warn("IRQ %d override to %s, %s", 101 dev_warn(&dev->dev, "IRQ %d override to %s, %s\n",
106 gsi, t ? "edge":"level", p ? "low":"high"); 102 gsi, t ? "edge":"level", p ? "low":"high");
107 triggering = t; 103 triggering = t;
108 polarity = p; 104 polarity = p;
109 } 105 }
110 } 106 }
111 107
112 res->irq_resource[i].flags = IORESOURCE_IRQ; // Also clears _UNSET flag 108 flags = irq_flags(triggering, polarity, shareable);
113 res->irq_resource[i].flags |= irq_flags(triggering, polarity);
114 irq = acpi_register_gsi(gsi, triggering, polarity); 109 irq = acpi_register_gsi(gsi, triggering, polarity);
115 if (irq < 0) { 110 if (irq >= 0)
116 res->irq_resource[i].flags |= IORESOURCE_DISABLED; 111 pcibios_penalize_isa_irq(irq, 1);
117 return; 112 else
118 } 113 flags |= IORESOURCE_DISABLED;
119
120 if (shareable)
121 res->irq_resource[i].flags |= IORESOURCE_IRQ_SHAREABLE;
122 114
123 res->irq_resource[i].start = irq; 115 pnp_add_irq_resource(dev, irq, flags);
124 res->irq_resource[i].end = irq;
125 pcibios_penalize_isa_irq(irq, 1);
126} 116}
127 117
128static int dma_flags(int type, int bus_master, int transfer) 118static int dma_flags(int type, int bus_master, int transfer)
@@ -168,88 +158,36 @@ static int dma_flags(int type, int bus_master, int transfer)
168 return flags; 158 return flags;
169} 159}
170 160
171static void pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table *res, 161static void pnpacpi_parse_allocated_ioresource(struct pnp_dev *dev, u64 start,
172 u32 dma, int type, 162 u64 len, int io_decode)
173 int bus_master, int transfer)
174{ 163{
175 int i = 0; 164 int flags = 0;
176 static unsigned char warned; 165 u64 end = start + len - 1;
177
178 while (i < PNP_MAX_DMA &&
179 !(res->dma_resource[i].flags & IORESOURCE_UNSET))
180 i++;
181 if (i < PNP_MAX_DMA) {
182 res->dma_resource[i].flags = IORESOURCE_DMA; // Also clears _UNSET flag
183 res->dma_resource[i].flags |=
184 dma_flags(type, bus_master, transfer);
185 if (dma == -1) {
186 res->dma_resource[i].flags |= IORESOURCE_DISABLED;
187 return;
188 }
189 res->dma_resource[i].start = dma;
190 res->dma_resource[i].end = dma;
191 } else if (!warned) {
192 printk(KERN_WARNING "pnpacpi: exceeded the max number of DMA "
193 "resources: %d \n", PNP_MAX_DMA);
194 warned = 1;
195 }
196}
197 166
198static void pnpacpi_parse_allocated_ioresource(struct pnp_resource_table *res, 167 if (io_decode == ACPI_DECODE_16)
199 u64 io, u64 len, int io_decode) 168 flags |= PNP_PORT_FLAG_16BITADDR;
200{ 169 if (len == 0 || end >= 0x10003)
201 int i = 0; 170 flags |= IORESOURCE_DISABLED;
202 static unsigned char warned;
203 171
204 while (!(res->port_resource[i].flags & IORESOURCE_UNSET) && 172 pnp_add_io_resource(dev, start, end, flags);
205 i < PNP_MAX_PORT)
206 i++;
207 if (i < PNP_MAX_PORT) {
208 res->port_resource[i].flags = IORESOURCE_IO; // Also clears _UNSET flag
209 if (io_decode == ACPI_DECODE_16)
210 res->port_resource[i].flags |= PNP_PORT_FLAG_16BITADDR;
211 if (len <= 0 || (io + len - 1) >= 0x10003) {
212 res->port_resource[i].flags |= IORESOURCE_DISABLED;
213 return;
214 }
215 res->port_resource[i].start = io;
216 res->port_resource[i].end = io + len - 1;
217 } else if (!warned) {
218 printk(KERN_WARNING "pnpacpi: exceeded the max number of IO "
219 "resources: %d \n", PNP_MAX_PORT);
220 warned = 1;
221 }
222} 173}
223 174
224static void pnpacpi_parse_allocated_memresource(struct pnp_resource_table *res, 175static void pnpacpi_parse_allocated_memresource(struct pnp_dev *dev,
225 u64 mem, u64 len, 176 u64 start, u64 len,
226 int write_protect) 177 int write_protect)
227{ 178{
228 int i = 0; 179 int flags = 0;
229 static unsigned char warned; 180 u64 end = start + len - 1;
230 181
231 while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) && 182 if (len == 0)
232 (i < PNP_MAX_MEM)) 183 flags |= IORESOURCE_DISABLED;
233 i++; 184 if (write_protect == ACPI_READ_WRITE_MEMORY)
234 if (i < PNP_MAX_MEM) { 185 flags |= IORESOURCE_MEM_WRITEABLE;
235 res->mem_resource[i].flags = IORESOURCE_MEM; // Also clears _UNSET flag 186
236 if (len <= 0) { 187 pnp_add_mem_resource(dev, start, end, flags);
237 res->mem_resource[i].flags |= IORESOURCE_DISABLED;
238 return;
239 }
240 if (write_protect == ACPI_READ_WRITE_MEMORY)
241 res->mem_resource[i].flags |= IORESOURCE_MEM_WRITEABLE;
242
243 res->mem_resource[i].start = mem;
244 res->mem_resource[i].end = mem + len - 1;
245 } else if (!warned) {
246 printk(KERN_WARNING "pnpacpi: exceeded the max number of mem "
247 "resources: %d\n", PNP_MAX_MEM);
248 warned = 1;
249 }
250} 188}
251 189
252static void pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res_table, 190static void pnpacpi_parse_allocated_address_space(struct pnp_dev *dev,
253 struct acpi_resource *res) 191 struct acpi_resource *res)
254{ 192{
255 struct acpi_resource_address64 addr, *p = &addr; 193 struct acpi_resource_address64 addr, *p = &addr;
@@ -257,7 +195,7 @@ static void pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res
257 195
258 status = acpi_resource_to_address64(res, p); 196 status = acpi_resource_to_address64(res, p);
259 if (!ACPI_SUCCESS(status)) { 197 if (!ACPI_SUCCESS(status)) {
260 pnp_warn("PnPACPI: failed to convert resource type %d", 198 dev_warn(&dev->dev, "failed to convert resource type %d\n",
261 res->type); 199 res->type);
262 return; 200 return;
263 } 201 }
@@ -266,11 +204,11 @@ static void pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res
266 return; 204 return;
267 205
268 if (p->resource_type == ACPI_MEMORY_RANGE) 206 if (p->resource_type == ACPI_MEMORY_RANGE)
269 pnpacpi_parse_allocated_memresource(res_table, 207 pnpacpi_parse_allocated_memresource(dev,
270 p->minimum, p->address_length, 208 p->minimum, p->address_length,
271 p->info.mem.write_protect); 209 p->info.mem.write_protect);
272 else if (p->resource_type == ACPI_IO_RANGE) 210 else if (p->resource_type == ACPI_IO_RANGE)
273 pnpacpi_parse_allocated_ioresource(res_table, 211 pnpacpi_parse_allocated_ioresource(dev,
274 p->minimum, p->address_length, 212 p->minimum, p->address_length,
275 p->granularity == 0xfff ? ACPI_DECODE_10 : 213 p->granularity == 0xfff ? ACPI_DECODE_10 :
276 ACPI_DECODE_16); 214 ACPI_DECODE_16);
@@ -279,8 +217,16 @@ static void pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res
279static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res, 217static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
280 void *data) 218 void *data)
281{ 219{
282 struct pnp_resource_table *res_table = data; 220 struct pnp_dev *dev = data;
283 int i; 221 struct acpi_resource_irq *irq;
222 struct acpi_resource_dma *dma;
223 struct acpi_resource_io *io;
224 struct acpi_resource_fixed_io *fixed_io;
225 struct acpi_resource_memory24 *memory24;
226 struct acpi_resource_memory32 *memory32;
227 struct acpi_resource_fixed_memory32 *fixed_memory32;
228 struct acpi_resource_extended_irq *extended_irq;
229 int i, flags;
284 230
285 switch (res->type) { 231 switch (res->type) {
286 case ACPI_RESOURCE_TYPE_IRQ: 232 case ACPI_RESOURCE_TYPE_IRQ:
@@ -288,29 +234,33 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
288 * Per spec, only one interrupt per descriptor is allowed in 234 * Per spec, only one interrupt per descriptor is allowed in
289 * _CRS, but some firmware violates this, so parse them all. 235 * _CRS, but some firmware violates this, so parse them all.
290 */ 236 */
291 for (i = 0; i < res->data.irq.interrupt_count; i++) { 237 irq = &res->data.irq;
292 pnpacpi_parse_allocated_irqresource(res_table, 238 for (i = 0; i < irq->interrupt_count; i++) {
293 res->data.irq.interrupts[i], 239 pnpacpi_parse_allocated_irqresource(dev,
294 res->data.irq.triggering, 240 irq->interrupts[i],
295 res->data.irq.polarity, 241 irq->triggering,
296 res->data.irq.sharable); 242 irq->polarity,
243 irq->sharable);
297 } 244 }
298 break; 245 break;
299 246
300 case ACPI_RESOURCE_TYPE_DMA: 247 case ACPI_RESOURCE_TYPE_DMA:
301 if (res->data.dma.channel_count > 0) 248 dma = &res->data.dma;
302 pnpacpi_parse_allocated_dmaresource(res_table, 249 if (dma->channel_count > 0) {
303 res->data.dma.channels[0], 250 flags = dma_flags(dma->type, dma->bus_master,
304 res->data.dma.type, 251 dma->transfer);
305 res->data.dma.bus_master, 252 if (dma->channels[0] == (u8) -1)
306 res->data.dma.transfer); 253 flags |= IORESOURCE_DISABLED;
254 pnp_add_dma_resource(dev, dma->channels[0], flags);
255 }
307 break; 256 break;
308 257
309 case ACPI_RESOURCE_TYPE_IO: 258 case ACPI_RESOURCE_TYPE_IO:
310 pnpacpi_parse_allocated_ioresource(res_table, 259 io = &res->data.io;
311 res->data.io.minimum, 260 pnpacpi_parse_allocated_ioresource(dev,
312 res->data.io.address_length, 261 io->minimum,
313 res->data.io.io_decode); 262 io->address_length,
263 io->io_decode);
314 break; 264 break;
315 265
316 case ACPI_RESOURCE_TYPE_START_DEPENDENT: 266 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
@@ -318,9 +268,10 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
318 break; 268 break;
319 269
320 case ACPI_RESOURCE_TYPE_FIXED_IO: 270 case ACPI_RESOURCE_TYPE_FIXED_IO:
321 pnpacpi_parse_allocated_ioresource(res_table, 271 fixed_io = &res->data.fixed_io;
322 res->data.fixed_io.address, 272 pnpacpi_parse_allocated_ioresource(dev,
323 res->data.fixed_io.address_length, 273 fixed_io->address,
274 fixed_io->address_length,
324 ACPI_DECODE_10); 275 ACPI_DECODE_10);
325 break; 276 break;
326 277
@@ -331,27 +282,30 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
331 break; 282 break;
332 283
333 case ACPI_RESOURCE_TYPE_MEMORY24: 284 case ACPI_RESOURCE_TYPE_MEMORY24:
334 pnpacpi_parse_allocated_memresource(res_table, 285 memory24 = &res->data.memory24;
335 res->data.memory24.minimum, 286 pnpacpi_parse_allocated_memresource(dev,
336 res->data.memory24.address_length, 287 memory24->minimum,
337 res->data.memory24.write_protect); 288 memory24->address_length,
289 memory24->write_protect);
338 break; 290 break;
339 case ACPI_RESOURCE_TYPE_MEMORY32: 291 case ACPI_RESOURCE_TYPE_MEMORY32:
340 pnpacpi_parse_allocated_memresource(res_table, 292 memory32 = &res->data.memory32;
341 res->data.memory32.minimum, 293 pnpacpi_parse_allocated_memresource(dev,
342 res->data.memory32.address_length, 294 memory32->minimum,
343 res->data.memory32.write_protect); 295 memory32->address_length,
296 memory32->write_protect);
344 break; 297 break;
345 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: 298 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
346 pnpacpi_parse_allocated_memresource(res_table, 299 fixed_memory32 = &res->data.fixed_memory32;
347 res->data.fixed_memory32.address, 300 pnpacpi_parse_allocated_memresource(dev,
348 res->data.fixed_memory32.address_length, 301 fixed_memory32->address,
349 res->data.fixed_memory32.write_protect); 302 fixed_memory32->address_length,
303 fixed_memory32->write_protect);
350 break; 304 break;
351 case ACPI_RESOURCE_TYPE_ADDRESS16: 305 case ACPI_RESOURCE_TYPE_ADDRESS16:
352 case ACPI_RESOURCE_TYPE_ADDRESS32: 306 case ACPI_RESOURCE_TYPE_ADDRESS32:
353 case ACPI_RESOURCE_TYPE_ADDRESS64: 307 case ACPI_RESOURCE_TYPE_ADDRESS64:
354 pnpacpi_parse_allocated_address_space(res_table, res); 308 pnpacpi_parse_allocated_address_space(dev, res);
355 break; 309 break;
356 310
357 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64: 311 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
@@ -360,15 +314,16 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
360 break; 314 break;
361 315
362 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: 316 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
363 if (res->data.extended_irq.producer_consumer == ACPI_PRODUCER) 317 extended_irq = &res->data.extended_irq;
318 if (extended_irq->producer_consumer == ACPI_PRODUCER)
364 return AE_OK; 319 return AE_OK;
365 320
366 for (i = 0; i < res->data.extended_irq.interrupt_count; i++) { 321 for (i = 0; i < extended_irq->interrupt_count; i++) {
367 pnpacpi_parse_allocated_irqresource(res_table, 322 pnpacpi_parse_allocated_irqresource(dev,
368 res->data.extended_irq.interrupts[i], 323 extended_irq->interrupts[i],
369 res->data.extended_irq.triggering, 324 extended_irq->triggering,
370 res->data.extended_irq.polarity, 325 extended_irq->polarity,
371 res->data.extended_irq.sharable); 326 extended_irq->sharable);
372 } 327 }
373 break; 328 break;
374 329
@@ -376,24 +331,36 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
376 break; 331 break;
377 332
378 default: 333 default:
379 pnp_warn("PnPACPI: unknown resource type %d", res->type); 334 dev_warn(&dev->dev, "unknown resource type %d in _CRS\n",
335 res->type);
380 return AE_ERROR; 336 return AE_ERROR;
381 } 337 }
382 338
383 return AE_OK; 339 return AE_OK;
384} 340}
385 341
386acpi_status pnpacpi_parse_allocated_resource(acpi_handle handle, 342int pnpacpi_parse_allocated_resource(struct pnp_dev *dev)
387 struct pnp_resource_table * res)
388{ 343{
389 /* Blank the resource table values */ 344 acpi_handle handle = dev->data;
390 pnp_init_resource_table(res); 345 acpi_status status;
346
347 dev_dbg(&dev->dev, "parse allocated resources\n");
391 348
392 return acpi_walk_resources(handle, METHOD_NAME__CRS, 349 pnp_init_resources(dev);
393 pnpacpi_allocated_resource, res); 350
351 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
352 pnpacpi_allocated_resource, dev);
353
354 if (ACPI_FAILURE(status)) {
355 if (status != AE_NOT_FOUND)
356 dev_err(&dev->dev, "can't evaluate _CRS: %d", status);
357 return -EPERM;
358 }
359 return 0;
394} 360}
395 361
396static __init void pnpacpi_parse_dma_option(struct pnp_option *option, 362static __init void pnpacpi_parse_dma_option(struct pnp_dev *dev,
363 struct pnp_option *option,
397 struct acpi_resource_dma *p) 364 struct acpi_resource_dma *p)
398{ 365{
399 int i; 366 int i;
@@ -410,10 +377,11 @@ static __init void pnpacpi_parse_dma_option(struct pnp_option *option,
410 377
411 dma->flags = dma_flags(p->type, p->bus_master, p->transfer); 378 dma->flags = dma_flags(p->type, p->bus_master, p->transfer);
412 379
413 pnp_register_dma_resource(option, dma); 380 pnp_register_dma_resource(dev, option, dma);
414} 381}
415 382
416static __init void pnpacpi_parse_irq_option(struct pnp_option *option, 383static __init void pnpacpi_parse_irq_option(struct pnp_dev *dev,
384 struct pnp_option *option,
417 struct acpi_resource_irq *p) 385 struct acpi_resource_irq *p)
418{ 386{
419 int i; 387 int i;
@@ -428,12 +396,13 @@ static __init void pnpacpi_parse_irq_option(struct pnp_option *option,
428 for (i = 0; i < p->interrupt_count; i++) 396 for (i = 0; i < p->interrupt_count; i++)
429 if (p->interrupts[i]) 397 if (p->interrupts[i])
430 __set_bit(p->interrupts[i], irq->map); 398 __set_bit(p->interrupts[i], irq->map);
431 irq->flags = irq_flags(p->triggering, p->polarity); 399 irq->flags = irq_flags(p->triggering, p->polarity, p->sharable);
432 400
433 pnp_register_irq_resource(option, irq); 401 pnp_register_irq_resource(dev, option, irq);
434} 402}
435 403
436static __init void pnpacpi_parse_ext_irq_option(struct pnp_option *option, 404static __init void pnpacpi_parse_ext_irq_option(struct pnp_dev *dev,
405 struct pnp_option *option,
437 struct acpi_resource_extended_irq *p) 406 struct acpi_resource_extended_irq *p)
438{ 407{
439 int i; 408 int i;
@@ -448,12 +417,13 @@ static __init void pnpacpi_parse_ext_irq_option(struct pnp_option *option,
448 for (i = 0; i < p->interrupt_count; i++) 417 for (i = 0; i < p->interrupt_count; i++)
449 if (p->interrupts[i]) 418 if (p->interrupts[i])
450 __set_bit(p->interrupts[i], irq->map); 419 __set_bit(p->interrupts[i], irq->map);
451 irq->flags = irq_flags(p->triggering, p->polarity); 420 irq->flags = irq_flags(p->triggering, p->polarity, p->sharable);
452 421
453 pnp_register_irq_resource(option, irq); 422 pnp_register_irq_resource(dev, option, irq);
454} 423}
455 424
456static __init void pnpacpi_parse_port_option(struct pnp_option *option, 425static __init void pnpacpi_parse_port_option(struct pnp_dev *dev,
426 struct pnp_option *option,
457 struct acpi_resource_io *io) 427 struct acpi_resource_io *io)
458{ 428{
459 struct pnp_port *port; 429 struct pnp_port *port;
@@ -469,10 +439,11 @@ static __init void pnpacpi_parse_port_option(struct pnp_option *option,
469 port->size = io->address_length; 439 port->size = io->address_length;
470 port->flags = ACPI_DECODE_16 == io->io_decode ? 440 port->flags = ACPI_DECODE_16 == io->io_decode ?
471 PNP_PORT_FLAG_16BITADDR : 0; 441 PNP_PORT_FLAG_16BITADDR : 0;
472 pnp_register_port_resource(option, port); 442 pnp_register_port_resource(dev, option, port);
473} 443}
474 444
475static __init void pnpacpi_parse_fixed_port_option(struct pnp_option *option, 445static __init void pnpacpi_parse_fixed_port_option(struct pnp_dev *dev,
446 struct pnp_option *option,
476 struct acpi_resource_fixed_io *io) 447 struct acpi_resource_fixed_io *io)
477{ 448{
478 struct pnp_port *port; 449 struct pnp_port *port;
@@ -486,10 +457,11 @@ static __init void pnpacpi_parse_fixed_port_option(struct pnp_option *option,
486 port->size = io->address_length; 457 port->size = io->address_length;
487 port->align = 0; 458 port->align = 0;
488 port->flags = PNP_PORT_FLAG_FIXED; 459 port->flags = PNP_PORT_FLAG_FIXED;
489 pnp_register_port_resource(option, port); 460 pnp_register_port_resource(dev, option, port);
490} 461}
491 462
492static __init void pnpacpi_parse_mem24_option(struct pnp_option *option, 463static __init void pnpacpi_parse_mem24_option(struct pnp_dev *dev,
464 struct pnp_option *option,
493 struct acpi_resource_memory24 *p) 465 struct acpi_resource_memory24 *p)
494{ 466{
495 struct pnp_mem *mem; 467 struct pnp_mem *mem;
@@ -507,10 +479,11 @@ static __init void pnpacpi_parse_mem24_option(struct pnp_option *option,
507 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ? 479 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
508 IORESOURCE_MEM_WRITEABLE : 0; 480 IORESOURCE_MEM_WRITEABLE : 0;
509 481
510 pnp_register_mem_resource(option, mem); 482 pnp_register_mem_resource(dev, option, mem);
511} 483}
512 484
513static __init void pnpacpi_parse_mem32_option(struct pnp_option *option, 485static __init void pnpacpi_parse_mem32_option(struct pnp_dev *dev,
486 struct pnp_option *option,
514 struct acpi_resource_memory32 *p) 487 struct acpi_resource_memory32 *p)
515{ 488{
516 struct pnp_mem *mem; 489 struct pnp_mem *mem;
@@ -528,10 +501,11 @@ static __init void pnpacpi_parse_mem32_option(struct pnp_option *option,
528 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ? 501 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
529 IORESOURCE_MEM_WRITEABLE : 0; 502 IORESOURCE_MEM_WRITEABLE : 0;
530 503
531 pnp_register_mem_resource(option, mem); 504 pnp_register_mem_resource(dev, option, mem);
532} 505}
533 506
534static __init void pnpacpi_parse_fixed_mem32_option(struct pnp_option *option, 507static __init void pnpacpi_parse_fixed_mem32_option(struct pnp_dev *dev,
508 struct pnp_option *option,
535 struct acpi_resource_fixed_memory32 *p) 509 struct acpi_resource_fixed_memory32 *p)
536{ 510{
537 struct pnp_mem *mem; 511 struct pnp_mem *mem;
@@ -548,10 +522,11 @@ static __init void pnpacpi_parse_fixed_mem32_option(struct pnp_option *option,
548 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ? 522 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
549 IORESOURCE_MEM_WRITEABLE : 0; 523 IORESOURCE_MEM_WRITEABLE : 0;
550 524
551 pnp_register_mem_resource(option, mem); 525 pnp_register_mem_resource(dev, option, mem);
552} 526}
553 527
554static __init void pnpacpi_parse_address_option(struct pnp_option *option, 528static __init void pnpacpi_parse_address_option(struct pnp_dev *dev,
529 struct pnp_option *option,
555 struct acpi_resource *r) 530 struct acpi_resource *r)
556{ 531{
557 struct acpi_resource_address64 addr, *p = &addr; 532 struct acpi_resource_address64 addr, *p = &addr;
@@ -579,7 +554,7 @@ static __init void pnpacpi_parse_address_option(struct pnp_option *option,
579 mem->flags = (p->info.mem.write_protect == 554 mem->flags = (p->info.mem.write_protect ==
580 ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE 555 ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE
581 : 0; 556 : 0;
582 pnp_register_mem_resource(option, mem); 557 pnp_register_mem_resource(dev, option, mem);
583 } else if (p->resource_type == ACPI_IO_RANGE) { 558 } else if (p->resource_type == ACPI_IO_RANGE) {
584 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); 559 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
585 if (!port) 560 if (!port)
@@ -588,7 +563,7 @@ static __init void pnpacpi_parse_address_option(struct pnp_option *option,
588 port->size = p->address_length; 563 port->size = p->address_length;
589 port->align = 0; 564 port->align = 0;
590 port->flags = PNP_PORT_FLAG_FIXED; 565 port->flags = PNP_PORT_FLAG_FIXED;
591 pnp_register_port_resource(option, port); 566 pnp_register_port_resource(dev, option, port);
592 } 567 }
593} 568}
594 569
@@ -608,11 +583,11 @@ static __init acpi_status pnpacpi_option_resource(struct acpi_resource *res,
608 583
609 switch (res->type) { 584 switch (res->type) {
610 case ACPI_RESOURCE_TYPE_IRQ: 585 case ACPI_RESOURCE_TYPE_IRQ:
611 pnpacpi_parse_irq_option(option, &res->data.irq); 586 pnpacpi_parse_irq_option(dev, option, &res->data.irq);
612 break; 587 break;
613 588
614 case ACPI_RESOURCE_TYPE_DMA: 589 case ACPI_RESOURCE_TYPE_DMA:
615 pnpacpi_parse_dma_option(option, &res->data.dma); 590 pnpacpi_parse_dma_option(dev, option, &res->data.dma);
616 break; 591 break;
617 592
618 case ACPI_RESOURCE_TYPE_START_DEPENDENT: 593 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
@@ -642,19 +617,22 @@ static __init acpi_status pnpacpi_option_resource(struct acpi_resource *res,
642 case ACPI_RESOURCE_TYPE_END_DEPENDENT: 617 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
643 /*only one EndDependentFn is allowed */ 618 /*only one EndDependentFn is allowed */
644 if (!parse_data->option_independent) { 619 if (!parse_data->option_independent) {
645 pnp_warn("PnPACPI: more than one EndDependentFn"); 620 dev_warn(&dev->dev, "more than one EndDependentFn "
621 "in _PRS\n");
646 return AE_ERROR; 622 return AE_ERROR;
647 } 623 }
648 parse_data->option = parse_data->option_independent; 624 parse_data->option = parse_data->option_independent;
649 parse_data->option_independent = NULL; 625 parse_data->option_independent = NULL;
626 dev_dbg(&dev->dev, "end dependent options\n");
650 break; 627 break;
651 628
652 case ACPI_RESOURCE_TYPE_IO: 629 case ACPI_RESOURCE_TYPE_IO:
653 pnpacpi_parse_port_option(option, &res->data.io); 630 pnpacpi_parse_port_option(dev, option, &res->data.io);
654 break; 631 break;
655 632
656 case ACPI_RESOURCE_TYPE_FIXED_IO: 633 case ACPI_RESOURCE_TYPE_FIXED_IO:
657 pnpacpi_parse_fixed_port_option(option, &res->data.fixed_io); 634 pnpacpi_parse_fixed_port_option(dev, option,
635 &res->data.fixed_io);
658 break; 636 break;
659 637
660 case ACPI_RESOURCE_TYPE_VENDOR: 638 case ACPI_RESOURCE_TYPE_VENDOR:
@@ -662,57 +640,67 @@ static __init acpi_status pnpacpi_option_resource(struct acpi_resource *res,
662 break; 640 break;
663 641
664 case ACPI_RESOURCE_TYPE_MEMORY24: 642 case ACPI_RESOURCE_TYPE_MEMORY24:
665 pnpacpi_parse_mem24_option(option, &res->data.memory24); 643 pnpacpi_parse_mem24_option(dev, option, &res->data.memory24);
666 break; 644 break;
667 645
668 case ACPI_RESOURCE_TYPE_MEMORY32: 646 case ACPI_RESOURCE_TYPE_MEMORY32:
669 pnpacpi_parse_mem32_option(option, &res->data.memory32); 647 pnpacpi_parse_mem32_option(dev, option, &res->data.memory32);
670 break; 648 break;
671 649
672 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: 650 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
673 pnpacpi_parse_fixed_mem32_option(option, 651 pnpacpi_parse_fixed_mem32_option(dev, option,
674 &res->data.fixed_memory32); 652 &res->data.fixed_memory32);
675 break; 653 break;
676 654
677 case ACPI_RESOURCE_TYPE_ADDRESS16: 655 case ACPI_RESOURCE_TYPE_ADDRESS16:
678 case ACPI_RESOURCE_TYPE_ADDRESS32: 656 case ACPI_RESOURCE_TYPE_ADDRESS32:
679 case ACPI_RESOURCE_TYPE_ADDRESS64: 657 case ACPI_RESOURCE_TYPE_ADDRESS64:
680 pnpacpi_parse_address_option(option, res); 658 pnpacpi_parse_address_option(dev, option, res);
681 break; 659 break;
682 660
683 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64: 661 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
684 break; 662 break;
685 663
686 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: 664 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
687 pnpacpi_parse_ext_irq_option(option, &res->data.extended_irq); 665 pnpacpi_parse_ext_irq_option(dev, option,
666 &res->data.extended_irq);
688 break; 667 break;
689 668
690 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER: 669 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
691 break; 670 break;
692 671
693 default: 672 default:
694 pnp_warn("PnPACPI: unknown resource type %d", res->type); 673 dev_warn(&dev->dev, "unknown resource type %d in _PRS\n",
674 res->type);
695 return AE_ERROR; 675 return AE_ERROR;
696 } 676 }
697 677
698 return AE_OK; 678 return AE_OK;
699} 679}
700 680
701acpi_status __init pnpacpi_parse_resource_option_data(acpi_handle handle, 681int __init pnpacpi_parse_resource_option_data(struct pnp_dev *dev)
702 struct pnp_dev *dev)
703{ 682{
683 acpi_handle handle = dev->data;
704 acpi_status status; 684 acpi_status status;
705 struct acpipnp_parse_option_s parse_data; 685 struct acpipnp_parse_option_s parse_data;
706 686
687 dev_dbg(&dev->dev, "parse resource options\n");
688
707 parse_data.option = pnp_register_independent_option(dev); 689 parse_data.option = pnp_register_independent_option(dev);
708 if (!parse_data.option) 690 if (!parse_data.option)
709 return AE_ERROR; 691 return -ENOMEM;
692
710 parse_data.option_independent = parse_data.option; 693 parse_data.option_independent = parse_data.option;
711 parse_data.dev = dev; 694 parse_data.dev = dev;
712 status = acpi_walk_resources(handle, METHOD_NAME__PRS, 695 status = acpi_walk_resources(handle, METHOD_NAME__PRS,
713 pnpacpi_option_resource, &parse_data); 696 pnpacpi_option_resource, &parse_data);
714 697
715 return status; 698 if (ACPI_FAILURE(status)) {
699 if (status != AE_NOT_FOUND)
700 dev_err(&dev->dev, "can't evaluate _PRS: %d", status);
701 return -EPERM;
702 }
703 return 0;
716} 704}
717 705
718static int pnpacpi_supported_resource(struct acpi_resource *res) 706static int pnpacpi_supported_resource(struct acpi_resource *res)
@@ -760,9 +748,10 @@ static acpi_status pnpacpi_type_resources(struct acpi_resource *res, void *data)
760 return AE_OK; 748 return AE_OK;
761} 749}
762 750
763int pnpacpi_build_resource_template(acpi_handle handle, 751int pnpacpi_build_resource_template(struct pnp_dev *dev,
764 struct acpi_buffer *buffer) 752 struct acpi_buffer *buffer)
765{ 753{
754 acpi_handle handle = dev->data;
766 struct acpi_resource *resource; 755 struct acpi_resource *resource;
767 int res_cnt = 0; 756 int res_cnt = 0;
768 acpi_status status; 757 acpi_status status;
@@ -770,7 +759,7 @@ int pnpacpi_build_resource_template(acpi_handle handle,
770 status = acpi_walk_resources(handle, METHOD_NAME__CRS, 759 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
771 pnpacpi_count_resources, &res_cnt); 760 pnpacpi_count_resources, &res_cnt);
772 if (ACPI_FAILURE(status)) { 761 if (ACPI_FAILURE(status)) {
773 pnp_err("Evaluate _CRS failed"); 762 dev_err(&dev->dev, "can't evaluate _CRS: %d\n", status);
774 return -EINVAL; 763 return -EINVAL;
775 } 764 }
776 if (!res_cnt) 765 if (!res_cnt)
@@ -779,13 +768,13 @@ int pnpacpi_build_resource_template(acpi_handle handle,
779 buffer->pointer = kzalloc(buffer->length - 1, GFP_KERNEL); 768 buffer->pointer = kzalloc(buffer->length - 1, GFP_KERNEL);
780 if (!buffer->pointer) 769 if (!buffer->pointer)
781 return -ENOMEM; 770 return -ENOMEM;
782 pnp_dbg("Res cnt %d", res_cnt); 771
783 resource = (struct acpi_resource *)buffer->pointer; 772 resource = (struct acpi_resource *)buffer->pointer;
784 status = acpi_walk_resources(handle, METHOD_NAME__CRS, 773 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
785 pnpacpi_type_resources, &resource); 774 pnpacpi_type_resources, &resource);
786 if (ACPI_FAILURE(status)) { 775 if (ACPI_FAILURE(status)) {
787 kfree(buffer->pointer); 776 kfree(buffer->pointer);
788 pnp_err("Evaluate _CRS failed"); 777 dev_err(&dev->dev, "can't evaluate _CRS: %d\n", status);
789 return -EINVAL; 778 return -EINVAL;
790 } 779 }
791 /* resource will pointer the end resource now */ 780 /* resource will pointer the end resource now */
@@ -794,129 +783,184 @@ int pnpacpi_build_resource_template(acpi_handle handle,
794 return 0; 783 return 0;
795} 784}
796 785
797static void pnpacpi_encode_irq(struct acpi_resource *resource, 786static void pnpacpi_encode_irq(struct pnp_dev *dev,
787 struct acpi_resource *resource,
798 struct resource *p) 788 struct resource *p)
799{ 789{
790 struct acpi_resource_irq *irq = &resource->data.irq;
800 int triggering, polarity; 791 int triggering, polarity;
801 792
802 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity); 793 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
803 resource->data.irq.triggering = triggering; 794 irq->triggering = triggering;
804 resource->data.irq.polarity = polarity; 795 irq->polarity = polarity;
805 if (triggering == ACPI_EDGE_SENSITIVE) 796 if (triggering == ACPI_EDGE_SENSITIVE)
806 resource->data.irq.sharable = ACPI_EXCLUSIVE; 797 irq->sharable = ACPI_EXCLUSIVE;
807 else 798 else
808 resource->data.irq.sharable = ACPI_SHARED; 799 irq->sharable = ACPI_SHARED;
809 resource->data.irq.interrupt_count = 1; 800 irq->interrupt_count = 1;
810 resource->data.irq.interrupts[0] = p->start; 801 irq->interrupts[0] = p->start;
802
803 dev_dbg(&dev->dev, " encode irq %d %s %s %s\n", (int) p->start,
804 triggering == ACPI_LEVEL_SENSITIVE ? "level" : "edge",
805 polarity == ACPI_ACTIVE_LOW ? "low" : "high",
806 irq->sharable == ACPI_SHARED ? "shared" : "exclusive");
811} 807}
812 808
813static void pnpacpi_encode_ext_irq(struct acpi_resource *resource, 809static void pnpacpi_encode_ext_irq(struct pnp_dev *dev,
810 struct acpi_resource *resource,
814 struct resource *p) 811 struct resource *p)
815{ 812{
813 struct acpi_resource_extended_irq *extended_irq = &resource->data.extended_irq;
816 int triggering, polarity; 814 int triggering, polarity;
817 815
818 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity); 816 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
819 resource->data.extended_irq.producer_consumer = ACPI_CONSUMER; 817 extended_irq->producer_consumer = ACPI_CONSUMER;
820 resource->data.extended_irq.triggering = triggering; 818 extended_irq->triggering = triggering;
821 resource->data.extended_irq.polarity = polarity; 819 extended_irq->polarity = polarity;
822 if (triggering == ACPI_EDGE_SENSITIVE) 820 if (triggering == ACPI_EDGE_SENSITIVE)
823 resource->data.irq.sharable = ACPI_EXCLUSIVE; 821 extended_irq->sharable = ACPI_EXCLUSIVE;
824 else 822 else
825 resource->data.irq.sharable = ACPI_SHARED; 823 extended_irq->sharable = ACPI_SHARED;
826 resource->data.extended_irq.interrupt_count = 1; 824 extended_irq->interrupt_count = 1;
827 resource->data.extended_irq.interrupts[0] = p->start; 825 extended_irq->interrupts[0] = p->start;
826
827 dev_dbg(&dev->dev, " encode irq %d %s %s %s\n", (int) p->start,
828 triggering == ACPI_LEVEL_SENSITIVE ? "level" : "edge",
829 polarity == ACPI_ACTIVE_LOW ? "low" : "high",
830 extended_irq->sharable == ACPI_SHARED ? "shared" : "exclusive");
828} 831}
829 832
830static void pnpacpi_encode_dma(struct acpi_resource *resource, 833static void pnpacpi_encode_dma(struct pnp_dev *dev,
834 struct acpi_resource *resource,
831 struct resource *p) 835 struct resource *p)
832{ 836{
837 struct acpi_resource_dma *dma = &resource->data.dma;
838
833 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */ 839 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
834 switch (p->flags & IORESOURCE_DMA_SPEED_MASK) { 840 switch (p->flags & IORESOURCE_DMA_SPEED_MASK) {
835 case IORESOURCE_DMA_TYPEA: 841 case IORESOURCE_DMA_TYPEA:
836 resource->data.dma.type = ACPI_TYPE_A; 842 dma->type = ACPI_TYPE_A;
837 break; 843 break;
838 case IORESOURCE_DMA_TYPEB: 844 case IORESOURCE_DMA_TYPEB:
839 resource->data.dma.type = ACPI_TYPE_B; 845 dma->type = ACPI_TYPE_B;
840 break; 846 break;
841 case IORESOURCE_DMA_TYPEF: 847 case IORESOURCE_DMA_TYPEF:
842 resource->data.dma.type = ACPI_TYPE_F; 848 dma->type = ACPI_TYPE_F;
843 break; 849 break;
844 default: 850 default:
845 resource->data.dma.type = ACPI_COMPATIBILITY; 851 dma->type = ACPI_COMPATIBILITY;
846 } 852 }
847 853
848 switch (p->flags & IORESOURCE_DMA_TYPE_MASK) { 854 switch (p->flags & IORESOURCE_DMA_TYPE_MASK) {
849 case IORESOURCE_DMA_8BIT: 855 case IORESOURCE_DMA_8BIT:
850 resource->data.dma.transfer = ACPI_TRANSFER_8; 856 dma->transfer = ACPI_TRANSFER_8;
851 break; 857 break;
852 case IORESOURCE_DMA_8AND16BIT: 858 case IORESOURCE_DMA_8AND16BIT:
853 resource->data.dma.transfer = ACPI_TRANSFER_8_16; 859 dma->transfer = ACPI_TRANSFER_8_16;
854 break; 860 break;
855 default: 861 default:
856 resource->data.dma.transfer = ACPI_TRANSFER_16; 862 dma->transfer = ACPI_TRANSFER_16;
857 } 863 }
858 864
859 resource->data.dma.bus_master = !!(p->flags & IORESOURCE_DMA_MASTER); 865 dma->bus_master = !!(p->flags & IORESOURCE_DMA_MASTER);
860 resource->data.dma.channel_count = 1; 866 dma->channel_count = 1;
861 resource->data.dma.channels[0] = p->start; 867 dma->channels[0] = p->start;
868
869 dev_dbg(&dev->dev, " encode dma %d "
870 "type %#x transfer %#x master %d\n",
871 (int) p->start, dma->type, dma->transfer, dma->bus_master);
862} 872}
863 873
864static void pnpacpi_encode_io(struct acpi_resource *resource, 874static void pnpacpi_encode_io(struct pnp_dev *dev,
875 struct acpi_resource *resource,
865 struct resource *p) 876 struct resource *p)
866{ 877{
878 struct acpi_resource_io *io = &resource->data.io;
879
867 /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */ 880 /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
868 resource->data.io.io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR) ? 881 io->io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR) ?
869 ACPI_DECODE_16 : ACPI_DECODE_10; 882 ACPI_DECODE_16 : ACPI_DECODE_10;
870 resource->data.io.minimum = p->start; 883 io->minimum = p->start;
871 resource->data.io.maximum = p->end; 884 io->maximum = p->end;
872 resource->data.io.alignment = 0; /* Correct? */ 885 io->alignment = 0; /* Correct? */
873 resource->data.io.address_length = p->end - p->start + 1; 886 io->address_length = p->end - p->start + 1;
887
888 dev_dbg(&dev->dev, " encode io %#llx-%#llx decode %#x\n",
889 (unsigned long long) p->start, (unsigned long long) p->end,
890 io->io_decode);
874} 891}
875 892
876static void pnpacpi_encode_fixed_io(struct acpi_resource *resource, 893static void pnpacpi_encode_fixed_io(struct pnp_dev *dev,
894 struct acpi_resource *resource,
877 struct resource *p) 895 struct resource *p)
878{ 896{
879 resource->data.fixed_io.address = p->start; 897 struct acpi_resource_fixed_io *fixed_io = &resource->data.fixed_io;
880 resource->data.fixed_io.address_length = p->end - p->start + 1; 898
899 fixed_io->address = p->start;
900 fixed_io->address_length = p->end - p->start + 1;
901
902 dev_dbg(&dev->dev, " encode fixed_io %#llx-%#llx\n",
903 (unsigned long long) p->start, (unsigned long long) p->end);
881} 904}
882 905
883static void pnpacpi_encode_mem24(struct acpi_resource *resource, 906static void pnpacpi_encode_mem24(struct pnp_dev *dev,
907 struct acpi_resource *resource,
884 struct resource *p) 908 struct resource *p)
885{ 909{
910 struct acpi_resource_memory24 *memory24 = &resource->data.memory24;
911
886 /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */ 912 /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
887 resource->data.memory24.write_protect = 913 memory24->write_protect =
888 (p->flags & IORESOURCE_MEM_WRITEABLE) ? 914 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
889 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; 915 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
890 resource->data.memory24.minimum = p->start; 916 memory24->minimum = p->start;
891 resource->data.memory24.maximum = p->end; 917 memory24->maximum = p->end;
892 resource->data.memory24.alignment = 0; 918 memory24->alignment = 0;
893 resource->data.memory24.address_length = p->end - p->start + 1; 919 memory24->address_length = p->end - p->start + 1;
920
921 dev_dbg(&dev->dev, " encode mem24 %#llx-%#llx write_protect %#x\n",
922 (unsigned long long) p->start, (unsigned long long) p->end,
923 memory24->write_protect);
894} 924}
895 925
896static void pnpacpi_encode_mem32(struct acpi_resource *resource, 926static void pnpacpi_encode_mem32(struct pnp_dev *dev,
927 struct acpi_resource *resource,
897 struct resource *p) 928 struct resource *p)
898{ 929{
899 resource->data.memory32.write_protect = 930 struct acpi_resource_memory32 *memory32 = &resource->data.memory32;
931
932 memory32->write_protect =
900 (p->flags & IORESOURCE_MEM_WRITEABLE) ? 933 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
901 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; 934 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
902 resource->data.memory32.minimum = p->start; 935 memory32->minimum = p->start;
903 resource->data.memory32.maximum = p->end; 936 memory32->maximum = p->end;
904 resource->data.memory32.alignment = 0; 937 memory32->alignment = 0;
905 resource->data.memory32.address_length = p->end - p->start + 1; 938 memory32->address_length = p->end - p->start + 1;
939
940 dev_dbg(&dev->dev, " encode mem32 %#llx-%#llx write_protect %#x\n",
941 (unsigned long long) p->start, (unsigned long long) p->end,
942 memory32->write_protect);
906} 943}
907 944
908static void pnpacpi_encode_fixed_mem32(struct acpi_resource *resource, 945static void pnpacpi_encode_fixed_mem32(struct pnp_dev *dev,
946 struct acpi_resource *resource,
909 struct resource *p) 947 struct resource *p)
910{ 948{
911 resource->data.fixed_memory32.write_protect = 949 struct acpi_resource_fixed_memory32 *fixed_memory32 = &resource->data.fixed_memory32;
950
951 fixed_memory32->write_protect =
912 (p->flags & IORESOURCE_MEM_WRITEABLE) ? 952 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
913 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; 953 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
914 resource->data.fixed_memory32.address = p->start; 954 fixed_memory32->address = p->start;
915 resource->data.fixed_memory32.address_length = p->end - p->start + 1; 955 fixed_memory32->address_length = p->end - p->start + 1;
956
957 dev_dbg(&dev->dev, " encode fixed_mem32 %#llx-%#llx "
958 "write_protect %#x\n",
959 (unsigned long long) p->start, (unsigned long long) p->end,
960 fixed_memory32->write_protect);
916} 961}
917 962
918int pnpacpi_encode_resources(struct pnp_resource_table *res_table, 963int pnpacpi_encode_resources(struct pnp_dev *dev, struct acpi_buffer *buffer)
919 struct acpi_buffer *buffer)
920{ 964{
921 int i = 0; 965 int i = 0;
922 /* pnpacpi_build_resource_template allocates extra mem */ 966 /* pnpacpi_build_resource_template allocates extra mem */
@@ -924,58 +968,48 @@ int pnpacpi_encode_resources(struct pnp_resource_table *res_table,
924 struct acpi_resource *resource = buffer->pointer; 968 struct acpi_resource *resource = buffer->pointer;
925 int port = 0, irq = 0, dma = 0, mem = 0; 969 int port = 0, irq = 0, dma = 0, mem = 0;
926 970
927 pnp_dbg("res cnt %d", res_cnt); 971 dev_dbg(&dev->dev, "encode %d resources\n", res_cnt);
928 while (i < res_cnt) { 972 while (i < res_cnt) {
929 switch (resource->type) { 973 switch (resource->type) {
930 case ACPI_RESOURCE_TYPE_IRQ: 974 case ACPI_RESOURCE_TYPE_IRQ:
931 pnp_dbg("Encode irq"); 975 pnpacpi_encode_irq(dev, resource,
932 pnpacpi_encode_irq(resource, 976 pnp_get_resource(dev, IORESOURCE_IRQ, irq));
933 &res_table->irq_resource[irq]);
934 irq++; 977 irq++;
935 break; 978 break;
936 979
937 case ACPI_RESOURCE_TYPE_DMA: 980 case ACPI_RESOURCE_TYPE_DMA:
938 pnp_dbg("Encode dma"); 981 pnpacpi_encode_dma(dev, resource,
939 pnpacpi_encode_dma(resource, 982 pnp_get_resource(dev, IORESOURCE_DMA, dma));
940 &res_table->dma_resource[dma]);
941 dma++; 983 dma++;
942 break; 984 break;
943 case ACPI_RESOURCE_TYPE_IO: 985 case ACPI_RESOURCE_TYPE_IO:
944 pnp_dbg("Encode io"); 986 pnpacpi_encode_io(dev, resource,
945 pnpacpi_encode_io(resource, 987 pnp_get_resource(dev, IORESOURCE_IO, port));
946 &res_table->port_resource[port]);
947 port++; 988 port++;
948 break; 989 break;
949 case ACPI_RESOURCE_TYPE_FIXED_IO: 990 case ACPI_RESOURCE_TYPE_FIXED_IO:
950 pnp_dbg("Encode fixed io"); 991 pnpacpi_encode_fixed_io(dev, resource,
951 pnpacpi_encode_fixed_io(resource, 992 pnp_get_resource(dev, IORESOURCE_IO, port));
952 &res_table->
953 port_resource[port]);
954 port++; 993 port++;
955 break; 994 break;
956 case ACPI_RESOURCE_TYPE_MEMORY24: 995 case ACPI_RESOURCE_TYPE_MEMORY24:
957 pnp_dbg("Encode mem24"); 996 pnpacpi_encode_mem24(dev, resource,
958 pnpacpi_encode_mem24(resource, 997 pnp_get_resource(dev, IORESOURCE_MEM, mem));
959 &res_table->mem_resource[mem]);
960 mem++; 998 mem++;
961 break; 999 break;
962 case ACPI_RESOURCE_TYPE_MEMORY32: 1000 case ACPI_RESOURCE_TYPE_MEMORY32:
963 pnp_dbg("Encode mem32"); 1001 pnpacpi_encode_mem32(dev, resource,
964 pnpacpi_encode_mem32(resource, 1002 pnp_get_resource(dev, IORESOURCE_MEM, mem));
965 &res_table->mem_resource[mem]);
966 mem++; 1003 mem++;
967 break; 1004 break;
968 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: 1005 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
969 pnp_dbg("Encode fixed mem32"); 1006 pnpacpi_encode_fixed_mem32(dev, resource,
970 pnpacpi_encode_fixed_mem32(resource, 1007 pnp_get_resource(dev, IORESOURCE_MEM, mem));
971 &res_table->
972 mem_resource[mem]);
973 mem++; 1008 mem++;
974 break; 1009 break;
975 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: 1010 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
976 pnp_dbg("Encode ext irq"); 1011 pnpacpi_encode_ext_irq(dev, resource,
977 pnpacpi_encode_ext_irq(resource, 1012 pnp_get_resource(dev, IORESOURCE_IRQ, irq));
978 &res_table->irq_resource[irq]);
979 irq++; 1013 irq++;
980 break; 1014 break;
981 case ACPI_RESOURCE_TYPE_START_DEPENDENT: 1015 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
@@ -988,7 +1022,8 @@ int pnpacpi_encode_resources(struct pnp_resource_table *res_table,
988 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64: 1022 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
989 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER: 1023 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
990 default: /* other type */ 1024 default: /* other type */
991 pnp_warn("unknown resource type %d", resource->type); 1025 dev_warn(&dev->dev, "can't encode unknown resource "
1026 "type %d\n", resource->type);
992 return -EINVAL; 1027 return -EINVAL;
993 } 1028 }
994 resource++; 1029 resource++;
diff --git a/drivers/pnp/pnpbios/Makefile b/drivers/pnp/pnpbios/Makefile
index 3cd3ed760605..310e2b3a7710 100644
--- a/drivers/pnp/pnpbios/Makefile
+++ b/drivers/pnp/pnpbios/Makefile
@@ -5,3 +5,7 @@
5pnpbios-proc-$(CONFIG_PNPBIOS_PROC_FS) = proc.o 5pnpbios-proc-$(CONFIG_PNPBIOS_PROC_FS) = proc.o
6 6
7obj-y := core.o bioscalls.o rsparser.o $(pnpbios-proc-y) 7obj-y := core.o bioscalls.o rsparser.o $(pnpbios-proc-y)
8
9ifeq ($(CONFIG_PNP_DEBUG),y)
10EXTRA_CFLAGS += -DDEBUG
11endif
diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
index a8364d815222..7ff824496b39 100644
--- a/drivers/pnp/pnpbios/bioscalls.c
+++ b/drivers/pnp/pnpbios/bioscalls.c
@@ -7,7 +7,6 @@
7#include <linux/init.h> 7#include <linux/init.h>
8#include <linux/linkage.h> 8#include <linux/linkage.h>
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/pnpbios.h>
11#include <linux/device.h> 10#include <linux/device.h>
12#include <linux/pnp.h> 11#include <linux/pnp.h>
13#include <linux/mm.h> 12#include <linux/mm.h>
diff --git a/drivers/pnp/pnpbios/core.c b/drivers/pnp/pnpbios/core.c
index a8a51500e1e9..19a4be1a9a31 100644
--- a/drivers/pnp/pnpbios/core.c
+++ b/drivers/pnp/pnpbios/core.c
@@ -50,7 +50,6 @@
50#include <linux/init.h> 50#include <linux/init.h>
51#include <linux/linkage.h> 51#include <linux/linkage.h>
52#include <linux/kernel.h> 52#include <linux/kernel.h>
53#include <linux/pnpbios.h>
54#include <linux/device.h> 53#include <linux/device.h>
55#include <linux/pnp.h> 54#include <linux/pnp.h>
56#include <linux/mm.h> 55#include <linux/mm.h>
@@ -69,6 +68,7 @@
69#include <asm/system.h> 68#include <asm/system.h>
70#include <asm/byteorder.h> 69#include <asm/byteorder.h>
71 70
71#include "../base.h"
72#include "pnpbios.h" 72#include "pnpbios.h"
73 73
74/* 74/*
@@ -203,8 +203,7 @@ static int pnp_dock_thread(void *unused)
203 203
204#endif /* CONFIG_HOTPLUG */ 204#endif /* CONFIG_HOTPLUG */
205 205
206static int pnpbios_get_resources(struct pnp_dev *dev, 206static int pnpbios_get_resources(struct pnp_dev *dev)
207 struct pnp_resource_table *res)
208{ 207{
209 u8 nodenum = dev->number; 208 u8 nodenum = dev->number;
210 struct pnp_bios_node *node; 209 struct pnp_bios_node *node;
@@ -212,6 +211,7 @@ static int pnpbios_get_resources(struct pnp_dev *dev,
212 if (!pnpbios_is_dynamic(dev)) 211 if (!pnpbios_is_dynamic(dev))
213 return -EPERM; 212 return -EPERM;
214 213
214 dev_dbg(&dev->dev, "get resources\n");
215 node = kzalloc(node_info.max_node_size, GFP_KERNEL); 215 node = kzalloc(node_info.max_node_size, GFP_KERNEL);
216 if (!node) 216 if (!node)
217 return -1; 217 return -1;
@@ -219,14 +219,13 @@ static int pnpbios_get_resources(struct pnp_dev *dev,
219 kfree(node); 219 kfree(node);
220 return -ENODEV; 220 return -ENODEV;
221 } 221 }
222 pnpbios_read_resources_from_node(res, node); 222 pnpbios_read_resources_from_node(dev, node);
223 dev->active = pnp_is_active(dev); 223 dev->active = pnp_is_active(dev);
224 kfree(node); 224 kfree(node);
225 return 0; 225 return 0;
226} 226}
227 227
228static int pnpbios_set_resources(struct pnp_dev *dev, 228static int pnpbios_set_resources(struct pnp_dev *dev)
229 struct pnp_resource_table *res)
230{ 229{
231 u8 nodenum = dev->number; 230 u8 nodenum = dev->number;
232 struct pnp_bios_node *node; 231 struct pnp_bios_node *node;
@@ -235,6 +234,7 @@ static int pnpbios_set_resources(struct pnp_dev *dev,
235 if (!pnpbios_is_dynamic(dev)) 234 if (!pnpbios_is_dynamic(dev))
236 return -EPERM; 235 return -EPERM;
237 236
237 dev_dbg(&dev->dev, "set resources\n");
238 node = kzalloc(node_info.max_node_size, GFP_KERNEL); 238 node = kzalloc(node_info.max_node_size, GFP_KERNEL);
239 if (!node) 239 if (!node)
240 return -1; 240 return -1;
@@ -242,7 +242,7 @@ static int pnpbios_set_resources(struct pnp_dev *dev,
242 kfree(node); 242 kfree(node);
243 return -ENODEV; 243 return -ENODEV;
244 } 244 }
245 if (pnpbios_write_resources_to_node(res, node) < 0) { 245 if (pnpbios_write_resources_to_node(dev, node) < 0) {
246 kfree(node); 246 kfree(node);
247 return -1; 247 return -1;
248 } 248 }
@@ -317,7 +317,6 @@ static int __init insert_device(struct pnp_bios_node *node)
317{ 317{
318 struct list_head *pos; 318 struct list_head *pos;
319 struct pnp_dev *dev; 319 struct pnp_dev *dev;
320 struct pnp_id *dev_id;
321 char id[8]; 320 char id[8];
322 321
323 /* check if the device is already added */ 322 /* check if the device is already added */
@@ -327,20 +326,11 @@ static int __init insert_device(struct pnp_bios_node *node)
327 return -1; 326 return -1;
328 } 327 }
329 328
330 dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL); 329 pnp_eisa_id_to_string(node->eisa_id & PNP_EISA_ID_MASK, id);
330 dev = pnp_alloc_dev(&pnpbios_protocol, node->handle, id);
331 if (!dev) 331 if (!dev)
332 return -1; 332 return -1;
333 333
334 dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
335 if (!dev_id) {
336 kfree(dev);
337 return -1;
338 }
339
340 dev->number = node->handle;
341 pnpid32_to_pnpid(node->eisa_id, id);
342 memcpy(dev_id->id, id, 7);
343 pnp_add_id(dev_id, dev);
344 pnpbios_parse_data_stream(dev, node); 334 pnpbios_parse_data_stream(dev, node);
345 dev->active = pnp_is_active(dev); 335 dev->active = pnp_is_active(dev);
346 dev->flags = node->flags; 336 dev->flags = node->flags;
@@ -353,11 +343,10 @@ static int __init insert_device(struct pnp_bios_node *node)
353 dev->capabilities |= PNP_WRITE; 343 dev->capabilities |= PNP_WRITE;
354 if (dev->flags & PNPBIOS_REMOVABLE) 344 if (dev->flags & PNPBIOS_REMOVABLE)
355 dev->capabilities |= PNP_REMOVABLE; 345 dev->capabilities |= PNP_REMOVABLE;
356 dev->protocol = &pnpbios_protocol;
357 346
358 /* clear out the damaged flags */ 347 /* clear out the damaged flags */
359 if (!dev->active) 348 if (!dev->active)
360 pnp_init_resource_table(&dev->res); 349 pnp_init_resources(dev);
361 350
362 pnp_add_device(dev); 351 pnp_add_device(dev);
363 pnpbios_interface_attach_device(node); 352 pnpbios_interface_attach_device(node);
diff --git a/drivers/pnp/pnpbios/pnpbios.h b/drivers/pnp/pnpbios/pnpbios.h
index d8cb2fd1f127..b09cf6dc2075 100644
--- a/drivers/pnp/pnpbios/pnpbios.h
+++ b/drivers/pnp/pnpbios/pnpbios.h
@@ -2,6 +2,142 @@
2 * pnpbios.h - contains local definitions 2 * pnpbios.h - contains local definitions
3 */ 3 */
4 4
5/*
6 * Include file for the interface to a PnP BIOS
7 *
8 * Original BIOS code (C) 1998 Christian Schmidt (chr.schmidt@tu-bs.de)
9 * PnP handler parts (c) 1998 Tom Lees <tom@lpsg.demon.co.uk>
10 * Minor reorganizations by David Hinds <dahinds@users.sourceforge.net>
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2, or (at your option) any
15 * later version.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
27/*
28 * Return codes
29 */
30#define PNP_SUCCESS 0x00
31#define PNP_NOT_SET_STATICALLY 0x7f
32#define PNP_UNKNOWN_FUNCTION 0x81
33#define PNP_FUNCTION_NOT_SUPPORTED 0x82
34#define PNP_INVALID_HANDLE 0x83
35#define PNP_BAD_PARAMETER 0x84
36#define PNP_SET_FAILED 0x85
37#define PNP_EVENTS_NOT_PENDING 0x86
38#define PNP_SYSTEM_NOT_DOCKED 0x87
39#define PNP_NO_ISA_PNP_CARDS 0x88
40#define PNP_UNABLE_TO_DETERMINE_DOCK_CAPABILITIES 0x89
41#define PNP_CONFIG_CHANGE_FAILED_NO_BATTERY 0x8a
42#define PNP_CONFIG_CHANGE_FAILED_RESOURCE_CONFLICT 0x8b
43#define PNP_BUFFER_TOO_SMALL 0x8c
44#define PNP_USE_ESCD_SUPPORT 0x8d
45#define PNP_MESSAGE_NOT_SUPPORTED 0x8e
46#define PNP_HARDWARE_ERROR 0x8f
47
48#define ESCD_SUCCESS 0x00
49#define ESCD_IO_ERROR_READING 0x55
50#define ESCD_INVALID 0x56
51#define ESCD_BUFFER_TOO_SMALL 0x59
52#define ESCD_NVRAM_TOO_SMALL 0x5a
53#define ESCD_FUNCTION_NOT_SUPPORTED 0x81
54
55/*
56 * Events that can be received by "get event"
57 */
58#define PNPEV_ABOUT_TO_CHANGE_CONFIG 0x0001
59#define PNPEV_DOCK_CHANGED 0x0002
60#define PNPEV_SYSTEM_DEVICE_CHANGED 0x0003
61#define PNPEV_CONFIG_CHANGED_FAILED 0x0004
62#define PNPEV_UNKNOWN_SYSTEM_EVENT 0xffff
63/* 0x8000 through 0xfffe are OEM defined */
64
65/*
66 * Messages that should be sent through "send message"
67 */
68#define PNPMSG_OK 0x00
69#define PNPMSG_ABORT 0x01
70#define PNPMSG_UNDOCK_DEFAULT_ACTION 0x40
71#define PNPMSG_POWER_OFF 0x41
72#define PNPMSG_PNP_OS_ACTIVE 0x42
73#define PNPMSG_PNP_OS_INACTIVE 0x43
74
75/*
76 * Plug and Play BIOS flags
77 */
78#define PNPBIOS_NO_DISABLE 0x0001
79#define PNPBIOS_NO_CONFIG 0x0002
80#define PNPBIOS_OUTPUT 0x0004
81#define PNPBIOS_INPUT 0x0008
82#define PNPBIOS_BOOTABLE 0x0010
83#define PNPBIOS_DOCK 0x0020
84#define PNPBIOS_REMOVABLE 0x0040
85#define pnpbios_is_static(x) (((x)->flags & 0x0100) == 0x0000)
86#define pnpbios_is_dynamic(x) ((x)->flags & 0x0080)
87
88/*
89 * Function Parameters
90 */
91#define PNPMODE_STATIC 1
92#define PNPMODE_DYNAMIC 0
93
94/* 0x8000 through 0xffff are OEM defined */
95
96#pragma pack(1)
97struct pnp_dev_node_info {
98 __u16 no_nodes;
99 __u16 max_node_size;
100};
101struct pnp_docking_station_info {
102 __u32 location_id;
103 __u32 serial;
104 __u16 capabilities;
105};
106struct pnp_isa_config_struc {
107 __u8 revision;
108 __u8 no_csns;
109 __u16 isa_rd_data_port;
110 __u16 reserved;
111};
112struct escd_info_struc {
113 __u16 min_escd_write_size;
114 __u16 escd_size;
115 __u32 nv_storage_base;
116};
117struct pnp_bios_node {
118 __u16 size;
119 __u8 handle;
120 __u32 eisa_id;
121 __u8 type_code[3];
122 __u16 flags;
123 __u8 data[0];
124};
125#pragma pack()
126
127/* non-exported */
128extern struct pnp_dev_node_info node_info;
129
130extern int pnp_bios_dev_node_info(struct pnp_dev_node_info *data);
131extern int pnp_bios_get_dev_node(u8 *nodenum, char config,
132 struct pnp_bios_node *data);
133extern int pnp_bios_set_dev_node(u8 nodenum, char config,
134 struct pnp_bios_node *data);
135extern int pnp_bios_get_stat_res(char *info);
136extern int pnp_bios_isapnp_config(struct pnp_isa_config_struc *data);
137extern int pnp_bios_escd_info(struct escd_info_struc *data);
138extern int pnp_bios_read_escd(char *data, u32 nvram_base);
139extern int pnp_bios_dock_station_info(struct pnp_docking_station_info *data);
140
5#pragma pack(1) 141#pragma pack(1)
6union pnp_bios_install_struct { 142union pnp_bios_install_struct {
7 struct { 143 struct {
@@ -28,8 +164,8 @@ extern int pnp_bios_present(void);
28extern int pnpbios_dont_use_current_config; 164extern int pnpbios_dont_use_current_config;
29 165
30extern int pnpbios_parse_data_stream(struct pnp_dev *dev, struct pnp_bios_node * node); 166extern int pnpbios_parse_data_stream(struct pnp_dev *dev, struct pnp_bios_node * node);
31extern int pnpbios_read_resources_from_node(struct pnp_resource_table *res, struct pnp_bios_node * node); 167extern int pnpbios_read_resources_from_node(struct pnp_dev *dev, struct pnp_bios_node *node);
32extern int pnpbios_write_resources_to_node(struct pnp_resource_table *res, struct pnp_bios_node * node); 168extern int pnpbios_write_resources_to_node(struct pnp_dev *dev, struct pnp_bios_node *node);
33extern void pnpid32_to_pnpid(u32 id, char *str); 169extern void pnpid32_to_pnpid(u32 id, char *str);
34 170
35extern void pnpbios_print_status(const char * module, u16 status); 171extern void pnpbios_print_status(const char * module, u16 status);
diff --git a/drivers/pnp/pnpbios/proc.c b/drivers/pnp/pnpbios/proc.c
index 46d506f66259..b35d921bac6e 100644
--- a/drivers/pnp/pnpbios/proc.c
+++ b/drivers/pnp/pnpbios/proc.c
@@ -23,7 +23,7 @@
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/types.h> 24#include <linux/types.h>
25#include <linux/proc_fs.h> 25#include <linux/proc_fs.h>
26#include <linux/pnpbios.h> 26#include <linux/pnp.h>
27#include <linux/init.h> 27#include <linux/init.h>
28 28
29#include <asm/uaccess.h> 29#include <asm/uaccess.h>
diff --git a/drivers/pnp/pnpbios/rsparser.c b/drivers/pnp/pnpbios/rsparser.c
index caade3531416..5ff9a4c0447e 100644
--- a/drivers/pnp/pnpbios/rsparser.c
+++ b/drivers/pnp/pnpbios/rsparser.c
@@ -4,7 +4,6 @@
4 4
5#include <linux/ctype.h> 5#include <linux/ctype.h>
6#include <linux/pnp.h> 6#include <linux/pnp.h>
7#include <linux/pnpbios.h>
8#include <linux/string.h> 7#include <linux/string.h>
9#include <linux/slab.h> 8#include <linux/slab.h>
10 9
@@ -16,6 +15,7 @@ inline void pcibios_penalize_isa_irq(int irq, int active)
16} 15}
17#endif /* CONFIG_PCI */ 16#endif /* CONFIG_PCI */
18 17
18#include "../base.h"
19#include "pnpbios.h" 19#include "pnpbios.h"
20 20
21/* standard resource tags */ 21/* standard resource tags */
@@ -53,97 +53,43 @@ inline void pcibios_penalize_isa_irq(int irq, int active)
53 * Allocated Resources 53 * Allocated Resources
54 */ 54 */
55 55
56static void pnpbios_parse_allocated_irqresource(struct pnp_resource_table *res, 56static void pnpbios_parse_allocated_ioresource(struct pnp_dev *dev,
57 int irq) 57 int start, int len)
58{ 58{
59 int i = 0; 59 int flags = 0;
60 60 int end = start + len - 1;
61 while (!(res->irq_resource[i].flags & IORESOURCE_UNSET)
62 && i < PNP_MAX_IRQ)
63 i++;
64 if (i < PNP_MAX_IRQ) {
65 res->irq_resource[i].flags = IORESOURCE_IRQ; // Also clears _UNSET flag
66 if (irq == -1) {
67 res->irq_resource[i].flags |= IORESOURCE_DISABLED;
68 return;
69 }
70 res->irq_resource[i].start =
71 res->irq_resource[i].end = (unsigned long)irq;
72 pcibios_penalize_isa_irq(irq, 1);
73 }
74}
75 61
76static void pnpbios_parse_allocated_dmaresource(struct pnp_resource_table *res, 62 if (len <= 0 || end >= 0x10003)
77 int dma) 63 flags |= IORESOURCE_DISABLED;
78{
79 int i = 0;
80
81 while (i < PNP_MAX_DMA &&
82 !(res->dma_resource[i].flags & IORESOURCE_UNSET))
83 i++;
84 if (i < PNP_MAX_DMA) {
85 res->dma_resource[i].flags = IORESOURCE_DMA; // Also clears _UNSET flag
86 if (dma == -1) {
87 res->dma_resource[i].flags |= IORESOURCE_DISABLED;
88 return;
89 }
90 res->dma_resource[i].start =
91 res->dma_resource[i].end = (unsigned long)dma;
92 }
93}
94 64
95static void pnpbios_parse_allocated_ioresource(struct pnp_resource_table *res, 65 pnp_add_io_resource(dev, start, end, flags);
96 int io, int len)
97{
98 int i = 0;
99
100 while (!(res->port_resource[i].flags & IORESOURCE_UNSET)
101 && i < PNP_MAX_PORT)
102 i++;
103 if (i < PNP_MAX_PORT) {
104 res->port_resource[i].flags = IORESOURCE_IO; // Also clears _UNSET flag
105 if (len <= 0 || (io + len - 1) >= 0x10003) {
106 res->port_resource[i].flags |= IORESOURCE_DISABLED;
107 return;
108 }
109 res->port_resource[i].start = (unsigned long)io;
110 res->port_resource[i].end = (unsigned long)(io + len - 1);
111 }
112} 66}
113 67
114static void pnpbios_parse_allocated_memresource(struct pnp_resource_table *res, 68static void pnpbios_parse_allocated_memresource(struct pnp_dev *dev,
115 int mem, int len) 69 int start, int len)
116{ 70{
117 int i = 0; 71 int flags = 0;
118 72 int end = start + len - 1;
119 while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) 73
120 && i < PNP_MAX_MEM) 74 if (len <= 0)
121 i++; 75 flags |= IORESOURCE_DISABLED;
122 if (i < PNP_MAX_MEM) { 76
123 res->mem_resource[i].flags = IORESOURCE_MEM; // Also clears _UNSET flag 77 pnp_add_mem_resource(dev, start, end, flags);
124 if (len <= 0) {
125 res->mem_resource[i].flags |= IORESOURCE_DISABLED;
126 return;
127 }
128 res->mem_resource[i].start = (unsigned long)mem;
129 res->mem_resource[i].end = (unsigned long)(mem + len - 1);
130 }
131} 78}
132 79
133static unsigned char *pnpbios_parse_allocated_resource_data(unsigned char *p, 80static unsigned char *pnpbios_parse_allocated_resource_data(struct pnp_dev *dev,
134 unsigned char *end, 81 unsigned char *p,
135 struct 82 unsigned char *end)
136 pnp_resource_table
137 *res)
138{ 83{
139 unsigned int len, tag; 84 unsigned int len, tag;
140 int io, size, mask, i; 85 int io, size, mask, i, flags;
141 86
142 if (!p) 87 if (!p)
143 return NULL; 88 return NULL;
144 89
145 /* Blank the resource table values */ 90 dev_dbg(&dev->dev, "parse allocated resources\n");
146 pnp_init_resource_table(res); 91
92 pnp_init_resources(dev);
147 93
148 while ((char *)p < (char *)end) { 94 while ((char *)p < (char *)end) {
149 95
@@ -163,7 +109,7 @@ static unsigned char *pnpbios_parse_allocated_resource_data(unsigned char *p,
163 goto len_err; 109 goto len_err;
164 io = *(short *)&p[4]; 110 io = *(short *)&p[4];
165 size = *(short *)&p[10]; 111 size = *(short *)&p[10];
166 pnpbios_parse_allocated_memresource(res, io, size); 112 pnpbios_parse_allocated_memresource(dev, io, size);
167 break; 113 break;
168 114
169 case LARGE_TAG_ANSISTR: 115 case LARGE_TAG_ANSISTR:
@@ -179,7 +125,7 @@ static unsigned char *pnpbios_parse_allocated_resource_data(unsigned char *p,
179 goto len_err; 125 goto len_err;
180 io = *(int *)&p[4]; 126 io = *(int *)&p[4];
181 size = *(int *)&p[16]; 127 size = *(int *)&p[16];
182 pnpbios_parse_allocated_memresource(res, io, size); 128 pnpbios_parse_allocated_memresource(dev, io, size);
183 break; 129 break;
184 130
185 case LARGE_TAG_FIXEDMEM32: 131 case LARGE_TAG_FIXEDMEM32:
@@ -187,29 +133,37 @@ static unsigned char *pnpbios_parse_allocated_resource_data(unsigned char *p,
187 goto len_err; 133 goto len_err;
188 io = *(int *)&p[4]; 134 io = *(int *)&p[4];
189 size = *(int *)&p[8]; 135 size = *(int *)&p[8];
190 pnpbios_parse_allocated_memresource(res, io, size); 136 pnpbios_parse_allocated_memresource(dev, io, size);
191 break; 137 break;
192 138
193 case SMALL_TAG_IRQ: 139 case SMALL_TAG_IRQ:
194 if (len < 2 || len > 3) 140 if (len < 2 || len > 3)
195 goto len_err; 141 goto len_err;
142 flags = 0;
196 io = -1; 143 io = -1;
197 mask = p[1] + p[2] * 256; 144 mask = p[1] + p[2] * 256;
198 for (i = 0; i < 16; i++, mask = mask >> 1) 145 for (i = 0; i < 16; i++, mask = mask >> 1)
199 if (mask & 0x01) 146 if (mask & 0x01)
200 io = i; 147 io = i;
201 pnpbios_parse_allocated_irqresource(res, io); 148 if (io != -1)
149 pcibios_penalize_isa_irq(io, 1);
150 else
151 flags = IORESOURCE_DISABLED;
152 pnp_add_irq_resource(dev, io, flags);
202 break; 153 break;
203 154
204 case SMALL_TAG_DMA: 155 case SMALL_TAG_DMA:
205 if (len != 2) 156 if (len != 2)
206 goto len_err; 157 goto len_err;
158 flags = 0;
207 io = -1; 159 io = -1;
208 mask = p[1]; 160 mask = p[1];
209 for (i = 0; i < 8; i++, mask = mask >> 1) 161 for (i = 0; i < 8; i++, mask = mask >> 1)
210 if (mask & 0x01) 162 if (mask & 0x01)
211 io = i; 163 io = i;
212 pnpbios_parse_allocated_dmaresource(res, io); 164 if (io == -1)
165 flags = IORESOURCE_DISABLED;
166 pnp_add_dma_resource(dev, io, flags);
213 break; 167 break;
214 168
215 case SMALL_TAG_PORT: 169 case SMALL_TAG_PORT:
@@ -217,7 +171,7 @@ static unsigned char *pnpbios_parse_allocated_resource_data(unsigned char *p,
217 goto len_err; 171 goto len_err;
218 io = p[2] + p[3] * 256; 172 io = p[2] + p[3] * 256;
219 size = p[7]; 173 size = p[7];
220 pnpbios_parse_allocated_ioresource(res, io, size); 174 pnpbios_parse_allocated_ioresource(dev, io, size);
221 break; 175 break;
222 176
223 case SMALL_TAG_VENDOR: 177 case SMALL_TAG_VENDOR:
@@ -229,7 +183,7 @@ static unsigned char *pnpbios_parse_allocated_resource_data(unsigned char *p,
229 goto len_err; 183 goto len_err;
230 io = p[1] + p[2] * 256; 184 io = p[1] + p[2] * 256;
231 size = p[3]; 185 size = p[3];
232 pnpbios_parse_allocated_ioresource(res, io, size); 186 pnpbios_parse_allocated_ioresource(dev, io, size);
233 break; 187 break;
234 188
235 case SMALL_TAG_END: 189 case SMALL_TAG_END:
@@ -239,9 +193,8 @@ static unsigned char *pnpbios_parse_allocated_resource_data(unsigned char *p,
239 193
240 default: /* an unkown tag */ 194 default: /* an unkown tag */
241len_err: 195len_err:
242 printk(KERN_ERR 196 dev_err(&dev->dev, "unknown tag %#x length %d\n",
243 "PnPBIOS: Unknown tag '0x%x', length '%d'.\n", 197 tag, len);
244 tag, len);
245 break; 198 break;
246 } 199 }
247 200
@@ -252,8 +205,7 @@ len_err:
252 p += len + 1; 205 p += len + 1;
253 } 206 }
254 207
255 printk(KERN_ERR 208 dev_err(&dev->dev, "no end tag in resource structure\n");
256 "PnPBIOS: Resource structure does not contain an end tag.\n");
257 209
258 return NULL; 210 return NULL;
259} 211}
@@ -262,7 +214,8 @@ len_err:
262 * Resource Configuration Options 214 * Resource Configuration Options
263 */ 215 */
264 216
265static __init void pnpbios_parse_mem_option(unsigned char *p, int size, 217static __init void pnpbios_parse_mem_option(struct pnp_dev *dev,
218 unsigned char *p, int size,
266 struct pnp_option *option) 219 struct pnp_option *option)
267{ 220{
268 struct pnp_mem *mem; 221 struct pnp_mem *mem;
@@ -275,10 +228,11 @@ static __init void pnpbios_parse_mem_option(unsigned char *p, int size,
275 mem->align = (p[9] << 8) | p[8]; 228 mem->align = (p[9] << 8) | p[8];
276 mem->size = ((p[11] << 8) | p[10]) << 8; 229 mem->size = ((p[11] << 8) | p[10]) << 8;
277 mem->flags = p[3]; 230 mem->flags = p[3];
278 pnp_register_mem_resource(option, mem); 231 pnp_register_mem_resource(dev, option, mem);
279} 232}
280 233
281static __init void pnpbios_parse_mem32_option(unsigned char *p, int size, 234static __init void pnpbios_parse_mem32_option(struct pnp_dev *dev,
235 unsigned char *p, int size,
282 struct pnp_option *option) 236 struct pnp_option *option)
283{ 237{
284 struct pnp_mem *mem; 238 struct pnp_mem *mem;
@@ -291,10 +245,11 @@ static __init void pnpbios_parse_mem32_option(unsigned char *p, int size,
291 mem->align = (p[15] << 24) | (p[14] << 16) | (p[13] << 8) | p[12]; 245 mem->align = (p[15] << 24) | (p[14] << 16) | (p[13] << 8) | p[12];
292 mem->size = (p[19] << 24) | (p[18] << 16) | (p[17] << 8) | p[16]; 246 mem->size = (p[19] << 24) | (p[18] << 16) | (p[17] << 8) | p[16];
293 mem->flags = p[3]; 247 mem->flags = p[3];
294 pnp_register_mem_resource(option, mem); 248 pnp_register_mem_resource(dev, option, mem);
295} 249}
296 250
297static __init void pnpbios_parse_fixed_mem32_option(unsigned char *p, int size, 251static __init void pnpbios_parse_fixed_mem32_option(struct pnp_dev *dev,
252 unsigned char *p, int size,
298 struct pnp_option *option) 253 struct pnp_option *option)
299{ 254{
300 struct pnp_mem *mem; 255 struct pnp_mem *mem;
@@ -306,11 +261,12 @@ static __init void pnpbios_parse_fixed_mem32_option(unsigned char *p, int size,
306 mem->size = (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | p[8]; 261 mem->size = (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | p[8];
307 mem->align = 0; 262 mem->align = 0;
308 mem->flags = p[3]; 263 mem->flags = p[3];
309 pnp_register_mem_resource(option, mem); 264 pnp_register_mem_resource(dev, option, mem);
310} 265}
311 266
312static __init void pnpbios_parse_irq_option(unsigned char *p, int size, 267static __init void pnpbios_parse_irq_option(struct pnp_dev *dev,
313 struct pnp_option *option) 268 unsigned char *p, int size,
269 struct pnp_option *option)
314{ 270{
315 struct pnp_irq *irq; 271 struct pnp_irq *irq;
316 unsigned long bits; 272 unsigned long bits;
@@ -324,11 +280,12 @@ static __init void pnpbios_parse_irq_option(unsigned char *p, int size,
324 irq->flags = p[3]; 280 irq->flags = p[3];
325 else 281 else
326 irq->flags = IORESOURCE_IRQ_HIGHEDGE; 282 irq->flags = IORESOURCE_IRQ_HIGHEDGE;
327 pnp_register_irq_resource(option, irq); 283 pnp_register_irq_resource(dev, option, irq);
328} 284}
329 285
330static __init void pnpbios_parse_dma_option(unsigned char *p, int size, 286static __init void pnpbios_parse_dma_option(struct pnp_dev *dev,
331 struct pnp_option *option) 287 unsigned char *p, int size,
288 struct pnp_option *option)
332{ 289{
333 struct pnp_dma *dma; 290 struct pnp_dma *dma;
334 291
@@ -337,10 +294,11 @@ static __init void pnpbios_parse_dma_option(unsigned char *p, int size,
337 return; 294 return;
338 dma->map = p[1]; 295 dma->map = p[1];
339 dma->flags = p[2]; 296 dma->flags = p[2];
340 pnp_register_dma_resource(option, dma); 297 pnp_register_dma_resource(dev, option, dma);
341} 298}
342 299
343static __init void pnpbios_parse_port_option(unsigned char *p, int size, 300static __init void pnpbios_parse_port_option(struct pnp_dev *dev,
301 unsigned char *p, int size,
344 struct pnp_option *option) 302 struct pnp_option *option)
345{ 303{
346 struct pnp_port *port; 304 struct pnp_port *port;
@@ -353,10 +311,11 @@ static __init void pnpbios_parse_port_option(unsigned char *p, int size,
353 port->align = p[6]; 311 port->align = p[6];
354 port->size = p[7]; 312 port->size = p[7];
355 port->flags = p[1] ? PNP_PORT_FLAG_16BITADDR : 0; 313 port->flags = p[1] ? PNP_PORT_FLAG_16BITADDR : 0;
356 pnp_register_port_resource(option, port); 314 pnp_register_port_resource(dev, option, port);
357} 315}
358 316
359static __init void pnpbios_parse_fixed_port_option(unsigned char *p, int size, 317static __init void pnpbios_parse_fixed_port_option(struct pnp_dev *dev,
318 unsigned char *p, int size,
360 struct pnp_option *option) 319 struct pnp_option *option)
361{ 320{
362 struct pnp_port *port; 321 struct pnp_port *port;
@@ -368,7 +327,7 @@ static __init void pnpbios_parse_fixed_port_option(unsigned char *p, int size,
368 port->size = p[3]; 327 port->size = p[3];
369 port->align = 0; 328 port->align = 0;
370 port->flags = PNP_PORT_FLAG_FIXED; 329 port->flags = PNP_PORT_FLAG_FIXED;
371 pnp_register_port_resource(option, port); 330 pnp_register_port_resource(dev, option, port);
372} 331}
373 332
374static __init unsigned char * 333static __init unsigned char *
@@ -382,6 +341,8 @@ pnpbios_parse_resource_option_data(unsigned char *p, unsigned char *end,
382 if (!p) 341 if (!p)
383 return NULL; 342 return NULL;
384 343
344 dev_dbg(&dev->dev, "parse resource options\n");
345
385 option_independent = option = pnp_register_independent_option(dev); 346 option_independent = option = pnp_register_independent_option(dev);
386 if (!option) 347 if (!option)
387 return NULL; 348 return NULL;
@@ -402,37 +363,37 @@ pnpbios_parse_resource_option_data(unsigned char *p, unsigned char *end,
402 case LARGE_TAG_MEM: 363 case LARGE_TAG_MEM:
403 if (len != 9) 364 if (len != 9)
404 goto len_err; 365 goto len_err;
405 pnpbios_parse_mem_option(p, len, option); 366 pnpbios_parse_mem_option(dev, p, len, option);
406 break; 367 break;
407 368
408 case LARGE_TAG_MEM32: 369 case LARGE_TAG_MEM32:
409 if (len != 17) 370 if (len != 17)
410 goto len_err; 371 goto len_err;
411 pnpbios_parse_mem32_option(p, len, option); 372 pnpbios_parse_mem32_option(dev, p, len, option);
412 break; 373 break;
413 374
414 case LARGE_TAG_FIXEDMEM32: 375 case LARGE_TAG_FIXEDMEM32:
415 if (len != 9) 376 if (len != 9)
416 goto len_err; 377 goto len_err;
417 pnpbios_parse_fixed_mem32_option(p, len, option); 378 pnpbios_parse_fixed_mem32_option(dev, p, len, option);
418 break; 379 break;
419 380
420 case SMALL_TAG_IRQ: 381 case SMALL_TAG_IRQ:
421 if (len < 2 || len > 3) 382 if (len < 2 || len > 3)
422 goto len_err; 383 goto len_err;
423 pnpbios_parse_irq_option(p, len, option); 384 pnpbios_parse_irq_option(dev, p, len, option);
424 break; 385 break;
425 386
426 case SMALL_TAG_DMA: 387 case SMALL_TAG_DMA:
427 if (len != 2) 388 if (len != 2)
428 goto len_err; 389 goto len_err;
429 pnpbios_parse_dma_option(p, len, option); 390 pnpbios_parse_dma_option(dev, p, len, option);
430 break; 391 break;
431 392
432 case SMALL_TAG_PORT: 393 case SMALL_TAG_PORT:
433 if (len != 7) 394 if (len != 7)
434 goto len_err; 395 goto len_err;
435 pnpbios_parse_port_option(p, len, option); 396 pnpbios_parse_port_option(dev, p, len, option);
436 break; 397 break;
437 398
438 case SMALL_TAG_VENDOR: 399 case SMALL_TAG_VENDOR:
@@ -442,7 +403,7 @@ pnpbios_parse_resource_option_data(unsigned char *p, unsigned char *end,
442 case SMALL_TAG_FIXEDPORT: 403 case SMALL_TAG_FIXEDPORT:
443 if (len != 3) 404 if (len != 3)
444 goto len_err; 405 goto len_err;
445 pnpbios_parse_fixed_port_option(p, len, option); 406 pnpbios_parse_fixed_port_option(dev, p, len, option);
446 break; 407 break;
447 408
448 case SMALL_TAG_STARTDEP: 409 case SMALL_TAG_STARTDEP:
@@ -460,9 +421,10 @@ pnpbios_parse_resource_option_data(unsigned char *p, unsigned char *end,
460 if (len != 0) 421 if (len != 0)
461 goto len_err; 422 goto len_err;
462 if (option_independent == option) 423 if (option_independent == option)
463 printk(KERN_WARNING 424 dev_warn(&dev->dev, "missing "
464 "PnPBIOS: Missing SMALL_TAG_STARTDEP tag\n"); 425 "SMALL_TAG_STARTDEP tag\n");
465 option = option_independent; 426 option = option_independent;
427 dev_dbg(&dev->dev, "end dependent options\n");
466 break; 428 break;
467 429
468 case SMALL_TAG_END: 430 case SMALL_TAG_END:
@@ -470,9 +432,8 @@ pnpbios_parse_resource_option_data(unsigned char *p, unsigned char *end,
470 432
471 default: /* an unkown tag */ 433 default: /* an unkown tag */
472len_err: 434len_err:
473 printk(KERN_ERR 435 dev_err(&dev->dev, "unknown tag %#x length %d\n",
474 "PnPBIOS: Unknown tag '0x%x', length '%d'.\n", 436 tag, len);
475 tag, len);
476 break; 437 break;
477 } 438 }
478 439
@@ -483,8 +444,7 @@ len_err:
483 p += len + 1; 444 p += len + 1;
484 } 445 }
485 446
486 printk(KERN_ERR 447 dev_err(&dev->dev, "no end tag in resource structure\n");
487 "PnPBIOS: Resource structure does not contain an end tag.\n");
488 448
489 return NULL; 449 return NULL;
490} 450}
@@ -493,32 +453,12 @@ len_err:
493 * Compatible Device IDs 453 * Compatible Device IDs
494 */ 454 */
495 455
496#define HEX(id,a) hex[((id)>>a) & 15]
497#define CHAR(id,a) (0x40 + (((id)>>a) & 31))
498
499void pnpid32_to_pnpid(u32 id, char *str)
500{
501 const char *hex = "0123456789abcdef";
502
503 id = be32_to_cpu(id);
504 str[0] = CHAR(id, 26);
505 str[1] = CHAR(id, 21);
506 str[2] = CHAR(id, 16);
507 str[3] = HEX(id, 12);
508 str[4] = HEX(id, 8);
509 str[5] = HEX(id, 4);
510 str[6] = HEX(id, 0);
511 str[7] = '\0';
512}
513
514#undef CHAR
515#undef HEX
516
517static unsigned char *pnpbios_parse_compatible_ids(unsigned char *p, 456static unsigned char *pnpbios_parse_compatible_ids(unsigned char *p,
518 unsigned char *end, 457 unsigned char *end,
519 struct pnp_dev *dev) 458 struct pnp_dev *dev)
520{ 459{
521 int len, tag; 460 int len, tag;
461 u32 eisa_id;
522 char id[8]; 462 char id[8];
523 struct pnp_id *dev_id; 463 struct pnp_id *dev_id;
524 464
@@ -548,13 +488,11 @@ static unsigned char *pnpbios_parse_compatible_ids(unsigned char *p,
548 case SMALL_TAG_COMPATDEVID: /* compatible ID */ 488 case SMALL_TAG_COMPATDEVID: /* compatible ID */
549 if (len != 4) 489 if (len != 4)
550 goto len_err; 490 goto len_err;
551 dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL); 491 eisa_id = p[1] | p[2] << 8 | p[3] << 16 | p[4] << 24;
492 pnp_eisa_id_to_string(eisa_id & PNP_EISA_ID_MASK, id);
493 dev_id = pnp_add_id(dev, id);
552 if (!dev_id) 494 if (!dev_id)
553 return NULL; 495 return NULL;
554 pnpid32_to_pnpid(p[1] | p[2] << 8 | p[3] << 16 | p[4] <<
555 24, id);
556 memcpy(&dev_id->id, id, 7);
557 pnp_add_id(dev_id, dev);
558 break; 496 break;
559 497
560 case SMALL_TAG_END: 498 case SMALL_TAG_END:
@@ -564,9 +502,8 @@ static unsigned char *pnpbios_parse_compatible_ids(unsigned char *p,
564 502
565 default: /* an unkown tag */ 503 default: /* an unkown tag */
566len_err: 504len_err:
567 printk(KERN_ERR 505 dev_err(&dev->dev, "unknown tag %#x length %d\n",
568 "PnPBIOS: Unknown tag '0x%x', length '%d'.\n", 506 tag, len);
569 tag, len);
570 break; 507 break;
571 } 508 }
572 509
@@ -577,8 +514,7 @@ len_err:
577 p += len + 1; 514 p += len + 1;
578 } 515 }
579 516
580 printk(KERN_ERR 517 dev_err(&dev->dev, "no end tag in resource structure\n");
581 "PnPBIOS: Resource structure does not contain an end tag.\n");
582 518
583 return NULL; 519 return NULL;
584} 520}
@@ -587,7 +523,8 @@ len_err:
587 * Allocated Resource Encoding 523 * Allocated Resource Encoding
588 */ 524 */
589 525
590static void pnpbios_encode_mem(unsigned char *p, struct resource *res) 526static void pnpbios_encode_mem(struct pnp_dev *dev, unsigned char *p,
527 struct resource *res)
591{ 528{
592 unsigned long base = res->start; 529 unsigned long base = res->start;
593 unsigned long len = res->end - res->start + 1; 530 unsigned long len = res->end - res->start + 1;
@@ -598,9 +535,13 @@ static void pnpbios_encode_mem(unsigned char *p, struct resource *res)
598 p[7] = ((base >> 8) >> 8) & 0xff; 535 p[7] = ((base >> 8) >> 8) & 0xff;
599 p[10] = (len >> 8) & 0xff; 536 p[10] = (len >> 8) & 0xff;
600 p[11] = ((len >> 8) >> 8) & 0xff; 537 p[11] = ((len >> 8) >> 8) & 0xff;
538
539 dev_dbg(&dev->dev, " encode mem %#llx-%#llx\n",
540 (unsigned long long) res->start, (unsigned long long) res->end);
601} 541}
602 542
603static void pnpbios_encode_mem32(unsigned char *p, struct resource *res) 543static void pnpbios_encode_mem32(struct pnp_dev *dev, unsigned char *p,
544 struct resource *res)
604{ 545{
605 unsigned long base = res->start; 546 unsigned long base = res->start;
606 unsigned long len = res->end - res->start + 1; 547 unsigned long len = res->end - res->start + 1;
@@ -617,9 +558,13 @@ static void pnpbios_encode_mem32(unsigned char *p, struct resource *res)
617 p[17] = (len >> 8) & 0xff; 558 p[17] = (len >> 8) & 0xff;
618 p[18] = (len >> 16) & 0xff; 559 p[18] = (len >> 16) & 0xff;
619 p[19] = (len >> 24) & 0xff; 560 p[19] = (len >> 24) & 0xff;
561
562 dev_dbg(&dev->dev, " encode mem32 %#llx-%#llx\n",
563 (unsigned long long) res->start, (unsigned long long) res->end);
620} 564}
621 565
622static void pnpbios_encode_fixed_mem32(unsigned char *p, struct resource *res) 566static void pnpbios_encode_fixed_mem32(struct pnp_dev *dev, unsigned char *p,
567 struct resource *res)
623{ 568{
624 unsigned long base = res->start; 569 unsigned long base = res->start;
625 unsigned long len = res->end - res->start + 1; 570 unsigned long len = res->end - res->start + 1;
@@ -632,26 +577,38 @@ static void pnpbios_encode_fixed_mem32(unsigned char *p, struct resource *res)
632 p[9] = (len >> 8) & 0xff; 577 p[9] = (len >> 8) & 0xff;
633 p[10] = (len >> 16) & 0xff; 578 p[10] = (len >> 16) & 0xff;
634 p[11] = (len >> 24) & 0xff; 579 p[11] = (len >> 24) & 0xff;
580
581 dev_dbg(&dev->dev, " encode fixed_mem32 %#llx-%#llx\n",
582 (unsigned long long) res->start, (unsigned long long) res->end);
635} 583}
636 584
637static void pnpbios_encode_irq(unsigned char *p, struct resource *res) 585static void pnpbios_encode_irq(struct pnp_dev *dev, unsigned char *p,
586 struct resource *res)
638{ 587{
639 unsigned long map = 0; 588 unsigned long map = 0;
640 589
641 map = 1 << res->start; 590 map = 1 << res->start;
642 p[1] = map & 0xff; 591 p[1] = map & 0xff;
643 p[2] = (map >> 8) & 0xff; 592 p[2] = (map >> 8) & 0xff;
593
594 dev_dbg(&dev->dev, " encode irq %llu\n",
595 (unsigned long long)res->start);
644} 596}
645 597
646static void pnpbios_encode_dma(unsigned char *p, struct resource *res) 598static void pnpbios_encode_dma(struct pnp_dev *dev, unsigned char *p,
599 struct resource *res)
647{ 600{
648 unsigned long map = 0; 601 unsigned long map = 0;
649 602
650 map = 1 << res->start; 603 map = 1 << res->start;
651 p[1] = map & 0xff; 604 p[1] = map & 0xff;
605
606 dev_dbg(&dev->dev, " encode dma %llu\n",
607 (unsigned long long)res->start);
652} 608}
653 609
654static void pnpbios_encode_port(unsigned char *p, struct resource *res) 610static void pnpbios_encode_port(struct pnp_dev *dev, unsigned char *p,
611 struct resource *res)
655{ 612{
656 unsigned long base = res->start; 613 unsigned long base = res->start;
657 unsigned long len = res->end - res->start + 1; 614 unsigned long len = res->end - res->start + 1;
@@ -661,9 +618,13 @@ static void pnpbios_encode_port(unsigned char *p, struct resource *res)
661 p[4] = base & 0xff; 618 p[4] = base & 0xff;
662 p[5] = (base >> 8) & 0xff; 619 p[5] = (base >> 8) & 0xff;
663 p[7] = len & 0xff; 620 p[7] = len & 0xff;
621
622 dev_dbg(&dev->dev, " encode io %#llx-%#llx\n",
623 (unsigned long long) res->start, (unsigned long long) res->end);
664} 624}
665 625
666static void pnpbios_encode_fixed_port(unsigned char *p, struct resource *res) 626static void pnpbios_encode_fixed_port(struct pnp_dev *dev, unsigned char *p,
627 struct resource *res)
667{ 628{
668 unsigned long base = res->start; 629 unsigned long base = res->start;
669 unsigned long len = res->end - res->start + 1; 630 unsigned long len = res->end - res->start + 1;
@@ -671,13 +632,15 @@ static void pnpbios_encode_fixed_port(unsigned char *p, struct resource *res)
671 p[1] = base & 0xff; 632 p[1] = base & 0xff;
672 p[2] = (base >> 8) & 0xff; 633 p[2] = (base >> 8) & 0xff;
673 p[3] = len & 0xff; 634 p[3] = len & 0xff;
635
636 dev_dbg(&dev->dev, " encode fixed_io %#llx-%#llx\n",
637 (unsigned long long) res->start, (unsigned long long) res->end);
674} 638}
675 639
676static unsigned char *pnpbios_encode_allocated_resource_data(unsigned char *p, 640static unsigned char *pnpbios_encode_allocated_resource_data(struct pnp_dev
677 unsigned char *end, 641 *dev,
678 struct 642 unsigned char *p,
679 pnp_resource_table 643 unsigned char *end)
680 *res)
681{ 644{
682 unsigned int len, tag; 645 unsigned int len, tag;
683 int port = 0, irq = 0, dma = 0, mem = 0; 646 int port = 0, irq = 0, dma = 0, mem = 0;
@@ -701,42 +664,48 @@ static unsigned char *pnpbios_encode_allocated_resource_data(unsigned char *p,
701 case LARGE_TAG_MEM: 664 case LARGE_TAG_MEM:
702 if (len != 9) 665 if (len != 9)
703 goto len_err; 666 goto len_err;
704 pnpbios_encode_mem(p, &res->mem_resource[mem]); 667 pnpbios_encode_mem(dev, p,
668 pnp_get_resource(dev, IORESOURCE_MEM, mem));
705 mem++; 669 mem++;
706 break; 670 break;
707 671
708 case LARGE_TAG_MEM32: 672 case LARGE_TAG_MEM32:
709 if (len != 17) 673 if (len != 17)
710 goto len_err; 674 goto len_err;
711 pnpbios_encode_mem32(p, &res->mem_resource[mem]); 675 pnpbios_encode_mem32(dev, p,
676 pnp_get_resource(dev, IORESOURCE_MEM, mem));
712 mem++; 677 mem++;
713 break; 678 break;
714 679
715 case LARGE_TAG_FIXEDMEM32: 680 case LARGE_TAG_FIXEDMEM32:
716 if (len != 9) 681 if (len != 9)
717 goto len_err; 682 goto len_err;
718 pnpbios_encode_fixed_mem32(p, &res->mem_resource[mem]); 683 pnpbios_encode_fixed_mem32(dev, p,
684 pnp_get_resource(dev, IORESOURCE_MEM, mem));
719 mem++; 685 mem++;
720 break; 686 break;
721 687
722 case SMALL_TAG_IRQ: 688 case SMALL_TAG_IRQ:
723 if (len < 2 || len > 3) 689 if (len < 2 || len > 3)
724 goto len_err; 690 goto len_err;
725 pnpbios_encode_irq(p, &res->irq_resource[irq]); 691 pnpbios_encode_irq(dev, p,
692 pnp_get_resource(dev, IORESOURCE_IRQ, irq));
726 irq++; 693 irq++;
727 break; 694 break;
728 695
729 case SMALL_TAG_DMA: 696 case SMALL_TAG_DMA:
730 if (len != 2) 697 if (len != 2)
731 goto len_err; 698 goto len_err;
732 pnpbios_encode_dma(p, &res->dma_resource[dma]); 699 pnpbios_encode_dma(dev, p,
700 pnp_get_resource(dev, IORESOURCE_DMA, dma));
733 dma++; 701 dma++;
734 break; 702 break;
735 703
736 case SMALL_TAG_PORT: 704 case SMALL_TAG_PORT:
737 if (len != 7) 705 if (len != 7)
738 goto len_err; 706 goto len_err;
739 pnpbios_encode_port(p, &res->port_resource[port]); 707 pnpbios_encode_port(dev, p,
708 pnp_get_resource(dev, IORESOURCE_IO, port));
740 port++; 709 port++;
741 break; 710 break;
742 711
@@ -747,7 +716,8 @@ static unsigned char *pnpbios_encode_allocated_resource_data(unsigned char *p,
747 case SMALL_TAG_FIXEDPORT: 716 case SMALL_TAG_FIXEDPORT:
748 if (len != 3) 717 if (len != 3)
749 goto len_err; 718 goto len_err;
750 pnpbios_encode_fixed_port(p, &res->port_resource[port]); 719 pnpbios_encode_fixed_port(dev, p,
720 pnp_get_resource(dev, IORESOURCE_IO, port));
751 port++; 721 port++;
752 break; 722 break;
753 723
@@ -758,9 +728,8 @@ static unsigned char *pnpbios_encode_allocated_resource_data(unsigned char *p,
758 728
759 default: /* an unkown tag */ 729 default: /* an unkown tag */
760len_err: 730len_err:
761 printk(KERN_ERR 731 dev_err(&dev->dev, "unknown tag %#x length %d\n",
762 "PnPBIOS: Unknown tag '0x%x', length '%d'.\n", 732 tag, len);
763 tag, len);
764 break; 733 break;
765 } 734 }
766 735
@@ -771,8 +740,7 @@ len_err:
771 p += len + 1; 740 p += len + 1;
772 } 741 }
773 742
774 printk(KERN_ERR 743 dev_err(&dev->dev, "no end tag in resource structure\n");
775 "PnPBIOS: Resource structure does not contain an end tag.\n");
776 744
777 return NULL; 745 return NULL;
778} 746}
@@ -787,7 +755,7 @@ int __init pnpbios_parse_data_stream(struct pnp_dev *dev,
787 unsigned char *p = (char *)node->data; 755 unsigned char *p = (char *)node->data;
788 unsigned char *end = (char *)(node->data + node->size); 756 unsigned char *end = (char *)(node->data + node->size);
789 757
790 p = pnpbios_parse_allocated_resource_data(p, end, &dev->res); 758 p = pnpbios_parse_allocated_resource_data(dev, p, end);
791 if (!p) 759 if (!p)
792 return -EIO; 760 return -EIO;
793 p = pnpbios_parse_resource_option_data(p, end, dev); 761 p = pnpbios_parse_resource_option_data(p, end, dev);
@@ -799,25 +767,25 @@ int __init pnpbios_parse_data_stream(struct pnp_dev *dev,
799 return 0; 767 return 0;
800} 768}
801 769
802int pnpbios_read_resources_from_node(struct pnp_resource_table *res, 770int pnpbios_read_resources_from_node(struct pnp_dev *dev,
803 struct pnp_bios_node *node) 771 struct pnp_bios_node *node)
804{ 772{
805 unsigned char *p = (char *)node->data; 773 unsigned char *p = (char *)node->data;
806 unsigned char *end = (char *)(node->data + node->size); 774 unsigned char *end = (char *)(node->data + node->size);
807 775
808 p = pnpbios_parse_allocated_resource_data(p, end, res); 776 p = pnpbios_parse_allocated_resource_data(dev, p, end);
809 if (!p) 777 if (!p)
810 return -EIO; 778 return -EIO;
811 return 0; 779 return 0;
812} 780}
813 781
814int pnpbios_write_resources_to_node(struct pnp_resource_table *res, 782int pnpbios_write_resources_to_node(struct pnp_dev *dev,
815 struct pnp_bios_node *node) 783 struct pnp_bios_node *node)
816{ 784{
817 unsigned char *p = (char *)node->data; 785 unsigned char *p = (char *)node->data;
818 unsigned char *end = (char *)(node->data + node->size); 786 unsigned char *end = (char *)(node->data + node->size);
819 787
820 p = pnpbios_encode_allocated_resource_data(p, end, res); 788 p = pnpbios_encode_allocated_resource_data(dev, p, end);
821 if (!p) 789 if (!p)
822 return -EIO; 790 return -EIO;
823 return 0; 791 return 0;
diff --git a/drivers/pnp/quirks.c b/drivers/pnp/quirks.c
index e4daf4635c48..d049a2279fea 100644
--- a/drivers/pnp/quirks.c
+++ b/drivers/pnp/quirks.c
@@ -117,6 +117,7 @@ static void quirk_sb16audio_resources(struct pnp_dev *dev)
117static void quirk_system_pci_resources(struct pnp_dev *dev) 117static void quirk_system_pci_resources(struct pnp_dev *dev)
118{ 118{
119 struct pci_dev *pdev = NULL; 119 struct pci_dev *pdev = NULL;
120 struct resource *res;
120 resource_size_t pnp_start, pnp_end, pci_start, pci_end; 121 resource_size_t pnp_start, pnp_end, pci_start, pci_end;
121 int i, j; 122 int i, j;
122 123
@@ -137,13 +138,15 @@ static void quirk_system_pci_resources(struct pnp_dev *dev)
137 138
138 pci_start = pci_resource_start(pdev, i); 139 pci_start = pci_resource_start(pdev, i);
139 pci_end = pci_resource_end(pdev, i); 140 pci_end = pci_resource_end(pdev, i);
140 for (j = 0; j < PNP_MAX_MEM; j++) { 141 for (j = 0;
141 if (!pnp_mem_valid(dev, j) || 142 (res = pnp_get_resource(dev, IORESOURCE_MEM, j));
142 pnp_mem_len(dev, j) == 0) 143 j++) {
144 if (res->flags & IORESOURCE_UNSET ||
145 (res->start == 0 && res->end == 0))
143 continue; 146 continue;
144 147
145 pnp_start = pnp_mem_start(dev, j); 148 pnp_start = res->start;
146 pnp_end = pnp_mem_end(dev, j); 149 pnp_end = res->end;
147 150
148 /* 151 /*
149 * If the PNP region doesn't overlap the PCI 152 * If the PNP region doesn't overlap the PCI
@@ -176,7 +179,7 @@ static void quirk_system_pci_resources(struct pnp_dev *dev)
176 pci_name(pdev), i, 179 pci_name(pdev), i,
177 (unsigned long long) pci_start, 180 (unsigned long long) pci_start,
178 (unsigned long long) pci_end); 181 (unsigned long long) pci_end);
179 pnp_mem_flags(dev, j) = 0; 182 res->flags = 0;
180 } 183 }
181 } 184 }
182 } 185 }
diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
index e50ebcffb962..2041620d5682 100644
--- a/drivers/pnp/resource.c
+++ b/drivers/pnp/resource.c
@@ -53,6 +53,8 @@ struct pnp_option *pnp_register_independent_option(struct pnp_dev *dev)
53 if (dev->independent) 53 if (dev->independent)
54 dev_err(&dev->dev, "independent resource already registered\n"); 54 dev_err(&dev->dev, "independent resource already registered\n");
55 dev->independent = option; 55 dev->independent = option;
56
57 dev_dbg(&dev->dev, "new independent option\n");
56 return option; 58 return option;
57} 59}
58 60
@@ -70,12 +72,18 @@ struct pnp_option *pnp_register_dependent_option(struct pnp_dev *dev,
70 parent->next = option; 72 parent->next = option;
71 } else 73 } else
72 dev->dependent = option; 74 dev->dependent = option;
75
76 dev_dbg(&dev->dev, "new dependent option (priority %#x)\n", priority);
73 return option; 77 return option;
74} 78}
75 79
76int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data) 80int pnp_register_irq_resource(struct pnp_dev *dev, struct pnp_option *option,
81 struct pnp_irq *data)
77{ 82{
78 struct pnp_irq *ptr; 83 struct pnp_irq *ptr;
84#ifdef DEBUG
85 char buf[PNP_IRQ_NR]; /* hex-encoded, so this is overkill but safe */
86#endif
79 87
80 ptr = option->irq; 88 ptr = option->irq;
81 while (ptr && ptr->next) 89 while (ptr && ptr->next)
@@ -94,10 +102,17 @@ int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data)
94 pcibios_penalize_isa_irq(i, 0); 102 pcibios_penalize_isa_irq(i, 0);
95 } 103 }
96#endif 104#endif
105
106#ifdef DEBUG
107 bitmap_scnprintf(buf, sizeof(buf), data->map, PNP_IRQ_NR);
108 dev_dbg(&dev->dev, " irq bitmask %s flags %#x\n", buf,
109 data->flags);
110#endif
97 return 0; 111 return 0;
98} 112}
99 113
100int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data) 114int pnp_register_dma_resource(struct pnp_dev *dev, struct pnp_option *option,
115 struct pnp_dma *data)
101{ 116{
102 struct pnp_dma *ptr; 117 struct pnp_dma *ptr;
103 118
@@ -109,10 +124,13 @@ int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data)
109 else 124 else
110 option->dma = data; 125 option->dma = data;
111 126
127 dev_dbg(&dev->dev, " dma bitmask %#x flags %#x\n", data->map,
128 data->flags);
112 return 0; 129 return 0;
113} 130}
114 131
115int pnp_register_port_resource(struct pnp_option *option, struct pnp_port *data) 132int pnp_register_port_resource(struct pnp_dev *dev, struct pnp_option *option,
133 struct pnp_port *data)
116{ 134{
117 struct pnp_port *ptr; 135 struct pnp_port *ptr;
118 136
@@ -124,10 +142,14 @@ int pnp_register_port_resource(struct pnp_option *option, struct pnp_port *data)
124 else 142 else
125 option->port = data; 143 option->port = data;
126 144
145 dev_dbg(&dev->dev, " io "
146 "min %#x max %#x align %d size %d flags %#x\n",
147 data->min, data->max, data->align, data->size, data->flags);
127 return 0; 148 return 0;
128} 149}
129 150
130int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data) 151int pnp_register_mem_resource(struct pnp_dev *dev, struct pnp_option *option,
152 struct pnp_mem *data)
131{ 153{
132 struct pnp_mem *ptr; 154 struct pnp_mem *ptr;
133 155
@@ -138,6 +160,10 @@ int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data)
138 ptr->next = data; 160 ptr->next = data;
139 else 161 else
140 option->mem = data; 162 option->mem = data;
163
164 dev_dbg(&dev->dev, " mem "
165 "min %#x max %#x align %d size %d flags %#x\n",
166 data->min, data->max, data->align, data->size, data->flags);
141 return 0; 167 return 0;
142} 168}
143 169
@@ -213,17 +239,18 @@ void pnp_free_option(struct pnp_option *option)
213#define cannot_compare(flags) \ 239#define cannot_compare(flags) \
214((flags) & (IORESOURCE_UNSET | IORESOURCE_DISABLED)) 240((flags) & (IORESOURCE_UNSET | IORESOURCE_DISABLED))
215 241
216int pnp_check_port(struct pnp_dev *dev, int idx) 242int pnp_check_port(struct pnp_dev *dev, struct resource *res)
217{ 243{
218 int tmp; 244 int i;
219 struct pnp_dev *tdev; 245 struct pnp_dev *tdev;
246 struct resource *tres;
220 resource_size_t *port, *end, *tport, *tend; 247 resource_size_t *port, *end, *tport, *tend;
221 248
222 port = &dev->res.port_resource[idx].start; 249 port = &res->start;
223 end = &dev->res.port_resource[idx].end; 250 end = &res->end;
224 251
225 /* if the resource doesn't exist, don't complain about it */ 252 /* if the resource doesn't exist, don't complain about it */
226 if (cannot_compare(dev->res.port_resource[idx].flags)) 253 if (cannot_compare(res->flags))
227 return 1; 254 return 1;
228 255
229 /* check if the resource is already in use, skip if the 256 /* check if the resource is already in use, skip if the
@@ -234,18 +261,18 @@ int pnp_check_port(struct pnp_dev *dev, int idx)
234 } 261 }
235 262
236 /* check if the resource is reserved */ 263 /* check if the resource is reserved */
237 for (tmp = 0; tmp < 8; tmp++) { 264 for (i = 0; i < 8; i++) {
238 int rport = pnp_reserve_io[tmp << 1]; 265 int rport = pnp_reserve_io[i << 1];
239 int rend = pnp_reserve_io[(tmp << 1) + 1] + rport - 1; 266 int rend = pnp_reserve_io[(i << 1) + 1] + rport - 1;
240 if (ranged_conflict(port, end, &rport, &rend)) 267 if (ranged_conflict(port, end, &rport, &rend))
241 return 0; 268 return 0;
242 } 269 }
243 270
244 /* check for internal conflicts */ 271 /* check for internal conflicts */
245 for (tmp = 0; tmp < PNP_MAX_PORT && tmp != idx; tmp++) { 272 for (i = 0; (tres = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) {
246 if (dev->res.port_resource[tmp].flags & IORESOURCE_IO) { 273 if (tres != res && tres->flags & IORESOURCE_IO) {
247 tport = &dev->res.port_resource[tmp].start; 274 tport = &tres->start;
248 tend = &dev->res.port_resource[tmp].end; 275 tend = &tres->end;
249 if (ranged_conflict(port, end, tport, tend)) 276 if (ranged_conflict(port, end, tport, tend))
250 return 0; 277 return 0;
251 } 278 }
@@ -255,13 +282,14 @@ int pnp_check_port(struct pnp_dev *dev, int idx)
255 pnp_for_each_dev(tdev) { 282 pnp_for_each_dev(tdev) {
256 if (tdev == dev) 283 if (tdev == dev)
257 continue; 284 continue;
258 for (tmp = 0; tmp < PNP_MAX_PORT; tmp++) { 285 for (i = 0;
259 if (tdev->res.port_resource[tmp].flags & IORESOURCE_IO) { 286 (tres = pnp_get_resource(tdev, IORESOURCE_IO, i));
260 if (cannot_compare 287 i++) {
261 (tdev->res.port_resource[tmp].flags)) 288 if (tres->flags & IORESOURCE_IO) {
289 if (cannot_compare(tres->flags))
262 continue; 290 continue;
263 tport = &tdev->res.port_resource[tmp].start; 291 tport = &tres->start;
264 tend = &tdev->res.port_resource[tmp].end; 292 tend = &tres->end;
265 if (ranged_conflict(port, end, tport, tend)) 293 if (ranged_conflict(port, end, tport, tend))
266 return 0; 294 return 0;
267 } 295 }
@@ -271,17 +299,18 @@ int pnp_check_port(struct pnp_dev *dev, int idx)
271 return 1; 299 return 1;
272} 300}
273 301
274int pnp_check_mem(struct pnp_dev *dev, int idx) 302int pnp_check_mem(struct pnp_dev *dev, struct resource *res)
275{ 303{
276 int tmp; 304 int i;
277 struct pnp_dev *tdev; 305 struct pnp_dev *tdev;
306 struct resource *tres;
278 resource_size_t *addr, *end, *taddr, *tend; 307 resource_size_t *addr, *end, *taddr, *tend;
279 308
280 addr = &dev->res.mem_resource[idx].start; 309 addr = &res->start;
281 end = &dev->res.mem_resource[idx].end; 310 end = &res->end;
282 311
283 /* if the resource doesn't exist, don't complain about it */ 312 /* if the resource doesn't exist, don't complain about it */
284 if (cannot_compare(dev->res.mem_resource[idx].flags)) 313 if (cannot_compare(res->flags))
285 return 1; 314 return 1;
286 315
287 /* check if the resource is already in use, skip if the 316 /* check if the resource is already in use, skip if the
@@ -292,18 +321,18 @@ int pnp_check_mem(struct pnp_dev *dev, int idx)
292 } 321 }
293 322
294 /* check if the resource is reserved */ 323 /* check if the resource is reserved */
295 for (tmp = 0; tmp < 8; tmp++) { 324 for (i = 0; i < 8; i++) {
296 int raddr = pnp_reserve_mem[tmp << 1]; 325 int raddr = pnp_reserve_mem[i << 1];
297 int rend = pnp_reserve_mem[(tmp << 1) + 1] + raddr - 1; 326 int rend = pnp_reserve_mem[(i << 1) + 1] + raddr - 1;
298 if (ranged_conflict(addr, end, &raddr, &rend)) 327 if (ranged_conflict(addr, end, &raddr, &rend))
299 return 0; 328 return 0;
300 } 329 }
301 330
302 /* check for internal conflicts */ 331 /* check for internal conflicts */
303 for (tmp = 0; tmp < PNP_MAX_MEM && tmp != idx; tmp++) { 332 for (i = 0; (tres = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) {
304 if (dev->res.mem_resource[tmp].flags & IORESOURCE_MEM) { 333 if (tres != res && tres->flags & IORESOURCE_MEM) {
305 taddr = &dev->res.mem_resource[tmp].start; 334 taddr = &tres->start;
306 tend = &dev->res.mem_resource[tmp].end; 335 tend = &tres->end;
307 if (ranged_conflict(addr, end, taddr, tend)) 336 if (ranged_conflict(addr, end, taddr, tend))
308 return 0; 337 return 0;
309 } 338 }
@@ -313,13 +342,14 @@ int pnp_check_mem(struct pnp_dev *dev, int idx)
313 pnp_for_each_dev(tdev) { 342 pnp_for_each_dev(tdev) {
314 if (tdev == dev) 343 if (tdev == dev)
315 continue; 344 continue;
316 for (tmp = 0; tmp < PNP_MAX_MEM; tmp++) { 345 for (i = 0;
317 if (tdev->res.mem_resource[tmp].flags & IORESOURCE_MEM) { 346 (tres = pnp_get_resource(tdev, IORESOURCE_MEM, i));
318 if (cannot_compare 347 i++) {
319 (tdev->res.mem_resource[tmp].flags)) 348 if (tres->flags & IORESOURCE_MEM) {
349 if (cannot_compare(tres->flags))
320 continue; 350 continue;
321 taddr = &tdev->res.mem_resource[tmp].start; 351 taddr = &tres->start;
322 tend = &tdev->res.mem_resource[tmp].end; 352 tend = &tres->end;
323 if (ranged_conflict(addr, end, taddr, tend)) 353 if (ranged_conflict(addr, end, taddr, tend))
324 return 0; 354 return 0;
325 } 355 }
@@ -334,14 +364,17 @@ static irqreturn_t pnp_test_handler(int irq, void *dev_id)
334 return IRQ_HANDLED; 364 return IRQ_HANDLED;
335} 365}
336 366
337int pnp_check_irq(struct pnp_dev *dev, int idx) 367int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
338{ 368{
339 int tmp; 369 int i;
340 struct pnp_dev *tdev; 370 struct pnp_dev *tdev;
341 resource_size_t *irq = &dev->res.irq_resource[idx].start; 371 struct resource *tres;
372 resource_size_t *irq;
373
374 irq = &res->start;
342 375
343 /* if the resource doesn't exist, don't complain about it */ 376 /* if the resource doesn't exist, don't complain about it */
344 if (cannot_compare(dev->res.irq_resource[idx].flags)) 377 if (cannot_compare(res->flags))
345 return 1; 378 return 1;
346 379
347 /* check if the resource is valid */ 380 /* check if the resource is valid */
@@ -349,15 +382,15 @@ int pnp_check_irq(struct pnp_dev *dev, int idx)
349 return 0; 382 return 0;
350 383
351 /* check if the resource is reserved */ 384 /* check if the resource is reserved */
352 for (tmp = 0; tmp < 16; tmp++) { 385 for (i = 0; i < 16; i++) {
353 if (pnp_reserve_irq[tmp] == *irq) 386 if (pnp_reserve_irq[i] == *irq)
354 return 0; 387 return 0;
355 } 388 }
356 389
357 /* check for internal conflicts */ 390 /* check for internal conflicts */
358 for (tmp = 0; tmp < PNP_MAX_IRQ && tmp != idx; tmp++) { 391 for (i = 0; (tres = pnp_get_resource(dev, IORESOURCE_IRQ, i)); i++) {
359 if (dev->res.irq_resource[tmp].flags & IORESOURCE_IRQ) { 392 if (tres != res && tres->flags & IORESOURCE_IRQ) {
360 if (dev->res.irq_resource[tmp].start == *irq) 393 if (tres->start == *irq)
361 return 0; 394 return 0;
362 } 395 }
363 } 396 }
@@ -388,12 +421,13 @@ int pnp_check_irq(struct pnp_dev *dev, int idx)
388 pnp_for_each_dev(tdev) { 421 pnp_for_each_dev(tdev) {
389 if (tdev == dev) 422 if (tdev == dev)
390 continue; 423 continue;
391 for (tmp = 0; tmp < PNP_MAX_IRQ; tmp++) { 424 for (i = 0;
392 if (tdev->res.irq_resource[tmp].flags & IORESOURCE_IRQ) { 425 (tres = pnp_get_resource(tdev, IORESOURCE_IRQ, i));
393 if (cannot_compare 426 i++) {
394 (tdev->res.irq_resource[tmp].flags)) 427 if (tres->flags & IORESOURCE_IRQ) {
428 if (cannot_compare(tres->flags))
395 continue; 429 continue;
396 if ((tdev->res.irq_resource[tmp].start == *irq)) 430 if (tres->start == *irq)
397 return 0; 431 return 0;
398 } 432 }
399 } 433 }
@@ -402,15 +436,18 @@ int pnp_check_irq(struct pnp_dev *dev, int idx)
402 return 1; 436 return 1;
403} 437}
404 438
405int pnp_check_dma(struct pnp_dev *dev, int idx) 439int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
406{ 440{
407#ifndef CONFIG_IA64 441#ifndef CONFIG_IA64
408 int tmp; 442 int i;
409 struct pnp_dev *tdev; 443 struct pnp_dev *tdev;
410 resource_size_t *dma = &dev->res.dma_resource[idx].start; 444 struct resource *tres;
445 resource_size_t *dma;
446
447 dma = &res->start;
411 448
412 /* if the resource doesn't exist, don't complain about it */ 449 /* if the resource doesn't exist, don't complain about it */
413 if (cannot_compare(dev->res.dma_resource[idx].flags)) 450 if (cannot_compare(res->flags))
414 return 1; 451 return 1;
415 452
416 /* check if the resource is valid */ 453 /* check if the resource is valid */
@@ -418,15 +455,15 @@ int pnp_check_dma(struct pnp_dev *dev, int idx)
418 return 0; 455 return 0;
419 456
420 /* check if the resource is reserved */ 457 /* check if the resource is reserved */
421 for (tmp = 0; tmp < 8; tmp++) { 458 for (i = 0; i < 8; i++) {
422 if (pnp_reserve_dma[tmp] == *dma) 459 if (pnp_reserve_dma[i] == *dma)
423 return 0; 460 return 0;
424 } 461 }
425 462
426 /* check for internal conflicts */ 463 /* check for internal conflicts */
427 for (tmp = 0; tmp < PNP_MAX_DMA && tmp != idx; tmp++) { 464 for (i = 0; (tres = pnp_get_resource(dev, IORESOURCE_DMA, i)); i++) {
428 if (dev->res.dma_resource[tmp].flags & IORESOURCE_DMA) { 465 if (tres != res && tres->flags & IORESOURCE_DMA) {
429 if (dev->res.dma_resource[tmp].start == *dma) 466 if (tres->start == *dma)
430 return 0; 467 return 0;
431 } 468 }
432 } 469 }
@@ -443,12 +480,13 @@ int pnp_check_dma(struct pnp_dev *dev, int idx)
443 pnp_for_each_dev(tdev) { 480 pnp_for_each_dev(tdev) {
444 if (tdev == dev) 481 if (tdev == dev)
445 continue; 482 continue;
446 for (tmp = 0; tmp < PNP_MAX_DMA; tmp++) { 483 for (i = 0;
447 if (tdev->res.dma_resource[tmp].flags & IORESOURCE_DMA) { 484 (tres = pnp_get_resource(tdev, IORESOURCE_DMA, i));
448 if (cannot_compare 485 i++) {
449 (tdev->res.dma_resource[tmp].flags)) 486 if (tres->flags & IORESOURCE_DMA) {
487 if (cannot_compare(tres->flags))
450 continue; 488 continue;
451 if ((tdev->res.dma_resource[tmp].start == *dma)) 489 if (tres->start == *dma)
452 return 0; 490 return 0;
453 } 491 }
454 } 492 }
@@ -461,6 +499,193 @@ int pnp_check_dma(struct pnp_dev *dev, int idx)
461#endif 499#endif
462} 500}
463 501
502struct pnp_resource *pnp_get_pnp_resource(struct pnp_dev *dev,
503 unsigned int type, unsigned int num)
504{
505 struct pnp_resource_table *res = dev->res;
506
507 switch (type) {
508 case IORESOURCE_IO:
509 if (num >= PNP_MAX_PORT)
510 return NULL;
511 return &res->port[num];
512 case IORESOURCE_MEM:
513 if (num >= PNP_MAX_MEM)
514 return NULL;
515 return &res->mem[num];
516 case IORESOURCE_IRQ:
517 if (num >= PNP_MAX_IRQ)
518 return NULL;
519 return &res->irq[num];
520 case IORESOURCE_DMA:
521 if (num >= PNP_MAX_DMA)
522 return NULL;
523 return &res->dma[num];
524 }
525 return NULL;
526}
527
528struct resource *pnp_get_resource(struct pnp_dev *dev,
529 unsigned int type, unsigned int num)
530{
531 struct pnp_resource *pnp_res;
532
533 pnp_res = pnp_get_pnp_resource(dev, type, num);
534 if (pnp_res)
535 return &pnp_res->res;
536
537 return NULL;
538}
539EXPORT_SYMBOL(pnp_get_resource);
540
541static struct pnp_resource *pnp_new_resource(struct pnp_dev *dev, int type)
542{
543 struct pnp_resource *pnp_res;
544 int i;
545
546 switch (type) {
547 case IORESOURCE_IO:
548 for (i = 0; i < PNP_MAX_PORT; i++) {
549 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IO, i);
550 if (pnp_res && !pnp_resource_valid(&pnp_res->res))
551 return pnp_res;
552 }
553 break;
554 case IORESOURCE_MEM:
555 for (i = 0; i < PNP_MAX_MEM; i++) {
556 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_MEM, i);
557 if (pnp_res && !pnp_resource_valid(&pnp_res->res))
558 return pnp_res;
559 }
560 break;
561 case IORESOURCE_IRQ:
562 for (i = 0; i < PNP_MAX_IRQ; i++) {
563 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IRQ, i);
564 if (pnp_res && !pnp_resource_valid(&pnp_res->res))
565 return pnp_res;
566 }
567 break;
568 case IORESOURCE_DMA:
569 for (i = 0; i < PNP_MAX_DMA; i++) {
570 pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_DMA, i);
571 if (pnp_res && !pnp_resource_valid(&pnp_res->res))
572 return pnp_res;
573 }
574 break;
575 }
576 return NULL;
577}
578
579struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
580 int flags)
581{
582 struct pnp_resource *pnp_res;
583 struct resource *res;
584 static unsigned char warned;
585
586 pnp_res = pnp_new_resource(dev, IORESOURCE_IRQ);
587 if (!pnp_res) {
588 if (!warned) {
589 dev_err(&dev->dev, "can't add resource for IRQ %d\n",
590 irq);
591 warned = 1;
592 }
593 return NULL;
594 }
595
596 res = &pnp_res->res;
597 res->flags = IORESOURCE_IRQ | flags;
598 res->start = irq;
599 res->end = irq;
600
601 dev_dbg(&dev->dev, " add irq %d flags %#x\n", irq, flags);
602 return pnp_res;
603}
604
605struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma,
606 int flags)
607{
608 struct pnp_resource *pnp_res;
609 struct resource *res;
610 static unsigned char warned;
611
612 pnp_res = pnp_new_resource(dev, IORESOURCE_DMA);
613 if (!pnp_res) {
614 if (!warned) {
615 dev_err(&dev->dev, "can't add resource for DMA %d\n",
616 dma);
617 warned = 1;
618 }
619 return NULL;
620 }
621
622 res = &pnp_res->res;
623 res->flags = IORESOURCE_DMA | flags;
624 res->start = dma;
625 res->end = dma;
626
627 dev_dbg(&dev->dev, " add dma %d flags %#x\n", dma, flags);
628 return pnp_res;
629}
630
631struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev,
632 resource_size_t start,
633 resource_size_t end, int flags)
634{
635 struct pnp_resource *pnp_res;
636 struct resource *res;
637 static unsigned char warned;
638
639 pnp_res = pnp_new_resource(dev, IORESOURCE_IO);
640 if (!pnp_res) {
641 if (!warned) {
642 dev_err(&dev->dev, "can't add resource for IO "
643 "%#llx-%#llx\n",(unsigned long long) start,
644 (unsigned long long) end);
645 warned = 1;
646 }
647 return NULL;
648 }
649
650 res = &pnp_res->res;
651 res->flags = IORESOURCE_IO | flags;
652 res->start = start;
653 res->end = end;
654
655 dev_dbg(&dev->dev, " add io %#llx-%#llx flags %#x\n",
656 (unsigned long long) start, (unsigned long long) end, flags);
657 return pnp_res;
658}
659
660struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev,
661 resource_size_t start,
662 resource_size_t end, int flags)
663{
664 struct pnp_resource *pnp_res;
665 struct resource *res;
666 static unsigned char warned;
667
668 pnp_res = pnp_new_resource(dev, IORESOURCE_MEM);
669 if (!pnp_res) {
670 if (!warned) {
671 dev_err(&dev->dev, "can't add resource for MEM "
672 "%#llx-%#llx\n",(unsigned long long) start,
673 (unsigned long long) end);
674 warned = 1;
675 }
676 return NULL;
677 }
678
679 res = &pnp_res->res;
680 res->flags = IORESOURCE_MEM | flags;
681 res->start = start;
682 res->end = end;
683
684 dev_dbg(&dev->dev, " add mem %#llx-%#llx flags %#x\n",
685 (unsigned long long) start, (unsigned long long) end, flags);
686 return pnp_res;
687}
688
464/* format is: pnp_reserve_irq=irq1[,irq2] .... */ 689/* format is: pnp_reserve_irq=irq1[,irq2] .... */
465static int __init pnp_setup_reserve_irq(char *str) 690static int __init pnp_setup_reserve_irq(char *str)
466{ 691{
diff --git a/drivers/pnp/support.c b/drivers/pnp/support.c
index 13c608f5fb30..3eba85ed729c 100644
--- a/drivers/pnp/support.c
+++ b/drivers/pnp/support.c
@@ -25,3 +25,66 @@ int pnp_is_active(struct pnp_dev *dev)
25} 25}
26 26
27EXPORT_SYMBOL(pnp_is_active); 27EXPORT_SYMBOL(pnp_is_active);
28
29/*
30 * Functionally similar to acpi_ex_eisa_id_to_string(), but that's
31 * buried in the ACPI CA, and we can't depend on it being present.
32 */
33void pnp_eisa_id_to_string(u32 id, char *str)
34{
35 id = be32_to_cpu(id);
36
37 /*
38 * According to the specs, the first three characters are five-bit
39 * compressed ASCII, and the left-over high order bit should be zero.
40 * However, the Linux ISAPNP code historically used six bits for the
41 * first character, and there seem to be IDs that depend on that,
42 * e.g., "nEC8241" in the Linux 8250_pnp serial driver and the
43 * FreeBSD sys/pc98/cbus/sio_cbus.c driver.
44 */
45 str[0] = 'A' + ((id >> 26) & 0x3f) - 1;
46 str[1] = 'A' + ((id >> 21) & 0x1f) - 1;
47 str[2] = 'A' + ((id >> 16) & 0x1f) - 1;
48 str[3] = hex_asc((id >> 12) & 0xf);
49 str[4] = hex_asc((id >> 8) & 0xf);
50 str[5] = hex_asc((id >> 4) & 0xf);
51 str[6] = hex_asc((id >> 0) & 0xf);
52 str[7] = '\0';
53}
54
55void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc)
56{
57#ifdef DEBUG
58 struct resource *res;
59 int i;
60
61 dev_dbg(&dev->dev, "current resources: %s\n", desc);
62
63 for (i = 0; i < PNP_MAX_IRQ; i++) {
64 res = pnp_get_resource(dev, IORESOURCE_IRQ, i);
65 if (res && !(res->flags & IORESOURCE_UNSET))
66 dev_dbg(&dev->dev, " irq %lld flags %#lx\n",
67 (unsigned long long) res->start, res->flags);
68 }
69 for (i = 0; i < PNP_MAX_DMA; i++) {
70 res = pnp_get_resource(dev, IORESOURCE_DMA, i);
71 if (res && !(res->flags & IORESOURCE_UNSET))
72 dev_dbg(&dev->dev, " dma %lld flags %#lx\n",
73 (unsigned long long) res->start, res->flags);
74 }
75 for (i = 0; i < PNP_MAX_PORT; i++) {
76 res = pnp_get_resource(dev, IORESOURCE_IO, i);
77 if (res && !(res->flags & IORESOURCE_UNSET))
78 dev_dbg(&dev->dev, " io %#llx-%#llx flags %#lx\n",
79 (unsigned long long) res->start,
80 (unsigned long long) res->end, res->flags);
81 }
82 for (i = 0; i < PNP_MAX_MEM; i++) {
83 res = pnp_get_resource(dev, IORESOURCE_MEM, i);
84 if (res && !(res->flags & IORESOURCE_UNSET))
85 dev_dbg(&dev->dev, " mem %#llx-%#llx flags %#lx\n",
86 (unsigned long long) res->start,
87 (unsigned long long) res->end, res->flags);
88 }
89#endif
90}
diff --git a/drivers/pnp/system.c b/drivers/pnp/system.c
index 55c4563986b3..9c2496dbeee4 100644
--- a/drivers/pnp/system.c
+++ b/drivers/pnp/system.c
@@ -56,14 +56,15 @@ static void reserve_range(struct pnp_dev *dev, resource_size_t start,
56 56
57static void reserve_resources_of_dev(struct pnp_dev *dev) 57static void reserve_resources_of_dev(struct pnp_dev *dev)
58{ 58{
59 struct resource *res;
59 int i; 60 int i;
60 61
61 for (i = 0; i < PNP_MAX_PORT; i++) { 62 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) {
62 if (!pnp_port_valid(dev, i)) 63 if (res->flags & IORESOURCE_UNSET)
63 continue; 64 continue;
64 if (pnp_port_start(dev, i) == 0) 65 if (res->start == 0)
65 continue; /* disabled */ 66 continue; /* disabled */
66 if (pnp_port_start(dev, i) < 0x100) 67 if (res->start < 0x100)
67 /* 68 /*
68 * Below 0x100 is only standard PC hardware 69 * Below 0x100 is only standard PC hardware
69 * (pics, kbd, timer, dma, ...) 70 * (pics, kbd, timer, dma, ...)
@@ -73,19 +74,17 @@ static void reserve_resources_of_dev(struct pnp_dev *dev)
73 * So, do nothing 74 * So, do nothing
74 */ 75 */
75 continue; 76 continue;
76 if (pnp_port_end(dev, i) < pnp_port_start(dev, i)) 77 if (res->end < res->start)
77 continue; /* invalid */ 78 continue; /* invalid */
78 79
79 reserve_range(dev, pnp_port_start(dev, i), 80 reserve_range(dev, res->start, res->end, 1);
80 pnp_port_end(dev, i), 1);
81 } 81 }
82 82
83 for (i = 0; i < PNP_MAX_MEM; i++) { 83 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) {
84 if (!pnp_mem_valid(dev, i)) 84 if (res->flags & IORESOURCE_UNSET)
85 continue; 85 continue;
86 86
87 reserve_range(dev, pnp_mem_start(dev, i), 87 reserve_range(dev, res->start, res->end, 0);
88 pnp_mem_end(dev, i), 0);
89 } 88 }
90} 89}
91 90
diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
index c8aa55b81fd8..82810b7bff9c 100644
--- a/drivers/power/pda_power.c
+++ b/drivers/power/pda_power.c
@@ -209,6 +209,12 @@ static int pda_power_probe(struct platform_device *pdev)
209 209
210 pdata = pdev->dev.platform_data; 210 pdata = pdev->dev.platform_data;
211 211
212 if (pdata->init) {
213 ret = pdata->init(dev);
214 if (ret < 0)
215 goto init_failed;
216 }
217
212 update_status(); 218 update_status();
213 update_charger(); 219 update_charger();
214 220
@@ -298,6 +304,9 @@ ac_irq_failed:
298 if (pdata->is_ac_online) 304 if (pdata->is_ac_online)
299 power_supply_unregister(&pda_psy_ac); 305 power_supply_unregister(&pda_psy_ac);
300ac_supply_failed: 306ac_supply_failed:
307 if (pdata->exit)
308 pdata->exit(dev);
309init_failed:
301wrongid: 310wrongid:
302 return ret; 311 return ret;
303} 312}
@@ -318,6 +327,8 @@ static int pda_power_remove(struct platform_device *pdev)
318 power_supply_unregister(&pda_psy_usb); 327 power_supply_unregister(&pda_psy_usb);
319 if (pdata->is_ac_online) 328 if (pdata->is_ac_online)
320 power_supply_unregister(&pda_psy_ac); 329 power_supply_unregister(&pda_psy_ac);
330 if (pdata->exit)
331 pdata->exit(dev);
321 332
322 return 0; 333 return 0;
323} 334}
diff --git a/drivers/power/pmu_battery.c b/drivers/power/pmu_battery.c
index 60a8cf3a0431..9346a862f1f2 100644
--- a/drivers/power/pmu_battery.c
+++ b/drivers/power/pmu_battery.c
@@ -159,7 +159,7 @@ static int __init pmu_bat_init(void)
159 if (!pbat) 159 if (!pbat)
160 break; 160 break;
161 161
162 sprintf(pbat->name, "PMU battery %d", i); 162 sprintf(pbat->name, "PMU_battery_%d", i);
163 pbat->bat.name = pbat->name; 163 pbat->bat.name = pbat->name;
164 pbat->bat.properties = pmu_bat_props; 164 pbat->bat.properties = pmu_bat_props;
165 pbat->bat.num_properties = ARRAY_SIZE(pmu_bat_props); 165 pbat->bat.num_properties = ARRAY_SIZE(pmu_bat_props);
diff --git a/drivers/ps3/ps3-lpm.c b/drivers/ps3/ps3-lpm.c
index 6c9592ce4996..85edf945ab86 100644
--- a/drivers/ps3/ps3-lpm.c
+++ b/drivers/ps3/ps3-lpm.c
@@ -22,6 +22,7 @@
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/uaccess.h> 24#include <linux/uaccess.h>
25#include <asm/time.h>
25#include <asm/ps3.h> 26#include <asm/ps3.h>
26#include <asm/lv1call.h> 27#include <asm/lv1call.h>
27#include <asm/cell-pmu.h> 28#include <asm/cell-pmu.h>
diff --git a/drivers/ps3/ps3-sys-manager.c b/drivers/ps3/ps3-sys-manager.c
index 7605453b74fd..f17513dd9d4b 100644
--- a/drivers/ps3/ps3-sys-manager.c
+++ b/drivers/ps3/ps3-sys-manager.c
@@ -184,10 +184,7 @@ enum ps3_sys_manager_next_op {
184 184
185/** 185/**
186 * enum ps3_sys_manager_wake_source - Next-op wakeup source (bit position mask). 186 * enum ps3_sys_manager_wake_source - Next-op wakeup source (bit position mask).
187 * @PS3_SM_WAKE_DEFAULT: Disk insert, power button, eject button, IR 187 * @PS3_SM_WAKE_DEFAULT: Disk insert, power button, eject button.
188 * controller, and bluetooth controller.
189 * @PS3_SM_WAKE_RTC:
190 * @PS3_SM_WAKE_RTC_ERROR:
191 * @PS3_SM_WAKE_W_O_L: Ether or wireless LAN. 188 * @PS3_SM_WAKE_W_O_L: Ether or wireless LAN.
192 * @PS3_SM_WAKE_P_O_R: Power on reset. 189 * @PS3_SM_WAKE_P_O_R: Power on reset.
193 * 190 *
@@ -200,8 +197,6 @@ enum ps3_sys_manager_next_op {
200enum ps3_sys_manager_wake_source { 197enum ps3_sys_manager_wake_source {
201 /* version 3 */ 198 /* version 3 */
202 PS3_SM_WAKE_DEFAULT = 0, 199 PS3_SM_WAKE_DEFAULT = 0,
203 PS3_SM_WAKE_RTC = 0x00000040,
204 PS3_SM_WAKE_RTC_ERROR = 0x00000080,
205 PS3_SM_WAKE_W_O_L = 0x00000400, 200 PS3_SM_WAKE_W_O_L = 0x00000400,
206 PS3_SM_WAKE_P_O_R = 0x80000000, 201 PS3_SM_WAKE_P_O_R = 0x80000000,
207}; 202};
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index dcdc142a3441..d060a06ce05b 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -854,11 +854,12 @@ cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
854 * don't define the IRQ. It should always be safe to 854 * don't define the IRQ. It should always be safe to
855 * hardcode it in these cases 855 * hardcode it in these cases
856 */ 856 */
857 return cmos_do_probe(&pnp->dev, &pnp->res.port_resource[0], 8); 857 return cmos_do_probe(&pnp->dev,
858 pnp_get_resource(pnp, IORESOURCE_IO, 0), 8);
858 else 859 else
859 return cmos_do_probe(&pnp->dev, 860 return cmos_do_probe(&pnp->dev,
860 &pnp->res.port_resource[0], 861 pnp_get_resource(pnp, IORESOURCE_IO, 0),
861 pnp->res.irq_resource[0].start); 862 pnp_irq(pnp, 0));
862} 863}
863 864
864static void __exit cmos_pnp_remove(struct pnp_dev *pnp) 865static void __exit cmos_pnp_remove(struct pnp_dev *pnp)
diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
index 0e1f35c9ed9d..3e5653c92f4b 100644
--- a/drivers/s390/char/con3215.c
+++ b/drivers/s390/char/con3215.c
@@ -982,15 +982,16 @@ tty3215_write(struct tty_struct * tty,
982/* 982/*
983 * Put character routine for 3215 ttys 983 * Put character routine for 3215 ttys
984 */ 984 */
985static void 985static int
986tty3215_put_char(struct tty_struct *tty, unsigned char ch) 986tty3215_put_char(struct tty_struct *tty, unsigned char ch)
987{ 987{
988 struct raw3215_info *raw; 988 struct raw3215_info *raw;
989 989
990 if (!tty) 990 if (!tty)
991 return; 991 return 0;
992 raw = (struct raw3215_info *) tty->driver_data; 992 raw = (struct raw3215_info *) tty->driver_data;
993 raw3215_putchar(raw, ch); 993 raw3215_putchar(raw, ch);
994 return 1;
994} 995}
995 996
996static void 997static void
diff --git a/drivers/s390/char/sclp_config.c b/drivers/s390/char/sclp_config.c
index b8f35bc52b7b..9e784d5f7f57 100644
--- a/drivers/s390/char/sclp_config.c
+++ b/drivers/s390/char/sclp_config.c
@@ -10,6 +10,7 @@
10#include <linux/cpu.h> 10#include <linux/cpu.h>
11#include <linux/sysdev.h> 11#include <linux/sysdev.h>
12#include <linux/workqueue.h> 12#include <linux/workqueue.h>
13#include <asm/smp.h>
13#include "sclp.h" 14#include "sclp.h"
14 15
15#define TAG "sclp_config: " 16#define TAG "sclp_config: "
@@ -19,9 +20,11 @@ struct conf_mgm_data {
19 u8 ev_qualifier; 20 u8 ev_qualifier;
20} __attribute__((packed)); 21} __attribute__((packed));
21 22
23#define EV_QUAL_CPU_CHANGE 1
22#define EV_QUAL_CAP_CHANGE 3 24#define EV_QUAL_CAP_CHANGE 3
23 25
24static struct work_struct sclp_cpu_capability_work; 26static struct work_struct sclp_cpu_capability_work;
27static struct work_struct sclp_cpu_change_work;
25 28
26static void sclp_cpu_capability_notify(struct work_struct *work) 29static void sclp_cpu_capability_notify(struct work_struct *work)
27{ 30{
@@ -37,13 +40,24 @@ static void sclp_cpu_capability_notify(struct work_struct *work)
37 put_online_cpus(); 40 put_online_cpus();
38} 41}
39 42
43static void sclp_cpu_change_notify(struct work_struct *work)
44{
45 smp_rescan_cpus();
46}
47
40static void sclp_conf_receiver_fn(struct evbuf_header *evbuf) 48static void sclp_conf_receiver_fn(struct evbuf_header *evbuf)
41{ 49{
42 struct conf_mgm_data *cdata; 50 struct conf_mgm_data *cdata;
43 51
44 cdata = (struct conf_mgm_data *)(evbuf + 1); 52 cdata = (struct conf_mgm_data *)(evbuf + 1);
45 if (cdata->ev_qualifier == EV_QUAL_CAP_CHANGE) 53 switch (cdata->ev_qualifier) {
54 case EV_QUAL_CPU_CHANGE:
55 schedule_work(&sclp_cpu_change_work);
56 break;
57 case EV_QUAL_CAP_CHANGE:
46 schedule_work(&sclp_cpu_capability_work); 58 schedule_work(&sclp_cpu_capability_work);
59 break;
60 }
47} 61}
48 62
49static struct sclp_register sclp_conf_register = 63static struct sclp_register sclp_conf_register =
@@ -57,6 +71,7 @@ static int __init sclp_conf_init(void)
57 int rc; 71 int rc;
58 72
59 INIT_WORK(&sclp_cpu_capability_work, sclp_cpu_capability_notify); 73 INIT_WORK(&sclp_cpu_capability_work, sclp_cpu_capability_notify);
74 INIT_WORK(&sclp_cpu_change_work, sclp_cpu_change_notify);
60 75
61 rc = sclp_register(&sclp_conf_register); 76 rc = sclp_register(&sclp_conf_register);
62 if (rc) { 77 if (rc) {
diff --git a/drivers/s390/char/sclp_tty.c b/drivers/s390/char/sclp_tty.c
index e3b3d390b4a3..40b11521cd20 100644
--- a/drivers/s390/char/sclp_tty.c
+++ b/drivers/s390/char/sclp_tty.c
@@ -412,14 +412,14 @@ sclp_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
412 * - including previous characters from sclp_tty_put_char() and strings from 412 * - including previous characters from sclp_tty_put_char() and strings from
413 * sclp_write() without final '\n' - will be written. 413 * sclp_write() without final '\n' - will be written.
414 */ 414 */
415static void 415static int
416sclp_tty_put_char(struct tty_struct *tty, unsigned char ch) 416sclp_tty_put_char(struct tty_struct *tty, unsigned char ch)
417{ 417{
418 sclp_tty_chars[sclp_tty_chars_count++] = ch; 418 sclp_tty_chars[sclp_tty_chars_count++] = ch;
419 if (ch == '\n' || sclp_tty_chars_count >= SCLP_TTY_BUF_SIZE) { 419 if (ch == '\n' || sclp_tty_chars_count >= SCLP_TTY_BUF_SIZE) {
420 sclp_tty_write_string(sclp_tty_chars, sclp_tty_chars_count); 420 sclp_tty_write_string(sclp_tty_chars, sclp_tty_chars_count);
421 sclp_tty_chars_count = 0; 421 sclp_tty_chars_count = 0;
422 } 422 } return 1;
423} 423}
424 424
425/* 425/*
diff --git a/drivers/s390/char/sclp_vt220.c b/drivers/s390/char/sclp_vt220.c
index ed507594e62b..35707c04e613 100644
--- a/drivers/s390/char/sclp_vt220.c
+++ b/drivers/s390/char/sclp_vt220.c
@@ -524,11 +524,15 @@ sclp_vt220_close(struct tty_struct *tty, struct file *filp)
524 * NOTE: include/linux/tty_driver.h specifies that a character should be 524 * NOTE: include/linux/tty_driver.h specifies that a character should be
525 * ignored if there is no room in the queue. This driver implements a different 525 * ignored if there is no room in the queue. This driver implements a different
526 * semantic in that it will block when there is no more room left. 526 * semantic in that it will block when there is no more room left.
527 *
528 * FIXME: putchar can currently be called from BH and other non blocking
529 * handlers so this semantic isn't a good idea.
527 */ 530 */
528static void 531static int
529sclp_vt220_put_char(struct tty_struct *tty, unsigned char ch) 532sclp_vt220_put_char(struct tty_struct *tty, unsigned char ch)
530{ 533{
531 __sclp_vt220_write(&ch, 1, 0, 0, 1); 534 __sclp_vt220_write(&ch, 1, 0, 0, 1);
535 return 1;
532} 536}
533 537
534/* 538/*
diff --git a/drivers/s390/char/tty3270.c b/drivers/s390/char/tty3270.c
index 70b1980a08b6..c1f2adefad41 100644
--- a/drivers/s390/char/tty3270.c
+++ b/drivers/s390/char/tty3270.c
@@ -965,7 +965,7 @@ tty3270_write_room(struct tty_struct *tty)
965 * Insert character into the screen at the current position with the 965 * Insert character into the screen at the current position with the
966 * current color and highlight. This function does NOT do cursor movement. 966 * current color and highlight. This function does NOT do cursor movement.
967 */ 967 */
968static void 968static int
969tty3270_put_character(struct tty3270 *tp, char ch) 969tty3270_put_character(struct tty3270 *tp, char ch)
970{ 970{
971 struct tty3270_line *line; 971 struct tty3270_line *line;
@@ -986,6 +986,7 @@ tty3270_put_character(struct tty3270 *tp, char ch)
986 cell->character = tp->view.ascebc[(unsigned int) ch]; 986 cell->character = tp->view.ascebc[(unsigned int) ch];
987 cell->highlight = tp->highlight; 987 cell->highlight = tp->highlight;
988 cell->f_color = tp->f_color; 988 cell->f_color = tp->f_color;
989 return 1;
989} 990}
990 991
991/* 992/*
diff --git a/drivers/s390/cio/ccwgroup.c b/drivers/s390/cio/ccwgroup.c
index fe1ad1722158..26a930e832bd 100644
--- a/drivers/s390/cio/ccwgroup.c
+++ b/drivers/s390/cio/ccwgroup.c
@@ -152,44 +152,89 @@ __ccwgroup_create_symlinks(struct ccwgroup_device *gdev)
152 return 0; 152 return 0;
153} 153}
154 154
155static int __get_next_bus_id(const char **buf, char *bus_id)
156{
157 int rc, len;
158 char *start, *end;
159
160 start = (char *)*buf;
161 end = strchr(start, ',');
162 if (!end) {
163 /* Last entry. Strip trailing newline, if applicable. */
164 end = strchr(start, '\n');
165 if (end)
166 *end = '\0';
167 len = strlen(start) + 1;
168 } else {
169 len = end - start + 1;
170 end++;
171 }
172 if (len < BUS_ID_SIZE) {
173 strlcpy(bus_id, start, len);
174 rc = 0;
175 } else
176 rc = -EINVAL;
177 *buf = end;
178 return rc;
179}
180
181static int __is_valid_bus_id(char bus_id[BUS_ID_SIZE])
182{
183 int cssid, ssid, devno;
184
185 /* Must be of form %x.%x.%04x */
186 if (sscanf(bus_id, "%x.%1x.%04x", &cssid, &ssid, &devno) != 3)
187 return 0;
188 return 1;
189}
190
155/** 191/**
156 * ccwgroup_create() - create and register a ccw group device 192 * ccwgroup_create_from_string() - create and register a ccw group device
157 * @root: parent device for the new device 193 * @root: parent device for the new device
158 * @creator_id: identifier of creating driver 194 * @creator_id: identifier of creating driver
159 * @cdrv: ccw driver of slave devices 195 * @cdrv: ccw driver of slave devices
160 * @argc: number of slave devices 196 * @num_devices: number of slave devices
161 * @argv: bus ids of slave devices 197 * @buf: buffer containing comma separated bus ids of slave devices
162 * 198 *
163 * Create and register a new ccw group device as a child of @root. Slave 199 * Create and register a new ccw group device as a child of @root. Slave
164 * devices are obtained from the list of bus ids given in @argv[] and must all 200 * devices are obtained from the list of bus ids given in @buf and must all
165 * belong to @cdrv. 201 * belong to @cdrv.
166 * Returns: 202 * Returns:
167 * %0 on success and an error code on failure. 203 * %0 on success and an error code on failure.
168 * Context: 204 * Context:
169 * non-atomic 205 * non-atomic
170 */ 206 */
171int ccwgroup_create(struct device *root, unsigned int creator_id, 207int ccwgroup_create_from_string(struct device *root, unsigned int creator_id,
172 struct ccw_driver *cdrv, int argc, char *argv[]) 208 struct ccw_driver *cdrv, int num_devices,
209 const char *buf)
173{ 210{
174 struct ccwgroup_device *gdev; 211 struct ccwgroup_device *gdev;
175 int i; 212 int rc, i;
176 int rc; 213 char tmp_bus_id[BUS_ID_SIZE];
214 const char *curr_buf;
177 215
178 if (argc > 256) /* disallow dumb users */ 216 gdev = kzalloc(sizeof(*gdev) + num_devices * sizeof(gdev->cdev[0]),
179 return -EINVAL; 217 GFP_KERNEL);
180
181 gdev = kzalloc(sizeof(*gdev) + argc*sizeof(gdev->cdev[0]), GFP_KERNEL);
182 if (!gdev) 218 if (!gdev)
183 return -ENOMEM; 219 return -ENOMEM;
184 220
185 atomic_set(&gdev->onoff, 0); 221 atomic_set(&gdev->onoff, 0);
186 mutex_init(&gdev->reg_mutex); 222 mutex_init(&gdev->reg_mutex);
187 mutex_lock(&gdev->reg_mutex); 223 mutex_lock(&gdev->reg_mutex);
188 for (i = 0; i < argc; i++) { 224 curr_buf = buf;
189 gdev->cdev[i] = get_ccwdev_by_busid(cdrv, argv[i]); 225 for (i = 0; i < num_devices && curr_buf; i++) {
190 226 rc = __get_next_bus_id(&curr_buf, tmp_bus_id);
191 /* all devices have to be of the same type in 227 if (rc != 0)
192 * order to be grouped */ 228 goto error;
229 if (!__is_valid_bus_id(tmp_bus_id)) {
230 rc = -EINVAL;
231 goto error;
232 }
233 gdev->cdev[i] = get_ccwdev_by_busid(cdrv, tmp_bus_id);
234 /*
235 * All devices have to be of the same type in
236 * order to be grouped.
237 */
193 if (!gdev->cdev[i] 238 if (!gdev->cdev[i]
194 || gdev->cdev[i]->id.driver_info != 239 || gdev->cdev[i]->id.driver_info !=
195 gdev->cdev[0]->id.driver_info) { 240 gdev->cdev[0]->id.driver_info) {
@@ -203,9 +248,18 @@ int ccwgroup_create(struct device *root, unsigned int creator_id,
203 } 248 }
204 dev_set_drvdata(&gdev->cdev[i]->dev, gdev); 249 dev_set_drvdata(&gdev->cdev[i]->dev, gdev);
205 } 250 }
206 251 /* Check for sufficient number of bus ids. */
252 if (i < num_devices && !curr_buf) {
253 rc = -EINVAL;
254 goto error;
255 }
256 /* Check for trailing stuff. */
257 if (i == num_devices && strlen(curr_buf) > 0) {
258 rc = -EINVAL;
259 goto error;
260 }
207 gdev->creator_id = creator_id; 261 gdev->creator_id = creator_id;
208 gdev->count = argc; 262 gdev->count = num_devices;
209 gdev->dev.bus = &ccwgroup_bus_type; 263 gdev->dev.bus = &ccwgroup_bus_type;
210 gdev->dev.parent = root; 264 gdev->dev.parent = root;
211 gdev->dev.release = ccwgroup_release; 265 gdev->dev.release = ccwgroup_release;
@@ -233,7 +287,7 @@ int ccwgroup_create(struct device *root, unsigned int creator_id,
233 device_remove_file(&gdev->dev, &dev_attr_ungroup); 287 device_remove_file(&gdev->dev, &dev_attr_ungroup);
234 device_unregister(&gdev->dev); 288 device_unregister(&gdev->dev);
235error: 289error:
236 for (i = 0; i < argc; i++) 290 for (i = 0; i < num_devices; i++)
237 if (gdev->cdev[i]) { 291 if (gdev->cdev[i]) {
238 if (dev_get_drvdata(&gdev->cdev[i]->dev) == gdev) 292 if (dev_get_drvdata(&gdev->cdev[i]->dev) == gdev)
239 dev_set_drvdata(&gdev->cdev[i]->dev, NULL); 293 dev_set_drvdata(&gdev->cdev[i]->dev, NULL);
@@ -243,6 +297,7 @@ error:
243 put_device(&gdev->dev); 297 put_device(&gdev->dev);
244 return rc; 298 return rc;
245} 299}
300EXPORT_SYMBOL(ccwgroup_create_from_string);
246 301
247static int __init 302static int __init
248init_ccwgroup (void) 303init_ccwgroup (void)
@@ -318,7 +373,7 @@ ccwgroup_online_store (struct device *dev, struct device_attribute *attr, const
318{ 373{
319 struct ccwgroup_device *gdev; 374 struct ccwgroup_device *gdev;
320 struct ccwgroup_driver *gdrv; 375 struct ccwgroup_driver *gdrv;
321 unsigned int value; 376 unsigned long value;
322 int ret; 377 int ret;
323 378
324 gdev = to_ccwgroupdev(dev); 379 gdev = to_ccwgroupdev(dev);
@@ -329,7 +384,9 @@ ccwgroup_online_store (struct device *dev, struct device_attribute *attr, const
329 if (!try_module_get(gdrv->owner)) 384 if (!try_module_get(gdrv->owner))
330 return -EINVAL; 385 return -EINVAL;
331 386
332 value = simple_strtoul(buf, NULL, 0); 387 ret = strict_strtoul(buf, 0, &value);
388 if (ret)
389 goto out;
333 ret = count; 390 ret = count;
334 if (value == 1) 391 if (value == 1)
335 ccwgroup_set_online(gdev); 392 ccwgroup_set_online(gdev);
@@ -337,6 +394,7 @@ ccwgroup_online_store (struct device *dev, struct device_attribute *attr, const
337 ccwgroup_set_offline(gdev); 394 ccwgroup_set_offline(gdev);
338 else 395 else
339 ret = -EINVAL; 396 ret = -EINVAL;
397out:
340 module_put(gdrv->owner); 398 module_put(gdrv->owner);
341 return ret; 399 return ret;
342} 400}
@@ -518,6 +576,5 @@ void ccwgroup_remove_ccwdev(struct ccw_device *cdev)
518MODULE_LICENSE("GPL"); 576MODULE_LICENSE("GPL");
519EXPORT_SYMBOL(ccwgroup_driver_register); 577EXPORT_SYMBOL(ccwgroup_driver_register);
520EXPORT_SYMBOL(ccwgroup_driver_unregister); 578EXPORT_SYMBOL(ccwgroup_driver_unregister);
521EXPORT_SYMBOL(ccwgroup_create);
522EXPORT_SYMBOL(ccwgroup_probe_ccwdev); 579EXPORT_SYMBOL(ccwgroup_probe_ccwdev);
523EXPORT_SYMBOL(ccwgroup_remove_ccwdev); 580EXPORT_SYMBOL(ccwgroup_remove_ccwdev);
diff --git a/drivers/s390/cio/cio.c b/drivers/s390/cio/cio.c
index 23ffcc4768a7..08a578161306 100644
--- a/drivers/s390/cio/cio.c
+++ b/drivers/s390/cio/cio.c
@@ -407,8 +407,7 @@ cio_modify (struct subchannel *sch)
407/* 407/*
408 * Enable subchannel. 408 * Enable subchannel.
409 */ 409 */
410int cio_enable_subchannel(struct subchannel *sch, unsigned int isc, 410int cio_enable_subchannel(struct subchannel *sch, u32 intparm)
411 u32 intparm)
412{ 411{
413 char dbf_txt[15]; 412 char dbf_txt[15];
414 int ccode; 413 int ccode;
@@ -426,7 +425,7 @@ int cio_enable_subchannel(struct subchannel *sch, unsigned int isc,
426 425
427 for (retry = 5, ret = 0; retry > 0; retry--) { 426 for (retry = 5, ret = 0; retry > 0; retry--) {
428 sch->schib.pmcw.ena = 1; 427 sch->schib.pmcw.ena = 1;
429 sch->schib.pmcw.isc = isc; 428 sch->schib.pmcw.isc = sch->isc;
430 sch->schib.pmcw.intparm = intparm; 429 sch->schib.pmcw.intparm = intparm;
431 ret = cio_modify(sch); 430 ret = cio_modify(sch);
432 if (ret == -ENODEV) 431 if (ret == -ENODEV)
@@ -600,6 +599,7 @@ cio_validate_subchannel (struct subchannel *sch, struct subchannel_id schid)
600 else 599 else
601 sch->opm = chp_get_sch_opm(sch); 600 sch->opm = chp_get_sch_opm(sch);
602 sch->lpm = sch->schib.pmcw.pam & sch->opm; 601 sch->lpm = sch->schib.pmcw.pam & sch->opm;
602 sch->isc = 3;
603 603
604 CIO_DEBUG(KERN_INFO, 0, 604 CIO_DEBUG(KERN_INFO, 0,
605 "Detected device %04x on subchannel 0.%x.%04X" 605 "Detected device %04x on subchannel 0.%x.%04X"
@@ -610,13 +610,11 @@ cio_validate_subchannel (struct subchannel *sch, struct subchannel_id schid)
610 610
611 /* 611 /*
612 * We now have to initially ... 612 * We now have to initially ...
613 * ... set "interruption subclass"
614 * ... enable "concurrent sense" 613 * ... enable "concurrent sense"
615 * ... enable "multipath mode" if more than one 614 * ... enable "multipath mode" if more than one
616 * CHPID is available. This is done regardless 615 * CHPID is available. This is done regardless
617 * whether multiple paths are available for us. 616 * whether multiple paths are available for us.
618 */ 617 */
619 sch->schib.pmcw.isc = 3; /* could be smth. else */
620 sch->schib.pmcw.csense = 1; /* concurrent sense */ 618 sch->schib.pmcw.csense = 1; /* concurrent sense */
621 sch->schib.pmcw.ena = 0; 619 sch->schib.pmcw.ena = 0;
622 if ((sch->lpm & (sch->lpm - 1)) != 0) 620 if ((sch->lpm & (sch->lpm - 1)) != 0)
@@ -812,6 +810,7 @@ cio_probe_console(void)
812 * enable console I/O-interrupt subclass 7 810 * enable console I/O-interrupt subclass 7
813 */ 811 */
814 ctl_set_bit(6, 24); 812 ctl_set_bit(6, 24);
813 console_subchannel.isc = 7;
815 console_subchannel.schib.pmcw.isc = 7; 814 console_subchannel.schib.pmcw.isc = 7;
816 console_subchannel.schib.pmcw.intparm = 815 console_subchannel.schib.pmcw.intparm =
817 (u32)(addr_t)&console_subchannel; 816 (u32)(addr_t)&console_subchannel;
diff --git a/drivers/s390/cio/cio.h b/drivers/s390/cio/cio.h
index 08f2235c5a6f..3c75412904dc 100644
--- a/drivers/s390/cio/cio.h
+++ b/drivers/s390/cio/cio.h
@@ -74,6 +74,7 @@ struct subchannel {
74 __u8 lpm; /* logical path mask */ 74 __u8 lpm; /* logical path mask */
75 __u8 opm; /* operational path mask */ 75 __u8 opm; /* operational path mask */
76 struct schib schib; /* subchannel information block */ 76 struct schib schib; /* subchannel information block */
77 int isc; /* desired interruption subclass */
77 struct chsc_ssd_info ssd_info; /* subchannel description */ 78 struct chsc_ssd_info ssd_info; /* subchannel description */
78 struct device dev; /* entry in device tree */ 79 struct device dev; /* entry in device tree */
79 struct css_driver *driver; 80 struct css_driver *driver;
@@ -85,7 +86,7 @@ struct subchannel {
85#define to_subchannel(n) container_of(n, struct subchannel, dev) 86#define to_subchannel(n) container_of(n, struct subchannel, dev)
86 87
87extern int cio_validate_subchannel (struct subchannel *, struct subchannel_id); 88extern int cio_validate_subchannel (struct subchannel *, struct subchannel_id);
88extern int cio_enable_subchannel(struct subchannel *, unsigned int, u32); 89extern int cio_enable_subchannel(struct subchannel *, u32);
89extern int cio_disable_subchannel (struct subchannel *); 90extern int cio_disable_subchannel (struct subchannel *);
90extern int cio_cancel (struct subchannel *); 91extern int cio_cancel (struct subchannel *);
91extern int cio_clear (struct subchannel *); 92extern int cio_clear (struct subchannel *);
diff --git a/drivers/s390/cio/cmf.c b/drivers/s390/cio/cmf.c
index f4c132ab39ed..2808b6833b9e 100644
--- a/drivers/s390/cio/cmf.c
+++ b/drivers/s390/cio/cmf.c
@@ -1219,16 +1219,21 @@ static ssize_t cmb_enable_store(struct device *dev,
1219{ 1219{
1220 struct ccw_device *cdev; 1220 struct ccw_device *cdev;
1221 int ret; 1221 int ret;
1222 unsigned long val;
1223
1224 ret = strict_strtoul(buf, 16, &val);
1225 if (ret)
1226 return ret;
1222 1227
1223 cdev = to_ccwdev(dev); 1228 cdev = to_ccwdev(dev);
1224 1229
1225 switch (buf[0]) { 1230 switch (val) {
1226 case '0': 1231 case 0:
1227 ret = disable_cmf(cdev); 1232 ret = disable_cmf(cdev);
1228 if (ret) 1233 if (ret)
1229 dev_info(&cdev->dev, "disable_cmf failed (%d)\n", ret); 1234 dev_info(&cdev->dev, "disable_cmf failed (%d)\n", ret);
1230 break; 1235 break;
1231 case '1': 1236 case 1:
1232 ret = enable_cmf(cdev); 1237 ret = enable_cmf(cdev);
1233 if (ret && ret != -EBUSY) 1238 if (ret && ret != -EBUSY)
1234 dev_info(&cdev->dev, "enable_cmf failed (%d)\n", ret); 1239 dev_info(&cdev->dev, "enable_cmf failed (%d)\n", ret);
diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c
index c1afab5f72d6..595e327d2f76 100644
--- a/drivers/s390/cio/css.c
+++ b/drivers/s390/cio/css.c
@@ -705,13 +705,17 @@ css_cm_enable_store(struct device *dev, struct device_attribute *attr,
705{ 705{
706 struct channel_subsystem *css = to_css(dev); 706 struct channel_subsystem *css = to_css(dev);
707 int ret; 707 int ret;
708 unsigned long val;
708 709
710 ret = strict_strtoul(buf, 16, &val);
711 if (ret)
712 return ret;
709 mutex_lock(&css->mutex); 713 mutex_lock(&css->mutex);
710 switch (buf[0]) { 714 switch (val) {
711 case '0': 715 case 0:
712 ret = css->cm_enabled ? chsc_secm(css, 0) : 0; 716 ret = css->cm_enabled ? chsc_secm(css, 0) : 0;
713 break; 717 break;
714 case '1': 718 case 1:
715 ret = css->cm_enabled ? 0 : chsc_secm(css, 1); 719 ret = css->cm_enabled ? 0 : chsc_secm(css, 1);
716 break; 720 break;
717 default: 721 default:
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index e0c7adb8958e..abfd601d237a 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -512,8 +512,8 @@ static ssize_t online_store (struct device *dev, struct device_attribute *attr,
512 const char *buf, size_t count) 512 const char *buf, size_t count)
513{ 513{
514 struct ccw_device *cdev = to_ccwdev(dev); 514 struct ccw_device *cdev = to_ccwdev(dev);
515 int i, force; 515 int force, ret;
516 char *tmp; 516 unsigned long i;
517 517
518 if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0) 518 if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0)
519 return -EAGAIN; 519 return -EAGAIN;
@@ -525,25 +525,30 @@ static ssize_t online_store (struct device *dev, struct device_attribute *attr,
525 if (!strncmp(buf, "force\n", count)) { 525 if (!strncmp(buf, "force\n", count)) {
526 force = 1; 526 force = 1;
527 i = 1; 527 i = 1;
528 ret = 0;
528 } else { 529 } else {
529 force = 0; 530 force = 0;
530 i = simple_strtoul(buf, &tmp, 16); 531 ret = strict_strtoul(buf, 16, &i);
531 } 532 }
532 533 if (ret)
534 goto out;
533 switch (i) { 535 switch (i) {
534 case 0: 536 case 0:
535 online_store_handle_offline(cdev); 537 online_store_handle_offline(cdev);
538 ret = count;
536 break; 539 break;
537 case 1: 540 case 1:
538 online_store_handle_online(cdev, force); 541 online_store_handle_online(cdev, force);
542 ret = count;
539 break; 543 break;
540 default: 544 default:
541 count = -EINVAL; 545 ret = -EINVAL;
542 } 546 }
547out:
543 if (cdev->drv) 548 if (cdev->drv)
544 module_put(cdev->drv->owner); 549 module_put(cdev->drv->owner);
545 atomic_set(&cdev->private->onoff, 0); 550 atomic_set(&cdev->private->onoff, 0);
546 return count; 551 return ret;
547} 552}
548 553
549static ssize_t 554static ssize_t
diff --git a/drivers/s390/cio/device_fsm.c b/drivers/s390/cio/device_fsm.c
index 4b92c84fb438..99403b0a97a7 100644
--- a/drivers/s390/cio/device_fsm.c
+++ b/drivers/s390/cio/device_fsm.c
@@ -555,8 +555,7 @@ ccw_device_recognition(struct ccw_device *cdev)
555 (cdev->private->state != DEV_STATE_BOXED)) 555 (cdev->private->state != DEV_STATE_BOXED))
556 return -EINVAL; 556 return -EINVAL;
557 sch = to_subchannel(cdev->dev.parent); 557 sch = to_subchannel(cdev->dev.parent);
558 ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc, 558 ret = cio_enable_subchannel(sch, (u32)(addr_t)sch);
559 (u32)(addr_t)sch);
560 if (ret != 0) 559 if (ret != 0)
561 /* Couldn't enable the subchannel for i/o. Sick device. */ 560 /* Couldn't enable the subchannel for i/o. Sick device. */
562 return ret; 561 return ret;
@@ -667,8 +666,7 @@ ccw_device_online(struct ccw_device *cdev)
667 sch = to_subchannel(cdev->dev.parent); 666 sch = to_subchannel(cdev->dev.parent);
668 if (css_init_done && !get_device(&cdev->dev)) 667 if (css_init_done && !get_device(&cdev->dev))
669 return -ENODEV; 668 return -ENODEV;
670 ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc, 669 ret = cio_enable_subchannel(sch, (u32)(addr_t)sch);
671 (u32)(addr_t)sch);
672 if (ret != 0) { 670 if (ret != 0) {
673 /* Couldn't enable the subchannel for i/o. Sick device. */ 671 /* Couldn't enable the subchannel for i/o. Sick device. */
674 if (ret == -ENODEV) 672 if (ret == -ENODEV)
@@ -1048,8 +1046,7 @@ ccw_device_start_id(struct ccw_device *cdev, enum dev_event dev_event)
1048 struct subchannel *sch; 1046 struct subchannel *sch;
1049 1047
1050 sch = to_subchannel(cdev->dev.parent); 1048 sch = to_subchannel(cdev->dev.parent);
1051 if (cio_enable_subchannel(sch, sch->schib.pmcw.isc, 1049 if (cio_enable_subchannel(sch, (u32)(addr_t)sch) != 0)
1052 (u32)(addr_t)sch) != 0)
1053 /* Couldn't enable the subchannel for i/o. Sick device. */ 1050 /* Couldn't enable the subchannel for i/o. Sick device. */
1054 return; 1051 return;
1055 1052
@@ -1082,7 +1079,6 @@ device_trigger_reprobe(struct subchannel *sch)
1082 */ 1079 */
1083 sch->lpm = sch->schib.pmcw.pam & sch->opm; 1080 sch->lpm = sch->schib.pmcw.pam & sch->opm;
1084 /* Re-set some bits in the pmcw that were lost. */ 1081 /* Re-set some bits in the pmcw that were lost. */
1085 sch->schib.pmcw.isc = 3;
1086 sch->schib.pmcw.csense = 1; 1082 sch->schib.pmcw.csense = 1;
1087 sch->schib.pmcw.ena = 0; 1083 sch->schib.pmcw.ena = 0;
1088 if ((sch->lpm & (sch->lpm - 1)) != 0) 1084 if ((sch->lpm & (sch->lpm - 1)) != 0)
diff --git a/drivers/s390/cio/device_ops.c b/drivers/s390/cio/device_ops.c
index a1718a0aa539..f308ad55a6d5 100644
--- a/drivers/s390/cio/device_ops.c
+++ b/drivers/s390/cio/device_ops.c
@@ -508,7 +508,7 @@ ccw_device_stlck(struct ccw_device *cdev)
508 return -ENOMEM; 508 return -ENOMEM;
509 } 509 }
510 spin_lock_irqsave(sch->lock, flags); 510 spin_lock_irqsave(sch->lock, flags);
511 ret = cio_enable_subchannel(sch, 3, (u32)(addr_t)sch); 511 ret = cio_enable_subchannel(sch, (u32)(addr_t)sch);
512 if (ret) 512 if (ret)
513 goto out_unlock; 513 goto out_unlock;
514 /* 514 /*
diff --git a/drivers/s390/cio/qdio.c b/drivers/s390/cio/qdio.c
index 43876e287370..445cf364e461 100644
--- a/drivers/s390/cio/qdio.c
+++ b/drivers/s390/cio/qdio.c
@@ -3663,11 +3663,11 @@ qdio_performance_stats_show(struct bus_type *bus, char *buf)
3663static ssize_t 3663static ssize_t
3664qdio_performance_stats_store(struct bus_type *bus, const char *buf, size_t count) 3664qdio_performance_stats_store(struct bus_type *bus, const char *buf, size_t count)
3665{ 3665{
3666 char *tmp; 3666 unsigned long i;
3667 int i; 3667 int ret;
3668 3668
3669 i = simple_strtoul(buf, &tmp, 16); 3669 ret = strict_strtoul(buf, 16, &i);
3670 if ((i == 0) || (i == 1)) { 3670 if (!ret && ((i == 0) || (i == 1))) {
3671 if (i == qdio_performance_stats) 3671 if (i == qdio_performance_stats)
3672 return count; 3672 return count;
3673 qdio_performance_stats = i; 3673 qdio_performance_stats = i;
diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/kvm/kvm_virtio.c
index bbef3764fbf8..47a7e6200b26 100644
--- a/drivers/s390/kvm/kvm_virtio.c
+++ b/drivers/s390/kvm/kvm_virtio.c
@@ -17,6 +17,7 @@
17#include <linux/virtio_config.h> 17#include <linux/virtio_config.h>
18#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19#include <linux/virtio_ring.h> 19#include <linux/virtio_ring.h>
20#include <linux/pfn.h>
20#include <asm/io.h> 21#include <asm/io.h>
21#include <asm/kvm_para.h> 22#include <asm/kvm_para.h>
22#include <asm/kvm_virtio.h> 23#include <asm/kvm_virtio.h>
@@ -180,11 +181,10 @@ static struct virtqueue *kvm_find_vq(struct virtio_device *vdev,
180 181
181 config = kvm_vq_config(kdev->desc)+index; 182 config = kvm_vq_config(kdev->desc)+index;
182 183
183 if (add_shared_memory(config->address, 184 err = vmem_add_mapping(config->address,
184 vring_size(config->num, PAGE_SIZE))) { 185 vring_size(config->num, PAGE_SIZE));
185 err = -ENOMEM; 186 if (err)
186 goto out; 187 goto out;
187 }
188 188
189 vq = vring_new_virtqueue(config->num, vdev, (void *) config->address, 189 vq = vring_new_virtqueue(config->num, vdev, (void *) config->address,
190 kvm_notify, callback); 190 kvm_notify, callback);
@@ -202,8 +202,8 @@ static struct virtqueue *kvm_find_vq(struct virtio_device *vdev,
202 vq->priv = config; 202 vq->priv = config;
203 return vq; 203 return vq;
204unmap: 204unmap:
205 remove_shared_memory(config->address, vring_size(config->num, 205 vmem_remove_mapping(config->address,
206 PAGE_SIZE)); 206 vring_size(config->num, PAGE_SIZE));
207out: 207out:
208 return ERR_PTR(err); 208 return ERR_PTR(err);
209} 209}
@@ -213,8 +213,8 @@ static void kvm_del_vq(struct virtqueue *vq)
213 struct kvm_vqconfig *config = vq->priv; 213 struct kvm_vqconfig *config = vq->priv;
214 214
215 vring_del_virtqueue(vq); 215 vring_del_virtqueue(vq);
216 remove_shared_memory(config->address, 216 vmem_remove_mapping(config->address,
217 vring_size(config->num, PAGE_SIZE)); 217 vring_size(config->num, PAGE_SIZE));
218} 218}
219 219
220/* 220/*
@@ -318,12 +318,13 @@ static int __init kvm_devices_init(void)
318 return rc; 318 return rc;
319 } 319 }
320 320
321 if (add_shared_memory((max_pfn) << PAGE_SHIFT, PAGE_SIZE)) { 321 rc = vmem_add_mapping(PFN_PHYS(max_pfn), PAGE_SIZE);
322 if (rc) {
322 device_unregister(&kvm_root); 323 device_unregister(&kvm_root);
323 return -ENOMEM; 324 return rc;
324 } 325 }
325 326
326 kvm_devices = (void *) (max_pfn << PAGE_SHIFT); 327 kvm_devices = (void *) PFN_PHYS(max_pfn);
327 328
328 ctl_set_bit(0, 9); 329 ctl_set_bit(0, 9);
329 register_external_interrupt(0x2603, kvm_extint_handler); 330 register_external_interrupt(0x2603, kvm_extint_handler);
diff --git a/drivers/s390/net/cu3088.c b/drivers/s390/net/cu3088.c
index 76728ae4b843..8e7697305a4c 100644
--- a/drivers/s390/net/cu3088.c
+++ b/drivers/s390/net/cu3088.c
@@ -62,30 +62,14 @@ static struct device *cu3088_root_dev;
62static ssize_t 62static ssize_t
63group_write(struct device_driver *drv, const char *buf, size_t count) 63group_write(struct device_driver *drv, const char *buf, size_t count)
64{ 64{
65 const char *start, *end;
66 char bus_ids[2][BUS_ID_SIZE], *argv[2];
67 int i;
68 int ret; 65 int ret;
69 struct ccwgroup_driver *cdrv; 66 struct ccwgroup_driver *cdrv;
70 67
71 cdrv = to_ccwgroupdrv(drv); 68 cdrv = to_ccwgroupdrv(drv);
72 if (!cdrv) 69 if (!cdrv)
73 return -EINVAL; 70 return -EINVAL;
74 start = buf; 71 ret = ccwgroup_create_from_string(cu3088_root_dev, cdrv->driver_id,
75 for (i=0; i<2; i++) { 72 &cu3088_driver, 2, buf);
76 static const char delim[] = {',', '\n'};
77 int len;
78
79 if (!(end = strchr(start, delim[i])))
80 return -EINVAL;
81 len = min_t(ptrdiff_t, BUS_ID_SIZE, end - start + 1);
82 strlcpy (bus_ids[i], start, len);
83 argv[i] = bus_ids[i];
84 start = end + 1;
85 }
86
87 ret = ccwgroup_create(cu3088_root_dev, cdrv->driver_id,
88 &cu3088_driver, 2, argv);
89 73
90 return (ret == 0) ? count : ret; 74 return (ret == 0) ? count : ret;
91} 75}
diff --git a/drivers/s390/net/lcs.c b/drivers/s390/net/lcs.c
index f51ed9972587..dd22f4b37037 100644
--- a/drivers/s390/net/lcs.c
+++ b/drivers/s390/net/lcs.c
@@ -1793,7 +1793,8 @@ lcs_get_skb(struct lcs_card *card, char *skb_data, unsigned int skb_len)
1793 skb->protocol = card->lan_type_trans(skb, card->dev); 1793 skb->protocol = card->lan_type_trans(skb, card->dev);
1794 card->stats.rx_bytes += skb_len; 1794 card->stats.rx_bytes += skb_len;
1795 card->stats.rx_packets++; 1795 card->stats.rx_packets++;
1796 *((__u32 *)skb->cb) = ++card->pkt_seq; 1796 if (skb->protocol == htons(ETH_P_802_2))
1797 *((__u32 *)skb->cb) = ++card->pkt_seq;
1797 netif_rx(skb); 1798 netif_rx(skb);
1798} 1799}
1799 1800
diff --git a/drivers/s390/net/netiucv.c b/drivers/s390/net/netiucv.c
index 8f876f6ab367..e4ba6a0372ac 100644
--- a/drivers/s390/net/netiucv.c
+++ b/drivers/s390/net/netiucv.c
@@ -1313,8 +1313,6 @@ static int netiucv_tx(struct sk_buff *skb, struct net_device *dev)
1313 * and throw away packet. 1313 * and throw away packet.
1314 */ 1314 */
1315 if (fsm_getstate(privptr->fsm) != DEV_STATE_RUNNING) { 1315 if (fsm_getstate(privptr->fsm) != DEV_STATE_RUNNING) {
1316 if (!in_atomic())
1317 fsm_event(privptr->fsm, DEV_EVENT_START, dev);
1318 dev_kfree_skb(skb); 1316 dev_kfree_skb(skb);
1319 privptr->stats.tx_dropped++; 1317 privptr->stats.tx_dropped++;
1320 privptr->stats.tx_errors++; 1318 privptr->stats.tx_errors++;
@@ -2147,6 +2145,7 @@ static int __init netiucv_init(void)
2147 if (rc) 2145 if (rc)
2148 goto out_dbf; 2146 goto out_dbf;
2149 IUCV_DBF_TEXT(trace, 3, __func__); 2147 IUCV_DBF_TEXT(trace, 3, __func__);
2148 netiucv_driver.groups = netiucv_drv_attr_groups;
2150 rc = driver_register(&netiucv_driver); 2149 rc = driver_register(&netiucv_driver);
2151 if (rc) { 2150 if (rc) {
2152 PRINT_ERR("NETIUCV: failed to register driver.\n"); 2151 PRINT_ERR("NETIUCV: failed to register driver.\n");
diff --git a/drivers/s390/net/qeth_core.h b/drivers/s390/net/qeth_core.h
index 66f4f12503c9..699ac11debd8 100644
--- a/drivers/s390/net/qeth_core.h
+++ b/drivers/s390/net/qeth_core.h
@@ -72,22 +72,7 @@ struct qeth_dbf_info {
72 debug_sprintf_event(qeth_dbf[QETH_DBF_MSG].id, level, text) 72 debug_sprintf_event(qeth_dbf[QETH_DBF_MSG].id, level, text)
73 73
74#define QETH_DBF_TEXT_(name, level, text...) \ 74#define QETH_DBF_TEXT_(name, level, text...) \
75 do { \ 75 qeth_dbf_longtext(QETH_DBF_##name, level, text)
76 if (qeth_dbf_passes(qeth_dbf[QETH_DBF_##name].id, level)) { \
77 char *dbf_txt_buf = \
78 get_cpu_var(QETH_DBF_TXT_BUF); \
79 sprintf(dbf_txt_buf, text); \
80 debug_text_event(qeth_dbf[QETH_DBF_##name].id, \
81 level, dbf_txt_buf); \
82 put_cpu_var(QETH_DBF_TXT_BUF); \
83 } \
84 } while (0)
85
86/* Allow to sort out low debug levels early to avoid wasted sprints */
87static inline int qeth_dbf_passes(debug_info_t *dbf_grp, int level)
88{
89 return (level <= dbf_grp->level);
90}
91 76
92/** 77/**
93 * some more debug stuff 78 * some more debug stuff
@@ -773,27 +758,6 @@ static inline int qeth_get_micros(void)
773 return (int) (get_clock() >> 12); 758 return (int) (get_clock() >> 12);
774} 759}
775 760
776static inline void *qeth_push_skb(struct qeth_card *card, struct sk_buff *skb,
777 int size)
778{
779 void *hdr;
780
781 hdr = (void *) skb_push(skb, size);
782 /*
783 * sanity check, the Linux memory allocation scheme should
784 * never present us cases like this one (the qdio header size plus
785 * the first 40 bytes of the paket cross a 4k boundary)
786 */
787 if ((((unsigned long) hdr) & (~(PAGE_SIZE - 1))) !=
788 (((unsigned long) hdr + size +
789 QETH_IP_HEADER_SIZE) & (~(PAGE_SIZE - 1)))) {
790 PRINT_ERR("Misaligned packet on interface %s. Discarded.",
791 QETH_CARD_IFNAME(card));
792 return NULL;
793 }
794 return hdr;
795}
796
797static inline int qeth_get_ip_version(struct sk_buff *skb) 761static inline int qeth_get_ip_version(struct sk_buff *skb)
798{ 762{
799 switch (skb->protocol) { 763 switch (skb->protocol) {
@@ -806,6 +770,12 @@ static inline int qeth_get_ip_version(struct sk_buff *skb)
806 } 770 }
807} 771}
808 772
773static inline void qeth_put_buffer_pool_entry(struct qeth_card *card,
774 struct qeth_buffer_pool_entry *entry)
775{
776 list_add_tail(&entry->list, &card->qdio.in_buf_pool.entry_list);
777}
778
809struct qeth_eddp_context; 779struct qeth_eddp_context;
810extern struct ccwgroup_driver qeth_l2_ccwgroup_driver; 780extern struct ccwgroup_driver qeth_l2_ccwgroup_driver;
811extern struct ccwgroup_driver qeth_l3_ccwgroup_driver; 781extern struct ccwgroup_driver qeth_l3_ccwgroup_driver;
@@ -843,8 +813,6 @@ struct qeth_cmd_buffer *qeth_get_ipacmd_buffer(struct qeth_card *,
843int qeth_query_setadapterparms(struct qeth_card *); 813int qeth_query_setadapterparms(struct qeth_card *);
844int qeth_check_qdio_errors(struct qdio_buffer *, unsigned int, 814int qeth_check_qdio_errors(struct qdio_buffer *, unsigned int,
845 unsigned int, const char *); 815 unsigned int, const char *);
846void qeth_put_buffer_pool_entry(struct qeth_card *,
847 struct qeth_buffer_pool_entry *);
848void qeth_queue_input_buffer(struct qeth_card *, int); 816void qeth_queue_input_buffer(struct qeth_card *, int);
849struct sk_buff *qeth_core_get_next_skb(struct qeth_card *, 817struct sk_buff *qeth_core_get_next_skb(struct qeth_card *,
850 struct qdio_buffer *, struct qdio_buffer_element **, int *, 818 struct qdio_buffer *, struct qdio_buffer_element **, int *,
@@ -880,8 +848,6 @@ int qeth_send_control_data(struct qeth_card *, int, struct qeth_cmd_buffer *,
880 void *reply_param); 848 void *reply_param);
881int qeth_get_cast_type(struct qeth_card *, struct sk_buff *); 849int qeth_get_cast_type(struct qeth_card *, struct sk_buff *);
882int qeth_get_priority_queue(struct qeth_card *, struct sk_buff *, int, int); 850int qeth_get_priority_queue(struct qeth_card *, struct sk_buff *, int, int);
883struct sk_buff *qeth_prepare_skb(struct qeth_card *, struct sk_buff *,
884 struct qeth_hdr **);
885int qeth_get_elements_no(struct qeth_card *, void *, struct sk_buff *, int); 851int qeth_get_elements_no(struct qeth_card *, void *, struct sk_buff *, int);
886int qeth_do_send_packet_fast(struct qeth_card *, struct qeth_qdio_out_q *, 852int qeth_do_send_packet_fast(struct qeth_card *, struct qeth_qdio_out_q *,
887 struct sk_buff *, struct qeth_hdr *, int, 853 struct sk_buff *, struct qeth_hdr *, int,
@@ -894,6 +860,8 @@ void qeth_core_get_ethtool_stats(struct net_device *,
894 struct ethtool_stats *, u64 *); 860 struct ethtool_stats *, u64 *);
895void qeth_core_get_strings(struct net_device *, u32, u8 *); 861void qeth_core_get_strings(struct net_device *, u32, u8 *);
896void qeth_core_get_drvinfo(struct net_device *, struct ethtool_drvinfo *); 862void qeth_core_get_drvinfo(struct net_device *, struct ethtool_drvinfo *);
863void qeth_dbf_longtext(enum qeth_dbf_names dbf_nix, int level, char *text, ...);
864int qeth_core_ethtool_get_settings(struct net_device *, struct ethtool_cmd *);
897 865
898/* exports for OSN */ 866/* exports for OSN */
899int qeth_osn_assist(struct net_device *, void *, int); 867int qeth_osn_assist(struct net_device *, void *, int);
diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
index 055f5c3e7b56..436bf1f6d4a6 100644
--- a/drivers/s390/net/qeth_core_main.c
+++ b/drivers/s390/net/qeth_core_main.c
@@ -26,9 +26,6 @@
26#include "qeth_core.h" 26#include "qeth_core.h"
27#include "qeth_core_offl.h" 27#include "qeth_core_offl.h"
28 28
29static DEFINE_PER_CPU(char[256], qeth_core_dbf_txt_buf);
30#define QETH_DBF_TXT_BUF qeth_core_dbf_txt_buf
31
32struct qeth_dbf_info qeth_dbf[QETH_DBF_INFOS] = { 29struct qeth_dbf_info qeth_dbf[QETH_DBF_INFOS] = {
33 /* define dbf - Name, Pages, Areas, Maxlen, Level, View, Handle */ 30 /* define dbf - Name, Pages, Areas, Maxlen, Level, View, Handle */
34 /* N P A M L V H */ 31 /* N P A M L V H */
@@ -2255,14 +2252,6 @@ void qeth_print_status_message(struct qeth_card *card)
2255} 2252}
2256EXPORT_SYMBOL_GPL(qeth_print_status_message); 2253EXPORT_SYMBOL_GPL(qeth_print_status_message);
2257 2254
2258void qeth_put_buffer_pool_entry(struct qeth_card *card,
2259 struct qeth_buffer_pool_entry *entry)
2260{
2261 QETH_DBF_TEXT(TRACE, 6, "ptbfplen");
2262 list_add_tail(&entry->list, &card->qdio.in_buf_pool.entry_list);
2263}
2264EXPORT_SYMBOL_GPL(qeth_put_buffer_pool_entry);
2265
2266static void qeth_initialize_working_pool_list(struct qeth_card *card) 2255static void qeth_initialize_working_pool_list(struct qeth_card *card)
2267{ 2256{
2268 struct qeth_buffer_pool_entry *entry; 2257 struct qeth_buffer_pool_entry *entry;
@@ -2603,7 +2592,6 @@ void qeth_queue_input_buffer(struct qeth_card *card, int index)
2603 int rc; 2592 int rc;
2604 int newcount = 0; 2593 int newcount = 0;
2605 2594
2606 QETH_DBF_TEXT(TRACE, 6, "queinbuf");
2607 count = (index < queue->next_buf_to_init)? 2595 count = (index < queue->next_buf_to_init)?
2608 card->qdio.in_buf_pool.buf_count - 2596 card->qdio.in_buf_pool.buf_count -
2609 (queue->next_buf_to_init - index) : 2597 (queue->next_buf_to_init - index) :
@@ -2792,8 +2780,6 @@ static void qeth_flush_buffers(struct qeth_qdio_out_q *queue, int under_int,
2792 int i; 2780 int i;
2793 unsigned int qdio_flags; 2781 unsigned int qdio_flags;
2794 2782
2795 QETH_DBF_TEXT(TRACE, 6, "flushbuf");
2796
2797 for (i = index; i < index + count; ++i) { 2783 for (i = index; i < index + count; ++i) {
2798 buf = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q]; 2784 buf = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q];
2799 buf->buffer->element[buf->next_element_to_fill - 1].flags |= 2785 buf->buffer->element[buf->next_element_to_fill - 1].flags |=
@@ -3037,49 +3023,6 @@ int qeth_get_priority_queue(struct qeth_card *card, struct sk_buff *skb,
3037} 3023}
3038EXPORT_SYMBOL_GPL(qeth_get_priority_queue); 3024EXPORT_SYMBOL_GPL(qeth_get_priority_queue);
3039 3025
3040static void __qeth_free_new_skb(struct sk_buff *orig_skb,
3041 struct sk_buff *new_skb)
3042{
3043 if (orig_skb != new_skb)
3044 dev_kfree_skb_any(new_skb);
3045}
3046
3047static inline struct sk_buff *qeth_realloc_headroom(struct qeth_card *card,
3048 struct sk_buff *skb, int size)
3049{
3050 struct sk_buff *new_skb = skb;
3051
3052 if (skb_headroom(skb) >= size)
3053 return skb;
3054 new_skb = skb_realloc_headroom(skb, size);
3055 if (!new_skb)
3056 PRINT_ERR("Could not realloc headroom for qeth_hdr "
3057 "on interface %s", QETH_CARD_IFNAME(card));
3058 return new_skb;
3059}
3060
3061struct sk_buff *qeth_prepare_skb(struct qeth_card *card, struct sk_buff *skb,
3062 struct qeth_hdr **hdr)
3063{
3064 struct sk_buff *new_skb;
3065
3066 QETH_DBF_TEXT(TRACE, 6, "prepskb");
3067
3068 new_skb = qeth_realloc_headroom(card, skb,
3069 sizeof(struct qeth_hdr));
3070 if (!new_skb)
3071 return NULL;
3072
3073 *hdr = ((struct qeth_hdr *)qeth_push_skb(card, new_skb,
3074 sizeof(struct qeth_hdr)));
3075 if (*hdr == NULL) {
3076 __qeth_free_new_skb(skb, new_skb);
3077 return NULL;
3078 }
3079 return new_skb;
3080}
3081EXPORT_SYMBOL_GPL(qeth_prepare_skb);
3082
3083int qeth_get_elements_no(struct qeth_card *card, void *hdr, 3026int qeth_get_elements_no(struct qeth_card *card, void *hdr,
3084 struct sk_buff *skb, int elems) 3027 struct sk_buff *skb, int elems)
3085{ 3028{
@@ -3100,8 +3043,8 @@ int qeth_get_elements_no(struct qeth_card *card, void *hdr,
3100} 3043}
3101EXPORT_SYMBOL_GPL(qeth_get_elements_no); 3044EXPORT_SYMBOL_GPL(qeth_get_elements_no);
3102 3045
3103static void __qeth_fill_buffer(struct sk_buff *skb, struct qdio_buffer *buffer, 3046static inline void __qeth_fill_buffer(struct sk_buff *skb,
3104 int is_tso, int *next_element_to_fill) 3047 struct qdio_buffer *buffer, int is_tso, int *next_element_to_fill)
3105{ 3048{
3106 int length = skb->len; 3049 int length = skb->len;
3107 int length_here; 3050 int length_here;
@@ -3143,15 +3086,13 @@ static void __qeth_fill_buffer(struct sk_buff *skb, struct qdio_buffer *buffer,
3143 *next_element_to_fill = element; 3086 *next_element_to_fill = element;
3144} 3087}
3145 3088
3146static int qeth_fill_buffer(struct qeth_qdio_out_q *queue, 3089static inline int qeth_fill_buffer(struct qeth_qdio_out_q *queue,
3147 struct qeth_qdio_out_buffer *buf, struct sk_buff *skb) 3090 struct qeth_qdio_out_buffer *buf, struct sk_buff *skb)
3148{ 3091{
3149 struct qdio_buffer *buffer; 3092 struct qdio_buffer *buffer;
3150 struct qeth_hdr_tso *hdr; 3093 struct qeth_hdr_tso *hdr;
3151 int flush_cnt = 0, hdr_len, large_send = 0; 3094 int flush_cnt = 0, hdr_len, large_send = 0;
3152 3095
3153 QETH_DBF_TEXT(TRACE, 6, "qdfillbf");
3154
3155 buffer = buf->buffer; 3096 buffer = buf->buffer;
3156 atomic_inc(&skb->users); 3097 atomic_inc(&skb->users);
3157 skb_queue_tail(&buf->skb_list, skb); 3098 skb_queue_tail(&buf->skb_list, skb);
@@ -3210,8 +3151,6 @@ int qeth_do_send_packet_fast(struct qeth_card *card,
3210 int flush_cnt = 0; 3151 int flush_cnt = 0;
3211 int index; 3152 int index;
3212 3153
3213 QETH_DBF_TEXT(TRACE, 6, "dosndpfa");
3214
3215 /* spin until we get the queue ... */ 3154 /* spin until we get the queue ... */
3216 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED, 3155 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
3217 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED); 3156 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
@@ -3263,8 +3202,6 @@ int qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue,
3263 int tmp; 3202 int tmp;
3264 int rc = 0; 3203 int rc = 0;
3265 3204
3266 QETH_DBF_TEXT(TRACE, 6, "dosndpkt");
3267
3268 /* spin until we get the queue ... */ 3205 /* spin until we get the queue ... */
3269 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED, 3206 while (atomic_cmpxchg(&queue->state, QETH_OUT_Q_UNLOCKED,
3270 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED); 3207 QETH_OUT_Q_LOCKED) != QETH_OUT_Q_UNLOCKED);
@@ -3827,27 +3764,8 @@ static struct ccw_driver qeth_ccw_driver = {
3827static int qeth_core_driver_group(const char *buf, struct device *root_dev, 3764static int qeth_core_driver_group(const char *buf, struct device *root_dev,
3828 unsigned long driver_id) 3765 unsigned long driver_id)
3829{ 3766{
3830 const char *start, *end; 3767 return ccwgroup_create_from_string(root_dev, driver_id,
3831 char bus_ids[3][BUS_ID_SIZE], *argv[3]; 3768 &qeth_ccw_driver, 3, buf);
3832 int i;
3833
3834 start = buf;
3835 for (i = 0; i < 3; i++) {
3836 static const char delim[] = { ',', ',', '\n' };
3837 int len;
3838
3839 end = strchr(start, delim[i]);
3840 if (!end)
3841 return -EINVAL;
3842 len = min_t(ptrdiff_t, BUS_ID_SIZE, end - start);
3843 strncpy(bus_ids[i], start, len);
3844 bus_ids[i][len] = '\0';
3845 start = end + 1;
3846 argv[i] = bus_ids[i];
3847 }
3848
3849 return (ccwgroup_create(root_dev, driver_id,
3850 &qeth_ccw_driver, 3, argv));
3851} 3769}
3852 3770
3853int qeth_core_hardsetup_card(struct qeth_card *card) 3771int qeth_core_hardsetup_card(struct qeth_card *card)
@@ -3885,8 +3803,9 @@ retry:
3885 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc); 3803 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
3886 return rc; 3804 return rc;
3887 } 3805 }
3888 3806 mpno = qdio_get_ssqd_pct(CARD_DDEV(card));
3889 mpno = QETH_MAX_PORTNO; 3807 if (mpno)
3808 mpno = min(mpno - 1, QETH_MAX_PORTNO);
3890 if (card->info.portno > mpno) { 3809 if (card->info.portno > mpno) {
3891 PRINT_ERR("Device %s does not offer port number %d \n.", 3810 PRINT_ERR("Device %s does not offer port number %d \n.",
3892 CARD_BUS_ID(card), card->info.portno); 3811 CARD_BUS_ID(card), card->info.portno);
@@ -3980,7 +3899,6 @@ struct sk_buff *qeth_core_get_next_skb(struct qeth_card *card,
3980 int use_rx_sg = 0; 3899 int use_rx_sg = 0;
3981 int frag = 0; 3900 int frag = 0;
3982 3901
3983 QETH_DBF_TEXT(TRACE, 6, "nextskb");
3984 /* qeth_hdr must not cross element boundaries */ 3902 /* qeth_hdr must not cross element boundaries */
3985 if (element->length < offset + sizeof(struct qeth_hdr)) { 3903 if (element->length < offset + sizeof(struct qeth_hdr)) {
3986 if (qeth_is_last_sbale(element)) 3904 if (qeth_is_last_sbale(element))
@@ -4086,6 +4004,18 @@ static void qeth_unregister_dbf_views(void)
4086 } 4004 }
4087} 4005}
4088 4006
4007void qeth_dbf_longtext(enum qeth_dbf_names dbf_nix, int level, char *text, ...)
4008{
4009 char dbf_txt_buf[32];
4010
4011 if (level > (qeth_dbf[dbf_nix].id)->level)
4012 return;
4013 snprintf(dbf_txt_buf, sizeof(dbf_txt_buf), text);
4014 debug_text_event(qeth_dbf[dbf_nix].id, level, dbf_txt_buf);
4015
4016}
4017EXPORT_SYMBOL_GPL(qeth_dbf_longtext);
4018
4089static int qeth_register_dbf_views(void) 4019static int qeth_register_dbf_views(void)
4090{ 4020{
4091 int ret; 4021 int ret;
@@ -4433,6 +4363,96 @@ void qeth_core_get_drvinfo(struct net_device *dev,
4433} 4363}
4434EXPORT_SYMBOL_GPL(qeth_core_get_drvinfo); 4364EXPORT_SYMBOL_GPL(qeth_core_get_drvinfo);
4435 4365
4366int qeth_core_ethtool_get_settings(struct net_device *netdev,
4367 struct ethtool_cmd *ecmd)
4368{
4369 struct qeth_card *card = netdev_priv(netdev);
4370 enum qeth_link_types link_type;
4371
4372 if ((card->info.type == QETH_CARD_TYPE_IQD) || (card->info.guestlan))
4373 link_type = QETH_LINK_TYPE_10GBIT_ETH;
4374 else
4375 link_type = card->info.link_type;
4376
4377 ecmd->transceiver = XCVR_INTERNAL;
4378 ecmd->supported = SUPPORTED_Autoneg;
4379 ecmd->advertising = ADVERTISED_Autoneg;
4380 ecmd->duplex = DUPLEX_FULL;
4381 ecmd->autoneg = AUTONEG_ENABLE;
4382
4383 switch (link_type) {
4384 case QETH_LINK_TYPE_FAST_ETH:
4385 case QETH_LINK_TYPE_LANE_ETH100:
4386 ecmd->supported |= SUPPORTED_10baseT_Half |
4387 SUPPORTED_10baseT_Full |
4388 SUPPORTED_100baseT_Half |
4389 SUPPORTED_100baseT_Full |
4390 SUPPORTED_TP;
4391 ecmd->advertising |= ADVERTISED_10baseT_Half |
4392 ADVERTISED_10baseT_Full |
4393 ADVERTISED_100baseT_Half |
4394 ADVERTISED_100baseT_Full |
4395 ADVERTISED_TP;
4396 ecmd->speed = SPEED_100;
4397 ecmd->port = PORT_TP;
4398 break;
4399
4400 case QETH_LINK_TYPE_GBIT_ETH:
4401 case QETH_LINK_TYPE_LANE_ETH1000:
4402 ecmd->supported |= SUPPORTED_10baseT_Half |
4403 SUPPORTED_10baseT_Full |
4404 SUPPORTED_100baseT_Half |
4405 SUPPORTED_100baseT_Full |
4406 SUPPORTED_1000baseT_Half |
4407 SUPPORTED_1000baseT_Full |
4408 SUPPORTED_FIBRE;
4409 ecmd->advertising |= ADVERTISED_10baseT_Half |
4410 ADVERTISED_10baseT_Full |
4411 ADVERTISED_100baseT_Half |
4412 ADVERTISED_100baseT_Full |
4413 ADVERTISED_1000baseT_Half |
4414 ADVERTISED_1000baseT_Full |
4415 ADVERTISED_FIBRE;
4416 ecmd->speed = SPEED_1000;
4417 ecmd->port = PORT_FIBRE;
4418 break;
4419
4420 case QETH_LINK_TYPE_10GBIT_ETH:
4421 ecmd->supported |= SUPPORTED_10baseT_Half |
4422 SUPPORTED_10baseT_Full |
4423 SUPPORTED_100baseT_Half |
4424 SUPPORTED_100baseT_Full |
4425 SUPPORTED_1000baseT_Half |
4426 SUPPORTED_1000baseT_Full |
4427 SUPPORTED_10000baseT_Full |
4428 SUPPORTED_FIBRE;
4429 ecmd->advertising |= ADVERTISED_10baseT_Half |
4430 ADVERTISED_10baseT_Full |
4431 ADVERTISED_100baseT_Half |
4432 ADVERTISED_100baseT_Full |
4433 ADVERTISED_1000baseT_Half |
4434 ADVERTISED_1000baseT_Full |
4435 ADVERTISED_10000baseT_Full |
4436 ADVERTISED_FIBRE;
4437 ecmd->speed = SPEED_10000;
4438 ecmd->port = PORT_FIBRE;
4439 break;
4440
4441 default:
4442 ecmd->supported |= SUPPORTED_10baseT_Half |
4443 SUPPORTED_10baseT_Full |
4444 SUPPORTED_TP;
4445 ecmd->advertising |= ADVERTISED_10baseT_Half |
4446 ADVERTISED_10baseT_Full |
4447 ADVERTISED_TP;
4448 ecmd->speed = SPEED_10;
4449 ecmd->port = PORT_TP;
4450 }
4451
4452 return 0;
4453}
4454EXPORT_SYMBOL_GPL(qeth_core_ethtool_get_settings);
4455
4436static int __init qeth_core_init(void) 4456static int __init qeth_core_init(void)
4437{ 4457{
4438 int rc; 4458 int rc;
diff --git a/drivers/s390/net/qeth_l2_main.c b/drivers/s390/net/qeth_l2_main.c
index 3921d1631a78..86ec50ddae13 100644
--- a/drivers/s390/net/qeth_l2_main.c
+++ b/drivers/s390/net/qeth_l2_main.c
@@ -22,9 +22,6 @@
22#include "qeth_core.h" 22#include "qeth_core.h"
23#include "qeth_core_offl.h" 23#include "qeth_core_offl.h"
24 24
25#define QETH_DBF_TXT_BUF qeth_l2_dbf_txt_buf
26static DEFINE_PER_CPU(char[256], qeth_l2_dbf_txt_buf);
27
28static int qeth_l2_set_offline(struct ccwgroup_device *); 25static int qeth_l2_set_offline(struct ccwgroup_device *);
29static int qeth_l2_stop(struct net_device *); 26static int qeth_l2_stop(struct net_device *);
30static int qeth_l2_send_delmac(struct qeth_card *, __u8 *); 27static int qeth_l2_send_delmac(struct qeth_card *, __u8 *);
@@ -635,8 +632,6 @@ static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
635 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO; 632 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
636 struct qeth_eddp_context *ctx = NULL; 633 struct qeth_eddp_context *ctx = NULL;
637 634
638 QETH_DBF_TEXT(TRACE, 6, "l2xmit");
639
640 if ((card->state != CARD_STATE_UP) || !card->lan_online) { 635 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
641 card->stats.tx_carrier_errors++; 636 card->stats.tx_carrier_errors++;
642 goto tx_drop; 637 goto tx_drop;
@@ -658,9 +653,12 @@ static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
658 if (card->info.type == QETH_CARD_TYPE_OSN) 653 if (card->info.type == QETH_CARD_TYPE_OSN)
659 hdr = (struct qeth_hdr *)skb->data; 654 hdr = (struct qeth_hdr *)skb->data;
660 else { 655 else {
661 new_skb = qeth_prepare_skb(card, skb, &hdr); 656 /* create a clone with writeable headroom */
657 new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr));
662 if (!new_skb) 658 if (!new_skb)
663 goto tx_drop; 659 goto tx_drop;
660 hdr = (struct qeth_hdr *)skb_push(new_skb,
661 sizeof(struct qeth_hdr));
664 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type); 662 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
665 } 663 }
666 664
@@ -747,7 +745,6 @@ static void qeth_l2_qdio_input_handler(struct ccw_device *ccwdev,
747 int index; 745 int index;
748 int i; 746 int i;
749 747
750 QETH_DBF_TEXT(TRACE, 6, "qdinput");
751 card = (struct qeth_card *) card_ptr; 748 card = (struct qeth_card *) card_ptr;
752 net_dev = card->dev; 749 net_dev = card->dev;
753 if (card->options.performance_stats) { 750 if (card->options.performance_stats) {
@@ -852,6 +849,22 @@ static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
852 return; 849 return;
853} 850}
854 851
852static int qeth_l2_ethtool_set_tso(struct net_device *dev, u32 data)
853{
854 struct qeth_card *card = netdev_priv(dev);
855
856 if (data) {
857 if (card->options.large_send == QETH_LARGE_SEND_NO) {
858 card->options.large_send = QETH_LARGE_SEND_EDDP;
859 dev->features |= NETIF_F_TSO;
860 }
861 } else {
862 dev->features &= ~NETIF_F_TSO;
863 card->options.large_send = QETH_LARGE_SEND_NO;
864 }
865 return 0;
866}
867
855static struct ethtool_ops qeth_l2_ethtool_ops = { 868static struct ethtool_ops qeth_l2_ethtool_ops = {
856 .get_link = ethtool_op_get_link, 869 .get_link = ethtool_op_get_link,
857 .get_tx_csum = ethtool_op_get_tx_csum, 870 .get_tx_csum = ethtool_op_get_tx_csum,
@@ -859,11 +872,12 @@ static struct ethtool_ops qeth_l2_ethtool_ops = {
859 .get_sg = ethtool_op_get_sg, 872 .get_sg = ethtool_op_get_sg,
860 .set_sg = ethtool_op_set_sg, 873 .set_sg = ethtool_op_set_sg,
861 .get_tso = ethtool_op_get_tso, 874 .get_tso = ethtool_op_get_tso,
862 .set_tso = ethtool_op_set_tso, 875 .set_tso = qeth_l2_ethtool_set_tso,
863 .get_strings = qeth_core_get_strings, 876 .get_strings = qeth_core_get_strings,
864 .get_ethtool_stats = qeth_core_get_ethtool_stats, 877 .get_ethtool_stats = qeth_core_get_ethtool_stats,
865 .get_stats_count = qeth_core_get_stats_count, 878 .get_stats_count = qeth_core_get_stats_count,
866 .get_drvinfo = qeth_core_get_drvinfo, 879 .get_drvinfo = qeth_core_get_drvinfo,
880 .get_settings = qeth_core_ethtool_get_settings,
867}; 881};
868 882
869static struct ethtool_ops qeth_l2_osn_ops = { 883static struct ethtool_ops qeth_l2_osn_ops = {
diff --git a/drivers/s390/net/qeth_l3.h b/drivers/s390/net/qeth_l3.h
index 1be353593a59..9f143c83bba3 100644
--- a/drivers/s390/net/qeth_l3.h
+++ b/drivers/s390/net/qeth_l3.h
@@ -13,9 +13,6 @@
13 13
14#include "qeth_core.h" 14#include "qeth_core.h"
15 15
16#define QETH_DBF_TXT_BUF qeth_l3_dbf_txt_buf
17DECLARE_PER_CPU(char[256], qeth_l3_dbf_txt_buf);
18
19struct qeth_ipaddr { 16struct qeth_ipaddr {
20 struct list_head entry; 17 struct list_head entry;
21 enum qeth_ip_types type; 18 enum qeth_ip_types type;
diff --git a/drivers/s390/net/qeth_l3_main.c b/drivers/s390/net/qeth_l3_main.c
index e1bfe56087d6..94a8ead64ed4 100644
--- a/drivers/s390/net/qeth_l3_main.c
+++ b/drivers/s390/net/qeth_l3_main.c
@@ -28,8 +28,6 @@
28#include "qeth_l3.h" 28#include "qeth_l3.h"
29#include "qeth_core_offl.h" 29#include "qeth_core_offl.h"
30 30
31DEFINE_PER_CPU(char[256], qeth_l3_dbf_txt_buf);
32
33static int qeth_l3_set_offline(struct ccwgroup_device *); 31static int qeth_l3_set_offline(struct ccwgroup_device *);
34static int qeth_l3_recover(void *); 32static int qeth_l3_recover(void *);
35static int qeth_l3_stop(struct net_device *); 33static int qeth_l3_stop(struct net_device *);
@@ -2093,6 +2091,11 @@ static int qeth_l3_stop_card(struct qeth_card *card, int recovery_mode)
2093 (card->state == CARD_STATE_UP)) { 2091 (card->state == CARD_STATE_UP)) {
2094 if (recovery_mode) 2092 if (recovery_mode)
2095 qeth_l3_stop(card->dev); 2093 qeth_l3_stop(card->dev);
2094 else {
2095 rtnl_lock();
2096 dev_close(card->dev);
2097 rtnl_unlock();
2098 }
2096 if (!card->use_hard_stop) { 2099 if (!card->use_hard_stop) {
2097 rc = qeth_send_stoplan(card); 2100 rc = qeth_send_stoplan(card);
2098 if (rc) 2101 if (rc)
@@ -2559,8 +2562,6 @@ static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2559static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr, 2562static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2560 struct sk_buff *skb, int ipv, int cast_type) 2563 struct sk_buff *skb, int ipv, int cast_type)
2561{ 2564{
2562 QETH_DBF_TEXT(TRACE, 6, "fillhdr");
2563
2564 memset(hdr, 0, sizeof(struct qeth_hdr)); 2565 memset(hdr, 0, sizeof(struct qeth_hdr));
2565 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3; 2566 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
2566 hdr->hdr.l3.ext_flags = 0; 2567 hdr->hdr.l3.ext_flags = 0;
@@ -2570,9 +2571,10 @@ static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
2570 * v6 uses passthrough, v4 sets the tag in the QDIO header. 2571 * v6 uses passthrough, v4 sets the tag in the QDIO header.
2571 */ 2572 */
2572 if (card->vlangrp && vlan_tx_tag_present(skb)) { 2573 if (card->vlangrp && vlan_tx_tag_present(skb)) {
2573 hdr->hdr.l3.ext_flags = (ipv == 4) ? 2574 if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD))
2574 QETH_HDR_EXT_VLAN_FRAME : 2575 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME;
2575 QETH_HDR_EXT_INCLUDE_VLAN_TAG; 2576 else
2577 hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG;
2576 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb); 2578 hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb);
2577 } 2579 }
2578 2580
@@ -2638,8 +2640,6 @@ static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
2638 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO; 2640 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
2639 struct qeth_eddp_context *ctx = NULL; 2641 struct qeth_eddp_context *ctx = NULL;
2640 2642
2641 QETH_DBF_TEXT(TRACE, 6, "l3xmit");
2642
2643 if ((card->info.type == QETH_CARD_TYPE_IQD) && 2643 if ((card->info.type == QETH_CARD_TYPE_IQD) &&
2644 (skb->protocol != htons(ETH_P_IPV6)) && 2644 (skb->protocol != htons(ETH_P_IPV6)) &&
2645 (skb->protocol != htons(ETH_P_IP))) 2645 (skb->protocol != htons(ETH_P_IP)))
@@ -2890,6 +2890,7 @@ static struct ethtool_ops qeth_l3_ethtool_ops = {
2890 .get_ethtool_stats = qeth_core_get_ethtool_stats, 2890 .get_ethtool_stats = qeth_core_get_ethtool_stats,
2891 .get_stats_count = qeth_core_get_stats_count, 2891 .get_stats_count = qeth_core_get_stats_count,
2892 .get_drvinfo = qeth_core_get_drvinfo, 2892 .get_drvinfo = qeth_core_get_drvinfo,
2893 .get_settings = qeth_core_ethtool_get_settings,
2893}; 2894};
2894 2895
2895/* 2896/*
@@ -2982,7 +2983,6 @@ static void qeth_l3_qdio_input_handler(struct ccw_device *ccwdev,
2982 int index; 2983 int index;
2983 int i; 2984 int i;
2984 2985
2985 QETH_DBF_TEXT(TRACE, 6, "qdinput");
2986 card = (struct qeth_card *) card_ptr; 2986 card = (struct qeth_card *) card_ptr;
2987 net_dev = card->dev; 2987 net_dev = card->dev;
2988 if (card->options.performance_stats) { 2988 if (card->options.performance_stats) {
@@ -3140,9 +3140,15 @@ static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode)
3140 netif_carrier_on(card->dev); 3140 netif_carrier_on(card->dev);
3141 3141
3142 qeth_set_allowed_threads(card, 0xffffffff, 0); 3142 qeth_set_allowed_threads(card, 0xffffffff, 0);
3143 if ((recover_flag == CARD_STATE_RECOVER) && recovery_mode) { 3143 if (recover_flag == CARD_STATE_RECOVER) {
3144 if (recovery_mode)
3144 qeth_l3_open(card->dev); 3145 qeth_l3_open(card->dev);
3145 qeth_l3_set_multicast_list(card->dev); 3146 else {
3147 rtnl_lock();
3148 dev_open(card->dev);
3149 rtnl_unlock();
3150 }
3151 qeth_l3_set_multicast_list(card->dev);
3146 } 3152 }
3147 /* let user_space know that device is online */ 3153 /* let user_space know that device is online */
3148 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE); 3154 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
diff --git a/drivers/s390/scsi/zfcp_dbf.c b/drivers/s390/scsi/zfcp_dbf.c
index 37b85c67b11d..c8bad675dbd1 100644
--- a/drivers/s390/scsi/zfcp_dbf.c
+++ b/drivers/s390/scsi/zfcp_dbf.c
@@ -1055,7 +1055,7 @@ static void zfcp_scsi_dbf_event(const char *tag, const char *tag2, int level,
1055 rec->scsi_result = scsi_cmnd->result; 1055 rec->scsi_result = scsi_cmnd->result;
1056 rec->scsi_cmnd = (unsigned long)scsi_cmnd; 1056 rec->scsi_cmnd = (unsigned long)scsi_cmnd;
1057 rec->scsi_serial = scsi_cmnd->serial_number; 1057 rec->scsi_serial = scsi_cmnd->serial_number;
1058 memcpy(rec->scsi_opcode, &scsi_cmnd->cmnd, 1058 memcpy(rec->scsi_opcode, scsi_cmnd->cmnd,
1059 min((int)scsi_cmnd->cmd_len, 1059 min((int)scsi_cmnd->cmd_len,
1060 ZFCP_DBF_SCSI_OPCODE)); 1060 ZFCP_DBF_SCSI_OPCODE));
1061 rec->scsi_retries = scsi_cmnd->retries; 1061 rec->scsi_retries = scsi_cmnd->retries;
diff --git a/drivers/s390/scsi/zfcp_fsf.c b/drivers/s390/scsi/zfcp_fsf.c
index 9af2330f07a2..b2ea4ea051f5 100644
--- a/drivers/s390/scsi/zfcp_fsf.c
+++ b/drivers/s390/scsi/zfcp_fsf.c
@@ -4014,7 +4014,7 @@ zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
4014 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n", 4014 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4015 scpnt->result); 4015 scpnt->result);
4016 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, 4016 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4017 (void *) &scpnt->cmnd, scpnt->cmd_len); 4017 scpnt->cmnd, scpnt->cmd_len);
4018 4018
4019 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n", 4019 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4020 fcp_rsp_iu->fcp_sns_len); 4020 fcp_rsp_iu->fcp_sns_len);
diff --git a/drivers/sbus/char/cpwatchdog.c b/drivers/sbus/char/cpwatchdog.c
index a4e758143665..235703414370 100644
--- a/drivers/sbus/char/cpwatchdog.c
+++ b/drivers/sbus/char/cpwatchdog.c
@@ -637,7 +637,7 @@ static int wd_inittimer(int whichdog)
637 break; 637 break;
638 default: 638 default:
639 printk("%s: %s: invalid watchdog id: %i\n", 639 printk("%s: %s: invalid watchdog id: %i\n",
640 WD_OBPNAME, __FUNCTION__, whichdog); 640 WD_OBPNAME, __func__, whichdog);
641 return(1); 641 return(1);
642 } 642 }
643 if(0 != misc_register(whichmisc)) 643 if(0 != misc_register(whichmisc))
diff --git a/drivers/sbus/char/uctrl.c b/drivers/sbus/char/uctrl.c
index 44d2ef906ac7..383f32c1d347 100644
--- a/drivers/sbus/char/uctrl.c
+++ b/drivers/sbus/char/uctrl.c
@@ -393,13 +393,13 @@ static int __init ts102_uctrl_init(void)
393 err = request_irq(driver->irq, uctrl_interrupt, 0, "uctrl", driver); 393 err = request_irq(driver->irq, uctrl_interrupt, 0, "uctrl", driver);
394 if (err) { 394 if (err) {
395 printk("%s: unable to register irq %d\n", 395 printk("%s: unable to register irq %d\n",
396 __FUNCTION__, driver->irq); 396 __func__, driver->irq);
397 return err; 397 return err;
398 } 398 }
399 399
400 if (misc_register(&uctrl_dev)) { 400 if (misc_register(&uctrl_dev)) {
401 printk("%s: unable to get misc minor %d\n", 401 printk("%s: unable to get misc minor %d\n",
402 __FUNCTION__, uctrl_dev.minor); 402 __func__, uctrl_dev.minor);
403 free_irq(driver->irq, driver); 403 free_irq(driver->irq, driver);
404 return -ENODEV; 404 return -ENODEV;
405 } 405 }
diff --git a/drivers/scsi/53c700.c b/drivers/scsi/53c700.c
index f4c4fe90240a..f5a9addb7050 100644
--- a/drivers/scsi/53c700.c
+++ b/drivers/scsi/53c700.c
@@ -599,7 +599,7 @@ NCR_700_scsi_done(struct NCR_700_Host_Parameters *hostdata,
599 (struct NCR_700_command_slot *)SCp->host_scribble; 599 (struct NCR_700_command_slot *)SCp->host_scribble;
600 600
601 dma_unmap_single(hostdata->dev, slot->pCmd, 601 dma_unmap_single(hostdata->dev, slot->pCmd,
602 sizeof(SCp->cmnd), DMA_TO_DEVICE); 602 MAX_COMMAND_SIZE, DMA_TO_DEVICE);
603 if (slot->flags == NCR_700_FLAG_AUTOSENSE) { 603 if (slot->flags == NCR_700_FLAG_AUTOSENSE) {
604 char *cmnd = NCR_700_get_sense_cmnd(SCp->device); 604 char *cmnd = NCR_700_get_sense_cmnd(SCp->device);
605#ifdef NCR_700_DEBUG 605#ifdef NCR_700_DEBUG
@@ -1004,7 +1004,7 @@ process_script_interrupt(__u32 dsps, __u32 dsp, struct scsi_cmnd *SCp,
1004 * here */ 1004 * here */
1005 NCR_700_unmap(hostdata, SCp, slot); 1005 NCR_700_unmap(hostdata, SCp, slot);
1006 dma_unmap_single(hostdata->dev, slot->pCmd, 1006 dma_unmap_single(hostdata->dev, slot->pCmd,
1007 sizeof(SCp->cmnd), 1007 MAX_COMMAND_SIZE,
1008 DMA_TO_DEVICE); 1008 DMA_TO_DEVICE);
1009 1009
1010 cmnd[0] = REQUEST_SENSE; 1010 cmnd[0] = REQUEST_SENSE;
@@ -1901,7 +1901,7 @@ NCR_700_queuecommand(struct scsi_cmnd *SCp, void (*done)(struct scsi_cmnd *))
1901 } 1901 }
1902 slot->resume_offset = 0; 1902 slot->resume_offset = 0;
1903 slot->pCmd = dma_map_single(hostdata->dev, SCp->cmnd, 1903 slot->pCmd = dma_map_single(hostdata->dev, SCp->cmnd,
1904 sizeof(SCp->cmnd), DMA_TO_DEVICE); 1904 MAX_COMMAND_SIZE, DMA_TO_DEVICE);
1905 NCR_700_start_command(SCp); 1905 NCR_700_start_command(SCp);
1906 return 0; 1906 return 0;
1907} 1907}
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 99c57b0c1d54..81ccbd7f9e34 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -504,10 +504,9 @@ config SCSI_AIC7XXX_OLD
504source "drivers/scsi/aic7xxx/Kconfig.aic79xx" 504source "drivers/scsi/aic7xxx/Kconfig.aic79xx"
505source "drivers/scsi/aic94xx/Kconfig" 505source "drivers/scsi/aic94xx/Kconfig"
506 506
507# All the I2O code and drivers do not seem to be 64bit safe.
508config SCSI_DPT_I2O 507config SCSI_DPT_I2O
509 tristate "Adaptec I2O RAID support " 508 tristate "Adaptec I2O RAID support "
510 depends on !64BIT && SCSI && PCI && VIRT_TO_BUS 509 depends on SCSI && PCI && VIRT_TO_BUS
511 help 510 help
512 This driver supports all of Adaptec's I2O based RAID controllers as 511 This driver supports all of Adaptec's I2O based RAID controllers as
513 well as the DPT SmartRaid V cards. This is an Adaptec maintained 512 well as the DPT SmartRaid V cards. This is an Adaptec maintained
@@ -1680,6 +1679,7 @@ config MAC_SCSI
1680config SCSI_MAC_ESP 1679config SCSI_MAC_ESP
1681 tristate "Macintosh NCR53c9[46] SCSI" 1680 tristate "Macintosh NCR53c9[46] SCSI"
1682 depends on MAC && SCSI 1681 depends on MAC && SCSI
1682 select SCSI_SPI_ATTRS
1683 help 1683 help
1684 This is the NCR 53c9x SCSI controller found on most of the 68040 1684 This is the NCR 53c9x SCSI controller found on most of the 68040
1685 based Macintoshes. 1685 based Macintoshes.
diff --git a/drivers/scsi/a100u2w.c b/drivers/scsi/a100u2w.c
index 792b2e807bf3..ced3eebe252c 100644
--- a/drivers/scsi/a100u2w.c
+++ b/drivers/scsi/a100u2w.c
@@ -895,7 +895,7 @@ static void inia100_build_scb(struct orc_host * host, struct orc_scb * scb, stru
895 } else { 895 } else {
896 scb->tag_msg = 0; /* No tag support */ 896 scb->tag_msg = 0; /* No tag support */
897 } 897 }
898 memcpy(&scb->cdb[0], &cmd->cmnd, scb->cdb_len); 898 memcpy(scb->cdb, cmd->cmnd, scb->cdb_len);
899} 899}
900 900
901/** 901/**
diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c
index 460d4024c46c..aa4e77c25273 100644
--- a/drivers/scsi/aacraid/aachba.c
+++ b/drivers/scsi/aacraid/aachba.c
@@ -498,6 +498,11 @@ static void _aac_probe_container2(void * context, struct fib * fibptr)
498 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) && 498 (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
499 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) { 499 (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
500 fsa_dev_ptr->valid = 1; 500 fsa_dev_ptr->valid = 1;
501 /* sense_key holds the current state of the spin-up */
502 if (dresp->mnt[0].state & cpu_to_le32(FSCS_NOT_READY))
503 fsa_dev_ptr->sense_data.sense_key = NOT_READY;
504 else if (fsa_dev_ptr->sense_data.sense_key == NOT_READY)
505 fsa_dev_ptr->sense_data.sense_key = NO_SENSE;
501 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol); 506 fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
502 fsa_dev_ptr->size 507 fsa_dev_ptr->size
503 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) + 508 = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
@@ -1509,20 +1514,35 @@ static void io_callback(void *context, struct fib * fibptr)
1509 scsi_dma_unmap(scsicmd); 1514 scsi_dma_unmap(scsicmd);
1510 1515
1511 readreply = (struct aac_read_reply *)fib_data(fibptr); 1516 readreply = (struct aac_read_reply *)fib_data(fibptr);
1512 if (le32_to_cpu(readreply->status) == ST_OK) 1517 switch (le32_to_cpu(readreply->status)) {
1513 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 1518 case ST_OK:
1514 else { 1519 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1520 SAM_STAT_GOOD;
1521 dev->fsa_dev[cid].sense_data.sense_key = NO_SENSE;
1522 break;
1523 case ST_NOT_READY:
1524 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1525 SAM_STAT_CHECK_CONDITION;
1526 set_sense(&dev->fsa_dev[cid].sense_data, NOT_READY,
1527 SENCODE_BECOMING_READY, ASENCODE_BECOMING_READY, 0, 0);
1528 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1529 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1530 SCSI_SENSE_BUFFERSIZE));
1531 break;
1532 default:
1515#ifdef AAC_DETAILED_STATUS_INFO 1533#ifdef AAC_DETAILED_STATUS_INFO
1516 printk(KERN_WARNING "io_callback: io failed, status = %d\n", 1534 printk(KERN_WARNING "io_callback: io failed, status = %d\n",
1517 le32_to_cpu(readreply->status)); 1535 le32_to_cpu(readreply->status));
1518#endif 1536#endif
1519 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION; 1537 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1538 SAM_STAT_CHECK_CONDITION;
1520 set_sense(&dev->fsa_dev[cid].sense_data, 1539 set_sense(&dev->fsa_dev[cid].sense_data,
1521 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE, 1540 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
1522 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0); 1541 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
1523 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data, 1542 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1524 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data), 1543 min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
1525 SCSI_SENSE_BUFFERSIZE)); 1544 SCSI_SENSE_BUFFERSIZE));
1545 break;
1526 } 1546 }
1527 aac_fib_complete(fibptr); 1547 aac_fib_complete(fibptr);
1528 aac_fib_free(fibptr); 1548 aac_fib_free(fibptr);
@@ -1863,6 +1883,84 @@ static int aac_synchronize(struct scsi_cmnd *scsicmd)
1863 return SCSI_MLQUEUE_HOST_BUSY; 1883 return SCSI_MLQUEUE_HOST_BUSY;
1864} 1884}
1865 1885
1886static void aac_start_stop_callback(void *context, struct fib *fibptr)
1887{
1888 struct scsi_cmnd *scsicmd = context;
1889
1890 if (!aac_valid_context(scsicmd, fibptr))
1891 return;
1892
1893 BUG_ON(fibptr == NULL);
1894
1895 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
1896
1897 aac_fib_complete(fibptr);
1898 aac_fib_free(fibptr);
1899 scsicmd->scsi_done(scsicmd);
1900}
1901
1902static int aac_start_stop(struct scsi_cmnd *scsicmd)
1903{
1904 int status;
1905 struct fib *cmd_fibcontext;
1906 struct aac_power_management *pmcmd;
1907 struct scsi_device *sdev = scsicmd->device;
1908 struct aac_dev *aac = (struct aac_dev *)sdev->host->hostdata;
1909
1910 if (!(aac->supplement_adapter_info.SupportedOptions2 &
1911 AAC_OPTION_POWER_MANAGEMENT)) {
1912 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1913 SAM_STAT_GOOD;
1914 scsicmd->scsi_done(scsicmd);
1915 return 0;
1916 }
1917
1918 if (aac->in_reset)
1919 return SCSI_MLQUEUE_HOST_BUSY;
1920
1921 /*
1922 * Allocate and initialize a Fib
1923 */
1924 cmd_fibcontext = aac_fib_alloc(aac);
1925 if (!cmd_fibcontext)
1926 return SCSI_MLQUEUE_HOST_BUSY;
1927
1928 aac_fib_init(cmd_fibcontext);
1929
1930 pmcmd = fib_data(cmd_fibcontext);
1931 pmcmd->command = cpu_to_le32(VM_ContainerConfig);
1932 pmcmd->type = cpu_to_le32(CT_POWER_MANAGEMENT);
1933 /* Eject bit ignored, not relevant */
1934 pmcmd->sub = (scsicmd->cmnd[4] & 1) ?
1935 cpu_to_le32(CT_PM_START_UNIT) : cpu_to_le32(CT_PM_STOP_UNIT);
1936 pmcmd->cid = cpu_to_le32(sdev_id(sdev));
1937 pmcmd->parm = (scsicmd->cmnd[1] & 1) ?
1938 cpu_to_le32(CT_PM_UNIT_IMMEDIATE) : 0;
1939
1940 /*
1941 * Now send the Fib to the adapter
1942 */
1943 status = aac_fib_send(ContainerCommand,
1944 cmd_fibcontext,
1945 sizeof(struct aac_power_management),
1946 FsaNormal,
1947 0, 1,
1948 (fib_callback)aac_start_stop_callback,
1949 (void *)scsicmd);
1950
1951 /*
1952 * Check that the command queued to the controller
1953 */
1954 if (status == -EINPROGRESS) {
1955 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1956 return 0;
1957 }
1958
1959 aac_fib_complete(cmd_fibcontext);
1960 aac_fib_free(cmd_fibcontext);
1961 return SCSI_MLQUEUE_HOST_BUSY;
1962}
1963
1866/** 1964/**
1867 * aac_scsi_cmd() - Process SCSI command 1965 * aac_scsi_cmd() - Process SCSI command
1868 * @scsicmd: SCSI command block 1966 * @scsicmd: SCSI command block
@@ -1899,7 +1997,9 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1899 * If the target container doesn't exist, it may have 1997 * If the target container doesn't exist, it may have
1900 * been newly created 1998 * been newly created
1901 */ 1999 */
1902 if ((fsa_dev_ptr[cid].valid & 1) == 0) { 2000 if (((fsa_dev_ptr[cid].valid & 1) == 0) ||
2001 (fsa_dev_ptr[cid].sense_data.sense_key ==
2002 NOT_READY)) {
1903 switch (scsicmd->cmnd[0]) { 2003 switch (scsicmd->cmnd[0]) {
1904 case SERVICE_ACTION_IN: 2004 case SERVICE_ACTION_IN:
1905 if (!(dev->raw_io_interface) || 2005 if (!(dev->raw_io_interface) ||
@@ -2091,8 +2191,8 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2091 scsi_sg_copy_from_buffer(scsicmd, cp, sizeof(cp)); 2191 scsi_sg_copy_from_buffer(scsicmd, cp, sizeof(cp));
2092 /* Do not cache partition table for arrays */ 2192 /* Do not cache partition table for arrays */
2093 scsicmd->device->removable = 1; 2193 scsicmd->device->removable = 1;
2094 2194 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2095 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 2195 SAM_STAT_GOOD;
2096 scsicmd->scsi_done(scsicmd); 2196 scsicmd->scsi_done(scsicmd);
2097 2197
2098 return 0; 2198 return 0;
@@ -2187,15 +2287,32 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2187 * These commands are all No-Ops 2287 * These commands are all No-Ops
2188 */ 2288 */
2189 case TEST_UNIT_READY: 2289 case TEST_UNIT_READY:
2290 if (fsa_dev_ptr[cid].sense_data.sense_key == NOT_READY) {
2291 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
2292 SAM_STAT_CHECK_CONDITION;
2293 set_sense(&dev->fsa_dev[cid].sense_data,
2294 NOT_READY, SENCODE_BECOMING_READY,
2295 ASENCODE_BECOMING_READY, 0, 0);
2296 memcpy(scsicmd->sense_buffer,
2297 &dev->fsa_dev[cid].sense_data,
2298 min_t(size_t,
2299 sizeof(dev->fsa_dev[cid].sense_data),
2300 SCSI_SENSE_BUFFERSIZE));
2301 scsicmd->scsi_done(scsicmd);
2302 return 0;
2303 }
2304 /* FALLTHRU */
2190 case RESERVE: 2305 case RESERVE:
2191 case RELEASE: 2306 case RELEASE:
2192 case REZERO_UNIT: 2307 case REZERO_UNIT:
2193 case REASSIGN_BLOCKS: 2308 case REASSIGN_BLOCKS:
2194 case SEEK_10: 2309 case SEEK_10:
2195 case START_STOP:
2196 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD; 2310 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
2197 scsicmd->scsi_done(scsicmd); 2311 scsicmd->scsi_done(scsicmd);
2198 return 0; 2312 return 0;
2313
2314 case START_STOP:
2315 return aac_start_stop(scsicmd);
2199 } 2316 }
2200 2317
2201 switch (scsicmd->cmnd[0]) 2318 switch (scsicmd->cmnd[0])
diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
index 113ca9c8934c..73916adb8f80 100644
--- a/drivers/scsi/aacraid/aacraid.h
+++ b/drivers/scsi/aacraid/aacraid.h
@@ -12,7 +12,7 @@
12 *----------------------------------------------------------------------------*/ 12 *----------------------------------------------------------------------------*/
13 13
14#ifndef AAC_DRIVER_BUILD 14#ifndef AAC_DRIVER_BUILD
15# define AAC_DRIVER_BUILD 2455 15# define AAC_DRIVER_BUILD 2456
16# define AAC_DRIVER_BRANCH "-ms" 16# define AAC_DRIVER_BRANCH "-ms"
17#endif 17#endif
18#define MAXIMUM_NUM_CONTAINERS 32 18#define MAXIMUM_NUM_CONTAINERS 32
@@ -34,8 +34,8 @@
34#define CONTAINER_TO_ID(cont) (cont) 34#define CONTAINER_TO_ID(cont) (cont)
35#define CONTAINER_TO_LUN(cont) (0) 35#define CONTAINER_TO_LUN(cont) (0)
36 36
37#define aac_phys_to_logical(x) (x+1) 37#define aac_phys_to_logical(x) ((x)+1)
38#define aac_logical_to_phys(x) (x?x-1:0) 38#define aac_logical_to_phys(x) ((x)?(x)-1:0)
39 39
40/* #define AAC_DETAILED_STATUS_INFO */ 40/* #define AAC_DETAILED_STATUS_INFO */
41 41
@@ -424,6 +424,8 @@ struct aac_init
424 */ 424 */
425 __le32 InitFlags; /* flags for supported features */ 425 __le32 InitFlags; /* flags for supported features */
426#define INITFLAGS_NEW_COMM_SUPPORTED 0x00000001 426#define INITFLAGS_NEW_COMM_SUPPORTED 0x00000001
427#define INITFLAGS_DRIVER_USES_UTC_TIME 0x00000010
428#define INITFLAGS_DRIVER_SUPPORTS_PM 0x00000020
427 __le32 MaxIoCommands; /* max outstanding commands */ 429 __le32 MaxIoCommands; /* max outstanding commands */
428 __le32 MaxIoSize; /* largest I/O command */ 430 __le32 MaxIoSize; /* largest I/O command */
429 __le32 MaxFibSize; /* largest FIB to adapter */ 431 __le32 MaxFibSize; /* largest FIB to adapter */
@@ -867,8 +869,10 @@ struct aac_supplement_adapter_info
867}; 869};
868#define AAC_FEATURE_FALCON cpu_to_le32(0x00000010) 870#define AAC_FEATURE_FALCON cpu_to_le32(0x00000010)
869#define AAC_FEATURE_JBOD cpu_to_le32(0x08000000) 871#define AAC_FEATURE_JBOD cpu_to_le32(0x08000000)
870#define AAC_OPTION_MU_RESET cpu_to_le32(0x00000001) 872/* SupportedOptions2 */
871#define AAC_OPTION_IGNORE_RESET cpu_to_le32(0x00000002) 873#define AAC_OPTION_MU_RESET cpu_to_le32(0x00000001)
874#define AAC_OPTION_IGNORE_RESET cpu_to_le32(0x00000002)
875#define AAC_OPTION_POWER_MANAGEMENT cpu_to_le32(0x00000004)
872#define AAC_SIS_VERSION_V3 3 876#define AAC_SIS_VERSION_V3 3
873#define AAC_SIS_SLOT_UNKNOWN 0xFF 877#define AAC_SIS_SLOT_UNKNOWN 0xFF
874 878
@@ -1148,6 +1152,7 @@ struct aac_dev
1148#define ST_DQUOT 69 1152#define ST_DQUOT 69
1149#define ST_STALE 70 1153#define ST_STALE 70
1150#define ST_REMOTE 71 1154#define ST_REMOTE 71
1155#define ST_NOT_READY 72
1151#define ST_BADHANDLE 10001 1156#define ST_BADHANDLE 10001
1152#define ST_NOT_SYNC 10002 1157#define ST_NOT_SYNC 10002
1153#define ST_BAD_COOKIE 10003 1158#define ST_BAD_COOKIE 10003
@@ -1269,6 +1274,18 @@ struct aac_synchronize_reply {
1269 u8 data[16]; 1274 u8 data[16];
1270}; 1275};
1271 1276
1277#define CT_POWER_MANAGEMENT 245
1278#define CT_PM_START_UNIT 2
1279#define CT_PM_STOP_UNIT 3
1280#define CT_PM_UNIT_IMMEDIATE 1
1281struct aac_power_management {
1282 __le32 command; /* VM_ContainerConfig */
1283 __le32 type; /* CT_POWER_MANAGEMENT */
1284 __le32 sub; /* CT_PM_* */
1285 __le32 cid;
1286 __le32 parm; /* CT_PM_sub_* */
1287};
1288
1272#define CT_PAUSE_IO 65 1289#define CT_PAUSE_IO 65
1273#define CT_RELEASE_IO 66 1290#define CT_RELEASE_IO 66
1274struct aac_pause { 1291struct aac_pause {
@@ -1536,6 +1553,7 @@ struct aac_mntent {
1536#define FSCS_NOTCLEAN 0x0001 /* fsck is necessary before mounting */ 1553#define FSCS_NOTCLEAN 0x0001 /* fsck is necessary before mounting */
1537#define FSCS_READONLY 0x0002 /* possible result of broken mirror */ 1554#define FSCS_READONLY 0x0002 /* possible result of broken mirror */
1538#define FSCS_HIDDEN 0x0004 /* should be ignored - set during a clear */ 1555#define FSCS_HIDDEN 0x0004 /* should be ignored - set during a clear */
1556#define FSCS_NOT_READY 0x0008 /* Array spinning up to fulfil request */
1539 1557
1540struct aac_query_mount { 1558struct aac_query_mount {
1541 __le32 command; 1559 __le32 command;
diff --git a/drivers/scsi/aacraid/comminit.c b/drivers/scsi/aacraid/comminit.c
index 294a802450be..cbac06355107 100644
--- a/drivers/scsi/aacraid/comminit.c
+++ b/drivers/scsi/aacraid/comminit.c
@@ -97,6 +97,8 @@ static int aac_alloc_comm(struct aac_dev *dev, void **commaddr, unsigned long co
97 init->InitFlags = cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED); 97 init->InitFlags = cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED);
98 dprintk((KERN_WARNING"aacraid: New Comm Interface enabled\n")); 98 dprintk((KERN_WARNING"aacraid: New Comm Interface enabled\n"));
99 } 99 }
100 init->InitFlags |= cpu_to_le32(INITFLAGS_DRIVER_USES_UTC_TIME |
101 INITFLAGS_DRIVER_SUPPORTS_PM);
100 init->MaxIoCommands = cpu_to_le32(dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB); 102 init->MaxIoCommands = cpu_to_le32(dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB);
101 init->MaxIoSize = cpu_to_le32(dev->scsi_host_ptr->max_sectors << 9); 103 init->MaxIoSize = cpu_to_le32(dev->scsi_host_ptr->max_sectors << 9);
102 init->MaxFibSize = cpu_to_le32(dev->max_fib_size); 104 init->MaxFibSize = cpu_to_le32(dev->max_fib_size);
diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c
index ef67816a6fe5..289304aab690 100644
--- a/drivers/scsi/aacraid/commsup.c
+++ b/drivers/scsi/aacraid/commsup.c
@@ -515,7 +515,7 @@ int aac_fib_send(u16 command, struct fib *fibptr, unsigned long size,
515 } 515 }
516 udelay(5); 516 udelay(5);
517 } 517 }
518 } else if (down_interruptible(&fibptr->event_wait) == 0) { 518 } else if (down_interruptible(&fibptr->event_wait)) {
519 fibptr->done = 2; 519 fibptr->done = 2;
520 up(&fibptr->event_wait); 520 up(&fibptr->event_wait);
521 } 521 }
@@ -906,15 +906,22 @@ static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr)
906 case AifEnAddJBOD: 906 case AifEnAddJBOD:
907 case AifEnDeleteJBOD: 907 case AifEnDeleteJBOD:
908 container = le32_to_cpu(((__le32 *)aifcmd->data)[1]); 908 container = le32_to_cpu(((__le32 *)aifcmd->data)[1]);
909 if ((container >> 28)) 909 if ((container >> 28)) {
910 container = (u32)-1;
910 break; 911 break;
912 }
911 channel = (container >> 24) & 0xF; 913 channel = (container >> 24) & 0xF;
912 if (channel >= dev->maximum_num_channels) 914 if (channel >= dev->maximum_num_channels) {
915 container = (u32)-1;
913 break; 916 break;
917 }
914 id = container & 0xFFFF; 918 id = container & 0xFFFF;
915 if (id >= dev->maximum_num_physicals) 919 if (id >= dev->maximum_num_physicals) {
920 container = (u32)-1;
916 break; 921 break;
922 }
917 lun = (container >> 16) & 0xFF; 923 lun = (container >> 16) & 0xFF;
924 container = (u32)-1;
918 channel = aac_phys_to_logical(channel); 925 channel = aac_phys_to_logical(channel);
919 device_config_needed = 926 device_config_needed =
920 (((__le32 *)aifcmd->data)[0] == 927 (((__le32 *)aifcmd->data)[0] ==
@@ -933,13 +940,18 @@ static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr)
933 case EM_DRIVE_REMOVAL: 940 case EM_DRIVE_REMOVAL:
934 container = le32_to_cpu( 941 container = le32_to_cpu(
935 ((__le32 *)aifcmd->data)[2]); 942 ((__le32 *)aifcmd->data)[2]);
936 if ((container >> 28)) 943 if ((container >> 28)) {
944 container = (u32)-1;
937 break; 945 break;
946 }
938 channel = (container >> 24) & 0xF; 947 channel = (container >> 24) & 0xF;
939 if (channel >= dev->maximum_num_channels) 948 if (channel >= dev->maximum_num_channels) {
949 container = (u32)-1;
940 break; 950 break;
951 }
941 id = container & 0xFFFF; 952 id = container & 0xFFFF;
942 lun = (container >> 16) & 0xFF; 953 lun = (container >> 16) & 0xFF;
954 container = (u32)-1;
943 if (id >= dev->maximum_num_physicals) { 955 if (id >= dev->maximum_num_physicals) {
944 /* legacy dev_t ? */ 956 /* legacy dev_t ? */
945 if ((0x2000 <= id) || lun || channel || 957 if ((0x2000 <= id) || lun || channel ||
@@ -1025,9 +1037,10 @@ static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr)
1025 break; 1037 break;
1026 } 1038 }
1027 1039
1040 container = 0;
1041retry_next:
1028 if (device_config_needed == NOTHING) 1042 if (device_config_needed == NOTHING)
1029 for (container = 0; container < dev->maximum_num_containers; 1043 for (; container < dev->maximum_num_containers; ++container) {
1030 ++container) {
1031 if ((dev->fsa_dev[container].config_waiting_on == 0) && 1044 if ((dev->fsa_dev[container].config_waiting_on == 0) &&
1032 (dev->fsa_dev[container].config_needed != NOTHING) && 1045 (dev->fsa_dev[container].config_needed != NOTHING) &&
1033 time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT)) { 1046 time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT)) {
@@ -1110,6 +1123,11 @@ static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr)
1110 } 1123 }
1111 if (device_config_needed == ADD) 1124 if (device_config_needed == ADD)
1112 scsi_add_device(dev->scsi_host_ptr, channel, id, lun); 1125 scsi_add_device(dev->scsi_host_ptr, channel, id, lun);
1126 if (channel == CONTAINER_CHANNEL) {
1127 container++;
1128 device_config_needed = NOTHING;
1129 goto retry_next;
1130 }
1113} 1131}
1114 1132
1115static int _aac_reset_adapter(struct aac_dev *aac, int forced) 1133static int _aac_reset_adapter(struct aac_dev *aac, int forced)
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index c109f63f8279..1f7c83607f84 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -401,6 +401,8 @@ static int aac_biosparm(struct scsi_device *sdev, struct block_device *bdev,
401static int aac_slave_configure(struct scsi_device *sdev) 401static int aac_slave_configure(struct scsi_device *sdev)
402{ 402{
403 struct aac_dev *aac = (struct aac_dev *)sdev->host->hostdata; 403 struct aac_dev *aac = (struct aac_dev *)sdev->host->hostdata;
404 if (aac->jbod && (sdev->type == TYPE_DISK))
405 sdev->removable = 1;
404 if ((sdev->type == TYPE_DISK) && 406 if ((sdev->type == TYPE_DISK) &&
405 (sdev_channel(sdev) != CONTAINER_CHANNEL) && 407 (sdev_channel(sdev) != CONTAINER_CHANNEL) &&
406 (!aac->jbod || sdev->inq_periph_qual) && 408 (!aac->jbod || sdev->inq_periph_qual) &&
@@ -809,6 +811,12 @@ static ssize_t aac_show_flags(struct device *cdev,
809 "SAI_READ_CAPACITY_16\n"); 811 "SAI_READ_CAPACITY_16\n");
810 if (dev->jbod) 812 if (dev->jbod)
811 len += snprintf(buf + len, PAGE_SIZE - len, "SUPPORTED_JBOD\n"); 813 len += snprintf(buf + len, PAGE_SIZE - len, "SUPPORTED_JBOD\n");
814 if (dev->supplement_adapter_info.SupportedOptions2 &
815 AAC_OPTION_POWER_MANAGEMENT)
816 len += snprintf(buf + len, PAGE_SIZE - len,
817 "SUPPORTED_POWER_MANAGEMENT\n");
818 if (dev->msi)
819 len += snprintf(buf + len, PAGE_SIZE - len, "PCI_HAS_MSI\n");
812 return len; 820 return len;
813} 821}
814 822
@@ -1106,7 +1114,7 @@ static int __devinit aac_probe_one(struct pci_dev *pdev,
1106 aac->pdev = pdev; 1114 aac->pdev = pdev;
1107 aac->name = aac_driver_template.name; 1115 aac->name = aac_driver_template.name;
1108 aac->id = shost->unique_id; 1116 aac->id = shost->unique_id;
1109 aac->cardtype = index; 1117 aac->cardtype = index;
1110 INIT_LIST_HEAD(&aac->entry); 1118 INIT_LIST_HEAD(&aac->entry);
1111 1119
1112 aac->fibs = kmalloc(sizeof(struct fib) * (shost->can_queue + AAC_NUM_MGT_FIB), GFP_KERNEL); 1120 aac->fibs = kmalloc(sizeof(struct fib) * (shost->can_queue + AAC_NUM_MGT_FIB), GFP_KERNEL);
@@ -1146,19 +1154,19 @@ static int __devinit aac_probe_one(struct pci_dev *pdev,
1146 goto out_deinit; 1154 goto out_deinit;
1147 1155
1148 /* 1156 /*
1149 * Lets override negotiations and drop the maximum SG limit to 34 1157 * Lets override negotiations and drop the maximum SG limit to 34
1150 */ 1158 */
1151 if ((aac_drivers[index].quirks & AAC_QUIRK_34SG) && 1159 if ((aac_drivers[index].quirks & AAC_QUIRK_34SG) &&
1152 (shost->sg_tablesize > 34)) { 1160 (shost->sg_tablesize > 34)) {
1153 shost->sg_tablesize = 34; 1161 shost->sg_tablesize = 34;
1154 shost->max_sectors = (shost->sg_tablesize * 8) + 112; 1162 shost->max_sectors = (shost->sg_tablesize * 8) + 112;
1155 } 1163 }
1156 1164
1157 if ((aac_drivers[index].quirks & AAC_QUIRK_17SG) && 1165 if ((aac_drivers[index].quirks & AAC_QUIRK_17SG) &&
1158 (shost->sg_tablesize > 17)) { 1166 (shost->sg_tablesize > 17)) {
1159 shost->sg_tablesize = 17; 1167 shost->sg_tablesize = 17;
1160 shost->max_sectors = (shost->sg_tablesize * 8) + 112; 1168 shost->max_sectors = (shost->sg_tablesize * 8) + 112;
1161 } 1169 }
1162 1170
1163 error = pci_set_dma_max_seg_size(pdev, 1171 error = pci_set_dma_max_seg_size(pdev,
1164 (aac->adapter_info.options & AAC_OPT_NEW_COMM) ? 1172 (aac->adapter_info.options & AAC_OPT_NEW_COMM) ?
@@ -1174,7 +1182,7 @@ static int __devinit aac_probe_one(struct pci_dev *pdev,
1174 else 1182 else
1175 aac->printf_enabled = 0; 1183 aac->printf_enabled = 0;
1176 1184
1177 /* 1185 /*
1178 * max channel will be the physical channels plus 1 virtual channel 1186 * max channel will be the physical channels plus 1 virtual channel
1179 * all containers are on the virtual channel 0 (CONTAINER_CHANNEL) 1187 * all containers are on the virtual channel 0 (CONTAINER_CHANNEL)
1180 * physical channels are address by their actual physical number+1 1188 * physical channels are address by their actual physical number+1
diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
index 90f5e0a6f2e3..2a730c470f62 100644
--- a/drivers/scsi/aic94xx/aic94xx_init.c
+++ b/drivers/scsi/aic94xx/aic94xx_init.c
@@ -529,10 +529,10 @@ static void asd_remove_dev_attrs(struct asd_ha_struct *asd_ha)
529/* The first entry, 0, is used for dynamic ids, the rest for devices 529/* The first entry, 0, is used for dynamic ids, the rest for devices
530 * we know about. 530 * we know about.
531 */ 531 */
532static struct asd_pcidev_struct { 532static const struct asd_pcidev_struct {
533 const char * name; 533 const char * name;
534 int (*setup)(struct asd_ha_struct *asd_ha); 534 int (*setup)(struct asd_ha_struct *asd_ha);
535} asd_pcidev_data[] = { 535} asd_pcidev_data[] __devinitconst = {
536 /* Id 0 is used for dynamic ids. */ 536 /* Id 0 is used for dynamic ids. */
537 { .name = "Adaptec AIC-94xx SAS/SATA Host Adapter", 537 { .name = "Adaptec AIC-94xx SAS/SATA Host Adapter",
538 .setup = asd_aic9410_setup 538 .setup = asd_aic9410_setup
@@ -735,7 +735,7 @@ static int asd_unregister_sas_ha(struct asd_ha_struct *asd_ha)
735static int __devinit asd_pci_probe(struct pci_dev *dev, 735static int __devinit asd_pci_probe(struct pci_dev *dev,
736 const struct pci_device_id *id) 736 const struct pci_device_id *id)
737{ 737{
738 struct asd_pcidev_struct *asd_dev; 738 const struct asd_pcidev_struct *asd_dev;
739 unsigned asd_id = (unsigned) id->driver_data; 739 unsigned asd_id = (unsigned) id->driver_data;
740 struct asd_ha_struct *asd_ha; 740 struct asd_ha_struct *asd_ha;
741 struct Scsi_Host *shost; 741 struct Scsi_Host *shost;
diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c
index 403a7f2d8f9b..9785d7384199 100644
--- a/drivers/scsi/constants.c
+++ b/drivers/scsi/constants.c
@@ -28,7 +28,6 @@
28#define SERVICE_ACTION_OUT_12 0xa9 28#define SERVICE_ACTION_OUT_12 0xa9
29#define SERVICE_ACTION_IN_16 0x9e 29#define SERVICE_ACTION_IN_16 0x9e
30#define SERVICE_ACTION_OUT_16 0x9f 30#define SERVICE_ACTION_OUT_16 0x9f
31#define VARIABLE_LENGTH_CMD 0x7f
32 31
33 32
34 33
@@ -210,7 +209,7 @@ static void print_opcode_name(unsigned char * cdbp, int cdb_len)
210 cdb0 = cdbp[0]; 209 cdb0 = cdbp[0];
211 switch(cdb0) { 210 switch(cdb0) {
212 case VARIABLE_LENGTH_CMD: 211 case VARIABLE_LENGTH_CMD:
213 len = cdbp[7] + 8; 212 len = scsi_varlen_cdb_length(cdbp);
214 if (len < 10) { 213 if (len < 10) {
215 printk("short variable length command, " 214 printk("short variable length command, "
216 "len=%d ext_len=%d", len, cdb_len); 215 "len=%d ext_len=%d", len, cdb_len);
@@ -300,7 +299,7 @@ static void print_opcode_name(unsigned char * cdbp, int cdb_len)
300 cdb0 = cdbp[0]; 299 cdb0 = cdbp[0];
301 switch(cdb0) { 300 switch(cdb0) {
302 case VARIABLE_LENGTH_CMD: 301 case VARIABLE_LENGTH_CMD:
303 len = cdbp[7] + 8; 302 len = scsi_varlen_cdb_length(cdbp);
304 if (len < 10) { 303 if (len < 10) {
305 printk("short opcode=0x%x command, len=%d " 304 printk("short opcode=0x%x command, len=%d "
306 "ext_len=%d", cdb0, len, cdb_len); 305 "ext_len=%d", cdb0, len, cdb_len);
@@ -335,10 +334,7 @@ void __scsi_print_command(unsigned char *cdb)
335 int k, len; 334 int k, len;
336 335
337 print_opcode_name(cdb, 0); 336 print_opcode_name(cdb, 0);
338 if (VARIABLE_LENGTH_CMD == cdb[0]) 337 len = scsi_command_size(cdb);
339 len = cdb[7] + 8;
340 else
341 len = COMMAND_SIZE(cdb[0]);
342 /* print out all bytes in cdb */ 338 /* print out all bytes in cdb */
343 for (k = 0; k < len; ++k) 339 for (k = 0; k < len; ++k)
344 printk(" %02x", cdb[k]); 340 printk(" %02x", cdb[k]);
diff --git a/drivers/scsi/dpt/dpti_ioctl.h b/drivers/scsi/dpt/dpti_ioctl.h
index cc784e8f6e9d..f60236721e0d 100644
--- a/drivers/scsi/dpt/dpti_ioctl.h
+++ b/drivers/scsi/dpt/dpti_ioctl.h
@@ -89,7 +89,7 @@ typedef struct {
89 int njobs; /* # of jobs sent to HA */ 89 int njobs; /* # of jobs sent to HA */
90 int qdepth; /* Controller queue depth. */ 90 int qdepth; /* Controller queue depth. */
91 int wakebase; /* mpx wakeup base index. */ 91 int wakebase; /* mpx wakeup base index. */
92 uLONG SGsize; /* Scatter/Gather list size. */ 92 uINT SGsize; /* Scatter/Gather list size. */
93 unsigned heads; /* heads for drives on cntlr. */ 93 unsigned heads; /* heads for drives on cntlr. */
94 unsigned sectors; /* sectors for drives on cntlr. */ 94 unsigned sectors; /* sectors for drives on cntlr. */
95 uCHAR do_drive32; /* Flag for Above 16 MB Ability */ 95 uCHAR do_drive32; /* Flag for Above 16 MB Ability */
@@ -97,8 +97,8 @@ typedef struct {
97 char idPAL[4]; /* 4 Bytes Of The ID Pal */ 97 char idPAL[4]; /* 4 Bytes Of The ID Pal */
98 uCHAR primary; /* 1 For Primary, 0 For Secondary */ 98 uCHAR primary; /* 1 For Primary, 0 For Secondary */
99 uCHAR eataVersion; /* EATA Version */ 99 uCHAR eataVersion; /* EATA Version */
100 uLONG cpLength; /* EATA Command Packet Length */ 100 uINT cpLength; /* EATA Command Packet Length */
101 uLONG spLength; /* EATA Status Packet Length */ 101 uINT spLength; /* EATA Status Packet Length */
102 uCHAR drqNum; /* DRQ Index (0,5,6,7) */ 102 uCHAR drqNum; /* DRQ Index (0,5,6,7) */
103 uCHAR flag1; /* EATA Flags 1 (Byte 9) */ 103 uCHAR flag1; /* EATA Flags 1 (Byte 9) */
104 uCHAR flag2; /* EATA Flags 2 (Byte 30) */ 104 uCHAR flag2; /* EATA Flags 2 (Byte 30) */
@@ -107,23 +107,23 @@ typedef struct {
107typedef struct { 107typedef struct {
108 uSHORT length; // Remaining length of this 108 uSHORT length; // Remaining length of this
109 uSHORT drvrHBAnum; // Relative HBA # used by the driver 109 uSHORT drvrHBAnum; // Relative HBA # used by the driver
110 uLONG baseAddr; // Base I/O address 110 uINT baseAddr; // Base I/O address
111 uSHORT blinkState; // Blink LED state (0=Not in blink LED) 111 uSHORT blinkState; // Blink LED state (0=Not in blink LED)
112 uCHAR pciBusNum; // PCI Bus # (Optional) 112 uCHAR pciBusNum; // PCI Bus # (Optional)
113 uCHAR pciDeviceNum; // PCI Device # (Optional) 113 uCHAR pciDeviceNum; // PCI Device # (Optional)
114 uSHORT hbaFlags; // Miscellaneous HBA flags 114 uSHORT hbaFlags; // Miscellaneous HBA flags
115 uSHORT Interrupt; // Interrupt set for this device. 115 uSHORT Interrupt; // Interrupt set for this device.
116# if (defined(_DPT_ARC)) 116# if (defined(_DPT_ARC))
117 uLONG baseLength; 117 uINT baseLength;
118 ADAPTER_OBJECT *AdapterObject; 118 ADAPTER_OBJECT *AdapterObject;
119 LARGE_INTEGER DmaLogicalAddress; 119 LARGE_INTEGER DmaLogicalAddress;
120 PVOID DmaVirtualAddress; 120 PVOID DmaVirtualAddress;
121 LARGE_INTEGER ReplyLogicalAddress; 121 LARGE_INTEGER ReplyLogicalAddress;
122 PVOID ReplyVirtualAddress; 122 PVOID ReplyVirtualAddress;
123# else 123# else
124 uLONG reserved1; // Reserved for future expansion 124 uINT reserved1; // Reserved for future expansion
125 uLONG reserved2; // Reserved for future expansion 125 uINT reserved2; // Reserved for future expansion
126 uLONG reserved3; // Reserved for future expansion 126 uINT reserved3; // Reserved for future expansion
127# endif 127# endif
128} drvrHBAinfo_S; 128} drvrHBAinfo_S;
129 129
diff --git a/drivers/scsi/dpt/dptsig.h b/drivers/scsi/dpt/dptsig.h
index 94bc894d1200..72c8992fdf21 100644
--- a/drivers/scsi/dpt/dptsig.h
+++ b/drivers/scsi/dpt/dptsig.h
@@ -33,11 +33,7 @@
33/* to make sure we are talking the same size under all OS's */ 33/* to make sure we are talking the same size under all OS's */
34typedef unsigned char sigBYTE; 34typedef unsigned char sigBYTE;
35typedef unsigned short sigWORD; 35typedef unsigned short sigWORD;
36#if (defined(_MULTI_DATAMODEL) && defined(sun) && !defined(_ILP32)) 36typedef unsigned int sigINT;
37typedef uint32_t sigLONG;
38#else
39typedef unsigned long sigLONG;
40#endif
41 37
42/* 38/*
43 * use sigWORDLittleEndian for: 39 * use sigWORDLittleEndian for:
@@ -300,7 +296,7 @@ typedef struct dpt_sig {
300 sigBYTE dsFiletype; /* type of file */ 296 sigBYTE dsFiletype; /* type of file */
301 sigBYTE dsFiletypeFlags; /* flags to specify load type, etc. */ 297 sigBYTE dsFiletypeFlags; /* flags to specify load type, etc. */
302 sigBYTE dsOEM; /* OEM file was created for */ 298 sigBYTE dsOEM; /* OEM file was created for */
303 sigLONG dsOS; /* which Operating systems */ 299 sigINT dsOS; /* which Operating systems */
304 sigWORD dsCapabilities; /* RAID levels, etc. */ 300 sigWORD dsCapabilities; /* RAID levels, etc. */
305 sigWORD dsDeviceSupp; /* Types of SCSI devices supported */ 301 sigWORD dsDeviceSupp; /* Types of SCSI devices supported */
306 sigWORD dsAdapterSupp; /* DPT adapter families supported */ 302 sigWORD dsAdapterSupp; /* DPT adapter families supported */
diff --git a/drivers/scsi/dpt/sys_info.h b/drivers/scsi/dpt/sys_info.h
index d23b70c8c768..a90c4cb8ea8b 100644
--- a/drivers/scsi/dpt/sys_info.h
+++ b/drivers/scsi/dpt/sys_info.h
@@ -145,8 +145,8 @@
145 uCHAR smartROMRevision; 145 uCHAR smartROMRevision;
146 uSHORT flags; /* See bit definitions above */ 146 uSHORT flags; /* See bit definitions above */
147 uSHORT conventionalMemSize; /* in KB */ 147 uSHORT conventionalMemSize; /* in KB */
148 uLONG extendedMemSize; /* in KB */ 148 uINT extendedMemSize; /* in KB */
149 uLONG osType; /* Same as DPTSIG's definition */ 149 uINT osType; /* Same as DPTSIG's definition */
150 uCHAR osMajorVersion; 150 uCHAR osMajorVersion;
151 uCHAR osMinorVersion; /* The OS version */ 151 uCHAR osMinorVersion; /* The OS version */
152 uCHAR osRevision; 152 uCHAR osRevision;
diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
index ac92ac143b46..0fb5bf4c43ac 100644
--- a/drivers/scsi/dpt_i2o.c
+++ b/drivers/scsi/dpt_i2o.c
@@ -29,11 +29,6 @@
29/*#define DEBUG 1 */ 29/*#define DEBUG 1 */
30/*#define UARTDELAY 1 */ 30/*#define UARTDELAY 1 */
31 31
32/* On the real kernel ADDR32 should always be zero for 2.4. GFP_HIGH allocates
33 high pages. Keep the macro around because of the broken unmerged ia64 tree */
34
35#define ADDR32 (0)
36
37#include <linux/module.h> 32#include <linux/module.h>
38 33
39MODULE_AUTHOR("Deanna Bonds, with _lots_ of help from Mark Salyzyn"); 34MODULE_AUTHOR("Deanna Bonds, with _lots_ of help from Mark Salyzyn");
@@ -108,27 +103,28 @@ static dpt_sig_S DPTI_sig = {
108 103
109static DEFINE_MUTEX(adpt_configuration_lock); 104static DEFINE_MUTEX(adpt_configuration_lock);
110 105
111static struct i2o_sys_tbl *sys_tbl = NULL; 106static struct i2o_sys_tbl *sys_tbl;
112static int sys_tbl_ind = 0; 107static dma_addr_t sys_tbl_pa;
113static int sys_tbl_len = 0; 108static int sys_tbl_ind;
109static int sys_tbl_len;
114 110
115static adpt_hba* hba_chain = NULL; 111static adpt_hba* hba_chain = NULL;
116static int hba_count = 0; 112static int hba_count = 0;
117 113
114static struct class *adpt_sysfs_class;
115
116#ifdef CONFIG_COMPAT
117static long compat_adpt_ioctl(struct file *, unsigned int, unsigned long);
118#endif
119
118static const struct file_operations adpt_fops = { 120static const struct file_operations adpt_fops = {
119 .ioctl = adpt_ioctl, 121 .ioctl = adpt_ioctl,
120 .open = adpt_open, 122 .open = adpt_open,
121 .release = adpt_close 123 .release = adpt_close,
122}; 124#ifdef CONFIG_COMPAT
123 125 .compat_ioctl = compat_adpt_ioctl,
124#ifdef REBOOT_NOTIFIER
125static struct notifier_block adpt_reboot_notifier =
126{
127 adpt_reboot_event,
128 NULL,
129 0
130};
131#endif 126#endif
127};
132 128
133/* Structures and definitions for synchronous message posting. 129/* Structures and definitions for synchronous message posting.
134 * See adpt_i2o_post_wait() for description 130 * See adpt_i2o_post_wait() for description
@@ -151,6 +147,21 @@ static DEFINE_SPINLOCK(adpt_post_wait_lock);
151 *============================================================================ 147 *============================================================================
152 */ 148 */
153 149
150static inline int dpt_dma64(adpt_hba *pHba)
151{
152 return (sizeof(dma_addr_t) > 4 && (pHba)->dma64);
153}
154
155static inline u32 dma_high(dma_addr_t addr)
156{
157 return upper_32_bits(addr);
158}
159
160static inline u32 dma_low(dma_addr_t addr)
161{
162 return (u32)addr;
163}
164
154static u8 adpt_read_blink_led(adpt_hba* host) 165static u8 adpt_read_blink_led(adpt_hba* host)
155{ 166{
156 if (host->FwDebugBLEDflag_P) { 167 if (host->FwDebugBLEDflag_P) {
@@ -178,8 +189,6 @@ static int adpt_detect(struct scsi_host_template* sht)
178 struct pci_dev *pDev = NULL; 189 struct pci_dev *pDev = NULL;
179 adpt_hba* pHba; 190 adpt_hba* pHba;
180 191
181 adpt_init();
182
183 PINFO("Detecting Adaptec I2O RAID controllers...\n"); 192 PINFO("Detecting Adaptec I2O RAID controllers...\n");
184 193
185 /* search for all Adatpec I2O RAID cards */ 194 /* search for all Adatpec I2O RAID cards */
@@ -247,13 +256,29 @@ rebuild_sys_tab:
247 adpt_inquiry(pHba); 256 adpt_inquiry(pHba);
248 } 257 }
249 258
259 adpt_sysfs_class = class_create(THIS_MODULE, "dpt_i2o");
260 if (IS_ERR(adpt_sysfs_class)) {
261 printk(KERN_WARNING"dpti: unable to create dpt_i2o class\n");
262 adpt_sysfs_class = NULL;
263 }
264
250 for (pHba = hba_chain; pHba; pHba = pHba->next) { 265 for (pHba = hba_chain; pHba; pHba = pHba->next) {
251 if( adpt_scsi_register(pHba,sht) < 0){ 266 if (adpt_scsi_host_alloc(pHba, sht) < 0){
252 adpt_i2o_delete_hba(pHba); 267 adpt_i2o_delete_hba(pHba);
253 continue; 268 continue;
254 } 269 }
255 pHba->initialized = TRUE; 270 pHba->initialized = TRUE;
256 pHba->state &= ~DPTI_STATE_RESET; 271 pHba->state &= ~DPTI_STATE_RESET;
272 if (adpt_sysfs_class) {
273 struct device *dev = device_create(adpt_sysfs_class,
274 NULL, MKDEV(DPTI_I2O_MAJOR, pHba->unit),
275 "dpti%d", pHba->unit);
276 if (IS_ERR(dev)) {
277 printk(KERN_WARNING"dpti%d: unable to "
278 "create device in dpt_i2o class\n",
279 pHba->unit);
280 }
281 }
257 } 282 }
258 283
259 // Register our control device node 284 // Register our control device node
@@ -282,7 +307,7 @@ static int adpt_release(struct Scsi_Host *host)
282 307
283static void adpt_inquiry(adpt_hba* pHba) 308static void adpt_inquiry(adpt_hba* pHba)
284{ 309{
285 u32 msg[14]; 310 u32 msg[17];
286 u32 *mptr; 311 u32 *mptr;
287 u32 *lenptr; 312 u32 *lenptr;
288 int direction; 313 int direction;
@@ -290,11 +315,12 @@ static void adpt_inquiry(adpt_hba* pHba)
290 u32 len; 315 u32 len;
291 u32 reqlen; 316 u32 reqlen;
292 u8* buf; 317 u8* buf;
318 dma_addr_t addr;
293 u8 scb[16]; 319 u8 scb[16];
294 s32 rcode; 320 s32 rcode;
295 321
296 memset(msg, 0, sizeof(msg)); 322 memset(msg, 0, sizeof(msg));
297 buf = kmalloc(80,GFP_KERNEL|ADDR32); 323 buf = dma_alloc_coherent(&pHba->pDev->dev, 80, &addr, GFP_KERNEL);
298 if(!buf){ 324 if(!buf){
299 printk(KERN_ERR"%s: Could not allocate buffer\n",pHba->name); 325 printk(KERN_ERR"%s: Could not allocate buffer\n",pHba->name);
300 return; 326 return;
@@ -305,7 +331,10 @@ static void adpt_inquiry(adpt_hba* pHba)
305 direction = 0x00000000; 331 direction = 0x00000000;
306 scsidir =0x40000000; // DATA IN (iop<--dev) 332 scsidir =0x40000000; // DATA IN (iop<--dev)
307 333
308 reqlen = 14; // SINGLE SGE 334 if (dpt_dma64(pHba))
335 reqlen = 17; // SINGLE SGE, 64 bit
336 else
337 reqlen = 14; // SINGLE SGE, 32 bit
309 /* Stick the headers on */ 338 /* Stick the headers on */
310 msg[0] = reqlen<<16 | SGL_OFFSET_12; 339 msg[0] = reqlen<<16 | SGL_OFFSET_12;
311 msg[1] = (0xff<<24|HOST_TID<<12|ADAPTER_TID); 340 msg[1] = (0xff<<24|HOST_TID<<12|ADAPTER_TID);
@@ -338,8 +367,16 @@ static void adpt_inquiry(adpt_hba* pHba)
338 367
339 /* Now fill in the SGList and command */ 368 /* Now fill in the SGList and command */
340 *lenptr = len; 369 *lenptr = len;
341 *mptr++ = 0xD0000000|direction|len; 370 if (dpt_dma64(pHba)) {
342 *mptr++ = virt_to_bus(buf); 371 *mptr++ = (0x7C<<24)+(2<<16)+0x02; /* Enable 64 bit */
372 *mptr++ = 1 << PAGE_SHIFT;
373 *mptr++ = 0xD0000000|direction|len;
374 *mptr++ = dma_low(addr);
375 *mptr++ = dma_high(addr);
376 } else {
377 *mptr++ = 0xD0000000|direction|len;
378 *mptr++ = addr;
379 }
343 380
344 // Send it on it's way 381 // Send it on it's way
345 rcode = adpt_i2o_post_wait(pHba, msg, reqlen<<2, 120); 382 rcode = adpt_i2o_post_wait(pHba, msg, reqlen<<2, 120);
@@ -347,7 +384,7 @@ static void adpt_inquiry(adpt_hba* pHba)
347 sprintf(pHba->detail, "Adaptec I2O RAID"); 384 sprintf(pHba->detail, "Adaptec I2O RAID");
348 printk(KERN_INFO "%s: Inquiry Error (%d)\n",pHba->name,rcode); 385 printk(KERN_INFO "%s: Inquiry Error (%d)\n",pHba->name,rcode);
349 if (rcode != -ETIME && rcode != -EINTR) 386 if (rcode != -ETIME && rcode != -EINTR)
350 kfree(buf); 387 dma_free_coherent(&pHba->pDev->dev, 80, buf, addr);
351 } else { 388 } else {
352 memset(pHba->detail, 0, sizeof(pHba->detail)); 389 memset(pHba->detail, 0, sizeof(pHba->detail));
353 memcpy(&(pHba->detail), "Vendor: Adaptec ", 16); 390 memcpy(&(pHba->detail), "Vendor: Adaptec ", 16);
@@ -356,7 +393,7 @@ static void adpt_inquiry(adpt_hba* pHba)
356 memcpy(&(pHba->detail[40]), " FW: ", 4); 393 memcpy(&(pHba->detail[40]), " FW: ", 4);
357 memcpy(&(pHba->detail[44]), (u8*) &buf[32], 4); 394 memcpy(&(pHba->detail[44]), (u8*) &buf[32], 4);
358 pHba->detail[48] = '\0'; /* precautionary */ 395 pHba->detail[48] = '\0'; /* precautionary */
359 kfree(buf); 396 dma_free_coherent(&pHba->pDev->dev, 80, buf, addr);
360 } 397 }
361 adpt_i2o_status_get(pHba); 398 adpt_i2o_status_get(pHba);
362 return ; 399 return ;
@@ -632,6 +669,91 @@ stop_output:
632 return len; 669 return len;
633} 670}
634 671
672/*
673 * Turn a struct scsi_cmnd * into a unique 32 bit 'context'.
674 */
675static u32 adpt_cmd_to_context(struct scsi_cmnd *cmd)
676{
677 return (u32)cmd->serial_number;
678}
679
680/*
681 * Go from a u32 'context' to a struct scsi_cmnd * .
682 * This could probably be made more efficient.
683 */
684static struct scsi_cmnd *
685 adpt_cmd_from_context(adpt_hba * pHba, u32 context)
686{
687 struct scsi_cmnd * cmd;
688 struct scsi_device * d;
689
690 if (context == 0)
691 return NULL;
692
693 spin_unlock(pHba->host->host_lock);
694 shost_for_each_device(d, pHba->host) {
695 unsigned long flags;
696 spin_lock_irqsave(&d->list_lock, flags);
697 list_for_each_entry(cmd, &d->cmd_list, list) {
698 if (((u32)cmd->serial_number == context)) {
699 spin_unlock_irqrestore(&d->list_lock, flags);
700 scsi_device_put(d);
701 spin_lock(pHba->host->host_lock);
702 return cmd;
703 }
704 }
705 spin_unlock_irqrestore(&d->list_lock, flags);
706 }
707 spin_lock(pHba->host->host_lock);
708
709 return NULL;
710}
711
712/*
713 * Turn a pointer to ioctl reply data into an u32 'context'
714 */
715static u32 adpt_ioctl_to_context(adpt_hba * pHba, void *reply)
716{
717#if BITS_PER_LONG == 32
718 return (u32)(unsigned long)reply;
719#else
720 ulong flags = 0;
721 u32 nr, i;
722
723 spin_lock_irqsave(pHba->host->host_lock, flags);
724 nr = ARRAY_SIZE(pHba->ioctl_reply_context);
725 for (i = 0; i < nr; i++) {
726 if (pHba->ioctl_reply_context[i] == NULL) {
727 pHba->ioctl_reply_context[i] = reply;
728 break;
729 }
730 }
731 spin_unlock_irqrestore(pHba->host->host_lock, flags);
732 if (i >= nr) {
733 kfree (reply);
734 printk(KERN_WARNING"%s: Too many outstanding "
735 "ioctl commands\n", pHba->name);
736 return (u32)-1;
737 }
738
739 return i;
740#endif
741}
742
743/*
744 * Go from an u32 'context' to a pointer to ioctl reply data.
745 */
746static void *adpt_ioctl_from_context(adpt_hba *pHba, u32 context)
747{
748#if BITS_PER_LONG == 32
749 return (void *)(unsigned long)context;
750#else
751 void *p = pHba->ioctl_reply_context[context];
752 pHba->ioctl_reply_context[context] = NULL;
753
754 return p;
755#endif
756}
635 757
636/*=========================================================================== 758/*===========================================================================
637 * Error Handling routines 759 * Error Handling routines
@@ -660,7 +782,7 @@ static int adpt_abort(struct scsi_cmnd * cmd)
660 msg[1] = I2O_CMD_SCSI_ABORT<<24|HOST_TID<<12|dptdevice->tid; 782 msg[1] = I2O_CMD_SCSI_ABORT<<24|HOST_TID<<12|dptdevice->tid;
661 msg[2] = 0; 783 msg[2] = 0;
662 msg[3]= 0; 784 msg[3]= 0;
663 msg[4] = (u32)cmd; 785 msg[4] = adpt_cmd_to_context(cmd);
664 if (pHba->host) 786 if (pHba->host)
665 spin_lock_irq(pHba->host->host_lock); 787 spin_lock_irq(pHba->host->host_lock);
666 rcode = adpt_i2o_post_wait(pHba, msg, sizeof(msg), FOREVER); 788 rcode = adpt_i2o_post_wait(pHba, msg, sizeof(msg), FOREVER);
@@ -861,27 +983,6 @@ static void adpt_i2o_sys_shutdown(void)
861 printk(KERN_INFO "Adaptec I2O controllers down.\n"); 983 printk(KERN_INFO "Adaptec I2O controllers down.\n");
862} 984}
863 985
864/*
865 * reboot/shutdown notification.
866 *
867 * - Quiesce each IOP in the system
868 *
869 */
870
871#ifdef REBOOT_NOTIFIER
872static int adpt_reboot_event(struct notifier_block *n, ulong code, void *p)
873{
874
875 if(code != SYS_RESTART && code != SYS_HALT && code != SYS_POWER_OFF)
876 return NOTIFY_DONE;
877
878 adpt_i2o_sys_shutdown();
879
880 return NOTIFY_DONE;
881}
882#endif
883
884
885static int adpt_install_hba(struct scsi_host_template* sht, struct pci_dev* pDev) 986static int adpt_install_hba(struct scsi_host_template* sht, struct pci_dev* pDev)
886{ 987{
887 988
@@ -893,6 +994,7 @@ static int adpt_install_hba(struct scsi_host_template* sht, struct pci_dev* pDev
893 u32 hba_map1_area_size = 0; 994 u32 hba_map1_area_size = 0;
894 void __iomem *base_addr_virt = NULL; 995 void __iomem *base_addr_virt = NULL;
895 void __iomem *msg_addr_virt = NULL; 996 void __iomem *msg_addr_virt = NULL;
997 int dma64 = 0;
896 998
897 int raptorFlag = FALSE; 999 int raptorFlag = FALSE;
898 1000
@@ -906,9 +1008,21 @@ static int adpt_install_hba(struct scsi_host_template* sht, struct pci_dev* pDev
906 } 1008 }
907 1009
908 pci_set_master(pDev); 1010 pci_set_master(pDev);
909 if (pci_set_dma_mask(pDev, DMA_32BIT_MASK)) 1011
1012 /*
1013 * See if we should enable dma64 mode.
1014 */
1015 if (sizeof(dma_addr_t) > 4 &&
1016 pci_set_dma_mask(pDev, DMA_64BIT_MASK) == 0) {
1017 if (dma_get_required_mask(&pDev->dev) > DMA_32BIT_MASK)
1018 dma64 = 1;
1019 }
1020 if (!dma64 && pci_set_dma_mask(pDev, DMA_32BIT_MASK) != 0)
910 return -EINVAL; 1021 return -EINVAL;
911 1022
1023 /* adapter only supports message blocks below 4GB */
1024 pci_set_consistent_dma_mask(pDev, DMA_32BIT_MASK);
1025
912 base_addr0_phys = pci_resource_start(pDev,0); 1026 base_addr0_phys = pci_resource_start(pDev,0);
913 hba_map0_area_size = pci_resource_len(pDev,0); 1027 hba_map0_area_size = pci_resource_len(pDev,0);
914 1028
@@ -929,6 +1043,25 @@ static int adpt_install_hba(struct scsi_host_template* sht, struct pci_dev* pDev
929 raptorFlag = TRUE; 1043 raptorFlag = TRUE;
930 } 1044 }
931 1045
1046#if BITS_PER_LONG == 64
1047 /*
1048 * The original Adaptec 64 bit driver has this comment here:
1049 * "x86_64 machines need more optimal mappings"
1050 *
1051 * I assume some HBAs report ridiculously large mappings
1052 * and we need to limit them on platforms with IOMMUs.
1053 */
1054 if (raptorFlag == TRUE) {
1055 if (hba_map0_area_size > 128)
1056 hba_map0_area_size = 128;
1057 if (hba_map1_area_size > 524288)
1058 hba_map1_area_size = 524288;
1059 } else {
1060 if (hba_map0_area_size > 524288)
1061 hba_map0_area_size = 524288;
1062 }
1063#endif
1064
932 base_addr_virt = ioremap(base_addr0_phys,hba_map0_area_size); 1065 base_addr_virt = ioremap(base_addr0_phys,hba_map0_area_size);
933 if (!base_addr_virt) { 1066 if (!base_addr_virt) {
934 pci_release_regions(pDev); 1067 pci_release_regions(pDev);
@@ -991,16 +1124,22 @@ static int adpt_install_hba(struct scsi_host_template* sht, struct pci_dev* pDev
991 pHba->state = DPTI_STATE_RESET; 1124 pHba->state = DPTI_STATE_RESET;
992 pHba->pDev = pDev; 1125 pHba->pDev = pDev;
993 pHba->devices = NULL; 1126 pHba->devices = NULL;
1127 pHba->dma64 = dma64;
994 1128
995 // Initializing the spinlocks 1129 // Initializing the spinlocks
996 spin_lock_init(&pHba->state_lock); 1130 spin_lock_init(&pHba->state_lock);
997 spin_lock_init(&adpt_post_wait_lock); 1131 spin_lock_init(&adpt_post_wait_lock);
998 1132
999 if(raptorFlag == 0){ 1133 if(raptorFlag == 0){
1000 printk(KERN_INFO"Adaptec I2O RAID controller %d at %p size=%x irq=%d\n", 1134 printk(KERN_INFO "Adaptec I2O RAID controller"
1001 hba_count-1, base_addr_virt, hba_map0_area_size, pDev->irq); 1135 " %d at %p size=%x irq=%d%s\n",
1136 hba_count-1, base_addr_virt,
1137 hba_map0_area_size, pDev->irq,
1138 dma64 ? " (64-bit DMA)" : "");
1002 } else { 1139 } else {
1003 printk(KERN_INFO"Adaptec I2O RAID controller %d irq=%d\n",hba_count-1, pDev->irq); 1140 printk(KERN_INFO"Adaptec I2O RAID controller %d irq=%d%s\n",
1141 hba_count-1, pDev->irq,
1142 dma64 ? " (64-bit DMA)" : "");
1004 printk(KERN_INFO" BAR0 %p - size= %x\n",base_addr_virt,hba_map0_area_size); 1143 printk(KERN_INFO" BAR0 %p - size= %x\n",base_addr_virt,hba_map0_area_size);
1005 printk(KERN_INFO" BAR1 %p - size= %x\n",msg_addr_virt,hba_map1_area_size); 1144 printk(KERN_INFO" BAR1 %p - size= %x\n",msg_addr_virt,hba_map1_area_size);
1006 } 1145 }
@@ -1053,10 +1192,26 @@ static void adpt_i2o_delete_hba(adpt_hba* pHba)
1053 if(pHba->msg_addr_virt != pHba->base_addr_virt){ 1192 if(pHba->msg_addr_virt != pHba->base_addr_virt){
1054 iounmap(pHba->msg_addr_virt); 1193 iounmap(pHba->msg_addr_virt);
1055 } 1194 }
1056 kfree(pHba->hrt); 1195 if(pHba->FwDebugBuffer_P)
1057 kfree(pHba->lct); 1196 iounmap(pHba->FwDebugBuffer_P);
1058 kfree(pHba->status_block); 1197 if(pHba->hrt) {
1059 kfree(pHba->reply_pool); 1198 dma_free_coherent(&pHba->pDev->dev,
1199 pHba->hrt->num_entries * pHba->hrt->entry_len << 2,
1200 pHba->hrt, pHba->hrt_pa);
1201 }
1202 if(pHba->lct) {
1203 dma_free_coherent(&pHba->pDev->dev, pHba->lct_size,
1204 pHba->lct, pHba->lct_pa);
1205 }
1206 if(pHba->status_block) {
1207 dma_free_coherent(&pHba->pDev->dev, sizeof(i2o_status_block),
1208 pHba->status_block, pHba->status_block_pa);
1209 }
1210 if(pHba->reply_pool) {
1211 dma_free_coherent(&pHba->pDev->dev,
1212 pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4,
1213 pHba->reply_pool, pHba->reply_pool_pa);
1214 }
1060 1215
1061 for(d = pHba->devices; d ; d = next){ 1216 for(d = pHba->devices; d ; d = next){
1062 next = d->next; 1217 next = d->next;
@@ -1075,23 +1230,19 @@ static void adpt_i2o_delete_hba(adpt_hba* pHba)
1075 pci_dev_put(pHba->pDev); 1230 pci_dev_put(pHba->pDev);
1076 kfree(pHba); 1231 kfree(pHba);
1077 1232
1233 if (adpt_sysfs_class)
1234 device_destroy(adpt_sysfs_class,
1235 MKDEV(DPTI_I2O_MAJOR, pHba->unit));
1236
1078 if(hba_count <= 0){ 1237 if(hba_count <= 0){
1079 unregister_chrdev(DPTI_I2O_MAJOR, DPT_DRIVER); 1238 unregister_chrdev(DPTI_I2O_MAJOR, DPT_DRIVER);
1239 if (adpt_sysfs_class) {
1240 class_destroy(adpt_sysfs_class);
1241 adpt_sysfs_class = NULL;
1242 }
1080 } 1243 }
1081} 1244}
1082 1245
1083
1084static int adpt_init(void)
1085{
1086 printk("Loading Adaptec I2O RAID: Version " DPT_I2O_VERSION "\n");
1087#ifdef REBOOT_NOTIFIER
1088 register_reboot_notifier(&adpt_reboot_notifier);
1089#endif
1090
1091 return 0;
1092}
1093
1094
1095static struct adpt_device* adpt_find_device(adpt_hba* pHba, u32 chan, u32 id, u32 lun) 1246static struct adpt_device* adpt_find_device(adpt_hba* pHba, u32 chan, u32 id, u32 lun)
1096{ 1247{
1097 struct adpt_device* d; 1248 struct adpt_device* d;
@@ -1283,6 +1434,7 @@ static s32 adpt_i2o_reset_hba(adpt_hba* pHba)
1283{ 1434{
1284 u32 msg[8]; 1435 u32 msg[8];
1285 u8* status; 1436 u8* status;
1437 dma_addr_t addr;
1286 u32 m = EMPTY_QUEUE ; 1438 u32 m = EMPTY_QUEUE ;
1287 ulong timeout = jiffies + (TMOUT_IOPRESET*HZ); 1439 ulong timeout = jiffies + (TMOUT_IOPRESET*HZ);
1288 1440
@@ -1305,12 +1457,13 @@ static s32 adpt_i2o_reset_hba(adpt_hba* pHba)
1305 schedule_timeout_uninterruptible(1); 1457 schedule_timeout_uninterruptible(1);
1306 } while (m == EMPTY_QUEUE); 1458 } while (m == EMPTY_QUEUE);
1307 1459
1308 status = kzalloc(4, GFP_KERNEL|ADDR32); 1460 status = dma_alloc_coherent(&pHba->pDev->dev, 4, &addr, GFP_KERNEL);
1309 if(status == NULL) { 1461 if(status == NULL) {
1310 adpt_send_nop(pHba, m); 1462 adpt_send_nop(pHba, m);
1311 printk(KERN_ERR"IOP reset failed - no free memory.\n"); 1463 printk(KERN_ERR"IOP reset failed - no free memory.\n");
1312 return -ENOMEM; 1464 return -ENOMEM;
1313 } 1465 }
1466 memset(status,0,4);
1314 1467
1315 msg[0]=EIGHT_WORD_MSG_SIZE|SGL_OFFSET_0; 1468 msg[0]=EIGHT_WORD_MSG_SIZE|SGL_OFFSET_0;
1316 msg[1]=I2O_CMD_ADAPTER_RESET<<24|HOST_TID<<12|ADAPTER_TID; 1469 msg[1]=I2O_CMD_ADAPTER_RESET<<24|HOST_TID<<12|ADAPTER_TID;
@@ -1318,8 +1471,8 @@ static s32 adpt_i2o_reset_hba(adpt_hba* pHba)
1318 msg[3]=0; 1471 msg[3]=0;
1319 msg[4]=0; 1472 msg[4]=0;
1320 msg[5]=0; 1473 msg[5]=0;
1321 msg[6]=virt_to_bus(status); 1474 msg[6]=dma_low(addr);
1322 msg[7]=0; 1475 msg[7]=dma_high(addr);
1323 1476
1324 memcpy_toio(pHba->msg_addr_virt+m, msg, sizeof(msg)); 1477 memcpy_toio(pHba->msg_addr_virt+m, msg, sizeof(msg));
1325 wmb(); 1478 wmb();
@@ -1329,7 +1482,10 @@ static s32 adpt_i2o_reset_hba(adpt_hba* pHba)
1329 while(*status == 0){ 1482 while(*status == 0){
1330 if(time_after(jiffies,timeout)){ 1483 if(time_after(jiffies,timeout)){
1331 printk(KERN_WARNING"%s: IOP Reset Timeout\n",pHba->name); 1484 printk(KERN_WARNING"%s: IOP Reset Timeout\n",pHba->name);
1332 kfree(status); 1485 /* We lose 4 bytes of "status" here, but we cannot
1486 free these because controller may awake and corrupt
1487 those bytes at any time */
1488 /* dma_free_coherent(&pHba->pDev->dev, 4, buf, addr); */
1333 return -ETIMEDOUT; 1489 return -ETIMEDOUT;
1334 } 1490 }
1335 rmb(); 1491 rmb();
@@ -1348,6 +1504,10 @@ static s32 adpt_i2o_reset_hba(adpt_hba* pHba)
1348 } 1504 }
1349 if(time_after(jiffies,timeout)){ 1505 if(time_after(jiffies,timeout)){
1350 printk(KERN_ERR "%s:Timeout waiting for IOP Reset.\n",pHba->name); 1506 printk(KERN_ERR "%s:Timeout waiting for IOP Reset.\n",pHba->name);
1507 /* We lose 4 bytes of "status" here, but we
1508 cannot free these because controller may
1509 awake and corrupt those bytes at any time */
1510 /* dma_free_coherent(&pHba->pDev->dev, 4, buf, addr); */
1351 return -ETIMEDOUT; 1511 return -ETIMEDOUT;
1352 } 1512 }
1353 schedule_timeout_uninterruptible(1); 1513 schedule_timeout_uninterruptible(1);
@@ -1364,7 +1524,7 @@ static s32 adpt_i2o_reset_hba(adpt_hba* pHba)
1364 PDEBUG("%s: Reset completed.\n", pHba->name); 1524 PDEBUG("%s: Reset completed.\n", pHba->name);
1365 } 1525 }
1366 1526
1367 kfree(status); 1527 dma_free_coherent(&pHba->pDev->dev, 4, status, addr);
1368#ifdef UARTDELAY 1528#ifdef UARTDELAY
1369 // This delay is to allow someone attached to the card through the debug UART to 1529 // This delay is to allow someone attached to the card through the debug UART to
1370 // set up the dump levels that they want before the rest of the initialization sequence 1530 // set up the dump levels that they want before the rest of the initialization sequence
@@ -1636,6 +1796,7 @@ static int adpt_i2o_passthru(adpt_hba* pHba, u32 __user *arg)
1636 u32 i = 0; 1796 u32 i = 0;
1637 u32 rcode = 0; 1797 u32 rcode = 0;
1638 void *p = NULL; 1798 void *p = NULL;
1799 dma_addr_t addr;
1639 ulong flags = 0; 1800 ulong flags = 0;
1640 1801
1641 memset(&msg, 0, MAX_MESSAGE_SIZE*4); 1802 memset(&msg, 0, MAX_MESSAGE_SIZE*4);
@@ -1668,10 +1829,13 @@ static int adpt_i2o_passthru(adpt_hba* pHba, u32 __user *arg)
1668 } 1829 }
1669 sg_offset = (msg[0]>>4)&0xf; 1830 sg_offset = (msg[0]>>4)&0xf;
1670 msg[2] = 0x40000000; // IOCTL context 1831 msg[2] = 0x40000000; // IOCTL context
1671 msg[3] = (u32)reply; 1832 msg[3] = adpt_ioctl_to_context(pHba, reply);
1833 if (msg[3] == (u32)-1)
1834 return -EBUSY;
1835
1672 memset(sg_list,0, sizeof(sg_list[0])*pHba->sg_tablesize); 1836 memset(sg_list,0, sizeof(sg_list[0])*pHba->sg_tablesize);
1673 if(sg_offset) { 1837 if(sg_offset) {
1674 // TODO 64bit fix 1838 // TODO add 64 bit API
1675 struct sg_simple_element *sg = (struct sg_simple_element*) (msg+sg_offset); 1839 struct sg_simple_element *sg = (struct sg_simple_element*) (msg+sg_offset);
1676 sg_count = (size - sg_offset*4) / sizeof(struct sg_simple_element); 1840 sg_count = (size - sg_offset*4) / sizeof(struct sg_simple_element);
1677 if (sg_count > pHba->sg_tablesize){ 1841 if (sg_count > pHba->sg_tablesize){
@@ -1690,7 +1854,7 @@ static int adpt_i2o_passthru(adpt_hba* pHba, u32 __user *arg)
1690 } 1854 }
1691 sg_size = sg[i].flag_count & 0xffffff; 1855 sg_size = sg[i].flag_count & 0xffffff;
1692 /* Allocate memory for the transfer */ 1856 /* Allocate memory for the transfer */
1693 p = kmalloc(sg_size, GFP_KERNEL|ADDR32); 1857 p = dma_alloc_coherent(&pHba->pDev->dev, sg_size, &addr, GFP_KERNEL);
1694 if(!p) { 1858 if(!p) {
1695 printk(KERN_DEBUG"%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n", 1859 printk(KERN_DEBUG"%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
1696 pHba->name,sg_size,i,sg_count); 1860 pHba->name,sg_size,i,sg_count);
@@ -1700,15 +1864,15 @@ static int adpt_i2o_passthru(adpt_hba* pHba, u32 __user *arg)
1700 sg_list[sg_index++] = p; // sglist indexed with input frame, not our internal frame. 1864 sg_list[sg_index++] = p; // sglist indexed with input frame, not our internal frame.
1701 /* Copy in the user's SG buffer if necessary */ 1865 /* Copy in the user's SG buffer if necessary */
1702 if(sg[i].flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR*/) { 1866 if(sg[i].flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR*/) {
1703 // TODO 64bit fix 1867 // sg_simple_element API is 32 bit
1704 if (copy_from_user(p,(void __user *)sg[i].addr_bus, sg_size)) { 1868 if (copy_from_user(p,(void __user *)(ulong)sg[i].addr_bus, sg_size)) {
1705 printk(KERN_DEBUG"%s: Could not copy SG buf %d FROM user\n",pHba->name,i); 1869 printk(KERN_DEBUG"%s: Could not copy SG buf %d FROM user\n",pHba->name,i);
1706 rcode = -EFAULT; 1870 rcode = -EFAULT;
1707 goto cleanup; 1871 goto cleanup;
1708 } 1872 }
1709 } 1873 }
1710 //TODO 64bit fix 1874 /* sg_simple_element API is 32 bit, but addr < 4GB */
1711 sg[i].addr_bus = (u32)virt_to_bus(p); 1875 sg[i].addr_bus = addr;
1712 } 1876 }
1713 } 1877 }
1714 1878
@@ -1736,7 +1900,7 @@ static int adpt_i2o_passthru(adpt_hba* pHba, u32 __user *arg)
1736 if(sg_offset) { 1900 if(sg_offset) {
1737 /* Copy back the Scatter Gather buffers back to user space */ 1901 /* Copy back the Scatter Gather buffers back to user space */
1738 u32 j; 1902 u32 j;
1739 // TODO 64bit fix 1903 // TODO add 64 bit API
1740 struct sg_simple_element* sg; 1904 struct sg_simple_element* sg;
1741 int sg_size; 1905 int sg_size;
1742 1906
@@ -1756,14 +1920,14 @@ static int adpt_i2o_passthru(adpt_hba* pHba, u32 __user *arg)
1756 } 1920 }
1757 sg_count = (size - sg_offset*4) / sizeof(struct sg_simple_element); 1921 sg_count = (size - sg_offset*4) / sizeof(struct sg_simple_element);
1758 1922
1759 // TODO 64bit fix 1923 // TODO add 64 bit API
1760 sg = (struct sg_simple_element*)(msg + sg_offset); 1924 sg = (struct sg_simple_element*)(msg + sg_offset);
1761 for (j = 0; j < sg_count; j++) { 1925 for (j = 0; j < sg_count; j++) {
1762 /* Copy out the SG list to user's buffer if necessary */ 1926 /* Copy out the SG list to user's buffer if necessary */
1763 if(! (sg[j].flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR*/)) { 1927 if(! (sg[j].flag_count & 0x4000000 /*I2O_SGL_FLAGS_DIR*/)) {
1764 sg_size = sg[j].flag_count & 0xffffff; 1928 sg_size = sg[j].flag_count & 0xffffff;
1765 // TODO 64bit fix 1929 // sg_simple_element API is 32 bit
1766 if (copy_to_user((void __user *)sg[j].addr_bus,sg_list[j], sg_size)) { 1930 if (copy_to_user((void __user *)(ulong)sg[j].addr_bus,sg_list[j], sg_size)) {
1767 printk(KERN_WARNING"%s: Could not copy %p TO user %x\n",pHba->name, sg_list[j], sg[j].addr_bus); 1931 printk(KERN_WARNING"%s: Could not copy %p TO user %x\n",pHba->name, sg_list[j], sg[j].addr_bus);
1768 rcode = -EFAULT; 1932 rcode = -EFAULT;
1769 goto cleanup; 1933 goto cleanup;
@@ -1787,12 +1951,17 @@ static int adpt_i2o_passthru(adpt_hba* pHba, u32 __user *arg)
1787 1951
1788 1952
1789cleanup: 1953cleanup:
1790 if (rcode != -ETIME && rcode != -EINTR) 1954 if (rcode != -ETIME && rcode != -EINTR) {
1955 struct sg_simple_element *sg =
1956 (struct sg_simple_element*) (msg +sg_offset);
1791 kfree (reply); 1957 kfree (reply);
1792 while(sg_index) { 1958 while(sg_index) {
1793 if(sg_list[--sg_index]) { 1959 if(sg_list[--sg_index]) {
1794 if (rcode != -ETIME && rcode != -EINTR) 1960 dma_free_coherent(&pHba->pDev->dev,
1795 kfree(sg_list[sg_index]); 1961 sg[sg_index].flag_count & 0xffffff,
1962 sg_list[sg_index],
1963 sg[sg_index].addr_bus);
1964 }
1796 } 1965 }
1797 } 1966 }
1798 return rcode; 1967 return rcode;
@@ -1978,6 +2147,38 @@ static int adpt_ioctl(struct inode *inode, struct file *file, uint cmd,
1978 return error; 2147 return error;
1979} 2148}
1980 2149
2150#ifdef CONFIG_COMPAT
2151static long compat_adpt_ioctl(struct file *file,
2152 unsigned int cmd, unsigned long arg)
2153{
2154 struct inode *inode;
2155 long ret;
2156
2157 inode = file->f_dentry->d_inode;
2158
2159 lock_kernel();
2160
2161 switch(cmd) {
2162 case DPT_SIGNATURE:
2163 case I2OUSRCMD:
2164 case DPT_CTRLINFO:
2165 case DPT_SYSINFO:
2166 case DPT_BLINKLED:
2167 case I2ORESETCMD:
2168 case I2ORESCANCMD:
2169 case (DPT_TARGET_BUSY & 0xFFFF):
2170 case DPT_TARGET_BUSY:
2171 ret = adpt_ioctl(inode, file, cmd, arg);
2172 break;
2173 default:
2174 ret = -ENOIOCTLCMD;
2175 }
2176
2177 unlock_kernel();
2178
2179 return ret;
2180}
2181#endif
1981 2182
1982static irqreturn_t adpt_isr(int irq, void *dev_id) 2183static irqreturn_t adpt_isr(int irq, void *dev_id)
1983{ 2184{
@@ -2009,7 +2210,16 @@ static irqreturn_t adpt_isr(int irq, void *dev_id)
2009 goto out; 2210 goto out;
2010 } 2211 }
2011 } 2212 }
2012 reply = bus_to_virt(m); 2213 if (pHba->reply_pool_pa <= m &&
2214 m < pHba->reply_pool_pa +
2215 (pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4)) {
2216 reply = (u8 *)pHba->reply_pool +
2217 (m - pHba->reply_pool_pa);
2218 } else {
2219 /* Ick, we should *never* be here */
2220 printk(KERN_ERR "dpti: reply frame not from pool\n");
2221 reply = (u8 *)bus_to_virt(m);
2222 }
2013 2223
2014 if (readl(reply) & MSG_FAIL) { 2224 if (readl(reply) & MSG_FAIL) {
2015 u32 old_m = readl(reply+28); 2225 u32 old_m = readl(reply+28);
@@ -2029,7 +2239,7 @@ static irqreturn_t adpt_isr(int irq, void *dev_id)
2029 } 2239 }
2030 context = readl(reply+8); 2240 context = readl(reply+8);
2031 if(context & 0x40000000){ // IOCTL 2241 if(context & 0x40000000){ // IOCTL
2032 void *p = (void *)readl(reply+12); 2242 void *p = adpt_ioctl_from_context(pHba, readl(reply+12));
2033 if( p != NULL) { 2243 if( p != NULL) {
2034 memcpy_fromio(p, reply, REPLY_FRAME_SIZE * 4); 2244 memcpy_fromio(p, reply, REPLY_FRAME_SIZE * 4);
2035 } 2245 }
@@ -2043,15 +2253,17 @@ static irqreturn_t adpt_isr(int irq, void *dev_id)
2043 status = I2O_POST_WAIT_OK; 2253 status = I2O_POST_WAIT_OK;
2044 } 2254 }
2045 if(!(context & 0x40000000)) { 2255 if(!(context & 0x40000000)) {
2046 cmd = (struct scsi_cmnd*) readl(reply+12); 2256 cmd = adpt_cmd_from_context(pHba,
2257 readl(reply+12));
2047 if(cmd != NULL) { 2258 if(cmd != NULL) {
2048 printk(KERN_WARNING"%s: Apparent SCSI cmd in Post Wait Context - cmd=%p context=%x\n", pHba->name, cmd, context); 2259 printk(KERN_WARNING"%s: Apparent SCSI cmd in Post Wait Context - cmd=%p context=%x\n", pHba->name, cmd, context);
2049 } 2260 }
2050 } 2261 }
2051 adpt_i2o_post_wait_complete(context, status); 2262 adpt_i2o_post_wait_complete(context, status);
2052 } else { // SCSI message 2263 } else { // SCSI message
2053 cmd = (struct scsi_cmnd*) readl(reply+12); 2264 cmd = adpt_cmd_from_context (pHba, readl(reply+12));
2054 if(cmd != NULL){ 2265 if(cmd != NULL){
2266 scsi_dma_unmap(cmd);
2055 if(cmd->serial_number != 0) { // If not timedout 2267 if(cmd->serial_number != 0) { // If not timedout
2056 adpt_i2o_to_scsi(reply, cmd); 2268 adpt_i2o_to_scsi(reply, cmd);
2057 } 2269 }
@@ -2072,6 +2284,7 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_d
2072 int i; 2284 int i;
2073 u32 msg[MAX_MESSAGE_SIZE]; 2285 u32 msg[MAX_MESSAGE_SIZE];
2074 u32* mptr; 2286 u32* mptr;
2287 u32* lptr;
2075 u32 *lenptr; 2288 u32 *lenptr;
2076 int direction; 2289 int direction;
2077 int scsidir; 2290 int scsidir;
@@ -2079,6 +2292,7 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_d
2079 u32 len; 2292 u32 len;
2080 u32 reqlen; 2293 u32 reqlen;
2081 s32 rcode; 2294 s32 rcode;
2295 dma_addr_t addr;
2082 2296
2083 memset(msg, 0 , sizeof(msg)); 2297 memset(msg, 0 , sizeof(msg));
2084 len = scsi_bufflen(cmd); 2298 len = scsi_bufflen(cmd);
@@ -2118,7 +2332,7 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_d
2118 // I2O_CMD_SCSI_EXEC 2332 // I2O_CMD_SCSI_EXEC
2119 msg[1] = ((0xff<<24)|(HOST_TID<<12)|d->tid); 2333 msg[1] = ((0xff<<24)|(HOST_TID<<12)|d->tid);
2120 msg[2] = 0; 2334 msg[2] = 0;
2121 msg[3] = (u32)cmd; /* We want the SCSI control block back */ 2335 msg[3] = adpt_cmd_to_context(cmd); /* Want SCSI control block back */
2122 // Our cards use the transaction context as the tag for queueing 2336 // Our cards use the transaction context as the tag for queueing
2123 // Adaptec/DPT Private stuff 2337 // Adaptec/DPT Private stuff
2124 msg[4] = I2O_CMD_SCSI_EXEC|(DPT_ORGANIZATION_ID<<16); 2338 msg[4] = I2O_CMD_SCSI_EXEC|(DPT_ORGANIZATION_ID<<16);
@@ -2136,7 +2350,13 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_d
2136 memcpy(mptr, cmd->cmnd, cmd->cmd_len); 2350 memcpy(mptr, cmd->cmnd, cmd->cmd_len);
2137 mptr+=4; 2351 mptr+=4;
2138 lenptr=mptr++; /* Remember me - fill in when we know */ 2352 lenptr=mptr++; /* Remember me - fill in when we know */
2139 reqlen = 14; // SINGLE SGE 2353 if (dpt_dma64(pHba)) {
2354 reqlen = 16; // SINGLE SGE
2355 *mptr++ = (0x7C<<24)+(2<<16)+0x02; /* Enable 64 bit */
2356 *mptr++ = 1 << PAGE_SHIFT;
2357 } else {
2358 reqlen = 14; // SINGLE SGE
2359 }
2140 /* Now fill in the SGList and command */ 2360 /* Now fill in the SGList and command */
2141 2361
2142 nseg = scsi_dma_map(cmd); 2362 nseg = scsi_dma_map(cmd);
@@ -2146,12 +2366,16 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_d
2146 2366
2147 len = 0; 2367 len = 0;
2148 scsi_for_each_sg(cmd, sg, nseg, i) { 2368 scsi_for_each_sg(cmd, sg, nseg, i) {
2369 lptr = mptr;
2149 *mptr++ = direction|0x10000000|sg_dma_len(sg); 2370 *mptr++ = direction|0x10000000|sg_dma_len(sg);
2150 len+=sg_dma_len(sg); 2371 len+=sg_dma_len(sg);
2151 *mptr++ = sg_dma_address(sg); 2372 addr = sg_dma_address(sg);
2373 *mptr++ = dma_low(addr);
2374 if (dpt_dma64(pHba))
2375 *mptr++ = dma_high(addr);
2152 /* Make this an end of list */ 2376 /* Make this an end of list */
2153 if (i == nseg - 1) 2377 if (i == nseg - 1)
2154 mptr[-2] = direction|0xD0000000|sg_dma_len(sg); 2378 *lptr = direction|0xD0000000|sg_dma_len(sg);
2155 } 2379 }
2156 reqlen = mptr - msg; 2380 reqlen = mptr - msg;
2157 *lenptr = len; 2381 *lenptr = len;
@@ -2177,13 +2401,13 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_d
2177} 2401}
2178 2402
2179 2403
2180static s32 adpt_scsi_register(adpt_hba* pHba,struct scsi_host_template * sht) 2404static s32 adpt_scsi_host_alloc(adpt_hba* pHba, struct scsi_host_template *sht)
2181{ 2405{
2182 struct Scsi_Host *host = NULL; 2406 struct Scsi_Host *host;
2183 2407
2184 host = scsi_register(sht, sizeof(adpt_hba*)); 2408 host = scsi_host_alloc(sht, sizeof(adpt_hba*));
2185 if (host == NULL) { 2409 if (host == NULL) {
2186 printk ("%s: scsi_register returned NULL\n",pHba->name); 2410 printk("%s: scsi_host_alloc returned NULL\n", pHba->name);
2187 return -1; 2411 return -1;
2188 } 2412 }
2189 host->hostdata[0] = (unsigned long)pHba; 2413 host->hostdata[0] = (unsigned long)pHba;
@@ -2200,7 +2424,7 @@ static s32 adpt_scsi_register(adpt_hba* pHba,struct scsi_host_template * sht)
2200 host->max_lun = 256; 2424 host->max_lun = 256;
2201 host->max_channel = pHba->top_scsi_channel + 1; 2425 host->max_channel = pHba->top_scsi_channel + 1;
2202 host->cmd_per_lun = 1; 2426 host->cmd_per_lun = 1;
2203 host->unique_id = (uint) pHba; 2427 host->unique_id = (u32)sys_tbl_pa + pHba->unit;
2204 host->sg_tablesize = pHba->sg_tablesize; 2428 host->sg_tablesize = pHba->sg_tablesize;
2205 host->can_queue = pHba->post_fifo_size; 2429 host->can_queue = pHba->post_fifo_size;
2206 2430
@@ -2640,11 +2864,10 @@ static s32 adpt_send_nop(adpt_hba*pHba,u32 m)
2640static s32 adpt_i2o_init_outbound_q(adpt_hba* pHba) 2864static s32 adpt_i2o_init_outbound_q(adpt_hba* pHba)
2641{ 2865{
2642 u8 *status; 2866 u8 *status;
2867 dma_addr_t addr;
2643 u32 __iomem *msg = NULL; 2868 u32 __iomem *msg = NULL;
2644 int i; 2869 int i;
2645 ulong timeout = jiffies + TMOUT_INITOUTBOUND*HZ; 2870 ulong timeout = jiffies + TMOUT_INITOUTBOUND*HZ;
2646 u32* ptr;
2647 u32 outbound_frame; // This had to be a 32 bit address
2648 u32 m; 2871 u32 m;
2649 2872
2650 do { 2873 do {
@@ -2663,13 +2886,14 @@ static s32 adpt_i2o_init_outbound_q(adpt_hba* pHba)
2663 2886
2664 msg=(u32 __iomem *)(pHba->msg_addr_virt+m); 2887 msg=(u32 __iomem *)(pHba->msg_addr_virt+m);
2665 2888
2666 status = kzalloc(4, GFP_KERNEL|ADDR32); 2889 status = dma_alloc_coherent(&pHba->pDev->dev, 4, &addr, GFP_KERNEL);
2667 if (!status) { 2890 if (!status) {
2668 adpt_send_nop(pHba, m); 2891 adpt_send_nop(pHba, m);
2669 printk(KERN_WARNING"%s: IOP reset failed - no free memory.\n", 2892 printk(KERN_WARNING"%s: IOP reset failed - no free memory.\n",
2670 pHba->name); 2893 pHba->name);
2671 return -ENOMEM; 2894 return -ENOMEM;
2672 } 2895 }
2896 memset(status, 0, 4);
2673 2897
2674 writel(EIGHT_WORD_MSG_SIZE| SGL_OFFSET_6, &msg[0]); 2898 writel(EIGHT_WORD_MSG_SIZE| SGL_OFFSET_6, &msg[0]);
2675 writel(I2O_CMD_OUTBOUND_INIT<<24 | HOST_TID<<12 | ADAPTER_TID, &msg[1]); 2899 writel(I2O_CMD_OUTBOUND_INIT<<24 | HOST_TID<<12 | ADAPTER_TID, &msg[1]);
@@ -2678,7 +2902,7 @@ static s32 adpt_i2o_init_outbound_q(adpt_hba* pHba)
2678 writel(4096, &msg[4]); /* Host page frame size */ 2902 writel(4096, &msg[4]); /* Host page frame size */
2679 writel((REPLY_FRAME_SIZE)<<16|0x80, &msg[5]); /* Outbound msg frame size and Initcode */ 2903 writel((REPLY_FRAME_SIZE)<<16|0x80, &msg[5]); /* Outbound msg frame size and Initcode */
2680 writel(0xD0000004, &msg[6]); /* Simple SG LE, EOB */ 2904 writel(0xD0000004, &msg[6]); /* Simple SG LE, EOB */
2681 writel(virt_to_bus(status), &msg[7]); 2905 writel((u32)addr, &msg[7]);
2682 2906
2683 writel(m, pHba->post_port); 2907 writel(m, pHba->post_port);
2684 wmb(); 2908 wmb();
@@ -2693,6 +2917,10 @@ static s32 adpt_i2o_init_outbound_q(adpt_hba* pHba)
2693 rmb(); 2917 rmb();
2694 if(time_after(jiffies,timeout)){ 2918 if(time_after(jiffies,timeout)){
2695 printk(KERN_WARNING"%s: Timeout Initializing\n",pHba->name); 2919 printk(KERN_WARNING"%s: Timeout Initializing\n",pHba->name);
2920 /* We lose 4 bytes of "status" here, but we
2921 cannot free these because controller may
2922 awake and corrupt those bytes at any time */
2923 /* dma_free_coherent(&pHba->pDev->dev, 4, status, addr); */
2696 return -ETIMEDOUT; 2924 return -ETIMEDOUT;
2697 } 2925 }
2698 schedule_timeout_uninterruptible(1); 2926 schedule_timeout_uninterruptible(1);
@@ -2701,25 +2929,30 @@ static s32 adpt_i2o_init_outbound_q(adpt_hba* pHba)
2701 // If the command was successful, fill the fifo with our reply 2929 // If the command was successful, fill the fifo with our reply
2702 // message packets 2930 // message packets
2703 if(*status != 0x04 /*I2O_EXEC_OUTBOUND_INIT_COMPLETE*/) { 2931 if(*status != 0x04 /*I2O_EXEC_OUTBOUND_INIT_COMPLETE*/) {
2704 kfree(status); 2932 dma_free_coherent(&pHba->pDev->dev, 4, status, addr);
2705 return -2; 2933 return -2;
2706 } 2934 }
2707 kfree(status); 2935 dma_free_coherent(&pHba->pDev->dev, 4, status, addr);
2708 2936
2709 kfree(pHba->reply_pool); 2937 if(pHba->reply_pool != NULL) {
2938 dma_free_coherent(&pHba->pDev->dev,
2939 pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4,
2940 pHba->reply_pool, pHba->reply_pool_pa);
2941 }
2710 2942
2711 pHba->reply_pool = kzalloc(pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4, GFP_KERNEL|ADDR32); 2943 pHba->reply_pool = dma_alloc_coherent(&pHba->pDev->dev,
2944 pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4,
2945 &pHba->reply_pool_pa, GFP_KERNEL);
2712 if (!pHba->reply_pool) { 2946 if (!pHba->reply_pool) {
2713 printk(KERN_ERR "%s: Could not allocate reply pool\n", pHba->name); 2947 printk(KERN_ERR "%s: Could not allocate reply pool\n", pHba->name);
2714 return -ENOMEM; 2948 return -ENOMEM;
2715 } 2949 }
2950 memset(pHba->reply_pool, 0 , pHba->reply_fifo_size * REPLY_FRAME_SIZE * 4);
2716 2951
2717 ptr = pHba->reply_pool;
2718 for(i = 0; i < pHba->reply_fifo_size; i++) { 2952 for(i = 0; i < pHba->reply_fifo_size; i++) {
2719 outbound_frame = (u32)virt_to_bus(ptr); 2953 writel(pHba->reply_pool_pa + (i * REPLY_FRAME_SIZE * 4),
2720 writel(outbound_frame, pHba->reply_port); 2954 pHba->reply_port);
2721 wmb(); 2955 wmb();
2722 ptr += REPLY_FRAME_SIZE;
2723 } 2956 }
2724 adpt_i2o_status_get(pHba); 2957 adpt_i2o_status_get(pHba);
2725 return 0; 2958 return 0;
@@ -2743,11 +2976,11 @@ static s32 adpt_i2o_status_get(adpt_hba* pHba)
2743 u32 m; 2976 u32 m;
2744 u32 __iomem *msg; 2977 u32 __iomem *msg;
2745 u8 *status_block=NULL; 2978 u8 *status_block=NULL;
2746 ulong status_block_bus;
2747 2979
2748 if(pHba->status_block == NULL) { 2980 if(pHba->status_block == NULL) {
2749 pHba->status_block = (i2o_status_block*) 2981 pHba->status_block = dma_alloc_coherent(&pHba->pDev->dev,
2750 kmalloc(sizeof(i2o_status_block),GFP_KERNEL|ADDR32); 2982 sizeof(i2o_status_block),
2983 &pHba->status_block_pa, GFP_KERNEL);
2751 if(pHba->status_block == NULL) { 2984 if(pHba->status_block == NULL) {
2752 printk(KERN_ERR 2985 printk(KERN_ERR
2753 "dpti%d: Get Status Block failed; Out of memory. \n", 2986 "dpti%d: Get Status Block failed; Out of memory. \n",
@@ -2757,7 +2990,6 @@ static s32 adpt_i2o_status_get(adpt_hba* pHba)
2757 } 2990 }
2758 memset(pHba->status_block, 0, sizeof(i2o_status_block)); 2991 memset(pHba->status_block, 0, sizeof(i2o_status_block));
2759 status_block = (u8*)(pHba->status_block); 2992 status_block = (u8*)(pHba->status_block);
2760 status_block_bus = virt_to_bus(pHba->status_block);
2761 timeout = jiffies+TMOUT_GETSTATUS*HZ; 2993 timeout = jiffies+TMOUT_GETSTATUS*HZ;
2762 do { 2994 do {
2763 rmb(); 2995 rmb();
@@ -2782,8 +3014,8 @@ static s32 adpt_i2o_status_get(adpt_hba* pHba)
2782 writel(0, &msg[3]); 3014 writel(0, &msg[3]);
2783 writel(0, &msg[4]); 3015 writel(0, &msg[4]);
2784 writel(0, &msg[5]); 3016 writel(0, &msg[5]);
2785 writel(((u32)status_block_bus)&0xffffffff, &msg[6]); 3017 writel( dma_low(pHba->status_block_pa), &msg[6]);
2786 writel(0, &msg[7]); 3018 writel( dma_high(pHba->status_block_pa), &msg[7]);
2787 writel(sizeof(i2o_status_block), &msg[8]); // 88 bytes 3019 writel(sizeof(i2o_status_block), &msg[8]); // 88 bytes
2788 3020
2789 //post message 3021 //post message
@@ -2812,7 +3044,17 @@ static s32 adpt_i2o_status_get(adpt_hba* pHba)
2812 } 3044 }
2813 3045
2814 // Calculate the Scatter Gather list size 3046 // Calculate the Scatter Gather list size
2815 pHba->sg_tablesize = (pHba->status_block->inbound_frame_size * 4 -40)/ sizeof(struct sg_simple_element); 3047 if (dpt_dma64(pHba)) {
3048 pHba->sg_tablesize
3049 = ((pHba->status_block->inbound_frame_size * 4
3050 - 14 * sizeof(u32))
3051 / (sizeof(struct sg_simple_element) + sizeof(u32)));
3052 } else {
3053 pHba->sg_tablesize
3054 = ((pHba->status_block->inbound_frame_size * 4
3055 - 12 * sizeof(u32))
3056 / sizeof(struct sg_simple_element));
3057 }
2816 if (pHba->sg_tablesize > SG_LIST_ELEMENTS) { 3058 if (pHba->sg_tablesize > SG_LIST_ELEMENTS) {
2817 pHba->sg_tablesize = SG_LIST_ELEMENTS; 3059 pHba->sg_tablesize = SG_LIST_ELEMENTS;
2818 } 3060 }
@@ -2863,7 +3105,9 @@ static int adpt_i2o_lct_get(adpt_hba* pHba)
2863 } 3105 }
2864 do { 3106 do {
2865 if (pHba->lct == NULL) { 3107 if (pHba->lct == NULL) {
2866 pHba->lct = kmalloc(pHba->lct_size, GFP_KERNEL|ADDR32); 3108 pHba->lct = dma_alloc_coherent(&pHba->pDev->dev,
3109 pHba->lct_size, &pHba->lct_pa,
3110 GFP_KERNEL);
2867 if(pHba->lct == NULL) { 3111 if(pHba->lct == NULL) {
2868 printk(KERN_CRIT "%s: Lct Get failed. Out of memory.\n", 3112 printk(KERN_CRIT "%s: Lct Get failed. Out of memory.\n",
2869 pHba->name); 3113 pHba->name);
@@ -2879,7 +3123,7 @@ static int adpt_i2o_lct_get(adpt_hba* pHba)
2879 msg[4] = 0xFFFFFFFF; /* All devices */ 3123 msg[4] = 0xFFFFFFFF; /* All devices */
2880 msg[5] = 0x00000000; /* Report now */ 3124 msg[5] = 0x00000000; /* Report now */
2881 msg[6] = 0xD0000000|pHba->lct_size; 3125 msg[6] = 0xD0000000|pHba->lct_size;
2882 msg[7] = virt_to_bus(pHba->lct); 3126 msg[7] = (u32)pHba->lct_pa;
2883 3127
2884 if ((ret=adpt_i2o_post_wait(pHba, msg, sizeof(msg), 360))) { 3128 if ((ret=adpt_i2o_post_wait(pHba, msg, sizeof(msg), 360))) {
2885 printk(KERN_ERR "%s: LCT Get failed (status=%#10x.\n", 3129 printk(KERN_ERR "%s: LCT Get failed (status=%#10x.\n",
@@ -2890,7 +3134,8 @@ static int adpt_i2o_lct_get(adpt_hba* pHba)
2890 3134
2891 if ((pHba->lct->table_size << 2) > pHba->lct_size) { 3135 if ((pHba->lct->table_size << 2) > pHba->lct_size) {
2892 pHba->lct_size = pHba->lct->table_size << 2; 3136 pHba->lct_size = pHba->lct->table_size << 2;
2893 kfree(pHba->lct); 3137 dma_free_coherent(&pHba->pDev->dev, pHba->lct_size,
3138 pHba->lct, pHba->lct_pa);
2894 pHba->lct = NULL; 3139 pHba->lct = NULL;
2895 } 3140 }
2896 } while (pHba->lct == NULL); 3141 } while (pHba->lct == NULL);
@@ -2901,13 +3146,19 @@ static int adpt_i2o_lct_get(adpt_hba* pHba)
2901 // I2O_DPT_EXEC_IOP_BUFFERS_GROUP_NO; 3146 // I2O_DPT_EXEC_IOP_BUFFERS_GROUP_NO;
2902 if(adpt_i2o_query_scalar(pHba, 0 , 0x8000, -1, buf, sizeof(buf))>=0) { 3147 if(adpt_i2o_query_scalar(pHba, 0 , 0x8000, -1, buf, sizeof(buf))>=0) {
2903 pHba->FwDebugBufferSize = buf[1]; 3148 pHba->FwDebugBufferSize = buf[1];
2904 pHba->FwDebugBuffer_P = pHba->base_addr_virt + buf[0]; 3149 pHba->FwDebugBuffer_P = ioremap(pHba->base_addr_phys + buf[0],
2905 pHba->FwDebugFlags_P = pHba->FwDebugBuffer_P + FW_DEBUG_FLAGS_OFFSET; 3150 pHba->FwDebugBufferSize);
2906 pHba->FwDebugBLEDvalue_P = pHba->FwDebugBuffer_P + FW_DEBUG_BLED_OFFSET; 3151 if (pHba->FwDebugBuffer_P) {
2907 pHba->FwDebugBLEDflag_P = pHba->FwDebugBLEDvalue_P + 1; 3152 pHba->FwDebugFlags_P = pHba->FwDebugBuffer_P +
2908 pHba->FwDebugStrLength_P = pHba->FwDebugBuffer_P + FW_DEBUG_STR_LENGTH_OFFSET; 3153 FW_DEBUG_FLAGS_OFFSET;
2909 pHba->FwDebugBuffer_P += buf[2]; 3154 pHba->FwDebugBLEDvalue_P = pHba->FwDebugBuffer_P +
2910 pHba->FwDebugFlags = 0; 3155 FW_DEBUG_BLED_OFFSET;
3156 pHba->FwDebugBLEDflag_P = pHba->FwDebugBLEDvalue_P + 1;
3157 pHba->FwDebugStrLength_P = pHba->FwDebugBuffer_P +
3158 FW_DEBUG_STR_LENGTH_OFFSET;
3159 pHba->FwDebugBuffer_P += buf[2];
3160 pHba->FwDebugFlags = 0;
3161 }
2911 } 3162 }
2912 3163
2913 return 0; 3164 return 0;
@@ -2915,25 +3166,30 @@ static int adpt_i2o_lct_get(adpt_hba* pHba)
2915 3166
2916static int adpt_i2o_build_sys_table(void) 3167static int adpt_i2o_build_sys_table(void)
2917{ 3168{
2918 adpt_hba* pHba = NULL; 3169 adpt_hba* pHba = hba_chain;
2919 int count = 0; 3170 int count = 0;
2920 3171
3172 if (sys_tbl)
3173 dma_free_coherent(&pHba->pDev->dev, sys_tbl_len,
3174 sys_tbl, sys_tbl_pa);
3175
2921 sys_tbl_len = sizeof(struct i2o_sys_tbl) + // Header + IOPs 3176 sys_tbl_len = sizeof(struct i2o_sys_tbl) + // Header + IOPs
2922 (hba_count) * sizeof(struct i2o_sys_tbl_entry); 3177 (hba_count) * sizeof(struct i2o_sys_tbl_entry);
2923 3178
2924 kfree(sys_tbl); 3179 sys_tbl = dma_alloc_coherent(&pHba->pDev->dev,
2925 3180 sys_tbl_len, &sys_tbl_pa, GFP_KERNEL);
2926 sys_tbl = kzalloc(sys_tbl_len, GFP_KERNEL|ADDR32);
2927 if (!sys_tbl) { 3181 if (!sys_tbl) {
2928 printk(KERN_WARNING "SysTab Set failed. Out of memory.\n"); 3182 printk(KERN_WARNING "SysTab Set failed. Out of memory.\n");
2929 return -ENOMEM; 3183 return -ENOMEM;
2930 } 3184 }
3185 memset(sys_tbl, 0, sys_tbl_len);
2931 3186
2932 sys_tbl->num_entries = hba_count; 3187 sys_tbl->num_entries = hba_count;
2933 sys_tbl->version = I2OVERSION; 3188 sys_tbl->version = I2OVERSION;
2934 sys_tbl->change_ind = sys_tbl_ind++; 3189 sys_tbl->change_ind = sys_tbl_ind++;
2935 3190
2936 for(pHba = hba_chain; pHba; pHba = pHba->next) { 3191 for(pHba = hba_chain; pHba; pHba = pHba->next) {
3192 u64 addr;
2937 // Get updated Status Block so we have the latest information 3193 // Get updated Status Block so we have the latest information
2938 if (adpt_i2o_status_get(pHba)) { 3194 if (adpt_i2o_status_get(pHba)) {
2939 sys_tbl->num_entries--; 3195 sys_tbl->num_entries--;
@@ -2949,8 +3205,9 @@ static int adpt_i2o_build_sys_table(void)
2949 sys_tbl->iops[count].frame_size = pHba->status_block->inbound_frame_size; 3205 sys_tbl->iops[count].frame_size = pHba->status_block->inbound_frame_size;
2950 sys_tbl->iops[count].last_changed = sys_tbl_ind - 1; // ?? 3206 sys_tbl->iops[count].last_changed = sys_tbl_ind - 1; // ??
2951 sys_tbl->iops[count].iop_capabilities = pHba->status_block->iop_capabilities; 3207 sys_tbl->iops[count].iop_capabilities = pHba->status_block->iop_capabilities;
2952 sys_tbl->iops[count].inbound_low = (u32)virt_to_bus(pHba->post_port); 3208 addr = pHba->base_addr_phys + 0x40;
2953 sys_tbl->iops[count].inbound_high = (u32)((u64)virt_to_bus(pHba->post_port)>>32); 3209 sys_tbl->iops[count].inbound_low = dma_low(addr);
3210 sys_tbl->iops[count].inbound_high = dma_high(addr);
2954 3211
2955 count++; 3212 count++;
2956 } 3213 }
@@ -3086,7 +3343,8 @@ static s32 adpt_i2o_hrt_get(adpt_hba* pHba)
3086 3343
3087 do { 3344 do {
3088 if (pHba->hrt == NULL) { 3345 if (pHba->hrt == NULL) {
3089 pHba->hrt=kmalloc(size, GFP_KERNEL|ADDR32); 3346 pHba->hrt = dma_alloc_coherent(&pHba->pDev->dev,
3347 size, &pHba->hrt_pa, GFP_KERNEL);
3090 if (pHba->hrt == NULL) { 3348 if (pHba->hrt == NULL) {
3091 printk(KERN_CRIT "%s: Hrt Get failed; Out of memory.\n", pHba->name); 3349 printk(KERN_CRIT "%s: Hrt Get failed; Out of memory.\n", pHba->name);
3092 return -ENOMEM; 3350 return -ENOMEM;
@@ -3098,7 +3356,7 @@ static s32 adpt_i2o_hrt_get(adpt_hba* pHba)
3098 msg[2]= 0; 3356 msg[2]= 0;
3099 msg[3]= 0; 3357 msg[3]= 0;
3100 msg[4]= (0xD0000000 | size); /* Simple transaction */ 3358 msg[4]= (0xD0000000 | size); /* Simple transaction */
3101 msg[5]= virt_to_bus(pHba->hrt); /* Dump it here */ 3359 msg[5]= (u32)pHba->hrt_pa; /* Dump it here */
3102 3360
3103 if ((ret = adpt_i2o_post_wait(pHba, msg, sizeof(msg),20))) { 3361 if ((ret = adpt_i2o_post_wait(pHba, msg, sizeof(msg),20))) {
3104 printk(KERN_ERR "%s: Unable to get HRT (status=%#10x)\n", pHba->name, ret); 3362 printk(KERN_ERR "%s: Unable to get HRT (status=%#10x)\n", pHba->name, ret);
@@ -3106,8 +3364,10 @@ static s32 adpt_i2o_hrt_get(adpt_hba* pHba)
3106 } 3364 }
3107 3365
3108 if (pHba->hrt->num_entries * pHba->hrt->entry_len << 2 > size) { 3366 if (pHba->hrt->num_entries * pHba->hrt->entry_len << 2 > size) {
3109 size = pHba->hrt->num_entries * pHba->hrt->entry_len << 2; 3367 int newsize = pHba->hrt->num_entries * pHba->hrt->entry_len << 2;
3110 kfree(pHba->hrt); 3368 dma_free_coherent(&pHba->pDev->dev, size,
3369 pHba->hrt, pHba->hrt_pa);
3370 size = newsize;
3111 pHba->hrt = NULL; 3371 pHba->hrt = NULL;
3112 } 3372 }
3113 } while(pHba->hrt == NULL); 3373 } while(pHba->hrt == NULL);
@@ -3121,33 +3381,54 @@ static int adpt_i2o_query_scalar(adpt_hba* pHba, int tid,
3121 int group, int field, void *buf, int buflen) 3381 int group, int field, void *buf, int buflen)
3122{ 3382{
3123 u16 opblk[] = { 1, 0, I2O_PARAMS_FIELD_GET, group, 1, field }; 3383 u16 opblk[] = { 1, 0, I2O_PARAMS_FIELD_GET, group, 1, field };
3124 u8 *resblk; 3384 u8 *opblk_va;
3385 dma_addr_t opblk_pa;
3386 u8 *resblk_va;
3387 dma_addr_t resblk_pa;
3125 3388
3126 int size; 3389 int size;
3127 3390
3128 /* 8 bytes for header */ 3391 /* 8 bytes for header */
3129 resblk = kmalloc(sizeof(u8) * (8+buflen), GFP_KERNEL|ADDR32); 3392 resblk_va = dma_alloc_coherent(&pHba->pDev->dev,
3130 if (resblk == NULL) { 3393 sizeof(u8) * (8 + buflen), &resblk_pa, GFP_KERNEL);
3394 if (resblk_va == NULL) {
3131 printk(KERN_CRIT "%s: query scalar failed; Out of memory.\n", pHba->name); 3395 printk(KERN_CRIT "%s: query scalar failed; Out of memory.\n", pHba->name);
3132 return -ENOMEM; 3396 return -ENOMEM;
3133 } 3397 }
3134 3398
3399 opblk_va = dma_alloc_coherent(&pHba->pDev->dev,
3400 sizeof(opblk), &opblk_pa, GFP_KERNEL);
3401 if (opblk_va == NULL) {
3402 dma_free_coherent(&pHba->pDev->dev, sizeof(u8) * (8+buflen),
3403 resblk_va, resblk_pa);
3404 printk(KERN_CRIT "%s: query operatio failed; Out of memory.\n",
3405 pHba->name);
3406 return -ENOMEM;
3407 }
3135 if (field == -1) /* whole group */ 3408 if (field == -1) /* whole group */
3136 opblk[4] = -1; 3409 opblk[4] = -1;
3137 3410
3411 memcpy(opblk_va, opblk, sizeof(opblk));
3138 size = adpt_i2o_issue_params(I2O_CMD_UTIL_PARAMS_GET, pHba, tid, 3412 size = adpt_i2o_issue_params(I2O_CMD_UTIL_PARAMS_GET, pHba, tid,
3139 opblk, sizeof(opblk), resblk, sizeof(u8)*(8+buflen)); 3413 opblk_va, opblk_pa, sizeof(opblk),
3414 resblk_va, resblk_pa, sizeof(u8)*(8+buflen));
3415 dma_free_coherent(&pHba->pDev->dev, sizeof(opblk), opblk_va, opblk_pa);
3140 if (size == -ETIME) { 3416 if (size == -ETIME) {
3417 dma_free_coherent(&pHba->pDev->dev, sizeof(u8) * (8+buflen),
3418 resblk_va, resblk_pa);
3141 printk(KERN_WARNING "%s: issue params failed; Timed out.\n", pHba->name); 3419 printk(KERN_WARNING "%s: issue params failed; Timed out.\n", pHba->name);
3142 return -ETIME; 3420 return -ETIME;
3143 } else if (size == -EINTR) { 3421 } else if (size == -EINTR) {
3422 dma_free_coherent(&pHba->pDev->dev, sizeof(u8) * (8+buflen),
3423 resblk_va, resblk_pa);
3144 printk(KERN_WARNING "%s: issue params failed; Interrupted.\n", pHba->name); 3424 printk(KERN_WARNING "%s: issue params failed; Interrupted.\n", pHba->name);
3145 return -EINTR; 3425 return -EINTR;
3146 } 3426 }
3147 3427
3148 memcpy(buf, resblk+8, buflen); /* cut off header */ 3428 memcpy(buf, resblk_va+8, buflen); /* cut off header */
3149 3429
3150 kfree(resblk); 3430 dma_free_coherent(&pHba->pDev->dev, sizeof(u8) * (8+buflen),
3431 resblk_va, resblk_pa);
3151 if (size < 0) 3432 if (size < 0)
3152 return size; 3433 return size;
3153 3434
@@ -3164,10 +3445,11 @@ static int adpt_i2o_query_scalar(adpt_hba* pHba, int tid,
3164 * ResultCount, ErrorInfoSize, BlockStatus and BlockSize. 3445 * ResultCount, ErrorInfoSize, BlockStatus and BlockSize.
3165 */ 3446 */
3166static int adpt_i2o_issue_params(int cmd, adpt_hba* pHba, int tid, 3447static int adpt_i2o_issue_params(int cmd, adpt_hba* pHba, int tid,
3167 void *opblk, int oplen, void *resblk, int reslen) 3448 void *opblk_va, dma_addr_t opblk_pa, int oplen,
3449 void *resblk_va, dma_addr_t resblk_pa, int reslen)
3168{ 3450{
3169 u32 msg[9]; 3451 u32 msg[9];
3170 u32 *res = (u32 *)resblk; 3452 u32 *res = (u32 *)resblk_va;
3171 int wait_status; 3453 int wait_status;
3172 3454
3173 msg[0] = NINE_WORD_MSG_SIZE | SGL_OFFSET_5; 3455 msg[0] = NINE_WORD_MSG_SIZE | SGL_OFFSET_5;
@@ -3176,12 +3458,12 @@ static int adpt_i2o_issue_params(int cmd, adpt_hba* pHba, int tid,
3176 msg[3] = 0; 3458 msg[3] = 0;
3177 msg[4] = 0; 3459 msg[4] = 0;
3178 msg[5] = 0x54000000 | oplen; /* OperationBlock */ 3460 msg[5] = 0x54000000 | oplen; /* OperationBlock */
3179 msg[6] = virt_to_bus(opblk); 3461 msg[6] = (u32)opblk_pa;
3180 msg[7] = 0xD0000000 | reslen; /* ResultBlock */ 3462 msg[7] = 0xD0000000 | reslen; /* ResultBlock */
3181 msg[8] = virt_to_bus(resblk); 3463 msg[8] = (u32)resblk_pa;
3182 3464
3183 if ((wait_status = adpt_i2o_post_wait(pHba, msg, sizeof(msg), 20))) { 3465 if ((wait_status = adpt_i2o_post_wait(pHba, msg, sizeof(msg), 20))) {
3184 printk("adpt_i2o_issue_params: post_wait failed (%p)\n", resblk); 3466 printk("adpt_i2o_issue_params: post_wait failed (%p)\n", resblk_va);
3185 return wait_status; /* -DetailedStatus */ 3467 return wait_status; /* -DetailedStatus */
3186 } 3468 }
3187 3469
@@ -3284,7 +3566,7 @@ static int adpt_i2o_systab_send(adpt_hba* pHba)
3284 * Private i/o space declaration 3566 * Private i/o space declaration
3285 */ 3567 */
3286 msg[6] = 0x54000000 | sys_tbl_len; 3568 msg[6] = 0x54000000 | sys_tbl_len;
3287 msg[7] = virt_to_phys(sys_tbl); 3569 msg[7] = (u32)sys_tbl_pa;
3288 msg[8] = 0x54000000 | 0; 3570 msg[8] = 0x54000000 | 0;
3289 msg[9] = 0; 3571 msg[9] = 0;
3290 msg[10] = 0xD4000000 | 0; 3572 msg[10] = 0xD4000000 | 0;
@@ -3323,11 +3605,10 @@ static static void adpt_delay(int millisec)
3323#endif 3605#endif
3324 3606
3325static struct scsi_host_template driver_template = { 3607static struct scsi_host_template driver_template = {
3608 .module = THIS_MODULE,
3326 .name = "dpt_i2o", 3609 .name = "dpt_i2o",
3327 .proc_name = "dpt_i2o", 3610 .proc_name = "dpt_i2o",
3328 .proc_info = adpt_proc_info, 3611 .proc_info = adpt_proc_info,
3329 .detect = adpt_detect,
3330 .release = adpt_release,
3331 .info = adpt_info, 3612 .info = adpt_info,
3332 .queuecommand = adpt_queue, 3613 .queuecommand = adpt_queue,
3333 .eh_abort_handler = adpt_abort, 3614 .eh_abort_handler = adpt_abort,
@@ -3341,5 +3622,48 @@ static struct scsi_host_template driver_template = {
3341 .cmd_per_lun = 1, 3622 .cmd_per_lun = 1,
3342 .use_clustering = ENABLE_CLUSTERING, 3623 .use_clustering = ENABLE_CLUSTERING,
3343}; 3624};
3344#include "scsi_module.c" 3625
3626static int __init adpt_init(void)
3627{
3628 int error;
3629 adpt_hba *pHba, *next;
3630
3631 printk("Loading Adaptec I2O RAID: Version " DPT_I2O_VERSION "\n");
3632
3633 error = adpt_detect(&driver_template);
3634 if (error < 0)
3635 return error;
3636 if (hba_chain == NULL)
3637 return -ENODEV;
3638
3639 for (pHba = hba_chain; pHba; pHba = pHba->next) {
3640 error = scsi_add_host(pHba->host, &pHba->pDev->dev);
3641 if (error)
3642 goto fail;
3643 scsi_scan_host(pHba->host);
3644 }
3645 return 0;
3646fail:
3647 for (pHba = hba_chain; pHba; pHba = next) {
3648 next = pHba->next;
3649 scsi_remove_host(pHba->host);
3650 }
3651 return error;
3652}
3653
3654static void __exit adpt_exit(void)
3655{
3656 adpt_hba *pHba, *next;
3657
3658 for (pHba = hba_chain; pHba; pHba = pHba->next)
3659 scsi_remove_host(pHba->host);
3660 for (pHba = hba_chain; pHba; pHba = next) {
3661 next = pHba->next;
3662 adpt_release(pHba->host);
3663 }
3664}
3665
3666module_init(adpt_init);
3667module_exit(adpt_exit);
3668
3345MODULE_LICENSE("GPL"); 3669MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/dpti.h b/drivers/scsi/dpti.h
index fd79068c5869..924cd5a51676 100644
--- a/drivers/scsi/dpti.h
+++ b/drivers/scsi/dpti.h
@@ -84,7 +84,6 @@ static int adpt_device_reset(struct scsi_cmnd* cmd);
84#define PCI_DPT_DEVICE_ID (0xA501) // DPT PCI I2O Device ID 84#define PCI_DPT_DEVICE_ID (0xA501) // DPT PCI I2O Device ID
85#define PCI_DPT_RAPTOR_DEVICE_ID (0xA511) 85#define PCI_DPT_RAPTOR_DEVICE_ID (0xA511)
86 86
87//#define REBOOT_NOTIFIER 1
88/* Debugging macro from Linux Device Drivers - Rubini */ 87/* Debugging macro from Linux Device Drivers - Rubini */
89#undef PDEBUG 88#undef PDEBUG
90#ifdef DEBUG 89#ifdef DEBUG
@@ -229,14 +228,19 @@ typedef struct _adpt_hba {
229 u32 post_fifo_size; 228 u32 post_fifo_size;
230 u32 reply_fifo_size; 229 u32 reply_fifo_size;
231 u32* reply_pool; 230 u32* reply_pool;
231 dma_addr_t reply_pool_pa;
232 u32 sg_tablesize; // Scatter/Gather List Size. 232 u32 sg_tablesize; // Scatter/Gather List Size.
233 u8 top_scsi_channel; 233 u8 top_scsi_channel;
234 u8 top_scsi_id; 234 u8 top_scsi_id;
235 u8 top_scsi_lun; 235 u8 top_scsi_lun;
236 u8 dma64;
236 237
237 i2o_status_block* status_block; 238 i2o_status_block* status_block;
239 dma_addr_t status_block_pa;
238 i2o_hrt* hrt; 240 i2o_hrt* hrt;
241 dma_addr_t hrt_pa;
239 i2o_lct* lct; 242 i2o_lct* lct;
243 dma_addr_t lct_pa;
240 uint lct_size; 244 uint lct_size;
241 struct i2o_device* devices; 245 struct i2o_device* devices;
242 struct adpt_channel channel[MAX_CHANNEL]; 246 struct adpt_channel channel[MAX_CHANNEL];
@@ -249,6 +253,7 @@ typedef struct _adpt_hba {
249 void __iomem *FwDebugBLEDflag_P;// Virtual Addr Of FW Debug BLED 253 void __iomem *FwDebugBLEDflag_P;// Virtual Addr Of FW Debug BLED
250 void __iomem *FwDebugBLEDvalue_P;// Virtual Addr Of FW Debug BLED 254 void __iomem *FwDebugBLEDvalue_P;// Virtual Addr Of FW Debug BLED
251 u32 FwDebugFlags; 255 u32 FwDebugFlags;
256 u32 *ioctl_reply_context[4];
252} adpt_hba; 257} adpt_hba;
253 258
254struct sg_simple_element { 259struct sg_simple_element {
@@ -264,9 +269,6 @@ static void adpt_i2o_sys_shutdown(void);
264static int adpt_init(void); 269static int adpt_init(void);
265static int adpt_i2o_build_sys_table(void); 270static int adpt_i2o_build_sys_table(void);
266static irqreturn_t adpt_isr(int irq, void *dev_id); 271static irqreturn_t adpt_isr(int irq, void *dev_id);
267#ifdef REBOOT_NOTIFIER
268static int adpt_reboot_event(struct notifier_block *n, ulong code, void *p);
269#endif
270 272
271static void adpt_i2o_report_hba_unit(adpt_hba* pHba, struct i2o_device *d); 273static void adpt_i2o_report_hba_unit(adpt_hba* pHba, struct i2o_device *d);
272static int adpt_i2o_query_scalar(adpt_hba* pHba, int tid, 274static int adpt_i2o_query_scalar(adpt_hba* pHba, int tid,
@@ -275,7 +277,8 @@ static int adpt_i2o_query_scalar(adpt_hba* pHba, int tid,
275static const char *adpt_i2o_get_class_name(int class); 277static const char *adpt_i2o_get_class_name(int class);
276#endif 278#endif
277static int adpt_i2o_issue_params(int cmd, adpt_hba* pHba, int tid, 279static int adpt_i2o_issue_params(int cmd, adpt_hba* pHba, int tid,
278 void *opblk, int oplen, void *resblk, int reslen); 280 void *opblk, dma_addr_t opblk_pa, int oplen,
281 void *resblk, dma_addr_t resblk_pa, int reslen);
279static int adpt_i2o_post_wait(adpt_hba* pHba, u32* msg, int len, int timeout); 282static int adpt_i2o_post_wait(adpt_hba* pHba, u32* msg, int len, int timeout);
280static int adpt_i2o_lct_get(adpt_hba* pHba); 283static int adpt_i2o_lct_get(adpt_hba* pHba);
281static int adpt_i2o_parse_lct(adpt_hba* pHba); 284static int adpt_i2o_parse_lct(adpt_hba* pHba);
@@ -289,7 +292,7 @@ static s32 adpt_i2o_init_outbound_q(adpt_hba* pHba);
289static s32 adpt_i2o_hrt_get(adpt_hba* pHba); 292static s32 adpt_i2o_hrt_get(adpt_hba* pHba);
290static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_device* dptdevice); 293static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_device* dptdevice);
291static s32 adpt_i2o_to_scsi(void __iomem *reply, struct scsi_cmnd* cmd); 294static s32 adpt_i2o_to_scsi(void __iomem *reply, struct scsi_cmnd* cmd);
292static s32 adpt_scsi_register(adpt_hba* pHba,struct scsi_host_template * sht); 295static s32 adpt_scsi_host_alloc(adpt_hba* pHba,struct scsi_host_template * sht);
293static s32 adpt_hba_reset(adpt_hba* pHba); 296static s32 adpt_hba_reset(adpt_hba* pHba);
294static s32 adpt_i2o_reset_hba(adpt_hba* pHba); 297static s32 adpt_i2o_reset_hba(adpt_hba* pHba);
295static s32 adpt_rescan(adpt_hba* pHba); 298static s32 adpt_rescan(adpt_hba* pHba);
diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index c6d6e7c6559a..8e2e964af668 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -465,7 +465,7 @@ int __gdth_execute(struct scsi_device *sdev, gdth_cmd_str *gdtcmd, char *cmnd,
465 scp->request = (struct request *)&wait; 465 scp->request = (struct request *)&wait;
466 scp->timeout_per_command = timeout*HZ; 466 scp->timeout_per_command = timeout*HZ;
467 scp->cmd_len = 12; 467 scp->cmd_len = 12;
468 memcpy(scp->cmnd, cmnd, 12); 468 scp->cmnd = cmnd;
469 cmndinfo.priority = IOCTL_PRI; 469 cmndinfo.priority = IOCTL_PRI;
470 cmndinfo.internal_cmd_str = gdtcmd; 470 cmndinfo.internal_cmd_str = gdtcmd;
471 cmndinfo.internal_command = 1; 471 cmndinfo.internal_command = 1;
diff --git a/drivers/scsi/hptiop.c b/drivers/scsi/hptiop.c
index 5b7be1e9841c..aaa48e0c8ed0 100644
--- a/drivers/scsi/hptiop.c
+++ b/drivers/scsi/hptiop.c
@@ -763,9 +763,9 @@ static int hptiop_queuecommand(struct scsi_cmnd *scp,
763 scp, 763 scp,
764 host->host_no, scp->device->channel, 764 host->host_no, scp->device->channel,
765 scp->device->id, scp->device->lun, 765 scp->device->id, scp->device->lun,
766 *((u32 *)&scp->cmnd), 766 ((u32 *)scp->cmnd)[0],
767 *((u32 *)&scp->cmnd + 1), 767 ((u32 *)scp->cmnd)[1],
768 *((u32 *)&scp->cmnd + 2), 768 ((u32 *)scp->cmnd)[2],
769 _req->index, _req->req_virt); 769 _req->index, _req->req_virt);
770 770
771 scp->result = 0; 771 scp->result = 0;
diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.c b/drivers/scsi/ibmvscsi/ibmvscsi.c
index 4a922c57125e..ccfd8aca3765 100644
--- a/drivers/scsi/ibmvscsi/ibmvscsi.c
+++ b/drivers/scsi/ibmvscsi/ibmvscsi.c
@@ -686,7 +686,7 @@ static void handle_cmd_rsp(struct srp_event_struct *evt_struct)
686 } 686 }
687 687
688 if (cmnd) { 688 if (cmnd) {
689 cmnd->result = rsp->status; 689 cmnd->result |= rsp->status;
690 if (((cmnd->result >> 1) & 0x1f) == CHECK_CONDITION) 690 if (((cmnd->result >> 1) & 0x1f) == CHECK_CONDITION)
691 memcpy(cmnd->sense_buffer, 691 memcpy(cmnd->sense_buffer,
692 rsp->data, 692 rsp->data,
@@ -730,6 +730,7 @@ static int ibmvscsi_queuecommand(struct scsi_cmnd *cmnd,
730 u16 lun = lun_from_dev(cmnd->device); 730 u16 lun = lun_from_dev(cmnd->device);
731 u8 out_fmt, in_fmt; 731 u8 out_fmt, in_fmt;
732 732
733 cmnd->result = (DID_OK << 16);
733 evt_struct = get_event_struct(&hostdata->pool); 734 evt_struct = get_event_struct(&hostdata->pool);
734 if (!evt_struct) 735 if (!evt_struct)
735 return SCSI_MLQUEUE_HOST_BUSY; 736 return SCSI_MLQUEUE_HOST_BUSY;
@@ -738,7 +739,7 @@ static int ibmvscsi_queuecommand(struct scsi_cmnd *cmnd,
738 srp_cmd = &evt_struct->iu.srp.cmd; 739 srp_cmd = &evt_struct->iu.srp.cmd;
739 memset(srp_cmd, 0x00, SRP_MAX_IU_LEN); 740 memset(srp_cmd, 0x00, SRP_MAX_IU_LEN);
740 srp_cmd->opcode = SRP_CMD; 741 srp_cmd->opcode = SRP_CMD;
741 memcpy(srp_cmd->cdb, cmnd->cmnd, sizeof(cmnd->cmnd)); 742 memcpy(srp_cmd->cdb, cmnd->cmnd, sizeof(srp_cmd->cdb));
742 srp_cmd->lun = ((u64) lun) << 48; 743 srp_cmd->lun = ((u64) lun) << 48;
743 744
744 if (!map_data_for_srp_cmd(cmnd, evt_struct, srp_cmd, hostdata->dev)) { 745 if (!map_data_for_srp_cmd(cmnd, evt_struct, srp_cmd, hostdata->dev)) {
@@ -1347,6 +1348,8 @@ void ibmvscsi_handle_crq(struct viosrp_crq *crq,
1347 1348
1348 del_timer(&evt_struct->timer); 1349 del_timer(&evt_struct->timer);
1349 1350
1351 if (crq->status != VIOSRP_OK && evt_struct->cmnd)
1352 evt_struct->cmnd->result = DID_ERROR << 16;
1350 if (evt_struct->done) 1353 if (evt_struct->done)
1351 evt_struct->done(evt_struct); 1354 evt_struct->done(evt_struct);
1352 else 1355 else
diff --git a/drivers/scsi/ibmvscsi/viosrp.h b/drivers/scsi/ibmvscsi/viosrp.h
index 90f1a61283ad..4c4aadb3e405 100644
--- a/drivers/scsi/ibmvscsi/viosrp.h
+++ b/drivers/scsi/ibmvscsi/viosrp.h
@@ -59,6 +59,15 @@ enum viosrp_crq_formats {
59 VIOSRP_INLINE_FORMAT = 0x07 59 VIOSRP_INLINE_FORMAT = 0x07
60}; 60};
61 61
62enum viosrp_crq_status {
63 VIOSRP_OK = 0x0,
64 VIOSRP_NONRECOVERABLE_ERR = 0x1,
65 VIOSRP_VIOLATES_MAX_XFER = 0x2,
66 VIOSRP_PARTNER_PANIC = 0x3,
67 VIOSRP_DEVICE_BUSY = 0x8,
68 VIOSRP_ADAPTER_FAIL = 0x10
69};
70
62struct viosrp_crq { 71struct viosrp_crq {
63 u8 valid; /* used by RPA */ 72 u8 valid; /* used by RPA */
64 u8 format; /* SCSI vs out-of-band */ 73 u8 format; /* SCSI vs out-of-band */
diff --git a/drivers/scsi/initio.c b/drivers/scsi/initio.c
index dbae3fdb8506..e3f739776bad 100644
--- a/drivers/scsi/initio.c
+++ b/drivers/scsi/initio.c
@@ -2590,7 +2590,7 @@ static void initio_build_scb(struct initio_host * host, struct scsi_ctrl_blk * c
2590 cblk->hastat = 0; 2590 cblk->hastat = 0;
2591 cblk->tastat = 0; 2591 cblk->tastat = 0;
2592 /* Command the command */ 2592 /* Command the command */
2593 memcpy(&cblk->cdb[0], &cmnd->cmnd, cmnd->cmd_len); 2593 memcpy(cblk->cdb, cmnd->cmnd, cmnd->cmd_len);
2594 2594
2595 /* Set up tags */ 2595 /* Set up tags */
2596 if (cmnd->device->tagged_supported) { /* Tag Support */ 2596 if (cmnd->device->tagged_supported) { /* Tag Support */
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index de5ae6a65029..999e91ea7451 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -2791,7 +2791,7 @@ static ssize_t ipr_store_adapter_state(struct device *dev,
2791 2791
2792static struct device_attribute ipr_ioa_state_attr = { 2792static struct device_attribute ipr_ioa_state_attr = {
2793 .attr = { 2793 .attr = {
2794 .name = "state", 2794 .name = "online_state",
2795 .mode = S_IRUGO | S_IWUSR, 2795 .mode = S_IRUGO | S_IWUSR,
2796 }, 2796 },
2797 .show = ipr_show_adapter_state, 2797 .show = ipr_show_adapter_state,
diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
index 820f91fb63ba..70a0f11f48b2 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -3168,6 +3168,23 @@ megaraid_mbox_support_random_del(adapter_t *adapter)
3168 uint8_t raw_mbox[sizeof(mbox_t)]; 3168 uint8_t raw_mbox[sizeof(mbox_t)];
3169 int rval; 3169 int rval;
3170 3170
3171 /*
3172 * Newer firmware on Dell CERC expect a different
3173 * random deletion handling, so disable it.
3174 */
3175 if (adapter->pdev->vendor == PCI_VENDOR_ID_AMI &&
3176 adapter->pdev->device == PCI_DEVICE_ID_AMI_MEGARAID3 &&
3177 adapter->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL &&
3178 adapter->pdev->subsystem_device == PCI_SUBSYS_ID_CERC_ATA100_4CH &&
3179 (adapter->fw_version[0] > '6' ||
3180 (adapter->fw_version[0] == '6' &&
3181 adapter->fw_version[2] > '6') ||
3182 (adapter->fw_version[0] == '6'
3183 && adapter->fw_version[2] == '6'
3184 && adapter->fw_version[3] > '1'))) {
3185 con_log(CL_DLEVEL1, ("megaraid: disable random deletion\n"));
3186 return 0;
3187 }
3171 3188
3172 mbox = (mbox_t *)raw_mbox; 3189 mbox = (mbox_t *)raw_mbox;
3173 3190
diff --git a/drivers/scsi/megaraid/megaraid_mbox.h b/drivers/scsi/megaraid/megaraid_mbox.h
index 626459d1e902..c1d86d961a92 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.h
+++ b/drivers/scsi/megaraid/megaraid_mbox.h
@@ -88,6 +88,7 @@
88#define PCI_SUBSYS_ID_PERC3_QC 0x0471 88#define PCI_SUBSYS_ID_PERC3_QC 0x0471
89#define PCI_SUBSYS_ID_PERC3_DC 0x0493 89#define PCI_SUBSYS_ID_PERC3_DC 0x0493
90#define PCI_SUBSYS_ID_PERC3_SC 0x0475 90#define PCI_SUBSYS_ID_PERC3_SC 0x0475
91#define PCI_SUBSYS_ID_CERC_ATA100_4CH 0x0511
91 92
92 93
93#define MBOX_MAX_SCSI_CMDS 128 // number of cmds reserved for kernel 94#define MBOX_MAX_SCSI_CMDS 128 // number of cmds reserved for kernel
diff --git a/drivers/scsi/megaraid/megaraid_sas.c b/drivers/scsi/megaraid/megaraid_sas.c
index b937e9cddb23..7d84c8bbcf3f 100644
--- a/drivers/scsi/megaraid/megaraid_sas.c
+++ b/drivers/scsi/megaraid/megaraid_sas.c
@@ -10,7 +10,7 @@
10 * 2 of the License, or (at your option) any later version. 10 * 2 of the License, or (at your option) any later version.
11 * 11 *
12 * FILE : megaraid_sas.c 12 * FILE : megaraid_sas.c
13 * Version : v00.00.03.16-rc1 13 * Version : v00.00.03.20-rc1
14 * 14 *
15 * Authors: 15 * Authors:
16 * (email-id : megaraidlinux@lsi.com) 16 * (email-id : megaraidlinux@lsi.com)
@@ -2650,12 +2650,13 @@ static void megasas_shutdown_controller(struct megasas_instance *instance,
2650 return; 2650 return;
2651} 2651}
2652 2652
2653#ifdef CONFIG_PM
2653/** 2654/**
2654 * megasas_suspend - driver suspend entry point 2655 * megasas_suspend - driver suspend entry point
2655 * @pdev: PCI device structure 2656 * @pdev: PCI device structure
2656 * @state: PCI power state to suspend routine 2657 * @state: PCI power state to suspend routine
2657 */ 2658 */
2658static int __devinit 2659static int
2659megasas_suspend(struct pci_dev *pdev, pm_message_t state) 2660megasas_suspend(struct pci_dev *pdev, pm_message_t state)
2660{ 2661{
2661 struct Scsi_Host *host; 2662 struct Scsi_Host *host;
@@ -2687,7 +2688,7 @@ megasas_suspend(struct pci_dev *pdev, pm_message_t state)
2687 * megasas_resume- driver resume entry point 2688 * megasas_resume- driver resume entry point
2688 * @pdev: PCI device structure 2689 * @pdev: PCI device structure
2689 */ 2690 */
2690static int __devinit 2691static int
2691megasas_resume(struct pci_dev *pdev) 2692megasas_resume(struct pci_dev *pdev)
2692{ 2693{
2693 int rval; 2694 int rval;
@@ -2782,12 +2783,16 @@ fail_ready_state:
2782 2783
2783 return -ENODEV; 2784 return -ENODEV;
2784} 2785}
2786#else
2787#define megasas_suspend NULL
2788#define megasas_resume NULL
2789#endif
2785 2790
2786/** 2791/**
2787 * megasas_detach_one - PCI hot"un"plug entry point 2792 * megasas_detach_one - PCI hot"un"plug entry point
2788 * @pdev: PCI device structure 2793 * @pdev: PCI device structure
2789 */ 2794 */
2790static void megasas_detach_one(struct pci_dev *pdev) 2795static void __devexit megasas_detach_one(struct pci_dev *pdev)
2791{ 2796{
2792 int i; 2797 int i;
2793 struct Scsi_Host *host; 2798 struct Scsi_Host *host;
diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index 3a997eb457bf..b0c41e671702 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -18,9 +18,9 @@
18/* 18/*
19 * MegaRAID SAS Driver meta data 19 * MegaRAID SAS Driver meta data
20 */ 20 */
21#define MEGASAS_VERSION "00.00.03.16-rc1" 21#define MEGASAS_VERSION "00.00.03.20-rc1"
22#define MEGASAS_RELDATE "Nov. 07, 2007" 22#define MEGASAS_RELDATE "March 10, 2008"
23#define MEGASAS_EXT_VERSION "Thu. Nov. 07 10:09:32 PDT 2007" 23#define MEGASAS_EXT_VERSION "Mon. March 10 11:02:31 PDT 2008"
24 24
25/* 25/*
26 * Device IDs 26 * Device IDs
diff --git a/drivers/scsi/mvsas.c b/drivers/scsi/mvsas.c
index e55b9037adb2..1dd70d7a4947 100644
--- a/drivers/scsi/mvsas.c
+++ b/drivers/scsi/mvsas.c
@@ -2822,7 +2822,9 @@ static void mvs_update_phyinfo(struct mvs_info *mvi, int i,
2822 dev_printk(KERN_DEBUG, &pdev->dev, 2822 dev_printk(KERN_DEBUG, &pdev->dev,
2823 "phy[%d] Get Attached Address 0x%llX ," 2823 "phy[%d] Get Attached Address 0x%llX ,"
2824 " SAS Address 0x%llX\n", 2824 " SAS Address 0x%llX\n",
2825 i, phy->att_dev_sas_addr, phy->dev_sas_addr); 2825 i,
2826 (unsigned long long)phy->att_dev_sas_addr,
2827 (unsigned long long)phy->dev_sas_addr);
2826 dev_printk(KERN_DEBUG, &pdev->dev, 2828 dev_printk(KERN_DEBUG, &pdev->dev,
2827 "Rate = %x , type = %d\n", 2829 "Rate = %x , type = %d\n",
2828 sas_phy->linkrate, phy->phy_type); 2830 sas_phy->linkrate, phy->phy_type);
diff --git a/drivers/scsi/ncr53c8xx.c b/drivers/scsi/ncr53c8xx.c
index ceab4f73caf1..c57c94c0ffd2 100644
--- a/drivers/scsi/ncr53c8xx.c
+++ b/drivers/scsi/ncr53c8xx.c
@@ -8222,7 +8222,7 @@ static void process_waiting_list(struct ncb *np, int sts)
8222#ifdef DEBUG_WAITING_LIST 8222#ifdef DEBUG_WAITING_LIST
8223 if (waiting_list) printk("%s: waiting_list=%lx processing sts=%d\n", ncr_name(np), (u_long) waiting_list, sts); 8223 if (waiting_list) printk("%s: waiting_list=%lx processing sts=%d\n", ncr_name(np), (u_long) waiting_list, sts);
8224#endif 8224#endif
8225 while (wcmd = waiting_list) { 8225 while ((wcmd = waiting_list) != NULL) {
8226 waiting_list = (struct scsi_cmnd *) wcmd->next_wcmd; 8226 waiting_list = (struct scsi_cmnd *) wcmd->next_wcmd;
8227 wcmd->next_wcmd = NULL; 8227 wcmd->next_wcmd = NULL;
8228 if (sts == DID_OK) { 8228 if (sts == DID_OK) {
diff --git a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c
index 09ab3eac1c1a..fa060932d2b4 100644
--- a/drivers/scsi/qla1280.c
+++ b/drivers/scsi/qla1280.c
@@ -2858,7 +2858,7 @@ qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
2858 2858
2859 /* Load SCSI command packet. */ 2859 /* Load SCSI command packet. */
2860 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd)); 2860 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
2861 memcpy(pkt->scsi_cdb, &(CMD_CDBP(cmd)), CMD_CDBLEN(cmd)); 2861 memcpy(pkt->scsi_cdb, CMD_CDBP(cmd), CMD_CDBLEN(cmd));
2862 /* dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */ 2862 /* dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
2863 2863
2864 /* Set transfer direction. */ 2864 /* Set transfer direction. */
@@ -3127,7 +3127,7 @@ qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
3127 3127
3128 /* Load SCSI command packet. */ 3128 /* Load SCSI command packet. */
3129 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd)); 3129 pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
3130 memcpy(pkt->scsi_cdb, &(CMD_CDBP(cmd)), CMD_CDBLEN(cmd)); 3130 memcpy(pkt->scsi_cdb, CMD_CDBP(cmd), CMD_CDBLEN(cmd));
3131 3131
3132 /*dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */ 3132 /*dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
3133 /* Set transfer direction. */ 3133 /* Set transfer direction. */
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 12d69d7c8577..110e776d1a07 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -79,15 +79,6 @@ static void scsi_done(struct scsi_cmnd *cmd);
79#define MIN_RESET_PERIOD (15*HZ) 79#define MIN_RESET_PERIOD (15*HZ)
80 80
81/* 81/*
82 * Macro to determine the size of SCSI command. This macro takes vendor
83 * unique commands into account. SCSI commands in groups 6 and 7 are
84 * vendor unique and we will depend upon the command length being
85 * supplied correctly in cmd_len.
86 */
87#define CDB_SIZE(cmd) (((((cmd)->cmnd[0] >> 5) & 7) < 6) ? \
88 COMMAND_SIZE((cmd)->cmnd[0]) : (cmd)->cmd_len)
89
90/*
91 * Note - the initial logging level can be set here to log events at boot time. 82 * Note - the initial logging level can be set here to log events at boot time.
92 * After the system is up, you may enable logging via the /proc interface. 83 * After the system is up, you may enable logging via the /proc interface.
93 */ 84 */
@@ -469,6 +460,7 @@ int scsi_setup_command_freelist(struct Scsi_Host *shost)
469 cmd = scsi_pool_alloc_command(shost->cmd_pool, gfp_mask); 460 cmd = scsi_pool_alloc_command(shost->cmd_pool, gfp_mask);
470 if (!cmd) { 461 if (!cmd) {
471 scsi_put_host_cmd_pool(gfp_mask); 462 scsi_put_host_cmd_pool(gfp_mask);
463 shost->cmd_pool = NULL;
472 return -ENOMEM; 464 return -ENOMEM;
473 } 465 }
474 list_add(&cmd->list, &shost->free_list); 466 list_add(&cmd->list, &shost->free_list);
@@ -481,6 +473,13 @@ int scsi_setup_command_freelist(struct Scsi_Host *shost)
481 */ 473 */
482void scsi_destroy_command_freelist(struct Scsi_Host *shost) 474void scsi_destroy_command_freelist(struct Scsi_Host *shost)
483{ 475{
476 /*
477 * If cmd_pool is NULL the free list was not initialized, so
478 * do not attempt to release resources.
479 */
480 if (!shost->cmd_pool)
481 return;
482
484 while (!list_empty(&shost->free_list)) { 483 while (!list_empty(&shost->free_list)) {
485 struct scsi_cmnd *cmd; 484 struct scsi_cmnd *cmd;
486 485
@@ -701,9 +700,11 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
701 * Before we queue this command, check if the command 700 * Before we queue this command, check if the command
702 * length exceeds what the host adapter can handle. 701 * length exceeds what the host adapter can handle.
703 */ 702 */
704 if (CDB_SIZE(cmd) > cmd->device->host->max_cmd_len) { 703 if (cmd->cmd_len > cmd->device->host->max_cmd_len) {
705 SCSI_LOG_MLQUEUE(3, 704 SCSI_LOG_MLQUEUE(3,
706 printk("queuecommand : command too long.\n")); 705 printk("queuecommand : command too long. "
706 "cdb_size=%d host->max_cmd_len=%d\n",
707 cmd->cmd_len, cmd->device->host->max_cmd_len));
707 cmd->result = (DID_ABORT << 16); 708 cmd->result = (DID_ABORT << 16);
708 709
709 scsi_done(cmd); 710 scsi_done(cmd);
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 1eaba6cd80f4..eaf5a8add1ba 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -626,7 +626,7 @@ static void scsi_abort_eh_cmnd(struct scsi_cmnd *scmd)
626 * @scmd: SCSI command structure to hijack 626 * @scmd: SCSI command structure to hijack
627 * @ses: structure to save restore information 627 * @ses: structure to save restore information
628 * @cmnd: CDB to send. Can be NULL if no new cmnd is needed 628 * @cmnd: CDB to send. Can be NULL if no new cmnd is needed
629 * @cmnd_size: size in bytes of @cmnd 629 * @cmnd_size: size in bytes of @cmnd (must be <= BLK_MAX_CDB)
630 * @sense_bytes: size of sense data to copy. or 0 (if != 0 @cmnd is ignored) 630 * @sense_bytes: size of sense data to copy. or 0 (if != 0 @cmnd is ignored)
631 * 631 *
632 * This function is used to save a scsi command information before re-execution 632 * This function is used to save a scsi command information before re-execution
@@ -648,12 +648,14 @@ void scsi_eh_prep_cmnd(struct scsi_cmnd *scmd, struct scsi_eh_save *ses,
648 * command. 648 * command.
649 */ 649 */
650 ses->cmd_len = scmd->cmd_len; 650 ses->cmd_len = scmd->cmd_len;
651 memcpy(ses->cmnd, scmd->cmnd, sizeof(scmd->cmnd)); 651 ses->cmnd = scmd->cmnd;
652 ses->data_direction = scmd->sc_data_direction; 652 ses->data_direction = scmd->sc_data_direction;
653 ses->sdb = scmd->sdb; 653 ses->sdb = scmd->sdb;
654 ses->next_rq = scmd->request->next_rq; 654 ses->next_rq = scmd->request->next_rq;
655 ses->result = scmd->result; 655 ses->result = scmd->result;
656 656
657 scmd->cmnd = ses->eh_cmnd;
658 memset(scmd->cmnd, 0, BLK_MAX_CDB);
657 memset(&scmd->sdb, 0, sizeof(scmd->sdb)); 659 memset(&scmd->sdb, 0, sizeof(scmd->sdb));
658 scmd->request->next_rq = NULL; 660 scmd->request->next_rq = NULL;
659 661
@@ -665,14 +667,13 @@ void scsi_eh_prep_cmnd(struct scsi_cmnd *scmd, struct scsi_eh_save *ses,
665 scmd->sdb.table.sgl = &ses->sense_sgl; 667 scmd->sdb.table.sgl = &ses->sense_sgl;
666 scmd->sc_data_direction = DMA_FROM_DEVICE; 668 scmd->sc_data_direction = DMA_FROM_DEVICE;
667 scmd->sdb.table.nents = 1; 669 scmd->sdb.table.nents = 1;
668 memset(scmd->cmnd, 0, sizeof(scmd->cmnd));
669 scmd->cmnd[0] = REQUEST_SENSE; 670 scmd->cmnd[0] = REQUEST_SENSE;
670 scmd->cmnd[4] = scmd->sdb.length; 671 scmd->cmnd[4] = scmd->sdb.length;
671 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]); 672 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
672 } else { 673 } else {
673 scmd->sc_data_direction = DMA_NONE; 674 scmd->sc_data_direction = DMA_NONE;
674 if (cmnd) { 675 if (cmnd) {
675 memset(scmd->cmnd, 0, sizeof(scmd->cmnd)); 676 BUG_ON(cmnd_size > BLK_MAX_CDB);
676 memcpy(scmd->cmnd, cmnd, cmnd_size); 677 memcpy(scmd->cmnd, cmnd, cmnd_size);
677 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]); 678 scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
678 } 679 }
@@ -705,7 +706,7 @@ void scsi_eh_restore_cmnd(struct scsi_cmnd* scmd, struct scsi_eh_save *ses)
705 * Restore original data 706 * Restore original data
706 */ 707 */
707 scmd->cmd_len = ses->cmd_len; 708 scmd->cmd_len = ses->cmd_len;
708 memcpy(scmd->cmnd, ses->cmnd, sizeof(scmd->cmnd)); 709 scmd->cmnd = ses->cmnd;
709 scmd->sc_data_direction = ses->data_direction; 710 scmd->sc_data_direction = ses->data_direction;
710 scmd->sdb = ses->sdb; 711 scmd->sdb = ses->sdb;
711 scmd->request->next_rq = ses->next_rq; 712 scmd->request->next_rq = ses->next_rq;
@@ -1775,8 +1776,8 @@ scsi_reset_provider(struct scsi_device *dev, int flag)
1775 scmd->request = &req; 1776 scmd->request = &req;
1776 memset(&scmd->eh_timeout, 0, sizeof(scmd->eh_timeout)); 1777 memset(&scmd->eh_timeout, 0, sizeof(scmd->eh_timeout));
1777 1778
1778 memset(&scmd->cmnd, '\0', sizeof(scmd->cmnd)); 1779 scmd->cmnd = req.cmd;
1779 1780
1780 scmd->scsi_done = scsi_reset_provider_done_command; 1781 scmd->scsi_done = scsi_reset_provider_done_command;
1781 memset(&scmd->sdb, 0, sizeof(scmd->sdb)); 1782 memset(&scmd->sdb, 0, sizeof(scmd->sdb));
1782 1783
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index d545ad1cf47a..a82d2fe80fb5 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -445,7 +445,7 @@ static void scsi_init_cmd_errh(struct scsi_cmnd *cmd)
445 scsi_set_resid(cmd, 0); 445 scsi_set_resid(cmd, 0);
446 memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); 446 memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
447 if (cmd->cmd_len == 0) 447 if (cmd->cmd_len == 0)
448 cmd->cmd_len = COMMAND_SIZE(cmd->cmnd[0]); 448 cmd->cmd_len = scsi_command_size(cmd->cmnd);
449} 449}
450 450
451void scsi_device_unbusy(struct scsi_device *sdev) 451void scsi_device_unbusy(struct scsi_device *sdev)
@@ -1094,6 +1094,8 @@ static struct scsi_cmnd *scsi_get_cmd_from_req(struct scsi_device *sdev,
1094 cmd->tag = req->tag; 1094 cmd->tag = req->tag;
1095 cmd->request = req; 1095 cmd->request = req;
1096 1096
1097 cmd->cmnd = req->cmd;
1098
1097 return cmd; 1099 return cmd;
1098} 1100}
1099 1101
@@ -1131,8 +1133,6 @@ int scsi_setup_blk_pc_cmnd(struct scsi_device *sdev, struct request *req)
1131 req->buffer = NULL; 1133 req->buffer = NULL;
1132 } 1134 }
1133 1135
1134 BUILD_BUG_ON(sizeof(req->cmd) > sizeof(cmd->cmnd));
1135 memcpy(cmd->cmnd, req->cmd, sizeof(cmd->cmnd));
1136 cmd->cmd_len = req->cmd_len; 1136 cmd->cmd_len = req->cmd_len;
1137 if (!req->data_len) 1137 if (!req->data_len)
1138 cmd->sc_data_direction = DMA_NONE; 1138 cmd->sc_data_direction = DMA_NONE;
@@ -1169,6 +1169,7 @@ int scsi_setup_fs_cmnd(struct scsi_device *sdev, struct request *req)
1169 if (unlikely(!cmd)) 1169 if (unlikely(!cmd))
1170 return BLKPREP_DEFER; 1170 return BLKPREP_DEFER;
1171 1171
1172 memset(cmd->cmnd, 0, BLK_MAX_CDB);
1172 return scsi_init_io(cmd, GFP_ATOMIC); 1173 return scsi_init_io(cmd, GFP_ATOMIC);
1173} 1174}
1174EXPORT_SYMBOL(scsi_setup_fs_cmnd); 1175EXPORT_SYMBOL(scsi_setup_fs_cmnd);
diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
index ee8496aa0336..257e097c39af 100644
--- a/drivers/scsi/scsi_tgt_lib.c
+++ b/drivers/scsi/scsi_tgt_lib.c
@@ -107,6 +107,8 @@ struct scsi_cmnd *scsi_host_get_command(struct Scsi_Host *shost,
107 cmd->jiffies_at_alloc = jiffies; 107 cmd->jiffies_at_alloc = jiffies;
108 cmd->request = rq; 108 cmd->request = rq;
109 109
110 cmd->cmnd = rq->cmd;
111
110 rq->special = cmd; 112 rq->special = cmd;
111 rq->cmd_type = REQ_TYPE_SPECIAL; 113 rq->cmd_type = REQ_TYPE_SPECIAL;
112 rq->cmd_flags |= REQ_TYPE_BLOCK_PC; 114 rq->cmd_flags |= REQ_TYPE_BLOCK_PC;
diff --git a/drivers/scsi/u14-34f.c b/drivers/scsi/u14-34f.c
index 640333b1e75c..329eb8780e74 100644
--- a/drivers/scsi/u14-34f.c
+++ b/drivers/scsi/u14-34f.c
@@ -744,7 +744,8 @@ static int wait_on_busy(unsigned long iobase, unsigned int loop) {
744static int board_inquiry(unsigned int j) { 744static int board_inquiry(unsigned int j) {
745 struct mscp *cpp; 745 struct mscp *cpp;
746 dma_addr_t id_dma_addr; 746 dma_addr_t id_dma_addr;
747 unsigned int time, limit = 0; 747 unsigned int limit = 0;
748 unsigned long time;
748 749
749 id_dma_addr = pci_map_single(HD(j)->pdev, HD(j)->board_id, 750 id_dma_addr = pci_map_single(HD(j)->pdev, HD(j)->board_id,
750 sizeof(HD(j)->board_id), PCI_DMA_BIDIRECTIONAL); 751 sizeof(HD(j)->board_id), PCI_DMA_BIDIRECTIONAL);
@@ -1392,7 +1393,8 @@ static int u14_34f_eh_abort(struct scsi_cmnd *SCarg) {
1392} 1393}
1393 1394
1394static int u14_34f_eh_host_reset(struct scsi_cmnd *SCarg) { 1395static int u14_34f_eh_host_reset(struct scsi_cmnd *SCarg) {
1395 unsigned int i, j, time, k, c, limit = 0; 1396 unsigned int i, j, k, c, limit = 0;
1397 unsigned long time;
1396 int arg_done = FALSE; 1398 int arg_done = FALSE;
1397 struct scsi_cmnd *SCpnt; 1399 struct scsi_cmnd *SCpnt;
1398 1400
diff --git a/drivers/serial/68328serial.c b/drivers/serial/68328serial.c
index 2b8a410e0959..bbf5bc5892c7 100644
--- a/drivers/serial/68328serial.c
+++ b/drivers/serial/68328serial.c
@@ -200,7 +200,7 @@ static void rs_stop(struct tty_struct *tty)
200 local_irq_restore(flags); 200 local_irq_restore(flags);
201} 201}
202 202
203static void rs_put_char(char ch) 203static int rs_put_char(char ch)
204{ 204{
205 int flags, loops = 0; 205 int flags, loops = 0;
206 206
@@ -214,6 +214,7 @@ static void rs_put_char(char ch)
214 UTX_TXDATA = ch; 214 UTX_TXDATA = ch;
215 udelay(5); 215 udelay(5);
216 local_irq_restore(flags); 216 local_irq_restore(flags);
217 return 1;
217} 218}
218 219
219static void rs_start(struct tty_struct *tty) 220static void rs_start(struct tty_struct *tty)
@@ -1017,18 +1018,6 @@ static int rs_ioctl(struct tty_struct *tty, struct file * file,
1017 tty_wait_until_sent(tty, 0); 1018 tty_wait_until_sent(tty, 0);
1018 send_break(info, arg ? arg*(100) : 250); 1019 send_break(info, arg ? arg*(100) : 250);
1019 return 0; 1020 return 0;
1020 case TIOCGSOFTCAR:
1021 error = put_user(C_CLOCAL(tty) ? 1 : 0,
1022 (unsigned long *) arg);
1023 if (error)
1024 return error;
1025 return 0;
1026 case TIOCSSOFTCAR:
1027 get_user(arg, (unsigned long *) arg);
1028 tty->termios->c_cflag =
1029 ((tty->termios->c_cflag & ~CLOCAL) |
1030 (arg ? CLOCAL : 0));
1031 return 0;
1032 case TIOCGSERIAL: 1021 case TIOCGSERIAL:
1033 if (access_ok(VERIFY_WRITE, (void *) arg, 1022 if (access_ok(VERIFY_WRITE, (void *) arg,
1034 sizeof(struct serial_struct))) 1023 sizeof(struct serial_struct)))
@@ -1061,9 +1050,6 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1061{ 1050{
1062 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data; 1051 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
1063 1052
1064 if (tty->termios->c_cflag == old_termios->c_cflag)
1065 return;
1066
1067 change_speed(info); 1053 change_speed(info);
1068 1054
1069 if ((old_termios->c_cflag & CRTSCTS) && 1055 if ((old_termios->c_cflag & CRTSCTS) &&
@@ -1140,8 +1126,7 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
1140 uart->ustcnt &= ~(USTCNT_RXEN | USTCNT_RX_INTR_MASK); 1126 uart->ustcnt &= ~(USTCNT_RXEN | USTCNT_RX_INTR_MASK);
1141 1127
1142 shutdown(info); 1128 shutdown(info);
1143 if (tty->driver->flush_buffer) 1129 rs_flush_buffer(tty);
1144 tty->driver->flush_buffer(tty);
1145 1130
1146 tty_ldisc_flush(tty); 1131 tty_ldisc_flush(tty);
1147 tty->closing = 0; 1132 tty->closing = 0;
diff --git a/drivers/serial/68360serial.c b/drivers/serial/68360serial.c
index f59463601874..d9d4e9552a4d 100644
--- a/drivers/serial/68360serial.c
+++ b/drivers/serial/68360serial.c
@@ -995,10 +995,10 @@ static void rs_360_put_char(struct tty_struct *tty, unsigned char ch)
995 volatile QUICC_BD *bdp; 995 volatile QUICC_BD *bdp;
996 996
997 if (serial_paranoia_check(info, tty->name, "rs_put_char")) 997 if (serial_paranoia_check(info, tty->name, "rs_put_char"))
998 return; 998 return 0;
999 999
1000 if (!tty) 1000 if (!tty)
1001 return; 1001 return 0;
1002 1002
1003 bdp = info->tx_cur; 1003 bdp = info->tx_cur;
1004 while (bdp->status & BD_SC_READY); 1004 while (bdp->status & BD_SC_READY);
@@ -1016,6 +1016,7 @@ static void rs_360_put_char(struct tty_struct *tty, unsigned char ch)
1016 bdp++; 1016 bdp++;
1017 1017
1018 info->tx_cur = (QUICC_BD *)bdp; 1018 info->tx_cur = (QUICC_BD *)bdp;
1019 return 1;
1019 1020
1020} 1021}
1021 1022
@@ -1246,7 +1247,7 @@ static int rs_360_tiocmget(struct tty_struct *tty, struct file *file)
1246#ifdef modem_control 1247#ifdef modem_control
1247 unsigned char control, status; 1248 unsigned char control, status;
1248 1249
1249 if (serial_paranoia_check(info, tty->name, __FUNCTION__)) 1250 if (serial_paranoia_check(info, tty->name, __func__))
1250 return -ENODEV; 1251 return -ENODEV;
1251 1252
1252 if (tty->flags & (1 << TTY_IO_ERROR)) 1253 if (tty->flags & (1 << TTY_IO_ERROR))
@@ -1277,12 +1278,12 @@ static int rs_360_tiocmset(struct tty_struct *tty, struct file *file,
1277 ser_info_t *info = (ser_info_t *)tty->driver_data; 1278 ser_info_t *info = (ser_info_t *)tty->driver_data;
1278 unsigned int arg; 1279 unsigned int arg;
1279 1280
1280 if (serial_paranoia_check(info, tty->name, __FUNCTION__)) 1281 if (serial_paranoia_check(info, tty->name, __func__))
1281 return -ENODEV; 1282 return -ENODEV;
1282 1283
1283 if (tty->flags & (1 << TTY_IO_ERROR)) 1284 if (tty->flags & (1 << TTY_IO_ERROR))
1284 return -EIO; 1285 return -EIO;
1285 1286 /* FIXME: locking on info->mcr */
1286 if (set & TIOCM_RTS) 1287 if (set & TIOCM_RTS)
1287 info->mcr |= UART_MCR_RTS; 1288 info->mcr |= UART_MCR_RTS;
1288 if (set & TIOCM_DTR) 1289 if (set & TIOCM_DTR)
@@ -1436,18 +1437,6 @@ static int rs_360_ioctl(struct tty_struct *tty, struct file * file,
1436 return retval; 1437 return retval;
1437 end_break(info); 1438 end_break(info);
1438 return 0; 1439 return 0;
1439 case TIOCGSOFTCAR:
1440 /* return put_user(C_CLOCAL(tty) ? 1 : 0, (int *) arg); */
1441 put_user(C_CLOCAL(tty) ? 1 : 0, (int *) arg);
1442 return 0;
1443 case TIOCSSOFTCAR:
1444 error = get_user(arg, (unsigned int *) arg);
1445 if (error)
1446 return error;
1447 tty->termios->c_cflag =
1448 ((tty->termios->c_cflag & ~CLOCAL) |
1449 (arg ? CLOCAL : 0));
1450 return 0;
1451#ifdef maybe 1440#ifdef maybe
1452 case TIOCSERGETLSR: /* Get line status register */ 1441 case TIOCSERGETLSR: /* Get line status register */
1453 return get_lsr_info(info, (unsigned int *) arg); 1442 return get_lsr_info(info, (unsigned int *) arg);
@@ -1665,8 +1654,7 @@ static void rs_360_close(struct tty_struct *tty, struct file * filp)
1665 rs_360_wait_until_sent(tty, info->timeout); 1654 rs_360_wait_until_sent(tty, info->timeout);
1666 } 1655 }
1667 shutdown(info); 1656 shutdown(info);
1668 if (tty->driver->flush_buffer) 1657 rs_360_flush_buffer(tty);
1669 tty->driver->flush_buffer(tty);
1670 tty_ldisc_flush(tty); 1658 tty_ldisc_flush(tty);
1671 tty->closing = 0; 1659 tty->closing = 0;
1672 info->event = 0; 1660 info->event = 0;
@@ -1717,6 +1705,7 @@ static void rs_360_wait_until_sent(struct tty_struct *tty, int timeout)
1717 printk("jiff=%lu...", jiffies); 1705 printk("jiff=%lu...", jiffies);
1718#endif 1706#endif
1719 1707
1708 lock_kernel();
1720 /* We go through the loop at least once because we can't tell 1709 /* We go through the loop at least once because we can't tell
1721 * exactly when the last character exits the shifter. There can 1710 * exactly when the last character exits the shifter. There can
1722 * be at least two characters waiting to be sent after the buffers 1711 * be at least two characters waiting to be sent after the buffers
@@ -1745,6 +1734,7 @@ static void rs_360_wait_until_sent(struct tty_struct *tty, int timeout)
1745 bdp--; 1734 bdp--;
1746 } while (bdp->status & BD_SC_READY); 1735 } while (bdp->status & BD_SC_READY);
1747 current->state = TASK_RUNNING; 1736 current->state = TASK_RUNNING;
1737 unlock_kernel();
1748#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT 1738#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1749 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies); 1739 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
1750#endif 1740#endif
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index ea41f2626458..a1ca9b7bf2d5 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -2271,7 +2271,8 @@ static int serial8250_request_std_resource(struct uart_8250_port *up)
2271 } 2271 }
2272 2272
2273 if (up->port.flags & UPF_IOREMAP) { 2273 if (up->port.flags & UPF_IOREMAP) {
2274 up->port.membase = ioremap(up->port.mapbase, size); 2274 up->port.membase = ioremap_nocache(up->port.mapbase,
2275 size);
2275 if (!up->port.membase) { 2276 if (!up->port.membase) {
2276 release_mem_region(up->port.mapbase, size); 2277 release_mem_region(up->port.mapbase, size);
2277 ret = -ENOMEM; 2278 ret = -ENOMEM;
diff --git a/drivers/serial/8250_early.c b/drivers/serial/8250_early.c
index 38776e8b064b..f279745e9fef 100644
--- a/drivers/serial/8250_early.c
+++ b/drivers/serial/8250_early.c
@@ -153,10 +153,10 @@ static int __init parse_options(struct early_serial8250_device *device,
153 (void __iomem *)__fix_to_virt(FIX_EARLYCON_MEM_BASE); 153 (void __iomem *)__fix_to_virt(FIX_EARLYCON_MEM_BASE);
154 port->membase += port->mapbase & ~PAGE_MASK; 154 port->membase += port->mapbase & ~PAGE_MASK;
155#else 155#else
156 port->membase = ioremap(port->mapbase, 64); 156 port->membase = ioremap_nocache(port->mapbase, 64);
157 if (!port->membase) { 157 if (!port->membase) {
158 printk(KERN_ERR "%s: Couldn't ioremap 0x%llx\n", 158 printk(KERN_ERR "%s: Couldn't ioremap 0x%llx\n",
159 __FUNCTION__, 159 __func__,
160 (unsigned long long)port->mapbase); 160 (unsigned long long)port->mapbase);
161 return -ENOMEM; 161 return -ENOMEM;
162 } 162 }
diff --git a/drivers/serial/8250_pci.c b/drivers/serial/8250_pci.c
index 6e57382b9137..53fa19cf2f06 100644
--- a/drivers/serial/8250_pci.c
+++ b/drivers/serial/8250_pci.c
@@ -86,7 +86,7 @@ setup_port(struct serial_private *priv, struct uart_port *port,
86 len = pci_resource_len(dev, bar); 86 len = pci_resource_len(dev, bar);
87 87
88 if (!priv->remapped_bar[bar]) 88 if (!priv->remapped_bar[bar])
89 priv->remapped_bar[bar] = ioremap(base, len); 89 priv->remapped_bar[bar] = ioremap_nocache(base, len);
90 if (!priv->remapped_bar[bar]) 90 if (!priv->remapped_bar[bar])
91 return -ENOMEM; 91 return -ENOMEM;
92 92
@@ -270,7 +270,7 @@ static int pci_plx9050_init(struct pci_dev *dev)
270 /* 270 /*
271 * enable/disable interrupts 271 * enable/disable interrupts
272 */ 272 */
273 p = ioremap(pci_resource_start(dev, 0), 0x80); 273 p = ioremap_nocache(pci_resource_start(dev, 0), 0x80);
274 if (p == NULL) 274 if (p == NULL)
275 return -ENOMEM; 275 return -ENOMEM;
276 writel(irq_config, p + 0x4c); 276 writel(irq_config, p + 0x4c);
@@ -294,7 +294,7 @@ static void __devexit pci_plx9050_exit(struct pci_dev *dev)
294 /* 294 /*
295 * disable interrupts 295 * disable interrupts
296 */ 296 */
297 p = ioremap(pci_resource_start(dev, 0), 0x80); 297 p = ioremap_nocache(pci_resource_start(dev, 0), 0x80);
298 if (p != NULL) { 298 if (p != NULL) {
299 writel(0, p + 0x4c); 299 writel(0, p + 0x4c);
300 300
@@ -341,7 +341,8 @@ static int sbs_init(struct pci_dev *dev)
341{ 341{
342 u8 __iomem *p; 342 u8 __iomem *p;
343 343
344 p = ioremap(pci_resource_start(dev, 0), pci_resource_len(dev, 0)); 344 p = ioremap_nocache(pci_resource_start(dev, 0),
345 pci_resource_len(dev, 0));
345 346
346 if (p == NULL) 347 if (p == NULL)
347 return -ENOMEM; 348 return -ENOMEM;
@@ -365,7 +366,8 @@ static void __devexit sbs_exit(struct pci_dev *dev)
365{ 366{
366 u8 __iomem *p; 367 u8 __iomem *p;
367 368
368 p = ioremap(pci_resource_start(dev, 0), pci_resource_len(dev, 0)); 369 p = ioremap_nocache(pci_resource_start(dev, 0),
370 pci_resource_len(dev, 0));
369 /* FIXME: What if resource_len < OCT_REG_CR_OFF */ 371 /* FIXME: What if resource_len < OCT_REG_CR_OFF */
370 if (p != NULL) 372 if (p != NULL)
371 writeb(0, p + OCT_REG_CR_OFF); 373 writeb(0, p + OCT_REG_CR_OFF);
@@ -419,7 +421,7 @@ static int pci_siig10x_init(struct pci_dev *dev)
419 break; 421 break;
420 } 422 }
421 423
422 p = ioremap(pci_resource_start(dev, 0), 0x80); 424 p = ioremap_nocache(pci_resource_start(dev, 0), 0x80);
423 if (p == NULL) 425 if (p == NULL)
424 return -ENOMEM; 426 return -ENOMEM;
425 427
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 34b809e3b596..36acbcca2d48 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -1355,4 +1355,47 @@ config SERIAL_SC26XX_CONSOLE
1355 help 1355 help
1356 Support for Console on SC2681/SC2692 serial ports. 1356 Support for Console on SC2681/SC2692 serial ports.
1357 1357
1358config SERIAL_BFIN_SPORT
1359 tristate "Blackfin SPORT emulate UART (EXPERIMENTAL)"
1360 depends on BFIN && EXPERIMENTAL
1361 select SERIAL_CORE
1362 help
1363 Enble support SPORT emulate UART on Blackfin series.
1364
1365 To compile this driver as a module, choose M here: the
1366 module will be called bfin_sport_uart.
1367
1368choice
1369 prompt "Baud rate for Blackfin SPORT UART"
1370 depends on SERIAL_BFIN_SPORT
1371 default SERIAL_SPORT_BAUD_RATE_57600
1372 help
1373 Choose a baud rate for the SPORT UART, other uart settings are
1374 8 bit, 1 stop bit, no parity, no flow control.
1375
1376config SERIAL_SPORT_BAUD_RATE_115200
1377 bool "115200"
1378
1379config SERIAL_SPORT_BAUD_RATE_57600
1380 bool "57600"
1381
1382config SERIAL_SPORT_BAUD_RATE_38400
1383 bool "38400"
1384
1385config SERIAL_SPORT_BAUD_RATE_19200
1386 bool "19200"
1387
1388config SERIAL_SPORT_BAUD_RATE_9600
1389 bool "9600"
1390endchoice
1391
1392config SPORT_BAUD_RATE
1393 int
1394 depends on SERIAL_BFIN_SPORT
1395 default 115200 if (SERIAL_SPORT_BAUD_RATE_115200)
1396 default 57600 if (SERIAL_SPORT_BAUD_RATE_57600)
1397 default 38400 if (SERIAL_SPORT_BAUD_RATE_38400)
1398 default 19200 if (SERIAL_SPORT_BAUD_RATE_19200)
1399 default 9600 if (SERIAL_SPORT_BAUD_RATE_9600)
1400
1358endmenu 1401endmenu
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
index f02ff9fad017..0d9c09b1e836 100644
--- a/drivers/serial/Makefile
+++ b/drivers/serial/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_SERIAL_PXA) += pxa.o
27obj-$(CONFIG_SERIAL_PNX8XXX) += pnx8xxx_uart.o 27obj-$(CONFIG_SERIAL_PNX8XXX) += pnx8xxx_uart.o
28obj-$(CONFIG_SERIAL_SA1100) += sa1100.o 28obj-$(CONFIG_SERIAL_SA1100) += sa1100.o
29obj-$(CONFIG_SERIAL_BFIN) += bfin_5xx.o 29obj-$(CONFIG_SERIAL_BFIN) += bfin_5xx.o
30obj-$(CONFIG_SERIAL_BFIN_SPORT) += bfin_sport_uart.o
30obj-$(CONFIG_SERIAL_S3C2410) += s3c2410.o 31obj-$(CONFIG_SERIAL_S3C2410) += s3c2410.o
31obj-$(CONFIG_SERIAL_SUNCORE) += suncore.o 32obj-$(CONFIG_SERIAL_SUNCORE) += suncore.o
32obj-$(CONFIG_SERIAL_SUNHV) += sunhv.o 33obj-$(CONFIG_SERIAL_SUNHV) += sunhv.o
diff --git a/drivers/serial/bfin_5xx.c b/drivers/serial/bfin_5xx.c
index 5f55534a290b..8a2f6a1baa74 100644
--- a/drivers/serial/bfin_5xx.c
+++ b/drivers/serial/bfin_5xx.c
@@ -762,7 +762,7 @@ bfin_serial_set_termios(struct uart_port *port, struct ktermios *termios,
762 break; 762 break;
763 default: 763 default:
764 printk(KERN_ERR "%s: word lengh not supported\n", 764 printk(KERN_ERR "%s: word lengh not supported\n",
765 __FUNCTION__); 765 __func__);
766 } 766 }
767 767
768 if (termios->c_cflag & CSTOPB) 768 if (termios->c_cflag & CSTOPB)
@@ -1029,7 +1029,7 @@ bfin_serial_console_get_options(struct bfin_serial_port *uart, int *baud,
1029 1029
1030 *baud = get_sclk() / (16*(dll | dlh << 8)); 1030 *baud = get_sclk() / (16*(dll | dlh << 8));
1031 } 1031 }
1032 pr_debug("%s:baud = %d, parity = %c, bits= %d\n", __FUNCTION__, *baud, *parity, *bits); 1032 pr_debug("%s:baud = %d, parity = %c, bits= %d\n", __func__, *baud, *parity, *bits);
1033} 1033}
1034#endif 1034#endif
1035 1035
diff --git a/drivers/serial/bfin_sport_uart.c b/drivers/serial/bfin_sport_uart.c
new file mode 100644
index 000000000000..aca1240ad808
--- /dev/null
+++ b/drivers/serial/bfin_sport_uart.c
@@ -0,0 +1,614 @@
1/*
2 * File: linux/drivers/serial/bfin_sport_uart.c
3 *
4 * Based on: drivers/serial/bfin_5xx.c by Aubrey Li.
5 * Author: Roy Huang <roy.huang@analog.com>
6 *
7 * Created: Nov 22, 2006
8 * Copyright: (c) 2006-2007 Analog Devices Inc.
9 * Description: this driver enable SPORTs on Blackfin emulate UART.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see the file COPYING, or write
23 * to the Free Software Foundation, Inc.,
24 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 */
26
27/*
28 * This driver and the hardware supported are in term of EE-191 of ADI.
29 * http://www.analog.com/UploadedFiles/Application_Notes/399447663EE191.pdf
30 * This application note describe how to implement a UART on a Sharc DSP,
31 * but this driver is implemented on Blackfin Processor.
32 */
33
34/* After reset, there is a prelude of low level pulse when transmit data first
35 * time. No addtional pulse in following transmit.
36 * According to document:
37 * The SPORTs are ready to start transmitting or receiving data no later than
38 * three serial clock cycles after they are enabled in the SPORTx_TCR1 or
39 * SPORTx_RCR1 register. No serial clock cycles are lost from this point on.
40 * The first internal frame sync will occur one frame sync delay after the
41 * SPORTs are ready. External frame syncs can occur as soon as the SPORT is
42 * ready.
43 */
44
45/* Thanks to Axel Alatalo <axel@rubico.se> for fixing sport rx bug. Sometimes
46 * sport receives data incorrectly. The following is Axel's words.
47 * As EE-191, sport rx samples 3 times of the UART baudrate and takes the
48 * middle smaple of every 3 samples as the data bit. For a 8-N-1 UART setting,
49 * 30 samples will be required for a byte. If transmitter sends a 1/3 bit short
50 * byte due to buadrate drift, then the 30th sample of a byte, this sample is
51 * also the third sample of the stop bit, will happens on the immediately
52 * following start bit which will be thrown away and missed. Thus since parts
53 * of the startbit will be missed and the receiver will begin to drift, the
54 * effect accumulates over time until synchronization is lost.
55 * If only require 2 samples of the stopbit (by sampling in total 29 samples),
56 * then a to short byte as in the case above will be tolerated. Then the 1/3
57 * early startbit will trigger a framesync since the last read is complete
58 * after only 2/3 stopbit and framesync is active during the last 1/3 looking
59 * for a possible early startbit. */
60
61//#define DEBUG
62
63#include <linux/module.h>
64#include <linux/ioport.h>
65#include <linux/init.h>
66#include <linux/console.h>
67#include <linux/sysrq.h>
68#include <linux/platform_device.h>
69#include <linux/tty.h>
70#include <linux/tty_flip.h>
71#include <linux/serial_core.h>
72
73#include <asm/delay.h>
74#include <asm/portmux.h>
75
76#include "bfin_sport_uart.h"
77
78unsigned short bfin_uart_pin_req_sport0[] =
79 {P_SPORT0_TFS, P_SPORT0_DTPRI, P_SPORT0_TSCLK, P_SPORT0_RFS, \
80 P_SPORT0_DRPRI, P_SPORT0_RSCLK, P_SPORT0_DRSEC, P_SPORT0_DTSEC, 0};
81
82unsigned short bfin_uart_pin_req_sport1[] =
83 {P_SPORT1_TFS, P_SPORT1_DTPRI, P_SPORT1_TSCLK, P_SPORT1_RFS, \
84 P_SPORT1_DRPRI, P_SPORT1_RSCLK, P_SPORT1_DRSEC, P_SPORT1_DTSEC, 0};
85
86#define DRV_NAME "bfin-sport-uart"
87
88struct sport_uart_port {
89 struct uart_port port;
90 char *name;
91
92 int tx_irq;
93 int rx_irq;
94 int err_irq;
95};
96
97static void sport_uart_tx_chars(struct sport_uart_port *up);
98static void sport_stop_tx(struct uart_port *port);
99
100static inline void tx_one_byte(struct sport_uart_port *up, unsigned int value)
101{
102 pr_debug("%s value:%x\n", __FUNCTION__, value);
103 /* Place a Start and Stop bit */
104 __asm__ volatile (
105 "R2 = b#01111111100;\n\t"
106 "R3 = b#10000000001;\n\t"
107 "%0 <<= 2;\n\t"
108 "%0 = %0 & R2;\n\t"
109 "%0 = %0 | R3;\n\t"
110 :"=r"(value)
111 :"0"(value)
112 :"R2", "R3");
113 pr_debug("%s value:%x\n", __FUNCTION__, value);
114
115 SPORT_PUT_TX(up, value);
116}
117
118static inline unsigned int rx_one_byte(struct sport_uart_port *up)
119{
120 unsigned int value, extract;
121
122 value = SPORT_GET_RX32(up);
123 pr_debug("%s value:%x\n", __FUNCTION__, value);
124
125 /* Extract 8 bits data */
126 __asm__ volatile (
127 "R5 = 0;\n\t"
128 "P0 = 8;\n\t"
129 "R1 = 0x1801(Z);\n\t"
130 "R3 = 0x0300(Z);\n\t"
131 "R4 = 0;\n\t"
132 "LSETUP(loop_s, loop_e) LC0 = P0;\nloop_s:\t"
133 "R2 = extract(%1, R1.L)(Z);\n\t"
134 "R2 <<= R4;\n\t"
135 "R5 = R5 | R2;\n\t"
136 "R1 = R1 - R3;\nloop_e:\t"
137 "R4 += 1;\n\t"
138 "%0 = R5;\n\t"
139 :"=r"(extract)
140 :"r"(value)
141 :"P0", "R1", "R2","R3","R4", "R5");
142
143 pr_debug(" extract:%x\n", extract);
144 return extract;
145}
146
147static int sport_uart_setup(struct sport_uart_port *up, int sclk, int baud_rate)
148{
149 int tclkdiv, tfsdiv, rclkdiv;
150
151 /* Set TCR1 and TCR2 */
152 SPORT_PUT_TCR1(up, (LTFS | ITFS | TFSR | TLSBIT | ITCLK));
153 SPORT_PUT_TCR2(up, 10);
154 pr_debug("%s TCR1:%x, TCR2:%x\n", __FUNCTION__, SPORT_GET_TCR1(up), SPORT_GET_TCR2(up));
155
156 /* Set RCR1 and RCR2 */
157 SPORT_PUT_RCR1(up, (RCKFE | LARFS | LRFS | RFSR | IRCLK));
158 SPORT_PUT_RCR2(up, 28);
159 pr_debug("%s RCR1:%x, RCR2:%x\n", __FUNCTION__, SPORT_GET_RCR1(up), SPORT_GET_RCR2(up));
160
161 tclkdiv = sclk/(2 * baud_rate) - 1;
162 tfsdiv = 12;
163 rclkdiv = sclk/(2 * baud_rate * 3) - 1;
164 SPORT_PUT_TCLKDIV(up, tclkdiv);
165 SPORT_PUT_TFSDIV(up, tfsdiv);
166 SPORT_PUT_RCLKDIV(up, rclkdiv);
167 SSYNC();
168 pr_debug("%s sclk:%d, baud_rate:%d, tclkdiv:%d, tfsdiv:%d, rclkdiv:%d\n",
169 __FUNCTION__, sclk, baud_rate, tclkdiv, tfsdiv, rclkdiv);
170
171 return 0;
172}
173
174static irqreturn_t sport_uart_rx_irq(int irq, void *dev_id)
175{
176 struct sport_uart_port *up = dev_id;
177 struct tty_struct *tty = up->port.info->tty;
178 unsigned int ch;
179
180 do {
181 ch = rx_one_byte(up);
182 up->port.icount.rx++;
183
184 if (uart_handle_sysrq_char(&up->port, ch))
185 ;
186 else
187 tty_insert_flip_char(tty, ch, TTY_NORMAL);
188 } while (SPORT_GET_STAT(up) & RXNE);
189 tty_flip_buffer_push(tty);
190
191 return IRQ_HANDLED;
192}
193
194static irqreturn_t sport_uart_tx_irq(int irq, void *dev_id)
195{
196 sport_uart_tx_chars(dev_id);
197
198 return IRQ_HANDLED;
199}
200
201static irqreturn_t sport_uart_err_irq(int irq, void *dev_id)
202{
203 struct sport_uart_port *up = dev_id;
204 struct tty_struct *tty = up->port.info->tty;
205 unsigned int stat = SPORT_GET_STAT(up);
206
207 /* Overflow in RX FIFO */
208 if (stat & ROVF) {
209 up->port.icount.overrun++;
210 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
211 SPORT_PUT_STAT(up, ROVF); /* Clear ROVF bit */
212 }
213 /* These should not happen */
214 if (stat & (TOVF | TUVF | RUVF)) {
215 printk(KERN_ERR "SPORT Error:%s %s %s\n",
216 (stat & TOVF)?"TX overflow":"",
217 (stat & TUVF)?"TX underflow":"",
218 (stat & RUVF)?"RX underflow":"");
219 SPORT_PUT_TCR1(up, SPORT_GET_TCR1(up) & ~TSPEN);
220 SPORT_PUT_RCR1(up, SPORT_GET_RCR1(up) & ~RSPEN);
221 }
222 SSYNC();
223
224 return IRQ_HANDLED;
225}
226
227/* Reqeust IRQ, Setup clock */
228static int sport_startup(struct uart_port *port)
229{
230 struct sport_uart_port *up = (struct sport_uart_port *)port;
231 char buffer[20];
232 int retval;
233
234 pr_debug("%s enter\n", __FUNCTION__);
235 memset(buffer, 20, '\0');
236 snprintf(buffer, 20, "%s rx", up->name);
237 retval = request_irq(up->rx_irq, sport_uart_rx_irq, IRQF_SAMPLE_RANDOM, buffer, up);
238 if (retval) {
239 printk(KERN_ERR "Unable to request interrupt %s\n", buffer);
240 return retval;
241 }
242
243 snprintf(buffer, 20, "%s tx", up->name);
244 retval = request_irq(up->tx_irq, sport_uart_tx_irq, IRQF_SAMPLE_RANDOM, buffer, up);
245 if (retval) {
246 printk(KERN_ERR "Unable to request interrupt %s\n", buffer);
247 goto fail1;
248 }
249
250 snprintf(buffer, 20, "%s err", up->name);
251 retval = request_irq(up->err_irq, sport_uart_err_irq, IRQF_SAMPLE_RANDOM, buffer, up);
252 if (retval) {
253 printk(KERN_ERR "Unable to request interrupt %s\n", buffer);
254 goto fail2;
255 }
256
257 if (port->line) {
258 if (peripheral_request_list(bfin_uart_pin_req_sport1, DRV_NAME))
259 goto fail3;
260 } else {
261 if (peripheral_request_list(bfin_uart_pin_req_sport0, DRV_NAME))
262 goto fail3;
263 }
264
265 sport_uart_setup(up, get_sclk(), port->uartclk);
266
267 /* Enable receive interrupt */
268 SPORT_PUT_RCR1(up, (SPORT_GET_RCR1(up) | RSPEN));
269 SSYNC();
270
271 return 0;
272
273
274fail3:
275 printk(KERN_ERR DRV_NAME
276 ": Requesting Peripherals failed\n");
277
278 free_irq(up->err_irq, up);
279fail2:
280 free_irq(up->tx_irq, up);
281fail1:
282 free_irq(up->rx_irq, up);
283
284 return retval;
285
286}
287
288static void sport_uart_tx_chars(struct sport_uart_port *up)
289{
290 struct circ_buf *xmit = &up->port.info->xmit;
291
292 if (SPORT_GET_STAT(up) & TXF)
293 return;
294
295 if (up->port.x_char) {
296 tx_one_byte(up, up->port.x_char);
297 up->port.icount.tx++;
298 up->port.x_char = 0;
299 return;
300 }
301
302 if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) {
303 sport_stop_tx(&up->port);
304 return;
305 }
306
307 while(!(SPORT_GET_STAT(up) & TXF) && !uart_circ_empty(xmit)) {
308 tx_one_byte(up, xmit->buf[xmit->tail]);
309 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE -1);
310 up->port.icount.tx++;
311 }
312
313 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
314 uart_write_wakeup(&up->port);
315}
316
317static unsigned int sport_tx_empty(struct uart_port *port)
318{
319 struct sport_uart_port *up = (struct sport_uart_port *)port;
320 unsigned int stat;
321
322 stat = SPORT_GET_STAT(up);
323 pr_debug("%s stat:%04x\n", __FUNCTION__, stat);
324 if (stat & TXHRE) {
325 return TIOCSER_TEMT;
326 } else
327 return 0;
328}
329
330static unsigned int sport_get_mctrl(struct uart_port *port)
331{
332 pr_debug("%s enter\n", __FUNCTION__);
333 return (TIOCM_CTS | TIOCM_CD | TIOCM_DSR);
334}
335
336static void sport_set_mctrl(struct uart_port *port, unsigned int mctrl)
337{
338 pr_debug("%s enter\n", __FUNCTION__);
339}
340
341static void sport_stop_tx(struct uart_port *port)
342{
343 struct sport_uart_port *up = (struct sport_uart_port *)port;
344 unsigned int stat;
345
346 pr_debug("%s enter\n", __FUNCTION__);
347
348 stat = SPORT_GET_STAT(up);
349 while(!(stat & TXHRE)) {
350 udelay(1);
351 stat = SPORT_GET_STAT(up);
352 }
353 /* Although the hold register is empty, last byte is still in shift
354 * register and not sent out yet. If baud rate is lower than default,
355 * delay should be longer. For example, if the baud rate is 9600,
356 * the delay must be at least 2ms by experience */
357 udelay(500);
358
359 SPORT_PUT_TCR1(up, (SPORT_GET_TCR1(up) & ~TSPEN));
360 SSYNC();
361
362 return;
363}
364
365static void sport_start_tx(struct uart_port *port)
366{
367 struct sport_uart_port *up = (struct sport_uart_port *)port;
368
369 pr_debug("%s enter\n", __FUNCTION__);
370 /* Write data into SPORT FIFO before enable SPROT to transmit */
371 sport_uart_tx_chars(up);
372
373 /* Enable transmit, then an interrupt will generated */
374 SPORT_PUT_TCR1(up, (SPORT_GET_TCR1(up) | TSPEN));
375 SSYNC();
376 pr_debug("%s exit\n", __FUNCTION__);
377}
378
379static void sport_stop_rx(struct uart_port *port)
380{
381 struct sport_uart_port *up = (struct sport_uart_port *)port;
382
383 pr_debug("%s enter\n", __FUNCTION__);
384 /* Disable sport to stop rx */
385 SPORT_PUT_RCR1(up, (SPORT_GET_RCR1(up) & ~RSPEN));
386 SSYNC();
387}
388
389static void sport_enable_ms(struct uart_port *port)
390{
391 pr_debug("%s enter\n", __FUNCTION__);
392}
393
394static void sport_break_ctl(struct uart_port *port, int break_state)
395{
396 pr_debug("%s enter\n", __FUNCTION__);
397}
398
399static void sport_shutdown(struct uart_port *port)
400{
401 struct sport_uart_port *up = (struct sport_uart_port *)port;
402
403 pr_debug("%s enter\n", __FUNCTION__);
404
405 /* Disable sport */
406 SPORT_PUT_TCR1(up, (SPORT_GET_TCR1(up) & ~TSPEN));
407 SPORT_PUT_RCR1(up, (SPORT_GET_RCR1(up) & ~RSPEN));
408 SSYNC();
409
410 if (port->line) {
411 peripheral_free_list(bfin_uart_pin_req_sport1);
412 } else {
413 peripheral_free_list(bfin_uart_pin_req_sport0);
414 }
415
416 free_irq(up->rx_irq, up);
417 free_irq(up->tx_irq, up);
418 free_irq(up->err_irq, up);
419}
420
421static void sport_set_termios(struct uart_port *port,
422 struct termios *termios, struct termios *old)
423{
424 pr_debug("%s enter, c_cflag:%08x\n", __FUNCTION__, termios->c_cflag);
425 uart_update_timeout(port, CS8 ,port->uartclk);
426}
427
428static const char *sport_type(struct uart_port *port)
429{
430 struct sport_uart_port *up = (struct sport_uart_port *)port;
431
432 pr_debug("%s enter\n", __FUNCTION__);
433 return up->name;
434}
435
436static void sport_release_port(struct uart_port *port)
437{
438 pr_debug("%s enter\n", __FUNCTION__);
439}
440
441static int sport_request_port(struct uart_port *port)
442{
443 pr_debug("%s enter\n", __FUNCTION__);
444 return 0;
445}
446
447static void sport_config_port(struct uart_port *port, int flags)
448{
449 struct sport_uart_port *up = (struct sport_uart_port *)port;
450
451 pr_debug("%s enter\n", __FUNCTION__);
452 up->port.type = PORT_BFIN_SPORT;
453}
454
455static int sport_verify_port(struct uart_port *port, struct serial_struct *ser)
456{
457 pr_debug("%s enter\n", __FUNCTION__);
458 return 0;
459}
460
461struct uart_ops sport_uart_ops = {
462 .tx_empty = sport_tx_empty,
463 .set_mctrl = sport_set_mctrl,
464 .get_mctrl = sport_get_mctrl,
465 .stop_tx = sport_stop_tx,
466 .start_tx = sport_start_tx,
467 .stop_rx = sport_stop_rx,
468 .enable_ms = sport_enable_ms,
469 .break_ctl = sport_break_ctl,
470 .startup = sport_startup,
471 .shutdown = sport_shutdown,
472 .set_termios = sport_set_termios,
473 .type = sport_type,
474 .release_port = sport_release_port,
475 .request_port = sport_request_port,
476 .config_port = sport_config_port,
477 .verify_port = sport_verify_port,
478};
479
480static struct sport_uart_port sport_uart_ports[] = {
481 { /* SPORT 0 */
482 .name = "SPORT0",
483 .tx_irq = IRQ_SPORT0_TX,
484 .rx_irq = IRQ_SPORT0_RX,
485 .err_irq= IRQ_SPORT0_ERROR,
486 .port = {
487 .type = PORT_BFIN_SPORT,
488 .iotype = UPIO_MEM,
489 .membase = (void __iomem *)SPORT0_TCR1,
490 .mapbase = SPORT0_TCR1,
491 .irq = IRQ_SPORT0_RX,
492 .uartclk = CONFIG_SPORT_BAUD_RATE,
493 .fifosize = 8,
494 .ops = &sport_uart_ops,
495 .line = 0,
496 },
497 }, { /* SPORT 1 */
498 .name = "SPORT1",
499 .tx_irq = IRQ_SPORT1_TX,
500 .rx_irq = IRQ_SPORT1_RX,
501 .err_irq= IRQ_SPORT1_ERROR,
502 .port = {
503 .type = PORT_BFIN_SPORT,
504 .iotype = UPIO_MEM,
505 .membase = (void __iomem *)SPORT1_TCR1,
506 .mapbase = SPORT1_TCR1,
507 .irq = IRQ_SPORT1_RX,
508 .uartclk = CONFIG_SPORT_BAUD_RATE,
509 .fifosize = 8,
510 .ops = &sport_uart_ops,
511 .line = 1,
512 },
513 }
514};
515
516static struct uart_driver sport_uart_reg = {
517 .owner = THIS_MODULE,
518 .driver_name = "SPORT-UART",
519 .dev_name = "ttySS",
520 .major = 204,
521 .minor = 84,
522 .nr = ARRAY_SIZE(sport_uart_ports),
523 .cons = NULL,
524};
525
526static int sport_uart_suspend(struct platform_device *dev, pm_message_t state)
527{
528 struct sport_uart_port *sport = platform_get_drvdata(dev);
529
530 pr_debug("%s enter\n", __FUNCTION__);
531 if (sport)
532 uart_suspend_port(&sport_uart_reg, &sport->port);
533
534 return 0;
535}
536
537static int sport_uart_resume(struct platform_device *dev)
538{
539 struct sport_uart_port *sport = platform_get_drvdata(dev);
540
541 pr_debug("%s enter\n", __FUNCTION__);
542 if (sport)
543 uart_resume_port(&sport_uart_reg, &sport->port);
544
545 return 0;
546}
547
548static int sport_uart_probe(struct platform_device *dev)
549{
550 pr_debug("%s enter\n", __FUNCTION__);
551 sport_uart_ports[dev->id].port.dev = &dev->dev;
552 uart_add_one_port(&sport_uart_reg, &sport_uart_ports[dev->id].port);
553 platform_set_drvdata(dev, &sport_uart_ports[dev->id]);
554
555 return 0;
556}
557
558static int sport_uart_remove(struct platform_device *dev)
559{
560 struct sport_uart_port *sport = platform_get_drvdata(dev);
561
562 pr_debug("%s enter\n", __FUNCTION__);
563 platform_set_drvdata(dev, NULL);
564
565 if (sport)
566 uart_remove_one_port(&sport_uart_reg, &sport->port);
567
568 return 0;
569}
570
571static struct platform_driver sport_uart_driver = {
572 .probe = sport_uart_probe,
573 .remove = sport_uart_remove,
574 .suspend = sport_uart_suspend,
575 .resume = sport_uart_resume,
576 .driver = {
577 .name = DRV_NAME,
578 },
579};
580
581static int __init sport_uart_init(void)
582{
583 int ret;
584
585 pr_debug("%s enter\n", __FUNCTION__);
586 ret = uart_register_driver(&sport_uart_reg);
587 if (ret != 0) {
588 printk(KERN_ERR "Failed to register %s:%d\n",
589 sport_uart_reg.driver_name, ret);
590 return ret;
591 }
592
593 ret = platform_driver_register(&sport_uart_driver);
594 if (ret != 0) {
595 printk(KERN_ERR "Failed to register sport uart driver:%d\n", ret);
596 uart_unregister_driver(&sport_uart_reg);
597 }
598
599
600 pr_debug("%s exit\n", __FUNCTION__);
601 return ret;
602}
603
604static void __exit sport_uart_exit(void)
605{
606 pr_debug("%s enter\n", __FUNCTION__);
607 platform_driver_unregister(&sport_uart_driver);
608 uart_unregister_driver(&sport_uart_reg);
609}
610
611module_init(sport_uart_init);
612module_exit(sport_uart_exit);
613
614MODULE_LICENSE("GPL");
diff --git a/drivers/serial/bfin_sport_uart.h b/drivers/serial/bfin_sport_uart.h
new file mode 100644
index 000000000000..671d41cc1a3f
--- /dev/null
+++ b/drivers/serial/bfin_sport_uart.h
@@ -0,0 +1,63 @@
1/*
2 * File: linux/drivers/serial/bfin_sport_uart.h
3 *
4 * Based on: include/asm-blackfin/mach-533/bfin_serial_5xx.h
5 * Author: Roy Huang <roy.huang>analog.com>
6 *
7 * Created: Nov 22, 2006
8 * Copyright: (C) Analog Device Inc.
9 * Description: this driver enable SPORTs on Blackfin emulate UART.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see the file COPYING, or write
23 * to the Free Software Foundation, Inc.,
24 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 */
26
27
28#define OFFSET_TCR1 0x00 /* Transmit Configuration 1 Register */
29#define OFFSET_TCR2 0x04 /* Transmit Configuration 2 Register */
30#define OFFSET_TCLKDIV 0x08 /* Transmit Serial Clock Divider Register */
31#define OFFSET_TFSDIV 0x0C /* Transmit Frame Sync Divider Register */
32#define OFFSET_TX 0x10 /* Transmit Data Register */
33#define OFFSET_RX 0x18 /* Receive Data Register */
34#define OFFSET_RCR1 0x20 /* Receive Configuration 1 Register */
35#define OFFSET_RCR2 0x24 /* Receive Configuration 2 Register */
36#define OFFSET_RCLKDIV 0x28 /* Receive Serial Clock Divider Register */
37#define OFFSET_RFSDIV 0x2c /* Receive Frame Sync Divider Register */
38#define OFFSET_STAT 0x30 /* Status Register */
39
40#define SPORT_GET_TCR1(sport) bfin_read16(((sport)->port.membase + OFFSET_TCR1))
41#define SPORT_GET_TCR2(sport) bfin_read16(((sport)->port.membase + OFFSET_TCR2))
42#define SPORT_GET_TCLKDIV(sport) bfin_read16(((sport)->port.membase + OFFSET_TCLKDIV))
43#define SPORT_GET_TFSDIV(sport) bfin_read16(((sport)->port.membase + OFFSET_TFSDIV))
44#define SPORT_GET_TX(sport) bfin_read16(((sport)->port.membase + OFFSET_TX))
45#define SPORT_GET_RX(sport) bfin_read16(((sport)->port.membase + OFFSET_RX))
46#define SPORT_GET_RX32(sport) bfin_read32(((sport)->port.membase + OFFSET_RX))
47#define SPORT_GET_RCR1(sport) bfin_read16(((sport)->port.membase + OFFSET_RCR1))
48#define SPORT_GET_RCR2(sport) bfin_read16(((sport)->port.membase + OFFSET_RCR2))
49#define SPORT_GET_RCLKDIV(sport) bfin_read16(((sport)->port.membase + OFFSET_RCLKDIV))
50#define SPORT_GET_RFSDIV(sport) bfin_read16(((sport)->port.membase + OFFSET_RFSDIV))
51#define SPORT_GET_STAT(sport) bfin_read16(((sport)->port.membase + OFFSET_STAT))
52
53#define SPORT_PUT_TCR1(sport, v) bfin_write16(((sport)->port.membase + OFFSET_TCR1), v)
54#define SPORT_PUT_TCR2(sport, v) bfin_write16(((sport)->port.membase + OFFSET_TCR2), v)
55#define SPORT_PUT_TCLKDIV(sport, v) bfin_write16(((sport)->port.membase + OFFSET_TCLKDIV), v)
56#define SPORT_PUT_TFSDIV(sport, v) bfin_write16(((sport)->port.membase + OFFSET_TFSDIV), v)
57#define SPORT_PUT_TX(sport, v) bfin_write16(((sport)->port.membase + OFFSET_TX), v)
58#define SPORT_PUT_RX(sport, v) bfin_write16(((sport)->port.membase + OFFSET_RX), v)
59#define SPORT_PUT_RCR1(sport, v) bfin_write16(((sport)->port.membase + OFFSET_RCR1), v)
60#define SPORT_PUT_RCR2(sport, v) bfin_write16(((sport)->port.membase + OFFSET_RCR2), v)
61#define SPORT_PUT_RCLKDIV(sport, v) bfin_write16(((sport)->port.membase + OFFSET_RCLKDIV), v)
62#define SPORT_PUT_RFSDIV(sport, v) bfin_write16(((sport)->port.membase + OFFSET_RFSDIV), v)
63#define SPORT_PUT_STAT(sport, v) bfin_write16(((sport)->port.membase + OFFSET_STAT), v)
diff --git a/drivers/serial/cpm_uart/cpm_uart_core.c b/drivers/serial/cpm_uart/cpm_uart_core.c
index a638ba0679ac..a19dc7ef8861 100644
--- a/drivers/serial/cpm_uart/cpm_uart_core.c
+++ b/drivers/serial/cpm_uart/cpm_uart_core.c
@@ -1117,7 +1117,7 @@ int cpm_uart_drv_get_platform_data(struct platform_device *pdev, int is_con)
1117 1117
1118 line = cpm_uart_id2nr(idx); 1118 line = cpm_uart_id2nr(idx);
1119 if(line < 0) { 1119 if(line < 0) {
1120 printk(KERN_ERR"%s(): port %d is not registered", __FUNCTION__, idx); 1120 printk(KERN_ERR"%s(): port %d is not registered", __func__, idx);
1121 return -EINVAL; 1121 return -EINVAL;
1122 } 1122 }
1123 1123
diff --git a/drivers/serial/crisv10.c b/drivers/serial/crisv10.c
index 88e7c1d5b919..f9fa237aa949 100644
--- a/drivers/serial/crisv10.c
+++ b/drivers/serial/crisv10.c
@@ -1788,7 +1788,7 @@ static unsigned int handle_descr_data(struct e100_serial *info,
1788 1788
1789 if (info->recv_cnt + recvl > 65536) { 1789 if (info->recv_cnt + recvl > 65536) {
1790 printk(KERN_CRIT 1790 printk(KERN_CRIT
1791 "%s: Too much pending incoming serial data! Dropping %u bytes.\n", __FUNCTION__, recvl); 1791 "%s: Too much pending incoming serial data! Dropping %u bytes.\n", __func__, recvl);
1792 return 0; 1792 return 0;
1793 } 1793 }
1794 1794
@@ -1801,7 +1801,7 @@ static unsigned int handle_descr_data(struct e100_serial *info,
1801 append_recv_buffer(info, buffer); 1801 append_recv_buffer(info, buffer);
1802 1802
1803 if (!(buffer = alloc_recv_buffer(SERIAL_DESCR_BUF_SIZE))) 1803 if (!(buffer = alloc_recv_buffer(SERIAL_DESCR_BUF_SIZE)))
1804 panic("%s: Failed to allocate memory for receive buffer!\n", __FUNCTION__); 1804 panic("%s: Failed to allocate memory for receive buffer!\n", __func__);
1805 1805
1806 descr->buf = virt_to_phys(buffer->buffer); 1806 descr->buf = virt_to_phys(buffer->buffer);
1807 1807
@@ -1925,7 +1925,7 @@ static int start_recv_dma(struct e100_serial *info)
1925 /* Set up the receiving descriptors */ 1925 /* Set up the receiving descriptors */
1926 for (i = 0; i < SERIAL_RECV_DESCRIPTORS; i++) { 1926 for (i = 0; i < SERIAL_RECV_DESCRIPTORS; i++) {
1927 if (!(buffer = alloc_recv_buffer(SERIAL_DESCR_BUF_SIZE))) 1927 if (!(buffer = alloc_recv_buffer(SERIAL_DESCR_BUF_SIZE)))
1928 panic("%s: Failed to allocate memory for receive buffer!\n", __FUNCTION__); 1928 panic("%s: Failed to allocate memory for receive buffer!\n", __func__);
1929 1929
1930 descr[i].ctrl = d_int; 1930 descr[i].ctrl = d_int;
1931 descr[i].buf = virt_to_phys(buffer->buffer); 1931 descr[i].buf = virt_to_phys(buffer->buffer);
@@ -3581,8 +3581,9 @@ rs_tiocmset(struct tty_struct *tty, struct file *file,
3581 unsigned int set, unsigned int clear) 3581 unsigned int set, unsigned int clear)
3582{ 3582{
3583 struct e100_serial *info = (struct e100_serial *)tty->driver_data; 3583 struct e100_serial *info = (struct e100_serial *)tty->driver_data;
3584 unsigned long flags;
3584 3585
3585 lock_kernel(); 3586 local_irq_save(flags);
3586 3587
3587 if (clear & TIOCM_RTS) 3588 if (clear & TIOCM_RTS)
3588 e100_rts(info, 0); 3589 e100_rts(info, 0);
@@ -3604,7 +3605,7 @@ rs_tiocmset(struct tty_struct *tty, struct file *file,
3604 if (set & TIOCM_CD) 3605 if (set & TIOCM_CD)
3605 e100_cd_out(info, 1); 3606 e100_cd_out(info, 1);
3606 3607
3607 unlock_kernel(); 3608 local_irq_restore(flags);
3608 return 0; 3609 return 0;
3609} 3610}
3610 3611
@@ -3613,8 +3614,10 @@ rs_tiocmget(struct tty_struct *tty, struct file *file)
3613{ 3614{
3614 struct e100_serial *info = (struct e100_serial *)tty->driver_data; 3615 struct e100_serial *info = (struct e100_serial *)tty->driver_data;
3615 unsigned int result; 3616 unsigned int result;
3617 unsigned long flags;
3618
3619 local_irq_save(flags);
3616 3620
3617 lock_kernel();
3618 result = 3621 result =
3619 (!E100_RTS_GET(info) ? TIOCM_RTS : 0) 3622 (!E100_RTS_GET(info) ? TIOCM_RTS : 0)
3620 | (!E100_DTR_GET(info) ? TIOCM_DTR : 0) 3623 | (!E100_DTR_GET(info) ? TIOCM_DTR : 0)
@@ -3623,7 +3626,7 @@ rs_tiocmget(struct tty_struct *tty, struct file *file)
3623 | (!E100_CD_GET(info) ? TIOCM_CAR : 0) 3626 | (!E100_CD_GET(info) ? TIOCM_CAR : 0)
3624 | (!E100_CTS_GET(info) ? TIOCM_CTS : 0); 3627 | (!E100_CTS_GET(info) ? TIOCM_CTS : 0);
3625 3628
3626 unlock_kernel(); 3629 local_irq_restore(flags);
3627 3630
3628#ifdef SERIAL_DEBUG_IO 3631#ifdef SERIAL_DEBUG_IO
3629 printk(KERN_DEBUG "ser%i: modem state: %i 0x%08X\n", 3632 printk(KERN_DEBUG "ser%i: modem state: %i 0x%08X\n",
@@ -3702,10 +3705,6 @@ rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
3702{ 3705{
3703 struct e100_serial *info = (struct e100_serial *)tty->driver_data; 3706 struct e100_serial *info = (struct e100_serial *)tty->driver_data;
3704 3707
3705 if (tty->termios->c_cflag == old_termios->c_cflag &&
3706 tty->termios->c_iflag == old_termios->c_iflag)
3707 return;
3708
3709 change_speed(info); 3708 change_speed(info);
3710 3709
3711 /* Handle turning off CRTSCTS */ 3710 /* Handle turning off CRTSCTS */
@@ -3808,10 +3807,8 @@ rs_close(struct tty_struct *tty, struct file * filp)
3808#endif 3807#endif
3809 3808
3810 shutdown(info); 3809 shutdown(info);
3811 if (tty->driver->flush_buffer) 3810 rs_flush_buffer(tty);
3812 tty->driver->flush_buffer(tty); 3811 tty_ldisc_flush_buffer(tty);
3813 if (tty->ldisc.flush_buffer)
3814 tty->ldisc.flush_buffer(tty);
3815 tty->closing = 0; 3812 tty->closing = 0;
3816 info->event = 0; 3813 info->event = 0;
3817 info->tty = 0; 3814 info->tty = 0;
@@ -3885,6 +3882,7 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
3885 * Check R_DMA_CHx_STATUS bit 0-6=number of available bytes in FIFO 3882 * Check R_DMA_CHx_STATUS bit 0-6=number of available bytes in FIFO
3886 * R_DMA_CHx_HWSW bit 31-16=nbr of bytes left in DMA buffer (0=64k) 3883 * R_DMA_CHx_HWSW bit 31-16=nbr of bytes left in DMA buffer (0=64k)
3887 */ 3884 */
3885 lock_kernel();
3888 orig_jiffies = jiffies; 3886 orig_jiffies = jiffies;
3889 while (info->xmit.head != info->xmit.tail || /* More in send queue */ 3887 while (info->xmit.head != info->xmit.tail || /* More in send queue */
3890 (*info->ostatusadr & 0x007f) || /* more in FIFO */ 3888 (*info->ostatusadr & 0x007f) || /* more in FIFO */
@@ -3901,6 +3899,7 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
3901 curr_time_usec - info->last_tx_active_usec; 3899 curr_time_usec - info->last_tx_active_usec;
3902 } 3900 }
3903 set_current_state(TASK_RUNNING); 3901 set_current_state(TASK_RUNNING);
3902 unlock_kernel();
3904} 3903}
3905 3904
3906/* 3905/*
@@ -4520,7 +4519,7 @@ rs_init(void)
4520 4519
4521 if (request_irq(SERIAL_IRQ_NBR, ser_interrupt, 4520 if (request_irq(SERIAL_IRQ_NBR, ser_interrupt,
4522 IRQF_SHARED | IRQF_DISABLED, "serial ", driver)) 4521 IRQF_SHARED | IRQF_DISABLED, "serial ", driver))
4523 panic("%s: Failed to request irq8", __FUNCTION__); 4522 panic("%s: Failed to request irq8", __func__);
4524 4523
4525#endif 4524#endif
4526#endif /* CONFIG_SVINTO_SIM */ 4525#endif /* CONFIG_SVINTO_SIM */
diff --git a/drivers/serial/ioc3_serial.c b/drivers/serial/ioc3_serial.c
index 168073f12cec..4f1af71e9a1b 100644
--- a/drivers/serial/ioc3_serial.c
+++ b/drivers/serial/ioc3_serial.c
@@ -52,7 +52,7 @@ static unsigned int Submodule_slot;
52#define DPRINT_CONFIG(_x...) ; 52#define DPRINT_CONFIG(_x...) ;
53//#define DPRINT_CONFIG(_x...) printk _x 53//#define DPRINT_CONFIG(_x...) printk _x
54#define NOT_PROGRESS() ; 54#define NOT_PROGRESS() ;
55//#define NOT_PROGRESS() printk("%s : fails %d\n", __FUNCTION__, __LINE__) 55//#define NOT_PROGRESS() printk("%s : fails %d\n", __func__, __LINE__)
56 56
57/* number of characters we want to transmit to the lower level at a time */ 57/* number of characters we want to transmit to the lower level at a time */
58#define MAX_CHARS 256 58#define MAX_CHARS 256
@@ -445,7 +445,7 @@ static int inline port_init(struct ioc3_port *port)
445 sbbr_h = &idd->vma->sbbr_h; 445 sbbr_h = &idd->vma->sbbr_h;
446 ring_pci_addr = (unsigned long __iomem)port->ip_dma_ringbuf; 446 ring_pci_addr = (unsigned long __iomem)port->ip_dma_ringbuf;
447 DPRINT_CONFIG(("%s: ring_pci_addr 0x%p\n", 447 DPRINT_CONFIG(("%s: ring_pci_addr 0x%p\n",
448 __FUNCTION__, (void *)ring_pci_addr)); 448 __func__, (void *)ring_pci_addr));
449 449
450 writel((unsigned int)((uint64_t) ring_pci_addr >> 32), sbbr_h); 450 writel((unsigned int)((uint64_t) ring_pci_addr >> 32), sbbr_h);
451 writel((unsigned int)ring_pci_addr | BUF_SIZE_BIT, sbbr_l); 451 writel((unsigned int)ring_pci_addr | BUF_SIZE_BIT, sbbr_l);
@@ -593,7 +593,7 @@ config_port(struct ioc3_port *port,
593 593
594 DPRINT_CONFIG(("%s: line %d baud %d byte_size %d stop %d parenb %d " 594 DPRINT_CONFIG(("%s: line %d baud %d byte_size %d stop %d parenb %d "
595 "parodd %d\n", 595 "parodd %d\n",
596 __FUNCTION__, ((struct uart_port *)port->ip_port)->line, 596 __func__, ((struct uart_port *)port->ip_port)->line,
597 baud, byte_size, stop_bits, parenb, parodd)); 597 baud, byte_size, stop_bits, parenb, parodd));
598 598
599 if (set_baud(port, baud)) 599 if (set_baud(port, baud))
@@ -871,14 +871,14 @@ static int ioc3_set_proto(struct ioc3_port *port, int proto)
871 default: 871 default:
872 case PROTO_RS232: 872 case PROTO_RS232:
873 /* Clear the appropriate GIO pin */ 873 /* Clear the appropriate GIO pin */
874 DPRINT_CONFIG(("%s: rs232\n", __FUNCTION__)); 874 DPRINT_CONFIG(("%s: rs232\n", __func__));
875 writel(0, (&port->ip_idd->vma->gppr[0] 875 writel(0, (&port->ip_idd->vma->gppr[0]
876 + hooks->rs422_select_pin)); 876 + hooks->rs422_select_pin));
877 break; 877 break;
878 878
879 case PROTO_RS422: 879 case PROTO_RS422:
880 /* Set the appropriate GIO pin */ 880 /* Set the appropriate GIO pin */
881 DPRINT_CONFIG(("%s: rs422\n", __FUNCTION__)); 881 DPRINT_CONFIG(("%s: rs422\n", __func__));
882 writel(1, (&port->ip_idd->vma->gppr[0] 882 writel(1, (&port->ip_idd->vma->gppr[0]
883 + hooks->rs422_select_pin)); 883 + hooks->rs422_select_pin));
884 break; 884 break;
@@ -988,7 +988,7 @@ ioc3_change_speed(struct uart_port *the_port,
988 } 988 }
989 baud = uart_get_baud_rate(the_port, new_termios, old_termios, 989 baud = uart_get_baud_rate(the_port, new_termios, old_termios,
990 MIN_BAUD_SUPPORTED, MAX_BAUD_SUPPORTED); 990 MIN_BAUD_SUPPORTED, MAX_BAUD_SUPPORTED);
991 DPRINT_CONFIG(("%s: returned baud %d for line %d\n", __FUNCTION__, baud, 991 DPRINT_CONFIG(("%s: returned baud %d for line %d\n", __func__, baud,
992 the_port->line)); 992 the_port->line));
993 993
994 if (!the_port->fifosize) 994 if (!the_port->fifosize)
@@ -1026,7 +1026,7 @@ ioc3_change_speed(struct uart_port *the_port,
1026 DPRINT_CONFIG(("%s : port 0x%p line %d cflag 0%o " 1026 DPRINT_CONFIG(("%s : port 0x%p line %d cflag 0%o "
1027 "config_port(baud %d data %d stop %d penable %d " 1027 "config_port(baud %d data %d stop %d penable %d "
1028 " parity %d), notification 0x%x\n", 1028 " parity %d), notification 0x%x\n",
1029 __FUNCTION__, (void *)port, the_port->line, cflag, baud, 1029 __func__, (void *)port, the_port->line, cflag, baud,
1030 new_data, new_stop, new_parity_enable, new_parity, 1030 new_data, new_stop, new_parity_enable, new_parity,
1031 the_port->ignore_status_mask)); 1031 the_port->ignore_status_mask));
1032 1032
@@ -1919,7 +1919,7 @@ static inline int ioc3_serial_core_attach( struct ioc3_submodule *is,
1919 struct pci_dev *pdev = idd->pdev; 1919 struct pci_dev *pdev = idd->pdev;
1920 1920
1921 DPRINT_CONFIG(("%s: attach pdev 0x%p - card_ptr 0x%p\n", 1921 DPRINT_CONFIG(("%s: attach pdev 0x%p - card_ptr 0x%p\n",
1922 __FUNCTION__, pdev, (void *)card_ptr)); 1922 __func__, pdev, (void *)card_ptr));
1923 1923
1924 if (!card_ptr) 1924 if (!card_ptr)
1925 return -ENODEV; 1925 return -ENODEV;
@@ -1933,7 +1933,7 @@ static inline int ioc3_serial_core_attach( struct ioc3_submodule *is,
1933 port->ip_port = the_port; 1933 port->ip_port = the_port;
1934 1934
1935 DPRINT_CONFIG(("%s: attach the_port 0x%p / port 0x%p [%d/%d]\n", 1935 DPRINT_CONFIG(("%s: attach the_port 0x%p / port 0x%p [%d/%d]\n",
1936 __FUNCTION__, (void *)the_port, (void *)port, 1936 __func__, (void *)the_port, (void *)port,
1937 phys_port, ii)); 1937 phys_port, ii));
1938 1938
1939 /* membase, iobase and mapbase just need to be non-0 */ 1939 /* membase, iobase and mapbase just need to be non-0 */
@@ -1950,7 +1950,7 @@ static inline int ioc3_serial_core_attach( struct ioc3_submodule *is,
1950 if (uart_add_one_port(&ioc3_uart, the_port) < 0) { 1950 if (uart_add_one_port(&ioc3_uart, the_port) < 0) {
1951 printk(KERN_WARNING 1951 printk(KERN_WARNING
1952 "%s: unable to add port %d bus %d\n", 1952 "%s: unable to add port %d bus %d\n",
1953 __FUNCTION__, the_port->line, pdev->bus->number); 1953 __func__, the_port->line, pdev->bus->number);
1954 } else { 1954 } else {
1955 DPRINT_CONFIG(("IOC3 serial port %d irq %d bus %d\n", 1955 DPRINT_CONFIG(("IOC3 serial port %d irq %d bus %d\n",
1956 the_port->line, the_port->irq, pdev->bus->number)); 1956 the_port->line, the_port->irq, pdev->bus->number));
@@ -2017,7 +2017,7 @@ ioc3uart_probe(struct ioc3_submodule *is, struct ioc3_driver_data *idd)
2017 struct ioc3_port *ports[PORTS_PER_CARD]; 2017 struct ioc3_port *ports[PORTS_PER_CARD];
2018 int phys_port; 2018 int phys_port;
2019 2019
2020 DPRINT_CONFIG(("%s (0x%p, 0x%p)\n", __FUNCTION__, is, idd)); 2020 DPRINT_CONFIG(("%s (0x%p, 0x%p)\n", __func__, is, idd));
2021 2021
2022 card_ptr = kzalloc(sizeof(struct ioc3_card), GFP_KERNEL); 2022 card_ptr = kzalloc(sizeof(struct ioc3_card), GFP_KERNEL);
2023 if (!card_ptr) { 2023 if (!card_ptr) {
@@ -2067,7 +2067,7 @@ ioc3uart_probe(struct ioc3_submodule *is, struct ioc3_driver_data *idd)
2067 2067
2068 DPRINT_CONFIG(("%s : Port A ip_serial_regs 0x%p " 2068 DPRINT_CONFIG(("%s : Port A ip_serial_regs 0x%p "
2069 "ip_uart_regs 0x%p\n", 2069 "ip_uart_regs 0x%p\n",
2070 __FUNCTION__, 2070 __func__,
2071 (void *)port->ip_serial_regs, 2071 (void *)port->ip_serial_regs,
2072 (void *)port->ip_uart_regs)); 2072 (void *)port->ip_uart_regs));
2073 2073
@@ -2082,7 +2082,7 @@ ioc3uart_probe(struct ioc3_submodule *is, struct ioc3_driver_data *idd)
2082 DPRINT_CONFIG(("%s : Port A ip_cpu_ringbuf 0x%p " 2082 DPRINT_CONFIG(("%s : Port A ip_cpu_ringbuf 0x%p "
2083 "ip_dma_ringbuf 0x%p, ip_inring 0x%p " 2083 "ip_dma_ringbuf 0x%p, ip_inring 0x%p "
2084 "ip_outring 0x%p\n", 2084 "ip_outring 0x%p\n",
2085 __FUNCTION__, 2085 __func__,
2086 (void *)port->ip_cpu_ringbuf, 2086 (void *)port->ip_cpu_ringbuf,
2087 (void *)port->ip_dma_ringbuf, 2087 (void *)port->ip_dma_ringbuf,
2088 (void *)port->ip_inring, 2088 (void *)port->ip_inring,
@@ -2094,7 +2094,7 @@ ioc3uart_probe(struct ioc3_submodule *is, struct ioc3_driver_data *idd)
2094 2094
2095 DPRINT_CONFIG(("%s : Port B ip_serial_regs 0x%p " 2095 DPRINT_CONFIG(("%s : Port B ip_serial_regs 0x%p "
2096 "ip_uart_regs 0x%p\n", 2096 "ip_uart_regs 0x%p\n",
2097 __FUNCTION__, 2097 __func__,
2098 (void *)port->ip_serial_regs, 2098 (void *)port->ip_serial_regs,
2099 (void *)port->ip_uart_regs)); 2099 (void *)port->ip_uart_regs));
2100 2100
@@ -2108,7 +2108,7 @@ ioc3uart_probe(struct ioc3_submodule *is, struct ioc3_driver_data *idd)
2108 DPRINT_CONFIG(("%s : Port B ip_cpu_ringbuf 0x%p " 2108 DPRINT_CONFIG(("%s : Port B ip_cpu_ringbuf 0x%p "
2109 "ip_dma_ringbuf 0x%p, ip_inring 0x%p " 2109 "ip_dma_ringbuf 0x%p, ip_inring 0x%p "
2110 "ip_outring 0x%p\n", 2110 "ip_outring 0x%p\n",
2111 __FUNCTION__, 2111 __func__,
2112 (void *)port->ip_cpu_ringbuf, 2112 (void *)port->ip_cpu_ringbuf,
2113 (void *)port->ip_dma_ringbuf, 2113 (void *)port->ip_dma_ringbuf,
2114 (void *)port->ip_inring, 2114 (void *)port->ip_inring,
@@ -2116,7 +2116,7 @@ ioc3uart_probe(struct ioc3_submodule *is, struct ioc3_driver_data *idd)
2116 } 2116 }
2117 2117
2118 DPRINT_CONFIG(("%s : port %d [addr 0x%p] card_ptr 0x%p", 2118 DPRINT_CONFIG(("%s : port %d [addr 0x%p] card_ptr 0x%p",
2119 __FUNCTION__, 2119 __func__,
2120 phys_port, (void *)port, (void *)card_ptr)); 2120 phys_port, (void *)port, (void *)card_ptr));
2121 DPRINT_CONFIG((" ip_serial_regs 0x%p ip_uart_regs 0x%p\n", 2121 DPRINT_CONFIG((" ip_serial_regs 0x%p ip_uart_regs 0x%p\n",
2122 (void *)port->ip_serial_regs, 2122 (void *)port->ip_serial_regs,
@@ -2127,7 +2127,7 @@ ioc3uart_probe(struct ioc3_submodule *is, struct ioc3_driver_data *idd)
2127 2127
2128 DPRINT_CONFIG(("%s: phys_port %d port 0x%p inring 0x%p " 2128 DPRINT_CONFIG(("%s: phys_port %d port 0x%p inring 0x%p "
2129 "outring 0x%p\n", 2129 "outring 0x%p\n",
2130 __FUNCTION__, 2130 __func__,
2131 phys_port, (void *)port, 2131 phys_port, (void *)port,
2132 (void *)port->ip_inring, 2132 (void *)port->ip_inring,
2133 (void *)port->ip_outring)); 2133 (void *)port->ip_outring));
@@ -2170,7 +2170,7 @@ static int __devinit ioc3uart_init(void)
2170 if ((ret = uart_register_driver(&ioc3_uart)) < 0) { 2170 if ((ret = uart_register_driver(&ioc3_uart)) < 0) {
2171 printk(KERN_WARNING 2171 printk(KERN_WARNING
2172 "%s: Couldn't register IOC3 uart serial driver\n", 2172 "%s: Couldn't register IOC3 uart serial driver\n",
2173 __FUNCTION__); 2173 __func__);
2174 return ret; 2174 return ret;
2175 } 2175 }
2176 ret = ioc3_register_submodule(&ioc3uart_submodule); 2176 ret = ioc3_register_submodule(&ioc3uart_submodule);
diff --git a/drivers/serial/ioc4_serial.c b/drivers/serial/ioc4_serial.c
index 0c179384fb0c..49b8a82b7b9f 100644
--- a/drivers/serial/ioc4_serial.c
+++ b/drivers/serial/ioc4_serial.c
@@ -889,7 +889,7 @@ static int inline port_init(struct ioc4_port *port)
889 889
890 ring_pci_addr = (unsigned long __iomem)port->ip_dma_ringbuf; 890 ring_pci_addr = (unsigned long __iomem)port->ip_dma_ringbuf;
891 DPRINT_CONFIG(("%s: ring_pci_addr 0x%lx\n", 891 DPRINT_CONFIG(("%s: ring_pci_addr 0x%lx\n",
892 __FUNCTION__, ring_pci_addr)); 892 __func__, ring_pci_addr));
893 893
894 writel((unsigned int)((uint64_t)ring_pci_addr >> 32), sbbr_h); 894 writel((unsigned int)((uint64_t)ring_pci_addr >> 32), sbbr_h);
895 writel((unsigned int)ring_pci_addr | IOC4_BUF_SIZE_BIT, sbbr_l); 895 writel((unsigned int)ring_pci_addr | IOC4_BUF_SIZE_BIT, sbbr_l);
@@ -1028,7 +1028,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
1028 spin_lock_irqsave(&soft->is_ir_lock, flag); 1028 spin_lock_irqsave(&soft->is_ir_lock, flag);
1029 printk ("%s : %d : mem 0x%p sio_ir 0x%x sio_ies 0x%x " 1029 printk ("%s : %d : mem 0x%p sio_ir 0x%x sio_ies 0x%x "
1030 "other_ir 0x%x other_ies 0x%x mask 0x%x\n", 1030 "other_ir 0x%x other_ies 0x%x mask 0x%x\n",
1031 __FUNCTION__, __LINE__, 1031 __func__, __LINE__,
1032 (void *)mem, readl(&mem->sio_ir.raw), 1032 (void *)mem, readl(&mem->sio_ir.raw),
1033 readl(&mem->sio_ies.raw), 1033 readl(&mem->sio_ies.raw),
1034 readl(&mem->other_ir.raw), 1034 readl(&mem->other_ir.raw),
@@ -1155,14 +1155,14 @@ static int inline ioc4_attach_local(struct ioc4_driver_data *idd)
1155 (TOTAL_RING_BUF_SIZE - 1)) == 0)); 1155 (TOTAL_RING_BUF_SIZE - 1)) == 0));
1156 DPRINT_CONFIG(("%s : ip_cpu_ringbuf 0x%p " 1156 DPRINT_CONFIG(("%s : ip_cpu_ringbuf 0x%p "
1157 "ip_dma_ringbuf 0x%p\n", 1157 "ip_dma_ringbuf 0x%p\n",
1158 __FUNCTION__, 1158 __func__,
1159 (void *)port->ip_cpu_ringbuf, 1159 (void *)port->ip_cpu_ringbuf,
1160 (void *)port->ip_dma_ringbuf)); 1160 (void *)port->ip_dma_ringbuf));
1161 port->ip_inring = RING(port, RX_0_OR_2); 1161 port->ip_inring = RING(port, RX_0_OR_2);
1162 port->ip_outring = RING(port, TX_0_OR_2); 1162 port->ip_outring = RING(port, TX_0_OR_2);
1163 } 1163 }
1164 DPRINT_CONFIG(("%s : port %d [addr 0x%p] control 0x%p", 1164 DPRINT_CONFIG(("%s : port %d [addr 0x%p] control 0x%p",
1165 __FUNCTION__, 1165 __func__,
1166 port_number, (void *)port, (void *)control)); 1166 port_number, (void *)port, (void *)control));
1167 DPRINT_CONFIG((" ip_serial_regs 0x%p ip_uart_regs 0x%p\n", 1167 DPRINT_CONFIG((" ip_serial_regs 0x%p ip_uart_regs 0x%p\n",
1168 (void *)port->ip_serial_regs, 1168 (void *)port->ip_serial_regs,
@@ -1173,7 +1173,7 @@ static int inline ioc4_attach_local(struct ioc4_driver_data *idd)
1173 1173
1174 DPRINT_CONFIG(("%s: port_number %d port 0x%p inring 0x%p " 1174 DPRINT_CONFIG(("%s: port_number %d port 0x%p inring 0x%p "
1175 "outring 0x%p\n", 1175 "outring 0x%p\n",
1176 __FUNCTION__, 1176 __func__,
1177 port_number, (void *)port, 1177 port_number, (void *)port,
1178 (void *)port->ip_inring, 1178 (void *)port->ip_inring,
1179 (void *)port->ip_outring)); 1179 (void *)port->ip_outring));
@@ -1317,7 +1317,7 @@ config_port(struct ioc4_port *port,
1317 int spiniter = 0; 1317 int spiniter = 0;
1318 1318
1319 DPRINT_CONFIG(("%s: baud %d byte_size %d stop %d parenb %d parodd %d\n", 1319 DPRINT_CONFIG(("%s: baud %d byte_size %d stop %d parenb %d parodd %d\n",
1320 __FUNCTION__, baud, byte_size, stop_bits, parenb, parodd)); 1320 __func__, baud, byte_size, stop_bits, parenb, parodd));
1321 1321
1322 if (set_baud(port, baud)) 1322 if (set_baud(port, baud))
1323 return 1; 1323 return 1;
@@ -1725,7 +1725,7 @@ ioc4_change_speed(struct uart_port *the_port,
1725 } 1725 }
1726 baud = uart_get_baud_rate(the_port, new_termios, old_termios, 1726 baud = uart_get_baud_rate(the_port, new_termios, old_termios,
1727 MIN_BAUD_SUPPORTED, MAX_BAUD_SUPPORTED); 1727 MIN_BAUD_SUPPORTED, MAX_BAUD_SUPPORTED);
1728 DPRINT_CONFIG(("%s: returned baud %d\n", __FUNCTION__, baud)); 1728 DPRINT_CONFIG(("%s: returned baud %d\n", __func__, baud));
1729 1729
1730 /* default is 9600 */ 1730 /* default is 9600 */
1731 if (!baud) 1731 if (!baud)
@@ -1765,7 +1765,7 @@ ioc4_change_speed(struct uart_port *the_port,
1765 DPRINT_CONFIG(("%s : port 0x%p cflag 0%o " 1765 DPRINT_CONFIG(("%s : port 0x%p cflag 0%o "
1766 "config_port(baud %d data %d stop %d p enable %d parity %d)," 1766 "config_port(baud %d data %d stop %d p enable %d parity %d),"
1767 " notification 0x%x\n", 1767 " notification 0x%x\n",
1768 __FUNCTION__, (void *)port, cflag, baud, new_data, new_stop, 1768 __func__, (void *)port, cflag, baud, new_data, new_stop,
1769 new_parity_enable, new_parity, the_port->ignore_status_mask)); 1769 new_parity_enable, new_parity, the_port->ignore_status_mask));
1770 1770
1771 if ((config_port(port, baud, /* baud */ 1771 if ((config_port(port, baud, /* baud */
@@ -2715,7 +2715,7 @@ ioc4_serial_core_attach(struct pci_dev *pdev, int port_type)
2715 2715
2716 2716
2717 DPRINT_CONFIG(("%s: attach pdev 0x%p - control 0x%p\n", 2717 DPRINT_CONFIG(("%s: attach pdev 0x%p - control 0x%p\n",
2718 __FUNCTION__, pdev, (void *)control)); 2718 __func__, pdev, (void *)control));
2719 2719
2720 if (!control) 2720 if (!control)
2721 return -ENODEV; 2721 return -ENODEV;
@@ -2734,7 +2734,7 @@ ioc4_serial_core_attach(struct pci_dev *pdev, int port_type)
2734 port->ip_all_ports[port_type_idx] = the_port; 2734 port->ip_all_ports[port_type_idx] = the_port;
2735 2735
2736 DPRINT_CONFIG(("%s: attach the_port 0x%p / port 0x%p : type %s\n", 2736 DPRINT_CONFIG(("%s: attach the_port 0x%p / port 0x%p : type %s\n",
2737 __FUNCTION__, (void *)the_port, 2737 __func__, (void *)the_port,
2738 (void *)port, 2738 (void *)port,
2739 port_type == PROTO_RS232 ? "rs232" : "rs422")); 2739 port_type == PROTO_RS232 ? "rs232" : "rs422"));
2740 2740
@@ -2752,7 +2752,7 @@ ioc4_serial_core_attach(struct pci_dev *pdev, int port_type)
2752 if (uart_add_one_port(u_driver, the_port) < 0) { 2752 if (uart_add_one_port(u_driver, the_port) < 0) {
2753 printk(KERN_WARNING 2753 printk(KERN_WARNING
2754 "%s: unable to add port %d bus %d\n", 2754 "%s: unable to add port %d bus %d\n",
2755 __FUNCTION__, the_port->line, pdev->bus->number); 2755 __func__, the_port->line, pdev->bus->number);
2756 } else { 2756 } else {
2757 DPRINT_CONFIG( 2757 DPRINT_CONFIG(
2758 ("IOC4 serial port %d irq = %d, bus %d\n", 2758 ("IOC4 serial port %d irq = %d, bus %d\n",
@@ -2777,7 +2777,7 @@ ioc4_serial_attach_one(struct ioc4_driver_data *idd)
2777 int ret = 0; 2777 int ret = 0;
2778 2778
2779 2779
2780 DPRINT_CONFIG(("%s (0x%p, 0x%p)\n", __FUNCTION__, idd->idd_pdev, 2780 DPRINT_CONFIG(("%s (0x%p, 0x%p)\n", __func__, idd->idd_pdev,
2781 idd->idd_pci_id)); 2781 idd->idd_pci_id));
2782 2782
2783 /* PCI-RT does not bring out serial connections. 2783 /* PCI-RT does not bring out serial connections.
@@ -2806,7 +2806,7 @@ ioc4_serial_attach_one(struct ioc4_driver_data *idd)
2806 goto out2; 2806 goto out2;
2807 } 2807 }
2808 DPRINT_CONFIG(("%s : mem 0x%p, serial 0x%p\n", 2808 DPRINT_CONFIG(("%s : mem 0x%p, serial 0x%p\n",
2809 __FUNCTION__, (void *)idd->idd_misc_regs, 2809 __func__, (void *)idd->idd_misc_regs,
2810 (void *)serial)); 2810 (void *)serial));
2811 2811
2812 /* Get memory for the new card */ 2812 /* Get memory for the new card */
@@ -2858,7 +2858,7 @@ ioc4_serial_attach_one(struct ioc4_driver_data *idd)
2858 } else { 2858 } else {
2859 printk(KERN_WARNING 2859 printk(KERN_WARNING
2860 "%s : request_irq fails for IRQ 0x%x\n ", 2860 "%s : request_irq fails for IRQ 0x%x\n ",
2861 __FUNCTION__, idd->idd_pdev->irq); 2861 __func__, idd->idd_pdev->irq);
2862 } 2862 }
2863 ret = ioc4_attach_local(idd); 2863 ret = ioc4_attach_local(idd);
2864 if (ret) 2864 if (ret)
@@ -2911,13 +2911,13 @@ int ioc4_serial_init(void)
2911 if ((ret = uart_register_driver(&ioc4_uart_rs232)) < 0) { 2911 if ((ret = uart_register_driver(&ioc4_uart_rs232)) < 0) {
2912 printk(KERN_WARNING 2912 printk(KERN_WARNING
2913 "%s: Couldn't register rs232 IOC4 serial driver\n", 2913 "%s: Couldn't register rs232 IOC4 serial driver\n",
2914 __FUNCTION__); 2914 __func__);
2915 return ret; 2915 return ret;
2916 } 2916 }
2917 if ((ret = uart_register_driver(&ioc4_uart_rs422)) < 0) { 2917 if ((ret = uart_register_driver(&ioc4_uart_rs422)) < 0) {
2918 printk(KERN_WARNING 2918 printk(KERN_WARNING
2919 "%s: Couldn't register rs422 IOC4 serial driver\n", 2919 "%s: Couldn't register rs422 IOC4 serial driver\n",
2920 __FUNCTION__); 2920 __func__);
2921 return ret; 2921 return ret;
2922 } 2922 }
2923 2923
diff --git a/drivers/serial/jsm/jsm.h b/drivers/serial/jsm/jsm.h
index 12c934a1f274..8871aaa3dba6 100644
--- a/drivers/serial/jsm/jsm.h
+++ b/drivers/serial/jsm/jsm.h
@@ -373,6 +373,7 @@ struct neo_uart_struct {
373#define PCI_DEVICE_NEO_2DB9PRI_PCI_NAME "Neo 2 - DB9 Universal PCI - Powered Ring Indicator" 373#define PCI_DEVICE_NEO_2DB9PRI_PCI_NAME "Neo 2 - DB9 Universal PCI - Powered Ring Indicator"
374#define PCI_DEVICE_NEO_2RJ45_PCI_NAME "Neo 2 - RJ45 Universal PCI" 374#define PCI_DEVICE_NEO_2RJ45_PCI_NAME "Neo 2 - RJ45 Universal PCI"
375#define PCI_DEVICE_NEO_2RJ45PRI_PCI_NAME "Neo 2 - RJ45 Universal PCI - Powered Ring Indicator" 375#define PCI_DEVICE_NEO_2RJ45PRI_PCI_NAME "Neo 2 - RJ45 Universal PCI - Powered Ring Indicator"
376#define PCIE_DEVICE_NEO_IBM_PCI_NAME "Neo 4 - PCI Express - IBM"
376 377
377/* 378/*
378 * Our Global Variables. 379 * Our Global Variables.
diff --git a/drivers/serial/jsm/jsm_driver.c b/drivers/serial/jsm/jsm_driver.c
index 6767ee381cd1..338cf8a08b43 100644
--- a/drivers/serial/jsm/jsm_driver.c
+++ b/drivers/serial/jsm/jsm_driver.c
@@ -82,7 +82,10 @@ static int jsm_probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
82 /* store the info for the board we've found */ 82 /* store the info for the board we've found */
83 brd->boardnum = adapter_count++; 83 brd->boardnum = adapter_count++;
84 brd->pci_dev = pdev; 84 brd->pci_dev = pdev;
85 brd->maxports = 2; 85 if (pdev->device == PCIE_DEVICE_ID_NEO_4_IBM)
86 brd->maxports = 4;
87 else
88 brd->maxports = 2;
86 89
87 spin_lock_init(&brd->bd_lock); 90 spin_lock_init(&brd->bd_lock);
88 spin_lock_init(&brd->bd_intr_lock); 91 spin_lock_init(&brd->bd_intr_lock);
@@ -208,6 +211,7 @@ static struct pci_device_id jsm_pci_tbl[] = {
208 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2DB9PRI), 0, 0, 1 }, 211 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2DB9PRI), 0, 0, 1 },
209 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2RJ45), 0, 0, 2 }, 212 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2RJ45), 0, 0, 2 },
210 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2RJ45PRI), 0, 0, 3 }, 213 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_NEO_2RJ45PRI), 0, 0, 3 },
214 { PCI_DEVICE(PCI_VENDOR_ID_DIGI, PCIE_DEVICE_ID_NEO_4_IBM), 0, 0, 4 },
211 { 0, } 215 { 0, }
212}; 216};
213MODULE_DEVICE_TABLE(pci, jsm_pci_tbl); 217MODULE_DEVICE_TABLE(pci, jsm_pci_tbl);
diff --git a/drivers/serial/kgdboc.c b/drivers/serial/kgdboc.c
index 9cf03327386a..eadc1ab6bbce 100644
--- a/drivers/serial/kgdboc.c
+++ b/drivers/serial/kgdboc.c
@@ -96,12 +96,14 @@ static void cleanup_kgdboc(void)
96 96
97static int kgdboc_get_char(void) 97static int kgdboc_get_char(void)
98{ 98{
99 return kgdb_tty_driver->poll_get_char(kgdb_tty_driver, kgdb_tty_line); 99 return kgdb_tty_driver->ops->poll_get_char(kgdb_tty_driver,
100 kgdb_tty_line);
100} 101}
101 102
102static void kgdboc_put_char(u8 chr) 103static void kgdboc_put_char(u8 chr)
103{ 104{
104 kgdb_tty_driver->poll_put_char(kgdb_tty_driver, kgdb_tty_line, chr); 105 kgdb_tty_driver->ops->poll_put_char(kgdb_tty_driver,
106 kgdb_tty_line, chr);
105} 107}
106 108
107static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp) 109static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
diff --git a/drivers/serial/mcfserial.c b/drivers/serial/mcfserial.c
index ddd3aa50d4ad..43af40d59b8a 100644
--- a/drivers/serial/mcfserial.c
+++ b/drivers/serial/mcfserial.c
@@ -1072,18 +1072,6 @@ static int mcfrs_ioctl(struct tty_struct *tty, struct file * file,
1072 tty_wait_until_sent(tty, 0); 1072 tty_wait_until_sent(tty, 0);
1073 send_break(info, arg ? arg*(HZ/10) : HZ/4); 1073 send_break(info, arg ? arg*(HZ/10) : HZ/4);
1074 return 0; 1074 return 0;
1075 case TIOCGSOFTCAR:
1076 error = put_user(C_CLOCAL(tty) ? 1 : 0,
1077 (unsigned long *) arg);
1078 if (error)
1079 return error;
1080 return 0;
1081 case TIOCSSOFTCAR:
1082 get_user(arg, (unsigned long *) arg);
1083 tty->termios->c_cflag =
1084 ((tty->termios->c_cflag & ~CLOCAL) |
1085 (arg ? CLOCAL : 0));
1086 return 0;
1087 case TIOCGSERIAL: 1075 case TIOCGSERIAL:
1088 if (access_ok(VERIFY_WRITE, (void *) arg, 1076 if (access_ok(VERIFY_WRITE, (void *) arg,
1089 sizeof(struct serial_struct))) 1077 sizeof(struct serial_struct)))
@@ -1222,8 +1210,7 @@ static void mcfrs_close(struct tty_struct *tty, struct file * filp)
1222 } else 1210 } else
1223#endif 1211#endif
1224 shutdown(info); 1212 shutdown(info);
1225 if (tty->driver->flush_buffer) 1213 mcfrs_flush_buffer(tty);
1226 tty->driver->flush_buffer(tty);
1227 tty_ldisc_flush(tty); 1214 tty_ldisc_flush(tty);
1228 1215
1229 tty->closing = 0; 1216 tty->closing = 0;
@@ -1276,6 +1263,8 @@ mcfrs_wait_until_sent(struct tty_struct *tty, int timeout)
1276 * Note: we have to use pretty tight timings here to satisfy 1263 * Note: we have to use pretty tight timings here to satisfy
1277 * the NIST-PCTS. 1264 * the NIST-PCTS.
1278 */ 1265 */
1266 lock_kernel();
1267
1279 fifo_time = (MCF5272_FIFO_SIZE * HZ * 10) / info->baud; 1268 fifo_time = (MCF5272_FIFO_SIZE * HZ * 10) / info->baud;
1280 char_time = fifo_time / 5; 1269 char_time = fifo_time / 5;
1281 if (char_time == 0) 1270 if (char_time == 0)
@@ -1312,6 +1301,7 @@ mcfrs_wait_until_sent(struct tty_struct *tty, int timeout)
1312 if (timeout && time_after(jiffies, orig_jiffies + timeout)) 1301 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1313 break; 1302 break;
1314 } 1303 }
1304 unlock_kernel();
1315#else 1305#else
1316 /* 1306 /*
1317 * For the other coldfire models, assume all data has been sent 1307 * For the other coldfire models, assume all data has been sent
@@ -1907,7 +1897,7 @@ static struct tty_driver *mcfrs_console_device(struct console *c, int *index)
1907 * This is used for console output. 1897 * This is used for console output.
1908 */ 1898 */
1909 1899
1910void mcfrs_put_char(char ch) 1900int mcfrs_put_char(char ch)
1911{ 1901{
1912 volatile unsigned char *uartp; 1902 volatile unsigned char *uartp;
1913 unsigned long flags; 1903 unsigned long flags;
@@ -1931,7 +1921,7 @@ void mcfrs_put_char(char ch)
1931 mcfrs_init_console(); /* try and get it back */ 1921 mcfrs_init_console(); /* try and get it back */
1932 local_irq_restore(flags); 1922 local_irq_restore(flags);
1933 1923
1934 return; 1924 return 1;
1935} 1925}
1936 1926
1937 1927
diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index d93b3578c5e2..efc971d9647b 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -783,7 +783,9 @@ mpc52xx_uart_int_rx_chars(struct uart_port *port)
783 } 783 }
784 } 784 }
785 785
786 spin_unlock(&port->lock);
786 tty_flip_buffer_push(tty); 787 tty_flip_buffer_push(tty);
788 spin_lock(&port->lock);
787 789
788 return psc_ops->raw_rx_rdy(port); 790 return psc_ops->raw_rx_rdy(port);
789} 791}
@@ -1221,8 +1223,8 @@ static struct of_device_id mpc52xx_uart_of_match[] = {
1221#endif 1223#endif
1222#ifdef CONFIG_PPC_MPC512x 1224#ifdef CONFIG_PPC_MPC512x
1223 { .compatible = "fsl,mpc5121-psc-uart", .data = &mpc512x_psc_ops, }, 1225 { .compatible = "fsl,mpc5121-psc-uart", .data = &mpc512x_psc_ops, },
1224 {},
1225#endif 1226#endif
1227 {},
1226}; 1228};
1227 1229
1228static int __devinit 1230static int __devinit
diff --git a/drivers/serial/netx-serial.c b/drivers/serial/netx-serial.c
index 3123ffeac8ad..81ac9bb4f39b 100644
--- a/drivers/serial/netx-serial.c
+++ b/drivers/serial/netx-serial.c
@@ -287,6 +287,7 @@ static void netx_set_mctrl(struct uart_port *port, unsigned int mctrl)
287{ 287{
288 unsigned int val; 288 unsigned int val;
289 289
290 /* FIXME: Locking needed ? */
290 if (mctrl & TIOCM_RTS) { 291 if (mctrl & TIOCM_RTS) {
291 val = readl(port->membase + UART_RTS_CR); 292 val = readl(port->membase + UART_RTS_CR);
292 writel(val | RTS_CR_RTS, port->membase + UART_RTS_CR); 293 writel(val | RTS_CR_RTS, port->membase + UART_RTS_CR);
diff --git a/drivers/serial/s3c2410.c b/drivers/serial/s3c2410.c
index da5a02cb4f63..2b6a013639e6 100644
--- a/drivers/serial/s3c2410.c
+++ b/drivers/serial/s3c2410.c
@@ -1096,13 +1096,13 @@ static int s3c24xx_serial_probe(struct platform_device *dev,
1096 ourport = &s3c24xx_serial_ports[probe_index]; 1096 ourport = &s3c24xx_serial_ports[probe_index];
1097 probe_index++; 1097 probe_index++;
1098 1098
1099 dbg("%s: initialising port %p...\n", __FUNCTION__, ourport); 1099 dbg("%s: initialising port %p...\n", __func__, ourport);
1100 1100
1101 ret = s3c24xx_serial_init_port(ourport, info, dev); 1101 ret = s3c24xx_serial_init_port(ourport, info, dev);
1102 if (ret < 0) 1102 if (ret < 0)
1103 goto probe_err; 1103 goto probe_err;
1104 1104
1105 dbg("%s: adding port\n", __FUNCTION__); 1105 dbg("%s: adding port\n", __func__);
1106 uart_add_one_port(&s3c24xx_uart_drv, &ourport->port); 1106 uart_add_one_port(&s3c24xx_uart_drv, &ourport->port);
1107 platform_set_drvdata(dev, &ourport->port); 1107 platform_set_drvdata(dev, &ourport->port);
1108 1108
@@ -1587,7 +1587,7 @@ static int s3c2412_serial_resetport(struct uart_port *port,
1587 unsigned long ucon = rd_regl(port, S3C2410_UCON); 1587 unsigned long ucon = rd_regl(port, S3C2410_UCON);
1588 1588
1589 dbg("%s: port=%p (%08lx), cfg=%p\n", 1589 dbg("%s: port=%p (%08lx), cfg=%p\n",
1590 __FUNCTION__, port, port->mapbase, cfg); 1590 __func__, port, port->mapbase, cfg);
1591 1591
1592 /* ensure we don't change the clock settings... */ 1592 /* ensure we don't change the clock settings... */
1593 1593
diff --git a/drivers/serial/sa1100.c b/drivers/serial/sa1100.c
index 67b2338913c2..62b38582f5e9 100644
--- a/drivers/serial/sa1100.c
+++ b/drivers/serial/sa1100.c
@@ -655,7 +655,7 @@ void __init sa1100_register_uart_fns(struct sa1100_port_fns *fns)
655void __init sa1100_register_uart(int idx, int port) 655void __init sa1100_register_uart(int idx, int port)
656{ 656{
657 if (idx >= NR_PORTS) { 657 if (idx >= NR_PORTS) {
658 printk(KERN_ERR "%s: bad index number %d\n", __FUNCTION__, idx); 658 printk(KERN_ERR "%s: bad index number %d\n", __func__, idx);
659 return; 659 return;
660 } 660 }
661 661
@@ -682,7 +682,7 @@ void __init sa1100_register_uart(int idx, int port)
682 break; 682 break;
683 683
684 default: 684 default:
685 printk(KERN_ERR "%s: bad port number %d\n", __FUNCTION__, port); 685 printk(KERN_ERR "%s: bad port number %d\n", __func__, port);
686 } 686 }
687} 687}
688 688
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index 977ce820ce30..1e2b9d826f69 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -422,6 +422,7 @@ uart_get_divisor(struct uart_port *port, unsigned int baud)
422 422
423EXPORT_SYMBOL(uart_get_divisor); 423EXPORT_SYMBOL(uart_get_divisor);
424 424
425/* FIXME: Consistent locking policy */
425static void 426static void
426uart_change_speed(struct uart_state *state, struct ktermios *old_termios) 427uart_change_speed(struct uart_state *state, struct ktermios *old_termios)
427{ 428{
@@ -454,27 +455,30 @@ uart_change_speed(struct uart_state *state, struct ktermios *old_termios)
454 port->ops->set_termios(port, termios, old_termios); 455 port->ops->set_termios(port, termios, old_termios);
455} 456}
456 457
457static inline void 458static inline int
458__uart_put_char(struct uart_port *port, struct circ_buf *circ, unsigned char c) 459__uart_put_char(struct uart_port *port, struct circ_buf *circ, unsigned char c)
459{ 460{
460 unsigned long flags; 461 unsigned long flags;
462 int ret = 0;
461 463
462 if (!circ->buf) 464 if (!circ->buf)
463 return; 465 return 0;
464 466
465 spin_lock_irqsave(&port->lock, flags); 467 spin_lock_irqsave(&port->lock, flags);
466 if (uart_circ_chars_free(circ) != 0) { 468 if (uart_circ_chars_free(circ) != 0) {
467 circ->buf[circ->head] = c; 469 circ->buf[circ->head] = c;
468 circ->head = (circ->head + 1) & (UART_XMIT_SIZE - 1); 470 circ->head = (circ->head + 1) & (UART_XMIT_SIZE - 1);
471 ret = 1;
469 } 472 }
470 spin_unlock_irqrestore(&port->lock, flags); 473 spin_unlock_irqrestore(&port->lock, flags);
474 return ret;
471} 475}
472 476
473static void uart_put_char(struct tty_struct *tty, unsigned char ch) 477static int uart_put_char(struct tty_struct *tty, unsigned char ch)
474{ 478{
475 struct uart_state *state = tty->driver_data; 479 struct uart_state *state = tty->driver_data;
476 480
477 __uart_put_char(state->port, &state->info->xmit, ch); 481 return __uart_put_char(state->port, &state->info->xmit, ch);
478} 482}
479 483
480static void uart_flush_chars(struct tty_struct *tty) 484static void uart_flush_chars(struct tty_struct *tty)
@@ -528,15 +532,25 @@ uart_write(struct tty_struct *tty, const unsigned char *buf, int count)
528static int uart_write_room(struct tty_struct *tty) 532static int uart_write_room(struct tty_struct *tty)
529{ 533{
530 struct uart_state *state = tty->driver_data; 534 struct uart_state *state = tty->driver_data;
535 unsigned long flags;
536 int ret;
531 537
532 return uart_circ_chars_free(&state->info->xmit); 538 spin_lock_irqsave(&state->port->lock, flags);
539 ret = uart_circ_chars_free(&state->info->xmit);
540 spin_unlock_irqrestore(&state->port->lock, flags);
541 return ret;
533} 542}
534 543
535static int uart_chars_in_buffer(struct tty_struct *tty) 544static int uart_chars_in_buffer(struct tty_struct *tty)
536{ 545{
537 struct uart_state *state = tty->driver_data; 546 struct uart_state *state = tty->driver_data;
547 unsigned long flags;
548 int ret;
538 549
539 return uart_circ_chars_pending(&state->info->xmit); 550 spin_lock_irqsave(&state->port->lock, flags);
551 ret = uart_circ_chars_pending(&state->info->xmit);
552 spin_unlock_irqrestore(&state->port->lock, flags);
553 return ret;
540} 554}
541 555
542static void uart_flush_buffer(struct tty_struct *tty) 556static void uart_flush_buffer(struct tty_struct *tty)
@@ -618,6 +632,11 @@ static int uart_get_info(struct uart_state *state,
618 struct serial_struct tmp; 632 struct serial_struct tmp;
619 633
620 memset(&tmp, 0, sizeof(tmp)); 634 memset(&tmp, 0, sizeof(tmp));
635
636 /* Ensure the state we copy is consistent and no hardware changes
637 occur as we go */
638 mutex_lock(&state->mutex);
639
621 tmp.type = port->type; 640 tmp.type = port->type;
622 tmp.line = port->line; 641 tmp.line = port->line;
623 tmp.port = port->iobase; 642 tmp.port = port->iobase;
@@ -637,6 +656,8 @@ static int uart_get_info(struct uart_state *state,
637 tmp.iomem_reg_shift = port->regshift; 656 tmp.iomem_reg_shift = port->regshift;
638 tmp.iomem_base = (void *)(unsigned long)port->mapbase; 657 tmp.iomem_base = (void *)(unsigned long)port->mapbase;
639 658
659 mutex_unlock(&state->mutex);
660
640 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 661 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
641 return -EFAULT; 662 return -EFAULT;
642 return 0; 663 return 0;
@@ -914,8 +935,6 @@ static void uart_break_ctl(struct tty_struct *tty, int break_state)
914 struct uart_state *state = tty->driver_data; 935 struct uart_state *state = tty->driver_data;
915 struct uart_port *port = state->port; 936 struct uart_port *port = state->port;
916 937
917 BUG_ON(!kernel_locked());
918
919 mutex_lock(&state->mutex); 938 mutex_lock(&state->mutex);
920 939
921 if (port->type != PORT_UNKNOWN) 940 if (port->type != PORT_UNKNOWN)
@@ -1059,7 +1078,7 @@ static int uart_get_count(struct uart_state *state,
1059} 1078}
1060 1079
1061/* 1080/*
1062 * Called via sys_ioctl under the BKL. We can use spin_lock_irq() here. 1081 * Called via sys_ioctl. We can use spin_lock_irq() here.
1063 */ 1082 */
1064static int 1083static int
1065uart_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd, 1084uart_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd,
@@ -1069,7 +1088,6 @@ uart_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd,
1069 void __user *uarg = (void __user *)arg; 1088 void __user *uarg = (void __user *)arg;
1070 int ret = -ENOIOCTLCMD; 1089 int ret = -ENOIOCTLCMD;
1071 1090
1072 BUG_ON(!kernel_locked());
1073 1091
1074 /* 1092 /*
1075 * These ioctls don't rely on the hardware to be present. 1093 * These ioctls don't rely on the hardware to be present.
@@ -1140,9 +1158,9 @@ uart_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd,
1140 break; 1158 break;
1141 } 1159 }
1142 } 1160 }
1143 out_up: 1161out_up:
1144 mutex_unlock(&state->mutex); 1162 mutex_unlock(&state->mutex);
1145 out: 1163out:
1146 return ret; 1164 return ret;
1147} 1165}
1148 1166
@@ -1153,7 +1171,6 @@ static void uart_set_termios(struct tty_struct *tty,
1153 unsigned long flags; 1171 unsigned long flags;
1154 unsigned int cflag = tty->termios->c_cflag; 1172 unsigned int cflag = tty->termios->c_cflag;
1155 1173
1156 BUG_ON(!kernel_locked());
1157 1174
1158 /* 1175 /*
1159 * These are the bits that are used to setup various 1176 * These are the bits that are used to setup various
@@ -1165,8 +1182,9 @@ static void uart_set_termios(struct tty_struct *tty,
1165 if ((cflag ^ old_termios->c_cflag) == 0 && 1182 if ((cflag ^ old_termios->c_cflag) == 0 &&
1166 tty->termios->c_ospeed == old_termios->c_ospeed && 1183 tty->termios->c_ospeed == old_termios->c_ospeed &&
1167 tty->termios->c_ispeed == old_termios->c_ispeed && 1184 tty->termios->c_ispeed == old_termios->c_ispeed &&
1168 RELEVANT_IFLAG(tty->termios->c_iflag ^ old_termios->c_iflag) == 0) 1185 RELEVANT_IFLAG(tty->termios->c_iflag ^ old_termios->c_iflag) == 0) {
1169 return; 1186 return;
1187 }
1170 1188
1171 uart_change_speed(state, old_termios); 1189 uart_change_speed(state, old_termios);
1172 1190
@@ -1200,7 +1218,6 @@ static void uart_set_termios(struct tty_struct *tty,
1200 } 1218 }
1201 spin_unlock_irqrestore(&state->port->lock, flags); 1219 spin_unlock_irqrestore(&state->port->lock, flags);
1202 } 1220 }
1203
1204#if 0 1221#if 0
1205 /* 1222 /*
1206 * No need to wake up processes in open wait, since they 1223 * No need to wake up processes in open wait, since they
@@ -1316,11 +1333,11 @@ static void uart_wait_until_sent(struct tty_struct *tty, int timeout)
1316 struct uart_port *port = state->port; 1333 struct uart_port *port = state->port;
1317 unsigned long char_time, expire; 1334 unsigned long char_time, expire;
1318 1335
1319 BUG_ON(!kernel_locked());
1320
1321 if (port->type == PORT_UNKNOWN || port->fifosize == 0) 1336 if (port->type == PORT_UNKNOWN || port->fifosize == 0)
1322 return; 1337 return;
1323 1338
1339 lock_kernel();
1340
1324 /* 1341 /*
1325 * Set the check interval to be 1/5 of the estimated time to 1342 * Set the check interval to be 1/5 of the estimated time to
1326 * send a single character, and make it at least 1. The check 1343 * send a single character, and make it at least 1. The check
@@ -1366,6 +1383,7 @@ static void uart_wait_until_sent(struct tty_struct *tty, int timeout)
1366 break; 1383 break;
1367 } 1384 }
1368 set_current_state(TASK_RUNNING); /* might not be needed */ 1385 set_current_state(TASK_RUNNING); /* might not be needed */
1386 unlock_kernel();
1369} 1387}
1370 1388
1371/* 1389/*
@@ -2079,7 +2097,9 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *port)
2079 int ret; 2097 int ret;
2080 2098
2081 uart_change_pm(state, 0); 2099 uart_change_pm(state, 0);
2100 spin_lock_irq(&port->lock);
2082 ops->set_mctrl(port, 0); 2101 ops->set_mctrl(port, 0);
2102 spin_unlock_irq(&port->lock);
2083 ret = ops->startup(port); 2103 ret = ops->startup(port);
2084 if (ret == 0) { 2104 if (ret == 0) {
2085 uart_change_speed(state, NULL); 2105 uart_change_speed(state, NULL);
diff --git a/drivers/serial/sh-sci.c b/drivers/serial/sh-sci.c
index c2ea5d4df44a..969106187718 100644
--- a/drivers/serial/sh-sci.c
+++ b/drivers/serial/sh-sci.c
@@ -855,7 +855,7 @@ static int sci_notifier(struct notifier_block *self,
855 855
856 printk(KERN_INFO "%s: got a postchange notification " 856 printk(KERN_INFO "%s: got a postchange notification "
857 "for cpu %d (old %d, new %d)\n", 857 "for cpu %d (old %d, new %d)\n",
858 __FUNCTION__, freqs->cpu, freqs->old, freqs->new); 858 __func__, freqs->cpu, freqs->old, freqs->new);
859 } 859 }
860 860
861 return NOTIFY_OK; 861 return NOTIFY_OK;
diff --git a/drivers/serial/sn_console.c b/drivers/serial/sn_console.c
index 41fc61264443..019da2e05f0b 100644
--- a/drivers/serial/sn_console.c
+++ b/drivers/serial/sn_console.c
@@ -839,7 +839,7 @@ static int __init sn_sal_module_init(void)
839 839
840 if (uart_add_one_port(&sal_console_uart, &sal_console_port.sc_port) < 0) { 840 if (uart_add_one_port(&sal_console_uart, &sal_console_port.sc_port) < 0) {
841 /* error - not sure what I'd do - so I'll do nothing */ 841 /* error - not sure what I'd do - so I'll do nothing */
842 printk(KERN_ERR "%s: unable to add port\n", __FUNCTION__); 842 printk(KERN_ERR "%s: unable to add port\n", __func__);
843 } 843 }
844 844
845 /* when this driver is compiled in, the console initialization 845 /* when this driver is compiled in, the console initialization
diff --git a/drivers/serial/sunhv.c b/drivers/serial/sunhv.c
index be0fe152891b..145c0281495d 100644
--- a/drivers/serial/sunhv.c
+++ b/drivers/serial/sunhv.c
@@ -392,7 +392,7 @@ static struct uart_ops sunhv_pops = {
392 392
393static struct uart_driver sunhv_reg = { 393static struct uart_driver sunhv_reg = {
394 .owner = THIS_MODULE, 394 .owner = THIS_MODULE,
395 .driver_name = "serial", 395 .driver_name = "sunhv",
396 .dev_name = "ttyS", 396 .dev_name = "ttyS",
397 .major = TTY_MAJOR, 397 .major = TTY_MAJOR,
398}; 398};
diff --git a/drivers/serial/sunsab.c b/drivers/serial/sunsab.c
index 543f93741e6f..9ff5b38f3bee 100644
--- a/drivers/serial/sunsab.c
+++ b/drivers/serial/sunsab.c
@@ -826,7 +826,7 @@ static struct uart_ops sunsab_pops = {
826 826
827static struct uart_driver sunsab_reg = { 827static struct uart_driver sunsab_reg = {
828 .owner = THIS_MODULE, 828 .owner = THIS_MODULE,
829 .driver_name = "serial", 829 .driver_name = "sunsab",
830 .dev_name = "ttyS", 830 .dev_name = "ttyS",
831 .major = TTY_MAJOR, 831 .major = TTY_MAJOR,
832}; 832};
diff --git a/drivers/serial/sunsu.c b/drivers/serial/sunsu.c
index 4e2302d43ab1..03806a935209 100644
--- a/drivers/serial/sunsu.c
+++ b/drivers/serial/sunsu.c
@@ -1173,7 +1173,7 @@ out:
1173 1173
1174static struct uart_driver sunsu_reg = { 1174static struct uart_driver sunsu_reg = {
1175 .owner = THIS_MODULE, 1175 .owner = THIS_MODULE,
1176 .driver_name = "serial", 1176 .driver_name = "sunsu",
1177 .dev_name = "ttyS", 1177 .dev_name = "ttyS",
1178 .major = TTY_MAJOR, 1178 .major = TTY_MAJOR,
1179}; 1179};
diff --git a/drivers/serial/sunzilog.c b/drivers/serial/sunzilog.c
index 90a20a152ebf..7e9fa5ef0eb7 100644
--- a/drivers/serial/sunzilog.c
+++ b/drivers/serial/sunzilog.c
@@ -1023,7 +1023,7 @@ static struct uart_sunzilog_port *sunzilog_irq_chain;
1023 1023
1024static struct uart_driver sunzilog_reg = { 1024static struct uart_driver sunzilog_reg = {
1025 .owner = THIS_MODULE, 1025 .owner = THIS_MODULE,
1026 .driver_name = "ttyS", 1026 .driver_name = "sunzilog",
1027 .dev_name = "ttyS", 1027 .dev_name = "ttyS",
1028 .major = TTY_MAJOR, 1028 .major = TTY_MAJOR,
1029}; 1029};
diff --git a/drivers/serial/uartlite.c b/drivers/serial/uartlite.c
index b565d5a37499..b51c24245be4 100644
--- a/drivers/serial/uartlite.c
+++ b/drivers/serial/uartlite.c
@@ -584,7 +584,7 @@ ulite_of_probe(struct of_device *op, const struct of_device_id *match)
584 const unsigned int *id; 584 const unsigned int *id;
585 int irq, rc; 585 int irq, rc;
586 586
587 dev_dbg(&op->dev, "%s(%p, %p)\n", __FUNCTION__, op, match); 587 dev_dbg(&op->dev, "%s(%p, %p)\n", __func__, op, match);
588 588
589 rc = of_address_to_resource(op->node, 0, &res); 589 rc = of_address_to_resource(op->node, 0, &res);
590 if (rc) { 590 if (rc) {
diff --git a/drivers/serial/ucc_uart.c b/drivers/serial/ucc_uart.c
index 5e4310ccd591..01917c433f17 100644
--- a/drivers/serial/ucc_uart.c
+++ b/drivers/serial/ucc_uart.c
@@ -215,7 +215,7 @@ static inline dma_addr_t cpu2qe_addr(void *addr, struct uart_qe_port *qe_port)
215 return qe_port->bd_dma_addr + (addr - qe_port->bd_virt); 215 return qe_port->bd_dma_addr + (addr - qe_port->bd_virt);
216 216
217 /* something nasty happened */ 217 /* something nasty happened */
218 printk(KERN_ERR "%s: addr=%p\n", __FUNCTION__, addr); 218 printk(KERN_ERR "%s: addr=%p\n", __func__, addr);
219 BUG(); 219 BUG();
220 return 0; 220 return 0;
221} 221}
@@ -234,7 +234,7 @@ static inline void *qe2cpu_addr(dma_addr_t addr, struct uart_qe_port *qe_port)
234 return qe_port->bd_virt + (addr - qe_port->bd_dma_addr); 234 return qe_port->bd_virt + (addr - qe_port->bd_dma_addr);
235 235
236 /* something nasty happened */ 236 /* something nasty happened */
237 printk(KERN_ERR "%s: addr=%x\n", __FUNCTION__, addr); 237 printk(KERN_ERR "%s: addr=%x\n", __func__, addr);
238 BUG(); 238 BUG();
239 return NULL; 239 return NULL;
240} 240}
diff --git a/drivers/spi/atmel_spi.c b/drivers/spi/atmel_spi.c
index 02c8e305b14f..e81d59d78910 100644
--- a/drivers/spi/atmel_spi.c
+++ b/drivers/spi/atmel_spi.c
@@ -497,7 +497,7 @@ static int atmel_spi_setup(struct spi_device *spi)
497 struct atmel_spi *as; 497 struct atmel_spi *as;
498 u32 scbr, csr; 498 u32 scbr, csr;
499 unsigned int bits = spi->bits_per_word; 499 unsigned int bits = spi->bits_per_word;
500 unsigned long bus_hz, sck_hz; 500 unsigned long bus_hz;
501 unsigned int npcs_pin; 501 unsigned int npcs_pin;
502 int ret; 502 int ret;
503 503
@@ -536,14 +536,25 @@ static int atmel_spi_setup(struct spi_device *spi)
536 return -EINVAL; 536 return -EINVAL;
537 } 537 }
538 538
539 /* speed zero convention is used by some upper layers */ 539 /*
540 * Pre-new_1 chips start out at half the peripheral
541 * bus speed.
542 */
540 bus_hz = clk_get_rate(as->clk); 543 bus_hz = clk_get_rate(as->clk);
544 if (!as->new_1)
545 bus_hz /= 2;
546
541 if (spi->max_speed_hz) { 547 if (spi->max_speed_hz) {
542 /* assume div32/fdiv/mbz == 0 */ 548 /*
543 if (!as->new_1) 549 * Calculate the lowest divider that satisfies the
544 bus_hz /= 2; 550 * constraint, assuming div32/fdiv/mbz == 0.
545 scbr = ((bus_hz + spi->max_speed_hz - 1) 551 */
546 / spi->max_speed_hz); 552 scbr = DIV_ROUND_UP(bus_hz, spi->max_speed_hz);
553
554 /*
555 * If the resulting divider doesn't fit into the
556 * register bitfield, we can't satisfy the constraint.
557 */
547 if (scbr >= (1 << SPI_SCBR_SIZE)) { 558 if (scbr >= (1 << SPI_SCBR_SIZE)) {
548 dev_dbg(&spi->dev, 559 dev_dbg(&spi->dev,
549 "setup: %d Hz too slow, scbr %u; min %ld Hz\n", 560 "setup: %d Hz too slow, scbr %u; min %ld Hz\n",
@@ -551,8 +562,8 @@ static int atmel_spi_setup(struct spi_device *spi)
551 return -EINVAL; 562 return -EINVAL;
552 } 563 }
553 } else 564 } else
565 /* speed zero means "as slow as possible" */
554 scbr = 0xff; 566 scbr = 0xff;
555 sck_hz = bus_hz / scbr;
556 567
557 csr = SPI_BF(SCBR, scbr) | SPI_BF(BITS, bits - 8); 568 csr = SPI_BF(SCBR, scbr) | SPI_BF(BITS, bits - 8);
558 if (spi->mode & SPI_CPOL) 569 if (spi->mode & SPI_CPOL)
@@ -589,7 +600,7 @@ static int atmel_spi_setup(struct spi_device *spi)
589 600
590 dev_dbg(&spi->dev, 601 dev_dbg(&spi->dev,
591 "setup: %lu Hz bpw %u mode 0x%x -> csr%d %08x\n", 602 "setup: %lu Hz bpw %u mode 0x%x -> csr%d %08x\n",
592 sck_hz, bits, spi->mode, spi->chip_select, csr); 603 bus_hz / scbr, bits, spi->mode, spi->chip_select, csr);
593 604
594 spi_writel(as, CSR0 + 4 * spi->chip_select, csr); 605 spi_writel(as, CSR0 + 4 * spi->chip_select, csr);
595 606
diff --git a/drivers/spi/spi_bfin5xx.c b/drivers/spi/spi_bfin5xx.c
index a9ac1fdb3094..7fea3cf4588a 100644
--- a/drivers/spi/spi_bfin5xx.c
+++ b/drivers/spi/spi_bfin5xx.c
@@ -608,6 +608,7 @@ static void pump_transfers(unsigned long data)
608 u8 width; 608 u8 width;
609 u16 cr, dma_width, dma_config; 609 u16 cr, dma_width, dma_config;
610 u32 tranf_success = 1; 610 u32 tranf_success = 1;
611 u8 full_duplex = 0;
611 612
612 /* Get current state information */ 613 /* Get current state information */
613 message = drv_data->cur_msg; 614 message = drv_data->cur_msg;
@@ -658,6 +659,7 @@ static void pump_transfers(unsigned long data)
658 } 659 }
659 660
660 if (transfer->rx_buf != NULL) { 661 if (transfer->rx_buf != NULL) {
662 full_duplex = transfer->tx_buf != NULL;
661 drv_data->rx = transfer->rx_buf; 663 drv_data->rx = transfer->rx_buf;
662 drv_data->rx_end = drv_data->rx + transfer->len; 664 drv_data->rx_end = drv_data->rx + transfer->len;
663 dev_dbg(&drv_data->pdev->dev, "rx_buf is %p, rx_end is %p\n", 665 dev_dbg(&drv_data->pdev->dev, "rx_buf is %p, rx_end is %p\n",
@@ -740,7 +742,8 @@ static void pump_transfers(unsigned long data)
740 * successful use different way to r/w according to 742 * successful use different way to r/w according to
741 * drv_data->cur_chip->enable_dma 743 * drv_data->cur_chip->enable_dma
742 */ 744 */
743 if (drv_data->cur_chip->enable_dma && drv_data->len > 6) { 745 if (!full_duplex && drv_data->cur_chip->enable_dma
746 && drv_data->len > 6) {
744 747
745 disable_dma(drv_data->dma_channel); 748 disable_dma(drv_data->dma_channel);
746 clear_dma_irqstat(drv_data->dma_channel); 749 clear_dma_irqstat(drv_data->dma_channel);
@@ -828,7 +831,7 @@ static void pump_transfers(unsigned long data)
828 /* IO mode write then read */ 831 /* IO mode write then read */
829 dev_dbg(&drv_data->pdev->dev, "doing IO transfer\n"); 832 dev_dbg(&drv_data->pdev->dev, "doing IO transfer\n");
830 833
831 if (drv_data->tx != NULL && drv_data->rx != NULL) { 834 if (full_duplex) {
832 /* full duplex mode */ 835 /* full duplex mode */
833 BUG_ON((drv_data->tx_end - drv_data->tx) != 836 BUG_ON((drv_data->tx_end - drv_data->tx) !=
834 (drv_data->rx_end - drv_data->rx)); 837 (drv_data->rx_end - drv_data->rx));
diff --git a/drivers/spi/spi_s3c24xx.c b/drivers/spi/spi_s3c24xx.c
index 34bfb7dd7764..0885cc357a37 100644
--- a/drivers/spi/spi_s3c24xx.c
+++ b/drivers/spi/spi_s3c24xx.c
@@ -125,10 +125,10 @@ static int s3c24xx_spi_setupxfer(struct spi_device *spi,
125 /* is clk = pclk / (2 * (pre+1)), or is it 125 /* is clk = pclk / (2 * (pre+1)), or is it
126 * clk = (pclk * 2) / ( pre + 1) */ 126 * clk = (pclk * 2) / ( pre + 1) */
127 127
128 div = (div / 2) - 1; 128 div /= 2;
129 129
130 if (div < 0) 130 if (div > 0)
131 div = 1; 131 div -= 1;
132 132
133 if (div > 255) 133 if (div > 255)
134 div = 255; 134 div = 255;
diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
index 17e71d56f31e..4b628526df09 100644
--- a/drivers/thermal/Kconfig
+++ b/drivers/thermal/Kconfig
@@ -3,7 +3,7 @@
3# 3#
4 4
5menuconfig THERMAL 5menuconfig THERMAL
6 bool "Generic Thermal sysfs driver" 6 tristate "Generic Thermal sysfs driver"
7 help 7 help
8 Generic Thermal Sysfs driver offers a generic mechanism for 8 Generic Thermal Sysfs driver offers a generic mechanism for
9 thermal management. Usually it's made up of one or more thermal 9 thermal management. Usually it's made up of one or more thermal
@@ -11,4 +11,4 @@ menuconfig THERMAL
11 Each thermal zone contains its own temperature, trip points, 11 Each thermal zone contains its own temperature, trip points,
12 cooling devices. 12 cooling devices.
13 All platforms with ACPI thermal support can use this driver. 13 All platforms with ACPI thermal support can use this driver.
14 If you want this support, you should say Y here. 14 If you want this support, you should say Y or M here.
diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
index 8ef1232de376..31108a01c22e 100644
--- a/drivers/thermal/Makefile
+++ b/drivers/thermal/Makefile
@@ -2,4 +2,4 @@
2# Makefile for sensor chip drivers. 2# Makefile for sensor chip drivers.
3# 3#
4 4
5obj-$(CONFIG_THERMAL) += thermal.o 5obj-$(CONFIG_THERMAL) += thermal_sys.o
diff --git a/drivers/thermal/thermal.c b/drivers/thermal/thermal_sys.c
index 7f79bbf652d7..6098787341f3 100644
--- a/drivers/thermal/thermal.c
+++ b/drivers/thermal/thermal_sys.c
@@ -31,7 +31,7 @@
31#include <linux/thermal.h> 31#include <linux/thermal.h>
32#include <linux/spinlock.h> 32#include <linux/spinlock.h>
33 33
34MODULE_AUTHOR("Zhang Rui") 34MODULE_AUTHOR("Zhang Rui");
35MODULE_DESCRIPTION("Generic thermal management sysfs support"); 35MODULE_DESCRIPTION("Generic thermal management sysfs support");
36MODULE_LICENSE("GPL"); 36MODULE_LICENSE("GPL");
37 37
@@ -295,6 +295,164 @@ thermal_cooling_device_trip_point_show(struct device *dev,
295 295
296/* Device management */ 296/* Device management */
297 297
298#if defined(CONFIG_HWMON) || \
299 (defined(CONFIG_HWMON_MODULE) && defined(CONFIG_THERMAL_MODULE))
300/* hwmon sys I/F */
301#include <linux/hwmon.h>
302static LIST_HEAD(thermal_hwmon_list);
303
304static ssize_t
305name_show(struct device *dev, struct device_attribute *attr, char *buf)
306{
307 struct thermal_hwmon_device *hwmon = dev->driver_data;
308 return sprintf(buf, "%s\n", hwmon->type);
309}
310static DEVICE_ATTR(name, 0444, name_show, NULL);
311
312static ssize_t
313temp_input_show(struct device *dev, struct device_attribute *attr, char *buf)
314{
315 struct thermal_hwmon_attr *hwmon_attr
316 = container_of(attr, struct thermal_hwmon_attr, attr);
317 struct thermal_zone_device *tz
318 = container_of(hwmon_attr, struct thermal_zone_device,
319 temp_input);
320
321 return tz->ops->get_temp(tz, buf);
322}
323
324static ssize_t
325temp_crit_show(struct device *dev, struct device_attribute *attr,
326 char *buf)
327{
328 struct thermal_hwmon_attr *hwmon_attr
329 = container_of(attr, struct thermal_hwmon_attr, attr);
330 struct thermal_zone_device *tz
331 = container_of(hwmon_attr, struct thermal_zone_device,
332 temp_crit);
333
334 return tz->ops->get_trip_temp(tz, 0, buf);
335}
336
337
338static int
339thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
340{
341 struct thermal_hwmon_device *hwmon;
342 int new_hwmon_device = 1;
343 int result;
344
345 mutex_lock(&thermal_list_lock);
346 list_for_each_entry(hwmon, &thermal_hwmon_list, node)
347 if (!strcmp(hwmon->type, tz->type)) {
348 new_hwmon_device = 0;
349 mutex_unlock(&thermal_list_lock);
350 goto register_sys_interface;
351 }
352 mutex_unlock(&thermal_list_lock);
353
354 hwmon = kzalloc(sizeof(struct thermal_hwmon_device), GFP_KERNEL);
355 if (!hwmon)
356 return -ENOMEM;
357
358 INIT_LIST_HEAD(&hwmon->tz_list);
359 strlcpy(hwmon->type, tz->type, THERMAL_NAME_LENGTH);
360 hwmon->device = hwmon_device_register(NULL);
361 if (IS_ERR(hwmon->device)) {
362 result = PTR_ERR(hwmon->device);
363 goto free_mem;
364 }
365 hwmon->device->driver_data = hwmon;
366 result = device_create_file(hwmon->device, &dev_attr_name);
367 if (result)
368 goto unregister_hwmon_device;
369
370 register_sys_interface:
371 tz->hwmon = hwmon;
372 hwmon->count++;
373
374 snprintf(tz->temp_input.name, THERMAL_NAME_LENGTH,
375 "temp%d_input", hwmon->count);
376 tz->temp_input.attr.attr.name = tz->temp_input.name;
377 tz->temp_input.attr.attr.mode = 0444;
378 tz->temp_input.attr.show = temp_input_show;
379 result = device_create_file(hwmon->device, &tz->temp_input.attr);
380 if (result)
381 goto unregister_hwmon_device;
382
383 if (tz->ops->get_crit_temp) {
384 unsigned long temperature;
385 if (!tz->ops->get_crit_temp(tz, &temperature)) {
386 snprintf(tz->temp_crit.name, THERMAL_NAME_LENGTH,
387 "temp%d_crit", hwmon->count);
388 tz->temp_crit.attr.attr.name = tz->temp_crit.name;
389 tz->temp_crit.attr.attr.mode = 0444;
390 tz->temp_crit.attr.show = temp_crit_show;
391 result = device_create_file(hwmon->device,
392 &tz->temp_crit.attr);
393 if (result)
394 goto unregister_hwmon_device;
395 }
396 }
397
398 mutex_lock(&thermal_list_lock);
399 if (new_hwmon_device)
400 list_add_tail(&hwmon->node, &thermal_hwmon_list);
401 list_add_tail(&tz->hwmon_node, &hwmon->tz_list);
402 mutex_unlock(&thermal_list_lock);
403
404 return 0;
405
406 unregister_hwmon_device:
407 device_remove_file(hwmon->device, &tz->temp_crit.attr);
408 device_remove_file(hwmon->device, &tz->temp_input.attr);
409 if (new_hwmon_device) {
410 device_remove_file(hwmon->device, &dev_attr_name);
411 hwmon_device_unregister(hwmon->device);
412 }
413 free_mem:
414 if (new_hwmon_device)
415 kfree(hwmon);
416
417 return result;
418}
419
420static void
421thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
422{
423 struct thermal_hwmon_device *hwmon = tz->hwmon;
424
425 tz->hwmon = NULL;
426 device_remove_file(hwmon->device, &tz->temp_input.attr);
427 device_remove_file(hwmon->device, &tz->temp_crit.attr);
428
429 mutex_lock(&thermal_list_lock);
430 list_del(&tz->hwmon_node);
431 if (!list_empty(&hwmon->tz_list)) {
432 mutex_unlock(&thermal_list_lock);
433 return;
434 }
435 list_del(&hwmon->node);
436 mutex_unlock(&thermal_list_lock);
437
438 device_remove_file(hwmon->device, &dev_attr_name);
439 hwmon_device_unregister(hwmon->device);
440 kfree(hwmon);
441}
442#else
443static int
444thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
445{
446 return 0;
447}
448
449static void
450thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
451{
452}
453#endif
454
455
298/** 456/**
299 * thermal_zone_bind_cooling_device - bind a cooling device to a thermal zone 457 * thermal_zone_bind_cooling_device - bind a cooling device to a thermal zone
300 * @tz: thermal zone device 458 * @tz: thermal zone device
@@ -642,6 +800,10 @@ struct thermal_zone_device *thermal_zone_device_register(char *type,
642 goto unregister; 800 goto unregister;
643 } 801 }
644 802
803 result = thermal_add_hwmon_sysfs(tz);
804 if (result)
805 goto unregister;
806
645 mutex_lock(&thermal_list_lock); 807 mutex_lock(&thermal_list_lock);
646 list_add_tail(&tz->node, &thermal_tz_list); 808 list_add_tail(&tz->node, &thermal_tz_list);
647 if (ops->bind) 809 if (ops->bind)
@@ -700,6 +862,7 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
700 for (count = 0; count < tz->trips; count++) 862 for (count = 0; count < tz->trips; count++)
701 TRIP_POINT_ATTR_REMOVE(&tz->device, count); 863 TRIP_POINT_ATTR_REMOVE(&tz->device, count);
702 864
865 thermal_remove_hwmon_sysfs(tz);
703 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id); 866 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
704 idr_destroy(&tz->idr); 867 idr_destroy(&tz->idr);
705 mutex_destroy(&tz->lock); 868 mutex_destroy(&tz->lock);
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 516a6400db43..a419c42e880e 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -17,6 +17,8 @@ obj-$(CONFIG_USB_SL811_HCD) += host/
17obj-$(CONFIG_USB_U132_HCD) += host/ 17obj-$(CONFIG_USB_U132_HCD) += host/
18obj-$(CONFIG_USB_R8A66597_HCD) += host/ 18obj-$(CONFIG_USB_R8A66597_HCD) += host/
19 19
20obj-$(CONFIG_USB_C67X00_HCD) += c67x00/
21
20obj-$(CONFIG_USB_ACM) += class/ 22obj-$(CONFIG_USB_ACM) += class/
21obj-$(CONFIG_USB_PRINTER) += class/ 23obj-$(CONFIG_USB_PRINTER) += class/
22 24
diff --git a/drivers/usb/atm/Kconfig b/drivers/usb/atm/Kconfig
index 86e64035edb0..be0b8daac9c7 100644
--- a/drivers/usb/atm/Kconfig
+++ b/drivers/usb/atm/Kconfig
@@ -19,7 +19,6 @@ if USB_ATM
19 19
20config USB_SPEEDTOUCH 20config USB_SPEEDTOUCH
21 tristate "Speedtouch USB support" 21 tristate "Speedtouch USB support"
22 depends on USB_ATM
23 select FW_LOADER 22 select FW_LOADER
24 help 23 help
25 Say Y here if you have an SpeedTouch USB or SpeedTouch 330 24 Say Y here if you have an SpeedTouch USB or SpeedTouch 330
@@ -32,7 +31,6 @@ config USB_SPEEDTOUCH
32 31
33config USB_CXACRU 32config USB_CXACRU
34 tristate "Conexant AccessRunner USB support" 33 tristate "Conexant AccessRunner USB support"
35 depends on USB_ATM
36 select FW_LOADER 34 select FW_LOADER
37 help 35 help
38 Say Y here if you have an ADSL USB modem based on the Conexant 36 Say Y here if you have an ADSL USB modem based on the Conexant
@@ -45,7 +43,6 @@ config USB_CXACRU
45 43
46config USB_UEAGLEATM 44config USB_UEAGLEATM
47 tristate "ADI 930 and eagle USB DSL modem" 45 tristate "ADI 930 and eagle USB DSL modem"
48 depends on USB_ATM
49 select FW_LOADER 46 select FW_LOADER
50 help 47 help
51 Say Y here if you have an ADSL USB modem based on the ADI 930 48 Say Y here if you have an ADSL USB modem based on the ADI 930
@@ -58,7 +55,6 @@ config USB_UEAGLEATM
58 55
59config USB_XUSBATM 56config USB_XUSBATM
60 tristate "Other USB DSL modem support" 57 tristate "Other USB DSL modem support"
61 depends on USB_ATM
62 help 58 help
63 Say Y here if you have a DSL USB modem not explicitly supported by 59 Say Y here if you have a DSL USB modem not explicitly supported by
64 another USB DSL drivers. In order to use your modem you will need to 60 another USB DSL drivers. In order to use your modem you will need to
diff --git a/drivers/usb/c67x00/Makefile b/drivers/usb/c67x00/Makefile
new file mode 100644
index 000000000000..868bc41b5980
--- /dev/null
+++ b/drivers/usb/c67x00/Makefile
@@ -0,0 +1,9 @@
1#
2# Makefile for Cypress C67X00 USB Controller
3#
4
5ccflags-$(CONFIG_USB_DEBUG) += -DDEBUG
6
7obj-$(CONFIG_USB_C67X00_HCD) += c67x00.o
8
9c67x00-objs := c67x00-drv.o c67x00-ll-hpi.o c67x00-hcd.o c67x00-sched.o
diff --git a/drivers/usb/c67x00/c67x00-drv.c b/drivers/usb/c67x00/c67x00-drv.c
new file mode 100644
index 000000000000..5633bc5c8bf2
--- /dev/null
+++ b/drivers/usb/c67x00/c67x00-drv.c
@@ -0,0 +1,243 @@
1/*
2 * c67x00-drv.c: Cypress C67X00 USB Common infrastructure
3 *
4 * Copyright (C) 2006-2008 Barco N.V.
5 * Derived from the Cypress cy7c67200/300 ezusb linux driver and
6 * based on multiple host controller drivers inside the linux kernel.
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, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 * MA 02110-1301 USA.
22 */
23
24/*
25 * This file implements the common infrastructure for using the c67x00.
26 * It is both the link between the platform configuration and subdrivers and
27 * the link between the common hardware parts and the subdrivers (e.g.
28 * interrupt handling).
29 *
30 * The c67x00 has 2 SIE's (serial interface engine) wich can be configured
31 * to be host, device or OTG (with some limitations, E.G. only SIE1 can be OTG).
32 *
33 * Depending on the platform configuration, the SIE's are created and
34 * the corresponding subdriver is initialized (c67x00_probe_sie).
35 */
36
37#include <linux/device.h>
38#include <linux/io.h>
39#include <linux/list.h>
40#include <linux/usb.h>
41#include <linux/usb/c67x00.h>
42
43#include "c67x00.h"
44#include "c67x00-hcd.h"
45
46static void c67x00_probe_sie(struct c67x00_sie *sie,
47 struct c67x00_device *dev, int sie_num)
48{
49 spin_lock_init(&sie->lock);
50 sie->dev = dev;
51 sie->sie_num = sie_num;
52 sie->mode = c67x00_sie_config(dev->pdata->sie_config, sie_num);
53
54 switch (sie->mode) {
55 case C67X00_SIE_HOST:
56 c67x00_hcd_probe(sie);
57 break;
58
59 case C67X00_SIE_UNUSED:
60 dev_info(sie_dev(sie),
61 "Not using SIE %d as requested\n", sie->sie_num);
62 break;
63
64 default:
65 dev_err(sie_dev(sie),
66 "Unsupported configuration: 0x%x for SIE %d\n",
67 sie->mode, sie->sie_num);
68 break;
69 }
70}
71
72static void c67x00_remove_sie(struct c67x00_sie *sie)
73{
74 switch (sie->mode) {
75 case C67X00_SIE_HOST:
76 c67x00_hcd_remove(sie);
77 break;
78
79 default:
80 break;
81 }
82}
83
84static irqreturn_t c67x00_irq(int irq, void *__dev)
85{
86 struct c67x00_device *c67x00 = __dev;
87 struct c67x00_sie *sie;
88 u16 msg, int_status;
89 int i, count = 8;
90
91 int_status = c67x00_ll_hpi_status(c67x00);
92 if (!int_status)
93 return IRQ_NONE;
94
95 while (int_status != 0 && (count-- >= 0)) {
96 c67x00_ll_irq(c67x00, int_status);
97 for (i = 0; i < C67X00_SIES; i++) {
98 sie = &c67x00->sie[i];
99 msg = 0;
100 if (int_status & SIEMSG_FLG(i))
101 msg = c67x00_ll_fetch_siemsg(c67x00, i);
102 if (sie->irq)
103 sie->irq(sie, int_status, msg);
104 }
105 int_status = c67x00_ll_hpi_status(c67x00);
106 }
107
108 if (int_status)
109 dev_warn(&c67x00->pdev->dev, "Not all interrupts handled! "
110 "status = 0x%04x\n", int_status);
111
112 return IRQ_HANDLED;
113}
114
115/* ------------------------------------------------------------------------- */
116
117static int __devinit c67x00_drv_probe(struct platform_device *pdev)
118{
119 struct c67x00_device *c67x00;
120 struct c67x00_platform_data *pdata;
121 struct resource *res, *res2;
122 int ret, i;
123
124 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
125 if (!res)
126 return -ENODEV;
127
128 res2 = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
129 if (!res2)
130 return -ENODEV;
131
132 pdata = pdev->dev.platform_data;
133 if (!pdata)
134 return -ENODEV;
135
136 c67x00 = kzalloc(sizeof(*c67x00), GFP_KERNEL);
137 if (!c67x00)
138 return -ENOMEM;
139
140 if (!request_mem_region(res->start, res->end - res->start + 1,
141 pdev->name)) {
142 dev_err(&pdev->dev, "Memory region busy\n");
143 ret = -EBUSY;
144 goto request_mem_failed;
145 }
146 c67x00->hpi.base = ioremap(res->start, res->end - res->start + 1);
147 if (!c67x00->hpi.base) {
148 dev_err(&pdev->dev, "Unable to map HPI registers\n");
149 ret = -EIO;
150 goto map_failed;
151 }
152
153 spin_lock_init(&c67x00->hpi.lock);
154 c67x00->hpi.regstep = pdata->hpi_regstep;
155 c67x00->pdata = pdev->dev.platform_data;
156 c67x00->pdev = pdev;
157
158 c67x00_ll_init(c67x00);
159 c67x00_ll_hpi_reg_init(c67x00);
160
161 ret = request_irq(res2->start, c67x00_irq, 0, pdev->name, c67x00);
162 if (ret) {
163 dev_err(&pdev->dev, "Cannot claim IRQ\n");
164 goto request_irq_failed;
165 }
166
167 ret = c67x00_ll_reset(c67x00);
168 if (ret) {
169 dev_err(&pdev->dev, "Device reset failed\n");
170 goto reset_failed;
171 }
172
173 for (i = 0; i < C67X00_SIES; i++)
174 c67x00_probe_sie(&c67x00->sie[i], c67x00, i);
175
176 platform_set_drvdata(pdev, c67x00);
177
178 return 0;
179
180 reset_failed:
181 free_irq(res2->start, c67x00);
182 request_irq_failed:
183 iounmap(c67x00->hpi.base);
184 map_failed:
185 release_mem_region(res->start, res->end - res->start + 1);
186 request_mem_failed:
187 kfree(c67x00);
188
189 return ret;
190}
191
192static int __devexit c67x00_drv_remove(struct platform_device *pdev)
193{
194 struct c67x00_device *c67x00 = platform_get_drvdata(pdev);
195 struct resource *res;
196 int i;
197
198 for (i = 0; i < C67X00_SIES; i++)
199 c67x00_remove_sie(&c67x00->sie[i]);
200
201 c67x00_ll_release(c67x00);
202
203 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
204 if (res)
205 free_irq(res->start, c67x00);
206
207 iounmap(c67x00->hpi.base);
208
209 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
210 if (res)
211 release_mem_region(res->start, res->end - res->start + 1);
212
213 kfree(c67x00);
214
215 return 0;
216}
217
218static struct platform_driver c67x00_driver = {
219 .probe = c67x00_drv_probe,
220 .remove = __devexit_p(c67x00_drv_remove),
221 .driver = {
222 .owner = THIS_MODULE,
223 .name = "c67x00",
224 },
225};
226MODULE_ALIAS("platform:c67x00");
227
228static int __init c67x00_init(void)
229{
230 return platform_driver_register(&c67x00_driver);
231}
232
233static void __exit c67x00_exit(void)
234{
235 platform_driver_unregister(&c67x00_driver);
236}
237
238module_init(c67x00_init);
239module_exit(c67x00_exit);
240
241MODULE_AUTHOR("Peter Korsgaard, Jan Veldeman, Grant Likely");
242MODULE_DESCRIPTION("Cypress C67X00 USB Controller Driver");
243MODULE_LICENSE("GPL");
diff --git a/drivers/usb/c67x00/c67x00-hcd.c b/drivers/usb/c67x00/c67x00-hcd.c
new file mode 100644
index 000000000000..a22b887f4e9e
--- /dev/null
+++ b/drivers/usb/c67x00/c67x00-hcd.c
@@ -0,0 +1,412 @@
1/*
2 * c67x00-hcd.c: Cypress C67X00 USB Host Controller Driver
3 *
4 * Copyright (C) 2006-2008 Barco N.V.
5 * Derived from the Cypress cy7c67200/300 ezusb linux driver and
6 * based on multiple host controller drivers inside the linux kernel.
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, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 * MA 02110-1301 USA.
22 */
23
24#include <linux/device.h>
25#include <linux/platform_device.h>
26#include <linux/usb.h>
27
28#include "c67x00.h"
29#include "c67x00-hcd.h"
30
31/* --------------------------------------------------------------------------
32 * Root Hub Support
33 */
34
35static __u8 c67x00_hub_des[] = {
36 0x09, /* __u8 bLength; */
37 0x29, /* __u8 bDescriptorType; Hub-descriptor */
38 0x02, /* __u8 bNbrPorts; */
39 0x00, /* __u16 wHubCharacteristics; */
40 0x00, /* (per-port OC, no power switching) */
41 0x32, /* __u8 bPwrOn2pwrGood; 2ms */
42 0x00, /* __u8 bHubContrCurrent; 0 mA */
43 0x00, /* __u8 DeviceRemovable; ** 7 Ports max ** */
44 0xff, /* __u8 PortPwrCtrlMask; ** 7 ports max ** */
45};
46
47static void c67x00_hub_reset_host_port(struct c67x00_sie *sie, int port)
48{
49 struct c67x00_hcd *c67x00 = sie->private_data;
50 unsigned long flags;
51
52 c67x00_ll_husb_reset(sie, port);
53
54 spin_lock_irqsave(&c67x00->lock, flags);
55 c67x00_ll_husb_reset_port(sie, port);
56 spin_unlock_irqrestore(&c67x00->lock, flags);
57
58 c67x00_ll_set_husb_eot(sie->dev, DEFAULT_EOT);
59}
60
61static int c67x00_hub_status_data(struct usb_hcd *hcd, char *buf)
62{
63 struct c67x00_hcd *c67x00 = hcd_to_c67x00_hcd(hcd);
64 struct c67x00_sie *sie = c67x00->sie;
65 u16 status;
66 int i;
67
68 *buf = 0;
69 status = c67x00_ll_usb_get_status(sie);
70 for (i = 0; i < C67X00_PORTS; i++)
71 if (status & PORT_CONNECT_CHANGE(i))
72 *buf |= (1 << i);
73
74 /* bit 0 denotes hub change, b1..n port change */
75 *buf <<= 1;
76
77 return !!*buf;
78}
79
80static int c67x00_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
81 u16 wIndex, char *buf, u16 wLength)
82{
83 struct c67x00_hcd *c67x00 = hcd_to_c67x00_hcd(hcd);
84 struct c67x00_sie *sie = c67x00->sie;
85 u16 status, usb_status;
86 int len = 0;
87 unsigned int port = wIndex-1;
88 u16 wPortChange, wPortStatus;
89
90 switch (typeReq) {
91
92 case GetHubStatus:
93 *(__le32 *) buf = cpu_to_le32(0);
94 len = 4; /* hub power */
95 break;
96
97 case GetPortStatus:
98 if (wIndex > C67X00_PORTS)
99 return -EPIPE;
100
101 status = c67x00_ll_usb_get_status(sie);
102 usb_status = c67x00_ll_get_usb_ctl(sie);
103
104 wPortChange = 0;
105 if (status & PORT_CONNECT_CHANGE(port))
106 wPortChange |= USB_PORT_STAT_C_CONNECTION;
107
108 wPortStatus = USB_PORT_STAT_POWER;
109 if (!(status & PORT_SE0_STATUS(port)))
110 wPortStatus |= USB_PORT_STAT_CONNECTION;
111 if (usb_status & LOW_SPEED_PORT(port)) {
112 wPortStatus |= USB_PORT_STAT_LOW_SPEED;
113 c67x00->low_speed_ports |= (1 << port);
114 } else
115 c67x00->low_speed_ports &= ~(1 << port);
116
117 if (usb_status & SOF_EOP_EN(port))
118 wPortStatus |= USB_PORT_STAT_ENABLE;
119
120 *(__le16 *) buf = cpu_to_le16(wPortStatus);
121 *(__le16 *) (buf + 2) = cpu_to_le16(wPortChange);
122 len = 4;
123 break;
124
125 case SetHubFeature: /* We don't implement these */
126 case ClearHubFeature:
127 switch (wValue) {
128 case C_HUB_OVER_CURRENT:
129 case C_HUB_LOCAL_POWER:
130 len = 0;
131 break;
132
133 default:
134 return -EPIPE;
135 }
136 break;
137
138 case SetPortFeature:
139 if (wIndex > C67X00_PORTS)
140 return -EPIPE;
141
142 switch (wValue) {
143 case USB_PORT_FEAT_SUSPEND:
144 dev_dbg(c67x00_hcd_dev(c67x00),
145 "SetPortFeature %d (SUSPEND)\n", port);
146 len = 0;
147 break;
148
149 case USB_PORT_FEAT_RESET:
150 c67x00_hub_reset_host_port(sie, port);
151 len = 0;
152 break;
153
154 case USB_PORT_FEAT_POWER:
155 /* Power always enabled */
156 len = 0;
157 break;
158
159 default:
160 dev_dbg(c67x00_hcd_dev(c67x00),
161 "%s: SetPortFeature %d (0x%04x) Error!\n",
162 __func__, port, wValue);
163 return -EPIPE;
164 }
165 break;
166
167 case ClearPortFeature:
168 if (wIndex > C67X00_PORTS)
169 return -EPIPE;
170
171 switch (wValue) {
172 case USB_PORT_FEAT_ENABLE:
173 /* Reset the port so that the c67x00 also notices the
174 * disconnect */
175 c67x00_hub_reset_host_port(sie, port);
176 len = 0;
177 break;
178
179 case USB_PORT_FEAT_C_ENABLE:
180 dev_dbg(c67x00_hcd_dev(c67x00),
181 "ClearPortFeature (%d): C_ENABLE\n", port);
182 len = 0;
183 break;
184
185 case USB_PORT_FEAT_SUSPEND:
186 dev_dbg(c67x00_hcd_dev(c67x00),
187 "ClearPortFeature (%d): SUSPEND\n", port);
188 len = 0;
189 break;
190
191 case USB_PORT_FEAT_C_SUSPEND:
192 dev_dbg(c67x00_hcd_dev(c67x00),
193 "ClearPortFeature (%d): C_SUSPEND\n", port);
194 len = 0;
195 break;
196
197 case USB_PORT_FEAT_POWER:
198 dev_dbg(c67x00_hcd_dev(c67x00),
199 "ClearPortFeature (%d): POWER\n", port);
200 return -EPIPE;
201
202 case USB_PORT_FEAT_C_CONNECTION:
203 c67x00_ll_usb_clear_status(sie,
204 PORT_CONNECT_CHANGE(port));
205 len = 0;
206 break;
207
208 case USB_PORT_FEAT_C_OVER_CURRENT:
209 dev_dbg(c67x00_hcd_dev(c67x00),
210 "ClearPortFeature (%d): OVER_CURRENT\n", port);
211 len = 0;
212 break;
213
214 case USB_PORT_FEAT_C_RESET:
215 dev_dbg(c67x00_hcd_dev(c67x00),
216 "ClearPortFeature (%d): C_RESET\n", port);
217 len = 0;
218 break;
219
220 default:
221 dev_dbg(c67x00_hcd_dev(c67x00),
222 "%s: ClearPortFeature %d (0x%04x) Error!\n",
223 __func__, port, wValue);
224 return -EPIPE;
225 }
226 break;
227
228 case GetHubDescriptor:
229 len = min_t(unsigned int, sizeof(c67x00_hub_des), wLength);
230 memcpy(buf, c67x00_hub_des, len);
231 break;
232
233 default:
234 dev_dbg(c67x00_hcd_dev(c67x00), "%s: unknown\n", __func__);
235 return -EPIPE;
236 }
237
238 return 0;
239}
240
241/* ---------------------------------------------------------------------
242 * Main part of host controller driver
243 */
244
245/**
246 * c67x00_hcd_irq
247 *
248 * This function is called from the interrupt handler in c67x00-drv.c
249 */
250static void c67x00_hcd_irq(struct c67x00_sie *sie, u16 int_status, u16 msg)
251{
252 struct c67x00_hcd *c67x00 = sie->private_data;
253 struct usb_hcd *hcd = c67x00_hcd_to_hcd(c67x00);
254
255 /* Handle sie message flags */
256 if (msg) {
257 if (msg & HUSB_TDListDone)
258 c67x00_sched_kick(c67x00);
259 else
260 dev_warn(c67x00_hcd_dev(c67x00),
261 "Unknown SIE msg flag(s): 0x%04x\n", msg);
262 }
263
264 if (unlikely(hcd->state == HC_STATE_HALT))
265 return;
266
267 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))
268 return;
269
270 /* Handle Start of frame events */
271 if (int_status & SOFEOP_FLG(sie->sie_num)) {
272 c67x00_ll_usb_clear_status(sie, SOF_EOP_IRQ_FLG);
273 c67x00_sched_kick(c67x00);
274 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
275 }
276}
277
278/**
279 * c67x00_hcd_start: Host controller start hook
280 */
281static int c67x00_hcd_start(struct usb_hcd *hcd)
282{
283 hcd->uses_new_polling = 1;
284 hcd->state = HC_STATE_RUNNING;
285 hcd->poll_rh = 1;
286
287 return 0;
288}
289
290/**
291 * c67x00_hcd_stop: Host controller stop hook
292 */
293static void c67x00_hcd_stop(struct usb_hcd *hcd)
294{
295 /* Nothing to do */
296}
297
298static int c67x00_hcd_get_frame(struct usb_hcd *hcd)
299{
300 struct c67x00_hcd *c67x00 = hcd_to_c67x00_hcd(hcd);
301 u16 temp_val;
302
303 dev_dbg(c67x00_hcd_dev(c67x00), "%s\n", __func__);
304 temp_val = c67x00_ll_husb_get_frame(c67x00->sie);
305 temp_val &= HOST_FRAME_MASK;
306 return temp_val ? (temp_val - 1) : HOST_FRAME_MASK;
307}
308
309static struct hc_driver c67x00_hc_driver = {
310 .description = "c67x00-hcd",
311 .product_desc = "Cypress C67X00 Host Controller",
312 .hcd_priv_size = sizeof(struct c67x00_hcd),
313 .flags = HCD_USB11 | HCD_MEMORY,
314
315 /*
316 * basic lifecycle operations
317 */
318 .start = c67x00_hcd_start,
319 .stop = c67x00_hcd_stop,
320
321 /*
322 * managing i/o requests and associated device resources
323 */
324 .urb_enqueue = c67x00_urb_enqueue,
325 .urb_dequeue = c67x00_urb_dequeue,
326 .endpoint_disable = c67x00_endpoint_disable,
327
328 /*
329 * scheduling support
330 */
331 .get_frame_number = c67x00_hcd_get_frame,
332
333 /*
334 * root hub support
335 */
336 .hub_status_data = c67x00_hub_status_data,
337 .hub_control = c67x00_hub_control,
338};
339
340/* ---------------------------------------------------------------------
341 * Setup/Teardown routines
342 */
343
344int c67x00_hcd_probe(struct c67x00_sie *sie)
345{
346 struct c67x00_hcd *c67x00;
347 struct usb_hcd *hcd;
348 unsigned long flags;
349 int retval;
350
351 if (usb_disabled())
352 return -ENODEV;
353
354 hcd = usb_create_hcd(&c67x00_hc_driver, sie_dev(sie), "c67x00_sie");
355 if (!hcd) {
356 retval = -ENOMEM;
357 goto err0;
358 }
359 c67x00 = hcd_to_c67x00_hcd(hcd);
360
361 spin_lock_init(&c67x00->lock);
362 c67x00->sie = sie;
363
364 INIT_LIST_HEAD(&c67x00->list[PIPE_ISOCHRONOUS]);
365 INIT_LIST_HEAD(&c67x00->list[PIPE_INTERRUPT]);
366 INIT_LIST_HEAD(&c67x00->list[PIPE_CONTROL]);
367 INIT_LIST_HEAD(&c67x00->list[PIPE_BULK]);
368 c67x00->urb_count = 0;
369 INIT_LIST_HEAD(&c67x00->td_list);
370 c67x00->td_base_addr = CY_HCD_BUF_ADDR + SIE_TD_OFFSET(sie->sie_num);
371 c67x00->buf_base_addr = CY_HCD_BUF_ADDR + SIE_BUF_OFFSET(sie->sie_num);
372 c67x00->max_frame_bw = MAX_FRAME_BW_STD;
373
374 c67x00_ll_husb_init_host_port(sie);
375
376 init_completion(&c67x00->endpoint_disable);
377 retval = c67x00_sched_start_scheduler(c67x00);
378 if (retval)
379 goto err1;
380
381 retval = usb_add_hcd(hcd, 0, 0);
382 if (retval) {
383 dev_dbg(sie_dev(sie), "%s: usb_add_hcd returned %d\n",
384 __func__, retval);
385 goto err2;
386 }
387
388 spin_lock_irqsave(&sie->lock, flags);
389 sie->private_data = c67x00;
390 sie->irq = c67x00_hcd_irq;
391 spin_unlock_irqrestore(&sie->lock, flags);
392
393 return retval;
394
395 err2:
396 c67x00_sched_stop_scheduler(c67x00);
397 err1:
398 usb_put_hcd(hcd);
399 err0:
400 return retval;
401}
402
403/* may be called with controller, bus, and devices active */
404void c67x00_hcd_remove(struct c67x00_sie *sie)
405{
406 struct c67x00_hcd *c67x00 = sie->private_data;
407 struct usb_hcd *hcd = c67x00_hcd_to_hcd(c67x00);
408
409 c67x00_sched_stop_scheduler(c67x00);
410 usb_remove_hcd(hcd);
411 usb_put_hcd(hcd);
412}
diff --git a/drivers/usb/c67x00/c67x00-hcd.h b/drivers/usb/c67x00/c67x00-hcd.h
new file mode 100644
index 000000000000..e8c6d94b2514
--- /dev/null
+++ b/drivers/usb/c67x00/c67x00-hcd.h
@@ -0,0 +1,133 @@
1/*
2 * c67x00-hcd.h: Cypress C67X00 USB HCD
3 *
4 * Copyright (C) 2006-2008 Barco N.V.
5 * Derived from the Cypress cy7c67200/300 ezusb linux driver and
6 * based on multiple host controller drivers inside the linux kernel.
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, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 * MA 02110-1301 USA.
22 */
23
24#ifndef _USB_C67X00_HCD_H
25#define _USB_C67X00_HCD_H
26
27#include <linux/kernel.h>
28#include <linux/spinlock.h>
29#include <linux/list.h>
30#include <linux/usb.h>
31#include "../core/hcd.h"
32#include "c67x00.h"
33
34/*
35 * The following parameters depend on the CPU speed, bus speed, ...
36 * These can be tuned for specific use cases, e.g. if isochronous transfers
37 * are very important, bandwith can be sacrificed to guarantee that the
38 * 1ms deadline will be met.
39 * If bulk transfers are important, the MAX_FRAME_BW can be increased,
40 * but some (or many) isochronous deadlines might not be met.
41 *
42 * The values are specified in bittime.
43 */
44
45/*
46 * The current implementation switches between _STD (default) and _ISO (when
47 * isochronous transfers are scheduled), in order to optimize the throughput
48 * in normal cicrumstances, but also provide good isochronous behaviour.
49 *
50 * Bandwidth is described in bit time so with a 12MHz USB clock and 1ms
51 * frames; there are 12000 bit times per frame.
52 */
53
54#define TOTAL_FRAME_BW 12000
55#define DEFAULT_EOT 2250
56
57#define MAX_FRAME_BW_STD (TOTAL_FRAME_BW - DEFAULT_EOT)
58#define MAX_FRAME_BW_ISO 2400
59
60/*
61 * Periodic transfers may only use 90% of the full frame, but as
62 * we currently don't even use 90% of the full frame, we may
63 * use the full usable time for periodic transfers.
64 */
65#define MAX_PERIODIC_BW(full_bw) full_bw
66
67/* -------------------------------------------------------------------------- */
68
69struct c67x00_hcd {
70 spinlock_t lock;
71 struct c67x00_sie *sie;
72 unsigned int low_speed_ports; /* bitmask of low speed ports */
73 unsigned int urb_count;
74 unsigned int urb_iso_count;
75
76 struct list_head list[4]; /* iso, int, ctrl, bulk */
77#if PIPE_BULK != 3
78#error "Sanity check failed, this code presumes PIPE_... to range from 0 to 3"
79#endif
80
81 /* USB bandwidth allocated to td_list */
82 int bandwidth_allocated;
83 /* USB bandwidth allocated for isoc/int transfer */
84 int periodic_bw_allocated;
85 struct list_head td_list;
86 int max_frame_bw;
87
88 u16 td_base_addr;
89 u16 buf_base_addr;
90 u16 next_td_addr;
91 u16 next_buf_addr;
92
93 struct tasklet_struct tasklet;
94
95 struct completion endpoint_disable;
96
97 u16 current_frame;
98 u16 last_frame;
99};
100
101static inline struct c67x00_hcd *hcd_to_c67x00_hcd(struct usb_hcd *hcd)
102{
103 return (struct c67x00_hcd *)(hcd->hcd_priv);
104}
105
106static inline struct usb_hcd *c67x00_hcd_to_hcd(struct c67x00_hcd *c67x00)
107{
108 return container_of((void *)c67x00, struct usb_hcd, hcd_priv);
109}
110
111/* ---------------------------------------------------------------------
112 * Functions used by c67x00-drv
113 */
114
115int c67x00_hcd_probe(struct c67x00_sie *sie);
116void c67x00_hcd_remove(struct c67x00_sie *sie);
117
118/* ---------------------------------------------------------------------
119 * Transfer Descriptor scheduling functions
120 */
121int c67x00_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags);
122int c67x00_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status);
123void c67x00_endpoint_disable(struct usb_hcd *hcd,
124 struct usb_host_endpoint *ep);
125
126void c67x00_hcd_msg_received(struct c67x00_sie *sie, u16 msg);
127void c67x00_sched_kick(struct c67x00_hcd *c67x00);
128int c67x00_sched_start_scheduler(struct c67x00_hcd *c67x00);
129void c67x00_sched_stop_scheduler(struct c67x00_hcd *c67x00);
130
131#define c67x00_hcd_dev(x) (c67x00_hcd_to_hcd(x)->self.controller)
132
133#endif /* _USB_C67X00_HCD_H */
diff --git a/drivers/usb/c67x00/c67x00-ll-hpi.c b/drivers/usb/c67x00/c67x00-ll-hpi.c
new file mode 100644
index 000000000000..f3430b372f09
--- /dev/null
+++ b/drivers/usb/c67x00/c67x00-ll-hpi.c
@@ -0,0 +1,480 @@
1/*
2 * c67x00-ll-hpi.c: Cypress C67X00 USB Low level interface using HPI
3 *
4 * Copyright (C) 2006-2008 Barco N.V.
5 * Derived from the Cypress cy7c67200/300 ezusb linux driver and
6 * based on multiple host controller drivers inside the linux kernel.
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, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 * MA 02110-1301 USA.
22 */
23
24#include <asm/byteorder.h>
25#include <linux/io.h>
26#include <linux/usb/c67x00.h>
27#include "c67x00.h"
28
29#define COMM_REGS 14
30
31struct c67x00_lcp_int_data {
32 u16 regs[COMM_REGS];
33};
34
35/* -------------------------------------------------------------------------- */
36/* Interface definitions */
37
38#define COMM_ACK 0x0FED
39#define COMM_NAK 0xDEAD
40
41#define COMM_RESET 0xFA50
42#define COMM_EXEC_INT 0xCE01
43#define COMM_INT_NUM 0x01C2
44
45/* Registers 0 to COMM_REGS-1 */
46#define COMM_R(x) (0x01C4 + 2 * (x))
47
48#define HUSB_SIE_pCurrentTDPtr(x) ((x) ? 0x01B2 : 0x01B0)
49#define HUSB_SIE_pTDListDone_Sem(x) ((x) ? 0x01B8 : 0x01B6)
50#define HUSB_pEOT 0x01B4
51
52/* Software interrupts */
53/* 114, 115: */
54#define HUSB_SIE_INIT_INT(x) ((x) ? 0x0073 : 0x0072)
55#define HUSB_RESET_INT 0x0074
56
57#define SUSB_INIT_INT 0x0071
58#define SUSB_INIT_INT_LOC (SUSB_INIT_INT * 2)
59
60/* -----------------------------------------------------------------------
61 * HPI implementation
62 *
63 * The c67x00 chip also support control via SPI or HSS serial
64 * interfaces. However, this driver assumes that register access can
65 * be performed from IRQ context. While this is a safe assuption with
66 * the HPI interface, it is not true for the serial interfaces.
67 */
68
69/* HPI registers */
70#define HPI_DATA 0
71#define HPI_MAILBOX 1
72#define HPI_ADDR 2
73#define HPI_STATUS 3
74
75static inline u16 hpi_read_reg(struct c67x00_device *dev, int reg)
76{
77 return __raw_readw(dev->hpi.base + reg * dev->hpi.regstep);
78}
79
80static inline void hpi_write_reg(struct c67x00_device *dev, int reg, u16 value)
81{
82 __raw_writew(value, dev->hpi.base + reg * dev->hpi.regstep);
83}
84
85static inline u16 hpi_read_word_nolock(struct c67x00_device *dev, u16 reg)
86{
87 hpi_write_reg(dev, HPI_ADDR, reg);
88 return hpi_read_reg(dev, HPI_DATA);
89}
90
91static u16 hpi_read_word(struct c67x00_device *dev, u16 reg)
92{
93 u16 value;
94 unsigned long flags;
95
96 spin_lock_irqsave(&dev->hpi.lock, flags);
97 value = hpi_read_word_nolock(dev, reg);
98 spin_unlock_irqrestore(&dev->hpi.lock, flags);
99
100 return value;
101}
102
103static void hpi_write_word_nolock(struct c67x00_device *dev, u16 reg, u16 value)
104{
105 hpi_write_reg(dev, HPI_ADDR, reg);
106 hpi_write_reg(dev, HPI_DATA, value);
107}
108
109static void hpi_write_word(struct c67x00_device *dev, u16 reg, u16 value)
110{
111 unsigned long flags;
112
113 spin_lock_irqsave(&dev->hpi.lock, flags);
114 hpi_write_word_nolock(dev, reg, value);
115 spin_unlock_irqrestore(&dev->hpi.lock, flags);
116}
117
118/*
119 * Only data is little endian, addr has cpu endianess
120 */
121static void hpi_write_words_le16(struct c67x00_device *dev, u16 addr,
122 u16 *data, u16 count)
123{
124 unsigned long flags;
125 int i;
126
127 spin_lock_irqsave(&dev->hpi.lock, flags);
128
129 hpi_write_reg(dev, HPI_ADDR, addr);
130 for (i = 0; i < count; i++)
131 hpi_write_reg(dev, HPI_DATA, cpu_to_le16(*data++));
132
133 spin_unlock_irqrestore(&dev->hpi.lock, flags);
134}
135
136/*
137 * Only data is little endian, addr has cpu endianess
138 */
139static void hpi_read_words_le16(struct c67x00_device *dev, u16 addr,
140 u16 *data, u16 count)
141{
142 unsigned long flags;
143 int i;
144
145 spin_lock_irqsave(&dev->hpi.lock, flags);
146 hpi_write_reg(dev, HPI_ADDR, addr);
147 for (i = 0; i < count; i++)
148 *data++ = le16_to_cpu(hpi_read_reg(dev, HPI_DATA));
149
150 spin_unlock_irqrestore(&dev->hpi.lock, flags);
151}
152
153static void hpi_set_bits(struct c67x00_device *dev, u16 reg, u16 mask)
154{
155 u16 value;
156 unsigned long flags;
157
158 spin_lock_irqsave(&dev->hpi.lock, flags);
159 value = hpi_read_word_nolock(dev, reg);
160 hpi_write_word_nolock(dev, reg, value | mask);
161 spin_unlock_irqrestore(&dev->hpi.lock, flags);
162}
163
164static void hpi_clear_bits(struct c67x00_device *dev, u16 reg, u16 mask)
165{
166 u16 value;
167 unsigned long flags;
168
169 spin_lock_irqsave(&dev->hpi.lock, flags);
170 value = hpi_read_word_nolock(dev, reg);
171 hpi_write_word_nolock(dev, reg, value & ~mask);
172 spin_unlock_irqrestore(&dev->hpi.lock, flags);
173}
174
175static u16 hpi_recv_mbox(struct c67x00_device *dev)
176{
177 u16 value;
178 unsigned long flags;
179
180 spin_lock_irqsave(&dev->hpi.lock, flags);
181 value = hpi_read_reg(dev, HPI_MAILBOX);
182 spin_unlock_irqrestore(&dev->hpi.lock, flags);
183
184 return value;
185}
186
187static u16 hpi_send_mbox(struct c67x00_device *dev, u16 value)
188{
189 unsigned long flags;
190
191 spin_lock_irqsave(&dev->hpi.lock, flags);
192 hpi_write_reg(dev, HPI_MAILBOX, value);
193 spin_unlock_irqrestore(&dev->hpi.lock, flags);
194
195 return value;
196}
197
198u16 c67x00_ll_hpi_status(struct c67x00_device *dev)
199{
200 u16 value;
201 unsigned long flags;
202
203 spin_lock_irqsave(&dev->hpi.lock, flags);
204 value = hpi_read_reg(dev, HPI_STATUS);
205 spin_unlock_irqrestore(&dev->hpi.lock, flags);
206
207 return value;
208}
209
210void c67x00_ll_hpi_reg_init(struct c67x00_device *dev)
211{
212 int i;
213
214 hpi_recv_mbox(dev);
215 c67x00_ll_hpi_status(dev);
216 hpi_write_word(dev, HPI_IRQ_ROUTING_REG, 0);
217
218 for (i = 0; i < C67X00_SIES; i++) {
219 hpi_write_word(dev, SIEMSG_REG(i), 0);
220 hpi_read_word(dev, SIEMSG_REG(i));
221 }
222}
223
224void c67x00_ll_hpi_enable_sofeop(struct c67x00_sie *sie)
225{
226 hpi_set_bits(sie->dev, HPI_IRQ_ROUTING_REG,
227 SOFEOP_TO_HPI_EN(sie->sie_num));
228}
229
230void c67x00_ll_hpi_disable_sofeop(struct c67x00_sie *sie)
231{
232 hpi_clear_bits(sie->dev, HPI_IRQ_ROUTING_REG,
233 SOFEOP_TO_HPI_EN(sie->sie_num));
234}
235
236/* -------------------------------------------------------------------------- */
237/* Transactions */
238
239static inline u16 ll_recv_msg(struct c67x00_device *dev)
240{
241 u16 res;
242
243 res = wait_for_completion_timeout(&dev->hpi.lcp.msg_received, 5 * HZ);
244 WARN_ON(!res);
245
246 return (res == 0) ? -EIO : 0;
247}
248
249/* -------------------------------------------------------------------------- */
250/* General functions */
251
252u16 c67x00_ll_fetch_siemsg(struct c67x00_device *dev, int sie_num)
253{
254 u16 val;
255
256 val = hpi_read_word(dev, SIEMSG_REG(sie_num));
257 /* clear register to allow next message */
258 hpi_write_word(dev, SIEMSG_REG(sie_num), 0);
259
260 return val;
261}
262
263u16 c67x00_ll_get_usb_ctl(struct c67x00_sie *sie)
264{
265 return hpi_read_word(sie->dev, USB_CTL_REG(sie->sie_num));
266}
267
268/**
269 * c67x00_ll_usb_clear_status - clear the USB status bits
270 */
271void c67x00_ll_usb_clear_status(struct c67x00_sie *sie, u16 bits)
272{
273 hpi_write_word(sie->dev, USB_STAT_REG(sie->sie_num), bits);
274}
275
276u16 c67x00_ll_usb_get_status(struct c67x00_sie *sie)
277{
278 return hpi_read_word(sie->dev, USB_STAT_REG(sie->sie_num));
279}
280
281/* -------------------------------------------------------------------------- */
282
283static int c67x00_comm_exec_int(struct c67x00_device *dev, u16 nr,
284 struct c67x00_lcp_int_data *data)
285{
286 int i, rc;
287
288 mutex_lock(&dev->hpi.lcp.mutex);
289 hpi_write_word(dev, COMM_INT_NUM, nr);
290 for (i = 0; i < COMM_REGS; i++)
291 hpi_write_word(dev, COMM_R(i), data->regs[i]);
292 hpi_send_mbox(dev, COMM_EXEC_INT);
293 rc = ll_recv_msg(dev);
294 mutex_unlock(&dev->hpi.lcp.mutex);
295
296 return rc;
297}
298
299/* -------------------------------------------------------------------------- */
300/* Host specific functions */
301
302void c67x00_ll_set_husb_eot(struct c67x00_device *dev, u16 value)
303{
304 mutex_lock(&dev->hpi.lcp.mutex);
305 hpi_write_word(dev, HUSB_pEOT, value);
306 mutex_unlock(&dev->hpi.lcp.mutex);
307}
308
309static inline void c67x00_ll_husb_sie_init(struct c67x00_sie *sie)
310{
311 struct c67x00_device *dev = sie->dev;
312 struct c67x00_lcp_int_data data;
313 int rc;
314
315 rc = c67x00_comm_exec_int(dev, HUSB_SIE_INIT_INT(sie->sie_num), &data);
316 BUG_ON(rc); /* No return path for error code; crash spectacularly */
317}
318
319void c67x00_ll_husb_reset(struct c67x00_sie *sie, int port)
320{
321 struct c67x00_device *dev = sie->dev;
322 struct c67x00_lcp_int_data data;
323 int rc;
324
325 data.regs[0] = 50; /* Reset USB port for 50ms */
326 data.regs[1] = port | (sie->sie_num << 1);
327 rc = c67x00_comm_exec_int(dev, HUSB_RESET_INT, &data);
328 BUG_ON(rc); /* No return path for error code; crash spectacularly */
329}
330
331void c67x00_ll_husb_set_current_td(struct c67x00_sie *sie, u16 addr)
332{
333 hpi_write_word(sie->dev, HUSB_SIE_pCurrentTDPtr(sie->sie_num), addr);
334}
335
336u16 c67x00_ll_husb_get_current_td(struct c67x00_sie *sie)
337{
338 return hpi_read_word(sie->dev, HUSB_SIE_pCurrentTDPtr(sie->sie_num));
339}
340
341u16 c67x00_ll_husb_get_frame(struct c67x00_sie *sie)
342{
343 return hpi_read_word(sie->dev, HOST_FRAME_REG(sie->sie_num));
344}
345
346void c67x00_ll_husb_init_host_port(struct c67x00_sie *sie)
347{
348 /* Set port into host mode */
349 hpi_set_bits(sie->dev, USB_CTL_REG(sie->sie_num), HOST_MODE);
350 c67x00_ll_husb_sie_init(sie);
351 /* Clear interrupts */
352 c67x00_ll_usb_clear_status(sie, HOST_STAT_MASK);
353 /* Check */
354 if (!(hpi_read_word(sie->dev, USB_CTL_REG(sie->sie_num)) & HOST_MODE))
355 dev_warn(sie_dev(sie),
356 "SIE %d not set to host mode\n", sie->sie_num);
357}
358
359void c67x00_ll_husb_reset_port(struct c67x00_sie *sie, int port)
360{
361 /* Clear connect change */
362 c67x00_ll_usb_clear_status(sie, PORT_CONNECT_CHANGE(port));
363
364 /* Enable interrupts */
365 hpi_set_bits(sie->dev, HPI_IRQ_ROUTING_REG,
366 SOFEOP_TO_CPU_EN(sie->sie_num));
367 hpi_set_bits(sie->dev, HOST_IRQ_EN_REG(sie->sie_num),
368 SOF_EOP_IRQ_EN | DONE_IRQ_EN);
369
370 /* Enable pull down transistors */
371 hpi_set_bits(sie->dev, USB_CTL_REG(sie->sie_num), PORT_RES_EN(port));
372}
373
374/* -------------------------------------------------------------------------- */
375
376void c67x00_ll_irq(struct c67x00_device *dev, u16 int_status)
377{
378 if ((int_status & MBX_OUT_FLG) == 0)
379 return;
380
381 dev->hpi.lcp.last_msg = hpi_recv_mbox(dev);
382 complete(&dev->hpi.lcp.msg_received);
383}
384
385/* -------------------------------------------------------------------------- */
386
387int c67x00_ll_reset(struct c67x00_device *dev)
388{
389 int rc;
390
391 mutex_lock(&dev->hpi.lcp.mutex);
392 hpi_send_mbox(dev, COMM_RESET);
393 rc = ll_recv_msg(dev);
394 mutex_unlock(&dev->hpi.lcp.mutex);
395
396 return rc;
397}
398
399/* -------------------------------------------------------------------------- */
400
401/**
402 * c67x00_ll_write_mem_le16 - write into c67x00 memory
403 * Only data is little endian, addr has cpu endianess.
404 */
405void c67x00_ll_write_mem_le16(struct c67x00_device *dev, u16 addr,
406 void *data, int len)
407{
408 u8 *buf = data;
409
410 /* Sanity check */
411 if (addr + len > 0xffff) {
412 dev_err(&dev->pdev->dev,
413 "Trying to write beyond writable region!\n");
414 return;
415 }
416
417 if (addr & 0x01) {
418 /* unaligned access */
419 u16 tmp;
420 tmp = hpi_read_word(dev, addr - 1);
421 tmp = (tmp & 0x00ff) | (*buf++ << 8);
422 hpi_write_word(dev, addr - 1, tmp);
423 addr++;
424 len--;
425 }
426
427 hpi_write_words_le16(dev, addr, (u16 *)buf, len / 2);
428 buf += len & ~0x01;
429 addr += len & ~0x01;
430 len &= 0x01;
431
432 if (len) {
433 u16 tmp;
434 tmp = hpi_read_word(dev, addr);
435 tmp = (tmp & 0xff00) | *buf;
436 hpi_write_word(dev, addr, tmp);
437 }
438}
439
440/**
441 * c67x00_ll_read_mem_le16 - read from c67x00 memory
442 * Only data is little endian, addr has cpu endianess.
443 */
444void c67x00_ll_read_mem_le16(struct c67x00_device *dev, u16 addr,
445 void *data, int len)
446{
447 u8 *buf = data;
448
449 if (addr & 0x01) {
450 /* unaligned access */
451 u16 tmp;
452 tmp = hpi_read_word(dev, addr - 1);
453 *buf++ = (tmp >> 8) & 0x00ff;
454 addr++;
455 len--;
456 }
457
458 hpi_read_words_le16(dev, addr, (u16 *)buf, len / 2);
459 buf += len & ~0x01;
460 addr += len & ~0x01;
461 len &= 0x01;
462
463 if (len) {
464 u16 tmp;
465 tmp = hpi_read_word(dev, addr);
466 *buf = tmp & 0x00ff;
467 }
468}
469
470/* -------------------------------------------------------------------------- */
471
472void c67x00_ll_init(struct c67x00_device *dev)
473{
474 mutex_init(&dev->hpi.lcp.mutex);
475 init_completion(&dev->hpi.lcp.msg_received);
476}
477
478void c67x00_ll_release(struct c67x00_device *dev)
479{
480}
diff --git a/drivers/usb/c67x00/c67x00-sched.c b/drivers/usb/c67x00/c67x00-sched.c
new file mode 100644
index 000000000000..85dfe2965661
--- /dev/null
+++ b/drivers/usb/c67x00/c67x00-sched.c
@@ -0,0 +1,1170 @@
1/*
2 * c67x00-sched.c: Cypress C67X00 USB Host Controller Driver - TD scheduling
3 *
4 * Copyright (C) 2006-2008 Barco N.V.
5 * Derived from the Cypress cy7c67200/300 ezusb linux driver and
6 * based on multiple host controller drivers inside the linux kernel.
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, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 * MA 02110-1301 USA.
22 */
23
24#include <linux/kthread.h>
25
26#include "c67x00.h"
27#include "c67x00-hcd.h"
28
29/*
30 * These are the stages for a control urb, they are kept
31 * in both urb->interval and td->privdata.
32 */
33#define SETUP_STAGE 0
34#define DATA_STAGE 1
35#define STATUS_STAGE 2
36
37/* -------------------------------------------------------------------------- */
38
39/**
40 * struct c67x00_ep_data: Host endpoint data structure
41 */
42struct c67x00_ep_data {
43 struct list_head queue;
44 struct list_head node;
45 struct usb_host_endpoint *hep;
46 struct usb_device *dev;
47 u16 next_frame; /* For int/isoc transactions */
48};
49
50/**
51 * struct c67x00_td
52 *
53 * Hardware parts are little endiannes, SW in CPU endianess.
54 */
55struct c67x00_td {
56 /* HW specific part */
57 __le16 ly_base_addr; /* Bytes 0-1 */
58 __le16 port_length; /* Bytes 2-3 */
59 u8 pid_ep; /* Byte 4 */
60 u8 dev_addr; /* Byte 5 */
61 u8 ctrl_reg; /* Byte 6 */
62 u8 status; /* Byte 7 */
63 u8 retry_cnt; /* Byte 8 */
64#define TT_OFFSET 2
65#define TT_CONTROL 0
66#define TT_ISOCHRONOUS 1
67#define TT_BULK 2
68#define TT_INTERRUPT 3
69 u8 residue; /* Byte 9 */
70 __le16 next_td_addr; /* Bytes 10-11 */
71 /* SW part */
72 struct list_head td_list;
73 u16 td_addr;
74 void *data;
75 struct urb *urb;
76 unsigned long privdata;
77
78 /* These are needed for handling the toggle bits:
79 * an urb can be dequeued while a td is in progress
80 * after checking the td, the toggle bit might need to
81 * be fixed */
82 struct c67x00_ep_data *ep_data;
83 unsigned int pipe;
84};
85
86struct c67x00_urb_priv {
87 struct list_head hep_node;
88 struct urb *urb;
89 int port;
90 int cnt; /* packet number for isoc */
91 int status;
92 struct c67x00_ep_data *ep_data;
93};
94
95#define td_udev(td) ((td)->ep_data->dev)
96
97#define CY_TD_SIZE 12
98
99#define TD_PIDEP_OFFSET 0x04
100#define TD_PIDEPMASK_PID 0xF0
101#define TD_PIDEPMASK_EP 0x0F
102#define TD_PORTLENMASK_DL 0x02FF
103#define TD_PORTLENMASK_PN 0xC000
104
105#define TD_STATUS_OFFSET 0x07
106#define TD_STATUSMASK_ACK 0x01
107#define TD_STATUSMASK_ERR 0x02
108#define TD_STATUSMASK_TMOUT 0x04
109#define TD_STATUSMASK_SEQ 0x08
110#define TD_STATUSMASK_SETUP 0x10
111#define TD_STATUSMASK_OVF 0x20
112#define TD_STATUSMASK_NAK 0x40
113#define TD_STATUSMASK_STALL 0x80
114
115#define TD_ERROR_MASK (TD_STATUSMASK_ERR | TD_STATUSMASK_TMOUT | \
116 TD_STATUSMASK_STALL)
117
118#define TD_RETRYCNT_OFFSET 0x08
119#define TD_RETRYCNTMASK_ACT_FLG 0x10
120#define TD_RETRYCNTMASK_TX_TYPE 0x0C
121#define TD_RETRYCNTMASK_RTY_CNT 0x03
122
123#define TD_RESIDUE_OVERFLOW 0x80
124
125#define TD_PID_IN 0x90
126
127/* Residue: signed 8bits, neg -> OVERFLOW, pos -> UNDERFLOW */
128#define td_residue(td) ((__s8)(td->residue))
129#define td_ly_base_addr(td) (__le16_to_cpu((td)->ly_base_addr))
130#define td_port_length(td) (__le16_to_cpu((td)->port_length))
131#define td_next_td_addr(td) (__le16_to_cpu((td)->next_td_addr))
132
133#define td_active(td) ((td)->retry_cnt & TD_RETRYCNTMASK_ACT_FLG)
134#define td_length(td) (td_port_length(td) & TD_PORTLENMASK_DL)
135
136#define td_sequence_ok(td) (!td->status || \
137 (!(td->status & TD_STATUSMASK_SEQ) == \
138 !(td->ctrl_reg & SEQ_SEL)))
139
140#define td_acked(td) (!td->status || \
141 (td->status & TD_STATUSMASK_ACK))
142#define td_actual_bytes(td) (td_length(td) - td_residue(td))
143
144/* -------------------------------------------------------------------------- */
145
146#ifdef DEBUG
147
148/**
149 * dbg_td - Dump the contents of the TD
150 */
151static void dbg_td(struct c67x00_hcd *c67x00, struct c67x00_td *td, char *msg)
152{
153 struct device *dev = c67x00_hcd_dev(c67x00);
154
155 dev_dbg(dev, "### %s at 0x%04x\n", msg, td->td_addr);
156 dev_dbg(dev, "urb: 0x%p\n", td->urb);
157 dev_dbg(dev, "endpoint: %4d\n", usb_pipeendpoint(td->pipe));
158 dev_dbg(dev, "pipeout: %4d\n", usb_pipeout(td->pipe));
159 dev_dbg(dev, "ly_base_addr: 0x%04x\n", td_ly_base_addr(td));
160 dev_dbg(dev, "port_length: 0x%04x\n", td_port_length(td));
161 dev_dbg(dev, "pid_ep: 0x%02x\n", td->pid_ep);
162 dev_dbg(dev, "dev_addr: 0x%02x\n", td->dev_addr);
163 dev_dbg(dev, "ctrl_reg: 0x%02x\n", td->ctrl_reg);
164 dev_dbg(dev, "status: 0x%02x\n", td->status);
165 dev_dbg(dev, "retry_cnt: 0x%02x\n", td->retry_cnt);
166 dev_dbg(dev, "residue: 0x%02x\n", td->residue);
167 dev_dbg(dev, "next_td_addr: 0x%04x\n", td_next_td_addr(td));
168 dev_dbg(dev, "data:");
169 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 1,
170 td->data, td_length(td), 1);
171}
172#else /* DEBUG */
173
174static inline void
175dbg_td(struct c67x00_hcd *c67x00, struct c67x00_td *td, char *msg) { }
176
177#endif /* DEBUG */
178
179/* -------------------------------------------------------------------------- */
180/* Helper functions */
181
182static inline u16 c67x00_get_current_frame_number(struct c67x00_hcd *c67x00)
183{
184 return c67x00_ll_husb_get_frame(c67x00->sie) & HOST_FRAME_MASK;
185}
186
187/**
188 * frame_add
189 * Software wraparound for framenumbers.
190 */
191static inline u16 frame_add(u16 a, u16 b)
192{
193 return (a + b) & HOST_FRAME_MASK;
194}
195
196/**
197 * frame_after - is frame a after frame b
198 */
199static inline int frame_after(u16 a, u16 b)
200{
201 return ((HOST_FRAME_MASK + a - b) & HOST_FRAME_MASK) <
202 (HOST_FRAME_MASK / 2);
203}
204
205/**
206 * frame_after_eq - is frame a after or equal to frame b
207 */
208static inline int frame_after_eq(u16 a, u16 b)
209{
210 return ((HOST_FRAME_MASK + 1 + a - b) & HOST_FRAME_MASK) <
211 (HOST_FRAME_MASK / 2);
212}
213
214/* -------------------------------------------------------------------------- */
215
216/**
217 * c67x00_release_urb - remove link from all tds to this urb
218 * Disconnects the urb from it's tds, so that it can be given back.
219 * pre: urb->hcpriv != NULL
220 */
221static void c67x00_release_urb(struct c67x00_hcd *c67x00, struct urb *urb)
222{
223 struct c67x00_td *td;
224 struct c67x00_urb_priv *urbp;
225
226 BUG_ON(!urb);
227
228 c67x00->urb_count--;
229
230 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
231 c67x00->urb_iso_count--;
232 if (c67x00->urb_iso_count == 0)
233 c67x00->max_frame_bw = MAX_FRAME_BW_STD;
234 }
235
236 /* TODO this might be not so efficient when we've got many urbs!
237 * Alternatives:
238 * * only clear when needed
239 * * keep a list of tds with each urbp
240 */
241 list_for_each_entry(td, &c67x00->td_list, td_list)
242 if (urb == td->urb)
243 td->urb = NULL;
244
245 urbp = urb->hcpriv;
246 urb->hcpriv = NULL;
247 list_del(&urbp->hep_node);
248 kfree(urbp);
249}
250
251/* -------------------------------------------------------------------------- */
252
253static struct c67x00_ep_data *
254c67x00_ep_data_alloc(struct c67x00_hcd *c67x00, struct urb *urb)
255{
256 struct usb_host_endpoint *hep = urb->ep;
257 struct c67x00_ep_data *ep_data;
258 int type;
259
260 c67x00->current_frame = c67x00_get_current_frame_number(c67x00);
261
262 /* Check if endpoint already has a c67x00_ep_data struct allocated */
263 if (hep->hcpriv) {
264 ep_data = hep->hcpriv;
265 if (frame_after(c67x00->current_frame, ep_data->next_frame))
266 ep_data->next_frame =
267 frame_add(c67x00->current_frame, 1);
268 return hep->hcpriv;
269 }
270
271 /* Allocate and initialize a new c67x00 endpoint data structure */
272 ep_data = kzalloc(sizeof(*ep_data), GFP_ATOMIC);
273 if (!ep_data)
274 return NULL;
275
276 INIT_LIST_HEAD(&ep_data->queue);
277 INIT_LIST_HEAD(&ep_data->node);
278 ep_data->hep = hep;
279
280 /* hold a reference to udev as long as this endpoint lives,
281 * this is needed to possibly fix the data toggle */
282 ep_data->dev = usb_get_dev(urb->dev);
283 hep->hcpriv = ep_data;
284
285 /* For ISOC and INT endpoints, start ASAP: */
286 ep_data->next_frame = frame_add(c67x00->current_frame, 1);
287
288 /* Add the endpoint data to one of the pipe lists; must be added
289 in order of endpoint address */
290 type = usb_pipetype(urb->pipe);
291 if (list_empty(&ep_data->node)) {
292 list_add(&ep_data->node, &c67x00->list[type]);
293 } else {
294 struct c67x00_ep_data *prev;
295
296 list_for_each_entry(prev, &c67x00->list[type], node) {
297 if (prev->hep->desc.bEndpointAddress >
298 hep->desc.bEndpointAddress) {
299 list_add(&ep_data->node, prev->node.prev);
300 break;
301 }
302 }
303 }
304
305 return ep_data;
306}
307
308static int c67x00_ep_data_free(struct usb_host_endpoint *hep)
309{
310 struct c67x00_ep_data *ep_data = hep->hcpriv;
311
312 if (!ep_data)
313 return 0;
314
315 if (!list_empty(&ep_data->queue))
316 return -EBUSY;
317
318 usb_put_dev(ep_data->dev);
319 list_del(&ep_data->queue);
320 list_del(&ep_data->node);
321
322 kfree(ep_data);
323 hep->hcpriv = NULL;
324
325 return 0;
326}
327
328void c67x00_endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
329{
330 struct c67x00_hcd *c67x00 = hcd_to_c67x00_hcd(hcd);
331 unsigned long flags;
332
333 if (!list_empty(&ep->urb_list))
334 dev_warn(c67x00_hcd_dev(c67x00), "error: urb list not empty\n");
335
336 spin_lock_irqsave(&c67x00->lock, flags);
337
338 /* loop waiting for all transfers in the endpoint queue to complete */
339 while (c67x00_ep_data_free(ep)) {
340 /* Drop the lock so we can sleep waiting for the hardware */
341 spin_unlock_irqrestore(&c67x00->lock, flags);
342
343 /* it could happen that we reinitialize this completion, while
344 * somebody was waiting for that completion. The timeout and
345 * while loop handle such cases, but this might be improved */
346 INIT_COMPLETION(c67x00->endpoint_disable);
347 c67x00_sched_kick(c67x00);
348 wait_for_completion_timeout(&c67x00->endpoint_disable, 1 * HZ);
349
350 spin_lock_irqsave(&c67x00->lock, flags);
351 }
352
353 spin_unlock_irqrestore(&c67x00->lock, flags);
354}
355
356/* -------------------------------------------------------------------------- */
357
358static inline int get_root_port(struct usb_device *dev)
359{
360 while (dev->parent->parent)
361 dev = dev->parent;
362 return dev->portnum;
363}
364
365int c67x00_urb_enqueue(struct usb_hcd *hcd,
366 struct urb *urb, gfp_t mem_flags)
367{
368 int ret;
369 unsigned long flags;
370 struct c67x00_urb_priv *urbp;
371 struct c67x00_hcd *c67x00 = hcd_to_c67x00_hcd(hcd);
372 int port = get_root_port(urb->dev)-1;
373
374 spin_lock_irqsave(&c67x00->lock, flags);
375
376 /* Make sure host controller is running */
377 if (!HC_IS_RUNNING(hcd->state)) {
378 ret = -ENODEV;
379 goto err_not_linked;
380 }
381
382 ret = usb_hcd_link_urb_to_ep(hcd, urb);
383 if (ret)
384 goto err_not_linked;
385
386 /* Allocate and initialize urb private data */
387 urbp = kzalloc(sizeof(*urbp), mem_flags);
388 if (!urbp) {
389 ret = -ENOMEM;
390 goto err_urbp;
391 }
392
393 INIT_LIST_HEAD(&urbp->hep_node);
394 urbp->urb = urb;
395 urbp->port = port;
396
397 urbp->ep_data = c67x00_ep_data_alloc(c67x00, urb);
398
399 if (!urbp->ep_data) {
400 ret = -ENOMEM;
401 goto err_epdata;
402 }
403
404 /* TODO claim bandwidth with usb_claim_bandwidth?
405 * also release it somewhere! */
406
407 urb->hcpriv = urbp;
408
409 urb->actual_length = 0; /* Nothing received/transmitted yet */
410
411 switch (usb_pipetype(urb->pipe)) {
412 case PIPE_CONTROL:
413 urb->interval = SETUP_STAGE;
414 break;
415 case PIPE_INTERRUPT:
416 break;
417 case PIPE_BULK:
418 break;
419 case PIPE_ISOCHRONOUS:
420 if (c67x00->urb_iso_count == 0)
421 c67x00->max_frame_bw = MAX_FRAME_BW_ISO;
422 c67x00->urb_iso_count++;
423 /* Assume always URB_ISO_ASAP, FIXME */
424 if (list_empty(&urbp->ep_data->queue))
425 urb->start_frame = urbp->ep_data->next_frame;
426 else {
427 /* Go right after the last one */
428 struct urb *last_urb;
429
430 last_urb = list_entry(urbp->ep_data->queue.prev,
431 struct c67x00_urb_priv,
432 hep_node)->urb;
433 urb->start_frame =
434 frame_add(last_urb->start_frame,
435 last_urb->number_of_packets *
436 last_urb->interval);
437 }
438 urbp->cnt = 0;
439 break;
440 }
441
442 /* Add the URB to the endpoint queue */
443 list_add_tail(&urbp->hep_node, &urbp->ep_data->queue);
444
445 /* If this is the only URB, kick start the controller */
446 if (!c67x00->urb_count++)
447 c67x00_ll_hpi_enable_sofeop(c67x00->sie);
448
449 c67x00_sched_kick(c67x00);
450 spin_unlock_irqrestore(&c67x00->lock, flags);
451
452 return 0;
453
454err_epdata:
455 kfree(urbp);
456err_urbp:
457 usb_hcd_unlink_urb_from_ep(hcd, urb);
458err_not_linked:
459 spin_unlock_irqrestore(&c67x00->lock, flags);
460
461 return ret;
462}
463
464int c67x00_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
465{
466 struct c67x00_hcd *c67x00 = hcd_to_c67x00_hcd(hcd);
467 unsigned long flags;
468 int rc;
469
470 spin_lock_irqsave(&c67x00->lock, flags);
471 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
472 if (rc)
473 goto done;
474
475 c67x00_release_urb(c67x00, urb);
476 usb_hcd_unlink_urb_from_ep(hcd, urb);
477
478 spin_unlock(&c67x00->lock);
479 usb_hcd_giveback_urb(hcd, urb, status);
480 spin_lock(&c67x00->lock);
481
482 spin_unlock_irqrestore(&c67x00->lock, flags);
483
484 return 0;
485
486 done:
487 spin_unlock_irqrestore(&c67x00->lock, flags);
488 return rc;
489}
490
491/* -------------------------------------------------------------------------- */
492
493/*
494 * pre: c67x00 locked, urb unlocked
495 */
496static void
497c67x00_giveback_urb(struct c67x00_hcd *c67x00, struct urb *urb, int status)
498{
499 struct c67x00_urb_priv *urbp;
500
501 if (!urb)
502 return;
503
504 urbp = urb->hcpriv;
505 urbp->status = status;
506
507 list_del_init(&urbp->hep_node);
508
509 c67x00_release_urb(c67x00, urb);
510 usb_hcd_unlink_urb_from_ep(c67x00_hcd_to_hcd(c67x00), urb);
511 spin_unlock(&c67x00->lock);
512 usb_hcd_giveback_urb(c67x00_hcd_to_hcd(c67x00), urb, urbp->status);
513 spin_lock(&c67x00->lock);
514}
515
516/* -------------------------------------------------------------------------- */
517
518static int c67x00_claim_frame_bw(struct c67x00_hcd *c67x00, struct urb *urb,
519 int len, int periodic)
520{
521 struct c67x00_urb_priv *urbp = urb->hcpriv;
522 int bit_time;
523
524 /* According to the C67x00 BIOS user manual, page 3-18,19, the
525 * following calculations provide the full speed bit times for
526 * a transaction.
527 *
528 * FS(in) = 112.5 + 9.36*BC + HOST_DELAY
529 * FS(in,iso) = 90.5 + 9.36*BC + HOST_DELAY
530 * FS(out) = 112.5 + 9.36*BC + HOST_DELAY
531 * FS(out,iso) = 78.4 + 9.36*BC + HOST_DELAY
532 * LS(in) = 802.4 + 75.78*BC + HOST_DELAY
533 * LS(out) = 802.6 + 74.67*BC + HOST_DELAY
534 *
535 * HOST_DELAY == 106 for the c67200 and c67300.
536 */
537
538 /* make calculations in 1/100 bit times to maintain resolution */
539 if (urbp->ep_data->dev->speed == USB_SPEED_LOW) {
540 /* Low speed pipe */
541 if (usb_pipein(urb->pipe))
542 bit_time = 80240 + 7578*len;
543 else
544 bit_time = 80260 + 7467*len;
545 } else {
546 /* FS pipes */
547 if (usb_pipeisoc(urb->pipe))
548 bit_time = usb_pipein(urb->pipe) ? 9050 : 7840;
549 else
550 bit_time = 11250;
551 bit_time += 936*len;
552 }
553
554 /* Scale back down to integer bit times. Use a host delay of 106.
555 * (this is the only place it is used) */
556 bit_time = ((bit_time+50) / 100) + 106;
557
558 if (unlikely(bit_time + c67x00->bandwidth_allocated >=
559 c67x00->max_frame_bw))
560 return -EMSGSIZE;
561
562 if (unlikely(c67x00->next_td_addr + CY_TD_SIZE >=
563 c67x00->td_base_addr + SIE_TD_SIZE))
564 return -EMSGSIZE;
565
566 if (unlikely(c67x00->next_buf_addr + len >=
567 c67x00->buf_base_addr + SIE_TD_BUF_SIZE))
568 return -EMSGSIZE;
569
570 if (periodic) {
571 if (unlikely(bit_time + c67x00->periodic_bw_allocated >=
572 MAX_PERIODIC_BW(c67x00->max_frame_bw)))
573 return -EMSGSIZE;
574 c67x00->periodic_bw_allocated += bit_time;
575 }
576
577 c67x00->bandwidth_allocated += bit_time;
578 return 0;
579}
580
581/* -------------------------------------------------------------------------- */
582
583/**
584 * td_addr and buf_addr must be word aligned
585 */
586static int c67x00_create_td(struct c67x00_hcd *c67x00, struct urb *urb,
587 void *data, int len, int pid, int toggle,
588 unsigned long privdata)
589{
590 struct c67x00_td *td;
591 struct c67x00_urb_priv *urbp = urb->hcpriv;
592 const __u8 active_flag = 1, retry_cnt = 1;
593 __u8 cmd = 0;
594 int tt = 0;
595
596 if (c67x00_claim_frame_bw(c67x00, urb, len, usb_pipeisoc(urb->pipe)
597 || usb_pipeint(urb->pipe)))
598 return -EMSGSIZE; /* Not really an error, but expected */
599
600 td = kzalloc(sizeof(*td), GFP_ATOMIC);
601 if (!td)
602 return -ENOMEM;
603
604 td->pipe = urb->pipe;
605 td->ep_data = urbp->ep_data;
606
607 if ((td_udev(td)->speed == USB_SPEED_LOW) &&
608 !(c67x00->low_speed_ports & (1 << urbp->port)))
609 cmd |= PREAMBLE_EN;
610
611 switch (usb_pipetype(td->pipe)) {
612 case PIPE_ISOCHRONOUS:
613 tt = TT_ISOCHRONOUS;
614 cmd |= ISO_EN;
615 break;
616 case PIPE_CONTROL:
617 tt = TT_CONTROL;
618 break;
619 case PIPE_BULK:
620 tt = TT_BULK;
621 break;
622 case PIPE_INTERRUPT:
623 tt = TT_INTERRUPT;
624 break;
625 }
626
627 if (toggle)
628 cmd |= SEQ_SEL;
629
630 cmd |= ARM_EN;
631
632 /* SW part */
633 td->td_addr = c67x00->next_td_addr;
634 c67x00->next_td_addr = c67x00->next_td_addr + CY_TD_SIZE;
635
636 /* HW part */
637 td->ly_base_addr = __cpu_to_le16(c67x00->next_buf_addr);
638 td->port_length = __cpu_to_le16((c67x00->sie->sie_num << 15) |
639 (urbp->port << 14) | (len & 0x3FF));
640 td->pid_ep = ((pid & 0xF) << TD_PIDEP_OFFSET) |
641 (usb_pipeendpoint(td->pipe) & 0xF);
642 td->dev_addr = usb_pipedevice(td->pipe) & 0x7F;
643 td->ctrl_reg = cmd;
644 td->status = 0;
645 td->retry_cnt = (tt << TT_OFFSET) | (active_flag << 4) | retry_cnt;
646 td->residue = 0;
647 td->next_td_addr = __cpu_to_le16(c67x00->next_td_addr);
648
649 /* SW part */
650 td->data = data;
651 td->urb = urb;
652 td->privdata = privdata;
653
654 c67x00->next_buf_addr += (len + 1) & ~0x01; /* properly align */
655
656 list_add_tail(&td->td_list, &c67x00->td_list);
657 return 0;
658}
659
660static inline void c67x00_release_td(struct c67x00_td *td)
661{
662 list_del_init(&td->td_list);
663 kfree(td);
664}
665
666/* -------------------------------------------------------------------------- */
667
668static int c67x00_add_data_urb(struct c67x00_hcd *c67x00, struct urb *urb)
669{
670 int remaining;
671 int toggle;
672 int pid;
673 int ret = 0;
674 int maxps;
675 int need_empty;
676
677 toggle = usb_gettoggle(urb->dev, usb_pipeendpoint(urb->pipe),
678 usb_pipeout(urb->pipe));
679 remaining = urb->transfer_buffer_length - urb->actual_length;
680
681 maxps = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe));
682
683 need_empty = (urb->transfer_flags & URB_ZERO_PACKET) &&
684 usb_pipeout(urb->pipe) && !(remaining % maxps);
685
686 while (remaining || need_empty) {
687 int len;
688 char *td_buf;
689
690 len = (remaining > maxps) ? maxps : remaining;
691 if (!len)
692 need_empty = 0;
693
694 pid = usb_pipeout(urb->pipe) ? USB_PID_OUT : USB_PID_IN;
695 td_buf = urb->transfer_buffer + urb->transfer_buffer_length -
696 remaining;
697 ret = c67x00_create_td(c67x00, urb, td_buf, len, pid, toggle,
698 DATA_STAGE);
699 if (ret)
700 return ret; /* td wasn't created */
701
702 toggle ^= 1;
703 remaining -= len;
704 if (usb_pipecontrol(urb->pipe))
705 break;
706 }
707
708 return 0;
709}
710
711/**
712 * return 0 in case more bandwidth is available, else errorcode
713 */
714static int c67x00_add_ctrl_urb(struct c67x00_hcd *c67x00, struct urb *urb)
715{
716 int ret;
717 int pid;
718
719 switch (urb->interval) {
720 default:
721 case SETUP_STAGE:
722 ret = c67x00_create_td(c67x00, urb, urb->setup_packet,
723 8, USB_PID_SETUP, 0, SETUP_STAGE);
724 if (ret)
725 return ret;
726 urb->interval = SETUP_STAGE;
727 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
728 usb_pipeout(urb->pipe), 1);
729 break;
730 case DATA_STAGE:
731 if (urb->transfer_buffer_length) {
732 ret = c67x00_add_data_urb(c67x00, urb);
733 if (ret)
734 return ret;
735 break;
736 } /* else fallthrough */
737 case STATUS_STAGE:
738 pid = !usb_pipeout(urb->pipe) ? USB_PID_OUT : USB_PID_IN;
739 ret = c67x00_create_td(c67x00, urb, NULL, 0, pid, 1,
740 STATUS_STAGE);
741 if (ret)
742 return ret;
743 break;
744 }
745
746 return 0;
747}
748
749/*
750 * return 0 in case more bandwidth is available, else errorcode
751 */
752static int c67x00_add_int_urb(struct c67x00_hcd *c67x00, struct urb *urb)
753{
754 struct c67x00_urb_priv *urbp = urb->hcpriv;
755
756 if (frame_after_eq(c67x00->current_frame, urbp->ep_data->next_frame)) {
757 urbp->ep_data->next_frame =
758 frame_add(urbp->ep_data->next_frame, urb->interval);
759 return c67x00_add_data_urb(c67x00, urb);
760 }
761 return 0;
762}
763
764static int c67x00_add_iso_urb(struct c67x00_hcd *c67x00, struct urb *urb)
765{
766 struct c67x00_urb_priv *urbp = urb->hcpriv;
767
768 if (frame_after_eq(c67x00->current_frame, urbp->ep_data->next_frame)) {
769 char *td_buf;
770 int len, pid, ret;
771
772 BUG_ON(urbp->cnt >= urb->number_of_packets);
773
774 td_buf = urb->transfer_buffer +
775 urb->iso_frame_desc[urbp->cnt].offset;
776 len = urb->iso_frame_desc[urbp->cnt].length;
777 pid = usb_pipeout(urb->pipe) ? USB_PID_OUT : USB_PID_IN;
778
779 ret = c67x00_create_td(c67x00, urb, td_buf, len, pid, 0,
780 urbp->cnt);
781 if (ret) {
782 printk(KERN_DEBUG "create failed: %d\n", ret);
783 urb->iso_frame_desc[urbp->cnt].actual_length = 0;
784 urb->iso_frame_desc[urbp->cnt].status = ret;
785 if (urbp->cnt + 1 == urb->number_of_packets)
786 c67x00_giveback_urb(c67x00, urb, 0);
787 }
788
789 urbp->ep_data->next_frame =
790 frame_add(urbp->ep_data->next_frame, urb->interval);
791 urbp->cnt++;
792 }
793 return 0;
794}
795
796/* -------------------------------------------------------------------------- */
797
798static void c67x00_fill_from_list(struct c67x00_hcd *c67x00, int type,
799 int (*add)(struct c67x00_hcd *, struct urb *))
800{
801 struct c67x00_ep_data *ep_data;
802 struct urb *urb;
803
804 /* traverse every endpoint on the list */
805 list_for_each_entry(ep_data, &c67x00->list[type], node) {
806 if (!list_empty(&ep_data->queue)) {
807 /* and add the first urb */
808 /* isochronous transfer rely on this */
809 urb = list_entry(ep_data->queue.next,
810 struct c67x00_urb_priv,
811 hep_node)->urb;
812 add(c67x00, urb);
813 }
814 }
815}
816
817static void c67x00_fill_frame(struct c67x00_hcd *c67x00)
818{
819 struct c67x00_td *td, *ttd;
820
821 /* Check if we can proceed */
822 if (!list_empty(&c67x00->td_list)) {
823 dev_warn(c67x00_hcd_dev(c67x00),
824 "TD list not empty! This should not happen!\n");
825 list_for_each_entry_safe(td, ttd, &c67x00->td_list, td_list) {
826 dbg_td(c67x00, td, "Unprocessed td");
827 c67x00_release_td(td);
828 }
829 }
830
831 /* Reinitialize variables */
832 c67x00->bandwidth_allocated = 0;
833 c67x00->periodic_bw_allocated = 0;
834
835 c67x00->next_td_addr = c67x00->td_base_addr;
836 c67x00->next_buf_addr = c67x00->buf_base_addr;
837
838 /* Fill the list */
839 c67x00_fill_from_list(c67x00, PIPE_ISOCHRONOUS, c67x00_add_iso_urb);
840 c67x00_fill_from_list(c67x00, PIPE_INTERRUPT, c67x00_add_int_urb);
841 c67x00_fill_from_list(c67x00, PIPE_CONTROL, c67x00_add_ctrl_urb);
842 c67x00_fill_from_list(c67x00, PIPE_BULK, c67x00_add_data_urb);
843}
844
845/* -------------------------------------------------------------------------- */
846
847/**
848 * Get TD from C67X00
849 */
850static inline void
851c67x00_parse_td(struct c67x00_hcd *c67x00, struct c67x00_td *td)
852{
853 c67x00_ll_read_mem_le16(c67x00->sie->dev,
854 td->td_addr, td, CY_TD_SIZE);
855
856 if (usb_pipein(td->pipe) && td_actual_bytes(td))
857 c67x00_ll_read_mem_le16(c67x00->sie->dev, td_ly_base_addr(td),
858 td->data, td_actual_bytes(td));
859}
860
861static int c67x00_td_to_error(struct c67x00_hcd *c67x00, struct c67x00_td *td)
862{
863 if (td->status & TD_STATUSMASK_ERR) {
864 dbg_td(c67x00, td, "ERROR_FLAG");
865 return -EILSEQ;
866 }
867 if (td->status & TD_STATUSMASK_STALL) {
868 /* dbg_td(c67x00, td, "STALL"); */
869 return -EPIPE;
870 }
871 if (td->status & TD_STATUSMASK_TMOUT) {
872 dbg_td(c67x00, td, "TIMEOUT");
873 return -ETIMEDOUT;
874 }
875
876 return 0;
877}
878
879static inline int c67x00_end_of_data(struct c67x00_td *td)
880{
881 int maxps, need_empty, remaining;
882 struct urb *urb = td->urb;
883 int act_bytes;
884
885 act_bytes = td_actual_bytes(td);
886
887 if (unlikely(!act_bytes))
888 return 1; /* This was an empty packet */
889
890 maxps = usb_maxpacket(td_udev(td), td->pipe, usb_pipeout(td->pipe));
891
892 if (unlikely(act_bytes < maxps))
893 return 1; /* Smaller then full packet */
894
895 remaining = urb->transfer_buffer_length - urb->actual_length;
896 need_empty = (urb->transfer_flags & URB_ZERO_PACKET) &&
897 usb_pipeout(urb->pipe) && !(remaining % maxps);
898
899 if (unlikely(!remaining && !need_empty))
900 return 1;
901
902 return 0;
903}
904
905/* -------------------------------------------------------------------------- */
906
907/* Remove all td's from the list which come
908 * after last_td and are meant for the same pipe.
909 * This is used when a short packet has occured */
910static inline void c67x00_clear_pipe(struct c67x00_hcd *c67x00,
911 struct c67x00_td *last_td)
912{
913 struct c67x00_td *td, *tmp;
914 td = last_td;
915 tmp = last_td;
916 while (td->td_list.next != &c67x00->td_list) {
917 td = list_entry(td->td_list.next, struct c67x00_td, td_list);
918 if (td->pipe == last_td->pipe) {
919 c67x00_release_td(td);
920 td = tmp;
921 }
922 tmp = td;
923 }
924}
925
926/* -------------------------------------------------------------------------- */
927
928static void c67x00_handle_successful_td(struct c67x00_hcd *c67x00,
929 struct c67x00_td *td)
930{
931 struct urb *urb = td->urb;
932
933 if (!urb)
934 return;
935
936 urb->actual_length += td_actual_bytes(td);
937
938 switch (usb_pipetype(td->pipe)) {
939 /* isochronous tds are handled separately */
940 case PIPE_CONTROL:
941 switch (td->privdata) {
942 case SETUP_STAGE:
943 urb->interval =
944 urb->transfer_buffer_length ?
945 DATA_STAGE : STATUS_STAGE;
946 /* Don't count setup_packet with normal data: */
947 urb->actual_length = 0;
948 break;
949
950 case DATA_STAGE:
951 if (c67x00_end_of_data(td)) {
952 urb->interval = STATUS_STAGE;
953 c67x00_clear_pipe(c67x00, td);
954 }
955 break;
956
957 case STATUS_STAGE:
958 urb->interval = 0;
959 c67x00_giveback_urb(c67x00, urb, 0);
960 break;
961 }
962 break;
963
964 case PIPE_INTERRUPT:
965 case PIPE_BULK:
966 if (unlikely(c67x00_end_of_data(td))) {
967 c67x00_clear_pipe(c67x00, td);
968 c67x00_giveback_urb(c67x00, urb, 0);
969 }
970 break;
971 }
972}
973
974static void c67x00_handle_isoc(struct c67x00_hcd *c67x00, struct c67x00_td *td)
975{
976 struct urb *urb = td->urb;
977 struct c67x00_urb_priv *urbp;
978 int cnt;
979
980 if (!urb)
981 return;
982
983 urbp = urb->hcpriv;
984 cnt = td->privdata;
985
986 if (td->status & TD_ERROR_MASK)
987 urb->error_count++;
988
989 urb->iso_frame_desc[cnt].actual_length = td_actual_bytes(td);
990 urb->iso_frame_desc[cnt].status = c67x00_td_to_error(c67x00, td);
991 if (cnt + 1 == urb->number_of_packets) /* Last packet */
992 c67x00_giveback_urb(c67x00, urb, 0);
993}
994
995/* -------------------------------------------------------------------------- */
996
997/**
998 * c67x00_check_td_list - handle tds which have been processed by the c67x00
999 * pre: current_td == 0
1000 */
1001static inline void c67x00_check_td_list(struct c67x00_hcd *c67x00)
1002{
1003 struct c67x00_td *td, *tmp;
1004 struct urb *urb;
1005 int ack_ok;
1006 int clear_endpoint;
1007
1008 list_for_each_entry_safe(td, tmp, &c67x00->td_list, td_list) {
1009 /* get the TD */
1010 c67x00_parse_td(c67x00, td);
1011 urb = td->urb; /* urb can be NULL! */
1012 ack_ok = 0;
1013 clear_endpoint = 1;
1014
1015 /* Handle isochronous transfers separately */
1016 if (usb_pipeisoc(td->pipe)) {
1017 clear_endpoint = 0;
1018 c67x00_handle_isoc(c67x00, td);
1019 goto cont;
1020 }
1021
1022 /* When an error occurs, all td's for that pipe go into an
1023 * inactive state. This state matches successful transfers so
1024 * we must make sure not to service them. */
1025 if (td->status & TD_ERROR_MASK) {
1026 c67x00_giveback_urb(c67x00, urb,
1027 c67x00_td_to_error(c67x00, td));
1028 goto cont;
1029 }
1030
1031 if ((td->status & TD_STATUSMASK_NAK) || !td_sequence_ok(td) ||
1032 !td_acked(td))
1033 goto cont;
1034
1035 /* Sequence ok and acked, don't need to fix toggle */
1036 ack_ok = 1;
1037
1038 if (unlikely(td->status & TD_STATUSMASK_OVF)) {
1039 if (td_residue(td) & TD_RESIDUE_OVERFLOW) {
1040 /* Overflow */
1041 c67x00_giveback_urb(c67x00, urb, -EOVERFLOW);
1042 goto cont;
1043 }
1044 }
1045
1046 clear_endpoint = 0;
1047 c67x00_handle_successful_td(c67x00, td);
1048
1049cont:
1050 if (clear_endpoint)
1051 c67x00_clear_pipe(c67x00, td);
1052 if (ack_ok)
1053 usb_settoggle(td_udev(td), usb_pipeendpoint(td->pipe),
1054 usb_pipeout(td->pipe),
1055 !(td->ctrl_reg & SEQ_SEL));
1056 /* next in list could have been removed, due to clear_pipe! */
1057 tmp = list_entry(td->td_list.next, typeof(*td), td_list);
1058 c67x00_release_td(td);
1059 }
1060}
1061
1062/* -------------------------------------------------------------------------- */
1063
1064static inline int c67x00_all_tds_processed(struct c67x00_hcd *c67x00)
1065{
1066 /* If all tds are processed, we can check the previous frame (if
1067 * there was any) and start our next frame.
1068 */
1069 return !c67x00_ll_husb_get_current_td(c67x00->sie);
1070}
1071
1072/**
1073 * Send td to C67X00
1074 */
1075static void c67x00_send_td(struct c67x00_hcd *c67x00, struct c67x00_td *td)
1076{
1077 int len = td_length(td);
1078
1079 if (len && ((td->pid_ep & TD_PIDEPMASK_PID) != TD_PID_IN))
1080 c67x00_ll_write_mem_le16(c67x00->sie->dev, td_ly_base_addr(td),
1081 td->data, len);
1082
1083 c67x00_ll_write_mem_le16(c67x00->sie->dev,
1084 td->td_addr, td, CY_TD_SIZE);
1085}
1086
1087static void c67x00_send_frame(struct c67x00_hcd *c67x00)
1088{
1089 struct c67x00_td *td;
1090
1091 if (list_empty(&c67x00->td_list))
1092 dev_warn(c67x00_hcd_dev(c67x00),
1093 "%s: td list should not be empty here!\n",
1094 __func__);
1095
1096 list_for_each_entry(td, &c67x00->td_list, td_list) {
1097 if (td->td_list.next == &c67x00->td_list)
1098 td->next_td_addr = 0; /* Last td in list */
1099
1100 c67x00_send_td(c67x00, td);
1101 }
1102
1103 c67x00_ll_husb_set_current_td(c67x00->sie, c67x00->td_base_addr);
1104}
1105
1106/* -------------------------------------------------------------------------- */
1107
1108/**
1109 * c67x00_do_work - Schedulers state machine
1110 */
1111static void c67x00_do_work(struct c67x00_hcd *c67x00)
1112{
1113 spin_lock(&c67x00->lock);
1114 /* Make sure all tds are processed */
1115 if (!c67x00_all_tds_processed(c67x00))
1116 goto out;
1117
1118 c67x00_check_td_list(c67x00);
1119
1120 /* no td's are being processed (current == 0)
1121 * and all have been "checked" */
1122 complete(&c67x00->endpoint_disable);
1123
1124 if (!list_empty(&c67x00->td_list))
1125 goto out;
1126
1127 c67x00->current_frame = c67x00_get_current_frame_number(c67x00);
1128 if (c67x00->current_frame == c67x00->last_frame)
1129 goto out; /* Don't send tds in same frame */
1130 c67x00->last_frame = c67x00->current_frame;
1131
1132 /* If no urbs are scheduled, our work is done */
1133 if (!c67x00->urb_count) {
1134 c67x00_ll_hpi_disable_sofeop(c67x00->sie);
1135 goto out;
1136 }
1137
1138 c67x00_fill_frame(c67x00);
1139 if (!list_empty(&c67x00->td_list))
1140 /* TD's have been added to the frame */
1141 c67x00_send_frame(c67x00);
1142
1143 out:
1144 spin_unlock(&c67x00->lock);
1145}
1146
1147/* -------------------------------------------------------------------------- */
1148
1149static void c67x00_sched_tasklet(unsigned long __c67x00)
1150{
1151 struct c67x00_hcd *c67x00 = (struct c67x00_hcd *)__c67x00;
1152 c67x00_do_work(c67x00);
1153}
1154
1155void c67x00_sched_kick(struct c67x00_hcd *c67x00)
1156{
1157 tasklet_hi_schedule(&c67x00->tasklet);
1158}
1159
1160int c67x00_sched_start_scheduler(struct c67x00_hcd *c67x00)
1161{
1162 tasklet_init(&c67x00->tasklet, c67x00_sched_tasklet,
1163 (unsigned long)c67x00);
1164 return 0;
1165}
1166
1167void c67x00_sched_stop_scheduler(struct c67x00_hcd *c67x00)
1168{
1169 tasklet_kill(&c67x00->tasklet);
1170}
diff --git a/drivers/usb/c67x00/c67x00.h b/drivers/usb/c67x00/c67x00.h
new file mode 100644
index 000000000000..a26e9ded0f32
--- /dev/null
+++ b/drivers/usb/c67x00/c67x00.h
@@ -0,0 +1,294 @@
1/*
2 * c67x00.h: Cypress C67X00 USB register and field definitions
3 *
4 * Copyright (C) 2006-2008 Barco N.V.
5 * Derived from the Cypress cy7c67200/300 ezusb linux driver and
6 * based on multiple host controller drivers inside the linux kernel.
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, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 * MA 02110-1301 USA.
22 */
23
24#ifndef _USB_C67X00_H
25#define _USB_C67X00_H
26
27#include <linux/spinlock.h>
28#include <linux/platform_device.h>
29#include <linux/completion.h>
30#include <linux/mutex.h>
31
32/* ---------------------------------------------------------------------
33 * Cypress C67x00 register definitions
34 */
35
36/* Hardware Revision Register */
37#define HW_REV_REG 0xC004
38
39/* General USB registers */
40/* ===================== */
41
42/* USB Control Register */
43#define USB_CTL_REG(x) ((x) ? 0xC0AA : 0xC08A)
44
45#define LOW_SPEED_PORT(x) ((x) ? 0x0800 : 0x0400)
46#define HOST_MODE 0x0200
47#define PORT_RES_EN(x) ((x) ? 0x0100 : 0x0080)
48#define SOF_EOP_EN(x) ((x) ? 0x0002 : 0x0001)
49
50/* USB status register - Notice it has different content in hcd/udc mode */
51#define USB_STAT_REG(x) ((x) ? 0xC0B0 : 0xC090)
52
53#define EP0_IRQ_FLG 0x0001
54#define EP1_IRQ_FLG 0x0002
55#define EP2_IRQ_FLG 0x0004
56#define EP3_IRQ_FLG 0x0008
57#define EP4_IRQ_FLG 0x0010
58#define EP5_IRQ_FLG 0x0020
59#define EP6_IRQ_FLG 0x0040
60#define EP7_IRQ_FLG 0x0080
61#define RESET_IRQ_FLG 0x0100
62#define SOF_EOP_IRQ_FLG 0x0200
63#define ID_IRQ_FLG 0x4000
64#define VBUS_IRQ_FLG 0x8000
65
66/* USB Host only registers */
67/* ======================= */
68
69/* Host n Control Register */
70#define HOST_CTL_REG(x) ((x) ? 0xC0A0 : 0xC080)
71
72#define PREAMBLE_EN 0x0080 /* Preamble enable */
73#define SEQ_SEL 0x0040 /* Data Toggle Sequence Bit Select */
74#define ISO_EN 0x0010 /* Isochronous enable */
75#define ARM_EN 0x0001 /* Arm operation */
76
77/* Host n Interrupt Enable Register */
78#define HOST_IRQ_EN_REG(x) ((x) ? 0xC0AC : 0xC08C)
79
80#define SOF_EOP_IRQ_EN 0x0200 /* SOF/EOP Interrupt Enable */
81#define SOF_EOP_TMOUT_IRQ_EN 0x0800 /* SOF/EOP Timeout Interrupt Enable */
82#define ID_IRQ_EN 0x4000 /* ID interrupt enable */
83#define VBUS_IRQ_EN 0x8000 /* VBUS interrupt enable */
84#define DONE_IRQ_EN 0x0001 /* Done Interrupt Enable */
85
86/* USB status register */
87#define HOST_STAT_MASK 0x02FD
88#define PORT_CONNECT_CHANGE(x) ((x) ? 0x0020 : 0x0010)
89#define PORT_SE0_STATUS(x) ((x) ? 0x0008 : 0x0004)
90
91/* Host Frame Register */
92#define HOST_FRAME_REG(x) ((x) ? 0xC0B6 : 0xC096)
93
94#define HOST_FRAME_MASK 0x07FF
95
96/* USB Peripheral only registers */
97/* ============================= */
98
99/* Device n Port Sel reg */
100#define DEVICE_N_PORT_SEL(x) ((x) ? 0xC0A4 : 0xC084)
101
102/* Device n Interrupt Enable Register */
103#define DEVICE_N_IRQ_EN_REG(x) ((x) ? 0xC0AC : 0xC08C)
104
105#define DEVICE_N_ENDPOINT_N_CTL_REG(dev, ep) ((dev) \
106 ? (0x0280 + (ep << 4)) \
107 : (0x0200 + (ep << 4)))
108#define DEVICE_N_ENDPOINT_N_STAT_REG(dev, ep) ((dev) \
109 ? (0x0286 + (ep << 4)) \
110 : (0x0206 + (ep << 4)))
111
112#define DEVICE_N_ADDRESS(dev) ((dev) ? (0xC0AE) : (0xC08E))
113
114/* HPI registers */
115/* ============= */
116
117/* HPI Status register */
118#define SOFEOP_FLG(x) (1 << ((x) ? 12 : 10))
119#define SIEMSG_FLG(x) (1 << (4 + (x)))
120#define RESET_FLG(x) ((x) ? 0x0200 : 0x0002)
121#define DONE_FLG(x) (1 << (2 + (x)))
122#define RESUME_FLG(x) (1 << (6 + (x)))
123#define MBX_OUT_FLG 0x0001 /* Message out available */
124#define MBX_IN_FLG 0x0100
125#define ID_FLG 0x4000
126#define VBUS_FLG 0x8000
127
128/* Interrupt routing register */
129#define HPI_IRQ_ROUTING_REG 0x0142
130
131#define HPI_SWAP_ENABLE(x) ((x) ? 0x0100 : 0x0001)
132#define RESET_TO_HPI_ENABLE(x) ((x) ? 0x0200 : 0x0002)
133#define DONE_TO_HPI_ENABLE(x) ((x) ? 0x0008 : 0x0004)
134#define RESUME_TO_HPI_ENABLE(x) ((x) ? 0x0080 : 0x0040)
135#define SOFEOP_TO_HPI_EN(x) ((x) ? 0x2000 : 0x0800)
136#define SOFEOP_TO_CPU_EN(x) ((x) ? 0x1000 : 0x0400)
137#define ID_TO_HPI_ENABLE 0x4000
138#define VBUS_TO_HPI_ENABLE 0x8000
139
140/* SIE msg registers */
141#define SIEMSG_REG(x) ((x) ? 0x0148 : 0x0144)
142
143#define HUSB_TDListDone 0x1000
144
145#define SUSB_EP0_MSG 0x0001
146#define SUSB_EP1_MSG 0x0002
147#define SUSB_EP2_MSG 0x0004
148#define SUSB_EP3_MSG 0x0008
149#define SUSB_EP4_MSG 0x0010
150#define SUSB_EP5_MSG 0x0020
151#define SUSB_EP6_MSG 0x0040
152#define SUSB_EP7_MSG 0x0080
153#define SUSB_RST_MSG 0x0100
154#define SUSB_SOF_MSG 0x0200
155#define SUSB_CFG_MSG 0x0400
156#define SUSB_SUS_MSG 0x0800
157#define SUSB_ID_MSG 0x4000
158#define SUSB_VBUS_MSG 0x8000
159
160/* BIOS interrupt routines */
161
162#define SUSBx_RECEIVE_INT(x) ((x) ? 97 : 81)
163#define SUSBx_SEND_INT(x) ((x) ? 96 : 80)
164
165#define SUSBx_DEV_DESC_VEC(x) ((x) ? 0x00D4 : 0x00B4)
166#define SUSBx_CONF_DESC_VEC(x) ((x) ? 0x00D6 : 0x00B6)
167#define SUSBx_STRING_DESC_VEC(x) ((x) ? 0x00D8 : 0x00B8)
168
169#define CY_HCD_BUF_ADDR 0x500 /* Base address for host */
170#define SIE_TD_SIZE 0x200 /* size of the td list */
171#define SIE_TD_BUF_SIZE 0x400 /* size of the data buffer */
172
173#define SIE_TD_OFFSET(host) ((host) ? (SIE_TD_SIZE+SIE_TD_BUF_SIZE) : 0)
174#define SIE_BUF_OFFSET(host) (SIE_TD_OFFSET(host) + SIE_TD_SIZE)
175
176/* Base address of HCD + 2 x TD_SIZE + 2 x TD_BUF_SIZE */
177#define CY_UDC_REQ_HEADER_BASE 0x1100
178/* 8- byte request headers for IN/OUT transfers */
179#define CY_UDC_REQ_HEADER_SIZE 8
180
181#define CY_UDC_REQ_HEADER_ADDR(ep_num) (CY_UDC_REQ_HEADER_BASE + \
182 ((ep_num) * CY_UDC_REQ_HEADER_SIZE))
183#define CY_UDC_DESC_BASE_ADDRESS (CY_UDC_REQ_HEADER_ADDR(8))
184
185#define CY_UDC_BIOS_REPLACE_BASE 0x1800
186#define CY_UDC_REQ_BUFFER_BASE 0x2000
187#define CY_UDC_REQ_BUFFER_SIZE 0x0400
188#define CY_UDC_REQ_BUFFER_ADDR(ep_num) (CY_UDC_REQ_BUFFER_BASE + \
189 ((ep_num) * CY_UDC_REQ_BUFFER_SIZE))
190
191/* ---------------------------------------------------------------------
192 * Driver data structures
193 */
194
195struct c67x00_device;
196
197/**
198 * struct c67x00_sie - Common data associated with a SIE
199 * @lock: lock to protect this struct and the associated chip registers
200 * @private_data: subdriver dependent data
201 * @irq: subdriver dependent irq handler, set NULL when not used
202 * @dev: link to common driver structure
203 * @sie_num: SIE number on chip, starting from 0
204 * @mode: SIE mode (host/peripheral/otg/not used)
205 */
206struct c67x00_sie {
207 /* Entries to be used by the subdrivers */
208 spinlock_t lock; /* protect this structure */
209 void *private_data;
210 void (*irq) (struct c67x00_sie *sie, u16 int_status, u16 msg);
211
212 /* Read only: */
213 struct c67x00_device *dev;
214 int sie_num;
215 int mode;
216};
217
218#define sie_dev(s) (&(s)->dev->pdev->dev)
219
220/**
221 * struct c67x00_lcp
222 */
223struct c67x00_lcp {
224 /* Internal use only */
225 struct mutex mutex;
226 struct completion msg_received;
227 u16 last_msg;
228};
229
230/*
231 * struct c67x00_hpi
232 */
233struct c67x00_hpi {
234 void __iomem *base;
235 int regstep;
236 spinlock_t lock;
237 struct c67x00_lcp lcp;
238};
239
240#define C67X00_SIES 2
241#define C67X00_PORTS 2
242
243/**
244 * struct c67x00_device - Common data associated with a c67x00 instance
245 * @hpi: hpi addresses
246 * @sie: array of sie's on this chip
247 * @pdev: platform device of instance
248 * @pdata: configuration provided by the platform
249 */
250struct c67x00_device {
251 struct c67x00_hpi hpi;
252 struct c67x00_sie sie[C67X00_SIES];
253 struct platform_device *pdev;
254 struct c67x00_platform_data *pdata;
255};
256
257/* ---------------------------------------------------------------------
258 * Low level interface functions
259 */
260
261/* Host Port Interface (HPI) functions */
262u16 c67x00_ll_hpi_status(struct c67x00_device *dev);
263void c67x00_ll_hpi_reg_init(struct c67x00_device *dev);
264void c67x00_ll_hpi_enable_sofeop(struct c67x00_sie *sie);
265void c67x00_ll_hpi_disable_sofeop(struct c67x00_sie *sie);
266
267/* General functions */
268u16 c67x00_ll_fetch_siemsg(struct c67x00_device *dev, int sie_num);
269u16 c67x00_ll_get_usb_ctl(struct c67x00_sie *sie);
270void c67x00_ll_usb_clear_status(struct c67x00_sie *sie, u16 bits);
271u16 c67x00_ll_usb_get_status(struct c67x00_sie *sie);
272void c67x00_ll_write_mem_le16(struct c67x00_device *dev, u16 addr,
273 void *data, int len);
274void c67x00_ll_read_mem_le16(struct c67x00_device *dev, u16 addr,
275 void *data, int len);
276
277/* Host specific functions */
278void c67x00_ll_set_husb_eot(struct c67x00_device *dev, u16 value);
279void c67x00_ll_husb_reset(struct c67x00_sie *sie, int port);
280void c67x00_ll_husb_set_current_td(struct c67x00_sie *sie, u16 addr);
281u16 c67x00_ll_husb_get_current_td(struct c67x00_sie *sie);
282u16 c67x00_ll_husb_get_frame(struct c67x00_sie *sie);
283void c67x00_ll_husb_init_host_port(struct c67x00_sie *sie);
284void c67x00_ll_husb_reset_port(struct c67x00_sie *sie, int port);
285
286/* Called by c67x00_irq to handle lcp interrupts */
287void c67x00_ll_irq(struct c67x00_device *dev, u16 int_status);
288
289/* Setup and teardown */
290void c67x00_ll_init(struct c67x00_device *dev);
291void c67x00_ll_release(struct c67x00_device *dev);
292int c67x00_ll_reset(struct c67x00_device *dev);
293
294#endif /* _USB_C67X00_H */
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index e819e5359d57..3e69266e1f4d 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -394,7 +394,9 @@ int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev,
394 if (!io->urbs) 394 if (!io->urbs)
395 goto nomem; 395 goto nomem;
396 396
397 urb_flags = URB_NO_TRANSFER_DMA_MAP | URB_NO_INTERRUPT; 397 urb_flags = URB_NO_INTERRUPT;
398 if (dma)
399 urb_flags |= URB_NO_TRANSFER_DMA_MAP;
398 if (usb_pipein(pipe)) 400 if (usb_pipein(pipe))
399 urb_flags |= URB_SHORT_NOT_OK; 401 urb_flags |= URB_SHORT_NOT_OK;
400 402
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index f7b54651dd42..6e784d2db423 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -231,6 +231,26 @@ config SUPERH_BUILT_IN_M66592
231 However, this problem is improved if change a value of 231 However, this problem is improved if change a value of
232 NET_IP_ALIGN to 4. 232 NET_IP_ALIGN to 4.
233 233
234config USB_GADGET_PXA27X
235 boolean "PXA 27x"
236 depends on ARCH_PXA && PXA27x
237 help
238 Intel's PXA 27x series XScale ARM v5TE processors include
239 an integrated full speed USB 1.1 device controller.
240
241 It has up to 23 endpoints, as well as endpoint zero (for
242 control transfers).
243
244 Say "y" to link the driver statically, or "m" to build a
245 dynamically linked module called "pxa27x_udc" and force all
246 gadget drivers to also be dynamically linked.
247
248config USB_PXA27X
249 tristate
250 depends on USB_GADGET_PXA27X
251 default USB_GADGET
252 select USB_GADGET_SELECTED
253
234config USB_GADGET_GOKU 254config USB_GADGET_GOKU
235 boolean "Toshiba TC86C001 'Goku-S'" 255 boolean "Toshiba TC86C001 'Goku-S'"
236 depends on PCI 256 depends on PCI
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index c3aab80b6c76..12357255d740 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o
9obj-$(CONFIG_USB_NET2280) += net2280.o 9obj-$(CONFIG_USB_NET2280) += net2280.o
10obj-$(CONFIG_USB_AMD5536UDC) += amd5536udc.o 10obj-$(CONFIG_USB_AMD5536UDC) += amd5536udc.o
11obj-$(CONFIG_USB_PXA2XX) += pxa2xx_udc.o 11obj-$(CONFIG_USB_PXA2XX) += pxa2xx_udc.o
12obj-$(CONFIG_USB_PXA27X) += pxa27x_udc.o
12obj-$(CONFIG_USB_GOKU) += goku_udc.o 13obj-$(CONFIG_USB_GOKU) += goku_udc.o
13obj-$(CONFIG_USB_OMAP) += omap_udc.o 14obj-$(CONFIG_USB_OMAP) += omap_udc.o
14obj-$(CONFIG_USB_LH7A40X) += lh7a40x_udc.o 15obj-$(CONFIG_USB_LH7A40X) += lh7a40x_udc.o
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index bb93bdd76593..8d61ea67a817 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -235,10 +235,6 @@ MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
235#define DEV_CONFIG_CDC 235#define DEV_CONFIG_CDC
236#endif 236#endif
237 237
238#ifdef CONFIG_USB_GADGET_PXA27X
239#define DEV_CONFIG_CDC
240#endif
241
242#ifdef CONFIG_USB_GADGET_S3C2410 238#ifdef CONFIG_USB_GADGET_S3C2410
243#define DEV_CONFIG_CDC 239#define DEV_CONFIG_CDC
244#endif 240#endif
@@ -270,6 +266,10 @@ MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
270#define DEV_CONFIG_SUBSET 266#define DEV_CONFIG_SUBSET
271#endif 267#endif
272 268
269#ifdef CONFIG_USB_GADGET_PXA27X
270#define DEV_CONFIG_SUBSET
271#endif
272
273#ifdef CONFIG_USB_GADGET_SUPERH 273#ifdef CONFIG_USB_GADGET_SUPERH
274#define DEV_CONFIG_SUBSET 274#define DEV_CONFIG_SUBSET
275#endif 275#endif
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index bf3f946fd455..47bb9f09a1aa 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -2307,6 +2307,29 @@ static int halt_bulk_in_endpoint(struct fsg_dev *fsg)
2307 return rc; 2307 return rc;
2308} 2308}
2309 2309
2310static int wedge_bulk_in_endpoint(struct fsg_dev *fsg)
2311{
2312 int rc;
2313
2314 DBG(fsg, "bulk-in set wedge\n");
2315 rc = usb_ep_set_wedge(fsg->bulk_in);
2316 if (rc == -EAGAIN)
2317 VDBG(fsg, "delayed bulk-in endpoint wedge\n");
2318 while (rc != 0) {
2319 if (rc != -EAGAIN) {
2320 WARN(fsg, "usb_ep_set_wedge -> %d\n", rc);
2321 rc = 0;
2322 break;
2323 }
2324
2325 /* Wait for a short time and then try again */
2326 if (msleep_interruptible(100) != 0)
2327 return -EINTR;
2328 rc = usb_ep_set_wedge(fsg->bulk_in);
2329 }
2330 return rc;
2331}
2332
2310static int pad_with_zeros(struct fsg_dev *fsg) 2333static int pad_with_zeros(struct fsg_dev *fsg)
2311{ 2334{
2312 struct fsg_buffhd *bh = fsg->next_buffhd_to_fill; 2335 struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
@@ -2957,7 +2980,7 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2957 * We aren't required to halt the OUT endpoint; instead 2980 * We aren't required to halt the OUT endpoint; instead
2958 * we can simply accept and discard any data received 2981 * we can simply accept and discard any data received
2959 * until the next reset. */ 2982 * until the next reset. */
2960 halt_bulk_in_endpoint(fsg); 2983 wedge_bulk_in_endpoint(fsg);
2961 set_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags); 2984 set_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
2962 return -EINVAL; 2985 return -EINVAL;
2963 } 2986 }
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c
new file mode 100644
index 000000000000..75eba202f737
--- /dev/null
+++ b/drivers/usb/gadget/pxa27x_udc.c
@@ -0,0 +1,2404 @@
1/*
2 * Handles the Intel 27x USB Device Controller (UDC)
3 *
4 * Inspired by original driver by Frank Becker, David Brownell, and others.
5 * Copyright (C) 2008 Robert Jarzmik
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/types.h>
25#include <linux/version.h>
26#include <linux/errno.h>
27#include <linux/platform_device.h>
28#include <linux/delay.h>
29#include <linux/list.h>
30#include <linux/interrupt.h>
31#include <linux/proc_fs.h>
32#include <linux/clk.h>
33#include <linux/irq.h>
34
35#include <asm/byteorder.h>
36#include <asm/hardware.h>
37
38#include <linux/usb.h>
39#include <linux/usb/ch9.h>
40#include <linux/usb/gadget.h>
41
42#include <asm/arch/udc.h>
43
44#include "pxa27x_udc.h"
45
46/*
47 * This driver handles the USB Device Controller (UDC) in Intel's PXA 27x
48 * series processors.
49 *
50 * Such controller drivers work with a gadget driver. The gadget driver
51 * returns descriptors, implements configuration and data protocols used
52 * by the host to interact with this device, and allocates endpoints to
53 * the different protocol interfaces. The controller driver virtualizes
54 * usb hardware so that the gadget drivers will be more portable.
55 *
56 * This UDC hardware wants to implement a bit too much USB protocol. The
57 * biggest issues are: that the endpoints have to be set up before the
58 * controller can be enabled (minor, and not uncommon); and each endpoint
59 * can only have one configuration, interface and alternative interface
60 * number (major, and very unusual). Once set up, these cannot be changed
61 * without a controller reset.
62 *
63 * The workaround is to setup all combinations necessary for the gadgets which
64 * will work with this driver. This is done in pxa_udc structure, statically.
65 * See pxa_udc, udc_usb_ep versus pxa_ep, and matching function find_pxa_ep.
66 * (You could modify this if needed. Some drivers have a "fifo_mode" module
67 * parameter to facilitate such changes.)
68 *
69 * The combinations have been tested with these gadgets :
70 * - zero gadget
71 * - file storage gadget
72 * - ether gadget
73 *
74 * The driver doesn't use DMA, only IO access and IRQ callbacks. No use is
75 * made of UDC's double buffering either. USB "On-The-Go" is not implemented.
76 *
77 * All the requests are handled the same way :
78 * - the drivers tries to handle the request directly to the IO
79 * - if the IO fifo is not big enough, the remaining is send/received in
80 * interrupt handling.
81 */
82
83#define DRIVER_VERSION "2008-04-18"
84#define DRIVER_DESC "PXA 27x USB Device Controller driver"
85
86static const char driver_name[] = "pxa27x_udc";
87static struct pxa_udc *the_controller;
88
89static void handle_ep(struct pxa_ep *ep);
90
91/*
92 * Debug filesystem
93 */
94#ifdef CONFIG_USB_GADGET_DEBUG_FS
95
96#include <linux/debugfs.h>
97#include <linux/uaccess.h>
98#include <linux/seq_file.h>
99
100static int state_dbg_show(struct seq_file *s, void *p)
101{
102 struct pxa_udc *udc = s->private;
103 int pos = 0, ret;
104 u32 tmp;
105
106 ret = -ENODEV;
107 if (!udc->driver)
108 goto out;
109
110 /* basic device status */
111 pos += seq_printf(s, DRIVER_DESC "\n"
112 "%s version: %s\nGadget driver: %s\n",
113 driver_name, DRIVER_VERSION,
114 udc->driver ? udc->driver->driver.name : "(none)");
115
116 tmp = udc_readl(udc, UDCCR);
117 pos += seq_printf(s,
118 "udccr=0x%0x(%s%s%s%s%s%s%s%s%s%s), "
119 "con=%d,inter=%d,altinter=%d\n", tmp,
120 (tmp & UDCCR_OEN) ? " oen":"",
121 (tmp & UDCCR_AALTHNP) ? " aalthnp":"",
122 (tmp & UDCCR_AHNP) ? " rem" : "",
123 (tmp & UDCCR_BHNP) ? " rstir" : "",
124 (tmp & UDCCR_DWRE) ? " dwre" : "",
125 (tmp & UDCCR_SMAC) ? " smac" : "",
126 (tmp & UDCCR_EMCE) ? " emce" : "",
127 (tmp & UDCCR_UDR) ? " udr" : "",
128 (tmp & UDCCR_UDA) ? " uda" : "",
129 (tmp & UDCCR_UDE) ? " ude" : "",
130 (tmp & UDCCR_ACN) >> UDCCR_ACN_S,
131 (tmp & UDCCR_AIN) >> UDCCR_AIN_S,
132 (tmp & UDCCR_AAISN) >> UDCCR_AAISN_S);
133 /* registers for device and ep0 */
134 pos += seq_printf(s, "udcicr0=0x%08x udcicr1=0x%08x\n",
135 udc_readl(udc, UDCICR0), udc_readl(udc, UDCICR1));
136 pos += seq_printf(s, "udcisr0=0x%08x udcisr1=0x%08x\n",
137 udc_readl(udc, UDCISR0), udc_readl(udc, UDCISR1));
138 pos += seq_printf(s, "udcfnr=%d\n", udc_readl(udc, UDCFNR));
139 pos += seq_printf(s, "irqs: reset=%lu, suspend=%lu, resume=%lu, "
140 "reconfig=%lu\n",
141 udc->stats.irqs_reset, udc->stats.irqs_suspend,
142 udc->stats.irqs_resume, udc->stats.irqs_reconfig);
143
144 ret = 0;
145out:
146 return ret;
147}
148
149static int queues_dbg_show(struct seq_file *s, void *p)
150{
151 struct pxa_udc *udc = s->private;
152 struct pxa_ep *ep;
153 struct pxa27x_request *req;
154 int pos = 0, i, maxpkt, ret;
155
156 ret = -ENODEV;
157 if (!udc->driver)
158 goto out;
159
160 /* dump endpoint queues */
161 for (i = 0; i < NR_PXA_ENDPOINTS; i++) {
162 ep = &udc->pxa_ep[i];
163 maxpkt = ep->fifo_size;
164 pos += seq_printf(s, "%-12s max_pkt=%d %s\n",
165 EPNAME(ep), maxpkt, "pio");
166
167 if (list_empty(&ep->queue)) {
168 pos += seq_printf(s, "\t(nothing queued)\n");
169 continue;
170 }
171
172 list_for_each_entry(req, &ep->queue, queue) {
173 pos += seq_printf(s, "\treq %p len %d/%d buf %p\n",
174 &req->req, req->req.actual,
175 req->req.length, req->req.buf);
176 }
177 }
178
179 ret = 0;
180out:
181 return ret;
182}
183
184static int eps_dbg_show(struct seq_file *s, void *p)
185{
186 struct pxa_udc *udc = s->private;
187 struct pxa_ep *ep;
188 int pos = 0, i, ret;
189 u32 tmp;
190
191 ret = -ENODEV;
192 if (!udc->driver)
193 goto out;
194
195 ep = &udc->pxa_ep[0];
196 tmp = udc_ep_readl(ep, UDCCSR);
197 pos += seq_printf(s, "udccsr0=0x%03x(%s%s%s%s%s%s%s)\n", tmp,
198 (tmp & UDCCSR0_SA) ? " sa" : "",
199 (tmp & UDCCSR0_RNE) ? " rne" : "",
200 (tmp & UDCCSR0_FST) ? " fst" : "",
201 (tmp & UDCCSR0_SST) ? " sst" : "",
202 (tmp & UDCCSR0_DME) ? " dme" : "",
203 (tmp & UDCCSR0_IPR) ? " ipr" : "",
204 (tmp & UDCCSR0_OPC) ? " opc" : "");
205 for (i = 0; i < NR_PXA_ENDPOINTS; i++) {
206 ep = &udc->pxa_ep[i];
207 tmp = i? udc_ep_readl(ep, UDCCR) : udc_readl(udc, UDCCR);
208 pos += seq_printf(s, "%-12s: "
209 "IN %lu(%lu reqs), OUT %lu(%lu reqs), "
210 "irqs=%lu, udccr=0x%08x, udccsr=0x%03x, "
211 "udcbcr=%d\n",
212 EPNAME(ep),
213 ep->stats.in_bytes, ep->stats.in_ops,
214 ep->stats.out_bytes, ep->stats.out_ops,
215 ep->stats.irqs,
216 tmp, udc_ep_readl(ep, UDCCSR),
217 udc_ep_readl(ep, UDCBCR));
218 }
219
220 ret = 0;
221out:
222 return ret;
223}
224
225static int eps_dbg_open(struct inode *inode, struct file *file)
226{
227 return single_open(file, eps_dbg_show, inode->i_private);
228}
229
230static int queues_dbg_open(struct inode *inode, struct file *file)
231{
232 return single_open(file, queues_dbg_show, inode->i_private);
233}
234
235static int state_dbg_open(struct inode *inode, struct file *file)
236{
237 return single_open(file, state_dbg_show, inode->i_private);
238}
239
240static const struct file_operations state_dbg_fops = {
241 .owner = THIS_MODULE,
242 .open = state_dbg_open,
243 .llseek = seq_lseek,
244 .read = seq_read,
245 .release = single_release,
246};
247
248static const struct file_operations queues_dbg_fops = {
249 .owner = THIS_MODULE,
250 .open = queues_dbg_open,
251 .llseek = seq_lseek,
252 .read = seq_read,
253 .release = single_release,
254};
255
256static const struct file_operations eps_dbg_fops = {
257 .owner = THIS_MODULE,
258 .open = eps_dbg_open,
259 .llseek = seq_lseek,
260 .read = seq_read,
261 .release = single_release,
262};
263
264static void pxa_init_debugfs(struct pxa_udc *udc)
265{
266 struct dentry *root, *state, *queues, *eps;
267
268 root = debugfs_create_dir(udc->gadget.name, NULL);
269 if (IS_ERR(root) || !root)
270 goto err_root;
271
272 state = debugfs_create_file("udcstate", 0400, root, udc,
273 &state_dbg_fops);
274 if (!state)
275 goto err_state;
276 queues = debugfs_create_file("queues", 0400, root, udc,
277 &queues_dbg_fops);
278 if (!queues)
279 goto err_queues;
280 eps = debugfs_create_file("epstate", 0400, root, udc,
281 &eps_dbg_fops);
282 if (!queues)
283 goto err_eps;
284
285 udc->debugfs_root = root;
286 udc->debugfs_state = state;
287 udc->debugfs_queues = queues;
288 udc->debugfs_eps = eps;
289 return;
290err_eps:
291 debugfs_remove(eps);
292err_queues:
293 debugfs_remove(queues);
294err_state:
295 debugfs_remove(root);
296err_root:
297 dev_err(udc->dev, "debugfs is not available\n");
298}
299
300static void pxa_cleanup_debugfs(struct pxa_udc *udc)
301{
302 debugfs_remove(udc->debugfs_eps);
303 debugfs_remove(udc->debugfs_queues);
304 debugfs_remove(udc->debugfs_state);
305 debugfs_remove(udc->debugfs_root);
306 udc->debugfs_eps = NULL;
307 udc->debugfs_queues = NULL;
308 udc->debugfs_state = NULL;
309 udc->debugfs_root = NULL;
310}
311
312#else
313static inline void pxa_init_debugfs(struct pxa_udc *udc)
314{
315}
316
317static inline void pxa_cleanup_debugfs(struct pxa_udc *udc)
318{
319}
320#endif
321
322/**
323 * is_match_usb_pxa - check if usb_ep and pxa_ep match
324 * @udc_usb_ep: usb endpoint
325 * @ep: pxa endpoint
326 * @config: configuration required in pxa_ep
327 * @interface: interface required in pxa_ep
328 * @altsetting: altsetting required in pxa_ep
329 *
330 * Returns 1 if all criteria match between pxa and usb endpoint, 0 otherwise
331 */
332static int is_match_usb_pxa(struct udc_usb_ep *udc_usb_ep, struct pxa_ep *ep,
333 int config, int interface, int altsetting)
334{
335 if (usb_endpoint_num(&udc_usb_ep->desc) != ep->addr)
336 return 0;
337 if (usb_endpoint_dir_in(&udc_usb_ep->desc) != ep->dir_in)
338 return 0;
339 if (usb_endpoint_type(&udc_usb_ep->desc) != ep->type)
340 return 0;
341 if ((ep->config != config) || (ep->interface != interface)
342 || (ep->alternate != altsetting))
343 return 0;
344 return 1;
345}
346
347/**
348 * find_pxa_ep - find pxa_ep structure matching udc_usb_ep
349 * @udc: pxa udc
350 * @udc_usb_ep: udc_usb_ep structure
351 *
352 * Match udc_usb_ep and all pxa_ep available, to see if one matches.
353 * This is necessary because of the strong pxa hardware restriction requiring
354 * that once pxa endpoints are initialized, their configuration is freezed, and
355 * no change can be made to their address, direction, or in which configuration,
356 * interface or altsetting they are active ... which differs from more usual
357 * models which have endpoints be roughly just addressable fifos, and leave
358 * configuration events up to gadget drivers (like all control messages).
359 *
360 * Note that there is still a blurred point here :
361 * - we rely on UDCCR register "active interface" and "active altsetting".
362 * This is a nonsense in regard of USB spec, where multiple interfaces are
363 * active at the same time.
364 * - if we knew for sure that the pxa can handle multiple interface at the
365 * same time, assuming Intel's Developer Guide is wrong, this function
366 * should be reviewed, and a cache of couples (iface, altsetting) should
367 * be kept in the pxa_udc structure. In this case this function would match
368 * against the cache of couples instead of the "last altsetting" set up.
369 *
370 * Returns the matched pxa_ep structure or NULL if none found
371 */
372static struct pxa_ep *find_pxa_ep(struct pxa_udc *udc,
373 struct udc_usb_ep *udc_usb_ep)
374{
375 int i;
376 struct pxa_ep *ep;
377 int cfg = udc->config;
378 int iface = udc->last_interface;
379 int alt = udc->last_alternate;
380
381 if (udc_usb_ep == &udc->udc_usb_ep[0])
382 return &udc->pxa_ep[0];
383
384 for (i = 1; i < NR_PXA_ENDPOINTS; i++) {
385 ep = &udc->pxa_ep[i];
386 if (is_match_usb_pxa(udc_usb_ep, ep, cfg, iface, alt))
387 return ep;
388 }
389 return NULL;
390}
391
392/**
393 * update_pxa_ep_matches - update pxa_ep cached values in all udc_usb_ep
394 * @udc: pxa udc
395 *
396 * Context: in_interrupt()
397 *
398 * Updates all pxa_ep fields in udc_usb_ep structures, if this field was
399 * previously set up (and is not NULL). The update is necessary is a
400 * configuration change or altsetting change was issued by the USB host.
401 */
402static void update_pxa_ep_matches(struct pxa_udc *udc)
403{
404 int i;
405 struct udc_usb_ep *udc_usb_ep;
406
407 for (i = 1; i < NR_USB_ENDPOINTS; i++) {
408 udc_usb_ep = &udc->udc_usb_ep[i];
409 if (udc_usb_ep->pxa_ep)
410 udc_usb_ep->pxa_ep = find_pxa_ep(udc, udc_usb_ep);
411 }
412}
413
414/**
415 * pio_irq_enable - Enables irq generation for one endpoint
416 * @ep: udc endpoint
417 */
418static void pio_irq_enable(struct pxa_ep *ep)
419{
420 struct pxa_udc *udc = ep->dev;
421 int index = EPIDX(ep);
422 u32 udcicr0 = udc_readl(udc, UDCICR0);
423 u32 udcicr1 = udc_readl(udc, UDCICR1);
424
425 if (index < 16)
426 udc_writel(udc, UDCICR0, udcicr0 | (3 << (index * 2)));
427 else
428 udc_writel(udc, UDCICR1, udcicr1 | (3 << ((index - 16) * 2)));
429}
430
431/**
432 * pio_irq_disable - Disables irq generation for one endpoint
433 * @ep: udc endpoint
434 * @index: endpoint number
435 */
436static void pio_irq_disable(struct pxa_ep *ep)
437{
438 struct pxa_udc *udc = ep->dev;
439 int index = EPIDX(ep);
440 u32 udcicr0 = udc_readl(udc, UDCICR0);
441 u32 udcicr1 = udc_readl(udc, UDCICR1);
442
443 if (index < 16)
444 udc_writel(udc, UDCICR0, udcicr0 & ~(3 << (index * 2)));
445 else
446 udc_writel(udc, UDCICR1, udcicr1 & ~(3 << ((index - 16) * 2)));
447}
448
449/**
450 * udc_set_mask_UDCCR - set bits in UDCCR
451 * @udc: udc device
452 * @mask: bits to set in UDCCR
453 *
454 * Sets bits in UDCCR, leaving DME and FST bits as they were.
455 */
456static inline void udc_set_mask_UDCCR(struct pxa_udc *udc, int mask)
457{
458 u32 udccr = udc_readl(udc, UDCCR);
459 udc_writel(udc, UDCCR,
460 (udccr & UDCCR_MASK_BITS) | (mask & UDCCR_MASK_BITS));
461}
462
463/**
464 * udc_clear_mask_UDCCR - clears bits in UDCCR
465 * @udc: udc device
466 * @mask: bit to clear in UDCCR
467 *
468 * Clears bits in UDCCR, leaving DME and FST bits as they were.
469 */
470static inline void udc_clear_mask_UDCCR(struct pxa_udc *udc, int mask)
471{
472 u32 udccr = udc_readl(udc, UDCCR);
473 udc_writel(udc, UDCCR,
474 (udccr & UDCCR_MASK_BITS) & ~(mask & UDCCR_MASK_BITS));
475}
476
477/**
478 * ep_count_bytes_remain - get how many bytes in udc endpoint
479 * @ep: udc endpoint
480 *
481 * Returns number of bytes in OUT fifos. Broken for IN fifos (-EOPNOTSUPP)
482 */
483static int ep_count_bytes_remain(struct pxa_ep *ep)
484{
485 if (ep->dir_in)
486 return -EOPNOTSUPP;
487 return udc_ep_readl(ep, UDCBCR) & 0x3ff;
488}
489
490/**
491 * ep_is_empty - checks if ep has byte ready for reading
492 * @ep: udc endpoint
493 *
494 * If endpoint is the control endpoint, checks if there are bytes in the
495 * control endpoint fifo. If endpoint is a data endpoint, checks if bytes
496 * are ready for reading on OUT endpoint.
497 *
498 * Returns 0 if ep not empty, 1 if ep empty, -EOPNOTSUPP if IN endpoint
499 */
500static int ep_is_empty(struct pxa_ep *ep)
501{
502 int ret;
503
504 if (!is_ep0(ep) && ep->dir_in)
505 return -EOPNOTSUPP;
506 if (is_ep0(ep))
507 ret = !(udc_ep_readl(ep, UDCCSR) & UDCCSR0_RNE);
508 else
509 ret = !(udc_ep_readl(ep, UDCCSR) & UDCCSR_BNE);
510 return ret;
511}
512
513/**
514 * ep_is_full - checks if ep has place to write bytes
515 * @ep: udc endpoint
516 *
517 * If endpoint is not the control endpoint and is an IN endpoint, checks if
518 * there is place to write bytes into the endpoint.
519 *
520 * Returns 0 if ep not full, 1 if ep full, -EOPNOTSUPP if OUT endpoint
521 */
522static int ep_is_full(struct pxa_ep *ep)
523{
524 if (is_ep0(ep))
525 return (udc_ep_readl(ep, UDCCSR) & UDCCSR0_IPR);
526 if (!ep->dir_in)
527 return -EOPNOTSUPP;
528 return (!(udc_ep_readl(ep, UDCCSR) & UDCCSR_BNF));
529}
530
531/**
532 * epout_has_pkt - checks if OUT endpoint fifo has a packet available
533 * @ep: pxa endpoint
534 *
535 * Returns 1 if a complete packet is available, 0 if not, -EOPNOTSUPP for IN ep.
536 */
537static int epout_has_pkt(struct pxa_ep *ep)
538{
539 if (!is_ep0(ep) && ep->dir_in)
540 return -EOPNOTSUPP;
541 if (is_ep0(ep))
542 return (udc_ep_readl(ep, UDCCSR) & UDCCSR0_OPC);
543 return (udc_ep_readl(ep, UDCCSR) & UDCCSR_PC);
544}
545
546/**
547 * set_ep0state - Set ep0 automata state
548 * @dev: udc device
549 * @state: state
550 */
551static void set_ep0state(struct pxa_udc *udc, int state)
552{
553 struct pxa_ep *ep = &udc->pxa_ep[0];
554 char *old_stname = EP0_STNAME(udc);
555
556 udc->ep0state = state;
557 ep_dbg(ep, "state=%s->%s, udccsr0=0x%03x, udcbcr=%d\n", old_stname,
558 EP0_STNAME(udc), udc_ep_readl(ep, UDCCSR),
559 udc_ep_readl(ep, UDCBCR));
560}
561
562/**
563 * ep0_idle - Put control endpoint into idle state
564 * @dev: udc device
565 */
566static void ep0_idle(struct pxa_udc *dev)
567{
568 set_ep0state(dev, WAIT_FOR_SETUP);
569}
570
571/**
572 * inc_ep_stats_reqs - Update ep stats counts
573 * @ep: physical endpoint
574 * @req: usb request
575 * @is_in: ep direction (USB_DIR_IN or 0)
576 *
577 */
578static void inc_ep_stats_reqs(struct pxa_ep *ep, int is_in)
579{
580 if (is_in)
581 ep->stats.in_ops++;
582 else
583 ep->stats.out_ops++;
584}
585
586/**
587 * inc_ep_stats_bytes - Update ep stats counts
588 * @ep: physical endpoint
589 * @count: bytes transfered on endpoint
590 * @req: usb request
591 * @is_in: ep direction (USB_DIR_IN or 0)
592 */
593static void inc_ep_stats_bytes(struct pxa_ep *ep, int count, int is_in)
594{
595 if (is_in)
596 ep->stats.in_bytes += count;
597 else
598 ep->stats.out_bytes += count;
599}
600
601/**
602 * pxa_ep_setup - Sets up an usb physical endpoint
603 * @ep: pxa27x physical endpoint
604 *
605 * Find the physical pxa27x ep, and setup its UDCCR
606 */
607static __init void pxa_ep_setup(struct pxa_ep *ep)
608{
609 u32 new_udccr;
610
611 new_udccr = ((ep->config << UDCCONR_CN_S) & UDCCONR_CN)
612 | ((ep->interface << UDCCONR_IN_S) & UDCCONR_IN)
613 | ((ep->alternate << UDCCONR_AISN_S) & UDCCONR_AISN)
614 | ((EPADDR(ep) << UDCCONR_EN_S) & UDCCONR_EN)
615 | ((EPXFERTYPE(ep) << UDCCONR_ET_S) & UDCCONR_ET)
616 | ((ep->dir_in) ? UDCCONR_ED : 0)
617 | ((ep->fifo_size << UDCCONR_MPS_S) & UDCCONR_MPS)
618 | UDCCONR_EE;
619
620 udc_ep_writel(ep, UDCCR, new_udccr);
621}
622
623/**
624 * pxa_eps_setup - Sets up all usb physical endpoints
625 * @dev: udc device
626 *
627 * Setup all pxa physical endpoints, except ep0
628 */
629static __init void pxa_eps_setup(struct pxa_udc *dev)
630{
631 unsigned int i;
632
633 dev_dbg(dev->dev, "%s: dev=%p\n", __func__, dev);
634
635 for (i = 1; i < NR_PXA_ENDPOINTS; i++)
636 pxa_ep_setup(&dev->pxa_ep[i]);
637}
638
639/**
640 * pxa_ep_alloc_request - Allocate usb request
641 * @_ep: usb endpoint
642 * @gfp_flags:
643 *
644 * For the pxa27x, these can just wrap kmalloc/kfree. gadget drivers
645 * must still pass correctly initialized endpoints, since other controller
646 * drivers may care about how it's currently set up (dma issues etc).
647 */
648static struct usb_request *
649pxa_ep_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
650{
651 struct pxa27x_request *req;
652
653 req = kzalloc(sizeof *req, gfp_flags);
654 if (!req || !_ep)
655 return NULL;
656
657 INIT_LIST_HEAD(&req->queue);
658 req->in_use = 0;
659 req->udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
660
661 return &req->req;
662}
663
664/**
665 * pxa_ep_free_request - Free usb request
666 * @_ep: usb endpoint
667 * @_req: usb request
668 *
669 * Wrapper around kfree to free _req
670 */
671static void pxa_ep_free_request(struct usb_ep *_ep, struct usb_request *_req)
672{
673 struct pxa27x_request *req;
674
675 req = container_of(_req, struct pxa27x_request, req);
676 WARN_ON(!list_empty(&req->queue));
677 kfree(req);
678}
679
680/**
681 * ep_add_request - add a request to the endpoint's queue
682 * @ep: usb endpoint
683 * @req: usb request
684 *
685 * Context: ep->lock held
686 *
687 * Queues the request in the endpoint's queue, and enables the interrupts
688 * on the endpoint.
689 */
690static void ep_add_request(struct pxa_ep *ep, struct pxa27x_request *req)
691{
692 if (unlikely(!req))
693 return;
694 ep_vdbg(ep, "req:%p, lg=%d, udccsr=0x%03x\n", req,
695 req->req.length, udc_ep_readl(ep, UDCCSR));
696
697 req->in_use = 1;
698 list_add_tail(&req->queue, &ep->queue);
699 pio_irq_enable(ep);
700}
701
702/**
703 * ep_del_request - removes a request from the endpoint's queue
704 * @ep: usb endpoint
705 * @req: usb request
706 *
707 * Context: ep->lock held
708 *
709 * Unqueue the request from the endpoint's queue. If there are no more requests
710 * on the endpoint, and if it's not the control endpoint, interrupts are
711 * disabled on the endpoint.
712 */
713static void ep_del_request(struct pxa_ep *ep, struct pxa27x_request *req)
714{
715 if (unlikely(!req))
716 return;
717 ep_vdbg(ep, "req:%p, lg=%d, udccsr=0x%03x\n", req,
718 req->req.length, udc_ep_readl(ep, UDCCSR));
719
720 list_del_init(&req->queue);
721 req->in_use = 0;
722 if (!is_ep0(ep) && list_empty(&ep->queue))
723 pio_irq_disable(ep);
724}
725
726/**
727 * req_done - Complete an usb request
728 * @ep: pxa physical endpoint
729 * @req: pxa request
730 * @status: usb request status sent to gadget API
731 *
732 * Context: ep->lock held
733 *
734 * Retire a pxa27x usb request. Endpoint must be locked.
735 */
736static void req_done(struct pxa_ep *ep, struct pxa27x_request *req, int status)
737{
738 ep_del_request(ep, req);
739 if (likely(req->req.status == -EINPROGRESS))
740 req->req.status = status;
741 else
742 status = req->req.status;
743
744 if (status && status != -ESHUTDOWN)
745 ep_dbg(ep, "complete req %p stat %d len %u/%u\n",
746 &req->req, status,
747 req->req.actual, req->req.length);
748
749 req->req.complete(&req->udc_usb_ep->usb_ep, &req->req);
750}
751
752/**
753 * ep_end_out_req - Ends control endpoint in request
754 * @ep: physical endpoint
755 * @req: pxa request
756 *
757 * Context: ep->lock held
758 *
759 * Ends endpoint in request (completes usb request).
760 */
761static void ep_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req)
762{
763 inc_ep_stats_reqs(ep, !USB_DIR_IN);
764 req_done(ep, req, 0);
765}
766
767/**
768 * ep0_end_out_req - Ends control endpoint in request (ends data stage)
769 * @ep: physical endpoint
770 * @req: pxa request
771 *
772 * Context: ep->lock held
773 *
774 * Ends control endpoint in request (completes usb request), and puts
775 * control endpoint into idle state
776 */
777static void ep0_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req)
778{
779 set_ep0state(ep->dev, OUT_STATUS_STAGE);
780 ep_end_out_req(ep, req);
781 ep0_idle(ep->dev);
782}
783
784/**
785 * ep_end_in_req - Ends endpoint out request
786 * @ep: physical endpoint
787 * @req: pxa request
788 *
789 * Context: ep->lock held
790 *
791 * Ends endpoint out request (completes usb request).
792 */
793static void ep_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req)
794{
795 inc_ep_stats_reqs(ep, USB_DIR_IN);
796 req_done(ep, req, 0);
797}
798
799/**
800 * ep0_end_in_req - Ends control endpoint out request (ends data stage)
801 * @ep: physical endpoint
802 * @req: pxa request
803 *
804 * Context: ep->lock held
805 *
806 * Ends control endpoint out request (completes usb request), and puts
807 * control endpoint into status state
808 */
809static void ep0_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req)
810{
811 struct pxa_udc *udc = ep->dev;
812
813 set_ep0state(udc, IN_STATUS_STAGE);
814 ep_end_in_req(ep, req);
815}
816
817/**
818 * nuke - Dequeue all requests
819 * @ep: pxa endpoint
820 * @status: usb request status
821 *
822 * Context: ep->lock held
823 *
824 * Dequeues all requests on an endpoint. As a side effect, interrupts will be
825 * disabled on that endpoint (because no more requests).
826 */
827static void nuke(struct pxa_ep *ep, int status)
828{
829 struct pxa27x_request *req;
830
831 while (!list_empty(&ep->queue)) {
832 req = list_entry(ep->queue.next, struct pxa27x_request, queue);
833 req_done(ep, req, status);
834 }
835}
836
837/**
838 * read_packet - transfer 1 packet from an OUT endpoint into request
839 * @ep: pxa physical endpoint
840 * @req: usb request
841 *
842 * Takes bytes from OUT endpoint and transfers them info the usb request.
843 * If there is less space in request than bytes received in OUT endpoint,
844 * bytes are left in the OUT endpoint.
845 *
846 * Returns how many bytes were actually transfered
847 */
848static int read_packet(struct pxa_ep *ep, struct pxa27x_request *req)
849{
850 u32 *buf;
851 int bytes_ep, bufferspace, count, i;
852
853 bytes_ep = ep_count_bytes_remain(ep);
854 bufferspace = req->req.length - req->req.actual;
855
856 buf = (u32 *)(req->req.buf + req->req.actual);
857 prefetchw(buf);
858
859 if (likely(!ep_is_empty(ep)))
860 count = min(bytes_ep, bufferspace);
861 else /* zlp */
862 count = 0;
863
864 for (i = count; i > 0; i -= 4)
865 *buf++ = udc_ep_readl(ep, UDCDR);
866 req->req.actual += count;
867
868 udc_ep_writel(ep, UDCCSR, UDCCSR_PC);
869
870 return count;
871}
872
873/**
874 * write_packet - transfer 1 packet from request into an IN endpoint
875 * @ep: pxa physical endpoint
876 * @req: usb request
877 * @max: max bytes that fit into endpoint
878 *
879 * Takes bytes from usb request, and transfers them into the physical
880 * endpoint. If there are no bytes to transfer, doesn't write anything
881 * to physical endpoint.
882 *
883 * Returns how many bytes were actually transfered.
884 */
885static int write_packet(struct pxa_ep *ep, struct pxa27x_request *req,
886 unsigned int max)
887{
888 int length, count, remain, i;
889 u32 *buf;
890 u8 *buf_8;
891
892 buf = (u32 *)(req->req.buf + req->req.actual);
893 prefetch(buf);
894
895 length = min(req->req.length - req->req.actual, max);
896 req->req.actual += length;
897
898 remain = length & 0x3;
899 count = length & ~(0x3);
900 for (i = count; i > 0 ; i -= 4)
901 udc_ep_writel(ep, UDCDR, *buf++);
902
903 buf_8 = (u8 *)buf;
904 for (i = remain; i > 0; i--)
905 udc_ep_writeb(ep, UDCDR, *buf_8++);
906
907 ep_vdbg(ep, "length=%d+%d, udccsr=0x%03x\n", count, remain,
908 udc_ep_readl(ep, UDCCSR));
909
910 return length;
911}
912
913/**
914 * read_fifo - Transfer packets from OUT endpoint into usb request
915 * @ep: pxa physical endpoint
916 * @req: usb request
917 *
918 * Context: callable when in_interrupt()
919 *
920 * Unload as many packets as possible from the fifo we use for usb OUT
921 * transfers and put them into the request. Caller should have made sure
922 * there's at least one packet ready.
923 * Doesn't complete the request, that's the caller's job
924 *
925 * Returns 1 if the request completed, 0 otherwise
926 */
927static int read_fifo(struct pxa_ep *ep, struct pxa27x_request *req)
928{
929 int count, is_short, completed = 0;
930
931 while (epout_has_pkt(ep)) {
932 count = read_packet(ep, req);
933 inc_ep_stats_bytes(ep, count, !USB_DIR_IN);
934
935 is_short = (count < ep->fifo_size);
936 ep_dbg(ep, "read udccsr:%03x, count:%d bytes%s req %p %d/%d\n",
937 udc_ep_readl(ep, UDCCSR), count, is_short ? "/S" : "",
938 &req->req, req->req.actual, req->req.length);
939
940 /* completion */
941 if (is_short || req->req.actual == req->req.length) {
942 completed = 1;
943 break;
944 }
945 /* finished that packet. the next one may be waiting... */
946 }
947 return completed;
948}
949
950/**
951 * write_fifo - transfer packets from usb request into an IN endpoint
952 * @ep: pxa physical endpoint
953 * @req: pxa usb request
954 *
955 * Write to an IN endpoint fifo, as many packets as possible.
956 * irqs will use this to write the rest later.
957 * caller guarantees at least one packet buffer is ready (or a zlp).
958 * Doesn't complete the request, that's the caller's job
959 *
960 * Returns 1 if request fully transfered, 0 if partial transfer
961 */
962static int write_fifo(struct pxa_ep *ep, struct pxa27x_request *req)
963{
964 unsigned max;
965 int count, is_short, is_last = 0, completed = 0, totcount = 0;
966 u32 udccsr;
967
968 max = ep->fifo_size;
969 do {
970 is_short = 0;
971
972 udccsr = udc_ep_readl(ep, UDCCSR);
973 if (udccsr & UDCCSR_PC) {
974 ep_vdbg(ep, "Clearing Transmit Complete, udccsr=%x\n",
975 udccsr);
976 udc_ep_writel(ep, UDCCSR, UDCCSR_PC);
977 }
978 if (udccsr & UDCCSR_TRN) {
979 ep_vdbg(ep, "Clearing Underrun on, udccsr=%x\n",
980 udccsr);
981 udc_ep_writel(ep, UDCCSR, UDCCSR_TRN);
982 }
983
984 count = write_packet(ep, req, max);
985 inc_ep_stats_bytes(ep, count, USB_DIR_IN);
986 totcount += count;
987
988 /* last packet is usually short (or a zlp) */
989 if (unlikely(count < max)) {
990 is_last = 1;
991 is_short = 1;
992 } else {
993 if (likely(req->req.length > req->req.actual)
994 || req->req.zero)
995 is_last = 0;
996 else
997 is_last = 1;
998 /* interrupt/iso maxpacket may not fill the fifo */
999 is_short = unlikely(max < ep->fifo_size);
1000 }
1001
1002 if (is_short)
1003 udc_ep_writel(ep, UDCCSR, UDCCSR_SP);
1004
1005 /* requests complete when all IN data is in the FIFO */
1006 if (is_last) {
1007 completed = 1;
1008 break;
1009 }
1010 } while (!ep_is_full(ep));
1011
1012 ep_dbg(ep, "wrote count:%d bytes%s%s, left:%d req=%p\n",
1013 totcount, is_last ? "/L" : "", is_short ? "/S" : "",
1014 req->req.length - req->req.actual, &req->req);
1015
1016 return completed;
1017}
1018
1019/**
1020 * read_ep0_fifo - Transfer packets from control endpoint into usb request
1021 * @ep: control endpoint
1022 * @req: pxa usb request
1023 *
1024 * Special ep0 version of the above read_fifo. Reads as many bytes from control
1025 * endpoint as can be read, and stores them into usb request (limited by request
1026 * maximum length).
1027 *
1028 * Returns 0 if usb request only partially filled, 1 if fully filled
1029 */
1030static int read_ep0_fifo(struct pxa_ep *ep, struct pxa27x_request *req)
1031{
1032 int count, is_short, completed = 0;
1033
1034 while (epout_has_pkt(ep)) {
1035 count = read_packet(ep, req);
1036 udc_ep_writel(ep, UDCCSR, UDCCSR0_OPC);
1037 inc_ep_stats_bytes(ep, count, !USB_DIR_IN);
1038
1039 is_short = (count < ep->fifo_size);
1040 ep_dbg(ep, "read udccsr:%03x, count:%d bytes%s req %p %d/%d\n",
1041 udc_ep_readl(ep, UDCCSR), count, is_short ? "/S" : "",
1042 &req->req, req->req.actual, req->req.length);
1043
1044 if (is_short || req->req.actual >= req->req.length) {
1045 completed = 1;
1046 break;
1047 }
1048 }
1049
1050 return completed;
1051}
1052
1053/**
1054 * write_ep0_fifo - Send a request to control endpoint (ep0 in)
1055 * @ep: control endpoint
1056 * @req: request
1057 *
1058 * Context: callable when in_interrupt()
1059 *
1060 * Sends a request (or a part of the request) to the control endpoint (ep0 in).
1061 * If the request doesn't fit, the remaining part will be sent from irq.
1062 * The request is considered fully written only if either :
1063 * - last write transfered all remaining bytes, but fifo was not fully filled
1064 * - last write was a 0 length write
1065 *
1066 * Returns 1 if request fully written, 0 if request only partially sent
1067 */
1068static int write_ep0_fifo(struct pxa_ep *ep, struct pxa27x_request *req)
1069{
1070 unsigned count;
1071 int is_last, is_short;
1072
1073 count = write_packet(ep, req, EP0_FIFO_SIZE);
1074 inc_ep_stats_bytes(ep, count, USB_DIR_IN);
1075
1076 is_short = (count < EP0_FIFO_SIZE);
1077 is_last = ((count == 0) || (count < EP0_FIFO_SIZE));
1078
1079 /* Sends either a short packet or a 0 length packet */
1080 if (unlikely(is_short))
1081 udc_ep_writel(ep, UDCCSR, UDCCSR0_IPR);
1082
1083 ep_dbg(ep, "in %d bytes%s%s, %d left, req=%p, udccsr0=0x%03x\n",
1084 count, is_short ? "/S" : "", is_last ? "/L" : "",
1085 req->req.length - req->req.actual,
1086 &req->req, udc_ep_readl(ep, UDCCSR));
1087
1088 return is_last;
1089}
1090
1091/**
1092 * pxa_ep_queue - Queue a request into an IN endpoint
1093 * @_ep: usb endpoint
1094 * @_req: usb request
1095 * @gfp_flags: flags
1096 *
1097 * Context: normally called when !in_interrupt, but callable when in_interrupt()
1098 * in the special case of ep0 setup :
1099 * (irq->handle_ep0_ctrl_req->gadget_setup->pxa_ep_queue)
1100 *
1101 * Returns 0 if succedeed, error otherwise
1102 */
1103static int pxa_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
1104 gfp_t gfp_flags)
1105{
1106 struct udc_usb_ep *udc_usb_ep;
1107 struct pxa_ep *ep;
1108 struct pxa27x_request *req;
1109 struct pxa_udc *dev;
1110 unsigned long flags;
1111 int rc = 0;
1112 int is_first_req;
1113 unsigned length;
1114
1115 req = container_of(_req, struct pxa27x_request, req);
1116 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
1117
1118 if (unlikely(!_req || !_req->complete || !_req->buf))
1119 return -EINVAL;
1120
1121 if (unlikely(!_ep))
1122 return -EINVAL;
1123
1124 dev = udc_usb_ep->dev;
1125 ep = udc_usb_ep->pxa_ep;
1126 if (unlikely(!ep))
1127 return -EINVAL;
1128
1129 dev = ep->dev;
1130 if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) {
1131 ep_dbg(ep, "bogus device state\n");
1132 return -ESHUTDOWN;
1133 }
1134
1135 /* iso is always one packet per request, that's the only way
1136 * we can report per-packet status. that also helps with dma.
1137 */
1138 if (unlikely(EPXFERTYPE_is_ISO(ep)
1139 && req->req.length > ep->fifo_size))
1140 return -EMSGSIZE;
1141
1142 spin_lock_irqsave(&ep->lock, flags);
1143
1144 is_first_req = list_empty(&ep->queue);
1145 ep_dbg(ep, "queue req %p(first=%s), len %d buf %p\n",
1146 _req, is_first_req ? "yes" : "no",
1147 _req->length, _req->buf);
1148
1149 if (!ep->enabled) {
1150 _req->status = -ESHUTDOWN;
1151 rc = -ESHUTDOWN;
1152 goto out;
1153 }
1154
1155 if (req->in_use) {
1156 ep_err(ep, "refusing to queue req %p (already queued)\n", req);
1157 goto out;
1158 }
1159
1160 length = _req->length;
1161 _req->status = -EINPROGRESS;
1162 _req->actual = 0;
1163
1164 ep_add_request(ep, req);
1165
1166 if (is_ep0(ep)) {
1167 switch (dev->ep0state) {
1168 case WAIT_ACK_SET_CONF_INTERF:
1169 if (length == 0) {
1170 ep_end_in_req(ep, req);
1171 } else {
1172 ep_err(ep, "got a request of %d bytes while"
1173 "in state WATI_ACK_SET_CONF_INTERF\n",
1174 length);
1175 ep_del_request(ep, req);
1176 rc = -EL2HLT;
1177 }
1178 ep0_idle(ep->dev);
1179 break;
1180 case IN_DATA_STAGE:
1181 if (!ep_is_full(ep))
1182 if (write_ep0_fifo(ep, req))
1183 ep0_end_in_req(ep, req);
1184 break;
1185 case OUT_DATA_STAGE:
1186 if ((length == 0) || !epout_has_pkt(ep))
1187 if (read_ep0_fifo(ep, req))
1188 ep0_end_out_req(ep, req);
1189 break;
1190 default:
1191 ep_err(ep, "odd state %s to send me a request\n",
1192 EP0_STNAME(ep->dev));
1193 ep_del_request(ep, req);
1194 rc = -EL2HLT;
1195 break;
1196 }
1197 } else {
1198 handle_ep(ep);
1199 }
1200
1201out:
1202 spin_unlock_irqrestore(&ep->lock, flags);
1203 return rc;
1204}
1205
1206/**
1207 * pxa_ep_dequeue - Dequeue one request
1208 * @_ep: usb endpoint
1209 * @_req: usb request
1210 *
1211 * Return 0 if no error, -EINVAL or -ECONNRESET otherwise
1212 */
1213static int pxa_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
1214{
1215 struct pxa_ep *ep;
1216 struct udc_usb_ep *udc_usb_ep;
1217 struct pxa27x_request *req;
1218 unsigned long flags;
1219 int rc;
1220
1221 if (!_ep)
1222 return -EINVAL;
1223 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
1224 ep = udc_usb_ep->pxa_ep;
1225 if (!ep || is_ep0(ep))
1226 return -EINVAL;
1227
1228 spin_lock_irqsave(&ep->lock, flags);
1229
1230 /* make sure it's actually queued on this endpoint */
1231 list_for_each_entry(req, &ep->queue, queue) {
1232 if (&req->req == _req)
1233 break;
1234 }
1235
1236 rc = -EINVAL;
1237 if (&req->req != _req)
1238 goto out;
1239
1240 rc = 0;
1241 req_done(ep, req, -ECONNRESET);
1242out:
1243 spin_unlock_irqrestore(&ep->lock, flags);
1244 return rc;
1245}
1246
1247/**
1248 * pxa_ep_set_halt - Halts operations on one endpoint
1249 * @_ep: usb endpoint
1250 * @value:
1251 *
1252 * Returns 0 if no error, -EINVAL, -EROFS, -EAGAIN otherwise
1253 */
1254static int pxa_ep_set_halt(struct usb_ep *_ep, int value)
1255{
1256 struct pxa_ep *ep;
1257 struct udc_usb_ep *udc_usb_ep;
1258 unsigned long flags;
1259 int rc;
1260
1261
1262 if (!_ep)
1263 return -EINVAL;
1264 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
1265 ep = udc_usb_ep->pxa_ep;
1266 if (!ep || is_ep0(ep))
1267 return -EINVAL;
1268
1269 if (value == 0) {
1270 /*
1271 * This path (reset toggle+halt) is needed to implement
1272 * SET_INTERFACE on normal hardware. but it can't be
1273 * done from software on the PXA UDC, and the hardware
1274 * forgets to do it as part of SET_INTERFACE automagic.
1275 */
1276 ep_dbg(ep, "only host can clear halt\n");
1277 return -EROFS;
1278 }
1279
1280 spin_lock_irqsave(&ep->lock, flags);
1281
1282 rc = -EAGAIN;
1283 if (ep->dir_in && (ep_is_full(ep) || !list_empty(&ep->queue)))
1284 goto out;
1285
1286 /* FST, FEF bits are the same for control and non control endpoints */
1287 rc = 0;
1288 udc_ep_writel(ep, UDCCSR, UDCCSR_FST | UDCCSR_FEF);
1289 if (is_ep0(ep))
1290 set_ep0state(ep->dev, STALL);
1291
1292out:
1293 spin_unlock_irqrestore(&ep->lock, flags);
1294 return rc;
1295}
1296
1297/**
1298 * pxa_ep_fifo_status - Get how many bytes in physical endpoint
1299 * @_ep: usb endpoint
1300 *
1301 * Returns number of bytes in OUT fifos. Broken for IN fifos.
1302 */
1303static int pxa_ep_fifo_status(struct usb_ep *_ep)
1304{
1305 struct pxa_ep *ep;
1306 struct udc_usb_ep *udc_usb_ep;
1307
1308 if (!_ep)
1309 return -ENODEV;
1310 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
1311 ep = udc_usb_ep->pxa_ep;
1312 if (!ep || is_ep0(ep))
1313 return -ENODEV;
1314
1315 if (ep->dir_in)
1316 return -EOPNOTSUPP;
1317 if (ep->dev->gadget.speed == USB_SPEED_UNKNOWN || ep_is_empty(ep))
1318 return 0;
1319 else
1320 return ep_count_bytes_remain(ep) + 1;
1321}
1322
1323/**
1324 * pxa_ep_fifo_flush - Flushes one endpoint
1325 * @_ep: usb endpoint
1326 *
1327 * Discards all data in one endpoint(IN or OUT), except control endpoint.
1328 */
1329static void pxa_ep_fifo_flush(struct usb_ep *_ep)
1330{
1331 struct pxa_ep *ep;
1332 struct udc_usb_ep *udc_usb_ep;
1333 unsigned long flags;
1334
1335 if (!_ep)
1336 return;
1337 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
1338 ep = udc_usb_ep->pxa_ep;
1339 if (!ep || is_ep0(ep))
1340 return;
1341
1342 spin_lock_irqsave(&ep->lock, flags);
1343
1344 if (unlikely(!list_empty(&ep->queue)))
1345 ep_dbg(ep, "called while queue list not empty\n");
1346 ep_dbg(ep, "called\n");
1347
1348 /* for OUT, just read and discard the FIFO contents. */
1349 if (!ep->dir_in) {
1350 while (!ep_is_empty(ep))
1351 udc_ep_readl(ep, UDCDR);
1352 } else {
1353 /* most IN status is the same, but ISO can't stall */
1354 udc_ep_writel(ep, UDCCSR,
1355 UDCCSR_PC | UDCCSR_FEF | UDCCSR_TRN
1356 | (EPXFERTYPE_is_ISO(ep) ? 0 : UDCCSR_SST));
1357 }
1358
1359 spin_unlock_irqrestore(&ep->lock, flags);
1360
1361 return;
1362}
1363
1364/**
1365 * pxa_ep_enable - Enables usb endpoint
1366 * @_ep: usb endpoint
1367 * @desc: usb endpoint descriptor
1368 *
1369 * Nothing much to do here, as ep configuration is done once and for all
1370 * before udc is enabled. After udc enable, no physical endpoint configuration
1371 * can be changed.
1372 * Function makes sanity checks and flushes the endpoint.
1373 */
1374static int pxa_ep_enable(struct usb_ep *_ep,
1375 const struct usb_endpoint_descriptor *desc)
1376{
1377 struct pxa_ep *ep;
1378 struct udc_usb_ep *udc_usb_ep;
1379 struct pxa_udc *udc;
1380
1381 if (!_ep || !desc)
1382 return -EINVAL;
1383
1384 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
1385 if (udc_usb_ep->pxa_ep) {
1386 ep = udc_usb_ep->pxa_ep;
1387 ep_warn(ep, "usb_ep %s already enabled, doing nothing\n",
1388 _ep->name);
1389 } else {
1390 ep = find_pxa_ep(udc_usb_ep->dev, udc_usb_ep);
1391 }
1392
1393 if (!ep || is_ep0(ep)) {
1394 dev_err(udc_usb_ep->dev->dev,
1395 "unable to match pxa_ep for ep %s\n",
1396 _ep->name);
1397 return -EINVAL;
1398 }
1399
1400 if ((desc->bDescriptorType != USB_DT_ENDPOINT)
1401 || (ep->type != usb_endpoint_type(desc))) {
1402 ep_err(ep, "type mismatch\n");
1403 return -EINVAL;
1404 }
1405
1406 if (ep->fifo_size < le16_to_cpu(desc->wMaxPacketSize)) {
1407 ep_err(ep, "bad maxpacket\n");
1408 return -ERANGE;
1409 }
1410
1411 udc_usb_ep->pxa_ep = ep;
1412 udc = ep->dev;
1413
1414 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) {
1415 ep_err(ep, "bogus device state\n");
1416 return -ESHUTDOWN;
1417 }
1418
1419 ep->enabled = 1;
1420
1421 /* flush fifo (mostly for OUT buffers) */
1422 pxa_ep_fifo_flush(_ep);
1423
1424 ep_dbg(ep, "enabled\n");
1425 return 0;
1426}
1427
1428/**
1429 * pxa_ep_disable - Disable usb endpoint
1430 * @_ep: usb endpoint
1431 *
1432 * Same as for pxa_ep_enable, no physical endpoint configuration can be
1433 * changed.
1434 * Function flushes the endpoint and related requests.
1435 */
1436static int pxa_ep_disable(struct usb_ep *_ep)
1437{
1438 struct pxa_ep *ep;
1439 struct udc_usb_ep *udc_usb_ep;
1440 unsigned long flags;
1441
1442 if (!_ep)
1443 return -EINVAL;
1444
1445 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
1446 ep = udc_usb_ep->pxa_ep;
1447 if (!ep || is_ep0(ep) || !list_empty(&ep->queue))
1448 return -EINVAL;
1449
1450 spin_lock_irqsave(&ep->lock, flags);
1451 ep->enabled = 0;
1452 nuke(ep, -ESHUTDOWN);
1453 spin_unlock_irqrestore(&ep->lock, flags);
1454
1455 pxa_ep_fifo_flush(_ep);
1456 udc_usb_ep->pxa_ep = NULL;
1457
1458 ep_dbg(ep, "disabled\n");
1459 return 0;
1460}
1461
1462static struct usb_ep_ops pxa_ep_ops = {
1463 .enable = pxa_ep_enable,
1464 .disable = pxa_ep_disable,
1465
1466 .alloc_request = pxa_ep_alloc_request,
1467 .free_request = pxa_ep_free_request,
1468
1469 .queue = pxa_ep_queue,
1470 .dequeue = pxa_ep_dequeue,
1471
1472 .set_halt = pxa_ep_set_halt,
1473 .fifo_status = pxa_ep_fifo_status,
1474 .fifo_flush = pxa_ep_fifo_flush,
1475};
1476
1477
1478/**
1479 * pxa_udc_get_frame - Returns usb frame number
1480 * @_gadget: usb gadget
1481 */
1482static int pxa_udc_get_frame(struct usb_gadget *_gadget)
1483{
1484 struct pxa_udc *udc = to_gadget_udc(_gadget);
1485
1486 return (udc_readl(udc, UDCFNR) & 0x7ff);
1487}
1488
1489/**
1490 * pxa_udc_wakeup - Force udc device out of suspend
1491 * @_gadget: usb gadget
1492 *
1493 * Returns 0 if succesfull, error code otherwise
1494 */
1495static int pxa_udc_wakeup(struct usb_gadget *_gadget)
1496{
1497 struct pxa_udc *udc = to_gadget_udc(_gadget);
1498
1499 /* host may not have enabled remote wakeup */
1500 if ((udc_readl(udc, UDCCR) & UDCCR_DWRE) == 0)
1501 return -EHOSTUNREACH;
1502 udc_set_mask_UDCCR(udc, UDCCR_UDR);
1503 return 0;
1504}
1505
1506static const struct usb_gadget_ops pxa_udc_ops = {
1507 .get_frame = pxa_udc_get_frame,
1508 .wakeup = pxa_udc_wakeup,
1509 /* current versions must always be self-powered */
1510};
1511
1512/**
1513 * udc_disable - disable udc device controller
1514 * @udc: udc device
1515 *
1516 * Disables the udc device : disables clocks, udc interrupts, control endpoint
1517 * interrupts.
1518 */
1519static void udc_disable(struct pxa_udc *udc)
1520{
1521 udc_writel(udc, UDCICR0, 0);
1522 udc_writel(udc, UDCICR1, 0);
1523
1524 udc_clear_mask_UDCCR(udc, UDCCR_UDE);
1525 clk_disable(udc->clk);
1526
1527 ep0_idle(udc);
1528 udc->gadget.speed = USB_SPEED_UNKNOWN;
1529 udc->mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT);
1530}
1531
1532/**
1533 * udc_init_data - Initialize udc device data structures
1534 * @dev: udc device
1535 *
1536 * Initializes gadget endpoint list, endpoints locks. No action is taken
1537 * on the hardware.
1538 */
1539static __init void udc_init_data(struct pxa_udc *dev)
1540{
1541 int i;
1542 struct pxa_ep *ep;
1543
1544 /* device/ep0 records init */
1545 INIT_LIST_HEAD(&dev->gadget.ep_list);
1546 INIT_LIST_HEAD(&dev->gadget.ep0->ep_list);
1547 dev->udc_usb_ep[0].pxa_ep = &dev->pxa_ep[0];
1548 ep0_idle(dev);
1549 strcpy(dev->dev->bus_id, "");
1550
1551 /* PXA endpoints init */
1552 for (i = 0; i < NR_PXA_ENDPOINTS; i++) {
1553 ep = &dev->pxa_ep[i];
1554
1555 ep->enabled = is_ep0(ep);
1556 INIT_LIST_HEAD(&ep->queue);
1557 spin_lock_init(&ep->lock);
1558 }
1559
1560 /* USB endpoints init */
1561 for (i = 0; i < NR_USB_ENDPOINTS; i++)
1562 if (i != 0)
1563 list_add_tail(&dev->udc_usb_ep[i].usb_ep.ep_list,
1564 &dev->gadget.ep_list);
1565}
1566
1567/**
1568 * udc_enable - Enables the udc device
1569 * @dev: udc device
1570 *
1571 * Enables the udc device : enables clocks, udc interrupts, control endpoint
1572 * interrupts, sets usb as UDC client and setups endpoints.
1573 */
1574static void udc_enable(struct pxa_udc *udc)
1575{
1576 udc_writel(udc, UDCICR0, 0);
1577 udc_writel(udc, UDCICR1, 0);
1578 udc_writel(udc, UP2OCR, UP2OCR_HXOE);
1579 udc_clear_mask_UDCCR(udc, UDCCR_UDE);
1580
1581 clk_enable(udc->clk);
1582
1583 ep0_idle(udc);
1584 udc->gadget.speed = USB_SPEED_FULL;
1585 memset(&udc->stats, 0, sizeof(udc->stats));
1586
1587 udc_set_mask_UDCCR(udc, UDCCR_UDE);
1588 udelay(2);
1589 if (udc_readl(udc, UDCCR) & UDCCR_EMCE)
1590 dev_err(udc->dev, "Configuration errors, udc disabled\n");
1591
1592 /*
1593 * Caller must be able to sleep in order to cope with startup transients
1594 */
1595 msleep(100);
1596
1597 /* enable suspend/resume and reset irqs */
1598 udc_writel(udc, UDCICR1,
1599 UDCICR1_IECC | UDCICR1_IERU
1600 | UDCICR1_IESU | UDCICR1_IERS);
1601
1602 /* enable ep0 irqs */
1603 pio_irq_enable(&udc->pxa_ep[0]);
1604
1605 dev_info(udc->dev, "UDC connecting\n");
1606 if (udc->mach->udc_command)
1607 udc->mach->udc_command(PXA2XX_UDC_CMD_CONNECT);
1608}
1609
1610/**
1611 * usb_gadget_register_driver - Register gadget driver
1612 * @driver: gadget driver
1613 *
1614 * When a driver is successfully registered, it will receive control requests
1615 * including set_configuration(), which enables non-control requests. Then
1616 * usb traffic follows until a disconnect is reported. Then a host may connect
1617 * again, or the driver might get unbound.
1618 *
1619 * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise
1620 */
1621int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1622{
1623 struct pxa_udc *udc = the_controller;
1624 int retval;
1625
1626 if (!driver || driver->speed != USB_SPEED_FULL || !driver->bind
1627 || !driver->disconnect || !driver->setup)
1628 return -EINVAL;
1629 if (!udc)
1630 return -ENODEV;
1631 if (udc->driver)
1632 return -EBUSY;
1633
1634 /* first hook up the driver ... */
1635 udc->driver = driver;
1636 udc->gadget.dev.driver = &driver->driver;
1637
1638 retval = device_add(&udc->gadget.dev);
1639 if (retval) {
1640 dev_err(udc->dev, "device_add error %d\n", retval);
1641 goto add_fail;
1642 }
1643 retval = driver->bind(&udc->gadget);
1644 if (retval) {
1645 dev_err(udc->dev, "bind to driver %s --> error %d\n",
1646 driver->driver.name, retval);
1647 goto bind_fail;
1648 }
1649 dev_dbg(udc->dev, "registered gadget driver '%s'\n",
1650 driver->driver.name);
1651
1652 udc_enable(udc);
1653 return 0;
1654
1655bind_fail:
1656 device_del(&udc->gadget.dev);
1657add_fail:
1658 udc->driver = NULL;
1659 udc->gadget.dev.driver = NULL;
1660 return retval;
1661}
1662EXPORT_SYMBOL(usb_gadget_register_driver);
1663
1664
1665/**
1666 * stop_activity - Stops udc endpoints
1667 * @udc: udc device
1668 * @driver: gadget driver
1669 *
1670 * Disables all udc endpoints (even control endpoint), report disconnect to
1671 * the gadget user.
1672 */
1673static void stop_activity(struct pxa_udc *udc, struct usb_gadget_driver *driver)
1674{
1675 int i;
1676
1677 /* don't disconnect drivers more than once */
1678 if (udc->gadget.speed == USB_SPEED_UNKNOWN)
1679 driver = NULL;
1680 udc->gadget.speed = USB_SPEED_UNKNOWN;
1681
1682 for (i = 0; i < NR_USB_ENDPOINTS; i++)
1683 pxa_ep_disable(&udc->udc_usb_ep[i].usb_ep);
1684
1685 if (driver)
1686 driver->disconnect(&udc->gadget);
1687}
1688
1689/**
1690 * usb_gadget_unregister_driver - Unregister the gadget driver
1691 * @driver: gadget driver
1692 *
1693 * Returns 0 if no error, -ENODEV, -EINVAL otherwise
1694 */
1695int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1696{
1697 struct pxa_udc *udc = the_controller;
1698
1699 if (!udc)
1700 return -ENODEV;
1701 if (!driver || driver != udc->driver || !driver->unbind)
1702 return -EINVAL;
1703
1704 stop_activity(udc, driver);
1705 udc_disable(udc);
1706
1707 driver->unbind(&udc->gadget);
1708 udc->driver = NULL;
1709
1710 device_del(&udc->gadget.dev);
1711
1712 dev_info(udc->dev, "unregistered gadget driver '%s'\n",
1713 driver->driver.name);
1714 return 0;
1715}
1716EXPORT_SYMBOL(usb_gadget_unregister_driver);
1717
1718/**
1719 * handle_ep0_ctrl_req - handle control endpoint control request
1720 * @udc: udc device
1721 * @req: control request
1722 */
1723static void handle_ep0_ctrl_req(struct pxa_udc *udc,
1724 struct pxa27x_request *req)
1725{
1726 struct pxa_ep *ep = &udc->pxa_ep[0];
1727 union {
1728 struct usb_ctrlrequest r;
1729 u32 word[2];
1730 } u;
1731 int i;
1732 int have_extrabytes = 0;
1733
1734 nuke(ep, -EPROTO);
1735
1736 /* read SETUP packet */
1737 for (i = 0; i < 2; i++) {
1738 if (unlikely(ep_is_empty(ep)))
1739 goto stall;
1740 u.word[i] = udc_ep_readl(ep, UDCDR);
1741 }
1742
1743 have_extrabytes = !ep_is_empty(ep);
1744 while (!ep_is_empty(ep)) {
1745 i = udc_ep_readl(ep, UDCDR);
1746 ep_err(ep, "wrong to have extra bytes for setup : 0x%08x\n", i);
1747 }
1748
1749 le16_to_cpus(&u.r.wValue);
1750 le16_to_cpus(&u.r.wIndex);
1751 le16_to_cpus(&u.r.wLength);
1752
1753 ep_dbg(ep, "SETUP %02x.%02x v%04x i%04x l%04x\n",
1754 u.r.bRequestType, u.r.bRequest,
1755 u.r.wValue, u.r.wIndex, u.r.wLength);
1756 if (unlikely(have_extrabytes))
1757 goto stall;
1758
1759 if (u.r.bRequestType & USB_DIR_IN)
1760 set_ep0state(udc, IN_DATA_STAGE);
1761 else
1762 set_ep0state(udc, OUT_DATA_STAGE);
1763
1764 /* Tell UDC to enter Data Stage */
1765 udc_ep_writel(ep, UDCCSR, UDCCSR0_SA | UDCCSR0_OPC);
1766
1767 i = udc->driver->setup(&udc->gadget, &u.r);
1768 if (i < 0)
1769 goto stall;
1770out:
1771 return;
1772stall:
1773 ep_dbg(ep, "protocol STALL, udccsr0=%03x err %d\n",
1774 udc_ep_readl(ep, UDCCSR), i);
1775 udc_ep_writel(ep, UDCCSR, UDCCSR0_FST | UDCCSR0_FTF);
1776 set_ep0state(udc, STALL);
1777 goto out;
1778}
1779
1780/**
1781 * handle_ep0 - Handle control endpoint data transfers
1782 * @udc: udc device
1783 * @fifo_irq: 1 if triggered by fifo service type irq
1784 * @opc_irq: 1 if triggered by output packet complete type irq
1785 *
1786 * Context : when in_interrupt() or with ep->lock held
1787 *
1788 * Tries to transfer all pending request data into the endpoint and/or
1789 * transfer all pending data in the endpoint into usb requests.
1790 * Handles states of ep0 automata.
1791 *
1792 * PXA27x hardware handles several standard usb control requests without
1793 * driver notification. The requests fully handled by hardware are :
1794 * SET_ADDRESS, SET_FEATURE, CLEAR_FEATURE, GET_CONFIGURATION, GET_INTERFACE,
1795 * GET_STATUS
1796 * The requests handled by hardware, but with irq notification are :
1797 * SYNCH_FRAME, SET_CONFIGURATION, SET_INTERFACE
1798 * The remaining standard requests really handled by handle_ep0 are :
1799 * GET_DESCRIPTOR, SET_DESCRIPTOR, specific requests.
1800 * Requests standardized outside of USB 2.0 chapter 9 are handled more
1801 * uniformly, by gadget drivers.
1802 *
1803 * The control endpoint state machine is _not_ USB spec compliant, it's even
1804 * hardly compliant with Intel PXA270 developers guide.
1805 * The key points which inferred this state machine are :
1806 * - on every setup token, bit UDCCSR0_SA is raised and held until cleared by
1807 * software.
1808 * - on every OUT packet received, UDCCSR0_OPC is raised and held until
1809 * cleared by software.
1810 * - clearing UDCCSR0_OPC always flushes ep0. If in setup stage, never do it
1811 * before reading ep0.
1812 * - irq can be called on a "packet complete" event (opc_irq=1), while
1813 * UDCCSR0_OPC is not yet raised (delta can be as big as 100ms
1814 * from experimentation).
1815 * - as UDCCSR0_SA can be activated while in irq handling, and clearing
1816 * UDCCSR0_OPC would flush the setup data, we almost never clear UDCCSR0_OPC
1817 * => we never actually read the "status stage" packet of an IN data stage
1818 * => this is not documented in Intel documentation
1819 * - hardware as no idea of STATUS STAGE, it only handle SETUP STAGE and DATA
1820 * STAGE. The driver add STATUS STAGE to send last zero length packet in
1821 * OUT_STATUS_STAGE.
1822 * - special attention was needed for IN_STATUS_STAGE. If a packet complete
1823 * event is detected, we terminate the status stage without ackowledging the
1824 * packet (not to risk to loose a potential SETUP packet)
1825 */
1826static void handle_ep0(struct pxa_udc *udc, int fifo_irq, int opc_irq)
1827{
1828 u32 udccsr0;
1829 struct pxa_ep *ep = &udc->pxa_ep[0];
1830 struct pxa27x_request *req = NULL;
1831 int completed = 0;
1832
1833 udccsr0 = udc_ep_readl(ep, UDCCSR);
1834 ep_dbg(ep, "state=%s, req=%p, udccsr0=0x%03x, udcbcr=%d, irq_msk=%x\n",
1835 EP0_STNAME(udc), req, udccsr0, udc_ep_readl(ep, UDCBCR),
1836 (fifo_irq << 1 | opc_irq));
1837
1838 if (!list_empty(&ep->queue))
1839 req = list_entry(ep->queue.next, struct pxa27x_request, queue);
1840
1841 if (udccsr0 & UDCCSR0_SST) {
1842 ep_dbg(ep, "clearing stall status\n");
1843 nuke(ep, -EPIPE);
1844 udc_ep_writel(ep, UDCCSR, UDCCSR0_SST);
1845 ep0_idle(udc);
1846 }
1847
1848 if (udccsr0 & UDCCSR0_SA) {
1849 nuke(ep, 0);
1850 set_ep0state(udc, SETUP_STAGE);
1851 }
1852
1853 switch (udc->ep0state) {
1854 case WAIT_FOR_SETUP:
1855 /*
1856 * Hardware bug : beware, we cannot clear OPC, since we would
1857 * miss a potential OPC irq for a setup packet.
1858 * So, we only do ... nothing, and hope for a next irq with
1859 * UDCCSR0_SA set.
1860 */
1861 break;
1862 case SETUP_STAGE:
1863 udccsr0 &= UDCCSR0_CTRL_REQ_MASK;
1864 if (likely(udccsr0 == UDCCSR0_CTRL_REQ_MASK))
1865 handle_ep0_ctrl_req(udc, req);
1866 break;
1867 case IN_DATA_STAGE: /* GET_DESCRIPTOR */
1868 if (epout_has_pkt(ep))
1869 udc_ep_writel(ep, UDCCSR, UDCCSR0_OPC);
1870 if (req && !ep_is_full(ep))
1871 completed = write_ep0_fifo(ep, req);
1872 if (completed)
1873 ep0_end_in_req(ep, req);
1874 break;
1875 case OUT_DATA_STAGE: /* SET_DESCRIPTOR */
1876 if (epout_has_pkt(ep) && req)
1877 completed = read_ep0_fifo(ep, req);
1878 if (completed)
1879 ep0_end_out_req(ep, req);
1880 break;
1881 case STALL:
1882 udc_ep_writel(ep, UDCCSR, UDCCSR0_FST);
1883 break;
1884 case IN_STATUS_STAGE:
1885 /*
1886 * Hardware bug : beware, we cannot clear OPC, since we would
1887 * miss a potential PC irq for a setup packet.
1888 * So, we only put the ep0 into WAIT_FOR_SETUP state.
1889 */
1890 if (opc_irq)
1891 ep0_idle(udc);
1892 break;
1893 case OUT_STATUS_STAGE:
1894 case WAIT_ACK_SET_CONF_INTERF:
1895 ep_warn(ep, "should never get in %s state here!!!\n",
1896 EP0_STNAME(ep->dev));
1897 ep0_idle(udc);
1898 break;
1899 }
1900}
1901
1902/**
1903 * handle_ep - Handle endpoint data tranfers
1904 * @ep: pxa physical endpoint
1905 *
1906 * Tries to transfer all pending request data into the endpoint and/or
1907 * transfer all pending data in the endpoint into usb requests.
1908 *
1909 * Is always called when in_interrupt() or with ep->lock held.
1910 */
1911static void handle_ep(struct pxa_ep *ep)
1912{
1913 struct pxa27x_request *req;
1914 int completed;
1915 u32 udccsr;
1916 int is_in = ep->dir_in;
1917 int loop = 0;
1918
1919 do {
1920 completed = 0;
1921 udccsr = udc_ep_readl(ep, UDCCSR);
1922 if (likely(!list_empty(&ep->queue)))
1923 req = list_entry(ep->queue.next,
1924 struct pxa27x_request, queue);
1925 else
1926 req = NULL;
1927
1928 ep_dbg(ep, "req:%p, udccsr 0x%03x loop=%d\n",
1929 req, udccsr, loop++);
1930
1931 if (unlikely(udccsr & (UDCCSR_SST | UDCCSR_TRN)))
1932 udc_ep_writel(ep, UDCCSR,
1933 udccsr & (UDCCSR_SST | UDCCSR_TRN));
1934 if (!req)
1935 break;
1936
1937 if (unlikely(is_in)) {
1938 if (likely(!ep_is_full(ep)))
1939 completed = write_fifo(ep, req);
1940 if (completed)
1941 ep_end_in_req(ep, req);
1942 } else {
1943 if (likely(epout_has_pkt(ep)))
1944 completed = read_fifo(ep, req);
1945 if (completed)
1946 ep_end_out_req(ep, req);
1947 }
1948 } while (completed);
1949}
1950
1951/**
1952 * pxa27x_change_configuration - Handle SET_CONF usb request notification
1953 * @udc: udc device
1954 * @config: usb configuration
1955 *
1956 * Post the request to upper level.
1957 * Don't use any pxa specific harware configuration capabilities
1958 */
1959static void pxa27x_change_configuration(struct pxa_udc *udc, int config)
1960{
1961 struct usb_ctrlrequest req ;
1962
1963 dev_dbg(udc->dev, "config=%d\n", config);
1964
1965 udc->config = config;
1966 udc->last_interface = 0;
1967 udc->last_alternate = 0;
1968
1969 req.bRequestType = 0;
1970 req.bRequest = USB_REQ_SET_CONFIGURATION;
1971 req.wValue = config;
1972 req.wIndex = 0;
1973 req.wLength = 0;
1974
1975 set_ep0state(udc, WAIT_ACK_SET_CONF_INTERF);
1976 udc->driver->setup(&udc->gadget, &req);
1977}
1978
1979/**
1980 * pxa27x_change_interface - Handle SET_INTERF usb request notification
1981 * @udc: udc device
1982 * @iface: interface number
1983 * @alt: alternate setting number
1984 *
1985 * Post the request to upper level.
1986 * Don't use any pxa specific harware configuration capabilities
1987 */
1988static void pxa27x_change_interface(struct pxa_udc *udc, int iface, int alt)
1989{
1990 struct usb_ctrlrequest req;
1991
1992 dev_dbg(udc->dev, "interface=%d, alternate setting=%d\n", iface, alt);
1993
1994 udc->last_interface = iface;
1995 udc->last_alternate = alt;
1996
1997 req.bRequestType = USB_RECIP_INTERFACE;
1998 req.bRequest = USB_REQ_SET_INTERFACE;
1999 req.wValue = alt;
2000 req.wIndex = iface;
2001 req.wLength = 0;
2002
2003 set_ep0state(udc, WAIT_ACK_SET_CONF_INTERF);
2004 udc->driver->setup(&udc->gadget, &req);
2005}
2006
2007/*
2008 * irq_handle_data - Handle data transfer
2009 * @irq: irq IRQ number
2010 * @udc: dev pxa_udc device structure
2011 *
2012 * Called from irq handler, transferts data to or from endpoint to queue
2013 */
2014static void irq_handle_data(int irq, struct pxa_udc *udc)
2015{
2016 int i;
2017 struct pxa_ep *ep;
2018 u32 udcisr0 = udc_readl(udc, UDCISR0) & UDCCISR0_EP_MASK;
2019 u32 udcisr1 = udc_readl(udc, UDCISR1) & UDCCISR1_EP_MASK;
2020
2021 if (udcisr0 & UDCISR_INT_MASK) {
2022 udc->pxa_ep[0].stats.irqs++;
2023 udc_writel(udc, UDCISR0, UDCISR_INT(0, UDCISR_INT_MASK));
2024 handle_ep0(udc, !!(udcisr0 & UDCICR_FIFOERR),
2025 !!(udcisr0 & UDCICR_PKTCOMPL));
2026 }
2027
2028 udcisr0 >>= 2;
2029 for (i = 1; udcisr0 != 0 && i < 16; udcisr0 >>= 2, i++) {
2030 if (!(udcisr0 & UDCISR_INT_MASK))
2031 continue;
2032
2033 udc_writel(udc, UDCISR0, UDCISR_INT(i, UDCISR_INT_MASK));
2034 ep = &udc->pxa_ep[i];
2035 ep->stats.irqs++;
2036 handle_ep(ep);
2037 }
2038
2039 for (i = 16; udcisr1 != 0 && i < 24; udcisr1 >>= 2, i++) {
2040 udc_writel(udc, UDCISR1, UDCISR_INT(i - 16, UDCISR_INT_MASK));
2041 if (!(udcisr1 & UDCISR_INT_MASK))
2042 continue;
2043
2044 ep = &udc->pxa_ep[i];
2045 ep->stats.irqs++;
2046 handle_ep(ep);
2047 }
2048
2049}
2050
2051/**
2052 * irq_udc_suspend - Handle IRQ "UDC Suspend"
2053 * @udc: udc device
2054 */
2055static void irq_udc_suspend(struct pxa_udc *udc)
2056{
2057 udc_writel(udc, UDCISR1, UDCISR1_IRSU);
2058 udc->stats.irqs_suspend++;
2059
2060 if (udc->gadget.speed != USB_SPEED_UNKNOWN
2061 && udc->driver && udc->driver->suspend)
2062 udc->driver->suspend(&udc->gadget);
2063 ep0_idle(udc);
2064}
2065
2066/**
2067 * irq_udc_resume - Handle IRQ "UDC Resume"
2068 * @udc: udc device
2069 */
2070static void irq_udc_resume(struct pxa_udc *udc)
2071{
2072 udc_writel(udc, UDCISR1, UDCISR1_IRRU);
2073 udc->stats.irqs_resume++;
2074
2075 if (udc->gadget.speed != USB_SPEED_UNKNOWN
2076 && udc->driver && udc->driver->resume)
2077 udc->driver->resume(&udc->gadget);
2078}
2079
2080/**
2081 * irq_udc_reconfig - Handle IRQ "UDC Change Configuration"
2082 * @udc: udc device
2083 */
2084static void irq_udc_reconfig(struct pxa_udc *udc)
2085{
2086 unsigned config, interface, alternate, config_change;
2087 u32 udccr = udc_readl(udc, UDCCR);
2088
2089 udc_writel(udc, UDCISR1, UDCISR1_IRCC);
2090 udc->stats.irqs_reconfig++;
2091
2092 config = (udccr & UDCCR_ACN) >> UDCCR_ACN_S;
2093 config_change = (config != udc->config);
2094 pxa27x_change_configuration(udc, config);
2095
2096 interface = (udccr & UDCCR_AIN) >> UDCCR_AIN_S;
2097 alternate = (udccr & UDCCR_AAISN) >> UDCCR_AAISN_S;
2098 pxa27x_change_interface(udc, interface, alternate);
2099
2100 if (config_change)
2101 update_pxa_ep_matches(udc);
2102 udc_set_mask_UDCCR(udc, UDCCR_SMAC);
2103}
2104
2105/**
2106 * irq_udc_reset - Handle IRQ "UDC Reset"
2107 * @udc: udc device
2108 */
2109static void irq_udc_reset(struct pxa_udc *udc)
2110{
2111 u32 udccr = udc_readl(udc, UDCCR);
2112 struct pxa_ep *ep = &udc->pxa_ep[0];
2113
2114 dev_info(udc->dev, "USB reset\n");
2115 udc_writel(udc, UDCISR1, UDCISR1_IRRS);
2116 udc->stats.irqs_reset++;
2117
2118 if ((udccr & UDCCR_UDA) == 0) {
2119 dev_dbg(udc->dev, "USB reset start\n");
2120 stop_activity(udc, udc->driver);
2121 }
2122 udc->gadget.speed = USB_SPEED_FULL;
2123 memset(&udc->stats, 0, sizeof udc->stats);
2124
2125 nuke(ep, -EPROTO);
2126 udc_ep_writel(ep, UDCCSR, UDCCSR0_FTF | UDCCSR0_OPC);
2127 ep0_idle(udc);
2128}
2129
2130/**
2131 * pxa_udc_irq - Main irq handler
2132 * @irq: irq number
2133 * @_dev: udc device
2134 *
2135 * Handles all udc interrupts
2136 */
2137static irqreturn_t pxa_udc_irq(int irq, void *_dev)
2138{
2139 struct pxa_udc *udc = _dev;
2140 u32 udcisr0 = udc_readl(udc, UDCISR0);
2141 u32 udcisr1 = udc_readl(udc, UDCISR1);
2142 u32 udccr = udc_readl(udc, UDCCR);
2143 u32 udcisr1_spec;
2144
2145 dev_vdbg(udc->dev, "Interrupt, UDCISR0:0x%08x, UDCISR1:0x%08x, "
2146 "UDCCR:0x%08x\n", udcisr0, udcisr1, udccr);
2147
2148 udcisr1_spec = udcisr1 & 0xf8000000;
2149 if (unlikely(udcisr1_spec & UDCISR1_IRSU))
2150 irq_udc_suspend(udc);
2151 if (unlikely(udcisr1_spec & UDCISR1_IRRU))
2152 irq_udc_resume(udc);
2153 if (unlikely(udcisr1_spec & UDCISR1_IRCC))
2154 irq_udc_reconfig(udc);
2155 if (unlikely(udcisr1_spec & UDCISR1_IRRS))
2156 irq_udc_reset(udc);
2157
2158 if ((udcisr0 & UDCCISR0_EP_MASK) | (udcisr1 & UDCCISR1_EP_MASK))
2159 irq_handle_data(irq, udc);
2160
2161 return IRQ_HANDLED;
2162}
2163
2164static struct pxa_udc memory = {
2165 .gadget = {
2166 .ops = &pxa_udc_ops,
2167 .ep0 = &memory.udc_usb_ep[0].usb_ep,
2168 .name = driver_name,
2169 .dev = {
2170 .bus_id = "gadget",
2171 },
2172 },
2173
2174 .udc_usb_ep = {
2175 USB_EP_CTRL,
2176 USB_EP_OUT_BULK(1),
2177 USB_EP_IN_BULK(2),
2178 USB_EP_IN_ISO(3),
2179 USB_EP_OUT_ISO(4),
2180 USB_EP_IN_INT(5),
2181 },
2182
2183 .pxa_ep = {
2184 PXA_EP_CTRL,
2185 /* Endpoints for gadget zero */
2186 PXA_EP_OUT_BULK(1, 1, 3, 0, 0),
2187 PXA_EP_IN_BULK(2, 2, 3, 0, 0),
2188 /* Endpoints for ether gadget, file storage gadget */
2189 PXA_EP_OUT_BULK(3, 1, 1, 0, 0),
2190 PXA_EP_IN_BULK(4, 2, 1, 0, 0),
2191 PXA_EP_IN_ISO(5, 3, 1, 0, 0),
2192 PXA_EP_OUT_ISO(6, 4, 1, 0, 0),
2193 PXA_EP_IN_INT(7, 5, 1, 0, 0),
2194 /* Endpoints for RNDIS, serial */
2195 PXA_EP_OUT_BULK(8, 1, 2, 0, 0),
2196 PXA_EP_IN_BULK(9, 2, 2, 0, 0),
2197 PXA_EP_IN_INT(10, 5, 2, 0, 0),
2198 /*
2199 * All the following endpoints are only for completion. They
2200 * won't never work, as multiple interfaces are really broken on
2201 * the pxa.
2202 */
2203 PXA_EP_OUT_BULK(11, 1, 2, 1, 0),
2204 PXA_EP_IN_BULK(12, 2, 2, 1, 0),
2205 /* Endpoint for CDC Ether */
2206 PXA_EP_OUT_BULK(13, 1, 1, 1, 1),
2207 PXA_EP_IN_BULK(14, 2, 1, 1, 1),
2208 }
2209};
2210
2211/**
2212 * pxa_udc_probe - probes the udc device
2213 * @_dev: platform device
2214 *
2215 * Perform basic init : allocates udc clock, creates sysfs files, requests
2216 * irq.
2217 */
2218static int __init pxa_udc_probe(struct platform_device *pdev)
2219{
2220 struct resource *regs;
2221 struct pxa_udc *udc = &memory;
2222 int retval;
2223
2224 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2225 if (!regs)
2226 return -ENXIO;
2227 udc->irq = platform_get_irq(pdev, 0);
2228 if (udc->irq < 0)
2229 return udc->irq;
2230
2231 udc->dev = &pdev->dev;
2232 udc->mach = pdev->dev.platform_data;
2233
2234 udc->clk = clk_get(&pdev->dev, "UDCCLK");
2235 if (IS_ERR(udc->clk)) {
2236 retval = PTR_ERR(udc->clk);
2237 goto err_clk;
2238 }
2239
2240 retval = -ENOMEM;
2241 udc->regs = ioremap(regs->start, regs->end - regs->start + 1);
2242 if (!udc->regs) {
2243 dev_err(&pdev->dev, "Unable to map UDC I/O memory\n");
2244 goto err_map;
2245 }
2246
2247 device_initialize(&udc->gadget.dev);
2248 udc->gadget.dev.parent = &pdev->dev;
2249 udc->gadget.dev.dma_mask = NULL;
2250
2251 the_controller = udc;
2252 platform_set_drvdata(pdev, udc);
2253 udc_init_data(udc);
2254 pxa_eps_setup(udc);
2255
2256 /* irq setup after old hardware state is cleaned up */
2257 retval = request_irq(udc->irq, pxa_udc_irq,
2258 IRQF_SHARED, driver_name, udc);
2259 if (retval != 0) {
2260 dev_err(udc->dev, "%s: can't get irq %i, err %d\n",
2261 driver_name, IRQ_USB, retval);
2262 goto err_irq;
2263 }
2264
2265 pxa_init_debugfs(udc);
2266 return 0;
2267err_irq:
2268 iounmap(udc->regs);
2269err_map:
2270 clk_put(udc->clk);
2271 udc->clk = NULL;
2272err_clk:
2273 return retval;
2274}
2275
2276/**
2277 * pxa_udc_remove - removes the udc device driver
2278 * @_dev: platform device
2279 */
2280static int __exit pxa_udc_remove(struct platform_device *_dev)
2281{
2282 struct pxa_udc *udc = platform_get_drvdata(_dev);
2283
2284 usb_gadget_unregister_driver(udc->driver);
2285 free_irq(udc->irq, udc);
2286 pxa_cleanup_debugfs(udc);
2287
2288 platform_set_drvdata(_dev, NULL);
2289 the_controller = NULL;
2290 clk_put(udc->clk);
2291
2292 return 0;
2293}
2294
2295static void pxa_udc_shutdown(struct platform_device *_dev)
2296{
2297 struct pxa_udc *udc = platform_get_drvdata(_dev);
2298
2299 udc_disable(udc);
2300}
2301
2302#ifdef CONFIG_PM
2303/**
2304 * pxa_udc_suspend - Suspend udc device
2305 * @_dev: platform device
2306 * @state: suspend state
2307 *
2308 * Suspends udc : saves configuration registers (UDCCR*), then disables the udc
2309 * device.
2310 */
2311static int pxa_udc_suspend(struct platform_device *_dev, pm_message_t state)
2312{
2313 int i;
2314 struct pxa_udc *udc = platform_get_drvdata(_dev);
2315 struct pxa_ep *ep;
2316
2317 ep = &udc->pxa_ep[0];
2318 udc->udccsr0 = udc_ep_readl(ep, UDCCSR);
2319 for (i = 1; i < NR_PXA_ENDPOINTS; i++) {
2320 ep = &udc->pxa_ep[i];
2321 ep->udccsr_value = udc_ep_readl(ep, UDCCSR);
2322 ep->udccr_value = udc_ep_readl(ep, UDCCR);
2323 ep_dbg(ep, "udccsr:0x%03x, udccr:0x%x\n",
2324 ep->udccsr_value, ep->udccr_value);
2325 }
2326
2327 udc_disable(udc);
2328
2329 return 0;
2330}
2331
2332/**
2333 * pxa_udc_resume - Resume udc device
2334 * @_dev: platform device
2335 *
2336 * Resumes udc : restores configuration registers (UDCCR*), then enables the udc
2337 * device.
2338 */
2339static int pxa_udc_resume(struct platform_device *_dev)
2340{
2341 int i;
2342 struct pxa_udc *udc = platform_get_drvdata(_dev);
2343 struct pxa_ep *ep;
2344
2345 ep = &udc->pxa_ep[0];
2346 udc_ep_writel(ep, UDCCSR, udc->udccsr0 & (UDCCSR0_FST | UDCCSR0_DME));
2347 for (i = 1; i < NR_PXA_ENDPOINTS; i++) {
2348 ep = &udc->pxa_ep[i];
2349 udc_ep_writel(ep, UDCCSR, ep->udccsr_value);
2350 udc_ep_writel(ep, UDCCR, ep->udccr_value);
2351 ep_dbg(ep, "udccsr:0x%03x, udccr:0x%x\n",
2352 ep->udccsr_value, ep->udccr_value);
2353 }
2354
2355 udc_enable(udc);
2356 /*
2357 * We do not handle OTG yet.
2358 *
2359 * OTGPH bit is set when sleep mode is entered.
2360 * it indicates that OTG pad is retaining its state.
2361 * Upon exit from sleep mode and before clearing OTGPH,
2362 * Software must configure the USB OTG pad, UDC, and UHC
2363 * to the state they were in before entering sleep mode.
2364 *
2365 * Should be : PSSR |= PSSR_OTGPH;
2366 */
2367
2368 return 0;
2369}
2370#endif
2371
2372/* work with hotplug and coldplug */
2373MODULE_ALIAS("platform:pxa2xx-udc");
2374
2375static struct platform_driver udc_driver = {
2376 .driver = {
2377 .name = "pxa2xx-udc",
2378 .owner = THIS_MODULE,
2379 },
2380 .remove = __exit_p(pxa_udc_remove),
2381 .shutdown = pxa_udc_shutdown,
2382#ifdef CONFIG_PM
2383 .suspend = pxa_udc_suspend,
2384 .resume = pxa_udc_resume
2385#endif
2386};
2387
2388static int __init udc_init(void)
2389{
2390 printk(KERN_INFO "%s: version %s\n", driver_name, DRIVER_VERSION);
2391 return platform_driver_probe(&udc_driver, pxa_udc_probe);
2392}
2393module_init(udc_init);
2394
2395
2396static void __exit udc_exit(void)
2397{
2398 platform_driver_unregister(&udc_driver);
2399}
2400module_exit(udc_exit);
2401
2402MODULE_DESCRIPTION(DRIVER_DESC);
2403MODULE_AUTHOR("Robert Jarzmik");
2404MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/pxa27x_udc.h b/drivers/usb/gadget/pxa27x_udc.h
new file mode 100644
index 000000000000..1d1b7936ee11
--- /dev/null
+++ b/drivers/usb/gadget/pxa27x_udc.h
@@ -0,0 +1,487 @@
1/*
2 * linux/drivers/usb/gadget/pxa27x_udc.h
3 * Intel PXA27x on-chip full speed USB device controller
4 *
5 * Inspired by original driver by Frank Becker, David Brownell, and others.
6 * Copyright (C) 2008 Robert Jarzmik
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, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#ifndef __LINUX_USB_GADGET_PXA27X_H
24#define __LINUX_USB_GADGET_PXA27X_H
25
26#include <linux/types.h>
27#include <linux/spinlock.h>
28#include <linux/io.h>
29
30/*
31 * Register definitions
32 */
33/* Offsets */
34#define UDCCR 0x0000 /* UDC Control Register */
35#define UDCICR0 0x0004 /* UDC Interrupt Control Register0 */
36#define UDCICR1 0x0008 /* UDC Interrupt Control Register1 */
37#define UDCISR0 0x000C /* UDC Interrupt Status Register 0 */
38#define UDCISR1 0x0010 /* UDC Interrupt Status Register 1 */
39#define UDCFNR 0x0014 /* UDC Frame Number Register */
40#define UDCOTGICR 0x0018 /* UDC On-The-Go interrupt control */
41#define UP2OCR 0x0020 /* USB Port 2 Output Control register */
42#define UP3OCR 0x0024 /* USB Port 3 Output Control register */
43#define UDCCSRn(x) (0x0100 + ((x)<<2)) /* UDC Control/Status register */
44#define UDCBCRn(x) (0x0200 + ((x)<<2)) /* UDC Byte Count Register */
45#define UDCDRn(x) (0x0300 + ((x)<<2)) /* UDC Data Register */
46#define UDCCRn(x) (0x0400 + ((x)<<2)) /* UDC Control Register */
47
48#define UDCCR_OEN (1 << 31) /* On-the-Go Enable */
49#define UDCCR_AALTHNP (1 << 30) /* A-device Alternate Host Negotiation
50 Protocol Port Support */
51#define UDCCR_AHNP (1 << 29) /* A-device Host Negotiation Protocol
52 Support */
53#define UDCCR_BHNP (1 << 28) /* B-device Host Negotiation Protocol
54 Enable */
55#define UDCCR_DWRE (1 << 16) /* Device Remote Wake-up Enable */
56#define UDCCR_ACN (0x03 << 11) /* Active UDC configuration Number */
57#define UDCCR_ACN_S 11
58#define UDCCR_AIN (0x07 << 8) /* Active UDC interface Number */
59#define UDCCR_AIN_S 8
60#define UDCCR_AAISN (0x07 << 5) /* Active UDC Alternate Interface
61 Setting Number */
62#define UDCCR_AAISN_S 5
63#define UDCCR_SMAC (1 << 4) /* Switch Endpoint Memory to Active
64 Configuration */
65#define UDCCR_EMCE (1 << 3) /* Endpoint Memory Configuration
66 Error */
67#define UDCCR_UDR (1 << 2) /* UDC Resume */
68#define UDCCR_UDA (1 << 1) /* UDC Active */
69#define UDCCR_UDE (1 << 0) /* UDC Enable */
70
71#define UDCICR_INT(n, intr) (((intr) & 0x03) << (((n) & 0x0F) * 2))
72#define UDCICR1_IECC (1 << 31) /* IntEn - Configuration Change */
73#define UDCICR1_IESOF (1 << 30) /* IntEn - Start of Frame */
74#define UDCICR1_IERU (1 << 29) /* IntEn - Resume */
75#define UDCICR1_IESU (1 << 28) /* IntEn - Suspend */
76#define UDCICR1_IERS (1 << 27) /* IntEn - Reset */
77#define UDCICR_FIFOERR (1 << 1) /* FIFO Error interrupt for EP */
78#define UDCICR_PKTCOMPL (1 << 0) /* Packet Complete interrupt for EP */
79#define UDCICR_INT_MASK (UDCICR_FIFOERR | UDCICR_PKTCOMPL)
80
81#define UDCISR_INT(n, intr) (((intr) & 0x03) << (((n) & 0x0F) * 2))
82#define UDCISR1_IRCC (1 << 31) /* IntReq - Configuration Change */
83#define UDCISR1_IRSOF (1 << 30) /* IntReq - Start of Frame */
84#define UDCISR1_IRRU (1 << 29) /* IntReq - Resume */
85#define UDCISR1_IRSU (1 << 28) /* IntReq - Suspend */
86#define UDCISR1_IRRS (1 << 27) /* IntReq - Reset */
87#define UDCISR_INT_MASK (UDCICR_FIFOERR | UDCICR_PKTCOMPL)
88
89#define UDCOTGICR_IESF (1 << 24) /* OTG SET_FEATURE command recvd */
90#define UDCOTGICR_IEXR (1 << 17) /* Extra Transciever Interrupt
91 Rising Edge Interrupt Enable */
92#define UDCOTGICR_IEXF (1 << 16) /* Extra Transciever Interrupt
93 Falling Edge Interrupt Enable */
94#define UDCOTGICR_IEVV40R (1 << 9) /* OTG Vbus Valid 4.0V Rising Edge
95 Interrupt Enable */
96#define UDCOTGICR_IEVV40F (1 << 8) /* OTG Vbus Valid 4.0V Falling Edge
97 Interrupt Enable */
98#define UDCOTGICR_IEVV44R (1 << 7) /* OTG Vbus Valid 4.4V Rising Edge
99 Interrupt Enable */
100#define UDCOTGICR_IEVV44F (1 << 6) /* OTG Vbus Valid 4.4V Falling Edge
101 Interrupt Enable */
102#define UDCOTGICR_IESVR (1 << 5) /* OTG Session Valid Rising Edge
103 Interrupt Enable */
104#define UDCOTGICR_IESVF (1 << 4) /* OTG Session Valid Falling Edge
105 Interrupt Enable */
106#define UDCOTGICR_IESDR (1 << 3) /* OTG A-Device SRP Detect Rising
107 Edge Interrupt Enable */
108#define UDCOTGICR_IESDF (1 << 2) /* OTG A-Device SRP Detect Falling
109 Edge Interrupt Enable */
110#define UDCOTGICR_IEIDR (1 << 1) /* OTG ID Change Rising Edge
111 Interrupt Enable */
112#define UDCOTGICR_IEIDF (1 << 0) /* OTG ID Change Falling Edge
113 Interrupt Enable */
114
115/* Host Port 2 field bits */
116#define UP2OCR_CPVEN (1 << 0) /* Charge Pump Vbus Enable */
117#define UP2OCR_CPVPE (1 << 1) /* Charge Pump Vbus Pulse Enable */
118 /* Transceiver enablers */
119#define UP2OCR_DPPDE (1 << 2) /* D+ Pull Down Enable */
120#define UP2OCR_DMPDE (1 << 3) /* D- Pull Down Enable */
121#define UP2OCR_DPPUE (1 << 4) /* D+ Pull Up Enable */
122#define UP2OCR_DMPUE (1 << 5) /* D- Pull Up Enable */
123#define UP2OCR_DPPUBE (1 << 6) /* D+ Pull Up Bypass Enable */
124#define UP2OCR_DMPUBE (1 << 7) /* D- Pull Up Bypass Enable */
125#define UP2OCR_EXSP (1 << 8) /* External Transceiver Speed Control */
126#define UP2OCR_EXSUS (1 << 9) /* External Transceiver Speed Enable */
127#define UP2OCR_IDON (1 << 10) /* OTG ID Read Enable */
128#define UP2OCR_HXS (1 << 16) /* Transceiver Output Select */
129#define UP2OCR_HXOE (1 << 17) /* Transceiver Output Enable */
130#define UP2OCR_SEOS (1 << 24) /* Single-Ended Output Select */
131
132#define UDCCSR0_SA (1 << 7) /* Setup Active */
133#define UDCCSR0_RNE (1 << 6) /* Receive FIFO Not Empty */
134#define UDCCSR0_FST (1 << 5) /* Force Stall */
135#define UDCCSR0_SST (1 << 4) /* Sent Stall */
136#define UDCCSR0_DME (1 << 3) /* DMA Enable */
137#define UDCCSR0_FTF (1 << 2) /* Flush Transmit FIFO */
138#define UDCCSR0_IPR (1 << 1) /* IN Packet Ready */
139#define UDCCSR0_OPC (1 << 0) /* OUT Packet Complete */
140
141#define UDCCSR_DPE (1 << 9) /* Data Packet Error */
142#define UDCCSR_FEF (1 << 8) /* Flush Endpoint FIFO */
143#define UDCCSR_SP (1 << 7) /* Short Packet Control/Status */
144#define UDCCSR_BNE (1 << 6) /* Buffer Not Empty (IN endpoints) */
145#define UDCCSR_BNF (1 << 6) /* Buffer Not Full (OUT endpoints) */
146#define UDCCSR_FST (1 << 5) /* Force STALL */
147#define UDCCSR_SST (1 << 4) /* Sent STALL */
148#define UDCCSR_DME (1 << 3) /* DMA Enable */
149#define UDCCSR_TRN (1 << 2) /* Tx/Rx NAK */
150#define UDCCSR_PC (1 << 1) /* Packet Complete */
151#define UDCCSR_FS (1 << 0) /* FIFO needs service */
152
153#define UDCCONR_CN (0x03 << 25) /* Configuration Number */
154#define UDCCONR_CN_S 25
155#define UDCCONR_IN (0x07 << 22) /* Interface Number */
156#define UDCCONR_IN_S 22
157#define UDCCONR_AISN (0x07 << 19) /* Alternate Interface Number */
158#define UDCCONR_AISN_S 19
159#define UDCCONR_EN (0x0f << 15) /* Endpoint Number */
160#define UDCCONR_EN_S 15
161#define UDCCONR_ET (0x03 << 13) /* Endpoint Type: */
162#define UDCCONR_ET_S 13
163#define UDCCONR_ET_INT (0x03 << 13) /* Interrupt */
164#define UDCCONR_ET_BULK (0x02 << 13) /* Bulk */
165#define UDCCONR_ET_ISO (0x01 << 13) /* Isochronous */
166#define UDCCONR_ET_NU (0x00 << 13) /* Not used */
167#define UDCCONR_ED (1 << 12) /* Endpoint Direction */
168#define UDCCONR_MPS (0x3ff << 2) /* Maximum Packet Size */
169#define UDCCONR_MPS_S 2
170#define UDCCONR_DE (1 << 1) /* Double Buffering Enable */
171#define UDCCONR_EE (1 << 0) /* Endpoint Enable */
172
173#define UDCCR_MASK_BITS (UDCCR_OEN | UDCCR_SMAC | UDCCR_UDR | UDCCR_UDE)
174#define UDCCSR_WR_MASK (UDCCSR_DME | UDCCSR_FST)
175#define UDC_FNR_MASK (0x7ff)
176#define UDC_BCR_MASK (0x3ff)
177
178/*
179 * UDCCR = UDC Endpoint Configuration Registers
180 * UDCCSR = UDC Control/Status Register for this EP
181 * UDCBCR = UDC Byte Count Remaining (contents of OUT fifo)
182 * UDCDR = UDC Endpoint Data Register (the fifo)
183 */
184#define ofs_UDCCR(ep) (UDCCRn(ep->idx))
185#define ofs_UDCCSR(ep) (UDCCSRn(ep->idx))
186#define ofs_UDCBCR(ep) (UDCBCRn(ep->idx))
187#define ofs_UDCDR(ep) (UDCDRn(ep->idx))
188
189/* Register access macros */
190#define udc_ep_readl(ep, reg) \
191 __raw_readl((ep)->dev->regs + ofs_##reg(ep))
192#define udc_ep_writel(ep, reg, value) \
193 __raw_writel((value), ep->dev->regs + ofs_##reg(ep))
194#define udc_ep_readb(ep, reg) \
195 __raw_readb((ep)->dev->regs + ofs_##reg(ep))
196#define udc_ep_writeb(ep, reg, value) \
197 __raw_writeb((value), ep->dev->regs + ofs_##reg(ep))
198#define udc_readl(dev, reg) \
199 __raw_readl((dev)->regs + (reg))
200#define udc_writel(udc, reg, value) \
201 __raw_writel((value), (udc)->regs + (reg))
202
203#define UDCCSR_MASK (UDCCSR_FST | UDCCSR_DME)
204#define UDCCISR0_EP_MASK ~0
205#define UDCCISR1_EP_MASK 0xffff
206#define UDCCSR0_CTRL_REQ_MASK (UDCCSR0_OPC | UDCCSR0_SA | UDCCSR0_RNE)
207
208#define EPIDX(ep) (ep->idx)
209#define EPADDR(ep) (ep->addr)
210#define EPXFERTYPE(ep) (ep->type)
211#define EPNAME(ep) (ep->name)
212#define is_ep0(ep) (!ep->idx)
213#define EPXFERTYPE_is_ISO(ep) (EPXFERTYPE(ep) == USB_ENDPOINT_XFER_ISOC)
214
215/*
216 * Endpoint definitions
217 *
218 * Once enabled, pxa endpoint configuration is freezed, and cannot change
219 * unless a reset happens or the udc is disabled.
220 * Therefore, we must define all pxa potential endpoint definitions needed for
221 * all gadget and set them up before the udc is enabled.
222 *
223 * As the architecture chosen is fully static, meaning the pxa endpoint
224 * configurations are set up once and for all, we must provide a way to match
225 * one usb endpoint (usb_ep) to several pxa endpoints. The reason is that gadget
226 * layer autoconf doesn't choose the usb_ep endpoint on (config, interface, alt)
227 * criteria, while the pxa architecture requires that.
228 *
229 * The solution is to define several pxa endpoints matching one usb_ep. Ex:
230 * - "ep1-in" matches pxa endpoint EPA (which is an IN ep at addr 1, when
231 * the udc talks on (config=3, interface=0, alt=0)
232 * - "ep1-in" matches pxa endpoint EPB (which is an IN ep at addr 1, when
233 * the udc talks on (config=3, interface=0, alt=1)
234 * - "ep1-in" matches pxa endpoint EPC (which is an IN ep at addr 1, when
235 * the udc talks on (config=2, interface=0, alt=0)
236 *
237 * We'll define the pxa endpoint by its index (EPA => idx=1, EPB => idx=2, ...)
238 */
239
240/*
241 * Endpoint definition helpers
242 */
243#define USB_EP_DEF(addr, bname, dir, type, maxpkt) \
244{ .usb_ep = { .name = bname, .ops = &pxa_ep_ops, .maxpacket = maxpkt, }, \
245 .desc = { .bEndpointAddress = addr | (dir ? USB_DIR_IN : 0), \
246 .bmAttributes = type, \
247 .wMaxPacketSize = maxpkt, }, \
248 .dev = &memory \
249}
250#define USB_EP_BULK(addr, bname, dir) \
251 USB_EP_DEF(addr, bname, dir, USB_ENDPOINT_XFER_BULK, BULK_FIFO_SIZE)
252#define USB_EP_ISO(addr, bname, dir) \
253 USB_EP_DEF(addr, bname, dir, USB_ENDPOINT_XFER_ISOC, ISO_FIFO_SIZE)
254#define USB_EP_INT(addr, bname, dir) \
255 USB_EP_DEF(addr, bname, dir, USB_ENDPOINT_XFER_INT, INT_FIFO_SIZE)
256#define USB_EP_IN_BULK(n) USB_EP_BULK(n, "ep" #n "in-bulk", 1)
257#define USB_EP_OUT_BULK(n) USB_EP_BULK(n, "ep" #n "out-bulk", 0)
258#define USB_EP_IN_ISO(n) USB_EP_ISO(n, "ep" #n "in-iso", 1)
259#define USB_EP_OUT_ISO(n) USB_EP_ISO(n, "ep" #n "out-iso", 0)
260#define USB_EP_IN_INT(n) USB_EP_INT(n, "ep" #n "in-int", 1)
261#define USB_EP_CTRL USB_EP_DEF(0, "ep0", 0, 0, EP0_FIFO_SIZE)
262
263#define PXA_EP_DEF(_idx, _addr, dir, _type, maxpkt, _config, iface, altset) \
264{ \
265 .dev = &memory, \
266 .name = "ep" #_idx, \
267 .idx = _idx, .enabled = 0, \
268 .dir_in = dir, .addr = _addr, \
269 .config = _config, .interface = iface, .alternate = altset, \
270 .type = _type, .fifo_size = maxpkt, \
271}
272#define PXA_EP_BULK(_idx, addr, dir, config, iface, alt) \
273 PXA_EP_DEF(_idx, addr, dir, USB_ENDPOINT_XFER_BULK, BULK_FIFO_SIZE, \
274 config, iface, alt)
275#define PXA_EP_ISO(_idx, addr, dir, config, iface, alt) \
276 PXA_EP_DEF(_idx, addr, dir, USB_ENDPOINT_XFER_ISOC, ISO_FIFO_SIZE, \
277 config, iface, alt)
278#define PXA_EP_INT(_idx, addr, dir, config, iface, alt) \
279 PXA_EP_DEF(_idx, addr, dir, USB_ENDPOINT_XFER_INT, INT_FIFO_SIZE, \
280 config, iface, alt)
281#define PXA_EP_IN_BULK(i, adr, c, f, a) PXA_EP_BULK(i, adr, 1, c, f, a)
282#define PXA_EP_OUT_BULK(i, adr, c, f, a) PXA_EP_BULK(i, adr, 0, c, f, a)
283#define PXA_EP_IN_ISO(i, adr, c, f, a) PXA_EP_ISO(i, adr, 1, c, f, a)
284#define PXA_EP_OUT_ISO(i, adr, c, f, a) PXA_EP_ISO(i, adr, 0, c, f, a)
285#define PXA_EP_IN_INT(i, adr, c, f, a) PXA_EP_INT(i, adr, 1, c, f, a)
286#define PXA_EP_CTRL PXA_EP_DEF(0, 0, 0, 0, EP0_FIFO_SIZE, 0, 0, 0)
287
288struct pxa27x_udc;
289
290struct stats {
291 unsigned long in_ops;
292 unsigned long out_ops;
293 unsigned long in_bytes;
294 unsigned long out_bytes;
295 unsigned long irqs;
296};
297
298/**
299 * struct udc_usb_ep - container of each usb_ep structure
300 * @usb_ep: usb endpoint
301 * @desc: usb descriptor, especially type and address
302 * @dev: udc managing this endpoint
303 * @pxa_ep: matching pxa_ep (cache of find_pxa_ep() call)
304 */
305struct udc_usb_ep {
306 struct usb_ep usb_ep;
307 struct usb_endpoint_descriptor desc;
308 struct pxa_udc *dev;
309 struct pxa_ep *pxa_ep;
310};
311
312/**
313 * struct pxa_ep - pxa endpoint
314 * @dev: udc device
315 * @queue: requests queue
316 * @lock: lock to pxa_ep data (queues and stats)
317 * @enabled: true when endpoint enabled (not stopped by gadget layer)
318 * @idx: endpoint index (1 => epA, 2 => epB, ..., 24 => epX)
319 * @name: endpoint name (for trace/debug purpose)
320 * @dir_in: 1 if IN endpoint, 0 if OUT endpoint
321 * @addr: usb endpoint number
322 * @config: configuration in which this endpoint is active
323 * @interface: interface in which this endpoint is active
324 * @alternate: altsetting in which this endpoitn is active
325 * @fifo_size: max packet size in the endpoint fifo
326 * @type: endpoint type (bulk, iso, int, ...)
327 * @udccsr_value: save register of UDCCSR0 for suspend/resume
328 * @udccr_value: save register of UDCCR for suspend/resume
329 * @stats: endpoint statistics
330 *
331 * The *PROBLEM* is that pxa's endpoint configuration scheme is both misdesigned
332 * (cares about config/interface/altsetting, thus placing needless limits on
333 * device capability) and full of implementation bugs forcing it to be set up
334 * for use more or less like a pxa255.
335 *
336 * As we define the pxa_ep statically, we must guess all needed pxa_ep for all
337 * gadget which may work with this udc driver.
338 */
339struct pxa_ep {
340 struct pxa_udc *dev;
341
342 struct list_head queue;
343 spinlock_t lock; /* Protects this structure */
344 /* (queues, stats) */
345 unsigned enabled:1;
346
347 unsigned idx:5;
348 char *name;
349
350 /*
351 * Specific pxa endpoint data, needed for hardware initialization
352 */
353 unsigned dir_in:1;
354 unsigned addr:3;
355 unsigned config:2;
356 unsigned interface:3;
357 unsigned alternate:3;
358 unsigned fifo_size;
359 unsigned type;
360
361#ifdef CONFIG_PM
362 u32 udccsr_value;
363 u32 udccr_value;
364#endif
365 struct stats stats;
366};
367
368/**
369 * struct pxa27x_request - container of each usb_request structure
370 * @req: usb request
371 * @udc_usb_ep: usb endpoint the request was submitted on
372 * @in_use: sanity check if request already queued on an pxa_ep
373 * @queue: linked list of requests, linked on pxa_ep->queue
374 */
375struct pxa27x_request {
376 struct usb_request req;
377 struct udc_usb_ep *udc_usb_ep;
378 unsigned in_use:1;
379 struct list_head queue;
380};
381
382enum ep0_state {
383 WAIT_FOR_SETUP,
384 SETUP_STAGE,
385 IN_DATA_STAGE,
386 OUT_DATA_STAGE,
387 IN_STATUS_STAGE,
388 OUT_STATUS_STAGE,
389 STALL,
390 WAIT_ACK_SET_CONF_INTERF
391};
392
393static char *ep0_state_name[] = {
394 "WAIT_FOR_SETUP", "SETUP_STAGE", "IN_DATA_STAGE", "OUT_DATA_STAGE",
395 "IN_STATUS_STAGE", "OUT_STATUS_STAGE", "STALL",
396 "WAIT_ACK_SET_CONF_INTERF"
397};
398#define EP0_STNAME(udc) ep0_state_name[(udc)->ep0state]
399
400#define EP0_FIFO_SIZE 16U
401#define BULK_FIFO_SIZE 64U
402#define ISO_FIFO_SIZE 256U
403#define INT_FIFO_SIZE 16U
404
405struct udc_stats {
406 unsigned long irqs_reset;
407 unsigned long irqs_suspend;
408 unsigned long irqs_resume;
409 unsigned long irqs_reconfig;
410};
411
412#define NR_USB_ENDPOINTS (1 + 5) /* ep0 + ep1in-bulk + .. + ep3in-iso */
413#define NR_PXA_ENDPOINTS (1 + 14) /* ep0 + epA + epB + .. + epX */
414
415/**
416 * struct pxa_udc - udc structure
417 * @regs: mapped IO space
418 * @irq: udc irq
419 * @clk: udc clock
420 * @usb_gadget: udc gadget structure
421 * @driver: bound gadget (zero, g_ether, g_file_storage, ...)
422 * @dev: device
423 * @mach: machine info, used to activate specific GPIO
424 * @ep0state: control endpoint state machine state
425 * @stats: statistics on udc usage
426 * @udc_usb_ep: array of usb endpoints offered by the gadget
427 * @pxa_ep: array of pxa available endpoints
428 * @config: UDC active configuration
429 * @last_interface: UDC interface of the last SET_INTERFACE host request
430 * @last_alternate: UDC altsetting of the last SET_INTERFACE host request
431 * @udccsr0: save of udccsr0 in case of suspend
432 * @debugfs_root: root entry of debug filesystem
433 * @debugfs_state: debugfs entry for "udcstate"
434 * @debugfs_queues: debugfs entry for "queues"
435 * @debugfs_eps: debugfs entry for "epstate"
436 */
437struct pxa_udc {
438 void __iomem *regs;
439 int irq;
440 struct clk *clk;
441
442 struct usb_gadget gadget;
443 struct usb_gadget_driver *driver;
444 struct device *dev;
445 struct pxa2xx_udc_mach_info *mach;
446
447 enum ep0_state ep0state;
448 struct udc_stats stats;
449
450 struct udc_usb_ep udc_usb_ep[NR_USB_ENDPOINTS];
451 struct pxa_ep pxa_ep[NR_PXA_ENDPOINTS];
452
453 unsigned config:2;
454 unsigned last_interface:3;
455 unsigned last_alternate:3;
456
457#ifdef CONFIG_PM
458 unsigned udccsr0;
459#endif
460#ifdef CONFIG_USB_GADGET_DEBUG_FS
461 struct dentry *debugfs_root;
462 struct dentry *debugfs_state;
463 struct dentry *debugfs_queues;
464 struct dentry *debugfs_eps;
465#endif
466};
467
468static inline struct pxa_udc *to_gadget_udc(struct usb_gadget *gadget)
469{
470 return container_of(gadget, struct pxa_udc, gadget);
471}
472
473/*
474 * Debugging/message support
475 */
476#define ep_dbg(ep, fmt, arg...) \
477 dev_dbg(ep->dev->dev, "%s:%s: " fmt, EPNAME(ep), __func__, ## arg)
478#define ep_vdbg(ep, fmt, arg...) \
479 dev_vdbg(ep->dev->dev, "%s:%s: " fmt, EPNAME(ep), __func__, ## arg)
480#define ep_err(ep, fmt, arg...) \
481 dev_err(ep->dev->dev, "%s:%s: " fmt, EPNAME(ep), __func__, ## arg)
482#define ep_info(ep, fmt, arg...) \
483 dev_info(ep->dev->dev, "%s:%s: " fmt, EPNAME(ep), __func__, ## arg)
484#define ep_warn(ep, fmt, arg...) \
485 dev_warn(ep->dev->dev, "%s:%s:" fmt, EPNAME(ep), __func__, ## arg)
486
487#endif /* __LINUX_USB_GADGET_PXA27X_H */
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 433b3f44f42e..54cdd6f94034 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -135,7 +135,10 @@ struct gs_port {
135 int port_in_use; /* open/close in progress */ 135 int port_in_use; /* open/close in progress */
136 wait_queue_head_t port_write_wait;/* waiting to write */ 136 wait_queue_head_t port_write_wait;/* waiting to write */
137 struct gs_buf *port_write_buf; 137 struct gs_buf *port_write_buf;
138 struct usb_cdc_line_coding port_line_coding; 138 struct usb_cdc_line_coding port_line_coding; /* 8-N-1 etc */
139 u16 port_handshake_bits;
140#define RS232_RTS (1 << 1)
141#define RS232_DTE (1 << 0)
139}; 142};
140 143
141/* the device structure holds info for the USB device */ 144/* the device structure holds info for the USB device */
@@ -170,7 +173,7 @@ static int gs_open(struct tty_struct *tty, struct file *file);
170static void gs_close(struct tty_struct *tty, struct file *file); 173static void gs_close(struct tty_struct *tty, struct file *file);
171static int gs_write(struct tty_struct *tty, 174static int gs_write(struct tty_struct *tty,
172 const unsigned char *buf, int count); 175 const unsigned char *buf, int count);
173static void gs_put_char(struct tty_struct *tty, unsigned char ch); 176static int gs_put_char(struct tty_struct *tty, unsigned char ch);
174static void gs_flush_chars(struct tty_struct *tty); 177static void gs_flush_chars(struct tty_struct *tty);
175static int gs_write_room(struct tty_struct *tty); 178static int gs_write_room(struct tty_struct *tty);
176static int gs_chars_in_buffer(struct tty_struct *tty); 179static int gs_chars_in_buffer(struct tty_struct *tty);
@@ -199,6 +202,8 @@ static int gs_setup_standard(struct usb_gadget *gadget,
199static int gs_setup_class(struct usb_gadget *gadget, 202static int gs_setup_class(struct usb_gadget *gadget,
200 const struct usb_ctrlrequest *ctrl); 203 const struct usb_ctrlrequest *ctrl);
201static void gs_setup_complete(struct usb_ep *ep, struct usb_request *req); 204static void gs_setup_complete(struct usb_ep *ep, struct usb_request *req);
205static void gs_setup_complete_set_line_coding(struct usb_ep *ep,
206 struct usb_request *req);
202static void gs_disconnect(struct usb_gadget *gadget); 207static void gs_disconnect(struct usb_gadget *gadget);
203static int gs_set_config(struct gs_dev *dev, unsigned config); 208static int gs_set_config(struct gs_dev *dev, unsigned config);
204static void gs_reset_config(struct gs_dev *dev); 209static void gs_reset_config(struct gs_dev *dev);
@@ -406,7 +411,7 @@ static struct usb_cdc_acm_descriptor gs_acm_descriptor = {
406 .bLength = sizeof(gs_acm_descriptor), 411 .bLength = sizeof(gs_acm_descriptor),
407 .bDescriptorType = USB_DT_CS_INTERFACE, 412 .bDescriptorType = USB_DT_CS_INTERFACE,
408 .bDescriptorSubType = USB_CDC_ACM_TYPE, 413 .bDescriptorSubType = USB_CDC_ACM_TYPE,
409 .bmCapabilities = 0, 414 .bmCapabilities = (1 << 1),
410}; 415};
411 416
412static const struct usb_cdc_union_desc gs_union_desc = { 417static const struct usb_cdc_union_desc gs_union_desc = {
@@ -883,14 +888,15 @@ exit:
883/* 888/*
884 * gs_put_char 889 * gs_put_char
885 */ 890 */
886static void gs_put_char(struct tty_struct *tty, unsigned char ch) 891static int gs_put_char(struct tty_struct *tty, unsigned char ch)
887{ 892{
888 unsigned long flags; 893 unsigned long flags;
889 struct gs_port *port = tty->driver_data; 894 struct gs_port *port = tty->driver_data;
895 int ret = 0;
890 896
891 if (port == NULL) { 897 if (port == NULL) {
892 pr_err("gs_put_char: NULL port pointer\n"); 898 pr_err("gs_put_char: NULL port pointer\n");
893 return; 899 return 0;
894 } 900 }
895 901
896 gs_debug("gs_put_char: (%d,%p) char=0x%x, called from %p\n", 902 gs_debug("gs_put_char: (%d,%p) char=0x%x, called from %p\n",
@@ -910,10 +916,11 @@ static void gs_put_char(struct tty_struct *tty, unsigned char ch)
910 goto exit; 916 goto exit;
911 } 917 }
912 918
913 gs_buf_put(port->port_write_buf, &ch, 1); 919 ret = gs_buf_put(port->port_write_buf, &ch, 1);
914 920
915exit: 921exit:
916 spin_unlock_irqrestore(&port->port_lock, flags); 922 spin_unlock_irqrestore(&port->port_lock, flags);
923 return ret;
917} 924}
918 925
919/* 926/*
@@ -1500,6 +1507,8 @@ static int gs_setup(struct usb_gadget *gadget,
1500 u16 wValue = le16_to_cpu(ctrl->wValue); 1507 u16 wValue = le16_to_cpu(ctrl->wValue);
1501 u16 wLength = le16_to_cpu(ctrl->wLength); 1508 u16 wLength = le16_to_cpu(ctrl->wLength);
1502 1509
1510 req->complete = gs_setup_complete;
1511
1503 switch (ctrl->bRequestType & USB_TYPE_MASK) { 1512 switch (ctrl->bRequestType & USB_TYPE_MASK) {
1504 case USB_TYPE_STANDARD: 1513 case USB_TYPE_STANDARD:
1505 ret = gs_setup_standard(gadget,ctrl); 1514 ret = gs_setup_standard(gadget,ctrl);
@@ -1677,18 +1686,14 @@ static int gs_setup_class(struct usb_gadget *gadget,
1677 1686
1678 switch (ctrl->bRequest) { 1687 switch (ctrl->bRequest) {
1679 case USB_CDC_REQ_SET_LINE_CODING: 1688 case USB_CDC_REQ_SET_LINE_CODING:
1680 /* FIXME Submit req to read the data; have its completion 1689 if (wLength != sizeof(struct usb_cdc_line_coding))
1681 * handler copy that data to port->port_line_coding (iff 1690 break;
1682 * it's valid) and maybe pass it on. Until then, fail. 1691 ret = wLength;
1683 */ 1692 req->complete = gs_setup_complete_set_line_coding;
1684 pr_warning("gs_setup: set_line_coding "
1685 "unuspported\n");
1686 break; 1693 break;
1687 1694
1688 case USB_CDC_REQ_GET_LINE_CODING: 1695 case USB_CDC_REQ_GET_LINE_CODING:
1689 port = dev->dev_port[0]; /* ACM only has one port */ 1696 ret = min_t(int, wLength, sizeof(struct usb_cdc_line_coding));
1690 ret = min(wLength,
1691 (u16)sizeof(struct usb_cdc_line_coding));
1692 if (port) { 1697 if (port) {
1693 spin_lock(&port->port_lock); 1698 spin_lock(&port->port_lock);
1694 memcpy(req->buf, &port->port_line_coding, ret); 1699 memcpy(req->buf, &port->port_line_coding, ret);
@@ -1697,15 +1702,27 @@ static int gs_setup_class(struct usb_gadget *gadget,
1697 break; 1702 break;
1698 1703
1699 case USB_CDC_REQ_SET_CONTROL_LINE_STATE: 1704 case USB_CDC_REQ_SET_CONTROL_LINE_STATE:
1700 /* FIXME Submit req to read the data; have its completion 1705 if (wLength != 0)
1701 * handler use that to set the state (iff it's valid) and 1706 break;
1702 * maybe pass it on. Until then, fail. 1707 ret = 0;
1703 */ 1708 if (port) {
1704 pr_warning("gs_setup: set_control_line_state " 1709 /* REVISIT: we currently just remember this data.
1705 "unuspported\n"); 1710 * If we change that, update whatever hardware needs
1711 * updating.
1712 */
1713 spin_lock(&port->port_lock);
1714 port->port_handshake_bits = wValue;
1715 spin_unlock(&port->port_lock);
1716 }
1706 break; 1717 break;
1707 1718
1708 default: 1719 default:
1720 /* NOTE: strictly speaking, we should accept AT-commands
1721 * using SEND_ENCPSULATED_COMMAND/GET_ENCAPSULATED_RESPONSE.
1722 * But our call management descriptor says we don't handle
1723 * call management, so we should be able to get by without
1724 * handling those "required" commands (except by stalling).
1725 */
1709 pr_err("gs_setup: unknown class request, " 1726 pr_err("gs_setup: unknown class request, "
1710 "type=%02x, request=%02x, value=%04x, " 1727 "type=%02x, request=%02x, value=%04x, "
1711 "index=%04x, length=%d\n", 1728 "index=%04x, length=%d\n",
@@ -1717,6 +1734,42 @@ static int gs_setup_class(struct usb_gadget *gadget,
1717 return ret; 1734 return ret;
1718} 1735}
1719 1736
1737static void gs_setup_complete_set_line_coding(struct usb_ep *ep,
1738 struct usb_request *req)
1739{
1740 struct gs_dev *dev = ep->driver_data;
1741 struct gs_port *port = dev->dev_port[0]; /* ACM only has one port */
1742
1743 switch (req->status) {
1744 case 0:
1745 /* normal completion */
1746 if (req->actual != sizeof(port->port_line_coding))
1747 usb_ep_set_halt(ep);
1748 else if (port) {
1749 struct usb_cdc_line_coding *value = req->buf;
1750
1751 /* REVISIT: we currently just remember this data.
1752 * If we change that, (a) validate it first, then
1753 * (b) update whatever hardware needs updating.
1754 */
1755 spin_lock(&port->port_lock);
1756 port->port_line_coding = *value;
1757 spin_unlock(&port->port_lock);
1758 }
1759 break;
1760
1761 case -ESHUTDOWN:
1762 /* disconnect */
1763 gs_free_req(ep, req);
1764 break;
1765
1766 default:
1767 /* unexpected */
1768 break;
1769 }
1770 return;
1771}
1772
1720/* 1773/*
1721 * gs_setup_complete 1774 * gs_setup_complete
1722 */ 1775 */
@@ -1904,6 +1957,11 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
1904 } 1957 }
1905 } 1958 }
1906 1959
1960 /* REVISIT the ACM mode should be able to actually *issue* some
1961 * notifications, for at least serial state change events if
1962 * not also for network connection; say so in bmCapabilities.
1963 */
1964
1907 pr_info("gs_set_config: %s configured, %s speed %s config\n", 1965 pr_info("gs_set_config: %s configured, %s speed %s config\n",
1908 GS_LONG_NAME, 1966 GS_LONG_NAME,
1909 gadget->speed == USB_SPEED_HIGH ? "high" : "full", 1967 gadget->speed == USB_SPEED_HIGH ? "high" : "full",
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index d3d4f4048e6c..fce4924dbbe8 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -23,9 +23,7 @@
23/* 23/*
24 * Gadget Zero only needs two bulk endpoints, and is an example of how you 24 * Gadget Zero only needs two bulk endpoints, and is an example of how you
25 * can write a hardware-agnostic gadget driver running inside a USB device. 25 * can write a hardware-agnostic gadget driver running inside a USB device.
26 * 26 * Some hardware details are visible, but don't affect most of the driver.
27 * Hardware details are visible (see CONFIG_USB_ZERO_* below) but don't
28 * affect most of the driver.
29 * 27 *
30 * Use it with the Linux host/master side "usbtest" driver to get a basic 28 * Use it with the Linux host/master side "usbtest" driver to get a basic
31 * functional test of your device-side usb stack, or with "usb-skeleton". 29 * functional test of your device-side usb stack, or with "usb-skeleton".
@@ -37,6 +35,7 @@
37 * buflen=N default N=4096, buffer size used 35 * buflen=N default N=4096, buffer size used
38 * qlen=N default N=32, how many buffers in the loopback queue 36 * qlen=N default N=32, how many buffers in the loopback queue
39 * loopdefault default false, list loopback config first 37 * loopdefault default false, list loopback config first
38 * autoresume=N default N=0, seconds before triggering remote wakeup
40 * 39 *
41 * Many drivers will only have one configuration, letting them be much 40 * Many drivers will only have one configuration, letting them be much
42 * simpler if they also don't support high speed operation (like this 41 * simpler if they also don't support high speed operation (like this
@@ -62,13 +61,13 @@
62 61
63/*-------------------------------------------------------------------------*/ 62/*-------------------------------------------------------------------------*/
64 63
65#define DRIVER_VERSION "Lughnasadh, 2007" 64#define DRIVER_VERSION "Earth Day 2008"
66 65
67static const char shortname [] = "zero"; 66static const char shortname[] = "zero";
68static const char longname [] = "Gadget Zero"; 67static const char longname[] = "Gadget Zero";
69 68
70static const char source_sink [] = "source and sink data"; 69static const char source_sink[] = "source and sink data";
71static const char loopback [] = "loop input to output"; 70static const char loopback[] = "loop input to output";
72 71
73/*-------------------------------------------------------------------------*/ 72/*-------------------------------------------------------------------------*/
74 73
@@ -120,16 +119,16 @@ static unsigned buflen = 4096;
120static unsigned qlen = 32; 119static unsigned qlen = 32;
121static unsigned pattern = 0; 120static unsigned pattern = 0;
122 121
123module_param (buflen, uint, S_IRUGO); 122module_param(buflen, uint, S_IRUGO);
124module_param (qlen, uint, S_IRUGO); 123module_param(qlen, uint, S_IRUGO);
125module_param (pattern, uint, S_IRUGO|S_IWUSR); 124module_param(pattern, uint, S_IRUGO|S_IWUSR);
126 125
127/* 126/*
128 * if it's nonzero, autoresume says how many seconds to wait 127 * if it's nonzero, autoresume says how many seconds to wait
129 * before trying to wake up the host after suspend. 128 * before trying to wake up the host after suspend.
130 */ 129 */
131static unsigned autoresume = 0; 130static unsigned autoresume = 0;
132module_param (autoresume, uint, 0); 131module_param(autoresume, uint, 0);
133 132
134/* 133/*
135 * Normally the "loopback" configuration is second (index 1) so 134 * Normally the "loopback" configuration is second (index 1) so
@@ -138,8 +137,7 @@ module_param (autoresume, uint, 0);
138 * Or controllers (like superh) that only support one config. 137 * Or controllers (like superh) that only support one config.
139 */ 138 */
140static int loopdefault = 0; 139static int loopdefault = 0;
141 140module_param(loopdefault, bool, S_IRUGO|S_IWUSR);
142module_param (loopdefault, bool, S_IRUGO|S_IWUSR);
143 141
144/*-------------------------------------------------------------------------*/ 142/*-------------------------------------------------------------------------*/
145 143
@@ -176,24 +174,22 @@ module_param (loopdefault, bool, S_IRUGO|S_IWUSR);
176#define CONFIG_SOURCE_SINK 3 174#define CONFIG_SOURCE_SINK 3
177#define CONFIG_LOOPBACK 2 175#define CONFIG_LOOPBACK 2
178 176
179static struct usb_device_descriptor 177static struct usb_device_descriptor device_desc = {
180device_desc = {
181 .bLength = sizeof device_desc, 178 .bLength = sizeof device_desc,
182 .bDescriptorType = USB_DT_DEVICE, 179 .bDescriptorType = USB_DT_DEVICE,
183 180
184 .bcdUSB = __constant_cpu_to_le16 (0x0200), 181 .bcdUSB = __constant_cpu_to_le16(0x0200),
185 .bDeviceClass = USB_CLASS_VENDOR_SPEC, 182 .bDeviceClass = USB_CLASS_VENDOR_SPEC,
186 183
187 .idVendor = __constant_cpu_to_le16 (DRIVER_VENDOR_NUM), 184 .idVendor = __constant_cpu_to_le16(DRIVER_VENDOR_NUM),
188 .idProduct = __constant_cpu_to_le16 (DRIVER_PRODUCT_NUM), 185 .idProduct = __constant_cpu_to_le16(DRIVER_PRODUCT_NUM),
189 .iManufacturer = STRING_MANUFACTURER, 186 .iManufacturer = STRING_MANUFACTURER,
190 .iProduct = STRING_PRODUCT, 187 .iProduct = STRING_PRODUCT,
191 .iSerialNumber = STRING_SERIAL, 188 .iSerialNumber = STRING_SERIAL,
192 .bNumConfigurations = 2, 189 .bNumConfigurations = 2,
193}; 190};
194 191
195static struct usb_config_descriptor 192static struct usb_config_descriptor source_sink_config = {
196source_sink_config = {
197 .bLength = sizeof source_sink_config, 193 .bLength = sizeof source_sink_config,
198 .bDescriptorType = USB_DT_CONFIG, 194 .bDescriptorType = USB_DT_CONFIG,
199 195
@@ -205,8 +201,7 @@ source_sink_config = {
205 .bMaxPower = 1, /* self-powered */ 201 .bMaxPower = 1, /* self-powered */
206}; 202};
207 203
208static struct usb_config_descriptor 204static struct usb_config_descriptor loopback_config = {
209loopback_config = {
210 .bLength = sizeof loopback_config, 205 .bLength = sizeof loopback_config,
211 .bDescriptorType = USB_DT_CONFIG, 206 .bDescriptorType = USB_DT_CONFIG,
212 207
@@ -218,8 +213,7 @@ loopback_config = {
218 .bMaxPower = 1, /* self-powered */ 213 .bMaxPower = 1, /* self-powered */
219}; 214};
220 215
221static struct usb_otg_descriptor 216static struct usb_otg_descriptor otg_descriptor = {
222otg_descriptor = {
223 .bLength = sizeof otg_descriptor, 217 .bLength = sizeof otg_descriptor,
224 .bDescriptorType = USB_DT_OTG, 218 .bDescriptorType = USB_DT_OTG,
225 219
@@ -228,8 +222,7 @@ otg_descriptor = {
228 222
229/* one interface in each configuration */ 223/* one interface in each configuration */
230 224
231static const struct usb_interface_descriptor 225static const struct usb_interface_descriptor source_sink_intf = {
232source_sink_intf = {
233 .bLength = sizeof source_sink_intf, 226 .bLength = sizeof source_sink_intf,
234 .bDescriptorType = USB_DT_INTERFACE, 227 .bDescriptorType = USB_DT_INTERFACE,
235 228
@@ -238,8 +231,7 @@ source_sink_intf = {
238 .iInterface = STRING_SOURCE_SINK, 231 .iInterface = STRING_SOURCE_SINK,
239}; 232};
240 233
241static const struct usb_interface_descriptor 234static const struct usb_interface_descriptor loopback_intf = {
242loopback_intf = {
243 .bLength = sizeof loopback_intf, 235 .bLength = sizeof loopback_intf,
244 .bDescriptorType = USB_DT_INTERFACE, 236 .bDescriptorType = USB_DT_INTERFACE,
245 237
@@ -250,8 +242,7 @@ loopback_intf = {
250 242
251/* two full speed bulk endpoints; their use is config-dependent */ 243/* two full speed bulk endpoints; their use is config-dependent */
252 244
253static struct usb_endpoint_descriptor 245static struct usb_endpoint_descriptor fs_source_desc = {
254fs_source_desc = {
255 .bLength = USB_DT_ENDPOINT_SIZE, 246 .bLength = USB_DT_ENDPOINT_SIZE,
256 .bDescriptorType = USB_DT_ENDPOINT, 247 .bDescriptorType = USB_DT_ENDPOINT,
257 248
@@ -259,8 +250,7 @@ fs_source_desc = {
259 .bmAttributes = USB_ENDPOINT_XFER_BULK, 250 .bmAttributes = USB_ENDPOINT_XFER_BULK,
260}; 251};
261 252
262static struct usb_endpoint_descriptor 253static struct usb_endpoint_descriptor fs_sink_desc = {
263fs_sink_desc = {
264 .bLength = USB_DT_ENDPOINT_SIZE, 254 .bLength = USB_DT_ENDPOINT_SIZE,
265 .bDescriptorType = USB_DT_ENDPOINT, 255 .bDescriptorType = USB_DT_ENDPOINT,
266 256
@@ -268,7 +258,7 @@ fs_sink_desc = {
268 .bmAttributes = USB_ENDPOINT_XFER_BULK, 258 .bmAttributes = USB_ENDPOINT_XFER_BULK,
269}; 259};
270 260
271static const struct usb_descriptor_header *fs_source_sink_function [] = { 261static const struct usb_descriptor_header *fs_source_sink_function[] = {
272 (struct usb_descriptor_header *) &otg_descriptor, 262 (struct usb_descriptor_header *) &otg_descriptor,
273 (struct usb_descriptor_header *) &source_sink_intf, 263 (struct usb_descriptor_header *) &source_sink_intf,
274 (struct usb_descriptor_header *) &fs_sink_desc, 264 (struct usb_descriptor_header *) &fs_sink_desc,
@@ -276,7 +266,7 @@ static const struct usb_descriptor_header *fs_source_sink_function [] = {
276 NULL, 266 NULL,
277}; 267};
278 268
279static const struct usb_descriptor_header *fs_loopback_function [] = { 269static const struct usb_descriptor_header *fs_loopback_function[] = {
280 (struct usb_descriptor_header *) &otg_descriptor, 270 (struct usb_descriptor_header *) &otg_descriptor,
281 (struct usb_descriptor_header *) &loopback_intf, 271 (struct usb_descriptor_header *) &loopback_intf,
282 (struct usb_descriptor_header *) &fs_sink_desc, 272 (struct usb_descriptor_header *) &fs_sink_desc,
@@ -293,36 +283,33 @@ static const struct usb_descriptor_header *fs_loopback_function [] = {
293 * for the config descriptor. 283 * for the config descriptor.
294 */ 284 */
295 285
296static struct usb_endpoint_descriptor 286static struct usb_endpoint_descriptor hs_source_desc = {
297hs_source_desc = {
298 .bLength = USB_DT_ENDPOINT_SIZE, 287 .bLength = USB_DT_ENDPOINT_SIZE,
299 .bDescriptorType = USB_DT_ENDPOINT, 288 .bDescriptorType = USB_DT_ENDPOINT,
300 289
301 .bmAttributes = USB_ENDPOINT_XFER_BULK, 290 .bmAttributes = USB_ENDPOINT_XFER_BULK,
302 .wMaxPacketSize = __constant_cpu_to_le16 (512), 291 .wMaxPacketSize = __constant_cpu_to_le16(512),
303}; 292};
304 293
305static struct usb_endpoint_descriptor 294static struct usb_endpoint_descriptor hs_sink_desc = {
306hs_sink_desc = {
307 .bLength = USB_DT_ENDPOINT_SIZE, 295 .bLength = USB_DT_ENDPOINT_SIZE,
308 .bDescriptorType = USB_DT_ENDPOINT, 296 .bDescriptorType = USB_DT_ENDPOINT,
309 297
310 .bmAttributes = USB_ENDPOINT_XFER_BULK, 298 .bmAttributes = USB_ENDPOINT_XFER_BULK,
311 .wMaxPacketSize = __constant_cpu_to_le16 (512), 299 .wMaxPacketSize = __constant_cpu_to_le16(512),
312}; 300};
313 301
314static struct usb_qualifier_descriptor 302static struct usb_qualifier_descriptor dev_qualifier = {
315dev_qualifier = {
316 .bLength = sizeof dev_qualifier, 303 .bLength = sizeof dev_qualifier,
317 .bDescriptorType = USB_DT_DEVICE_QUALIFIER, 304 .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
318 305
319 .bcdUSB = __constant_cpu_to_le16 (0x0200), 306 .bcdUSB = __constant_cpu_to_le16(0x0200),
320 .bDeviceClass = USB_CLASS_VENDOR_SPEC, 307 .bDeviceClass = USB_CLASS_VENDOR_SPEC,
321 308
322 .bNumConfigurations = 2, 309 .bNumConfigurations = 2,
323}; 310};
324 311
325static const struct usb_descriptor_header *hs_source_sink_function [] = { 312static const struct usb_descriptor_header *hs_source_sink_function[] = {
326 (struct usb_descriptor_header *) &otg_descriptor, 313 (struct usb_descriptor_header *) &otg_descriptor,
327 (struct usb_descriptor_header *) &source_sink_intf, 314 (struct usb_descriptor_header *) &source_sink_intf,
328 (struct usb_descriptor_header *) &hs_source_desc, 315 (struct usb_descriptor_header *) &hs_source_desc,
@@ -330,7 +317,7 @@ static const struct usb_descriptor_header *hs_source_sink_function [] = {
330 NULL, 317 NULL,
331}; 318};
332 319
333static const struct usb_descriptor_header *hs_loopback_function [] = { 320static const struct usb_descriptor_header *hs_loopback_function[] = {
334 (struct usb_descriptor_header *) &otg_descriptor, 321 (struct usb_descriptor_header *) &otg_descriptor,
335 (struct usb_descriptor_header *) &loopback_intf, 322 (struct usb_descriptor_header *) &loopback_intf,
336 (struct usb_descriptor_header *) &hs_source_desc, 323 (struct usb_descriptor_header *) &hs_source_desc,
@@ -355,7 +342,7 @@ static char serial[] = "0123456789.0123456789.0123456789";
355 342
356 343
357/* static strings, in UTF-8 */ 344/* static strings, in UTF-8 */
358static struct usb_string strings [] = { 345static struct usb_string strings[] = {
359 { STRING_MANUFACTURER, manufacturer, }, 346 { STRING_MANUFACTURER, manufacturer, },
360 { STRING_PRODUCT, longname, }, 347 { STRING_PRODUCT, longname, },
361 { STRING_SERIAL, serial, }, 348 { STRING_SERIAL, serial, },
@@ -364,7 +351,7 @@ static struct usb_string strings [] = {
364 { } /* end of list */ 351 { } /* end of list */
365}; 352};
366 353
367static struct usb_gadget_strings stringtab = { 354static struct usb_gadget_strings stringtab = {
368 .language = 0x0409, /* en-us */ 355 .language = 0x0409, /* en-us */
369 .strings = strings, 356 .strings = strings,
370}; 357};
@@ -387,8 +374,7 @@ static struct usb_gadget_strings stringtab = {
387 * high bandwidth modes at high speed. (Maybe work like Intel's test 374 * high bandwidth modes at high speed. (Maybe work like Intel's test
388 * device?) 375 * device?)
389 */ 376 */
390static int 377static int config_buf(struct usb_gadget *gadget,
391config_buf (struct usb_gadget *gadget,
392 u8 *buf, u8 type, unsigned index) 378 u8 *buf, u8 type, unsigned index)
393{ 379{
394 int is_source_sink; 380 int is_source_sink;
@@ -419,7 +405,7 @@ config_buf (struct usb_gadget *gadget,
419 if (!gadget_is_otg(gadget)) 405 if (!gadget_is_otg(gadget))
420 function++; 406 function++;
421 407
422 len = usb_gadget_config_buf (is_source_sink 408 len = usb_gadget_config_buf(is_source_sink
423 ? &source_sink_config 409 ? &source_sink_config
424 : &loopback_config, 410 : &loopback_config,
425 buf, USB_BUFSIZ, function); 411 buf, USB_BUFSIZ, function);
@@ -431,27 +417,26 @@ config_buf (struct usb_gadget *gadget,
431 417
432/*-------------------------------------------------------------------------*/ 418/*-------------------------------------------------------------------------*/
433 419
434static struct usb_request * 420static struct usb_request *alloc_ep_req(struct usb_ep *ep, unsigned length)
435alloc_ep_req (struct usb_ep *ep, unsigned length)
436{ 421{
437 struct usb_request *req; 422 struct usb_request *req;
438 423
439 req = usb_ep_alloc_request (ep, GFP_ATOMIC); 424 req = usb_ep_alloc_request(ep, GFP_ATOMIC);
440 if (req) { 425 if (req) {
441 req->length = length; 426 req->length = length;
442 req->buf = kmalloc(length, GFP_ATOMIC); 427 req->buf = kmalloc(length, GFP_ATOMIC);
443 if (!req->buf) { 428 if (!req->buf) {
444 usb_ep_free_request (ep, req); 429 usb_ep_free_request(ep, req);
445 req = NULL; 430 req = NULL;
446 } 431 }
447 } 432 }
448 return req; 433 return req;
449} 434}
450 435
451static void free_ep_req (struct usb_ep *ep, struct usb_request *req) 436static void free_ep_req(struct usb_ep *ep, struct usb_request *req)
452{ 437{
453 kfree(req->buf); 438 kfree(req->buf);
454 usb_ep_free_request (ep, req); 439 usb_ep_free_request(ep, req);
455} 440}
456 441
457/*-------------------------------------------------------------------------*/ 442/*-------------------------------------------------------------------------*/
@@ -472,7 +457,7 @@ static void free_ep_req (struct usb_ep *ep, struct usb_request *req)
472/* optionally require specific source/sink data patterns */ 457/* optionally require specific source/sink data patterns */
473 458
474static int 459static int
475check_read_data ( 460check_read_data(
476 struct zero_dev *dev, 461 struct zero_dev *dev,
477 struct usb_ep *ep, 462 struct usb_ep *ep,
478 struct usb_request *req 463 struct usb_request *req
@@ -498,8 +483,8 @@ check_read_data (
498 continue; 483 continue;
499 break; 484 break;
500 } 485 }
501 ERROR (dev, "bad OUT byte, buf [%d] = %d\n", i, *buf); 486 ERROR(dev, "bad OUT byte, buf[%d] = %d\n", i, *buf);
502 usb_ep_set_halt (ep); 487 usb_ep_set_halt(ep);
503 return -EINVAL; 488 return -EINVAL;
504 } 489 }
505 return 0; 490 return 0;
@@ -512,7 +497,7 @@ static void reinit_write_data(struct usb_ep *ep, struct usb_request *req)
512 497
513 switch (pattern) { 498 switch (pattern) {
514 case 0: 499 case 0:
515 memset (req->buf, 0, req->length); 500 memset(req->buf, 0, req->length);
516 break; 501 break;
517 case 1: 502 case 1:
518 for (i = 0; i < req->length; i++) 503 for (i = 0; i < req->length; i++)
@@ -525,7 +510,7 @@ static void reinit_write_data(struct usb_ep *ep, struct usb_request *req)
525 * irq delay between end of one request and start of the next. 510 * irq delay between end of one request and start of the next.
526 * that prevents using hardware dma queues. 511 * that prevents using hardware dma queues.
527 */ 512 */
528static void source_sink_complete (struct usb_ep *ep, struct usb_request *req) 513static void source_sink_complete(struct usb_ep *ep, struct usb_request *req)
529{ 514{
530 struct zero_dev *dev = ep->driver_data; 515 struct zero_dev *dev = ep->driver_data;
531 int status = req->status; 516 int status = req->status;
@@ -534,8 +519,8 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req)
534 519
535 case 0: /* normal completion? */ 520 case 0: /* normal completion? */
536 if (ep == dev->out_ep) { 521 if (ep == dev->out_ep) {
537 check_read_data (dev, ep, req); 522 check_read_data(dev, ep, req);
538 memset (req->buf, 0x55, req->length); 523 memset(req->buf, 0x55, req->length);
539 } else 524 } else
540 reinit_write_data(ep, req); 525 reinit_write_data(ep, req);
541 break; 526 break;
@@ -544,11 +529,11 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req)
544 case -ECONNABORTED: /* hardware forced ep reset */ 529 case -ECONNABORTED: /* hardware forced ep reset */
545 case -ECONNRESET: /* request dequeued */ 530 case -ECONNRESET: /* request dequeued */
546 case -ESHUTDOWN: /* disconnect from host */ 531 case -ESHUTDOWN: /* disconnect from host */
547 VDBG (dev, "%s gone (%d), %d/%d\n", ep->name, status, 532 VDBG(dev, "%s gone (%d), %d/%d\n", ep->name, status,
548 req->actual, req->length); 533 req->actual, req->length);
549 if (ep == dev->out_ep) 534 if (ep == dev->out_ep)
550 check_read_data (dev, ep, req); 535 check_read_data(dev, ep, req);
551 free_ep_req (ep, req); 536 free_ep_req(ep, req);
552 return; 537 return;
553 538
554 case -EOVERFLOW: /* buffer overrun on read means that 539 case -EOVERFLOW: /* buffer overrun on read means that
@@ -557,18 +542,18 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req)
557 */ 542 */
558 default: 543 default:
559#if 1 544#if 1
560 DBG (dev, "%s complete --> %d, %d/%d\n", ep->name, 545 DBG(dev, "%s complete --> %d, %d/%d\n", ep->name,
561 status, req->actual, req->length); 546 status, req->actual, req->length);
562#endif 547#endif
563 case -EREMOTEIO: /* short read */ 548 case -EREMOTEIO: /* short read */
564 break; 549 break;
565 } 550 }
566 551
567 status = usb_ep_queue (ep, req, GFP_ATOMIC); 552 status = usb_ep_queue(ep, req, GFP_ATOMIC);
568 if (status) { 553 if (status) {
569 ERROR (dev, "kill %s: resubmit %d bytes --> %d\n", 554 ERROR(dev, "kill %s: resubmit %d bytes --> %d\n",
570 ep->name, req->length, status); 555 ep->name, req->length, status);
571 usb_ep_set_halt (ep); 556 usb_ep_set_halt(ep);
572 /* FIXME recover later ... somehow */ 557 /* FIXME recover later ... somehow */
573 } 558 }
574} 559}
@@ -578,24 +563,24 @@ static struct usb_request *source_sink_start_ep(struct usb_ep *ep)
578 struct usb_request *req; 563 struct usb_request *req;
579 int status; 564 int status;
580 565
581 req = alloc_ep_req (ep, buflen); 566 req = alloc_ep_req(ep, buflen);
582 if (!req) 567 if (!req)
583 return NULL; 568 return NULL;
584 569
585 memset (req->buf, 0, req->length); 570 memset(req->buf, 0, req->length);
586 req->complete = source_sink_complete; 571 req->complete = source_sink_complete;
587 572
588 if (strcmp (ep->name, EP_IN_NAME) == 0) 573 if (strcmp(ep->name, EP_IN_NAME) == 0)
589 reinit_write_data(ep, req); 574 reinit_write_data(ep, req);
590 else 575 else
591 memset (req->buf, 0x55, req->length); 576 memset(req->buf, 0x55, req->length);
592 577
593 status = usb_ep_queue(ep, req, GFP_ATOMIC); 578 status = usb_ep_queue(ep, req, GFP_ATOMIC);
594 if (status) { 579 if (status) {
595 struct zero_dev *dev = ep->driver_data; 580 struct zero_dev *dev = ep->driver_data;
596 581
597 ERROR (dev, "start %s --> %d\n", ep->name, status); 582 ERROR(dev, "start %s --> %d\n", ep->name, status);
598 free_ep_req (ep, req); 583 free_ep_req(ep, req);
599 req = NULL; 584 req = NULL;
600 } 585 }
601 586
@@ -608,34 +593,34 @@ static int set_source_sink_config(struct zero_dev *dev)
608 struct usb_ep *ep; 593 struct usb_ep *ep;
609 struct usb_gadget *gadget = dev->gadget; 594 struct usb_gadget *gadget = dev->gadget;
610 595
611 gadget_for_each_ep (ep, gadget) { 596 gadget_for_each_ep(ep, gadget) {
612 const struct usb_endpoint_descriptor *d; 597 const struct usb_endpoint_descriptor *d;
613 598
614 /* one endpoint writes (sources) zeroes in (to the host) */ 599 /* one endpoint writes (sources) zeroes in (to the host) */
615 if (strcmp (ep->name, EP_IN_NAME) == 0) { 600 if (strcmp(ep->name, EP_IN_NAME) == 0) {
616 d = ep_desc (gadget, &hs_source_desc, &fs_source_desc); 601 d = ep_desc(gadget, &hs_source_desc, &fs_source_desc);
617 result = usb_ep_enable (ep, d); 602 result = usb_ep_enable(ep, d);
618 if (result == 0) { 603 if (result == 0) {
619 ep->driver_data = dev; 604 ep->driver_data = dev;
620 if (source_sink_start_ep(ep) != NULL) { 605 if (source_sink_start_ep(ep) != NULL) {
621 dev->in_ep = ep; 606 dev->in_ep = ep;
622 continue; 607 continue;
623 } 608 }
624 usb_ep_disable (ep); 609 usb_ep_disable(ep);
625 result = -EIO; 610 result = -EIO;
626 } 611 }
627 612
628 /* one endpoint reads (sinks) anything out (from the host) */ 613 /* one endpoint reads (sinks) anything out (from the host) */
629 } else if (strcmp (ep->name, EP_OUT_NAME) == 0) { 614 } else if (strcmp(ep->name, EP_OUT_NAME) == 0) {
630 d = ep_desc (gadget, &hs_sink_desc, &fs_sink_desc); 615 d = ep_desc(gadget, &hs_sink_desc, &fs_sink_desc);
631 result = usb_ep_enable (ep, d); 616 result = usb_ep_enable(ep, d);
632 if (result == 0) { 617 if (result == 0) {
633 ep->driver_data = dev; 618 ep->driver_data = dev;
634 if (source_sink_start_ep(ep) != NULL) { 619 if (source_sink_start_ep(ep) != NULL) {
635 dev->out_ep = ep; 620 dev->out_ep = ep;
636 continue; 621 continue;
637 } 622 }
638 usb_ep_disable (ep); 623 usb_ep_disable(ep);
639 result = -EIO; 624 result = -EIO;
640 } 625 }
641 626
@@ -644,11 +629,11 @@ static int set_source_sink_config(struct zero_dev *dev)
644 continue; 629 continue;
645 630
646 /* stop on error */ 631 /* stop on error */
647 ERROR (dev, "can't start %s, result %d\n", ep->name, result); 632 ERROR(dev, "can't start %s, result %d\n", ep->name, result);
648 break; 633 break;
649 } 634 }
650 if (result == 0) 635 if (result == 0)
651 DBG (dev, "buflen %d\n", buflen); 636 DBG(dev, "buflen %d\n", buflen);
652 637
653 /* caller is responsible for cleanup on error */ 638 /* caller is responsible for cleanup on error */
654 return result; 639 return result;
@@ -656,7 +641,7 @@ static int set_source_sink_config(struct zero_dev *dev)
656 641
657/*-------------------------------------------------------------------------*/ 642/*-------------------------------------------------------------------------*/
658 643
659static void loopback_complete (struct usb_ep *ep, struct usb_request *req) 644static void loopback_complete(struct usb_ep *ep, struct usb_request *req)
660{ 645{
661 struct zero_dev *dev = ep->driver_data; 646 struct zero_dev *dev = ep->driver_data;
662 int status = req->status; 647 int status = req->status;
@@ -668,19 +653,19 @@ static void loopback_complete (struct usb_ep *ep, struct usb_request *req)
668 /* loop this OUT packet back IN to the host */ 653 /* loop this OUT packet back IN to the host */
669 req->zero = (req->actual < req->length); 654 req->zero = (req->actual < req->length);
670 req->length = req->actual; 655 req->length = req->actual;
671 status = usb_ep_queue (dev->in_ep, req, GFP_ATOMIC); 656 status = usb_ep_queue(dev->in_ep, req, GFP_ATOMIC);
672 if (status == 0) 657 if (status == 0)
673 return; 658 return;
674 659
675 /* "should never get here" */ 660 /* "should never get here" */
676 ERROR (dev, "can't loop %s to %s: %d\n", 661 ERROR(dev, "can't loop %s to %s: %d\n",
677 ep->name, dev->in_ep->name, 662 ep->name, dev->in_ep->name,
678 status); 663 status);
679 } 664 }
680 665
681 /* queue the buffer for some later OUT packet */ 666 /* queue the buffer for some later OUT packet */
682 req->length = buflen; 667 req->length = buflen;
683 status = usb_ep_queue (dev->out_ep, req, GFP_ATOMIC); 668 status = usb_ep_queue(dev->out_ep, req, GFP_ATOMIC);
684 if (status == 0) 669 if (status == 0)
685 return; 670 return;
686 671
@@ -688,7 +673,7 @@ static void loopback_complete (struct usb_ep *ep, struct usb_request *req)
688 /* FALLTHROUGH */ 673 /* FALLTHROUGH */
689 674
690 default: 675 default:
691 ERROR (dev, "%s loop complete --> %d, %d/%d\n", ep->name, 676 ERROR(dev, "%s loop complete --> %d, %d/%d\n", ep->name,
692 status, req->actual, req->length); 677 status, req->actual, req->length);
693 /* FALLTHROUGH */ 678 /* FALLTHROUGH */
694 679
@@ -700,7 +685,7 @@ static void loopback_complete (struct usb_ep *ep, struct usb_request *req)
700 case -ECONNABORTED: /* hardware forced ep reset */ 685 case -ECONNABORTED: /* hardware forced ep reset */
701 case -ECONNRESET: /* request dequeued */ 686 case -ECONNRESET: /* request dequeued */
702 case -ESHUTDOWN: /* disconnect from host */ 687 case -ESHUTDOWN: /* disconnect from host */
703 free_ep_req (ep, req); 688 free_ep_req(ep, req);
704 return; 689 return;
705 } 690 }
706} 691}
@@ -711,13 +696,13 @@ static int set_loopback_config(struct zero_dev *dev)
711 struct usb_ep *ep; 696 struct usb_ep *ep;
712 struct usb_gadget *gadget = dev->gadget; 697 struct usb_gadget *gadget = dev->gadget;
713 698
714 gadget_for_each_ep (ep, gadget) { 699 gadget_for_each_ep(ep, gadget) {
715 const struct usb_endpoint_descriptor *d; 700 const struct usb_endpoint_descriptor *d;
716 701
717 /* one endpoint writes data back IN to the host */ 702 /* one endpoint writes data back IN to the host */
718 if (strcmp (ep->name, EP_IN_NAME) == 0) { 703 if (strcmp(ep->name, EP_IN_NAME) == 0) {
719 d = ep_desc (gadget, &hs_source_desc, &fs_source_desc); 704 d = ep_desc(gadget, &hs_source_desc, &fs_source_desc);
720 result = usb_ep_enable (ep, d); 705 result = usb_ep_enable(ep, d);
721 if (result == 0) { 706 if (result == 0) {
722 ep->driver_data = dev; 707 ep->driver_data = dev;
723 dev->in_ep = ep; 708 dev->in_ep = ep;
@@ -725,9 +710,9 @@ static int set_loopback_config(struct zero_dev *dev)
725 } 710 }
726 711
727 /* one endpoint just reads OUT packets */ 712 /* one endpoint just reads OUT packets */
728 } else if (strcmp (ep->name, EP_OUT_NAME) == 0) { 713 } else if (strcmp(ep->name, EP_OUT_NAME) == 0) {
729 d = ep_desc (gadget, &hs_sink_desc, &fs_sink_desc); 714 d = ep_desc(gadget, &hs_sink_desc, &fs_sink_desc);
730 result = usb_ep_enable (ep, d); 715 result = usb_ep_enable(ep, d);
731 if (result == 0) { 716 if (result == 0) {
732 ep->driver_data = dev; 717 ep->driver_data = dev;
733 dev->out_ep = ep; 718 dev->out_ep = ep;
@@ -739,7 +724,7 @@ static int set_loopback_config(struct zero_dev *dev)
739 continue; 724 continue;
740 725
741 /* stop on error */ 726 /* stop on error */
742 ERROR (dev, "can't enable %s, result %d\n", ep->name, result); 727 ERROR(dev, "can't enable %s, result %d\n", ep->name, result);
743 break; 728 break;
744 } 729 }
745 730
@@ -753,19 +738,19 @@ static int set_loopback_config(struct zero_dev *dev)
753 738
754 ep = dev->out_ep; 739 ep = dev->out_ep;
755 for (i = 0; i < qlen && result == 0; i++) { 740 for (i = 0; i < qlen && result == 0; i++) {
756 req = alloc_ep_req (ep, buflen); 741 req = alloc_ep_req(ep, buflen);
757 if (req) { 742 if (req) {
758 req->complete = loopback_complete; 743 req->complete = loopback_complete;
759 result = usb_ep_queue (ep, req, GFP_ATOMIC); 744 result = usb_ep_queue(ep, req, GFP_ATOMIC);
760 if (result) 745 if (result)
761 DBG (dev, "%s queue req --> %d\n", 746 DBG(dev, "%s queue req --> %d\n",
762 ep->name, result); 747 ep->name, result);
763 } else 748 } else
764 result = -ENOMEM; 749 result = -ENOMEM;
765 } 750 }
766 } 751 }
767 if (result == 0) 752 if (result == 0)
768 DBG (dev, "qlen %d, buflen %d\n", qlen, buflen); 753 DBG(dev, "qlen %d, buflen %d\n", qlen, buflen);
769 754
770 /* caller is responsible for cleanup on error */ 755 /* caller is responsible for cleanup on error */
771 return result; 756 return result;
@@ -773,26 +758,26 @@ static int set_loopback_config(struct zero_dev *dev)
773 758
774/*-------------------------------------------------------------------------*/ 759/*-------------------------------------------------------------------------*/
775 760
776static void zero_reset_config (struct zero_dev *dev) 761static void zero_reset_config(struct zero_dev *dev)
777{ 762{
778 if (dev->config == 0) 763 if (dev->config == 0)
779 return; 764 return;
780 765
781 DBG (dev, "reset config\n"); 766 DBG(dev, "reset config\n");
782 767
783 /* just disable endpoints, forcing completion of pending i/o. 768 /* just disable endpoints, forcing completion of pending i/o.
784 * all our completion handlers free their requests in this case. 769 * all our completion handlers free their requests in this case.
785 */ 770 */
786 if (dev->in_ep) { 771 if (dev->in_ep) {
787 usb_ep_disable (dev->in_ep); 772 usb_ep_disable(dev->in_ep);
788 dev->in_ep = NULL; 773 dev->in_ep = NULL;
789 } 774 }
790 if (dev->out_ep) { 775 if (dev->out_ep) {
791 usb_ep_disable (dev->out_ep); 776 usb_ep_disable(dev->out_ep);
792 dev->out_ep = NULL; 777 dev->out_ep = NULL;
793 } 778 }
794 dev->config = 0; 779 dev->config = 0;
795 del_timer (&dev->resume); 780 del_timer(&dev->resume);
796} 781}
797 782
798/* change our operational config. this code must agree with the code 783/* change our operational config. this code must agree with the code
@@ -813,12 +798,12 @@ static int zero_set_config(struct zero_dev *dev, unsigned number)
813 if (number == dev->config) 798 if (number == dev->config)
814 return 0; 799 return 0;
815 800
816 if (gadget_is_sa1100 (gadget) && dev->config) { 801 if (gadget_is_sa1100(gadget) && dev->config) {
817 /* tx fifo is full, but we can't clear it...*/ 802 /* tx fifo is full, but we can't clear it...*/
818 ERROR(dev, "can't change configurations\n"); 803 ERROR(dev, "can't change configurations\n");
819 return -ESPIPE; 804 return -ESPIPE;
820 } 805 }
821 zero_reset_config (dev); 806 zero_reset_config(dev);
822 807
823 switch (number) { 808 switch (number) {
824 case CONFIG_SOURCE_SINK: 809 case CONFIG_SOURCE_SINK:
@@ -837,7 +822,7 @@ static int zero_set_config(struct zero_dev *dev, unsigned number)
837 if (!result && (!dev->in_ep || !dev->out_ep)) 822 if (!result && (!dev->in_ep || !dev->out_ep))
838 result = -ENODEV; 823 result = -ENODEV;
839 if (result) 824 if (result)
840 zero_reset_config (dev); 825 zero_reset_config(dev);
841 else { 826 else {
842 char *speed; 827 char *speed;
843 828
@@ -849,7 +834,7 @@ static int zero_set_config(struct zero_dev *dev, unsigned number)
849 } 834 }
850 835
851 dev->config = number; 836 dev->config = number;
852 INFO (dev, "%s speed config #%d: %s\n", speed, number, 837 INFO(dev, "%s speed config #%d: %s\n", speed, number,
853 (number == CONFIG_SOURCE_SINK) 838 (number == CONFIG_SOURCE_SINK)
854 ? source_sink : loopback); 839 ? source_sink : loopback);
855 } 840 }
@@ -858,10 +843,10 @@ static int zero_set_config(struct zero_dev *dev, unsigned number)
858 843
859/*-------------------------------------------------------------------------*/ 844/*-------------------------------------------------------------------------*/
860 845
861static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req) 846static void zero_setup_complete(struct usb_ep *ep, struct usb_request *req)
862{ 847{
863 if (req->status || req->actual != req->length) 848 if (req->status || req->actual != req->length)
864 DBG ((struct zero_dev *) ep->driver_data, 849 DBG((struct zero_dev *) ep->driver_data,
865 "setup complete --> %d, %d/%d\n", 850 "setup complete --> %d, %d/%d\n",
866 req->status, req->actual, req->length); 851 req->status, req->actual, req->length);
867} 852}
@@ -874,9 +859,9 @@ static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req)
874 * the work is in config-specific setup. 859 * the work is in config-specific setup.
875 */ 860 */
876static int 861static int
877zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) 862zero_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
878{ 863{
879 struct zero_dev *dev = get_gadget_data (gadget); 864 struct zero_dev *dev = get_gadget_data(gadget);
880 struct usb_request *req = dev->req; 865 struct usb_request *req = dev->req;
881 int value = -EOPNOTSUPP; 866 int value = -EOPNOTSUPP;
882 u16 w_index = le16_to_cpu(ctrl->wIndex); 867 u16 w_index = le16_to_cpu(ctrl->wIndex);
@@ -895,14 +880,14 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
895 switch (w_value >> 8) { 880 switch (w_value >> 8) {
896 881
897 case USB_DT_DEVICE: 882 case USB_DT_DEVICE:
898 value = min (w_length, (u16) sizeof device_desc); 883 value = min(w_length, (u16) sizeof device_desc);
899 memcpy (req->buf, &device_desc, value); 884 memcpy(req->buf, &device_desc, value);
900 break; 885 break;
901 case USB_DT_DEVICE_QUALIFIER: 886 case USB_DT_DEVICE_QUALIFIER:
902 if (!gadget_is_dualspeed(gadget)) 887 if (!gadget_is_dualspeed(gadget))
903 break; 888 break;
904 value = min (w_length, (u16) sizeof dev_qualifier); 889 value = min(w_length, (u16) sizeof dev_qualifier);
905 memcpy (req->buf, &dev_qualifier, value); 890 memcpy(req->buf, &dev_qualifier, value);
906 break; 891 break;
907 892
908 case USB_DT_OTHER_SPEED_CONFIG: 893 case USB_DT_OTHER_SPEED_CONFIG:
@@ -910,11 +895,11 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
910 break; 895 break;
911 // FALLTHROUGH 896 // FALLTHROUGH
912 case USB_DT_CONFIG: 897 case USB_DT_CONFIG:
913 value = config_buf (gadget, req->buf, 898 value = config_buf(gadget, req->buf,
914 w_value >> 8, 899 w_value >> 8,
915 w_value & 0xff); 900 w_value & 0xff);
916 if (value >= 0) 901 if (value >= 0)
917 value = min (w_length, (u16) value); 902 value = min(w_length, (u16) value);
918 break; 903 break;
919 904
920 case USB_DT_STRING: 905 case USB_DT_STRING:
@@ -923,10 +908,10 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
923 * add string tables for other languages, using 908 * add string tables for other languages, using
924 * any UTF-8 characters 909 * any UTF-8 characters
925 */ 910 */
926 value = usb_gadget_get_string (&stringtab, 911 value = usb_gadget_get_string(&stringtab,
927 w_value & 0xff, req->buf); 912 w_value & 0xff, req->buf);
928 if (value >= 0) 913 if (value >= 0)
929 value = min (w_length, (u16) value); 914 value = min(w_length, (u16) value);
930 break; 915 break;
931 } 916 }
932 break; 917 break;
@@ -936,20 +921,20 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
936 if (ctrl->bRequestType != 0) 921 if (ctrl->bRequestType != 0)
937 goto unknown; 922 goto unknown;
938 if (gadget->a_hnp_support) 923 if (gadget->a_hnp_support)
939 DBG (dev, "HNP available\n"); 924 DBG(dev, "HNP available\n");
940 else if (gadget->a_alt_hnp_support) 925 else if (gadget->a_alt_hnp_support)
941 DBG (dev, "HNP needs a different root port\n"); 926 DBG(dev, "HNP needs a different root port\n");
942 else 927 else
943 VDBG (dev, "HNP inactive\n"); 928 VDBG(dev, "HNP inactive\n");
944 spin_lock (&dev->lock); 929 spin_lock(&dev->lock);
945 value = zero_set_config(dev, w_value); 930 value = zero_set_config(dev, w_value);
946 spin_unlock (&dev->lock); 931 spin_unlock(&dev->lock);
947 break; 932 break;
948 case USB_REQ_GET_CONFIGURATION: 933 case USB_REQ_GET_CONFIGURATION:
949 if (ctrl->bRequestType != USB_DIR_IN) 934 if (ctrl->bRequestType != USB_DIR_IN)
950 goto unknown; 935 goto unknown;
951 *(u8 *)req->buf = dev->config; 936 *(u8 *)req->buf = dev->config;
952 value = min (w_length, (u16) 1); 937 value = min(w_length, (u16) 1);
953 break; 938 break;
954 939
955 /* until we add altsetting support, or other interfaces, 940 /* until we add altsetting support, or other interfaces,
@@ -959,7 +944,7 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
959 case USB_REQ_SET_INTERFACE: 944 case USB_REQ_SET_INTERFACE:
960 if (ctrl->bRequestType != USB_RECIP_INTERFACE) 945 if (ctrl->bRequestType != USB_RECIP_INTERFACE)
961 goto unknown; 946 goto unknown;
962 spin_lock (&dev->lock); 947 spin_lock(&dev->lock);
963 if (dev->config && w_index == 0 && w_value == 0) { 948 if (dev->config && w_index == 0 && w_value == 0) {
964 u8 config = dev->config; 949 u8 config = dev->config;
965 950
@@ -970,11 +955,11 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
970 * if we had more than one interface we couldn't 955 * if we had more than one interface we couldn't
971 * use this "reset the config" shortcut. 956 * use this "reset the config" shortcut.
972 */ 957 */
973 zero_reset_config (dev); 958 zero_reset_config(dev);
974 zero_set_config(dev, config); 959 zero_set_config(dev, config);
975 value = 0; 960 value = 0;
976 } 961 }
977 spin_unlock (&dev->lock); 962 spin_unlock(&dev->lock);
978 break; 963 break;
979 case USB_REQ_GET_INTERFACE: 964 case USB_REQ_GET_INTERFACE:
980 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE)) 965 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
@@ -986,7 +971,7 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
986 break; 971 break;
987 } 972 }
988 *(u8 *)req->buf = 0; 973 *(u8 *)req->buf = 0;
989 value = min (w_length, (u16) 1); 974 value = min(w_length, (u16) 1);
990 break; 975 break;
991 976
992 /* 977 /*
@@ -1018,7 +1003,7 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1018 1003
1019 default: 1004 default:
1020unknown: 1005unknown:
1021 VDBG (dev, 1006 VDBG(dev,
1022 "unknown control req%02x.%02x v%04x i%04x l%d\n", 1007 "unknown control req%02x.%02x v%04x i%04x l%d\n",
1023 ctrl->bRequestType, ctrl->bRequest, 1008 ctrl->bRequestType, ctrl->bRequest,
1024 w_value, w_index, w_length); 1009 w_value, w_index, w_length);
@@ -1028,11 +1013,11 @@ unknown:
1028 if (value >= 0) { 1013 if (value >= 0) {
1029 req->length = value; 1014 req->length = value;
1030 req->zero = value < w_length; 1015 req->zero = value < w_length;
1031 value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC); 1016 value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
1032 if (value < 0) { 1017 if (value < 0) {
1033 DBG (dev, "ep_queue --> %d\n", value); 1018 DBG(dev, "ep_queue --> %d\n", value);
1034 req->status = 0; 1019 req->status = 0;
1035 zero_setup_complete (gadget->ep0, req); 1020 zero_setup_complete(gadget->ep0, req);
1036 } 1021 }
1037 } 1022 }
1038 1023
@@ -1040,28 +1025,26 @@ unknown:
1040 return value; 1025 return value;
1041} 1026}
1042 1027
1043static void 1028static void zero_disconnect(struct usb_gadget *gadget)
1044zero_disconnect (struct usb_gadget *gadget)
1045{ 1029{
1046 struct zero_dev *dev = get_gadget_data (gadget); 1030 struct zero_dev *dev = get_gadget_data(gadget);
1047 unsigned long flags; 1031 unsigned long flags;
1048 1032
1049 spin_lock_irqsave (&dev->lock, flags); 1033 spin_lock_irqsave(&dev->lock, flags);
1050 zero_reset_config (dev); 1034 zero_reset_config(dev);
1051 1035
1052 /* a more significant application might have some non-usb 1036 /* a more significant application might have some non-usb
1053 * activities to quiesce here, saving resources like power 1037 * activities to quiesce here, saving resources like power
1054 * or pushing the notification up a network stack. 1038 * or pushing the notification up a network stack.
1055 */ 1039 */
1056 spin_unlock_irqrestore (&dev->lock, flags); 1040 spin_unlock_irqrestore(&dev->lock, flags);
1057 1041
1058 /* next we may get setup() calls to enumerate new connections; 1042 /* next we may get setup() calls to enumerate new connections;
1059 * or an unbind() during shutdown (including removing module). 1043 * or an unbind() during shutdown (including removing module).
1060 */ 1044 */
1061} 1045}
1062 1046
1063static void 1047static void zero_autoresume(unsigned long _dev)
1064zero_autoresume (unsigned long _dev)
1065{ 1048{
1066 struct zero_dev *dev = (struct zero_dev *) _dev; 1049 struct zero_dev *dev = (struct zero_dev *) _dev;
1067 int status; 1050 int status;
@@ -1070,32 +1053,30 @@ zero_autoresume (unsigned long _dev)
1070 * more significant than just a timer firing... 1053 * more significant than just a timer firing...
1071 */ 1054 */
1072 if (dev->gadget->speed != USB_SPEED_UNKNOWN) { 1055 if (dev->gadget->speed != USB_SPEED_UNKNOWN) {
1073 status = usb_gadget_wakeup (dev->gadget); 1056 status = usb_gadget_wakeup(dev->gadget);
1074 DBG (dev, "wakeup --> %d\n", status); 1057 DBG(dev, "wakeup --> %d\n", status);
1075 } 1058 }
1076} 1059}
1077 1060
1078/*-------------------------------------------------------------------------*/ 1061/*-------------------------------------------------------------------------*/
1079 1062
1080static void /* __init_or_exit */ 1063static void zero_unbind(struct usb_gadget *gadget)
1081zero_unbind (struct usb_gadget *gadget)
1082{ 1064{
1083 struct zero_dev *dev = get_gadget_data (gadget); 1065 struct zero_dev *dev = get_gadget_data(gadget);
1084 1066
1085 DBG (dev, "unbind\n"); 1067 DBG(dev, "unbind\n");
1086 1068
1087 /* we've already been disconnected ... no i/o is active */ 1069 /* we've already been disconnected ... no i/o is active */
1088 if (dev->req) { 1070 if (dev->req) {
1089 dev->req->length = USB_BUFSIZ; 1071 dev->req->length = USB_BUFSIZ;
1090 free_ep_req (gadget->ep0, dev->req); 1072 free_ep_req(gadget->ep0, dev->req);
1091 } 1073 }
1092 del_timer_sync (&dev->resume); 1074 del_timer_sync(&dev->resume);
1093 kfree (dev); 1075 kfree(dev);
1094 set_gadget_data (gadget, NULL); 1076 set_gadget_data(gadget, NULL);
1095} 1077}
1096 1078
1097static int __init 1079static int __init zero_bind(struct usb_gadget *gadget)
1098zero_bind (struct usb_gadget *gadget)
1099{ 1080{
1100 struct zero_dev *dev; 1081 struct zero_dev *dev;
1101 struct usb_ep *ep; 1082 struct usb_ep *ep;
@@ -1111,8 +1092,8 @@ zero_bind (struct usb_gadget *gadget)
1111 * autoconfigure on any sane usb controller driver, 1092 * autoconfigure on any sane usb controller driver,
1112 * but there may also be important quirks to address. 1093 * but there may also be important quirks to address.
1113 */ 1094 */
1114 usb_ep_autoconfig_reset (gadget); 1095 usb_ep_autoconfig_reset(gadget);
1115 ep = usb_ep_autoconfig (gadget, &fs_source_desc); 1096 ep = usb_ep_autoconfig(gadget, &fs_source_desc);
1116 if (!ep) { 1097 if (!ep) {
1117autoconf_fail: 1098autoconf_fail:
1118 pr_err("%s: can't autoconfigure on %s\n", 1099 pr_err("%s: can't autoconfigure on %s\n",
@@ -1122,15 +1103,15 @@ autoconf_fail:
1122 EP_IN_NAME = ep->name; 1103 EP_IN_NAME = ep->name;
1123 ep->driver_data = ep; /* claim */ 1104 ep->driver_data = ep; /* claim */
1124 1105
1125 ep = usb_ep_autoconfig (gadget, &fs_sink_desc); 1106 ep = usb_ep_autoconfig(gadget, &fs_sink_desc);
1126 if (!ep) 1107 if (!ep)
1127 goto autoconf_fail; 1108 goto autoconf_fail;
1128 EP_OUT_NAME = ep->name; 1109 EP_OUT_NAME = ep->name;
1129 ep->driver_data = ep; /* claim */ 1110 ep->driver_data = ep; /* claim */
1130 1111
1131 gcnum = usb_gadget_controller_number (gadget); 1112 gcnum = usb_gadget_controller_number(gadget);
1132 if (gcnum >= 0) 1113 if (gcnum >= 0)
1133 device_desc.bcdDevice = cpu_to_le16 (0x0200 + gcnum); 1114 device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
1134 else { 1115 else {
1135 /* gadget zero is so simple (for now, no altsettings) that 1116 /* gadget zero is so simple (for now, no altsettings) that
1136 * it SHOULD NOT have problems with bulk-capable hardware. 1117 * it SHOULD NOT have problems with bulk-capable hardware.
@@ -1141,7 +1122,7 @@ autoconf_fail:
1141 */ 1122 */
1142 pr_warning("%s: controller '%s' not recognized\n", 1123 pr_warning("%s: controller '%s' not recognized\n",
1143 shortname, gadget->name); 1124 shortname, gadget->name);
1144 device_desc.bcdDevice = __constant_cpu_to_le16 (0x9999); 1125 device_desc.bcdDevice = __constant_cpu_to_le16(0x9999);
1145 } 1126 }
1146 1127
1147 1128
@@ -1149,12 +1130,16 @@ autoconf_fail:
1149 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 1130 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1150 if (!dev) 1131 if (!dev)
1151 return -ENOMEM; 1132 return -ENOMEM;
1152 spin_lock_init (&dev->lock); 1133 spin_lock_init(&dev->lock);
1153 dev->gadget = gadget; 1134 dev->gadget = gadget;
1154 set_gadget_data (gadget, dev); 1135 set_gadget_data(gadget, dev);
1136
1137 init_timer(&dev->resume);
1138 dev->resume.function = zero_autoresume;
1139 dev->resume.data = (unsigned long) dev;
1155 1140
1156 /* preallocate control response and buffer */ 1141 /* preallocate control response and buffer */
1157 dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL); 1142 dev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL);
1158 if (!dev->req) 1143 if (!dev->req)
1159 goto enomem; 1144 goto enomem;
1160 dev->req->buf = kmalloc(USB_BUFSIZ, GFP_KERNEL); 1145 dev->req->buf = kmalloc(USB_BUFSIZ, GFP_KERNEL);
@@ -1182,11 +1167,8 @@ autoconf_fail:
1182 loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 1167 loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1183 } 1168 }
1184 1169
1185 usb_gadget_set_selfpowered (gadget); 1170 usb_gadget_set_selfpowered(gadget);
1186 1171
1187 init_timer (&dev->resume);
1188 dev->resume.function = zero_autoresume;
1189 dev->resume.data = (unsigned long) dev;
1190 if (autoresume) { 1172 if (autoresume) {
1191 source_sink_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 1173 source_sink_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
1192 loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 1174 loopback_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
@@ -1194,45 +1176,43 @@ autoconf_fail:
1194 1176
1195 gadget->ep0->driver_data = dev; 1177 gadget->ep0->driver_data = dev;
1196 1178
1197 INFO (dev, "%s, version: " DRIVER_VERSION "\n", longname); 1179 INFO(dev, "%s, version: " DRIVER_VERSION "\n", longname);
1198 INFO (dev, "using %s, OUT %s IN %s\n", gadget->name, 1180 INFO(dev, "using %s, OUT %s IN %s\n", gadget->name,
1199 EP_OUT_NAME, EP_IN_NAME); 1181 EP_OUT_NAME, EP_IN_NAME);
1200 1182
1201 snprintf (manufacturer, sizeof manufacturer, "%s %s with %s", 1183 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
1202 init_utsname()->sysname, init_utsname()->release, 1184 init_utsname()->sysname, init_utsname()->release,
1203 gadget->name); 1185 gadget->name);
1204 1186
1205 return 0; 1187 return 0;
1206 1188
1207enomem: 1189enomem:
1208 zero_unbind (gadget); 1190 zero_unbind(gadget);
1209 return -ENOMEM; 1191 return -ENOMEM;
1210} 1192}
1211 1193
1212/*-------------------------------------------------------------------------*/ 1194/*-------------------------------------------------------------------------*/
1213 1195
1214static void 1196static void zero_suspend(struct usb_gadget *gadget)
1215zero_suspend (struct usb_gadget *gadget)
1216{ 1197{
1217 struct zero_dev *dev = get_gadget_data (gadget); 1198 struct zero_dev *dev = get_gadget_data(gadget);
1218 1199
1219 if (gadget->speed == USB_SPEED_UNKNOWN) 1200 if (gadget->speed == USB_SPEED_UNKNOWN)
1220 return; 1201 return;
1221 1202
1222 if (autoresume) { 1203 if (autoresume) {
1223 mod_timer (&dev->resume, jiffies + (HZ * autoresume)); 1204 mod_timer(&dev->resume, jiffies + (HZ * autoresume));
1224 DBG (dev, "suspend, wakeup in %d seconds\n", autoresume); 1205 DBG(dev, "suspend, wakeup in %d seconds\n", autoresume);
1225 } else 1206 } else
1226 DBG (dev, "suspend\n"); 1207 DBG(dev, "suspend\n");
1227} 1208}
1228 1209
1229static void 1210static void zero_resume(struct usb_gadget *gadget)
1230zero_resume (struct usb_gadget *gadget)
1231{ 1211{
1232 struct zero_dev *dev = get_gadget_data (gadget); 1212 struct zero_dev *dev = get_gadget_data(gadget);
1233 1213
1234 DBG (dev, "resume\n"); 1214 DBG(dev, "resume\n");
1235 del_timer (&dev->resume); 1215 del_timer(&dev->resume);
1236} 1216}
1237 1217
1238 1218
@@ -1264,15 +1244,15 @@ MODULE_AUTHOR("David Brownell");
1264MODULE_LICENSE("GPL"); 1244MODULE_LICENSE("GPL");
1265 1245
1266 1246
1267static int __init init (void) 1247static int __init init(void)
1268{ 1248{
1269 return usb_gadget_register_driver (&zero_driver); 1249 return usb_gadget_register_driver(&zero_driver);
1270} 1250}
1271module_init (init); 1251module_init(init);
1272 1252
1273static void __exit cleanup (void) 1253static void __exit cleanup(void)
1274{ 1254{
1275 usb_gadget_unregister_driver (&zero_driver); 1255 usb_gadget_unregister_driver(&zero_driver);
1276} 1256}
1277module_exit (cleanup); 1257module_exit(cleanup);
1278 1258
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 0b87480dd713..33b467a8352d 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -4,6 +4,19 @@
4comment "USB Host Controller Drivers" 4comment "USB Host Controller Drivers"
5 depends on USB 5 depends on USB
6 6
7config USB_C67X00_HCD
8 tristate "Cypress C67x00 HCD support"
9 depends on USB
10 help
11 The Cypress C67x00 (EZ-Host/EZ-OTG) chips are dual-role
12 host/peripheral/OTG USB controllers.
13
14 Enable this option to support this chip in host controller mode.
15 If unsure, say N.
16
17 To compile this driver as a module, choose M here: the
18 module will be called c67x00.
19
7config USB_EHCI_HCD 20config USB_EHCI_HCD
8 tristate "EHCI HCD (USB 2.0) support" 21 tristate "EHCI HCD (USB 2.0) support"
9 depends on USB && USB_ARCH_HAS_EHCI 22 depends on USB && USB_ARCH_HAS_EHCI
@@ -95,6 +108,32 @@ config USB_ISP116X_HCD
95 To compile this driver as a module, choose M here: the 108 To compile this driver as a module, choose M here: the
96 module will be called isp116x-hcd. 109 module will be called isp116x-hcd.
97 110
111config USB_ISP1760_HCD
112 tristate "ISP 1760 HCD support"
113 depends on USB && EXPERIMENTAL
114 ---help---
115 The ISP1760 chip is a USB 2.0 host controller.
116
117 This driver does not support isochronous transfers or OTG.
118
119 To compile this driver as a module, choose M here: the
120 module will be called isp1760-hcd.
121
122config USB_ISP1760_PCI
123 bool "Support for the PCI bus"
124 depends on USB_ISP1760_HCD && PCI
125 ---help---
126 Enables support for the device present on the PCI bus.
127 This should only be required if you happen to have the eval kit from
128 NXP and you are going to test it.
129
130config USB_ISP1760_OF
131 bool "Support for the OF platform bus"
132 depends on USB_ISP1760_HCD && OF
133 ---help---
134 Enables support for the device present on the PowerPC
135 OpenFirmware platform bus.
136
98config USB_OHCI_HCD 137config USB_OHCI_HCD
99 tristate "OHCI HCD support" 138 tristate "OHCI HCD support"
100 depends on USB && USB_ARCH_HAS_OHCI 139 depends on USB && USB_ARCH_HAS_OHCI
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index bb8e9d44f371..f1edda2dcfde 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -6,6 +6,8 @@ ifeq ($(CONFIG_USB_DEBUG),y)
6 EXTRA_CFLAGS += -DDEBUG 6 EXTRA_CFLAGS += -DDEBUG
7endif 7endif
8 8
9isp1760-objs := isp1760-hcd.o isp1760-if.o
10
9obj-$(CONFIG_PCI) += pci-quirks.o 11obj-$(CONFIG_PCI) += pci-quirks.o
10 12
11obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o 13obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o
@@ -16,4 +18,4 @@ obj-$(CONFIG_USB_SL811_HCD) += sl811-hcd.o
16obj-$(CONFIG_USB_SL811_CS) += sl811_cs.o 18obj-$(CONFIG_USB_SL811_CS) += sl811_cs.o
17obj-$(CONFIG_USB_U132_HCD) += u132-hcd.o 19obj-$(CONFIG_USB_U132_HCD) += u132-hcd.o
18obj-$(CONFIG_USB_R8A66597_HCD) += r8a66597-hcd.o 20obj-$(CONFIG_USB_R8A66597_HCD) += r8a66597-hcd.o
19 21obj-$(CONFIG_USB_ISP1760_HCD) += isp1760.o
diff --git a/drivers/usb/host/isp1760-hcd.c b/drivers/usb/host/isp1760-hcd.c
new file mode 100644
index 000000000000..4ba96c1e060c
--- /dev/null
+++ b/drivers/usb/host/isp1760-hcd.c
@@ -0,0 +1,2231 @@
1/*
2 * Driver for the NXP ISP1760 chip
3 *
4 * However, the code might contain some bugs. What doesn't work for sure is:
5 * - ISO
6 * - OTG
7 e The interrupt line is configured as active low, level.
8 *
9 * (c) 2007 Sebastian Siewior <bigeasy@linutronix.de>
10 *
11 */
12#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/slab.h>
15#include <linux/list.h>
16#include <linux/usb.h>
17#include <linux/debugfs.h>
18#include <linux/uaccess.h>
19#include <linux/io.h>
20#include <asm/unaligned.h>
21
22#include "../core/hcd.h"
23#include "isp1760-hcd.h"
24
25static struct kmem_cache *qtd_cachep;
26static struct kmem_cache *qh_cachep;
27
28struct isp1760_hcd {
29 u32 hcs_params;
30 spinlock_t lock;
31 struct inter_packet_info atl_ints[32];
32 struct inter_packet_info int_ints[32];
33 struct memory_chunk memory_pool[BLOCKS];
34
35 /* periodic schedule support */
36#define DEFAULT_I_TDPS 1024
37 unsigned periodic_size;
38 unsigned i_thresh;
39 unsigned long reset_done;
40 unsigned long next_statechange;
41};
42
43static inline struct isp1760_hcd *hcd_to_priv(struct usb_hcd *hcd)
44{
45 return (struct isp1760_hcd *) (hcd->hcd_priv);
46}
47static inline struct usb_hcd *priv_to_hcd(struct isp1760_hcd *priv)
48{
49 return container_of((void *) priv, struct usb_hcd, hcd_priv);
50}
51
52/* Section 2.2 Host Controller Capability Registers */
53#define HC_LENGTH(p) (((p)>>00)&0x00ff) /* bits 7:0 */
54#define HC_VERSION(p) (((p)>>16)&0xffff) /* bits 31:16 */
55#define HCS_INDICATOR(p) ((p)&(1 << 16)) /* true: has port indicators */
56#define HCS_PPC(p) ((p)&(1 << 4)) /* true: port power control */
57#define HCS_N_PORTS(p) (((p)>>0)&0xf) /* bits 3:0, ports on HC */
58#define HCC_ISOC_CACHE(p) ((p)&(1 << 7)) /* true: can cache isoc frame */
59#define HCC_ISOC_THRES(p) (((p)>>4)&0x7) /* bits 6:4, uframes cached */
60
61/* Section 2.3 Host Controller Operational Registers */
62#define CMD_LRESET (1<<7) /* partial reset (no ports, etc) */
63#define CMD_RESET (1<<1) /* reset HC not bus */
64#define CMD_RUN (1<<0) /* start/stop HC */
65#define STS_PCD (1<<2) /* port change detect */
66#define FLAG_CF (1<<0) /* true: we'll support "high speed" */
67
68#define PORT_OWNER (1<<13) /* true: companion hc owns this port */
69#define PORT_POWER (1<<12) /* true: has power (see PPC) */
70#define PORT_USB11(x) (((x) & (3 << 10)) == (1 << 10)) /* USB 1.1 device */
71#define PORT_RESET (1<<8) /* reset port */
72#define PORT_SUSPEND (1<<7) /* suspend port */
73#define PORT_RESUME (1<<6) /* resume it */
74#define PORT_PE (1<<2) /* port enable */
75#define PORT_CSC (1<<1) /* connect status change */
76#define PORT_CONNECT (1<<0) /* device connected */
77#define PORT_RWC_BITS (PORT_CSC)
78
79struct isp1760_qtd {
80 struct isp1760_qtd *hw_next;
81 u8 packet_type;
82 u8 toggle;
83
84 void *data_buffer;
85 /* the rest is HCD-private */
86 struct list_head qtd_list;
87 struct urb *urb;
88 size_t length;
89
90 /* isp special*/
91 u32 status;
92#define URB_COMPLETE_NOTIFY (1 << 0)
93#define URB_ENQUEUED (1 << 1)
94#define URB_TYPE_ATL (1 << 2)
95#define URB_TYPE_INT (1 << 3)
96};
97
98struct isp1760_qh {
99 /* first part defined by EHCI spec */
100 struct list_head qtd_list;
101 struct isp1760_hcd *priv;
102
103 /* periodic schedule info */
104 unsigned short period; /* polling interval */
105 struct usb_device *dev;
106
107 u32 toggle;
108 u32 ping;
109};
110
111#define ehci_port_speed(priv, portsc) (1 << USB_PORT_FEAT_HIGHSPEED)
112
113static unsigned int isp1760_readl(__u32 __iomem *regs)
114{
115 return readl(regs);
116}
117
118static void isp1760_writel(const unsigned int val, __u32 __iomem *regs)
119{
120 writel(val, regs);
121}
122
123/*
124 * The next two copy via MMIO data to/from the device. memcpy_{to|from}io()
125 * doesn't quite work because some people have to enforce 32-bit access
126 */
127static void priv_read_copy(struct isp1760_hcd *priv, u32 *src,
128 __u32 __iomem *dst, u32 offset, u32 len)
129{
130 struct usb_hcd *hcd = priv_to_hcd(priv);
131 u32 val;
132 u8 *buff8;
133
134 if (!src) {
135 printk(KERN_ERR "ERROR: buffer: %p len: %d\n", src, len);
136 return;
137 }
138 isp1760_writel(offset, hcd->regs + HC_MEMORY_REG);
139 /* XXX
140 * 90nsec delay, the spec says something how this could be avoided.
141 */
142 mdelay(1);
143
144 while (len >= 4) {
145 *src = __raw_readl(dst);
146 len -= 4;
147 src++;
148 dst++;
149 }
150
151 if (!len)
152 return;
153
154 /* in case we have 3, 2 or 1 by left. The dst buffer may not be fully
155 * allocated.
156 */
157 val = isp1760_readl(dst);
158
159 buff8 = (u8 *)src;
160 while (len) {
161
162 *buff8 = val;
163 val >>= 8;
164 len--;
165 buff8++;
166 }
167}
168
169static void priv_write_copy(const struct isp1760_hcd *priv, const u32 *src,
170 __u32 __iomem *dst, u32 len)
171{
172 while (len >= 4) {
173 __raw_writel(*src, dst);
174 len -= 4;
175 src++;
176 dst++;
177 }
178
179 if (!len)
180 return;
181 /* in case we have 3, 2 or 1 by left. The buffer is allocated and the
182 * extra bytes should not be read by the HW
183 */
184
185 __raw_writel(*src, dst);
186}
187
188/* memory management of the 60kb on the chip from 0x1000 to 0xffff */
189static void init_memory(struct isp1760_hcd *priv)
190{
191 int i;
192 u32 payload;
193
194 payload = 0x1000;
195 for (i = 0; i < BLOCK_1_NUM; i++) {
196 priv->memory_pool[i].start = payload;
197 priv->memory_pool[i].size = BLOCK_1_SIZE;
198 priv->memory_pool[i].free = 1;
199 payload += priv->memory_pool[i].size;
200 }
201
202
203 for (i = BLOCK_1_NUM; i < BLOCK_1_NUM + BLOCK_2_NUM; i++) {
204 priv->memory_pool[i].start = payload;
205 priv->memory_pool[i].size = BLOCK_2_SIZE;
206 priv->memory_pool[i].free = 1;
207 payload += priv->memory_pool[i].size;
208 }
209
210
211 for (i = BLOCK_1_NUM + BLOCK_2_NUM; i < BLOCKS; i++) {
212 priv->memory_pool[i].start = payload;
213 priv->memory_pool[i].size = BLOCK_3_SIZE;
214 priv->memory_pool[i].free = 1;
215 payload += priv->memory_pool[i].size;
216 }
217
218 BUG_ON(payload - priv->memory_pool[i - 1].size > PAYLOAD_SIZE);
219}
220
221static u32 alloc_mem(struct isp1760_hcd *priv, u32 size)
222{
223 int i;
224
225 if (!size)
226 return ISP1760_NULL_POINTER;
227
228 for (i = 0; i < BLOCKS; i++) {
229 if (priv->memory_pool[i].size >= size &&
230 priv->memory_pool[i].free) {
231
232 priv->memory_pool[i].free = 0;
233 return priv->memory_pool[i].start;
234 }
235 }
236
237 printk(KERN_ERR "ISP1760 MEM: can not allocate %d bytes of memory\n",
238 size);
239 printk(KERN_ERR "Current memory map:\n");
240 for (i = 0; i < BLOCKS; i++) {
241 printk(KERN_ERR "Pool %2d size %4d status: %d\n",
242 i, priv->memory_pool[i].size,
243 priv->memory_pool[i].free);
244 }
245 /* XXX maybe -ENOMEM could be possible */
246 BUG();
247 return 0;
248}
249
250static void free_mem(struct isp1760_hcd *priv, u32 mem)
251{
252 int i;
253
254 if (mem == ISP1760_NULL_POINTER)
255 return;
256
257 for (i = 0; i < BLOCKS; i++) {
258 if (priv->memory_pool[i].start == mem) {
259
260 BUG_ON(priv->memory_pool[i].free);
261
262 priv->memory_pool[i].free = 1;
263 return ;
264 }
265 }
266
267 printk(KERN_ERR "Trying to free not-here-allocated memory :%08x\n",
268 mem);
269 BUG();
270}
271
272static void isp1760_init_regs(struct usb_hcd *hcd)
273{
274 isp1760_writel(0, hcd->regs + HC_BUFFER_STATUS_REG);
275 isp1760_writel(NO_TRANSFER_ACTIVE, hcd->regs +
276 HC_ATL_PTD_SKIPMAP_REG);
277 isp1760_writel(NO_TRANSFER_ACTIVE, hcd->regs +
278 HC_INT_PTD_SKIPMAP_REG);
279 isp1760_writel(NO_TRANSFER_ACTIVE, hcd->regs +
280 HC_ISO_PTD_SKIPMAP_REG);
281
282 isp1760_writel(~NO_TRANSFER_ACTIVE, hcd->regs +
283 HC_ATL_PTD_DONEMAP_REG);
284 isp1760_writel(~NO_TRANSFER_ACTIVE, hcd->regs +
285 HC_INT_PTD_DONEMAP_REG);
286 isp1760_writel(~NO_TRANSFER_ACTIVE, hcd->regs +
287 HC_ISO_PTD_DONEMAP_REG);
288}
289
290static int handshake(struct isp1760_hcd *priv, void __iomem *ptr,
291 u32 mask, u32 done, int usec)
292{
293 u32 result;
294
295 do {
296 result = isp1760_readl(ptr);
297 if (result == ~0)
298 return -ENODEV;
299 result &= mask;
300 if (result == done)
301 return 0;
302 udelay(1);
303 usec--;
304 } while (usec > 0);
305 return -ETIMEDOUT;
306}
307
308/* reset a non-running (STS_HALT == 1) controller */
309static int ehci_reset(struct isp1760_hcd *priv)
310{
311 int retval;
312 struct usb_hcd *hcd = priv_to_hcd(priv);
313 u32 command = isp1760_readl(hcd->regs + HC_USBCMD);
314
315 command |= CMD_RESET;
316 isp1760_writel(command, hcd->regs + HC_USBCMD);
317 hcd->state = HC_STATE_HALT;
318 priv->next_statechange = jiffies;
319 retval = handshake(priv, hcd->regs + HC_USBCMD,
320 CMD_RESET, 0, 250 * 1000);
321 return retval;
322}
323
324static void qh_destroy(struct isp1760_qh *qh)
325{
326 BUG_ON(!list_empty(&qh->qtd_list));
327 kmem_cache_free(qh_cachep, qh);
328}
329
330static struct isp1760_qh *isp1760_qh_alloc(struct isp1760_hcd *priv,
331 gfp_t flags)
332{
333 struct isp1760_qh *qh;
334
335 qh = kmem_cache_zalloc(qh_cachep, flags);
336 if (!qh)
337 return qh;
338
339 INIT_LIST_HEAD(&qh->qtd_list);
340 qh->priv = priv;
341 return qh;
342}
343
344/* magic numbers that can affect system performance */
345#define EHCI_TUNE_CERR 3 /* 0-3 qtd retries; 0 == don't stop */
346#define EHCI_TUNE_RL_HS 4 /* nak throttle; see 4.9 */
347#define EHCI_TUNE_RL_TT 0
348#define EHCI_TUNE_MULT_HS 1 /* 1-3 transactions/uframe; 4.10.3 */
349#define EHCI_TUNE_MULT_TT 1
350#define EHCI_TUNE_FLS 2 /* (small) 256 frame schedule */
351
352/* one-time init, only for memory state */
353static int priv_init(struct usb_hcd *hcd)
354{
355 struct isp1760_hcd *priv = hcd_to_priv(hcd);
356 u32 hcc_params;
357
358 spin_lock_init(&priv->lock);
359
360 /*
361 * hw default: 1K periodic list heads, one per frame.
362 * periodic_size can shrink by USBCMD update if hcc_params allows.
363 */
364 priv->periodic_size = DEFAULT_I_TDPS;
365
366 /* controllers may cache some of the periodic schedule ... */
367 hcc_params = isp1760_readl(hcd->regs + HC_HCCPARAMS);
368 /* full frame cache */
369 if (HCC_ISOC_CACHE(hcc_params))
370 priv->i_thresh = 8;
371 else /* N microframes cached */
372 priv->i_thresh = 2 + HCC_ISOC_THRES(hcc_params);
373
374 return 0;
375}
376
377static int isp1760_hc_setup(struct usb_hcd *hcd)
378{
379 struct isp1760_hcd *priv = hcd_to_priv(hcd);
380 int result;
381 u32 scratch;
382
383 isp1760_writel(0xdeadbabe, hcd->regs + HC_SCRATCH_REG);
384 scratch = isp1760_readl(hcd->regs + HC_SCRATCH_REG);
385 if (scratch != 0xdeadbabe) {
386 printk(KERN_ERR "ISP1760: Scratch test failed.\n");
387 return -ENODEV;
388 }
389
390 /* pre reset */
391 isp1760_init_regs(hcd);
392
393 /* reset */
394 isp1760_writel(SW_RESET_RESET_ALL, hcd->regs + HC_RESET_REG);
395 mdelay(100);
396
397 isp1760_writel(SW_RESET_RESET_HC, hcd->regs + HC_RESET_REG);
398 mdelay(100);
399
400 result = ehci_reset(priv);
401 if (result)
402 return result;
403
404 /* Step 11 passed */
405
406 isp1760_writel(INTERRUPT_ENABLE_MASK, hcd->regs + HC_INTERRUPT_REG);
407 isp1760_writel(INTERRUPT_ENABLE_MASK, hcd->regs + HC_INTERRUPT_ENABLE);
408
409 /* ATL reset */
410 scratch = isp1760_readl(hcd->regs + HC_HW_MODE_CTRL);
411 isp1760_writel(scratch | ALL_ATX_RESET, hcd->regs + HC_HW_MODE_CTRL);
412 mdelay(10);
413 isp1760_writel(scratch, hcd->regs + HC_HW_MODE_CTRL);
414
415 isp1760_writel(PORT1_POWER | PORT1_INIT2, hcd->regs + HC_PORT1_CTRL);
416 mdelay(10);
417
418 priv->hcs_params = isp1760_readl(hcd->regs + HC_HCSPARAMS);
419
420 return priv_init(hcd);
421}
422
423static void isp1760_init_maps(struct usb_hcd *hcd)
424{
425 /*set last maps, for iso its only 1, else 32 tds bitmap*/
426 isp1760_writel(0x80000000, hcd->regs + HC_ATL_PTD_LASTPTD_REG);
427 isp1760_writel(0x80000000, hcd->regs + HC_INT_PTD_LASTPTD_REG);
428 isp1760_writel(0x00000001, hcd->regs + HC_ISO_PTD_LASTPTD_REG);
429}
430
431static void isp1760_enable_interrupts(struct usb_hcd *hcd)
432{
433 isp1760_writel(0, hcd->regs + HC_ATL_IRQ_MASK_AND_REG);
434 isp1760_writel(0, hcd->regs + HC_ATL_IRQ_MASK_OR_REG);
435 isp1760_writel(0, hcd->regs + HC_INT_IRQ_MASK_AND_REG);
436 isp1760_writel(0, hcd->regs + HC_INT_IRQ_MASK_OR_REG);
437 isp1760_writel(0, hcd->regs + HC_ISO_IRQ_MASK_AND_REG);
438 isp1760_writel(0xffffffff, hcd->regs + HC_ISO_IRQ_MASK_OR_REG);
439 /* step 23 passed */
440}
441
442static int isp1760_run(struct usb_hcd *hcd)
443{
444 struct isp1760_hcd *priv = hcd_to_priv(hcd);
445 int retval;
446 u32 temp;
447 u32 command;
448 u32 chipid;
449
450 hcd->uses_new_polling = 1;
451 hcd->poll_rh = 0;
452
453 hcd->state = HC_STATE_RUNNING;
454 isp1760_enable_interrupts(hcd);
455 temp = isp1760_readl(hcd->regs + HC_HW_MODE_CTRL);
456 temp |= FINAL_HW_CONFIG;
457 isp1760_writel(temp, hcd->regs + HC_HW_MODE_CTRL);
458
459 command = isp1760_readl(hcd->regs + HC_USBCMD);
460 command &= ~(CMD_LRESET|CMD_RESET);
461 command |= CMD_RUN;
462 isp1760_writel(command, hcd->regs + HC_USBCMD);
463
464 retval = handshake(priv, hcd->regs + HC_USBCMD, CMD_RUN, CMD_RUN,
465 250 * 1000);
466 if (retval)
467 return retval;
468
469 /*
470 * XXX
471 * Spec says to write FLAG_CF as last config action, priv code grabs
472 * the semaphore while doing so.
473 */
474 down_write(&ehci_cf_port_reset_rwsem);
475 isp1760_writel(FLAG_CF, hcd->regs + HC_CONFIGFLAG);
476
477 retval = handshake(priv, hcd->regs + HC_CONFIGFLAG, FLAG_CF, FLAG_CF,
478 250 * 1000);
479 up_write(&ehci_cf_port_reset_rwsem);
480 if (retval)
481 return retval;
482
483 chipid = isp1760_readl(hcd->regs + HC_CHIP_ID_REG);
484 isp1760_info(priv, "USB ISP %04x HW rev. %d started\n", chipid & 0xffff,
485 chipid >> 16);
486
487 /* PTD Register Init Part 2, Step 28 */
488 /* enable INTs */
489 isp1760_init_maps(hcd);
490
491 /* GRR this is run-once init(), being done every time the HC starts.
492 * So long as they're part of class devices, we can't do it init()
493 * since the class device isn't created that early.
494 */
495 return 0;
496}
497
498static u32 base_to_chip(u32 base)
499{
500 return ((base - 0x400) >> 3);
501}
502
503static void transform_into_atl(struct isp1760_hcd *priv, struct isp1760_qh *qh,
504 struct isp1760_qtd *qtd, struct urb *urb,
505 u32 payload, struct ptd *ptd)
506{
507 u32 dw0;
508 u32 dw1;
509 u32 dw2;
510 u32 dw3;
511 u32 maxpacket;
512 u32 multi;
513 u32 pid_code;
514 u32 rl = RL_COUNTER;
515 u32 nak = NAK_COUNTER;
516
517 /* according to 3.6.2, max packet len can not be > 0x400 */
518 maxpacket = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe));
519 multi = 1 + ((maxpacket >> 11) & 0x3);
520 maxpacket &= 0x7ff;
521
522 /* DW0 */
523 dw0 = PTD_VALID;
524 dw0 |= PTD_LENGTH(qtd->length);
525 dw0 |= PTD_MAXPACKET(maxpacket);
526 dw0 |= PTD_ENDPOINT(usb_pipeendpoint(urb->pipe));
527 dw1 = usb_pipeendpoint(urb->pipe) >> 1;
528
529 /* DW1 */
530 dw1 |= PTD_DEVICE_ADDR(usb_pipedevice(urb->pipe));
531
532 pid_code = qtd->packet_type;
533 dw1 |= PTD_PID_TOKEN(pid_code);
534
535 if (usb_pipebulk(urb->pipe))
536 dw1 |= PTD_TRANS_BULK;
537 else if (usb_pipeint(urb->pipe))
538 dw1 |= PTD_TRANS_INT;
539
540 if (urb->dev->speed != USB_SPEED_HIGH) {
541 /* split transaction */
542
543 dw1 |= PTD_TRANS_SPLIT;
544 if (urb->dev->speed == USB_SPEED_LOW)
545 dw1 |= PTD_SE_USB_LOSPEED;
546
547 dw1 |= PTD_PORT_NUM(urb->dev->ttport);
548 dw1 |= PTD_HUB_NUM(urb->dev->tt->hub->devnum);
549
550 /* SE bit for Split INT transfers */
551 if (usb_pipeint(urb->pipe) &&
552 (urb->dev->speed == USB_SPEED_LOW))
553 dw1 |= 2 << 16;
554
555 dw3 = 0;
556 rl = 0;
557 nak = 0;
558 } else {
559 dw0 |= PTD_MULTI(multi);
560 if (usb_pipecontrol(urb->pipe) || usb_pipebulk(urb->pipe))
561 dw3 = qh->ping;
562 else
563 dw3 = 0;
564 }
565 /* DW2 */
566 dw2 = 0;
567 dw2 |= PTD_DATA_START_ADDR(base_to_chip(payload));
568 dw2 |= PTD_RL_CNT(rl);
569 dw3 |= PTD_NAC_CNT(nak);
570
571 /* DW3 */
572 if (usb_pipecontrol(urb->pipe))
573 dw3 |= PTD_DATA_TOGGLE(qtd->toggle);
574 else
575 dw3 |= qh->toggle;
576
577
578 dw3 |= PTD_ACTIVE;
579 /* Cerr */
580 dw3 |= PTD_CERR(ERR_COUNTER);
581
582 memset(ptd, 0, sizeof(*ptd));
583
584 ptd->dw0 = cpu_to_le32(dw0);
585 ptd->dw1 = cpu_to_le32(dw1);
586 ptd->dw2 = cpu_to_le32(dw2);
587 ptd->dw3 = cpu_to_le32(dw3);
588}
589
590static void transform_add_int(struct isp1760_hcd *priv, struct isp1760_qh *qh,
591 struct isp1760_qtd *qtd, struct urb *urb,
592 u32 payload, struct ptd *ptd)
593{
594 u32 maxpacket;
595 u32 multi;
596 u32 numberofusofs;
597 u32 i;
598 u32 usofmask, usof;
599 u32 period;
600
601 maxpacket = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe));
602 multi = 1 + ((maxpacket >> 11) & 0x3);
603 maxpacket &= 0x7ff;
604 /* length of the data per uframe */
605 maxpacket = multi * maxpacket;
606
607 numberofusofs = urb->transfer_buffer_length / maxpacket;
608 if (urb->transfer_buffer_length % maxpacket)
609 numberofusofs += 1;
610
611 usofmask = 1;
612 usof = 0;
613 for (i = 0; i < numberofusofs; i++) {
614 usof |= usofmask;
615 usofmask <<= 1;
616 }
617
618 if (urb->dev->speed != USB_SPEED_HIGH) {
619 /* split */
620 ptd->dw5 = __constant_cpu_to_le32(0x1c);
621
622 if (qh->period >= 32)
623 period = qh->period / 2;
624 else
625 period = qh->period;
626
627 } else {
628
629 if (qh->period >= 8)
630 period = qh->period/8;
631 else
632 period = qh->period;
633
634 if (period >= 32)
635 period = 16;
636
637 if (qh->period >= 8) {
638 /* millisecond period */
639 period = (period << 3);
640 } else {
641 /* usof based tranmsfers */
642 /* minimum 4 usofs */
643 usof = 0x11;
644 }
645 }
646
647 ptd->dw2 |= cpu_to_le32(period);
648 ptd->dw4 = cpu_to_le32(usof);
649}
650
651static void transform_into_int(struct isp1760_hcd *priv, struct isp1760_qh *qh,
652 struct isp1760_qtd *qtd, struct urb *urb,
653 u32 payload, struct ptd *ptd)
654{
655 transform_into_atl(priv, qh, qtd, urb, payload, ptd);
656 transform_add_int(priv, qh, qtd, urb, payload, ptd);
657}
658
659static int qtd_fill(struct isp1760_qtd *qtd, void *databuffer, size_t len,
660 u32 token)
661{
662 int count;
663
664 qtd->data_buffer = databuffer;
665 qtd->packet_type = GET_QTD_TOKEN_TYPE(token);
666 qtd->toggle = GET_DATA_TOGGLE(token);
667
668 if (len > HC_ATL_PL_SIZE)
669 count = HC_ATL_PL_SIZE;
670 else
671 count = len;
672
673 qtd->length = count;
674 return count;
675}
676
677static int check_error(struct ptd *ptd)
678{
679 int error = 0;
680 u32 dw3;
681
682 dw3 = le32_to_cpu(ptd->dw3);
683 if (dw3 & DW3_HALT_BIT)
684 error = -EPIPE;
685
686 if (dw3 & DW3_ERROR_BIT) {
687 printk(KERN_ERR "error bit is set in DW3\n");
688 error = -EPIPE;
689 }
690
691 if (dw3 & DW3_QTD_ACTIVE) {
692 printk(KERN_ERR "transfer active bit is set DW3\n");
693 printk(KERN_ERR "nak counter: %d, rl: %d\n", (dw3 >> 19) & 0xf,
694 (le32_to_cpu(ptd->dw2) >> 25) & 0xf);
695 }
696
697 return error;
698}
699
700static void check_int_err_status(u32 dw4)
701{
702 u32 i;
703
704 dw4 >>= 8;
705
706 for (i = 0; i < 8; i++) {
707 switch (dw4 & 0x7) {
708 case INT_UNDERRUN:
709 printk(KERN_ERR "ERROR: under run , %d\n", i);
710 break;
711
712 case INT_EXACT:
713 printk(KERN_ERR "ERROR: transaction error, %d\n", i);
714 break;
715
716 case INT_BABBLE:
717 printk(KERN_ERR "ERROR: babble error, %d\n", i);
718 break;
719 }
720 dw4 >>= 3;
721 }
722}
723
724static void enqueue_one_qtd(struct isp1760_qtd *qtd, struct isp1760_hcd *priv,
725 u32 payload)
726{
727 u32 token;
728 struct usb_hcd *hcd = priv_to_hcd(priv);
729
730 token = qtd->packet_type;
731
732 if (qtd->length && (qtd->length <= HC_ATL_PL_SIZE)) {
733 switch (token) {
734 case IN_PID:
735 break;
736 case OUT_PID:
737 case SETUP_PID:
738 priv_write_copy(priv, qtd->data_buffer,
739 hcd->regs + payload,
740 qtd->length);
741 }
742 }
743}
744
745static void enqueue_one_atl_qtd(u32 atl_regs, u32 payload,
746 struct isp1760_hcd *priv, struct isp1760_qh *qh,
747 struct urb *urb, u32 slot, struct isp1760_qtd *qtd)
748{
749 struct ptd ptd;
750 struct usb_hcd *hcd = priv_to_hcd(priv);
751
752 transform_into_atl(priv, qh, qtd, urb, payload, &ptd);
753 priv_write_copy(priv, (u32 *)&ptd, hcd->regs + atl_regs, sizeof(ptd));
754 enqueue_one_qtd(qtd, priv, payload);
755
756 priv->atl_ints[slot].urb = urb;
757 priv->atl_ints[slot].qh = qh;
758 priv->atl_ints[slot].qtd = qtd;
759 priv->atl_ints[slot].data_buffer = qtd->data_buffer;
760 priv->atl_ints[slot].payload = payload;
761 qtd->status |= URB_ENQUEUED | URB_TYPE_ATL;
762 qtd->status |= slot << 16;
763}
764
765static void enqueue_one_int_qtd(u32 int_regs, u32 payload,
766 struct isp1760_hcd *priv, struct isp1760_qh *qh,
767 struct urb *urb, u32 slot, struct isp1760_qtd *qtd)
768{
769 struct ptd ptd;
770 struct usb_hcd *hcd = priv_to_hcd(priv);
771
772 transform_into_int(priv, qh, qtd, urb, payload, &ptd);
773 priv_write_copy(priv, (u32 *)&ptd, hcd->regs + int_regs, sizeof(ptd));
774 enqueue_one_qtd(qtd, priv, payload);
775
776 priv->int_ints[slot].urb = urb;
777 priv->int_ints[slot].qh = qh;
778 priv->int_ints[slot].qtd = qtd;
779 priv->int_ints[slot].data_buffer = qtd->data_buffer;
780 priv->int_ints[slot].payload = payload;
781 qtd->status |= URB_ENQUEUED | URB_TYPE_INT;
782 qtd->status |= slot << 16;
783}
784
785void enqueue_an_ATL_packet(struct usb_hcd *hcd, struct isp1760_qh *qh,
786 struct isp1760_qtd *qtd)
787{
788 struct isp1760_hcd *priv = hcd_to_priv(hcd);
789 u32 skip_map, or_map;
790 u32 queue_entry;
791 u32 slot;
792 u32 atl_regs, payload;
793 u32 buffstatus;
794
795 skip_map = isp1760_readl(hcd->regs + HC_ATL_PTD_SKIPMAP_REG);
796
797 BUG_ON(!skip_map);
798 slot = __ffs(skip_map);
799 queue_entry = 1 << slot;
800
801 atl_regs = ATL_REGS_OFFSET + slot * sizeof(struct ptd);
802
803 payload = alloc_mem(priv, qtd->length);
804
805 enqueue_one_atl_qtd(atl_regs, payload, priv, qh, qtd->urb, slot, qtd);
806
807 or_map = isp1760_readl(hcd->regs + HC_ATL_IRQ_MASK_OR_REG);
808 or_map |= queue_entry;
809 isp1760_writel(or_map, hcd->regs + HC_ATL_IRQ_MASK_OR_REG);
810
811 skip_map &= ~queue_entry;
812 isp1760_writel(skip_map, hcd->regs + HC_ATL_PTD_SKIPMAP_REG);
813
814 buffstatus = isp1760_readl(hcd->regs + HC_BUFFER_STATUS_REG);
815 buffstatus |= ATL_BUFFER;
816 isp1760_writel(buffstatus, hcd->regs + HC_BUFFER_STATUS_REG);
817}
818
819void enqueue_an_INT_packet(struct usb_hcd *hcd, struct isp1760_qh *qh,
820 struct isp1760_qtd *qtd)
821{
822 struct isp1760_hcd *priv = hcd_to_priv(hcd);
823 u32 skip_map, or_map;
824 u32 queue_entry;
825 u32 slot;
826 u32 int_regs, payload;
827 u32 buffstatus;
828
829 skip_map = isp1760_readl(hcd->regs + HC_INT_PTD_SKIPMAP_REG);
830
831 BUG_ON(!skip_map);
832 slot = __ffs(skip_map);
833 queue_entry = 1 << slot;
834
835 int_regs = INT_REGS_OFFSET + slot * sizeof(struct ptd);
836
837 payload = alloc_mem(priv, qtd->length);
838
839 enqueue_one_int_qtd(int_regs, payload, priv, qh, qtd->urb, slot, qtd);
840
841 or_map = isp1760_readl(hcd->regs + HC_INT_IRQ_MASK_OR_REG);
842 or_map |= queue_entry;
843 isp1760_writel(or_map, hcd->regs + HC_INT_IRQ_MASK_OR_REG);
844
845 skip_map &= ~queue_entry;
846 isp1760_writel(skip_map, hcd->regs + HC_INT_PTD_SKIPMAP_REG);
847
848 buffstatus = isp1760_readl(hcd->regs + HC_BUFFER_STATUS_REG);
849 buffstatus |= INT_BUFFER;
850 isp1760_writel(buffstatus, hcd->regs + HC_BUFFER_STATUS_REG);
851}
852
853static void isp1760_urb_done(struct isp1760_hcd *priv, struct urb *urb, int status)
854__releases(priv->lock)
855__acquires(priv->lock)
856{
857 if (!urb->unlinked) {
858 if (status == -EINPROGRESS)
859 status = 0;
860 }
861
862 /* complete() can reenter this HCD */
863 usb_hcd_unlink_urb_from_ep(priv_to_hcd(priv), urb);
864 spin_unlock(&priv->lock);
865 usb_hcd_giveback_urb(priv_to_hcd(priv), urb, status);
866 spin_lock(&priv->lock);
867}
868
869static void isp1760_qtd_free(struct isp1760_qtd *qtd)
870{
871 kmem_cache_free(qtd_cachep, qtd);
872}
873
874static struct isp1760_qtd *clean_this_qtd(struct isp1760_qtd *qtd)
875{
876 struct isp1760_qtd *tmp_qtd;
877
878 tmp_qtd = qtd->hw_next;
879 list_del(&qtd->qtd_list);
880 isp1760_qtd_free(qtd);
881 return tmp_qtd;
882}
883
884/*
885 * Remove this QTD from the QH list and free its memory. If this QTD
886 * isn't the last one than remove also his successor(s).
887 * Returns the QTD which is part of an new URB and should be enqueued.
888 */
889static struct isp1760_qtd *clean_up_qtdlist(struct isp1760_qtd *qtd)
890{
891 struct isp1760_qtd *tmp_qtd;
892 int last_one;
893
894 do {
895 tmp_qtd = qtd->hw_next;
896 last_one = qtd->status & URB_COMPLETE_NOTIFY;
897 list_del(&qtd->qtd_list);
898 isp1760_qtd_free(qtd);
899 qtd = tmp_qtd;
900 } while (!last_one && qtd);
901
902 return qtd;
903}
904
905static void do_atl_int(struct usb_hcd *usb_hcd)
906{
907 struct isp1760_hcd *priv = hcd_to_priv(usb_hcd);
908 u32 done_map, skip_map;
909 struct ptd ptd;
910 struct urb *urb = NULL;
911 u32 atl_regs_base;
912 u32 atl_regs;
913 u32 queue_entry;
914 u32 payload;
915 u32 length;
916 u32 or_map;
917 u32 status = -EINVAL;
918 int error;
919 struct isp1760_qtd *qtd;
920 struct isp1760_qh *qh;
921 u32 rl;
922 u32 nakcount;
923
924 done_map = isp1760_readl(usb_hcd->regs +
925 HC_ATL_PTD_DONEMAP_REG);
926 skip_map = isp1760_readl(usb_hcd->regs +
927 HC_ATL_PTD_SKIPMAP_REG);
928
929 or_map = isp1760_readl(usb_hcd->regs + HC_ATL_IRQ_MASK_OR_REG);
930 or_map &= ~done_map;
931 isp1760_writel(or_map, usb_hcd->regs + HC_ATL_IRQ_MASK_OR_REG);
932
933 atl_regs_base = ATL_REGS_OFFSET;
934 while (done_map) {
935 u32 dw1;
936 u32 dw2;
937 u32 dw3;
938
939 status = 0;
940
941 queue_entry = __ffs(done_map);
942 done_map &= ~(1 << queue_entry);
943 skip_map |= 1 << queue_entry;
944
945 atl_regs = atl_regs_base + queue_entry * sizeof(struct ptd);
946
947 urb = priv->atl_ints[queue_entry].urb;
948 qtd = priv->atl_ints[queue_entry].qtd;
949 qh = priv->atl_ints[queue_entry].qh;
950 payload = priv->atl_ints[queue_entry].payload;
951
952 if (!qh) {
953 printk(KERN_ERR "qh is 0\n");
954 continue;
955 }
956 priv_read_copy(priv, (u32 *)&ptd, usb_hcd->regs + atl_regs,
957 atl_regs, sizeof(ptd));
958
959 dw1 = le32_to_cpu(ptd.dw1);
960 dw2 = le32_to_cpu(ptd.dw2);
961 dw3 = le32_to_cpu(ptd.dw3);
962 rl = (dw2 >> 25) & 0x0f;
963 nakcount = (dw3 >> 19) & 0xf;
964
965 /* Transfer Error, *but* active and no HALT -> reload */
966 if ((dw3 & DW3_ERROR_BIT) && (dw3 & DW3_QTD_ACTIVE) &&
967 !(dw3 & DW3_HALT_BIT)) {
968
969 /* according to ppriv code, we have to
970 * reload this one if trasfered bytes != requested bytes
971 * else act like everything went smooth..
972 * XXX This just doesn't feel right and hasn't
973 * triggered so far.
974 */
975
976 length = PTD_XFERRED_LENGTH(dw3);
977 printk(KERN_ERR "Should reload now.... transfered %d "
978 "of %zu\n", length, qtd->length);
979 BUG();
980 }
981
982 if (!nakcount && (dw3 & DW3_QTD_ACTIVE)) {
983 u32 buffstatus;
984
985 /* XXX
986 * NAKs are handled in HW by the chip. Usually if the
987 * device is not able to send data fast enough.
988 * This did not trigger for a long time now.
989 */
990 printk(KERN_ERR "Reloading ptd %p/%p... qh %p readed: "
991 "%d of %d done: %08x cur: %08x\n", qtd,
992 urb, qh, PTD_XFERRED_LENGTH(dw3),
993 qtd->length, done_map,
994 (1 << queue_entry));
995
996 /* RL counter = ERR counter */
997 dw3 &= ~(0xf << 19);
998 dw3 |= rl << 19;
999 dw3 &= ~(3 << (55 - 32));
1000 dw3 |= ERR_COUNTER << (55 - 32);
1001
1002 /*
1003 * It is not needed to write skip map back because it
1004 * is unchanged. Just make sure that this entry is
1005 * unskipped once it gets written to the HW.
1006 */
1007 skip_map &= ~(1 << queue_entry);
1008 or_map = isp1760_readl(usb_hcd->regs +
1009 HC_ATL_IRQ_MASK_OR_REG);
1010 or_map |= 1 << queue_entry;
1011 isp1760_writel(or_map, usb_hcd->regs +
1012 HC_ATL_IRQ_MASK_OR_REG);
1013
1014 ptd.dw3 = cpu_to_le32(dw3);
1015 priv_write_copy(priv, (u32 *)&ptd, usb_hcd->regs +
1016 atl_regs, sizeof(ptd));
1017
1018 ptd.dw0 |= __constant_cpu_to_le32(PTD_VALID);
1019 priv_write_copy(priv, (u32 *)&ptd, usb_hcd->regs +
1020 atl_regs, sizeof(ptd));
1021
1022 buffstatus = isp1760_readl(usb_hcd->regs +
1023 HC_BUFFER_STATUS_REG);
1024 buffstatus |= ATL_BUFFER;
1025 isp1760_writel(buffstatus, usb_hcd->regs +
1026 HC_BUFFER_STATUS_REG);
1027 continue;
1028 }
1029
1030 error = check_error(&ptd);
1031 if (error) {
1032 status = error;
1033 priv->atl_ints[queue_entry].qh->toggle = 0;
1034 priv->atl_ints[queue_entry].qh->ping = 0;
1035 urb->status = -EPIPE;
1036
1037#if 0
1038 printk(KERN_ERR "Error in %s().\n", __func__);
1039 printk(KERN_ERR "IN dw0: %08x dw1: %08x dw2: %08x "
1040 "dw3: %08x dw4: %08x dw5: %08x dw6: "
1041 "%08x dw7: %08x\n",
1042 ptd.dw0, ptd.dw1, ptd.dw2, ptd.dw3,
1043 ptd.dw4, ptd.dw5, ptd.dw6, ptd.dw7);
1044#endif
1045 } else {
1046 if (usb_pipetype(urb->pipe) == PIPE_BULK) {
1047 priv->atl_ints[queue_entry].qh->toggle = dw3 &
1048 (1 << 25);
1049 priv->atl_ints[queue_entry].qh->ping = dw3 &
1050 (1 << 26);
1051 }
1052 }
1053
1054 length = PTD_XFERRED_LENGTH(dw3);
1055 if (length) {
1056 switch (DW1_GET_PID(dw1)) {
1057 case IN_PID:
1058 priv_read_copy(priv,
1059 priv->atl_ints[queue_entry].data_buffer,
1060 usb_hcd->regs + payload, payload,
1061 length);
1062
1063 case OUT_PID:
1064
1065 urb->actual_length += length;
1066
1067 case SETUP_PID:
1068 break;
1069 }
1070 }
1071
1072 priv->atl_ints[queue_entry].data_buffer = NULL;
1073 priv->atl_ints[queue_entry].urb = NULL;
1074 priv->atl_ints[queue_entry].qtd = NULL;
1075 priv->atl_ints[queue_entry].qh = NULL;
1076
1077 free_mem(priv, payload);
1078
1079 isp1760_writel(skip_map, usb_hcd->regs +
1080 HC_ATL_PTD_SKIPMAP_REG);
1081
1082 if (urb->status == -EPIPE) {
1083 /* HALT was received */
1084
1085 qtd = clean_up_qtdlist(qtd);
1086 isp1760_urb_done(priv, urb, urb->status);
1087
1088 } else if (usb_pipebulk(urb->pipe) && (length < qtd->length)) {
1089 /* short BULK received */
1090
1091 printk(KERN_ERR "short bulk, %d instead %d\n", length,
1092 qtd->length);
1093 if (urb->transfer_flags & URB_SHORT_NOT_OK) {
1094 urb->status = -EREMOTEIO;
1095 printk(KERN_ERR "not okey\n");
1096 }
1097
1098 if (urb->status == -EINPROGRESS)
1099 urb->status = 0;
1100
1101 qtd = clean_up_qtdlist(qtd);
1102
1103 isp1760_urb_done(priv, urb, urb->status);
1104
1105 } else if (qtd->status & URB_COMPLETE_NOTIFY) {
1106 /* that was the last qtd of that URB */
1107
1108 if (urb->status == -EINPROGRESS)
1109 urb->status = 0;
1110
1111 qtd = clean_this_qtd(qtd);
1112 isp1760_urb_done(priv, urb, urb->status);
1113
1114 } else {
1115 /* next QTD of this URB */
1116
1117 qtd = clean_this_qtd(qtd);
1118 BUG_ON(!qtd);
1119 }
1120
1121 if (qtd)
1122 enqueue_an_ATL_packet(usb_hcd, qh, qtd);
1123
1124 skip_map = isp1760_readl(usb_hcd->regs +
1125 HC_ATL_PTD_SKIPMAP_REG);
1126 }
1127}
1128
1129static void do_intl_int(struct usb_hcd *usb_hcd)
1130{
1131 struct isp1760_hcd *priv = hcd_to_priv(usb_hcd);
1132 u32 done_map, skip_map;
1133 struct ptd ptd;
1134 struct urb *urb = NULL;
1135 u32 int_regs;
1136 u32 int_regs_base;
1137 u32 payload;
1138 u32 length;
1139 u32 or_map;
1140 int error;
1141 u32 queue_entry;
1142 struct isp1760_qtd *qtd;
1143 struct isp1760_qh *qh;
1144
1145 done_map = isp1760_readl(usb_hcd->regs +
1146 HC_INT_PTD_DONEMAP_REG);
1147 skip_map = isp1760_readl(usb_hcd->regs +
1148 HC_INT_PTD_SKIPMAP_REG);
1149
1150 or_map = isp1760_readl(usb_hcd->regs + HC_INT_IRQ_MASK_OR_REG);
1151 or_map &= ~done_map;
1152 isp1760_writel(or_map, usb_hcd->regs + HC_INT_IRQ_MASK_OR_REG);
1153
1154 int_regs_base = INT_REGS_OFFSET;
1155
1156 while (done_map) {
1157 u32 dw1;
1158 u32 dw3;
1159
1160 queue_entry = __ffs(done_map);
1161 done_map &= ~(1 << queue_entry);
1162 skip_map |= 1 << queue_entry;
1163
1164 int_regs = int_regs_base + queue_entry * sizeof(struct ptd);
1165 urb = priv->int_ints[queue_entry].urb;
1166 qtd = priv->int_ints[queue_entry].qtd;
1167 qh = priv->int_ints[queue_entry].qh;
1168 payload = priv->int_ints[queue_entry].payload;
1169
1170 if (!qh) {
1171 printk(KERN_ERR "(INT) qh is 0\n");
1172 continue;
1173 }
1174
1175 priv_read_copy(priv, (u32 *)&ptd, usb_hcd->regs + int_regs,
1176 int_regs, sizeof(ptd));
1177 dw1 = le32_to_cpu(ptd.dw1);
1178 dw3 = le32_to_cpu(ptd.dw3);
1179 check_int_err_status(le32_to_cpu(ptd.dw4));
1180
1181 error = check_error(&ptd);
1182 if (error) {
1183#if 0
1184 printk(KERN_ERR "Error in %s().\n", __func__);
1185 printk(KERN_ERR "IN dw0: %08x dw1: %08x dw2: %08x "
1186 "dw3: %08x dw4: %08x dw5: %08x dw6: "
1187 "%08x dw7: %08x\n",
1188 ptd.dw0, ptd.dw1, ptd.dw2, ptd.dw3,
1189 ptd.dw4, ptd.dw5, ptd.dw6, ptd.dw7);
1190#endif
1191 urb->status = -EPIPE;
1192 priv->int_ints[queue_entry].qh->toggle = 0;
1193 priv->int_ints[queue_entry].qh->ping = 0;
1194
1195 } else {
1196 priv->int_ints[queue_entry].qh->toggle =
1197 dw3 & (1 << 25);
1198 priv->int_ints[queue_entry].qh->ping = dw3 & (1 << 26);
1199 }
1200
1201 if (urb->dev->speed != USB_SPEED_HIGH)
1202 length = PTD_XFERRED_LENGTH_LO(dw3);
1203 else
1204 length = PTD_XFERRED_LENGTH(dw3);
1205
1206 if (length) {
1207 switch (DW1_GET_PID(dw1)) {
1208 case IN_PID:
1209 priv_read_copy(priv,
1210 priv->int_ints[queue_entry].data_buffer,
1211 usb_hcd->regs + payload , payload,
1212 length);
1213 case OUT_PID:
1214
1215 urb->actual_length += length;
1216
1217 case SETUP_PID:
1218 break;
1219 }
1220 }
1221
1222 priv->int_ints[queue_entry].data_buffer = NULL;
1223 priv->int_ints[queue_entry].urb = NULL;
1224 priv->int_ints[queue_entry].qtd = NULL;
1225 priv->int_ints[queue_entry].qh = NULL;
1226
1227 isp1760_writel(skip_map, usb_hcd->regs +
1228 HC_INT_PTD_SKIPMAP_REG);
1229 free_mem(priv, payload);
1230
1231 if (urb->status == -EPIPE) {
1232 /* HALT received */
1233
1234 qtd = clean_up_qtdlist(qtd);
1235 isp1760_urb_done(priv, urb, urb->status);
1236
1237 } else if (qtd->status & URB_COMPLETE_NOTIFY) {
1238
1239 if (urb->status == -EINPROGRESS)
1240 urb->status = 0;
1241
1242 qtd = clean_this_qtd(qtd);
1243 isp1760_urb_done(priv, urb, urb->status);
1244
1245 } else {
1246 /* next QTD of this URB */
1247
1248 qtd = clean_this_qtd(qtd);
1249 BUG_ON(!qtd);
1250 }
1251
1252 if (qtd)
1253 enqueue_an_INT_packet(usb_hcd, qh, qtd);
1254
1255 skip_map = isp1760_readl(usb_hcd->regs +
1256 HC_INT_PTD_SKIPMAP_REG);
1257 }
1258}
1259
1260#define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
1261static struct isp1760_qh *qh_make(struct isp1760_hcd *priv, struct urb *urb,
1262 gfp_t flags)
1263{
1264 struct isp1760_qh *qh;
1265 int is_input, type;
1266
1267 qh = isp1760_qh_alloc(priv, flags);
1268 if (!qh)
1269 return qh;
1270
1271 /*
1272 * init endpoint/device data for this QH
1273 */
1274 is_input = usb_pipein(urb->pipe);
1275 type = usb_pipetype(urb->pipe);
1276
1277 if (type == PIPE_INTERRUPT) {
1278
1279 if (urb->dev->speed == USB_SPEED_HIGH) {
1280
1281 qh->period = urb->interval >> 3;
1282 if (qh->period == 0 && urb->interval != 1) {
1283 /* NOTE interval 2 or 4 uframes could work.
1284 * But interval 1 scheduling is simpler, and
1285 * includes high bandwidth.
1286 */
1287 printk(KERN_ERR "intr period %d uframes, NYET!",
1288 urb->interval);
1289 qh_destroy(qh);
1290 return NULL;
1291 }
1292 } else {
1293 qh->period = urb->interval;
1294 }
1295 }
1296
1297 /* support for tt scheduling, and access to toggles */
1298 qh->dev = urb->dev;
1299
1300 if (!usb_pipecontrol(urb->pipe))
1301 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), !is_input,
1302 1);
1303 return qh;
1304}
1305
1306/*
1307 * For control/bulk/interrupt, return QH with these TDs appended.
1308 * Allocates and initializes the QH if necessary.
1309 * Returns null if it can't allocate a QH it needs to.
1310 * If the QH has TDs (urbs) already, that's great.
1311 */
1312static struct isp1760_qh *qh_append_tds(struct isp1760_hcd *priv,
1313 struct urb *urb, struct list_head *qtd_list, int epnum,
1314 void **ptr)
1315{
1316 struct isp1760_qh *qh;
1317 struct isp1760_qtd *qtd;
1318 struct isp1760_qtd *prev_qtd;
1319
1320 qh = (struct isp1760_qh *)*ptr;
1321 if (!qh) {
1322 /* can't sleep here, we have priv->lock... */
1323 qh = qh_make(priv, urb, GFP_ATOMIC);
1324 if (!qh)
1325 return qh;
1326 *ptr = qh;
1327 }
1328
1329 qtd = list_entry(qtd_list->next, struct isp1760_qtd,
1330 qtd_list);
1331 if (!list_empty(&qh->qtd_list))
1332 prev_qtd = list_entry(qh->qtd_list.prev,
1333 struct isp1760_qtd, qtd_list);
1334 else
1335 prev_qtd = NULL;
1336
1337 list_splice(qtd_list, qh->qtd_list.prev);
1338 if (prev_qtd) {
1339 BUG_ON(prev_qtd->hw_next);
1340 prev_qtd->hw_next = qtd;
1341 }
1342
1343 urb->hcpriv = qh;
1344 return qh;
1345}
1346
1347static void qtd_list_free(struct isp1760_hcd *priv, struct urb *urb,
1348 struct list_head *qtd_list)
1349{
1350 struct list_head *entry, *temp;
1351
1352 list_for_each_safe(entry, temp, qtd_list) {
1353 struct isp1760_qtd *qtd;
1354
1355 qtd = list_entry(entry, struct isp1760_qtd, qtd_list);
1356 list_del(&qtd->qtd_list);
1357 isp1760_qtd_free(qtd);
1358 }
1359}
1360
1361static int isp1760_prepare_enqueue(struct isp1760_hcd *priv, struct urb *urb,
1362 struct list_head *qtd_list, gfp_t mem_flags, packet_enqueue *p)
1363{
1364 struct isp1760_qtd *qtd;
1365 int epnum;
1366 unsigned long flags;
1367 struct isp1760_qh *qh = NULL;
1368 int rc;
1369 int qh_busy;
1370
1371 qtd = list_entry(qtd_list->next, struct isp1760_qtd, qtd_list);
1372 epnum = urb->ep->desc.bEndpointAddress;
1373
1374 spin_lock_irqsave(&priv->lock, flags);
1375 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &priv_to_hcd(priv)->flags)) {
1376 rc = -ESHUTDOWN;
1377 goto done;
1378 }
1379 rc = usb_hcd_link_urb_to_ep(priv_to_hcd(priv), urb);
1380 if (rc)
1381 goto done;
1382
1383 qh = urb->ep->hcpriv;
1384 if (qh)
1385 qh_busy = !list_empty(&qh->qtd_list);
1386 else
1387 qh_busy = 0;
1388
1389 qh = qh_append_tds(priv, urb, qtd_list, epnum, &urb->ep->hcpriv);
1390 if (!qh) {
1391 usb_hcd_unlink_urb_from_ep(priv_to_hcd(priv), urb);
1392 rc = -ENOMEM;
1393 goto done;
1394 }
1395
1396 if (!qh_busy)
1397 p(priv_to_hcd(priv), qh, qtd);
1398
1399done:
1400 spin_unlock_irqrestore(&priv->lock, flags);
1401 if (!qh)
1402 qtd_list_free(priv, urb, qtd_list);
1403 return rc;
1404}
1405
1406static struct isp1760_qtd *isp1760_qtd_alloc(struct isp1760_hcd *priv,
1407 gfp_t flags)
1408{
1409 struct isp1760_qtd *qtd;
1410
1411 qtd = kmem_cache_zalloc(qtd_cachep, flags);
1412 if (qtd)
1413 INIT_LIST_HEAD(&qtd->qtd_list);
1414
1415 return qtd;
1416}
1417
1418/*
1419 * create a list of filled qtds for this URB; won't link into qh.
1420 */
1421static struct list_head *qh_urb_transaction(struct isp1760_hcd *priv,
1422 struct urb *urb, struct list_head *head, gfp_t flags)
1423{
1424 struct isp1760_qtd *qtd, *qtd_prev;
1425 void *buf;
1426 int len, maxpacket;
1427 int is_input;
1428 u32 token;
1429
1430 /*
1431 * URBs map to sequences of QTDs: one logical transaction
1432 */
1433 qtd = isp1760_qtd_alloc(priv, flags);
1434 if (!qtd)
1435 return NULL;
1436
1437 list_add_tail(&qtd->qtd_list, head);
1438 qtd->urb = urb;
1439 urb->status = -EINPROGRESS;
1440
1441 token = 0;
1442 /* for split transactions, SplitXState initialized to zero */
1443
1444 len = urb->transfer_buffer_length;
1445 is_input = usb_pipein(urb->pipe);
1446 if (usb_pipecontrol(urb->pipe)) {
1447 /* SETUP pid */
1448 qtd_fill(qtd, urb->setup_packet,
1449 sizeof(struct usb_ctrlrequest),
1450 token | SETUP_PID);
1451
1452 /* ... and always at least one more pid */
1453 token ^= DATA_TOGGLE;
1454 qtd_prev = qtd;
1455 qtd = isp1760_qtd_alloc(priv, flags);
1456 if (!qtd)
1457 goto cleanup;
1458 qtd->urb = urb;
1459 qtd_prev->hw_next = qtd;
1460 list_add_tail(&qtd->qtd_list, head);
1461
1462 /* for zero length DATA stages, STATUS is always IN */
1463 if (len == 0)
1464 token |= IN_PID;
1465 }
1466
1467 /*
1468 * data transfer stage: buffer setup
1469 */
1470 buf = urb->transfer_buffer;
1471
1472 if (is_input)
1473 token |= IN_PID;
1474 else
1475 token |= OUT_PID;
1476
1477 maxpacket = max_packet(usb_maxpacket(urb->dev, urb->pipe, !is_input));
1478
1479 /*
1480 * buffer gets wrapped in one or more qtds;
1481 * last one may be "short" (including zero len)
1482 * and may serve as a control status ack
1483 */
1484 for (;;) {
1485 int this_qtd_len;
1486
1487 if (!buf && len) {
1488 /* XXX This looks like usb storage / SCSI bug */
1489 printk(KERN_ERR "buf is null, dma is %08lx len is %d\n",
1490 (long unsigned)urb->transfer_dma, len);
1491 WARN_ON(1);
1492 }
1493
1494 this_qtd_len = qtd_fill(qtd, buf, len, token);
1495 len -= this_qtd_len;
1496 buf += this_qtd_len;
1497
1498 /* qh makes control packets use qtd toggle; maybe switch it */
1499 if ((maxpacket & (this_qtd_len + (maxpacket - 1))) == 0)
1500 token ^= DATA_TOGGLE;
1501
1502 if (len <= 0)
1503 break;
1504
1505 qtd_prev = qtd;
1506 qtd = isp1760_qtd_alloc(priv, flags);
1507 if (!qtd)
1508 goto cleanup;
1509 qtd->urb = urb;
1510 qtd_prev->hw_next = qtd;
1511 list_add_tail(&qtd->qtd_list, head);
1512 }
1513
1514 /*
1515 * control requests may need a terminating data "status" ack;
1516 * bulk ones may need a terminating short packet (zero length).
1517 */
1518 if (urb->transfer_buffer_length != 0) {
1519 int one_more = 0;
1520
1521 if (usb_pipecontrol(urb->pipe)) {
1522 one_more = 1;
1523 /* "in" <--> "out" */
1524 token ^= IN_PID;
1525 /* force DATA1 */
1526 token |= DATA_TOGGLE;
1527 } else if (usb_pipebulk(urb->pipe)
1528 && (urb->transfer_flags & URB_ZERO_PACKET)
1529 && !(urb->transfer_buffer_length % maxpacket)) {
1530 one_more = 1;
1531 }
1532 if (one_more) {
1533 qtd_prev = qtd;
1534 qtd = isp1760_qtd_alloc(priv, flags);
1535 if (!qtd)
1536 goto cleanup;
1537 qtd->urb = urb;
1538 qtd_prev->hw_next = qtd;
1539 list_add_tail(&qtd->qtd_list, head);
1540
1541 /* never any data in such packets */
1542 qtd_fill(qtd, NULL, 0, token);
1543 }
1544 }
1545
1546 qtd->status = URB_COMPLETE_NOTIFY;
1547 return head;
1548
1549cleanup:
1550 qtd_list_free(priv, urb, head);
1551 return NULL;
1552}
1553
1554static int isp1760_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
1555 gfp_t mem_flags)
1556{
1557 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1558 struct list_head qtd_list;
1559 packet_enqueue *pe;
1560
1561 INIT_LIST_HEAD(&qtd_list);
1562
1563 switch (usb_pipetype(urb->pipe)) {
1564 case PIPE_CONTROL:
1565 case PIPE_BULK:
1566
1567 if (!qh_urb_transaction(priv, urb, &qtd_list, mem_flags))
1568 return -ENOMEM;
1569 pe = enqueue_an_ATL_packet;
1570 break;
1571
1572 case PIPE_INTERRUPT:
1573 if (!qh_urb_transaction(priv, urb, &qtd_list, mem_flags))
1574 return -ENOMEM;
1575 pe = enqueue_an_INT_packet;
1576 break;
1577
1578 case PIPE_ISOCHRONOUS:
1579 printk(KERN_ERR "PIPE_ISOCHRONOUS ain't supported\n");
1580 default:
1581 return -EPIPE;
1582 }
1583
1584 isp1760_prepare_enqueue(priv, urb, &qtd_list, mem_flags, pe);
1585 return 0;
1586}
1587
1588static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb,
1589 int status)
1590{
1591 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1592 struct inter_packet_info *ints;
1593 u32 i;
1594 u32 reg_base, or_reg, skip_reg;
1595 int flags;
1596 struct ptd ptd;
1597
1598 switch (usb_pipetype(urb->pipe)) {
1599 case PIPE_ISOCHRONOUS:
1600 return -EPIPE;
1601 break;
1602
1603 case PIPE_INTERRUPT:
1604 ints = priv->int_ints;
1605 reg_base = INT_REGS_OFFSET;
1606 or_reg = HC_INT_IRQ_MASK_OR_REG;
1607 skip_reg = HC_INT_PTD_SKIPMAP_REG;
1608 break;
1609
1610 default:
1611 ints = priv->atl_ints;
1612 reg_base = ATL_REGS_OFFSET;
1613 or_reg = HC_ATL_IRQ_MASK_OR_REG;
1614 skip_reg = HC_ATL_PTD_SKIPMAP_REG;
1615 break;
1616 }
1617
1618 memset(&ptd, 0, sizeof(ptd));
1619 spin_lock_irqsave(&priv->lock, flags);
1620
1621 for (i = 0; i < 32; i++) {
1622 if (ints->urb == urb) {
1623 u32 skip_map;
1624 u32 or_map;
1625 struct isp1760_qtd *qtd;
1626
1627 skip_map = isp1760_readl(hcd->regs + skip_reg);
1628 skip_map |= 1 << i;
1629 isp1760_writel(skip_map, hcd->regs + skip_reg);
1630
1631 or_map = isp1760_readl(hcd->regs + or_reg);
1632 or_map &= ~(1 << i);
1633 isp1760_writel(or_map, hcd->regs + or_reg);
1634
1635 priv_write_copy(priv, (u32 *)&ptd, hcd->regs + reg_base
1636 + i * sizeof(ptd), sizeof(ptd));
1637 qtd = ints->qtd;
1638
1639 clean_up_qtdlist(qtd);
1640
1641 free_mem(priv, ints->payload);
1642
1643 ints->urb = NULL;
1644 ints->qh = NULL;
1645 ints->qtd = NULL;
1646 ints->data_buffer = NULL;
1647 ints->payload = 0;
1648
1649 isp1760_urb_done(priv, urb, status);
1650 break;
1651 }
1652 ints++;
1653 }
1654
1655 spin_unlock_irqrestore(&priv->lock, flags);
1656 return 0;
1657}
1658
1659static irqreturn_t isp1760_irq(struct usb_hcd *usb_hcd)
1660{
1661 struct isp1760_hcd *priv = hcd_to_priv(usb_hcd);
1662 u32 imask;
1663 irqreturn_t irqret = IRQ_NONE;
1664
1665 spin_lock(&priv->lock);
1666
1667 if (!(usb_hcd->state & HC_STATE_RUNNING))
1668 goto leave;
1669
1670 imask = isp1760_readl(usb_hcd->regs + HC_INTERRUPT_REG);
1671 if (unlikely(!imask))
1672 goto leave;
1673
1674 isp1760_writel(imask, usb_hcd->regs + HC_INTERRUPT_REG);
1675 if (imask & HC_ATL_INT)
1676 do_atl_int(usb_hcd);
1677
1678 if (imask & HC_INTL_INT)
1679 do_intl_int(usb_hcd);
1680
1681 irqret = IRQ_HANDLED;
1682leave:
1683 spin_unlock(&priv->lock);
1684 return irqret;
1685}
1686
1687static int isp1760_hub_status_data(struct usb_hcd *hcd, char *buf)
1688{
1689 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1690 u32 temp, status = 0;
1691 u32 mask;
1692 int retval = 1;
1693 unsigned long flags;
1694
1695 /* if !USB_SUSPEND, root hub timers won't get shut down ... */
1696 if (!HC_IS_RUNNING(hcd->state))
1697 return 0;
1698
1699 /* init status to no-changes */
1700 buf[0] = 0;
1701 mask = PORT_CSC;
1702
1703 spin_lock_irqsave(&priv->lock, flags);
1704 temp = isp1760_readl(hcd->regs + HC_PORTSC1);
1705
1706 if (temp & PORT_OWNER) {
1707 if (temp & PORT_CSC) {
1708 temp &= ~PORT_CSC;
1709 isp1760_writel(temp, hcd->regs + HC_PORTSC1);
1710 goto done;
1711 }
1712 }
1713
1714 /*
1715 * Return status information even for ports with OWNER set.
1716 * Otherwise khubd wouldn't see the disconnect event when a
1717 * high-speed device is switched over to the companion
1718 * controller by the user.
1719 */
1720
1721 if ((temp & mask) != 0
1722 || ((temp & PORT_RESUME) != 0
1723 && time_after_eq(jiffies,
1724 priv->reset_done))) {
1725 buf [0] |= 1 << (0 + 1);
1726 status = STS_PCD;
1727 }
1728 /* FIXME autosuspend idle root hubs */
1729done:
1730 spin_unlock_irqrestore(&priv->lock, flags);
1731 return status ? retval : 0;
1732}
1733
1734static void isp1760_hub_descriptor(struct isp1760_hcd *priv,
1735 struct usb_hub_descriptor *desc)
1736{
1737 int ports = HCS_N_PORTS(priv->hcs_params);
1738 u16 temp;
1739
1740 desc->bDescriptorType = 0x29;
1741 /* priv 1.0, 2.3.9 says 20ms max */
1742 desc->bPwrOn2PwrGood = 10;
1743 desc->bHubContrCurrent = 0;
1744
1745 desc->bNbrPorts = ports;
1746 temp = 1 + (ports / 8);
1747 desc->bDescLength = 7 + 2 * temp;
1748
1749 /* two bitmaps: ports removable, and usb 1.0 legacy PortPwrCtrlMask */
1750 memset(&desc->bitmap[0], 0, temp);
1751 memset(&desc->bitmap[temp], 0xff, temp);
1752
1753 /* per-port overcurrent reporting */
1754 temp = 0x0008;
1755 if (HCS_PPC(priv->hcs_params))
1756 /* per-port power control */
1757 temp |= 0x0001;
1758 else
1759 /* no power switching */
1760 temp |= 0x0002;
1761 desc->wHubCharacteristics = cpu_to_le16(temp);
1762}
1763
1764#define PORT_WAKE_BITS (PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E)
1765
1766static int check_reset_complete(struct isp1760_hcd *priv, int index,
1767 u32 __iomem *status_reg, int port_status)
1768{
1769 if (!(port_status & PORT_CONNECT))
1770 return port_status;
1771
1772 /* if reset finished and it's still not enabled -- handoff */
1773 if (!(port_status & PORT_PE)) {
1774
1775 printk(KERN_ERR "port %d full speed --> companion\n",
1776 index + 1);
1777
1778 port_status |= PORT_OWNER;
1779 port_status &= ~PORT_RWC_BITS;
1780 isp1760_writel(port_status, status_reg);
1781
1782 } else
1783 printk(KERN_ERR "port %d high speed\n", index + 1);
1784
1785 return port_status;
1786}
1787
1788static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
1789 u16 wValue, u16 wIndex, char *buf, u16 wLength)
1790{
1791 struct isp1760_hcd *priv = hcd_to_priv(hcd);
1792 int ports = HCS_N_PORTS(priv->hcs_params);
1793 u32 __iomem *status_reg = hcd->regs + HC_PORTSC1;
1794 u32 temp, status;
1795 unsigned long flags;
1796 int retval = 0;
1797 unsigned selector;
1798
1799 /*
1800 * FIXME: support SetPortFeatures USB_PORT_FEAT_INDICATOR.
1801 * HCS_INDICATOR may say we can change LEDs to off/amber/green.
1802 * (track current state ourselves) ... blink for diagnostics,
1803 * power, "this is the one", etc. EHCI spec supports this.
1804 */
1805
1806 spin_lock_irqsave(&priv->lock, flags);
1807 switch (typeReq) {
1808 case ClearHubFeature:
1809 switch (wValue) {
1810 case C_HUB_LOCAL_POWER:
1811 case C_HUB_OVER_CURRENT:
1812 /* no hub-wide feature/status flags */
1813 break;
1814 default:
1815 goto error;
1816 }
1817 break;
1818 case ClearPortFeature:
1819 if (!wIndex || wIndex > ports)
1820 goto error;
1821 wIndex--;
1822 temp = isp1760_readl(status_reg);
1823
1824 /*
1825 * Even if OWNER is set, so the port is owned by the
1826 * companion controller, khubd needs to be able to clear
1827 * the port-change status bits (especially
1828 * USB_PORT_FEAT_C_CONNECTION).
1829 */
1830
1831 switch (wValue) {
1832 case USB_PORT_FEAT_ENABLE:
1833 isp1760_writel(temp & ~PORT_PE, status_reg);
1834 break;
1835 case USB_PORT_FEAT_C_ENABLE:
1836 /* XXX error? */
1837 break;
1838 case USB_PORT_FEAT_SUSPEND:
1839 if (temp & PORT_RESET)
1840 goto error;
1841
1842 if (temp & PORT_SUSPEND) {
1843 if ((temp & PORT_PE) == 0)
1844 goto error;
1845 /* resume signaling for 20 msec */
1846 temp &= ~(PORT_RWC_BITS);
1847 isp1760_writel(temp | PORT_RESUME,
1848 status_reg);
1849 priv->reset_done = jiffies +
1850 msecs_to_jiffies(20);
1851 }
1852 break;
1853 case USB_PORT_FEAT_C_SUSPEND:
1854 /* we auto-clear this feature */
1855 break;
1856 case USB_PORT_FEAT_POWER:
1857 if (HCS_PPC(priv->hcs_params))
1858 isp1760_writel(temp & ~PORT_POWER, status_reg);
1859 break;
1860 case USB_PORT_FEAT_C_CONNECTION:
1861 isp1760_writel(temp | PORT_CSC,
1862 status_reg);
1863 break;
1864 case USB_PORT_FEAT_C_OVER_CURRENT:
1865 /* XXX error ?*/
1866 break;
1867 case USB_PORT_FEAT_C_RESET:
1868 /* GetPortStatus clears reset */
1869 break;
1870 default:
1871 goto error;
1872 }
1873 isp1760_readl(hcd->regs + HC_USBCMD);
1874 break;
1875 case GetHubDescriptor:
1876 isp1760_hub_descriptor(priv, (struct usb_hub_descriptor *)
1877 buf);
1878 break;
1879 case GetHubStatus:
1880 /* no hub-wide feature/status flags */
1881 memset(buf, 0, 4);
1882 break;
1883 case GetPortStatus:
1884 if (!wIndex || wIndex > ports)
1885 goto error;
1886 wIndex--;
1887 status = 0;
1888 temp = isp1760_readl(status_reg);
1889
1890 /* wPortChange bits */
1891 if (temp & PORT_CSC)
1892 status |= 1 << USB_PORT_FEAT_C_CONNECTION;
1893
1894
1895 /* whoever resumes must GetPortStatus to complete it!! */
1896 if (temp & PORT_RESUME) {
1897 printk(KERN_ERR "Port resume should be skipped.\n");
1898
1899 /* Remote Wakeup received? */
1900 if (!priv->reset_done) {
1901 /* resume signaling for 20 msec */
1902 priv->reset_done = jiffies
1903 + msecs_to_jiffies(20);
1904 /* check the port again */
1905 mod_timer(&priv_to_hcd(priv)->rh_timer,
1906 priv->reset_done);
1907 }
1908
1909 /* resume completed? */
1910 else if (time_after_eq(jiffies,
1911 priv->reset_done)) {
1912 status |= 1 << USB_PORT_FEAT_C_SUSPEND;
1913 priv->reset_done = 0;
1914
1915 /* stop resume signaling */
1916 temp = isp1760_readl(status_reg);
1917 isp1760_writel(
1918 temp & ~(PORT_RWC_BITS | PORT_RESUME),
1919 status_reg);
1920 retval = handshake(priv, status_reg,
1921 PORT_RESUME, 0, 2000 /* 2msec */);
1922 if (retval != 0) {
1923 isp1760_err(priv,
1924 "port %d resume error %d\n",
1925 wIndex + 1, retval);
1926 goto error;
1927 }
1928 temp &= ~(PORT_SUSPEND|PORT_RESUME|(3<<10));
1929 }
1930 }
1931
1932 /* whoever resets must GetPortStatus to complete it!! */
1933 if ((temp & PORT_RESET)
1934 && time_after_eq(jiffies,
1935 priv->reset_done)) {
1936 status |= 1 << USB_PORT_FEAT_C_RESET;
1937 priv->reset_done = 0;
1938
1939 /* force reset to complete */
1940 isp1760_writel(temp & ~PORT_RESET,
1941 status_reg);
1942 /* REVISIT: some hardware needs 550+ usec to clear
1943 * this bit; seems too long to spin routinely...
1944 */
1945 retval = handshake(priv, status_reg,
1946 PORT_RESET, 0, 750);
1947 if (retval != 0) {
1948 isp1760_err(priv, "port %d reset error %d\n",
1949 wIndex + 1, retval);
1950 goto error;
1951 }
1952
1953 /* see what we found out */
1954 temp = check_reset_complete(priv, wIndex, status_reg,
1955 isp1760_readl(status_reg));
1956 }
1957 /*
1958 * Even if OWNER is set, there's no harm letting khubd
1959 * see the wPortStatus values (they should all be 0 except
1960 * for PORT_POWER anyway).
1961 */
1962
1963 if (temp & PORT_OWNER)
1964 printk(KERN_ERR "Warning: PORT_OWNER is set\n");
1965
1966 if (temp & PORT_CONNECT) {
1967 status |= 1 << USB_PORT_FEAT_CONNECTION;
1968 /* status may be from integrated TT */
1969 status |= ehci_port_speed(priv, temp);
1970 }
1971 if (temp & PORT_PE)
1972 status |= 1 << USB_PORT_FEAT_ENABLE;
1973 if (temp & (PORT_SUSPEND|PORT_RESUME))
1974 status |= 1 << USB_PORT_FEAT_SUSPEND;
1975 if (temp & PORT_RESET)
1976 status |= 1 << USB_PORT_FEAT_RESET;
1977 if (temp & PORT_POWER)
1978 status |= 1 << USB_PORT_FEAT_POWER;
1979
1980 put_unaligned(cpu_to_le32(status), (__le32 *) buf);
1981 break;
1982 case SetHubFeature:
1983 switch (wValue) {
1984 case C_HUB_LOCAL_POWER:
1985 case C_HUB_OVER_CURRENT:
1986 /* no hub-wide feature/status flags */
1987 break;
1988 default:
1989 goto error;
1990 }
1991 break;
1992 case SetPortFeature:
1993 selector = wIndex >> 8;
1994 wIndex &= 0xff;
1995 if (!wIndex || wIndex > ports)
1996 goto error;
1997 wIndex--;
1998 temp = isp1760_readl(status_reg);
1999 if (temp & PORT_OWNER)
2000 break;
2001
2002/* temp &= ~PORT_RWC_BITS; */
2003 switch (wValue) {
2004 case USB_PORT_FEAT_ENABLE:
2005 isp1760_writel(temp | PORT_PE, status_reg);
2006 break;
2007
2008 case USB_PORT_FEAT_SUSPEND:
2009 if ((temp & PORT_PE) == 0
2010 || (temp & PORT_RESET) != 0)
2011 goto error;
2012
2013 isp1760_writel(temp | PORT_SUSPEND, status_reg);
2014 break;
2015 case USB_PORT_FEAT_POWER:
2016 if (HCS_PPC(priv->hcs_params))
2017 isp1760_writel(temp | PORT_POWER,
2018 status_reg);
2019 break;
2020 case USB_PORT_FEAT_RESET:
2021 if (temp & PORT_RESUME)
2022 goto error;
2023 /* line status bits may report this as low speed,
2024 * which can be fine if this root hub has a
2025 * transaction translator built in.
2026 */
2027 if ((temp & (PORT_PE|PORT_CONNECT)) == PORT_CONNECT
2028 && PORT_USB11(temp)) {
2029 temp |= PORT_OWNER;
2030 } else {
2031 temp |= PORT_RESET;
2032 temp &= ~PORT_PE;
2033
2034 /*
2035 * caller must wait, then call GetPortStatus
2036 * usb 2.0 spec says 50 ms resets on root
2037 */
2038 priv->reset_done = jiffies +
2039 msecs_to_jiffies(50);
2040 }
2041 isp1760_writel(temp, status_reg);
2042 break;
2043 default:
2044 goto error;
2045 }
2046 isp1760_readl(hcd->regs + HC_USBCMD);
2047 break;
2048
2049 default:
2050error:
2051 /* "stall" on error */
2052 retval = -EPIPE;
2053 }
2054 spin_unlock_irqrestore(&priv->lock, flags);
2055 return retval;
2056}
2057
2058static void isp1760_endpoint_disable(struct usb_hcd *usb_hcd,
2059 struct usb_host_endpoint *ep)
2060{
2061 struct isp1760_hcd *priv = hcd_to_priv(usb_hcd);
2062 struct isp1760_qh *qh;
2063 struct isp1760_qtd *qtd;
2064 u32 flags;
2065
2066 spin_lock_irqsave(&priv->lock, flags);
2067 qh = ep->hcpriv;
2068 if (!qh)
2069 goto out;
2070
2071 ep->hcpriv = NULL;
2072 do {
2073 /* more than entry might get removed */
2074 if (list_empty(&qh->qtd_list))
2075 break;
2076
2077 qtd = list_first_entry(&qh->qtd_list, struct isp1760_qtd,
2078 qtd_list);
2079
2080 if (qtd->status & URB_ENQUEUED) {
2081
2082 spin_unlock_irqrestore(&priv->lock, flags);
2083 isp1760_urb_dequeue(usb_hcd, qtd->urb, -ECONNRESET);
2084 spin_lock_irqsave(&priv->lock, flags);
2085 } else {
2086 struct urb *urb;
2087
2088 urb = qtd->urb;
2089 clean_up_qtdlist(qtd);
2090 isp1760_urb_done(priv, urb, -ECONNRESET);
2091 }
2092 } while (1);
2093
2094 qh_destroy(qh);
2095 /* remove requests and leak them.
2096 * ATL are pretty fast done, INT could take a while...
2097 * The latter shoule be removed
2098 */
2099out:
2100 spin_unlock_irqrestore(&priv->lock, flags);
2101}
2102
2103static int isp1760_get_frame(struct usb_hcd *hcd)
2104{
2105 struct isp1760_hcd *priv = hcd_to_priv(hcd);
2106 u32 fr;
2107
2108 fr = isp1760_readl(hcd->regs + HC_FRINDEX);
2109 return (fr >> 3) % priv->periodic_size;
2110}
2111
2112static void isp1760_stop(struct usb_hcd *hcd)
2113{
2114 struct isp1760_hcd *priv = hcd_to_priv(hcd);
2115
2116 isp1760_hub_control(hcd, ClearPortFeature, USB_PORT_FEAT_POWER, 1,
2117 NULL, 0);
2118 mdelay(20);
2119
2120 spin_lock_irq(&priv->lock);
2121 ehci_reset(priv);
2122 /* Disable IRQ */
2123 isp1760_writel(HW_DATA_BUS_32BIT, hcd->regs + HC_HW_MODE_CTRL);
2124 spin_unlock_irq(&priv->lock);
2125
2126 isp1760_writel(0, hcd->regs + HC_CONFIGFLAG);
2127}
2128
2129static void isp1760_shutdown(struct usb_hcd *hcd)
2130{
2131 u32 command;
2132
2133 isp1760_stop(hcd);
2134 isp1760_writel(HW_DATA_BUS_32BIT, hcd->regs + HC_HW_MODE_CTRL);
2135
2136 command = isp1760_readl(hcd->regs + HC_USBCMD);
2137 command &= ~CMD_RUN;
2138 isp1760_writel(command, hcd->regs + HC_USBCMD);
2139}
2140
2141static const struct hc_driver isp1760_hc_driver = {
2142 .description = "isp1760-hcd",
2143 .product_desc = "NXP ISP1760 USB Host Controller",
2144 .hcd_priv_size = sizeof(struct isp1760_hcd),
2145 .irq = isp1760_irq,
2146 .flags = HCD_MEMORY | HCD_USB2,
2147 .reset = isp1760_hc_setup,
2148 .start = isp1760_run,
2149 .stop = isp1760_stop,
2150 .shutdown = isp1760_shutdown,
2151 .urb_enqueue = isp1760_urb_enqueue,
2152 .urb_dequeue = isp1760_urb_dequeue,
2153 .endpoint_disable = isp1760_endpoint_disable,
2154 .get_frame_number = isp1760_get_frame,
2155 .hub_status_data = isp1760_hub_status_data,
2156 .hub_control = isp1760_hub_control,
2157};
2158
2159int __init init_kmem_once(void)
2160{
2161 qtd_cachep = kmem_cache_create("isp1760_qtd",
2162 sizeof(struct isp1760_qtd), 0, SLAB_TEMPORARY |
2163 SLAB_MEM_SPREAD, NULL);
2164
2165 if (!qtd_cachep)
2166 return -ENOMEM;
2167
2168 qh_cachep = kmem_cache_create("isp1760_qh", sizeof(struct isp1760_qh),
2169 0, SLAB_TEMPORARY | SLAB_MEM_SPREAD, NULL);
2170
2171 if (!qh_cachep) {
2172 kmem_cache_destroy(qtd_cachep);
2173 return -ENOMEM;
2174 }
2175
2176 return 0;
2177}
2178
2179void deinit_kmem_cache(void)
2180{
2181 kmem_cache_destroy(qtd_cachep);
2182 kmem_cache_destroy(qh_cachep);
2183}
2184
2185struct usb_hcd *isp1760_register(u64 res_start, u64 res_len, int irq,
2186 u64 irqflags, struct device *dev, const char *busname)
2187{
2188 struct usb_hcd *hcd;
2189 struct isp1760_hcd *priv;
2190 int ret;
2191
2192 if (usb_disabled())
2193 return ERR_PTR(-ENODEV);
2194
2195 /* prevent usb-core allocating DMA pages */
2196 dev->dma_mask = NULL;
2197
2198 hcd = usb_create_hcd(&isp1760_hc_driver, dev, dev->bus_id);
2199 if (!hcd)
2200 return ERR_PTR(-ENOMEM);
2201
2202 priv = hcd_to_priv(hcd);
2203 init_memory(priv);
2204 hcd->regs = ioremap(res_start, res_len);
2205 if (!hcd->regs) {
2206 ret = -EIO;
2207 goto err_put;
2208 }
2209
2210 ret = usb_add_hcd(hcd, irq, irqflags);
2211 if (ret)
2212 goto err_unmap;
2213
2214 hcd->irq = irq;
2215 hcd->rsrc_start = res_start;
2216 hcd->rsrc_len = res_len;
2217
2218 return hcd;
2219
2220err_unmap:
2221 iounmap(hcd->regs);
2222
2223err_put:
2224 usb_put_hcd(hcd);
2225
2226 return ERR_PTR(ret);
2227}
2228
2229MODULE_DESCRIPTION("Driver for the ISP1760 USB-controller from NXP");
2230MODULE_AUTHOR("Sebastian Siewior <bigeasy@linuxtronix.de>");
2231MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/host/isp1760-hcd.h b/drivers/usb/host/isp1760-hcd.h
new file mode 100644
index 000000000000..3d86d0f6b147
--- /dev/null
+++ b/drivers/usb/host/isp1760-hcd.h
@@ -0,0 +1,206 @@
1#ifndef _ISP1760_HCD_H_
2#define _ISP1760_HCD_H_
3
4/* exports for if */
5struct usb_hcd *isp1760_register(u64 res_start, u64 res_len, int irq,
6 u64 irqflags, struct device *dev, const char *busname);
7int init_kmem_once(void);
8void deinit_kmem_cache(void);
9
10/* EHCI capability registers */
11#define HC_CAPLENGTH 0x00
12#define HC_HCSPARAMS 0x04
13#define HC_HCCPARAMS 0x08
14
15/* EHCI operational registers */
16#define HC_USBCMD 0x20
17#define HC_USBSTS 0x24
18#define HC_FRINDEX 0x2c
19#define HC_CONFIGFLAG 0x60
20#define HC_PORTSC1 0x64
21#define HC_ISO_PTD_DONEMAP_REG 0x130
22#define HC_ISO_PTD_SKIPMAP_REG 0x134
23#define HC_ISO_PTD_LASTPTD_REG 0x138
24#define HC_INT_PTD_DONEMAP_REG 0x140
25#define HC_INT_PTD_SKIPMAP_REG 0x144
26#define HC_INT_PTD_LASTPTD_REG 0x148
27#define HC_ATL_PTD_DONEMAP_REG 0x150
28#define HC_ATL_PTD_SKIPMAP_REG 0x154
29#define HC_ATL_PTD_LASTPTD_REG 0x158
30
31/* Configuration Register */
32#define HC_HW_MODE_CTRL 0x300
33#define ALL_ATX_RESET (1 << 31)
34#define HW_DATA_BUS_32BIT (1 << 8)
35#define HW_DACK_POL_HIGH (1 << 6)
36#define HW_DREQ_POL_HIGH (1 << 5)
37#define HW_INTR_HIGH_ACT (1 << 2)
38#define HW_INTR_EDGE_TRIG (1 << 1)
39#define HW_GLOBAL_INTR_EN (1 << 0)
40
41#define HC_CHIP_ID_REG 0x304
42#define HC_SCRATCH_REG 0x308
43
44#define HC_RESET_REG 0x30c
45#define SW_RESET_RESET_HC (1 << 1)
46#define SW_RESET_RESET_ALL (1 << 0)
47
48#define HC_BUFFER_STATUS_REG 0x334
49#define ATL_BUFFER 0x1
50#define INT_BUFFER 0x2
51#define ISO_BUFFER 0x4
52#define BUFFER_MAP 0x7
53
54#define HC_MEMORY_REG 0x33c
55#define HC_PORT1_CTRL 0x374
56#define PORT1_POWER (3 << 3)
57#define PORT1_INIT1 (1 << 7)
58#define PORT1_INIT2 (1 << 23)
59
60/* Interrupt Register */
61#define HC_INTERRUPT_REG 0x310
62
63#define HC_INTERRUPT_ENABLE 0x314
64#define INTERRUPT_ENABLE_MASK (HC_INTL_INT | HC_ATL_INT | HC_EOT_INT)
65#define FINAL_HW_CONFIG (HW_GLOBAL_INTR_EN | HW_DATA_BUS_32BIT)
66
67#define HC_ISO_INT (1 << 9)
68#define HC_ATL_INT (1 << 8)
69#define HC_INTL_INT (1 << 7)
70#define HC_EOT_INT (1 << 3)
71#define HC_SOT_INT (1 << 1)
72
73#define HC_ISO_IRQ_MASK_OR_REG 0x318
74#define HC_INT_IRQ_MASK_OR_REG 0x31C
75#define HC_ATL_IRQ_MASK_OR_REG 0x320
76#define HC_ISO_IRQ_MASK_AND_REG 0x324
77#define HC_INT_IRQ_MASK_AND_REG 0x328
78#define HC_ATL_IRQ_MASK_AND_REG 0x32C
79
80/* Register sets */
81#define HC_BEGIN_OF_ATL 0x0c00
82#define HC_BEGIN_OF_INT 0x0800
83#define HC_BEGIN_OF_ISO 0x0400
84#define HC_BEGIN_OF_PAYLOAD 0x1000
85
86/* urb state*/
87#define DELETE_URB (0x0008)
88#define NO_TRANSFER_ACTIVE (0xffffffff)
89
90#define ATL_REGS_OFFSET (0xc00)
91#define INT_REGS_OFFSET (0x800)
92
93/* Philips Transfer Descriptor (PTD) */
94struct ptd {
95 __le32 dw0;
96 __le32 dw1;
97 __le32 dw2;
98 __le32 dw3;
99 __le32 dw4;
100 __le32 dw5;
101 __le32 dw6;
102 __le32 dw7;
103};
104
105struct inter_packet_info {
106 void *data_buffer;
107 u32 payload;
108#define PTD_FIRE_NEXT (1 << 0)
109#define PTD_URB_FINISHED (1 << 1)
110 struct urb *urb;
111 struct isp1760_qh *qh;
112 struct isp1760_qtd *qtd;
113};
114
115
116typedef void (packet_enqueue)(struct usb_hcd *hcd, struct isp1760_qh *qh,
117 struct isp1760_qtd *qtd);
118
119#define isp1760_info(priv, fmt, args...) \
120 dev_info(priv_to_hcd(priv)->self.controller, fmt, ##args)
121
122#define isp1760_err(priv, fmt, args...) \
123 dev_err(priv_to_hcd(priv)->self.controller, fmt, ##args)
124
125/* chip memory management */
126struct memory_chunk {
127 unsigned int start;
128 unsigned int size;
129 unsigned int free;
130};
131
132/*
133 * 60kb divided in:
134 * - 32 blocks @ 256 bytes
135 * - 20 blocks @ 1024 bytes
136 * - 4 blocks @ 8192 bytes
137 */
138
139#define BLOCK_1_NUM 32
140#define BLOCK_2_NUM 20
141#define BLOCK_3_NUM 4
142
143#define BLOCK_1_SIZE 256
144#define BLOCK_2_SIZE 1024
145#define BLOCK_3_SIZE 8192
146#define BLOCKS (BLOCK_1_NUM + BLOCK_2_NUM + BLOCK_3_NUM)
147#define PAYLOAD_SIZE 0xf000
148
149/* I saw if some reloads if the pointer was negative */
150#define ISP1760_NULL_POINTER (0x400)
151
152/* ATL */
153/* DW0 */
154#define PTD_VALID 1
155#define PTD_LENGTH(x) (((u32) x) << 3)
156#define PTD_MAXPACKET(x) (((u32) x) << 18)
157#define PTD_MULTI(x) (((u32) x) << 29)
158#define PTD_ENDPOINT(x) (((u32) x) << 31)
159/* DW1 */
160#define PTD_DEVICE_ADDR(x) (((u32) x) << 3)
161#define PTD_PID_TOKEN(x) (((u32) x) << 10)
162#define PTD_TRANS_BULK ((u32) 2 << 12)
163#define PTD_TRANS_INT ((u32) 3 << 12)
164#define PTD_TRANS_SPLIT ((u32) 1 << 14)
165#define PTD_SE_USB_LOSPEED ((u32) 2 << 16)
166#define PTD_PORT_NUM(x) (((u32) x) << 18)
167#define PTD_HUB_NUM(x) (((u32) x) << 25)
168#define PTD_PING(x) (((u32) x) << 26)
169/* DW2 */
170#define PTD_RL_CNT(x) (((u32) x) << 25)
171#define PTD_DATA_START_ADDR(x) (((u32) x) << 8)
172#define BASE_ADDR 0x1000
173/* DW3 */
174#define PTD_CERR(x) (((u32) x) << 23)
175#define PTD_NAC_CNT(x) (((u32) x) << 19)
176#define PTD_ACTIVE ((u32) 1 << 31)
177#define PTD_DATA_TOGGLE(x) (((u32) x) << 25)
178
179#define DW3_HALT_BIT (1 << 30)
180#define DW3_ERROR_BIT (1 << 28)
181#define DW3_QTD_ACTIVE (1 << 31)
182
183#define INT_UNDERRUN (1 << 2)
184#define INT_BABBLE (1 << 1)
185#define INT_EXACT (1 << 0)
186
187#define DW1_GET_PID(x) (((x) >> 10) & 0x3)
188#define PTD_XFERRED_LENGTH(x) ((x) & 0x7fff)
189#define PTD_XFERRED_LENGTH_LO(x) ((x) & 0x7ff)
190
191#define SETUP_PID (2)
192#define IN_PID (1)
193#define OUT_PID (0)
194#define GET_QTD_TOKEN_TYPE(x) ((x) & 0x3)
195
196#define DATA_TOGGLE (1 << 31)
197#define GET_DATA_TOGGLE(x) ((x) >> 31)
198
199/* Errata 1 */
200#define RL_COUNTER (0)
201#define NAK_COUNTER (0)
202#define ERR_COUNTER (2)
203
204#define HC_ATL_PL_SIZE (8192)
205
206#endif
diff --git a/drivers/usb/host/isp1760-if.c b/drivers/usb/host/isp1760-if.c
new file mode 100644
index 000000000000..73fb2a38f1e4
--- /dev/null
+++ b/drivers/usb/host/isp1760-if.c
@@ -0,0 +1,298 @@
1/*
2 * Glue code for the ISP1760 driver and bus
3 * Currently there is support for
4 * - OpenFirmware
5 * - PCI
6 *
7 * (c) 2007 Sebastian Siewior <bigeasy@linutronix.de>
8 *
9 */
10
11#include <linux/usb.h>
12#include <linux/io.h>
13
14#include "../core/hcd.h"
15#include "isp1760-hcd.h"
16
17#ifdef CONFIG_USB_ISP1760_OF
18#include <linux/of.h>
19#include <linux/of_platform.h>
20#endif
21
22#ifdef CONFIG_USB_ISP1760_PCI
23#include <linux/pci.h>
24#endif
25
26#ifdef CONFIG_USB_ISP1760_OF
27static int of_isp1760_probe(struct of_device *dev,
28 const struct of_device_id *match)
29{
30 struct usb_hcd *hcd;
31 struct device_node *dp = dev->node;
32 struct resource *res;
33 struct resource memory;
34 struct of_irq oirq;
35 int virq;
36 u64 res_len;
37 int ret;
38
39 ret = of_address_to_resource(dp, 0, &memory);
40 if (ret)
41 return -ENXIO;
42
43 res = request_mem_region(memory.start, memory.end - memory.start + 1,
44 dev->dev.bus_id);
45 if (!res)
46 return -EBUSY;
47
48 res_len = memory.end - memory.start + 1;
49
50 if (of_irq_map_one(dp, 0, &oirq)) {
51 ret = -ENODEV;
52 goto release_reg;
53 }
54
55 virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
56 oirq.size);
57
58 hcd = isp1760_register(memory.start, res_len, virq,
59 IRQF_SHARED | IRQF_DISABLED, &dev->dev, dev->dev.bus_id);
60 if (IS_ERR(hcd)) {
61 ret = PTR_ERR(hcd);
62 goto release_reg;
63 }
64
65 dev_set_drvdata(&dev->dev, hcd);
66 return ret;
67
68release_reg:
69 release_mem_region(memory.start, memory.end - memory.start + 1);
70 return ret;
71}
72
73static int of_isp1760_remove(struct of_device *dev)
74{
75 struct usb_hcd *hcd = dev_get_drvdata(&dev->dev);
76
77 dev_set_drvdata(&dev->dev, NULL);
78
79 usb_remove_hcd(hcd);
80 iounmap(hcd->regs);
81 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
82 usb_put_hcd(hcd);
83 return 0;
84}
85
86static struct of_device_id of_isp1760_match[] = {
87 {
88 .compatible = "nxp,usb-isp1760",
89 },
90 { },
91};
92MODULE_DEVICE_TABLE(of, of_isp1760_match);
93
94static struct of_platform_driver isp1760_of_driver = {
95 .name = "nxp-isp1760",
96 .match_table = of_isp1760_match,
97 .probe = of_isp1760_probe,
98 .remove = of_isp1760_remove,
99};
100#endif
101
102#ifdef CONFIG_USB_ISP1760_PCI
103static u32 nxp_pci_io_base;
104static u32 iolength;
105static u32 pci_mem_phy0;
106static u32 length;
107static u8 *chip_addr;
108static u8 *iobase;
109
110static int __devinit isp1761_pci_probe(struct pci_dev *dev,
111 const struct pci_device_id *id)
112{
113 u8 latency, limit;
114 __u32 reg_data;
115 int retry_count;
116 int length;
117 int status = 1;
118 struct usb_hcd *hcd;
119
120 if (usb_disabled())
121 return -ENODEV;
122
123 if (pci_enable_device(dev) < 0)
124 return -ENODEV;
125
126 if (!dev->irq)
127 return -ENODEV;
128
129 /* Grab the PLX PCI mem maped port start address we need */
130 nxp_pci_io_base = pci_resource_start(dev, 0);
131 iolength = pci_resource_len(dev, 0);
132
133 if (!request_mem_region(nxp_pci_io_base, iolength, "ISP1761 IO MEM")) {
134 printk(KERN_ERR "request region #1\n");
135 return -EBUSY;
136 }
137
138 iobase = ioremap_nocache(nxp_pci_io_base, iolength);
139 if (!iobase) {
140 printk(KERN_ERR "ioremap #1\n");
141 release_mem_region(nxp_pci_io_base, iolength);
142 return -ENOMEM;
143 }
144 /* Grab the PLX PCI shared memory of the ISP 1761 we need */
145 pci_mem_phy0 = pci_resource_start(dev, 3);
146 length = pci_resource_len(dev, 3);
147
148 if (length < 0xffff) {
149 printk(KERN_ERR "memory length for this resource is less than "
150 "required\n");
151 release_mem_region(nxp_pci_io_base, iolength);
152 iounmap(iobase);
153 return -ENOMEM;
154 }
155
156 if (!request_mem_region(pci_mem_phy0, length, "ISP-PCI")) {
157 printk(KERN_ERR "host controller already in use\n");
158 release_mem_region(nxp_pci_io_base, iolength);
159 iounmap(iobase);
160 return -EBUSY;
161 }
162
163 /* bad pci latencies can contribute to overruns */
164 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &latency);
165 if (latency) {
166 pci_read_config_byte(dev, PCI_MAX_LAT, &limit);
167 if (limit && limit < latency)
168 pci_write_config_byte(dev, PCI_LATENCY_TIMER, limit);
169 }
170
171 /* Try to check whether we can access Scratch Register of
172 * Host Controller or not. The initial PCI access is retried until
173 * local init for the PCI bridge is completed
174 */
175 retry_count = 20;
176 reg_data = 0;
177 while ((reg_data != 0xFACE) && retry_count) {
178 /*by default host is in 16bit mode, so
179 * io operations at this stage must be 16 bit
180 * */
181 writel(0xface, chip_addr + HC_SCRATCH_REG);
182 udelay(100);
183 reg_data = readl(chip_addr + HC_SCRATCH_REG);
184 retry_count--;
185 }
186
187 /* Host Controller presence is detected by writing to scratch register
188 * and reading back and checking the contents are same or not
189 */
190 if (reg_data != 0xFACE) {
191 err("scratch register mismatch %x", reg_data);
192 goto clean;
193 }
194
195 pci_set_master(dev);
196
197 status = readl(iobase + 0x68);
198 status |= 0x900;
199 writel(status, iobase + 0x68);
200
201 dev->dev.dma_mask = NULL;
202 hcd = isp1760_register(pci_mem_phy0, length, dev->irq,
203 IRQF_SHARED | IRQF_DISABLED, &dev->dev, dev->dev.bus_id);
204 pci_set_drvdata(dev, hcd);
205 if (!hcd)
206 return 0;
207clean:
208 status = -ENODEV;
209 iounmap(iobase);
210 release_mem_region(pci_mem_phy0, length);
211 release_mem_region(nxp_pci_io_base, iolength);
212 return status;
213}
214static void isp1761_pci_remove(struct pci_dev *dev)
215{
216 struct usb_hcd *hcd;
217
218 hcd = pci_get_drvdata(dev);
219
220 usb_remove_hcd(hcd);
221 iounmap(hcd->regs);
222 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
223 usb_put_hcd(hcd);
224
225 pci_disable_device(dev);
226
227 iounmap(iobase);
228 iounmap(chip_addr);
229
230 release_mem_region(nxp_pci_io_base, iolength);
231 release_mem_region(pci_mem_phy0, length);
232}
233
234static void isp1761_pci_shutdown(struct pci_dev *dev)
235{
236 printk(KERN_ERR "ips1761_pci_shutdown\n");
237}
238
239static const struct pci_device_id isp1760_plx [] = { {
240 /* handle any USB 2.0 EHCI controller */
241 PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_OTHER << 8) | (0x06 << 16)), ~0),
242 .driver_data = 0,
243},
244{ /* end: all zeroes */ }
245};
246MODULE_DEVICE_TABLE(pci, isp1760_plx);
247
248static struct pci_driver isp1761_pci_driver = {
249 .name = "isp1760",
250 .id_table = isp1760_plx,
251 .probe = isp1761_pci_probe,
252 .remove = isp1761_pci_remove,
253 .shutdown = isp1761_pci_shutdown,
254};
255#endif
256
257static int __init isp1760_init(void)
258{
259 int ret;
260
261 init_kmem_once();
262
263#ifdef CONFIG_USB_ISP1760_OF
264 ret = of_register_platform_driver(&isp1760_of_driver);
265 if (ret) {
266 deinit_kmem_cache();
267 return ret;
268 }
269#endif
270#ifdef CONFIG_USB_ISP1760_PCI
271 ret = pci_register_driver(&isp1761_pci_driver);
272 if (ret)
273 goto unreg_of;
274#endif
275 return ret;
276
277#ifdef CONFIG_USB_ISP1760_PCI
278unreg_of:
279#endif
280#ifdef CONFIG_USB_ISP1760_OF
281 of_unregister_platform_driver(&isp1760_of_driver);
282#endif
283 deinit_kmem_cache();
284 return ret;
285}
286module_init(isp1760_init);
287
288static void __exit isp1760_exit(void)
289{
290#ifdef CONFIG_USB_ISP1760_OF
291 of_unregister_platform_driver(&isp1760_of_driver);
292#endif
293#ifdef CONFIG_USB_ISP1760_PCI
294 pci_unregister_driver(&isp1761_pci_driver);
295#endif
296 deinit_kmem_cache();
297}
298module_exit(isp1760_exit);
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index 17dc2eccda83..79a78029f896 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -613,7 +613,7 @@ static void start_hnp(struct ohci_hcd *ohci);
613static inline int root_port_reset (struct ohci_hcd *ohci, unsigned port) 613static inline int root_port_reset (struct ohci_hcd *ohci, unsigned port)
614{ 614{
615 __hc32 __iomem *portstat = &ohci->regs->roothub.portstatus [port]; 615 __hc32 __iomem *portstat = &ohci->regs->roothub.portstatus [port];
616 u32 temp; 616 u32 temp = 0;
617 u16 now = ohci_readl(ohci, &ohci->regs->fmnumber); 617 u16 now = ohci_readl(ohci, &ohci->regs->fmnumber);
618 u16 reset_done = now + PORT_RESET_MSEC; 618 u16 reset_done = now + PORT_RESET_MSEC;
619 int limit_1 = DIV_ROUND_UP(PORT_RESET_MSEC, PORT_RESET_HW_MSEC); 619 int limit_1 = DIV_ROUND_UP(PORT_RESET_MSEC, PORT_RESET_HW_MSEC);
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index d3e0d8aa3980..3a7bfe7a8874 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -234,7 +234,7 @@ static int resume_detect_interrupts_are_broken(struct uhci_hcd *uhci)
234 return 0; 234 return 0;
235} 235}
236 236
237static int remote_wakeup_is_broken(struct uhci_hcd *uhci) 237static int global_suspend_mode_is_broken(struct uhci_hcd *uhci)
238{ 238{
239 int port; 239 int port;
240 const char *sys_info; 240 const char *sys_info;
@@ -261,27 +261,60 @@ __releases(uhci->lock)
261__acquires(uhci->lock) 261__acquires(uhci->lock)
262{ 262{
263 int auto_stop; 263 int auto_stop;
264 int int_enable, egsm_enable; 264 int int_enable, egsm_enable, wakeup_enable;
265 struct usb_device *rhdev = uhci_to_hcd(uhci)->self.root_hub; 265 struct usb_device *rhdev = uhci_to_hcd(uhci)->self.root_hub;
266 266
267 auto_stop = (new_state == UHCI_RH_AUTO_STOPPED); 267 auto_stop = (new_state == UHCI_RH_AUTO_STOPPED);
268 dev_dbg(&rhdev->dev, "%s%s\n", __func__, 268 dev_dbg(&rhdev->dev, "%s%s\n", __func__,
269 (auto_stop ? " (auto-stop)" : "")); 269 (auto_stop ? " (auto-stop)" : ""));
270 270
271 /* Enable resume-detect interrupts if they work. 271 /* Start off by assuming Resume-Detect interrupts and EGSM work
272 * Then enter Global Suspend mode if _it_ works, still configured. 272 * and that remote wakeups should be enabled.
273 */ 273 */
274 egsm_enable = USBCMD_EGSM; 274 egsm_enable = USBCMD_EGSM;
275 uhci->working_RD = 1; 275 uhci->RD_enable = 1;
276 int_enable = USBINTR_RESUME; 276 int_enable = USBINTR_RESUME;
277 if (remote_wakeup_is_broken(uhci)) 277 wakeup_enable = 1;
278 egsm_enable = 0; 278
279 if (resume_detect_interrupts_are_broken(uhci) || !egsm_enable || 279 /* In auto-stop mode wakeups must always be detected, but
280 * Resume-Detect interrupts may be prohibited. (In the absence
281 * of CONFIG_PM, they are always disallowed.)
282 */
283 if (auto_stop) {
284 if (!device_may_wakeup(&rhdev->dev))
285 int_enable = 0;
286
287 /* In bus-suspend mode wakeups may be disabled, but if they are
288 * allowed then so are Resume-Detect interrupts.
289 */
290 } else {
280#ifdef CONFIG_PM 291#ifdef CONFIG_PM
281 (!auto_stop && !rhdev->do_remote_wakeup) || 292 if (!rhdev->do_remote_wakeup)
293 wakeup_enable = 0;
282#endif 294#endif
283 (auto_stop && !device_may_wakeup(&rhdev->dev))) 295 }
284 uhci->working_RD = int_enable = 0; 296
297 /* EGSM causes the root hub to echo a 'K' signal (resume) out any
298 * port which requests a remote wakeup. According to the USB spec,
299 * every hub is supposed to do this. But if we are ignoring
300 * remote-wakeup requests anyway then there's no point to it.
301 * We also shouldn't enable EGSM if it's broken.
302 */
303 if (!wakeup_enable || global_suspend_mode_is_broken(uhci))
304 egsm_enable = 0;
305
306 /* If we're ignoring wakeup events then there's no reason to
307 * enable Resume-Detect interrupts. We also shouldn't enable
308 * them if they are broken or disallowed.
309 *
310 * This logic may lead us to enabling RD but not EGSM. The UHCI
311 * spec foolishly says that RD works only when EGSM is on, but
312 * there's no harm in enabling it anyway -- perhaps some chips
313 * will implement it!
314 */
315 if (!wakeup_enable || resume_detect_interrupts_are_broken(uhci) ||
316 !int_enable)
317 uhci->RD_enable = int_enable = 0;
285 318
286 outw(int_enable, uhci->io_addr + USBINTR); 319 outw(int_enable, uhci->io_addr + USBINTR);
287 outw(egsm_enable | USBCMD_CF, uhci->io_addr + USBCMD); 320 outw(egsm_enable | USBCMD_CF, uhci->io_addr + USBCMD);
@@ -308,7 +341,11 @@ __acquires(uhci->lock)
308 341
309 uhci->rh_state = new_state; 342 uhci->rh_state = new_state;
310 uhci->is_stopped = UHCI_IS_STOPPED; 343 uhci->is_stopped = UHCI_IS_STOPPED;
311 uhci_to_hcd(uhci)->poll_rh = !int_enable; 344
345 /* If interrupts don't work and remote wakeup is enabled then
346 * the suspended root hub needs to be polled.
347 */
348 uhci_to_hcd(uhci)->poll_rh = (!int_enable && wakeup_enable);
312 349
313 uhci_scan_schedule(uhci); 350 uhci_scan_schedule(uhci);
314 uhci_fsbr_off(uhci); 351 uhci_fsbr_off(uhci);
@@ -344,9 +381,12 @@ __acquires(uhci->lock)
344 * for 20 ms. 381 * for 20 ms.
345 */ 382 */
346 if (uhci->rh_state == UHCI_RH_SUSPENDED) { 383 if (uhci->rh_state == UHCI_RH_SUSPENDED) {
384 unsigned egsm;
385
386 /* Keep EGSM on if it was set before */
387 egsm = inw(uhci->io_addr + USBCMD) & USBCMD_EGSM;
347 uhci->rh_state = UHCI_RH_RESUMING; 388 uhci->rh_state = UHCI_RH_RESUMING;
348 outw(USBCMD_FGR | USBCMD_EGSM | USBCMD_CF, 389 outw(USBCMD_FGR | USBCMD_CF | egsm, uhci->io_addr + USBCMD);
349 uhci->io_addr + USBCMD);
350 spin_unlock_irq(&uhci->lock); 390 spin_unlock_irq(&uhci->lock);
351 msleep(20); 391 msleep(20);
352 spin_lock_irq(&uhci->lock); 392 spin_lock_irq(&uhci->lock);
@@ -801,8 +841,10 @@ static int uhci_pci_resume(struct usb_hcd *hcd)
801 841
802 spin_unlock_irq(&uhci->lock); 842 spin_unlock_irq(&uhci->lock);
803 843
804 if (!uhci->working_RD) { 844 /* If interrupts don't work and remote wakeup is enabled then
805 /* Suspended root hub needs to be polled */ 845 * the suspended root hub needs to be polled.
846 */
847 if (!uhci->RD_enable && hcd->self.root_hub->do_remote_wakeup) {
806 hcd->poll_rh = 1; 848 hcd->poll_rh = 1;
807 usb_hcd_poll_rh_status(hcd); 849 usb_hcd_poll_rh_status(hcd);
808 } 850 }
diff --git a/drivers/usb/host/uhci-hcd.h b/drivers/usb/host/uhci-hcd.h
index 340d6ed3e6e9..7d01c5677f92 100644
--- a/drivers/usb/host/uhci-hcd.h
+++ b/drivers/usb/host/uhci-hcd.h
@@ -400,8 +400,9 @@ struct uhci_hcd {
400 unsigned int scan_in_progress:1; /* Schedule scan is running */ 400 unsigned int scan_in_progress:1; /* Schedule scan is running */
401 unsigned int need_rescan:1; /* Redo the schedule scan */ 401 unsigned int need_rescan:1; /* Redo the schedule scan */
402 unsigned int dead:1; /* Controller has died */ 402 unsigned int dead:1; /* Controller has died */
403 unsigned int working_RD:1; /* Suspended root hub doesn't 403 unsigned int RD_enable:1; /* Suspended root hub with
404 need to be polled */ 404 Resume-Detect interrupts
405 enabled */
405 unsigned int is_initialized:1; /* Data structure is usable */ 406 unsigned int is_initialized:1; /* Data structure is usable */
406 unsigned int fsbr_is_on:1; /* FSBR is turned on */ 407 unsigned int fsbr_is_on:1; /* FSBR is turned on */
407 unsigned int fsbr_is_wanted:1; /* Does any URB want FSBR? */ 408 unsigned int fsbr_is_wanted:1; /* Does any URB want FSBR? */
diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
index 11580e81e2c6..7aafd53fbcab 100644
--- a/drivers/usb/misc/ldusb.c
+++ b/drivers/usb/misc/ldusb.c
@@ -148,7 +148,7 @@ MODULE_PARM_DESC(min_interrupt_out_interval, "Minimum interrupt out interval in
148 148
149/* Structure to hold all of our device specific stuff */ 149/* Structure to hold all of our device specific stuff */
150struct ld_usb { 150struct ld_usb {
151 struct semaphore sem; /* locks this structure */ 151 struct mutex mutex; /* locks this structure */
152 struct usb_interface* intf; /* save off the usb interface pointer */ 152 struct usb_interface* intf; /* save off the usb interface pointer */
153 153
154 int open_count; /* number of times this port has been opened */ 154 int open_count; /* number of times this port has been opened */
@@ -319,7 +319,7 @@ static int ld_usb_open(struct inode *inode, struct file *file)
319 return -ENODEV; 319 return -ENODEV;
320 320
321 /* lock this device */ 321 /* lock this device */
322 if (down_interruptible(&dev->sem)) 322 if (mutex_lock_interruptible(&dev->mutex))
323 return -ERESTARTSYS; 323 return -ERESTARTSYS;
324 324
325 /* allow opening only once */ 325 /* allow opening only once */
@@ -358,7 +358,7 @@ static int ld_usb_open(struct inode *inode, struct file *file)
358 file->private_data = dev; 358 file->private_data = dev;
359 359
360unlock_exit: 360unlock_exit:
361 up(&dev->sem); 361 mutex_unlock(&dev->mutex);
362 362
363 return retval; 363 return retval;
364} 364}
@@ -378,7 +378,7 @@ static int ld_usb_release(struct inode *inode, struct file *file)
378 goto exit; 378 goto exit;
379 } 379 }
380 380
381 if (down_interruptible(&dev->sem)) { 381 if (mutex_lock_interruptible(&dev->mutex)) {
382 retval = -ERESTARTSYS; 382 retval = -ERESTARTSYS;
383 goto exit; 383 goto exit;
384 } 384 }
@@ -389,7 +389,7 @@ static int ld_usb_release(struct inode *inode, struct file *file)
389 } 389 }
390 if (dev->intf == NULL) { 390 if (dev->intf == NULL) {
391 /* the device was unplugged before the file was released */ 391 /* the device was unplugged before the file was released */
392 up(&dev->sem); 392 mutex_unlock(&dev->mutex);
393 /* unlock here as ld_usb_delete frees dev */ 393 /* unlock here as ld_usb_delete frees dev */
394 ld_usb_delete(dev); 394 ld_usb_delete(dev);
395 goto exit; 395 goto exit;
@@ -402,7 +402,7 @@ static int ld_usb_release(struct inode *inode, struct file *file)
402 dev->open_count = 0; 402 dev->open_count = 0;
403 403
404unlock_exit: 404unlock_exit:
405 up(&dev->sem); 405 mutex_unlock(&dev->mutex);
406 406
407exit: 407exit:
408 return retval; 408 return retval;
@@ -448,7 +448,7 @@ static ssize_t ld_usb_read(struct file *file, char __user *buffer, size_t count,
448 goto exit; 448 goto exit;
449 449
450 /* lock this object */ 450 /* lock this object */
451 if (down_interruptible(&dev->sem)) { 451 if (mutex_lock_interruptible(&dev->mutex)) {
452 retval = -ERESTARTSYS; 452 retval = -ERESTARTSYS;
453 goto exit; 453 goto exit;
454 } 454 }
@@ -505,7 +505,7 @@ static ssize_t ld_usb_read(struct file *file, char __user *buffer, size_t count,
505 505
506unlock_exit: 506unlock_exit:
507 /* unlock the device */ 507 /* unlock the device */
508 up(&dev->sem); 508 mutex_unlock(&dev->mutex);
509 509
510exit: 510exit:
511 return retval; 511 return retval;
@@ -528,7 +528,7 @@ static ssize_t ld_usb_write(struct file *file, const char __user *buffer,
528 goto exit; 528 goto exit;
529 529
530 /* lock this object */ 530 /* lock this object */
531 if (down_interruptible(&dev->sem)) { 531 if (mutex_lock_interruptible(&dev->mutex)) {
532 retval = -ERESTARTSYS; 532 retval = -ERESTARTSYS;
533 goto exit; 533 goto exit;
534 } 534 }
@@ -602,7 +602,7 @@ static ssize_t ld_usb_write(struct file *file, const char __user *buffer,
602 602
603unlock_exit: 603unlock_exit:
604 /* unlock the device */ 604 /* unlock the device */
605 up(&dev->sem); 605 mutex_unlock(&dev->mutex);
606 606
607exit: 607exit:
608 return retval; 608 return retval;
@@ -651,7 +651,7 @@ static int ld_usb_probe(struct usb_interface *intf, const struct usb_device_id *
651 dev_err(&intf->dev, "Out of memory\n"); 651 dev_err(&intf->dev, "Out of memory\n");
652 goto exit; 652 goto exit;
653 } 653 }
654 init_MUTEX(&dev->sem); 654 mutex_init(&dev->mutex);
655 spin_lock_init(&dev->rbsl); 655 spin_lock_init(&dev->rbsl);
656 dev->intf = intf; 656 dev->intf = intf;
657 init_waitqueue_head(&dev->read_wait); 657 init_waitqueue_head(&dev->read_wait);
@@ -765,15 +765,15 @@ static void ld_usb_disconnect(struct usb_interface *intf)
765 /* give back our minor */ 765 /* give back our minor */
766 usb_deregister_dev(intf, &ld_usb_class); 766 usb_deregister_dev(intf, &ld_usb_class);
767 767
768 down(&dev->sem); 768 mutex_lock(&dev->mutex);
769 769
770 /* if the device is not opened, then we clean up right now */ 770 /* if the device is not opened, then we clean up right now */
771 if (!dev->open_count) { 771 if (!dev->open_count) {
772 up(&dev->sem); 772 mutex_unlock(&dev->mutex);
773 ld_usb_delete(dev); 773 ld_usb_delete(dev);
774 } else { 774 } else {
775 dev->intf = NULL; 775 dev->intf = NULL;
776 up(&dev->sem); 776 mutex_unlock(&dev->mutex);
777 } 777 }
778 778
779 dev_info(&intf->dev, "LD USB Device #%d now disconnected\n", 779 dev_info(&intf->dev, "LD USB Device #%d now disconnected\n",
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index a51983854ca0..742be3c35947 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -79,30 +79,10 @@ static struct usb_device *testdev_to_usbdev (struct usbtest_dev *test)
79/* set up all urbs so they can be used with either bulk or interrupt */ 79/* set up all urbs so they can be used with either bulk or interrupt */
80#define INTERRUPT_RATE 1 /* msec/transfer */ 80#define INTERRUPT_RATE 1 /* msec/transfer */
81 81
82#define xprintk(tdev,level,fmt,args...) \ 82#define ERROR(tdev, fmt, args...) \
83 dev_printk(level , &(tdev)->intf->dev , fmt , ## args) 83 dev_err(&(tdev)->intf->dev , fmt , ## args)
84 84#define WARN(tdev, fmt, args...) \
85#ifdef DEBUG 85 dev_warn(&(tdev)->intf->dev , fmt , ## args)
86#define DBG(dev,fmt,args...) \
87 xprintk(dev , KERN_DEBUG , fmt , ## args)
88#else
89#define DBG(dev,fmt,args...) \
90 do { } while (0)
91#endif /* DEBUG */
92
93#ifdef VERBOSE
94#define VDBG DBG
95#else
96#define VDBG(dev,fmt,args...) \
97 do { } while (0)
98#endif /* VERBOSE */
99
100#define ERROR(dev,fmt,args...) \
101 xprintk(dev , KERN_ERR , fmt , ## args)
102#define WARN(dev,fmt,args...) \
103 xprintk(dev , KERN_WARNING , fmt , ## args)
104#define INFO(dev,fmt,args...) \
105 xprintk(dev , KERN_INFO , fmt , ## args)
106 86
107/*-------------------------------------------------------------------------*/ 87/*-------------------------------------------------------------------------*/
108 88
@@ -236,7 +216,7 @@ static struct urb *simple_alloc_urb (
236 216
237static unsigned pattern = 0; 217static unsigned pattern = 0;
238module_param (pattern, uint, S_IRUGO); 218module_param (pattern, uint, S_IRUGO);
239// MODULE_PARM_DESC (pattern, "i/o pattern (0 == zeroes)"); 219MODULE_PARM_DESC(pattern, "i/o pattern (0 == zeroes)");
240 220
241static inline void simple_fill_buf (struct urb *urb) 221static inline void simple_fill_buf (struct urb *urb)
242{ 222{
@@ -257,7 +237,7 @@ static inline void simple_fill_buf (struct urb *urb)
257 } 237 }
258} 238}
259 239
260static inline int simple_check_buf (struct urb *urb) 240static inline int simple_check_buf(struct usbtest_dev *tdev, struct urb *urb)
261{ 241{
262 unsigned i; 242 unsigned i;
263 u8 expected; 243 u8 expected;
@@ -285,7 +265,7 @@ static inline int simple_check_buf (struct urb *urb)
285 } 265 }
286 if (*buf == expected) 266 if (*buf == expected)
287 continue; 267 continue;
288 dbg ("buf[%d] = %d (not %d)", i, *buf, expected); 268 ERROR(tdev, "buf[%d] = %d (not %d)\n", i, *buf, expected);
289 return -EINVAL; 269 return -EINVAL;
290 } 270 }
291 return 0; 271 return 0;
@@ -299,6 +279,7 @@ static void simple_free_urb (struct urb *urb)
299} 279}
300 280
301static int simple_io ( 281static int simple_io (
282 struct usbtest_dev *tdev,
302 struct urb *urb, 283 struct urb *urb,
303 int iterations, 284 int iterations,
304 int vary, 285 int vary,
@@ -324,7 +305,7 @@ static int simple_io (
324 retval = urb->status; 305 retval = urb->status;
325 urb->dev = udev; 306 urb->dev = udev;
326 if (retval == 0 && usb_pipein (urb->pipe)) 307 if (retval == 0 && usb_pipein (urb->pipe))
327 retval = simple_check_buf (urb); 308 retval = simple_check_buf(tdev, urb);
328 309
329 if (vary) { 310 if (vary) {
330 int len = urb->transfer_buffer_length; 311 int len = urb->transfer_buffer_length;
@@ -341,7 +322,7 @@ static int simple_io (
341 urb->transfer_buffer_length = max; 322 urb->transfer_buffer_length = max;
342 323
343 if (expected != retval) 324 if (expected != retval)
344 dev_dbg (&udev->dev, 325 dev_err(&udev->dev,
345 "%s failed, iterations left %d, status %d (not %d)\n", 326 "%s failed, iterations left %d, status %d (not %d)\n",
346 label, iterations, retval, expected); 327 label, iterations, retval, expected);
347 return retval; 328 return retval;
@@ -357,7 +338,7 @@ static int simple_io (
357static void free_sglist (struct scatterlist *sg, int nents) 338static void free_sglist (struct scatterlist *sg, int nents)
358{ 339{
359 unsigned i; 340 unsigned i;
360 341
361 if (!sg) 342 if (!sg)
362 return; 343 return;
363 for (i = 0; i < nents; i++) { 344 for (i = 0; i < nents; i++) {
@@ -415,7 +396,7 @@ alloc_sglist (int nents, int max, int vary)
415} 396}
416 397
417static int perform_sglist ( 398static int perform_sglist (
418 struct usb_device *udev, 399 struct usbtest_dev *tdev,
419 unsigned iterations, 400 unsigned iterations,
420 int pipe, 401 int pipe,
421 struct usb_sg_request *req, 402 struct usb_sg_request *req,
@@ -423,6 +404,7 @@ static int perform_sglist (
423 int nents 404 int nents
424) 405)
425{ 406{
407 struct usb_device *udev = testdev_to_usbdev(tdev);
426 int retval = 0; 408 int retval = 0;
427 409
428 while (retval == 0 && iterations-- > 0) { 410 while (retval == 0 && iterations-- > 0) {
@@ -431,7 +413,7 @@ static int perform_sglist (
431 ? (INTERRUPT_RATE << 3) 413 ? (INTERRUPT_RATE << 3)
432 : INTERRUPT_RATE, 414 : INTERRUPT_RATE,
433 sg, nents, 0, GFP_KERNEL); 415 sg, nents, 0, GFP_KERNEL);
434 416
435 if (retval) 417 if (retval)
436 break; 418 break;
437 usb_sg_wait (req); 419 usb_sg_wait (req);
@@ -446,7 +428,8 @@ static int perform_sglist (
446 // failure if retval is as we expected ... 428 // failure if retval is as we expected ...
447 429
448 if (retval) 430 if (retval)
449 dbg ("perform_sglist failed, iterations left %d, status %d", 431 ERROR(tdev, "perform_sglist failed, "
432 "iterations left %d, status %d\n",
450 iterations, retval); 433 iterations, retval);
451 return retval; 434 return retval;
452} 435}
@@ -505,28 +488,28 @@ static int set_altsetting (struct usbtest_dev *dev, int alternate)
505 alternate); 488 alternate);
506} 489}
507 490
508static int is_good_config (char *buf, int len) 491static int is_good_config(struct usbtest_dev *tdev, int len)
509{ 492{
510 struct usb_config_descriptor *config; 493 struct usb_config_descriptor *config;
511 494
512 if (len < sizeof *config) 495 if (len < sizeof *config)
513 return 0; 496 return 0;
514 config = (struct usb_config_descriptor *) buf; 497 config = (struct usb_config_descriptor *) tdev->buf;
515 498
516 switch (config->bDescriptorType) { 499 switch (config->bDescriptorType) {
517 case USB_DT_CONFIG: 500 case USB_DT_CONFIG:
518 case USB_DT_OTHER_SPEED_CONFIG: 501 case USB_DT_OTHER_SPEED_CONFIG:
519 if (config->bLength != 9) { 502 if (config->bLength != 9) {
520 dbg ("bogus config descriptor length"); 503 ERROR(tdev, "bogus config descriptor length\n");
521 return 0; 504 return 0;
522 } 505 }
523 /* this bit 'must be 1' but often isn't */ 506 /* this bit 'must be 1' but often isn't */
524 if (!realworld && !(config->bmAttributes & 0x80)) { 507 if (!realworld && !(config->bmAttributes & 0x80)) {
525 dbg ("high bit of config attributes not set"); 508 ERROR(tdev, "high bit of config attributes not set\n");
526 return 0; 509 return 0;
527 } 510 }
528 if (config->bmAttributes & 0x1f) { /* reserved == 0 */ 511 if (config->bmAttributes & 0x1f) { /* reserved == 0 */
529 dbg ("reserved config bits set"); 512 ERROR(tdev, "reserved config bits set\n");
530 return 0; 513 return 0;
531 } 514 }
532 break; 515 break;
@@ -538,7 +521,7 @@ static int is_good_config (char *buf, int len)
538 return 1; 521 return 1;
539 if (le16_to_cpu(config->wTotalLength) >= TBUF_SIZE) /* max partial read */ 522 if (le16_to_cpu(config->wTotalLength) >= TBUF_SIZE) /* max partial read */
540 return 1; 523 return 1;
541 dbg ("bogus config descriptor read size"); 524 ERROR(tdev, "bogus config descriptor read size\n");
542 return 0; 525 return 0;
543} 526}
544 527
@@ -571,7 +554,7 @@ static int ch9_postconfig (struct usbtest_dev *dev)
571 /* 9.2.3 constrains the range here */ 554 /* 9.2.3 constrains the range here */
572 alt = iface->altsetting [i].desc.bAlternateSetting; 555 alt = iface->altsetting [i].desc.bAlternateSetting;
573 if (alt < 0 || alt >= iface->num_altsetting) { 556 if (alt < 0 || alt >= iface->num_altsetting) {
574 dev_dbg (&iface->dev, 557 dev_err(&iface->dev,
575 "invalid alt [%d].bAltSetting = %d\n", 558 "invalid alt [%d].bAltSetting = %d\n",
576 i, alt); 559 i, alt);
577 } 560 }
@@ -583,7 +566,7 @@ static int ch9_postconfig (struct usbtest_dev *dev)
583 /* [9.4.10] set_interface */ 566 /* [9.4.10] set_interface */
584 retval = set_altsetting (dev, alt); 567 retval = set_altsetting (dev, alt);
585 if (retval) { 568 if (retval) {
586 dev_dbg (&iface->dev, "can't set_interface = %d, %d\n", 569 dev_err(&iface->dev, "can't set_interface = %d, %d\n",
587 alt, retval); 570 alt, retval);
588 return retval; 571 return retval;
589 } 572 }
@@ -591,7 +574,7 @@ static int ch9_postconfig (struct usbtest_dev *dev)
591 /* [9.4.4] get_interface always works */ 574 /* [9.4.4] get_interface always works */
592 retval = get_altsetting (dev); 575 retval = get_altsetting (dev);
593 if (retval != alt) { 576 if (retval != alt) {
594 dev_dbg (&iface->dev, "get alt should be %d, was %d\n", 577 dev_err(&iface->dev, "get alt should be %d, was %d\n",
595 alt, retval); 578 alt, retval);
596 return (retval < 0) ? retval : -EDOM; 579 return (retval < 0) ? retval : -EDOM;
597 } 580 }
@@ -611,7 +594,7 @@ static int ch9_postconfig (struct usbtest_dev *dev)
611 USB_DIR_IN | USB_RECIP_DEVICE, 594 USB_DIR_IN | USB_RECIP_DEVICE,
612 0, 0, dev->buf, 1, USB_CTRL_GET_TIMEOUT); 595 0, 0, dev->buf, 1, USB_CTRL_GET_TIMEOUT);
613 if (retval != 1 || dev->buf [0] != expected) { 596 if (retval != 1 || dev->buf [0] != expected) {
614 dev_dbg (&iface->dev, "get config --> %d %d (1 %d)\n", 597 dev_err(&iface->dev, "get config --> %d %d (1 %d)\n",
615 retval, dev->buf[0], expected); 598 retval, dev->buf[0], expected);
616 return (retval < 0) ? retval : -EDOM; 599 return (retval < 0) ? retval : -EDOM;
617 } 600 }
@@ -621,7 +604,7 @@ static int ch9_postconfig (struct usbtest_dev *dev)
621 retval = usb_get_descriptor (udev, USB_DT_DEVICE, 0, 604 retval = usb_get_descriptor (udev, USB_DT_DEVICE, 0,
622 dev->buf, sizeof udev->descriptor); 605 dev->buf, sizeof udev->descriptor);
623 if (retval != sizeof udev->descriptor) { 606 if (retval != sizeof udev->descriptor) {
624 dev_dbg (&iface->dev, "dev descriptor --> %d\n", retval); 607 dev_err(&iface->dev, "dev descriptor --> %d\n", retval);
625 return (retval < 0) ? retval : -EDOM; 608 return (retval < 0) ? retval : -EDOM;
626 } 609 }
627 610
@@ -629,8 +612,8 @@ static int ch9_postconfig (struct usbtest_dev *dev)
629 for (i = 0; i < udev->descriptor.bNumConfigurations; i++) { 612 for (i = 0; i < udev->descriptor.bNumConfigurations; i++) {
630 retval = usb_get_descriptor (udev, USB_DT_CONFIG, i, 613 retval = usb_get_descriptor (udev, USB_DT_CONFIG, i,
631 dev->buf, TBUF_SIZE); 614 dev->buf, TBUF_SIZE);
632 if (!is_good_config (dev->buf, retval)) { 615 if (!is_good_config(dev, retval)) {
633 dev_dbg (&iface->dev, 616 dev_err(&iface->dev,
634 "config [%d] descriptor --> %d\n", 617 "config [%d] descriptor --> %d\n",
635 i, retval); 618 i, retval);
636 return (retval < 0) ? retval : -EDOM; 619 return (retval < 0) ? retval : -EDOM;
@@ -650,14 +633,14 @@ static int ch9_postconfig (struct usbtest_dev *dev)
650 sizeof (struct usb_qualifier_descriptor)); 633 sizeof (struct usb_qualifier_descriptor));
651 if (retval == -EPIPE) { 634 if (retval == -EPIPE) {
652 if (udev->speed == USB_SPEED_HIGH) { 635 if (udev->speed == USB_SPEED_HIGH) {
653 dev_dbg (&iface->dev, 636 dev_err(&iface->dev,
654 "hs dev qualifier --> %d\n", 637 "hs dev qualifier --> %d\n",
655 retval); 638 retval);
656 return (retval < 0) ? retval : -EDOM; 639 return (retval < 0) ? retval : -EDOM;
657 } 640 }
658 /* usb2.0 but not high-speed capable; fine */ 641 /* usb2.0 but not high-speed capable; fine */
659 } else if (retval != sizeof (struct usb_qualifier_descriptor)) { 642 } else if (retval != sizeof (struct usb_qualifier_descriptor)) {
660 dev_dbg (&iface->dev, "dev qualifier --> %d\n", retval); 643 dev_err(&iface->dev, "dev qualifier --> %d\n", retval);
661 return (retval < 0) ? retval : -EDOM; 644 return (retval < 0) ? retval : -EDOM;
662 } else 645 } else
663 d = (struct usb_qualifier_descriptor *) dev->buf; 646 d = (struct usb_qualifier_descriptor *) dev->buf;
@@ -669,8 +652,8 @@ static int ch9_postconfig (struct usbtest_dev *dev)
669 retval = usb_get_descriptor (udev, 652 retval = usb_get_descriptor (udev,
670 USB_DT_OTHER_SPEED_CONFIG, i, 653 USB_DT_OTHER_SPEED_CONFIG, i,
671 dev->buf, TBUF_SIZE); 654 dev->buf, TBUF_SIZE);
672 if (!is_good_config (dev->buf, retval)) { 655 if (!is_good_config(dev, retval)) {
673 dev_dbg (&iface->dev, 656 dev_err(&iface->dev,
674 "other speed config --> %d\n", 657 "other speed config --> %d\n",
675 retval); 658 retval);
676 return (retval < 0) ? retval : -EDOM; 659 return (retval < 0) ? retval : -EDOM;
@@ -683,7 +666,7 @@ static int ch9_postconfig (struct usbtest_dev *dev)
683 /* [9.4.5] get_status always works */ 666 /* [9.4.5] get_status always works */
684 retval = usb_get_status (udev, USB_RECIP_DEVICE, 0, dev->buf); 667 retval = usb_get_status (udev, USB_RECIP_DEVICE, 0, dev->buf);
685 if (retval != 2) { 668 if (retval != 2) {
686 dev_dbg (&iface->dev, "get dev status --> %d\n", retval); 669 dev_err(&iface->dev, "get dev status --> %d\n", retval);
687 return (retval < 0) ? retval : -EDOM; 670 return (retval < 0) ? retval : -EDOM;
688 } 671 }
689 672
@@ -693,11 +676,11 @@ static int ch9_postconfig (struct usbtest_dev *dev)
693 retval = usb_get_status (udev, USB_RECIP_INTERFACE, 676 retval = usb_get_status (udev, USB_RECIP_INTERFACE,
694 iface->altsetting [0].desc.bInterfaceNumber, dev->buf); 677 iface->altsetting [0].desc.bInterfaceNumber, dev->buf);
695 if (retval != 2) { 678 if (retval != 2) {
696 dev_dbg (&iface->dev, "get interface status --> %d\n", retval); 679 dev_err(&iface->dev, "get interface status --> %d\n", retval);
697 return (retval < 0) ? retval : -EDOM; 680 return (retval < 0) ? retval : -EDOM;
698 } 681 }
699 // FIXME get status for each endpoint in the interface 682 // FIXME get status for each endpoint in the interface
700 683
701 return 0; 684 return 0;
702} 685}
703 686
@@ -752,8 +735,9 @@ static void ctrl_complete (struct urb *urb)
752 */ 735 */
753 if (subcase->number > 0) { 736 if (subcase->number > 0) {
754 if ((subcase->number - ctx->last) != 1) { 737 if ((subcase->number - ctx->last) != 1) {
755 dbg ("subcase %d completed out of order, last %d", 738 ERROR(ctx->dev,
756 subcase->number, ctx->last); 739 "subcase %d completed out of order, last %d\n",
740 subcase->number, ctx->last);
757 status = -EDOM; 741 status = -EDOM;
758 ctx->last = subcase->number; 742 ctx->last = subcase->number;
759 goto error; 743 goto error;
@@ -777,7 +761,7 @@ static void ctrl_complete (struct urb *urb)
777 else if (subcase->number == 12 && status == -EPIPE) 761 else if (subcase->number == 12 && status == -EPIPE)
778 status = 0; 762 status = 0;
779 else 763 else
780 dbg ("subtest %d error, status %d", 764 ERROR(ctx->dev, "subtest %d error, status %d\n",
781 subcase->number, status); 765 subcase->number, status);
782 } 766 }
783 767
@@ -788,9 +772,12 @@ error:
788 int i; 772 int i;
789 773
790 ctx->status = status; 774 ctx->status = status;
791 info ("control queue %02x.%02x, err %d, %d left", 775 ERROR(ctx->dev, "control queue %02x.%02x, err %d, "
776 "%d left, subcase %d, len %d/%d\n",
792 reqp->bRequestType, reqp->bRequest, 777 reqp->bRequestType, reqp->bRequest,
793 status, ctx->count); 778 status, ctx->count, subcase->number,
779 urb->actual_length,
780 urb->transfer_buffer_length);
794 781
795 /* FIXME this "unlink everything" exit route should 782 /* FIXME this "unlink everything" exit route should
796 * be a separate test case. 783 * be a separate test case.
@@ -799,7 +786,8 @@ error:
799 /* unlink whatever's still pending */ 786 /* unlink whatever's still pending */
800 for (i = 1; i < ctx->param->sglen; i++) { 787 for (i = 1; i < ctx->param->sglen; i++) {
801 struct urb *u = ctx->urb [ 788 struct urb *u = ctx->urb [
802 (i + subcase->number) % ctx->param->sglen]; 789 (i + subcase->number)
790 % ctx->param->sglen];
803 791
804 if (u == urb || !u->dev) 792 if (u == urb || !u->dev)
805 continue; 793 continue;
@@ -812,7 +800,8 @@ error:
812 case -EIDRM: 800 case -EIDRM:
813 continue; 801 continue;
814 default: 802 default:
815 dbg ("urb unlink --> %d", status); 803 ERROR(ctx->dev, "urb unlink --> %d\n",
804 status);
816 } 805 }
817 } 806 }
818 status = ctx->status; 807 status = ctx->status;
@@ -822,14 +811,15 @@ error:
822 /* resubmit if we need to, else mark this as done */ 811 /* resubmit if we need to, else mark this as done */
823 if ((status == 0) && (ctx->pending < ctx->count)) { 812 if ((status == 0) && (ctx->pending < ctx->count)) {
824 if ((status = usb_submit_urb (urb, GFP_ATOMIC)) != 0) { 813 if ((status = usb_submit_urb (urb, GFP_ATOMIC)) != 0) {
825 dbg ("can't resubmit ctrl %02x.%02x, err %d", 814 ERROR(ctx->dev,
815 "can't resubmit ctrl %02x.%02x, err %d\n",
826 reqp->bRequestType, reqp->bRequest, status); 816 reqp->bRequestType, reqp->bRequest, status);
827 urb->dev = NULL; 817 urb->dev = NULL;
828 } else 818 } else
829 ctx->pending++; 819 ctx->pending++;
830 } else 820 } else
831 urb->dev = NULL; 821 urb->dev = NULL;
832 822
833 /* signal completion when nothing's queued */ 823 /* signal completion when nothing's queued */
834 if (ctx->pending == 0) 824 if (ctx->pending == 0)
835 complete (&ctx->complete); 825 complete (&ctx->complete);
@@ -918,11 +908,11 @@ test_ctrl_queue (struct usbtest_dev *dev, struct usbtest_param *param)
918 req.wValue = cpu_to_le16 (USB_DT_INTERFACE << 8); 908 req.wValue = cpu_to_le16 (USB_DT_INTERFACE << 8);
919 // interface == 0 909 // interface == 0
920 len = sizeof (struct usb_interface_descriptor); 910 len = sizeof (struct usb_interface_descriptor);
921 expected = EPIPE; 911 expected = -EPIPE;
922 break; 912 break;
923 // NOTE: two consecutive stalls in the queue here. 913 // NOTE: two consecutive stalls in the queue here.
924 // that tests fault recovery a bit more aggressively. 914 // that tests fault recovery a bit more aggressively.
925 case 8: // clear endpoint halt (USUALLY STALLS) 915 case 8: // clear endpoint halt (MAY STALL)
926 req.bRequest = USB_REQ_CLEAR_FEATURE; 916 req.bRequest = USB_REQ_CLEAR_FEATURE;
927 req.bRequestType = USB_RECIP_ENDPOINT; 917 req.bRequestType = USB_RECIP_ENDPOINT;
928 // wValue 0 == ep halt 918 // wValue 0 == ep halt
@@ -965,7 +955,7 @@ test_ctrl_queue (struct usbtest_dev *dev, struct usbtest_param *param)
965 break; 955 break;
966 case 14: // short read; try to fill the last packet 956 case 14: // short read; try to fill the last packet
967 req.wValue = cpu_to_le16 ((USB_DT_DEVICE << 8) | 0); 957 req.wValue = cpu_to_le16 ((USB_DT_DEVICE << 8) | 0);
968 // device descriptor size == 18 bytes 958 /* device descriptor size == 18 bytes */
969 len = udev->descriptor.bMaxPacketSize0; 959 len = udev->descriptor.bMaxPacketSize0;
970 switch (len) { 960 switch (len) {
971 case 8: len = 24; break; 961 case 8: len = 24; break;
@@ -974,7 +964,7 @@ test_ctrl_queue (struct usbtest_dev *dev, struct usbtest_param *param)
974 expected = -EREMOTEIO; 964 expected = -EREMOTEIO;
975 break; 965 break;
976 default: 966 default:
977 err ("bogus number of ctrl queue testcases!"); 967 ERROR(dev, "bogus number of ctrl queue testcases!\n");
978 context.status = -EINVAL; 968 context.status = -EINVAL;
979 goto cleanup; 969 goto cleanup;
980 } 970 }
@@ -1003,7 +993,7 @@ test_ctrl_queue (struct usbtest_dev *dev, struct usbtest_param *param)
1003 for (i = 0; i < param->sglen; i++) { 993 for (i = 0; i < param->sglen; i++) {
1004 context.status = usb_submit_urb (urb [i], GFP_ATOMIC); 994 context.status = usb_submit_urb (urb [i], GFP_ATOMIC);
1005 if (context.status != 0) { 995 if (context.status != 0) {
1006 dbg ("can't submit urb[%d], status %d", 996 ERROR(dev, "can't submit urb[%d], status %d\n",
1007 i, context.status); 997 i, context.status);
1008 context.count = context.pending; 998 context.count = context.pending;
1009 break; 999 break;
@@ -1070,7 +1060,7 @@ static int unlink1 (struct usbtest_dev *dev, int pipe, int size, int async)
1070 * due to errors, or is just NAKing requests. 1060 * due to errors, or is just NAKing requests.
1071 */ 1061 */
1072 if ((retval = usb_submit_urb (urb, GFP_KERNEL)) != 0) { 1062 if ((retval = usb_submit_urb (urb, GFP_KERNEL)) != 0) {
1073 dev_dbg (&dev->intf->dev, "submit fail %d\n", retval); 1063 dev_err(&dev->intf->dev, "submit fail %d\n", retval);
1074 return retval; 1064 return retval;
1075 } 1065 }
1076 1066
@@ -1087,13 +1077,13 @@ retry:
1087 * "normal" drivers would prevent resubmission, but 1077 * "normal" drivers would prevent resubmission, but
1088 * since we're testing unlink paths, we can't. 1078 * since we're testing unlink paths, we can't.
1089 */ 1079 */
1090 dev_dbg (&dev->intf->dev, "unlink retry\n"); 1080 ERROR(dev, "unlink retry\n");
1091 goto retry; 1081 goto retry;
1092 } 1082 }
1093 } else 1083 } else
1094 usb_kill_urb (urb); 1084 usb_kill_urb (urb);
1095 if (!(retval == 0 || retval == -EINPROGRESS)) { 1085 if (!(retval == 0 || retval == -EINPROGRESS)) {
1096 dev_dbg (&dev->intf->dev, "unlink fail %d\n", retval); 1086 dev_err(&dev->intf->dev, "unlink fail %d\n", retval);
1097 return retval; 1087 return retval;
1098 } 1088 }
1099 1089
@@ -1121,7 +1111,7 @@ static int unlink_simple (struct usbtest_dev *dev, int pipe, int len)
1121 1111
1122/*-------------------------------------------------------------------------*/ 1112/*-------------------------------------------------------------------------*/
1123 1113
1124static int verify_not_halted (int ep, struct urb *urb) 1114static int verify_not_halted(struct usbtest_dev *tdev, int ep, struct urb *urb)
1125{ 1115{
1126 int retval; 1116 int retval;
1127 u16 status; 1117 u16 status;
@@ -1129,20 +1119,21 @@ static int verify_not_halted (int ep, struct urb *urb)
1129 /* shouldn't look or act halted */ 1119 /* shouldn't look or act halted */
1130 retval = usb_get_status (urb->dev, USB_RECIP_ENDPOINT, ep, &status); 1120 retval = usb_get_status (urb->dev, USB_RECIP_ENDPOINT, ep, &status);
1131 if (retval < 0) { 1121 if (retval < 0) {
1132 dbg ("ep %02x couldn't get no-halt status, %d", ep, retval); 1122 ERROR(tdev, "ep %02x couldn't get no-halt status, %d\n",
1123 ep, retval);
1133 return retval; 1124 return retval;
1134 } 1125 }
1135 if (status != 0) { 1126 if (status != 0) {
1136 dbg ("ep %02x bogus status: %04x != 0", ep, status); 1127 ERROR(tdev, "ep %02x bogus status: %04x != 0\n", ep, status);
1137 return -EINVAL; 1128 return -EINVAL;
1138 } 1129 }
1139 retval = simple_io (urb, 1, 0, 0, __func__); 1130 retval = simple_io(tdev, urb, 1, 0, 0, __func__);
1140 if (retval != 0) 1131 if (retval != 0)
1141 return -EINVAL; 1132 return -EINVAL;
1142 return 0; 1133 return 0;
1143} 1134}
1144 1135
1145static int verify_halted (int ep, struct urb *urb) 1136static int verify_halted(struct usbtest_dev *tdev, int ep, struct urb *urb)
1146{ 1137{
1147 int retval; 1138 int retval;
1148 u16 status; 1139 u16 status;
@@ -1150,29 +1141,30 @@ static int verify_halted (int ep, struct urb *urb)
1150 /* should look and act halted */ 1141 /* should look and act halted */
1151 retval = usb_get_status (urb->dev, USB_RECIP_ENDPOINT, ep, &status); 1142 retval = usb_get_status (urb->dev, USB_RECIP_ENDPOINT, ep, &status);
1152 if (retval < 0) { 1143 if (retval < 0) {
1153 dbg ("ep %02x couldn't get halt status, %d", ep, retval); 1144 ERROR(tdev, "ep %02x couldn't get halt status, %d\n",
1145 ep, retval);
1154 return retval; 1146 return retval;
1155 } 1147 }
1156 le16_to_cpus(&status); 1148 le16_to_cpus(&status);
1157 if (status != 1) { 1149 if (status != 1) {
1158 dbg ("ep %02x bogus status: %04x != 1", ep, status); 1150 ERROR(tdev, "ep %02x bogus status: %04x != 1\n", ep, status);
1159 return -EINVAL; 1151 return -EINVAL;
1160 } 1152 }
1161 retval = simple_io (urb, 1, 0, -EPIPE, __func__); 1153 retval = simple_io(tdev, urb, 1, 0, -EPIPE, __func__);
1162 if (retval != -EPIPE) 1154 if (retval != -EPIPE)
1163 return -EINVAL; 1155 return -EINVAL;
1164 retval = simple_io (urb, 1, 0, -EPIPE, "verify_still_halted"); 1156 retval = simple_io(tdev, urb, 1, 0, -EPIPE, "verify_still_halted");
1165 if (retval != -EPIPE) 1157 if (retval != -EPIPE)
1166 return -EINVAL; 1158 return -EINVAL;
1167 return 0; 1159 return 0;
1168} 1160}
1169 1161
1170static int test_halt (int ep, struct urb *urb) 1162static int test_halt(struct usbtest_dev *tdev, int ep, struct urb *urb)
1171{ 1163{
1172 int retval; 1164 int retval;
1173 1165
1174 /* shouldn't look or act halted now */ 1166 /* shouldn't look or act halted now */
1175 retval = verify_not_halted (ep, urb); 1167 retval = verify_not_halted(tdev, ep, urb);
1176 if (retval < 0) 1168 if (retval < 0)
1177 return retval; 1169 return retval;
1178 1170
@@ -1182,20 +1174,20 @@ static int test_halt (int ep, struct urb *urb)
1182 USB_ENDPOINT_HALT, ep, 1174 USB_ENDPOINT_HALT, ep,
1183 NULL, 0, USB_CTRL_SET_TIMEOUT); 1175 NULL, 0, USB_CTRL_SET_TIMEOUT);
1184 if (retval < 0) { 1176 if (retval < 0) {
1185 dbg ("ep %02x couldn't set halt, %d", ep, retval); 1177 ERROR(tdev, "ep %02x couldn't set halt, %d\n", ep, retval);
1186 return retval; 1178 return retval;
1187 } 1179 }
1188 retval = verify_halted (ep, urb); 1180 retval = verify_halted(tdev, ep, urb);
1189 if (retval < 0) 1181 if (retval < 0)
1190 return retval; 1182 return retval;
1191 1183
1192 /* clear halt (tests API + protocol), verify it worked */ 1184 /* clear halt (tests API + protocol), verify it worked */
1193 retval = usb_clear_halt (urb->dev, urb->pipe); 1185 retval = usb_clear_halt (urb->dev, urb->pipe);
1194 if (retval < 0) { 1186 if (retval < 0) {
1195 dbg ("ep %02x couldn't clear halt, %d", ep, retval); 1187 ERROR(tdev, "ep %02x couldn't clear halt, %d\n", ep, retval);
1196 return retval; 1188 return retval;
1197 } 1189 }
1198 retval = verify_not_halted (ep, urb); 1190 retval = verify_not_halted(tdev, ep, urb);
1199 if (retval < 0) 1191 if (retval < 0)
1200 return retval; 1192 return retval;
1201 1193
@@ -1217,7 +1209,7 @@ static int halt_simple (struct usbtest_dev *dev)
1217 if (dev->in_pipe) { 1209 if (dev->in_pipe) {
1218 ep = usb_pipeendpoint (dev->in_pipe) | USB_DIR_IN; 1210 ep = usb_pipeendpoint (dev->in_pipe) | USB_DIR_IN;
1219 urb->pipe = dev->in_pipe; 1211 urb->pipe = dev->in_pipe;
1220 retval = test_halt (ep, urb); 1212 retval = test_halt(dev, ep, urb);
1221 if (retval < 0) 1213 if (retval < 0)
1222 goto done; 1214 goto done;
1223 } 1215 }
@@ -1225,7 +1217,7 @@ static int halt_simple (struct usbtest_dev *dev)
1225 if (dev->out_pipe) { 1217 if (dev->out_pipe) {
1226 ep = usb_pipeendpoint (dev->out_pipe); 1218 ep = usb_pipeendpoint (dev->out_pipe);
1227 urb->pipe = dev->out_pipe; 1219 urb->pipe = dev->out_pipe;
1228 retval = test_halt (ep, urb); 1220 retval = test_halt(dev, ep, urb);
1229 } 1221 }
1230done: 1222done:
1231 simple_free_urb (urb); 1223 simple_free_urb (urb);
@@ -1275,7 +1267,7 @@ static int ctrl_out (struct usbtest_dev *dev,
1275 if (retval != len) { 1267 if (retval != len) {
1276 what = "write"; 1268 what = "write";
1277 if (retval >= 0) { 1269 if (retval >= 0) {
1278 INFO(dev, "ctrl_out, wlen %d (expected %d)\n", 1270 ERROR(dev, "ctrl_out, wlen %d (expected %d)\n",
1279 retval, len); 1271 retval, len);
1280 retval = -EBADMSG; 1272 retval = -EBADMSG;
1281 } 1273 }
@@ -1289,7 +1281,7 @@ static int ctrl_out (struct usbtest_dev *dev,
1289 if (retval != len) { 1281 if (retval != len) {
1290 what = "read"; 1282 what = "read";
1291 if (retval >= 0) { 1283 if (retval >= 0) {
1292 INFO(dev, "ctrl_out, rlen %d (expected %d)\n", 1284 ERROR(dev, "ctrl_out, rlen %d (expected %d)\n",
1293 retval, len); 1285 retval, len);
1294 retval = -EBADMSG; 1286 retval = -EBADMSG;
1295 } 1287 }
@@ -1299,7 +1291,7 @@ static int ctrl_out (struct usbtest_dev *dev,
1299 /* fail if we can't verify */ 1291 /* fail if we can't verify */
1300 for (j = 0; j < len; j++) { 1292 for (j = 0; j < len; j++) {
1301 if (buf [j] != (u8) (i + j)) { 1293 if (buf [j] != (u8) (i + j)) {
1302 INFO (dev, "ctrl_out, byte %d is %d not %d\n", 1294 ERROR(dev, "ctrl_out, byte %d is %d not %d\n",
1303 j, buf [j], (u8) i + j); 1295 j, buf [j], (u8) i + j);
1304 retval = -EBADMSG; 1296 retval = -EBADMSG;
1305 break; 1297 break;
@@ -1321,7 +1313,7 @@ static int ctrl_out (struct usbtest_dev *dev,
1321 } 1313 }
1322 1314
1323 if (retval < 0) 1315 if (retval < 0)
1324 INFO (dev, "ctrl_out %s failed, code %d, count %d\n", 1316 ERROR (dev, "ctrl_out %s failed, code %d, count %d\n",
1325 what, retval, i); 1317 what, retval, i);
1326 1318
1327 kfree (buf); 1319 kfree (buf);
@@ -1366,7 +1358,7 @@ static void iso_callback (struct urb *urb)
1366 case 0: 1358 case 0:
1367 goto done; 1359 goto done;
1368 default: 1360 default:
1369 dev_dbg (&ctx->dev->intf->dev, 1361 dev_err(&ctx->dev->intf->dev,
1370 "iso resubmit err %d\n", 1362 "iso resubmit err %d\n",
1371 status); 1363 status);
1372 /* FALLTHROUGH */ 1364 /* FALLTHROUGH */
@@ -1381,7 +1373,7 @@ static void iso_callback (struct urb *urb)
1381 ctx->pending--; 1373 ctx->pending--;
1382 if (ctx->pending == 0) { 1374 if (ctx->pending == 0) {
1383 if (ctx->errors) 1375 if (ctx->errors)
1384 dev_dbg (&ctx->dev->intf->dev, 1376 dev_err(&ctx->dev->intf->dev,
1385 "iso test, %lu errors out of %lu\n", 1377 "iso test, %lu errors out of %lu\n",
1386 ctx->errors, ctx->packet_count); 1378 ctx->errors, ctx->packet_count);
1387 complete (&ctx->done); 1379 complete (&ctx->done);
@@ -1458,7 +1450,7 @@ test_iso_queue (struct usbtest_dev *dev, struct usbtest_param *param,
1458 1450
1459 memset (urbs, 0, sizeof urbs); 1451 memset (urbs, 0, sizeof urbs);
1460 udev = testdev_to_usbdev (dev); 1452 udev = testdev_to_usbdev (dev);
1461 dev_dbg (&dev->intf->dev, 1453 dev_info(&dev->intf->dev,
1462 "... iso period %d %sframes, wMaxPacket %04x\n", 1454 "... iso period %d %sframes, wMaxPacket %04x\n",
1463 1 << (desc->bInterval - 1), 1455 1 << (desc->bInterval - 1),
1464 (udev->speed == USB_SPEED_HIGH) ? "micro" : "", 1456 (udev->speed == USB_SPEED_HIGH) ? "micro" : "",
@@ -1475,7 +1467,7 @@ test_iso_queue (struct usbtest_dev *dev, struct usbtest_param *param,
1475 urbs [i]->context = &context; 1467 urbs [i]->context = &context;
1476 } 1468 }
1477 packets *= param->iterations; 1469 packets *= param->iterations;
1478 dev_dbg (&dev->intf->dev, 1470 dev_info(&dev->intf->dev,
1479 "... total %lu msec (%lu packets)\n", 1471 "... total %lu msec (%lu packets)\n",
1480 (packets * (1 << (desc->bInterval - 1))) 1472 (packets * (1 << (desc->bInterval - 1)))
1481 / ((udev->speed == USB_SPEED_HIGH) ? 8 : 1), 1473 / ((udev->speed == USB_SPEED_HIGH) ? 8 : 1),
@@ -1537,6 +1529,13 @@ fail:
1537 * except indirectly by consuming USB bandwidth and CPU resources for test 1529 * except indirectly by consuming USB bandwidth and CPU resources for test
1538 * threads and request completion. But the only way to know that for sure 1530 * threads and request completion. But the only way to know that for sure
1539 * is to test when HC queues are in use by many devices. 1531 * is to test when HC queues are in use by many devices.
1532 *
1533 * WARNING: Because usbfs grabs udev->dev.sem before calling this ioctl(),
1534 * it locks out usbcore in certain code paths. Notably, if you disconnect
1535 * the device-under-test, khubd will wait block forever waiting for the
1536 * ioctl to complete ... so that usb_disconnect() can abort the pending
1537 * urbs and then call usbtest_disconnect(). To abort a test, you're best
1538 * off just killing the userspace task and waiting for it to exit.
1540 */ 1539 */
1541 1540
1542static int 1541static int
@@ -1575,7 +1574,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1575 * altsettings; force a default so most tests don't need to check. 1574 * altsettings; force a default so most tests don't need to check.
1576 */ 1575 */
1577 if (dev->info->alt >= 0) { 1576 if (dev->info->alt >= 0) {
1578 int res; 1577 int res;
1579 1578
1580 if (intf->altsetting->desc.bInterfaceNumber) { 1579 if (intf->altsetting->desc.bInterfaceNumber) {
1581 mutex_unlock(&dev->lock); 1580 mutex_unlock(&dev->lock);
@@ -1604,7 +1603,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1604 switch (param->test_num) { 1603 switch (param->test_num) {
1605 1604
1606 case 0: 1605 case 0:
1607 dev_dbg (&intf->dev, "TEST 0: NOP\n"); 1606 dev_info(&intf->dev, "TEST 0: NOP\n");
1608 retval = 0; 1607 retval = 0;
1609 break; 1608 break;
1610 1609
@@ -1612,7 +1611,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1612 case 1: 1611 case 1:
1613 if (dev->out_pipe == 0) 1612 if (dev->out_pipe == 0)
1614 break; 1613 break;
1615 dev_dbg (&intf->dev, 1614 dev_info(&intf->dev,
1616 "TEST 1: write %d bytes %u times\n", 1615 "TEST 1: write %d bytes %u times\n",
1617 param->length, param->iterations); 1616 param->length, param->iterations);
1618 urb = simple_alloc_urb (udev, dev->out_pipe, param->length); 1617 urb = simple_alloc_urb (udev, dev->out_pipe, param->length);
@@ -1621,13 +1620,13 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1621 break; 1620 break;
1622 } 1621 }
1623 // FIRMWARE: bulk sink (maybe accepts short writes) 1622 // FIRMWARE: bulk sink (maybe accepts short writes)
1624 retval = simple_io (urb, param->iterations, 0, 0, "test1"); 1623 retval = simple_io(dev, urb, param->iterations, 0, 0, "test1");
1625 simple_free_urb (urb); 1624 simple_free_urb (urb);
1626 break; 1625 break;
1627 case 2: 1626 case 2:
1628 if (dev->in_pipe == 0) 1627 if (dev->in_pipe == 0)
1629 break; 1628 break;
1630 dev_dbg (&intf->dev, 1629 dev_info(&intf->dev,
1631 "TEST 2: read %d bytes %u times\n", 1630 "TEST 2: read %d bytes %u times\n",
1632 param->length, param->iterations); 1631 param->length, param->iterations);
1633 urb = simple_alloc_urb (udev, dev->in_pipe, param->length); 1632 urb = simple_alloc_urb (udev, dev->in_pipe, param->length);
@@ -1636,13 +1635,13 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1636 break; 1635 break;
1637 } 1636 }
1638 // FIRMWARE: bulk source (maybe generates short writes) 1637 // FIRMWARE: bulk source (maybe generates short writes)
1639 retval = simple_io (urb, param->iterations, 0, 0, "test2"); 1638 retval = simple_io(dev, urb, param->iterations, 0, 0, "test2");
1640 simple_free_urb (urb); 1639 simple_free_urb (urb);
1641 break; 1640 break;
1642 case 3: 1641 case 3:
1643 if (dev->out_pipe == 0 || param->vary == 0) 1642 if (dev->out_pipe == 0 || param->vary == 0)
1644 break; 1643 break;
1645 dev_dbg (&intf->dev, 1644 dev_info(&intf->dev,
1646 "TEST 3: write/%d 0..%d bytes %u times\n", 1645 "TEST 3: write/%d 0..%d bytes %u times\n",
1647 param->vary, param->length, param->iterations); 1646 param->vary, param->length, param->iterations);
1648 urb = simple_alloc_urb (udev, dev->out_pipe, param->length); 1647 urb = simple_alloc_urb (udev, dev->out_pipe, param->length);
@@ -1651,14 +1650,14 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1651 break; 1650 break;
1652 } 1651 }
1653 // FIRMWARE: bulk sink (maybe accepts short writes) 1652 // FIRMWARE: bulk sink (maybe accepts short writes)
1654 retval = simple_io (urb, param->iterations, param->vary, 1653 retval = simple_io(dev, urb, param->iterations, param->vary,
1655 0, "test3"); 1654 0, "test3");
1656 simple_free_urb (urb); 1655 simple_free_urb (urb);
1657 break; 1656 break;
1658 case 4: 1657 case 4:
1659 if (dev->in_pipe == 0 || param->vary == 0) 1658 if (dev->in_pipe == 0 || param->vary == 0)
1660 break; 1659 break;
1661 dev_dbg (&intf->dev, 1660 dev_info(&intf->dev,
1662 "TEST 4: read/%d 0..%d bytes %u times\n", 1661 "TEST 4: read/%d 0..%d bytes %u times\n",
1663 param->vary, param->length, param->iterations); 1662 param->vary, param->length, param->iterations);
1664 urb = simple_alloc_urb (udev, dev->in_pipe, param->length); 1663 urb = simple_alloc_urb (udev, dev->in_pipe, param->length);
@@ -1667,7 +1666,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1667 break; 1666 break;
1668 } 1667 }
1669 // FIRMWARE: bulk source (maybe generates short writes) 1668 // FIRMWARE: bulk source (maybe generates short writes)
1670 retval = simple_io (urb, param->iterations, param->vary, 1669 retval = simple_io(dev, urb, param->iterations, param->vary,
1671 0, "test4"); 1670 0, "test4");
1672 simple_free_urb (urb); 1671 simple_free_urb (urb);
1673 break; 1672 break;
@@ -1676,7 +1675,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1676 case 5: 1675 case 5:
1677 if (dev->out_pipe == 0 || param->sglen == 0) 1676 if (dev->out_pipe == 0 || param->sglen == 0)
1678 break; 1677 break;
1679 dev_dbg (&intf->dev, 1678 dev_info(&intf->dev,
1680 "TEST 5: write %d sglists %d entries of %d bytes\n", 1679 "TEST 5: write %d sglists %d entries of %d bytes\n",
1681 param->iterations, 1680 param->iterations,
1682 param->sglen, param->length); 1681 param->sglen, param->length);
@@ -1686,7 +1685,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1686 break; 1685 break;
1687 } 1686 }
1688 // FIRMWARE: bulk sink (maybe accepts short writes) 1687 // FIRMWARE: bulk sink (maybe accepts short writes)
1689 retval = perform_sglist (udev, param->iterations, dev->out_pipe, 1688 retval = perform_sglist(dev, param->iterations, dev->out_pipe,
1690 &req, sg, param->sglen); 1689 &req, sg, param->sglen);
1691 free_sglist (sg, param->sglen); 1690 free_sglist (sg, param->sglen);
1692 break; 1691 break;
@@ -1694,7 +1693,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1694 case 6: 1693 case 6:
1695 if (dev->in_pipe == 0 || param->sglen == 0) 1694 if (dev->in_pipe == 0 || param->sglen == 0)
1696 break; 1695 break;
1697 dev_dbg (&intf->dev, 1696 dev_info(&intf->dev,
1698 "TEST 6: read %d sglists %d entries of %d bytes\n", 1697 "TEST 6: read %d sglists %d entries of %d bytes\n",
1699 param->iterations, 1698 param->iterations,
1700 param->sglen, param->length); 1699 param->sglen, param->length);
@@ -1704,14 +1703,14 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1704 break; 1703 break;
1705 } 1704 }
1706 // FIRMWARE: bulk source (maybe generates short writes) 1705 // FIRMWARE: bulk source (maybe generates short writes)
1707 retval = perform_sglist (udev, param->iterations, dev->in_pipe, 1706 retval = perform_sglist(dev, param->iterations, dev->in_pipe,
1708 &req, sg, param->sglen); 1707 &req, sg, param->sglen);
1709 free_sglist (sg, param->sglen); 1708 free_sglist (sg, param->sglen);
1710 break; 1709 break;
1711 case 7: 1710 case 7:
1712 if (dev->out_pipe == 0 || param->sglen == 0 || param->vary == 0) 1711 if (dev->out_pipe == 0 || param->sglen == 0 || param->vary == 0)
1713 break; 1712 break;
1714 dev_dbg (&intf->dev, 1713 dev_info(&intf->dev,
1715 "TEST 7: write/%d %d sglists %d entries 0..%d bytes\n", 1714 "TEST 7: write/%d %d sglists %d entries 0..%d bytes\n",
1716 param->vary, param->iterations, 1715 param->vary, param->iterations,
1717 param->sglen, param->length); 1716 param->sglen, param->length);
@@ -1721,14 +1720,14 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1721 break; 1720 break;
1722 } 1721 }
1723 // FIRMWARE: bulk sink (maybe accepts short writes) 1722 // FIRMWARE: bulk sink (maybe accepts short writes)
1724 retval = perform_sglist (udev, param->iterations, dev->out_pipe, 1723 retval = perform_sglist(dev, param->iterations, dev->out_pipe,
1725 &req, sg, param->sglen); 1724 &req, sg, param->sglen);
1726 free_sglist (sg, param->sglen); 1725 free_sglist (sg, param->sglen);
1727 break; 1726 break;
1728 case 8: 1727 case 8:
1729 if (dev->in_pipe == 0 || param->sglen == 0 || param->vary == 0) 1728 if (dev->in_pipe == 0 || param->sglen == 0 || param->vary == 0)
1730 break; 1729 break;
1731 dev_dbg (&intf->dev, 1730 dev_info(&intf->dev,
1732 "TEST 8: read/%d %d sglists %d entries 0..%d bytes\n", 1731 "TEST 8: read/%d %d sglists %d entries 0..%d bytes\n",
1733 param->vary, param->iterations, 1732 param->vary, param->iterations,
1734 param->sglen, param->length); 1733 param->sglen, param->length);
@@ -1738,7 +1737,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1738 break; 1737 break;
1739 } 1738 }
1740 // FIRMWARE: bulk source (maybe generates short writes) 1739 // FIRMWARE: bulk source (maybe generates short writes)
1741 retval = perform_sglist (udev, param->iterations, dev->in_pipe, 1740 retval = perform_sglist(dev, param->iterations, dev->in_pipe,
1742 &req, sg, param->sglen); 1741 &req, sg, param->sglen);
1743 free_sglist (sg, param->sglen); 1742 free_sglist (sg, param->sglen);
1744 break; 1743 break;
@@ -1746,13 +1745,14 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1746 /* non-queued sanity tests for control (chapter 9 subset) */ 1745 /* non-queued sanity tests for control (chapter 9 subset) */
1747 case 9: 1746 case 9:
1748 retval = 0; 1747 retval = 0;
1749 dev_dbg (&intf->dev, 1748 dev_info(&intf->dev,
1750 "TEST 9: ch9 (subset) control tests, %d times\n", 1749 "TEST 9: ch9 (subset) control tests, %d times\n",
1751 param->iterations); 1750 param->iterations);
1752 for (i = param->iterations; retval == 0 && i--; /* NOP */) 1751 for (i = param->iterations; retval == 0 && i--; /* NOP */)
1753 retval = ch9_postconfig (dev); 1752 retval = ch9_postconfig (dev);
1754 if (retval) 1753 if (retval)
1755 dbg ("ch9 subset failed, iterations left %d", i); 1754 dev_err(&intf->dev, "ch9 subset failed, "
1755 "iterations left %d\n", i);
1756 break; 1756 break;
1757 1757
1758 /* queued control messaging */ 1758 /* queued control messaging */
@@ -1760,7 +1760,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1760 if (param->sglen == 0) 1760 if (param->sglen == 0)
1761 break; 1761 break;
1762 retval = 0; 1762 retval = 0;
1763 dev_dbg (&intf->dev, 1763 dev_info(&intf->dev,
1764 "TEST 10: queue %d control calls, %d times\n", 1764 "TEST 10: queue %d control calls, %d times\n",
1765 param->sglen, 1765 param->sglen,
1766 param->iterations); 1766 param->iterations);
@@ -1772,26 +1772,26 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1772 if (dev->in_pipe == 0 || !param->length) 1772 if (dev->in_pipe == 0 || !param->length)
1773 break; 1773 break;
1774 retval = 0; 1774 retval = 0;
1775 dev_dbg (&intf->dev, "TEST 11: unlink %d reads of %d\n", 1775 dev_info(&intf->dev, "TEST 11: unlink %d reads of %d\n",
1776 param->iterations, param->length); 1776 param->iterations, param->length);
1777 for (i = param->iterations; retval == 0 && i--; /* NOP */) 1777 for (i = param->iterations; retval == 0 && i--; /* NOP */)
1778 retval = unlink_simple (dev, dev->in_pipe, 1778 retval = unlink_simple (dev, dev->in_pipe,
1779 param->length); 1779 param->length);
1780 if (retval) 1780 if (retval)
1781 dev_dbg (&intf->dev, "unlink reads failed %d, " 1781 dev_err(&intf->dev, "unlink reads failed %d, "
1782 "iterations left %d\n", retval, i); 1782 "iterations left %d\n", retval, i);
1783 break; 1783 break;
1784 case 12: 1784 case 12:
1785 if (dev->out_pipe == 0 || !param->length) 1785 if (dev->out_pipe == 0 || !param->length)
1786 break; 1786 break;
1787 retval = 0; 1787 retval = 0;
1788 dev_dbg (&intf->dev, "TEST 12: unlink %d writes of %d\n", 1788 dev_info(&intf->dev, "TEST 12: unlink %d writes of %d\n",
1789 param->iterations, param->length); 1789 param->iterations, param->length);
1790 for (i = param->iterations; retval == 0 && i--; /* NOP */) 1790 for (i = param->iterations; retval == 0 && i--; /* NOP */)
1791 retval = unlink_simple (dev, dev->out_pipe, 1791 retval = unlink_simple (dev, dev->out_pipe,
1792 param->length); 1792 param->length);
1793 if (retval) 1793 if (retval)
1794 dev_dbg (&intf->dev, "unlink writes failed %d, " 1794 dev_err(&intf->dev, "unlink writes failed %d, "
1795 "iterations left %d\n", retval, i); 1795 "iterations left %d\n", retval, i);
1796 break; 1796 break;
1797 1797
@@ -1800,24 +1800,24 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1800 if (dev->out_pipe == 0 && dev->in_pipe == 0) 1800 if (dev->out_pipe == 0 && dev->in_pipe == 0)
1801 break; 1801 break;
1802 retval = 0; 1802 retval = 0;
1803 dev_dbg (&intf->dev, "TEST 13: set/clear %d halts\n", 1803 dev_info(&intf->dev, "TEST 13: set/clear %d halts\n",
1804 param->iterations); 1804 param->iterations);
1805 for (i = param->iterations; retval == 0 && i--; /* NOP */) 1805 for (i = param->iterations; retval == 0 && i--; /* NOP */)
1806 retval = halt_simple (dev); 1806 retval = halt_simple (dev);
1807 1807
1808 if (retval) 1808 if (retval)
1809 DBG (dev, "halts failed, iterations left %d\n", i); 1809 ERROR(dev, "halts failed, iterations left %d\n", i);
1810 break; 1810 break;
1811 1811
1812 /* control write tests */ 1812 /* control write tests */
1813 case 14: 1813 case 14:
1814 if (!dev->info->ctrl_out) 1814 if (!dev->info->ctrl_out)
1815 break; 1815 break;
1816 dev_dbg (&intf->dev, "TEST 14: %d ep0out, %d..%d vary %d\n", 1816 dev_info(&intf->dev, "TEST 14: %d ep0out, %d..%d vary %d\n",
1817 param->iterations, 1817 param->iterations,
1818 realworld ? 1 : 0, param->length, 1818 realworld ? 1 : 0, param->length,
1819 param->vary); 1819 param->vary);
1820 retval = ctrl_out (dev, param->iterations, 1820 retval = ctrl_out(dev, param->iterations,
1821 param->length, param->vary); 1821 param->length, param->vary);
1822 break; 1822 break;
1823 1823
@@ -1825,7 +1825,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1825 case 15: 1825 case 15:
1826 if (dev->out_iso_pipe == 0 || param->sglen == 0) 1826 if (dev->out_iso_pipe == 0 || param->sglen == 0)
1827 break; 1827 break;
1828 dev_dbg (&intf->dev, 1828 dev_info(&intf->dev,
1829 "TEST 15: write %d iso, %d entries of %d bytes\n", 1829 "TEST 15: write %d iso, %d entries of %d bytes\n",
1830 param->iterations, 1830 param->iterations,
1831 param->sglen, param->length); 1831 param->sglen, param->length);
@@ -1838,7 +1838,7 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1838 case 16: 1838 case 16:
1839 if (dev->in_iso_pipe == 0 || param->sglen == 0) 1839 if (dev->in_iso_pipe == 0 || param->sglen == 0)
1840 break; 1840 break;
1841 dev_dbg (&intf->dev, 1841 dev_info(&intf->dev,
1842 "TEST 16: read %d iso, %d entries of %d bytes\n", 1842 "TEST 16: read %d iso, %d entries of %d bytes\n",
1843 param->iterations, 1843 param->iterations,
1844 param->sglen, param->length); 1844 param->sglen, param->length);
@@ -1898,7 +1898,8 @@ usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id)
1898 return -ENODEV; 1898 return -ENODEV;
1899 if (product && le16_to_cpu(udev->descriptor.idProduct) != (u16)product) 1899 if (product && le16_to_cpu(udev->descriptor.idProduct) != (u16)product)
1900 return -ENODEV; 1900 return -ENODEV;
1901 dbg ("matched module params, vend=0x%04x prod=0x%04x", 1901 dev_info(&intf->dev, "matched module params, "
1902 "vend=0x%04x prod=0x%04x\n",
1902 le16_to_cpu(udev->descriptor.idVendor), 1903 le16_to_cpu(udev->descriptor.idVendor),
1903 le16_to_cpu(udev->descriptor.idProduct)); 1904 le16_to_cpu(udev->descriptor.idProduct));
1904 } 1905 }
@@ -1940,7 +1941,8 @@ usbtest_probe (struct usb_interface *intf, const struct usb_device_id *id)
1940 1941
1941 status = get_endpoints (dev, intf); 1942 status = get_endpoints (dev, intf);
1942 if (status < 0) { 1943 if (status < 0) {
1943 dbg ("couldn't get endpoints, %d\n", status); 1944 WARN(dev, "couldn't get endpoints, %d\n",
1945 status);
1944 return status; 1946 return status;
1945 } 1947 }
1946 /* may find bulk or ISO pipes */ 1948 /* may find bulk or ISO pipes */
@@ -2082,21 +2084,9 @@ static struct usbtest_info generic_info = {
2082}; 2084};
2083#endif 2085#endif
2084 2086
2085// FIXME remove this
2086static struct usbtest_info hact_info = {
2087 .name = "FX2/hact",
2088 //.ep_in = 6,
2089 .ep_out = 2,
2090 .alt = -1,
2091};
2092
2093 2087
2094static struct usb_device_id id_table [] = { 2088static struct usb_device_id id_table [] = {
2095 2089
2096 { USB_DEVICE (0x0547, 0x1002),
2097 .driver_info = (unsigned long) &hact_info,
2098 },
2099
2100 /*-------------------------------------------------------------*/ 2090 /*-------------------------------------------------------------*/
2101 2091
2102 /* EZ-USB devices which download firmware to replace (or in our 2092 /* EZ-USB devices which download firmware to replace (or in our
@@ -2185,7 +2175,7 @@ static int __init usbtest_init (void)
2185{ 2175{
2186#ifdef GENERIC 2176#ifdef GENERIC
2187 if (vendor) 2177 if (vendor)
2188 dbg ("params: vend=0x%04x prod=0x%04x", vendor, product); 2178 pr_debug("params: vend=0x%04x prod=0x%04x\n", vendor, product);
2189#endif 2179#endif
2190 return usb_register (&usbtest_driver); 2180 return usb_register (&usbtest_driver);
2191} 2181}
diff --git a/drivers/usb/serial/aircable.c b/drivers/usb/serial/aircable.c
index 9b1bb347dc2d..db6f97a93c02 100644
--- a/drivers/usb/serial/aircable.c
+++ b/drivers/usb/serial/aircable.c
@@ -147,7 +147,7 @@ static void serial_buf_free(struct circ_buf *cb)
147 */ 147 */
148static int serial_buf_data_avail(struct circ_buf *cb) 148static int serial_buf_data_avail(struct circ_buf *cb)
149{ 149{
150 return CIRC_CNT(cb->head,cb->tail,AIRCABLE_BUF_SIZE); 150 return CIRC_CNT(cb->head, cb->tail, AIRCABLE_BUF_SIZE);
151} 151}
152 152
153/* 153/*
@@ -171,7 +171,7 @@ static int serial_buf_put(struct circ_buf *cb, const char *buf, int count)
171 cb->head = (cb->head + c) & (AIRCABLE_BUF_SIZE-1); 171 cb->head = (cb->head + c) & (AIRCABLE_BUF_SIZE-1);
172 buf += c; 172 buf += c;
173 count -= c; 173 count -= c;
174 ret= c; 174 ret = c;
175 } 175 }
176 return ret; 176 return ret;
177} 177}
@@ -197,7 +197,7 @@ static int serial_buf_get(struct circ_buf *cb, char *buf, int count)
197 cb->tail = (cb->tail + c) & (AIRCABLE_BUF_SIZE-1); 197 cb->tail = (cb->tail + c) & (AIRCABLE_BUF_SIZE-1);
198 buf += c; 198 buf += c;
199 count -= c; 199 count -= c;
200 ret= c; 200 ret = c;
201 } 201 }
202 return ret; 202 return ret;
203} 203}
@@ -208,7 +208,7 @@ static void aircable_send(struct usb_serial_port *port)
208{ 208{
209 int count, result; 209 int count, result;
210 struct aircable_private *priv = usb_get_serial_port_data(port); 210 struct aircable_private *priv = usb_get_serial_port_data(port);
211 unsigned char* buf; 211 unsigned char *buf;
212 __le16 *dbuf; 212 __le16 *dbuf;
213 dbg("%s - port %d", __func__, port->number); 213 dbg("%s - port %d", __func__, port->number);
214 if (port->write_urb_busy) 214 if (port->write_urb_busy)
@@ -229,7 +229,8 @@ static void aircable_send(struct usb_serial_port *port)
229 buf[1] = TX_HEADER_1; 229 buf[1] = TX_HEADER_1;
230 dbuf = (__le16 *)&buf[2]; 230 dbuf = (__le16 *)&buf[2];
231 *dbuf = cpu_to_le16((u16)count); 231 *dbuf = cpu_to_le16((u16)count);
232 serial_buf_get(priv->tx_buf,buf + HCI_HEADER_LENGTH, MAX_HCI_FRAMESIZE); 232 serial_buf_get(priv->tx_buf, buf + HCI_HEADER_LENGTH,
233 MAX_HCI_FRAMESIZE);
233 234
234 memcpy(port->write_urb->transfer_buffer, buf, 235 memcpy(port->write_urb->transfer_buffer, buf,
235 count + HCI_HEADER_LENGTH); 236 count + HCI_HEADER_LENGTH);
@@ -261,7 +262,7 @@ static void aircable_read(struct work_struct *work)
261 struct tty_struct *tty; 262 struct tty_struct *tty;
262 unsigned char *data; 263 unsigned char *data;
263 int count; 264 int count;
264 if (priv->rx_flags & THROTTLED){ 265 if (priv->rx_flags & THROTTLED) {
265 if (priv->rx_flags & ACTUALLY_THROTTLED) 266 if (priv->rx_flags & ACTUALLY_THROTTLED)
266 schedule_work(&priv->rx_work); 267 schedule_work(&priv->rx_work);
267 return; 268 return;
@@ -282,10 +283,10 @@ static void aircable_read(struct work_struct *work)
282 count = min(64, serial_buf_data_avail(priv->rx_buf)); 283 count = min(64, serial_buf_data_avail(priv->rx_buf));
283 284
284 if (count <= 0) 285 if (count <= 0)
285 return; //We have finished sending everything. 286 return; /* We have finished sending everything. */
286 287
287 tty_prepare_flip_string(tty, &data, count); 288 tty_prepare_flip_string(tty, &data, count);
288 if (!data){ 289 if (!data) {
289 err("%s- kzalloc(%d) failed.", __func__, count); 290 err("%s- kzalloc(%d) failed.", __func__, count);
290 return; 291 return;
291 } 292 }
@@ -304,9 +305,10 @@ static void aircable_read(struct work_struct *work)
304static int aircable_probe(struct usb_serial *serial, 305static int aircable_probe(struct usb_serial *serial,
305 const struct usb_device_id *id) 306 const struct usb_device_id *id)
306{ 307{
307 struct usb_host_interface *iface_desc = serial->interface->cur_altsetting; 308 struct usb_host_interface *iface_desc = serial->interface->
309 cur_altsetting;
308 struct usb_endpoint_descriptor *endpoint; 310 struct usb_endpoint_descriptor *endpoint;
309 int num_bulk_out=0; 311 int num_bulk_out = 0;
310 int i; 312 int i;
311 313
312 for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) { 314 for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
@@ -325,13 +327,13 @@ static int aircable_probe(struct usb_serial *serial,
325 return 0; 327 return 0;
326} 328}
327 329
328static int aircable_attach (struct usb_serial *serial) 330static int aircable_attach(struct usb_serial *serial)
329{ 331{
330 struct usb_serial_port *port = serial->port[0]; 332 struct usb_serial_port *port = serial->port[0];
331 struct aircable_private *priv; 333 struct aircable_private *priv;
332 334
333 priv = kzalloc(sizeof(struct aircable_private), GFP_KERNEL); 335 priv = kzalloc(sizeof(struct aircable_private), GFP_KERNEL);
334 if (!priv){ 336 if (!priv) {
335 err("%s- kmalloc(%Zd) failed.", __func__, 337 err("%s- kmalloc(%Zd) failed.", __func__,
336 sizeof(struct aircable_private)); 338 sizeof(struct aircable_private));
337 return -ENOMEM; 339 return -ENOMEM;
@@ -392,7 +394,7 @@ static int aircable_write(struct usb_serial_port *port,
392 394
393 usb_serial_debug_data(debug, &port->dev, __func__, count, source); 395 usb_serial_debug_data(debug, &port->dev, __func__, count, source);
394 396
395 if (!count){ 397 if (!count) {
396 dbg("%s - write request of 0 bytes", __func__); 398 dbg("%s - write request of 0 bytes", __func__);
397 return count; 399 return count;
398 } 400 }
@@ -418,31 +420,31 @@ static void aircable_write_bulk_callback(struct urb *urb)
418 420
419 /* This has been taken from cypress_m8.c cypress_write_int_callback */ 421 /* This has been taken from cypress_m8.c cypress_write_int_callback */
420 switch (status) { 422 switch (status) {
421 case 0: 423 case 0:
422 /* success */ 424 /* success */
423 break; 425 break;
424 case -ECONNRESET: 426 case -ECONNRESET:
425 case -ENOENT: 427 case -ENOENT:
426 case -ESHUTDOWN: 428 case -ESHUTDOWN:
427 /* this urb is terminated, clean up */ 429 /* this urb is terminated, clean up */
428 dbg("%s - urb shutting down with status: %d", 430 dbg("%s - urb shutting down with status: %d",
429 __func__, status); 431 __func__, status);
430 port->write_urb_busy = 0; 432 port->write_urb_busy = 0;
433 return;
434 default:
435 /* error in the urb, so we have to resubmit it */
436 dbg("%s - Overflow in write", __func__);
437 dbg("%s - nonzero write bulk status received: %d",
438 __func__, status);
439 port->write_urb->transfer_buffer_length = 1;
440 port->write_urb->dev = port->serial->dev;
441 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
442 if (result)
443 dev_err(&urb->dev->dev,
444 "%s - failed resubmitting write urb, error %d\n",
445 __func__, result);
446 else
431 return; 447 return;
432 default:
433 /* error in the urb, so we have to resubmit it */
434 dbg("%s - Overflow in write", __func__);
435 dbg("%s - nonzero write bulk status received: %d",
436 __func__, status);
437 port->write_urb->transfer_buffer_length = 1;
438 port->write_urb->dev = port->serial->dev;
439 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
440 if (result)
441 dev_err(&urb->dev->dev,
442 "%s - failed resubmitting write urb, error %d\n",
443 __func__, result);
444 else
445 return;
446 } 448 }
447 449
448 port->write_urb_busy = 0; 450 port->write_urb_busy = 0;
@@ -472,11 +474,11 @@ static void aircable_read_bulk_callback(struct urb *urb)
472 dbg("%s - caught -EPROTO, resubmitting the urb", 474 dbg("%s - caught -EPROTO, resubmitting the urb",
473 __func__); 475 __func__);
474 usb_fill_bulk_urb(port->read_urb, port->serial->dev, 476 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
475 usb_rcvbulkpipe(port->serial->dev, 477 usb_rcvbulkpipe(port->serial->dev,
476 port->bulk_in_endpointAddress), 478 port->bulk_in_endpointAddress),
477 port->read_urb->transfer_buffer, 479 port->read_urb->transfer_buffer,
478 port->read_urb->transfer_buffer_length, 480 port->read_urb->transfer_buffer_length,
479 aircable_read_bulk_callback, port); 481 aircable_read_bulk_callback, port);
480 482
481 result = usb_submit_urb(urb, GFP_ATOMIC); 483 result = usb_submit_urb(urb, GFP_ATOMIC);
482 if (result) 484 if (result)
@@ -490,7 +492,7 @@ static void aircable_read_bulk_callback(struct urb *urb)
490 } 492 }
491 493
492 usb_serial_debug_data(debug, &port->dev, __func__, 494 usb_serial_debug_data(debug, &port->dev, __func__,
493 urb->actual_length,urb->transfer_buffer); 495 urb->actual_length, urb->transfer_buffer);
494 496
495 tty = port->tty; 497 tty = port->tty;
496 if (tty && urb->actual_length) { 498 if (tty && urb->actual_length) {
@@ -507,9 +509,9 @@ static void aircable_read_bulk_callback(struct urb *urb)
507 no_packages = urb->actual_length / (HCI_COMPLETE_FRAME); 509 no_packages = urb->actual_length / (HCI_COMPLETE_FRAME);
508 510
509 if (urb->actual_length % HCI_COMPLETE_FRAME != 0) 511 if (urb->actual_length % HCI_COMPLETE_FRAME != 0)
510 no_packages+=1; 512 no_packages++;
511 513
512 for (i = 0; i < no_packages ;i++) { 514 for (i = 0; i < no_packages; i++) {
513 if (remaining > (HCI_COMPLETE_FRAME)) 515 if (remaining > (HCI_COMPLETE_FRAME))
514 package_length = HCI_COMPLETE_FRAME; 516 package_length = HCI_COMPLETE_FRAME;
515 else 517 else
@@ -529,7 +531,7 @@ static void aircable_read_bulk_callback(struct urb *urb)
529 if (port->open_count) { 531 if (port->open_count) {
530 usb_fill_bulk_urb(port->read_urb, port->serial->dev, 532 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
531 usb_rcvbulkpipe(port->serial->dev, 533 usb_rcvbulkpipe(port->serial->dev,
532 port->bulk_in_endpointAddress), 534 port->bulk_in_endpointAddress),
533 port->read_urb->transfer_buffer, 535 port->read_urb->transfer_buffer,
534 port->read_urb->transfer_buffer_length, 536 port->read_urb->transfer_buffer_length,
535 aircable_read_bulk_callback, port); 537 aircable_read_bulk_callback, port);
@@ -602,7 +604,7 @@ static struct usb_serial_driver aircable_device = {
602 .unthrottle = aircable_unthrottle, 604 .unthrottle = aircable_unthrottle,
603}; 605};
604 606
605static int __init aircable_init (void) 607static int __init aircable_init(void)
606{ 608{
607 int retval; 609 int retval;
608 retval = usb_serial_register(&aircable_device); 610 retval = usb_serial_register(&aircable_device);
@@ -619,7 +621,7 @@ failed_usb_register:
619 return retval; 621 return retval;
620} 622}
621 623
622static void __exit aircable_exit (void) 624static void __exit aircable_exit(void)
623{ 625{
624 usb_deregister(&aircable_driver); 626 usb_deregister(&aircable_driver);
625 usb_serial_deregister(&aircable_device); 627 usb_serial_deregister(&aircable_device);
diff --git a/drivers/usb/serial/airprime.c b/drivers/usb/serial/airprime.c
index 725b6b94c274..0798c14ce787 100644
--- a/drivers/usb/serial/airprime.c
+++ b/drivers/usb/serial/airprime.c
@@ -68,8 +68,9 @@ static int airprime_send_setup(struct usb_serial_port *port)
68 val |= 0x02; 68 val |= 0x02;
69 69
70 return usb_control_msg(serial->dev, 70 return usb_control_msg(serial->dev,
71 usb_rcvctrlpipe(serial->dev, 0), 71 usb_rcvctrlpipe(serial->dev, 0),
72 0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT); 72 0x22, 0x21, val, 0, NULL, 0,
73 USB_CTRL_SET_TIMEOUT);
73 } 74 }
74 75
75 return 0; 76 return 0;
@@ -90,17 +91,19 @@ static void airprime_read_bulk_callback(struct urb *urb)
90 __func__, status); 91 __func__, status);
91 return; 92 return;
92 } 93 }
93 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 94 usb_serial_debug_data(debug, &port->dev, __func__,
95 urb->actual_length, data);
94 96
95 tty = port->tty; 97 tty = port->tty;
96 if (tty && urb->actual_length) { 98 if (tty && urb->actual_length) {
97 tty_insert_flip_string (tty, data, urb->actual_length); 99 tty_insert_flip_string(tty, data, urb->actual_length);
98 tty_flip_buffer_push (tty); 100 tty_flip_buffer_push(tty);
99 } 101 }
100 102
101 result = usb_submit_urb (urb, GFP_ATOMIC); 103 result = usb_submit_urb(urb, GFP_ATOMIC);
102 if (result) 104 if (result)
103 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", 105 dev_err(&port->dev,
106 "%s - failed resubmitting read urb, error %d\n",
104 __func__, result); 107 __func__, result);
105 return; 108 return;
106} 109}
@@ -115,7 +118,7 @@ static void airprime_write_bulk_callback(struct urb *urb)
115 dbg("%s - port %d", __func__, port->number); 118 dbg("%s - port %d", __func__, port->number);
116 119
117 /* free up the transfer buffer, as usb_free_urb() does not do this */ 120 /* free up the transfer buffer, as usb_free_urb() does not do this */
118 kfree (urb->transfer_buffer); 121 kfree(urb->transfer_buffer);
119 122
120 if (status) 123 if (status)
121 dbg("%s - nonzero write bulk status received: %d", 124 dbg("%s - nonzero write bulk status received: %d",
@@ -171,7 +174,7 @@ static int airprime_open(struct usb_serial_port *port, struct file *filp)
171 } 174 }
172 usb_fill_bulk_urb(urb, serial->dev, 175 usb_fill_bulk_urb(urb, serial->dev,
173 usb_rcvbulkpipe(serial->dev, 176 usb_rcvbulkpipe(serial->dev,
174 port->bulk_out_endpointAddress), 177 port->bulk_out_endpointAddress),
175 buffer, buffer_size, 178 buffer, buffer_size,
176 airprime_read_bulk_callback, port); 179 airprime_read_bulk_callback, port);
177 result = usb_submit_urb(urb, GFP_KERNEL); 180 result = usb_submit_urb(urb, GFP_KERNEL);
@@ -183,7 +186,8 @@ static int airprime_open(struct usb_serial_port *port, struct file *filp)
183 __func__, i, port->number, result); 186 __func__, i, port->number, result);
184 goto errout; 187 goto errout;
185 } 188 }
186 /* remember this urb so we can kill it when the port is closed */ 189 /* remember this urb so we can kill it when the
190 port is closed */
187 priv->read_urbp[i] = urb; 191 priv->read_urbp[i] = urb;
188 } 192 }
189 193
@@ -192,22 +196,22 @@ static int airprime_open(struct usb_serial_port *port, struct file *filp)
192 goto out; 196 goto out;
193 197
194 errout: 198 errout:
195 /* some error happened, cancel any submitted urbs and clean up anything that 199 /* some error happened, cancel any submitted urbs and clean up
196 got allocated successfully */ 200 anything that got allocated successfully */
197 201
198 while (i-- != 0) { 202 while (i-- != 0) {
199 urb = priv->read_urbp[i]; 203 urb = priv->read_urbp[i];
200 buffer = urb->transfer_buffer; 204 buffer = urb->transfer_buffer;
201 usb_kill_urb (urb); 205 usb_kill_urb(urb);
202 usb_free_urb (urb); 206 usb_free_urb(urb);
203 kfree (buffer); 207 kfree(buffer);
204 } 208 }
205 209
206 out: 210 out:
207 return result; 211 return result;
208} 212}
209 213
210static void airprime_close(struct usb_serial_port *port, struct file * filp) 214static void airprime_close(struct usb_serial_port *port, struct file *filp)
211{ 215{
212 struct airprime_private *priv = usb_get_serial_port_data(port); 216 struct airprime_private *priv = usb_get_serial_port_data(port);
213 int i; 217 int i;
@@ -220,16 +224,16 @@ static void airprime_close(struct usb_serial_port *port, struct file * filp)
220 mutex_lock(&port->serial->disc_mutex); 224 mutex_lock(&port->serial->disc_mutex);
221 if (!port->serial->disconnected) 225 if (!port->serial->disconnected)
222 airprime_send_setup(port); 226 airprime_send_setup(port);
223 mutex_lock(&port->serial->disc_mutex); 227 mutex_unlock(&port->serial->disc_mutex);
224 228
225 for (i = 0; i < NUM_READ_URBS; ++i) { 229 for (i = 0; i < NUM_READ_URBS; ++i) {
226 usb_kill_urb (priv->read_urbp[i]); 230 usb_kill_urb(priv->read_urbp[i]);
227 kfree (priv->read_urbp[i]->transfer_buffer); 231 kfree(priv->read_urbp[i]->transfer_buffer);
228 usb_free_urb (priv->read_urbp[i]); 232 usb_free_urb(priv->read_urbp[i]);
229 } 233 }
230 234
231 /* free up private structure */ 235 /* free up private structure */
232 kfree (priv); 236 kfree(priv);
233 usb_set_serial_port_data(port, NULL); 237 usb_set_serial_port_data(port, NULL);
234} 238}
235 239
@@ -259,10 +263,10 @@ static int airprime_write(struct usb_serial_port *port,
259 urb = usb_alloc_urb(0, GFP_ATOMIC); 263 urb = usb_alloc_urb(0, GFP_ATOMIC);
260 if (!urb) { 264 if (!urb) {
261 dev_err(&port->dev, "no more free urbs\n"); 265 dev_err(&port->dev, "no more free urbs\n");
262 kfree (buffer); 266 kfree(buffer);
263 return -ENOMEM; 267 return -ENOMEM;
264 } 268 }
265 memcpy (buffer, buf, count); 269 memcpy(buffer, buf, count);
266 270
267 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer); 271 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer);
268 272
@@ -279,7 +283,7 @@ static int airprime_write(struct usb_serial_port *port,
279 "%s - usb_submit_urb(write bulk) failed with status = %d\n", 283 "%s - usb_submit_urb(write bulk) failed with status = %d\n",
280 __func__, status); 284 __func__, status);
281 count = status; 285 count = status;
282 kfree (buffer); 286 kfree(buffer);
283 } else { 287 } else {
284 spin_lock_irqsave(&priv->lock, flags); 288 spin_lock_irqsave(&priv->lock, flags);
285 ++priv->outstanding_urbs; 289 ++priv->outstanding_urbs;
@@ -287,7 +291,7 @@ static int airprime_write(struct usb_serial_port *port,
287 } 291 }
288 /* we are done with this urb, so let the host driver 292 /* we are done with this urb, so let the host driver
289 * really free it when it is finished with it */ 293 * really free it when it is finished with it */
290 usb_free_urb (urb); 294 usb_free_urb(urb);
291 return count; 295 return count;
292} 296}
293 297
@@ -315,8 +319,10 @@ static int __init airprime_init(void)
315{ 319{
316 int retval; 320 int retval;
317 321
318 airprime_device.num_ports = 322 airprime_device.num_ports = endpoints;
319 (endpoints > 0 && endpoints <= MAX_BULK_EPS) ? endpoints : NUM_BULK_EPS; 323 if (endpoints < 0 || endpoints >= MAX_BULK_EPS)
324 airprime_device.num_ports = NUM_BULK_EPS;
325
320 retval = usb_serial_register(&airprime_device); 326 retval = usb_serial_register(&airprime_device);
321 if (retval) 327 if (retval)
322 return retval; 328 return retval;
@@ -341,6 +347,7 @@ MODULE_LICENSE("GPL");
341module_param(debug, bool, S_IRUGO | S_IWUSR); 347module_param(debug, bool, S_IRUGO | S_IWUSR);
342MODULE_PARM_DESC(debug, "Debug enabled"); 348MODULE_PARM_DESC(debug, "Debug enabled");
343module_param(buffer_size, int, 0); 349module_param(buffer_size, int, 0);
344MODULE_PARM_DESC(buffer_size, "Size of the transfer buffers in bytes (default 4096)"); 350MODULE_PARM_DESC(buffer_size,
351 "Size of the transfer buffers in bytes (default 4096)");
345module_param(endpoints, int, 0); 352module_param(endpoints, int, 0);
346MODULE_PARM_DESC(endpoints, "Number of bulk EPs to configure (default 3)"); 353MODULE_PARM_DESC(endpoints, "Number of bulk EPs to configure (default 3)");
diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
index 599ab2e548a7..77895c8f8f31 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -24,7 +24,7 @@
24#include <linux/usb.h> 24#include <linux/usb.h>
25#include <linux/usb/serial.h> 25#include <linux/usb/serial.h>
26#include <linux/serial.h> 26#include <linux/serial.h>
27#include <asm/uaccess.h> 27#include <linux/uaccess.h>
28 28
29 29
30static int debug; 30static int debug;
@@ -246,29 +246,29 @@ static void ark3116_set_termios(struct usb_serial_port *port,
246 baud = tty_get_baud_rate(port->tty); 246 baud = tty_get_baud_rate(port->tty);
247 247
248 switch (baud) { 248 switch (baud) {
249 case 75: 249 case 75:
250 case 150: 250 case 150:
251 case 300: 251 case 300:
252 case 600: 252 case 600:
253 case 1200: 253 case 1200:
254 case 1800: 254 case 1800:
255 case 2400: 255 case 2400:
256 case 4800: 256 case 4800:
257 case 9600: 257 case 9600:
258 case 19200: 258 case 19200:
259 case 38400: 259 case 38400:
260 case 57600: 260 case 57600:
261 case 115200: 261 case 115200:
262 case 230400: 262 case 230400:
263 case 460800: 263 case 460800:
264 /* Report the resulting rate back to the caller */ 264 /* Report the resulting rate back to the caller */
265 tty_encode_baud_rate(port->tty, baud, baud); 265 tty_encode_baud_rate(port->tty, baud, baud);
266 break; 266 break;
267 /* set 9600 as default (if given baudrate is invalid for example) */ 267 /* set 9600 as default (if given baudrate is invalid for example) */
268 default: 268 default:
269 tty_encode_baud_rate(port->tty, 9600, 9600); 269 tty_encode_baud_rate(port->tty, 9600, 9600);
270 case 0: 270 case 0:
271 baud = 9600; 271 baud = 9600;
272 } 272 }
273 273
274 /* 274 /*
@@ -380,19 +380,19 @@ static int ark3116_ioctl(struct usb_serial_port *port, struct file *file,
380 switch (cmd) { 380 switch (cmd) {
381 case TIOCGSERIAL: 381 case TIOCGSERIAL:
382 /* XXX: Some of these values are probably wrong. */ 382 /* XXX: Some of these values are probably wrong. */
383 memset(&serstruct, 0, sizeof (serstruct)); 383 memset(&serstruct, 0, sizeof(serstruct));
384 serstruct.type = PORT_16654; 384 serstruct.type = PORT_16654;
385 serstruct.line = port->serial->minor; 385 serstruct.line = port->serial->minor;
386 serstruct.port = port->number; 386 serstruct.port = port->number;
387 serstruct.custom_divisor = 0; 387 serstruct.custom_divisor = 0;
388 serstruct.baud_base = 460800; 388 serstruct.baud_base = 460800;
389 389
390 if (copy_to_user(user_arg, &serstruct, sizeof (serstruct))) 390 if (copy_to_user(user_arg, &serstruct, sizeof(serstruct)))
391 return -EFAULT; 391 return -EFAULT;
392 392
393 return 0; 393 return 0;
394 case TIOCSSERIAL: 394 case TIOCSSERIAL:
395 if (copy_from_user(&serstruct, user_arg, sizeof (serstruct))) 395 if (copy_from_user(&serstruct, user_arg, sizeof(serstruct)))
396 return -EFAULT; 396 return -EFAULT;
397 return 0; 397 return 0;
398 default: 398 default:
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index d947d955bceb..ba28fdc9ccd2 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -130,7 +130,7 @@ static int ch341_get_status(struct usb_device *dev)
130 return -ENOMEM; 130 return -ENOMEM;
131 131
132 r = ch341_control_in(dev, 0x95, 0x0706, 0, buffer, size); 132 r = ch341_control_in(dev, 0x95, 0x0706, 0, buffer, size);
133 if ( r < 0) 133 if (r < 0)
134 goto out; 134 goto out;
135 135
136 /* Not having the datasheet for the CH341, we ignore the bytes returned 136 /* Not having the datasheet for the CH341, we ignore the bytes returned
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index d17d1645714f..04a56f300ea6 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -1421,8 +1421,7 @@ static void digi_close(struct usb_serial_port *port, struct file *filp)
1421 tty_wait_until_sent(tty, DIGI_CLOSE_TIMEOUT); 1421 tty_wait_until_sent(tty, DIGI_CLOSE_TIMEOUT);
1422 1422
1423 /* flush driver and line discipline buffers */ 1423 /* flush driver and line discipline buffers */
1424 if (tty->driver->flush_buffer) 1424 tty_driver_flush_buffer(tty);
1425 tty->driver->flush_buffer(tty);
1426 tty_ldisc_flush(tty); 1425 tty_ldisc_flush(tty);
1427 1426
1428 if (port->serial->dev) { 1427 if (port->serial->dev) {
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index c7329f43d9c9..5b349ece7247 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -133,6 +133,14 @@ static struct ftdi_sio_quirk ftdi_HE_TIRA1_quirk = {
133static struct usb_device_id id_table_combined [] = { 133static struct usb_device_id id_table_combined [] = {
134 { USB_DEVICE(FTDI_VID, FTDI_AMC232_PID) }, 134 { USB_DEVICE(FTDI_VID, FTDI_AMC232_PID) },
135 { USB_DEVICE(FTDI_VID, FTDI_CANUSB_PID) }, 135 { USB_DEVICE(FTDI_VID, FTDI_CANUSB_PID) },
136 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_0_PID) },
137 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_1_PID) },
138 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_2_PID) },
139 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_3_PID) },
140 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_4_PID) },
141 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_5_PID) },
142 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_6_PID) },
143 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_7_PID) },
136 { USB_DEVICE(FTDI_VID, FTDI_ACTZWAVE_PID) }, 144 { USB_DEVICE(FTDI_VID, FTDI_ACTZWAVE_PID) },
137 { USB_DEVICE(FTDI_VID, FTDI_IRTRANS_PID) }, 145 { USB_DEVICE(FTDI_VID, FTDI_IRTRANS_PID) },
138 { USB_DEVICE(FTDI_VID, FTDI_IPLUS_PID) }, 146 { USB_DEVICE(FTDI_VID, FTDI_IPLUS_PID) },
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h
index 6da539ede0ee..504edf8c3a3f 100644
--- a/drivers/usb/serial/ftdi_sio.h
+++ b/drivers/usb/serial/ftdi_sio.h
@@ -40,6 +40,17 @@
40/* AlphaMicro Components AMC-232USB01 device */ 40/* AlphaMicro Components AMC-232USB01 device */
41#define FTDI_AMC232_PID 0xFF00 /* Product Id */ 41#define FTDI_AMC232_PID 0xFF00 /* Product Id */
42 42
43/* SCS HF Radio Modems PID's (http://www.scs-ptc.com) */
44/* the VID is the standard ftdi vid (FTDI_VID) */
45#define FTDI_SCS_DEVICE_0_PID 0xD010 /* SCS PTC-IIusb */
46#define FTDI_SCS_DEVICE_1_PID 0xD011 /* SCS Tracker / DSP TNC */
47#define FTDI_SCS_DEVICE_2_PID 0xD012
48#define FTDI_SCS_DEVICE_3_PID 0xD013
49#define FTDI_SCS_DEVICE_4_PID 0xD014
50#define FTDI_SCS_DEVICE_5_PID 0xD015
51#define FTDI_SCS_DEVICE_6_PID 0xD016
52#define FTDI_SCS_DEVICE_7_PID 0xD017
53
43/* ACT Solutions HomePro ZWave interface (http://www.act-solutions.com/HomePro.htm) */ 54/* ACT Solutions HomePro ZWave interface (http://www.act-solutions.com/HomePro.htm) */
44#define FTDI_ACTZWAVE_PID 0xF2D0 55#define FTDI_ACTZWAVE_PID 0xF2D0
45 56
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 6bcb82d3911a..78f2f6db494d 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -1713,7 +1713,7 @@ static int mos7840_tiocmset(struct usb_serial_port *port, struct file *file,
1713{ 1713{
1714 struct moschip_port *mos7840_port; 1714 struct moschip_port *mos7840_port;
1715 unsigned int mcr; 1715 unsigned int mcr;
1716 unsigned int status; 1716 int status;
1717 1717
1718 dbg("%s - port %d", __func__, port->number); 1718 dbg("%s - port %d", __func__, port->number);
1719 1719
@@ -1740,11 +1740,10 @@ static int mos7840_tiocmset(struct usb_serial_port *port, struct file *file,
1740 1740
1741 mos7840_port->shadowMCR = mcr; 1741 mos7840_port->shadowMCR = mcr;
1742 1742
1743 status = 0;
1744 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, mcr); 1743 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, mcr);
1745 if (status < 0) { 1744 if (status < 0) {
1746 dbg("setting MODEM_CONTROL_REGISTER Failed\n"); 1745 dbg("setting MODEM_CONTROL_REGISTER Failed\n");
1747 return -1; 1746 return status;
1748 } 1747 }
1749 1748
1750 return 0; 1749 return 0;
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index a9934a3f9845..0cb0d77dc429 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -296,16 +296,14 @@ static int serial_write (struct tty_struct * tty, const unsigned char *buf, int
296 struct usb_serial_port *port = tty->driver_data; 296 struct usb_serial_port *port = tty->driver_data;
297 int retval = -ENODEV; 297 int retval = -ENODEV;
298 298
299 if (!port || port->serial->dev->state == USB_STATE_NOTATTACHED) 299 if (port->serial->dev->state == USB_STATE_NOTATTACHED)
300 goto exit; 300 goto exit;
301 301
302 dbg("%s - port %d, %d byte(s)", __func__, port->number, count); 302 dbg("%s - port %d, %d byte(s)", __func__, port->number, count);
303 303
304 if (!port->open_count) { 304 /* open_count is managed under the mutex lock for the tty so cannot
305 retval = -EINVAL; 305 drop to zero until after the last close completes */
306 dbg("%s - port not opened", __func__); 306 WARN_ON(!port->open_count);
307 goto exit;
308 }
309 307
310 /* pass on to the driver specific version of this function */ 308 /* pass on to the driver specific version of this function */
311 retval = port->serial->type->write(port, buf, count); 309 retval = port->serial->type->write(port, buf, count);
@@ -317,61 +315,28 @@ exit:
317static int serial_write_room (struct tty_struct *tty) 315static int serial_write_room (struct tty_struct *tty)
318{ 316{
319 struct usb_serial_port *port = tty->driver_data; 317 struct usb_serial_port *port = tty->driver_data;
320 int retval = -ENODEV;
321
322 if (!port)
323 goto exit;
324
325 dbg("%s - port %d", __func__, port->number); 318 dbg("%s - port %d", __func__, port->number);
326 319 WARN_ON(!port->open_count);
327 if (!port->open_count) {
328 dbg("%s - port not open", __func__);
329 goto exit;
330 }
331
332 /* pass on to the driver specific version of this function */ 320 /* pass on to the driver specific version of this function */
333 retval = port->serial->type->write_room(port); 321 return port->serial->type->write_room(port);
334
335exit:
336 return retval;
337} 322}
338 323
339static int serial_chars_in_buffer (struct tty_struct *tty) 324static int serial_chars_in_buffer (struct tty_struct *tty)
340{ 325{
341 struct usb_serial_port *port = tty->driver_data; 326 struct usb_serial_port *port = tty->driver_data;
342 int retval = -ENODEV;
343
344 if (!port)
345 goto exit;
346
347 dbg("%s = port %d", __func__, port->number); 327 dbg("%s = port %d", __func__, port->number);
348 328
349 if (!port->open_count) { 329 WARN_ON(!port->open_count);
350 dbg("%s - port not open", __func__);
351 goto exit;
352 }
353
354 /* pass on to the driver specific version of this function */ 330 /* pass on to the driver specific version of this function */
355 retval = port->serial->type->chars_in_buffer(port); 331 return port->serial->type->chars_in_buffer(port);
356
357exit:
358 return retval;
359} 332}
360 333
361static void serial_throttle (struct tty_struct * tty) 334static void serial_throttle (struct tty_struct * tty)
362{ 335{
363 struct usb_serial_port *port = tty->driver_data; 336 struct usb_serial_port *port = tty->driver_data;
364
365 if (!port)
366 return;
367
368 dbg("%s - port %d", __func__, port->number); 337 dbg("%s - port %d", __func__, port->number);
369 338
370 if (!port->open_count) { 339 WARN_ON(!port->open_count);
371 dbg ("%s - port not open", __func__);
372 return;
373 }
374
375 /* pass on to the driver specific version of this function */ 340 /* pass on to the driver specific version of this function */
376 if (port->serial->type->throttle) 341 if (port->serial->type->throttle)
377 port->serial->type->throttle(port); 342 port->serial->type->throttle(port);
@@ -380,17 +345,9 @@ static void serial_throttle (struct tty_struct * tty)
380static void serial_unthrottle (struct tty_struct * tty) 345static void serial_unthrottle (struct tty_struct * tty)
381{ 346{
382 struct usb_serial_port *port = tty->driver_data; 347 struct usb_serial_port *port = tty->driver_data;
383
384 if (!port)
385 return;
386
387 dbg("%s - port %d", __func__, port->number); 348 dbg("%s - port %d", __func__, port->number);
388 349
389 if (!port->open_count) { 350 WARN_ON(!port->open_count);
390 dbg("%s - port not open", __func__);
391 return;
392 }
393
394 /* pass on to the driver specific version of this function */ 351 /* pass on to the driver specific version of this function */
395 if (port->serial->type->unthrottle) 352 if (port->serial->type->unthrottle)
396 port->serial->type->unthrottle(port); 353 port->serial->type->unthrottle(port);
@@ -401,42 +358,27 @@ static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned in
401 struct usb_serial_port *port = tty->driver_data; 358 struct usb_serial_port *port = tty->driver_data;
402 int retval = -ENODEV; 359 int retval = -ENODEV;
403 360
404 lock_kernel();
405 if (!port)
406 goto exit;
407
408 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd); 361 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd);
409 362
410 /* Caution - port->open_count is BKL protected */ 363 WARN_ON(!port->open_count);
411 if (!port->open_count) {
412 dbg ("%s - port not open", __func__);
413 goto exit;
414 }
415 364
416 /* pass on to the driver specific version of this function if it is available */ 365 /* pass on to the driver specific version of this function if it is available */
417 if (port->serial->type->ioctl) 366 if (port->serial->type->ioctl) {
367 lock_kernel();
418 retval = port->serial->type->ioctl(port, file, cmd, arg); 368 retval = port->serial->type->ioctl(port, file, cmd, arg);
369 unlock_kernel();
370 }
419 else 371 else
420 retval = -ENOIOCTLCMD; 372 retval = -ENOIOCTLCMD;
421exit:
422 unlock_kernel();
423 return retval; 373 return retval;
424} 374}
425 375
426static void serial_set_termios (struct tty_struct *tty, struct ktermios * old) 376static void serial_set_termios (struct tty_struct *tty, struct ktermios * old)
427{ 377{
428 struct usb_serial_port *port = tty->driver_data; 378 struct usb_serial_port *port = tty->driver_data;
429
430 if (!port)
431 return;
432
433 dbg("%s - port %d", __func__, port->number); 379 dbg("%s - port %d", __func__, port->number);
434 380
435 if (!port->open_count) { 381 WARN_ON(!port->open_count);
436 dbg("%s - port not open", __func__);
437 return;
438 }
439
440 /* pass on to the driver specific version of this function if it is available */ 382 /* pass on to the driver specific version of this function if it is available */
441 if (port->serial->type->set_termios) 383 if (port->serial->type->set_termios)
442 port->serial->type->set_termios(port, old); 384 port->serial->type->set_termios(port, old);
@@ -448,24 +390,15 @@ static void serial_break (struct tty_struct *tty, int break_state)
448{ 390{
449 struct usb_serial_port *port = tty->driver_data; 391 struct usb_serial_port *port = tty->driver_data;
450 392
451 lock_kernel();
452 if (!port) {
453 unlock_kernel();
454 return;
455 }
456
457 dbg("%s - port %d", __func__, port->number); 393 dbg("%s - port %d", __func__, port->number);
458 394
459 if (!port->open_count) { 395 WARN_ON(!port->open_count);
460 dbg("%s - port not open", __func__);
461 unlock_kernel();
462 return;
463 }
464
465 /* pass on to the driver specific version of this function if it is available */ 396 /* pass on to the driver specific version of this function if it is available */
466 if (port->serial->type->break_ctl) 397 if (port->serial->type->break_ctl) {
398 lock_kernel();
467 port->serial->type->break_ctl(port, break_state); 399 port->serial->type->break_ctl(port, break_state);
468 unlock_kernel(); 400 unlock_kernel();
401 }
469} 402}
470 403
471static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data) 404static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data)
@@ -519,19 +452,11 @@ static int serial_tiocmget (struct tty_struct *tty, struct file *file)
519{ 452{
520 struct usb_serial_port *port = tty->driver_data; 453 struct usb_serial_port *port = tty->driver_data;
521 454
522 if (!port)
523 return -ENODEV;
524
525 dbg("%s - port %d", __func__, port->number); 455 dbg("%s - port %d", __func__, port->number);
526 456
527 if (!port->open_count) { 457 WARN_ON(!port->open_count);
528 dbg("%s - port not open", __func__);
529 return -ENODEV;
530 }
531
532 if (port->serial->type->tiocmget) 458 if (port->serial->type->tiocmget)
533 return port->serial->type->tiocmget(port, file); 459 return port->serial->type->tiocmget(port, file);
534
535 return -EINVAL; 460 return -EINVAL;
536} 461}
537 462
@@ -540,19 +465,11 @@ static int serial_tiocmset (struct tty_struct *tty, struct file *file,
540{ 465{
541 struct usb_serial_port *port = tty->driver_data; 466 struct usb_serial_port *port = tty->driver_data;
542 467
543 if (!port)
544 return -ENODEV;
545
546 dbg("%s - port %d", __func__, port->number); 468 dbg("%s - port %d", __func__, port->number);
547 469
548 if (!port->open_count) { 470 WARN_ON(!port->open_count);
549 dbg("%s - port not open", __func__);
550 return -ENODEV;
551 }
552
553 if (port->serial->type->tiocmset) 471 if (port->serial->type->tiocmset)
554 return port->serial->type->tiocmset(port, file, set, clear); 472 return port->serial->type->tiocmset(port, file, set, clear);
555
556 return -EINVAL; 473 return -EINVAL;
557} 474}
558 475
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c
index e96bf8663ffc..f07e8a4c1f3d 100644
--- a/drivers/usb/serial/whiteheat.c
+++ b/drivers/usb/serial/whiteheat.c
@@ -673,15 +673,13 @@ static void whiteheat_close(struct usb_serial_port *port, struct file * filp)
673 } 673 }
674*/ 674*/
675 675
676 if (port->tty->driver->flush_buffer) 676 tty_driver_flush_buffer(port->tty);
677 port->tty->driver->flush_buffer(port->tty);
678 tty_ldisc_flush(port->tty); 677 tty_ldisc_flush(port->tty);
679 678
680 firm_report_tx_done(port); 679 firm_report_tx_done(port);
681 680
682 firm_close(port); 681 firm_close(port);
683 682
684printk(KERN_ERR"Before processing rx_urbs_submitted.\n");
685 /* shutdown our bulk reads and writes */ 683 /* shutdown our bulk reads and writes */
686 mutex_lock(&info->deathwarrant); 684 mutex_lock(&info->deathwarrant);
687 spin_lock_irq(&info->lock); 685 spin_lock_irq(&info->lock);
diff --git a/drivers/usb/storage/Kconfig b/drivers/usb/storage/Kconfig
index 0f6d234d699b..3d9249632ae1 100644
--- a/drivers/usb/storage/Kconfig
+++ b/drivers/usb/storage/Kconfig
@@ -123,7 +123,8 @@ config USB_STORAGE_ALAUDA
123 123
124config USB_STORAGE_ONETOUCH 124config USB_STORAGE_ONETOUCH
125 bool "Support OneTouch Button on Maxtor Hard Drives" 125 bool "Support OneTouch Button on Maxtor Hard Drives"
126 depends on USB_STORAGE && INPUT_EVDEV 126 depends on USB_STORAGE
127 depends on INPUT=y || INPUT=USB_STORAGE
127 help 128 help
128 Say Y here to include additional code to support the Maxtor OneTouch 129 Say Y here to include additional code to support the Maxtor OneTouch
129 USB hard drive's onetouch button. 130 USB hard drive's onetouch button.
diff --git a/drivers/usb/storage/cypress_atacb.c b/drivers/usb/storage/cypress_atacb.c
index d88824b3511c..898e67d30e56 100644
--- a/drivers/usb/storage/cypress_atacb.c
+++ b/drivers/usb/storage/cypress_atacb.c
@@ -46,7 +46,7 @@ void cypress_atacb_passthrough(struct scsi_cmnd *srb, struct us_data *us)
46 } 46 }
47 47
48 memcpy(save_cmnd, srb->cmnd, sizeof(save_cmnd)); 48 memcpy(save_cmnd, srb->cmnd, sizeof(save_cmnd));
49 memset(srb->cmnd, 0, sizeof(srb->cmnd)); 49 memset(srb->cmnd, 0, MAX_COMMAND_SIZE);
50 50
51 /* check if we support the command */ 51 /* check if we support the command */
52 if (save_cmnd[1] >> 5) /* MULTIPLE_COUNT */ 52 if (save_cmnd[1] >> 5) /* MULTIPLE_COUNT */
diff --git a/drivers/usb/storage/isd200.c b/drivers/usb/storage/isd200.c
index 971d13dd5e65..3addcd8f827b 100644
--- a/drivers/usb/storage/isd200.c
+++ b/drivers/usb/storage/isd200.c
@@ -292,6 +292,7 @@ struct isd200_info {
292 292
293 /* maximum number of LUNs supported */ 293 /* maximum number of LUNs supported */
294 unsigned char MaxLUNs; 294 unsigned char MaxLUNs;
295 unsigned char cmnd[BLK_MAX_CDB];
295 struct scsi_cmnd srb; 296 struct scsi_cmnd srb;
296 struct scatterlist sg; 297 struct scatterlist sg;
297}; 298};
@@ -450,6 +451,7 @@ static int isd200_action( struct us_data *us, int action,
450 451
451 memset(&ata, 0, sizeof(ata)); 452 memset(&ata, 0, sizeof(ata));
452 memset(&srb_dev, 0, sizeof(srb_dev)); 453 memset(&srb_dev, 0, sizeof(srb_dev));
454 srb->cmnd = info->cmnd;
453 srb->device = &srb_dev; 455 srb->device = &srb_dev;
454 ++srb->serial_number; 456 ++srb->serial_number;
455 457
diff --git a/drivers/usb/storage/libusual.c b/drivers/usb/storage/libusual.c
index a28d49122e7a..d617e8ae6b00 100644
--- a/drivers/usb/storage/libusual.c
+++ b/drivers/usb/storage/libusual.c
@@ -135,7 +135,7 @@ static int usu_probe(struct usb_interface *intf,
135 stat[type].fls |= USU_MOD_FL_THREAD; 135 stat[type].fls |= USU_MOD_FL_THREAD;
136 spin_unlock_irqrestore(&usu_lock, flags); 136 spin_unlock_irqrestore(&usu_lock, flags);
137 137
138 task = kthread_run(usu_probe_thread, (void*)type, "libusual_%d", type); 138 task = kthread_run(usu_probe_thread, (void*)type, "libusual_%ld", type);
139 if (IS_ERR(task)) { 139 if (IS_ERR(task)) {
140 rc = PTR_ERR(task); 140 rc = PTR_ERR(task);
141 printk(KERN_WARNING "libusual: " 141 printk(KERN_WARNING "libusual: "
diff --git a/drivers/usb/storage/onetouch.c b/drivers/usb/storage/onetouch.c
index dfd42fe9e5f0..98b89ea9e312 100644
--- a/drivers/usb/storage/onetouch.c
+++ b/drivers/usb/storage/onetouch.c
@@ -38,7 +38,7 @@
38#include "onetouch.h" 38#include "onetouch.h"
39#include "debug.h" 39#include "debug.h"
40 40
41void onetouch_release_input(void *onetouch_); 41static void onetouch_release_input(void *onetouch_);
42 42
43struct usb_onetouch { 43struct usb_onetouch {
44 char name[128]; 44 char name[128];
@@ -223,7 +223,7 @@ int onetouch_connect_input(struct us_data *ss)
223 return error; 223 return error;
224} 224}
225 225
226void onetouch_release_input(void *onetouch_) 226static void onetouch_release_input(void *onetouch_)
227{ 227{
228 struct usb_onetouch *onetouch = (struct usb_onetouch *) onetouch_; 228 struct usb_onetouch *onetouch = (struct usb_onetouch *) onetouch_;
229 229
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index 732bf52a775e..a0ed889230aa 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -44,7 +44,8 @@
44 * running with this patch. 44 * running with this patch.
45 * Send your submission to either Phil Dibowitz <phil@ipom.com> or 45 * Send your submission to either Phil Dibowitz <phil@ipom.com> or
46 * Alan Stern <stern@rowland.harvard.edu>, and don't forget to CC: the 46 * Alan Stern <stern@rowland.harvard.edu>, and don't forget to CC: the
47 * USB development list <linux-usb-devel@lists.sourceforge.net>. 47 * USB development list <linux-usb@vger.kernel.org> and the USB storage list
48 * <usb-storage@lists.one-eyed-alien.net>
48 */ 49 */
49 50
50/* patch submitted by Vivian Bregier <Vivian.Bregier@imag.fr> 51/* patch submitted by Vivian Bregier <Vivian.Bregier@imag.fr>
@@ -557,6 +558,13 @@ UNUSUAL_DEV( 0x04e6, 0x1010, 0x0000, 0x9999,
557 US_FL_SINGLE_LUN), 558 US_FL_SINGLE_LUN),
558#endif 559#endif
559 560
561/* Reported by Dmitry Khlystov <adminimus@gmail.com> */
562UNUSUAL_DEV( 0x04e8, 0x507c, 0x0220, 0x0220,
563 "Samsung",
564 "YP-U3",
565 US_SC_DEVICE, US_PR_DEVICE, NULL,
566 US_FL_MAX_SECTORS_64),
567
560/* Reported by Bob Sass <rls@vectordb.com> -- only rev 1.33 tested */ 568/* Reported by Bob Sass <rls@vectordb.com> -- only rev 1.33 tested */
561UNUSUAL_DEV( 0x050d, 0x0115, 0x0133, 0x0133, 569UNUSUAL_DEV( 0x050d, 0x0115, 0x0133, 0x0133,
562 "Belkin", 570 "Belkin",
@@ -1200,6 +1208,17 @@ UNUSUAL_DEV( 0x084d, 0x0011, 0x0110, 0x0110,
1200 US_SC_DEVICE, US_PR_DEVICE, NULL, 1208 US_SC_DEVICE, US_PR_DEVICE, NULL,
1201 US_FL_BULK32), 1209 US_FL_BULK32),
1202 1210
1211/* Andrew Lunn <andrew@lunn.ch>
1212 * PanDigital Digital Picture Frame. Does not like ALLOW_MEDIUM_REMOVAL
1213 * on LUN 4.
1214 * Note: Vend:Prod clash with "Ltd Maxell WS30 Slim Digital Camera"
1215*/
1216UNUSUAL_DEV( 0x0851, 0x1543, 0x0200, 0x0200,
1217 "PanDigital",
1218 "Photo Frame",
1219 US_SC_DEVICE, US_PR_DEVICE, NULL,
1220 US_FL_NOT_LOCKABLE),
1221
1203/* Submitted by Jan De Luyck <lkml@kcore.org> */ 1222/* Submitted by Jan De Luyck <lkml@kcore.org> */
1204UNUSUAL_DEV( 0x08bd, 0x1100, 0x0000, 0x0000, 1223UNUSUAL_DEV( 0x08bd, 0x1100, 0x0000, 0x0000,
1205 "CITIZEN", 1224 "CITIZEN",
@@ -1342,6 +1361,13 @@ UNUSUAL_DEV( 0x0d96, 0x410a, 0x0001, 0xffff,
1342 US_SC_DEVICE, US_PR_DEVICE, NULL, 1361 US_SC_DEVICE, US_PR_DEVICE, NULL,
1343 US_FL_FIX_INQUIRY), 1362 US_FL_FIX_INQUIRY),
1344 1363
1364/* Reported by Rohan Hart <rohan.hart17@gmail.com> */
1365UNUSUAL_DEV( 0x2770, 0x915d, 0x0010, 0x0010,
1366 "INTOVA",
1367 "Pixtreme",
1368 US_SC_DEVICE, US_PR_DEVICE, NULL,
1369 US_FL_FIX_CAPACITY ),
1370
1345/* 1371/*
1346 * Entry for Jenoptik JD 5200z3 1372 * Entry for Jenoptik JD 5200z3
1347 * 1373 *
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index a856effad3bd..e268aacb773a 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -539,7 +539,8 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id)
539 " has %s in unusual_devs.h (kernel" 539 " has %s in unusual_devs.h (kernel"
540 " %s)\n" 540 " %s)\n"
541 " Please send a copy of this message to " 541 " Please send a copy of this message to "
542 "<linux-usb-devel@lists.sourceforge.net>\n", 542 "<linux-usb@vger.kernel.org> and "
543 "<usb-storage@lists.one-eyed-alien.net>\n",
543 le16_to_cpu(ddesc->idVendor), 544 le16_to_cpu(ddesc->idVendor),
544 le16_to_cpu(ddesc->idProduct), 545 le16_to_cpu(ddesc->idProduct),
545 le16_to_cpu(ddesc->bcdDevice), 546 le16_to_cpu(ddesc->bcdDevice),
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index a576dc261732..bb1dadaa4a23 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -1774,6 +1774,11 @@ config FB_PXA
1774 1774
1775 If unsure, say N. 1775 If unsure, say N.
1776 1776
1777config FB_PXA_SMARTPANEL
1778 bool "PXA Smartpanel LCD support"
1779 default n
1780 depends on FB_PXA
1781
1777config FB_PXA_PARAMETERS 1782config FB_PXA_PARAMETERS
1778 bool "PXA LCD command line parameters" 1783 bool "PXA LCD command line parameters"
1779 default n 1784 default n
diff --git a/drivers/video/pxafb.c b/drivers/video/pxafb.c
index 757651954e6c..3ab6e3d973a1 100644
--- a/drivers/video/pxafb.c
+++ b/drivers/video/pxafb.c
@@ -39,6 +39,9 @@
39#include <linux/dma-mapping.h> 39#include <linux/dma-mapping.h>
40#include <linux/clk.h> 40#include <linux/clk.h>
41#include <linux/err.h> 41#include <linux/err.h>
42#include <linux/completion.h>
43#include <linux/kthread.h>
44#include <linux/freezer.h>
42 45
43#include <asm/hardware.h> 46#include <asm/hardware.h>
44#include <asm/io.h> 47#include <asm/io.h>
@@ -57,19 +60,31 @@
57#include "pxafb.h" 60#include "pxafb.h"
58 61
59/* Bits which should not be set in machine configuration structures */ 62/* Bits which should not be set in machine configuration structures */
60#define LCCR0_INVALID_CONFIG_MASK (LCCR0_OUM|LCCR0_BM|LCCR0_QDM|LCCR0_DIS|LCCR0_EFM|LCCR0_IUM|LCCR0_SFM|LCCR0_LDM|LCCR0_ENB) 63#define LCCR0_INVALID_CONFIG_MASK (LCCR0_OUM | LCCR0_BM | LCCR0_QDM |\
61#define LCCR3_INVALID_CONFIG_MASK (LCCR3_HSP|LCCR3_VSP|LCCR3_PCD|LCCR3_BPP) 64 LCCR0_DIS | LCCR0_EFM | LCCR0_IUM |\
65 LCCR0_SFM | LCCR0_LDM | LCCR0_ENB)
66
67#define LCCR3_INVALID_CONFIG_MASK (LCCR3_HSP | LCCR3_VSP |\
68 LCCR3_PCD | LCCR3_BPP)
62 69
63static void (*pxafb_backlight_power)(int); 70static void (*pxafb_backlight_power)(int);
64static void (*pxafb_lcd_power)(int, struct fb_var_screeninfo *); 71static void (*pxafb_lcd_power)(int, struct fb_var_screeninfo *);
65 72
66static int pxafb_activate_var(struct fb_var_screeninfo *var, struct pxafb_info *); 73static int pxafb_activate_var(struct fb_var_screeninfo *var,
74 struct pxafb_info *);
67static void set_ctrlr_state(struct pxafb_info *fbi, u_int state); 75static void set_ctrlr_state(struct pxafb_info *fbi, u_int state);
68 76
69#ifdef CONFIG_FB_PXA_PARAMETERS 77static inline unsigned long
70#define PXAFB_OPTIONS_SIZE 256 78lcd_readl(struct pxafb_info *fbi, unsigned int off)
71static char g_options[PXAFB_OPTIONS_SIZE] __devinitdata = ""; 79{
72#endif 80 return __raw_readl(fbi->mmio_base + off);
81}
82
83static inline void
84lcd_writel(struct pxafb_info *fbi, unsigned int off, unsigned long val)
85{
86 __raw_writel(val, fbi->mmio_base + off);
87}
73 88
74static inline void pxafb_schedule_work(struct pxafb_info *fbi, u_int state) 89static inline void pxafb_schedule_work(struct pxafb_info *fbi, u_int state)
75{ 90{
@@ -79,10 +94,12 @@ static inline void pxafb_schedule_work(struct pxafb_info *fbi, u_int state)
79 /* 94 /*
80 * We need to handle two requests being made at the same time. 95 * We need to handle two requests being made at the same time.
81 * There are two important cases: 96 * There are two important cases:
82 * 1. When we are changing VT (C_REENABLE) while unblanking (C_ENABLE) 97 * 1. When we are changing VT (C_REENABLE) while unblanking
83 * We must perform the unblanking, which will do our REENABLE for us. 98 * (C_ENABLE) We must perform the unblanking, which will
84 * 2. When we are blanking, but immediately unblank before we have 99 * do our REENABLE for us.
85 * blanked. We do the "REENABLE" thing here as well, just to be sure. 100 * 2. When we are blanking, but immediately unblank before
101 * we have blanked. We do the "REENABLE" thing here as
102 * well, just to be sure.
86 */ 103 */
87 if (fbi->task_state == C_ENABLE && state == C_REENABLE) 104 if (fbi->task_state == C_ENABLE && state == C_REENABLE)
88 state = (u_int) -1; 105 state = (u_int) -1;
@@ -129,13 +146,13 @@ pxafb_setpalettereg(u_int regno, u_int red, u_int green, u_int blue,
129 val = ((red << 8) & 0x00f80000); 146 val = ((red << 8) & 0x00f80000);
130 val |= ((green >> 0) & 0x0000fc00); 147 val |= ((green >> 0) & 0x0000fc00);
131 val |= ((blue >> 8) & 0x000000f8); 148 val |= ((blue >> 8) & 0x000000f8);
132 ((u32*)(fbi->palette_cpu))[regno] = val; 149 ((u32 *)(fbi->palette_cpu))[regno] = val;
133 break; 150 break;
134 case LCCR4_PAL_FOR_2: 151 case LCCR4_PAL_FOR_2:
135 val = ((red << 8) & 0x00fc0000); 152 val = ((red << 8) & 0x00fc0000);
136 val |= ((green >> 0) & 0x0000fc00); 153 val |= ((green >> 0) & 0x0000fc00);
137 val |= ((blue >> 8) & 0x000000fc); 154 val |= ((blue >> 8) & 0x000000fc);
138 ((u32*)(fbi->palette_cpu))[regno] = val; 155 ((u32 *)(fbi->palette_cpu))[regno] = val;
139 break; 156 break;
140 } 157 }
141 158
@@ -203,15 +220,15 @@ pxafb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
203 */ 220 */
204static int pxafb_bpp_to_lccr3(struct fb_var_screeninfo *var) 221static int pxafb_bpp_to_lccr3(struct fb_var_screeninfo *var)
205{ 222{
206 int ret = 0; 223 int ret = 0;
207 switch (var->bits_per_pixel) { 224 switch (var->bits_per_pixel) {
208 case 1: ret = LCCR3_1BPP; break; 225 case 1: ret = LCCR3_1BPP; break;
209 case 2: ret = LCCR3_2BPP; break; 226 case 2: ret = LCCR3_2BPP; break;
210 case 4: ret = LCCR3_4BPP; break; 227 case 4: ret = LCCR3_4BPP; break;
211 case 8: ret = LCCR3_8BPP; break; 228 case 8: ret = LCCR3_8BPP; break;
212 case 16: ret = LCCR3_16BPP; break; 229 case 16: ret = LCCR3_16BPP; break;
213 } 230 }
214 return ret; 231 return ret;
215} 232}
216 233
217#ifdef CONFIG_CPU_FREQ 234#ifdef CONFIG_CPU_FREQ
@@ -223,31 +240,32 @@ static int pxafb_bpp_to_lccr3(struct fb_var_screeninfo *var)
223 */ 240 */
224static unsigned int pxafb_display_dma_period(struct fb_var_screeninfo *var) 241static unsigned int pxafb_display_dma_period(struct fb_var_screeninfo *var)
225{ 242{
226 /* 243 /*
227 * Period = pixclock * bits_per_byte * bytes_per_transfer 244 * Period = pixclock * bits_per_byte * bytes_per_transfer
228 * / memory_bits_per_pixel; 245 * / memory_bits_per_pixel;
229 */ 246 */
230 return var->pixclock * 8 * 16 / var->bits_per_pixel; 247 return var->pixclock * 8 * 16 / var->bits_per_pixel;
231} 248}
232
233extern unsigned int get_clk_frequency_khz(int info);
234#endif 249#endif
235 250
236/* 251/*
237 * Select the smallest mode that allows the desired resolution to be 252 * Select the smallest mode that allows the desired resolution to be
238 * displayed. If desired parameters can be rounded up. 253 * displayed. If desired parameters can be rounded up.
239 */ 254 */
240static struct pxafb_mode_info *pxafb_getmode(struct pxafb_mach_info *mach, struct fb_var_screeninfo *var) 255static struct pxafb_mode_info *pxafb_getmode(struct pxafb_mach_info *mach,
256 struct fb_var_screeninfo *var)
241{ 257{
242 struct pxafb_mode_info *mode = NULL; 258 struct pxafb_mode_info *mode = NULL;
243 struct pxafb_mode_info *modelist = mach->modes; 259 struct pxafb_mode_info *modelist = mach->modes;
244 unsigned int best_x = 0xffffffff, best_y = 0xffffffff; 260 unsigned int best_x = 0xffffffff, best_y = 0xffffffff;
245 unsigned int i; 261 unsigned int i;
246 262
247 for (i = 0 ; i < mach->num_modes ; i++) { 263 for (i = 0; i < mach->num_modes; i++) {
248 if (modelist[i].xres >= var->xres && modelist[i].yres >= var->yres && 264 if (modelist[i].xres >= var->xres &&
249 modelist[i].xres < best_x && modelist[i].yres < best_y && 265 modelist[i].yres >= var->yres &&
250 modelist[i].bpp >= var->bits_per_pixel ) { 266 modelist[i].xres < best_x &&
267 modelist[i].yres < best_y &&
268 modelist[i].bpp >= var->bits_per_pixel) {
251 best_x = modelist[i].xres; 269 best_x = modelist[i].xres;
252 best_y = modelist[i].yres; 270 best_y = modelist[i].yres;
253 mode = &modelist[i]; 271 mode = &modelist[i];
@@ -257,7 +275,8 @@ static struct pxafb_mode_info *pxafb_getmode(struct pxafb_mach_info *mach, struc
257 return mode; 275 return mode;
258} 276}
259 277
260static void pxafb_setmode(struct fb_var_screeninfo *var, struct pxafb_mode_info *mode) 278static void pxafb_setmode(struct fb_var_screeninfo *var,
279 struct pxafb_mode_info *mode)
261{ 280{
262 var->xres = mode->xres; 281 var->xres = mode->xres;
263 var->yres = mode->yres; 282 var->yres = mode->yres;
@@ -315,19 +334,20 @@ static int pxafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
315 var->yres_virtual = 334 var->yres_virtual =
316 max(var->yres_virtual, var->yres); 335 max(var->yres_virtual, var->yres);
317 336
318 /* 337 /*
319 * Setup the RGB parameters for this display. 338 * Setup the RGB parameters for this display.
320 * 339 *
321 * The pixel packing format is described on page 7-11 of the 340 * The pixel packing format is described on page 7-11 of the
322 * PXA2XX Developer's Manual. 341 * PXA2XX Developer's Manual.
323 */ 342 */
324 if (var->bits_per_pixel == 16) { 343 if (var->bits_per_pixel == 16) {
325 var->red.offset = 11; var->red.length = 5; 344 var->red.offset = 11; var->red.length = 5;
326 var->green.offset = 5; var->green.length = 6; 345 var->green.offset = 5; var->green.length = 6;
327 var->blue.offset = 0; var->blue.length = 5; 346 var->blue.offset = 0; var->blue.length = 5;
328 var->transp.offset = var->transp.length = 0; 347 var->transp.offset = var->transp.length = 0;
329 } else { 348 } else {
330 var->red.offset = var->green.offset = var->blue.offset = var->transp.offset = 0; 349 var->red.offset = var->green.offset = 0;
350 var->blue.offset = var->transp.offset = 0;
331 var->red.length = 8; 351 var->red.length = 8;
332 var->green.length = 8; 352 var->green.length = 8;
333 var->blue.length = 8; 353 var->blue.length = 8;
@@ -345,8 +365,7 @@ static int pxafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
345 365
346static inline void pxafb_set_truecolor(u_int is_true_color) 366static inline void pxafb_set_truecolor(u_int is_true_color)
347{ 367{
348 pr_debug("pxafb: true_color = %d\n", is_true_color); 368 /* do your machine-specific setup if needed */
349 // do your machine-specific setup if needed
350} 369}
351 370
352/* 371/*
@@ -357,9 +376,6 @@ static int pxafb_set_par(struct fb_info *info)
357{ 376{
358 struct pxafb_info *fbi = (struct pxafb_info *)info; 377 struct pxafb_info *fbi = (struct pxafb_info *)info;
359 struct fb_var_screeninfo *var = &info->var; 378 struct fb_var_screeninfo *var = &info->var;
360 unsigned long palette_mem_size;
361
362 pr_debug("pxafb: set_par\n");
363 379
364 if (var->bits_per_pixel == 16) 380 if (var->bits_per_pixel == 16)
365 fbi->fb.fix.visual = FB_VISUAL_TRUECOLOR; 381 fbi->fb.fix.visual = FB_VISUAL_TRUECOLOR;
@@ -379,17 +395,10 @@ static int pxafb_set_par(struct fb_info *info)
379 if (var->bits_per_pixel == 16) 395 if (var->bits_per_pixel == 16)
380 fbi->palette_size = 0; 396 fbi->palette_size = 0;
381 else 397 else
382 fbi->palette_size = var->bits_per_pixel == 1 ? 4 : 1 << var->bits_per_pixel; 398 fbi->palette_size = var->bits_per_pixel == 1 ?
383 399 4 : 1 << var->bits_per_pixel;
384 if ((fbi->lccr4 & LCCR4_PAL_FOR_MASK) == LCCR4_PAL_FOR_0)
385 palette_mem_size = fbi->palette_size * sizeof(u16);
386 else
387 palette_mem_size = fbi->palette_size * sizeof(u32);
388
389 pr_debug("pxafb: palette_mem_size = 0x%08lx\n", palette_mem_size);
390 400
391 fbi->palette_cpu = (u16 *)(fbi->map_cpu + PAGE_SIZE - palette_mem_size); 401 fbi->palette_cpu = (u16 *)&fbi->dma_buff->palette[0];
392 fbi->palette_dma = fbi->map_dma + PAGE_SIZE - palette_mem_size;
393 402
394 /* 403 /*
395 * Set (any) board control register to handle new color depth 404 * Set (any) board control register to handle new color depth
@@ -407,36 +416,6 @@ static int pxafb_set_par(struct fb_info *info)
407} 416}
408 417
409/* 418/*
410 * Formal definition of the VESA spec:
411 * On
412 * This refers to the state of the display when it is in full operation
413 * Stand-By
414 * This defines an optional operating state of minimal power reduction with
415 * the shortest recovery time
416 * Suspend
417 * This refers to a level of power management in which substantial power
418 * reduction is achieved by the display. The display can have a longer
419 * recovery time from this state than from the Stand-by state
420 * Off
421 * This indicates that the display is consuming the lowest level of power
422 * and is non-operational. Recovery from this state may optionally require
423 * the user to manually power on the monitor
424 *
425 * Now, the fbdev driver adds an additional state, (blank), where they
426 * turn off the video (maybe by colormap tricks), but don't mess with the
427 * video itself: think of it semantically between on and Stand-By.
428 *
429 * So here's what we should do in our fbdev blank routine:
430 *
431 * VESA_NO_BLANKING (mode 0) Video on, front/back light on
432 * VESA_VSYNC_SUSPEND (mode 1) Video on, front/back light off
433 * VESA_HSYNC_SUSPEND (mode 2) Video on, front/back light off
434 * VESA_POWERDOWN (mode 3) Video off, front/back light off
435 *
436 * This will match the matrox implementation.
437 */
438
439/*
440 * pxafb_blank(): 419 * pxafb_blank():
441 * Blank the display by setting all palette values to zero. Note, the 420 * Blank the display by setting all palette values to zero. Note, the
442 * 16 bpp mode does not really use the palette, so this will not 421 * 16 bpp mode does not really use the palette, so this will not
@@ -447,8 +426,6 @@ static int pxafb_blank(int blank, struct fb_info *info)
447 struct pxafb_info *fbi = (struct pxafb_info *)info; 426 struct pxafb_info *fbi = (struct pxafb_info *)info;
448 int i; 427 int i;
449 428
450 pr_debug("pxafb: blank=%d\n", blank);
451
452 switch (blank) { 429 switch (blank) {
453 case FB_BLANK_POWERDOWN: 430 case FB_BLANK_POWERDOWN:
454 case FB_BLANK_VSYNC_SUSPEND: 431 case FB_BLANK_VSYNC_SUSPEND:
@@ -460,11 +437,11 @@ static int pxafb_blank(int blank, struct fb_info *info)
460 pxafb_setpalettereg(i, 0, 0, 0, 0, info); 437 pxafb_setpalettereg(i, 0, 0, 0, 0, info);
461 438
462 pxafb_schedule_work(fbi, C_DISABLE); 439 pxafb_schedule_work(fbi, C_DISABLE);
463 //TODO if (pxafb_blank_helper) pxafb_blank_helper(blank); 440 /* TODO if (pxafb_blank_helper) pxafb_blank_helper(blank); */
464 break; 441 break;
465 442
466 case FB_BLANK_UNBLANK: 443 case FB_BLANK_UNBLANK:
467 //TODO if (pxafb_blank_helper) pxafb_blank_helper(blank); 444 /* TODO if (pxafb_blank_helper) pxafb_blank_helper(blank); */
468 if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR || 445 if (fbi->fb.fix.visual == FB_VISUAL_PSEUDOCOLOR ||
469 fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR) 446 fbi->fb.fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR)
470 fb_set_cmap(&fbi->fb.cmap, info); 447 fb_set_cmap(&fbi->fb.cmap, info);
@@ -480,7 +457,7 @@ static int pxafb_mmap(struct fb_info *info,
480 unsigned long off = vma->vm_pgoff << PAGE_SHIFT; 457 unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
481 458
482 if (off < info->fix.smem_len) { 459 if (off < info->fix.smem_len) {
483 vma->vm_pgoff += 1; 460 vma->vm_pgoff += fbi->video_offset / PAGE_SIZE;
484 return dma_mmap_writecombine(fbi->dev, vma, fbi->map_cpu, 461 return dma_mmap_writecombine(fbi->dev, vma, fbi->map_cpu,
485 fbi->map_dma, fbi->map_size); 462 fbi->map_dma, fbi->map_size);
486 } 463 }
@@ -529,7 +506,8 @@ static struct fb_ops pxafb_ops = {
529 * 506 *
530 * Factoring the 10^4 and 10^-12 out gives 10^-8 == 1 / 100000000 as used below. 507 * Factoring the 10^4 and 10^-12 out gives 10^-8 == 1 / 100000000 as used below.
531 */ 508 */
532static inline unsigned int get_pcd(struct pxafb_info *fbi, unsigned int pixclock) 509static inline unsigned int get_pcd(struct pxafb_info *fbi,
510 unsigned int pixclock)
533{ 511{
534 unsigned long long pcd; 512 unsigned long long pcd;
535 513
@@ -555,7 +533,7 @@ static inline void set_hsync_time(struct pxafb_info *fbi, unsigned int pcd)
555 unsigned long htime; 533 unsigned long htime;
556 534
557 if ((pcd == 0) || (fbi->fb.var.hsync_len == 0)) { 535 if ((pcd == 0) || (fbi->fb.var.hsync_len == 0)) {
558 fbi->hsync_time=0; 536 fbi->hsync_time = 0;
559 return; 537 return;
560 } 538 }
561 539
@@ -576,71 +554,231 @@ unsigned long pxafb_get_hsync_time(struct device *dev)
576} 554}
577EXPORT_SYMBOL(pxafb_get_hsync_time); 555EXPORT_SYMBOL(pxafb_get_hsync_time);
578 556
579/* 557static int setup_frame_dma(struct pxafb_info *fbi, int dma, int pal,
580 * pxafb_activate_var(): 558 unsigned int offset, size_t size)
581 * Configures LCD Controller based on entries in var parameter. Settings are
582 * only written to the controller if changes were made.
583 */
584static int pxafb_activate_var(struct fb_var_screeninfo *var, struct pxafb_info *fbi)
585{ 559{
586 struct pxafb_lcd_reg new_regs; 560 struct pxafb_dma_descriptor *dma_desc, *pal_desc;
587 u_long flags; 561 unsigned int dma_desc_off, pal_desc_off;
588 u_int lines_per_panel, pcd = get_pcd(fbi, var->pixclock);
589 562
590 pr_debug("pxafb: Configuring PXA LCD\n"); 563 if (dma < 0 || dma >= DMA_MAX)
564 return -EINVAL;
591 565
592 pr_debug("var: xres=%d hslen=%d lm=%d rm=%d\n", 566 dma_desc = &fbi->dma_buff->dma_desc[dma];
593 var->xres, var->hsync_len, 567 dma_desc_off = offsetof(struct pxafb_dma_buff, dma_desc[dma]);
594 var->left_margin, var->right_margin);
595 pr_debug("var: yres=%d vslen=%d um=%d bm=%d\n",
596 var->yres, var->vsync_len,
597 var->upper_margin, var->lower_margin);
598 pr_debug("var: pixclock=%d pcd=%d\n", var->pixclock, pcd);
599 568
600#if DEBUG_VAR 569 dma_desc->fsadr = fbi->screen_dma + offset;
601 if (var->xres < 16 || var->xres > 1024) 570 dma_desc->fidr = 0;
602 printk(KERN_ERR "%s: invalid xres %d\n", 571 dma_desc->ldcmd = size;
603 fbi->fb.fix.id, var->xres); 572
604 switch(var->bits_per_pixel) { 573 if (pal < 0 || pal >= PAL_MAX) {
605 case 1: 574 dma_desc->fdadr = fbi->dma_buff_phys + dma_desc_off;
606 case 2: 575 fbi->fdadr[dma] = fbi->dma_buff_phys + dma_desc_off;
607 case 4: 576 } else {
608 case 8: 577 pal_desc = &fbi->dma_buff->pal_desc[dma];
609 case 16: 578 pal_desc_off = offsetof(struct pxafb_dma_buff, dma_desc[pal]);
610 break; 579
611 default: 580 pal_desc->fsadr = fbi->dma_buff_phys + pal * PALETTE_SIZE;
612 printk(KERN_ERR "%s: invalid bit depth %d\n", 581 pal_desc->fidr = 0;
613 fbi->fb.fix.id, var->bits_per_pixel); 582
614 break; 583 if ((fbi->lccr4 & LCCR4_PAL_FOR_MASK) == LCCR4_PAL_FOR_0)
584 pal_desc->ldcmd = fbi->palette_size * sizeof(u16);
585 else
586 pal_desc->ldcmd = fbi->palette_size * sizeof(u32);
587
588 pal_desc->ldcmd |= LDCMD_PAL;
589
590 /* flip back and forth between palette and frame buffer */
591 pal_desc->fdadr = fbi->dma_buff_phys + dma_desc_off;
592 dma_desc->fdadr = fbi->dma_buff_phys + pal_desc_off;
593 fbi->fdadr[dma] = fbi->dma_buff_phys + dma_desc_off;
615 } 594 }
616 if (var->hsync_len < 1 || var->hsync_len > 64)
617 printk(KERN_ERR "%s: invalid hsync_len %d\n",
618 fbi->fb.fix.id, var->hsync_len);
619 if (var->left_margin < 1 || var->left_margin > 255)
620 printk(KERN_ERR "%s: invalid left_margin %d\n",
621 fbi->fb.fix.id, var->left_margin);
622 if (var->right_margin < 1 || var->right_margin > 255)
623 printk(KERN_ERR "%s: invalid right_margin %d\n",
624 fbi->fb.fix.id, var->right_margin);
625 if (var->yres < 1 || var->yres > 1024)
626 printk(KERN_ERR "%s: invalid yres %d\n",
627 fbi->fb.fix.id, var->yres);
628 if (var->vsync_len < 1 || var->vsync_len > 64)
629 printk(KERN_ERR "%s: invalid vsync_len %d\n",
630 fbi->fb.fix.id, var->vsync_len);
631 if (var->upper_margin < 0 || var->upper_margin > 255)
632 printk(KERN_ERR "%s: invalid upper_margin %d\n",
633 fbi->fb.fix.id, var->upper_margin);
634 if (var->lower_margin < 0 || var->lower_margin > 255)
635 printk(KERN_ERR "%s: invalid lower_margin %d\n",
636 fbi->fb.fix.id, var->lower_margin);
637#endif
638 595
639 new_regs.lccr0 = fbi->lccr0 | 596 return 0;
640 (LCCR0_LDM | LCCR0_SFM | LCCR0_IUM | LCCR0_EFM | 597}
641 LCCR0_QDM | LCCR0_BM | LCCR0_OUM); 598
599#ifdef CONFIG_FB_PXA_SMARTPANEL
600static int setup_smart_dma(struct pxafb_info *fbi)
601{
602 struct pxafb_dma_descriptor *dma_desc;
603 unsigned long dma_desc_off, cmd_buff_off;
604
605 dma_desc = &fbi->dma_buff->dma_desc[DMA_CMD];
606 dma_desc_off = offsetof(struct pxafb_dma_buff, dma_desc[DMA_CMD]);
607 cmd_buff_off = offsetof(struct pxafb_dma_buff, cmd_buff);
608
609 dma_desc->fdadr = fbi->dma_buff_phys + dma_desc_off;
610 dma_desc->fsadr = fbi->dma_buff_phys + cmd_buff_off;
611 dma_desc->fidr = 0;
612 dma_desc->ldcmd = fbi->n_smart_cmds * sizeof(uint16_t);
613
614 fbi->fdadr[DMA_CMD] = dma_desc->fdadr;
615 return 0;
616}
617
618int pxafb_smart_flush(struct fb_info *info)
619{
620 struct pxafb_info *fbi = container_of(info, struct pxafb_info, fb);
621 uint32_t prsr;
622 int ret = 0;
623
624 /* disable controller until all registers are set up */
625 lcd_writel(fbi, LCCR0, fbi->reg_lccr0 & ~LCCR0_ENB);
626
627 /* 1. make it an even number of commands to align on 32-bit boundary
628 * 2. add the interrupt command to the end of the chain so we can
629 * keep track of the end of the transfer
630 */
631
632 while (fbi->n_smart_cmds & 1)
633 fbi->smart_cmds[fbi->n_smart_cmds++] = SMART_CMD_NOOP;
634
635 fbi->smart_cmds[fbi->n_smart_cmds++] = SMART_CMD_INTERRUPT;
636 fbi->smart_cmds[fbi->n_smart_cmds++] = SMART_CMD_WAIT_FOR_VSYNC;
637 setup_smart_dma(fbi);
638
639 /* continue to execute next command */
640 prsr = lcd_readl(fbi, PRSR) | PRSR_ST_OK | PRSR_CON_NT;
641 lcd_writel(fbi, PRSR, prsr);
642
643 /* stop the processor in case it executed "wait for sync" cmd */
644 lcd_writel(fbi, CMDCR, 0x0001);
645
646 /* don't send interrupts for fifo underruns on channel 6 */
647 lcd_writel(fbi, LCCR5, LCCR5_IUM(6));
648
649 lcd_writel(fbi, LCCR1, fbi->reg_lccr1);
650 lcd_writel(fbi, LCCR2, fbi->reg_lccr2);
651 lcd_writel(fbi, LCCR3, fbi->reg_lccr3);
652 lcd_writel(fbi, FDADR0, fbi->fdadr[0]);
653 lcd_writel(fbi, FDADR6, fbi->fdadr[6]);
654
655 /* begin sending */
656 lcd_writel(fbi, LCCR0, fbi->reg_lccr0 | LCCR0_ENB);
657
658 if (wait_for_completion_timeout(&fbi->command_done, HZ/2) == 0) {
659 pr_warning("%s: timeout waiting for command done\n",
660 __func__);
661 ret = -ETIMEDOUT;
662 }
663
664 /* quick disable */
665 prsr = lcd_readl(fbi, PRSR) & ~(PRSR_ST_OK | PRSR_CON_NT);
666 lcd_writel(fbi, PRSR, prsr);
667 lcd_writel(fbi, LCCR0, fbi->reg_lccr0 & ~LCCR0_ENB);
668 lcd_writel(fbi, FDADR6, 0);
669 fbi->n_smart_cmds = 0;
670 return ret;
671}
672
673int pxafb_smart_queue(struct fb_info *info, uint16_t *cmds, int n_cmds)
674{
675 int i;
676 struct pxafb_info *fbi = container_of(info, struct pxafb_info, fb);
677
678 /* leave 2 commands for INTERRUPT and WAIT_FOR_SYNC */
679 for (i = 0; i < n_cmds; i++) {
680 if (fbi->n_smart_cmds == CMD_BUFF_SIZE - 8)
681 pxafb_smart_flush(info);
682
683 fbi->smart_cmds[fbi->n_smart_cmds++] = *cmds++;
684 }
685
686 return 0;
687}
688
689static unsigned int __smart_timing(unsigned time_ns, unsigned long lcd_clk)
690{
691 unsigned int t = (time_ns * (lcd_clk / 1000000) / 1000);
692 return (t == 0) ? 1 : t;
693}
694
695static void setup_smart_timing(struct pxafb_info *fbi,
696 struct fb_var_screeninfo *var)
697{
698 struct pxafb_mach_info *inf = fbi->dev->platform_data;
699 struct pxafb_mode_info *mode = &inf->modes[0];
700 unsigned long lclk = clk_get_rate(fbi->clk);
701 unsigned t1, t2, t3, t4;
702
703 t1 = max(mode->a0csrd_set_hld, mode->a0cswr_set_hld);
704 t2 = max(mode->rd_pulse_width, mode->wr_pulse_width);
705 t3 = mode->op_hold_time;
706 t4 = mode->cmd_inh_time;
707
708 fbi->reg_lccr1 =
709 LCCR1_DisWdth(var->xres) |
710 LCCR1_BegLnDel(__smart_timing(t1, lclk)) |
711 LCCR1_EndLnDel(__smart_timing(t2, lclk)) |
712 LCCR1_HorSnchWdth(__smart_timing(t3, lclk));
713
714 fbi->reg_lccr2 = LCCR2_DisHght(var->yres);
715 fbi->reg_lccr3 = LCCR3_PixClkDiv(__smart_timing(t4, lclk));
716
717 /* FIXME: make this configurable */
718 fbi->reg_cmdcr = 1;
719}
720
721static int pxafb_smart_thread(void *arg)
722{
723 struct pxafb_info *fbi = arg;
724 struct pxafb_mach_info *inf = fbi->dev->platform_data;
725
726 if (!fbi || !inf->smart_update) {
727 pr_err("%s: not properly initialized, thread terminated\n",
728 __func__);
729 return -EINVAL;
730 }
642 731
643 new_regs.lccr1 = 732 pr_debug("%s(): task starting\n", __func__);
733
734 set_freezable();
735 while (!kthread_should_stop()) {
736
737 if (try_to_freeze())
738 continue;
739
740 if (fbi->state == C_ENABLE) {
741 inf->smart_update(&fbi->fb);
742 complete(&fbi->refresh_done);
743 }
744
745 set_current_state(TASK_INTERRUPTIBLE);
746 schedule_timeout(30 * HZ / 1000);
747 }
748
749 pr_debug("%s(): task ending\n", __func__);
750 return 0;
751}
752
753static int pxafb_smart_init(struct pxafb_info *fbi)
754{
755 fbi->smart_thread = kthread_run(pxafb_smart_thread, fbi,
756 "lcd_refresh");
757 if (IS_ERR(fbi->smart_thread)) {
758 printk(KERN_ERR "%s: unable to create kernel thread\n",
759 __func__);
760 return PTR_ERR(fbi->smart_thread);
761 }
762 return 0;
763}
764#else
765int pxafb_smart_queue(struct fb_info *info, uint16_t *cmds, int n_cmds)
766{
767 return 0;
768}
769
770int pxafb_smart_flush(struct fb_info *info)
771{
772 return 0;
773}
774#endif /* CONFIG_FB_SMART_PANEL */
775
776static void setup_parallel_timing(struct pxafb_info *fbi,
777 struct fb_var_screeninfo *var)
778{
779 unsigned int lines_per_panel, pcd = get_pcd(fbi, var->pixclock);
780
781 fbi->reg_lccr1 =
644 LCCR1_DisWdth(var->xres) + 782 LCCR1_DisWdth(var->xres) +
645 LCCR1_HorSnchWdth(var->hsync_len) + 783 LCCR1_HorSnchWdth(var->hsync_len) +
646 LCCR1_BegLnDel(var->left_margin) + 784 LCCR1_BegLnDel(var->left_margin) +
@@ -654,110 +792,118 @@ static int pxafb_activate_var(struct fb_var_screeninfo *var, struct pxafb_info *
654 if ((fbi->lccr0 & LCCR0_SDS) == LCCR0_Dual) 792 if ((fbi->lccr0 & LCCR0_SDS) == LCCR0_Dual)
655 lines_per_panel /= 2; 793 lines_per_panel /= 2;
656 794
657 new_regs.lccr2 = 795 fbi->reg_lccr2 =
658 LCCR2_DisHght(lines_per_panel) + 796 LCCR2_DisHght(lines_per_panel) +
659 LCCR2_VrtSnchWdth(var->vsync_len) + 797 LCCR2_VrtSnchWdth(var->vsync_len) +
660 LCCR2_BegFrmDel(var->upper_margin) + 798 LCCR2_BegFrmDel(var->upper_margin) +
661 LCCR2_EndFrmDel(var->lower_margin); 799 LCCR2_EndFrmDel(var->lower_margin);
662 800
663 new_regs.lccr3 = fbi->lccr3 | 801 fbi->reg_lccr3 = fbi->lccr3 |
664 pxafb_bpp_to_lccr3(var) | 802 (var->sync & FB_SYNC_HOR_HIGH_ACT ?
665 (var->sync & FB_SYNC_HOR_HIGH_ACT ? LCCR3_HorSnchH : LCCR3_HorSnchL) | 803 LCCR3_HorSnchH : LCCR3_HorSnchL) |
666 (var->sync & FB_SYNC_VERT_HIGH_ACT ? LCCR3_VrtSnchH : LCCR3_VrtSnchL); 804 (var->sync & FB_SYNC_VERT_HIGH_ACT ?
805 LCCR3_VrtSnchH : LCCR3_VrtSnchL);
806
807 if (pcd) {
808 fbi->reg_lccr3 |= LCCR3_PixClkDiv(pcd);
809 set_hsync_time(fbi, pcd);
810 }
811}
667 812
668 if (pcd) 813/*
669 new_regs.lccr3 |= LCCR3_PixClkDiv(pcd); 814 * pxafb_activate_var():
815 * Configures LCD Controller based on entries in var parameter.
816 * Settings are only written to the controller if changes were made.
817 */
818static int pxafb_activate_var(struct fb_var_screeninfo *var,
819 struct pxafb_info *fbi)
820{
821 u_long flags;
822 size_t nbytes;
670 823
671 pr_debug("nlccr0 = 0x%08x\n", new_regs.lccr0); 824#if DEBUG_VAR
672 pr_debug("nlccr1 = 0x%08x\n", new_regs.lccr1); 825 if (!(fbi->lccr0 & LCCR0_LCDT)) {
673 pr_debug("nlccr2 = 0x%08x\n", new_regs.lccr2); 826 if (var->xres < 16 || var->xres > 1024)
674 pr_debug("nlccr3 = 0x%08x\n", new_regs.lccr3); 827 printk(KERN_ERR "%s: invalid xres %d\n",
828 fbi->fb.fix.id, var->xres);
829 switch (var->bits_per_pixel) {
830 case 1:
831 case 2:
832 case 4:
833 case 8:
834 case 16:
835 break;
836 default:
837 printk(KERN_ERR "%s: invalid bit depth %d\n",
838 fbi->fb.fix.id, var->bits_per_pixel);
839 break;
840 }
675 841
842 if (var->hsync_len < 1 || var->hsync_len > 64)
843 printk(KERN_ERR "%s: invalid hsync_len %d\n",
844 fbi->fb.fix.id, var->hsync_len);
845 if (var->left_margin < 1 || var->left_margin > 255)
846 printk(KERN_ERR "%s: invalid left_margin %d\n",
847 fbi->fb.fix.id, var->left_margin);
848 if (var->right_margin < 1 || var->right_margin > 255)
849 printk(KERN_ERR "%s: invalid right_margin %d\n",
850 fbi->fb.fix.id, var->right_margin);
851 if (var->yres < 1 || var->yres > 1024)
852 printk(KERN_ERR "%s: invalid yres %d\n",
853 fbi->fb.fix.id, var->yres);
854 if (var->vsync_len < 1 || var->vsync_len > 64)
855 printk(KERN_ERR "%s: invalid vsync_len %d\n",
856 fbi->fb.fix.id, var->vsync_len);
857 if (var->upper_margin < 0 || var->upper_margin > 255)
858 printk(KERN_ERR "%s: invalid upper_margin %d\n",
859 fbi->fb.fix.id, var->upper_margin);
860 if (var->lower_margin < 0 || var->lower_margin > 255)
861 printk(KERN_ERR "%s: invalid lower_margin %d\n",
862 fbi->fb.fix.id, var->lower_margin);
863 }
864#endif
676 /* Update shadow copy atomically */ 865 /* Update shadow copy atomically */
677 local_irq_save(flags); 866 local_irq_save(flags);
678 867
679 /* setup dma descriptors */ 868#ifdef CONFIG_FB_PXA_SMARTPANEL
680 fbi->dmadesc_fblow_cpu = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette_cpu - 3*16); 869 if (fbi->lccr0 & LCCR0_LCDT)
681 fbi->dmadesc_fbhigh_cpu = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette_cpu - 2*16); 870 setup_smart_timing(fbi, var);
682 fbi->dmadesc_palette_cpu = (struct pxafb_dma_descriptor *)((unsigned int)fbi->palette_cpu - 1*16); 871 else
683 872#endif
684 fbi->dmadesc_fblow_dma = fbi->palette_dma - 3*16; 873 setup_parallel_timing(fbi, var);
685 fbi->dmadesc_fbhigh_dma = fbi->palette_dma - 2*16;
686 fbi->dmadesc_palette_dma = fbi->palette_dma - 1*16;
687
688#define BYTES_PER_PANEL (lines_per_panel * fbi->fb.fix.line_length)
689
690 /* populate descriptors */
691 fbi->dmadesc_fblow_cpu->fdadr = fbi->dmadesc_fblow_dma;
692 fbi->dmadesc_fblow_cpu->fsadr = fbi->screen_dma + BYTES_PER_PANEL;
693 fbi->dmadesc_fblow_cpu->fidr = 0;
694 fbi->dmadesc_fblow_cpu->ldcmd = BYTES_PER_PANEL;
695 874
696 fbi->fdadr1 = fbi->dmadesc_fblow_dma; /* only used in dual-panel mode */ 875 fbi->reg_lccr0 = fbi->lccr0 |
876 (LCCR0_LDM | LCCR0_SFM | LCCR0_IUM | LCCR0_EFM |
877 LCCR0_QDM | LCCR0_BM | LCCR0_OUM);
697 878
698 fbi->dmadesc_fbhigh_cpu->fsadr = fbi->screen_dma; 879 fbi->reg_lccr3 |= pxafb_bpp_to_lccr3(var);
699 fbi->dmadesc_fbhigh_cpu->fidr = 0;
700 fbi->dmadesc_fbhigh_cpu->ldcmd = BYTES_PER_PANEL;
701 880
702 fbi->dmadesc_palette_cpu->fsadr = fbi->palette_dma; 881 nbytes = var->yres * fbi->fb.fix.line_length;
703 fbi->dmadesc_palette_cpu->fidr = 0;
704 if ((fbi->lccr4 & LCCR4_PAL_FOR_MASK) == LCCR4_PAL_FOR_0)
705 fbi->dmadesc_palette_cpu->ldcmd = fbi->palette_size *
706 sizeof(u16);
707 else
708 fbi->dmadesc_palette_cpu->ldcmd = fbi->palette_size *
709 sizeof(u32);
710 fbi->dmadesc_palette_cpu->ldcmd |= LDCMD_PAL;
711 882
712 if (var->bits_per_pixel == 16) { 883 if ((fbi->lccr0 & LCCR0_SDS) == LCCR0_Dual) {
713 /* palette shouldn't be loaded in true-color mode */ 884 nbytes = nbytes / 2;
714 fbi->dmadesc_fbhigh_cpu->fdadr = fbi->dmadesc_fbhigh_dma; 885 setup_frame_dma(fbi, DMA_LOWER, PAL_NONE, nbytes, nbytes);
715 fbi->fdadr0 = fbi->dmadesc_fbhigh_dma; /* no pal just fbhigh */
716 /* init it to something, even though we won't be using it */
717 fbi->dmadesc_palette_cpu->fdadr = fbi->dmadesc_palette_dma;
718 } else {
719 fbi->dmadesc_palette_cpu->fdadr = fbi->dmadesc_fbhigh_dma;
720 fbi->dmadesc_fbhigh_cpu->fdadr = fbi->dmadesc_palette_dma;
721 fbi->fdadr0 = fbi->dmadesc_palette_dma; /* flips back and forth between pal and fbhigh */
722 } 886 }
723 887
724#if 0 888 if ((var->bits_per_pixel >= 16) || (fbi->lccr0 & LCCR0_LCDT))
725 pr_debug("fbi->dmadesc_fblow_cpu = 0x%p\n", fbi->dmadesc_fblow_cpu); 889 setup_frame_dma(fbi, DMA_BASE, PAL_NONE, 0, nbytes);
726 pr_debug("fbi->dmadesc_fbhigh_cpu = 0x%p\n", fbi->dmadesc_fbhigh_cpu); 890 else
727 pr_debug("fbi->dmadesc_palette_cpu = 0x%p\n", fbi->dmadesc_palette_cpu); 891 setup_frame_dma(fbi, DMA_BASE, PAL_BASE, 0, nbytes);
728 pr_debug("fbi->dmadesc_fblow_dma = 0x%x\n", fbi->dmadesc_fblow_dma);
729 pr_debug("fbi->dmadesc_fbhigh_dma = 0x%x\n", fbi->dmadesc_fbhigh_dma);
730 pr_debug("fbi->dmadesc_palette_dma = 0x%x\n", fbi->dmadesc_palette_dma);
731
732 pr_debug("fbi->dmadesc_fblow_cpu->fdadr = 0x%x\n", fbi->dmadesc_fblow_cpu->fdadr);
733 pr_debug("fbi->dmadesc_fbhigh_cpu->fdadr = 0x%x\n", fbi->dmadesc_fbhigh_cpu->fdadr);
734 pr_debug("fbi->dmadesc_palette_cpu->fdadr = 0x%x\n", fbi->dmadesc_palette_cpu->fdadr);
735
736 pr_debug("fbi->dmadesc_fblow_cpu->fsadr = 0x%x\n", fbi->dmadesc_fblow_cpu->fsadr);
737 pr_debug("fbi->dmadesc_fbhigh_cpu->fsadr = 0x%x\n", fbi->dmadesc_fbhigh_cpu->fsadr);
738 pr_debug("fbi->dmadesc_palette_cpu->fsadr = 0x%x\n", fbi->dmadesc_palette_cpu->fsadr);
739
740 pr_debug("fbi->dmadesc_fblow_cpu->ldcmd = 0x%x\n", fbi->dmadesc_fblow_cpu->ldcmd);
741 pr_debug("fbi->dmadesc_fbhigh_cpu->ldcmd = 0x%x\n", fbi->dmadesc_fbhigh_cpu->ldcmd);
742 pr_debug("fbi->dmadesc_palette_cpu->ldcmd = 0x%x\n", fbi->dmadesc_palette_cpu->ldcmd);
743#endif
744 892
745 fbi->reg_lccr0 = new_regs.lccr0; 893 fbi->reg_lccr4 = lcd_readl(fbi, LCCR4) & ~LCCR4_PAL_FOR_MASK;
746 fbi->reg_lccr1 = new_regs.lccr1;
747 fbi->reg_lccr2 = new_regs.lccr2;
748 fbi->reg_lccr3 = new_regs.lccr3;
749 fbi->reg_lccr4 = LCCR4 & (~LCCR4_PAL_FOR_MASK);
750 fbi->reg_lccr4 |= (fbi->lccr4 & LCCR4_PAL_FOR_MASK); 894 fbi->reg_lccr4 |= (fbi->lccr4 & LCCR4_PAL_FOR_MASK);
751 set_hsync_time(fbi, pcd);
752 local_irq_restore(flags); 895 local_irq_restore(flags);
753 896
754 /* 897 /*
755 * Only update the registers if the controller is enabled 898 * Only update the registers if the controller is enabled
756 * and something has changed. 899 * and something has changed.
757 */ 900 */
758 if ((LCCR0 != fbi->reg_lccr0) || (LCCR1 != fbi->reg_lccr1) || 901 if ((lcd_readl(fbi, LCCR0) != fbi->reg_lccr0) ||
759 (LCCR2 != fbi->reg_lccr2) || (LCCR3 != fbi->reg_lccr3) || 902 (lcd_readl(fbi, LCCR1) != fbi->reg_lccr1) ||
760 (FDADR0 != fbi->fdadr0) || (FDADR1 != fbi->fdadr1)) 903 (lcd_readl(fbi, LCCR2) != fbi->reg_lccr2) ||
904 (lcd_readl(fbi, LCCR3) != fbi->reg_lccr3) ||
905 (lcd_readl(fbi, FDADR0) != fbi->fdadr[0]) ||
906 (lcd_readl(fbi, FDADR1) != fbi->fdadr[1]))
761 pxafb_schedule_work(fbi, C_REENABLE); 907 pxafb_schedule_work(fbi, C_REENABLE);
762 908
763 return 0; 909 return 0;
@@ -773,8 +919,8 @@ static inline void __pxafb_backlight_power(struct pxafb_info *fbi, int on)
773{ 919{
774 pr_debug("pxafb: backlight o%s\n", on ? "n" : "ff"); 920 pr_debug("pxafb: backlight o%s\n", on ? "n" : "ff");
775 921
776 if (pxafb_backlight_power) 922 if (pxafb_backlight_power)
777 pxafb_backlight_power(on); 923 pxafb_backlight_power(on);
778} 924}
779 925
780static inline void __pxafb_lcd_power(struct pxafb_info *fbi, int on) 926static inline void __pxafb_lcd_power(struct pxafb_info *fbi, int on)
@@ -788,11 +934,11 @@ static inline void __pxafb_lcd_power(struct pxafb_info *fbi, int on)
788static void pxafb_setup_gpio(struct pxafb_info *fbi) 934static void pxafb_setup_gpio(struct pxafb_info *fbi)
789{ 935{
790 int gpio, ldd_bits; 936 int gpio, ldd_bits;
791 unsigned int lccr0 = fbi->lccr0; 937 unsigned int lccr0 = fbi->lccr0;
792 938
793 /* 939 /*
794 * setup is based on type of panel supported 940 * setup is based on type of panel supported
795 */ 941 */
796 942
797 /* 4 bit interface */ 943 /* 4 bit interface */
798 if ((lccr0 & LCCR0_CMS) == LCCR0_Mono && 944 if ((lccr0 & LCCR0_CMS) == LCCR0_Mono &&
@@ -801,21 +947,25 @@ static void pxafb_setup_gpio(struct pxafb_info *fbi)
801 ldd_bits = 4; 947 ldd_bits = 4;
802 948
803 /* 8 bit interface */ 949 /* 8 bit interface */
804 else if (((lccr0 & LCCR0_CMS) == LCCR0_Mono && 950 else if (((lccr0 & LCCR0_CMS) == LCCR0_Mono &&
805 ((lccr0 & LCCR0_SDS) == LCCR0_Dual || (lccr0 & LCCR0_DPD) == LCCR0_8PixMono)) || 951 ((lccr0 & LCCR0_SDS) == LCCR0_Dual ||
806 ((lccr0 & LCCR0_CMS) == LCCR0_Color && 952 (lccr0 & LCCR0_DPD) == LCCR0_8PixMono)) ||
807 (lccr0 & LCCR0_PAS) == LCCR0_Pas && (lccr0 & LCCR0_SDS) == LCCR0_Sngl)) 953 ((lccr0 & LCCR0_CMS) == LCCR0_Color &&
954 (lccr0 & LCCR0_PAS) == LCCR0_Pas &&
955 (lccr0 & LCCR0_SDS) == LCCR0_Sngl))
808 ldd_bits = 8; 956 ldd_bits = 8;
809 957
810 /* 16 bit interface */ 958 /* 16 bit interface */
811 else if ((lccr0 & LCCR0_CMS) == LCCR0_Color && 959 else if ((lccr0 & LCCR0_CMS) == LCCR0_Color &&
812 ((lccr0 & LCCR0_SDS) == LCCR0_Dual || (lccr0 & LCCR0_PAS) == LCCR0_Act)) 960 ((lccr0 & LCCR0_SDS) == LCCR0_Dual ||
961 (lccr0 & LCCR0_PAS) == LCCR0_Act))
813 ldd_bits = 16; 962 ldd_bits = 16;
814 963
815 else { 964 else {
816 printk(KERN_ERR "pxafb_setup_gpio: unable to determine bits per pixel\n"); 965 printk(KERN_ERR "pxafb_setup_gpio: unable to determine "
966 "bits per pixel\n");
817 return; 967 return;
818 } 968 }
819 969
820 for (gpio = 58; ldd_bits; gpio++, ldd_bits--) 970 for (gpio = 58; ldd_bits; gpio++, ldd_bits--)
821 pxa_gpio_mode(gpio | GPIO_ALT_FN_2_OUT); 971 pxa_gpio_mode(gpio | GPIO_ALT_FN_2_OUT);
@@ -828,8 +978,8 @@ static void pxafb_setup_gpio(struct pxafb_info *fbi)
828static void pxafb_enable_controller(struct pxafb_info *fbi) 978static void pxafb_enable_controller(struct pxafb_info *fbi)
829{ 979{
830 pr_debug("pxafb: Enabling LCD controller\n"); 980 pr_debug("pxafb: Enabling LCD controller\n");
831 pr_debug("fdadr0 0x%08x\n", (unsigned int) fbi->fdadr0); 981 pr_debug("fdadr0 0x%08x\n", (unsigned int) fbi->fdadr[0]);
832 pr_debug("fdadr1 0x%08x\n", (unsigned int) fbi->fdadr1); 982 pr_debug("fdadr1 0x%08x\n", (unsigned int) fbi->fdadr[1]);
833 pr_debug("reg_lccr0 0x%08x\n", (unsigned int) fbi->reg_lccr0); 983 pr_debug("reg_lccr0 0x%08x\n", (unsigned int) fbi->reg_lccr0);
834 pr_debug("reg_lccr1 0x%08x\n", (unsigned int) fbi->reg_lccr1); 984 pr_debug("reg_lccr1 0x%08x\n", (unsigned int) fbi->reg_lccr1);
835 pr_debug("reg_lccr2 0x%08x\n", (unsigned int) fbi->reg_lccr2); 985 pr_debug("reg_lccr2 0x%08x\n", (unsigned int) fbi->reg_lccr2);
@@ -838,40 +988,40 @@ static void pxafb_enable_controller(struct pxafb_info *fbi)
838 /* enable LCD controller clock */ 988 /* enable LCD controller clock */
839 clk_enable(fbi->clk); 989 clk_enable(fbi->clk);
840 990
991 if (fbi->lccr0 & LCCR0_LCDT)
992 return;
993
841 /* Sequence from 11.7.10 */ 994 /* Sequence from 11.7.10 */
842 LCCR3 = fbi->reg_lccr3; 995 lcd_writel(fbi, LCCR3, fbi->reg_lccr3);
843 LCCR2 = fbi->reg_lccr2; 996 lcd_writel(fbi, LCCR2, fbi->reg_lccr2);
844 LCCR1 = fbi->reg_lccr1; 997 lcd_writel(fbi, LCCR1, fbi->reg_lccr1);
845 LCCR0 = fbi->reg_lccr0 & ~LCCR0_ENB; 998 lcd_writel(fbi, LCCR0, fbi->reg_lccr0 & ~LCCR0_ENB);
846 999
847 FDADR0 = fbi->fdadr0; 1000 lcd_writel(fbi, FDADR0, fbi->fdadr[0]);
848 FDADR1 = fbi->fdadr1; 1001 lcd_writel(fbi, FDADR1, fbi->fdadr[1]);
849 LCCR0 |= LCCR0_ENB; 1002 lcd_writel(fbi, LCCR0, fbi->reg_lccr0 | LCCR0_ENB);
850
851 pr_debug("FDADR0 0x%08x\n", (unsigned int) FDADR0);
852 pr_debug("FDADR1 0x%08x\n", (unsigned int) FDADR1);
853 pr_debug("LCCR0 0x%08x\n", (unsigned int) LCCR0);
854 pr_debug("LCCR1 0x%08x\n", (unsigned int) LCCR1);
855 pr_debug("LCCR2 0x%08x\n", (unsigned int) LCCR2);
856 pr_debug("LCCR3 0x%08x\n", (unsigned int) LCCR3);
857 pr_debug("LCCR4 0x%08x\n", (unsigned int) LCCR4);
858} 1003}
859 1004
860static void pxafb_disable_controller(struct pxafb_info *fbi) 1005static void pxafb_disable_controller(struct pxafb_info *fbi)
861{ 1006{
862 DECLARE_WAITQUEUE(wait, current); 1007 uint32_t lccr0;
863 1008
864 pr_debug("pxafb: disabling LCD controller\n"); 1009#ifdef CONFIG_FB_PXA_SMARTPANEL
1010 if (fbi->lccr0 & LCCR0_LCDT) {
1011 wait_for_completion_timeout(&fbi->refresh_done,
1012 200 * HZ / 1000);
1013 return;
1014 }
1015#endif
865 1016
866 set_current_state(TASK_UNINTERRUPTIBLE); 1017 /* Clear LCD Status Register */
867 add_wait_queue(&fbi->ctrlr_wait, &wait); 1018 lcd_writel(fbi, LCSR, 0xffffffff);
868 1019
869 LCSR = 0xffffffff; /* Clear LCD Status Register */ 1020 lccr0 = lcd_readl(fbi, LCCR0) & ~LCCR0_LDM;
870 LCCR0 &= ~LCCR0_LDM; /* Enable LCD Disable Done Interrupt */ 1021 lcd_writel(fbi, LCCR0, lccr0);
871 LCCR0 |= LCCR0_DIS; /* Disable LCD Controller */ 1022 lcd_writel(fbi, LCCR0, lccr0 | LCCR0_DIS);
872 1023
873 schedule_timeout(200 * HZ / 1000); 1024 wait_for_completion_timeout(&fbi->disable_done, 200 * HZ / 1000);
874 remove_wait_queue(&fbi->ctrlr_wait, &wait);
875 1025
876 /* disable LCD controller clock */ 1026 /* disable LCD controller clock */
877 clk_disable(fbi->clk); 1027 clk_disable(fbi->clk);
@@ -883,14 +1033,20 @@ static void pxafb_disable_controller(struct pxafb_info *fbi)
883static irqreturn_t pxafb_handle_irq(int irq, void *dev_id) 1033static irqreturn_t pxafb_handle_irq(int irq, void *dev_id)
884{ 1034{
885 struct pxafb_info *fbi = dev_id; 1035 struct pxafb_info *fbi = dev_id;
886 unsigned int lcsr = LCSR; 1036 unsigned int lccr0, lcsr = lcd_readl(fbi, LCSR);
887 1037
888 if (lcsr & LCSR_LDD) { 1038 if (lcsr & LCSR_LDD) {
889 LCCR0 |= LCCR0_LDM; 1039 lccr0 = lcd_readl(fbi, LCCR0);
890 wake_up(&fbi->ctrlr_wait); 1040 lcd_writel(fbi, LCCR0, lccr0 | LCCR0_LDM);
1041 complete(&fbi->disable_done);
891 } 1042 }
892 1043
893 LCSR = lcsr; 1044#ifdef CONFIG_FB_PXA_SMARTPANEL
1045 if (lcsr & LCSR_CMD_INT)
1046 complete(&fbi->command_done);
1047#endif
1048
1049 lcd_writel(fbi, LCSR, lcsr);
894 return IRQ_HANDLED; 1050 return IRQ_HANDLED;
895} 1051}
896 1052
@@ -921,7 +1077,7 @@ static void set_ctrlr_state(struct pxafb_info *fbi, u_int state)
921 */ 1077 */
922 if (old_state != C_DISABLE && old_state != C_DISABLE_PM) { 1078 if (old_state != C_DISABLE && old_state != C_DISABLE_PM) {
923 fbi->state = state; 1079 fbi->state = state;
924 //TODO __pxafb_lcd_power(fbi, 0); 1080 /* TODO __pxafb_lcd_power(fbi, 0); */
925 pxafb_disable_controller(fbi); 1081 pxafb_disable_controller(fbi);
926 } 1082 }
927 break; 1083 break;
@@ -948,7 +1104,7 @@ static void set_ctrlr_state(struct pxafb_info *fbi, u_int state)
948 if (old_state == C_DISABLE_CLKCHANGE) { 1104 if (old_state == C_DISABLE_CLKCHANGE) {
949 fbi->state = C_ENABLE; 1105 fbi->state = C_ENABLE;
950 pxafb_enable_controller(fbi); 1106 pxafb_enable_controller(fbi);
951 //TODO __pxafb_lcd_power(fbi, 1); 1107 /* TODO __pxafb_lcd_power(fbi, 1); */
952 } 1108 }
953 break; 1109 break;
954 1110
@@ -1019,7 +1175,7 @@ static int
1019pxafb_freq_transition(struct notifier_block *nb, unsigned long val, void *data) 1175pxafb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
1020{ 1176{
1021 struct pxafb_info *fbi = TO_INF(nb, freq_transition); 1177 struct pxafb_info *fbi = TO_INF(nb, freq_transition);
1022 //TODO struct cpufreq_freqs *f = data; 1178 /* TODO struct cpufreq_freqs *f = data; */
1023 u_int pcd; 1179 u_int pcd;
1024 1180
1025 switch (val) { 1181 switch (val) {
@@ -1030,7 +1186,8 @@ pxafb_freq_transition(struct notifier_block *nb, unsigned long val, void *data)
1030 case CPUFREQ_POSTCHANGE: 1186 case CPUFREQ_POSTCHANGE:
1031 pcd = get_pcd(fbi, fbi->fb.var.pixclock); 1187 pcd = get_pcd(fbi, fbi->fb.var.pixclock);
1032 set_hsync_time(fbi, pcd); 1188 set_hsync_time(fbi, pcd);
1033 fbi->reg_lccr3 = (fbi->reg_lccr3 & ~0xff) | LCCR3_PixClkDiv(pcd); 1189 fbi->reg_lccr3 = (fbi->reg_lccr3 & ~0xff) |
1190 LCCR3_PixClkDiv(pcd);
1034 set_ctrlr_state(fbi, C_ENABLE_CLKCHANGE); 1191 set_ctrlr_state(fbi, C_ENABLE_CLKCHANGE);
1035 break; 1192 break;
1036 } 1193 }
@@ -1050,18 +1207,8 @@ pxafb_freq_policy(struct notifier_block *nb, unsigned long val, void *data)
1050 pr_debug("min dma period: %d ps, " 1207 pr_debug("min dma period: %d ps, "
1051 "new clock %d kHz\n", pxafb_display_dma_period(var), 1208 "new clock %d kHz\n", pxafb_display_dma_period(var),
1052 policy->max); 1209 policy->max);
1053 // TODO: fill in min/max values 1210 /* TODO: fill in min/max values */
1054 break;
1055#if 0
1056 case CPUFREQ_NOTIFY:
1057 printk(KERN_ERR "%s: got CPUFREQ_NOTIFY\n", __FUNCTION__);
1058 do {} while(0);
1059 /* todo: panic if min/max values aren't fulfilled
1060 * [can't really happen unless there's a bug in the
1061 * CPU policy verification process *
1062 */
1063 break; 1211 break;
1064#endif
1065 } 1212 }
1066 return 0; 1213 return 0;
1067} 1214}
@@ -1102,21 +1249,21 @@ static int pxafb_resume(struct platform_device *dev)
1102 */ 1249 */
1103static int __init pxafb_map_video_memory(struct pxafb_info *fbi) 1250static int __init pxafb_map_video_memory(struct pxafb_info *fbi)
1104{ 1251{
1105 u_long palette_mem_size;
1106
1107 /* 1252 /*
1108 * We reserve one page for the palette, plus the size 1253 * We reserve one page for the palette, plus the size
1109 * of the framebuffer. 1254 * of the framebuffer.
1110 */ 1255 */
1111 fbi->map_size = PAGE_ALIGN(fbi->fb.fix.smem_len + PAGE_SIZE); 1256 fbi->video_offset = PAGE_ALIGN(sizeof(struct pxafb_dma_buff));
1257 fbi->map_size = PAGE_ALIGN(fbi->fb.fix.smem_len + fbi->video_offset);
1112 fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size, 1258 fbi->map_cpu = dma_alloc_writecombine(fbi->dev, fbi->map_size,
1113 &fbi->map_dma, GFP_KERNEL); 1259 &fbi->map_dma, GFP_KERNEL);
1114 1260
1115 if (fbi->map_cpu) { 1261 if (fbi->map_cpu) {
1116 /* prevent initial garbage on screen */ 1262 /* prevent initial garbage on screen */
1117 memset(fbi->map_cpu, 0, fbi->map_size); 1263 memset(fbi->map_cpu, 0, fbi->map_size);
1118 fbi->fb.screen_base = fbi->map_cpu + PAGE_SIZE; 1264 fbi->fb.screen_base = fbi->map_cpu + fbi->video_offset;
1119 fbi->screen_dma = fbi->map_dma + PAGE_SIZE; 1265 fbi->screen_dma = fbi->map_dma + fbi->video_offset;
1266
1120 /* 1267 /*
1121 * FIXME: this is actually the wrong thing to place in 1268 * FIXME: this is actually the wrong thing to place in
1122 * smem_start. But fbdev suffers from the problem that 1269 * smem_start. But fbdev suffers from the problem that
@@ -1126,27 +1273,86 @@ static int __init pxafb_map_video_memory(struct pxafb_info *fbi)
1126 fbi->fb.fix.smem_start = fbi->screen_dma; 1273 fbi->fb.fix.smem_start = fbi->screen_dma;
1127 fbi->palette_size = fbi->fb.var.bits_per_pixel == 8 ? 256 : 16; 1274 fbi->palette_size = fbi->fb.var.bits_per_pixel == 8 ? 256 : 16;
1128 1275
1129 if ((fbi->lccr4 & LCCR4_PAL_FOR_MASK) == LCCR4_PAL_FOR_0) 1276 fbi->dma_buff = (void *) fbi->map_cpu;
1130 palette_mem_size = fbi->palette_size * sizeof(u16); 1277 fbi->dma_buff_phys = fbi->map_dma;
1131 else 1278 fbi->palette_cpu = (u16 *) fbi->dma_buff->palette;
1132 palette_mem_size = fbi->palette_size * sizeof(u32);
1133 1279
1134 pr_debug("pxafb: palette_mem_size = 0x%08lx\n", palette_mem_size); 1280#ifdef CONFIG_FB_PXA_SMARTPANEL
1135 1281 fbi->smart_cmds = (uint16_t *) fbi->dma_buff->cmd_buff;
1136 fbi->palette_cpu = (u16 *)(fbi->map_cpu + PAGE_SIZE - palette_mem_size); 1282 fbi->n_smart_cmds = 0;
1137 fbi->palette_dma = fbi->map_dma + PAGE_SIZE - palette_mem_size; 1283#endif
1138 } 1284 }
1139 1285
1140 return fbi->map_cpu ? 0 : -ENOMEM; 1286 return fbi->map_cpu ? 0 : -ENOMEM;
1141} 1287}
1142 1288
1289static void pxafb_decode_mode_info(struct pxafb_info *fbi,
1290 struct pxafb_mode_info *modes,
1291 unsigned int num_modes)
1292{
1293 unsigned int i, smemlen;
1294
1295 pxafb_setmode(&fbi->fb.var, &modes[0]);
1296
1297 for (i = 0; i < num_modes; i++) {
1298 smemlen = modes[i].xres * modes[i].yres * modes[i].bpp / 8;
1299 if (smemlen > fbi->fb.fix.smem_len)
1300 fbi->fb.fix.smem_len = smemlen;
1301 }
1302}
1303
1304static int pxafb_decode_mach_info(struct pxafb_info *fbi,
1305 struct pxafb_mach_info *inf)
1306{
1307 unsigned int lcd_conn = inf->lcd_conn;
1308
1309 fbi->cmap_inverse = inf->cmap_inverse;
1310 fbi->cmap_static = inf->cmap_static;
1311
1312 switch (lcd_conn & 0xf) {
1313 case LCD_TYPE_MONO_STN:
1314 fbi->lccr0 = LCCR0_CMS;
1315 break;
1316 case LCD_TYPE_MONO_DSTN:
1317 fbi->lccr0 = LCCR0_CMS | LCCR0_SDS;
1318 break;
1319 case LCD_TYPE_COLOR_STN:
1320 fbi->lccr0 = 0;
1321 break;
1322 case LCD_TYPE_COLOR_DSTN:
1323 fbi->lccr0 = LCCR0_SDS;
1324 break;
1325 case LCD_TYPE_COLOR_TFT:
1326 fbi->lccr0 = LCCR0_PAS;
1327 break;
1328 case LCD_TYPE_SMART_PANEL:
1329 fbi->lccr0 = LCCR0_LCDT | LCCR0_PAS;
1330 break;
1331 default:
1332 /* fall back to backward compatibility way */
1333 fbi->lccr0 = inf->lccr0;
1334 fbi->lccr3 = inf->lccr3;
1335 fbi->lccr4 = inf->lccr4;
1336 return -EINVAL;
1337 }
1338
1339 if (lcd_conn == LCD_MONO_STN_8BPP)
1340 fbi->lccr0 |= LCCR0_DPD;
1341
1342 fbi->lccr3 = LCCR3_Acb((inf->lcd_conn >> 10) & 0xff);
1343 fbi->lccr3 |= (lcd_conn & LCD_BIAS_ACTIVE_LOW) ? LCCR3_OEP : 0;
1344 fbi->lccr3 |= (lcd_conn & LCD_PCLK_EDGE_FALL) ? LCCR3_PCP : 0;
1345
1346 pxafb_decode_mode_info(fbi, inf->modes, inf->num_modes);
1347 return 0;
1348}
1349
1143static struct pxafb_info * __init pxafb_init_fbinfo(struct device *dev) 1350static struct pxafb_info * __init pxafb_init_fbinfo(struct device *dev)
1144{ 1351{
1145 struct pxafb_info *fbi; 1352 struct pxafb_info *fbi;
1146 void *addr; 1353 void *addr;
1147 struct pxafb_mach_info *inf = dev->platform_data; 1354 struct pxafb_mach_info *inf = dev->platform_data;
1148 struct pxafb_mode_info *mode = inf->modes; 1355 struct pxafb_mode_info *mode = inf->modes;
1149 int i, smemlen;
1150 1356
1151 /* Alloc the pxafb_info and pseudo_palette in one step */ 1357 /* Alloc the pxafb_info and pseudo_palette in one step */
1152 fbi = kmalloc(sizeof(struct pxafb_info) + sizeof(u32) * 16, GFP_KERNEL); 1358 fbi = kmalloc(sizeof(struct pxafb_info) + sizeof(u32) * 16, GFP_KERNEL);
@@ -1186,187 +1392,233 @@ static struct pxafb_info * __init pxafb_init_fbinfo(struct device *dev)
1186 addr = addr + sizeof(struct pxafb_info); 1392 addr = addr + sizeof(struct pxafb_info);
1187 fbi->fb.pseudo_palette = addr; 1393 fbi->fb.pseudo_palette = addr;
1188 1394
1189 pxafb_setmode(&fbi->fb.var, mode); 1395 fbi->state = C_STARTUP;
1396 fbi->task_state = (u_char)-1;
1190 1397
1191 fbi->cmap_inverse = inf->cmap_inverse; 1398 pxafb_decode_mach_info(fbi, inf);
1192 fbi->cmap_static = inf->cmap_static;
1193
1194 fbi->lccr0 = inf->lccr0;
1195 fbi->lccr3 = inf->lccr3;
1196 fbi->lccr4 = inf->lccr4;
1197 fbi->state = C_STARTUP;
1198 fbi->task_state = (u_char)-1;
1199
1200 for (i = 0; i < inf->num_modes; i++) {
1201 smemlen = mode[i].xres * mode[i].yres * mode[i].bpp / 8;
1202 if (smemlen > fbi->fb.fix.smem_len)
1203 fbi->fb.fix.smem_len = smemlen;
1204 }
1205 1399
1206 init_waitqueue_head(&fbi->ctrlr_wait); 1400 init_waitqueue_head(&fbi->ctrlr_wait);
1207 INIT_WORK(&fbi->task, pxafb_task); 1401 INIT_WORK(&fbi->task, pxafb_task);
1208 init_MUTEX(&fbi->ctrlr_sem); 1402 init_MUTEX(&fbi->ctrlr_sem);
1403 init_completion(&fbi->disable_done);
1404#ifdef CONFIG_FB_PXA_SMARTPANEL
1405 init_completion(&fbi->command_done);
1406 init_completion(&fbi->refresh_done);
1407#endif
1209 1408
1210 return fbi; 1409 return fbi;
1211} 1410}
1212 1411
1213#ifdef CONFIG_FB_PXA_PARAMETERS 1412#ifdef CONFIG_FB_PXA_PARAMETERS
1214static int __init pxafb_parse_options(struct device *dev, char *options) 1413static int __init parse_opt_mode(struct device *dev, const char *this_opt)
1414{
1415 struct pxafb_mach_info *inf = dev->platform_data;
1416
1417 const char *name = this_opt+5;
1418 unsigned int namelen = strlen(name);
1419 int res_specified = 0, bpp_specified = 0;
1420 unsigned int xres = 0, yres = 0, bpp = 0;
1421 int yres_specified = 0;
1422 int i;
1423 for (i = namelen-1; i >= 0; i--) {
1424 switch (name[i]) {
1425 case '-':
1426 namelen = i;
1427 if (!bpp_specified && !yres_specified) {
1428 bpp = simple_strtoul(&name[i+1], NULL, 0);
1429 bpp_specified = 1;
1430 } else
1431 goto done;
1432 break;
1433 case 'x':
1434 if (!yres_specified) {
1435 yres = simple_strtoul(&name[i+1], NULL, 0);
1436 yres_specified = 1;
1437 } else
1438 goto done;
1439 break;
1440 case '0' ... '9':
1441 break;
1442 default:
1443 goto done;
1444 }
1445 }
1446 if (i < 0 && yres_specified) {
1447 xres = simple_strtoul(name, NULL, 0);
1448 res_specified = 1;
1449 }
1450done:
1451 if (res_specified) {
1452 dev_info(dev, "overriding resolution: %dx%d\n", xres, yres);
1453 inf->modes[0].xres = xres; inf->modes[0].yres = yres;
1454 }
1455 if (bpp_specified)
1456 switch (bpp) {
1457 case 1:
1458 case 2:
1459 case 4:
1460 case 8:
1461 case 16:
1462 inf->modes[0].bpp = bpp;
1463 dev_info(dev, "overriding bit depth: %d\n", bpp);
1464 break;
1465 default:
1466 dev_err(dev, "Depth %d is not valid\n", bpp);
1467 return -EINVAL;
1468 }
1469 return 0;
1470}
1471
1472static int __init parse_opt(struct device *dev, char *this_opt)
1215{ 1473{
1216 struct pxafb_mach_info *inf = dev->platform_data; 1474 struct pxafb_mach_info *inf = dev->platform_data;
1475 struct pxafb_mode_info *mode = &inf->modes[0];
1476 char s[64];
1477
1478 s[0] = '\0';
1479
1480 if (!strncmp(this_opt, "mode:", 5)) {
1481 return parse_opt_mode(dev, this_opt);
1482 } else if (!strncmp(this_opt, "pixclock:", 9)) {
1483 mode->pixclock = simple_strtoul(this_opt+9, NULL, 0);
1484 sprintf(s, "pixclock: %ld\n", mode->pixclock);
1485 } else if (!strncmp(this_opt, "left:", 5)) {
1486 mode->left_margin = simple_strtoul(this_opt+5, NULL, 0);
1487 sprintf(s, "left: %u\n", mode->left_margin);
1488 } else if (!strncmp(this_opt, "right:", 6)) {
1489 mode->right_margin = simple_strtoul(this_opt+6, NULL, 0);
1490 sprintf(s, "right: %u\n", mode->right_margin);
1491 } else if (!strncmp(this_opt, "upper:", 6)) {
1492 mode->upper_margin = simple_strtoul(this_opt+6, NULL, 0);
1493 sprintf(s, "upper: %u\n", mode->upper_margin);
1494 } else if (!strncmp(this_opt, "lower:", 6)) {
1495 mode->lower_margin = simple_strtoul(this_opt+6, NULL, 0);
1496 sprintf(s, "lower: %u\n", mode->lower_margin);
1497 } else if (!strncmp(this_opt, "hsynclen:", 9)) {
1498 mode->hsync_len = simple_strtoul(this_opt+9, NULL, 0);
1499 sprintf(s, "hsynclen: %u\n", mode->hsync_len);
1500 } else if (!strncmp(this_opt, "vsynclen:", 9)) {
1501 mode->vsync_len = simple_strtoul(this_opt+9, NULL, 0);
1502 sprintf(s, "vsynclen: %u\n", mode->vsync_len);
1503 } else if (!strncmp(this_opt, "hsync:", 6)) {
1504 if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
1505 sprintf(s, "hsync: Active Low\n");
1506 mode->sync &= ~FB_SYNC_HOR_HIGH_ACT;
1507 } else {
1508 sprintf(s, "hsync: Active High\n");
1509 mode->sync |= FB_SYNC_HOR_HIGH_ACT;
1510 }
1511 } else if (!strncmp(this_opt, "vsync:", 6)) {
1512 if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
1513 sprintf(s, "vsync: Active Low\n");
1514 mode->sync &= ~FB_SYNC_VERT_HIGH_ACT;
1515 } else {
1516 sprintf(s, "vsync: Active High\n");
1517 mode->sync |= FB_SYNC_VERT_HIGH_ACT;
1518 }
1519 } else if (!strncmp(this_opt, "dpc:", 4)) {
1520 if (simple_strtoul(this_opt+4, NULL, 0) == 0) {
1521 sprintf(s, "double pixel clock: false\n");
1522 inf->lccr3 &= ~LCCR3_DPC;
1523 } else {
1524 sprintf(s, "double pixel clock: true\n");
1525 inf->lccr3 |= LCCR3_DPC;
1526 }
1527 } else if (!strncmp(this_opt, "outputen:", 9)) {
1528 if (simple_strtoul(this_opt+9, NULL, 0) == 0) {
1529 sprintf(s, "output enable: active low\n");
1530 inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnL;
1531 } else {
1532 sprintf(s, "output enable: active high\n");
1533 inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnH;
1534 }
1535 } else if (!strncmp(this_opt, "pixclockpol:", 12)) {
1536 if (simple_strtoul(this_opt+12, NULL, 0) == 0) {
1537 sprintf(s, "pixel clock polarity: falling edge\n");
1538 inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixFlEdg;
1539 } else {
1540 sprintf(s, "pixel clock polarity: rising edge\n");
1541 inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixRsEdg;
1542 }
1543 } else if (!strncmp(this_opt, "color", 5)) {
1544 inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Color;
1545 } else if (!strncmp(this_opt, "mono", 4)) {
1546 inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Mono;
1547 } else if (!strncmp(this_opt, "active", 6)) {
1548 inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Act;
1549 } else if (!strncmp(this_opt, "passive", 7)) {
1550 inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Pas;
1551 } else if (!strncmp(this_opt, "single", 6)) {
1552 inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Sngl;
1553 } else if (!strncmp(this_opt, "dual", 4)) {
1554 inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Dual;
1555 } else if (!strncmp(this_opt, "4pix", 4)) {
1556 inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_4PixMono;
1557 } else if (!strncmp(this_opt, "8pix", 4)) {
1558 inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_8PixMono;
1559 } else {
1560 dev_err(dev, "unknown option: %s\n", this_opt);
1561 return -EINVAL;
1562 }
1563
1564 if (s[0] != '\0')
1565 dev_info(dev, "override %s", s);
1566
1567 return 0;
1568}
1569
1570static int __init pxafb_parse_options(struct device *dev, char *options)
1571{
1217 char *this_opt; 1572 char *this_opt;
1573 int ret;
1218 1574
1219 if (!options || !*options) 1575 if (!options || !*options)
1220 return 0; 1576 return 0;
1221 1577
1222 dev_dbg(dev, "options are \"%s\"\n", options ? options : "null"); 1578 dev_dbg(dev, "options are \"%s\"\n", options ? options : "null");
1223 1579
1224 /* could be made table driven or similar?... */ 1580 /* could be made table driven or similar?... */
1225 while ((this_opt = strsep(&options, ",")) != NULL) { 1581 while ((this_opt = strsep(&options, ",")) != NULL) {
1226 if (!strncmp(this_opt, "mode:", 5)) { 1582 ret = parse_opt(dev, this_opt);
1227 const char *name = this_opt+5; 1583 if (ret)
1228 unsigned int namelen = strlen(name); 1584 return ret;
1229 int res_specified = 0, bpp_specified = 0; 1585 }
1230 unsigned int xres = 0, yres = 0, bpp = 0; 1586 return 0;
1231 int yres_specified = 0; 1587}
1232 int i; 1588
1233 for (i = namelen-1; i >= 0; i--) { 1589static char g_options[256] __devinitdata = "";
1234 switch (name[i]) {
1235 case '-':
1236 namelen = i;
1237 if (!bpp_specified && !yres_specified) {
1238 bpp = simple_strtoul(&name[i+1], NULL, 0);
1239 bpp_specified = 1;
1240 } else
1241 goto done;
1242 break;
1243 case 'x':
1244 if (!yres_specified) {
1245 yres = simple_strtoul(&name[i+1], NULL, 0);
1246 yres_specified = 1;
1247 } else
1248 goto done;
1249 break;
1250 case '0' ... '9':
1251 break;
1252 default:
1253 goto done;
1254 }
1255 }
1256 if (i < 0 && yres_specified) {
1257 xres = simple_strtoul(name, NULL, 0);
1258 res_specified = 1;
1259 }
1260 done:
1261 if (res_specified) {
1262 dev_info(dev, "overriding resolution: %dx%d\n", xres, yres);
1263 inf->modes[0].xres = xres; inf->modes[0].yres = yres;
1264 }
1265 if (bpp_specified)
1266 switch (bpp) {
1267 case 1:
1268 case 2:
1269 case 4:
1270 case 8:
1271 case 16:
1272 inf->modes[0].bpp = bpp;
1273 dev_info(dev, "overriding bit depth: %d\n", bpp);
1274 break;
1275 default:
1276 dev_err(dev, "Depth %d is not valid\n", bpp);
1277 }
1278 } else if (!strncmp(this_opt, "pixclock:", 9)) {
1279 inf->modes[0].pixclock = simple_strtoul(this_opt+9, NULL, 0);
1280 dev_info(dev, "override pixclock: %ld\n", inf->modes[0].pixclock);
1281 } else if (!strncmp(this_opt, "left:", 5)) {
1282 inf->modes[0].left_margin = simple_strtoul(this_opt+5, NULL, 0);
1283 dev_info(dev, "override left: %u\n", inf->modes[0].left_margin);
1284 } else if (!strncmp(this_opt, "right:", 6)) {
1285 inf->modes[0].right_margin = simple_strtoul(this_opt+6, NULL, 0);
1286 dev_info(dev, "override right: %u\n", inf->modes[0].right_margin);
1287 } else if (!strncmp(this_opt, "upper:", 6)) {
1288 inf->modes[0].upper_margin = simple_strtoul(this_opt+6, NULL, 0);
1289 dev_info(dev, "override upper: %u\n", inf->modes[0].upper_margin);
1290 } else if (!strncmp(this_opt, "lower:", 6)) {
1291 inf->modes[0].lower_margin = simple_strtoul(this_opt+6, NULL, 0);
1292 dev_info(dev, "override lower: %u\n", inf->modes[0].lower_margin);
1293 } else if (!strncmp(this_opt, "hsynclen:", 9)) {
1294 inf->modes[0].hsync_len = simple_strtoul(this_opt+9, NULL, 0);
1295 dev_info(dev, "override hsynclen: %u\n", inf->modes[0].hsync_len);
1296 } else if (!strncmp(this_opt, "vsynclen:", 9)) {
1297 inf->modes[0].vsync_len = simple_strtoul(this_opt+9, NULL, 0);
1298 dev_info(dev, "override vsynclen: %u\n", inf->modes[0].vsync_len);
1299 } else if (!strncmp(this_opt, "hsync:", 6)) {
1300 if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
1301 dev_info(dev, "override hsync: Active Low\n");
1302 inf->modes[0].sync &= ~FB_SYNC_HOR_HIGH_ACT;
1303 } else {
1304 dev_info(dev, "override hsync: Active High\n");
1305 inf->modes[0].sync |= FB_SYNC_HOR_HIGH_ACT;
1306 }
1307 } else if (!strncmp(this_opt, "vsync:", 6)) {
1308 if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
1309 dev_info(dev, "override vsync: Active Low\n");
1310 inf->modes[0].sync &= ~FB_SYNC_VERT_HIGH_ACT;
1311 } else {
1312 dev_info(dev, "override vsync: Active High\n");
1313 inf->modes[0].sync |= FB_SYNC_VERT_HIGH_ACT;
1314 }
1315 } else if (!strncmp(this_opt, "dpc:", 4)) {
1316 if (simple_strtoul(this_opt+4, NULL, 0) == 0) {
1317 dev_info(dev, "override double pixel clock: false\n");
1318 inf->lccr3 &= ~LCCR3_DPC;
1319 } else {
1320 dev_info(dev, "override double pixel clock: true\n");
1321 inf->lccr3 |= LCCR3_DPC;
1322 }
1323 } else if (!strncmp(this_opt, "outputen:", 9)) {
1324 if (simple_strtoul(this_opt+9, NULL, 0) == 0) {
1325 dev_info(dev, "override output enable: active low\n");
1326 inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnL;
1327 } else {
1328 dev_info(dev, "override output enable: active high\n");
1329 inf->lccr3 = (inf->lccr3 & ~LCCR3_OEP) | LCCR3_OutEnH;
1330 }
1331 } else if (!strncmp(this_opt, "pixclockpol:", 12)) {
1332 if (simple_strtoul(this_opt+12, NULL, 0) == 0) {
1333 dev_info(dev, "override pixel clock polarity: falling edge\n");
1334 inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixFlEdg;
1335 } else {
1336 dev_info(dev, "override pixel clock polarity: rising edge\n");
1337 inf->lccr3 = (inf->lccr3 & ~LCCR3_PCP) | LCCR3_PixRsEdg;
1338 }
1339 } else if (!strncmp(this_opt, "color", 5)) {
1340 inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Color;
1341 } else if (!strncmp(this_opt, "mono", 4)) {
1342 inf->lccr0 = (inf->lccr0 & ~LCCR0_CMS) | LCCR0_Mono;
1343 } else if (!strncmp(this_opt, "active", 6)) {
1344 inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Act;
1345 } else if (!strncmp(this_opt, "passive", 7)) {
1346 inf->lccr0 = (inf->lccr0 & ~LCCR0_PAS) | LCCR0_Pas;
1347 } else if (!strncmp(this_opt, "single", 6)) {
1348 inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Sngl;
1349 } else if (!strncmp(this_opt, "dual", 4)) {
1350 inf->lccr0 = (inf->lccr0 & ~LCCR0_SDS) | LCCR0_Dual;
1351 } else if (!strncmp(this_opt, "4pix", 4)) {
1352 inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_4PixMono;
1353 } else if (!strncmp(this_opt, "8pix", 4)) {
1354 inf->lccr0 = (inf->lccr0 & ~LCCR0_DPD) | LCCR0_8PixMono;
1355 } else {
1356 dev_err(dev, "unknown option: %s\n", this_opt);
1357 return -EINVAL;
1358 }
1359 }
1360 return 0;
1361 1590
1591#ifndef CONFIG_MODULES
1592static int __devinit pxafb_setup_options(void)
1593{
1594 char *options = NULL;
1595
1596 if (fb_get_options("pxafb", &options))
1597 return -ENODEV;
1598
1599 if (options)
1600 strlcpy(g_options, options, sizeof(g_options));
1601
1602 return 0;
1362} 1603}
1604#else
1605#define pxafb_setup_options() (0)
1606
1607module_param_string(options, g_options, sizeof(g_options), 0);
1608MODULE_PARM_DESC(options, "LCD parameters (see Documentation/fb/pxafb.txt)");
1609#endif
1610
1611#else
1612#define pxafb_parse_options(...) (0)
1613#define pxafb_setup_options() (0)
1363#endif 1614#endif
1364 1615
1365static int __init pxafb_probe(struct platform_device *dev) 1616static int __init pxafb_probe(struct platform_device *dev)
1366{ 1617{
1367 struct pxafb_info *fbi; 1618 struct pxafb_info *fbi;
1368 struct pxafb_mach_info *inf; 1619 struct pxafb_mach_info *inf;
1369 int ret; 1620 struct resource *r;
1621 int irq, ret;
1370 1622
1371 dev_dbg(&dev->dev, "pxafb_probe\n"); 1623 dev_dbg(&dev->dev, "pxafb_probe\n");
1372 1624
@@ -1376,38 +1628,45 @@ static int __init pxafb_probe(struct platform_device *dev)
1376 if (!inf) 1628 if (!inf)
1377 goto failed; 1629 goto failed;
1378 1630
1379#ifdef CONFIG_FB_PXA_PARAMETERS
1380 ret = pxafb_parse_options(&dev->dev, g_options); 1631 ret = pxafb_parse_options(&dev->dev, g_options);
1381 if (ret < 0) 1632 if (ret < 0)
1382 goto failed; 1633 goto failed;
1383#endif
1384 1634
1385#ifdef DEBUG_VAR 1635#ifdef DEBUG_VAR
1386 /* Check for various illegal bit-combinations. Currently only 1636 /* Check for various illegal bit-combinations. Currently only
1387 * a warning is given. */ 1637 * a warning is given. */
1388 1638
1389 if (inf->lccr0 & LCCR0_INVALID_CONFIG_MASK) 1639 if (inf->lccr0 & LCCR0_INVALID_CONFIG_MASK)
1390 dev_warn(&dev->dev, "machine LCCR0 setting contains illegal bits: %08x\n", 1640 dev_warn(&dev->dev, "machine LCCR0 setting contains "
1391 inf->lccr0 & LCCR0_INVALID_CONFIG_MASK); 1641 "illegal bits: %08x\n",
1392 if (inf->lccr3 & LCCR3_INVALID_CONFIG_MASK) 1642 inf->lccr0 & LCCR0_INVALID_CONFIG_MASK);
1393 dev_warn(&dev->dev, "machine LCCR3 setting contains illegal bits: %08x\n", 1643 if (inf->lccr3 & LCCR3_INVALID_CONFIG_MASK)
1394 inf->lccr3 & LCCR3_INVALID_CONFIG_MASK); 1644 dev_warn(&dev->dev, "machine LCCR3 setting contains "
1395 if (inf->lccr0 & LCCR0_DPD && 1645 "illegal bits: %08x\n",
1646 inf->lccr3 & LCCR3_INVALID_CONFIG_MASK);
1647 if (inf->lccr0 & LCCR0_DPD &&
1396 ((inf->lccr0 & LCCR0_PAS) != LCCR0_Pas || 1648 ((inf->lccr0 & LCCR0_PAS) != LCCR0_Pas ||
1397 (inf->lccr0 & LCCR0_SDS) != LCCR0_Sngl || 1649 (inf->lccr0 & LCCR0_SDS) != LCCR0_Sngl ||
1398 (inf->lccr0 & LCCR0_CMS) != LCCR0_Mono)) 1650 (inf->lccr0 & LCCR0_CMS) != LCCR0_Mono))
1399 dev_warn(&dev->dev, "Double Pixel Data (DPD) mode is only valid in passive mono" 1651 dev_warn(&dev->dev, "Double Pixel Data (DPD) mode is "
1400 " single panel mode\n"); 1652 "only valid in passive mono"
1401 if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Act && 1653 " single panel mode\n");
1654 if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Act &&
1402 (inf->lccr0 & LCCR0_SDS) == LCCR0_Dual) 1655 (inf->lccr0 & LCCR0_SDS) == LCCR0_Dual)
1403 dev_warn(&dev->dev, "Dual panel only valid in passive mode\n"); 1656 dev_warn(&dev->dev, "Dual panel only valid in passive mode\n");
1404 if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Pas && 1657 if ((inf->lccr0 & LCCR0_PAS) == LCCR0_Pas &&
1405 (inf->modes->upper_margin || inf->modes->lower_margin)) 1658 (inf->modes->upper_margin || inf->modes->lower_margin))
1406 dev_warn(&dev->dev, "Upper and lower margins must be 0 in passive mode\n"); 1659 dev_warn(&dev->dev, "Upper and lower margins must be 0 in "
1660 "passive mode\n");
1407#endif 1661#endif
1408 1662
1409 dev_dbg(&dev->dev, "got a %dx%dx%d LCD\n",inf->modes->xres, inf->modes->yres, inf->modes->bpp); 1663 dev_dbg(&dev->dev, "got a %dx%dx%d LCD\n",
1410 if (inf->modes->xres == 0 || inf->modes->yres == 0 || inf->modes->bpp == 0) { 1664 inf->modes->xres,
1665 inf->modes->yres,
1666 inf->modes->bpp);
1667 if (inf->modes->xres == 0 ||
1668 inf->modes->yres == 0 ||
1669 inf->modes->bpp == 0) {
1411 dev_err(&dev->dev, "Invalid resolution or bit depth\n"); 1670 dev_err(&dev->dev, "Invalid resolution or bit depth\n");
1412 ret = -EINVAL; 1671 ret = -EINVAL;
1413 goto failed; 1672 goto failed;
@@ -1416,26 +1675,62 @@ static int __init pxafb_probe(struct platform_device *dev)
1416 pxafb_lcd_power = inf->pxafb_lcd_power; 1675 pxafb_lcd_power = inf->pxafb_lcd_power;
1417 fbi = pxafb_init_fbinfo(&dev->dev); 1676 fbi = pxafb_init_fbinfo(&dev->dev);
1418 if (!fbi) { 1677 if (!fbi) {
1678 /* only reason for pxafb_init_fbinfo to fail is kmalloc */
1419 dev_err(&dev->dev, "Failed to initialize framebuffer device\n"); 1679 dev_err(&dev->dev, "Failed to initialize framebuffer device\n");
1420 ret = -ENOMEM; // only reason for pxafb_init_fbinfo to fail is kmalloc 1680 ret = -ENOMEM;
1421 goto failed; 1681 goto failed;
1422 } 1682 }
1423 1683
1684 r = platform_get_resource(dev, IORESOURCE_MEM, 0);
1685 if (r == NULL) {
1686 dev_err(&dev->dev, "no I/O memory resource defined\n");
1687 ret = -ENODEV;
1688 goto failed;
1689 }
1690
1691 r = request_mem_region(r->start, r->end - r->start + 1, dev->name);
1692 if (r == NULL) {
1693 dev_err(&dev->dev, "failed to request I/O memory\n");
1694 ret = -EBUSY;
1695 goto failed;
1696 }
1697
1698 fbi->mmio_base = ioremap(r->start, r->end - r->start + 1);
1699 if (fbi->mmio_base == NULL) {
1700 dev_err(&dev->dev, "failed to map I/O memory\n");
1701 ret = -EBUSY;
1702 goto failed_free_res;
1703 }
1704
1424 /* Initialize video memory */ 1705 /* Initialize video memory */
1425 ret = pxafb_map_video_memory(fbi); 1706 ret = pxafb_map_video_memory(fbi);
1426 if (ret) { 1707 if (ret) {
1427 dev_err(&dev->dev, "Failed to allocate video RAM: %d\n", ret); 1708 dev_err(&dev->dev, "Failed to allocate video RAM: %d\n", ret);
1428 ret = -ENOMEM; 1709 ret = -ENOMEM;
1429 goto failed; 1710 goto failed_free_io;
1711 }
1712
1713 irq = platform_get_irq(dev, 0);
1714 if (irq < 0) {
1715 dev_err(&dev->dev, "no IRQ defined\n");
1716 ret = -ENODEV;
1717 goto failed_free_mem;
1430 } 1718 }
1431 1719
1432 ret = request_irq(IRQ_LCD, pxafb_handle_irq, IRQF_DISABLED, "LCD", fbi); 1720 ret = request_irq(irq, pxafb_handle_irq, IRQF_DISABLED, "LCD", fbi);
1433 if (ret) { 1721 if (ret) {
1434 dev_err(&dev->dev, "request_irq failed: %d\n", ret); 1722 dev_err(&dev->dev, "request_irq failed: %d\n", ret);
1435 ret = -EBUSY; 1723 ret = -EBUSY;
1436 goto failed; 1724 goto failed_free_mem;
1437 } 1725 }
1438 1726
1727#ifdef CONFIG_FB_PXA_SMARTPANEL
1728 ret = pxafb_smart_init(fbi);
1729 if (ret) {
1730 dev_err(&dev->dev, "failed to initialize smartpanel\n");
1731 goto failed_free_irq;
1732 }
1733#endif
1439 /* 1734 /*
1440 * This makes sure that our colour bitfield 1735 * This makes sure that our colour bitfield
1441 * descriptors are correctly initialised. 1736 * descriptors are correctly initialised.
@@ -1447,19 +1742,18 @@ static int __init pxafb_probe(struct platform_device *dev)
1447 1742
1448 ret = register_framebuffer(&fbi->fb); 1743 ret = register_framebuffer(&fbi->fb);
1449 if (ret < 0) { 1744 if (ret < 0) {
1450 dev_err(&dev->dev, "Failed to register framebuffer device: %d\n", ret); 1745 dev_err(&dev->dev,
1451 goto failed; 1746 "Failed to register framebuffer device: %d\n", ret);
1747 goto failed_free_irq;
1452 } 1748 }
1453 1749
1454#ifdef CONFIG_PM
1455 // TODO
1456#endif
1457
1458#ifdef CONFIG_CPU_FREQ 1750#ifdef CONFIG_CPU_FREQ
1459 fbi->freq_transition.notifier_call = pxafb_freq_transition; 1751 fbi->freq_transition.notifier_call = pxafb_freq_transition;
1460 fbi->freq_policy.notifier_call = pxafb_freq_policy; 1752 fbi->freq_policy.notifier_call = pxafb_freq_policy;
1461 cpufreq_register_notifier(&fbi->freq_transition, CPUFREQ_TRANSITION_NOTIFIER); 1753 cpufreq_register_notifier(&fbi->freq_transition,
1462 cpufreq_register_notifier(&fbi->freq_policy, CPUFREQ_POLICY_NOTIFIER); 1754 CPUFREQ_TRANSITION_NOTIFIER);
1755 cpufreq_register_notifier(&fbi->freq_policy,
1756 CPUFREQ_POLICY_NOTIFIER);
1463#endif 1757#endif
1464 1758
1465 /* 1759 /*
@@ -1469,6 +1763,15 @@ static int __init pxafb_probe(struct platform_device *dev)
1469 1763
1470 return 0; 1764 return 0;
1471 1765
1766failed_free_irq:
1767 free_irq(irq, fbi);
1768failed_free_res:
1769 release_mem_region(r->start, r->end - r->start + 1);
1770failed_free_io:
1771 iounmap(fbi->mmio_base);
1772failed_free_mem:
1773 dma_free_writecombine(&dev->dev, fbi->map_size,
1774 fbi->map_cpu, fbi->map_dma);
1472failed: 1775failed:
1473 platform_set_drvdata(dev, NULL); 1776 platform_set_drvdata(dev, NULL);
1474 kfree(fbi); 1777 kfree(fbi);
@@ -1477,40 +1780,18 @@ failed:
1477 1780
1478static struct platform_driver pxafb_driver = { 1781static struct platform_driver pxafb_driver = {
1479 .probe = pxafb_probe, 1782 .probe = pxafb_probe,
1480#ifdef CONFIG_PM
1481 .suspend = pxafb_suspend, 1783 .suspend = pxafb_suspend,
1482 .resume = pxafb_resume, 1784 .resume = pxafb_resume,
1483#endif
1484 .driver = { 1785 .driver = {
1485 .name = "pxa2xx-fb", 1786 .name = "pxa2xx-fb",
1486 }, 1787 },
1487}; 1788};
1488 1789
1489#ifndef MODULE
1490static int __devinit pxafb_setup(char *options)
1491{
1492# ifdef CONFIG_FB_PXA_PARAMETERS
1493 if (options)
1494 strlcpy(g_options, options, sizeof(g_options));
1495# endif
1496 return 0;
1497}
1498#else
1499# ifdef CONFIG_FB_PXA_PARAMETERS
1500module_param_string(options, g_options, sizeof(g_options), 0);
1501MODULE_PARM_DESC(options, "LCD parameters (see Documentation/fb/pxafb.txt)");
1502# endif
1503#endif
1504
1505static int __devinit pxafb_init(void) 1790static int __devinit pxafb_init(void)
1506{ 1791{
1507#ifndef MODULE 1792 if (pxafb_setup_options())
1508 char *option = NULL; 1793 return -EINVAL;
1509 1794
1510 if (fb_get_options("pxafb", &option))
1511 return -ENODEV;
1512 pxafb_setup(option);
1513#endif
1514 return platform_driver_register(&pxafb_driver); 1795 return platform_driver_register(&pxafb_driver);
1515} 1796}
1516 1797
diff --git a/drivers/video/pxafb.h b/drivers/video/pxafb.h
index d920b8a14c35..8238dc826429 100644
--- a/drivers/video/pxafb.h
+++ b/drivers/video/pxafb.h
@@ -21,14 +21,6 @@
21 * for more details. 21 * for more details.
22 */ 22 */
23 23
24/* Shadows for LCD controller registers */
25struct pxafb_lcd_reg {
26 unsigned int lccr0;
27 unsigned int lccr1;
28 unsigned int lccr2;
29 unsigned int lccr3;
30};
31
32/* PXA LCD DMA descriptor */ 24/* PXA LCD DMA descriptor */
33struct pxafb_dma_descriptor { 25struct pxafb_dma_descriptor {
34 unsigned int fdadr; 26 unsigned int fdadr;
@@ -37,11 +29,49 @@ struct pxafb_dma_descriptor {
37 unsigned int ldcmd; 29 unsigned int ldcmd;
38}; 30};
39 31
32enum {
33 PAL_NONE = -1,
34 PAL_BASE = 0,
35 PAL_OV1 = 1,
36 PAL_OV2 = 2,
37 PAL_MAX,
38};
39
40enum {
41 DMA_BASE = 0,
42 DMA_UPPER = 0,
43 DMA_LOWER = 1,
44 DMA_OV1 = 1,
45 DMA_OV2_Y = 2,
46 DMA_OV2_Cb = 3,
47 DMA_OV2_Cr = 4,
48 DMA_CURSOR = 5,
49 DMA_CMD = 6,
50 DMA_MAX,
51};
52
53/* maximum palette size - 256 entries, each 4 bytes long */
54#define PALETTE_SIZE (256 * 4)
55#define CMD_BUFF_SIZE (1024 * 50)
56
57struct pxafb_dma_buff {
58 unsigned char palette[PAL_MAX * PALETTE_SIZE];
59 uint16_t cmd_buff[CMD_BUFF_SIZE];
60 struct pxafb_dma_descriptor pal_desc[PAL_MAX];
61 struct pxafb_dma_descriptor dma_desc[DMA_MAX];
62};
63
40struct pxafb_info { 64struct pxafb_info {
41 struct fb_info fb; 65 struct fb_info fb;
42 struct device *dev; 66 struct device *dev;
43 struct clk *clk; 67 struct clk *clk;
44 68
69 void __iomem *mmio_base;
70
71 struct pxafb_dma_buff *dma_buff;
72 dma_addr_t dma_buff_phys;
73 dma_addr_t fdadr[DMA_MAX];
74
45 /* 75 /*
46 * These are the addresses we mapped 76 * These are the addresses we mapped
47 * the framebuffer memory region to. 77 * the framebuffer memory region to.
@@ -55,19 +85,8 @@ struct pxafb_info {
55 u_char * screen_cpu; /* virtual address of frame buffer */ 85 u_char * screen_cpu; /* virtual address of frame buffer */
56 dma_addr_t screen_dma; /* physical address of frame buffer */ 86 dma_addr_t screen_dma; /* physical address of frame buffer */
57 u16 * palette_cpu; /* virtual address of palette memory */ 87 u16 * palette_cpu; /* virtual address of palette memory */
58 dma_addr_t palette_dma; /* physical address of palette memory */
59 u_int palette_size; 88 u_int palette_size;
60 89 ssize_t video_offset;
61 /* DMA descriptors */
62 struct pxafb_dma_descriptor * dmadesc_fblow_cpu;
63 dma_addr_t dmadesc_fblow_dma;
64 struct pxafb_dma_descriptor * dmadesc_fbhigh_cpu;
65 dma_addr_t dmadesc_fbhigh_dma;
66 struct pxafb_dma_descriptor * dmadesc_palette_cpu;
67 dma_addr_t dmadesc_palette_dma;
68
69 dma_addr_t fdadr0;
70 dma_addr_t fdadr1;
71 90
72 u_int lccr0; 91 u_int lccr0;
73 u_int lccr3; 92 u_int lccr3;
@@ -81,6 +100,7 @@ struct pxafb_info {
81 u_int reg_lccr2; 100 u_int reg_lccr2;
82 u_int reg_lccr3; 101 u_int reg_lccr3;
83 u_int reg_lccr4; 102 u_int reg_lccr4;
103 u_int reg_cmdcr;
84 104
85 unsigned long hsync_time; 105 unsigned long hsync_time;
86 106
@@ -90,6 +110,16 @@ struct pxafb_info {
90 wait_queue_head_t ctrlr_wait; 110 wait_queue_head_t ctrlr_wait;
91 struct work_struct task; 111 struct work_struct task;
92 112
113 struct completion disable_done;
114
115#ifdef CONFIG_FB_PXA_SMARTPANEL
116 uint16_t *smart_cmds;
117 size_t n_smart_cmds;
118 struct completion command_done;
119 struct completion refresh_done;
120 struct task_struct *smart_thread;
121#endif
122
93#ifdef CONFIG_CPU_FREQ 123#ifdef CONFIG_CPU_FREQ
94 struct notifier_block freq_transition; 124 struct notifier_block freq_transition;
95 struct notifier_block freq_policy; 125 struct notifier_block freq_policy;
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index b535483bc556..13866789b356 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -80,19 +80,51 @@ static void add_status(struct virtio_device *dev, unsigned status)
80 dev->config->set_status(dev, dev->config->get_status(dev) | status); 80 dev->config->set_status(dev, dev->config->get_status(dev) | status);
81} 81}
82 82
83void virtio_check_driver_offered_feature(const struct virtio_device *vdev,
84 unsigned int fbit)
85{
86 unsigned int i;
87 struct virtio_driver *drv = container_of(vdev->dev.driver,
88 struct virtio_driver, driver);
89
90 for (i = 0; i < drv->feature_table_size; i++)
91 if (drv->feature_table[i] == fbit)
92 return;
93 BUG();
94}
95EXPORT_SYMBOL_GPL(virtio_check_driver_offered_feature);
96
83static int virtio_dev_probe(struct device *_d) 97static int virtio_dev_probe(struct device *_d)
84{ 98{
85 int err; 99 int err, i;
86 struct virtio_device *dev = container_of(_d,struct virtio_device,dev); 100 struct virtio_device *dev = container_of(_d,struct virtio_device,dev);
87 struct virtio_driver *drv = container_of(dev->dev.driver, 101 struct virtio_driver *drv = container_of(dev->dev.driver,
88 struct virtio_driver, driver); 102 struct virtio_driver, driver);
103 u32 device_features;
89 104
105 /* We have a driver! */
90 add_status(dev, VIRTIO_CONFIG_S_DRIVER); 106 add_status(dev, VIRTIO_CONFIG_S_DRIVER);
107
108 /* Figure out what features the device supports. */
109 device_features = dev->config->get_features(dev);
110
111 /* Features supported by both device and driver into dev->features. */
112 memset(dev->features, 0, sizeof(dev->features));
113 for (i = 0; i < drv->feature_table_size; i++) {
114 unsigned int f = drv->feature_table[i];
115 BUG_ON(f >= 32);
116 if (device_features & (1 << f))
117 set_bit(f, dev->features);
118 }
119
91 err = drv->probe(dev); 120 err = drv->probe(dev);
92 if (err) 121 if (err)
93 add_status(dev, VIRTIO_CONFIG_S_FAILED); 122 add_status(dev, VIRTIO_CONFIG_S_FAILED);
94 else 123 else {
95 add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK); 124 add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
125 /* They should never have set feature bits beyond 32 */
126 dev->config->set_features(dev, dev->features[0]);
127 }
96 return err; 128 return err;
97} 129}
98 130
@@ -114,6 +146,8 @@ static int virtio_dev_remove(struct device *_d)
114 146
115int register_virtio_driver(struct virtio_driver *driver) 147int register_virtio_driver(struct virtio_driver *driver)
116{ 148{
149 /* Catch this early. */
150 BUG_ON(driver->feature_table_size && !driver->feature_table);
117 driver->driver.bus = &virtio_bus; 151 driver->driver.bus = &virtio_bus;
118 driver->driver.probe = virtio_dev_probe; 152 driver->driver.probe = virtio_dev_probe;
119 driver->driver.remove = virtio_dev_remove; 153 driver->driver.remove = virtio_dev_remove;
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 0b3efc31ee6d..bfef604160d1 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -155,9 +155,9 @@ static void virtballoon_changed(struct virtio_device *vdev)
155static inline s64 towards_target(struct virtio_balloon *vb) 155static inline s64 towards_target(struct virtio_balloon *vb)
156{ 156{
157 u32 v; 157 u32 v;
158 __virtio_config_val(vb->vdev, 158 vb->vdev->config->get(vb->vdev,
159 offsetof(struct virtio_balloon_config, num_pages), 159 offsetof(struct virtio_balloon_config, num_pages),
160 &v); 160 &v, sizeof(v));
161 return v - vb->num_pages; 161 return v - vb->num_pages;
162} 162}
163 163
@@ -227,7 +227,7 @@ static int virtballoon_probe(struct virtio_device *vdev)
227 } 227 }
228 228
229 vb->tell_host_first 229 vb->tell_host_first
230 = vdev->config->feature(vdev, VIRTIO_BALLOON_F_MUST_TELL_HOST); 230 = virtio_has_feature(vdev, VIRTIO_BALLOON_F_MUST_TELL_HOST);
231 231
232 return 0; 232 return 0;
233 233
@@ -259,7 +259,11 @@ static void virtballoon_remove(struct virtio_device *vdev)
259 kfree(vb); 259 kfree(vb);
260} 260}
261 261
262static unsigned int features[] = { VIRTIO_BALLOON_F_MUST_TELL_HOST };
263
262static struct virtio_driver virtio_balloon = { 264static struct virtio_driver virtio_balloon = {
265 .feature_table = features,
266 .feature_table_size = ARRAY_SIZE(features),
263 .driver.name = KBUILD_MODNAME, 267 .driver.name = KBUILD_MODNAME,
264 .driver.owner = THIS_MODULE, 268 .driver.owner = THIS_MODULE,
265 .id_table = id_table, 269 .id_table = id_table,
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
index c0df924766a7..27e9fc9117cd 100644
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -87,23 +87,22 @@ static struct virtio_pci_device *to_vp_device(struct virtio_device *vdev)
87 return container_of(vdev, struct virtio_pci_device, vdev); 87 return container_of(vdev, struct virtio_pci_device, vdev);
88} 88}
89 89
90/* virtio config->feature() implementation */ 90/* virtio config->get_features() implementation */
91static bool vp_feature(struct virtio_device *vdev, unsigned bit) 91static u32 vp_get_features(struct virtio_device *vdev)
92{
93 struct virtio_pci_device *vp_dev = to_vp_device(vdev);
94
95 /* When someone needs more than 32 feature bits, we'll need to
96 * steal a bit to indicate that the rest are somewhere else. */
97 return ioread32(vp_dev->ioaddr + VIRTIO_PCI_HOST_FEATURES);
98}
99
100/* virtio config->set_features() implementation */
101static void vp_set_features(struct virtio_device *vdev, u32 features)
92{ 102{
93 struct virtio_pci_device *vp_dev = to_vp_device(vdev); 103 struct virtio_pci_device *vp_dev = to_vp_device(vdev);
94 u32 mask;
95
96 /* Since this function is supposed to have the side effect of
97 * enabling a queried feature, we simulate that by doing a read
98 * from the host feature bitmask and then writing to the guest
99 * feature bitmask */
100 mask = ioread32(vp_dev->ioaddr + VIRTIO_PCI_HOST_FEATURES);
101 if (mask & (1 << bit)) {
102 mask |= (1 << bit);
103 iowrite32(mask, vp_dev->ioaddr + VIRTIO_PCI_GUEST_FEATURES);
104 }
105 104
106 return !!(mask & (1 << bit)); 105 iowrite32(features, vp_dev->ioaddr + VIRTIO_PCI_GUEST_FEATURES);
107} 106}
108 107
109/* virtio config->get() implementation */ 108/* virtio config->get() implementation */
@@ -145,14 +144,14 @@ static void vp_set_status(struct virtio_device *vdev, u8 status)
145 struct virtio_pci_device *vp_dev = to_vp_device(vdev); 144 struct virtio_pci_device *vp_dev = to_vp_device(vdev);
146 /* We should never be setting status to 0. */ 145 /* We should never be setting status to 0. */
147 BUG_ON(status == 0); 146 BUG_ON(status == 0);
148 return iowrite8(status, vp_dev->ioaddr + VIRTIO_PCI_STATUS); 147 iowrite8(status, vp_dev->ioaddr + VIRTIO_PCI_STATUS);
149} 148}
150 149
151static void vp_reset(struct virtio_device *vdev) 150static void vp_reset(struct virtio_device *vdev)
152{ 151{
153 struct virtio_pci_device *vp_dev = to_vp_device(vdev); 152 struct virtio_pci_device *vp_dev = to_vp_device(vdev);
154 /* 0 status means a reset. */ 153 /* 0 status means a reset. */
155 return iowrite8(0, vp_dev->ioaddr + VIRTIO_PCI_STATUS); 154 iowrite8(0, vp_dev->ioaddr + VIRTIO_PCI_STATUS);
156} 155}
157 156
158/* the notify function used when creating a virt queue */ 157/* the notify function used when creating a virt queue */
@@ -293,7 +292,6 @@ static void vp_del_vq(struct virtqueue *vq)
293} 292}
294 293
295static struct virtio_config_ops virtio_pci_config_ops = { 294static struct virtio_config_ops virtio_pci_config_ops = {
296 .feature = vp_feature,
297 .get = vp_get, 295 .get = vp_get,
298 .set = vp_set, 296 .set = vp_set,
299 .get_status = vp_get_status, 297 .get_status = vp_get_status,
@@ -301,6 +299,8 @@ static struct virtio_config_ops virtio_pci_config_ops = {
301 .reset = vp_reset, 299 .reset = vp_reset,
302 .find_vq = vp_find_vq, 300 .find_vq = vp_find_vq,
303 .del_vq = vp_del_vq, 301 .del_vq = vp_del_vq,
302 .get_features = vp_get_features,
303 .set_features = vp_set_features,
304}; 304};
305 305
306/* the PCI probing function */ 306/* the PCI probing function */
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index c2fa5c630813..937a49d6772c 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -184,6 +184,11 @@ static void *vring_get_buf(struct virtqueue *_vq, unsigned int *len)
184 184
185 START_USE(vq); 185 START_USE(vq);
186 186
187 if (unlikely(vq->broken)) {
188 END_USE(vq);
189 return NULL;
190 }
191
187 if (!more_used(vq)) { 192 if (!more_used(vq)) {
188 pr_debug("No more buffers in queue\n"); 193 pr_debug("No more buffers in queue\n");
189 END_USE(vq); 194 END_USE(vq);
diff --git a/drivers/w1/w1_log.h b/drivers/w1/w1_log.h
index fe6bdf43380f..e6ab7cf08f88 100644
--- a/drivers/w1/w1_log.h
+++ b/drivers/w1/w1_log.h
@@ -30,7 +30,7 @@
30# define assert(expr) \ 30# define assert(expr) \
31 if(unlikely(!(expr))) { \ 31 if(unlikely(!(expr))) { \
32 printk(KERN_ERR "Assertion failed! %s,%s,%s,line=%d\n", \ 32 printk(KERN_ERR "Assertion failed! %s,%s,%s,line=%d\n", \
33 #expr,__FILE__,__FUNCTION__,__LINE__); \ 33 #expr, __FILE__, __func__, __LINE__); \
34 } 34 }
35#endif 35#endif
36 36
diff --git a/fs/Kconfig b/fs/Kconfig
index 2e43d46f65d6..cf12c403b8c7 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -1005,7 +1005,8 @@ config TMPFS_POSIX_ACL
1005 1005
1006config HUGETLBFS 1006config HUGETLBFS
1007 bool "HugeTLB file system support" 1007 bool "HugeTLB file system support"
1008 depends on X86 || IA64 || PPC64 || SPARC64 || (SUPERH && MMU) || BROKEN 1008 depends on X86 || IA64 || PPC64 || SPARC64 || (SUPERH && MMU) || \
1009 (S390 && 64BIT) || BROKEN
1009 help 1010 help
1010 hugetlbfs is a filesystem backing for HugeTLB pages, based on 1011 hugetlbfs is a filesystem backing for HugeTLB pages, based on
1011 ramfs. For architectures that support it, say Y here and read 1012 ramfs. For architectures that support it, say Y here and read
diff --git a/fs/adfs/adfs.h b/fs/adfs/adfs.h
index 936f2af39c43..831157502d5a 100644
--- a/fs/adfs/adfs.h
+++ b/fs/adfs/adfs.h
@@ -75,7 +75,7 @@ extern unsigned int adfs_map_free(struct super_block *sb);
75/* Misc */ 75/* Misc */
76void __adfs_error(struct super_block *sb, const char *function, 76void __adfs_error(struct super_block *sb, const char *function,
77 const char *fmt, ...); 77 const char *fmt, ...);
78#define adfs_error(sb, fmt...) __adfs_error(sb, __FUNCTION__, fmt) 78#define adfs_error(sb, fmt...) __adfs_error(sb, __func__, fmt)
79 79
80/* super.c */ 80/* super.c */
81 81
diff --git a/fs/affs/file.c b/fs/affs/file.c
index e87ede608f77..1a4f092f24ef 100644
--- a/fs/affs/file.c
+++ b/fs/affs/file.c
@@ -539,7 +539,7 @@ affs_extent_file_ofs(struct inode *inode, u32 newsize)
539 tmp = min(bsize - boff, newsize - size); 539 tmp = min(bsize - boff, newsize - size);
540 BUG_ON(boff + tmp > bsize || tmp > bsize); 540 BUG_ON(boff + tmp > bsize || tmp > bsize);
541 memset(AFFS_DATA(bh) + boff, 0, tmp); 541 memset(AFFS_DATA(bh) + boff, 0, tmp);
542 AFFS_DATA_HEAD(bh)->size = cpu_to_be32(be32_to_cpu(AFFS_DATA_HEAD(bh)->size) + tmp); 542 be32_add_cpu(&AFFS_DATA_HEAD(bh)->size, tmp);
543 affs_fix_checksum(sb, bh); 543 affs_fix_checksum(sb, bh);
544 mark_buffer_dirty_inode(bh, inode); 544 mark_buffer_dirty_inode(bh, inode);
545 size += tmp; 545 size += tmp;
@@ -680,7 +680,7 @@ static int affs_write_end_ofs(struct file *file, struct address_space *mapping,
680 tmp = min(bsize - boff, to - from); 680 tmp = min(bsize - boff, to - from);
681 BUG_ON(boff + tmp > bsize || tmp > bsize); 681 BUG_ON(boff + tmp > bsize || tmp > bsize);
682 memcpy(AFFS_DATA(bh) + boff, data + from, tmp); 682 memcpy(AFFS_DATA(bh) + boff, data + from, tmp);
683 AFFS_DATA_HEAD(bh)->size = cpu_to_be32(be32_to_cpu(AFFS_DATA_HEAD(bh)->size) + tmp); 683 be32_add_cpu(&AFFS_DATA_HEAD(bh)->size, tmp);
684 affs_fix_checksum(sb, bh); 684 affs_fix_checksum(sb, bh);
685 mark_buffer_dirty_inode(bh, inode); 685 mark_buffer_dirty_inode(bh, inode);
686 written += tmp; 686 written += tmp;
diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index b58af8f18bc4..dfda03d4397d 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -140,7 +140,7 @@ static inline void afs_dir_check_page(struct inode *dir, struct page *page)
140 140
141 if (page->index == 0 && qty != ntohs(dbuf->blocks[0].pagehdr.npages)) { 141 if (page->index == 0 && qty != ntohs(dbuf->blocks[0].pagehdr.npages)) {
142 printk("kAFS: %s(%lu): wrong number of dir blocks %d!=%hu\n", 142 printk("kAFS: %s(%lu): wrong number of dir blocks %d!=%hu\n",
143 __FUNCTION__, dir->i_ino, qty, 143 __func__, dir->i_ino, qty,
144 ntohs(dbuf->blocks[0].pagehdr.npages)); 144 ntohs(dbuf->blocks[0].pagehdr.npages));
145 goto error; 145 goto error;
146 } 146 }
@@ -159,7 +159,7 @@ static inline void afs_dir_check_page(struct inode *dir, struct page *page)
159 for (tmp = 0; tmp < qty; tmp++) { 159 for (tmp = 0; tmp < qty; tmp++) {
160 if (dbuf->blocks[tmp].pagehdr.magic != AFS_DIR_MAGIC) { 160 if (dbuf->blocks[tmp].pagehdr.magic != AFS_DIR_MAGIC) {
161 printk("kAFS: %s(%lu): bad magic %d/%d is %04hx\n", 161 printk("kAFS: %s(%lu): bad magic %d/%d is %04hx\n",
162 __FUNCTION__, dir->i_ino, tmp, qty, 162 __func__, dir->i_ino, tmp, qty,
163 ntohs(dbuf->blocks[tmp].pagehdr.magic)); 163 ntohs(dbuf->blocks[tmp].pagehdr.magic));
164 goto error; 164 goto error;
165 } 165 }
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index eec41c76de72..7102824ba847 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -757,8 +757,8 @@ void _dbprintk(const char *fmt, ...)
757{ 757{
758} 758}
759 759
760#define kenter(FMT,...) dbgprintk("==> %s("FMT")",__FUNCTION__ ,##__VA_ARGS__) 760#define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
761#define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__FUNCTION__ ,##__VA_ARGS__) 761#define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
762#define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__) 762#define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
763 763
764 764
@@ -791,8 +791,8 @@ do { \
791} while (0) 791} while (0)
792 792
793#else 793#else
794#define _enter(FMT,...) _dbprintk("==> %s("FMT")",__FUNCTION__ ,##__VA_ARGS__) 794#define _enter(FMT,...) _dbprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
795#define _leave(FMT,...) _dbprintk("<== %s()"FMT"",__FUNCTION__ ,##__VA_ARGS__) 795#define _leave(FMT,...) _dbprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
796#define _debug(FMT,...) _dbprintk(" "FMT ,##__VA_ARGS__) 796#define _debug(FMT,...) _dbprintk(" "FMT ,##__VA_ARGS__)
797#endif 797#endif
798 798
diff --git a/fs/aio.c b/fs/aio.c
index 99c2352906a0..b5253e77eb2f 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -1078,9 +1078,7 @@ static void timeout_func(unsigned long data)
1078 1078
1079static inline void init_timeout(struct aio_timeout *to) 1079static inline void init_timeout(struct aio_timeout *to)
1080{ 1080{
1081 init_timer(&to->timer); 1081 setup_timer_on_stack(&to->timer, timeout_func, (unsigned long) to);
1082 to->timer.data = (unsigned long)to;
1083 to->timer.function = timeout_func;
1084 to->timed_out = 0; 1082 to->timed_out = 0;
1085 to->p = current; 1083 to->p = current;
1086} 1084}
@@ -1213,6 +1211,7 @@ retry:
1213 if (timeout) 1211 if (timeout)
1214 clear_timeout(&to); 1212 clear_timeout(&to);
1215out: 1213out:
1214 destroy_timer_on_stack(&to.timer);
1216 return i ? i : ret; 1215 return i ? i : ret;
1217} 1216}
1218 1217
diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c
index f42be069e085..977ef208c051 100644
--- a/fs/anon_inodes.c
+++ b/fs/anon_inodes.c
@@ -57,9 +57,6 @@ static struct dentry_operations anon_inodefs_dentry_operations = {
57 * anonymous inode, and a dentry that describe the "class" 57 * anonymous inode, and a dentry that describe the "class"
58 * of the file 58 * of the file
59 * 59 *
60 * @pfd: [out] pointer to the file descriptor
61 * @dpinode: [out] pointer to the inode
62 * @pfile: [out] pointer to the file struct
63 * @name: [in] name of the "class" of the new file 60 * @name: [in] name of the "class" of the new file
64 * @fops [in] file operations for the new file 61 * @fops [in] file operations for the new file
65 * @priv [in] private data for the new file (will be file's private_data) 62 * @priv [in] private data for the new file (will be file's private_data)
@@ -68,10 +65,9 @@ static struct dentry_operations anon_inodefs_dentry_operations = {
68 * that do not need to have a full-fledged inode in order to operate correctly. 65 * that do not need to have a full-fledged inode in order to operate correctly.
69 * All the files created with anon_inode_getfd() will share a single inode, 66 * All the files created with anon_inode_getfd() will share a single inode,
70 * hence saving memory and avoiding code duplication for the file/inode/dentry 67 * hence saving memory and avoiding code duplication for the file/inode/dentry
71 * setup. 68 * setup. Returns new descriptor or -error.
72 */ 69 */
73int anon_inode_getfd(int *pfd, struct inode **pinode, struct file **pfile, 70int anon_inode_getfd(const char *name, const struct file_operations *fops,
74 const char *name, const struct file_operations *fops,
75 void *priv) 71 void *priv)
76{ 72{
77 struct qstr this; 73 struct qstr this;
@@ -125,10 +121,7 @@ int anon_inode_getfd(int *pfd, struct inode **pinode, struct file **pfile,
125 121
126 fd_install(fd, file); 122 fd_install(fd, file);
127 123
128 *pfd = fd; 124 return fd;
129 *pinode = anon_inode_inode;
130 *pfile = file;
131 return 0;
132 125
133err_dput: 126err_dput:
134 dput(dentry); 127 dput(dentry);
diff --git a/fs/autofs4/autofs_i.h b/fs/autofs4/autofs_i.h
index 2d4ae40718d9..c3d352d7fa93 100644
--- a/fs/autofs4/autofs_i.h
+++ b/fs/autofs4/autofs_i.h
@@ -35,7 +35,7 @@
35/* #define DEBUG */ 35/* #define DEBUG */
36 36
37#ifdef DEBUG 37#ifdef DEBUG
38#define DPRINTK(fmt,args...) do { printk(KERN_DEBUG "pid %d: %s: " fmt "\n" , current->pid , __FUNCTION__ , ##args); } while(0) 38#define DPRINTK(fmt,args...) do { printk(KERN_DEBUG "pid %d: %s: " fmt "\n" , current->pid , __func__ , ##args); } while(0)
39#else 39#else
40#define DPRINTK(fmt,args...) do {} while(0) 40#define DPRINTK(fmt,args...) do {} while(0)
41#endif 41#endif
diff --git a/fs/autofs4/expire.c b/fs/autofs4/expire.c
index d96e5c14a9ca..894fee54d4d8 100644
--- a/fs/autofs4/expire.c
+++ b/fs/autofs4/expire.c
@@ -73,8 +73,8 @@ static int autofs4_mount_busy(struct vfsmount *mnt, struct dentry *dentry)
73 status = 0; 73 status = 0;
74done: 74done:
75 DPRINTK("returning = %d", status); 75 DPRINTK("returning = %d", status);
76 mntput(mnt);
77 dput(dentry); 76 dput(dentry);
77 mntput(mnt);
78 return status; 78 return status;
79} 79}
80 80
@@ -333,7 +333,7 @@ static struct dentry *autofs4_expire_indirect(struct super_block *sb,
333 /* Can we expire this guy */ 333 /* Can we expire this guy */
334 if (autofs4_can_expire(dentry, timeout, do_now)) { 334 if (autofs4_can_expire(dentry, timeout, do_now)) {
335 expired = dentry; 335 expired = dentry;
336 break; 336 goto found;
337 } 337 }
338 goto next; 338 goto next;
339 } 339 }
@@ -352,7 +352,7 @@ static struct dentry *autofs4_expire_indirect(struct super_block *sb,
352 inf->flags |= AUTOFS_INF_EXPIRING; 352 inf->flags |= AUTOFS_INF_EXPIRING;
353 spin_unlock(&sbi->fs_lock); 353 spin_unlock(&sbi->fs_lock);
354 expired = dentry; 354 expired = dentry;
355 break; 355 goto found;
356 } 356 }
357 spin_unlock(&sbi->fs_lock); 357 spin_unlock(&sbi->fs_lock);
358 /* 358 /*
@@ -363,7 +363,7 @@ static struct dentry *autofs4_expire_indirect(struct super_block *sb,
363 expired = autofs4_check_leaves(mnt, dentry, timeout, do_now); 363 expired = autofs4_check_leaves(mnt, dentry, timeout, do_now);
364 if (expired) { 364 if (expired) {
365 dput(dentry); 365 dput(dentry);
366 break; 366 goto found;
367 } 367 }
368 } 368 }
369next: 369next:
@@ -371,18 +371,16 @@ next:
371 spin_lock(&dcache_lock); 371 spin_lock(&dcache_lock);
372 next = next->next; 372 next = next->next;
373 } 373 }
374
375 if (expired) {
376 DPRINTK("returning %p %.*s",
377 expired, (int)expired->d_name.len, expired->d_name.name);
378 spin_lock(&dcache_lock);
379 list_move(&expired->d_parent->d_subdirs, &expired->d_u.d_child);
380 spin_unlock(&dcache_lock);
381 return expired;
382 }
383 spin_unlock(&dcache_lock); 374 spin_unlock(&dcache_lock);
384
385 return NULL; 375 return NULL;
376
377found:
378 DPRINTK("returning %p %.*s",
379 expired, (int)expired->d_name.len, expired->d_name.name);
380 spin_lock(&dcache_lock);
381 list_move(&expired->d_parent->d_subdirs, &expired->d_u.d_child);
382 spin_unlock(&dcache_lock);
383 return expired;
386} 384}
387 385
388/* Perform an expiry operation */ 386/* Perform an expiry operation */
diff --git a/fs/autofs4/root.c b/fs/autofs4/root.c
index aa4c5ff8a40d..edf5b6bddb52 100644
--- a/fs/autofs4/root.c
+++ b/fs/autofs4/root.c
@@ -146,17 +146,17 @@ static int autofs4_dir_open(struct inode *inode, struct file *file)
146 146
147 if (d_mountpoint(dentry)) { 147 if (d_mountpoint(dentry)) {
148 struct file *fp = NULL; 148 struct file *fp = NULL;
149 struct vfsmount *fp_mnt = mntget(mnt); 149 struct path fp_path = { .dentry = dentry, .mnt = mnt };
150 struct dentry *fp_dentry = dget(dentry);
151 150
152 if (!autofs4_follow_mount(&fp_mnt, &fp_dentry)) { 151 path_get(&fp_path);
153 dput(fp_dentry); 152
154 mntput(fp_mnt); 153 if (!autofs4_follow_mount(&fp_path.mnt, &fp_path.dentry)) {
154 path_put(&fp_path);
155 dcache_dir_close(inode, file); 155 dcache_dir_close(inode, file);
156 goto out; 156 goto out;
157 } 157 }
158 158
159 fp = dentry_open(fp_dentry, fp_mnt, file->f_flags); 159 fp = dentry_open(fp_path.dentry, fp_path.mnt, file->f_flags);
160 status = PTR_ERR(fp); 160 status = PTR_ERR(fp);
161 if (IS_ERR(fp)) { 161 if (IS_ERR(fp)) {
162 dcache_dir_close(inode, file); 162 dcache_dir_close(inode, file);
@@ -242,7 +242,8 @@ static int try_to_fill_dentry(struct dentry *dentry, int flags)
242{ 242{
243 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); 243 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
244 struct autofs_info *ino = autofs4_dentry_ino(dentry); 244 struct autofs_info *ino = autofs4_dentry_ino(dentry);
245 int status = 0; 245 struct dentry *new;
246 int status;
246 247
247 /* Block on any pending expiry here; invalidate the dentry 248 /* Block on any pending expiry here; invalidate the dentry
248 when expiration is done to trigger mount request with a new 249 when expiration is done to trigger mount request with a new
@@ -318,7 +319,28 @@ static int try_to_fill_dentry(struct dentry *dentry, int flags)
318 spin_lock(&dentry->d_lock); 319 spin_lock(&dentry->d_lock);
319 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING; 320 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
320 spin_unlock(&dentry->d_lock); 321 spin_unlock(&dentry->d_lock);
321 return status; 322
323 /*
324 * The dentry that is passed in from lookup may not be the one
325 * we end up using, as mkdir can create a new one. If this
326 * happens, and another process tries the lookup at the same time,
327 * it will set the PENDING flag on this new dentry, but add itself
328 * to our waitq. Then, if after the lookup succeeds, the first
329 * process that requested the mount performs another lookup of the
330 * same directory, it will show up as still pending! So, we need
331 * to redo the lookup here and clear pending on that dentry.
332 */
333 if (d_unhashed(dentry)) {
334 new = d_lookup(dentry->d_parent, &dentry->d_name);
335 if (new) {
336 spin_lock(&new->d_lock);
337 new->d_flags &= ~DCACHE_AUTOFS_PENDING;
338 spin_unlock(&new->d_lock);
339 dput(new);
340 }
341 }
342
343 return 0;
322} 344}
323 345
324/* For autofs direct mounts the follow link triggers the mount */ 346/* For autofs direct mounts the follow link triggers the mount */
diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
index 1fe28e4754c2..75e5955c3f6d 100644
--- a/fs/autofs4/waitq.c
+++ b/fs/autofs4/waitq.c
@@ -171,7 +171,7 @@ static int autofs4_getpath(struct autofs_sb_info *sbi,
171 for (tmp = dentry ; tmp != root ; tmp = tmp->d_parent) 171 for (tmp = dentry ; tmp != root ; tmp = tmp->d_parent)
172 len += tmp->d_name.len + 1; 172 len += tmp->d_name.len + 1;
173 173
174 if (--len > NAME_MAX) { 174 if (!len || --len > NAME_MAX) {
175 spin_unlock(&dcache_lock); 175 spin_unlock(&dcache_lock);
176 return 0; 176 return 0;
177 } 177 }
diff --git a/fs/bfs/bfs.h b/fs/bfs/bfs.h
index 71faf4d23908..70f5d3a8eede 100644
--- a/fs/bfs/bfs.h
+++ b/fs/bfs/bfs.h
@@ -42,7 +42,7 @@ static inline struct bfs_inode_info *BFS_I(struct inode *inode)
42 42
43 43
44#define printf(format, args...) \ 44#define printf(format, args...) \
45 printk(KERN_ERR "BFS-fs: %s(): " format, __FUNCTION__, ## args) 45 printk(KERN_ERR "BFS-fs: %s(): " format, __func__, ## args)
46 46
47/* inode.c */ 47/* inode.c */
48extern struct inode *bfs_iget(struct super_block *sb, unsigned long ino); 48extern struct inode *bfs_iget(struct super_block *sb, unsigned long ino);
diff --git a/fs/buffer.c b/fs/buffer.c
index 189efa4efc6e..a073f3f4f013 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -1101,7 +1101,7 @@ grow_buffers(struct block_device *bdev, sector_t block, int size)
1101 1101
1102 printk(KERN_ERR "%s: requested out-of-range block %llu for " 1102 printk(KERN_ERR "%s: requested out-of-range block %llu for "
1103 "device %s\n", 1103 "device %s\n",
1104 __FUNCTION__, (unsigned long long)block, 1104 __func__, (unsigned long long)block,
1105 bdevname(bdev, b)); 1105 bdevname(bdev, b));
1106 return -EIO; 1106 return -EIO;
1107 } 1107 }
diff --git a/fs/compat.c b/fs/compat.c
index 2ce4456aad30..332a869d2c53 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -24,6 +24,7 @@
24#include <linux/fcntl.h> 24#include <linux/fcntl.h>
25#include <linux/namei.h> 25#include <linux/namei.h>
26#include <linux/file.h> 26#include <linux/file.h>
27#include <linux/fdtable.h>
27#include <linux/vfs.h> 28#include <linux/vfs.h>
28#include <linux/ioctl.h> 29#include <linux/ioctl.h>
29#include <linux/init.h> 30#include <linux/init.h>
@@ -1634,7 +1635,7 @@ sticky:
1634 return ret; 1635 return ret;
1635} 1636}
1636 1637
1637#ifdef TIF_RESTORE_SIGMASK 1638#ifdef HAVE_SET_RESTORE_SIGMASK
1638asmlinkage long compat_sys_pselect7(int n, compat_ulong_t __user *inp, 1639asmlinkage long compat_sys_pselect7(int n, compat_ulong_t __user *inp,
1639 compat_ulong_t __user *outp, compat_ulong_t __user *exp, 1640 compat_ulong_t __user *outp, compat_ulong_t __user *exp,
1640 struct compat_timespec __user *tsp, compat_sigset_t __user *sigmask, 1641 struct compat_timespec __user *tsp, compat_sigset_t __user *sigmask,
@@ -1720,7 +1721,7 @@ sticky:
1720 if (sigmask) { 1721 if (sigmask) {
1721 memcpy(&current->saved_sigmask, &sigsaved, 1722 memcpy(&current->saved_sigmask, &sigsaved,
1722 sizeof(sigsaved)); 1723 sizeof(sigsaved));
1723 set_thread_flag(TIF_RESTORE_SIGMASK); 1724 set_restore_sigmask();
1724 } 1725 }
1725 } else if (sigmask) 1726 } else if (sigmask)
1726 sigprocmask(SIG_SETMASK, &sigsaved, NULL); 1727 sigprocmask(SIG_SETMASK, &sigsaved, NULL);
@@ -1791,7 +1792,7 @@ asmlinkage long compat_sys_ppoll(struct pollfd __user *ufds,
1791 if (sigmask) { 1792 if (sigmask) {
1792 memcpy(&current->saved_sigmask, &sigsaved, 1793 memcpy(&current->saved_sigmask, &sigsaved,
1793 sizeof(sigsaved)); 1794 sizeof(sigsaved));
1794 set_thread_flag(TIF_RESTORE_SIGMASK); 1795 set_restore_sigmask();
1795 } 1796 }
1796 ret = -ERESTARTNOHAND; 1797 ret = -ERESTARTNOHAND;
1797 } else if (sigmask) 1798 } else if (sigmask)
@@ -1825,7 +1826,7 @@ sticky:
1825 1826
1826 return ret; 1827 return ret;
1827} 1828}
1828#endif /* TIF_RESTORE_SIGMASK */ 1829#endif /* HAVE_SET_RESTORE_SIGMASK */
1829 1830
1830#if defined(CONFIG_NFSD) || defined(CONFIG_NFSD_MODULE) 1831#if defined(CONFIG_NFSD) || defined(CONFIG_NFSD_MODULE)
1831/* Stuff for NFS server syscalls... */ 1832/* Stuff for NFS server syscalls... */
@@ -2080,7 +2081,7 @@ long asmlinkage compat_sys_nfsservctl(int cmd, void *notused, void *notused2)
2080 2081
2081#ifdef CONFIG_EPOLL 2082#ifdef CONFIG_EPOLL
2082 2083
2083#ifdef TIF_RESTORE_SIGMASK 2084#ifdef HAVE_SET_RESTORE_SIGMASK
2084asmlinkage long compat_sys_epoll_pwait(int epfd, 2085asmlinkage long compat_sys_epoll_pwait(int epfd,
2085 struct compat_epoll_event __user *events, 2086 struct compat_epoll_event __user *events,
2086 int maxevents, int timeout, 2087 int maxevents, int timeout,
@@ -2117,14 +2118,14 @@ asmlinkage long compat_sys_epoll_pwait(int epfd,
2117 if (err == -EINTR) { 2118 if (err == -EINTR) {
2118 memcpy(&current->saved_sigmask, &sigsaved, 2119 memcpy(&current->saved_sigmask, &sigsaved,
2119 sizeof(sigsaved)); 2120 sizeof(sigsaved));
2120 set_thread_flag(TIF_RESTORE_SIGMASK); 2121 set_restore_sigmask();
2121 } else 2122 } else
2122 sigprocmask(SIG_SETMASK, &sigsaved, NULL); 2123 sigprocmask(SIG_SETMASK, &sigsaved, NULL);
2123 } 2124 }
2124 2125
2125 return err; 2126 return err;
2126} 2127}
2127#endif /* TIF_RESTORE_SIGMASK */ 2128#endif /* HAVE_SET_RESTORE_SIGMASK */
2128 2129
2129#endif /* CONFIG_EPOLL */ 2130#endif /* CONFIG_EPOLL */
2130 2131
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index c6e72aebd16b..97dba0d92348 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -1046,14 +1046,14 @@ static int vt_check(struct file *file)
1046 struct inode *inode = file->f_path.dentry->d_inode; 1046 struct inode *inode = file->f_path.dentry->d_inode;
1047 struct vc_data *vc; 1047 struct vc_data *vc;
1048 1048
1049 if (file->f_op->ioctl != tty_ioctl) 1049 if (file->f_op->unlocked_ioctl != tty_ioctl)
1050 return -EINVAL; 1050 return -EINVAL;
1051 1051
1052 tty = (struct tty_struct *)file->private_data; 1052 tty = (struct tty_struct *)file->private_data;
1053 if (tty_paranoia_check(tty, inode, "tty_ioctl")) 1053 if (tty_paranoia_check(tty, inode, "tty_ioctl"))
1054 return -EINVAL; 1054 return -EINVAL;
1055 1055
1056 if (tty->driver->ioctl != vt_ioctl) 1056 if (tty->ops->ioctl != vt_ioctl)
1057 return -EINVAL; 1057 return -EINVAL;
1058 1058
1059 vc = (struct vc_data *)tty->driver_data; 1059 vc = (struct vc_data *)tty->driver_data;
diff --git a/fs/configfs/file.c b/fs/configfs/file.c
index 397cb503a180..2b6cb23dd14e 100644
--- a/fs/configfs/file.c
+++ b/fs/configfs/file.c
@@ -115,7 +115,7 @@ configfs_read_file(struct file *file, char __user *buf, size_t count, loff_t *pp
115 goto out; 115 goto out;
116 } 116 }
117 pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n", 117 pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n",
118 __FUNCTION__, count, *ppos, buffer->page); 118 __func__, count, *ppos, buffer->page);
119 retval = simple_read_from_buffer(buf, count, ppos, buffer->page, 119 retval = simple_read_from_buffer(buf, count, ppos, buffer->page,
120 buffer->count); 120 buffer->count);
121out: 121out:
diff --git a/fs/configfs/inode.c b/fs/configfs/inode.c
index 4c1ebff778ee..b9a1d810346d 100644
--- a/fs/configfs/inode.c
+++ b/fs/configfs/inode.c
@@ -47,7 +47,7 @@ static const struct address_space_operations configfs_aops = {
47 47
48static struct backing_dev_info configfs_backing_dev_info = { 48static struct backing_dev_info configfs_backing_dev_info = {
49 .ra_pages = 0, /* No readahead */ 49 .ra_pages = 0, /* No readahead */
50 .capabilities = BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_WRITEBACK, 50 .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK,
51}; 51};
52 52
53static const struct inode_operations configfs_inode_operations ={ 53static const struct inode_operations configfs_inode_operations ={
diff --git a/fs/configfs/mount.c b/fs/configfs/mount.c
index de3b31d0a37d..8421cea7d8c7 100644
--- a/fs/configfs/mount.c
+++ b/fs/configfs/mount.c
@@ -92,7 +92,7 @@ static int configfs_fill_super(struct super_block *sb, void *data, int silent)
92 92
93 root = d_alloc_root(inode); 93 root = d_alloc_root(inode);
94 if (!root) { 94 if (!root) {
95 pr_debug("%s: could not get root dentry!\n",__FUNCTION__); 95 pr_debug("%s: could not get root dentry!\n",__func__);
96 iput(inode); 96 iput(inode);
97 return -ENOMEM; 97 return -ENOMEM;
98 } 98 }
diff --git a/fs/configfs/symlink.c b/fs/configfs/symlink.c
index 78929ea84ff2..2a731ef5f305 100644
--- a/fs/configfs/symlink.c
+++ b/fs/configfs/symlink.c
@@ -210,13 +210,13 @@ static int configfs_get_target_path(struct config_item * item, struct config_ite
210 if (size > PATH_MAX) 210 if (size > PATH_MAX)
211 return -ENAMETOOLONG; 211 return -ENAMETOOLONG;
212 212
213 pr_debug("%s: depth = %d, size = %d\n", __FUNCTION__, depth, size); 213 pr_debug("%s: depth = %d, size = %d\n", __func__, depth, size);
214 214
215 for (s = path; depth--; s += 3) 215 for (s = path; depth--; s += 3)
216 strcpy(s,"../"); 216 strcpy(s,"../");
217 217
218 fill_item_path(target, path, size); 218 fill_item_path(target, path, size);
219 pr_debug("%s: path = '%s'\n", __FUNCTION__, path); 219 pr_debug("%s: path = '%s'\n", __func__, path);
220 220
221 return 0; 221 return 0;
222} 222}
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index fddffe4851f5..159a5efd6a8a 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -9,7 +9,7 @@
9 * 2 as published by the Free Software Foundation. 9 * 2 as published by the Free Software Foundation.
10 * 10 *
11 * debugfs is for people to use instead of /proc or /sys. 11 * debugfs is for people to use instead of /proc or /sys.
12 * See Documentation/DocBook/kernel-api for more details. 12 * See Documentation/DocBook/filesystems for more details.
13 * 13 *
14 */ 14 */
15 15
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index f120e1207874..285b64a8b06e 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -17,6 +17,8 @@
17#include <linux/namei.h> 17#include <linux/namei.h>
18#include <linux/mount.h> 18#include <linux/mount.h>
19#include <linux/tty.h> 19#include <linux/tty.h>
20#include <linux/mutex.h>
21#include <linux/idr.h>
20#include <linux/devpts_fs.h> 22#include <linux/devpts_fs.h>
21#include <linux/parser.h> 23#include <linux/parser.h>
22#include <linux/fsnotify.h> 24#include <linux/fsnotify.h>
@@ -26,6 +28,10 @@
26 28
27#define DEVPTS_DEFAULT_MODE 0600 29#define DEVPTS_DEFAULT_MODE 0600
28 30
31extern int pty_limit; /* Config limit on Unix98 ptys */
32static DEFINE_IDR(allocated_ptys);
33static DEFINE_MUTEX(allocated_ptys_lock);
34
29static struct vfsmount *devpts_mnt; 35static struct vfsmount *devpts_mnt;
30static struct dentry *devpts_root; 36static struct dentry *devpts_root;
31 37
@@ -171,9 +177,44 @@ static struct dentry *get_node(int num)
171 return lookup_one_len(s, root, sprintf(s, "%d", num)); 177 return lookup_one_len(s, root, sprintf(s, "%d", num));
172} 178}
173 179
180int devpts_new_index(void)
181{
182 int index;
183 int idr_ret;
184
185retry:
186 if (!idr_pre_get(&allocated_ptys, GFP_KERNEL)) {
187 return -ENOMEM;
188 }
189
190 mutex_lock(&allocated_ptys_lock);
191 idr_ret = idr_get_new(&allocated_ptys, NULL, &index);
192 if (idr_ret < 0) {
193 mutex_unlock(&allocated_ptys_lock);
194 if (idr_ret == -EAGAIN)
195 goto retry;
196 return -EIO;
197 }
198
199 if (index >= pty_limit) {
200 idr_remove(&allocated_ptys, index);
201 mutex_unlock(&allocated_ptys_lock);
202 return -EIO;
203 }
204 mutex_unlock(&allocated_ptys_lock);
205 return index;
206}
207
208void devpts_kill_index(int idx)
209{
210 mutex_lock(&allocated_ptys_lock);
211 idr_remove(&allocated_ptys, idx);
212 mutex_unlock(&allocated_ptys_lock);
213}
214
174int devpts_pty_new(struct tty_struct *tty) 215int devpts_pty_new(struct tty_struct *tty)
175{ 216{
176 int number = tty->index; 217 int number = tty->index; /* tty layer puts index from devpts_new_index() in here */
177 struct tty_driver *driver = tty->driver; 218 struct tty_driver *driver = tty->driver;
178 dev_t device = MKDEV(driver->major, driver->minor_start+number); 219 dev_t device = MKDEV(driver->major, driver->minor_start+number);
179 struct dentry *dentry; 220 struct dentry *dentry;
diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c
index b64e55e0515d..499e16759e96 100644
--- a/fs/dlm/lockspace.c
+++ b/fs/dlm/lockspace.c
@@ -200,7 +200,7 @@ int __init dlm_lockspace_init(void)
200 200
201 dlm_kset = kset_create_and_add("dlm", NULL, kernel_kobj); 201 dlm_kset = kset_create_and_add("dlm", NULL, kernel_kobj);
202 if (!dlm_kset) { 202 if (!dlm_kset) {
203 printk(KERN_WARNING "%s: can not create kset\n", __FUNCTION__); 203 printk(KERN_WARNING "%s: can not create kset\n", __func__);
204 return -ENOMEM; 204 return -ENOMEM;
205 } 205 }
206 return 0; 206 return 0;
diff --git a/fs/dnotify.c b/fs/dnotify.c
index 28d01ed66de0..676073b8dda5 100644
--- a/fs/dnotify.c
+++ b/fs/dnotify.c
@@ -20,6 +20,7 @@
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/spinlock.h> 21#include <linux/spinlock.h>
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/fdtable.h>
23 24
24int dir_notify_enable __read_mostly = 1; 25int dir_notify_enable __read_mostly = 1;
25 26
@@ -66,6 +67,7 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg)
66 struct dnotify_struct **prev; 67 struct dnotify_struct **prev;
67 struct inode *inode; 68 struct inode *inode;
68 fl_owner_t id = current->files; 69 fl_owner_t id = current->files;
70 struct file *f;
69 int error = 0; 71 int error = 0;
70 72
71 if ((arg & ~DN_MULTISHOT) == 0) { 73 if ((arg & ~DN_MULTISHOT) == 0) {
@@ -92,6 +94,15 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg)
92 prev = &odn->dn_next; 94 prev = &odn->dn_next;
93 } 95 }
94 96
97 rcu_read_lock();
98 f = fcheck(fd);
99 rcu_read_unlock();
100 /* we'd lost the race with close(), sod off silently */
101 /* note that inode->i_lock prevents reordering problems
102 * between accesses to descriptor table and ->i_dnotify */
103 if (f != filp)
104 goto out_free;
105
95 error = __f_setown(filp, task_pid(current), PIDTYPE_PID, 0); 106 error = __f_setown(filp, task_pid(current), PIDTYPE_PID, 0);
96 if (error) 107 if (error)
97 goto out_free; 108 goto out_free;
diff --git a/fs/eventfd.c b/fs/eventfd.c
index a9f130cd50ac..343942deeec1 100644
--- a/fs/eventfd.c
+++ b/fs/eventfd.c
@@ -200,10 +200,8 @@ struct file *eventfd_fget(int fd)
200 200
201asmlinkage long sys_eventfd(unsigned int count) 201asmlinkage long sys_eventfd(unsigned int count)
202{ 202{
203 int error, fd; 203 int fd;
204 struct eventfd_ctx *ctx; 204 struct eventfd_ctx *ctx;
205 struct file *file;
206 struct inode *inode;
207 205
208 ctx = kmalloc(sizeof(*ctx), GFP_KERNEL); 206 ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
209 if (!ctx) 207 if (!ctx)
@@ -216,12 +214,9 @@ asmlinkage long sys_eventfd(unsigned int count)
216 * When we call this, the initialization must be complete, since 214 * When we call this, the initialization must be complete, since
217 * anon_inode_getfd() will install the fd. 215 * anon_inode_getfd() will install the fd.
218 */ 216 */
219 error = anon_inode_getfd(&fd, &inode, &file, "[eventfd]", 217 fd = anon_inode_getfd("[eventfd]", &eventfd_fops, ctx);
220 &eventfd_fops, ctx); 218 if (fd < 0)
221 if (!error) 219 kfree(ctx);
222 return fd; 220 return fd;
223
224 kfree(ctx);
225 return error;
226} 221}
227 222
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 0d237182d721..990c01d2d66b 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -1050,8 +1050,6 @@ asmlinkage long sys_epoll_create(int size)
1050{ 1050{
1051 int error, fd = -1; 1051 int error, fd = -1;
1052 struct eventpoll *ep; 1052 struct eventpoll *ep;
1053 struct inode *inode;
1054 struct file *file;
1055 1053
1056 DNPRINTK(3, (KERN_INFO "[%p] eventpoll: sys_epoll_create(%d)\n", 1054 DNPRINTK(3, (KERN_INFO "[%p] eventpoll: sys_epoll_create(%d)\n",
1057 current, size)); 1055 current, size));
@@ -1061,29 +1059,24 @@ asmlinkage long sys_epoll_create(int size)
1061 * structure ( "struct eventpoll" ). 1059 * structure ( "struct eventpoll" ).
1062 */ 1060 */
1063 error = -EINVAL; 1061 error = -EINVAL;
1064 if (size <= 0 || (error = ep_alloc(&ep)) != 0) 1062 if (size <= 0 || (error = ep_alloc(&ep)) < 0) {
1063 fd = error;
1065 goto error_return; 1064 goto error_return;
1065 }
1066 1066
1067 /* 1067 /*
1068 * Creates all the items needed to setup an eventpoll file. That is, 1068 * Creates all the items needed to setup an eventpoll file. That is,
1069 * a file structure, and inode and a free file descriptor. 1069 * a file structure and a free file descriptor.
1070 */ 1070 */
1071 error = anon_inode_getfd(&fd, &inode, &file, "[eventpoll]", 1071 fd = anon_inode_getfd("[eventpoll]", &eventpoll_fops, ep);
1072 &eventpoll_fops, ep); 1072 if (fd < 0)
1073 if (error) 1073 ep_free(ep);
1074 goto error_free;
1075 1074
1075error_return:
1076 DNPRINTK(3, (KERN_INFO "[%p] eventpoll: sys_epoll_create(%d) = %d\n", 1076 DNPRINTK(3, (KERN_INFO "[%p] eventpoll: sys_epoll_create(%d) = %d\n",
1077 current, size, fd)); 1077 current, size, fd));
1078 1078
1079 return fd; 1079 return fd;
1080
1081error_free:
1082 ep_free(ep);
1083error_return:
1084 DNPRINTK(3, (KERN_INFO "[%p] eventpoll: sys_epoll_create(%d) = %d\n",
1085 current, size, error));
1086 return error;
1087} 1080}
1088 1081
1089/* 1082/*
@@ -1241,7 +1234,7 @@ error_return:
1241 return error; 1234 return error;
1242} 1235}
1243 1236
1244#ifdef TIF_RESTORE_SIGMASK 1237#ifdef HAVE_SET_RESTORE_SIGMASK
1245 1238
1246/* 1239/*
1247 * Implement the event wait interface for the eventpoll file. It is the kernel 1240 * Implement the event wait interface for the eventpoll file. It is the kernel
@@ -1279,7 +1272,7 @@ asmlinkage long sys_epoll_pwait(int epfd, struct epoll_event __user *events,
1279 if (error == -EINTR) { 1272 if (error == -EINTR) {
1280 memcpy(&current->saved_sigmask, &sigsaved, 1273 memcpy(&current->saved_sigmask, &sigsaved,
1281 sizeof(sigsaved)); 1274 sizeof(sigsaved));
1282 set_thread_flag(TIF_RESTORE_SIGMASK); 1275 set_restore_sigmask();
1283 } else 1276 } else
1284 sigprocmask(SIG_SETMASK, &sigsaved, NULL); 1277 sigprocmask(SIG_SETMASK, &sigsaved, NULL);
1285 } 1278 }
@@ -1287,7 +1280,7 @@ asmlinkage long sys_epoll_pwait(int epfd, struct epoll_event __user *events,
1287 return error; 1280 return error;
1288} 1281}
1289 1282
1290#endif /* #ifdef TIF_RESTORE_SIGMASK */ 1283#endif /* HAVE_SET_RESTORE_SIGMASK */
1291 1284
1292static int __init eventpoll_init(void) 1285static int __init eventpoll_init(void)
1293{ 1286{
@@ -1309,4 +1302,3 @@ static int __init eventpoll_init(void)
1309 return 0; 1302 return 0;
1310} 1303}
1311fs_initcall(eventpoll_init); 1304fs_initcall(eventpoll_init);
1312
diff --git a/fs/exec.c b/fs/exec.c
index a13883903ee9..aeaa9791d8be 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -24,6 +24,7 @@
24 24
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/file.h> 26#include <linux/file.h>
27#include <linux/fdtable.h>
27#include <linux/mman.h> 28#include <linux/mman.h>
28#include <linux/a.out.h> 29#include <linux/a.out.h>
29#include <linux/stat.h> 30#include <linux/stat.h>
@@ -766,9 +767,7 @@ static int de_thread(struct task_struct *tsk)
766 767
767 /* 768 /*
768 * Kill all other threads in the thread group. 769 * Kill all other threads in the thread group.
769 * We must hold tasklist_lock to call zap_other_threads.
770 */ 770 */
771 read_lock(&tasklist_lock);
772 spin_lock_irq(lock); 771 spin_lock_irq(lock);
773 if (signal_group_exit(sig)) { 772 if (signal_group_exit(sig)) {
774 /* 773 /*
@@ -776,21 +775,10 @@ static int de_thread(struct task_struct *tsk)
776 * return so that the signal is processed. 775 * return so that the signal is processed.
777 */ 776 */
778 spin_unlock_irq(lock); 777 spin_unlock_irq(lock);
779 read_unlock(&tasklist_lock);
780 return -EAGAIN; 778 return -EAGAIN;
781 } 779 }
782
783 /*
784 * child_reaper ignores SIGKILL, change it now.
785 * Reparenting needs write_lock on tasklist_lock,
786 * so it is safe to do it under read_lock.
787 */
788 if (unlikely(tsk->group_leader == task_child_reaper(tsk)))
789 task_active_pid_ns(tsk)->child_reaper = tsk;
790
791 sig->group_exit_task = tsk; 780 sig->group_exit_task = tsk;
792 zap_other_threads(tsk); 781 zap_other_threads(tsk);
793 read_unlock(&tasklist_lock);
794 782
795 /* Account for the thread group leader hanging around: */ 783 /* Account for the thread group leader hanging around: */
796 count = thread_group_leader(tsk) ? 1 : 2; 784 count = thread_group_leader(tsk) ? 1 : 2;
@@ -811,7 +799,7 @@ static int de_thread(struct task_struct *tsk)
811 if (!thread_group_leader(tsk)) { 799 if (!thread_group_leader(tsk)) {
812 leader = tsk->group_leader; 800 leader = tsk->group_leader;
813 801
814 sig->notify_count = -1; 802 sig->notify_count = -1; /* for exit_notify() */
815 for (;;) { 803 for (;;) {
816 write_lock_irq(&tasklist_lock); 804 write_lock_irq(&tasklist_lock);
817 if (likely(leader->exit_state)) 805 if (likely(leader->exit_state))
@@ -821,6 +809,8 @@ static int de_thread(struct task_struct *tsk)
821 schedule(); 809 schedule();
822 } 810 }
823 811
812 if (unlikely(task_child_reaper(tsk) == leader))
813 task_active_pid_ns(tsk)->child_reaper = tsk;
824 /* 814 /*
825 * The only record we have of the real-time age of a 815 * The only record we have of the real-time age of a
826 * process, regardless of execs it's done, is start_time. 816 * process, regardless of execs it's done, is start_time.
diff --git a/fs/exportfs/expfs.c b/fs/exportfs/expfs.c
index 109ab5e44eca..cc91227d3bb8 100644
--- a/fs/exportfs/expfs.c
+++ b/fs/exportfs/expfs.c
@@ -150,12 +150,12 @@ reconnect_path(struct vfsmount *mnt, struct dentry *target_dir)
150 if (IS_ERR(ppd)) { 150 if (IS_ERR(ppd)) {
151 err = PTR_ERR(ppd); 151 err = PTR_ERR(ppd);
152 dprintk("%s: get_parent of %ld failed, err %d\n", 152 dprintk("%s: get_parent of %ld failed, err %d\n",
153 __FUNCTION__, pd->d_inode->i_ino, err); 153 __func__, pd->d_inode->i_ino, err);
154 dput(pd); 154 dput(pd);
155 break; 155 break;
156 } 156 }
157 157
158 dprintk("%s: find name of %lu in %lu\n", __FUNCTION__, 158 dprintk("%s: find name of %lu in %lu\n", __func__,
159 pd->d_inode->i_ino, ppd->d_inode->i_ino); 159 pd->d_inode->i_ino, ppd->d_inode->i_ino);
160 err = exportfs_get_name(mnt, ppd, nbuf, pd); 160 err = exportfs_get_name(mnt, ppd, nbuf, pd);
161 if (err) { 161 if (err) {
@@ -168,14 +168,14 @@ reconnect_path(struct vfsmount *mnt, struct dentry *target_dir)
168 continue; 168 continue;
169 break; 169 break;
170 } 170 }
171 dprintk("%s: found name: %s\n", __FUNCTION__, nbuf); 171 dprintk("%s: found name: %s\n", __func__, nbuf);
172 mutex_lock(&ppd->d_inode->i_mutex); 172 mutex_lock(&ppd->d_inode->i_mutex);
173 npd = lookup_one_len(nbuf, ppd, strlen(nbuf)); 173 npd = lookup_one_len(nbuf, ppd, strlen(nbuf));
174 mutex_unlock(&ppd->d_inode->i_mutex); 174 mutex_unlock(&ppd->d_inode->i_mutex);
175 if (IS_ERR(npd)) { 175 if (IS_ERR(npd)) {
176 err = PTR_ERR(npd); 176 err = PTR_ERR(npd);
177 dprintk("%s: lookup failed: %d\n", 177 dprintk("%s: lookup failed: %d\n",
178 __FUNCTION__, err); 178 __func__, err);
179 dput(ppd); 179 dput(ppd);
180 dput(pd); 180 dput(pd);
181 break; 181 break;
@@ -188,7 +188,7 @@ reconnect_path(struct vfsmount *mnt, struct dentry *target_dir)
188 if (npd == pd) 188 if (npd == pd)
189 noprogress = 0; 189 noprogress = 0;
190 else 190 else
191 printk("%s: npd != pd\n", __FUNCTION__); 191 printk("%s: npd != pd\n", __func__);
192 dput(npd); 192 dput(npd);
193 dput(ppd); 193 dput(ppd);
194 if (IS_ROOT(pd)) { 194 if (IS_ROOT(pd)) {
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c
index cc47b76091bf..6ae4ecf3ce40 100644
--- a/fs/ext3/inode.c
+++ b/fs/ext3/inode.c
@@ -1261,10 +1261,11 @@ static int ext3_ordered_write_end(struct file *file,
1261 new_i_size = pos + copied; 1261 new_i_size = pos + copied;
1262 if (new_i_size > EXT3_I(inode)->i_disksize) 1262 if (new_i_size > EXT3_I(inode)->i_disksize)
1263 EXT3_I(inode)->i_disksize = new_i_size; 1263 EXT3_I(inode)->i_disksize = new_i_size;
1264 copied = ext3_generic_write_end(file, mapping, pos, len, copied, 1264 ret2 = ext3_generic_write_end(file, mapping, pos, len, copied,
1265 page, fsdata); 1265 page, fsdata);
1266 if (copied < 0) 1266 copied = ret2;
1267 ret = copied; 1267 if (ret2 < 0)
1268 ret = ret2;
1268 } 1269 }
1269 ret2 = ext3_journal_stop(handle); 1270 ret2 = ext3_journal_stop(handle);
1270 if (!ret) 1271 if (!ret)
@@ -1289,10 +1290,11 @@ static int ext3_writeback_write_end(struct file *file,
1289 if (new_i_size > EXT3_I(inode)->i_disksize) 1290 if (new_i_size > EXT3_I(inode)->i_disksize)
1290 EXT3_I(inode)->i_disksize = new_i_size; 1291 EXT3_I(inode)->i_disksize = new_i_size;
1291 1292
1292 copied = ext3_generic_write_end(file, mapping, pos, len, copied, 1293 ret2 = ext3_generic_write_end(file, mapping, pos, len, copied,
1293 page, fsdata); 1294 page, fsdata);
1294 if (copied < 0) 1295 copied = ret2;
1295 ret = copied; 1296 if (ret2 < 0)
1297 ret = ret2;
1296 1298
1297 ret2 = ext3_journal_stop(handle); 1299 ret2 = ext3_journal_stop(handle);
1298 if (!ret) 1300 if (!ret)
diff --git a/fs/ext4/acl.c b/fs/ext4/acl.c
index a8bae8cd1d5d..3c8dab880d91 100644
--- a/fs/ext4/acl.c
+++ b/fs/ext4/acl.c
@@ -9,8 +9,8 @@
9#include <linux/slab.h> 9#include <linux/slab.h>
10#include <linux/capability.h> 10#include <linux/capability.h>
11#include <linux/fs.h> 11#include <linux/fs.h>
12#include <linux/ext4_jbd2.h> 12#include "ext4_jbd2.h"
13#include <linux/ext4_fs.h> 13#include "ext4.h"
14#include "xattr.h" 14#include "xattr.h"
15#include "acl.h" 15#include "acl.h"
16 16
@@ -37,7 +37,7 @@ ext4_acl_from_disk(const void *value, size_t size)
37 return ERR_PTR(-EINVAL); 37 return ERR_PTR(-EINVAL);
38 if (count == 0) 38 if (count == 0)
39 return NULL; 39 return NULL;
40 acl = posix_acl_alloc(count, GFP_KERNEL); 40 acl = posix_acl_alloc(count, GFP_NOFS);
41 if (!acl) 41 if (!acl)
42 return ERR_PTR(-ENOMEM); 42 return ERR_PTR(-ENOMEM);
43 for (n=0; n < count; n++) { 43 for (n=0; n < count; n++) {
@@ -91,7 +91,7 @@ ext4_acl_to_disk(const struct posix_acl *acl, size_t *size)
91 91
92 *size = ext4_acl_size(acl->a_count); 92 *size = ext4_acl_size(acl->a_count);
93 ext_acl = kmalloc(sizeof(ext4_acl_header) + acl->a_count * 93 ext_acl = kmalloc(sizeof(ext4_acl_header) + acl->a_count *
94 sizeof(ext4_acl_entry), GFP_KERNEL); 94 sizeof(ext4_acl_entry), GFP_NOFS);
95 if (!ext_acl) 95 if (!ext_acl)
96 return ERR_PTR(-ENOMEM); 96 return ERR_PTR(-ENOMEM);
97 ext_acl->a_version = cpu_to_le32(EXT4_ACL_VERSION); 97 ext_acl->a_version = cpu_to_le32(EXT4_ACL_VERSION);
@@ -187,7 +187,7 @@ ext4_get_acl(struct inode *inode, int type)
187 } 187 }
188 retval = ext4_xattr_get(inode, name_index, "", NULL, 0); 188 retval = ext4_xattr_get(inode, name_index, "", NULL, 0);
189 if (retval > 0) { 189 if (retval > 0) {
190 value = kmalloc(retval, GFP_KERNEL); 190 value = kmalloc(retval, GFP_NOFS);
191 if (!value) 191 if (!value)
192 return ERR_PTR(-ENOMEM); 192 return ERR_PTR(-ENOMEM);
193 retval = ext4_xattr_get(inode, name_index, "", value, retval); 193 retval = ext4_xattr_get(inode, name_index, "", value, retval);
@@ -335,7 +335,7 @@ ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
335 if (error) 335 if (error)
336 goto cleanup; 336 goto cleanup;
337 } 337 }
338 clone = posix_acl_clone(acl, GFP_KERNEL); 338 clone = posix_acl_clone(acl, GFP_NOFS);
339 error = -ENOMEM; 339 error = -ENOMEM;
340 if (!clone) 340 if (!clone)
341 goto cleanup; 341 goto cleanup;
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index 0737e05ba3dd..da994374ec3b 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -15,12 +15,12 @@
15#include <linux/capability.h> 15#include <linux/capability.h>
16#include <linux/fs.h> 16#include <linux/fs.h>
17#include <linux/jbd2.h> 17#include <linux/jbd2.h>
18#include <linux/ext4_fs.h>
19#include <linux/ext4_jbd2.h>
20#include <linux/quotaops.h> 18#include <linux/quotaops.h>
21#include <linux/buffer_head.h> 19#include <linux/buffer_head.h>
22 20#include "ext4.h"
21#include "ext4_jbd2.h"
23#include "group.h" 22#include "group.h"
23
24/* 24/*
25 * balloc.c contains the blocks allocation and deallocation routines 25 * balloc.c contains the blocks allocation and deallocation routines
26 */ 26 */
@@ -48,7 +48,6 @@ void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr,
48unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh, 48unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,
49 ext4_group_t block_group, struct ext4_group_desc *gdp) 49 ext4_group_t block_group, struct ext4_group_desc *gdp)
50{ 50{
51 unsigned long start;
52 int bit, bit_max; 51 int bit, bit_max;
53 unsigned free_blocks, group_blocks; 52 unsigned free_blocks, group_blocks;
54 struct ext4_sb_info *sbi = EXT4_SB(sb); 53 struct ext4_sb_info *sbi = EXT4_SB(sb);
@@ -59,7 +58,7 @@ unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,
59 /* If checksum is bad mark all blocks used to prevent allocation 58 /* If checksum is bad mark all blocks used to prevent allocation
60 * essentially implementing a per-group read-only flag. */ 59 * essentially implementing a per-group read-only flag. */
61 if (!ext4_group_desc_csum_verify(sbi, block_group, gdp)) { 60 if (!ext4_group_desc_csum_verify(sbi, block_group, gdp)) {
62 ext4_error(sb, __FUNCTION__, 61 ext4_error(sb, __func__,
63 "Checksum bad for group %lu\n", block_group); 62 "Checksum bad for group %lu\n", block_group);
64 gdp->bg_free_blocks_count = 0; 63 gdp->bg_free_blocks_count = 0;
65 gdp->bg_free_inodes_count = 0; 64 gdp->bg_free_inodes_count = 0;
@@ -106,11 +105,12 @@ unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,
106 free_blocks = group_blocks - bit_max; 105 free_blocks = group_blocks - bit_max;
107 106
108 if (bh) { 107 if (bh) {
108 ext4_fsblk_t start;
109
109 for (bit = 0; bit < bit_max; bit++) 110 for (bit = 0; bit < bit_max; bit++)
110 ext4_set_bit(bit, bh->b_data); 111 ext4_set_bit(bit, bh->b_data);
111 112
112 start = block_group * EXT4_BLOCKS_PER_GROUP(sb) + 113 start = ext4_group_first_block_no(sb, block_group);
113 le32_to_cpu(sbi->s_es->s_first_data_block);
114 114
115 /* Set bits for block and inode bitmaps, and inode table */ 115 /* Set bits for block and inode bitmaps, and inode table */
116 ext4_set_bit(ext4_block_bitmap(sb, gdp) - start, bh->b_data); 116 ext4_set_bit(ext4_block_bitmap(sb, gdp) - start, bh->b_data);
@@ -235,7 +235,7 @@ static int ext4_valid_block_bitmap(struct super_block *sb,
235 return 1; 235 return 1;
236 236
237err_out: 237err_out:
238 ext4_error(sb, __FUNCTION__, 238 ext4_error(sb, __func__,
239 "Invalid block bitmap - " 239 "Invalid block bitmap - "
240 "block_group = %d, block = %llu", 240 "block_group = %d, block = %llu",
241 block_group, bitmap_blk); 241 block_group, bitmap_blk);
@@ -264,7 +264,7 @@ read_block_bitmap(struct super_block *sb, ext4_group_t block_group)
264 bitmap_blk = ext4_block_bitmap(sb, desc); 264 bitmap_blk = ext4_block_bitmap(sb, desc);
265 bh = sb_getblk(sb, bitmap_blk); 265 bh = sb_getblk(sb, bitmap_blk);
266 if (unlikely(!bh)) { 266 if (unlikely(!bh)) {
267 ext4_error(sb, __FUNCTION__, 267 ext4_error(sb, __func__,
268 "Cannot read block bitmap - " 268 "Cannot read block bitmap - "
269 "block_group = %d, block_bitmap = %llu", 269 "block_group = %d, block_bitmap = %llu",
270 (int)block_group, (unsigned long long)bitmap_blk); 270 (int)block_group, (unsigned long long)bitmap_blk);
@@ -281,7 +281,7 @@ read_block_bitmap(struct super_block *sb, ext4_group_t block_group)
281 } 281 }
282 if (bh_submit_read(bh) < 0) { 282 if (bh_submit_read(bh) < 0) {
283 put_bh(bh); 283 put_bh(bh);
284 ext4_error(sb, __FUNCTION__, 284 ext4_error(sb, __func__,
285 "Cannot read block bitmap - " 285 "Cannot read block bitmap - "
286 "block_group = %d, block_bitmap = %llu", 286 "block_group = %d, block_bitmap = %llu",
287 (int)block_group, (unsigned long long)bitmap_blk); 287 (int)block_group, (unsigned long long)bitmap_blk);
@@ -360,7 +360,7 @@ restart:
360 BUG(); 360 BUG();
361} 361}
362#define rsv_window_dump(root, verbose) \ 362#define rsv_window_dump(root, verbose) \
363 __rsv_window_dump((root), (verbose), __FUNCTION__) 363 __rsv_window_dump((root), (verbose), __func__)
364#else 364#else
365#define rsv_window_dump(root, verbose) do {} while (0) 365#define rsv_window_dump(root, verbose) do {} while (0)
366#endif 366#endif
@@ -740,7 +740,7 @@ do_more:
740 if (!ext4_clear_bit_atomic(sb_bgl_lock(sbi, block_group), 740 if (!ext4_clear_bit_atomic(sb_bgl_lock(sbi, block_group),
741 bit + i, bitmap_bh->b_data)) { 741 bit + i, bitmap_bh->b_data)) {
742 jbd_unlock_bh_state(bitmap_bh); 742 jbd_unlock_bh_state(bitmap_bh);
743 ext4_error(sb, __FUNCTION__, 743 ext4_error(sb, __func__,
744 "bit already cleared for block %llu", 744 "bit already cleared for block %llu",
745 (ext4_fsblk_t)(block + i)); 745 (ext4_fsblk_t)(block + i));
746 jbd_lock_bh_state(bitmap_bh); 746 jbd_lock_bh_state(bitmap_bh);
@@ -752,9 +752,7 @@ do_more:
752 jbd_unlock_bh_state(bitmap_bh); 752 jbd_unlock_bh_state(bitmap_bh);
753 753
754 spin_lock(sb_bgl_lock(sbi, block_group)); 754 spin_lock(sb_bgl_lock(sbi, block_group));
755 desc->bg_free_blocks_count = 755 le16_add_cpu(&desc->bg_free_blocks_count, group_freed);
756 cpu_to_le16(le16_to_cpu(desc->bg_free_blocks_count) +
757 group_freed);
758 desc->bg_checksum = ext4_group_desc_csum(sbi, block_group, desc); 756 desc->bg_checksum = ext4_group_desc_csum(sbi, block_group, desc);
759 spin_unlock(sb_bgl_lock(sbi, block_group)); 757 spin_unlock(sb_bgl_lock(sbi, block_group));
760 percpu_counter_add(&sbi->s_freeblocks_counter, count); 758 percpu_counter_add(&sbi->s_freeblocks_counter, count);
@@ -1798,7 +1796,7 @@ allocated:
1798 if (ext4_test_bit(grp_alloc_blk+i, 1796 if (ext4_test_bit(grp_alloc_blk+i,
1799 bh2jh(bitmap_bh)->b_committed_data)) { 1797 bh2jh(bitmap_bh)->b_committed_data)) {
1800 printk("%s: block was unexpectedly set in " 1798 printk("%s: block was unexpectedly set in "
1801 "b_committed_data\n", __FUNCTION__); 1799 "b_committed_data\n", __func__);
1802 } 1800 }
1803 } 1801 }
1804 } 1802 }
@@ -1823,8 +1821,7 @@ allocated:
1823 spin_lock(sb_bgl_lock(sbi, group_no)); 1821 spin_lock(sb_bgl_lock(sbi, group_no));
1824 if (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) 1822 if (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT))
1825 gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT); 1823 gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT);
1826 gdp->bg_free_blocks_count = 1824 le16_add_cpu(&gdp->bg_free_blocks_count, -num);
1827 cpu_to_le16(le16_to_cpu(gdp->bg_free_blocks_count)-num);
1828 gdp->bg_checksum = ext4_group_desc_csum(sbi, group_no, gdp); 1825 gdp->bg_checksum = ext4_group_desc_csum(sbi, group_no, gdp);
1829 spin_unlock(sb_bgl_lock(sbi, group_no)); 1826 spin_unlock(sb_bgl_lock(sbi, group_no));
1830 percpu_counter_sub(&sbi->s_freeblocks_counter, num); 1827 percpu_counter_sub(&sbi->s_freeblocks_counter, num);
diff --git a/fs/ext4/bitmap.c b/fs/ext4/bitmap.c
index 420554f8f79d..d37ea6750454 100644
--- a/fs/ext4/bitmap.c
+++ b/fs/ext4/bitmap.c
@@ -9,7 +9,7 @@
9 9
10#include <linux/buffer_head.h> 10#include <linux/buffer_head.h>
11#include <linux/jbd2.h> 11#include <linux/jbd2.h>
12#include <linux/ext4_fs.h> 12#include "ext4.h"
13 13
14#ifdef EXT4FS_DEBUG 14#ifdef EXT4FS_DEBUG
15 15
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index 2c23bade9aa6..2bf0331ea194 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -23,10 +23,10 @@
23 23
24#include <linux/fs.h> 24#include <linux/fs.h>
25#include <linux/jbd2.h> 25#include <linux/jbd2.h>
26#include <linux/ext4_fs.h>
27#include <linux/buffer_head.h> 26#include <linux/buffer_head.h>
28#include <linux/slab.h> 27#include <linux/slab.h>
29#include <linux/rbtree.h> 28#include <linux/rbtree.h>
29#include "ext4.h"
30 30
31static unsigned char ext4_filetype_table[] = { 31static unsigned char ext4_filetype_table[] = {
32 DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK 32 DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK
@@ -42,7 +42,7 @@ const struct file_operations ext4_dir_operations = {
42 .llseek = generic_file_llseek, 42 .llseek = generic_file_llseek,
43 .read = generic_read_dir, 43 .read = generic_read_dir,
44 .readdir = ext4_readdir, /* we take BKL. needed?*/ 44 .readdir = ext4_readdir, /* we take BKL. needed?*/
45 .ioctl = ext4_ioctl, /* BKL held */ 45 .unlocked_ioctl = ext4_ioctl,
46#ifdef CONFIG_COMPAT 46#ifdef CONFIG_COMPAT
47 .compat_ioctl = ext4_compat_ioctl, 47 .compat_ioctl = ext4_compat_ioctl,
48#endif 48#endif
diff --git a/include/linux/ext4_fs.h b/fs/ext4/ext4.h
index 250032548597..8158083f7ac0 100644
--- a/include/linux/ext4_fs.h
+++ b/fs/ext4/ext4.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/include/linux/ext4_fs.h 2 * ext4.h
3 * 3 *
4 * Copyright (C) 1992, 1993, 1994, 1995 4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr) 5 * Remy Card (card@masi.ibp.fr)
@@ -13,14 +13,13 @@
13 * Copyright (C) 1991, 1992 Linus Torvalds 13 * Copyright (C) 1991, 1992 Linus Torvalds
14 */ 14 */
15 15
16#ifndef _LINUX_EXT4_FS_H 16#ifndef _EXT4_H
17#define _LINUX_EXT4_FS_H 17#define _EXT4_H
18 18
19#include <linux/types.h> 19#include <linux/types.h>
20#include <linux/blkdev.h> 20#include <linux/blkdev.h>
21#include <linux/magic.h> 21#include <linux/magic.h>
22 22#include "ext4_i.h"
23#include <linux/ext4_fs_i.h>
24 23
25/* 24/*
26 * The second extended filesystem constants/structures 25 * The second extended filesystem constants/structures
@@ -176,8 +175,7 @@ struct ext4_group_desc
176#define EXT4_BG_INODE_ZEROED 0x0004 /* On-disk itable initialized to zero */ 175#define EXT4_BG_INODE_ZEROED 0x0004 /* On-disk itable initialized to zero */
177 176
178#ifdef __KERNEL__ 177#ifdef __KERNEL__
179#include <linux/ext4_fs_i.h> 178#include "ext4_sb.h"
180#include <linux/ext4_fs_sb.h>
181#endif 179#endif
182/* 180/*
183 * Macro-instructions used to manage group descriptors 181 * Macro-instructions used to manage group descriptors
@@ -231,6 +229,7 @@ struct ext4_group_desc
231#define EXT4_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/ 229#define EXT4_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
232#define EXT4_HUGE_FILE_FL 0x00040000 /* Set to each huge file */ 230#define EXT4_HUGE_FILE_FL 0x00040000 /* Set to each huge file */
233#define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */ 231#define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */
232#define EXT4_EXT_MIGRATE 0x00100000 /* Inode is migrating */
234#define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */ 233#define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */
235 234
236#define EXT4_FL_USER_VISIBLE 0x000BDFFF /* User visible flags */ 235#define EXT4_FL_USER_VISIBLE 0x000BDFFF /* User visible flags */
@@ -1049,8 +1048,7 @@ extern int ext4_block_truncate_page(handle_t *handle, struct page *page,
1049 struct address_space *mapping, loff_t from); 1048 struct address_space *mapping, loff_t from);
1050 1049
1051/* ioctl.c */ 1050/* ioctl.c */
1052extern int ext4_ioctl (struct inode *, struct file *, unsigned int, 1051extern long ext4_ioctl(struct file *, unsigned int, unsigned long);
1053 unsigned long);
1054extern long ext4_compat_ioctl (struct file *, unsigned int, unsigned long); 1052extern long ext4_compat_ioctl (struct file *, unsigned int, unsigned long);
1055 1053
1056/* migrate.c */ 1054/* migrate.c */
@@ -1204,4 +1202,4 @@ extern int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode,
1204 int extend_disksize); 1202 int extend_disksize);
1205#endif /* __KERNEL__ */ 1203#endif /* __KERNEL__ */
1206 1204
1207#endif /* _LINUX_EXT4_FS_H */ 1205#endif /* _EXT4_H */
diff --git a/include/linux/ext4_fs_extents.h b/fs/ext4/ext4_extents.h
index 1285c583b2d8..75333b595fab 100644
--- a/include/linux/ext4_fs_extents.h
+++ b/fs/ext4/ext4_extents.h
@@ -16,10 +16,10 @@
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111- 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-
17 */ 17 */
18 18
19#ifndef _LINUX_EXT4_EXTENTS 19#ifndef _EXT4_EXTENTS
20#define _LINUX_EXT4_EXTENTS 20#define _EXT4_EXTENTS
21 21
22#include <linux/ext4_fs.h> 22#include "ext4.h"
23 23
24/* 24/*
25 * With AGGRESSIVE_TEST defined, the capacity of index/leaf blocks 25 * With AGGRESSIVE_TEST defined, the capacity of index/leaf blocks
@@ -228,5 +228,5 @@ extern int ext4_ext_search_left(struct inode *, struct ext4_ext_path *,
228extern int ext4_ext_search_right(struct inode *, struct ext4_ext_path *, 228extern int ext4_ext_search_right(struct inode *, struct ext4_ext_path *,
229 ext4_lblk_t *, ext4_fsblk_t *); 229 ext4_lblk_t *, ext4_fsblk_t *);
230extern void ext4_ext_drop_refs(struct ext4_ext_path *); 230extern void ext4_ext_drop_refs(struct ext4_ext_path *);
231#endif /* _LINUX_EXT4_EXTENTS */ 231#endif /* _EXT4_EXTENTS */
232 232
diff --git a/include/linux/ext4_fs_i.h b/fs/ext4/ext4_i.h
index d5508d3cf290..26a4ae255d79 100644
--- a/include/linux/ext4_fs_i.h
+++ b/fs/ext4/ext4_i.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/include/linux/ext4_fs_i.h 2 * ext4_i.h
3 * 3 *
4 * Copyright (C) 1992, 1993, 1994, 1995 4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr) 5 * Remy Card (card@masi.ibp.fr)
@@ -13,8 +13,8 @@
13 * Copyright (C) 1991, 1992 Linus Torvalds 13 * Copyright (C) 1991, 1992 Linus Torvalds
14 */ 14 */
15 15
16#ifndef _LINUX_EXT4_FS_I 16#ifndef _EXT4_I
17#define _LINUX_EXT4_FS_I 17#define _EXT4_I
18 18
19#include <linux/rwsem.h> 19#include <linux/rwsem.h>
20#include <linux/rbtree.h> 20#include <linux/rbtree.h>
@@ -164,4 +164,4 @@ struct ext4_inode_info {
164 spinlock_t i_prealloc_lock; 164 spinlock_t i_prealloc_lock;
165}; 165};
166 166
167#endif /* _LINUX_EXT4_FS_I */ 167#endif /* _EXT4_I */
diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c
index d6afe4e27340..c75384b34f2c 100644
--- a/fs/ext4/ext4_jbd2.c
+++ b/fs/ext4/ext4_jbd2.c
@@ -2,14 +2,14 @@
2 * Interface between ext4 and JBD 2 * Interface between ext4 and JBD
3 */ 3 */
4 4
5#include <linux/ext4_jbd2.h> 5#include "ext4_jbd2.h"
6 6
7int __ext4_journal_get_undo_access(const char *where, handle_t *handle, 7int __ext4_journal_get_undo_access(const char *where, handle_t *handle,
8 struct buffer_head *bh) 8 struct buffer_head *bh)
9{ 9{
10 int err = jbd2_journal_get_undo_access(handle, bh); 10 int err = jbd2_journal_get_undo_access(handle, bh);
11 if (err) 11 if (err)
12 ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err); 12 ext4_journal_abort_handle(where, __func__, bh, handle, err);
13 return err; 13 return err;
14} 14}
15 15
@@ -18,7 +18,7 @@ int __ext4_journal_get_write_access(const char *where, handle_t *handle,
18{ 18{
19 int err = jbd2_journal_get_write_access(handle, bh); 19 int err = jbd2_journal_get_write_access(handle, bh);
20 if (err) 20 if (err)
21 ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err); 21 ext4_journal_abort_handle(where, __func__, bh, handle, err);
22 return err; 22 return err;
23} 23}
24 24
@@ -27,7 +27,7 @@ int __ext4_journal_forget(const char *where, handle_t *handle,
27{ 27{
28 int err = jbd2_journal_forget(handle, bh); 28 int err = jbd2_journal_forget(handle, bh);
29 if (err) 29 if (err)
30 ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err); 30 ext4_journal_abort_handle(where, __func__, bh, handle, err);
31 return err; 31 return err;
32} 32}
33 33
@@ -36,7 +36,7 @@ int __ext4_journal_revoke(const char *where, handle_t *handle,
36{ 36{
37 int err = jbd2_journal_revoke(handle, blocknr, bh); 37 int err = jbd2_journal_revoke(handle, blocknr, bh);
38 if (err) 38 if (err)
39 ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err); 39 ext4_journal_abort_handle(where, __func__, bh, handle, err);
40 return err; 40 return err;
41} 41}
42 42
@@ -45,7 +45,7 @@ int __ext4_journal_get_create_access(const char *where,
45{ 45{
46 int err = jbd2_journal_get_create_access(handle, bh); 46 int err = jbd2_journal_get_create_access(handle, bh);
47 if (err) 47 if (err)
48 ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err); 48 ext4_journal_abort_handle(where, __func__, bh, handle, err);
49 return err; 49 return err;
50} 50}
51 51
@@ -54,6 +54,6 @@ int __ext4_journal_dirty_metadata(const char *where,
54{ 54{
55 int err = jbd2_journal_dirty_metadata(handle, bh); 55 int err = jbd2_journal_dirty_metadata(handle, bh);
56 if (err) 56 if (err)
57 ext4_journal_abort_handle(where, __FUNCTION__, bh, handle,err); 57 ext4_journal_abort_handle(where, __func__, bh, handle, err);
58 return err; 58 return err;
59} 59}
diff --git a/include/linux/ext4_jbd2.h b/fs/ext4/ext4_jbd2.h
index 38c71d3c8dbf..9255a7d28b24 100644
--- a/include/linux/ext4_jbd2.h
+++ b/fs/ext4/ext4_jbd2.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/include/linux/ext4_jbd2.h 2 * ext4_jbd2.h
3 * 3 *
4 * Written by Stephen C. Tweedie <sct@redhat.com>, 1999 4 * Written by Stephen C. Tweedie <sct@redhat.com>, 1999
5 * 5 *
@@ -12,12 +12,12 @@
12 * Ext4-specific journaling extensions. 12 * Ext4-specific journaling extensions.
13 */ 13 */
14 14
15#ifndef _LINUX_EXT4_JBD2_H 15#ifndef _EXT4_JBD2_H
16#define _LINUX_EXT4_JBD2_H 16#define _EXT4_JBD2_H
17 17
18#include <linux/fs.h> 18#include <linux/fs.h>
19#include <linux/jbd2.h> 19#include <linux/jbd2.h>
20#include <linux/ext4_fs.h> 20#include "ext4.h"
21 21
22#define EXT4_JOURNAL(inode) (EXT4_SB((inode)->i_sb)->s_journal) 22#define EXT4_JOURNAL(inode) (EXT4_SB((inode)->i_sb)->s_journal)
23 23
@@ -228,4 +228,4 @@ static inline int ext4_should_writeback_data(struct inode *inode)
228 return 0; 228 return 0;
229} 229}
230 230
231#endif /* _LINUX_EXT4_JBD2_H */ 231#endif /* _EXT4_JBD2_H */
diff --git a/include/linux/ext4_fs_sb.h b/fs/ext4/ext4_sb.h
index abaae2c8cccf..5802e69f2191 100644
--- a/include/linux/ext4_fs_sb.h
+++ b/fs/ext4/ext4_sb.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/include/linux/ext4_fs_sb.h 2 * ext4_sb.h
3 * 3 *
4 * Copyright (C) 1992, 1993, 1994, 1995 4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr) 5 * Remy Card (card@masi.ibp.fr)
@@ -13,8 +13,8 @@
13 * Copyright (C) 1991, 1992 Linus Torvalds 13 * Copyright (C) 1991, 1992 Linus Torvalds
14 */ 14 */
15 15
16#ifndef _LINUX_EXT4_FS_SB 16#ifndef _EXT4_SB
17#define _LINUX_EXT4_FS_SB 17#define _EXT4_SB
18 18
19#ifdef __KERNEL__ 19#ifdef __KERNEL__
20#include <linux/timer.h> 20#include <linux/timer.h>
@@ -145,4 +145,4 @@ struct ext4_sb_info {
145 struct ext4_locality_group *s_locality_groups; 145 struct ext4_locality_group *s_locality_groups;
146}; 146};
147 147
148#endif /* _LINUX_EXT4_FS_SB */ 148#endif /* _EXT4_SB */
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 9ae6e67090cd..47929c4e3dae 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -32,7 +32,6 @@
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/fs.h> 33#include <linux/fs.h>
34#include <linux/time.h> 34#include <linux/time.h>
35#include <linux/ext4_jbd2.h>
36#include <linux/jbd2.h> 35#include <linux/jbd2.h>
37#include <linux/highuid.h> 36#include <linux/highuid.h>
38#include <linux/pagemap.h> 37#include <linux/pagemap.h>
@@ -40,8 +39,9 @@
40#include <linux/string.h> 39#include <linux/string.h>
41#include <linux/slab.h> 40#include <linux/slab.h>
42#include <linux/falloc.h> 41#include <linux/falloc.h>
43#include <linux/ext4_fs_extents.h>
44#include <asm/uaccess.h> 42#include <asm/uaccess.h>
43#include "ext4_jbd2.h"
44#include "ext4_extents.h"
45 45
46 46
47/* 47/*
@@ -308,7 +308,7 @@ corrupted:
308} 308}
309 309
310#define ext4_ext_check_header(inode, eh, depth) \ 310#define ext4_ext_check_header(inode, eh, depth) \
311 __ext4_ext_check_header(__FUNCTION__, inode, eh, depth) 311 __ext4_ext_check_header(__func__, inode, eh, depth)
312 312
313#ifdef EXT_DEBUG 313#ifdef EXT_DEBUG
314static void ext4_ext_show_path(struct inode *inode, struct ext4_ext_path *path) 314static void ext4_ext_show_path(struct inode *inode, struct ext4_ext_path *path)
@@ -614,7 +614,7 @@ static int ext4_ext_insert_index(handle_t *handle, struct inode *inode,
614 614
615 ix->ei_block = cpu_to_le32(logical); 615 ix->ei_block = cpu_to_le32(logical);
616 ext4_idx_store_pblock(ix, ptr); 616 ext4_idx_store_pblock(ix, ptr);
617 curp->p_hdr->eh_entries = cpu_to_le16(le16_to_cpu(curp->p_hdr->eh_entries)+1); 617 le16_add_cpu(&curp->p_hdr->eh_entries, 1);
618 618
619 BUG_ON(le16_to_cpu(curp->p_hdr->eh_entries) 619 BUG_ON(le16_to_cpu(curp->p_hdr->eh_entries)
620 > le16_to_cpu(curp->p_hdr->eh_max)); 620 > le16_to_cpu(curp->p_hdr->eh_max));
@@ -736,7 +736,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
736 } 736 }
737 if (m) { 737 if (m) {
738 memmove(ex, path[depth].p_ext-m, sizeof(struct ext4_extent)*m); 738 memmove(ex, path[depth].p_ext-m, sizeof(struct ext4_extent)*m);
739 neh->eh_entries = cpu_to_le16(le16_to_cpu(neh->eh_entries)+m); 739 le16_add_cpu(&neh->eh_entries, m);
740 } 740 }
741 741
742 set_buffer_uptodate(bh); 742 set_buffer_uptodate(bh);
@@ -753,8 +753,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
753 err = ext4_ext_get_access(handle, inode, path + depth); 753 err = ext4_ext_get_access(handle, inode, path + depth);
754 if (err) 754 if (err)
755 goto cleanup; 755 goto cleanup;
756 path[depth].p_hdr->eh_entries = 756 le16_add_cpu(&path[depth].p_hdr->eh_entries, -m);
757 cpu_to_le16(le16_to_cpu(path[depth].p_hdr->eh_entries)-m);
758 err = ext4_ext_dirty(handle, inode, path + depth); 757 err = ext4_ext_dirty(handle, inode, path + depth);
759 if (err) 758 if (err)
760 goto cleanup; 759 goto cleanup;
@@ -817,8 +816,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
817 if (m) { 816 if (m) {
818 memmove(++fidx, path[i].p_idx - m, 817 memmove(++fidx, path[i].p_idx - m,
819 sizeof(struct ext4_extent_idx) * m); 818 sizeof(struct ext4_extent_idx) * m);
820 neh->eh_entries = 819 le16_add_cpu(&neh->eh_entries, m);
821 cpu_to_le16(le16_to_cpu(neh->eh_entries) + m);
822 } 820 }
823 set_buffer_uptodate(bh); 821 set_buffer_uptodate(bh);
824 unlock_buffer(bh); 822 unlock_buffer(bh);
@@ -834,7 +832,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,
834 err = ext4_ext_get_access(handle, inode, path + i); 832 err = ext4_ext_get_access(handle, inode, path + i);
835 if (err) 833 if (err)
836 goto cleanup; 834 goto cleanup;
837 path[i].p_hdr->eh_entries = cpu_to_le16(le16_to_cpu(path[i].p_hdr->eh_entries)-m); 835 le16_add_cpu(&path[i].p_hdr->eh_entries, -m);
838 err = ext4_ext_dirty(handle, inode, path + i); 836 err = ext4_ext_dirty(handle, inode, path + i);
839 if (err) 837 if (err)
840 goto cleanup; 838 goto cleanup;
@@ -1369,7 +1367,7 @@ int ext4_ext_try_to_merge(struct inode *inode,
1369 * sizeof(struct ext4_extent); 1367 * sizeof(struct ext4_extent);
1370 memmove(ex + 1, ex + 2, len); 1368 memmove(ex + 1, ex + 2, len);
1371 } 1369 }
1372 eh->eh_entries = cpu_to_le16(le16_to_cpu(eh->eh_entries) - 1); 1370 le16_add_cpu(&eh->eh_entries, -1);
1373 merge_done = 1; 1371 merge_done = 1;
1374 WARN_ON(eh->eh_entries == 0); 1372 WARN_ON(eh->eh_entries == 0);
1375 if (!eh->eh_entries) 1373 if (!eh->eh_entries)
@@ -1560,7 +1558,7 @@ has_space:
1560 path[depth].p_ext = nearex; 1558 path[depth].p_ext = nearex;
1561 } 1559 }
1562 1560
1563 eh->eh_entries = cpu_to_le16(le16_to_cpu(eh->eh_entries)+1); 1561 le16_add_cpu(&eh->eh_entries, 1);
1564 nearex = path[depth].p_ext; 1562 nearex = path[depth].p_ext;
1565 nearex->ee_block = newext->ee_block; 1563 nearex->ee_block = newext->ee_block;
1566 ext4_ext_store_pblock(nearex, ext_pblock(newext)); 1564 ext4_ext_store_pblock(nearex, ext_pblock(newext));
@@ -1699,7 +1697,7 @@ static int ext4_ext_rm_idx(handle_t *handle, struct inode *inode,
1699 err = ext4_ext_get_access(handle, inode, path); 1697 err = ext4_ext_get_access(handle, inode, path);
1700 if (err) 1698 if (err)
1701 return err; 1699 return err;
1702 path->p_hdr->eh_entries = cpu_to_le16(le16_to_cpu(path->p_hdr->eh_entries)-1); 1700 le16_add_cpu(&path->p_hdr->eh_entries, -1);
1703 err = ext4_ext_dirty(handle, inode, path); 1701 err = ext4_ext_dirty(handle, inode, path);
1704 if (err) 1702 if (err)
1705 return err; 1703 return err;
@@ -1902,7 +1900,7 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode,
1902 if (num == 0) { 1900 if (num == 0) {
1903 /* this extent is removed; mark slot entirely unused */ 1901 /* this extent is removed; mark slot entirely unused */
1904 ext4_ext_store_pblock(ex, 0); 1902 ext4_ext_store_pblock(ex, 0);
1905 eh->eh_entries = cpu_to_le16(le16_to_cpu(eh->eh_entries)-1); 1903 le16_add_cpu(&eh->eh_entries, -1);
1906 } 1904 }
1907 1905
1908 ex->ee_block = cpu_to_le32(block); 1906 ex->ee_block = cpu_to_le32(block);
@@ -1979,7 +1977,7 @@ static int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start)
1979 * We start scanning from right side, freeing all the blocks 1977 * We start scanning from right side, freeing all the blocks
1980 * after i_size and walking into the tree depth-wise. 1978 * after i_size and walking into the tree depth-wise.
1981 */ 1979 */
1982 path = kzalloc(sizeof(struct ext4_ext_path) * (depth + 1), GFP_KERNEL); 1980 path = kzalloc(sizeof(struct ext4_ext_path) * (depth + 1), GFP_NOFS);
1983 if (path == NULL) { 1981 if (path == NULL) {
1984 ext4_journal_stop(handle); 1982 ext4_journal_stop(handle);
1985 return -ENOMEM; 1983 return -ENOMEM;
@@ -2138,6 +2136,82 @@ void ext4_ext_release(struct super_block *sb)
2138#endif 2136#endif
2139} 2137}
2140 2138
2139static void bi_complete(struct bio *bio, int error)
2140{
2141 complete((struct completion *)bio->bi_private);
2142}
2143
2144/* FIXME!! we need to try to merge to left or right after zero-out */
2145static int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex)
2146{
2147 int ret = -EIO;
2148 struct bio *bio;
2149 int blkbits, blocksize;
2150 sector_t ee_pblock;
2151 struct completion event;
2152 unsigned int ee_len, len, done, offset;
2153
2154
2155 blkbits = inode->i_blkbits;
2156 blocksize = inode->i_sb->s_blocksize;
2157 ee_len = ext4_ext_get_actual_len(ex);
2158 ee_pblock = ext_pblock(ex);
2159
2160 /* convert ee_pblock to 512 byte sectors */
2161 ee_pblock = ee_pblock << (blkbits - 9);
2162
2163 while (ee_len > 0) {
2164
2165 if (ee_len > BIO_MAX_PAGES)
2166 len = BIO_MAX_PAGES;
2167 else
2168 len = ee_len;
2169
2170 bio = bio_alloc(GFP_NOIO, len);
2171 if (!bio)
2172 return -ENOMEM;
2173 bio->bi_sector = ee_pblock;
2174 bio->bi_bdev = inode->i_sb->s_bdev;
2175
2176 done = 0;
2177 offset = 0;
2178 while (done < len) {
2179 ret = bio_add_page(bio, ZERO_PAGE(0),
2180 blocksize, offset);
2181 if (ret != blocksize) {
2182 /*
2183 * We can't add any more pages because of
2184 * hardware limitations. Start a new bio.
2185 */
2186 break;
2187 }
2188 done++;
2189 offset += blocksize;
2190 if (offset >= PAGE_CACHE_SIZE)
2191 offset = 0;
2192 }
2193
2194 init_completion(&event);
2195 bio->bi_private = &event;
2196 bio->bi_end_io = bi_complete;
2197 submit_bio(WRITE, bio);
2198 wait_for_completion(&event);
2199
2200 if (test_bit(BIO_UPTODATE, &bio->bi_flags))
2201 ret = 0;
2202 else {
2203 ret = -EIO;
2204 break;
2205 }
2206 bio_put(bio);
2207 ee_len -= done;
2208 ee_pblock += done << (blkbits - 9);
2209 }
2210 return ret;
2211}
2212
2213#define EXT4_EXT_ZERO_LEN 7
2214
2141/* 2215/*
2142 * This function is called by ext4_ext_get_blocks() if someone tries to write 2216 * This function is called by ext4_ext_get_blocks() if someone tries to write
2143 * to an uninitialized extent. It may result in splitting the uninitialized 2217 * to an uninitialized extent. It may result in splitting the uninitialized
@@ -2154,7 +2228,7 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
2154 ext4_lblk_t iblock, 2228 ext4_lblk_t iblock,
2155 unsigned long max_blocks) 2229 unsigned long max_blocks)
2156{ 2230{
2157 struct ext4_extent *ex, newex; 2231 struct ext4_extent *ex, newex, orig_ex;
2158 struct ext4_extent *ex1 = NULL; 2232 struct ext4_extent *ex1 = NULL;
2159 struct ext4_extent *ex2 = NULL; 2233 struct ext4_extent *ex2 = NULL;
2160 struct ext4_extent *ex3 = NULL; 2234 struct ext4_extent *ex3 = NULL;
@@ -2173,10 +2247,26 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
2173 allocated = ee_len - (iblock - ee_block); 2247 allocated = ee_len - (iblock - ee_block);
2174 newblock = iblock - ee_block + ext_pblock(ex); 2248 newblock = iblock - ee_block + ext_pblock(ex);
2175 ex2 = ex; 2249 ex2 = ex;
2250 orig_ex.ee_block = ex->ee_block;
2251 orig_ex.ee_len = cpu_to_le16(ee_len);
2252 ext4_ext_store_pblock(&orig_ex, ext_pblock(ex));
2176 2253
2177 err = ext4_ext_get_access(handle, inode, path + depth); 2254 err = ext4_ext_get_access(handle, inode, path + depth);
2178 if (err) 2255 if (err)
2179 goto out; 2256 goto out;
2257 /* If extent has less than 2*EXT4_EXT_ZERO_LEN zerout directly */
2258 if (ee_len <= 2*EXT4_EXT_ZERO_LEN) {
2259 err = ext4_ext_zeroout(inode, &orig_ex);
2260 if (err)
2261 goto fix_extent_len;
2262 /* update the extent length and mark as initialized */
2263 ex->ee_block = orig_ex.ee_block;
2264 ex->ee_len = orig_ex.ee_len;
2265 ext4_ext_store_pblock(ex, ext_pblock(&orig_ex));
2266 ext4_ext_dirty(handle, inode, path + depth);
2267 /* zeroed the full extent */
2268 return allocated;
2269 }
2180 2270
2181 /* ex1: ee_block to iblock - 1 : uninitialized */ 2271 /* ex1: ee_block to iblock - 1 : uninitialized */
2182 if (iblock > ee_block) { 2272 if (iblock > ee_block) {
@@ -2195,19 +2285,103 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
2195 /* ex3: to ee_block + ee_len : uninitialised */ 2285 /* ex3: to ee_block + ee_len : uninitialised */
2196 if (allocated > max_blocks) { 2286 if (allocated > max_blocks) {
2197 unsigned int newdepth; 2287 unsigned int newdepth;
2288 /* If extent has less than EXT4_EXT_ZERO_LEN zerout directly */
2289 if (allocated <= EXT4_EXT_ZERO_LEN) {
2290 /* Mark first half uninitialized.
2291 * Mark second half initialized and zero out the
2292 * initialized extent
2293 */
2294 ex->ee_block = orig_ex.ee_block;
2295 ex->ee_len = cpu_to_le16(ee_len - allocated);
2296 ext4_ext_mark_uninitialized(ex);
2297 ext4_ext_store_pblock(ex, ext_pblock(&orig_ex));
2298 ext4_ext_dirty(handle, inode, path + depth);
2299
2300 ex3 = &newex;
2301 ex3->ee_block = cpu_to_le32(iblock);
2302 ext4_ext_store_pblock(ex3, newblock);
2303 ex3->ee_len = cpu_to_le16(allocated);
2304 err = ext4_ext_insert_extent(handle, inode, path, ex3);
2305 if (err == -ENOSPC) {
2306 err = ext4_ext_zeroout(inode, &orig_ex);
2307 if (err)
2308 goto fix_extent_len;
2309 ex->ee_block = orig_ex.ee_block;
2310 ex->ee_len = orig_ex.ee_len;
2311 ext4_ext_store_pblock(ex, ext_pblock(&orig_ex));
2312 ext4_ext_dirty(handle, inode, path + depth);
2313 /* zeroed the full extent */
2314 return allocated;
2315
2316 } else if (err)
2317 goto fix_extent_len;
2318
2319 /*
2320 * We need to zero out the second half because
2321 * an fallocate request can update file size and
2322 * converting the second half to initialized extent
2323 * implies that we can leak some junk data to user
2324 * space.
2325 */
2326 err = ext4_ext_zeroout(inode, ex3);
2327 if (err) {
2328 /*
2329 * We should actually mark the
2330 * second half as uninit and return error
2331 * Insert would have changed the extent
2332 */
2333 depth = ext_depth(inode);
2334 ext4_ext_drop_refs(path);
2335 path = ext4_ext_find_extent(inode,
2336 iblock, path);
2337 if (IS_ERR(path)) {
2338 err = PTR_ERR(path);
2339 return err;
2340 }
2341 ex = path[depth].p_ext;
2342 err = ext4_ext_get_access(handle, inode,
2343 path + depth);
2344 if (err)
2345 return err;
2346 ext4_ext_mark_uninitialized(ex);
2347 ext4_ext_dirty(handle, inode, path + depth);
2348 return err;
2349 }
2350
2351 /* zeroed the second half */
2352 return allocated;
2353 }
2198 ex3 = &newex; 2354 ex3 = &newex;
2199 ex3->ee_block = cpu_to_le32(iblock + max_blocks); 2355 ex3->ee_block = cpu_to_le32(iblock + max_blocks);
2200 ext4_ext_store_pblock(ex3, newblock + max_blocks); 2356 ext4_ext_store_pblock(ex3, newblock + max_blocks);
2201 ex3->ee_len = cpu_to_le16(allocated - max_blocks); 2357 ex3->ee_len = cpu_to_le16(allocated - max_blocks);
2202 ext4_ext_mark_uninitialized(ex3); 2358 ext4_ext_mark_uninitialized(ex3);
2203 err = ext4_ext_insert_extent(handle, inode, path, ex3); 2359 err = ext4_ext_insert_extent(handle, inode, path, ex3);
2204 if (err) 2360 if (err == -ENOSPC) {
2205 goto out; 2361 err = ext4_ext_zeroout(inode, &orig_ex);
2362 if (err)
2363 goto fix_extent_len;
2364 /* update the extent length and mark as initialized */
2365 ex->ee_block = orig_ex.ee_block;
2366 ex->ee_len = orig_ex.ee_len;
2367 ext4_ext_store_pblock(ex, ext_pblock(&orig_ex));
2368 ext4_ext_dirty(handle, inode, path + depth);
2369 /* zeroed the full extent */
2370 return allocated;
2371
2372 } else if (err)
2373 goto fix_extent_len;
2206 /* 2374 /*
2207 * The depth, and hence eh & ex might change 2375 * The depth, and hence eh & ex might change
2208 * as part of the insert above. 2376 * as part of the insert above.
2209 */ 2377 */
2210 newdepth = ext_depth(inode); 2378 newdepth = ext_depth(inode);
2379 /*
2380 * update the extent length after successfull insert of the
2381 * split extent
2382 */
2383 orig_ex.ee_len = cpu_to_le16(ee_len -
2384 ext4_ext_get_actual_len(ex3));
2211 if (newdepth != depth) { 2385 if (newdepth != depth) {
2212 depth = newdepth; 2386 depth = newdepth;
2213 ext4_ext_drop_refs(path); 2387 ext4_ext_drop_refs(path);
@@ -2226,6 +2400,24 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
2226 goto out; 2400 goto out;
2227 } 2401 }
2228 allocated = max_blocks; 2402 allocated = max_blocks;
2403
2404 /* If extent has less than EXT4_EXT_ZERO_LEN and we are trying
2405 * to insert a extent in the middle zerout directly
2406 * otherwise give the extent a chance to merge to left
2407 */
2408 if (le16_to_cpu(orig_ex.ee_len) <= EXT4_EXT_ZERO_LEN &&
2409 iblock != ee_block) {
2410 err = ext4_ext_zeroout(inode, &orig_ex);
2411 if (err)
2412 goto fix_extent_len;
2413 /* update the extent length and mark as initialized */
2414 ex->ee_block = orig_ex.ee_block;
2415 ex->ee_len = orig_ex.ee_len;
2416 ext4_ext_store_pblock(ex, ext_pblock(&orig_ex));
2417 ext4_ext_dirty(handle, inode, path + depth);
2418 /* zero out the first half */
2419 return allocated;
2420 }
2229 } 2421 }
2230 /* 2422 /*
2231 * If there was a change of depth as part of the 2423 * If there was a change of depth as part of the
@@ -2282,8 +2474,29 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
2282 goto out; 2474 goto out;
2283insert: 2475insert:
2284 err = ext4_ext_insert_extent(handle, inode, path, &newex); 2476 err = ext4_ext_insert_extent(handle, inode, path, &newex);
2477 if (err == -ENOSPC) {
2478 err = ext4_ext_zeroout(inode, &orig_ex);
2479 if (err)
2480 goto fix_extent_len;
2481 /* update the extent length and mark as initialized */
2482 ex->ee_block = orig_ex.ee_block;
2483 ex->ee_len = orig_ex.ee_len;
2484 ext4_ext_store_pblock(ex, ext_pblock(&orig_ex));
2485 ext4_ext_dirty(handle, inode, path + depth);
2486 /* zero out the first half */
2487 return allocated;
2488 } else if (err)
2489 goto fix_extent_len;
2285out: 2490out:
2286 return err ? err : allocated; 2491 return err ? err : allocated;
2492
2493fix_extent_len:
2494 ex->ee_block = orig_ex.ee_block;
2495 ex->ee_len = orig_ex.ee_len;
2496 ext4_ext_store_pblock(ex, ext_pblock(&orig_ex));
2497 ext4_ext_mark_uninitialized(ex);
2498 ext4_ext_dirty(handle, inode, path + depth);
2499 return err;
2287} 2500}
2288 2501
2289/* 2502/*
@@ -2393,8 +2606,20 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
2393 } 2606 }
2394 if (create == EXT4_CREATE_UNINITIALIZED_EXT) 2607 if (create == EXT4_CREATE_UNINITIALIZED_EXT)
2395 goto out; 2608 goto out;
2396 if (!create) 2609 if (!create) {
2610 /*
2611 * We have blocks reserved already. We
2612 * return allocated blocks so that delalloc
2613 * won't do block reservation for us. But
2614 * the buffer head will be unmapped so that
2615 * a read from the block returns 0s.
2616 */
2617 if (allocated > max_blocks)
2618 allocated = max_blocks;
2619 /* mark the buffer unwritten */
2620 __set_bit(BH_Unwritten, &bh_result->b_state);
2397 goto out2; 2621 goto out2;
2622 }
2398 2623
2399 ret = ext4_ext_convert_to_initialized(handle, inode, 2624 ret = ext4_ext_convert_to_initialized(handle, inode,
2400 path, iblock, 2625 path, iblock,
@@ -2584,6 +2809,8 @@ out_stop:
2584 ext4_orphan_del(handle, inode); 2809 ext4_orphan_del(handle, inode);
2585 2810
2586 up_write(&EXT4_I(inode)->i_data_sem); 2811 up_write(&EXT4_I(inode)->i_data_sem);
2812 inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
2813 ext4_mark_inode_dirty(handle, inode);
2587 ext4_journal_stop(handle); 2814 ext4_journal_stop(handle);
2588} 2815}
2589 2816
@@ -2608,6 +2835,28 @@ int ext4_ext_writepage_trans_blocks(struct inode *inode, int num)
2608 return needed; 2835 return needed;
2609} 2836}
2610 2837
2838static void ext4_falloc_update_inode(struct inode *inode,
2839 int mode, loff_t new_size, int update_ctime)
2840{
2841 struct timespec now;
2842
2843 if (update_ctime) {
2844 now = current_fs_time(inode->i_sb);
2845 if (!timespec_equal(&inode->i_ctime, &now))
2846 inode->i_ctime = now;
2847 }
2848 /*
2849 * Update only when preallocation was requested beyond
2850 * the file size.
2851 */
2852 if (!(mode & FALLOC_FL_KEEP_SIZE) &&
2853 new_size > i_size_read(inode)) {
2854 i_size_write(inode, new_size);
2855 EXT4_I(inode)->i_disksize = new_size;
2856 }
2857
2858}
2859
2611/* 2860/*
2612 * preallocate space for a file. This implements ext4's fallocate inode 2861 * preallocate space for a file. This implements ext4's fallocate inode
2613 * operation, which gets called from sys_fallocate system call. 2862 * operation, which gets called from sys_fallocate system call.
@@ -2619,8 +2868,8 @@ long ext4_fallocate(struct inode *inode, int mode, loff_t offset, loff_t len)
2619{ 2868{
2620 handle_t *handle; 2869 handle_t *handle;
2621 ext4_lblk_t block; 2870 ext4_lblk_t block;
2871 loff_t new_size;
2622 unsigned long max_blocks; 2872 unsigned long max_blocks;
2623 ext4_fsblk_t nblocks = 0;
2624 int ret = 0; 2873 int ret = 0;
2625 int ret2 = 0; 2874 int ret2 = 0;
2626 int retries = 0; 2875 int retries = 0;
@@ -2639,9 +2888,12 @@ long ext4_fallocate(struct inode *inode, int mode, loff_t offset, loff_t len)
2639 return -ENODEV; 2888 return -ENODEV;
2640 2889
2641 block = offset >> blkbits; 2890 block = offset >> blkbits;
2891 /*
2892 * We can't just convert len to max_blocks because
2893 * If blocksize = 4096 offset = 3072 and len = 2048
2894 */
2642 max_blocks = (EXT4_BLOCK_ALIGN(len + offset, blkbits) >> blkbits) 2895 max_blocks = (EXT4_BLOCK_ALIGN(len + offset, blkbits) >> blkbits)
2643 - block; 2896 - block;
2644
2645 /* 2897 /*
2646 * credits to insert 1 extent into extent tree + buffers to be able to 2898 * credits to insert 1 extent into extent tree + buffers to be able to
2647 * modify 1 super block, 1 block bitmap and 1 group descriptor. 2899 * modify 1 super block, 1 block bitmap and 1 group descriptor.
@@ -2657,7 +2909,6 @@ retry:
2657 ret = PTR_ERR(handle); 2909 ret = PTR_ERR(handle);
2658 break; 2910 break;
2659 } 2911 }
2660
2661 ret = ext4_get_blocks_wrap(handle, inode, block, 2912 ret = ext4_get_blocks_wrap(handle, inode, block,
2662 max_blocks, &map_bh, 2913 max_blocks, &map_bh,
2663 EXT4_CREATE_UNINITIALIZED_EXT, 0); 2914 EXT4_CREATE_UNINITIALIZED_EXT, 0);
@@ -2673,61 +2924,24 @@ retry:
2673 ret2 = ext4_journal_stop(handle); 2924 ret2 = ext4_journal_stop(handle);
2674 break; 2925 break;
2675 } 2926 }
2676 if (ret > 0) { 2927 if ((block + ret) >= (EXT4_BLOCK_ALIGN(offset + len,
2677 /* check wrap through sign-bit/zero here */ 2928 blkbits) >> blkbits))
2678 if ((block + ret) < 0 || (block + ret) < block) { 2929 new_size = offset + len;
2679 ret = -EIO; 2930 else
2680 ext4_mark_inode_dirty(handle, inode); 2931 new_size = (block + ret) << blkbits;
2681 ret2 = ext4_journal_stop(handle);
2682 break;
2683 }
2684 if (buffer_new(&map_bh) && ((block + ret) >
2685 (EXT4_BLOCK_ALIGN(i_size_read(inode), blkbits)
2686 >> blkbits)))
2687 nblocks = nblocks + ret;
2688 }
2689
2690 /* Update ctime if new blocks get allocated */
2691 if (nblocks) {
2692 struct timespec now;
2693
2694 now = current_fs_time(inode->i_sb);
2695 if (!timespec_equal(&inode->i_ctime, &now))
2696 inode->i_ctime = now;
2697 }
2698 2932
2933 ext4_falloc_update_inode(inode, mode, new_size,
2934 buffer_new(&map_bh));
2699 ext4_mark_inode_dirty(handle, inode); 2935 ext4_mark_inode_dirty(handle, inode);
2700 ret2 = ext4_journal_stop(handle); 2936 ret2 = ext4_journal_stop(handle);
2701 if (ret2) 2937 if (ret2)
2702 break; 2938 break;
2703 } 2939 }
2704 2940 if (ret == -ENOSPC &&
2705 if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) 2941 ext4_should_retry_alloc(inode->i_sb, &retries)) {
2942 ret = 0;
2706 goto retry; 2943 goto retry;
2707
2708 /*
2709 * Time to update the file size.
2710 * Update only when preallocation was requested beyond the file size.
2711 */
2712 if (!(mode & FALLOC_FL_KEEP_SIZE) &&
2713 (offset + len) > i_size_read(inode)) {
2714 if (ret > 0) {
2715 /*
2716 * if no error, we assume preallocation succeeded
2717 * completely
2718 */
2719 i_size_write(inode, offset + len);
2720 EXT4_I(inode)->i_disksize = i_size_read(inode);
2721 } else if (ret < 0 && nblocks) {
2722 /* Handle partial allocation scenario */
2723 loff_t newsize;
2724
2725 newsize = (nblocks << blkbits) + i_size_read(inode);
2726 i_size_write(inode, EXT4_BLOCK_ALIGN(newsize, blkbits));
2727 EXT4_I(inode)->i_disksize = i_size_read(inode);
2728 }
2729 } 2944 }
2730
2731 mutex_unlock(&inode->i_mutex); 2945 mutex_unlock(&inode->i_mutex);
2732 return ret > 0 ? ret2 : ret; 2946 return ret > 0 ? ret2 : ret;
2733} 2947}
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index ac35ec58db55..4159be6366ab 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -21,8 +21,8 @@
21#include <linux/time.h> 21#include <linux/time.h>
22#include <linux/fs.h> 22#include <linux/fs.h>
23#include <linux/jbd2.h> 23#include <linux/jbd2.h>
24#include <linux/ext4_fs.h> 24#include "ext4.h"
25#include <linux/ext4_jbd2.h> 25#include "ext4_jbd2.h"
26#include "xattr.h" 26#include "xattr.h"
27#include "acl.h" 27#include "acl.h"
28 28
@@ -129,7 +129,7 @@ const struct file_operations ext4_file_operations = {
129 .write = do_sync_write, 129 .write = do_sync_write,
130 .aio_read = generic_file_aio_read, 130 .aio_read = generic_file_aio_read,
131 .aio_write = ext4_file_write, 131 .aio_write = ext4_file_write,
132 .ioctl = ext4_ioctl, 132 .unlocked_ioctl = ext4_ioctl,
133#ifdef CONFIG_COMPAT 133#ifdef CONFIG_COMPAT
134 .compat_ioctl = ext4_compat_ioctl, 134 .compat_ioctl = ext4_compat_ioctl,
135#endif 135#endif
diff --git a/fs/ext4/fsync.c b/fs/ext4/fsync.c
index 8d50879d1c2c..1c8ba48d4f8d 100644
--- a/fs/ext4/fsync.c
+++ b/fs/ext4/fsync.c
@@ -27,8 +27,8 @@
27#include <linux/sched.h> 27#include <linux/sched.h>
28#include <linux/writeback.h> 28#include <linux/writeback.h>
29#include <linux/jbd2.h> 29#include <linux/jbd2.h>
30#include <linux/ext4_fs.h> 30#include "ext4.h"
31#include <linux/ext4_jbd2.h> 31#include "ext4_jbd2.h"
32 32
33/* 33/*
34 * akpm: A new design for ext4_sync_file(). 34 * akpm: A new design for ext4_sync_file().
@@ -72,6 +72,9 @@ int ext4_sync_file(struct file * file, struct dentry *dentry, int datasync)
72 goto out; 72 goto out;
73 } 73 }
74 74
75 if (datasync && !(inode->i_state & I_DIRTY_DATASYNC))
76 goto out;
77
75 /* 78 /*
76 * The VFS has written the file data. If the inode is unaltered 79 * The VFS has written the file data. If the inode is unaltered
77 * then we need not start a commit. 80 * then we need not start a commit.
diff --git a/fs/ext4/hash.c b/fs/ext4/hash.c
index 1555024e3b36..1d6329dbe390 100644
--- a/fs/ext4/hash.c
+++ b/fs/ext4/hash.c
@@ -11,8 +11,8 @@
11 11
12#include <linux/fs.h> 12#include <linux/fs.h>
13#include <linux/jbd2.h> 13#include <linux/jbd2.h>
14#include <linux/ext4_fs.h>
15#include <linux/cryptohash.h> 14#include <linux/cryptohash.h>
15#include "ext4.h"
16 16
17#define DELTA 0x9E3779B9 17#define DELTA 0x9E3779B9
18 18
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
index 486e46a3918d..c6efbab0c801 100644
--- a/fs/ext4/ialloc.c
+++ b/fs/ext4/ialloc.c
@@ -15,8 +15,6 @@
15#include <linux/time.h> 15#include <linux/time.h>
16#include <linux/fs.h> 16#include <linux/fs.h>
17#include <linux/jbd2.h> 17#include <linux/jbd2.h>
18#include <linux/ext4_fs.h>
19#include <linux/ext4_jbd2.h>
20#include <linux/stat.h> 18#include <linux/stat.h>
21#include <linux/string.h> 19#include <linux/string.h>
22#include <linux/quotaops.h> 20#include <linux/quotaops.h>
@@ -25,7 +23,8 @@
25#include <linux/bitops.h> 23#include <linux/bitops.h>
26#include <linux/blkdev.h> 24#include <linux/blkdev.h>
27#include <asm/byteorder.h> 25#include <asm/byteorder.h>
28 26#include "ext4.h"
27#include "ext4_jbd2.h"
29#include "xattr.h" 28#include "xattr.h"
30#include "acl.h" 29#include "acl.h"
31#include "group.h" 30#include "group.h"
@@ -75,7 +74,7 @@ unsigned ext4_init_inode_bitmap(struct super_block *sb, struct buffer_head *bh,
75 /* If checksum is bad mark all blocks and inodes use to prevent 74 /* If checksum is bad mark all blocks and inodes use to prevent
76 * allocation, essentially implementing a per-group read-only flag. */ 75 * allocation, essentially implementing a per-group read-only flag. */
77 if (!ext4_group_desc_csum_verify(sbi, block_group, gdp)) { 76 if (!ext4_group_desc_csum_verify(sbi, block_group, gdp)) {
78 ext4_error(sb, __FUNCTION__, "Checksum bad for group %lu\n", 77 ext4_error(sb, __func__, "Checksum bad for group %lu\n",
79 block_group); 78 block_group);
80 gdp->bg_free_blocks_count = 0; 79 gdp->bg_free_blocks_count = 0;
81 gdp->bg_free_inodes_count = 0; 80 gdp->bg_free_inodes_count = 0;
@@ -223,11 +222,9 @@ void ext4_free_inode (handle_t *handle, struct inode * inode)
223 222
224 if (gdp) { 223 if (gdp) {
225 spin_lock(sb_bgl_lock(sbi, block_group)); 224 spin_lock(sb_bgl_lock(sbi, block_group));
226 gdp->bg_free_inodes_count = cpu_to_le16( 225 le16_add_cpu(&gdp->bg_free_inodes_count, 1);
227 le16_to_cpu(gdp->bg_free_inodes_count) + 1);
228 if (is_directory) 226 if (is_directory)
229 gdp->bg_used_dirs_count = cpu_to_le16( 227 le16_add_cpu(&gdp->bg_used_dirs_count, -1);
230 le16_to_cpu(gdp->bg_used_dirs_count) - 1);
231 gdp->bg_checksum = ext4_group_desc_csum(sbi, 228 gdp->bg_checksum = ext4_group_desc_csum(sbi,
232 block_group, gdp); 229 block_group, gdp);
233 spin_unlock(sb_bgl_lock(sbi, block_group)); 230 spin_unlock(sb_bgl_lock(sbi, block_group));
@@ -588,7 +585,7 @@ got:
588 ino++; 585 ino++;
589 if ((group == 0 && ino < EXT4_FIRST_INO(sb)) || 586 if ((group == 0 && ino < EXT4_FIRST_INO(sb)) ||
590 ino > EXT4_INODES_PER_GROUP(sb)) { 587 ino > EXT4_INODES_PER_GROUP(sb)) {
591 ext4_error(sb, __FUNCTION__, 588 ext4_error(sb, __func__,
592 "reserved inode or inode > inodes count - " 589 "reserved inode or inode > inodes count - "
593 "block_group = %lu, inode=%lu", group, 590 "block_group = %lu, inode=%lu", group,
594 ino + group * EXT4_INODES_PER_GROUP(sb)); 591 ino + group * EXT4_INODES_PER_GROUP(sb));
@@ -664,11 +661,9 @@ got:
664 cpu_to_le16(EXT4_INODES_PER_GROUP(sb) - ino); 661 cpu_to_le16(EXT4_INODES_PER_GROUP(sb) - ino);
665 } 662 }
666 663
667 gdp->bg_free_inodes_count = 664 le16_add_cpu(&gdp->bg_free_inodes_count, -1);
668 cpu_to_le16(le16_to_cpu(gdp->bg_free_inodes_count) - 1);
669 if (S_ISDIR(mode)) { 665 if (S_ISDIR(mode)) {
670 gdp->bg_used_dirs_count = 666 le16_add_cpu(&gdp->bg_used_dirs_count, 1);
671 cpu_to_le16(le16_to_cpu(gdp->bg_used_dirs_count) + 1);
672 } 667 }
673 gdp->bg_checksum = ext4_group_desc_csum(sbi, group, gdp); 668 gdp->bg_checksum = ext4_group_desc_csum(sbi, group, gdp);
674 spin_unlock(sb_bgl_lock(sbi, group)); 669 spin_unlock(sb_bgl_lock(sbi, group));
@@ -744,23 +739,24 @@ got:
744 if (err) 739 if (err)
745 goto fail_free_drop; 740 goto fail_free_drop;
746 741
747 err = ext4_mark_inode_dirty(handle, inode);
748 if (err) {
749 ext4_std_error(sb, err);
750 goto fail_free_drop;
751 }
752 if (test_opt(sb, EXTENTS)) { 742 if (test_opt(sb, EXTENTS)) {
753 /* set extent flag only for directory and file */ 743 /* set extent flag only for diretory, file and normal symlink*/
754 if (S_ISDIR(mode) || S_ISREG(mode)) { 744 if (S_ISDIR(mode) || S_ISREG(mode) || S_ISLNK(mode)) {
755 EXT4_I(inode)->i_flags |= EXT4_EXTENTS_FL; 745 EXT4_I(inode)->i_flags |= EXT4_EXTENTS_FL;
756 ext4_ext_tree_init(handle, inode); 746 ext4_ext_tree_init(handle, inode);
757 err = ext4_update_incompat_feature(handle, sb, 747 err = ext4_update_incompat_feature(handle, sb,
758 EXT4_FEATURE_INCOMPAT_EXTENTS); 748 EXT4_FEATURE_INCOMPAT_EXTENTS);
759 if (err) 749 if (err)
760 goto fail; 750 goto fail_free_drop;
761 } 751 }
762 } 752 }
763 753
754 err = ext4_mark_inode_dirty(handle, inode);
755 if (err) {
756 ext4_std_error(sb, err);
757 goto fail_free_drop;
758 }
759
764 ext4_debug("allocating inode %lu\n", inode->i_ino); 760 ext4_debug("allocating inode %lu\n", inode->i_ino);
765 goto really_out; 761 goto really_out;
766fail: 762fail:
@@ -796,7 +792,7 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
796 792
797 /* Error cases - e2fsck has already cleaned up for us */ 793 /* Error cases - e2fsck has already cleaned up for us */
798 if (ino > max_ino) { 794 if (ino > max_ino) {
799 ext4_warning(sb, __FUNCTION__, 795 ext4_warning(sb, __func__,
800 "bad orphan ino %lu! e2fsck was run?", ino); 796 "bad orphan ino %lu! e2fsck was run?", ino);
801 goto error; 797 goto error;
802 } 798 }
@@ -805,7 +801,7 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
805 bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb); 801 bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb);
806 bitmap_bh = read_inode_bitmap(sb, block_group); 802 bitmap_bh = read_inode_bitmap(sb, block_group);
807 if (!bitmap_bh) { 803 if (!bitmap_bh) {
808 ext4_warning(sb, __FUNCTION__, 804 ext4_warning(sb, __func__,
809 "inode bitmap error for orphan %lu", ino); 805 "inode bitmap error for orphan %lu", ino);
810 goto error; 806 goto error;
811 } 807 }
@@ -830,7 +826,7 @@ iget_failed:
830 err = PTR_ERR(inode); 826 err = PTR_ERR(inode);
831 inode = NULL; 827 inode = NULL;
832bad_orphan: 828bad_orphan:
833 ext4_warning(sb, __FUNCTION__, 829 ext4_warning(sb, __func__,
834 "bad orphan inode %lu! e2fsck was run?", ino); 830 "bad orphan inode %lu! e2fsck was run?", ino);
835 printk(KERN_NOTICE "ext4_test_bit(bit=%d, block=%llu) = %d\n", 831 printk(KERN_NOTICE "ext4_test_bit(bit=%d, block=%llu) = %d\n",
836 bit, (unsigned long long)bitmap_bh->b_blocknr, 832 bit, (unsigned long long)bitmap_bh->b_blocknr,
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 8fab233cb05f..8d9707746413 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -25,7 +25,6 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/fs.h> 26#include <linux/fs.h>
27#include <linux/time.h> 27#include <linux/time.h>
28#include <linux/ext4_jbd2.h>
29#include <linux/jbd2.h> 28#include <linux/jbd2.h>
30#include <linux/highuid.h> 29#include <linux/highuid.h>
31#include <linux/pagemap.h> 30#include <linux/pagemap.h>
@@ -36,6 +35,7 @@
36#include <linux/mpage.h> 35#include <linux/mpage.h>
37#include <linux/uio.h> 36#include <linux/uio.h>
38#include <linux/bio.h> 37#include <linux/bio.h>
38#include "ext4_jbd2.h"
39#include "xattr.h" 39#include "xattr.h"
40#include "acl.h" 40#include "acl.h"
41 41
@@ -93,7 +93,7 @@ int ext4_forget(handle_t *handle, int is_metadata, struct inode *inode,
93 BUFFER_TRACE(bh, "call ext4_journal_revoke"); 93 BUFFER_TRACE(bh, "call ext4_journal_revoke");
94 err = ext4_journal_revoke(handle, blocknr, bh); 94 err = ext4_journal_revoke(handle, blocknr, bh);
95 if (err) 95 if (err)
96 ext4_abort(inode->i_sb, __FUNCTION__, 96 ext4_abort(inode->i_sb, __func__,
97 "error %d when attempting revoke", err); 97 "error %d when attempting revoke", err);
98 BUFFER_TRACE(bh, "exit"); 98 BUFFER_TRACE(bh, "exit");
99 return err; 99 return err;
@@ -985,6 +985,16 @@ int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block,
985 } else { 985 } else {
986 retval = ext4_get_blocks_handle(handle, inode, block, 986 retval = ext4_get_blocks_handle(handle, inode, block,
987 max_blocks, bh, create, extend_disksize); 987 max_blocks, bh, create, extend_disksize);
988
989 if (retval > 0 && buffer_new(bh)) {
990 /*
991 * We allocated new blocks which will result in
992 * i_data's format changing. Force the migrate
993 * to fail by clearing migrate flags
994 */
995 EXT4_I(inode)->i_flags = EXT4_I(inode)->i_flags &
996 ~EXT4_EXT_MIGRATE;
997 }
988 } 998 }
989 up_write((&EXT4_I(inode)->i_data_sem)); 999 up_write((&EXT4_I(inode)->i_data_sem));
990 return retval; 1000 return retval;
@@ -1230,7 +1240,7 @@ int ext4_journal_dirty_data(handle_t *handle, struct buffer_head *bh)
1230{ 1240{
1231 int err = jbd2_journal_dirty_data(handle, bh); 1241 int err = jbd2_journal_dirty_data(handle, bh);
1232 if (err) 1242 if (err)
1233 ext4_journal_abort_handle(__FUNCTION__, __FUNCTION__, 1243 ext4_journal_abort_handle(__func__, __func__,
1234 bh, handle, err); 1244 bh, handle, err);
1235 return err; 1245 return err;
1236} 1246}
@@ -1301,10 +1311,11 @@ static int ext4_ordered_write_end(struct file *file,
1301 new_i_size = pos + copied; 1311 new_i_size = pos + copied;
1302 if (new_i_size > EXT4_I(inode)->i_disksize) 1312 if (new_i_size > EXT4_I(inode)->i_disksize)
1303 EXT4_I(inode)->i_disksize = new_i_size; 1313 EXT4_I(inode)->i_disksize = new_i_size;
1304 copied = ext4_generic_write_end(file, mapping, pos, len, copied, 1314 ret2 = ext4_generic_write_end(file, mapping, pos, len, copied,
1305 page, fsdata); 1315 page, fsdata);
1306 if (copied < 0) 1316 copied = ret2;
1307 ret = copied; 1317 if (ret2 < 0)
1318 ret = ret2;
1308 } 1319 }
1309 ret2 = ext4_journal_stop(handle); 1320 ret2 = ext4_journal_stop(handle);
1310 if (!ret) 1321 if (!ret)
@@ -1329,10 +1340,11 @@ static int ext4_writeback_write_end(struct file *file,
1329 if (new_i_size > EXT4_I(inode)->i_disksize) 1340 if (new_i_size > EXT4_I(inode)->i_disksize)
1330 EXT4_I(inode)->i_disksize = new_i_size; 1341 EXT4_I(inode)->i_disksize = new_i_size;
1331 1342
1332 copied = ext4_generic_write_end(file, mapping, pos, len, copied, 1343 ret2 = ext4_generic_write_end(file, mapping, pos, len, copied,
1333 page, fsdata); 1344 page, fsdata);
1334 if (copied < 0) 1345 copied = ret2;
1335 ret = copied; 1346 if (ret2 < 0)
1347 ret = ret2;
1336 1348
1337 ret2 = ext4_journal_stop(handle); 1349 ret2 = ext4_journal_stop(handle);
1338 if (!ret) 1350 if (!ret)
@@ -2501,12 +2513,10 @@ out_stop:
2501static ext4_fsblk_t ext4_get_inode_block(struct super_block *sb, 2513static ext4_fsblk_t ext4_get_inode_block(struct super_block *sb,
2502 unsigned long ino, struct ext4_iloc *iloc) 2514 unsigned long ino, struct ext4_iloc *iloc)
2503{ 2515{
2504 unsigned long desc, group_desc;
2505 ext4_group_t block_group; 2516 ext4_group_t block_group;
2506 unsigned long offset; 2517 unsigned long offset;
2507 ext4_fsblk_t block; 2518 ext4_fsblk_t block;
2508 struct buffer_head *bh; 2519 struct ext4_group_desc *gdp;
2509 struct ext4_group_desc * gdp;
2510 2520
2511 if (!ext4_valid_inum(sb, ino)) { 2521 if (!ext4_valid_inum(sb, ino)) {
2512 /* 2522 /*
@@ -2518,22 +2528,10 @@ static ext4_fsblk_t ext4_get_inode_block(struct super_block *sb,
2518 } 2528 }
2519 2529
2520 block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb); 2530 block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
2521 if (block_group >= EXT4_SB(sb)->s_groups_count) { 2531 gdp = ext4_get_group_desc(sb, block_group, NULL);
2522 ext4_error(sb,"ext4_get_inode_block","group >= groups count"); 2532 if (!gdp)
2523 return 0; 2533 return 0;
2524 }
2525 smp_rmb();
2526 group_desc = block_group >> EXT4_DESC_PER_BLOCK_BITS(sb);
2527 desc = block_group & (EXT4_DESC_PER_BLOCK(sb) - 1);
2528 bh = EXT4_SB(sb)->s_group_desc[group_desc];
2529 if (!bh) {
2530 ext4_error (sb, "ext4_get_inode_block",
2531 "Descriptor not loaded");
2532 return 0;
2533 }
2534 2534
2535 gdp = (struct ext4_group_desc *)((__u8 *)bh->b_data +
2536 desc * EXT4_DESC_SIZE(sb));
2537 /* 2535 /*
2538 * Figure out the offset within the block group inode table 2536 * Figure out the offset within the block group inode table
2539 */ 2537 */
@@ -2976,7 +2974,8 @@ static int ext4_do_update_inode(handle_t *handle,
2976 if (ext4_inode_blocks_set(handle, raw_inode, ei)) 2974 if (ext4_inode_blocks_set(handle, raw_inode, ei))
2977 goto out_brelse; 2975 goto out_brelse;
2978 raw_inode->i_dtime = cpu_to_le32(ei->i_dtime); 2976 raw_inode->i_dtime = cpu_to_le32(ei->i_dtime);
2979 raw_inode->i_flags = cpu_to_le32(ei->i_flags); 2977 /* clear the migrate flag in the raw_inode */
2978 raw_inode->i_flags = cpu_to_le32(ei->i_flags & ~EXT4_EXT_MIGRATE);
2980 if (EXT4_SB(inode->i_sb)->s_es->s_creator_os != 2979 if (EXT4_SB(inode->i_sb)->s_es->s_creator_os !=
2981 cpu_to_le32(EXT4_OS_HURD)) 2980 cpu_to_le32(EXT4_OS_HURD))
2982 raw_inode->i_file_acl_high = 2981 raw_inode->i_file_acl_high =
@@ -3374,7 +3373,7 @@ int ext4_mark_inode_dirty(handle_t *handle, struct inode *inode)
3374 EXT4_I(inode)->i_state |= EXT4_STATE_NO_EXPAND; 3373 EXT4_I(inode)->i_state |= EXT4_STATE_NO_EXPAND;
3375 if (mnt_count != 3374 if (mnt_count !=
3376 le16_to_cpu(sbi->s_es->s_mnt_count)) { 3375 le16_to_cpu(sbi->s_es->s_mnt_count)) {
3377 ext4_warning(inode->i_sb, __FUNCTION__, 3376 ext4_warning(inode->i_sb, __func__,
3378 "Unable to expand inode %lu. Delete" 3377 "Unable to expand inode %lu. Delete"
3379 " some EAs or run e2fsck.", 3378 " some EAs or run e2fsck.",
3380 inode->i_ino); 3379 inode->i_ino);
@@ -3415,7 +3414,7 @@ void ext4_dirty_inode(struct inode *inode)
3415 current_handle->h_transaction != handle->h_transaction) { 3414 current_handle->h_transaction != handle->h_transaction) {
3416 /* This task has a transaction open against a different fs */ 3415 /* This task has a transaction open against a different fs */
3417 printk(KERN_EMERG "%s: transactions do not match!\n", 3416 printk(KERN_EMERG "%s: transactions do not match!\n",
3418 __FUNCTION__); 3417 __func__);
3419 } else { 3418 } else {
3420 jbd_debug(5, "marking dirty. outer handle=%p\n", 3419 jbd_debug(5, "marking dirty. outer handle=%p\n",
3421 current_handle); 3420 current_handle);
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index 25b13ede8086..7a6c2f1faba6 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -10,17 +10,17 @@
10#include <linux/fs.h> 10#include <linux/fs.h>
11#include <linux/jbd2.h> 11#include <linux/jbd2.h>
12#include <linux/capability.h> 12#include <linux/capability.h>
13#include <linux/ext4_fs.h>
14#include <linux/ext4_jbd2.h>
15#include <linux/time.h> 13#include <linux/time.h>
16#include <linux/compat.h> 14#include <linux/compat.h>
17#include <linux/smp_lock.h> 15#include <linux/smp_lock.h>
18#include <linux/mount.h> 16#include <linux/mount.h>
19#include <asm/uaccess.h> 17#include <asm/uaccess.h>
18#include "ext4_jbd2.h"
19#include "ext4.h"
20 20
21int ext4_ioctl (struct inode * inode, struct file * filp, unsigned int cmd, 21long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
22 unsigned long arg)
23{ 22{
23 struct inode *inode = filp->f_dentry->d_inode;
24 struct ext4_inode_info *ei = EXT4_I(inode); 24 struct ext4_inode_info *ei = EXT4_I(inode);
25 unsigned int flags; 25 unsigned int flags;
26 unsigned short rsv_window_size; 26 unsigned short rsv_window_size;
@@ -277,9 +277,6 @@ setversion_out:
277#ifdef CONFIG_COMPAT 277#ifdef CONFIG_COMPAT
278long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 278long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
279{ 279{
280 struct inode *inode = file->f_path.dentry->d_inode;
281 int ret;
282
283 /* These are just misnamed, they actually get/put from/to user an int */ 280 /* These are just misnamed, they actually get/put from/to user an int */
284 switch (cmd) { 281 switch (cmd) {
285 case EXT4_IOC32_GETFLAGS: 282 case EXT4_IOC32_GETFLAGS:
@@ -319,9 +316,6 @@ long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
319 default: 316 default:
320 return -ENOIOCTLCMD; 317 return -ENOIOCTLCMD;
321 } 318 }
322 lock_kernel(); 319 return ext4_ioctl(file, cmd, (unsigned long) compat_ptr(arg));
323 ret = ext4_ioctl(inode, file, cmd, (unsigned long) compat_ptr(arg));
324 unlock_kernel();
325 return ret;
326} 320}
327#endif 321#endif
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 9d57695de746..fbec2ef93797 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -21,21 +21,7 @@
21 * mballoc.c contains the multiblocks allocation routines 21 * mballoc.c contains the multiblocks allocation routines
22 */ 22 */
23 23
24#include <linux/time.h> 24#include "mballoc.h"
25#include <linux/fs.h>
26#include <linux/namei.h>
27#include <linux/ext4_jbd2.h>
28#include <linux/ext4_fs.h>
29#include <linux/quotaops.h>
30#include <linux/buffer_head.h>
31#include <linux/module.h>
32#include <linux/swap.h>
33#include <linux/proc_fs.h>
34#include <linux/pagemap.h>
35#include <linux/seq_file.h>
36#include <linux/version.h>
37#include "group.h"
38
39/* 25/*
40 * MUSTDO: 26 * MUSTDO:
41 * - test ext4_ext_search_left() and ext4_ext_search_right() 27 * - test ext4_ext_search_left() and ext4_ext_search_right()
@@ -345,288 +331,6 @@
345 * 331 *
346 */ 332 */
347 333
348/*
349 * with AGGRESSIVE_CHECK allocator runs consistency checks over
350 * structures. these checks slow things down a lot
351 */
352#define AGGRESSIVE_CHECK__
353
354/*
355 * with DOUBLE_CHECK defined mballoc creates persistent in-core
356 * bitmaps, maintains and uses them to check for double allocations
357 */
358#define DOUBLE_CHECK__
359
360/*
361 */
362#define MB_DEBUG__
363#ifdef MB_DEBUG
364#define mb_debug(fmt, a...) printk(fmt, ##a)
365#else
366#define mb_debug(fmt, a...)
367#endif
368
369/*
370 * with EXT4_MB_HISTORY mballoc stores last N allocations in memory
371 * and you can monitor it in /proc/fs/ext4/<dev>/mb_history
372 */
373#define EXT4_MB_HISTORY
374#define EXT4_MB_HISTORY_ALLOC 1 /* allocation */
375#define EXT4_MB_HISTORY_PREALLOC 2 /* preallocated blocks used */
376#define EXT4_MB_HISTORY_DISCARD 4 /* preallocation discarded */
377#define EXT4_MB_HISTORY_FREE 8 /* free */
378
379#define EXT4_MB_HISTORY_DEFAULT (EXT4_MB_HISTORY_ALLOC | \
380 EXT4_MB_HISTORY_PREALLOC)
381
382/*
383 * How long mballoc can look for a best extent (in found extents)
384 */
385#define MB_DEFAULT_MAX_TO_SCAN 200
386
387/*
388 * How long mballoc must look for a best extent
389 */
390#define MB_DEFAULT_MIN_TO_SCAN 10
391
392/*
393 * How many groups mballoc will scan looking for the best chunk
394 */
395#define MB_DEFAULT_MAX_GROUPS_TO_SCAN 5
396
397/*
398 * with 'ext4_mb_stats' allocator will collect stats that will be
399 * shown at umount. The collecting costs though!
400 */
401#define MB_DEFAULT_STATS 1
402
403/*
404 * files smaller than MB_DEFAULT_STREAM_THRESHOLD are served
405 * by the stream allocator, which purpose is to pack requests
406 * as close each to other as possible to produce smooth I/O traffic
407 * We use locality group prealloc space for stream request.
408 * We can tune the same via /proc/fs/ext4/<parition>/stream_req
409 */
410#define MB_DEFAULT_STREAM_THRESHOLD 16 /* 64K */
411
412/*
413 * for which requests use 2^N search using buddies
414 */
415#define MB_DEFAULT_ORDER2_REQS 2
416
417/*
418 * default group prealloc size 512 blocks
419 */
420#define MB_DEFAULT_GROUP_PREALLOC 512
421
422static struct kmem_cache *ext4_pspace_cachep;
423static struct kmem_cache *ext4_ac_cachep;
424
425#ifdef EXT4_BB_MAX_BLOCKS
426#undef EXT4_BB_MAX_BLOCKS
427#endif
428#define EXT4_BB_MAX_BLOCKS 30
429
430struct ext4_free_metadata {
431 ext4_group_t group;
432 unsigned short num;
433 ext4_grpblk_t blocks[EXT4_BB_MAX_BLOCKS];
434 struct list_head list;
435};
436
437struct ext4_group_info {
438 unsigned long bb_state;
439 unsigned long bb_tid;
440 struct ext4_free_metadata *bb_md_cur;
441 unsigned short bb_first_free;
442 unsigned short bb_free;
443 unsigned short bb_fragments;
444 struct list_head bb_prealloc_list;
445#ifdef DOUBLE_CHECK
446 void *bb_bitmap;
447#endif
448 unsigned short bb_counters[];
449};
450
451#define EXT4_GROUP_INFO_NEED_INIT_BIT 0
452#define EXT4_GROUP_INFO_LOCKED_BIT 1
453
454#define EXT4_MB_GRP_NEED_INIT(grp) \
455 (test_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &((grp)->bb_state)))
456
457
458struct ext4_prealloc_space {
459 struct list_head pa_inode_list;
460 struct list_head pa_group_list;
461 union {
462 struct list_head pa_tmp_list;
463 struct rcu_head pa_rcu;
464 } u;
465 spinlock_t pa_lock;
466 atomic_t pa_count;
467 unsigned pa_deleted;
468 ext4_fsblk_t pa_pstart; /* phys. block */
469 ext4_lblk_t pa_lstart; /* log. block */
470 unsigned short pa_len; /* len of preallocated chunk */
471 unsigned short pa_free; /* how many blocks are free */
472 unsigned short pa_linear; /* consumed in one direction
473 * strictly, for grp prealloc */
474 spinlock_t *pa_obj_lock;
475 struct inode *pa_inode; /* hack, for history only */
476};
477
478
479struct ext4_free_extent {
480 ext4_lblk_t fe_logical;
481 ext4_grpblk_t fe_start;
482 ext4_group_t fe_group;
483 int fe_len;
484};
485
486/*
487 * Locality group:
488 * we try to group all related changes together
489 * so that writeback can flush/allocate them together as well
490 */
491struct ext4_locality_group {
492 /* for allocator */
493 struct mutex lg_mutex; /* to serialize allocates */
494 struct list_head lg_prealloc_list;/* list of preallocations */
495 spinlock_t lg_prealloc_lock;
496};
497
498struct ext4_allocation_context {
499 struct inode *ac_inode;
500 struct super_block *ac_sb;
501
502 /* original request */
503 struct ext4_free_extent ac_o_ex;
504
505 /* goal request (after normalization) */
506 struct ext4_free_extent ac_g_ex;
507
508 /* the best found extent */
509 struct ext4_free_extent ac_b_ex;
510
511 /* copy of the bext found extent taken before preallocation efforts */
512 struct ext4_free_extent ac_f_ex;
513
514 /* number of iterations done. we have to track to limit searching */
515 unsigned long ac_ex_scanned;
516 __u16 ac_groups_scanned;
517 __u16 ac_found;
518 __u16 ac_tail;
519 __u16 ac_buddy;
520 __u16 ac_flags; /* allocation hints */
521 __u8 ac_status;
522 __u8 ac_criteria;
523 __u8 ac_repeats;
524 __u8 ac_2order; /* if request is to allocate 2^N blocks and
525 * N > 0, the field stores N, otherwise 0 */
526 __u8 ac_op; /* operation, for history only */
527 struct page *ac_bitmap_page;
528 struct page *ac_buddy_page;
529 struct ext4_prealloc_space *ac_pa;
530 struct ext4_locality_group *ac_lg;
531};
532
533#define AC_STATUS_CONTINUE 1
534#define AC_STATUS_FOUND 2
535#define AC_STATUS_BREAK 3
536
537struct ext4_mb_history {
538 struct ext4_free_extent orig; /* orig allocation */
539 struct ext4_free_extent goal; /* goal allocation */
540 struct ext4_free_extent result; /* result allocation */
541 unsigned pid;
542 unsigned ino;
543 __u16 found; /* how many extents have been found */
544 __u16 groups; /* how many groups have been scanned */
545 __u16 tail; /* what tail broke some buddy */
546 __u16 buddy; /* buddy the tail ^^^ broke */
547 __u16 flags;
548 __u8 cr:3; /* which phase the result extent was found at */
549 __u8 op:4;
550 __u8 merged:1;
551};
552
553struct ext4_buddy {
554 struct page *bd_buddy_page;
555 void *bd_buddy;
556 struct page *bd_bitmap_page;
557 void *bd_bitmap;
558 struct ext4_group_info *bd_info;
559 struct super_block *bd_sb;
560 __u16 bd_blkbits;
561 ext4_group_t bd_group;
562};
563#define EXT4_MB_BITMAP(e4b) ((e4b)->bd_bitmap)
564#define EXT4_MB_BUDDY(e4b) ((e4b)->bd_buddy)
565
566#ifndef EXT4_MB_HISTORY
567static inline void ext4_mb_store_history(struct ext4_allocation_context *ac)
568{
569 return;
570}
571#else
572static void ext4_mb_store_history(struct ext4_allocation_context *ac);
573#endif
574
575#define in_range(b, first, len) ((b) >= (first) && (b) <= (first) + (len) - 1)
576
577static struct proc_dir_entry *proc_root_ext4;
578struct buffer_head *read_block_bitmap(struct super_block *, ext4_group_t);
579ext4_fsblk_t ext4_new_blocks_old(handle_t *handle, struct inode *inode,
580 ext4_fsblk_t goal, unsigned long *count, int *errp);
581
582static void ext4_mb_generate_from_pa(struct super_block *sb, void *bitmap,
583 ext4_group_t group);
584static void ext4_mb_poll_new_transaction(struct super_block *, handle_t *);
585static void ext4_mb_free_committed_blocks(struct super_block *);
586static void ext4_mb_return_to_preallocation(struct inode *inode,
587 struct ext4_buddy *e4b, sector_t block,
588 int count);
589static void ext4_mb_put_pa(struct ext4_allocation_context *,
590 struct super_block *, struct ext4_prealloc_space *pa);
591static int ext4_mb_init_per_dev_proc(struct super_block *sb);
592static int ext4_mb_destroy_per_dev_proc(struct super_block *sb);
593
594
595static inline void ext4_lock_group(struct super_block *sb, ext4_group_t group)
596{
597 struct ext4_group_info *grinfo = ext4_get_group_info(sb, group);
598
599 bit_spin_lock(EXT4_GROUP_INFO_LOCKED_BIT, &(grinfo->bb_state));
600}
601
602static inline void ext4_unlock_group(struct super_block *sb,
603 ext4_group_t group)
604{
605 struct ext4_group_info *grinfo = ext4_get_group_info(sb, group);
606
607 bit_spin_unlock(EXT4_GROUP_INFO_LOCKED_BIT, &(grinfo->bb_state));
608}
609
610static inline int ext4_is_group_locked(struct super_block *sb,
611 ext4_group_t group)
612{
613 struct ext4_group_info *grinfo = ext4_get_group_info(sb, group);
614
615 return bit_spin_is_locked(EXT4_GROUP_INFO_LOCKED_BIT,
616 &(grinfo->bb_state));
617}
618
619static ext4_fsblk_t ext4_grp_offs_to_block(struct super_block *sb,
620 struct ext4_free_extent *fex)
621{
622 ext4_fsblk_t block;
623
624 block = (ext4_fsblk_t) fex->fe_group * EXT4_BLOCKS_PER_GROUP(sb)
625 + fex->fe_start
626 + le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block);
627 return block;
628}
629
630static inline void *mb_correct_addr_and_bit(int *bit, void *addr) 334static inline void *mb_correct_addr_and_bit(int *bit, void *addr)
631{ 335{
632#if BITS_PER_LONG == 64 336#if BITS_PER_LONG == 64
@@ -736,7 +440,7 @@ static void mb_free_blocks_double(struct inode *inode, struct ext4_buddy *e4b,
736 blocknr += 440 blocknr +=
737 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block); 441 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block);
738 442
739 ext4_error(sb, __FUNCTION__, "double-free of inode" 443 ext4_error(sb, __func__, "double-free of inode"
740 " %lu's block %llu(bit %u in group %lu)\n", 444 " %lu's block %llu(bit %u in group %lu)\n",
741 inode ? inode->i_ino : 0, blocknr, 445 inode ? inode->i_ino : 0, blocknr,
742 first + i, e4b->bd_group); 446 first + i, e4b->bd_group);
@@ -898,17 +602,17 @@ static int __mb_check_buddy(struct ext4_buddy *e4b, char *file,
898 list_for_each(cur, &grp->bb_prealloc_list) { 602 list_for_each(cur, &grp->bb_prealloc_list) {
899 ext4_group_t groupnr; 603 ext4_group_t groupnr;
900 struct ext4_prealloc_space *pa; 604 struct ext4_prealloc_space *pa;
901 pa = list_entry(cur, struct ext4_prealloc_space, group_list); 605 pa = list_entry(cur, struct ext4_prealloc_space, pa_group_list);
902 ext4_get_group_no_and_offset(sb, pa->pstart, &groupnr, &k); 606 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &groupnr, &k);
903 MB_CHECK_ASSERT(groupnr == e4b->bd_group); 607 MB_CHECK_ASSERT(groupnr == e4b->bd_group);
904 for (i = 0; i < pa->len; i++) 608 for (i = 0; i < pa->pa_len; i++)
905 MB_CHECK_ASSERT(mb_test_bit(k + i, buddy)); 609 MB_CHECK_ASSERT(mb_test_bit(k + i, buddy));
906 } 610 }
907 return 0; 611 return 0;
908} 612}
909#undef MB_CHECK_ASSERT 613#undef MB_CHECK_ASSERT
910#define mb_check_buddy(e4b) __mb_check_buddy(e4b, \ 614#define mb_check_buddy(e4b) __mb_check_buddy(e4b, \
911 __FILE__, __FUNCTION__, __LINE__) 615 __FILE__, __func__, __LINE__)
912#else 616#else
913#define mb_check_buddy(e4b) 617#define mb_check_buddy(e4b)
914#endif 618#endif
@@ -982,7 +686,7 @@ static void ext4_mb_generate_buddy(struct super_block *sb,
982 grp->bb_fragments = fragments; 686 grp->bb_fragments = fragments;
983 687
984 if (free != grp->bb_free) { 688 if (free != grp->bb_free) {
985 ext4_error(sb, __FUNCTION__, 689 ext4_error(sb, __func__,
986 "EXT4-fs: group %lu: %u blocks in bitmap, %u in gd\n", 690 "EXT4-fs: group %lu: %u blocks in bitmap, %u in gd\n",
987 group, free, grp->bb_free); 691 group, free, grp->bb_free);
988 /* 692 /*
@@ -1168,8 +872,9 @@ out:
1168 return err; 872 return err;
1169} 873}
1170 874
1171static int ext4_mb_load_buddy(struct super_block *sb, ext4_group_t group, 875static noinline_for_stack int
1172 struct ext4_buddy *e4b) 876ext4_mb_load_buddy(struct super_block *sb, ext4_group_t group,
877 struct ext4_buddy *e4b)
1173{ 878{
1174 struct ext4_sb_info *sbi = EXT4_SB(sb); 879 struct ext4_sb_info *sbi = EXT4_SB(sb);
1175 struct inode *inode = sbi->s_buddy_cache; 880 struct inode *inode = sbi->s_buddy_cache;
@@ -1367,7 +1072,7 @@ static int mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b,
1367 blocknr += 1072 blocknr +=
1368 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block); 1073 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block);
1369 1074
1370 ext4_error(sb, __FUNCTION__, "double-free of inode" 1075 ext4_error(sb, __func__, "double-free of inode"
1371 " %lu's block %llu(bit %u in group %lu)\n", 1076 " %lu's block %llu(bit %u in group %lu)\n",
1372 inode ? inode->i_ino : 0, blocknr, block, 1077 inode ? inode->i_ino : 0, blocknr, block,
1373 e4b->bd_group); 1078 e4b->bd_group);
@@ -1848,7 +1553,7 @@ static void ext4_mb_complex_scan_group(struct ext4_allocation_context *ac,
1848 * free blocks even though group info says we 1553 * free blocks even though group info says we
1849 * we have free blocks 1554 * we have free blocks
1850 */ 1555 */
1851 ext4_error(sb, __FUNCTION__, "%d free blocks as per " 1556 ext4_error(sb, __func__, "%d free blocks as per "
1852 "group info. But bitmap says 0\n", 1557 "group info. But bitmap says 0\n",
1853 free); 1558 free);
1854 break; 1559 break;
@@ -1857,7 +1562,7 @@ static void ext4_mb_complex_scan_group(struct ext4_allocation_context *ac,
1857 mb_find_extent(e4b, 0, i, ac->ac_g_ex.fe_len, &ex); 1562 mb_find_extent(e4b, 0, i, ac->ac_g_ex.fe_len, &ex);
1858 BUG_ON(ex.fe_len <= 0); 1563 BUG_ON(ex.fe_len <= 0);
1859 if (free < ex.fe_len) { 1564 if (free < ex.fe_len) {
1860 ext4_error(sb, __FUNCTION__, "%d free blocks as per " 1565 ext4_error(sb, __func__, "%d free blocks as per "
1861 "group info. But got %d blocks\n", 1566 "group info. But got %d blocks\n",
1862 free, ex.fe_len); 1567 free, ex.fe_len);
1863 /* 1568 /*
@@ -1965,7 +1670,8 @@ static int ext4_mb_good_group(struct ext4_allocation_context *ac,
1965 return 0; 1670 return 0;
1966} 1671}
1967 1672
1968static int ext4_mb_regular_allocator(struct ext4_allocation_context *ac) 1673static noinline_for_stack int
1674ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
1969{ 1675{
1970 ext4_group_t group; 1676 ext4_group_t group;
1971 ext4_group_t i; 1677 ext4_group_t i;
@@ -2465,7 +2171,8 @@ static void ext4_mb_history_init(struct super_block *sb)
2465 /* if we can't allocate history, then we simple won't use it */ 2171 /* if we can't allocate history, then we simple won't use it */
2466} 2172}
2467 2173
2468static void ext4_mb_store_history(struct ext4_allocation_context *ac) 2174static noinline_for_stack void
2175ext4_mb_store_history(struct ext4_allocation_context *ac)
2469{ 2176{
2470 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb); 2177 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
2471 struct ext4_mb_history h; 2178 struct ext4_mb_history h;
@@ -2565,13 +2272,13 @@ static int ext4_mb_init_backend(struct super_block *sb)
2565 meta_group_info[j] = kzalloc(len, GFP_KERNEL); 2272 meta_group_info[j] = kzalloc(len, GFP_KERNEL);
2566 if (meta_group_info[j] == NULL) { 2273 if (meta_group_info[j] == NULL) {
2567 printk(KERN_ERR "EXT4-fs: can't allocate buddy mem\n"); 2274 printk(KERN_ERR "EXT4-fs: can't allocate buddy mem\n");
2568 i--;
2569 goto err_freebuddy; 2275 goto err_freebuddy;
2570 } 2276 }
2571 desc = ext4_get_group_desc(sb, i, NULL); 2277 desc = ext4_get_group_desc(sb, i, NULL);
2572 if (desc == NULL) { 2278 if (desc == NULL) {
2573 printk(KERN_ERR 2279 printk(KERN_ERR
2574 "EXT4-fs: can't read descriptor %lu\n", i); 2280 "EXT4-fs: can't read descriptor %lu\n", i);
2281 i++;
2575 goto err_freebuddy; 2282 goto err_freebuddy;
2576 } 2283 }
2577 memset(meta_group_info[j], 0, len); 2284 memset(meta_group_info[j], 0, len);
@@ -2611,13 +2318,11 @@ static int ext4_mb_init_backend(struct super_block *sb)
2611 return 0; 2318 return 0;
2612 2319
2613err_freebuddy: 2320err_freebuddy:
2614 while (i >= 0) { 2321 while (i-- > 0)
2615 kfree(ext4_get_group_info(sb, i)); 2322 kfree(ext4_get_group_info(sb, i));
2616 i--;
2617 }
2618 i = num_meta_group_infos; 2323 i = num_meta_group_infos;
2619err_freemeta: 2324err_freemeta:
2620 while (--i >= 0) 2325 while (i-- > 0)
2621 kfree(sbi->s_group_info[i]); 2326 kfree(sbi->s_group_info[i]);
2622 iput(sbi->s_buddy_cache); 2327 iput(sbi->s_buddy_cache);
2623err_freesgi: 2328err_freesgi:
@@ -2801,7 +2506,8 @@ int ext4_mb_release(struct super_block *sb)
2801 return 0; 2506 return 0;
2802} 2507}
2803 2508
2804static void ext4_mb_free_committed_blocks(struct super_block *sb) 2509static noinline_for_stack void
2510ext4_mb_free_committed_blocks(struct super_block *sb)
2805{ 2511{
2806 struct ext4_sb_info *sbi = EXT4_SB(sb); 2512 struct ext4_sb_info *sbi = EXT4_SB(sb);
2807 int err; 2513 int err;
@@ -3021,7 +2727,8 @@ void exit_ext4_mballoc(void)
3021 * Check quota and mark choosed space (ac->ac_b_ex) non-free in bitmaps 2727 * Check quota and mark choosed space (ac->ac_b_ex) non-free in bitmaps
3022 * Returns 0 if success or error code 2728 * Returns 0 if success or error code
3023 */ 2729 */
3024static int ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac, 2730static noinline_for_stack int
2731ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,
3025 handle_t *handle) 2732 handle_t *handle)
3026{ 2733{
3027 struct buffer_head *bitmap_bh = NULL; 2734 struct buffer_head *bitmap_bh = NULL;
@@ -3070,7 +2777,7 @@ static int ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,
3070 in_range(block, ext4_inode_table(sb, gdp), 2777 in_range(block, ext4_inode_table(sb, gdp),
3071 EXT4_SB(sb)->s_itb_per_group)) { 2778 EXT4_SB(sb)->s_itb_per_group)) {
3072 2779
3073 ext4_error(sb, __FUNCTION__, 2780 ext4_error(sb, __func__,
3074 "Allocating block in system zone - block = %llu", 2781 "Allocating block in system zone - block = %llu",
3075 block); 2782 block);
3076 } 2783 }
@@ -3094,9 +2801,7 @@ static int ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,
3094 ac->ac_b_ex.fe_group, 2801 ac->ac_b_ex.fe_group,
3095 gdp)); 2802 gdp));
3096 } 2803 }
3097 gdp->bg_free_blocks_count = 2804 le16_add_cpu(&gdp->bg_free_blocks_count, -ac->ac_b_ex.fe_len);
3098 cpu_to_le16(le16_to_cpu(gdp->bg_free_blocks_count)
3099 - ac->ac_b_ex.fe_len);
3100 gdp->bg_checksum = ext4_group_desc_csum(sbi, ac->ac_b_ex.fe_group, gdp); 2805 gdp->bg_checksum = ext4_group_desc_csum(sbi, ac->ac_b_ex.fe_group, gdp);
3101 spin_unlock(sb_bgl_lock(sbi, ac->ac_b_ex.fe_group)); 2806 spin_unlock(sb_bgl_lock(sbi, ac->ac_b_ex.fe_group));
3102 percpu_counter_sub(&sbi->s_freeblocks_counter, ac->ac_b_ex.fe_len); 2807 percpu_counter_sub(&sbi->s_freeblocks_counter, ac->ac_b_ex.fe_len);
@@ -3130,7 +2835,7 @@ static void ext4_mb_normalize_group_request(struct ext4_allocation_context *ac)
3130 ac->ac_g_ex.fe_len = EXT4_SB(sb)->s_stripe; 2835 ac->ac_g_ex.fe_len = EXT4_SB(sb)->s_stripe;
3131 else 2836 else
3132 ac->ac_g_ex.fe_len = EXT4_SB(sb)->s_mb_group_prealloc; 2837 ac->ac_g_ex.fe_len = EXT4_SB(sb)->s_mb_group_prealloc;
3133 mb_debug("#%u: goal %lu blocks for locality group\n", 2838 mb_debug("#%u: goal %u blocks for locality group\n",
3134 current->pid, ac->ac_g_ex.fe_len); 2839 current->pid, ac->ac_g_ex.fe_len);
3135} 2840}
3136 2841
@@ -3138,15 +2843,16 @@ static void ext4_mb_normalize_group_request(struct ext4_allocation_context *ac)
3138 * Normalization means making request better in terms of 2843 * Normalization means making request better in terms of
3139 * size and alignment 2844 * size and alignment
3140 */ 2845 */
3141static void ext4_mb_normalize_request(struct ext4_allocation_context *ac, 2846static noinline_for_stack void
2847ext4_mb_normalize_request(struct ext4_allocation_context *ac,
3142 struct ext4_allocation_request *ar) 2848 struct ext4_allocation_request *ar)
3143{ 2849{
3144 int bsbits, max; 2850 int bsbits, max;
3145 ext4_lblk_t end; 2851 ext4_lblk_t end;
3146 struct list_head *cur;
3147 loff_t size, orig_size, start_off; 2852 loff_t size, orig_size, start_off;
3148 ext4_lblk_t start, orig_start; 2853 ext4_lblk_t start, orig_start;
3149 struct ext4_inode_info *ei = EXT4_I(ac->ac_inode); 2854 struct ext4_inode_info *ei = EXT4_I(ac->ac_inode);
2855 struct ext4_prealloc_space *pa;
3150 2856
3151 /* do normalize only data requests, metadata requests 2857 /* do normalize only data requests, metadata requests
3152 do not need preallocation */ 2858 do not need preallocation */
@@ -3232,12 +2938,9 @@ static void ext4_mb_normalize_request(struct ext4_allocation_context *ac,
3232 2938
3233 /* check we don't cross already preallocated blocks */ 2939 /* check we don't cross already preallocated blocks */
3234 rcu_read_lock(); 2940 rcu_read_lock();
3235 list_for_each_rcu(cur, &ei->i_prealloc_list) { 2941 list_for_each_entry_rcu(pa, &ei->i_prealloc_list, pa_inode_list) {
3236 struct ext4_prealloc_space *pa;
3237 unsigned long pa_end; 2942 unsigned long pa_end;
3238 2943
3239 pa = list_entry(cur, struct ext4_prealloc_space, pa_inode_list);
3240
3241 if (pa->pa_deleted) 2944 if (pa->pa_deleted)
3242 continue; 2945 continue;
3243 spin_lock(&pa->pa_lock); 2946 spin_lock(&pa->pa_lock);
@@ -3279,10 +2982,8 @@ static void ext4_mb_normalize_request(struct ext4_allocation_context *ac,
3279 2982
3280 /* XXX: extra loop to check we really don't overlap preallocations */ 2983 /* XXX: extra loop to check we really don't overlap preallocations */
3281 rcu_read_lock(); 2984 rcu_read_lock();
3282 list_for_each_rcu(cur, &ei->i_prealloc_list) { 2985 list_for_each_entry_rcu(pa, &ei->i_prealloc_list, pa_inode_list) {
3283 struct ext4_prealloc_space *pa;
3284 unsigned long pa_end; 2986 unsigned long pa_end;
3285 pa = list_entry(cur, struct ext4_prealloc_space, pa_inode_list);
3286 spin_lock(&pa->pa_lock); 2987 spin_lock(&pa->pa_lock);
3287 if (pa->pa_deleted == 0) { 2988 if (pa->pa_deleted == 0) {
3288 pa_end = pa->pa_lstart + pa->pa_len; 2989 pa_end = pa->pa_lstart + pa->pa_len;
@@ -3374,7 +3075,7 @@ static void ext4_mb_use_inode_pa(struct ext4_allocation_context *ac,
3374 BUG_ON(pa->pa_free < len); 3075 BUG_ON(pa->pa_free < len);
3375 pa->pa_free -= len; 3076 pa->pa_free -= len;
3376 3077
3377 mb_debug("use %llu/%lu from inode pa %p\n", start, len, pa); 3078 mb_debug("use %llu/%u from inode pa %p\n", start, len, pa);
3378} 3079}
3379 3080
3380/* 3081/*
@@ -3404,12 +3105,12 @@ static void ext4_mb_use_group_pa(struct ext4_allocation_context *ac,
3404/* 3105/*
3405 * search goal blocks in preallocated space 3106 * search goal blocks in preallocated space
3406 */ 3107 */
3407static int ext4_mb_use_preallocated(struct ext4_allocation_context *ac) 3108static noinline_for_stack int
3109ext4_mb_use_preallocated(struct ext4_allocation_context *ac)
3408{ 3110{
3409 struct ext4_inode_info *ei = EXT4_I(ac->ac_inode); 3111 struct ext4_inode_info *ei = EXT4_I(ac->ac_inode);
3410 struct ext4_locality_group *lg; 3112 struct ext4_locality_group *lg;
3411 struct ext4_prealloc_space *pa; 3113 struct ext4_prealloc_space *pa;
3412 struct list_head *cur;
3413 3114
3414 /* only data can be preallocated */ 3115 /* only data can be preallocated */
3415 if (!(ac->ac_flags & EXT4_MB_HINT_DATA)) 3116 if (!(ac->ac_flags & EXT4_MB_HINT_DATA))
@@ -3417,8 +3118,7 @@ static int ext4_mb_use_preallocated(struct ext4_allocation_context *ac)
3417 3118
3418 /* first, try per-file preallocation */ 3119 /* first, try per-file preallocation */
3419 rcu_read_lock(); 3120 rcu_read_lock();
3420 list_for_each_rcu(cur, &ei->i_prealloc_list) { 3121 list_for_each_entry_rcu(pa, &ei->i_prealloc_list, pa_inode_list) {
3421 pa = list_entry(cur, struct ext4_prealloc_space, pa_inode_list);
3422 3122
3423 /* all fields in this condition don't change, 3123 /* all fields in this condition don't change,
3424 * so we can skip locking for them */ 3124 * so we can skip locking for them */
@@ -3450,8 +3150,7 @@ static int ext4_mb_use_preallocated(struct ext4_allocation_context *ac)
3450 return 0; 3150 return 0;
3451 3151
3452 rcu_read_lock(); 3152 rcu_read_lock();
3453 list_for_each_rcu(cur, &lg->lg_prealloc_list) { 3153 list_for_each_entry_rcu(pa, &lg->lg_prealloc_list, pa_inode_list) {
3454 pa = list_entry(cur, struct ext4_prealloc_space, pa_inode_list);
3455 spin_lock(&pa->pa_lock); 3154 spin_lock(&pa->pa_lock);
3456 if (pa->pa_deleted == 0 && pa->pa_free >= ac->ac_o_ex.fe_len) { 3155 if (pa->pa_deleted == 0 && pa->pa_free >= ac->ac_o_ex.fe_len) {
3457 atomic_inc(&pa->pa_count); 3156 atomic_inc(&pa->pa_count);
@@ -3571,7 +3270,8 @@ static void ext4_mb_put_pa(struct ext4_allocation_context *ac,
3571/* 3270/*
3572 * creates new preallocated space for given inode 3271 * creates new preallocated space for given inode
3573 */ 3272 */
3574static int ext4_mb_new_inode_pa(struct ext4_allocation_context *ac) 3273static noinline_for_stack int
3274ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
3575{ 3275{
3576 struct super_block *sb = ac->ac_sb; 3276 struct super_block *sb = ac->ac_sb;
3577 struct ext4_prealloc_space *pa; 3277 struct ext4_prealloc_space *pa;
@@ -3658,7 +3358,8 @@ static int ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
3658/* 3358/*
3659 * creates new preallocated space for locality group inodes belongs to 3359 * creates new preallocated space for locality group inodes belongs to
3660 */ 3360 */
3661static int ext4_mb_new_group_pa(struct ext4_allocation_context *ac) 3361static noinline_for_stack int
3362ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
3662{ 3363{
3663 struct super_block *sb = ac->ac_sb; 3364 struct super_block *sb = ac->ac_sb;
3664 struct ext4_locality_group *lg; 3365 struct ext4_locality_group *lg;
@@ -3731,11 +3432,11 @@ static int ext4_mb_new_preallocation(struct ext4_allocation_context *ac)
3731 * the caller MUST hold group/inode locks. 3432 * the caller MUST hold group/inode locks.
3732 * TODO: optimize the case when there are no in-core structures yet 3433 * TODO: optimize the case when there are no in-core structures yet
3733 */ 3434 */
3734static int ext4_mb_release_inode_pa(struct ext4_buddy *e4b, 3435static noinline_for_stack int
3735 struct buffer_head *bitmap_bh, 3436ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
3736 struct ext4_prealloc_space *pa) 3437 struct ext4_prealloc_space *pa,
3438 struct ext4_allocation_context *ac)
3737{ 3439{
3738 struct ext4_allocation_context *ac;
3739 struct super_block *sb = e4b->bd_sb; 3440 struct super_block *sb = e4b->bd_sb;
3740 struct ext4_sb_info *sbi = EXT4_SB(sb); 3441 struct ext4_sb_info *sbi = EXT4_SB(sb);
3741 unsigned long end; 3442 unsigned long end;
@@ -3751,8 +3452,6 @@ static int ext4_mb_release_inode_pa(struct ext4_buddy *e4b,
3751 BUG_ON(group != e4b->bd_group && pa->pa_len != 0); 3452 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
3752 end = bit + pa->pa_len; 3453 end = bit + pa->pa_len;
3753 3454
3754 ac = kmem_cache_alloc(ext4_ac_cachep, GFP_NOFS);
3755
3756 if (ac) { 3455 if (ac) {
3757 ac->ac_sb = sb; 3456 ac->ac_sb = sb;
3758 ac->ac_inode = pa->pa_inode; 3457 ac->ac_inode = pa->pa_inode;
@@ -3789,7 +3488,7 @@ static int ext4_mb_release_inode_pa(struct ext4_buddy *e4b,
3789 pa, (unsigned long) pa->pa_lstart, 3488 pa, (unsigned long) pa->pa_lstart,
3790 (unsigned long) pa->pa_pstart, 3489 (unsigned long) pa->pa_pstart,
3791 (unsigned long) pa->pa_len); 3490 (unsigned long) pa->pa_len);
3792 ext4_error(sb, __FUNCTION__, "free %u, pa_free %u\n", 3491 ext4_error(sb, __func__, "free %u, pa_free %u\n",
3793 free, pa->pa_free); 3492 free, pa->pa_free);
3794 /* 3493 /*
3795 * pa is already deleted so we use the value obtained 3494 * pa is already deleted so we use the value obtained
@@ -3797,22 +3496,19 @@ static int ext4_mb_release_inode_pa(struct ext4_buddy *e4b,
3797 */ 3496 */
3798 } 3497 }
3799 atomic_add(free, &sbi->s_mb_discarded); 3498 atomic_add(free, &sbi->s_mb_discarded);
3800 if (ac)
3801 kmem_cache_free(ext4_ac_cachep, ac);
3802 3499
3803 return err; 3500 return err;
3804} 3501}
3805 3502
3806static int ext4_mb_release_group_pa(struct ext4_buddy *e4b, 3503static noinline_for_stack int
3807 struct ext4_prealloc_space *pa) 3504ext4_mb_release_group_pa(struct ext4_buddy *e4b,
3505 struct ext4_prealloc_space *pa,
3506 struct ext4_allocation_context *ac)
3808{ 3507{
3809 struct ext4_allocation_context *ac;
3810 struct super_block *sb = e4b->bd_sb; 3508 struct super_block *sb = e4b->bd_sb;
3811 ext4_group_t group; 3509 ext4_group_t group;
3812 ext4_grpblk_t bit; 3510 ext4_grpblk_t bit;
3813 3511
3814 ac = kmem_cache_alloc(ext4_ac_cachep, GFP_NOFS);
3815
3816 if (ac) 3512 if (ac)
3817 ac->ac_op = EXT4_MB_HISTORY_DISCARD; 3513 ac->ac_op = EXT4_MB_HISTORY_DISCARD;
3818 3514
@@ -3830,7 +3526,6 @@ static int ext4_mb_release_group_pa(struct ext4_buddy *e4b,
3830 ac->ac_b_ex.fe_len = pa->pa_len; 3526 ac->ac_b_ex.fe_len = pa->pa_len;
3831 ac->ac_b_ex.fe_logical = 0; 3527 ac->ac_b_ex.fe_logical = 0;
3832 ext4_mb_store_history(ac); 3528 ext4_mb_store_history(ac);
3833 kmem_cache_free(ext4_ac_cachep, ac);
3834 } 3529 }
3835 3530
3836 return 0; 3531 return 0;
@@ -3845,12 +3540,14 @@ static int ext4_mb_release_group_pa(struct ext4_buddy *e4b,
3845 * - how many do we discard 3540 * - how many do we discard
3846 * 1) how many requested 3541 * 1) how many requested
3847 */ 3542 */
3848static int ext4_mb_discard_group_preallocations(struct super_block *sb, 3543static noinline_for_stack int
3544ext4_mb_discard_group_preallocations(struct super_block *sb,
3849 ext4_group_t group, int needed) 3545 ext4_group_t group, int needed)
3850{ 3546{
3851 struct ext4_group_info *grp = ext4_get_group_info(sb, group); 3547 struct ext4_group_info *grp = ext4_get_group_info(sb, group);
3852 struct buffer_head *bitmap_bh = NULL; 3548 struct buffer_head *bitmap_bh = NULL;
3853 struct ext4_prealloc_space *pa, *tmp; 3549 struct ext4_prealloc_space *pa, *tmp;
3550 struct ext4_allocation_context *ac;
3854 struct list_head list; 3551 struct list_head list;
3855 struct ext4_buddy e4b; 3552 struct ext4_buddy e4b;
3856 int err; 3553 int err;
@@ -3878,6 +3575,7 @@ static int ext4_mb_discard_group_preallocations(struct super_block *sb,
3878 grp = ext4_get_group_info(sb, group); 3575 grp = ext4_get_group_info(sb, group);
3879 INIT_LIST_HEAD(&list); 3576 INIT_LIST_HEAD(&list);
3880 3577
3578 ac = kmem_cache_alloc(ext4_ac_cachep, GFP_NOFS);
3881repeat: 3579repeat:
3882 ext4_lock_group(sb, group); 3580 ext4_lock_group(sb, group);
3883 list_for_each_entry_safe(pa, tmp, 3581 list_for_each_entry_safe(pa, tmp,
@@ -3932,9 +3630,9 @@ repeat:
3932 spin_unlock(pa->pa_obj_lock); 3630 spin_unlock(pa->pa_obj_lock);
3933 3631
3934 if (pa->pa_linear) 3632 if (pa->pa_linear)
3935 ext4_mb_release_group_pa(&e4b, pa); 3633 ext4_mb_release_group_pa(&e4b, pa, ac);
3936 else 3634 else
3937 ext4_mb_release_inode_pa(&e4b, bitmap_bh, pa); 3635 ext4_mb_release_inode_pa(&e4b, bitmap_bh, pa, ac);
3938 3636
3939 list_del(&pa->u.pa_tmp_list); 3637 list_del(&pa->u.pa_tmp_list);
3940 call_rcu(&(pa)->u.pa_rcu, ext4_mb_pa_callback); 3638 call_rcu(&(pa)->u.pa_rcu, ext4_mb_pa_callback);
@@ -3942,6 +3640,8 @@ repeat:
3942 3640
3943out: 3641out:
3944 ext4_unlock_group(sb, group); 3642 ext4_unlock_group(sb, group);
3643 if (ac)
3644 kmem_cache_free(ext4_ac_cachep, ac);
3945 ext4_mb_release_desc(&e4b); 3645 ext4_mb_release_desc(&e4b);
3946 put_bh(bitmap_bh); 3646 put_bh(bitmap_bh);
3947 return free; 3647 return free;
@@ -3962,6 +3662,7 @@ void ext4_mb_discard_inode_preallocations(struct inode *inode)
3962 struct super_block *sb = inode->i_sb; 3662 struct super_block *sb = inode->i_sb;
3963 struct buffer_head *bitmap_bh = NULL; 3663 struct buffer_head *bitmap_bh = NULL;
3964 struct ext4_prealloc_space *pa, *tmp; 3664 struct ext4_prealloc_space *pa, *tmp;
3665 struct ext4_allocation_context *ac;
3965 ext4_group_t group = 0; 3666 ext4_group_t group = 0;
3966 struct list_head list; 3667 struct list_head list;
3967 struct ext4_buddy e4b; 3668 struct ext4_buddy e4b;
@@ -3976,6 +3677,7 @@ void ext4_mb_discard_inode_preallocations(struct inode *inode)
3976 3677
3977 INIT_LIST_HEAD(&list); 3678 INIT_LIST_HEAD(&list);
3978 3679
3680 ac = kmem_cache_alloc(ext4_ac_cachep, GFP_NOFS);
3979repeat: 3681repeat:
3980 /* first, collect all pa's in the inode */ 3682 /* first, collect all pa's in the inode */
3981 spin_lock(&ei->i_prealloc_lock); 3683 spin_lock(&ei->i_prealloc_lock);
@@ -4040,7 +3742,7 @@ repeat:
4040 3742
4041 ext4_lock_group(sb, group); 3743 ext4_lock_group(sb, group);
4042 list_del(&pa->pa_group_list); 3744 list_del(&pa->pa_group_list);
4043 ext4_mb_release_inode_pa(&e4b, bitmap_bh, pa); 3745 ext4_mb_release_inode_pa(&e4b, bitmap_bh, pa, ac);
4044 ext4_unlock_group(sb, group); 3746 ext4_unlock_group(sb, group);
4045 3747
4046 ext4_mb_release_desc(&e4b); 3748 ext4_mb_release_desc(&e4b);
@@ -4049,6 +3751,8 @@ repeat:
4049 list_del(&pa->u.pa_tmp_list); 3751 list_del(&pa->u.pa_tmp_list);
4050 call_rcu(&(pa)->u.pa_rcu, ext4_mb_pa_callback); 3752 call_rcu(&(pa)->u.pa_rcu, ext4_mb_pa_callback);
4051 } 3753 }
3754 if (ac)
3755 kmem_cache_free(ext4_ac_cachep, ac);
4052} 3756}
4053 3757
4054/* 3758/*
@@ -4108,7 +3812,7 @@ static void ext4_mb_show_ac(struct ext4_allocation_context *ac)
4108 printk(KERN_ERR "PA:%lu:%d:%u \n", i, 3812 printk(KERN_ERR "PA:%lu:%d:%u \n", i,
4109 start, pa->pa_len); 3813 start, pa->pa_len);
4110 } 3814 }
4111 ext4_lock_group(sb, i); 3815 ext4_unlock_group(sb, i);
4112 3816
4113 if (grp->bb_free == 0) 3817 if (grp->bb_free == 0)
4114 continue; 3818 continue;
@@ -4167,7 +3871,8 @@ static void ext4_mb_group_or_file(struct ext4_allocation_context *ac)
4167 mutex_lock(&ac->ac_lg->lg_mutex); 3871 mutex_lock(&ac->ac_lg->lg_mutex);
4168} 3872}
4169 3873
4170static int ext4_mb_initialize_context(struct ext4_allocation_context *ac, 3874static noinline_for_stack int
3875ext4_mb_initialize_context(struct ext4_allocation_context *ac,
4171 struct ext4_allocation_request *ar) 3876 struct ext4_allocation_request *ar)
4172{ 3877{
4173 struct super_block *sb = ar->inode->i_sb; 3878 struct super_block *sb = ar->inode->i_sb;
@@ -4398,7 +4103,8 @@ static void ext4_mb_poll_new_transaction(struct super_block *sb,
4398 ext4_mb_free_committed_blocks(sb); 4103 ext4_mb_free_committed_blocks(sb);
4399} 4104}
4400 4105
4401static int ext4_mb_free_metadata(handle_t *handle, struct ext4_buddy *e4b, 4106static noinline_for_stack int
4107ext4_mb_free_metadata(handle_t *handle, struct ext4_buddy *e4b,
4402 ext4_group_t group, ext4_grpblk_t block, int count) 4108 ext4_group_t group, ext4_grpblk_t block, int count)
4403{ 4109{
4404 struct ext4_group_info *db = e4b->bd_info; 4110 struct ext4_group_info *db = e4b->bd_info;
@@ -4489,7 +4195,7 @@ void ext4_mb_free_blocks(handle_t *handle, struct inode *inode,
4489 if (block < le32_to_cpu(es->s_first_data_block) || 4195 if (block < le32_to_cpu(es->s_first_data_block) ||
4490 block + count < block || 4196 block + count < block ||
4491 block + count > ext4_blocks_count(es)) { 4197 block + count > ext4_blocks_count(es)) {
4492 ext4_error(sb, __FUNCTION__, 4198 ext4_error(sb, __func__,
4493 "Freeing blocks not in datazone - " 4199 "Freeing blocks not in datazone - "
4494 "block = %lu, count = %lu", block, count); 4200 "block = %lu, count = %lu", block, count);
4495 goto error_return; 4201 goto error_return;
@@ -4530,7 +4236,7 @@ do_more:
4530 in_range(block + count - 1, ext4_inode_table(sb, gdp), 4236 in_range(block + count - 1, ext4_inode_table(sb, gdp),
4531 EXT4_SB(sb)->s_itb_per_group)) { 4237 EXT4_SB(sb)->s_itb_per_group)) {
4532 4238
4533 ext4_error(sb, __FUNCTION__, 4239 ext4_error(sb, __func__,
4534 "Freeing blocks in system zone - " 4240 "Freeing blocks in system zone - "
4535 "Block = %lu, count = %lu", block, count); 4241 "Block = %lu, count = %lu", block, count);
4536 } 4242 }
@@ -4588,8 +4294,7 @@ do_more:
4588 } 4294 }
4589 4295
4590 spin_lock(sb_bgl_lock(sbi, block_group)); 4296 spin_lock(sb_bgl_lock(sbi, block_group));
4591 gdp->bg_free_blocks_count = 4297 le16_add_cpu(&gdp->bg_free_blocks_count, count);
4592 cpu_to_le16(le16_to_cpu(gdp->bg_free_blocks_count) + count);
4593 gdp->bg_checksum = ext4_group_desc_csum(sbi, block_group, gdp); 4298 gdp->bg_checksum = ext4_group_desc_csum(sbi, block_group, gdp);
4594 spin_unlock(sb_bgl_lock(sbi, block_group)); 4299 spin_unlock(sb_bgl_lock(sbi, block_group));
4595 percpu_counter_add(&sbi->s_freeblocks_counter, count); 4300 percpu_counter_add(&sbi->s_freeblocks_counter, count);
diff --git a/fs/ext4/mballoc.h b/fs/ext4/mballoc.h
new file mode 100644
index 000000000000..bfe6add46bcf
--- /dev/null
+++ b/fs/ext4/mballoc.h
@@ -0,0 +1,304 @@
1/*
2 * fs/ext4/mballoc.h
3 *
4 * Written by: Alex Tomas <alex@clusterfs.com>
5 *
6 */
7#ifndef _EXT4_MBALLOC_H
8#define _EXT4_MBALLOC_H
9
10#include <linux/time.h>
11#include <linux/fs.h>
12#include <linux/namei.h>
13#include <linux/quotaops.h>
14#include <linux/buffer_head.h>
15#include <linux/module.h>
16#include <linux/swap.h>
17#include <linux/proc_fs.h>
18#include <linux/pagemap.h>
19#include <linux/seq_file.h>
20#include <linux/version.h>
21#include "ext4_jbd2.h"
22#include "ext4.h"
23#include "group.h"
24
25/*
26 * with AGGRESSIVE_CHECK allocator runs consistency checks over
27 * structures. these checks slow things down a lot
28 */
29#define AGGRESSIVE_CHECK__
30
31/*
32 * with DOUBLE_CHECK defined mballoc creates persistent in-core
33 * bitmaps, maintains and uses them to check for double allocations
34 */
35#define DOUBLE_CHECK__
36
37/*
38 */
39#define MB_DEBUG__
40#ifdef MB_DEBUG
41#define mb_debug(fmt, a...) printk(fmt, ##a)
42#else
43#define mb_debug(fmt, a...)
44#endif
45
46/*
47 * with EXT4_MB_HISTORY mballoc stores last N allocations in memory
48 * and you can monitor it in /proc/fs/ext4/<dev>/mb_history
49 */
50#define EXT4_MB_HISTORY
51#define EXT4_MB_HISTORY_ALLOC 1 /* allocation */
52#define EXT4_MB_HISTORY_PREALLOC 2 /* preallocated blocks used */
53#define EXT4_MB_HISTORY_DISCARD 4 /* preallocation discarded */
54#define EXT4_MB_HISTORY_FREE 8 /* free */
55
56#define EXT4_MB_HISTORY_DEFAULT (EXT4_MB_HISTORY_ALLOC | \
57 EXT4_MB_HISTORY_PREALLOC)
58
59/*
60 * How long mballoc can look for a best extent (in found extents)
61 */
62#define MB_DEFAULT_MAX_TO_SCAN 200
63
64/*
65 * How long mballoc must look for a best extent
66 */
67#define MB_DEFAULT_MIN_TO_SCAN 10
68
69/*
70 * How many groups mballoc will scan looking for the best chunk
71 */
72#define MB_DEFAULT_MAX_GROUPS_TO_SCAN 5
73
74/*
75 * with 'ext4_mb_stats' allocator will collect stats that will be
76 * shown at umount. The collecting costs though!
77 */
78#define MB_DEFAULT_STATS 1
79
80/*
81 * files smaller than MB_DEFAULT_STREAM_THRESHOLD are served
82 * by the stream allocator, which purpose is to pack requests
83 * as close each to other as possible to produce smooth I/O traffic
84 * We use locality group prealloc space for stream request.
85 * We can tune the same via /proc/fs/ext4/<parition>/stream_req
86 */
87#define MB_DEFAULT_STREAM_THRESHOLD 16 /* 64K */
88
89/*
90 * for which requests use 2^N search using buddies
91 */
92#define MB_DEFAULT_ORDER2_REQS 2
93
94/*
95 * default group prealloc size 512 blocks
96 */
97#define MB_DEFAULT_GROUP_PREALLOC 512
98
99static struct kmem_cache *ext4_pspace_cachep;
100static struct kmem_cache *ext4_ac_cachep;
101
102#ifdef EXT4_BB_MAX_BLOCKS
103#undef EXT4_BB_MAX_BLOCKS
104#endif
105#define EXT4_BB_MAX_BLOCKS 30
106
107struct ext4_free_metadata {
108 ext4_group_t group;
109 unsigned short num;
110 ext4_grpblk_t blocks[EXT4_BB_MAX_BLOCKS];
111 struct list_head list;
112};
113
114struct ext4_group_info {
115 unsigned long bb_state;
116 unsigned long bb_tid;
117 struct ext4_free_metadata *bb_md_cur;
118 unsigned short bb_first_free;
119 unsigned short bb_free;
120 unsigned short bb_fragments;
121 struct list_head bb_prealloc_list;
122#ifdef DOUBLE_CHECK
123 void *bb_bitmap;
124#endif
125 unsigned short bb_counters[];
126};
127
128#define EXT4_GROUP_INFO_NEED_INIT_BIT 0
129#define EXT4_GROUP_INFO_LOCKED_BIT 1
130
131#define EXT4_MB_GRP_NEED_INIT(grp) \
132 (test_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &((grp)->bb_state)))
133
134
135struct ext4_prealloc_space {
136 struct list_head pa_inode_list;
137 struct list_head pa_group_list;
138 union {
139 struct list_head pa_tmp_list;
140 struct rcu_head pa_rcu;
141 } u;
142 spinlock_t pa_lock;
143 atomic_t pa_count;
144 unsigned pa_deleted;
145 ext4_fsblk_t pa_pstart; /* phys. block */
146 ext4_lblk_t pa_lstart; /* log. block */
147 unsigned short pa_len; /* len of preallocated chunk */
148 unsigned short pa_free; /* how many blocks are free */
149 unsigned short pa_linear; /* consumed in one direction
150 * strictly, for grp prealloc */
151 spinlock_t *pa_obj_lock;
152 struct inode *pa_inode; /* hack, for history only */
153};
154
155
156struct ext4_free_extent {
157 ext4_lblk_t fe_logical;
158 ext4_grpblk_t fe_start;
159 ext4_group_t fe_group;
160 int fe_len;
161};
162
163/*
164 * Locality group:
165 * we try to group all related changes together
166 * so that writeback can flush/allocate them together as well
167 */
168struct ext4_locality_group {
169 /* for allocator */
170 struct mutex lg_mutex; /* to serialize allocates */
171 struct list_head lg_prealloc_list;/* list of preallocations */
172 spinlock_t lg_prealloc_lock;
173};
174
175struct ext4_allocation_context {
176 struct inode *ac_inode;
177 struct super_block *ac_sb;
178
179 /* original request */
180 struct ext4_free_extent ac_o_ex;
181
182 /* goal request (after normalization) */
183 struct ext4_free_extent ac_g_ex;
184
185 /* the best found extent */
186 struct ext4_free_extent ac_b_ex;
187
188 /* copy of the bext found extent taken before preallocation efforts */
189 struct ext4_free_extent ac_f_ex;
190
191 /* number of iterations done. we have to track to limit searching */
192 unsigned long ac_ex_scanned;
193 __u16 ac_groups_scanned;
194 __u16 ac_found;
195 __u16 ac_tail;
196 __u16 ac_buddy;
197 __u16 ac_flags; /* allocation hints */
198 __u8 ac_status;
199 __u8 ac_criteria;
200 __u8 ac_repeats;
201 __u8 ac_2order; /* if request is to allocate 2^N blocks and
202 * N > 0, the field stores N, otherwise 0 */
203 __u8 ac_op; /* operation, for history only */
204 struct page *ac_bitmap_page;
205 struct page *ac_buddy_page;
206 struct ext4_prealloc_space *ac_pa;
207 struct ext4_locality_group *ac_lg;
208};
209
210#define AC_STATUS_CONTINUE 1
211#define AC_STATUS_FOUND 2
212#define AC_STATUS_BREAK 3
213
214struct ext4_mb_history {
215 struct ext4_free_extent orig; /* orig allocation */
216 struct ext4_free_extent goal; /* goal allocation */
217 struct ext4_free_extent result; /* result allocation */
218 unsigned pid;
219 unsigned ino;
220 __u16 found; /* how many extents have been found */
221 __u16 groups; /* how many groups have been scanned */
222 __u16 tail; /* what tail broke some buddy */
223 __u16 buddy; /* buddy the tail ^^^ broke */
224 __u16 flags;
225 __u8 cr:3; /* which phase the result extent was found at */
226 __u8 op:4;
227 __u8 merged:1;
228};
229
230struct ext4_buddy {
231 struct page *bd_buddy_page;
232 void *bd_buddy;
233 struct page *bd_bitmap_page;
234 void *bd_bitmap;
235 struct ext4_group_info *bd_info;
236 struct super_block *bd_sb;
237 __u16 bd_blkbits;
238 ext4_group_t bd_group;
239};
240#define EXT4_MB_BITMAP(e4b) ((e4b)->bd_bitmap)
241#define EXT4_MB_BUDDY(e4b) ((e4b)->bd_buddy)
242
243#ifndef EXT4_MB_HISTORY
244static inline void ext4_mb_store_history(struct ext4_allocation_context *ac)
245{
246 return;
247}
248#else
249static void ext4_mb_store_history(struct ext4_allocation_context *ac);
250#endif
251
252#define in_range(b, first, len) ((b) >= (first) && (b) <= (first) + (len) - 1)
253
254static struct proc_dir_entry *proc_root_ext4;
255struct buffer_head *read_block_bitmap(struct super_block *, ext4_group_t);
256
257static void ext4_mb_generate_from_pa(struct super_block *sb, void *bitmap,
258 ext4_group_t group);
259static void ext4_mb_poll_new_transaction(struct super_block *, handle_t *);
260static void ext4_mb_free_committed_blocks(struct super_block *);
261static void ext4_mb_return_to_preallocation(struct inode *inode,
262 struct ext4_buddy *e4b, sector_t block,
263 int count);
264static void ext4_mb_put_pa(struct ext4_allocation_context *,
265 struct super_block *, struct ext4_prealloc_space *pa);
266static int ext4_mb_init_per_dev_proc(struct super_block *sb);
267static int ext4_mb_destroy_per_dev_proc(struct super_block *sb);
268
269
270static inline void ext4_lock_group(struct super_block *sb, ext4_group_t group)
271{
272 struct ext4_group_info *grinfo = ext4_get_group_info(sb, group);
273
274 bit_spin_lock(EXT4_GROUP_INFO_LOCKED_BIT, &(grinfo->bb_state));
275}
276
277static inline void ext4_unlock_group(struct super_block *sb,
278 ext4_group_t group)
279{
280 struct ext4_group_info *grinfo = ext4_get_group_info(sb, group);
281
282 bit_spin_unlock(EXT4_GROUP_INFO_LOCKED_BIT, &(grinfo->bb_state));
283}
284
285static inline int ext4_is_group_locked(struct super_block *sb,
286 ext4_group_t group)
287{
288 struct ext4_group_info *grinfo = ext4_get_group_info(sb, group);
289
290 return bit_spin_is_locked(EXT4_GROUP_INFO_LOCKED_BIT,
291 &(grinfo->bb_state));
292}
293
294static ext4_fsblk_t ext4_grp_offs_to_block(struct super_block *sb,
295 struct ext4_free_extent *fex)
296{
297 ext4_fsblk_t block;
298
299 block = (ext4_fsblk_t) fex->fe_group * EXT4_BLOCKS_PER_GROUP(sb)
300 + fex->fe_start
301 + le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block);
302 return block;
303}
304#endif
diff --git a/fs/ext4/migrate.c b/fs/ext4/migrate.c
index 5c1e27de7755..b9e077ba07e9 100644
--- a/fs/ext4/migrate.c
+++ b/fs/ext4/migrate.c
@@ -13,8 +13,8 @@
13 */ 13 */
14 14
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/ext4_jbd2.h> 16#include "ext4_jbd2.h"
17#include <linux/ext4_fs_extents.h> 17#include "ext4_extents.h"
18 18
19/* 19/*
20 * The contiguous blocks details which can be 20 * The contiguous blocks details which can be
@@ -327,7 +327,7 @@ static int free_ind_block(handle_t *handle, struct inode *inode, __le32 *i_data)
327} 327}
328 328
329static int ext4_ext_swap_inode_data(handle_t *handle, struct inode *inode, 329static int ext4_ext_swap_inode_data(handle_t *handle, struct inode *inode,
330 struct inode *tmp_inode) 330 struct inode *tmp_inode)
331{ 331{
332 int retval; 332 int retval;
333 __le32 i_data[3]; 333 __le32 i_data[3];
@@ -339,7 +339,7 @@ static int ext4_ext_swap_inode_data(handle_t *handle, struct inode *inode,
339 * i_data field of the original inode 339 * i_data field of the original inode
340 */ 340 */
341 retval = ext4_journal_extend(handle, 1); 341 retval = ext4_journal_extend(handle, 1);
342 if (retval != 0) { 342 if (retval) {
343 retval = ext4_journal_restart(handle, 1); 343 retval = ext4_journal_restart(handle, 1);
344 if (retval) 344 if (retval)
345 goto err_out; 345 goto err_out;
@@ -351,6 +351,18 @@ static int ext4_ext_swap_inode_data(handle_t *handle, struct inode *inode,
351 351
352 down_write(&EXT4_I(inode)->i_data_sem); 352 down_write(&EXT4_I(inode)->i_data_sem);
353 /* 353 /*
354 * if EXT4_EXT_MIGRATE is cleared a block allocation
355 * happened after we started the migrate. We need to
356 * fail the migrate
357 */
358 if (!(EXT4_I(inode)->i_flags & EXT4_EXT_MIGRATE)) {
359 retval = -EAGAIN;
360 up_write(&EXT4_I(inode)->i_data_sem);
361 goto err_out;
362 } else
363 EXT4_I(inode)->i_flags = EXT4_I(inode)->i_flags &
364 ~EXT4_EXT_MIGRATE;
365 /*
354 * We have the extent map build with the tmp inode. 366 * We have the extent map build with the tmp inode.
355 * Now copy the i_data across 367 * Now copy the i_data across
356 */ 368 */
@@ -508,6 +520,17 @@ int ext4_ext_migrate(struct inode *inode, struct file *filp,
508 * switch the inode format to prevent read. 520 * switch the inode format to prevent read.
509 */ 521 */
510 mutex_lock(&(inode->i_mutex)); 522 mutex_lock(&(inode->i_mutex));
523 /*
524 * Even though we take i_mutex we can still cause block allocation
525 * via mmap write to holes. If we have allocated new blocks we fail
526 * migrate. New block allocation will clear EXT4_EXT_MIGRATE flag.
527 * The flag is updated with i_data_sem held to prevent racing with
528 * block allocation.
529 */
530 down_read((&EXT4_I(inode)->i_data_sem));
531 EXT4_I(inode)->i_flags = EXT4_I(inode)->i_flags | EXT4_EXT_MIGRATE;
532 up_read((&EXT4_I(inode)->i_data_sem));
533
511 handle = ext4_journal_start(inode, 1); 534 handle = ext4_journal_start(inode, 1);
512 535
513 ei = EXT4_I(inode); 536 ei = EXT4_I(inode);
@@ -559,9 +582,15 @@ err_out:
559 * tmp_inode 582 * tmp_inode
560 */ 583 */
561 free_ext_block(handle, tmp_inode); 584 free_ext_block(handle, tmp_inode);
562 else 585 else {
563 retval = ext4_ext_swap_inode_data(handle, inode, 586 retval = ext4_ext_swap_inode_data(handle, inode, tmp_inode);
564 tmp_inode); 587 if (retval)
588 /*
589 * if we fail to swap inode data free the extent
590 * details of the tmp inode
591 */
592 free_ext_block(handle, tmp_inode);
593 }
565 594
566 /* We mark the tmp_inode dirty via ext4_ext_tree_init. */ 595 /* We mark the tmp_inode dirty via ext4_ext_tree_init. */
567 if (ext4_journal_extend(handle, 1) != 0) 596 if (ext4_journal_extend(handle, 1) != 0)
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 28aa2ed4297e..ab16beaa830d 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -28,14 +28,14 @@
28#include <linux/pagemap.h> 28#include <linux/pagemap.h>
29#include <linux/jbd2.h> 29#include <linux/jbd2.h>
30#include <linux/time.h> 30#include <linux/time.h>
31#include <linux/ext4_fs.h>
32#include <linux/ext4_jbd2.h>
33#include <linux/fcntl.h> 31#include <linux/fcntl.h>
34#include <linux/stat.h> 32#include <linux/stat.h>
35#include <linux/string.h> 33#include <linux/string.h>
36#include <linux/quotaops.h> 34#include <linux/quotaops.h>
37#include <linux/buffer_head.h> 35#include <linux/buffer_head.h>
38#include <linux/bio.h> 36#include <linux/bio.h>
37#include "ext4.h"
38#include "ext4_jbd2.h"
39 39
40#include "namei.h" 40#include "namei.h"
41#include "xattr.h" 41#include "xattr.h"
@@ -57,10 +57,15 @@ static struct buffer_head *ext4_append(handle_t *handle,
57 57
58 *block = inode->i_size >> inode->i_sb->s_blocksize_bits; 58 *block = inode->i_size >> inode->i_sb->s_blocksize_bits;
59 59
60 if ((bh = ext4_bread(handle, inode, *block, 1, err))) { 60 bh = ext4_bread(handle, inode, *block, 1, err);
61 if (bh) {
61 inode->i_size += inode->i_sb->s_blocksize; 62 inode->i_size += inode->i_sb->s_blocksize;
62 EXT4_I(inode)->i_disksize = inode->i_size; 63 EXT4_I(inode)->i_disksize = inode->i_size;
63 ext4_journal_get_write_access(handle,bh); 64 *err = ext4_journal_get_write_access(handle, bh);
65 if (*err) {
66 brelse(bh);
67 bh = NULL;
68 }
64 } 69 }
65 return bh; 70 return bh;
66} 71}
@@ -348,7 +353,7 @@ dx_probe(struct dentry *dentry, struct inode *dir,
348 if (root->info.hash_version != DX_HASH_TEA && 353 if (root->info.hash_version != DX_HASH_TEA &&
349 root->info.hash_version != DX_HASH_HALF_MD4 && 354 root->info.hash_version != DX_HASH_HALF_MD4 &&
350 root->info.hash_version != DX_HASH_LEGACY) { 355 root->info.hash_version != DX_HASH_LEGACY) {
351 ext4_warning(dir->i_sb, __FUNCTION__, 356 ext4_warning(dir->i_sb, __func__,
352 "Unrecognised inode hash code %d", 357 "Unrecognised inode hash code %d",
353 root->info.hash_version); 358 root->info.hash_version);
354 brelse(bh); 359 brelse(bh);
@@ -362,7 +367,7 @@ dx_probe(struct dentry *dentry, struct inode *dir,
362 hash = hinfo->hash; 367 hash = hinfo->hash;
363 368
364 if (root->info.unused_flags & 1) { 369 if (root->info.unused_flags & 1) {
365 ext4_warning(dir->i_sb, __FUNCTION__, 370 ext4_warning(dir->i_sb, __func__,
366 "Unimplemented inode hash flags: %#06x", 371 "Unimplemented inode hash flags: %#06x",
367 root->info.unused_flags); 372 root->info.unused_flags);
368 brelse(bh); 373 brelse(bh);
@@ -371,7 +376,7 @@ dx_probe(struct dentry *dentry, struct inode *dir,
371 } 376 }
372 377
373 if ((indirect = root->info.indirect_levels) > 1) { 378 if ((indirect = root->info.indirect_levels) > 1) {
374 ext4_warning(dir->i_sb, __FUNCTION__, 379 ext4_warning(dir->i_sb, __func__,
375 "Unimplemented inode hash depth: %#06x", 380 "Unimplemented inode hash depth: %#06x",
376 root->info.indirect_levels); 381 root->info.indirect_levels);
377 brelse(bh); 382 brelse(bh);
@@ -384,7 +389,7 @@ dx_probe(struct dentry *dentry, struct inode *dir,
384 389
385 if (dx_get_limit(entries) != dx_root_limit(dir, 390 if (dx_get_limit(entries) != dx_root_limit(dir,
386 root->info.info_length)) { 391 root->info.info_length)) {
387 ext4_warning(dir->i_sb, __FUNCTION__, 392 ext4_warning(dir->i_sb, __func__,
388 "dx entry: limit != root limit"); 393 "dx entry: limit != root limit");
389 brelse(bh); 394 brelse(bh);
390 *err = ERR_BAD_DX_DIR; 395 *err = ERR_BAD_DX_DIR;
@@ -396,7 +401,7 @@ dx_probe(struct dentry *dentry, struct inode *dir,
396 { 401 {
397 count = dx_get_count(entries); 402 count = dx_get_count(entries);
398 if (!count || count > dx_get_limit(entries)) { 403 if (!count || count > dx_get_limit(entries)) {
399 ext4_warning(dir->i_sb, __FUNCTION__, 404 ext4_warning(dir->i_sb, __func__,
400 "dx entry: no count or count > limit"); 405 "dx entry: no count or count > limit");
401 brelse(bh); 406 brelse(bh);
402 *err = ERR_BAD_DX_DIR; 407 *err = ERR_BAD_DX_DIR;
@@ -441,7 +446,7 @@ dx_probe(struct dentry *dentry, struct inode *dir,
441 goto fail2; 446 goto fail2;
442 at = entries = ((struct dx_node *) bh->b_data)->entries; 447 at = entries = ((struct dx_node *) bh->b_data)->entries;
443 if (dx_get_limit(entries) != dx_node_limit (dir)) { 448 if (dx_get_limit(entries) != dx_node_limit (dir)) {
444 ext4_warning(dir->i_sb, __FUNCTION__, 449 ext4_warning(dir->i_sb, __func__,
445 "dx entry: limit != node limit"); 450 "dx entry: limit != node limit");
446 brelse(bh); 451 brelse(bh);
447 *err = ERR_BAD_DX_DIR; 452 *err = ERR_BAD_DX_DIR;
@@ -457,7 +462,7 @@ fail2:
457 } 462 }
458fail: 463fail:
459 if (*err == ERR_BAD_DX_DIR) 464 if (*err == ERR_BAD_DX_DIR)
460 ext4_warning(dir->i_sb, __FUNCTION__, 465 ext4_warning(dir->i_sb, __func__,
461 "Corrupt dir inode %ld, running e2fsck is " 466 "Corrupt dir inode %ld, running e2fsck is "
462 "recommended.", dir->i_ino); 467 "recommended.", dir->i_ino);
463 return NULL; 468 return NULL;
@@ -914,7 +919,7 @@ restart:
914 wait_on_buffer(bh); 919 wait_on_buffer(bh);
915 if (!buffer_uptodate(bh)) { 920 if (!buffer_uptodate(bh)) {
916 /* read error, skip block & hope for the best */ 921 /* read error, skip block & hope for the best */
917 ext4_error(sb, __FUNCTION__, "reading directory #%lu " 922 ext4_error(sb, __func__, "reading directory #%lu "
918 "offset %lu", dir->i_ino, 923 "offset %lu", dir->i_ino,
919 (unsigned long)block); 924 (unsigned long)block);
920 brelse(bh); 925 brelse(bh);
@@ -1007,7 +1012,7 @@ static struct buffer_head * ext4_dx_find_entry(struct dentry *dentry,
1007 retval = ext4_htree_next_block(dir, hash, frame, 1012 retval = ext4_htree_next_block(dir, hash, frame,
1008 frames, NULL); 1013 frames, NULL);
1009 if (retval < 0) { 1014 if (retval < 0) {
1010 ext4_warning(sb, __FUNCTION__, 1015 ext4_warning(sb, __func__,
1011 "error reading index page in directory #%lu", 1016 "error reading index page in directory #%lu",
1012 dir->i_ino); 1017 dir->i_ino);
1013 *err = retval; 1018 *err = retval;
@@ -1532,7 +1537,7 @@ static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry,
1532 1537
1533 if (levels && (dx_get_count(frames->entries) == 1538 if (levels && (dx_get_count(frames->entries) ==
1534 dx_get_limit(frames->entries))) { 1539 dx_get_limit(frames->entries))) {
1535 ext4_warning(sb, __FUNCTION__, 1540 ext4_warning(sb, __func__,
1536 "Directory index full!"); 1541 "Directory index full!");
1537 err = -ENOSPC; 1542 err = -ENOSPC;
1538 goto cleanup; 1543 goto cleanup;
@@ -1860,11 +1865,11 @@ static int empty_dir (struct inode * inode)
1860 if (inode->i_size < EXT4_DIR_REC_LEN(1) + EXT4_DIR_REC_LEN(2) || 1865 if (inode->i_size < EXT4_DIR_REC_LEN(1) + EXT4_DIR_REC_LEN(2) ||
1861 !(bh = ext4_bread (NULL, inode, 0, 0, &err))) { 1866 !(bh = ext4_bread (NULL, inode, 0, 0, &err))) {
1862 if (err) 1867 if (err)
1863 ext4_error(inode->i_sb, __FUNCTION__, 1868 ext4_error(inode->i_sb, __func__,
1864 "error %d reading directory #%lu offset 0", 1869 "error %d reading directory #%lu offset 0",
1865 err, inode->i_ino); 1870 err, inode->i_ino);
1866 else 1871 else
1867 ext4_warning(inode->i_sb, __FUNCTION__, 1872 ext4_warning(inode->i_sb, __func__,
1868 "bad directory (dir #%lu) - no data block", 1873 "bad directory (dir #%lu) - no data block",
1869 inode->i_ino); 1874 inode->i_ino);
1870 return 1; 1875 return 1;
@@ -1893,7 +1898,7 @@ static int empty_dir (struct inode * inode)
1893 offset >> EXT4_BLOCK_SIZE_BITS(sb), 0, &err); 1898 offset >> EXT4_BLOCK_SIZE_BITS(sb), 0, &err);
1894 if (!bh) { 1899 if (!bh) {
1895 if (err) 1900 if (err)
1896 ext4_error(sb, __FUNCTION__, 1901 ext4_error(sb, __func__,
1897 "error %d reading directory" 1902 "error %d reading directory"
1898 " #%lu offset %lu", 1903 " #%lu offset %lu",
1899 err, inode->i_ino, offset); 1904 err, inode->i_ino, offset);
@@ -2217,6 +2222,8 @@ retry:
2217 goto out_stop; 2222 goto out_stop;
2218 } 2223 }
2219 } else { 2224 } else {
2225 /* clear the extent format for fast symlink */
2226 EXT4_I(inode)->i_flags &= ~EXT4_EXTENTS_FL;
2220 inode->i_op = &ext4_fast_symlink_inode_operations; 2227 inode->i_op = &ext4_fast_symlink_inode_operations;
2221 memcpy((char*)&EXT4_I(inode)->i_data,symname,l); 2228 memcpy((char*)&EXT4_I(inode)->i_data,symname,l);
2222 inode->i_size = l-1; 2229 inode->i_size = l-1;
@@ -2347,6 +2354,9 @@ static int ext4_rename (struct inode * old_dir, struct dentry *old_dentry,
2347 EXT4_FEATURE_INCOMPAT_FILETYPE)) 2354 EXT4_FEATURE_INCOMPAT_FILETYPE))
2348 new_de->file_type = old_de->file_type; 2355 new_de->file_type = old_de->file_type;
2349 new_dir->i_version++; 2356 new_dir->i_version++;
2357 new_dir->i_ctime = new_dir->i_mtime =
2358 ext4_current_time(new_dir);
2359 ext4_mark_inode_dirty(handle, new_dir);
2350 BUFFER_TRACE(new_bh, "call ext4_journal_dirty_metadata"); 2360 BUFFER_TRACE(new_bh, "call ext4_journal_dirty_metadata");
2351 ext4_journal_dirty_metadata(handle, new_bh); 2361 ext4_journal_dirty_metadata(handle, new_bh);
2352 brelse(new_bh); 2362 brelse(new_bh);
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index e29efa0f9d62..9f086a6a472b 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -11,11 +11,10 @@
11 11
12#define EXT4FS_DEBUG 12#define EXT4FS_DEBUG
13 13
14#include <linux/ext4_jbd2.h>
15
16#include <linux/errno.h> 14#include <linux/errno.h>
17#include <linux/slab.h> 15#include <linux/slab.h>
18 16
17#include "ext4_jbd2.h"
19#include "group.h" 18#include "group.h"
20 19
21#define outside(b, first, last) ((b) < (first) || (b) >= (last)) 20#define outside(b, first, last) ((b) < (first) || (b) >= (last))
@@ -50,63 +49,63 @@ static int verify_group_input(struct super_block *sb,
50 49
51 ext4_get_group_no_and_offset(sb, start, NULL, &offset); 50 ext4_get_group_no_and_offset(sb, start, NULL, &offset);
52 if (group != sbi->s_groups_count) 51 if (group != sbi->s_groups_count)
53 ext4_warning(sb, __FUNCTION__, 52 ext4_warning(sb, __func__,
54 "Cannot add at group %u (only %lu groups)", 53 "Cannot add at group %u (only %lu groups)",
55 input->group, sbi->s_groups_count); 54 input->group, sbi->s_groups_count);
56 else if (offset != 0) 55 else if (offset != 0)
57 ext4_warning(sb, __FUNCTION__, "Last group not full"); 56 ext4_warning(sb, __func__, "Last group not full");
58 else if (input->reserved_blocks > input->blocks_count / 5) 57 else if (input->reserved_blocks > input->blocks_count / 5)
59 ext4_warning(sb, __FUNCTION__, "Reserved blocks too high (%u)", 58 ext4_warning(sb, __func__, "Reserved blocks too high (%u)",
60 input->reserved_blocks); 59 input->reserved_blocks);
61 else if (free_blocks_count < 0) 60 else if (free_blocks_count < 0)
62 ext4_warning(sb, __FUNCTION__, "Bad blocks count %u", 61 ext4_warning(sb, __func__, "Bad blocks count %u",
63 input->blocks_count); 62 input->blocks_count);
64 else if (!(bh = sb_bread(sb, end - 1))) 63 else if (!(bh = sb_bread(sb, end - 1)))
65 ext4_warning(sb, __FUNCTION__, 64 ext4_warning(sb, __func__,
66 "Cannot read last block (%llu)", 65 "Cannot read last block (%llu)",
67 end - 1); 66 end - 1);
68 else if (outside(input->block_bitmap, start, end)) 67 else if (outside(input->block_bitmap, start, end))
69 ext4_warning(sb, __FUNCTION__, 68 ext4_warning(sb, __func__,
70 "Block bitmap not in group (block %llu)", 69 "Block bitmap not in group (block %llu)",
71 (unsigned long long)input->block_bitmap); 70 (unsigned long long)input->block_bitmap);
72 else if (outside(input->inode_bitmap, start, end)) 71 else if (outside(input->inode_bitmap, start, end))
73 ext4_warning(sb, __FUNCTION__, 72 ext4_warning(sb, __func__,
74 "Inode bitmap not in group (block %llu)", 73 "Inode bitmap not in group (block %llu)",
75 (unsigned long long)input->inode_bitmap); 74 (unsigned long long)input->inode_bitmap);
76 else if (outside(input->inode_table, start, end) || 75 else if (outside(input->inode_table, start, end) ||
77 outside(itend - 1, start, end)) 76 outside(itend - 1, start, end))
78 ext4_warning(sb, __FUNCTION__, 77 ext4_warning(sb, __func__,
79 "Inode table not in group (blocks %llu-%llu)", 78 "Inode table not in group (blocks %llu-%llu)",
80 (unsigned long long)input->inode_table, itend - 1); 79 (unsigned long long)input->inode_table, itend - 1);
81 else if (input->inode_bitmap == input->block_bitmap) 80 else if (input->inode_bitmap == input->block_bitmap)
82 ext4_warning(sb, __FUNCTION__, 81 ext4_warning(sb, __func__,
83 "Block bitmap same as inode bitmap (%llu)", 82 "Block bitmap same as inode bitmap (%llu)",
84 (unsigned long long)input->block_bitmap); 83 (unsigned long long)input->block_bitmap);
85 else if (inside(input->block_bitmap, input->inode_table, itend)) 84 else if (inside(input->block_bitmap, input->inode_table, itend))
86 ext4_warning(sb, __FUNCTION__, 85 ext4_warning(sb, __func__,
87 "Block bitmap (%llu) in inode table (%llu-%llu)", 86 "Block bitmap (%llu) in inode table (%llu-%llu)",
88 (unsigned long long)input->block_bitmap, 87 (unsigned long long)input->block_bitmap,
89 (unsigned long long)input->inode_table, itend - 1); 88 (unsigned long long)input->inode_table, itend - 1);
90 else if (inside(input->inode_bitmap, input->inode_table, itend)) 89 else if (inside(input->inode_bitmap, input->inode_table, itend))
91 ext4_warning(sb, __FUNCTION__, 90 ext4_warning(sb, __func__,
92 "Inode bitmap (%llu) in inode table (%llu-%llu)", 91 "Inode bitmap (%llu) in inode table (%llu-%llu)",
93 (unsigned long long)input->inode_bitmap, 92 (unsigned long long)input->inode_bitmap,
94 (unsigned long long)input->inode_table, itend - 1); 93 (unsigned long long)input->inode_table, itend - 1);
95 else if (inside(input->block_bitmap, start, metaend)) 94 else if (inside(input->block_bitmap, start, metaend))
96 ext4_warning(sb, __FUNCTION__, 95 ext4_warning(sb, __func__,
97 "Block bitmap (%llu) in GDT table" 96 "Block bitmap (%llu) in GDT table"
98 " (%llu-%llu)", 97 " (%llu-%llu)",
99 (unsigned long long)input->block_bitmap, 98 (unsigned long long)input->block_bitmap,
100 start, metaend - 1); 99 start, metaend - 1);
101 else if (inside(input->inode_bitmap, start, metaend)) 100 else if (inside(input->inode_bitmap, start, metaend))
102 ext4_warning(sb, __FUNCTION__, 101 ext4_warning(sb, __func__,
103 "Inode bitmap (%llu) in GDT table" 102 "Inode bitmap (%llu) in GDT table"
104 " (%llu-%llu)", 103 " (%llu-%llu)",
105 (unsigned long long)input->inode_bitmap, 104 (unsigned long long)input->inode_bitmap,
106 start, metaend - 1); 105 start, metaend - 1);
107 else if (inside(input->inode_table, start, metaend) || 106 else if (inside(input->inode_table, start, metaend) ||
108 inside(itend - 1, start, metaend)) 107 inside(itend - 1, start, metaend))
109 ext4_warning(sb, __FUNCTION__, 108 ext4_warning(sb, __func__,
110 "Inode table (%llu-%llu) overlaps" 109 "Inode table (%llu-%llu) overlaps"
111 "GDT table (%llu-%llu)", 110 "GDT table (%llu-%llu)",
112 (unsigned long long)input->inode_table, 111 (unsigned long long)input->inode_table,
@@ -368,7 +367,7 @@ static int verify_reserved_gdb(struct super_block *sb,
368 while ((grp = ext4_list_backups(sb, &three, &five, &seven)) < end) { 367 while ((grp = ext4_list_backups(sb, &three, &five, &seven)) < end) {
369 if (le32_to_cpu(*p++) != 368 if (le32_to_cpu(*p++) !=
370 grp * EXT4_BLOCKS_PER_GROUP(sb) + blk){ 369 grp * EXT4_BLOCKS_PER_GROUP(sb) + blk){
371 ext4_warning(sb, __FUNCTION__, 370 ext4_warning(sb, __func__,
372 "reserved GDT %llu" 371 "reserved GDT %llu"
373 " missing grp %d (%llu)", 372 " missing grp %d (%llu)",
374 blk, grp, 373 blk, grp,
@@ -424,7 +423,7 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
424 */ 423 */
425 if (EXT4_SB(sb)->s_sbh->b_blocknr != 424 if (EXT4_SB(sb)->s_sbh->b_blocknr !=
426 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block)) { 425 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block)) {
427 ext4_warning(sb, __FUNCTION__, 426 ext4_warning(sb, __func__,
428 "won't resize using backup superblock at %llu", 427 "won't resize using backup superblock at %llu",
429 (unsigned long long)EXT4_SB(sb)->s_sbh->b_blocknr); 428 (unsigned long long)EXT4_SB(sb)->s_sbh->b_blocknr);
430 return -EPERM; 429 return -EPERM;
@@ -448,7 +447,7 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
448 447
449 data = (__le32 *)dind->b_data; 448 data = (__le32 *)dind->b_data;
450 if (le32_to_cpu(data[gdb_num % EXT4_ADDR_PER_BLOCK(sb)]) != gdblock) { 449 if (le32_to_cpu(data[gdb_num % EXT4_ADDR_PER_BLOCK(sb)]) != gdblock) {
451 ext4_warning(sb, __FUNCTION__, 450 ext4_warning(sb, __func__,
452 "new group %u GDT block %llu not reserved", 451 "new group %u GDT block %llu not reserved",
453 input->group, gdblock); 452 input->group, gdblock);
454 err = -EINVAL; 453 err = -EINVAL;
@@ -469,10 +468,10 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
469 goto exit_dindj; 468 goto exit_dindj;
470 469
471 n_group_desc = kmalloc((gdb_num + 1) * sizeof(struct buffer_head *), 470 n_group_desc = kmalloc((gdb_num + 1) * sizeof(struct buffer_head *),
472 GFP_KERNEL); 471 GFP_NOFS);
473 if (!n_group_desc) { 472 if (!n_group_desc) {
474 err = -ENOMEM; 473 err = -ENOMEM;
475 ext4_warning (sb, __FUNCTION__, 474 ext4_warning(sb, __func__,
476 "not enough memory for %lu groups", gdb_num + 1); 475 "not enough memory for %lu groups", gdb_num + 1);
477 goto exit_inode; 476 goto exit_inode;
478 } 477 }
@@ -502,8 +501,7 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
502 EXT4_SB(sb)->s_gdb_count++; 501 EXT4_SB(sb)->s_gdb_count++;
503 kfree(o_group_desc); 502 kfree(o_group_desc);
504 503
505 es->s_reserved_gdt_blocks = 504 le16_add_cpu(&es->s_reserved_gdt_blocks, -1);
506 cpu_to_le16(le16_to_cpu(es->s_reserved_gdt_blocks) - 1);
507 ext4_journal_dirty_metadata(handle, EXT4_SB(sb)->s_sbh); 505 ext4_journal_dirty_metadata(handle, EXT4_SB(sb)->s_sbh);
508 506
509 return 0; 507 return 0;
@@ -553,7 +551,7 @@ static int reserve_backup_gdb(handle_t *handle, struct inode *inode,
553 int res, i; 551 int res, i;
554 int err; 552 int err;
555 553
556 primary = kmalloc(reserved_gdb * sizeof(*primary), GFP_KERNEL); 554 primary = kmalloc(reserved_gdb * sizeof(*primary), GFP_NOFS);
557 if (!primary) 555 if (!primary)
558 return -ENOMEM; 556 return -ENOMEM;
559 557
@@ -571,7 +569,7 @@ static int reserve_backup_gdb(handle_t *handle, struct inode *inode,
571 /* Get each reserved primary GDT block and verify it holds backups */ 569 /* Get each reserved primary GDT block and verify it holds backups */
572 for (res = 0; res < reserved_gdb; res++, blk++) { 570 for (res = 0; res < reserved_gdb; res++, blk++) {
573 if (le32_to_cpu(*data) != blk) { 571 if (le32_to_cpu(*data) != blk) {
574 ext4_warning(sb, __FUNCTION__, 572 ext4_warning(sb, __func__,
575 "reserved block %llu" 573 "reserved block %llu"
576 " not at offset %ld", 574 " not at offset %ld",
577 blk, 575 blk,
@@ -715,7 +713,7 @@ static void update_backups(struct super_block *sb,
715 */ 713 */
716exit_err: 714exit_err:
717 if (err) { 715 if (err) {
718 ext4_warning(sb, __FUNCTION__, 716 ext4_warning(sb, __func__,
719 "can't update backup for group %lu (err %d), " 717 "can't update backup for group %lu (err %d), "
720 "forcing fsck on next reboot", group, err); 718 "forcing fsck on next reboot", group, err);
721 sbi->s_mount_state &= ~EXT4_VALID_FS; 719 sbi->s_mount_state &= ~EXT4_VALID_FS;
@@ -755,33 +753,33 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)
755 753
756 if (gdb_off == 0 && !EXT4_HAS_RO_COMPAT_FEATURE(sb, 754 if (gdb_off == 0 && !EXT4_HAS_RO_COMPAT_FEATURE(sb,
757 EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER)) { 755 EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER)) {
758 ext4_warning(sb, __FUNCTION__, 756 ext4_warning(sb, __func__,
759 "Can't resize non-sparse filesystem further"); 757 "Can't resize non-sparse filesystem further");
760 return -EPERM; 758 return -EPERM;
761 } 759 }
762 760
763 if (ext4_blocks_count(es) + input->blocks_count < 761 if (ext4_blocks_count(es) + input->blocks_count <
764 ext4_blocks_count(es)) { 762 ext4_blocks_count(es)) {
765 ext4_warning(sb, __FUNCTION__, "blocks_count overflow\n"); 763 ext4_warning(sb, __func__, "blocks_count overflow\n");
766 return -EINVAL; 764 return -EINVAL;
767 } 765 }
768 766
769 if (le32_to_cpu(es->s_inodes_count) + EXT4_INODES_PER_GROUP(sb) < 767 if (le32_to_cpu(es->s_inodes_count) + EXT4_INODES_PER_GROUP(sb) <
770 le32_to_cpu(es->s_inodes_count)) { 768 le32_to_cpu(es->s_inodes_count)) {
771 ext4_warning(sb, __FUNCTION__, "inodes_count overflow\n"); 769 ext4_warning(sb, __func__, "inodes_count overflow\n");
772 return -EINVAL; 770 return -EINVAL;
773 } 771 }
774 772
775 if (reserved_gdb || gdb_off == 0) { 773 if (reserved_gdb || gdb_off == 0) {
776 if (!EXT4_HAS_COMPAT_FEATURE(sb, 774 if (!EXT4_HAS_COMPAT_FEATURE(sb,
777 EXT4_FEATURE_COMPAT_RESIZE_INODE)){ 775 EXT4_FEATURE_COMPAT_RESIZE_INODE)){
778 ext4_warning(sb, __FUNCTION__, 776 ext4_warning(sb, __func__,
779 "No reserved GDT blocks, can't resize"); 777 "No reserved GDT blocks, can't resize");
780 return -EPERM; 778 return -EPERM;
781 } 779 }
782 inode = ext4_iget(sb, EXT4_RESIZE_INO); 780 inode = ext4_iget(sb, EXT4_RESIZE_INO);
783 if (IS_ERR(inode)) { 781 if (IS_ERR(inode)) {
784 ext4_warning(sb, __FUNCTION__, 782 ext4_warning(sb, __func__,
785 "Error opening resize inode"); 783 "Error opening resize inode");
786 return PTR_ERR(inode); 784 return PTR_ERR(inode);
787 } 785 }
@@ -810,7 +808,7 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)
810 808
811 lock_super(sb); 809 lock_super(sb);
812 if (input->group != sbi->s_groups_count) { 810 if (input->group != sbi->s_groups_count) {
813 ext4_warning(sb, __FUNCTION__, 811 ext4_warning(sb, __func__,
814 "multiple resizers run on filesystem!"); 812 "multiple resizers run on filesystem!");
815 err = -EBUSY; 813 err = -EBUSY;
816 goto exit_journal; 814 goto exit_journal;
@@ -877,8 +875,7 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)
877 */ 875 */
878 ext4_blocks_count_set(es, ext4_blocks_count(es) + 876 ext4_blocks_count_set(es, ext4_blocks_count(es) +
879 input->blocks_count); 877 input->blocks_count);
880 es->s_inodes_count = cpu_to_le32(le32_to_cpu(es->s_inodes_count) + 878 le32_add_cpu(&es->s_inodes_count, EXT4_INODES_PER_GROUP(sb));
881 EXT4_INODES_PER_GROUP(sb));
882 879
883 /* 880 /*
884 * We need to protect s_groups_count against other CPUs seeing 881 * We need to protect s_groups_count against other CPUs seeing
@@ -977,13 +974,13 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es,
977 " too large to resize to %llu blocks safely\n", 974 " too large to resize to %llu blocks safely\n",
978 sb->s_id, n_blocks_count); 975 sb->s_id, n_blocks_count);
979 if (sizeof(sector_t) < 8) 976 if (sizeof(sector_t) < 8)
980 ext4_warning(sb, __FUNCTION__, 977 ext4_warning(sb, __func__,
981 "CONFIG_LBD not enabled\n"); 978 "CONFIG_LBD not enabled\n");
982 return -EINVAL; 979 return -EINVAL;
983 } 980 }
984 981
985 if (n_blocks_count < o_blocks_count) { 982 if (n_blocks_count < o_blocks_count) {
986 ext4_warning(sb, __FUNCTION__, 983 ext4_warning(sb, __func__,
987 "can't shrink FS - resize aborted"); 984 "can't shrink FS - resize aborted");
988 return -EBUSY; 985 return -EBUSY;
989 } 986 }
@@ -992,7 +989,7 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es,
992 ext4_get_group_no_and_offset(sb, o_blocks_count, NULL, &last); 989 ext4_get_group_no_and_offset(sb, o_blocks_count, NULL, &last);
993 990
994 if (last == 0) { 991 if (last == 0) {
995 ext4_warning(sb, __FUNCTION__, 992 ext4_warning(sb, __func__,
996 "need to use ext2online to resize further"); 993 "need to use ext2online to resize further");
997 return -EPERM; 994 return -EPERM;
998 } 995 }
@@ -1000,7 +997,7 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es,
1000 add = EXT4_BLOCKS_PER_GROUP(sb) - last; 997 add = EXT4_BLOCKS_PER_GROUP(sb) - last;
1001 998
1002 if (o_blocks_count + add < o_blocks_count) { 999 if (o_blocks_count + add < o_blocks_count) {
1003 ext4_warning(sb, __FUNCTION__, "blocks_count overflow"); 1000 ext4_warning(sb, __func__, "blocks_count overflow");
1004 return -EINVAL; 1001 return -EINVAL;
1005 } 1002 }
1006 1003
@@ -1008,7 +1005,7 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es,
1008 add = n_blocks_count - o_blocks_count; 1005 add = n_blocks_count - o_blocks_count;
1009 1006
1010 if (o_blocks_count + add < n_blocks_count) 1007 if (o_blocks_count + add < n_blocks_count)
1011 ext4_warning(sb, __FUNCTION__, 1008 ext4_warning(sb, __func__,
1012 "will only finish group (%llu" 1009 "will only finish group (%llu"
1013 " blocks, %u new)", 1010 " blocks, %u new)",
1014 o_blocks_count + add, add); 1011 o_blocks_count + add, add);
@@ -1016,7 +1013,7 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es,
1016 /* See if the device is actually as big as what was requested */ 1013 /* See if the device is actually as big as what was requested */
1017 bh = sb_bread(sb, o_blocks_count + add -1); 1014 bh = sb_bread(sb, o_blocks_count + add -1);
1018 if (!bh) { 1015 if (!bh) {
1019 ext4_warning(sb, __FUNCTION__, 1016 ext4_warning(sb, __func__,
1020 "can't read last block, resize aborted"); 1017 "can't read last block, resize aborted");
1021 return -ENOSPC; 1018 return -ENOSPC;
1022 } 1019 }
@@ -1028,13 +1025,13 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es,
1028 handle = ext4_journal_start_sb(sb, 3); 1025 handle = ext4_journal_start_sb(sb, 3);
1029 if (IS_ERR(handle)) { 1026 if (IS_ERR(handle)) {
1030 err = PTR_ERR(handle); 1027 err = PTR_ERR(handle);
1031 ext4_warning(sb, __FUNCTION__, "error %d on journal start",err); 1028 ext4_warning(sb, __func__, "error %d on journal start", err);
1032 goto exit_put; 1029 goto exit_put;
1033 } 1030 }
1034 1031
1035 lock_super(sb); 1032 lock_super(sb);
1036 if (o_blocks_count != ext4_blocks_count(es)) { 1033 if (o_blocks_count != ext4_blocks_count(es)) {
1037 ext4_warning(sb, __FUNCTION__, 1034 ext4_warning(sb, __func__,
1038 "multiple resizers run on filesystem!"); 1035 "multiple resizers run on filesystem!");
1039 unlock_super(sb); 1036 unlock_super(sb);
1040 ext4_journal_stop(handle); 1037 ext4_journal_stop(handle);
@@ -1044,7 +1041,7 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es,
1044 1041
1045 if ((err = ext4_journal_get_write_access(handle, 1042 if ((err = ext4_journal_get_write_access(handle,
1046 EXT4_SB(sb)->s_sbh))) { 1043 EXT4_SB(sb)->s_sbh))) {
1047 ext4_warning(sb, __FUNCTION__, 1044 ext4_warning(sb, __func__,
1048 "error %d on journal write access", err); 1045 "error %d on journal write access", err);
1049 unlock_super(sb); 1046 unlock_super(sb);
1050 ext4_journal_stop(handle); 1047 ext4_journal_stop(handle);
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index c81a8e759bad..52dd0679a4e2 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -21,8 +21,6 @@
21#include <linux/fs.h> 21#include <linux/fs.h>
22#include <linux/time.h> 22#include <linux/time.h>
23#include <linux/jbd2.h> 23#include <linux/jbd2.h>
24#include <linux/ext4_fs.h>
25#include <linux/ext4_jbd2.h>
26#include <linux/slab.h> 24#include <linux/slab.h>
27#include <linux/init.h> 25#include <linux/init.h>
28#include <linux/blkdev.h> 26#include <linux/blkdev.h>
@@ -38,9 +36,10 @@
38#include <linux/seq_file.h> 36#include <linux/seq_file.h>
39#include <linux/log2.h> 37#include <linux/log2.h>
40#include <linux/crc16.h> 38#include <linux/crc16.h>
41
42#include <asm/uaccess.h> 39#include <asm/uaccess.h>
43 40
41#include "ext4.h"
42#include "ext4_jbd2.h"
44#include "xattr.h" 43#include "xattr.h"
45#include "acl.h" 44#include "acl.h"
46#include "namei.h" 45#include "namei.h"
@@ -135,7 +134,7 @@ handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks)
135 * take the FS itself readonly cleanly. */ 134 * take the FS itself readonly cleanly. */
136 journal = EXT4_SB(sb)->s_journal; 135 journal = EXT4_SB(sb)->s_journal;
137 if (is_journal_aborted(journal)) { 136 if (is_journal_aborted(journal)) {
138 ext4_abort(sb, __FUNCTION__, 137 ext4_abort(sb, __func__,
139 "Detected aborted journal"); 138 "Detected aborted journal");
140 return ERR_PTR(-EROFS); 139 return ERR_PTR(-EROFS);
141 } 140 }
@@ -355,7 +354,7 @@ void ext4_update_dynamic_rev(struct super_block *sb)
355 if (le32_to_cpu(es->s_rev_level) > EXT4_GOOD_OLD_REV) 354 if (le32_to_cpu(es->s_rev_level) > EXT4_GOOD_OLD_REV)
356 return; 355 return;
357 356
358 ext4_warning(sb, __FUNCTION__, 357 ext4_warning(sb, __func__,
359 "updating to rev %d because of new feature flag, " 358 "updating to rev %d because of new feature flag, "
360 "running e2fsck is recommended", 359 "running e2fsck is recommended",
361 EXT4_DYNAMIC_REV); 360 EXT4_DYNAMIC_REV);
@@ -945,8 +944,8 @@ static match_table_t tokens = {
945 {Opt_mballoc, "mballoc"}, 944 {Opt_mballoc, "mballoc"},
946 {Opt_nomballoc, "nomballoc"}, 945 {Opt_nomballoc, "nomballoc"},
947 {Opt_stripe, "stripe=%u"}, 946 {Opt_stripe, "stripe=%u"},
948 {Opt_err, NULL},
949 {Opt_resize, "resize"}, 947 {Opt_resize, "resize"},
948 {Opt_err, NULL},
950}; 949};
951 950
952static ext4_fsblk_t get_sb_block(void **data) 951static ext4_fsblk_t get_sb_block(void **data)
@@ -1388,11 +1387,11 @@ static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
1388 * a plain journaled filesystem we can keep it set as 1387 * a plain journaled filesystem we can keep it set as
1389 * valid forever! :) 1388 * valid forever! :)
1390 */ 1389 */
1391 es->s_state = cpu_to_le16(le16_to_cpu(es->s_state) & ~EXT4_VALID_FS); 1390 es->s_state &= cpu_to_le16(~EXT4_VALID_FS);
1392#endif 1391#endif
1393 if (!(__s16) le16_to_cpu(es->s_max_mnt_count)) 1392 if (!(__s16) le16_to_cpu(es->s_max_mnt_count))
1394 es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT); 1393 es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT);
1395 es->s_mnt_count=cpu_to_le16(le16_to_cpu(es->s_mnt_count) + 1); 1394 le16_add_cpu(&es->s_mnt_count, 1);
1396 es->s_mtime = cpu_to_le32(get_seconds()); 1395 es->s_mtime = cpu_to_le32(get_seconds());
1397 ext4_update_dynamic_rev(sb); 1396 ext4_update_dynamic_rev(sb);
1398 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 1397 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
@@ -1485,36 +1484,33 @@ static int ext4_check_descriptors(struct super_block *sb)
1485 block_bitmap = ext4_block_bitmap(sb, gdp); 1484 block_bitmap = ext4_block_bitmap(sb, gdp);
1486 if (block_bitmap < first_block || block_bitmap > last_block) 1485 if (block_bitmap < first_block || block_bitmap > last_block)
1487 { 1486 {
1488 ext4_error (sb, "ext4_check_descriptors", 1487 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: "
1489 "Block bitmap for group %lu" 1488 "Block bitmap for group %lu not in group "
1490 " not in group (block %llu)!", 1489 "(block %llu)!", i, block_bitmap);
1491 i, block_bitmap);
1492 return 0; 1490 return 0;
1493 } 1491 }
1494 inode_bitmap = ext4_inode_bitmap(sb, gdp); 1492 inode_bitmap = ext4_inode_bitmap(sb, gdp);
1495 if (inode_bitmap < first_block || inode_bitmap > last_block) 1493 if (inode_bitmap < first_block || inode_bitmap > last_block)
1496 { 1494 {
1497 ext4_error (sb, "ext4_check_descriptors", 1495 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: "
1498 "Inode bitmap for group %lu" 1496 "Inode bitmap for group %lu not in group "
1499 " not in group (block %llu)!", 1497 "(block %llu)!", i, inode_bitmap);
1500 i, inode_bitmap);
1501 return 0; 1498 return 0;
1502 } 1499 }
1503 inode_table = ext4_inode_table(sb, gdp); 1500 inode_table = ext4_inode_table(sb, gdp);
1504 if (inode_table < first_block || 1501 if (inode_table < first_block ||
1505 inode_table + sbi->s_itb_per_group - 1 > last_block) 1502 inode_table + sbi->s_itb_per_group - 1 > last_block)
1506 { 1503 {
1507 ext4_error (sb, "ext4_check_descriptors", 1504 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: "
1508 "Inode table for group %lu" 1505 "Inode table for group %lu not in group "
1509 " not in group (block %llu)!", 1506 "(block %llu)!", i, inode_table);
1510 i, inode_table);
1511 return 0; 1507 return 0;
1512 } 1508 }
1513 if (!ext4_group_desc_csum_verify(sbi, i, gdp)) { 1509 if (!ext4_group_desc_csum_verify(sbi, i, gdp)) {
1514 ext4_error(sb, __FUNCTION__, 1510 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: "
1515 "Checksum for group %lu failed (%u!=%u)\n", 1511 "Checksum for group %lu failed (%u!=%u)\n",
1516 i, le16_to_cpu(ext4_group_desc_csum(sbi, i, 1512 i, le16_to_cpu(ext4_group_desc_csum(sbi, i,
1517 gdp)), le16_to_cpu(gdp->bg_checksum)); 1513 gdp)), le16_to_cpu(gdp->bg_checksum));
1518 return 0; 1514 return 0;
1519 } 1515 }
1520 if (!flexbg_flag) 1516 if (!flexbg_flag)
@@ -1594,8 +1590,8 @@ static void ext4_orphan_cleanup (struct super_block * sb,
1594 while (es->s_last_orphan) { 1590 while (es->s_last_orphan) {
1595 struct inode *inode; 1591 struct inode *inode;
1596 1592
1597 if (!(inode = 1593 inode = ext4_orphan_get(sb, le32_to_cpu(es->s_last_orphan));
1598 ext4_orphan_get(sb, le32_to_cpu(es->s_last_orphan)))) { 1594 if (IS_ERR(inode)) {
1599 es->s_last_orphan = 0; 1595 es->s_last_orphan = 0;
1600 break; 1596 break;
1601 } 1597 }
@@ -1605,7 +1601,7 @@ static void ext4_orphan_cleanup (struct super_block * sb,
1605 if (inode->i_nlink) { 1601 if (inode->i_nlink) {
1606 printk(KERN_DEBUG 1602 printk(KERN_DEBUG
1607 "%s: truncating inode %lu to %Ld bytes\n", 1603 "%s: truncating inode %lu to %Ld bytes\n",
1608 __FUNCTION__, inode->i_ino, inode->i_size); 1604 __func__, inode->i_ino, inode->i_size);
1609 jbd_debug(2, "truncating inode %lu to %Ld bytes\n", 1605 jbd_debug(2, "truncating inode %lu to %Ld bytes\n",
1610 inode->i_ino, inode->i_size); 1606 inode->i_ino, inode->i_size);
1611 ext4_truncate(inode); 1607 ext4_truncate(inode);
@@ -1613,7 +1609,7 @@ static void ext4_orphan_cleanup (struct super_block * sb,
1613 } else { 1609 } else {
1614 printk(KERN_DEBUG 1610 printk(KERN_DEBUG
1615 "%s: deleting unreferenced inode %lu\n", 1611 "%s: deleting unreferenced inode %lu\n",
1616 __FUNCTION__, inode->i_ino); 1612 __func__, inode->i_ino);
1617 jbd_debug(2, "deleting unreferenced inode %lu\n", 1613 jbd_debug(2, "deleting unreferenced inode %lu\n",
1618 inode->i_ino); 1614 inode->i_ino);
1619 nr_orphans++; 1615 nr_orphans++;
@@ -2699,9 +2695,9 @@ static void ext4_clear_journal_err(struct super_block * sb,
2699 char nbuf[16]; 2695 char nbuf[16];
2700 2696
2701 errstr = ext4_decode_error(sb, j_errno, nbuf); 2697 errstr = ext4_decode_error(sb, j_errno, nbuf);
2702 ext4_warning(sb, __FUNCTION__, "Filesystem error recorded " 2698 ext4_warning(sb, __func__, "Filesystem error recorded "
2703 "from previous mount: %s", errstr); 2699 "from previous mount: %s", errstr);
2704 ext4_warning(sb, __FUNCTION__, "Marking fs in need of " 2700 ext4_warning(sb, __func__, "Marking fs in need of "
2705 "filesystem check."); 2701 "filesystem check.");
2706 2702
2707 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 2703 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
@@ -2828,7 +2824,7 @@ static int ext4_remount (struct super_block * sb, int * flags, char * data)
2828 } 2824 }
2829 2825
2830 if (sbi->s_mount_opt & EXT4_MOUNT_ABORT) 2826 if (sbi->s_mount_opt & EXT4_MOUNT_ABORT)
2831 ext4_abort(sb, __FUNCTION__, "Abort forced by user"); 2827 ext4_abort(sb, __func__, "Abort forced by user");
2832 2828
2833 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | 2829 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2834 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0); 2830 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
@@ -3040,8 +3036,14 @@ static int ext4_dquot_drop(struct inode *inode)
3040 3036
3041 /* We may delete quota structure so we need to reserve enough blocks */ 3037 /* We may delete quota structure so we need to reserve enough blocks */
3042 handle = ext4_journal_start(inode, 2*EXT4_QUOTA_DEL_BLOCKS(inode->i_sb)); 3038 handle = ext4_journal_start(inode, 2*EXT4_QUOTA_DEL_BLOCKS(inode->i_sb));
3043 if (IS_ERR(handle)) 3039 if (IS_ERR(handle)) {
3040 /*
3041 * We call dquot_drop() anyway to at least release references
3042 * to quota structures so that umount does not hang.
3043 */
3044 dquot_drop(inode);
3044 return PTR_ERR(handle); 3045 return PTR_ERR(handle);
3046 }
3045 ret = dquot_drop(inode); 3047 ret = dquot_drop(inode);
3046 err = ext4_journal_stop(handle); 3048 err = ext4_journal_stop(handle);
3047 if (!ret) 3049 if (!ret)
diff --git a/fs/ext4/symlink.c b/fs/ext4/symlink.c
index e6f9da4287c4..e9178643dc01 100644
--- a/fs/ext4/symlink.c
+++ b/fs/ext4/symlink.c
@@ -19,8 +19,8 @@
19 19
20#include <linux/fs.h> 20#include <linux/fs.h>
21#include <linux/jbd2.h> 21#include <linux/jbd2.h>
22#include <linux/ext4_fs.h>
23#include <linux/namei.h> 22#include <linux/namei.h>
23#include "ext4.h"
24#include "xattr.h" 24#include "xattr.h"
25 25
26static void * ext4_follow_link(struct dentry *dentry, struct nameidata *nd) 26static void * ext4_follow_link(struct dentry *dentry, struct nameidata *nd)
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index e9054c1c7d93..3fbc2c6c3d0e 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -53,11 +53,11 @@
53#include <linux/init.h> 53#include <linux/init.h>
54#include <linux/fs.h> 54#include <linux/fs.h>
55#include <linux/slab.h> 55#include <linux/slab.h>
56#include <linux/ext4_jbd2.h>
57#include <linux/ext4_fs.h>
58#include <linux/mbcache.h> 56#include <linux/mbcache.h>
59#include <linux/quotaops.h> 57#include <linux/quotaops.h>
60#include <linux/rwsem.h> 58#include <linux/rwsem.h>
59#include "ext4_jbd2.h"
60#include "ext4.h"
61#include "xattr.h" 61#include "xattr.h"
62#include "acl.h" 62#include "acl.h"
63 63
@@ -92,6 +92,8 @@ static struct buffer_head *ext4_xattr_cache_find(struct inode *,
92 struct mb_cache_entry **); 92 struct mb_cache_entry **);
93static void ext4_xattr_rehash(struct ext4_xattr_header *, 93static void ext4_xattr_rehash(struct ext4_xattr_header *,
94 struct ext4_xattr_entry *); 94 struct ext4_xattr_entry *);
95static int ext4_xattr_list(struct inode *inode, char *buffer,
96 size_t buffer_size);
95 97
96static struct mb_cache *ext4_xattr_cache; 98static struct mb_cache *ext4_xattr_cache;
97 99
@@ -225,7 +227,7 @@ ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,
225 ea_bdebug(bh, "b_count=%d, refcount=%d", 227 ea_bdebug(bh, "b_count=%d, refcount=%d",
226 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount)); 228 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
227 if (ext4_xattr_check_block(bh)) { 229 if (ext4_xattr_check_block(bh)) {
228bad_block: ext4_error(inode->i_sb, __FUNCTION__, 230bad_block: ext4_error(inode->i_sb, __func__,
229 "inode %lu: bad block %llu", inode->i_ino, 231 "inode %lu: bad block %llu", inode->i_ino,
230 EXT4_I(inode)->i_file_acl); 232 EXT4_I(inode)->i_file_acl);
231 error = -EIO; 233 error = -EIO;
@@ -367,7 +369,7 @@ ext4_xattr_block_list(struct inode *inode, char *buffer, size_t buffer_size)
367 ea_bdebug(bh, "b_count=%d, refcount=%d", 369 ea_bdebug(bh, "b_count=%d, refcount=%d",
368 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount)); 370 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
369 if (ext4_xattr_check_block(bh)) { 371 if (ext4_xattr_check_block(bh)) {
370 ext4_error(inode->i_sb, __FUNCTION__, 372 ext4_error(inode->i_sb, __func__,
371 "inode %lu: bad block %llu", inode->i_ino, 373 "inode %lu: bad block %llu", inode->i_ino,
372 EXT4_I(inode)->i_file_acl); 374 EXT4_I(inode)->i_file_acl);
373 error = -EIO; 375 error = -EIO;
@@ -420,7 +422,7 @@ cleanup:
420 * Returns a negative error number on failure, or the number of bytes 422 * Returns a negative error number on failure, or the number of bytes
421 * used / required on success. 423 * used / required on success.
422 */ 424 */
423int 425static int
424ext4_xattr_list(struct inode *inode, char *buffer, size_t buffer_size) 426ext4_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
425{ 427{
426 int i_error, b_error; 428 int i_error, b_error;
@@ -484,8 +486,7 @@ ext4_xattr_release_block(handle_t *handle, struct inode *inode,
484 get_bh(bh); 486 get_bh(bh);
485 ext4_forget(handle, 1, inode, bh, bh->b_blocknr); 487 ext4_forget(handle, 1, inode, bh, bh->b_blocknr);
486 } else { 488 } else {
487 BHDR(bh)->h_refcount = cpu_to_le32( 489 le32_add_cpu(&BHDR(bh)->h_refcount, -1);
488 le32_to_cpu(BHDR(bh)->h_refcount) - 1);
489 error = ext4_journal_dirty_metadata(handle, bh); 490 error = ext4_journal_dirty_metadata(handle, bh);
490 if (IS_SYNC(inode)) 491 if (IS_SYNC(inode))
491 handle->h_sync = 1; 492 handle->h_sync = 1;
@@ -660,7 +661,7 @@ ext4_xattr_block_find(struct inode *inode, struct ext4_xattr_info *i,
660 atomic_read(&(bs->bh->b_count)), 661 atomic_read(&(bs->bh->b_count)),
661 le32_to_cpu(BHDR(bs->bh)->h_refcount)); 662 le32_to_cpu(BHDR(bs->bh)->h_refcount));
662 if (ext4_xattr_check_block(bs->bh)) { 663 if (ext4_xattr_check_block(bs->bh)) {
663 ext4_error(sb, __FUNCTION__, 664 ext4_error(sb, __func__,
664 "inode %lu: bad block %llu", inode->i_ino, 665 "inode %lu: bad block %llu", inode->i_ino,
665 EXT4_I(inode)->i_file_acl); 666 EXT4_I(inode)->i_file_acl);
666 error = -EIO; 667 error = -EIO;
@@ -738,7 +739,7 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
738 ce = NULL; 739 ce = NULL;
739 } 740 }
740 ea_bdebug(bs->bh, "cloning"); 741 ea_bdebug(bs->bh, "cloning");
741 s->base = kmalloc(bs->bh->b_size, GFP_KERNEL); 742 s->base = kmalloc(bs->bh->b_size, GFP_NOFS);
742 error = -ENOMEM; 743 error = -ENOMEM;
743 if (s->base == NULL) 744 if (s->base == NULL)
744 goto cleanup; 745 goto cleanup;
@@ -750,7 +751,7 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
750 } 751 }
751 } else { 752 } else {
752 /* Allocate a buffer where we construct the new block. */ 753 /* Allocate a buffer where we construct the new block. */
753 s->base = kzalloc(sb->s_blocksize, GFP_KERNEL); 754 s->base = kzalloc(sb->s_blocksize, GFP_NOFS);
754 /* assert(header == s->base) */ 755 /* assert(header == s->base) */
755 error = -ENOMEM; 756 error = -ENOMEM;
756 if (s->base == NULL) 757 if (s->base == NULL)
@@ -789,8 +790,7 @@ inserted:
789 if (error) 790 if (error)
790 goto cleanup_dquot; 791 goto cleanup_dquot;
791 lock_buffer(new_bh); 792 lock_buffer(new_bh);
792 BHDR(new_bh)->h_refcount = cpu_to_le32(1 + 793 le32_add_cpu(&BHDR(new_bh)->h_refcount, 1);
793 le32_to_cpu(BHDR(new_bh)->h_refcount));
794 ea_bdebug(new_bh, "reusing; refcount now=%d", 794 ea_bdebug(new_bh, "reusing; refcount now=%d",
795 le32_to_cpu(BHDR(new_bh)->h_refcount)); 795 le32_to_cpu(BHDR(new_bh)->h_refcount));
796 unlock_buffer(new_bh); 796 unlock_buffer(new_bh);
@@ -808,10 +808,8 @@ inserted:
808 get_bh(new_bh); 808 get_bh(new_bh);
809 } else { 809 } else {
810 /* We need to allocate a new block */ 810 /* We need to allocate a new block */
811 ext4_fsblk_t goal = le32_to_cpu( 811 ext4_fsblk_t goal = ext4_group_first_block_no(sb,
812 EXT4_SB(sb)->s_es->s_first_data_block) + 812 EXT4_I(inode)->i_block_group);
813 (ext4_fsblk_t)EXT4_I(inode)->i_block_group *
814 EXT4_BLOCKS_PER_GROUP(sb);
815 ext4_fsblk_t block = ext4_new_block(handle, inode, 813 ext4_fsblk_t block = ext4_new_block(handle, inode,
816 goal, &error); 814 goal, &error);
817 if (error) 815 if (error)
@@ -863,7 +861,7 @@ cleanup_dquot:
863 goto cleanup; 861 goto cleanup;
864 862
865bad_block: 863bad_block:
866 ext4_error(inode->i_sb, __FUNCTION__, 864 ext4_error(inode->i_sb, __func__,
867 "inode %lu: bad block %llu", inode->i_ino, 865 "inode %lu: bad block %llu", inode->i_ino,
868 EXT4_I(inode)->i_file_acl); 866 EXT4_I(inode)->i_file_acl);
869 goto cleanup; 867 goto cleanup;
@@ -1166,7 +1164,7 @@ retry:
1166 if (!bh) 1164 if (!bh)
1167 goto cleanup; 1165 goto cleanup;
1168 if (ext4_xattr_check_block(bh)) { 1166 if (ext4_xattr_check_block(bh)) {
1169 ext4_error(inode->i_sb, __FUNCTION__, 1167 ext4_error(inode->i_sb, __func__,
1170 "inode %lu: bad block %llu", inode->i_ino, 1168 "inode %lu: bad block %llu", inode->i_ino,
1171 EXT4_I(inode)->i_file_acl); 1169 EXT4_I(inode)->i_file_acl);
1172 error = -EIO; 1170 error = -EIO;
@@ -1341,14 +1339,14 @@ ext4_xattr_delete_inode(handle_t *handle, struct inode *inode)
1341 goto cleanup; 1339 goto cleanup;
1342 bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl); 1340 bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl);
1343 if (!bh) { 1341 if (!bh) {
1344 ext4_error(inode->i_sb, __FUNCTION__, 1342 ext4_error(inode->i_sb, __func__,
1345 "inode %lu: block %llu read error", inode->i_ino, 1343 "inode %lu: block %llu read error", inode->i_ino,
1346 EXT4_I(inode)->i_file_acl); 1344 EXT4_I(inode)->i_file_acl);
1347 goto cleanup; 1345 goto cleanup;
1348 } 1346 }
1349 if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) || 1347 if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) ||
1350 BHDR(bh)->h_blocks != cpu_to_le32(1)) { 1348 BHDR(bh)->h_blocks != cpu_to_le32(1)) {
1351 ext4_error(inode->i_sb, __FUNCTION__, 1349 ext4_error(inode->i_sb, __func__,
1352 "inode %lu: bad block %llu", inode->i_ino, 1350 "inode %lu: bad block %llu", inode->i_ino,
1353 EXT4_I(inode)->i_file_acl); 1351 EXT4_I(inode)->i_file_acl);
1354 goto cleanup; 1352 goto cleanup;
@@ -1475,7 +1473,7 @@ again:
1475 } 1473 }
1476 bh = sb_bread(inode->i_sb, ce->e_block); 1474 bh = sb_bread(inode->i_sb, ce->e_block);
1477 if (!bh) { 1475 if (!bh) {
1478 ext4_error(inode->i_sb, __FUNCTION__, 1476 ext4_error(inode->i_sb, __func__,
1479 "inode %lu: block %lu read error", 1477 "inode %lu: block %lu read error",
1480 inode->i_ino, (unsigned long) ce->e_block); 1478 inode->i_ino, (unsigned long) ce->e_block);
1481 } else if (le32_to_cpu(BHDR(bh)->h_refcount) >= 1479 } else if (le32_to_cpu(BHDR(bh)->h_refcount) >=
diff --git a/fs/ext4/xattr.h b/fs/ext4/xattr.h
index d7f5d6a12651..5992fe979bb9 100644
--- a/fs/ext4/xattr.h
+++ b/fs/ext4/xattr.h
@@ -74,7 +74,6 @@ extern struct xattr_handler ext4_xattr_security_handler;
74extern ssize_t ext4_listxattr(struct dentry *, char *, size_t); 74extern ssize_t ext4_listxattr(struct dentry *, char *, size_t);
75 75
76extern int ext4_xattr_get(struct inode *, int, const char *, void *, size_t); 76extern int ext4_xattr_get(struct inode *, int, const char *, void *, size_t);
77extern int ext4_xattr_list(struct inode *, char *, size_t);
78extern int ext4_xattr_set(struct inode *, int, const char *, const void *, size_t, int); 77extern int ext4_xattr_set(struct inode *, int, const char *, const void *, size_t, int);
79extern int ext4_xattr_set_handle(handle_t *, struct inode *, int, const char *, const void *, size_t, int); 78extern int ext4_xattr_set_handle(handle_t *, struct inode *, int, const char *, const void *, size_t, int);
80 79
@@ -99,12 +98,6 @@ ext4_xattr_get(struct inode *inode, int name_index, const char *name,
99} 98}
100 99
101static inline int 100static inline int
102ext4_xattr_list(struct inode *inode, void *buffer, size_t size)
103{
104 return -EOPNOTSUPP;
105}
106
107static inline int
108ext4_xattr_set(struct inode *inode, int name_index, const char *name, 101ext4_xattr_set(struct inode *inode, int name_index, const char *name,
109 const void *value, size_t size, int flags) 102 const void *value, size_t size, int flags)
110{ 103{
diff --git a/fs/ext4/xattr_security.c b/fs/ext4/xattr_security.c
index f17eaf2321b9..ca5f89fc6cae 100644
--- a/fs/ext4/xattr_security.c
+++ b/fs/ext4/xattr_security.c
@@ -6,9 +6,9 @@
6#include <linux/module.h> 6#include <linux/module.h>
7#include <linux/string.h> 7#include <linux/string.h>
8#include <linux/fs.h> 8#include <linux/fs.h>
9#include <linux/ext4_jbd2.h>
10#include <linux/ext4_fs.h>
11#include <linux/security.h> 9#include <linux/security.h>
10#include "ext4_jbd2.h"
11#include "ext4.h"
12#include "xattr.h" 12#include "xattr.h"
13 13
14static size_t 14static size_t
diff --git a/fs/ext4/xattr_trusted.c b/fs/ext4/xattr_trusted.c
index e0f05acdafec..fff33382cadc 100644
--- a/fs/ext4/xattr_trusted.c
+++ b/fs/ext4/xattr_trusted.c
@@ -9,8 +9,8 @@
9#include <linux/string.h> 9#include <linux/string.h>
10#include <linux/capability.h> 10#include <linux/capability.h>
11#include <linux/fs.h> 11#include <linux/fs.h>
12#include <linux/ext4_jbd2.h> 12#include "ext4_jbd2.h"
13#include <linux/ext4_fs.h> 13#include "ext4.h"
14#include "xattr.h" 14#include "xattr.h"
15 15
16#define XATTR_TRUSTED_PREFIX "trusted." 16#define XATTR_TRUSTED_PREFIX "trusted."
diff --git a/fs/ext4/xattr_user.c b/fs/ext4/xattr_user.c
index 7ed3d8ebf096..67be723fcc4e 100644
--- a/fs/ext4/xattr_user.c
+++ b/fs/ext4/xattr_user.c
@@ -8,8 +8,8 @@
8#include <linux/module.h> 8#include <linux/module.h>
9#include <linux/string.h> 9#include <linux/string.h>
10#include <linux/fs.h> 10#include <linux/fs.h>
11#include <linux/ext4_jbd2.h> 11#include "ext4_jbd2.h"
12#include <linux/ext4_fs.h> 12#include "ext4.h"
13#include "xattr.h" 13#include "xattr.h"
14 14
15#define XATTR_USER_PREFIX "user." 15#define XATTR_USER_PREFIX "user."
diff --git a/fs/fat/cache.c b/fs/fat/cache.c
index 639b3b4f86d1..fda25479af26 100644
--- a/fs/fat/cache.c
+++ b/fs/fat/cache.c
@@ -242,7 +242,7 @@ int fat_get_cluster(struct inode *inode, int cluster, int *fclus, int *dclus)
242 /* prevent the infinite loop of cluster chain */ 242 /* prevent the infinite loop of cluster chain */
243 if (*fclus > limit) { 243 if (*fclus > limit) {
244 fat_fs_panic(sb, "%s: detected the cluster chain loop" 244 fat_fs_panic(sb, "%s: detected the cluster chain loop"
245 " (i_pos %lld)", __FUNCTION__, 245 " (i_pos %lld)", __func__,
246 MSDOS_I(inode)->i_pos); 246 MSDOS_I(inode)->i_pos);
247 nr = -EIO; 247 nr = -EIO;
248 goto out; 248 goto out;
@@ -253,7 +253,7 @@ int fat_get_cluster(struct inode *inode, int cluster, int *fclus, int *dclus)
253 goto out; 253 goto out;
254 else if (nr == FAT_ENT_FREE) { 254 else if (nr == FAT_ENT_FREE) {
255 fat_fs_panic(sb, "%s: invalid cluster chain" 255 fat_fs_panic(sb, "%s: invalid cluster chain"
256 " (i_pos %lld)", __FUNCTION__, 256 " (i_pos %lld)", __func__,
257 MSDOS_I(inode)->i_pos); 257 MSDOS_I(inode)->i_pos);
258 nr = -EIO; 258 nr = -EIO;
259 goto out; 259 goto out;
@@ -286,7 +286,7 @@ static int fat_bmap_cluster(struct inode *inode, int cluster)
286 return ret; 286 return ret;
287 else if (ret == FAT_ENT_EOF) { 287 else if (ret == FAT_ENT_EOF) {
288 fat_fs_panic(sb, "%s: request beyond EOF (i_pos %lld)", 288 fat_fs_panic(sb, "%s: request beyond EOF (i_pos %lld)",
289 __FUNCTION__, MSDOS_I(inode)->i_pos); 289 __func__, MSDOS_I(inode)->i_pos);
290 return -EIO; 290 return -EIO;
291 } 291 }
292 return dclus; 292 return dclus;
diff --git a/fs/fat/fatent.c b/fs/fat/fatent.c
index 13ab763cc510..302e95c4af7e 100644
--- a/fs/fat/fatent.c
+++ b/fs/fat/fatent.c
@@ -546,7 +546,7 @@ int fat_free_clusters(struct inode *inode, int cluster)
546 goto error; 546 goto error;
547 } else if (cluster == FAT_ENT_FREE) { 547 } else if (cluster == FAT_ENT_FREE) {
548 fat_fs_panic(sb, "%s: deleting FAT entry beyond EOF", 548 fat_fs_panic(sb, "%s: deleting FAT entry beyond EOF",
549 __FUNCTION__); 549 __func__);
550 err = -EIO; 550 err = -EIO;
551 goto error; 551 goto error;
552 } 552 }
diff --git a/fs/fat/file.c b/fs/fat/file.c
index d604bb132422..27cc1164ec36 100644
--- a/fs/fat/file.c
+++ b/fs/fat/file.c
@@ -208,7 +208,7 @@ static int fat_free(struct inode *inode, int skip)
208 } else if (ret == FAT_ENT_FREE) { 208 } else if (ret == FAT_ENT_FREE) {
209 fat_fs_panic(sb, 209 fat_fs_panic(sb,
210 "%s: invalid cluster chain (i_pos %lld)", 210 "%s: invalid cluster chain (i_pos %lld)",
211 __FUNCTION__, MSDOS_I(inode)->i_pos); 211 __func__, MSDOS_I(inode)->i_pos);
212 ret = -EIO; 212 ret = -EIO;
213 } else if (ret > 0) { 213 } else if (ret > 0) {
214 err = fat_ent_write(inode, &fatent, FAT_ENT_EOF, wait); 214 err = fat_ent_write(inode, &fatent, FAT_ENT_EOF, wait);
diff --git a/fs/fcntl.c b/fs/fcntl.c
index 3f3ac630ccde..bfd776509a72 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -9,6 +9,7 @@
9#include <linux/mm.h> 9#include <linux/mm.h>
10#include <linux/fs.h> 10#include <linux/fs.h>
11#include <linux/file.h> 11#include <linux/file.h>
12#include <linux/fdtable.h>
12#include <linux/capability.h> 13#include <linux/capability.h>
13#include <linux/dnotify.h> 14#include <linux/dnotify.h>
14#include <linux/smp_lock.h> 15#include <linux/smp_lock.h>
diff --git a/fs/file.c b/fs/file.c
index 5110acb1c9ef..4c6f0ea12c41 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -12,6 +12,7 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/vmalloc.h> 13#include <linux/vmalloc.h>
14#include <linux/file.h> 14#include <linux/file.h>
15#include <linux/fdtable.h>
15#include <linux/bitops.h> 16#include <linux/bitops.h>
16#include <linux/interrupt.h> 17#include <linux/interrupt.h>
17#include <linux/spinlock.h> 18#include <linux/spinlock.h>
@@ -149,8 +150,16 @@ static struct fdtable * alloc_fdtable(unsigned int nr)
149 nr /= (1024 / sizeof(struct file *)); 150 nr /= (1024 / sizeof(struct file *));
150 nr = roundup_pow_of_two(nr + 1); 151 nr = roundup_pow_of_two(nr + 1);
151 nr *= (1024 / sizeof(struct file *)); 152 nr *= (1024 / sizeof(struct file *));
152 if (nr > sysctl_nr_open) 153 /*
153 nr = sysctl_nr_open; 154 * Note that this can drive nr *below* what we had passed if sysctl_nr_open
155 * had been set lower between the check in expand_files() and here. Deal
156 * with that in caller, it's cheaper that way.
157 *
158 * We make sure that nr remains a multiple of BITS_PER_LONG - otherwise
159 * bitmaps handling below becomes unpleasant, to put it mildly...
160 */
161 if (unlikely(nr > sysctl_nr_open))
162 nr = ((sysctl_nr_open - 1) | (BITS_PER_LONG - 1)) + 1;
154 163
155 fdt = kmalloc(sizeof(struct fdtable), GFP_KERNEL); 164 fdt = kmalloc(sizeof(struct fdtable), GFP_KERNEL);
156 if (!fdt) 165 if (!fdt)
@@ -199,6 +208,16 @@ static int expand_fdtable(struct files_struct *files, int nr)
199 if (!new_fdt) 208 if (!new_fdt)
200 return -ENOMEM; 209 return -ENOMEM;
201 /* 210 /*
211 * extremely unlikely race - sysctl_nr_open decreased between the check in
212 * caller and alloc_fdtable(). Cheaper to catch it here...
213 */
214 if (unlikely(new_fdt->max_fds <= nr)) {
215 free_fdarr(new_fdt);
216 free_fdset(new_fdt);
217 kfree(new_fdt);
218 return -EMFILE;
219 }
220 /*
202 * Check again since another task may have expanded the fd table while 221 * Check again since another task may have expanded the fd table while
203 * we dropped the lock 222 * we dropped the lock
204 */ 223 */
diff --git a/fs/file_table.c b/fs/file_table.c
index 7a0a9b872251..83084225b4c3 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -8,6 +8,7 @@
8#include <linux/string.h> 8#include <linux/string.h>
9#include <linux/slab.h> 9#include <linux/slab.h>
10#include <linux/file.h> 10#include <linux/file.h>
11#include <linux/fdtable.h>
11#include <linux/init.h> 12#include <linux/init.h>
12#include <linux/module.h> 13#include <linux/module.h>
13#include <linux/fs.h> 14#include <linux/fs.h>
diff --git a/fs/fuse/control.c b/fs/fuse/control.c
index 105d4a271e07..4f3cab321415 100644
--- a/fs/fuse/control.c
+++ b/fs/fuse/control.c
@@ -117,7 +117,7 @@ int fuse_ctl_add_conn(struct fuse_conn *fc)
117 117
118 parent = fuse_control_sb->s_root; 118 parent = fuse_control_sb->s_root;
119 inc_nlink(parent->d_inode); 119 inc_nlink(parent->d_inode);
120 sprintf(name, "%llu", (unsigned long long) fc->id); 120 sprintf(name, "%u", fc->dev);
121 parent = fuse_ctl_add_dentry(parent, fc, name, S_IFDIR | 0500, 2, 121 parent = fuse_ctl_add_dentry(parent, fc, name, S_IFDIR | 0500, 2,
122 &simple_dir_inode_operations, 122 &simple_dir_inode_operations,
123 &simple_dir_operations); 123 &simple_dir_operations);
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index af639807524e..87250b6a8682 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -47,6 +47,14 @@ struct fuse_req *fuse_request_alloc(void)
47 return req; 47 return req;
48} 48}
49 49
50struct fuse_req *fuse_request_alloc_nofs(void)
51{
52 struct fuse_req *req = kmem_cache_alloc(fuse_req_cachep, GFP_NOFS);
53 if (req)
54 fuse_request_init(req);
55 return req;
56}
57
50void fuse_request_free(struct fuse_req *req) 58void fuse_request_free(struct fuse_req *req)
51{ 59{
52 kmem_cache_free(fuse_req_cachep, req); 60 kmem_cache_free(fuse_req_cachep, req);
@@ -291,6 +299,7 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req)
291 299
292static void wait_answer_interruptible(struct fuse_conn *fc, 300static void wait_answer_interruptible(struct fuse_conn *fc,
293 struct fuse_req *req) 301 struct fuse_req *req)
302 __releases(fc->lock) __acquires(fc->lock)
294{ 303{
295 if (signal_pending(current)) 304 if (signal_pending(current))
296 return; 305 return;
@@ -307,8 +316,8 @@ static void queue_interrupt(struct fuse_conn *fc, struct fuse_req *req)
307 kill_fasync(&fc->fasync, SIGIO, POLL_IN); 316 kill_fasync(&fc->fasync, SIGIO, POLL_IN);
308} 317}
309 318
310/* Called with fc->lock held. Releases, and then reacquires it. */
311static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req) 319static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
320 __releases(fc->lock) __acquires(fc->lock)
312{ 321{
313 if (!fc->no_interrupt) { 322 if (!fc->no_interrupt) {
314 /* Any signal may interrupt this */ 323 /* Any signal may interrupt this */
@@ -430,6 +439,17 @@ void request_send_background(struct fuse_conn *fc, struct fuse_req *req)
430} 439}
431 440
432/* 441/*
442 * Called under fc->lock
443 *
444 * fc->connected must have been checked previously
445 */
446void request_send_background_locked(struct fuse_conn *fc, struct fuse_req *req)
447{
448 req->isreply = 1;
449 request_send_nowait_locked(fc, req);
450}
451
452/*
433 * Lock the request. Up to the next unlock_request() there mustn't be 453 * Lock the request. Up to the next unlock_request() there mustn't be
434 * anything that could cause a page-fault. If the request was already 454 * anything that could cause a page-fault. If the request was already
435 * aborted bail out. 455 * aborted bail out.
@@ -968,6 +988,7 @@ static void end_requests(struct fuse_conn *fc, struct list_head *head)
968 * locked). 988 * locked).
969 */ 989 */
970static void end_io_requests(struct fuse_conn *fc) 990static void end_io_requests(struct fuse_conn *fc)
991 __releases(fc->lock) __acquires(fc->lock)
971{ 992{
972 while (!list_empty(&fc->io)) { 993 while (!list_empty(&fc->io)) {
973 struct fuse_req *req = 994 struct fuse_req *req =
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index c4807b3fc8a3..2060bf06b906 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -132,7 +132,7 @@ static void fuse_lookup_init(struct fuse_req *req, struct inode *dir,
132 req->out.args[0].value = outarg; 132 req->out.args[0].value = outarg;
133} 133}
134 134
135static u64 fuse_get_attr_version(struct fuse_conn *fc) 135u64 fuse_get_attr_version(struct fuse_conn *fc)
136{ 136{
137 u64 curr_version; 137 u64 curr_version;
138 138
@@ -1107,6 +1107,50 @@ static void iattr_to_fattr(struct iattr *iattr, struct fuse_setattr_in *arg)
1107} 1107}
1108 1108
1109/* 1109/*
1110 * Prevent concurrent writepages on inode
1111 *
1112 * This is done by adding a negative bias to the inode write counter
1113 * and waiting for all pending writes to finish.
1114 */
1115void fuse_set_nowrite(struct inode *inode)
1116{
1117 struct fuse_conn *fc = get_fuse_conn(inode);
1118 struct fuse_inode *fi = get_fuse_inode(inode);
1119
1120 BUG_ON(!mutex_is_locked(&inode->i_mutex));
1121
1122 spin_lock(&fc->lock);
1123 BUG_ON(fi->writectr < 0);
1124 fi->writectr += FUSE_NOWRITE;
1125 spin_unlock(&fc->lock);
1126 wait_event(fi->page_waitq, fi->writectr == FUSE_NOWRITE);
1127}
1128
1129/*
1130 * Allow writepages on inode
1131 *
1132 * Remove the bias from the writecounter and send any queued
1133 * writepages.
1134 */
1135static void __fuse_release_nowrite(struct inode *inode)
1136{
1137 struct fuse_inode *fi = get_fuse_inode(inode);
1138
1139 BUG_ON(fi->writectr != FUSE_NOWRITE);
1140 fi->writectr = 0;
1141 fuse_flush_writepages(inode);
1142}
1143
1144void fuse_release_nowrite(struct inode *inode)
1145{
1146 struct fuse_conn *fc = get_fuse_conn(inode);
1147
1148 spin_lock(&fc->lock);
1149 __fuse_release_nowrite(inode);
1150 spin_unlock(&fc->lock);
1151}
1152
1153/*
1110 * Set attributes, and at the same time refresh them. 1154 * Set attributes, and at the same time refresh them.
1111 * 1155 *
1112 * Truncation is slightly complicated, because the 'truncate' request 1156 * Truncation is slightly complicated, because the 'truncate' request
@@ -1122,6 +1166,8 @@ static int fuse_do_setattr(struct dentry *entry, struct iattr *attr,
1122 struct fuse_req *req; 1166 struct fuse_req *req;
1123 struct fuse_setattr_in inarg; 1167 struct fuse_setattr_in inarg;
1124 struct fuse_attr_out outarg; 1168 struct fuse_attr_out outarg;
1169 bool is_truncate = false;
1170 loff_t oldsize;
1125 int err; 1171 int err;
1126 1172
1127 if (!fuse_allow_task(fc, current)) 1173 if (!fuse_allow_task(fc, current))
@@ -1145,12 +1191,16 @@ static int fuse_do_setattr(struct dentry *entry, struct iattr *attr,
1145 send_sig(SIGXFSZ, current, 0); 1191 send_sig(SIGXFSZ, current, 0);
1146 return -EFBIG; 1192 return -EFBIG;
1147 } 1193 }
1194 is_truncate = true;
1148 } 1195 }
1149 1196
1150 req = fuse_get_req(fc); 1197 req = fuse_get_req(fc);
1151 if (IS_ERR(req)) 1198 if (IS_ERR(req))
1152 return PTR_ERR(req); 1199 return PTR_ERR(req);
1153 1200
1201 if (is_truncate)
1202 fuse_set_nowrite(inode);
1203
1154 memset(&inarg, 0, sizeof(inarg)); 1204 memset(&inarg, 0, sizeof(inarg));
1155 memset(&outarg, 0, sizeof(outarg)); 1205 memset(&outarg, 0, sizeof(outarg));
1156 iattr_to_fattr(attr, &inarg); 1206 iattr_to_fattr(attr, &inarg);
@@ -1181,16 +1231,44 @@ static int fuse_do_setattr(struct dentry *entry, struct iattr *attr,
1181 if (err) { 1231 if (err) {
1182 if (err == -EINTR) 1232 if (err == -EINTR)
1183 fuse_invalidate_attr(inode); 1233 fuse_invalidate_attr(inode);
1184 return err; 1234 goto error;
1185 } 1235 }
1186 1236
1187 if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) { 1237 if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) {
1188 make_bad_inode(inode); 1238 make_bad_inode(inode);
1189 return -EIO; 1239 err = -EIO;
1240 goto error;
1241 }
1242
1243 spin_lock(&fc->lock);
1244 fuse_change_attributes_common(inode, &outarg.attr,
1245 attr_timeout(&outarg));
1246 oldsize = inode->i_size;
1247 i_size_write(inode, outarg.attr.size);
1248
1249 if (is_truncate) {
1250 /* NOTE: this may release/reacquire fc->lock */
1251 __fuse_release_nowrite(inode);
1252 }
1253 spin_unlock(&fc->lock);
1254
1255 /*
1256 * Only call invalidate_inode_pages2() after removing
1257 * FUSE_NOWRITE, otherwise fuse_launder_page() would deadlock.
1258 */
1259 if (S_ISREG(inode->i_mode) && oldsize != outarg.attr.size) {
1260 if (outarg.attr.size < oldsize)
1261 fuse_truncate(inode->i_mapping, outarg.attr.size);
1262 invalidate_inode_pages2(inode->i_mapping);
1190 } 1263 }
1191 1264
1192 fuse_change_attributes(inode, &outarg.attr, attr_timeout(&outarg), 0);
1193 return 0; 1265 return 0;
1266
1267error:
1268 if (is_truncate)
1269 fuse_release_nowrite(inode);
1270
1271 return err;
1194} 1272}
1195 1273
1196static int fuse_setattr(struct dentry *entry, struct iattr *attr) 1274static int fuse_setattr(struct dentry *entry, struct iattr *attr)
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 676b0bc8a86d..f28cf8b46f80 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -210,6 +210,49 @@ u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id)
210 return (u64) v0 + ((u64) v1 << 32); 210 return (u64) v0 + ((u64) v1 << 32);
211} 211}
212 212
213/*
214 * Check if page is under writeback
215 *
216 * This is currently done by walking the list of writepage requests
217 * for the inode, which can be pretty inefficient.
218 */
219static bool fuse_page_is_writeback(struct inode *inode, pgoff_t index)
220{
221 struct fuse_conn *fc = get_fuse_conn(inode);
222 struct fuse_inode *fi = get_fuse_inode(inode);
223 struct fuse_req *req;
224 bool found = false;
225
226 spin_lock(&fc->lock);
227 list_for_each_entry(req, &fi->writepages, writepages_entry) {
228 pgoff_t curr_index;
229
230 BUG_ON(req->inode != inode);
231 curr_index = req->misc.write.in.offset >> PAGE_CACHE_SHIFT;
232 if (curr_index == index) {
233 found = true;
234 break;
235 }
236 }
237 spin_unlock(&fc->lock);
238
239 return found;
240}
241
242/*
243 * Wait for page writeback to be completed.
244 *
245 * Since fuse doesn't rely on the VM writeback tracking, this has to
246 * use some other means.
247 */
248static int fuse_wait_on_page_writeback(struct inode *inode, pgoff_t index)
249{
250 struct fuse_inode *fi = get_fuse_inode(inode);
251
252 wait_event(fi->page_waitq, !fuse_page_is_writeback(inode, index));
253 return 0;
254}
255
213static int fuse_flush(struct file *file, fl_owner_t id) 256static int fuse_flush(struct file *file, fl_owner_t id)
214{ 257{
215 struct inode *inode = file->f_path.dentry->d_inode; 258 struct inode *inode = file->f_path.dentry->d_inode;
@@ -245,6 +288,21 @@ static int fuse_flush(struct file *file, fl_owner_t id)
245 return err; 288 return err;
246} 289}
247 290
291/*
292 * Wait for all pending writepages on the inode to finish.
293 *
294 * This is currently done by blocking further writes with FUSE_NOWRITE
295 * and waiting for all sent writes to complete.
296 *
297 * This must be called under i_mutex, otherwise the FUSE_NOWRITE usage
298 * could conflict with truncation.
299 */
300static void fuse_sync_writes(struct inode *inode)
301{
302 fuse_set_nowrite(inode);
303 fuse_release_nowrite(inode);
304}
305
248int fuse_fsync_common(struct file *file, struct dentry *de, int datasync, 306int fuse_fsync_common(struct file *file, struct dentry *de, int datasync,
249 int isdir) 307 int isdir)
250{ 308{
@@ -261,6 +319,17 @@ int fuse_fsync_common(struct file *file, struct dentry *de, int datasync,
261 if ((!isdir && fc->no_fsync) || (isdir && fc->no_fsyncdir)) 319 if ((!isdir && fc->no_fsync) || (isdir && fc->no_fsyncdir))
262 return 0; 320 return 0;
263 321
322 /*
323 * Start writeback against all dirty pages of the inode, then
324 * wait for all outstanding writes, before sending the FSYNC
325 * request.
326 */
327 err = write_inode_now(inode, 0);
328 if (err)
329 return err;
330
331 fuse_sync_writes(inode);
332
264 req = fuse_get_req(fc); 333 req = fuse_get_req(fc);
265 if (IS_ERR(req)) 334 if (IS_ERR(req))
266 return PTR_ERR(req); 335 return PTR_ERR(req);
@@ -294,7 +363,7 @@ static int fuse_fsync(struct file *file, struct dentry *de, int datasync)
294void fuse_read_fill(struct fuse_req *req, struct file *file, 363void fuse_read_fill(struct fuse_req *req, struct file *file,
295 struct inode *inode, loff_t pos, size_t count, int opcode) 364 struct inode *inode, loff_t pos, size_t count, int opcode)
296{ 365{
297 struct fuse_read_in *inarg = &req->misc.read_in; 366 struct fuse_read_in *inarg = &req->misc.read.in;
298 struct fuse_file *ff = file->private_data; 367 struct fuse_file *ff = file->private_data;
299 368
300 inarg->fh = ff->fh; 369 inarg->fh = ff->fh;
@@ -320,7 +389,7 @@ static size_t fuse_send_read(struct fuse_req *req, struct file *file,
320 389
321 fuse_read_fill(req, file, inode, pos, count, FUSE_READ); 390 fuse_read_fill(req, file, inode, pos, count, FUSE_READ);
322 if (owner != NULL) { 391 if (owner != NULL) {
323 struct fuse_read_in *inarg = &req->misc.read_in; 392 struct fuse_read_in *inarg = &req->misc.read.in;
324 393
325 inarg->read_flags |= FUSE_READ_LOCKOWNER; 394 inarg->read_flags |= FUSE_READ_LOCKOWNER;
326 inarg->lock_owner = fuse_lock_owner_id(fc, owner); 395 inarg->lock_owner = fuse_lock_owner_id(fc, owner);
@@ -329,31 +398,66 @@ static size_t fuse_send_read(struct fuse_req *req, struct file *file,
329 return req->out.args[0].size; 398 return req->out.args[0].size;
330} 399}
331 400
401static void fuse_read_update_size(struct inode *inode, loff_t size,
402 u64 attr_ver)
403{
404 struct fuse_conn *fc = get_fuse_conn(inode);
405 struct fuse_inode *fi = get_fuse_inode(inode);
406
407 spin_lock(&fc->lock);
408 if (attr_ver == fi->attr_version && size < inode->i_size) {
409 fi->attr_version = ++fc->attr_version;
410 i_size_write(inode, size);
411 }
412 spin_unlock(&fc->lock);
413}
414
332static int fuse_readpage(struct file *file, struct page *page) 415static int fuse_readpage(struct file *file, struct page *page)
333{ 416{
334 struct inode *inode = page->mapping->host; 417 struct inode *inode = page->mapping->host;
335 struct fuse_conn *fc = get_fuse_conn(inode); 418 struct fuse_conn *fc = get_fuse_conn(inode);
336 struct fuse_req *req; 419 struct fuse_req *req;
420 size_t num_read;
421 loff_t pos = page_offset(page);
422 size_t count = PAGE_CACHE_SIZE;
423 u64 attr_ver;
337 int err; 424 int err;
338 425
339 err = -EIO; 426 err = -EIO;
340 if (is_bad_inode(inode)) 427 if (is_bad_inode(inode))
341 goto out; 428 goto out;
342 429
430 /*
431 * Page writeback can extend beyond the liftime of the
432 * page-cache page, so make sure we read a properly synced
433 * page.
434 */
435 fuse_wait_on_page_writeback(inode, page->index);
436
343 req = fuse_get_req(fc); 437 req = fuse_get_req(fc);
344 err = PTR_ERR(req); 438 err = PTR_ERR(req);
345 if (IS_ERR(req)) 439 if (IS_ERR(req))
346 goto out; 440 goto out;
347 441
442 attr_ver = fuse_get_attr_version(fc);
443
348 req->out.page_zeroing = 1; 444 req->out.page_zeroing = 1;
349 req->num_pages = 1; 445 req->num_pages = 1;
350 req->pages[0] = page; 446 req->pages[0] = page;
351 fuse_send_read(req, file, inode, page_offset(page), PAGE_CACHE_SIZE, 447 num_read = fuse_send_read(req, file, inode, pos, count, NULL);
352 NULL);
353 err = req->out.h.error; 448 err = req->out.h.error;
354 fuse_put_request(fc, req); 449 fuse_put_request(fc, req);
355 if (!err) 450
451 if (!err) {
452 /*
453 * Short read means EOF. If file size is larger, truncate it
454 */
455 if (num_read < count)
456 fuse_read_update_size(inode, pos + num_read, attr_ver);
457
356 SetPageUptodate(page); 458 SetPageUptodate(page);
459 }
460
357 fuse_invalidate_attr(inode); /* atime changed */ 461 fuse_invalidate_attr(inode); /* atime changed */
358 out: 462 out:
359 unlock_page(page); 463 unlock_page(page);
@@ -363,8 +467,19 @@ static int fuse_readpage(struct file *file, struct page *page)
363static void fuse_readpages_end(struct fuse_conn *fc, struct fuse_req *req) 467static void fuse_readpages_end(struct fuse_conn *fc, struct fuse_req *req)
364{ 468{
365 int i; 469 int i;
470 size_t count = req->misc.read.in.size;
471 size_t num_read = req->out.args[0].size;
472 struct inode *inode = req->pages[0]->mapping->host;
473
474 /*
475 * Short read means EOF. If file size is larger, truncate it
476 */
477 if (!req->out.h.error && num_read < count) {
478 loff_t pos = page_offset(req->pages[0]) + num_read;
479 fuse_read_update_size(inode, pos, req->misc.read.attr_ver);
480 }
366 481
367 fuse_invalidate_attr(req->pages[0]->mapping->host); /* atime changed */ 482 fuse_invalidate_attr(inode); /* atime changed */
368 483
369 for (i = 0; i < req->num_pages; i++) { 484 for (i = 0; i < req->num_pages; i++) {
370 struct page *page = req->pages[i]; 485 struct page *page = req->pages[i];
@@ -387,6 +502,7 @@ static void fuse_send_readpages(struct fuse_req *req, struct file *file,
387 size_t count = req->num_pages << PAGE_CACHE_SHIFT; 502 size_t count = req->num_pages << PAGE_CACHE_SHIFT;
388 req->out.page_zeroing = 1; 503 req->out.page_zeroing = 1;
389 fuse_read_fill(req, file, inode, pos, count, FUSE_READ); 504 fuse_read_fill(req, file, inode, pos, count, FUSE_READ);
505 req->misc.read.attr_ver = fuse_get_attr_version(fc);
390 if (fc->async_read) { 506 if (fc->async_read) {
391 struct fuse_file *ff = file->private_data; 507 struct fuse_file *ff = file->private_data;
392 req->ff = fuse_file_get(ff); 508 req->ff = fuse_file_get(ff);
@@ -411,6 +527,8 @@ static int fuse_readpages_fill(void *_data, struct page *page)
411 struct inode *inode = data->inode; 527 struct inode *inode = data->inode;
412 struct fuse_conn *fc = get_fuse_conn(inode); 528 struct fuse_conn *fc = get_fuse_conn(inode);
413 529
530 fuse_wait_on_page_writeback(inode, page->index);
531
414 if (req->num_pages && 532 if (req->num_pages &&
415 (req->num_pages == FUSE_MAX_PAGES_PER_REQ || 533 (req->num_pages == FUSE_MAX_PAGES_PER_REQ ||
416 (req->num_pages + 1) * PAGE_CACHE_SIZE > fc->max_read || 534 (req->num_pages + 1) * PAGE_CACHE_SIZE > fc->max_read ||
@@ -477,11 +595,10 @@ static ssize_t fuse_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
477} 595}
478 596
479static void fuse_write_fill(struct fuse_req *req, struct file *file, 597static void fuse_write_fill(struct fuse_req *req, struct file *file,
480 struct inode *inode, loff_t pos, size_t count, 598 struct fuse_file *ff, struct inode *inode,
481 int writepage) 599 loff_t pos, size_t count, int writepage)
482{ 600{
483 struct fuse_conn *fc = get_fuse_conn(inode); 601 struct fuse_conn *fc = get_fuse_conn(inode);
484 struct fuse_file *ff = file->private_data;
485 struct fuse_write_in *inarg = &req->misc.write.in; 602 struct fuse_write_in *inarg = &req->misc.write.in;
486 struct fuse_write_out *outarg = &req->misc.write.out; 603 struct fuse_write_out *outarg = &req->misc.write.out;
487 604
@@ -490,7 +607,7 @@ static void fuse_write_fill(struct fuse_req *req, struct file *file,
490 inarg->offset = pos; 607 inarg->offset = pos;
491 inarg->size = count; 608 inarg->size = count;
492 inarg->write_flags = writepage ? FUSE_WRITE_CACHE : 0; 609 inarg->write_flags = writepage ? FUSE_WRITE_CACHE : 0;
493 inarg->flags = file->f_flags; 610 inarg->flags = file ? file->f_flags : 0;
494 req->in.h.opcode = FUSE_WRITE; 611 req->in.h.opcode = FUSE_WRITE;
495 req->in.h.nodeid = get_node_id(inode); 612 req->in.h.nodeid = get_node_id(inode);
496 req->in.argpages = 1; 613 req->in.argpages = 1;
@@ -511,7 +628,7 @@ static size_t fuse_send_write(struct fuse_req *req, struct file *file,
511 fl_owner_t owner) 628 fl_owner_t owner)
512{ 629{
513 struct fuse_conn *fc = get_fuse_conn(inode); 630 struct fuse_conn *fc = get_fuse_conn(inode);
514 fuse_write_fill(req, file, inode, pos, count, 0); 631 fuse_write_fill(req, file, file->private_data, inode, pos, count, 0);
515 if (owner != NULL) { 632 if (owner != NULL) {
516 struct fuse_write_in *inarg = &req->misc.write.in; 633 struct fuse_write_in *inarg = &req->misc.write.in;
517 inarg->write_flags |= FUSE_WRITE_LOCKOWNER; 634 inarg->write_flags |= FUSE_WRITE_LOCKOWNER;
@@ -533,19 +650,36 @@ static int fuse_write_begin(struct file *file, struct address_space *mapping,
533 return 0; 650 return 0;
534} 651}
535 652
653static void fuse_write_update_size(struct inode *inode, loff_t pos)
654{
655 struct fuse_conn *fc = get_fuse_conn(inode);
656 struct fuse_inode *fi = get_fuse_inode(inode);
657
658 spin_lock(&fc->lock);
659 fi->attr_version = ++fc->attr_version;
660 if (pos > inode->i_size)
661 i_size_write(inode, pos);
662 spin_unlock(&fc->lock);
663}
664
536static int fuse_buffered_write(struct file *file, struct inode *inode, 665static int fuse_buffered_write(struct file *file, struct inode *inode,
537 loff_t pos, unsigned count, struct page *page) 666 loff_t pos, unsigned count, struct page *page)
538{ 667{
539 int err; 668 int err;
540 size_t nres; 669 size_t nres;
541 struct fuse_conn *fc = get_fuse_conn(inode); 670 struct fuse_conn *fc = get_fuse_conn(inode);
542 struct fuse_inode *fi = get_fuse_inode(inode);
543 unsigned offset = pos & (PAGE_CACHE_SIZE - 1); 671 unsigned offset = pos & (PAGE_CACHE_SIZE - 1);
544 struct fuse_req *req; 672 struct fuse_req *req;
545 673
546 if (is_bad_inode(inode)) 674 if (is_bad_inode(inode))
547 return -EIO; 675 return -EIO;
548 676
677 /*
678 * Make sure writepages on the same page are not mixed up with
679 * plain writes.
680 */
681 fuse_wait_on_page_writeback(inode, page->index);
682
549 req = fuse_get_req(fc); 683 req = fuse_get_req(fc);
550 if (IS_ERR(req)) 684 if (IS_ERR(req))
551 return PTR_ERR(req); 685 return PTR_ERR(req);
@@ -560,12 +694,7 @@ static int fuse_buffered_write(struct file *file, struct inode *inode,
560 err = -EIO; 694 err = -EIO;
561 if (!err) { 695 if (!err) {
562 pos += nres; 696 pos += nres;
563 spin_lock(&fc->lock); 697 fuse_write_update_size(inode, pos);
564 fi->attr_version = ++fc->attr_version;
565 if (pos > inode->i_size)
566 i_size_write(inode, pos);
567 spin_unlock(&fc->lock);
568
569 if (count == PAGE_CACHE_SIZE) 698 if (count == PAGE_CACHE_SIZE)
570 SetPageUptodate(page); 699 SetPageUptodate(page);
571 } 700 }
@@ -588,6 +717,198 @@ static int fuse_write_end(struct file *file, struct address_space *mapping,
588 return res; 717 return res;
589} 718}
590 719
720static size_t fuse_send_write_pages(struct fuse_req *req, struct file *file,
721 struct inode *inode, loff_t pos,
722 size_t count)
723{
724 size_t res;
725 unsigned offset;
726 unsigned i;
727
728 for (i = 0; i < req->num_pages; i++)
729 fuse_wait_on_page_writeback(inode, req->pages[i]->index);
730
731 res = fuse_send_write(req, file, inode, pos, count, NULL);
732
733 offset = req->page_offset;
734 count = res;
735 for (i = 0; i < req->num_pages; i++) {
736 struct page *page = req->pages[i];
737
738 if (!req->out.h.error && !offset && count >= PAGE_CACHE_SIZE)
739 SetPageUptodate(page);
740
741 if (count > PAGE_CACHE_SIZE - offset)
742 count -= PAGE_CACHE_SIZE - offset;
743 else
744 count = 0;
745 offset = 0;
746
747 unlock_page(page);
748 page_cache_release(page);
749 }
750
751 return res;
752}
753
754static ssize_t fuse_fill_write_pages(struct fuse_req *req,
755 struct address_space *mapping,
756 struct iov_iter *ii, loff_t pos)
757{
758 struct fuse_conn *fc = get_fuse_conn(mapping->host);
759 unsigned offset = pos & (PAGE_CACHE_SIZE - 1);
760 size_t count = 0;
761 int err;
762
763 req->page_offset = offset;
764
765 do {
766 size_t tmp;
767 struct page *page;
768 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
769 size_t bytes = min_t(size_t, PAGE_CACHE_SIZE - offset,
770 iov_iter_count(ii));
771
772 bytes = min_t(size_t, bytes, fc->max_write - count);
773
774 again:
775 err = -EFAULT;
776 if (iov_iter_fault_in_readable(ii, bytes))
777 break;
778
779 err = -ENOMEM;
780 page = __grab_cache_page(mapping, index);
781 if (!page)
782 break;
783
784 pagefault_disable();
785 tmp = iov_iter_copy_from_user_atomic(page, ii, offset, bytes);
786 pagefault_enable();
787 flush_dcache_page(page);
788
789 if (!tmp) {
790 unlock_page(page);
791 page_cache_release(page);
792 bytes = min(bytes, iov_iter_single_seg_count(ii));
793 goto again;
794 }
795
796 err = 0;
797 req->pages[req->num_pages] = page;
798 req->num_pages++;
799
800 iov_iter_advance(ii, tmp);
801 count += tmp;
802 pos += tmp;
803 offset += tmp;
804 if (offset == PAGE_CACHE_SIZE)
805 offset = 0;
806
807 } while (iov_iter_count(ii) && count < fc->max_write &&
808 req->num_pages < FUSE_MAX_PAGES_PER_REQ && offset == 0);
809
810 return count > 0 ? count : err;
811}
812
813static ssize_t fuse_perform_write(struct file *file,
814 struct address_space *mapping,
815 struct iov_iter *ii, loff_t pos)
816{
817 struct inode *inode = mapping->host;
818 struct fuse_conn *fc = get_fuse_conn(inode);
819 int err = 0;
820 ssize_t res = 0;
821
822 if (is_bad_inode(inode))
823 return -EIO;
824
825 do {
826 struct fuse_req *req;
827 ssize_t count;
828
829 req = fuse_get_req(fc);
830 if (IS_ERR(req)) {
831 err = PTR_ERR(req);
832 break;
833 }
834
835 count = fuse_fill_write_pages(req, mapping, ii, pos);
836 if (count <= 0) {
837 err = count;
838 } else {
839 size_t num_written;
840
841 num_written = fuse_send_write_pages(req, file, inode,
842 pos, count);
843 err = req->out.h.error;
844 if (!err) {
845 res += num_written;
846 pos += num_written;
847
848 /* break out of the loop on short write */
849 if (num_written != count)
850 err = -EIO;
851 }
852 }
853 fuse_put_request(fc, req);
854 } while (!err && iov_iter_count(ii));
855
856 if (res > 0)
857 fuse_write_update_size(inode, pos);
858
859 fuse_invalidate_attr(inode);
860
861 return res > 0 ? res : err;
862}
863
864static ssize_t fuse_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
865 unsigned long nr_segs, loff_t pos)
866{
867 struct file *file = iocb->ki_filp;
868 struct address_space *mapping = file->f_mapping;
869 size_t count = 0;
870 ssize_t written = 0;
871 struct inode *inode = mapping->host;
872 ssize_t err;
873 struct iov_iter i;
874
875 WARN_ON(iocb->ki_pos != pos);
876
877 err = generic_segment_checks(iov, &nr_segs, &count, VERIFY_READ);
878 if (err)
879 return err;
880
881 mutex_lock(&inode->i_mutex);
882 vfs_check_frozen(inode->i_sb, SB_FREEZE_WRITE);
883
884 /* We can write back this queue in page reclaim */
885 current->backing_dev_info = mapping->backing_dev_info;
886
887 err = generic_write_checks(file, &pos, &count, S_ISBLK(inode->i_mode));
888 if (err)
889 goto out;
890
891 if (count == 0)
892 goto out;
893
894 err = remove_suid(file->f_path.dentry);
895 if (err)
896 goto out;
897
898 file_update_time(file);
899
900 iov_iter_init(&i, iov, nr_segs, count, 0);
901 written = fuse_perform_write(file, mapping, &i, pos);
902 if (written >= 0)
903 iocb->ki_pos = pos + written;
904
905out:
906 current->backing_dev_info = NULL;
907 mutex_unlock(&inode->i_mutex);
908
909 return written ? written : err;
910}
911
591static void fuse_release_user_pages(struct fuse_req *req, int write) 912static void fuse_release_user_pages(struct fuse_req *req, int write)
592{ 913{
593 unsigned i; 914 unsigned i;
@@ -613,7 +934,7 @@ static int fuse_get_user_pages(struct fuse_req *req, const char __user *buf,
613 934
614 nbytes = min(nbytes, (unsigned) FUSE_MAX_PAGES_PER_REQ << PAGE_SHIFT); 935 nbytes = min(nbytes, (unsigned) FUSE_MAX_PAGES_PER_REQ << PAGE_SHIFT);
615 npages = (nbytes + offset + PAGE_SIZE - 1) >> PAGE_SHIFT; 936 npages = (nbytes + offset + PAGE_SIZE - 1) >> PAGE_SHIFT;
616 npages = min(max(npages, 1), FUSE_MAX_PAGES_PER_REQ); 937 npages = clamp(npages, 1, FUSE_MAX_PAGES_PER_REQ);
617 down_read(&current->mm->mmap_sem); 938 down_read(&current->mm->mmap_sem);
618 npages = get_user_pages(current, current->mm, user_addr, npages, write, 939 npages = get_user_pages(current, current->mm, user_addr, npages, write,
619 0, req->pages, NULL); 940 0, req->pages, NULL);
@@ -645,14 +966,15 @@ static ssize_t fuse_direct_io(struct file *file, const char __user *buf,
645 966
646 while (count) { 967 while (count) {
647 size_t nres; 968 size_t nres;
648 size_t nbytes = min(count, nmax); 969 size_t nbytes_limit = min(count, nmax);
649 int err = fuse_get_user_pages(req, buf, nbytes, !write); 970 size_t nbytes;
971 int err = fuse_get_user_pages(req, buf, nbytes_limit, !write);
650 if (err) { 972 if (err) {
651 res = err; 973 res = err;
652 break; 974 break;
653 } 975 }
654 nbytes = (req->num_pages << PAGE_SHIFT) - req->page_offset; 976 nbytes = (req->num_pages << PAGE_SHIFT) - req->page_offset;
655 nbytes = min(count, nbytes); 977 nbytes = min(nbytes_limit, nbytes);
656 if (write) 978 if (write)
657 nres = fuse_send_write(req, file, inode, pos, nbytes, 979 nres = fuse_send_write(req, file, inode, pos, nbytes,
658 current->files); 980 current->files);
@@ -683,12 +1005,8 @@ static ssize_t fuse_direct_io(struct file *file, const char __user *buf,
683 } 1005 }
684 fuse_put_request(fc, req); 1006 fuse_put_request(fc, req);
685 if (res > 0) { 1007 if (res > 0) {
686 if (write) { 1008 if (write)
687 spin_lock(&fc->lock); 1009 fuse_write_update_size(inode, pos);
688 if (pos > inode->i_size)
689 i_size_write(inode, pos);
690 spin_unlock(&fc->lock);
691 }
692 *ppos = pos; 1010 *ppos = pos;
693 } 1011 }
694 fuse_invalidate_attr(inode); 1012 fuse_invalidate_attr(inode);
@@ -716,21 +1034,225 @@ static ssize_t fuse_direct_write(struct file *file, const char __user *buf,
716 return res; 1034 return res;
717} 1035}
718 1036
719static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma) 1037static void fuse_writepage_free(struct fuse_conn *fc, struct fuse_req *req)
720{ 1038{
721 if ((vma->vm_flags & VM_SHARED)) { 1039 __free_page(req->pages[0]);
722 if ((vma->vm_flags & VM_WRITE)) 1040 fuse_file_put(req->ff);
723 return -ENODEV; 1041 fuse_put_request(fc, req);
724 else 1042}
725 vma->vm_flags &= ~VM_MAYWRITE; 1043
1044static void fuse_writepage_finish(struct fuse_conn *fc, struct fuse_req *req)
1045{
1046 struct inode *inode = req->inode;
1047 struct fuse_inode *fi = get_fuse_inode(inode);
1048 struct backing_dev_info *bdi = inode->i_mapping->backing_dev_info;
1049
1050 list_del(&req->writepages_entry);
1051 dec_bdi_stat(bdi, BDI_WRITEBACK);
1052 dec_zone_page_state(req->pages[0], NR_WRITEBACK_TEMP);
1053 bdi_writeout_inc(bdi);
1054 wake_up(&fi->page_waitq);
1055}
1056
1057/* Called under fc->lock, may release and reacquire it */
1058static void fuse_send_writepage(struct fuse_conn *fc, struct fuse_req *req)
1059{
1060 struct fuse_inode *fi = get_fuse_inode(req->inode);
1061 loff_t size = i_size_read(req->inode);
1062 struct fuse_write_in *inarg = &req->misc.write.in;
1063
1064 if (!fc->connected)
1065 goto out_free;
1066
1067 if (inarg->offset + PAGE_CACHE_SIZE <= size) {
1068 inarg->size = PAGE_CACHE_SIZE;
1069 } else if (inarg->offset < size) {
1070 inarg->size = size & (PAGE_CACHE_SIZE - 1);
1071 } else {
1072 /* Got truncated off completely */
1073 goto out_free;
1074 }
1075
1076 req->in.args[1].size = inarg->size;
1077 fi->writectr++;
1078 request_send_background_locked(fc, req);
1079 return;
1080
1081 out_free:
1082 fuse_writepage_finish(fc, req);
1083 spin_unlock(&fc->lock);
1084 fuse_writepage_free(fc, req);
1085 spin_lock(&fc->lock);
1086}
1087
1088/*
1089 * If fi->writectr is positive (no truncate or fsync going on) send
1090 * all queued writepage requests.
1091 *
1092 * Called with fc->lock
1093 */
1094void fuse_flush_writepages(struct inode *inode)
1095{
1096 struct fuse_conn *fc = get_fuse_conn(inode);
1097 struct fuse_inode *fi = get_fuse_inode(inode);
1098 struct fuse_req *req;
1099
1100 while (fi->writectr >= 0 && !list_empty(&fi->queued_writes)) {
1101 req = list_entry(fi->queued_writes.next, struct fuse_req, list);
1102 list_del_init(&req->list);
1103 fuse_send_writepage(fc, req);
1104 }
1105}
1106
1107static void fuse_writepage_end(struct fuse_conn *fc, struct fuse_req *req)
1108{
1109 struct inode *inode = req->inode;
1110 struct fuse_inode *fi = get_fuse_inode(inode);
1111
1112 mapping_set_error(inode->i_mapping, req->out.h.error);
1113 spin_lock(&fc->lock);
1114 fi->writectr--;
1115 fuse_writepage_finish(fc, req);
1116 spin_unlock(&fc->lock);
1117 fuse_writepage_free(fc, req);
1118}
1119
1120static int fuse_writepage_locked(struct page *page)
1121{
1122 struct address_space *mapping = page->mapping;
1123 struct inode *inode = mapping->host;
1124 struct fuse_conn *fc = get_fuse_conn(inode);
1125 struct fuse_inode *fi = get_fuse_inode(inode);
1126 struct fuse_req *req;
1127 struct fuse_file *ff;
1128 struct page *tmp_page;
1129
1130 set_page_writeback(page);
1131
1132 req = fuse_request_alloc_nofs();
1133 if (!req)
1134 goto err;
1135
1136 tmp_page = alloc_page(GFP_NOFS | __GFP_HIGHMEM);
1137 if (!tmp_page)
1138 goto err_free;
1139
1140 spin_lock(&fc->lock);
1141 BUG_ON(list_empty(&fi->write_files));
1142 ff = list_entry(fi->write_files.next, struct fuse_file, write_entry);
1143 req->ff = fuse_file_get(ff);
1144 spin_unlock(&fc->lock);
1145
1146 fuse_write_fill(req, NULL, ff, inode, page_offset(page), 0, 1);
1147
1148 copy_highpage(tmp_page, page);
1149 req->num_pages = 1;
1150 req->pages[0] = tmp_page;
1151 req->page_offset = 0;
1152 req->end = fuse_writepage_end;
1153 req->inode = inode;
1154
1155 inc_bdi_stat(mapping->backing_dev_info, BDI_WRITEBACK);
1156 inc_zone_page_state(tmp_page, NR_WRITEBACK_TEMP);
1157 end_page_writeback(page);
1158
1159 spin_lock(&fc->lock);
1160 list_add(&req->writepages_entry, &fi->writepages);
1161 list_add_tail(&req->list, &fi->queued_writes);
1162 fuse_flush_writepages(inode);
1163 spin_unlock(&fc->lock);
1164
1165 return 0;
1166
1167err_free:
1168 fuse_request_free(req);
1169err:
1170 end_page_writeback(page);
1171 return -ENOMEM;
1172}
1173
1174static int fuse_writepage(struct page *page, struct writeback_control *wbc)
1175{
1176 int err;
1177
1178 err = fuse_writepage_locked(page);
1179 unlock_page(page);
1180
1181 return err;
1182}
1183
1184static int fuse_launder_page(struct page *page)
1185{
1186 int err = 0;
1187 if (clear_page_dirty_for_io(page)) {
1188 struct inode *inode = page->mapping->host;
1189 err = fuse_writepage_locked(page);
1190 if (!err)
1191 fuse_wait_on_page_writeback(inode, page->index);
726 } 1192 }
727 return generic_file_mmap(file, vma); 1193 return err;
728} 1194}
729 1195
730static int fuse_set_page_dirty(struct page *page) 1196/*
1197 * Write back dirty pages now, because there may not be any suitable
1198 * open files later
1199 */
1200static void fuse_vma_close(struct vm_area_struct *vma)
731{ 1201{
732 printk("fuse_set_page_dirty: should not happen\n"); 1202 filemap_write_and_wait(vma->vm_file->f_mapping);
733 dump_stack(); 1203}
1204
1205/*
1206 * Wait for writeback against this page to complete before allowing it
1207 * to be marked dirty again, and hence written back again, possibly
1208 * before the previous writepage completed.
1209 *
1210 * Block here, instead of in ->writepage(), so that the userspace fs
1211 * can only block processes actually operating on the filesystem.
1212 *
1213 * Otherwise unprivileged userspace fs would be able to block
1214 * unrelated:
1215 *
1216 * - page migration
1217 * - sync(2)
1218 * - try_to_free_pages() with order > PAGE_ALLOC_COSTLY_ORDER
1219 */
1220static int fuse_page_mkwrite(struct vm_area_struct *vma, struct page *page)
1221{
1222 /*
1223 * Don't use page->mapping as it may become NULL from a
1224 * concurrent truncate.
1225 */
1226 struct inode *inode = vma->vm_file->f_mapping->host;
1227
1228 fuse_wait_on_page_writeback(inode, page->index);
1229 return 0;
1230}
1231
1232static struct vm_operations_struct fuse_file_vm_ops = {
1233 .close = fuse_vma_close,
1234 .fault = filemap_fault,
1235 .page_mkwrite = fuse_page_mkwrite,
1236};
1237
1238static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma)
1239{
1240 if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE)) {
1241 struct inode *inode = file->f_dentry->d_inode;
1242 struct fuse_conn *fc = get_fuse_conn(inode);
1243 struct fuse_inode *fi = get_fuse_inode(inode);
1244 struct fuse_file *ff = file->private_data;
1245 /*
1246 * file may be written through mmap, so chain it onto the
1247 * inodes's write_file list
1248 */
1249 spin_lock(&fc->lock);
1250 if (list_empty(&ff->write_entry))
1251 list_add(&ff->write_entry, &fi->write_files);
1252 spin_unlock(&fc->lock);
1253 }
1254 file_accessed(file);
1255 vma->vm_ops = &fuse_file_vm_ops;
734 return 0; 1256 return 0;
735} 1257}
736 1258
@@ -909,12 +1431,37 @@ static sector_t fuse_bmap(struct address_space *mapping, sector_t block)
909 return err ? 0 : outarg.block; 1431 return err ? 0 : outarg.block;
910} 1432}
911 1433
1434static loff_t fuse_file_llseek(struct file *file, loff_t offset, int origin)
1435{
1436 loff_t retval;
1437 struct inode *inode = file->f_path.dentry->d_inode;
1438
1439 mutex_lock(&inode->i_mutex);
1440 switch (origin) {
1441 case SEEK_END:
1442 offset += i_size_read(inode);
1443 break;
1444 case SEEK_CUR:
1445 offset += file->f_pos;
1446 }
1447 retval = -EINVAL;
1448 if (offset >= 0 && offset <= inode->i_sb->s_maxbytes) {
1449 if (offset != file->f_pos) {
1450 file->f_pos = offset;
1451 file->f_version = 0;
1452 }
1453 retval = offset;
1454 }
1455 mutex_unlock(&inode->i_mutex);
1456 return retval;
1457}
1458
912static const struct file_operations fuse_file_operations = { 1459static const struct file_operations fuse_file_operations = {
913 .llseek = generic_file_llseek, 1460 .llseek = fuse_file_llseek,
914 .read = do_sync_read, 1461 .read = do_sync_read,
915 .aio_read = fuse_file_aio_read, 1462 .aio_read = fuse_file_aio_read,
916 .write = do_sync_write, 1463 .write = do_sync_write,
917 .aio_write = generic_file_aio_write, 1464 .aio_write = fuse_file_aio_write,
918 .mmap = fuse_file_mmap, 1465 .mmap = fuse_file_mmap,
919 .open = fuse_open, 1466 .open = fuse_open,
920 .flush = fuse_flush, 1467 .flush = fuse_flush,
@@ -926,7 +1473,7 @@ static const struct file_operations fuse_file_operations = {
926}; 1473};
927 1474
928static const struct file_operations fuse_direct_io_file_operations = { 1475static const struct file_operations fuse_direct_io_file_operations = {
929 .llseek = generic_file_llseek, 1476 .llseek = fuse_file_llseek,
930 .read = fuse_direct_read, 1477 .read = fuse_direct_read,
931 .write = fuse_direct_write, 1478 .write = fuse_direct_write,
932 .open = fuse_open, 1479 .open = fuse_open,
@@ -940,10 +1487,12 @@ static const struct file_operations fuse_direct_io_file_operations = {
940 1487
941static const struct address_space_operations fuse_file_aops = { 1488static const struct address_space_operations fuse_file_aops = {
942 .readpage = fuse_readpage, 1489 .readpage = fuse_readpage,
1490 .writepage = fuse_writepage,
1491 .launder_page = fuse_launder_page,
943 .write_begin = fuse_write_begin, 1492 .write_begin = fuse_write_begin,
944 .write_end = fuse_write_end, 1493 .write_end = fuse_write_end,
945 .readpages = fuse_readpages, 1494 .readpages = fuse_readpages,
946 .set_page_dirty = fuse_set_page_dirty, 1495 .set_page_dirty = __set_page_dirty_nobuffers,
947 .bmap = fuse_bmap, 1496 .bmap = fuse_bmap,
948}; 1497};
949 1498
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 67aaf6ee38ea..dadffa21a206 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -15,6 +15,7 @@
15#include <linux/mm.h> 15#include <linux/mm.h>
16#include <linux/backing-dev.h> 16#include <linux/backing-dev.h>
17#include <linux/mutex.h> 17#include <linux/mutex.h>
18#include <linux/rwsem.h>
18 19
19/** Max number of pages that can be used in a single read request */ 20/** Max number of pages that can be used in a single read request */
20#define FUSE_MAX_PAGES_PER_REQ 32 21#define FUSE_MAX_PAGES_PER_REQ 32
@@ -25,6 +26,9 @@
25/** Congestion starts at 75% of maximum */ 26/** Congestion starts at 75% of maximum */
26#define FUSE_CONGESTION_THRESHOLD (FUSE_MAX_BACKGROUND * 75 / 100) 27#define FUSE_CONGESTION_THRESHOLD (FUSE_MAX_BACKGROUND * 75 / 100)
27 28
29/** Bias for fi->writectr, meaning new writepages must not be sent */
30#define FUSE_NOWRITE INT_MIN
31
28/** It could be as large as PATH_MAX, but would that have any uses? */ 32/** It could be as large as PATH_MAX, but would that have any uses? */
29#define FUSE_NAME_MAX 1024 33#define FUSE_NAME_MAX 1024
30 34
@@ -73,6 +77,19 @@ struct fuse_inode {
73 77
74 /** Files usable in writepage. Protected by fc->lock */ 78 /** Files usable in writepage. Protected by fc->lock */
75 struct list_head write_files; 79 struct list_head write_files;
80
81 /** Writepages pending on truncate or fsync */
82 struct list_head queued_writes;
83
84 /** Number of sent writes, a negative bias (FUSE_NOWRITE)
85 * means more writes are blocked */
86 int writectr;
87
88 /** Waitq for writepage completion */
89 wait_queue_head_t page_waitq;
90
91 /** List of writepage requestst (pending or sent) */
92 struct list_head writepages;
76}; 93};
77 94
78/** FUSE specific file data */ 95/** FUSE specific file data */
@@ -222,7 +239,10 @@ struct fuse_req {
222 } release; 239 } release;
223 struct fuse_init_in init_in; 240 struct fuse_init_in init_in;
224 struct fuse_init_out init_out; 241 struct fuse_init_out init_out;
225 struct fuse_read_in read_in; 242 struct {
243 struct fuse_read_in in;
244 u64 attr_ver;
245 } read;
226 struct { 246 struct {
227 struct fuse_write_in in; 247 struct fuse_write_in in;
228 struct fuse_write_out out; 248 struct fuse_write_out out;
@@ -242,6 +262,12 @@ struct fuse_req {
242 /** File used in the request (or NULL) */ 262 /** File used in the request (or NULL) */
243 struct fuse_file *ff; 263 struct fuse_file *ff;
244 264
265 /** Inode used in the request or NULL */
266 struct inode *inode;
267
268 /** Link on fi->writepages */
269 struct list_head writepages_entry;
270
245 /** Request completion callback */ 271 /** Request completion callback */
246 void (*end)(struct fuse_conn *, struct fuse_req *); 272 void (*end)(struct fuse_conn *, struct fuse_req *);
247 273
@@ -390,8 +416,8 @@ struct fuse_conn {
390 /** Entry on the fuse_conn_list */ 416 /** Entry on the fuse_conn_list */
391 struct list_head entry; 417 struct list_head entry;
392 418
393 /** Unique ID */ 419 /** Device ID from super block */
394 u64 id; 420 dev_t dev;
395 421
396 /** Dentries in the control filesystem */ 422 /** Dentries in the control filesystem */
397 struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES]; 423 struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
@@ -438,7 +464,7 @@ extern const struct file_operations fuse_dev_operations;
438/** 464/**
439 * Get a filled in inode 465 * Get a filled in inode
440 */ 466 */
441struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid, 467struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
442 int generation, struct fuse_attr *attr, 468 int generation, struct fuse_attr *attr,
443 u64 attr_valid, u64 attr_version); 469 u64 attr_valid, u64 attr_version);
444 470
@@ -446,7 +472,7 @@ struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid,
446 * Send FORGET command 472 * Send FORGET command
447 */ 473 */
448void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req, 474void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req,
449 unsigned long nodeid, u64 nlookup); 475 u64 nodeid, u64 nlookup);
450 476
451/** 477/**
452 * Initialize READ or READDIR request 478 * Initialize READ or READDIR request
@@ -504,6 +530,11 @@ void fuse_init_symlink(struct inode *inode);
504void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, 530void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
505 u64 attr_valid, u64 attr_version); 531 u64 attr_valid, u64 attr_version);
506 532
533void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
534 u64 attr_valid);
535
536void fuse_truncate(struct address_space *mapping, loff_t offset);
537
507/** 538/**
508 * Initialize the client device 539 * Initialize the client device
509 */ 540 */
@@ -522,6 +553,8 @@ void fuse_ctl_cleanup(void);
522 */ 553 */
523struct fuse_req *fuse_request_alloc(void); 554struct fuse_req *fuse_request_alloc(void);
524 555
556struct fuse_req *fuse_request_alloc_nofs(void);
557
525/** 558/**
526 * Free a request 559 * Free a request
527 */ 560 */
@@ -558,6 +591,8 @@ void request_send_noreply(struct fuse_conn *fc, struct fuse_req *req);
558 */ 591 */
559void request_send_background(struct fuse_conn *fc, struct fuse_req *req); 592void request_send_background(struct fuse_conn *fc, struct fuse_req *req);
560 593
594void request_send_background_locked(struct fuse_conn *fc, struct fuse_req *req);
595
561/* Abort all requests */ 596/* Abort all requests */
562void fuse_abort_conn(struct fuse_conn *fc); 597void fuse_abort_conn(struct fuse_conn *fc);
563 598
@@ -600,3 +635,10 @@ u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id);
600 635
601int fuse_update_attributes(struct inode *inode, struct kstat *stat, 636int fuse_update_attributes(struct inode *inode, struct kstat *stat,
602 struct file *file, bool *refreshed); 637 struct file *file, bool *refreshed);
638
639void fuse_flush_writepages(struct inode *inode);
640
641void fuse_set_nowrite(struct inode *inode);
642void fuse_release_nowrite(struct inode *inode);
643
644u64 fuse_get_attr_version(struct fuse_conn *fc);
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 4df34da2284a..79b615873838 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -59,7 +59,11 @@ static struct inode *fuse_alloc_inode(struct super_block *sb)
59 fi->nodeid = 0; 59 fi->nodeid = 0;
60 fi->nlookup = 0; 60 fi->nlookup = 0;
61 fi->attr_version = 0; 61 fi->attr_version = 0;
62 fi->writectr = 0;
62 INIT_LIST_HEAD(&fi->write_files); 63 INIT_LIST_HEAD(&fi->write_files);
64 INIT_LIST_HEAD(&fi->queued_writes);
65 INIT_LIST_HEAD(&fi->writepages);
66 init_waitqueue_head(&fi->page_waitq);
63 fi->forget_req = fuse_request_alloc(); 67 fi->forget_req = fuse_request_alloc();
64 if (!fi->forget_req) { 68 if (!fi->forget_req) {
65 kmem_cache_free(fuse_inode_cachep, inode); 69 kmem_cache_free(fuse_inode_cachep, inode);
@@ -73,13 +77,14 @@ static void fuse_destroy_inode(struct inode *inode)
73{ 77{
74 struct fuse_inode *fi = get_fuse_inode(inode); 78 struct fuse_inode *fi = get_fuse_inode(inode);
75 BUG_ON(!list_empty(&fi->write_files)); 79 BUG_ON(!list_empty(&fi->write_files));
80 BUG_ON(!list_empty(&fi->queued_writes));
76 if (fi->forget_req) 81 if (fi->forget_req)
77 fuse_request_free(fi->forget_req); 82 fuse_request_free(fi->forget_req);
78 kmem_cache_free(fuse_inode_cachep, inode); 83 kmem_cache_free(fuse_inode_cachep, inode);
79} 84}
80 85
81void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req, 86void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req,
82 unsigned long nodeid, u64 nlookup) 87 u64 nodeid, u64 nlookup)
83{ 88{
84 struct fuse_forget_in *inarg = &req->misc.forget_in; 89 struct fuse_forget_in *inarg = &req->misc.forget_in;
85 inarg->nlookup = nlookup; 90 inarg->nlookup = nlookup;
@@ -109,7 +114,7 @@ static int fuse_remount_fs(struct super_block *sb, int *flags, char *data)
109 return 0; 114 return 0;
110} 115}
111 116
112static void fuse_truncate(struct address_space *mapping, loff_t offset) 117void fuse_truncate(struct address_space *mapping, loff_t offset)
113{ 118{
114 /* See vmtruncate() */ 119 /* See vmtruncate() */
115 unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1); 120 unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
@@ -117,19 +122,12 @@ static void fuse_truncate(struct address_space *mapping, loff_t offset)
117 unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1); 122 unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
118} 123}
119 124
120 125void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
121void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, 126 u64 attr_valid)
122 u64 attr_valid, u64 attr_version)
123{ 127{
124 struct fuse_conn *fc = get_fuse_conn(inode); 128 struct fuse_conn *fc = get_fuse_conn(inode);
125 struct fuse_inode *fi = get_fuse_inode(inode); 129 struct fuse_inode *fi = get_fuse_inode(inode);
126 loff_t oldsize;
127 130
128 spin_lock(&fc->lock);
129 if (attr_version != 0 && fi->attr_version > attr_version) {
130 spin_unlock(&fc->lock);
131 return;
132 }
133 fi->attr_version = ++fc->attr_version; 131 fi->attr_version = ++fc->attr_version;
134 fi->i_time = attr_valid; 132 fi->i_time = attr_valid;
135 133
@@ -159,6 +157,22 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
159 fi->orig_i_mode = inode->i_mode; 157 fi->orig_i_mode = inode->i_mode;
160 if (!(fc->flags & FUSE_DEFAULT_PERMISSIONS)) 158 if (!(fc->flags & FUSE_DEFAULT_PERMISSIONS))
161 inode->i_mode &= ~S_ISVTX; 159 inode->i_mode &= ~S_ISVTX;
160}
161
162void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
163 u64 attr_valid, u64 attr_version)
164{
165 struct fuse_conn *fc = get_fuse_conn(inode);
166 struct fuse_inode *fi = get_fuse_inode(inode);
167 loff_t oldsize;
168
169 spin_lock(&fc->lock);
170 if (attr_version != 0 && fi->attr_version > attr_version) {
171 spin_unlock(&fc->lock);
172 return;
173 }
174
175 fuse_change_attributes_common(inode, attr, attr_valid);
162 176
163 oldsize = inode->i_size; 177 oldsize = inode->i_size;
164 i_size_write(inode, attr->size); 178 i_size_write(inode, attr->size);
@@ -193,7 +207,7 @@ static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr)
193 207
194static int fuse_inode_eq(struct inode *inode, void *_nodeidp) 208static int fuse_inode_eq(struct inode *inode, void *_nodeidp)
195{ 209{
196 unsigned long nodeid = *(unsigned long *) _nodeidp; 210 u64 nodeid = *(u64 *) _nodeidp;
197 if (get_node_id(inode) == nodeid) 211 if (get_node_id(inode) == nodeid)
198 return 1; 212 return 1;
199 else 213 else
@@ -202,12 +216,12 @@ static int fuse_inode_eq(struct inode *inode, void *_nodeidp)
202 216
203static int fuse_inode_set(struct inode *inode, void *_nodeidp) 217static int fuse_inode_set(struct inode *inode, void *_nodeidp)
204{ 218{
205 unsigned long nodeid = *(unsigned long *) _nodeidp; 219 u64 nodeid = *(u64 *) _nodeidp;
206 get_fuse_inode(inode)->nodeid = nodeid; 220 get_fuse_inode(inode)->nodeid = nodeid;
207 return 0; 221 return 0;
208} 222}
209 223
210struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid, 224struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
211 int generation, struct fuse_attr *attr, 225 int generation, struct fuse_attr *attr,
212 u64 attr_valid, u64 attr_version) 226 u64 attr_valid, u64 attr_version)
213{ 227{
@@ -447,7 +461,7 @@ static int fuse_show_options(struct seq_file *m, struct vfsmount *mnt)
447 return 0; 461 return 0;
448} 462}
449 463
450static struct fuse_conn *new_conn(void) 464static struct fuse_conn *new_conn(struct super_block *sb)
451{ 465{
452 struct fuse_conn *fc; 466 struct fuse_conn *fc;
453 int err; 467 int err;
@@ -468,19 +482,41 @@ static struct fuse_conn *new_conn(void)
468 atomic_set(&fc->num_waiting, 0); 482 atomic_set(&fc->num_waiting, 0);
469 fc->bdi.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE; 483 fc->bdi.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE;
470 fc->bdi.unplug_io_fn = default_unplug_io_fn; 484 fc->bdi.unplug_io_fn = default_unplug_io_fn;
485 /* fuse does it's own writeback accounting */
486 fc->bdi.capabilities = BDI_CAP_NO_ACCT_WB;
487 fc->dev = sb->s_dev;
471 err = bdi_init(&fc->bdi); 488 err = bdi_init(&fc->bdi);
472 if (err) { 489 if (err)
473 kfree(fc); 490 goto error_kfree;
474 fc = NULL; 491 err = bdi_register_dev(&fc->bdi, fc->dev);
475 goto out; 492 if (err)
476 } 493 goto error_bdi_destroy;
494 /*
495 * For a single fuse filesystem use max 1% of dirty +
496 * writeback threshold.
497 *
498 * This gives about 1M of write buffer for memory maps on a
499 * machine with 1G and 10% dirty_ratio, which should be more
500 * than enough.
501 *
502 * Privileged users can raise it by writing to
503 *
504 * /sys/class/bdi/<bdi>/max_ratio
505 */
506 bdi_set_max_ratio(&fc->bdi, 1);
477 fc->reqctr = 0; 507 fc->reqctr = 0;
478 fc->blocked = 1; 508 fc->blocked = 1;
479 fc->attr_version = 1; 509 fc->attr_version = 1;
480 get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key)); 510 get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key));
481 } 511 }
482out:
483 return fc; 512 return fc;
513
514error_bdi_destroy:
515 bdi_destroy(&fc->bdi);
516error_kfree:
517 mutex_destroy(&fc->inst_mutex);
518 kfree(fc);
519 return NULL;
484} 520}
485 521
486void fuse_conn_put(struct fuse_conn *fc) 522void fuse_conn_put(struct fuse_conn *fc)
@@ -548,6 +584,7 @@ static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req)
548 fc->bdi.ra_pages = min(fc->bdi.ra_pages, ra_pages); 584 fc->bdi.ra_pages = min(fc->bdi.ra_pages, ra_pages);
549 fc->minor = arg->minor; 585 fc->minor = arg->minor;
550 fc->max_write = arg->minor < 5 ? 4096 : arg->max_write; 586 fc->max_write = arg->minor < 5 ? 4096 : arg->max_write;
587 fc->max_write = min_t(unsigned, 4096, fc->max_write);
551 fc->conn_init = 1; 588 fc->conn_init = 1;
552 } 589 }
553 fuse_put_request(fc, req); 590 fuse_put_request(fc, req);
@@ -578,12 +615,6 @@ static void fuse_send_init(struct fuse_conn *fc, struct fuse_req *req)
578 request_send_background(fc, req); 615 request_send_background(fc, req);
579} 616}
580 617
581static u64 conn_id(void)
582{
583 static u64 ctr = 1;
584 return ctr++;
585}
586
587static int fuse_fill_super(struct super_block *sb, void *data, int silent) 618static int fuse_fill_super(struct super_block *sb, void *data, int silent)
588{ 619{
589 struct fuse_conn *fc; 620 struct fuse_conn *fc;
@@ -621,14 +652,14 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent)
621 if (file->f_op != &fuse_dev_operations) 652 if (file->f_op != &fuse_dev_operations)
622 return -EINVAL; 653 return -EINVAL;
623 654
624 fc = new_conn(); 655 fc = new_conn(sb);
625 if (!fc) 656 if (!fc)
626 return -ENOMEM; 657 return -ENOMEM;
627 658
628 fc->flags = d.flags; 659 fc->flags = d.flags;
629 fc->user_id = d.user_id; 660 fc->user_id = d.user_id;
630 fc->group_id = d.group_id; 661 fc->group_id = d.group_id;
631 fc->max_read = d.max_read; 662 fc->max_read = min_t(unsigned, 4096, d.max_read);
632 663
633 /* Used by get_root_inode() */ 664 /* Used by get_root_inode() */
634 sb->s_fs_info = fc; 665 sb->s_fs_info = fc;
@@ -659,7 +690,6 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent)
659 if (file->private_data) 690 if (file->private_data)
660 goto err_unlock; 691 goto err_unlock;
661 692
662 fc->id = conn_id();
663 err = fuse_ctl_add_conn(fc); 693 err = fuse_ctl_add_conn(fc);
664 if (err) 694 if (err)
665 goto err_unlock; 695 goto err_unlock;
diff --git a/fs/gfs2/locking/dlm/sysfs.c b/fs/gfs2/locking/dlm/sysfs.c
index 8479da47049c..a4ff271df9ee 100644
--- a/fs/gfs2/locking/dlm/sysfs.c
+++ b/fs/gfs2/locking/dlm/sysfs.c
@@ -212,7 +212,7 @@ int gdlm_sysfs_init(void)
212{ 212{
213 gdlm_kset = kset_create_and_add("lock_dlm", NULL, kernel_kobj); 213 gdlm_kset = kset_create_and_add("lock_dlm", NULL, kernel_kobj);
214 if (!gdlm_kset) { 214 if (!gdlm_kset) {
215 printk(KERN_WARNING "%s: can not create kset\n", __FUNCTION__); 215 printk(KERN_WARNING "%s: can not create kset\n", __func__);
216 return -ENOMEM; 216 return -ENOMEM;
217 } 217 }
218 return 0; 218 return 0;
diff --git a/fs/gfs2/util.h b/fs/gfs2/util.h
index 509c5d60bd80..7f48576289c9 100644
--- a/fs/gfs2/util.h
+++ b/fs/gfs2/util.h
@@ -41,7 +41,7 @@ int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion,
41 41
42#define gfs2_assert_withdraw(sdp, assertion) \ 42#define gfs2_assert_withdraw(sdp, assertion) \
43((likely(assertion)) ? 0 : gfs2_assert_withdraw_i((sdp), #assertion, \ 43((likely(assertion)) ? 0 : gfs2_assert_withdraw_i((sdp), #assertion, \
44 __FUNCTION__, __FILE__, __LINE__)) 44 __func__, __FILE__, __LINE__))
45 45
46 46
47int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion, 47int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
@@ -49,28 +49,28 @@ int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion,
49 49
50#define gfs2_assert_warn(sdp, assertion) \ 50#define gfs2_assert_warn(sdp, assertion) \
51((likely(assertion)) ? 0 : gfs2_assert_warn_i((sdp), #assertion, \ 51((likely(assertion)) ? 0 : gfs2_assert_warn_i((sdp), #assertion, \
52 __FUNCTION__, __FILE__, __LINE__)) 52 __func__, __FILE__, __LINE__))
53 53
54 54
55int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide, 55int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide,
56 const char *function, char *file, unsigned int line); 56 const char *function, char *file, unsigned int line);
57 57
58#define gfs2_consist(sdp) \ 58#define gfs2_consist(sdp) \
59gfs2_consist_i((sdp), 0, __FUNCTION__, __FILE__, __LINE__) 59gfs2_consist_i((sdp), 0, __func__, __FILE__, __LINE__)
60 60
61 61
62int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide, 62int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide,
63 const char *function, char *file, unsigned int line); 63 const char *function, char *file, unsigned int line);
64 64
65#define gfs2_consist_inode(ip) \ 65#define gfs2_consist_inode(ip) \
66gfs2_consist_inode_i((ip), 0, __FUNCTION__, __FILE__, __LINE__) 66gfs2_consist_inode_i((ip), 0, __func__, __FILE__, __LINE__)
67 67
68 68
69int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide, 69int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide,
70 const char *function, char *file, unsigned int line); 70 const char *function, char *file, unsigned int line);
71 71
72#define gfs2_consist_rgrpd(rgd) \ 72#define gfs2_consist_rgrpd(rgd) \
73gfs2_consist_rgrpd_i((rgd), 0, __FUNCTION__, __FILE__, __LINE__) 73gfs2_consist_rgrpd_i((rgd), 0, __func__, __FILE__, __LINE__)
74 74
75 75
76int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, 76int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
@@ -91,7 +91,7 @@ static inline int gfs2_meta_check_i(struct gfs2_sbd *sdp,
91} 91}
92 92
93#define gfs2_meta_check(sdp, bh) \ 93#define gfs2_meta_check(sdp, bh) \
94gfs2_meta_check_i((sdp), (bh), __FUNCTION__, __FILE__, __LINE__) 94gfs2_meta_check_i((sdp), (bh), __func__, __FILE__, __LINE__)
95 95
96 96
97int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, 97int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh,
@@ -118,7 +118,7 @@ static inline int gfs2_metatype_check_i(struct gfs2_sbd *sdp,
118} 118}
119 119
120#define gfs2_metatype_check(sdp, bh, type) \ 120#define gfs2_metatype_check(sdp, bh, type) \
121gfs2_metatype_check_i((sdp), (bh), (type), __FUNCTION__, __FILE__, __LINE__) 121gfs2_metatype_check_i((sdp), (bh), (type), __func__, __FILE__, __LINE__)
122 122
123static inline void gfs2_metatype_set(struct buffer_head *bh, u16 type, 123static inline void gfs2_metatype_set(struct buffer_head *bh, u16 type,
124 u16 format) 124 u16 format)
@@ -134,14 +134,14 @@ int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function,
134 char *file, unsigned int line); 134 char *file, unsigned int line);
135 135
136#define gfs2_io_error(sdp) \ 136#define gfs2_io_error(sdp) \
137gfs2_io_error_i((sdp), __FUNCTION__, __FILE__, __LINE__); 137gfs2_io_error_i((sdp), __func__, __FILE__, __LINE__);
138 138
139 139
140int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh, 140int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh,
141 const char *function, char *file, unsigned int line); 141 const char *function, char *file, unsigned int line);
142 142
143#define gfs2_io_error_bh(sdp, bh) \ 143#define gfs2_io_error_bh(sdp, bh) \
144gfs2_io_error_bh_i((sdp), (bh), __FUNCTION__, __FILE__, __LINE__); 144gfs2_io_error_bh_i((sdp), (bh), __func__, __FILE__, __LINE__);
145 145
146 146
147extern struct kmem_cache *gfs2_glock_cachep; 147extern struct kmem_cache *gfs2_glock_cachep;
diff --git a/fs/hfs/btree.c b/fs/hfs/btree.c
index 24cf6fc43021..f6621a785202 100644
--- a/fs/hfs/btree.c
+++ b/fs/hfs/btree.c
@@ -208,7 +208,9 @@ struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree)
208 struct hfs_bnode *node, *next_node; 208 struct hfs_bnode *node, *next_node;
209 struct page **pagep; 209 struct page **pagep;
210 u32 nidx, idx; 210 u32 nidx, idx;
211 u16 off, len; 211 unsigned off;
212 u16 off16;
213 u16 len;
212 u8 *data, byte, m; 214 u8 *data, byte, m;
213 int i; 215 int i;
214 216
@@ -235,7 +237,8 @@ struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree)
235 node = hfs_bnode_find(tree, nidx); 237 node = hfs_bnode_find(tree, nidx);
236 if (IS_ERR(node)) 238 if (IS_ERR(node))
237 return node; 239 return node;
238 len = hfs_brec_lenoff(node, 2, &off); 240 len = hfs_brec_lenoff(node, 2, &off16);
241 off = off16;
239 242
240 off += node->page_offset; 243 off += node->page_offset;
241 pagep = node->page + (off >> PAGE_CACHE_SHIFT); 244 pagep = node->page + (off >> PAGE_CACHE_SHIFT);
@@ -280,7 +283,8 @@ struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree)
280 return next_node; 283 return next_node;
281 node = next_node; 284 node = next_node;
282 285
283 len = hfs_brec_lenoff(node, 0, &off); 286 len = hfs_brec_lenoff(node, 0, &off16);
287 off = off16;
284 off += node->page_offset; 288 off += node->page_offset;
285 pagep = node->page + (off >> PAGE_CACHE_SHIFT); 289 pagep = node->page + (off >> PAGE_CACHE_SHIFT);
286 data = kmap(*pagep); 290 data = kmap(*pagep);
diff --git a/fs/hfs/mdb.c b/fs/hfs/mdb.c
index b4651e128d7f..36ca2e1a4fa3 100644
--- a/fs/hfs/mdb.c
+++ b/fs/hfs/mdb.c
@@ -215,7 +215,7 @@ int hfs_mdb_get(struct super_block *sb)
215 attrib &= cpu_to_be16(~HFS_SB_ATTRIB_UNMNT); 215 attrib &= cpu_to_be16(~HFS_SB_ATTRIB_UNMNT);
216 attrib |= cpu_to_be16(HFS_SB_ATTRIB_INCNSTNT); 216 attrib |= cpu_to_be16(HFS_SB_ATTRIB_INCNSTNT);
217 mdb->drAtrb = attrib; 217 mdb->drAtrb = attrib;
218 mdb->drWrCnt = cpu_to_be32(be32_to_cpu(mdb->drWrCnt) + 1); 218 be32_add_cpu(&mdb->drWrCnt, 1);
219 mdb->drLsMod = hfs_mtime(); 219 mdb->drLsMod = hfs_mtime();
220 220
221 mark_buffer_dirty(HFS_SB(sb)->mdb_bh); 221 mark_buffer_dirty(HFS_SB(sb)->mdb_bh);
diff --git a/fs/hfsplus/btree.c b/fs/hfsplus/btree.c
index bb5433608a42..e49fcee1e293 100644
--- a/fs/hfsplus/btree.c
+++ b/fs/hfsplus/btree.c
@@ -184,7 +184,9 @@ struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree)
184 struct hfs_bnode *node, *next_node; 184 struct hfs_bnode *node, *next_node;
185 struct page **pagep; 185 struct page **pagep;
186 u32 nidx, idx; 186 u32 nidx, idx;
187 u16 off, len; 187 unsigned off;
188 u16 off16;
189 u16 len;
188 u8 *data, byte, m; 190 u8 *data, byte, m;
189 int i; 191 int i;
190 192
@@ -211,7 +213,8 @@ struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree)
211 node = hfs_bnode_find(tree, nidx); 213 node = hfs_bnode_find(tree, nidx);
212 if (IS_ERR(node)) 214 if (IS_ERR(node))
213 return node; 215 return node;
214 len = hfs_brec_lenoff(node, 2, &off); 216 len = hfs_brec_lenoff(node, 2, &off16);
217 off = off16;
215 218
216 off += node->page_offset; 219 off += node->page_offset;
217 pagep = node->page + (off >> PAGE_CACHE_SHIFT); 220 pagep = node->page + (off >> PAGE_CACHE_SHIFT);
@@ -256,7 +259,8 @@ struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree)
256 return next_node; 259 return next_node;
257 node = next_node; 260 node = next_node;
258 261
259 len = hfs_brec_lenoff(node, 0, &off); 262 len = hfs_brec_lenoff(node, 0, &off16);
263 off = off16;
260 off += node->page_offset; 264 off += node->page_offset;
261 pagep = node->page + (off >> PAGE_CACHE_SHIFT); 265 pagep = node->page + (off >> PAGE_CACHE_SHIFT);
262 data = kmap(*pagep); 266 data = kmap(*pagep);
diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
index 946466cd9f25..ce97a54518d8 100644
--- a/fs/hfsplus/super.c
+++ b/fs/hfsplus/super.c
@@ -423,7 +423,7 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
423 */ 423 */
424 vhdr->last_mount_vers = cpu_to_be32(HFSP_MOUNT_VERSION); 424 vhdr->last_mount_vers = cpu_to_be32(HFSP_MOUNT_VERSION);
425 vhdr->modify_date = hfsp_now2mt(); 425 vhdr->modify_date = hfsp_now2mt();
426 vhdr->write_count = cpu_to_be32(be32_to_cpu(vhdr->write_count) + 1); 426 be32_add_cpu(&vhdr->write_count, 1);
427 vhdr->attributes &= cpu_to_be32(~HFSPLUS_VOL_UNMNT); 427 vhdr->attributes &= cpu_to_be32(~HFSPLUS_VOL_UNMNT);
428 vhdr->attributes |= cpu_to_be32(HFSPLUS_VOL_INCNSTNT); 428 vhdr->attributes |= cpu_to_be32(HFSPLUS_VOL_INCNSTNT);
429 mark_buffer_dirty(HFSPLUS_SB(sb).s_vhbh); 429 mark_buffer_dirty(HFSPLUS_SB(sb).s_vhbh);
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 9783723e8ffe..aeabf80f81a5 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -45,7 +45,7 @@ static const struct inode_operations hugetlbfs_inode_operations;
45 45
46static struct backing_dev_info hugetlbfs_backing_dev_info = { 46static struct backing_dev_info hugetlbfs_backing_dev_info = {
47 .ra_pages = 0, /* No readahead */ 47 .ra_pages = 0, /* No readahead */
48 .capabilities = BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_WRITEBACK, 48 .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK,
49}; 49};
50 50
51int sysctl_hugetlb_shm_group; 51int sysctl_hugetlb_shm_group;
diff --git a/fs/isofs/dir.c b/fs/isofs/dir.c
index 1ba407c64df1..2f0dc5a14633 100644
--- a/fs/isofs/dir.c
+++ b/fs/isofs/dir.c
@@ -145,6 +145,14 @@ static int do_isofs_readdir(struct inode *inode, struct file *filp,
145 } 145 }
146 de = tmpde; 146 de = tmpde;
147 } 147 }
148 /* Basic sanity check, whether name doesn't exceed dir entry */
149 if (de_len < de->name_len[0] +
150 sizeof(struct iso_directory_record)) {
151 printk(KERN_NOTICE "iso9660: Corrupted directory entry"
152 " in block %lu of inode %lu\n", block,
153 inode->i_ino);
154 return -EIO;
155 }
148 156
149 if (first_de) { 157 if (first_de) {
150 isofs_normalize_block_and_offset(de, 158 isofs_normalize_block_and_offset(de,
diff --git a/fs/isofs/namei.c b/fs/isofs/namei.c
index 344b247bc29a..8299889a835e 100644
--- a/fs/isofs/namei.c
+++ b/fs/isofs/namei.c
@@ -111,6 +111,13 @@ isofs_find_entry(struct inode *dir, struct dentry *dentry,
111 111
112 dlen = de->name_len[0]; 112 dlen = de->name_len[0];
113 dpnt = de->name; 113 dpnt = de->name;
114 /* Basic sanity check, whether name doesn't exceed dir entry */
115 if (de_len < dlen + sizeof(struct iso_directory_record)) {
116 printk(KERN_NOTICE "iso9660: Corrupted directory entry"
117 " in block %lu of inode %lu\n", block,
118 dir->i_ino);
119 return 0;
120 }
114 121
115 if (sbi->s_rock && 122 if (sbi->s_rock &&
116 ((i = get_rock_ridge_filename(de, tmpname, dir)))) { 123 ((i = get_rock_ridge_filename(de, tmpname, dir)))) {
diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
index a8173081f831..e0139786f717 100644
--- a/fs/jbd2/commit.c
+++ b/fs/jbd2/commit.c
@@ -520,22 +520,6 @@ void jbd2_journal_commit_transaction(journal_t *journal)
520 jbd_debug (3, "JBD: commit phase 2\n"); 520 jbd_debug (3, "JBD: commit phase 2\n");
521 521
522 /* 522 /*
523 * First, drop modified flag: all accesses to the buffers
524 * will be tracked for a new trasaction only -bzzz
525 */
526 spin_lock(&journal->j_list_lock);
527 if (commit_transaction->t_buffers) {
528 new_jh = jh = commit_transaction->t_buffers->b_tnext;
529 do {
530 J_ASSERT_JH(new_jh, new_jh->b_modified == 1 ||
531 new_jh->b_modified == 0);
532 new_jh->b_modified = 0;
533 new_jh = new_jh->b_tnext;
534 } while (new_jh != jh);
535 }
536 spin_unlock(&journal->j_list_lock);
537
538 /*
539 * Now start flushing things to disk, in the order they appear 523 * Now start flushing things to disk, in the order they appear
540 * on the transaction lists. Data blocks go first. 524 * on the transaction lists. Data blocks go first.
541 */ 525 */
@@ -584,6 +568,9 @@ void jbd2_journal_commit_transaction(journal_t *journal)
584 stats.u.run.rs_blocks = commit_transaction->t_outstanding_credits; 568 stats.u.run.rs_blocks = commit_transaction->t_outstanding_credits;
585 stats.u.run.rs_blocks_logged = 0; 569 stats.u.run.rs_blocks_logged = 0;
586 570
571 J_ASSERT(commit_transaction->t_nr_buffers <=
572 commit_transaction->t_outstanding_credits);
573
587 descriptor = NULL; 574 descriptor = NULL;
588 bufs = 0; 575 bufs = 0;
589 while (commit_transaction->t_buffers) { 576 while (commit_transaction->t_buffers) {
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index eb7eb6c27bcb..53632e3e8457 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -534,7 +534,7 @@ int jbd2_log_wait_commit(journal_t *journal, tid_t tid)
534 if (!tid_geq(journal->j_commit_request, tid)) { 534 if (!tid_geq(journal->j_commit_request, tid)) {
535 printk(KERN_EMERG 535 printk(KERN_EMERG
536 "%s: error: j_commit_request=%d, tid=%d\n", 536 "%s: error: j_commit_request=%d, tid=%d\n",
537 __FUNCTION__, journal->j_commit_request, tid); 537 __func__, journal->j_commit_request, tid);
538 } 538 }
539 spin_unlock(&journal->j_state_lock); 539 spin_unlock(&journal->j_state_lock);
540#endif 540#endif
@@ -599,7 +599,7 @@ int jbd2_journal_bmap(journal_t *journal, unsigned long blocknr,
599 599
600 printk(KERN_ALERT "%s: journal block not found " 600 printk(KERN_ALERT "%s: journal block not found "
601 "at offset %lu on %s\n", 601 "at offset %lu on %s\n",
602 __FUNCTION__, 602 __func__,
603 blocknr, 603 blocknr,
604 bdevname(journal->j_dev, b)); 604 bdevname(journal->j_dev, b));
605 err = -EIO; 605 err = -EIO;
@@ -997,13 +997,14 @@ fail:
997 */ 997 */
998 998
999/** 999/**
1000 * journal_t * jbd2_journal_init_dev() - creates an initialises a journal structure 1000 * journal_t * jbd2_journal_init_dev() - creates and initialises a journal structure
1001 * @bdev: Block device on which to create the journal 1001 * @bdev: Block device on which to create the journal
1002 * @fs_dev: Device which hold journalled filesystem for this journal. 1002 * @fs_dev: Device which hold journalled filesystem for this journal.
1003 * @start: Block nr Start of journal. 1003 * @start: Block nr Start of journal.
1004 * @len: Length of the journal in blocks. 1004 * @len: Length of the journal in blocks.
1005 * @blocksize: blocksize of journalling device 1005 * @blocksize: blocksize of journalling device
1006 * @returns: a newly created journal_t * 1006 *
1007 * Returns: a newly created journal_t *
1007 * 1008 *
1008 * jbd2_journal_init_dev creates a journal which maps a fixed contiguous 1009 * jbd2_journal_init_dev creates a journal which maps a fixed contiguous
1009 * range of blocks on an arbitrary block device. 1010 * range of blocks on an arbitrary block device.
@@ -1027,7 +1028,7 @@ journal_t * jbd2_journal_init_dev(struct block_device *bdev,
1027 journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL); 1028 journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL);
1028 if (!journal->j_wbuf) { 1029 if (!journal->j_wbuf) {
1029 printk(KERN_ERR "%s: Cant allocate bhs for commit thread\n", 1030 printk(KERN_ERR "%s: Cant allocate bhs for commit thread\n",
1030 __FUNCTION__); 1031 __func__);
1031 kfree(journal); 1032 kfree(journal);
1032 journal = NULL; 1033 journal = NULL;
1033 goto out; 1034 goto out;
@@ -1083,7 +1084,7 @@ journal_t * jbd2_journal_init_inode (struct inode *inode)
1083 journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL); 1084 journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL);
1084 if (!journal->j_wbuf) { 1085 if (!journal->j_wbuf) {
1085 printk(KERN_ERR "%s: Cant allocate bhs for commit thread\n", 1086 printk(KERN_ERR "%s: Cant allocate bhs for commit thread\n",
1086 __FUNCTION__); 1087 __func__);
1087 kfree(journal); 1088 kfree(journal);
1088 return NULL; 1089 return NULL;
1089 } 1090 }
@@ -1092,7 +1093,7 @@ journal_t * jbd2_journal_init_inode (struct inode *inode)
1092 /* If that failed, give up */ 1093 /* If that failed, give up */
1093 if (err) { 1094 if (err) {
1094 printk(KERN_ERR "%s: Cannnot locate journal superblock\n", 1095 printk(KERN_ERR "%s: Cannnot locate journal superblock\n",
1095 __FUNCTION__); 1096 __func__);
1096 kfree(journal); 1097 kfree(journal);
1097 return NULL; 1098 return NULL;
1098 } 1099 }
@@ -1178,7 +1179,7 @@ int jbd2_journal_create(journal_t *journal)
1178 */ 1179 */
1179 printk(KERN_EMERG 1180 printk(KERN_EMERG
1180 "%s: creation of journal on external device!\n", 1181 "%s: creation of journal on external device!\n",
1181 __FUNCTION__); 1182 __func__);
1182 BUG(); 1183 BUG();
1183 } 1184 }
1184 1185
@@ -1976,9 +1977,10 @@ static int journal_init_jbd2_journal_head_cache(void)
1976 1977
1977static void jbd2_journal_destroy_jbd2_journal_head_cache(void) 1978static void jbd2_journal_destroy_jbd2_journal_head_cache(void)
1978{ 1979{
1979 J_ASSERT(jbd2_journal_head_cache != NULL); 1980 if (jbd2_journal_head_cache) {
1980 kmem_cache_destroy(jbd2_journal_head_cache); 1981 kmem_cache_destroy(jbd2_journal_head_cache);
1981 jbd2_journal_head_cache = NULL; 1982 jbd2_journal_head_cache = NULL;
1983 }
1982} 1984}
1983 1985
1984/* 1986/*
@@ -1997,7 +1999,7 @@ static struct journal_head *journal_alloc_journal_head(void)
1997 jbd_debug(1, "out of memory for journal_head\n"); 1999 jbd_debug(1, "out of memory for journal_head\n");
1998 if (time_after(jiffies, last_warning + 5*HZ)) { 2000 if (time_after(jiffies, last_warning + 5*HZ)) {
1999 printk(KERN_NOTICE "ENOMEM in %s, retrying.\n", 2001 printk(KERN_NOTICE "ENOMEM in %s, retrying.\n",
2000 __FUNCTION__); 2002 __func__);
2001 last_warning = jiffies; 2003 last_warning = jiffies;
2002 } 2004 }
2003 while (!ret) { 2005 while (!ret) {
@@ -2134,13 +2136,13 @@ static void __journal_remove_journal_head(struct buffer_head *bh)
2134 if (jh->b_frozen_data) { 2136 if (jh->b_frozen_data) {
2135 printk(KERN_WARNING "%s: freeing " 2137 printk(KERN_WARNING "%s: freeing "
2136 "b_frozen_data\n", 2138 "b_frozen_data\n",
2137 __FUNCTION__); 2139 __func__);
2138 jbd2_free(jh->b_frozen_data, bh->b_size); 2140 jbd2_free(jh->b_frozen_data, bh->b_size);
2139 } 2141 }
2140 if (jh->b_committed_data) { 2142 if (jh->b_committed_data) {
2141 printk(KERN_WARNING "%s: freeing " 2143 printk(KERN_WARNING "%s: freeing "
2142 "b_committed_data\n", 2144 "b_committed_data\n",
2143 __FUNCTION__); 2145 __func__);
2144 jbd2_free(jh->b_committed_data, bh->b_size); 2146 jbd2_free(jh->b_committed_data, bh->b_size);
2145 } 2147 }
2146 bh->b_private = NULL; 2148 bh->b_private = NULL;
@@ -2305,10 +2307,12 @@ static int __init journal_init(void)
2305 BUILD_BUG_ON(sizeof(struct journal_superblock_s) != 1024); 2307 BUILD_BUG_ON(sizeof(struct journal_superblock_s) != 1024);
2306 2308
2307 ret = journal_init_caches(); 2309 ret = journal_init_caches();
2308 if (ret != 0) 2310 if (ret == 0) {
2311 jbd2_create_debugfs_entry();
2312 jbd2_create_jbd_stats_proc_entry();
2313 } else {
2309 jbd2_journal_destroy_caches(); 2314 jbd2_journal_destroy_caches();
2310 jbd2_create_debugfs_entry(); 2315 }
2311 jbd2_create_jbd_stats_proc_entry();
2312 return ret; 2316 return ret;
2313} 2317}
2314 2318
diff --git a/fs/jbd2/revoke.c b/fs/jbd2/revoke.c
index 2e1453a5e998..257ff2625765 100644
--- a/fs/jbd2/revoke.c
+++ b/fs/jbd2/revoke.c
@@ -139,7 +139,7 @@ repeat:
139oom: 139oom:
140 if (!journal_oom_retry) 140 if (!journal_oom_retry)
141 return -ENOMEM; 141 return -ENOMEM;
142 jbd_debug(1, "ENOMEM in %s, retrying\n", __FUNCTION__); 142 jbd_debug(1, "ENOMEM in %s, retrying\n", __func__);
143 yield(); 143 yield();
144 goto repeat; 144 goto repeat;
145} 145}
@@ -167,138 +167,121 @@ static struct jbd2_revoke_record_s *find_revoke_record(journal_t *journal,
167 return NULL; 167 return NULL;
168} 168}
169 169
170void jbd2_journal_destroy_revoke_caches(void)
171{
172 if (jbd2_revoke_record_cache) {
173 kmem_cache_destroy(jbd2_revoke_record_cache);
174 jbd2_revoke_record_cache = NULL;
175 }
176 if (jbd2_revoke_table_cache) {
177 kmem_cache_destroy(jbd2_revoke_table_cache);
178 jbd2_revoke_table_cache = NULL;
179 }
180}
181
170int __init jbd2_journal_init_revoke_caches(void) 182int __init jbd2_journal_init_revoke_caches(void)
171{ 183{
184 J_ASSERT(!jbd2_revoke_record_cache);
185 J_ASSERT(!jbd2_revoke_table_cache);
186
172 jbd2_revoke_record_cache = kmem_cache_create("jbd2_revoke_record", 187 jbd2_revoke_record_cache = kmem_cache_create("jbd2_revoke_record",
173 sizeof(struct jbd2_revoke_record_s), 188 sizeof(struct jbd2_revoke_record_s),
174 0, 189 0,
175 SLAB_HWCACHE_ALIGN|SLAB_TEMPORARY, 190 SLAB_HWCACHE_ALIGN|SLAB_TEMPORARY,
176 NULL); 191 NULL);
177 if (!jbd2_revoke_record_cache) 192 if (!jbd2_revoke_record_cache)
178 return -ENOMEM; 193 goto record_cache_failure;
179 194
180 jbd2_revoke_table_cache = kmem_cache_create("jbd2_revoke_table", 195 jbd2_revoke_table_cache = kmem_cache_create("jbd2_revoke_table",
181 sizeof(struct jbd2_revoke_table_s), 196 sizeof(struct jbd2_revoke_table_s),
182 0, SLAB_TEMPORARY, NULL); 197 0, SLAB_TEMPORARY, NULL);
183 if (!jbd2_revoke_table_cache) { 198 if (!jbd2_revoke_table_cache)
184 kmem_cache_destroy(jbd2_revoke_record_cache); 199 goto table_cache_failure;
185 jbd2_revoke_record_cache = NULL;
186 return -ENOMEM;
187 }
188 return 0; 200 return 0;
201table_cache_failure:
202 jbd2_journal_destroy_revoke_caches();
203record_cache_failure:
204 return -ENOMEM;
189} 205}
190 206
191void jbd2_journal_destroy_revoke_caches(void) 207static struct jbd2_revoke_table_s *jbd2_journal_init_revoke_table(int hash_size)
192{ 208{
193 kmem_cache_destroy(jbd2_revoke_record_cache); 209 int shift = 0;
194 jbd2_revoke_record_cache = NULL; 210 int tmp = hash_size;
195 kmem_cache_destroy(jbd2_revoke_table_cache); 211 struct jbd2_revoke_table_s *table;
196 jbd2_revoke_table_cache = NULL;
197}
198
199/* Initialise the revoke table for a given journal to a given size. */
200
201int jbd2_journal_init_revoke(journal_t *journal, int hash_size)
202{
203 int shift, tmp;
204 212
205 J_ASSERT (journal->j_revoke_table[0] == NULL); 213 table = kmem_cache_alloc(jbd2_revoke_table_cache, GFP_KERNEL);
214 if (!table)
215 goto out;
206 216
207 shift = 0;
208 tmp = hash_size;
209 while((tmp >>= 1UL) != 0UL) 217 while((tmp >>= 1UL) != 0UL)
210 shift++; 218 shift++;
211 219
212 journal->j_revoke_table[0] = kmem_cache_alloc(jbd2_revoke_table_cache, GFP_KERNEL); 220 table->hash_size = hash_size;
213 if (!journal->j_revoke_table[0]) 221 table->hash_shift = shift;
214 return -ENOMEM; 222 table->hash_table =
215 journal->j_revoke = journal->j_revoke_table[0];
216
217 /* Check that the hash_size is a power of two */
218 J_ASSERT(is_power_of_2(hash_size));
219
220 journal->j_revoke->hash_size = hash_size;
221
222 journal->j_revoke->hash_shift = shift;
223
224 journal->j_revoke->hash_table =
225 kmalloc(hash_size * sizeof(struct list_head), GFP_KERNEL); 223 kmalloc(hash_size * sizeof(struct list_head), GFP_KERNEL);
226 if (!journal->j_revoke->hash_table) { 224 if (!table->hash_table) {
227 kmem_cache_free(jbd2_revoke_table_cache, journal->j_revoke_table[0]); 225 kmem_cache_free(jbd2_revoke_table_cache, table);
228 journal->j_revoke = NULL; 226 table = NULL;
229 return -ENOMEM; 227 goto out;
230 } 228 }
231 229
232 for (tmp = 0; tmp < hash_size; tmp++) 230 for (tmp = 0; tmp < hash_size; tmp++)
233 INIT_LIST_HEAD(&journal->j_revoke->hash_table[tmp]); 231 INIT_LIST_HEAD(&table->hash_table[tmp]);
234 232
235 journal->j_revoke_table[1] = kmem_cache_alloc(jbd2_revoke_table_cache, GFP_KERNEL); 233out:
236 if (!journal->j_revoke_table[1]) { 234 return table;
237 kfree(journal->j_revoke_table[0]->hash_table); 235}
238 kmem_cache_free(jbd2_revoke_table_cache, journal->j_revoke_table[0]); 236
239 return -ENOMEM; 237static void jbd2_journal_destroy_revoke_table(struct jbd2_revoke_table_s *table)
238{
239 int i;
240 struct list_head *hash_list;
241
242 for (i = 0; i < table->hash_size; i++) {
243 hash_list = &table->hash_table[i];
244 J_ASSERT(list_empty(hash_list));
240 } 245 }
241 246
242 journal->j_revoke = journal->j_revoke_table[1]; 247 kfree(table->hash_table);
248 kmem_cache_free(jbd2_revoke_table_cache, table);
249}
243 250
244 /* Check that the hash_size is a power of two */ 251/* Initialise the revoke table for a given journal to a given size. */
252int jbd2_journal_init_revoke(journal_t *journal, int hash_size)
253{
254 J_ASSERT(journal->j_revoke_table[0] == NULL);
245 J_ASSERT(is_power_of_2(hash_size)); 255 J_ASSERT(is_power_of_2(hash_size));
246 256
247 journal->j_revoke->hash_size = hash_size; 257 journal->j_revoke_table[0] = jbd2_journal_init_revoke_table(hash_size);
248 258 if (!journal->j_revoke_table[0])
249 journal->j_revoke->hash_shift = shift; 259 goto fail0;
250 260
251 journal->j_revoke->hash_table = 261 journal->j_revoke_table[1] = jbd2_journal_init_revoke_table(hash_size);
252 kmalloc(hash_size * sizeof(struct list_head), GFP_KERNEL); 262 if (!journal->j_revoke_table[1])
253 if (!journal->j_revoke->hash_table) { 263 goto fail1;
254 kfree(journal->j_revoke_table[0]->hash_table);
255 kmem_cache_free(jbd2_revoke_table_cache, journal->j_revoke_table[0]);
256 kmem_cache_free(jbd2_revoke_table_cache, journal->j_revoke_table[1]);
257 journal->j_revoke = NULL;
258 return -ENOMEM;
259 }
260 264
261 for (tmp = 0; tmp < hash_size; tmp++) 265 journal->j_revoke = journal->j_revoke_table[1];
262 INIT_LIST_HEAD(&journal->j_revoke->hash_table[tmp]);
263 266
264 spin_lock_init(&journal->j_revoke_lock); 267 spin_lock_init(&journal->j_revoke_lock);
265 268
266 return 0; 269 return 0;
267}
268 270
269/* Destoy a journal's revoke table. The table must already be empty! */ 271fail1:
272 jbd2_journal_destroy_revoke_table(journal->j_revoke_table[0]);
273fail0:
274 return -ENOMEM;
275}
270 276
277/* Destroy a journal's revoke table. The table must already be empty! */
271void jbd2_journal_destroy_revoke(journal_t *journal) 278void jbd2_journal_destroy_revoke(journal_t *journal)
272{ 279{
273 struct jbd2_revoke_table_s *table;
274 struct list_head *hash_list;
275 int i;
276
277 table = journal->j_revoke_table[0];
278 if (!table)
279 return;
280
281 for (i=0; i<table->hash_size; i++) {
282 hash_list = &table->hash_table[i];
283 J_ASSERT (list_empty(hash_list));
284 }
285
286 kfree(table->hash_table);
287 kmem_cache_free(jbd2_revoke_table_cache, table);
288 journal->j_revoke = NULL;
289
290 table = journal->j_revoke_table[1];
291 if (!table)
292 return;
293
294 for (i=0; i<table->hash_size; i++) {
295 hash_list = &table->hash_table[i];
296 J_ASSERT (list_empty(hash_list));
297 }
298
299 kfree(table->hash_table);
300 kmem_cache_free(jbd2_revoke_table_cache, table);
301 journal->j_revoke = NULL; 280 journal->j_revoke = NULL;
281 if (journal->j_revoke_table[0])
282 jbd2_journal_destroy_revoke_table(journal->j_revoke_table[0]);
283 if (journal->j_revoke_table[1])
284 jbd2_journal_destroy_revoke_table(journal->j_revoke_table[1]);
302} 285}
303 286
304 287
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index b9b0b6f899b9..d6e006e67804 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -618,6 +618,12 @@ repeat:
618 goto done; 618 goto done;
619 619
620 /* 620 /*
621 * this is the first time this transaction is touching this buffer,
622 * reset the modified flag
623 */
624 jh->b_modified = 0;
625
626 /*
621 * If there is already a copy-out version of this buffer, then we don't 627 * If there is already a copy-out version of this buffer, then we don't
622 * need to make another one 628 * need to make another one
623 */ 629 */
@@ -690,7 +696,7 @@ repeat:
690 if (!frozen_buffer) { 696 if (!frozen_buffer) {
691 printk(KERN_EMERG 697 printk(KERN_EMERG
692 "%s: OOM for frozen_buffer\n", 698 "%s: OOM for frozen_buffer\n",
693 __FUNCTION__); 699 __func__);
694 JBUFFER_TRACE(jh, "oom!"); 700 JBUFFER_TRACE(jh, "oom!");
695 error = -ENOMEM; 701 error = -ENOMEM;
696 jbd_lock_bh_state(bh); 702 jbd_lock_bh_state(bh);
@@ -829,9 +835,16 @@ int jbd2_journal_get_create_access(handle_t *handle, struct buffer_head *bh)
829 835
830 if (jh->b_transaction == NULL) { 836 if (jh->b_transaction == NULL) {
831 jh->b_transaction = transaction; 837 jh->b_transaction = transaction;
838
839 /* first access by this transaction */
840 jh->b_modified = 0;
841
832 JBUFFER_TRACE(jh, "file as BJ_Reserved"); 842 JBUFFER_TRACE(jh, "file as BJ_Reserved");
833 __jbd2_journal_file_buffer(jh, transaction, BJ_Reserved); 843 __jbd2_journal_file_buffer(jh, transaction, BJ_Reserved);
834 } else if (jh->b_transaction == journal->j_committing_transaction) { 844 } else if (jh->b_transaction == journal->j_committing_transaction) {
845 /* first access by this transaction */
846 jh->b_modified = 0;
847
835 JBUFFER_TRACE(jh, "set next transaction"); 848 JBUFFER_TRACE(jh, "set next transaction");
836 jh->b_next_transaction = transaction; 849 jh->b_next_transaction = transaction;
837 } 850 }
@@ -901,7 +914,7 @@ repeat:
901 committed_data = jbd2_alloc(jh2bh(jh)->b_size, GFP_NOFS); 914 committed_data = jbd2_alloc(jh2bh(jh)->b_size, GFP_NOFS);
902 if (!committed_data) { 915 if (!committed_data) {
903 printk(KERN_EMERG "%s: No memory for committed data\n", 916 printk(KERN_EMERG "%s: No memory for committed data\n",
904 __FUNCTION__); 917 __func__);
905 err = -ENOMEM; 918 err = -ENOMEM;
906 goto out; 919 goto out;
907 } 920 }
@@ -1230,6 +1243,7 @@ int jbd2_journal_forget (handle_t *handle, struct buffer_head *bh)
1230 struct journal_head *jh; 1243 struct journal_head *jh;
1231 int drop_reserve = 0; 1244 int drop_reserve = 0;
1232 int err = 0; 1245 int err = 0;
1246 int was_modified = 0;
1233 1247
1234 BUFFER_TRACE(bh, "entry"); 1248 BUFFER_TRACE(bh, "entry");
1235 1249
@@ -1248,6 +1262,9 @@ int jbd2_journal_forget (handle_t *handle, struct buffer_head *bh)
1248 goto not_jbd; 1262 goto not_jbd;
1249 } 1263 }
1250 1264
1265 /* keep track of wether or not this transaction modified us */
1266 was_modified = jh->b_modified;
1267
1251 /* 1268 /*
1252 * The buffer's going from the transaction, we must drop 1269 * The buffer's going from the transaction, we must drop
1253 * all references -bzzz 1270 * all references -bzzz
@@ -1265,7 +1282,12 @@ int jbd2_journal_forget (handle_t *handle, struct buffer_head *bh)
1265 1282
1266 JBUFFER_TRACE(jh, "belongs to current transaction: unfile"); 1283 JBUFFER_TRACE(jh, "belongs to current transaction: unfile");
1267 1284
1268 drop_reserve = 1; 1285 /*
1286 * we only want to drop a reference if this transaction
1287 * modified the buffer
1288 */
1289 if (was_modified)
1290 drop_reserve = 1;
1269 1291
1270 /* 1292 /*
1271 * We are no longer going to journal this buffer. 1293 * We are no longer going to journal this buffer.
@@ -1305,7 +1327,13 @@ int jbd2_journal_forget (handle_t *handle, struct buffer_head *bh)
1305 if (jh->b_next_transaction) { 1327 if (jh->b_next_transaction) {
1306 J_ASSERT(jh->b_next_transaction == transaction); 1328 J_ASSERT(jh->b_next_transaction == transaction);
1307 jh->b_next_transaction = NULL; 1329 jh->b_next_transaction = NULL;
1308 drop_reserve = 1; 1330
1331 /*
1332 * only drop a reference if this transaction modified
1333 * the buffer
1334 */
1335 if (was_modified)
1336 drop_reserve = 1;
1309 } 1337 }
1310 } 1338 }
1311 1339
@@ -1434,7 +1462,8 @@ int jbd2_journal_stop(handle_t *handle)
1434 return err; 1462 return err;
1435} 1463}
1436 1464
1437/**int jbd2_journal_force_commit() - force any uncommitted transactions 1465/**
1466 * int jbd2_journal_force_commit() - force any uncommitted transactions
1438 * @journal: journal to force 1467 * @journal: journal to force
1439 * 1468 *
1440 * For synchronous operations: force any uncommitted transactions 1469 * For synchronous operations: force any uncommitted transactions
@@ -2077,7 +2106,7 @@ void __jbd2_journal_refile_buffer(struct journal_head *jh)
2077 jh->b_transaction = jh->b_next_transaction; 2106 jh->b_transaction = jh->b_next_transaction;
2078 jh->b_next_transaction = NULL; 2107 jh->b_next_transaction = NULL;
2079 __jbd2_journal_file_buffer(jh, jh->b_transaction, 2108 __jbd2_journal_file_buffer(jh, jh->b_transaction,
2080 was_dirty ? BJ_Metadata : BJ_Reserved); 2109 jh->b_modified ? BJ_Metadata : BJ_Reserved);
2081 J_ASSERT_JH(jh, jh->b_transaction->t_state == T_RUNNING); 2110 J_ASSERT_JH(jh, jh->b_transaction->t_state == T_RUNNING);
2082 2111
2083 if (was_dirty) 2112 if (was_dirty)
diff --git a/fs/jffs2/build.c b/fs/jffs2/build.c
index d58f845ccb85..c5e1450d79f9 100644
--- a/fs/jffs2/build.c
+++ b/fs/jffs2/build.c
@@ -46,7 +46,7 @@ next_inode(int *i, struct jffs2_inode_cache *ic, struct jffs2_sb_info *c)
46 46
47 47
48static void jffs2_build_inode_pass1(struct jffs2_sb_info *c, 48static void jffs2_build_inode_pass1(struct jffs2_sb_info *c,
49 struct jffs2_inode_cache *ic) 49 struct jffs2_inode_cache *ic)
50{ 50{
51 struct jffs2_full_dirent *fd; 51 struct jffs2_full_dirent *fd;
52 52
@@ -68,11 +68,17 @@ static void jffs2_build_inode_pass1(struct jffs2_sb_info *c,
68 continue; 68 continue;
69 } 69 }
70 70
71 if (child_ic->nlink++ && fd->type == DT_DIR) { 71 if (fd->type == DT_DIR) {
72 JFFS2_ERROR("child dir \"%s\" (ino #%u) of dir ino #%u appears to be a hard link\n", 72 if (child_ic->pino_nlink) {
73 fd->name, fd->ino, ic->ino); 73 JFFS2_ERROR("child dir \"%s\" (ino #%u) of dir ino #%u appears to be a hard link\n",
74 /* TODO: What do we do about it? */ 74 fd->name, fd->ino, ic->ino);
75 } 75 /* TODO: What do we do about it? */
76 } else {
77 child_ic->pino_nlink = ic->ino;
78 }
79 } else
80 child_ic->pino_nlink++;
81
76 dbg_fsbuild("increased nlink for child \"%s\" (ino #%u)\n", fd->name, fd->ino); 82 dbg_fsbuild("increased nlink for child \"%s\" (ino #%u)\n", fd->name, fd->ino);
77 /* Can't free scan_dents so far. We might need them in pass 2 */ 83 /* Can't free scan_dents so far. We might need them in pass 2 */
78 } 84 }
@@ -125,7 +131,7 @@ static int jffs2_build_filesystem(struct jffs2_sb_info *c)
125 dbg_fsbuild("pass 2 starting\n"); 131 dbg_fsbuild("pass 2 starting\n");
126 132
127 for_each_inode(i, c, ic) { 133 for_each_inode(i, c, ic) {
128 if (ic->nlink) 134 if (ic->pino_nlink)
129 continue; 135 continue;
130 136
131 jffs2_build_remove_unlinked_inode(c, ic, &dead_fds); 137 jffs2_build_remove_unlinked_inode(c, ic, &dead_fds);
@@ -232,16 +238,19 @@ static void jffs2_build_remove_unlinked_inode(struct jffs2_sb_info *c,
232 /* Reduce nlink of the child. If it's now zero, stick it on the 238 /* Reduce nlink of the child. If it's now zero, stick it on the
233 dead_fds list to be cleaned up later. Else just free the fd */ 239 dead_fds list to be cleaned up later. Else just free the fd */
234 240
235 child_ic->nlink--; 241 if (fd->type == DT_DIR)
242 child_ic->pino_nlink = 0;
243 else
244 child_ic->pino_nlink--;
236 245
237 if (!child_ic->nlink) { 246 if (!child_ic->pino_nlink) {
238 dbg_fsbuild("inode #%u (\"%s\") has now got zero nlink, adding to dead_fds list.\n", 247 dbg_fsbuild("inode #%u (\"%s\") now has no links; adding to dead_fds list.\n",
239 fd->ino, fd->name); 248 fd->ino, fd->name);
240 fd->next = *dead_fds; 249 fd->next = *dead_fds;
241 *dead_fds = fd; 250 *dead_fds = fd;
242 } else { 251 } else {
243 dbg_fsbuild("inode #%u (\"%s\") has now got nlink %d. Ignoring.\n", 252 dbg_fsbuild("inode #%u (\"%s\") has now got nlink %d. Ignoring.\n",
244 fd->ino, fd->name, child_ic->nlink); 253 fd->ino, fd->name, child_ic->pino_nlink);
245 jffs2_free_full_dirent(fd); 254 jffs2_free_full_dirent(fd);
246 } 255 }
247 } 256 }
diff --git a/fs/jffs2/debug.h b/fs/jffs2/debug.h
index 9645275023e6..a113ecc3bafe 100644
--- a/fs/jffs2/debug.h
+++ b/fs/jffs2/debug.h
@@ -82,28 +82,28 @@
82 do { \ 82 do { \
83 printk(JFFS2_ERR_MSG_PREFIX \ 83 printk(JFFS2_ERR_MSG_PREFIX \
84 " (%d) %s: " fmt, task_pid_nr(current), \ 84 " (%d) %s: " fmt, task_pid_nr(current), \
85 __FUNCTION__ , ##__VA_ARGS__); \ 85 __func__ , ##__VA_ARGS__); \
86 } while(0) 86 } while(0)
87 87
88#define JFFS2_WARNING(fmt, ...) \ 88#define JFFS2_WARNING(fmt, ...) \
89 do { \ 89 do { \
90 printk(JFFS2_WARN_MSG_PREFIX \ 90 printk(JFFS2_WARN_MSG_PREFIX \
91 " (%d) %s: " fmt, task_pid_nr(current), \ 91 " (%d) %s: " fmt, task_pid_nr(current), \
92 __FUNCTION__ , ##__VA_ARGS__); \ 92 __func__ , ##__VA_ARGS__); \
93 } while(0) 93 } while(0)
94 94
95#define JFFS2_NOTICE(fmt, ...) \ 95#define JFFS2_NOTICE(fmt, ...) \
96 do { \ 96 do { \
97 printk(JFFS2_NOTICE_MSG_PREFIX \ 97 printk(JFFS2_NOTICE_MSG_PREFIX \
98 " (%d) %s: " fmt, task_pid_nr(current), \ 98 " (%d) %s: " fmt, task_pid_nr(current), \
99 __FUNCTION__ , ##__VA_ARGS__); \ 99 __func__ , ##__VA_ARGS__); \
100 } while(0) 100 } while(0)
101 101
102#define JFFS2_DEBUG(fmt, ...) \ 102#define JFFS2_DEBUG(fmt, ...) \
103 do { \ 103 do { \
104 printk(JFFS2_DBG_MSG_PREFIX \ 104 printk(JFFS2_DBG_MSG_PREFIX \
105 " (%d) %s: " fmt, task_pid_nr(current), \ 105 " (%d) %s: " fmt, task_pid_nr(current), \
106 __FUNCTION__ , ##__VA_ARGS__); \ 106 __func__ , ##__VA_ARGS__); \
107 } while(0) 107 } while(0)
108 108
109/* 109/*
diff --git a/fs/jffs2/dir.c b/fs/jffs2/dir.c
index c63e7a96af0d..c0c141f6fde1 100644
--- a/fs/jffs2/dir.c
+++ b/fs/jffs2/dir.c
@@ -208,6 +208,13 @@ static int jffs2_create(struct inode *dir_i, struct dentry *dentry, int mode,
208 f = JFFS2_INODE_INFO(inode); 208 f = JFFS2_INODE_INFO(inode);
209 dir_f = JFFS2_INODE_INFO(dir_i); 209 dir_f = JFFS2_INODE_INFO(dir_i);
210 210
211 /* jffs2_do_create() will want to lock it, _after_ reserving
212 space and taking c-alloc_sem. If we keep it locked here,
213 lockdep gets unhappy (although it's a false positive;
214 nothing else will be looking at this inode yet so there's
215 no chance of AB-BA deadlock involving its f->sem). */
216 mutex_unlock(&f->sem);
217
211 ret = jffs2_do_create(c, dir_f, f, ri, 218 ret = jffs2_do_create(c, dir_f, f, ri,
212 dentry->d_name.name, dentry->d_name.len); 219 dentry->d_name.name, dentry->d_name.len);
213 if (ret) 220 if (ret)
@@ -219,7 +226,8 @@ static int jffs2_create(struct inode *dir_i, struct dentry *dentry, int mode,
219 d_instantiate(dentry, inode); 226 d_instantiate(dentry, inode);
220 227
221 D1(printk(KERN_DEBUG "jffs2_create: Created ino #%lu with mode %o, nlink %d(%d). nrpages %ld\n", 228 D1(printk(KERN_DEBUG "jffs2_create: Created ino #%lu with mode %o, nlink %d(%d). nrpages %ld\n",
222 inode->i_ino, inode->i_mode, inode->i_nlink, f->inocache->nlink, inode->i_mapping->nrpages)); 229 inode->i_ino, inode->i_mode, inode->i_nlink,
230 f->inocache->pino_nlink, inode->i_mapping->nrpages));
223 return 0; 231 return 0;
224 232
225 fail: 233 fail:
@@ -243,7 +251,7 @@ static int jffs2_unlink(struct inode *dir_i, struct dentry *dentry)
243 ret = jffs2_do_unlink(c, dir_f, dentry->d_name.name, 251 ret = jffs2_do_unlink(c, dir_f, dentry->d_name.name,
244 dentry->d_name.len, dead_f, now); 252 dentry->d_name.len, dead_f, now);
245 if (dead_f->inocache) 253 if (dead_f->inocache)
246 dentry->d_inode->i_nlink = dead_f->inocache->nlink; 254 dentry->d_inode->i_nlink = dead_f->inocache->pino_nlink;
247 if (!ret) 255 if (!ret)
248 dir_i->i_mtime = dir_i->i_ctime = ITIME(now); 256 dir_i->i_mtime = dir_i->i_ctime = ITIME(now);
249 return ret; 257 return ret;
@@ -276,7 +284,7 @@ static int jffs2_link (struct dentry *old_dentry, struct inode *dir_i, struct de
276 284
277 if (!ret) { 285 if (!ret) {
278 mutex_lock(&f->sem); 286 mutex_lock(&f->sem);
279 old_dentry->d_inode->i_nlink = ++f->inocache->nlink; 287 old_dentry->d_inode->i_nlink = ++f->inocache->pino_nlink;
280 mutex_unlock(&f->sem); 288 mutex_unlock(&f->sem);
281 d_instantiate(dentry, old_dentry->d_inode); 289 d_instantiate(dentry, old_dentry->d_inode);
282 dir_i->i_mtime = dir_i->i_ctime = ITIME(now); 290 dir_i->i_mtime = dir_i->i_ctime = ITIME(now);
@@ -493,11 +501,14 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
493 501
494 inode->i_op = &jffs2_dir_inode_operations; 502 inode->i_op = &jffs2_dir_inode_operations;
495 inode->i_fop = &jffs2_dir_operations; 503 inode->i_fop = &jffs2_dir_operations;
496 /* Directories get nlink 2 at start */
497 inode->i_nlink = 2;
498 504
499 f = JFFS2_INODE_INFO(inode); 505 f = JFFS2_INODE_INFO(inode);
500 506
507 /* Directories get nlink 2 at start */
508 inode->i_nlink = 2;
509 /* but ic->pino_nlink is the parent ino# */
510 f->inocache->pino_nlink = dir_i->i_ino;
511
501 ri->data_crc = cpu_to_je32(0); 512 ri->data_crc = cpu_to_je32(0);
502 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); 513 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
503 514
@@ -594,17 +605,25 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
594 605
595static int jffs2_rmdir (struct inode *dir_i, struct dentry *dentry) 606static int jffs2_rmdir (struct inode *dir_i, struct dentry *dentry)
596{ 607{
608 struct jffs2_sb_info *c = JFFS2_SB_INFO(dir_i->i_sb);
609 struct jffs2_inode_info *dir_f = JFFS2_INODE_INFO(dir_i);
597 struct jffs2_inode_info *f = JFFS2_INODE_INFO(dentry->d_inode); 610 struct jffs2_inode_info *f = JFFS2_INODE_INFO(dentry->d_inode);
598 struct jffs2_full_dirent *fd; 611 struct jffs2_full_dirent *fd;
599 int ret; 612 int ret;
613 uint32_t now = get_seconds();
600 614
601 for (fd = f->dents ; fd; fd = fd->next) { 615 for (fd = f->dents ; fd; fd = fd->next) {
602 if (fd->ino) 616 if (fd->ino)
603 return -ENOTEMPTY; 617 return -ENOTEMPTY;
604 } 618 }
605 ret = jffs2_unlink(dir_i, dentry); 619
606 if (!ret) 620 ret = jffs2_do_unlink(c, dir_f, dentry->d_name.name,
621 dentry->d_name.len, f, now);
622 if (!ret) {
623 dir_i->i_mtime = dir_i->i_ctime = ITIME(now);
624 clear_nlink(dentry->d_inode);
607 drop_nlink(dir_i); 625 drop_nlink(dir_i);
626 }
608 return ret; 627 return ret;
609} 628}
610 629
@@ -817,7 +836,10 @@ static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
817 inode which didn't exist. */ 836 inode which didn't exist. */
818 if (victim_f->inocache) { 837 if (victim_f->inocache) {
819 mutex_lock(&victim_f->sem); 838 mutex_lock(&victim_f->sem);
820 victim_f->inocache->nlink--; 839 if (S_ISDIR(new_dentry->d_inode->i_mode))
840 victim_f->inocache->pino_nlink = 0;
841 else
842 victim_f->inocache->pino_nlink--;
821 mutex_unlock(&victim_f->sem); 843 mutex_unlock(&victim_f->sem);
822 } 844 }
823 } 845 }
@@ -838,8 +860,8 @@ static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
838 struct jffs2_inode_info *f = JFFS2_INODE_INFO(old_dentry->d_inode); 860 struct jffs2_inode_info *f = JFFS2_INODE_INFO(old_dentry->d_inode);
839 mutex_lock(&f->sem); 861 mutex_lock(&f->sem);
840 inc_nlink(old_dentry->d_inode); 862 inc_nlink(old_dentry->d_inode);
841 if (f->inocache) 863 if (f->inocache && !S_ISDIR(old_dentry->d_inode->i_mode))
842 f->inocache->nlink++; 864 f->inocache->pino_nlink++;
843 mutex_unlock(&f->sem); 865 mutex_unlock(&f->sem);
844 866
845 printk(KERN_NOTICE "jffs2_rename(): Link succeeded, unlink failed (err %d). You now have a hard link\n", ret); 867 printk(KERN_NOTICE "jffs2_rename(): Link succeeded, unlink failed (err %d). You now have a hard link\n", ret);
diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
index 25a640e566d3..dddb2a6c9e2c 100644
--- a/fs/jffs2/erase.c
+++ b/fs/jffs2/erase.c
@@ -294,7 +294,7 @@ static inline void jffs2_remove_node_refs_from_ino_list(struct jffs2_sb_info *c,
294 break; 294 break;
295#endif 295#endif
296 default: 296 default:
297 if (ic->nodes == (void *)ic && ic->nlink == 0) 297 if (ic->nodes == (void *)ic && ic->pino_nlink == 0)
298 jffs2_del_ino_cache(c, ic); 298 jffs2_del_ino_cache(c, ic);
299 } 299 }
300} 300}
@@ -332,7 +332,8 @@ static int jffs2_block_check_erase(struct jffs2_sb_info *c, struct jffs2_erasebl
332 if (c->mtd->point) { 332 if (c->mtd->point) {
333 unsigned long *wordebuf; 333 unsigned long *wordebuf;
334 334
335 ret = c->mtd->point(c->mtd, jeb->offset, c->sector_size, &retlen, (unsigned char **)&ebuf); 335 ret = c->mtd->point(c->mtd, jeb->offset, c->sector_size,
336 &retlen, &ebuf, NULL);
336 if (ret) { 337 if (ret) {
337 D1(printk(KERN_DEBUG "MTD point failed %d\n", ret)); 338 D1(printk(KERN_DEBUG "MTD point failed %d\n", ret));
338 goto do_flash_read; 339 goto do_flash_read;
@@ -340,7 +341,7 @@ static int jffs2_block_check_erase(struct jffs2_sb_info *c, struct jffs2_erasebl
340 if (retlen < c->sector_size) { 341 if (retlen < c->sector_size) {
341 /* Don't muck about if it won't let us point to the whole erase sector */ 342 /* Don't muck about if it won't let us point to the whole erase sector */
342 D1(printk(KERN_DEBUG "MTD point returned len too short: 0x%zx\n", retlen)); 343 D1(printk(KERN_DEBUG "MTD point returned len too short: 0x%zx\n", retlen));
343 c->mtd->unpoint(c->mtd, ebuf, jeb->offset, retlen); 344 c->mtd->unpoint(c->mtd, jeb->offset, retlen);
344 goto do_flash_read; 345 goto do_flash_read;
345 } 346 }
346 wordebuf = ebuf-sizeof(*wordebuf); 347 wordebuf = ebuf-sizeof(*wordebuf);
@@ -349,7 +350,7 @@ static int jffs2_block_check_erase(struct jffs2_sb_info *c, struct jffs2_erasebl
349 if (*++wordebuf != ~0) 350 if (*++wordebuf != ~0)
350 break; 351 break;
351 } while(--retlen); 352 } while(--retlen);
352 c->mtd->unpoint(c->mtd, ebuf, jeb->offset, c->sector_size); 353 c->mtd->unpoint(c->mtd, jeb->offset, c->sector_size);
353 if (retlen) { 354 if (retlen) {
354 printk(KERN_WARNING "Newly-erased block contained word 0x%lx at offset 0x%08tx\n", 355 printk(KERN_WARNING "Newly-erased block contained word 0x%lx at offset 0x%08tx\n",
355 *wordebuf, jeb->offset + c->sector_size-retlen*sizeof(*wordebuf)); 356 *wordebuf, jeb->offset + c->sector_size-retlen*sizeof(*wordebuf));
diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c
index 3eb1c84b0a33..086c43830221 100644
--- a/fs/jffs2/fs.c
+++ b/fs/jffs2/fs.c
@@ -273,7 +273,7 @@ struct inode *jffs2_iget(struct super_block *sb, unsigned long ino)
273 inode->i_mtime = ITIME(je32_to_cpu(latest_node.mtime)); 273 inode->i_mtime = ITIME(je32_to_cpu(latest_node.mtime));
274 inode->i_ctime = ITIME(je32_to_cpu(latest_node.ctime)); 274 inode->i_ctime = ITIME(je32_to_cpu(latest_node.ctime));
275 275
276 inode->i_nlink = f->inocache->nlink; 276 inode->i_nlink = f->inocache->pino_nlink;
277 277
278 inode->i_blocks = (inode->i_size + 511) >> 9; 278 inode->i_blocks = (inode->i_size + 511) >> 9;
279 279
@@ -286,13 +286,12 @@ struct inode *jffs2_iget(struct super_block *sb, unsigned long ino)
286 case S_IFDIR: 286 case S_IFDIR:
287 { 287 {
288 struct jffs2_full_dirent *fd; 288 struct jffs2_full_dirent *fd;
289 inode->i_nlink = 2; /* parent and '.' */
289 290
290 for (fd=f->dents; fd; fd = fd->next) { 291 for (fd=f->dents; fd; fd = fd->next) {
291 if (fd->type == DT_DIR && fd->ino) 292 if (fd->type == DT_DIR && fd->ino)
292 inc_nlink(inode); 293 inc_nlink(inode);
293 } 294 }
294 /* and '..' */
295 inc_nlink(inode);
296 /* Root dir gets i_nlink 3 for some reason */ 295 /* Root dir gets i_nlink 3 for some reason */
297 if (inode->i_ino == 1) 296 if (inode->i_ino == 1)
298 inc_nlink(inode); 297 inc_nlink(inode);
@@ -586,11 +585,12 @@ void jffs2_gc_release_inode(struct jffs2_sb_info *c,
586} 585}
587 586
588struct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c, 587struct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c,
589 int inum, int nlink) 588 int inum, int unlinked)
590{ 589{
591 struct inode *inode; 590 struct inode *inode;
592 struct jffs2_inode_cache *ic; 591 struct jffs2_inode_cache *ic;
593 if (!nlink) { 592
593 if (unlinked) {
594 /* The inode has zero nlink but its nodes weren't yet marked 594 /* The inode has zero nlink but its nodes weren't yet marked
595 obsolete. This has to be because we're still waiting for 595 obsolete. This has to be because we're still waiting for
596 the final (close() and) iput() to happen. 596 the final (close() and) iput() to happen.
@@ -638,8 +638,8 @@ struct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c,
638 return ERR_CAST(inode); 638 return ERR_CAST(inode);
639 } 639 }
640 if (is_bad_inode(inode)) { 640 if (is_bad_inode(inode)) {
641 printk(KERN_NOTICE "Eep. read_inode() failed for ino #%u. nlink %d\n", 641 printk(KERN_NOTICE "Eep. read_inode() failed for ino #%u. unlinked %d\n",
642 inum, nlink); 642 inum, unlinked);
643 /* NB. This will happen again. We need to do something appropriate here. */ 643 /* NB. This will happen again. We need to do something appropriate here. */
644 iput(inode); 644 iput(inode);
645 return ERR_PTR(-EIO); 645 return ERR_PTR(-EIO);
diff --git a/fs/jffs2/gc.c b/fs/jffs2/gc.c
index bad005664e30..090c556ffed2 100644
--- a/fs/jffs2/gc.c
+++ b/fs/jffs2/gc.c
@@ -161,8 +161,8 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
161 continue; 161 continue;
162 } 162 }
163 163
164 if (!ic->nlink) { 164 if (!ic->pino_nlink) {
165 D1(printk(KERN_DEBUG "Skipping check of ino #%d with nlink zero\n", 165 D1(printk(KERN_DEBUG "Skipping check of ino #%d with nlink/pino zero\n",
166 ic->ino)); 166 ic->ino));
167 spin_unlock(&c->inocache_lock); 167 spin_unlock(&c->inocache_lock);
168 jffs2_xattr_delete_inode(c, ic); 168 jffs2_xattr_delete_inode(c, ic);
@@ -398,10 +398,10 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
398 it's vaguely possible. */ 398 it's vaguely possible. */
399 399
400 inum = ic->ino; 400 inum = ic->ino;
401 nlink = ic->nlink; 401 nlink = ic->pino_nlink;
402 spin_unlock(&c->inocache_lock); 402 spin_unlock(&c->inocache_lock);
403 403
404 f = jffs2_gc_fetch_inode(c, inum, nlink); 404 f = jffs2_gc_fetch_inode(c, inum, !nlink);
405 if (IS_ERR(f)) { 405 if (IS_ERR(f)) {
406 ret = PTR_ERR(f); 406 ret = PTR_ERR(f);
407 goto release_sem; 407 goto release_sem;
diff --git a/fs/jffs2/nodelist.h b/fs/jffs2/nodelist.h
index 8219df6eb6d8..1750445556c3 100644
--- a/fs/jffs2/nodelist.h
+++ b/fs/jffs2/nodelist.h
@@ -177,7 +177,10 @@ struct jffs2_inode_cache {
177#ifdef CONFIG_JFFS2_FS_XATTR 177#ifdef CONFIG_JFFS2_FS_XATTR
178 struct jffs2_xattr_ref *xref; 178 struct jffs2_xattr_ref *xref;
179#endif 179#endif
180 int nlink; 180 uint32_t pino_nlink; /* Directories store parent inode
181 here; other inodes store nlink.
182 Zero always means that it's
183 completely unlinked. */
181}; 184};
182 185
183/* Inode states for 'state' above. We need the 'GC' state to prevent 186/* Inode states for 'state' above. We need the 'GC' state to prevent
diff --git a/fs/jffs2/nodemgmt.c b/fs/jffs2/nodemgmt.c
index 9df8f3ef20df..a9bf9603c1ba 100644
--- a/fs/jffs2/nodemgmt.c
+++ b/fs/jffs2/nodemgmt.c
@@ -709,7 +709,7 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
709 break; 709 break;
710#endif 710#endif
711 default: 711 default:
712 if (ic->nodes == (void *)ic && ic->nlink == 0) 712 if (ic->nodes == (void *)ic && ic->pino_nlink == 0)
713 jffs2_del_ino_cache(c, ic); 713 jffs2_del_ino_cache(c, ic);
714 break; 714 break;
715 } 715 }
diff --git a/fs/jffs2/os-linux.h b/fs/jffs2/os-linux.h
index 1b10d2594092..2cc866cf134f 100644
--- a/fs/jffs2/os-linux.h
+++ b/fs/jffs2/os-linux.h
@@ -187,7 +187,7 @@ int jffs2_do_fill_super(struct super_block *sb, void *data, int silent);
187void jffs2_gc_release_inode(struct jffs2_sb_info *c, 187void jffs2_gc_release_inode(struct jffs2_sb_info *c,
188 struct jffs2_inode_info *f); 188 struct jffs2_inode_info *f);
189struct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c, 189struct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c,
190 int inum, int nlink); 190 int inum, int unlinked);
191 191
192unsigned char *jffs2_gc_fetch_page(struct jffs2_sb_info *c, 192unsigned char *jffs2_gc_fetch_page(struct jffs2_sb_info *c,
193 struct jffs2_inode_info *f, 193 struct jffs2_inode_info *f,
diff --git a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c
index 4cb4d76de07f..6ca08ad887c0 100644
--- a/fs/jffs2/readinode.c
+++ b/fs/jffs2/readinode.c
@@ -63,10 +63,11 @@ static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info
63 /* TODO: instead, incapsulate point() stuff to jffs2_flash_read(), 63 /* TODO: instead, incapsulate point() stuff to jffs2_flash_read(),
64 * adding and jffs2_flash_read_end() interface. */ 64 * adding and jffs2_flash_read_end() interface. */
65 if (c->mtd->point) { 65 if (c->mtd->point) {
66 err = c->mtd->point(c->mtd, ofs, len, &retlen, &buffer); 66 err = c->mtd->point(c->mtd, ofs, len, &retlen,
67 (void **)&buffer, NULL);
67 if (!err && retlen < len) { 68 if (!err && retlen < len) {
68 JFFS2_WARNING("MTD point returned len too short: %zu instead of %u.\n", retlen, tn->csize); 69 JFFS2_WARNING("MTD point returned len too short: %zu instead of %u.\n", retlen, tn->csize);
69 c->mtd->unpoint(c->mtd, buffer, ofs, retlen); 70 c->mtd->unpoint(c->mtd, ofs, retlen);
70 } else if (err) 71 } else if (err)
71 JFFS2_WARNING("MTD point failed: error code %d.\n", err); 72 JFFS2_WARNING("MTD point failed: error code %d.\n", err);
72 else 73 else
@@ -100,7 +101,7 @@ static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info
100 kfree(buffer); 101 kfree(buffer);
101#ifndef __ECOS 102#ifndef __ECOS
102 else 103 else
103 c->mtd->unpoint(c->mtd, buffer, ofs, len); 104 c->mtd->unpoint(c->mtd, ofs, len);
104#endif 105#endif
105 106
106 if (crc != tn->data_crc) { 107 if (crc != tn->data_crc) {
@@ -136,7 +137,7 @@ free_out:
136 kfree(buffer); 137 kfree(buffer);
137#ifndef __ECOS 138#ifndef __ECOS
138 else 139 else
139 c->mtd->unpoint(c->mtd, buffer, ofs, len); 140 c->mtd->unpoint(c->mtd, ofs, len);
140#endif 141#endif
141 return err; 142 return err;
142} 143}
@@ -1123,7 +1124,8 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
1123 size_t retlen; 1124 size_t retlen;
1124 int ret; 1125 int ret;
1125 1126
1126 dbg_readinode("ino #%u nlink is %d\n", f->inocache->ino, f->inocache->nlink); 1127 dbg_readinode("ino #%u pino/nlink is %d\n", f->inocache->ino,
1128 f->inocache->pino_nlink);
1127 1129
1128 memset(&rii, 0, sizeof(rii)); 1130 memset(&rii, 0, sizeof(rii));
1129 1131
@@ -1358,7 +1360,7 @@ int jffs2_do_read_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
1358 } 1360 }
1359 dbg_readinode("creating inocache for root inode\n"); 1361 dbg_readinode("creating inocache for root inode\n");
1360 memset(f->inocache, 0, sizeof(struct jffs2_inode_cache)); 1362 memset(f->inocache, 0, sizeof(struct jffs2_inode_cache));
1361 f->inocache->ino = f->inocache->nlink = 1; 1363 f->inocache->ino = f->inocache->pino_nlink = 1;
1362 f->inocache->nodes = (struct jffs2_raw_node_ref *)f->inocache; 1364 f->inocache->nodes = (struct jffs2_raw_node_ref *)f->inocache;
1363 f->inocache->state = INO_STATE_READING; 1365 f->inocache->state = INO_STATE_READING;
1364 jffs2_add_ino_cache(c, f->inocache); 1366 jffs2_add_ino_cache(c, f->inocache);
@@ -1401,7 +1403,7 @@ void jffs2_do_clear_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f)
1401 jffs2_clear_acl(f); 1403 jffs2_clear_acl(f);
1402 jffs2_xattr_delete_inode(c, f->inocache); 1404 jffs2_xattr_delete_inode(c, f->inocache);
1403 mutex_lock(&f->sem); 1405 mutex_lock(&f->sem);
1404 deleted = f->inocache && !f->inocache->nlink; 1406 deleted = f->inocache && !f->inocache->pino_nlink;
1405 1407
1406 if (f->inocache && f->inocache->state != INO_STATE_CHECKING) 1408 if (f->inocache && f->inocache->state != INO_STATE_CHECKING)
1407 jffs2_set_inocache_state(c, f->inocache, INO_STATE_CLEARING); 1409 jffs2_set_inocache_state(c, f->inocache, INO_STATE_CLEARING);
diff --git a/fs/jffs2/scan.c b/fs/jffs2/scan.c
index 272872d27fd5..1d437de1e9a8 100644
--- a/fs/jffs2/scan.c
+++ b/fs/jffs2/scan.c
@@ -97,11 +97,12 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
97 size_t pointlen; 97 size_t pointlen;
98 98
99 if (c->mtd->point) { 99 if (c->mtd->point) {
100 ret = c->mtd->point (c->mtd, 0, c->mtd->size, &pointlen, &flashbuf); 100 ret = c->mtd->point(c->mtd, 0, c->mtd->size, &pointlen,
101 (void **)&flashbuf, NULL);
101 if (!ret && pointlen < c->mtd->size) { 102 if (!ret && pointlen < c->mtd->size) {
102 /* Don't muck about if it won't let us point to the whole flash */ 103 /* Don't muck about if it won't let us point to the whole flash */
103 D1(printk(KERN_DEBUG "MTD point returned len too short: 0x%zx\n", pointlen)); 104 D1(printk(KERN_DEBUG "MTD point returned len too short: 0x%zx\n", pointlen));
104 c->mtd->unpoint(c->mtd, flashbuf, 0, pointlen); 105 c->mtd->unpoint(c->mtd, 0, pointlen);
105 flashbuf = NULL; 106 flashbuf = NULL;
106 } 107 }
107 if (ret) 108 if (ret)
@@ -267,7 +268,7 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
267 kfree(flashbuf); 268 kfree(flashbuf);
268#ifndef __ECOS 269#ifndef __ECOS
269 else 270 else
270 c->mtd->unpoint(c->mtd, flashbuf, 0, c->mtd->size); 271 c->mtd->unpoint(c->mtd, 0, c->mtd->size);
271#endif 272#endif
272 if (s) 273 if (s)
273 kfree(s); 274 kfree(s);
@@ -940,7 +941,7 @@ struct jffs2_inode_cache *jffs2_scan_make_ino_cache(struct jffs2_sb_info *c, uin
940 ic->nodes = (void *)ic; 941 ic->nodes = (void *)ic;
941 jffs2_add_ino_cache(c, ic); 942 jffs2_add_ino_cache(c, ic);
942 if (ino == 1) 943 if (ino == 1)
943 ic->nlink = 1; 944 ic->pino_nlink = 1;
944 return ic; 945 return ic;
945} 946}
946 947
diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c
index f3353df178e7..7da69eae49e4 100644
--- a/fs/jffs2/super.c
+++ b/fs/jffs2/super.c
@@ -31,11 +31,12 @@ static struct kmem_cache *jffs2_inode_cachep;
31 31
32static struct inode *jffs2_alloc_inode(struct super_block *sb) 32static struct inode *jffs2_alloc_inode(struct super_block *sb)
33{ 33{
34 struct jffs2_inode_info *ei; 34 struct jffs2_inode_info *f;
35 ei = (struct jffs2_inode_info *)kmem_cache_alloc(jffs2_inode_cachep, GFP_KERNEL); 35
36 if (!ei) 36 f = kmem_cache_alloc(jffs2_inode_cachep, GFP_KERNEL);
37 if (!f)
37 return NULL; 38 return NULL;
38 return &ei->vfs_inode; 39 return &f->vfs_inode;
39} 40}
40 41
41static void jffs2_destroy_inode(struct inode *inode) 42static void jffs2_destroy_inode(struct inode *inode)
@@ -45,10 +46,10 @@ static void jffs2_destroy_inode(struct inode *inode)
45 46
46static void jffs2_i_init_once(struct kmem_cache *cachep, void *foo) 47static void jffs2_i_init_once(struct kmem_cache *cachep, void *foo)
47{ 48{
48 struct jffs2_inode_info *ei = (struct jffs2_inode_info *) foo; 49 struct jffs2_inode_info *f = foo;
49 50
50 mutex_init(&ei->sem); 51 mutex_init(&f->sem);
51 inode_init_once(&ei->vfs_inode); 52 inode_init_once(&f->vfs_inode);
52} 53}
53 54
54static int jffs2_sync_fs(struct super_block *sb, int wait) 55static int jffs2_sync_fs(struct super_block *sb, int wait)
diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
index 8de52b607678..0e78b00035e4 100644
--- a/fs/jffs2/wbuf.c
+++ b/fs/jffs2/wbuf.c
@@ -494,7 +494,7 @@ static void jffs2_wbuf_recover(struct jffs2_sb_info *c)
494 /* If it's an in-core inode, then we have to adjust any 494 /* If it's an in-core inode, then we have to adjust any
495 full_dirent or full_dnode structure to point to the 495 full_dirent or full_dnode structure to point to the
496 new version instead of the old */ 496 new version instead of the old */
497 f = jffs2_gc_fetch_inode(c, ic->ino, ic->nlink); 497 f = jffs2_gc_fetch_inode(c, ic->ino, !ic->pino_nlink);
498 if (IS_ERR(f)) { 498 if (IS_ERR(f)) {
499 /* Should never happen; it _must_ be present */ 499 /* Should never happen; it _must_ be present */
500 JFFS2_ERROR("Failed to iget() ino #%u, err %ld\n", 500 JFFS2_ERROR("Failed to iget() ino #%u, err %ld\n",
diff --git a/fs/jffs2/write.c b/fs/jffs2/write.c
index 665fce9797d3..ca29440e9435 100644
--- a/fs/jffs2/write.c
+++ b/fs/jffs2/write.c
@@ -19,7 +19,8 @@
19#include "compr.h" 19#include "compr.h"
20 20
21 21
22int jffs2_do_new_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, uint32_t mode, struct jffs2_raw_inode *ri) 22int jffs2_do_new_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
23 uint32_t mode, struct jffs2_raw_inode *ri)
23{ 24{
24 struct jffs2_inode_cache *ic; 25 struct jffs2_inode_cache *ic;
25 26
@@ -31,7 +32,7 @@ int jffs2_do_new_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, uint
31 memset(ic, 0, sizeof(*ic)); 32 memset(ic, 0, sizeof(*ic));
32 33
33 f->inocache = ic; 34 f->inocache = ic;
34 f->inocache->nlink = 1; 35 f->inocache->pino_nlink = 1; /* Will be overwritten shortly for directories */
35 f->inocache->nodes = (struct jffs2_raw_node_ref *)f->inocache; 36 f->inocache->nodes = (struct jffs2_raw_node_ref *)f->inocache;
36 f->inocache->state = INO_STATE_PRESENT; 37 f->inocache->state = INO_STATE_PRESENT;
37 38
@@ -438,10 +439,10 @@ int jffs2_do_create(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f, str
438 ret = jffs2_reserve_space(c, sizeof(*ri), &alloclen, ALLOC_NORMAL, 439 ret = jffs2_reserve_space(c, sizeof(*ri), &alloclen, ALLOC_NORMAL,
439 JFFS2_SUMMARY_INODE_SIZE); 440 JFFS2_SUMMARY_INODE_SIZE);
440 D1(printk(KERN_DEBUG "jffs2_do_create(): reserved 0x%x bytes\n", alloclen)); 441 D1(printk(KERN_DEBUG "jffs2_do_create(): reserved 0x%x bytes\n", alloclen));
441 if (ret) { 442 if (ret)
442 mutex_unlock(&f->sem);
443 return ret; 443 return ret;
444 } 444
445 mutex_lock(&f->sem);
445 446
446 ri->data_crc = cpu_to_je32(0); 447 ri->data_crc = cpu_to_je32(0);
447 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); 448 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
@@ -635,9 +636,9 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
635 jffs2_mark_node_obsolete(c, fd->raw); 636 jffs2_mark_node_obsolete(c, fd->raw);
636 jffs2_free_full_dirent(fd); 637 jffs2_free_full_dirent(fd);
637 } 638 }
638 } 639 dead_f->inocache->pino_nlink = 0;
639 640 } else
640 dead_f->inocache->nlink--; 641 dead_f->inocache->pino_nlink--;
641 /* NB: Caller must set inode nlink if appropriate */ 642 /* NB: Caller must set inode nlink if appropriate */
642 mutex_unlock(&dead_f->sem); 643 mutex_unlock(&dead_f->sem);
643 } 644 }
diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c
index e48665984cb3..082e844ab2db 100644
--- a/fs/jffs2/xattr.c
+++ b/fs/jffs2/xattr.c
@@ -82,7 +82,7 @@ static int is_xattr_datum_unchecked(struct jffs2_sb_info *c, struct jffs2_xattr_
82static void unload_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd) 82static void unload_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
83{ 83{
84 /* must be called under down_write(xattr_sem) */ 84 /* must be called under down_write(xattr_sem) */
85 D1(dbg_xattr("%s: xid=%u, version=%u\n", __FUNCTION__, xd->xid, xd->version)); 85 D1(dbg_xattr("%s: xid=%u, version=%u\n", __func__, xd->xid, xd->version));
86 if (xd->xname) { 86 if (xd->xname) {
87 c->xdatum_mem_usage -= (xd->name_len + 1 + xd->value_len); 87 c->xdatum_mem_usage -= (xd->name_len + 1 + xd->value_len);
88 kfree(xd->xname); 88 kfree(xd->xname);
@@ -592,7 +592,7 @@ void jffs2_xattr_delete_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache
592 When an inode with XATTR is removed, those XATTRs must be removed. */ 592 When an inode with XATTR is removed, those XATTRs must be removed. */
593 struct jffs2_xattr_ref *ref, *_ref; 593 struct jffs2_xattr_ref *ref, *_ref;
594 594
595 if (!ic || ic->nlink > 0) 595 if (!ic || ic->pino_nlink > 0)
596 return; 596 return;
597 597
598 down_write(&c->xattr_sem); 598 down_write(&c->xattr_sem);
@@ -829,7 +829,7 @@ void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c)
829 ref->xd and ref->ic are not valid yet. */ 829 ref->xd and ref->ic are not valid yet. */
830 xd = jffs2_find_xattr_datum(c, ref->xid); 830 xd = jffs2_find_xattr_datum(c, ref->xid);
831 ic = jffs2_get_ino_cache(c, ref->ino); 831 ic = jffs2_get_ino_cache(c, ref->ino);
832 if (!xd || !ic || !ic->nlink) { 832 if (!xd || !ic || !ic->pino_nlink) {
833 dbg_xattr("xref(ino=%u, xid=%u, xseqno=%u) is orphan.\n", 833 dbg_xattr("xref(ino=%u, xid=%u, xseqno=%u) is orphan.\n",
834 ref->ino, ref->xid, ref->xseqno); 834 ref->ino, ref->xid, ref->xseqno);
835 ref->xseqno |= XREF_DELETE_MARKER; 835 ref->xseqno |= XREF_DELETE_MARKER;
@@ -1252,7 +1252,7 @@ int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_
1252 rc = jffs2_reserve_space_gc(c, totlen, &length, JFFS2_SUMMARY_XREF_SIZE); 1252 rc = jffs2_reserve_space_gc(c, totlen, &length, JFFS2_SUMMARY_XREF_SIZE);
1253 if (rc) { 1253 if (rc) {
1254 JFFS2_WARNING("%s: jffs2_reserve_space_gc() = %d, request = %u\n", 1254 JFFS2_WARNING("%s: jffs2_reserve_space_gc() = %d, request = %u\n",
1255 __FUNCTION__, rc, totlen); 1255 __func__, rc, totlen);
1256 rc = rc ? rc : -EBADFD; 1256 rc = rc ? rc : -EBADFD;
1257 goto out; 1257 goto out;
1258 } 1258 }
diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
index 40b16f23e49a..5df517b81f3f 100644
--- a/fs/lockd/clntproc.c
+++ b/fs/lockd/clntproc.c
@@ -573,7 +573,7 @@ again:
573 /* Ensure the resulting lock will get added to granted list */ 573 /* Ensure the resulting lock will get added to granted list */
574 fl->fl_flags |= FL_SLEEP; 574 fl->fl_flags |= FL_SLEEP;
575 if (do_vfs_lock(fl) < 0) 575 if (do_vfs_lock(fl) < 0)
576 printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __FUNCTION__); 576 printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __func__);
577 up_read(&host->h_rwsem); 577 up_read(&host->h_rwsem);
578 fl->fl_flags = fl_flags; 578 fl->fl_flags = fl_flags;
579 status = 0; 579 status = 0;
diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index 4d81553d2948..81aca859bfde 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -752,7 +752,7 @@ nlmsvc_grant_blocked(struct nlm_block *block)
752 return; 752 return;
753 default: 753 default:
754 printk(KERN_WARNING "lockd: unexpected error %d in %s!\n", 754 printk(KERN_WARNING "lockd: unexpected error %d in %s!\n",
755 -error, __FUNCTION__); 755 -error, __func__);
756 nlmsvc_insert_block(block, 10 * HZ); 756 nlmsvc_insert_block(block, 10 * HZ);
757 nlmsvc_release_block(block); 757 nlmsvc_release_block(block);
758 return; 758 return;
diff --git a/fs/locks.c b/fs/locks.c
index 44d9a6a7ec50..663c069b59b3 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -116,6 +116,7 @@
116 116
117#include <linux/capability.h> 117#include <linux/capability.h>
118#include <linux/file.h> 118#include <linux/file.h>
119#include <linux/fdtable.h>
119#include <linux/fs.h> 120#include <linux/fs.h>
120#include <linux/init.h> 121#include <linux/init.h>
121#include <linux/module.h> 122#include <linux/module.h>
diff --git a/fs/msdos/namei.c b/fs/msdos/namei.c
index 2d4358c59f68..05ff4f1d7026 100644
--- a/fs/msdos/namei.c
+++ b/fs/msdos/namei.c
@@ -609,7 +609,7 @@ error_inode:
609 if (corrupt < 0) { 609 if (corrupt < 0) {
610 fat_fs_panic(new_dir->i_sb, 610 fat_fs_panic(new_dir->i_sb,
611 "%s: Filesystem corrupted (i_pos %lld)", 611 "%s: Filesystem corrupted (i_pos %lld)",
612 __FUNCTION__, sinfo.i_pos); 612 __func__, sinfo.i_pos);
613 } 613 }
614 goto out; 614 goto out;
615} 615}
diff --git a/fs/namespace.c b/fs/namespace.c
index 061e5edb4d27..4fc302c2a0e0 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -2329,10 +2329,10 @@ void __init mnt_init(void)
2329 err = sysfs_init(); 2329 err = sysfs_init();
2330 if (err) 2330 if (err)
2331 printk(KERN_WARNING "%s: sysfs_init error: %d\n", 2331 printk(KERN_WARNING "%s: sysfs_init error: %d\n",
2332 __FUNCTION__, err); 2332 __func__, err);
2333 fs_kobj = kobject_create_and_add("fs", NULL); 2333 fs_kobj = kobject_create_and_add("fs", NULL);
2334 if (!fs_kobj) 2334 if (!fs_kobj)
2335 printk(KERN_WARNING "%s: kobj create error\n", __FUNCTION__); 2335 printk(KERN_WARNING "%s: kobj create error\n", __func__);
2336 init_rootfs(); 2336 init_rootfs();
2337 init_mount_tree(); 2337 init_mount_tree();
2338} 2338}
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index fa220dc74609..7226a506f3ca 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -1575,6 +1575,11 @@ static int nfs_compare_super(struct super_block *sb, void *data)
1575 return nfs_compare_mount_options(sb, server, mntflags); 1575 return nfs_compare_mount_options(sb, server, mntflags);
1576} 1576}
1577 1577
1578static int nfs_bdi_register(struct nfs_server *server)
1579{
1580 return bdi_register_dev(&server->backing_dev_info, server->s_dev);
1581}
1582
1578static int nfs_get_sb(struct file_system_type *fs_type, 1583static int nfs_get_sb(struct file_system_type *fs_type,
1579 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt) 1584 int flags, const char *dev_name, void *raw_data, struct vfsmount *mnt)
1580{ 1585{
@@ -1617,6 +1622,10 @@ static int nfs_get_sb(struct file_system_type *fs_type,
1617 if (s->s_fs_info != server) { 1622 if (s->s_fs_info != server) {
1618 nfs_free_server(server); 1623 nfs_free_server(server);
1619 server = NULL; 1624 server = NULL;
1625 } else {
1626 error = nfs_bdi_register(server);
1627 if (error)
1628 goto error_splat_super;
1620 } 1629 }
1621 1630
1622 if (!s->s_root) { 1631 if (!s->s_root) {
@@ -1664,6 +1673,7 @@ static void nfs_kill_super(struct super_block *s)
1664{ 1673{
1665 struct nfs_server *server = NFS_SB(s); 1674 struct nfs_server *server = NFS_SB(s);
1666 1675
1676 bdi_unregister(&server->backing_dev_info);
1667 kill_anon_super(s); 1677 kill_anon_super(s);
1668 nfs_free_server(server); 1678 nfs_free_server(server);
1669} 1679}
@@ -1708,6 +1718,10 @@ static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1708 if (s->s_fs_info != server) { 1718 if (s->s_fs_info != server) {
1709 nfs_free_server(server); 1719 nfs_free_server(server);
1710 server = NULL; 1720 server = NULL;
1721 } else {
1722 error = nfs_bdi_register(server);
1723 if (error)
1724 goto error_splat_super;
1711 } 1725 }
1712 1726
1713 if (!s->s_root) { 1727 if (!s->s_root) {
@@ -1984,6 +1998,10 @@ static int nfs4_get_sb(struct file_system_type *fs_type,
1984 if (s->s_fs_info != server) { 1998 if (s->s_fs_info != server) {
1985 nfs_free_server(server); 1999 nfs_free_server(server);
1986 server = NULL; 2000 server = NULL;
2001 } else {
2002 error = nfs_bdi_register(server);
2003 if (error)
2004 goto error_splat_super;
1987 } 2005 }
1988 2006
1989 if (!s->s_root) { 2007 if (!s->s_root) {
@@ -2070,6 +2088,10 @@ static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
2070 if (s->s_fs_info != server) { 2088 if (s->s_fs_info != server) {
2071 nfs_free_server(server); 2089 nfs_free_server(server);
2072 server = NULL; 2090 server = NULL;
2091 } else {
2092 error = nfs_bdi_register(server);
2093 if (error)
2094 goto error_splat_super;
2073 } 2095 }
2074 2096
2075 if (!s->s_root) { 2097 if (!s->s_root) {
@@ -2149,6 +2171,10 @@ static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
2149 if (s->s_fs_info != server) { 2171 if (s->s_fs_info != server) {
2150 nfs_free_server(server); 2172 nfs_free_server(server);
2151 server = NULL; 2173 server = NULL;
2174 } else {
2175 error = nfs_bdi_register(server);
2176 if (error)
2177 goto error_splat_super;
2152 } 2178 }
2153 2179
2154 if (!s->s_root) { 2180 if (!s->s_root) {
diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c
index 562abf3380d0..0b3ffa9840c2 100644
--- a/fs/nfsd/nfs4callback.c
+++ b/fs/nfsd/nfs4callback.c
@@ -104,7 +104,7 @@ xdr_writemem(__be32 *p, const void *ptr, int nbytes)
104} while (0) 104} while (0)
105#define RESERVE_SPACE(nbytes) do { \ 105#define RESERVE_SPACE(nbytes) do { \
106 p = xdr_reserve_space(xdr, nbytes); \ 106 p = xdr_reserve_space(xdr, nbytes); \
107 if (!p) dprintk("NFSD: RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __FUNCTION__); \ 107 if (!p) dprintk("NFSD: RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __func__); \
108 BUG_ON(!p); \ 108 BUG_ON(!p); \
109} while (0) 109} while (0)
110 110
@@ -134,7 +134,7 @@ xdr_error: \
134 p = xdr_inline_decode(xdr, nbytes); \ 134 p = xdr_inline_decode(xdr, nbytes); \
135 if (!p) { \ 135 if (!p) { \
136 dprintk("NFSD: %s: reply buffer overflowed in line %d.\n", \ 136 dprintk("NFSD: %s: reply buffer overflowed in line %d.\n", \
137 __FUNCTION__, __LINE__); \ 137 __func__, __LINE__); \
138 return -EIO; \ 138 return -EIO; \
139 } \ 139 } \
140} while (0) 140} while (0)
diff --git a/fs/ntfs/debug.h b/fs/ntfs/debug.h
index 8ac37c33d127..5e6724c1afd1 100644
--- a/fs/ntfs/debug.h
+++ b/fs/ntfs/debug.h
@@ -45,7 +45,7 @@ static void ntfs_debug(const char *f, ...);
45extern void __ntfs_debug (const char *file, int line, const char *function, 45extern void __ntfs_debug (const char *file, int line, const char *function,
46 const char *format, ...) __attribute__ ((format (printf, 4, 5))); 46 const char *format, ...) __attribute__ ((format (printf, 4, 5)));
47#define ntfs_debug(f, a...) \ 47#define ntfs_debug(f, a...) \
48 __ntfs_debug(__FILE__, __LINE__, __FUNCTION__, f, ##a) 48 __ntfs_debug(__FILE__, __LINE__, __func__, f, ##a)
49 49
50extern void ntfs_debug_dump_runlist(const runlist_element *rl); 50extern void ntfs_debug_dump_runlist(const runlist_element *rl);
51 51
@@ -58,10 +58,10 @@ extern void ntfs_debug_dump_runlist(const runlist_element *rl);
58 58
59extern void __ntfs_warning(const char *function, const struct super_block *sb, 59extern void __ntfs_warning(const char *function, const struct super_block *sb,
60 const char *fmt, ...) __attribute__ ((format (printf, 3, 4))); 60 const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
61#define ntfs_warning(sb, f, a...) __ntfs_warning(__FUNCTION__, sb, f, ##a) 61#define ntfs_warning(sb, f, a...) __ntfs_warning(__func__, sb, f, ##a)
62 62
63extern void __ntfs_error(const char *function, const struct super_block *sb, 63extern void __ntfs_error(const char *function, const struct super_block *sb,
64 const char *fmt, ...) __attribute__ ((format (printf, 3, 4))); 64 const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
65#define ntfs_error(sb, f, a...) __ntfs_error(__FUNCTION__, sb, f, ##a) 65#define ntfs_error(sb, f, a...) __ntfs_error(__func__, sb, f, ##a)
66 66
67#endif /* _LINUX_NTFS_DEBUG_H */ 67#endif /* _LINUX_NTFS_DEBUG_H */
diff --git a/fs/ocfs2/cluster/sys.c b/fs/ocfs2/cluster/sys.c
index 98429fd68499..bc702dab5d1f 100644
--- a/fs/ocfs2/cluster/sys.c
+++ b/fs/ocfs2/cluster/sys.c
@@ -65,7 +65,7 @@ int o2cb_sys_init(void)
65{ 65{
66 int ret; 66 int ret;
67 67
68 o2cb_kset = kset_create_and_add("o2cb", NULL, NULL); 68 o2cb_kset = kset_create_and_add("o2cb", NULL, fs_kobj);
69 if (!o2cb_kset) 69 if (!o2cb_kset)
70 return -ENOMEM; 70 return -ENOMEM;
71 71
diff --git a/fs/ocfs2/dlm/dlmdebug.c b/fs/ocfs2/dlm/dlmdebug.c
index 5f6d858770a2..1b81dcba175d 100644
--- a/fs/ocfs2/dlm/dlmdebug.c
+++ b/fs/ocfs2/dlm/dlmdebug.c
@@ -44,7 +44,8 @@
44#define MLOG_MASK_PREFIX ML_DLM 44#define MLOG_MASK_PREFIX ML_DLM
45#include "cluster/masklog.h" 45#include "cluster/masklog.h"
46 46
47int stringify_lockname(const char *lockname, int locklen, char *buf, int len); 47static int stringify_lockname(const char *lockname, int locklen, char *buf,
48 int len);
48 49
49void dlm_print_one_lock_resource(struct dlm_lock_resource *res) 50void dlm_print_one_lock_resource(struct dlm_lock_resource *res)
50{ 51{
@@ -251,7 +252,8 @@ EXPORT_SYMBOL_GPL(dlm_errname);
251 * 252 *
252 * For more on lockname formats, please refer to dlmglue.c and ocfs2_lockid.h. 253 * For more on lockname formats, please refer to dlmglue.c and ocfs2_lockid.h.
253 */ 254 */
254int stringify_lockname(const char *lockname, int locklen, char *buf, int len) 255static int stringify_lockname(const char *lockname, int locklen, char *buf,
256 int len)
255{ 257{
256 int out = 0; 258 int out = 0;
257 __be64 inode_blkno_be; 259 __be64 inode_blkno_be;
@@ -368,7 +370,7 @@ static void dlm_debug_free(struct kref *kref)
368 kfree(dc); 370 kfree(dc);
369} 371}
370 372
371void dlm_debug_put(struct dlm_debug_ctxt *dc) 373static void dlm_debug_put(struct dlm_debug_ctxt *dc)
372{ 374{
373 if (dc) 375 if (dc)
374 kref_put(&dc->debug_refcnt, dlm_debug_free); 376 kref_put(&dc->debug_refcnt, dlm_debug_free);
diff --git a/fs/ocfs2/dlm/dlmfs.c b/fs/ocfs2/dlm/dlmfs.c
index 61a000f8524c..e48aba698b77 100644
--- a/fs/ocfs2/dlm/dlmfs.c
+++ b/fs/ocfs2/dlm/dlmfs.c
@@ -327,7 +327,7 @@ clear_fields:
327 327
328static struct backing_dev_info dlmfs_backing_dev_info = { 328static struct backing_dev_info dlmfs_backing_dev_info = {
329 .ra_pages = 0, /* No readahead */ 329 .ra_pages = 0, /* No readahead */
330 .capabilities = BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_WRITEBACK, 330 .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK,
331}; 331};
332 332
333static struct inode *dlmfs_get_root_inode(struct super_block *sb) 333static struct inode *dlmfs_get_root_inode(struct super_block *sb)
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index 9154c82d3258..57e0d30cde98 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -1048,6 +1048,10 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
1048 mlog_entry("(0x%p, '%.*s')\n", dentry, 1048 mlog_entry("(0x%p, '%.*s')\n", dentry,
1049 dentry->d_name.len, dentry->d_name.name); 1049 dentry->d_name.len, dentry->d_name.name);
1050 1050
1051 /* ensuring we don't even attempt to truncate a symlink */
1052 if (S_ISLNK(inode->i_mode))
1053 attr->ia_valid &= ~ATTR_SIZE;
1054
1051 if (attr->ia_valid & ATTR_MODE) 1055 if (attr->ia_valid & ATTR_MODE)
1052 mlog(0, "mode change: %d\n", attr->ia_mode); 1056 mlog(0, "mode change: %d\n", attr->ia_mode);
1053 if (attr->ia_valid & ATTR_UID) 1057 if (attr->ia_valid & ATTR_UID)
diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
index ce0dc147602a..be774bdc8b36 100644
--- a/fs/ocfs2/localalloc.c
+++ b/fs/ocfs2/localalloc.c
@@ -260,7 +260,7 @@ void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb)
260 bh = osb->local_alloc_bh; 260 bh = osb->local_alloc_bh;
261 alloc = (struct ocfs2_dinode *) bh->b_data; 261 alloc = (struct ocfs2_dinode *) bh->b_data;
262 262
263 alloc_copy = kmalloc(bh->b_size, GFP_KERNEL); 263 alloc_copy = kmalloc(bh->b_size, GFP_NOFS);
264 if (!alloc_copy) { 264 if (!alloc_copy) {
265 status = -ENOMEM; 265 status = -ENOMEM;
266 goto out_commit; 266 goto out_commit;
@@ -931,7 +931,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
931 * local alloc shutdown won't try to double free main bitmap 931 * local alloc shutdown won't try to double free main bitmap
932 * bits. Make a copy so the sync function knows which bits to 932 * bits. Make a copy so the sync function knows which bits to
933 * free. */ 933 * free. */
934 alloc_copy = kmalloc(osb->local_alloc_bh->b_size, GFP_KERNEL); 934 alloc_copy = kmalloc(osb->local_alloc_bh->b_size, GFP_NOFS);
935 if (!alloc_copy) { 935 if (!alloc_copy) {
936 status = -ENOMEM; 936 status = -ENOMEM;
937 mlog_errno(status); 937 mlog_errno(status);
diff --git a/fs/ocfs2/stack_o2cb.c b/fs/ocfs2/stack_o2cb.c
index ac1d74c63bf5..bbd1667aa7d3 100644
--- a/fs/ocfs2/stack_o2cb.c
+++ b/fs/ocfs2/stack_o2cb.c
@@ -385,7 +385,7 @@ static int o2cb_cluster_this_node(unsigned int *node)
385 return 0; 385 return 0;
386} 386}
387 387
388struct ocfs2_stack_operations o2cb_stack_ops = { 388static struct ocfs2_stack_operations o2cb_stack_ops = {
389 .connect = o2cb_cluster_connect, 389 .connect = o2cb_cluster_connect,
390 .disconnect = o2cb_cluster_disconnect, 390 .disconnect = o2cb_cluster_disconnect,
391 .hangup = o2cb_cluster_hangup, 391 .hangup = o2cb_cluster_hangup,
diff --git a/fs/ocfs2/stack_user.c b/fs/ocfs2/stack_user.c
index 7428663f9cbb..b503772cd0ec 100644
--- a/fs/ocfs2/stack_user.c
+++ b/fs/ocfs2/stack_user.c
@@ -635,7 +635,7 @@ static const struct file_operations ocfs2_control_fops = {
635 .owner = THIS_MODULE, 635 .owner = THIS_MODULE,
636}; 636};
637 637
638struct miscdevice ocfs2_control_device = { 638static struct miscdevice ocfs2_control_device = {
639 .minor = MISC_DYNAMIC_MINOR, 639 .minor = MISC_DYNAMIC_MINOR,
640 .name = "ocfs2_control", 640 .name = "ocfs2_control",
641 .fops = &ocfs2_control_fops, 641 .fops = &ocfs2_control_fops,
diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
index 7134007ba22f..ba9dbb51d25b 100644
--- a/fs/ocfs2/symlink.c
+++ b/fs/ocfs2/symlink.c
@@ -167,9 +167,11 @@ const struct inode_operations ocfs2_symlink_inode_operations = {
167 .readlink = page_readlink, 167 .readlink = page_readlink,
168 .follow_link = ocfs2_follow_link, 168 .follow_link = ocfs2_follow_link,
169 .getattr = ocfs2_getattr, 169 .getattr = ocfs2_getattr,
170 .setattr = ocfs2_setattr,
170}; 171};
171const struct inode_operations ocfs2_fast_symlink_inode_operations = { 172const struct inode_operations ocfs2_fast_symlink_inode_operations = {
172 .readlink = ocfs2_readlink, 173 .readlink = ocfs2_readlink,
173 .follow_link = ocfs2_follow_link, 174 .follow_link = ocfs2_follow_link,
174 .getattr = ocfs2_getattr, 175 .getattr = ocfs2_getattr,
176 .setattr = ocfs2_setattr,
175}; 177};
diff --git a/fs/open.c b/fs/open.c
index 7af1f05d5978..a1450086e92f 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -7,6 +7,7 @@
7#include <linux/string.h> 7#include <linux/string.h>
8#include <linux/mm.h> 8#include <linux/mm.h>
9#include <linux/file.h> 9#include <linux/file.h>
10#include <linux/fdtable.h>
10#include <linux/quotaops.h> 11#include <linux/quotaops.h>
11#include <linux/fsnotify.h> 12#include <linux/fsnotify.h>
12#include <linux/module.h> 13#include <linux/module.h>
diff --git a/fs/partitions/ldm.c b/fs/partitions/ldm.c
index e7dd1d4e3473..0fdda2e8a4cc 100644
--- a/fs/partitions/ldm.c
+++ b/fs/partitions/ldm.c
@@ -41,12 +41,12 @@
41#ifndef CONFIG_LDM_DEBUG 41#ifndef CONFIG_LDM_DEBUG
42#define ldm_debug(...) do {} while (0) 42#define ldm_debug(...) do {} while (0)
43#else 43#else
44#define ldm_debug(f, a...) _ldm_printk (KERN_DEBUG, __FUNCTION__, f, ##a) 44#define ldm_debug(f, a...) _ldm_printk (KERN_DEBUG, __func__, f, ##a)
45#endif 45#endif
46 46
47#define ldm_crit(f, a...) _ldm_printk (KERN_CRIT, __FUNCTION__, f, ##a) 47#define ldm_crit(f, a...) _ldm_printk (KERN_CRIT, __func__, f, ##a)
48#define ldm_error(f, a...) _ldm_printk (KERN_ERR, __FUNCTION__, f, ##a) 48#define ldm_error(f, a...) _ldm_printk (KERN_ERR, __func__, f, ##a)
49#define ldm_info(f, a...) _ldm_printk (KERN_INFO, __FUNCTION__, f, ##a) 49#define ldm_info(f, a...) _ldm_printk (KERN_INFO, __func__, f, ##a)
50 50
51__attribute__ ((format (printf, 3, 4))) 51__attribute__ ((format (printf, 3, 4)))
52static void _ldm_printk (const char *level, const char *function, 52static void _ldm_printk (const char *level, const char *function,
diff --git a/fs/pipe.c b/fs/pipe.c
index f73492b6817e..3499f9ff6316 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -1076,6 +1076,23 @@ int do_pipe(int *fd)
1076} 1076}
1077 1077
1078/* 1078/*
1079 * sys_pipe() is the normal C calling standard for creating
1080 * a pipe. It's not the way Unix traditionally does this, though.
1081 */
1082asmlinkage long __weak sys_pipe(int __user *fildes)
1083{
1084 int fd[2];
1085 int error;
1086
1087 error = do_pipe(fd);
1088 if (!error) {
1089 if (copy_to_user(fildes, fd, sizeof(fd)))
1090 error = -EFAULT;
1091 }
1092 return error;
1093}
1094
1095/*
1079 * pipefs should _never_ be mounted by userland - too much of security hassle, 1096 * pipefs should _never_ be mounted by userland - too much of security hassle,
1080 * no real gain from having the whole whorehouse mounted. So we don't need 1097 * no real gain from having the whole whorehouse mounted. So we don't need
1081 * any operations on the root directory. However, we need a non-trivial 1098 * any operations on the root directory. However, we need a non-trivial
diff --git a/fs/proc/array.c b/fs/proc/array.c
index 07d6c4853fe8..dca997a93bff 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -73,6 +73,7 @@
73#include <linux/signal.h> 73#include <linux/signal.h>
74#include <linux/highmem.h> 74#include <linux/highmem.h>
75#include <linux/file.h> 75#include <linux/file.h>
76#include <linux/fdtable.h>
76#include <linux/times.h> 77#include <linux/times.h>
77#include <linux/cpuset.h> 78#include <linux/cpuset.h>
78#include <linux/rcupdate.h> 79#include <linux/rcupdate.h>
@@ -425,12 +426,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
425 cutime = cstime = utime = stime = cputime_zero; 426 cutime = cstime = utime = stime = cputime_zero;
426 cgtime = gtime = cputime_zero; 427 cgtime = gtime = cputime_zero;
427 428
428 rcu_read_lock();
429 if (lock_task_sighand(task, &flags)) { 429 if (lock_task_sighand(task, &flags)) {
430 struct signal_struct *sig = task->signal; 430 struct signal_struct *sig = task->signal;
431 431
432 if (sig->tty) { 432 if (sig->tty) {
433 tty_pgrp = pid_nr_ns(sig->tty->pgrp, ns); 433 struct pid *pgrp = tty_get_pgrp(sig->tty);
434 tty_pgrp = pid_nr_ns(pgrp, ns);
435 put_pid(pgrp);
434 tty_nr = new_encode_dev(tty_devnum(sig->tty)); 436 tty_nr = new_encode_dev(tty_devnum(sig->tty));
435 } 437 }
436 438
@@ -469,7 +471,6 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
469 471
470 unlock_task_sighand(task, &flags); 472 unlock_task_sighand(task, &flags);
471 } 473 }
472 rcu_read_unlock();
473 474
474 if (!whole || num_threads < 2) 475 if (!whole || num_threads < 2)
475 wchan = get_wchan(task); 476 wchan = get_wchan(task);
diff --git a/fs/proc/base.c b/fs/proc/base.c
index fcf02f2deeba..808cbdc193d3 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -56,6 +56,7 @@
56#include <linux/init.h> 56#include <linux/init.h>
57#include <linux/capability.h> 57#include <linux/capability.h>
58#include <linux/file.h> 58#include <linux/file.h>
59#include <linux/fdtable.h>
59#include <linux/string.h> 60#include <linux/string.h>
60#include <linux/seq_file.h> 61#include <linux/seq_file.h>
61#include <linux/namei.h> 62#include <linux/namei.h>
diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index 9d53b39a9cf8..43e54e86cefd 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -641,6 +641,23 @@ struct proc_dir_entry *proc_mkdir_mode(const char *name, mode_t mode,
641 return ent; 641 return ent;
642} 642}
643 643
644struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
645 struct proc_dir_entry *parent)
646{
647 struct proc_dir_entry *ent;
648
649 ent = __proc_create(&parent, name, S_IFDIR | S_IRUGO | S_IXUGO, 2);
650 if (ent) {
651 ent->data = net;
652 if (proc_register(parent, ent) < 0) {
653 kfree(ent);
654 ent = NULL;
655 }
656 }
657 return ent;
658}
659EXPORT_SYMBOL_GPL(proc_net_mkdir);
660
644struct proc_dir_entry *proc_mkdir(const char *name, 661struct proc_dir_entry *proc_mkdir(const char *name,
645 struct proc_dir_entry *parent) 662 struct proc_dir_entry *parent)
646{ 663{
diff --git a/fs/proc/proc_misc.c b/fs/proc/proc_misc.c
index 48bcf20cec2f..74a323d2b850 100644
--- a/fs/proc/proc_misc.c
+++ b/fs/proc/proc_misc.c
@@ -179,6 +179,7 @@ static int meminfo_read_proc(char *page, char **start, off_t off,
179 "PageTables: %8lu kB\n" 179 "PageTables: %8lu kB\n"
180 "NFS_Unstable: %8lu kB\n" 180 "NFS_Unstable: %8lu kB\n"
181 "Bounce: %8lu kB\n" 181 "Bounce: %8lu kB\n"
182 "WritebackTmp: %8lu kB\n"
182 "CommitLimit: %8lu kB\n" 183 "CommitLimit: %8lu kB\n"
183 "Committed_AS: %8lu kB\n" 184 "Committed_AS: %8lu kB\n"
184 "VmallocTotal: %8lu kB\n" 185 "VmallocTotal: %8lu kB\n"
@@ -210,6 +211,7 @@ static int meminfo_read_proc(char *page, char **start, off_t off,
210 K(global_page_state(NR_PAGETABLE)), 211 K(global_page_state(NR_PAGETABLE)),
211 K(global_page_state(NR_UNSTABLE_NFS)), 212 K(global_page_state(NR_UNSTABLE_NFS)),
212 K(global_page_state(NR_BOUNCE)), 213 K(global_page_state(NR_BOUNCE)),
214 K(global_page_state(NR_WRITEBACK_TEMP)),
213 K(allowed), 215 K(allowed),
214 K(committed), 216 K(committed),
215 (unsigned long)VMALLOC_TOTAL >> 10, 217 (unsigned long)VMALLOC_TOTAL >> 10,
diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
index 13cd7835d0df..83f357b30d71 100644
--- a/fs/proc/proc_net.c
+++ b/fs/proc/proc_net.c
@@ -159,17 +159,6 @@ struct net *get_proc_net(const struct inode *inode)
159} 159}
160EXPORT_SYMBOL_GPL(get_proc_net); 160EXPORT_SYMBOL_GPL(get_proc_net);
161 161
162struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
163 struct proc_dir_entry *parent)
164{
165 struct proc_dir_entry *pde;
166 pde = proc_mkdir_mode(name, S_IRUGO | S_IXUGO, parent);
167 if (pde != NULL)
168 pde->data = net;
169 return pde;
170}
171EXPORT_SYMBOL_GPL(proc_net_mkdir);
172
173static __net_init int proc_net_ns_init(struct net *net) 162static __net_init int proc_net_ns_init(struct net *net)
174{ 163{
175 struct proc_dir_entry *netd, *net_statd; 164 struct proc_dir_entry *netd, *net_statd;
diff --git a/fs/proc/proc_tty.c b/fs/proc/proc_tty.c
index ac26ccc25f42..21f490f5d65c 100644
--- a/fs/proc/proc_tty.c
+++ b/fs/proc/proc_tty.c
@@ -192,16 +192,14 @@ void proc_tty_register_driver(struct tty_driver *driver)
192{ 192{
193 struct proc_dir_entry *ent; 193 struct proc_dir_entry *ent;
194 194
195 if ((!driver->read_proc && !driver->write_proc) || 195 if (!driver->ops->read_proc || !driver->driver_name ||
196 !driver->driver_name ||
197 driver->proc_entry) 196 driver->proc_entry)
198 return; 197 return;
199 198
200 ent = create_proc_entry(driver->driver_name, 0, proc_tty_driver); 199 ent = create_proc_entry(driver->driver_name, 0, proc_tty_driver);
201 if (!ent) 200 if (!ent)
202 return; 201 return;
203 ent->read_proc = driver->read_proc; 202 ent->read_proc = driver->ops->read_proc;
204 ent->write_proc = driver->write_proc;
205 ent->owner = driver->owner; 203 ent->owner = driver->owner;
206 ent->data = driver; 204 ent->data = driver;
207 205
diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
index 4b733f108455..4b4f9cc2f186 100644
--- a/fs/proc/task_nommu.c
+++ b/fs/proc/task_nommu.c
@@ -1,6 +1,7 @@
1 1
2#include <linux/mm.h> 2#include <linux/mm.h>
3#include <linux/file.h> 3#include <linux/file.h>
4#include <linux/fdtable.h>
4#include <linux/mount.h> 5#include <linux/mount.h>
5#include <linux/ptrace.h> 6#include <linux/ptrace.h>
6#include <linux/seq_file.h> 7#include <linux/seq_file.h>
diff --git a/fs/quota_v2.c b/fs/quota_v2.c
index 23b647f25d08..234ada903633 100644
--- a/fs/quota_v2.c
+++ b/fs/quota_v2.c
@@ -306,7 +306,7 @@ static uint find_free_dqentry(struct dquot *dquot, int *err)
306 printk(KERN_ERR "VFS: find_free_dqentry(): Can't remove block (%u) from entry free list.\n", blk); 306 printk(KERN_ERR "VFS: find_free_dqentry(): Can't remove block (%u) from entry free list.\n", blk);
307 goto out_buf; 307 goto out_buf;
308 } 308 }
309 dh->dqdh_entries = cpu_to_le16(le16_to_cpu(dh->dqdh_entries)+1); 309 le16_add_cpu(&dh->dqdh_entries, 1);
310 memset(&fakedquot, 0, sizeof(struct v2_disk_dqblk)); 310 memset(&fakedquot, 0, sizeof(struct v2_disk_dqblk));
311 /* Find free structure in block */ 311 /* Find free structure in block */
312 for (i = 0; i < V2_DQSTRINBLK && memcmp(&fakedquot, ddquot+i, sizeof(struct v2_disk_dqblk)); i++); 312 for (i = 0; i < V2_DQSTRINBLK && memcmp(&fakedquot, ddquot+i, sizeof(struct v2_disk_dqblk)); i++);
@@ -448,7 +448,7 @@ static int free_dqentry(struct dquot *dquot, uint blk)
448 goto out_buf; 448 goto out_buf;
449 } 449 }
450 dh = (struct v2_disk_dqdbheader *)buf; 450 dh = (struct v2_disk_dqdbheader *)buf;
451 dh->dqdh_entries = cpu_to_le16(le16_to_cpu(dh->dqdh_entries)-1); 451 le16_add_cpu(&dh->dqdh_entries, -1);
452 if (!le16_to_cpu(dh->dqdh_entries)) { /* Block got free? */ 452 if (!le16_to_cpu(dh->dqdh_entries)) { /* Block got free? */
453 if ((ret = remove_free_dqentry(sb, type, buf, blk)) < 0 || 453 if ((ret = remove_free_dqentry(sb, type, buf, blk)) < 0 ||
454 (ret = put_free_dqblk(sb, type, buf, blk)) < 0) { 454 (ret = put_free_dqblk(sb, type, buf, blk)) < 0) {
diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c
index 8428d5b2711d..b13123424e49 100644
--- a/fs/ramfs/inode.c
+++ b/fs/ramfs/inode.c
@@ -44,7 +44,7 @@ static const struct inode_operations ramfs_dir_inode_operations;
44 44
45static struct backing_dev_info ramfs_backing_dev_info = { 45static struct backing_dev_info ramfs_backing_dev_info = {
46 .ra_pages = 0, /* No readahead */ 46 .ra_pages = 0, /* No readahead */
47 .capabilities = BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_WRITEBACK | 47 .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK |
48 BDI_CAP_MAP_DIRECT | BDI_CAP_MAP_COPY | 48 BDI_CAP_MAP_DIRECT | BDI_CAP_MAP_COPY |
49 BDI_CAP_READ_MAP | BDI_CAP_WRITE_MAP | BDI_CAP_EXEC_MAP, 49 BDI_CAP_READ_MAP | BDI_CAP_WRITE_MAP | BDI_CAP_EXEC_MAP,
50}; 50};
diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
index da86042b3e03..e396b2fa4743 100644
--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -2574,11 +2574,9 @@ static int release_journal_dev(struct super_block *super,
2574 2574
2575 result = 0; 2575 result = 0;
2576 2576
2577 if (journal->j_dev_file != NULL) { 2577 if (journal->j_dev_bd != NULL) {
2578 result = filp_close(journal->j_dev_file, NULL); 2578 if (journal->j_dev_bd->bd_dev != super->s_dev)
2579 journal->j_dev_file = NULL; 2579 bd_release(journal->j_dev_bd);
2580 journal->j_dev_bd = NULL;
2581 } else if (journal->j_dev_bd != NULL) {
2582 result = blkdev_put(journal->j_dev_bd); 2580 result = blkdev_put(journal->j_dev_bd);
2583 journal->j_dev_bd = NULL; 2581 journal->j_dev_bd = NULL;
2584 } 2582 }
@@ -2603,7 +2601,6 @@ static int journal_init_dev(struct super_block *super,
2603 result = 0; 2601 result = 0;
2604 2602
2605 journal->j_dev_bd = NULL; 2603 journal->j_dev_bd = NULL;
2606 journal->j_dev_file = NULL;
2607 jdev = SB_ONDISK_JOURNAL_DEVICE(super) ? 2604 jdev = SB_ONDISK_JOURNAL_DEVICE(super) ?
2608 new_decode_dev(SB_ONDISK_JOURNAL_DEVICE(super)) : super->s_dev; 2605 new_decode_dev(SB_ONDISK_JOURNAL_DEVICE(super)) : super->s_dev;
2609 2606
@@ -2620,35 +2617,34 @@ static int journal_init_dev(struct super_block *super,
2620 "cannot init journal device '%s': %i", 2617 "cannot init journal device '%s': %i",
2621 __bdevname(jdev, b), result); 2618 __bdevname(jdev, b), result);
2622 return result; 2619 return result;
2623 } else if (jdev != super->s_dev) 2620 } else if (jdev != super->s_dev) {
2621 result = bd_claim(journal->j_dev_bd, journal);
2622 if (result) {
2623 blkdev_put(journal->j_dev_bd);
2624 return result;
2625 }
2626
2624 set_blocksize(journal->j_dev_bd, super->s_blocksize); 2627 set_blocksize(journal->j_dev_bd, super->s_blocksize);
2628 }
2629
2625 return 0; 2630 return 0;
2626 } 2631 }
2627 2632
2628 journal->j_dev_file = filp_open(jdev_name, 0, 0); 2633 journal->j_dev_bd = open_bdev_excl(jdev_name, 0, journal);
2629 if (!IS_ERR(journal->j_dev_file)) { 2634 if (IS_ERR(journal->j_dev_bd)) {
2630 struct inode *jdev_inode = journal->j_dev_file->f_mapping->host; 2635 result = PTR_ERR(journal->j_dev_bd);
2631 if (!S_ISBLK(jdev_inode->i_mode)) { 2636 journal->j_dev_bd = NULL;
2632 reiserfs_warning(super, "journal_init_dev: '%s' is "
2633 "not a block device", jdev_name);
2634 result = -ENOTBLK;
2635 release_journal_dev(super, journal);
2636 } else {
2637 /* ok */
2638 journal->j_dev_bd = I_BDEV(jdev_inode);
2639 set_blocksize(journal->j_dev_bd, super->s_blocksize);
2640 reiserfs_info(super,
2641 "journal_init_dev: journal device: %s\n",
2642 bdevname(journal->j_dev_bd, b));
2643 }
2644 } else {
2645 result = PTR_ERR(journal->j_dev_file);
2646 journal->j_dev_file = NULL;
2647 reiserfs_warning(super, 2637 reiserfs_warning(super,
2648 "journal_init_dev: Cannot open '%s': %i", 2638 "journal_init_dev: Cannot open '%s': %i",
2649 jdev_name, result); 2639 jdev_name, result);
2640 return result;
2650 } 2641 }
2651 return result; 2642
2643 set_blocksize(journal->j_dev_bd, super->s_blocksize);
2644 reiserfs_info(super,
2645 "journal_init_dev: journal device: %s\n",
2646 bdevname(journal->j_dev_bd, b));
2647 return 0;
2652} 2648}
2653 2649
2654/** 2650/**
diff --git a/fs/select.c b/fs/select.c
index 00f58c5c7e05..8dda969614a9 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -21,6 +21,7 @@
21#include <linux/poll.h> 21#include <linux/poll.h>
22#include <linux/personality.h> /* for STICKY_TIMEOUTS */ 22#include <linux/personality.h> /* for STICKY_TIMEOUTS */
23#include <linux/file.h> 23#include <linux/file.h>
24#include <linux/fdtable.h>
24#include <linux/fs.h> 25#include <linux/fs.h>
25#include <linux/rcupdate.h> 26#include <linux/rcupdate.h>
26 27
@@ -298,7 +299,7 @@ int do_select(int n, fd_set_bits *fds, s64 *timeout)
298#define MAX_SELECT_SECONDS \ 299#define MAX_SELECT_SECONDS \
299 ((unsigned long) (MAX_SCHEDULE_TIMEOUT / HZ)-1) 300 ((unsigned long) (MAX_SCHEDULE_TIMEOUT / HZ)-1)
300 301
301static int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp, 302int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp,
302 fd_set __user *exp, s64 *timeout) 303 fd_set __user *exp, s64 *timeout)
303{ 304{
304 fd_set_bits fds; 305 fd_set_bits fds;
@@ -425,7 +426,7 @@ sticky:
425 return ret; 426 return ret;
426} 427}
427 428
428#ifdef TIF_RESTORE_SIGMASK 429#ifdef HAVE_SET_RESTORE_SIGMASK
429asmlinkage long sys_pselect7(int n, fd_set __user *inp, fd_set __user *outp, 430asmlinkage long sys_pselect7(int n, fd_set __user *inp, fd_set __user *outp,
430 fd_set __user *exp, struct timespec __user *tsp, 431 fd_set __user *exp, struct timespec __user *tsp,
431 const sigset_t __user *sigmask, size_t sigsetsize) 432 const sigset_t __user *sigmask, size_t sigsetsize)
@@ -498,7 +499,7 @@ sticky:
498 if (sigmask) { 499 if (sigmask) {
499 memcpy(&current->saved_sigmask, &sigsaved, 500 memcpy(&current->saved_sigmask, &sigsaved,
500 sizeof(sigsaved)); 501 sizeof(sigsaved));
501 set_thread_flag(TIF_RESTORE_SIGMASK); 502 set_restore_sigmask();
502 } 503 }
503 } else if (sigmask) 504 } else if (sigmask)
504 sigprocmask(SIG_SETMASK, &sigsaved, NULL); 505 sigprocmask(SIG_SETMASK, &sigsaved, NULL);
@@ -528,7 +529,7 @@ asmlinkage long sys_pselect6(int n, fd_set __user *inp, fd_set __user *outp,
528 529
529 return sys_pselect7(n, inp, outp, exp, tsp, up, sigsetsize); 530 return sys_pselect7(n, inp, outp, exp, tsp, up, sigsetsize);
530} 531}
531#endif /* TIF_RESTORE_SIGMASK */ 532#endif /* HAVE_SET_RESTORE_SIGMASK */
532 533
533struct poll_list { 534struct poll_list {
534 struct poll_list *next; 535 struct poll_list *next;
@@ -759,7 +760,7 @@ asmlinkage long sys_poll(struct pollfd __user *ufds, unsigned int nfds,
759 return ret; 760 return ret;
760} 761}
761 762
762#ifdef TIF_RESTORE_SIGMASK 763#ifdef HAVE_SET_RESTORE_SIGMASK
763asmlinkage long sys_ppoll(struct pollfd __user *ufds, unsigned int nfds, 764asmlinkage long sys_ppoll(struct pollfd __user *ufds, unsigned int nfds,
764 struct timespec __user *tsp, const sigset_t __user *sigmask, 765 struct timespec __user *tsp, const sigset_t __user *sigmask,
765 size_t sigsetsize) 766 size_t sigsetsize)
@@ -805,7 +806,7 @@ asmlinkage long sys_ppoll(struct pollfd __user *ufds, unsigned int nfds,
805 if (sigmask) { 806 if (sigmask) {
806 memcpy(&current->saved_sigmask, &sigsaved, 807 memcpy(&current->saved_sigmask, &sigsaved,
807 sizeof(sigsaved)); 808 sizeof(sigsaved));
808 set_thread_flag(TIF_RESTORE_SIGMASK); 809 set_restore_sigmask();
809 } 810 }
810 ret = -ERESTARTNOHAND; 811 ret = -ERESTARTNOHAND;
811 } else if (sigmask) 812 } else if (sigmask)
@@ -839,4 +840,4 @@ asmlinkage long sys_ppoll(struct pollfd __user *ufds, unsigned int nfds,
839 840
840 return ret; 841 return ret;
841} 842}
842#endif /* TIF_RESTORE_SIGMASK */ 843#endif /* HAVE_SET_RESTORE_SIGMASK */
diff --git a/fs/signalfd.c b/fs/signalfd.c
index 8ead0db35933..619725644c75 100644
--- a/fs/signalfd.c
+++ b/fs/signalfd.c
@@ -207,11 +207,8 @@ static const struct file_operations signalfd_fops = {
207 207
208asmlinkage long sys_signalfd(int ufd, sigset_t __user *user_mask, size_t sizemask) 208asmlinkage long sys_signalfd(int ufd, sigset_t __user *user_mask, size_t sizemask)
209{ 209{
210 int error;
211 sigset_t sigmask; 210 sigset_t sigmask;
212 struct signalfd_ctx *ctx; 211 struct signalfd_ctx *ctx;
213 struct file *file;
214 struct inode *inode;
215 212
216 if (sizemask != sizeof(sigset_t) || 213 if (sizemask != sizeof(sigset_t) ||
217 copy_from_user(&sigmask, user_mask, sizeof(sigmask))) 214 copy_from_user(&sigmask, user_mask, sizeof(sigmask)))
@@ -230,12 +227,11 @@ asmlinkage long sys_signalfd(int ufd, sigset_t __user *user_mask, size_t sizemas
230 * When we call this, the initialization must be complete, since 227 * When we call this, the initialization must be complete, since
231 * anon_inode_getfd() will install the fd. 228 * anon_inode_getfd() will install the fd.
232 */ 229 */
233 error = anon_inode_getfd(&ufd, &inode, &file, "[signalfd]", 230 ufd = anon_inode_getfd("[signalfd]", &signalfd_fops, ctx);
234 &signalfd_fops, ctx); 231 if (ufd < 0)
235 if (error) 232 kfree(ctx);
236 goto err_fdalloc;
237 } else { 233 } else {
238 file = fget(ufd); 234 struct file *file = fget(ufd);
239 if (!file) 235 if (!file)
240 return -EBADF; 236 return -EBADF;
241 ctx = file->private_data; 237 ctx = file->private_data;
@@ -252,9 +248,4 @@ asmlinkage long sys_signalfd(int ufd, sigset_t __user *user_mask, size_t sizemas
252 } 248 }
253 249
254 return ufd; 250 return ufd;
255
256err_fdalloc:
257 kfree(ctx);
258 return error;
259} 251}
260
diff --git a/fs/smbfs/smb_debug.h b/fs/smbfs/smb_debug.h
index 734972b92694..fc4b1a5dd755 100644
--- a/fs/smbfs/smb_debug.h
+++ b/fs/smbfs/smb_debug.h
@@ -11,14 +11,14 @@
11 * these are normally enabled. 11 * these are normally enabled.
12 */ 12 */
13#ifdef SMBFS_PARANOIA 13#ifdef SMBFS_PARANOIA
14# define PARANOIA(f, a...) printk(KERN_NOTICE "%s: " f, __FUNCTION__ , ## a) 14# define PARANOIA(f, a...) printk(KERN_NOTICE "%s: " f, __func__ , ## a)
15#else 15#else
16# define PARANOIA(f, a...) do { ; } while(0) 16# define PARANOIA(f, a...) do { ; } while(0)
17#endif 17#endif
18 18
19/* lots of debug messages */ 19/* lots of debug messages */
20#ifdef SMBFS_DEBUG_VERBOSE 20#ifdef SMBFS_DEBUG_VERBOSE
21# define VERBOSE(f, a...) printk(KERN_DEBUG "%s: " f, __FUNCTION__ , ## a) 21# define VERBOSE(f, a...) printk(KERN_DEBUG "%s: " f, __func__ , ## a)
22#else 22#else
23# define VERBOSE(f, a...) do { ; } while(0) 23# define VERBOSE(f, a...) do { ; } while(0)
24#endif 24#endif
@@ -28,7 +28,7 @@
28 * too common name. 28 * too common name.
29 */ 29 */
30#ifdef SMBFS_DEBUG 30#ifdef SMBFS_DEBUG
31#define DEBUG1(f, a...) printk(KERN_DEBUG "%s: " f, __FUNCTION__ , ## a) 31#define DEBUG1(f, a...) printk(KERN_DEBUG "%s: " f, __func__ , ## a)
32#else 32#else
33#define DEBUG1(f, a...) do { ; } while(0) 33#define DEBUG1(f, a...) do { ; } while(0)
34#endif 34#endif
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index dbdfabbfd609..e7735f643cd1 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -135,7 +135,7 @@ sysfs_read_file(struct file *file, char __user *buf, size_t count, loff_t *ppos)
135 goto out; 135 goto out;
136 } 136 }
137 pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n", 137 pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n",
138 __FUNCTION__, count, *ppos, buffer->page); 138 __func__, count, *ppos, buffer->page);
139 retval = simple_read_from_buffer(buf, count, ppos, buffer->page, 139 retval = simple_read_from_buffer(buf, count, ppos, buffer->page,
140 buffer->count); 140 buffer->count);
141out: 141out:
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index d9262f74f94e..eb53c632f856 100644
--- a/fs/sysfs/inode.c
+++ b/fs/sysfs/inode.c
@@ -30,7 +30,7 @@ static const struct address_space_operations sysfs_aops = {
30 30
31static struct backing_dev_info sysfs_backing_dev_info = { 31static struct backing_dev_info sysfs_backing_dev_info = {
32 .ra_pages = 0, /* No readahead */ 32 .ra_pages = 0, /* No readahead */
33 .capabilities = BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_WRITEBACK, 33 .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK,
34}; 34};
35 35
36static const struct inode_operations sysfs_inode_operations ={ 36static const struct inode_operations sysfs_inode_operations ={
@@ -59,6 +59,8 @@ int sysfs_setattr(struct dentry * dentry, struct iattr * iattr)
59 if (error) 59 if (error)
60 return error; 60 return error;
61 61
62 iattr->ia_valid &= ~ATTR_SIZE; /* ignore size changes */
63
62 error = inode_setattr(inode, iattr); 64 error = inode_setattr(inode, iattr);
63 if (error) 65 if (error)
64 return error; 66 return error;
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
index 74168266cd59..14f0023984d7 100644
--- a/fs/sysfs/mount.c
+++ b/fs/sysfs/mount.c
@@ -61,7 +61,7 @@ static int sysfs_fill_super(struct super_block *sb, void *data, int silent)
61 /* instantiate and link root dentry */ 61 /* instantiate and link root dentry */
62 root = d_alloc_root(inode); 62 root = d_alloc_root(inode);
63 if (!root) { 63 if (!root) {
64 pr_debug("%s: could not get root dentry!\n",__FUNCTION__); 64 pr_debug("%s: could not get root dentry!\n",__func__);
65 iput(inode); 65 iput(inode);
66 return -ENOMEM; 66 return -ENOMEM;
67 } 67 }
diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
index 42d51d1c05cd..38ebe3f85b3d 100644
--- a/fs/sysv/sysv.h
+++ b/fs/sysv/sysv.h
@@ -217,9 +217,9 @@ static inline __fs32 fs32_add(struct sysv_sb_info *sbi, __fs32 *n, int d)
217 if (sbi->s_bytesex == BYTESEX_PDP) 217 if (sbi->s_bytesex == BYTESEX_PDP)
218 *(__u32*)n = PDP_swab(PDP_swab(*(__u32*)n)+d); 218 *(__u32*)n = PDP_swab(PDP_swab(*(__u32*)n)+d);
219 else if (sbi->s_bytesex == BYTESEX_LE) 219 else if (sbi->s_bytesex == BYTESEX_LE)
220 *(__le32*)n = cpu_to_le32(le32_to_cpu(*(__le32*)n)+d); 220 le32_add_cpu((__le32 *)n, d);
221 else 221 else
222 *(__be32*)n = cpu_to_be32(be32_to_cpu(*(__be32*)n)+d); 222 be32_add_cpu((__be32 *)n, d);
223 return *n; 223 return *n;
224} 224}
225 225
@@ -242,9 +242,9 @@ static inline __fs16 cpu_to_fs16(struct sysv_sb_info *sbi, __u16 n)
242static inline __fs16 fs16_add(struct sysv_sb_info *sbi, __fs16 *n, int d) 242static inline __fs16 fs16_add(struct sysv_sb_info *sbi, __fs16 *n, int d)
243{ 243{
244 if (sbi->s_bytesex != BYTESEX_BE) 244 if (sbi->s_bytesex != BYTESEX_BE)
245 *(__le16*)n = cpu_to_le16(le16_to_cpu(*(__le16 *)n)+d); 245 le16_add_cpu((__le16 *)n, d);
246 else 246 else
247 *(__be16*)n = cpu_to_be16(be16_to_cpu(*(__be16 *)n)+d); 247 be16_add_cpu((__be16 *)n, d);
248 return *n; 248 return *n;
249} 249}
250 250
diff --git a/fs/timerfd.c b/fs/timerfd.c
index 5400524e9cb1..d87d354ec424 100644
--- a/fs/timerfd.c
+++ b/fs/timerfd.c
@@ -181,10 +181,8 @@ static struct file *timerfd_fget(int fd)
181 181
182asmlinkage long sys_timerfd_create(int clockid, int flags) 182asmlinkage long sys_timerfd_create(int clockid, int flags)
183{ 183{
184 int error, ufd; 184 int ufd;
185 struct timerfd_ctx *ctx; 185 struct timerfd_ctx *ctx;
186 struct file *file;
187 struct inode *inode;
188 186
189 if (flags) 187 if (flags)
190 return -EINVAL; 188 return -EINVAL;
@@ -200,12 +198,9 @@ asmlinkage long sys_timerfd_create(int clockid, int flags)
200 ctx->clockid = clockid; 198 ctx->clockid = clockid;
201 hrtimer_init(&ctx->tmr, clockid, HRTIMER_MODE_ABS); 199 hrtimer_init(&ctx->tmr, clockid, HRTIMER_MODE_ABS);
202 200
203 error = anon_inode_getfd(&ufd, &inode, &file, "[timerfd]", 201 ufd = anon_inode_getfd("[timerfd]", &timerfd_fops, ctx);
204 &timerfd_fops, ctx); 202 if (ufd < 0)
205 if (error) {
206 kfree(ctx); 203 kfree(ctx);
207 return error;
208 }
209 204
210 return ufd; 205 return ufd;
211} 206}
diff --git a/fs/udf/super.c b/fs/udf/super.c
index b564fc140fe4..9fb18a340fc1 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -240,7 +240,7 @@ static int udf_sb_alloc_partition_maps(struct super_block *sb, u32 count)
240 sbi->s_partmaps = kcalloc(count, sizeof(struct udf_part_map), 240 sbi->s_partmaps = kcalloc(count, sizeof(struct udf_part_map),
241 GFP_KERNEL); 241 GFP_KERNEL);
242 if (!sbi->s_partmaps) { 242 if (!sbi->s_partmaps) {
243 udf_error(sb, __FUNCTION__, 243 udf_error(sb, __func__,
244 "Unable to allocate space for %d partition maps", 244 "Unable to allocate space for %d partition maps",
245 count); 245 count);
246 sbi->s_partitions = 0; 246 sbi->s_partitions = 0;
@@ -1086,7 +1086,7 @@ static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index)
1086 bitmap = vmalloc(size); /* TODO: get rid of vmalloc */ 1086 bitmap = vmalloc(size); /* TODO: get rid of vmalloc */
1087 1087
1088 if (bitmap == NULL) { 1088 if (bitmap == NULL) {
1089 udf_error(sb, __FUNCTION__, 1089 udf_error(sb, __func__,
1090 "Unable to allocate space for bitmap " 1090 "Unable to allocate space for bitmap "
1091 "and %d buffer_head pointers", nr_groups); 1091 "and %d buffer_head pointers", nr_groups);
1092 return NULL; 1092 return NULL;
diff --git a/fs/utimes.c b/fs/utimes.c
index a2bef77dc9c9..af059d5cb485 100644
--- a/fs/utimes.c
+++ b/fs/utimes.c
@@ -40,9 +40,14 @@ asmlinkage long sys_utime(char __user *filename, struct utimbuf __user *times)
40 40
41#endif 41#endif
42 42
43static bool nsec_special(long nsec)
44{
45 return nsec == UTIME_OMIT || nsec == UTIME_NOW;
46}
47
43static bool nsec_valid(long nsec) 48static bool nsec_valid(long nsec)
44{ 49{
45 if (nsec == UTIME_OMIT || nsec == UTIME_NOW) 50 if (nsec_special(nsec))
46 return true; 51 return true;
47 52
48 return nsec >= 0 && nsec <= 999999999; 53 return nsec >= 0 && nsec <= 999999999;
@@ -119,7 +124,15 @@ long do_utimes(int dfd, char __user *filename, struct timespec *times, int flags
119 newattrs.ia_mtime.tv_nsec = times[1].tv_nsec; 124 newattrs.ia_mtime.tv_nsec = times[1].tv_nsec;
120 newattrs.ia_valid |= ATTR_MTIME_SET; 125 newattrs.ia_valid |= ATTR_MTIME_SET;
121 } 126 }
122 } else { 127 }
128
129 /*
130 * If times is NULL or both times are either UTIME_OMIT or
131 * UTIME_NOW, then need to check permissions, because
132 * inode_change_ok() won't do it.
133 */
134 if (!times || (nsec_special(times[0].tv_nsec) &&
135 nsec_special(times[1].tv_nsec))) {
123 error = -EACCES; 136 error = -EACCES;
124 if (IS_IMMUTABLE(inode)) 137 if (IS_IMMUTABLE(inode))
125 goto mnt_drop_write_and_out; 138 goto mnt_drop_write_and_out;
diff --git a/fs/vfat/namei.c b/fs/vfat/namei.c
index 5b66162d0747..a3522727ea5b 100644
--- a/fs/vfat/namei.c
+++ b/fs/vfat/namei.c
@@ -986,7 +986,7 @@ error_inode:
986 if (corrupt < 0) { 986 if (corrupt < 0) {
987 fat_fs_panic(new_dir->i_sb, 987 fat_fs_panic(new_dir->i_sb,
988 "%s: Filesystem corrupted (i_pos %lld)", 988 "%s: Filesystem corrupted (i_pos %lld)",
989 __FUNCTION__, sinfo.i_pos); 989 __func__, sinfo.i_pos);
990 } 990 }
991 goto out; 991 goto out;
992} 992}
diff --git a/fs/xfs/Kconfig b/fs/xfs/Kconfig
index 524021ff5436..3f53dd101f99 100644
--- a/fs/xfs/Kconfig
+++ b/fs/xfs/Kconfig
@@ -64,3 +64,16 @@ config XFS_RT
64 See the xfs man page in section 5 for additional information. 64 See the xfs man page in section 5 for additional information.
65 65
66 If unsure, say N. 66 If unsure, say N.
67
68config XFS_DEBUG
69 bool "XFS Debugging support (EXPERIMENTAL)"
70 depends on XFS_FS && EXPERIMENTAL
71 help
72 Say Y here to get an XFS build with many debugging features,
73 including ASSERT checks, function wrappers around macros,
74 and extra sanity-checking functions in various code paths.
75
76 Note that the resulting code will be HUGE and SLOW, and probably
77 not useful unless you are debugging a particular problem.
78
79 Say N unless you are an XFS developer, or you play one on TV.
diff --git a/fs/xfs/linux-2.6/mrlock.h b/fs/xfs/linux-2.6/mrlock.h
index c110bb002665..ff6a19873e5c 100644
--- a/fs/xfs/linux-2.6/mrlock.h
+++ b/fs/xfs/linux-2.6/mrlock.h
@@ -20,29 +20,24 @@
20 20
21#include <linux/rwsem.h> 21#include <linux/rwsem.h>
22 22
23enum { MR_NONE, MR_ACCESS, MR_UPDATE };
24
25typedef struct { 23typedef struct {
26 struct rw_semaphore mr_lock; 24 struct rw_semaphore mr_lock;
25#ifdef DEBUG
27 int mr_writer; 26 int mr_writer;
27#endif
28} mrlock_t; 28} mrlock_t;
29 29
30#ifdef DEBUG
30#define mrinit(mrp, name) \ 31#define mrinit(mrp, name) \
31 do { (mrp)->mr_writer = 0; init_rwsem(&(mrp)->mr_lock); } while (0) 32 do { (mrp)->mr_writer = 0; init_rwsem(&(mrp)->mr_lock); } while (0)
33#else
34#define mrinit(mrp, name) \
35 do { init_rwsem(&(mrp)->mr_lock); } while (0)
36#endif
37
32#define mrlock_init(mrp, t,n,s) mrinit(mrp, n) 38#define mrlock_init(mrp, t,n,s) mrinit(mrp, n)
33#define mrfree(mrp) do { } while (0) 39#define mrfree(mrp) do { } while (0)
34 40
35static inline void mraccess(mrlock_t *mrp)
36{
37 down_read(&mrp->mr_lock);
38}
39
40static inline void mrupdate(mrlock_t *mrp)
41{
42 down_write(&mrp->mr_lock);
43 mrp->mr_writer = 1;
44}
45
46static inline void mraccess_nested(mrlock_t *mrp, int subclass) 41static inline void mraccess_nested(mrlock_t *mrp, int subclass)
47{ 42{
48 down_read_nested(&mrp->mr_lock, subclass); 43 down_read_nested(&mrp->mr_lock, subclass);
@@ -51,10 +46,11 @@ static inline void mraccess_nested(mrlock_t *mrp, int subclass)
51static inline void mrupdate_nested(mrlock_t *mrp, int subclass) 46static inline void mrupdate_nested(mrlock_t *mrp, int subclass)
52{ 47{
53 down_write_nested(&mrp->mr_lock, subclass); 48 down_write_nested(&mrp->mr_lock, subclass);
49#ifdef DEBUG
54 mrp->mr_writer = 1; 50 mrp->mr_writer = 1;
51#endif
55} 52}
56 53
57
58static inline int mrtryaccess(mrlock_t *mrp) 54static inline int mrtryaccess(mrlock_t *mrp)
59{ 55{
60 return down_read_trylock(&mrp->mr_lock); 56 return down_read_trylock(&mrp->mr_lock);
@@ -64,39 +60,31 @@ static inline int mrtryupdate(mrlock_t *mrp)
64{ 60{
65 if (!down_write_trylock(&mrp->mr_lock)) 61 if (!down_write_trylock(&mrp->mr_lock))
66 return 0; 62 return 0;
63#ifdef DEBUG
67 mrp->mr_writer = 1; 64 mrp->mr_writer = 1;
65#endif
68 return 1; 66 return 1;
69} 67}
70 68
71static inline void mrunlock(mrlock_t *mrp) 69static inline void mrunlock_excl(mrlock_t *mrp)
72{ 70{
73 if (mrp->mr_writer) { 71#ifdef DEBUG
74 mrp->mr_writer = 0; 72 mrp->mr_writer = 0;
75 up_write(&mrp->mr_lock); 73#endif
76 } else { 74 up_write(&mrp->mr_lock);
77 up_read(&mrp->mr_lock);
78 }
79} 75}
80 76
81static inline void mrdemote(mrlock_t *mrp) 77static inline void mrunlock_shared(mrlock_t *mrp)
82{ 78{
83 mrp->mr_writer = 0; 79 up_read(&mrp->mr_lock);
84 downgrade_write(&mrp->mr_lock);
85} 80}
86 81
87#ifdef DEBUG 82static inline void mrdemote(mrlock_t *mrp)
88/*
89 * Debug-only routine, without some platform-specific asm code, we can
90 * now only answer requests regarding whether we hold the lock for write
91 * (reader state is outside our visibility, we only track writer state).
92 * Note: means !ismrlocked would give false positives, so don't do that.
93 */
94static inline int ismrlocked(mrlock_t *mrp, int type)
95{ 83{
96 if (mrp && type == MR_UPDATE) 84#ifdef DEBUG
97 return mrp->mr_writer; 85 mrp->mr_writer = 0;
98 return 1;
99}
100#endif 86#endif
87 downgrade_write(&mrp->mr_lock);
88}
101 89
102#endif /* __XFS_SUPPORT_MRLOCK_H__ */ 90#endif /* __XFS_SUPPORT_MRLOCK_H__ */
diff --git a/fs/xfs/linux-2.6/xfs_buf.c b/fs/xfs/linux-2.6/xfs_buf.c
index 52f6846101d5..5105015a75ad 100644
--- a/fs/xfs/linux-2.6/xfs_buf.c
+++ b/fs/xfs/linux-2.6/xfs_buf.c
@@ -886,7 +886,7 @@ int
886xfs_buf_lock_value( 886xfs_buf_lock_value(
887 xfs_buf_t *bp) 887 xfs_buf_t *bp)
888{ 888{
889 return atomic_read(&bp->b_sema.count); 889 return bp->b_sema.count;
890} 890}
891#endif 891#endif
892 892
diff --git a/fs/xfs/linux-2.6/xfs_export.c b/fs/xfs/linux-2.6/xfs_export.c
index 265f0168ab76..c672b3238b14 100644
--- a/fs/xfs/linux-2.6/xfs_export.c
+++ b/fs/xfs/linux-2.6/xfs_export.c
@@ -133,7 +133,7 @@ xfs_nfs_get_inode(
133 if (!ip) 133 if (!ip)
134 return ERR_PTR(-EIO); 134 return ERR_PTR(-EIO);
135 135
136 if (!ip->i_d.di_mode || ip->i_d.di_gen != generation) { 136 if (ip->i_d.di_gen != generation) {
137 xfs_iput_new(ip, XFS_ILOCK_SHARED); 137 xfs_iput_new(ip, XFS_ILOCK_SHARED);
138 return ERR_PTR(-ENOENT); 138 return ERR_PTR(-ENOENT);
139 } 139 }
diff --git a/fs/xfs/linux-2.6/xfs_file.c b/fs/xfs/linux-2.6/xfs_file.c
index 05905246434d..65e78c13d4ae 100644
--- a/fs/xfs/linux-2.6/xfs_file.c
+++ b/fs/xfs/linux-2.6/xfs_file.c
@@ -43,9 +43,6 @@
43#include <linux/smp_lock.h> 43#include <linux/smp_lock.h>
44 44
45static struct vm_operations_struct xfs_file_vm_ops; 45static struct vm_operations_struct xfs_file_vm_ops;
46#ifdef CONFIG_XFS_DMAPI
47static struct vm_operations_struct xfs_dmapi_file_vm_ops;
48#endif
49 46
50STATIC_INLINE ssize_t 47STATIC_INLINE ssize_t
51__xfs_file_read( 48__xfs_file_read(
@@ -202,22 +199,6 @@ xfs_file_fsync(
202 (xfs_off_t)0, (xfs_off_t)-1); 199 (xfs_off_t)0, (xfs_off_t)-1);
203} 200}
204 201
205#ifdef CONFIG_XFS_DMAPI
206STATIC int
207xfs_vm_fault(
208 struct vm_area_struct *vma,
209 struct vm_fault *vmf)
210{
211 struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
212 bhv_vnode_t *vp = vn_from_inode(inode);
213
214 ASSERT_ALWAYS(vp->v_vfsp->vfs_flag & VFS_DMI);
215 if (XFS_SEND_MMAP(XFS_VFSTOM(vp->v_vfsp), vma, 0))
216 return VM_FAULT_SIGBUS;
217 return filemap_fault(vma, vmf);
218}
219#endif /* CONFIG_XFS_DMAPI */
220
221/* 202/*
222 * Unfortunately we can't just use the clean and simple readdir implementation 203 * Unfortunately we can't just use the clean and simple readdir implementation
223 * below, because nfs might call back into ->lookup from the filldir callback 204 * below, because nfs might call back into ->lookup from the filldir callback
@@ -386,11 +367,6 @@ xfs_file_mmap(
386 vma->vm_ops = &xfs_file_vm_ops; 367 vma->vm_ops = &xfs_file_vm_ops;
387 vma->vm_flags |= VM_CAN_NONLINEAR; 368 vma->vm_flags |= VM_CAN_NONLINEAR;
388 369
389#ifdef CONFIG_XFS_DMAPI
390 if (XFS_M(filp->f_path.dentry->d_inode->i_sb)->m_flags & XFS_MOUNT_DMAPI)
391 vma->vm_ops = &xfs_dmapi_file_vm_ops;
392#endif /* CONFIG_XFS_DMAPI */
393
394 file_accessed(filp); 370 file_accessed(filp);
395 return 0; 371 return 0;
396} 372}
@@ -437,47 +413,6 @@ xfs_file_ioctl_invis(
437 return error; 413 return error;
438} 414}
439 415
440#ifdef CONFIG_XFS_DMAPI
441#ifdef HAVE_VMOP_MPROTECT
442STATIC int
443xfs_vm_mprotect(
444 struct vm_area_struct *vma,
445 unsigned int newflags)
446{
447 struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
448 struct xfs_mount *mp = XFS_M(inode->i_sb);
449 int error = 0;
450
451 if (mp->m_flags & XFS_MOUNT_DMAPI) {
452 if ((vma->vm_flags & VM_MAYSHARE) &&
453 (newflags & VM_WRITE) && !(vma->vm_flags & VM_WRITE))
454 error = XFS_SEND_MMAP(mp, vma, VM_WRITE);
455 }
456 return error;
457}
458#endif /* HAVE_VMOP_MPROTECT */
459#endif /* CONFIG_XFS_DMAPI */
460
461#ifdef HAVE_FOP_OPEN_EXEC
462/* If the user is attempting to execute a file that is offline then
463 * we have to trigger a DMAPI READ event before the file is marked as busy
464 * otherwise the invisible I/O will not be able to write to the file to bring
465 * it back online.
466 */
467STATIC int
468xfs_file_open_exec(
469 struct inode *inode)
470{
471 struct xfs_mount *mp = XFS_M(inode->i_sb);
472 struct xfs_inode *ip = XFS_I(inode);
473
474 if (unlikely(mp->m_flags & XFS_MOUNT_DMAPI) &&
475 DM_EVENT_ENABLED(ip, DM_EVENT_READ))
476 return -XFS_SEND_DATA(mp, DM_EVENT_READ, ip, 0, 0, 0, NULL);
477 return 0;
478}
479#endif /* HAVE_FOP_OPEN_EXEC */
480
481/* 416/*
482 * mmap()d file has taken write protection fault and is being made 417 * mmap()d file has taken write protection fault and is being made
483 * writable. We can set the page state up correctly for a writable 418 * writable. We can set the page state up correctly for a writable
@@ -546,13 +481,3 @@ static struct vm_operations_struct xfs_file_vm_ops = {
546 .fault = filemap_fault, 481 .fault = filemap_fault,
547 .page_mkwrite = xfs_vm_page_mkwrite, 482 .page_mkwrite = xfs_vm_page_mkwrite,
548}; 483};
549
550#ifdef CONFIG_XFS_DMAPI
551static struct vm_operations_struct xfs_dmapi_file_vm_ops = {
552 .fault = xfs_vm_fault,
553 .page_mkwrite = xfs_vm_page_mkwrite,
554#ifdef HAVE_VMOP_MPROTECT
555 .mprotect = xfs_vm_mprotect,
556#endif
557};
558#endif /* CONFIG_XFS_DMAPI */
diff --git a/fs/xfs/linux-2.6/xfs_ioctl.c b/fs/xfs/linux-2.6/xfs_ioctl.c
index 4ddb86b73c6b..a42ba9d71156 100644
--- a/fs/xfs/linux-2.6/xfs_ioctl.c
+++ b/fs/xfs/linux-2.6/xfs_ioctl.c
@@ -238,7 +238,7 @@ xfs_vget_fsop_handlereq(
238 return error; 238 return error;
239 if (ip == NULL) 239 if (ip == NULL)
240 return XFS_ERROR(EIO); 240 return XFS_ERROR(EIO);
241 if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) { 241 if (ip->i_d.di_gen != igen) {
242 xfs_iput_new(ip, XFS_ILOCK_SHARED); 242 xfs_iput_new(ip, XFS_ILOCK_SHARED);
243 return XFS_ERROR(ENOENT); 243 return XFS_ERROR(ENOENT);
244 } 244 }
@@ -505,14 +505,14 @@ xfs_attrmulti_attr_get(
505{ 505{
506 char *kbuf; 506 char *kbuf;
507 int error = EFAULT; 507 int error = EFAULT;
508 508
509 if (*len > XATTR_SIZE_MAX) 509 if (*len > XATTR_SIZE_MAX)
510 return EINVAL; 510 return EINVAL;
511 kbuf = kmalloc(*len, GFP_KERNEL); 511 kbuf = kmalloc(*len, GFP_KERNEL);
512 if (!kbuf) 512 if (!kbuf)
513 return ENOMEM; 513 return ENOMEM;
514 514
515 error = xfs_attr_get(XFS_I(inode), name, kbuf, (int *)len, flags, NULL); 515 error = xfs_attr_get(XFS_I(inode), name, kbuf, (int *)len, flags);
516 if (error) 516 if (error)
517 goto out_kfree; 517 goto out_kfree;
518 518
@@ -546,7 +546,7 @@ xfs_attrmulti_attr_set(
546 546
547 if (copy_from_user(kbuf, ubuf, len)) 547 if (copy_from_user(kbuf, ubuf, len))
548 goto out_kfree; 548 goto out_kfree;
549 549
550 error = xfs_attr_set(XFS_I(inode), name, kbuf, len, flags); 550 error = xfs_attr_set(XFS_I(inode), name, kbuf, len, flags);
551 551
552 out_kfree: 552 out_kfree:
diff --git a/fs/xfs/linux-2.6/xfs_iops.c b/fs/xfs/linux-2.6/xfs_iops.c
index a1237dad6430..2bf287ef5489 100644
--- a/fs/xfs/linux-2.6/xfs_iops.c
+++ b/fs/xfs/linux-2.6/xfs_iops.c
@@ -511,7 +511,8 @@ xfs_vn_rename(
511 xfs_dentry_to_name(&nname, ndentry); 511 xfs_dentry_to_name(&nname, ndentry);
512 512
513 error = xfs_rename(XFS_I(odir), &oname, XFS_I(odentry->d_inode), 513 error = xfs_rename(XFS_I(odir), &oname, XFS_I(odentry->d_inode),
514 XFS_I(ndir), &nname); 514 XFS_I(ndir), &nname, new_inode ?
515 XFS_I(new_inode) : NULL);
515 if (likely(!error)) { 516 if (likely(!error)) {
516 if (new_inode) 517 if (new_inode)
517 xfs_validate_fields(new_inode); 518 xfs_validate_fields(new_inode);
diff --git a/fs/xfs/linux-2.6/xfs_linux.h b/fs/xfs/linux-2.6/xfs_linux.h
index e5143323e71f..4edc46915b57 100644
--- a/fs/xfs/linux-2.6/xfs_linux.h
+++ b/fs/xfs/linux-2.6/xfs_linux.h
@@ -75,6 +75,7 @@
75#include <linux/delay.h> 75#include <linux/delay.h>
76#include <linux/log2.h> 76#include <linux/log2.h>
77#include <linux/spinlock.h> 77#include <linux/spinlock.h>
78#include <linux/random.h>
78 79
79#include <asm/page.h> 80#include <asm/page.h>
80#include <asm/div64.h> 81#include <asm/div64.h>
@@ -99,7 +100,6 @@
99/* 100/*
100 * Feature macros (disable/enable) 101 * Feature macros (disable/enable)
101 */ 102 */
102#define HAVE_SPLICE /* a splice(2) exists in 2.6, but not in 2.4 */
103#ifdef CONFIG_SMP 103#ifdef CONFIG_SMP
104#define HAVE_PERCPU_SB /* per cpu superblock counters are a 2.6 feature */ 104#define HAVE_PERCPU_SB /* per cpu superblock counters are a 2.6 feature */
105#else 105#else
diff --git a/fs/xfs/linux-2.6/xfs_lrw.c b/fs/xfs/linux-2.6/xfs_lrw.c
index 1ebd8004469c..5e3b57516ec7 100644
--- a/fs/xfs/linux-2.6/xfs_lrw.c
+++ b/fs/xfs/linux-2.6/xfs_lrw.c
@@ -394,7 +394,7 @@ xfs_zero_last_block(
394 int error = 0; 394 int error = 0;
395 xfs_bmbt_irec_t imap; 395 xfs_bmbt_irec_t imap;
396 396
397 ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE) != 0); 397 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
398 398
399 zero_offset = XFS_B_FSB_OFFSET(mp, isize); 399 zero_offset = XFS_B_FSB_OFFSET(mp, isize);
400 if (zero_offset == 0) { 400 if (zero_offset == 0) {
@@ -425,14 +425,14 @@ xfs_zero_last_block(
425 * out sync. We need to drop the ilock while we do this so we 425 * out sync. We need to drop the ilock while we do this so we
426 * don't deadlock when the buffer cache calls back to us. 426 * don't deadlock when the buffer cache calls back to us.
427 */ 427 */
428 xfs_iunlock(ip, XFS_ILOCK_EXCL| XFS_EXTSIZE_RD); 428 xfs_iunlock(ip, XFS_ILOCK_EXCL);
429 429
430 zero_len = mp->m_sb.sb_blocksize - zero_offset; 430 zero_len = mp->m_sb.sb_blocksize - zero_offset;
431 if (isize + zero_len > offset) 431 if (isize + zero_len > offset)
432 zero_len = offset - isize; 432 zero_len = offset - isize;
433 error = xfs_iozero(ip, isize, zero_len); 433 error = xfs_iozero(ip, isize, zero_len);
434 434
435 xfs_ilock(ip, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD); 435 xfs_ilock(ip, XFS_ILOCK_EXCL);
436 ASSERT(error >= 0); 436 ASSERT(error >= 0);
437 return error; 437 return error;
438} 438}
@@ -465,8 +465,7 @@ xfs_zero_eof(
465 int error = 0; 465 int error = 0;
466 xfs_bmbt_irec_t imap; 466 xfs_bmbt_irec_t imap;
467 467
468 ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE)); 468 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_IOLOCK_EXCL));
469 ASSERT(ismrlocked(&ip->i_iolock, MR_UPDATE));
470 ASSERT(offset > isize); 469 ASSERT(offset > isize);
471 470
472 /* 471 /*
@@ -475,8 +474,7 @@ xfs_zero_eof(
475 */ 474 */
476 error = xfs_zero_last_block(ip, offset, isize); 475 error = xfs_zero_last_block(ip, offset, isize);
477 if (error) { 476 if (error) {
478 ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE)); 477 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_IOLOCK_EXCL));
479 ASSERT(ismrlocked(&ip->i_iolock, MR_UPDATE));
480 return error; 478 return error;
481 } 479 }
482 480
@@ -507,8 +505,7 @@ xfs_zero_eof(
507 error = xfs_bmapi(NULL, ip, start_zero_fsb, zero_count_fsb, 505 error = xfs_bmapi(NULL, ip, start_zero_fsb, zero_count_fsb,
508 0, NULL, 0, &imap, &nimaps, NULL, NULL); 506 0, NULL, 0, &imap, &nimaps, NULL, NULL);
509 if (error) { 507 if (error) {
510 ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE)); 508 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_IOLOCK_EXCL));
511 ASSERT(ismrlocked(&ip->i_iolock, MR_UPDATE));
512 return error; 509 return error;
513 } 510 }
514 ASSERT(nimaps > 0); 511 ASSERT(nimaps > 0);
@@ -532,7 +529,7 @@ xfs_zero_eof(
532 * Drop the inode lock while we're doing the I/O. 529 * Drop the inode lock while we're doing the I/O.
533 * We'll still have the iolock to protect us. 530 * We'll still have the iolock to protect us.
534 */ 531 */
535 xfs_iunlock(ip, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD); 532 xfs_iunlock(ip, XFS_ILOCK_EXCL);
536 533
537 zero_off = XFS_FSB_TO_B(mp, start_zero_fsb); 534 zero_off = XFS_FSB_TO_B(mp, start_zero_fsb);
538 zero_len = XFS_FSB_TO_B(mp, imap.br_blockcount); 535 zero_len = XFS_FSB_TO_B(mp, imap.br_blockcount);
@@ -548,13 +545,13 @@ xfs_zero_eof(
548 start_zero_fsb = imap.br_startoff + imap.br_blockcount; 545 start_zero_fsb = imap.br_startoff + imap.br_blockcount;
549 ASSERT(start_zero_fsb <= (end_zero_fsb + 1)); 546 ASSERT(start_zero_fsb <= (end_zero_fsb + 1));
550 547
551 xfs_ilock(ip, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD); 548 xfs_ilock(ip, XFS_ILOCK_EXCL);
552 } 549 }
553 550
554 return 0; 551 return 0;
555 552
556out_lock: 553out_lock:
557 xfs_ilock(ip, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD); 554 xfs_ilock(ip, XFS_ILOCK_EXCL);
558 ASSERT(error >= 0); 555 ASSERT(error >= 0);
559 return error; 556 return error;
560} 557}
diff --git a/fs/xfs/linux-2.6/xfs_lrw.h b/fs/xfs/linux-2.6/xfs_lrw.h
index e1d498b4ba7a..e6be37dbd0e9 100644
--- a/fs/xfs/linux-2.6/xfs_lrw.h
+++ b/fs/xfs/linux-2.6/xfs_lrw.h
@@ -50,7 +50,6 @@ struct xfs_iomap;
50#define XFS_INVAL_CACHED 18 50#define XFS_INVAL_CACHED 18
51#define XFS_DIORD_ENTER 19 51#define XFS_DIORD_ENTER 19
52#define XFS_DIOWR_ENTER 20 52#define XFS_DIOWR_ENTER 20
53#define XFS_SENDFILE_ENTER 21
54#define XFS_WRITEPAGE_ENTER 22 53#define XFS_WRITEPAGE_ENTER 22
55#define XFS_RELEASEPAGE_ENTER 23 54#define XFS_RELEASEPAGE_ENTER 23
56#define XFS_INVALIDPAGE_ENTER 24 55#define XFS_INVALIDPAGE_ENTER 24
diff --git a/fs/xfs/linux-2.6/xfs_super.c b/fs/xfs/linux-2.6/xfs_super.c
index 865eb708aa95..742b2c7852c1 100644
--- a/fs/xfs/linux-2.6/xfs_super.c
+++ b/fs/xfs/linux-2.6/xfs_super.c
@@ -1181,7 +1181,7 @@ xfs_fs_statfs(
1181 statp->f_fsid.val[0] = (u32)id; 1181 statp->f_fsid.val[0] = (u32)id;
1182 statp->f_fsid.val[1] = (u32)(id >> 32); 1182 statp->f_fsid.val[1] = (u32)(id >> 32);
1183 1183
1184 xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT); 1184 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
1185 1185
1186 spin_lock(&mp->m_sb_lock); 1186 spin_lock(&mp->m_sb_lock);
1187 statp->f_bsize = sbp->sb_blocksize; 1187 statp->f_bsize = sbp->sb_blocksize;
diff --git a/fs/xfs/linux-2.6/xfs_vnode.h b/fs/xfs/linux-2.6/xfs_vnode.h
index 8b4d63ce8694..9d73cb5c0fc7 100644
--- a/fs/xfs/linux-2.6/xfs_vnode.h
+++ b/fs/xfs/linux-2.6/xfs_vnode.h
@@ -25,12 +25,6 @@ struct attrlist_cursor_kern;
25 25
26typedef struct inode bhv_vnode_t; 26typedef struct inode bhv_vnode_t;
27 27
28#define VN_ISLNK(vp) S_ISLNK((vp)->i_mode)
29#define VN_ISREG(vp) S_ISREG((vp)->i_mode)
30#define VN_ISDIR(vp) S_ISDIR((vp)->i_mode)
31#define VN_ISCHR(vp) S_ISCHR((vp)->i_mode)
32#define VN_ISBLK(vp) S_ISBLK((vp)->i_mode)
33
34/* 28/*
35 * Vnode to Linux inode mapping. 29 * Vnode to Linux inode mapping.
36 */ 30 */
@@ -151,24 +145,6 @@ typedef struct bhv_vattr {
151 XFS_AT_TYPE|XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|\ 145 XFS_AT_TYPE|XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|\
152 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_GENCOUNT) 146 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_GENCOUNT)
153 147
154/*
155 * Modes.
156 */
157#define VSUID S_ISUID /* set user id on execution */
158#define VSGID S_ISGID /* set group id on execution */
159#define VSVTX S_ISVTX /* save swapped text even after use */
160#define VREAD S_IRUSR /* read, write, execute permissions */
161#define VWRITE S_IWUSR
162#define VEXEC S_IXUSR
163
164#define MODEMASK S_IALLUGO /* mode bits plus permission bits */
165
166/*
167 * Check whether mandatory file locking is enabled.
168 */
169#define MANDLOCK(vp, mode) \
170 (VN_ISREG(vp) && ((mode) & (VSGID|(VEXEC>>3))) == VSGID)
171
172extern void vn_init(void); 148extern void vn_init(void);
173extern int vn_revalidate(bhv_vnode_t *); 149extern int vn_revalidate(bhv_vnode_t *);
174 150
diff --git a/fs/xfs/quota/xfs_dquot.c b/fs/xfs/quota/xfs_dquot.c
index 631ebb31b295..85df3288efd5 100644
--- a/fs/xfs/quota/xfs_dquot.c
+++ b/fs/xfs/quota/xfs_dquot.c
@@ -933,7 +933,7 @@ xfs_qm_dqget(
933 type == XFS_DQ_PROJ || 933 type == XFS_DQ_PROJ ||
934 type == XFS_DQ_GROUP); 934 type == XFS_DQ_GROUP);
935 if (ip) { 935 if (ip) {
936 ASSERT(XFS_ISLOCKED_INODE_EXCL(ip)); 936 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
937 if (type == XFS_DQ_USER) 937 if (type == XFS_DQ_USER)
938 ASSERT(ip->i_udquot == NULL); 938 ASSERT(ip->i_udquot == NULL);
939 else 939 else
@@ -1088,7 +1088,7 @@ xfs_qm_dqget(
1088 xfs_qm_mplist_unlock(mp); 1088 xfs_qm_mplist_unlock(mp);
1089 XFS_DQ_HASH_UNLOCK(h); 1089 XFS_DQ_HASH_UNLOCK(h);
1090 dqret: 1090 dqret:
1091 ASSERT((ip == NULL) || XFS_ISLOCKED_INODE_EXCL(ip)); 1091 ASSERT((ip == NULL) || xfs_isilocked(ip, XFS_ILOCK_EXCL));
1092 xfs_dqtrace_entry(dqp, "DQGET DONE"); 1092 xfs_dqtrace_entry(dqp, "DQGET DONE");
1093 *O_dqpp = dqp; 1093 *O_dqpp = dqp;
1094 return (0); 1094 return (0);
diff --git a/fs/xfs/quota/xfs_qm.c b/fs/xfs/quota/xfs_qm.c
index 40ea56409561..d31cce1165c5 100644
--- a/fs/xfs/quota/xfs_qm.c
+++ b/fs/xfs/quota/xfs_qm.c
@@ -670,7 +670,7 @@ xfs_qm_dqattach_one(
670 xfs_dquot_t *dqp; 670 xfs_dquot_t *dqp;
671 int error; 671 int error;
672 672
673 ASSERT(XFS_ISLOCKED_INODE_EXCL(ip)); 673 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
674 error = 0; 674 error = 0;
675 /* 675 /*
676 * See if we already have it in the inode itself. IO_idqpp is 676 * See if we already have it in the inode itself. IO_idqpp is
@@ -874,7 +874,7 @@ xfs_qm_dqattach(
874 return 0; 874 return 0;
875 875
876 ASSERT((flags & XFS_QMOPT_ILOCKED) == 0 || 876 ASSERT((flags & XFS_QMOPT_ILOCKED) == 0 ||
877 XFS_ISLOCKED_INODE_EXCL(ip)); 877 xfs_isilocked(ip, XFS_ILOCK_EXCL));
878 878
879 if (! (flags & XFS_QMOPT_ILOCKED)) 879 if (! (flags & XFS_QMOPT_ILOCKED))
880 xfs_ilock(ip, XFS_ILOCK_EXCL); 880 xfs_ilock(ip, XFS_ILOCK_EXCL);
@@ -888,7 +888,8 @@ xfs_qm_dqattach(
888 goto done; 888 goto done;
889 nquotas++; 889 nquotas++;
890 } 890 }
891 ASSERT(XFS_ISLOCKED_INODE_EXCL(ip)); 891
892 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
892 if (XFS_IS_OQUOTA_ON(mp)) { 893 if (XFS_IS_OQUOTA_ON(mp)) {
893 error = XFS_IS_GQUOTA_ON(mp) ? 894 error = XFS_IS_GQUOTA_ON(mp) ?
894 xfs_qm_dqattach_one(ip, ip->i_d.di_gid, XFS_DQ_GROUP, 895 xfs_qm_dqattach_one(ip, ip->i_d.di_gid, XFS_DQ_GROUP,
@@ -913,7 +914,7 @@ xfs_qm_dqattach(
913 * This WON'T, in general, result in a thrash. 914 * This WON'T, in general, result in a thrash.
914 */ 915 */
915 if (nquotas == 2) { 916 if (nquotas == 2) {
916 ASSERT(XFS_ISLOCKED_INODE_EXCL(ip)); 917 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
917 ASSERT(ip->i_udquot); 918 ASSERT(ip->i_udquot);
918 ASSERT(ip->i_gdquot); 919 ASSERT(ip->i_gdquot);
919 920
@@ -956,7 +957,7 @@ xfs_qm_dqattach(
956 957
957#ifdef QUOTADEBUG 958#ifdef QUOTADEBUG
958 else 959 else
959 ASSERT(XFS_ISLOCKED_INODE_EXCL(ip)); 960 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
960#endif 961#endif
961 return error; 962 return error;
962} 963}
@@ -1291,7 +1292,7 @@ xfs_qm_dqget_noattach(
1291 xfs_mount_t *mp; 1292 xfs_mount_t *mp;
1292 xfs_dquot_t *udqp, *gdqp; 1293 xfs_dquot_t *udqp, *gdqp;
1293 1294
1294 ASSERT(XFS_ISLOCKED_INODE_EXCL(ip)); 1295 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
1295 mp = ip->i_mount; 1296 mp = ip->i_mount;
1296 udqp = NULL; 1297 udqp = NULL;
1297 gdqp = NULL; 1298 gdqp = NULL;
@@ -1392,7 +1393,7 @@ xfs_qm_qino_alloc(
1392 * Keep an extra reference to this quota inode. This inode is 1393 * Keep an extra reference to this quota inode. This inode is
1393 * locked exclusively and joined to the transaction already. 1394 * locked exclusively and joined to the transaction already.
1394 */ 1395 */
1395 ASSERT(XFS_ISLOCKED_INODE_EXCL(*ip)); 1396 ASSERT(xfs_isilocked(*ip, XFS_ILOCK_EXCL));
1396 VN_HOLD(XFS_ITOV((*ip))); 1397 VN_HOLD(XFS_ITOV((*ip)));
1397 1398
1398 /* 1399 /*
@@ -1737,12 +1738,6 @@ xfs_qm_dqusage_adjust(
1737 return error; 1738 return error;
1738 } 1739 }
1739 1740
1740 if (ip->i_d.di_mode == 0) {
1741 xfs_iput_new(ip, XFS_ILOCK_EXCL);
1742 *res = BULKSTAT_RV_NOTHING;
1743 return XFS_ERROR(ENOENT);
1744 }
1745
1746 /* 1741 /*
1747 * Obtain the locked dquots. In case of an error (eg. allocation 1742 * Obtain the locked dquots. In case of an error (eg. allocation
1748 * fails for ENOSPC), we return the negative of the error number 1743 * fails for ENOSPC), we return the negative of the error number
@@ -2563,7 +2558,7 @@ xfs_qm_vop_chown(
2563 uint bfield = XFS_IS_REALTIME_INODE(ip) ? 2558 uint bfield = XFS_IS_REALTIME_INODE(ip) ?
2564 XFS_TRANS_DQ_RTBCOUNT : XFS_TRANS_DQ_BCOUNT; 2559 XFS_TRANS_DQ_RTBCOUNT : XFS_TRANS_DQ_BCOUNT;
2565 2560
2566 ASSERT(XFS_ISLOCKED_INODE_EXCL(ip)); 2561 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
2567 ASSERT(XFS_IS_QUOTA_RUNNING(ip->i_mount)); 2562 ASSERT(XFS_IS_QUOTA_RUNNING(ip->i_mount));
2568 2563
2569 /* old dquot */ 2564 /* old dquot */
@@ -2607,7 +2602,7 @@ xfs_qm_vop_chown_reserve(
2607 uint delblks, blkflags, prjflags = 0; 2602 uint delblks, blkflags, prjflags = 0;
2608 xfs_dquot_t *unresudq, *unresgdq, *delblksudq, *delblksgdq; 2603 xfs_dquot_t *unresudq, *unresgdq, *delblksudq, *delblksgdq;
2609 2604
2610 ASSERT(XFS_ISLOCKED_INODE(ip)); 2605 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_ILOCK_SHARED));
2611 mp = ip->i_mount; 2606 mp = ip->i_mount;
2612 ASSERT(XFS_IS_QUOTA_RUNNING(mp)); 2607 ASSERT(XFS_IS_QUOTA_RUNNING(mp));
2613 2608
@@ -2717,7 +2712,7 @@ xfs_qm_vop_dqattach_and_dqmod_newinode(
2717 if (!XFS_IS_QUOTA_ON(tp->t_mountp)) 2712 if (!XFS_IS_QUOTA_ON(tp->t_mountp))
2718 return; 2713 return;
2719 2714
2720 ASSERT(XFS_ISLOCKED_INODE_EXCL(ip)); 2715 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
2721 ASSERT(XFS_IS_QUOTA_RUNNING(tp->t_mountp)); 2716 ASSERT(XFS_IS_QUOTA_RUNNING(tp->t_mountp));
2722 2717
2723 if (udqp) { 2718 if (udqp) {
diff --git a/fs/xfs/quota/xfs_qm_syscalls.c b/fs/xfs/quota/xfs_qm_syscalls.c
index 8342823dbdc3..768a3b27d2b6 100644
--- a/fs/xfs/quota/xfs_qm_syscalls.c
+++ b/fs/xfs/quota/xfs_qm_syscalls.c
@@ -1366,12 +1366,6 @@ xfs_qm_internalqcheck_adjust(
1366 return (error); 1366 return (error);
1367 } 1367 }
1368 1368
1369 if (ip->i_d.di_mode == 0) {
1370 xfs_iput_new(ip, lock_flags);
1371 *res = BULKSTAT_RV_NOTHING;
1372 return XFS_ERROR(ENOENT);
1373 }
1374
1375 /* 1369 /*
1376 * This inode can have blocks after eof which can get released 1370 * This inode can have blocks after eof which can get released
1377 * when we send it to inactive. Since we don't check the dquot 1371 * when we send it to inactive. Since we don't check the dquot
diff --git a/fs/xfs/quota/xfs_quota_priv.h b/fs/xfs/quota/xfs_quota_priv.h
index a8b85e2be9d5..5e4a40b1c565 100644
--- a/fs/xfs/quota/xfs_quota_priv.h
+++ b/fs/xfs/quota/xfs_quota_priv.h
@@ -27,11 +27,6 @@
27/* Number of dquots that fit in to a dquot block */ 27/* Number of dquots that fit in to a dquot block */
28#define XFS_QM_DQPERBLK(mp) ((mp)->m_quotainfo->qi_dqperchunk) 28#define XFS_QM_DQPERBLK(mp) ((mp)->m_quotainfo->qi_dqperchunk)
29 29
30#define XFS_ISLOCKED_INODE(ip) (ismrlocked(&(ip)->i_lock, \
31 MR_UPDATE | MR_ACCESS) != 0)
32#define XFS_ISLOCKED_INODE_EXCL(ip) (ismrlocked(&(ip)->i_lock, \
33 MR_UPDATE) != 0)
34
35#define XFS_DQ_IS_ADDEDTO_TRX(t, d) ((d)->q_transp == (t)) 30#define XFS_DQ_IS_ADDEDTO_TRX(t, d) ((d)->q_transp == (t))
36 31
37#define XFS_QI_MPLRECLAIMS(mp) ((mp)->m_quotainfo->qi_dqreclaims) 32#define XFS_QI_MPLRECLAIMS(mp) ((mp)->m_quotainfo->qi_dqreclaims)
diff --git a/fs/xfs/quota/xfs_trans_dquot.c b/fs/xfs/quota/xfs_trans_dquot.c
index f441f836ca8b..99611381e740 100644
--- a/fs/xfs/quota/xfs_trans_dquot.c
+++ b/fs/xfs/quota/xfs_trans_dquot.c
@@ -834,7 +834,7 @@ xfs_trans_reserve_quota_nblks(
834 ASSERT(ip->i_ino != mp->m_sb.sb_uquotino); 834 ASSERT(ip->i_ino != mp->m_sb.sb_uquotino);
835 ASSERT(ip->i_ino != mp->m_sb.sb_gquotino); 835 ASSERT(ip->i_ino != mp->m_sb.sb_gquotino);
836 836
837 ASSERT(XFS_ISLOCKED_INODE_EXCL(ip)); 837 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
838 ASSERT(XFS_IS_QUOTA_RUNNING(ip->i_mount)); 838 ASSERT(XFS_IS_QUOTA_RUNNING(ip->i_mount));
839 ASSERT((flags & ~(XFS_QMOPT_FORCE_RES | XFS_QMOPT_ENOSPC)) == 839 ASSERT((flags & ~(XFS_QMOPT_FORCE_RES | XFS_QMOPT_ENOSPC)) ==
840 XFS_TRANS_DQ_RES_RTBLKS || 840 XFS_TRANS_DQ_RES_RTBLKS ||
diff --git a/fs/xfs/support/debug.h b/fs/xfs/support/debug.h
index 855da0408647..75845f950814 100644
--- a/fs/xfs/support/debug.h
+++ b/fs/xfs/support/debug.h
@@ -49,8 +49,6 @@ extern void assfail(char *expr, char *f, int l);
49 49
50#else /* DEBUG */ 50#else /* DEBUG */
51 51
52#include <linux/random.h>
53
54#define ASSERT(expr) \ 52#define ASSERT(expr) \
55 (unlikely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__)) 53 (unlikely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__))
56 54
diff --git a/fs/xfs/xfs.h b/fs/xfs/xfs.h
index 765aaf65e2d3..540e4c989825 100644
--- a/fs/xfs/xfs.h
+++ b/fs/xfs/xfs.h
@@ -22,7 +22,7 @@
22#define STATIC 22#define STATIC
23#define DEBUG 1 23#define DEBUG 1
24#define XFS_BUF_LOCK_TRACKING 1 24#define XFS_BUF_LOCK_TRACKING 1
25#define QUOTADEBUG 1 25/* #define QUOTADEBUG 1 */
26#endif 26#endif
27 27
28#ifdef CONFIG_XFS_TRACE 28#ifdef CONFIG_XFS_TRACE
diff --git a/fs/xfs/xfs_acl.c b/fs/xfs/xfs_acl.c
index 8e130b9720ae..ebee3a4f703a 100644
--- a/fs/xfs/xfs_acl.c
+++ b/fs/xfs/xfs_acl.c
@@ -72,7 +72,7 @@ xfs_acl_vhasacl_default(
72{ 72{
73 int error; 73 int error;
74 74
75 if (!VN_ISDIR(vp)) 75 if (!S_ISDIR(vp->i_mode))
76 return 0; 76 return 0;
77 xfs_acl_get_attr(vp, NULL, _ACL_TYPE_DEFAULT, ATTR_KERNOVAL, &error); 77 xfs_acl_get_attr(vp, NULL, _ACL_TYPE_DEFAULT, ATTR_KERNOVAL, &error);
78 return (error == 0); 78 return (error == 0);
@@ -238,15 +238,8 @@ xfs_acl_vget(
238 error = EINVAL; 238 error = EINVAL;
239 goto out; 239 goto out;
240 } 240 }
241 if (kind == _ACL_TYPE_ACCESS) { 241 if (kind == _ACL_TYPE_ACCESS)
242 bhv_vattr_t va; 242 xfs_acl_sync_mode(xfs_vtoi(vp)->i_d.di_mode, xfs_acl);
243
244 va.va_mask = XFS_AT_MODE;
245 error = xfs_getattr(xfs_vtoi(vp), &va, 0);
246 if (error)
247 goto out;
248 xfs_acl_sync_mode(va.va_mode, xfs_acl);
249 }
250 error = -posix_acl_xfs_to_xattr(xfs_acl, ext_acl, size); 243 error = -posix_acl_xfs_to_xattr(xfs_acl, ext_acl, size);
251 } 244 }
252out: 245out:
@@ -341,14 +334,15 @@ xfs_acl_iaccess(
341{ 334{
342 xfs_acl_t *acl; 335 xfs_acl_t *acl;
343 int rval; 336 int rval;
337 struct xfs_name acl_name = {SGI_ACL_FILE, SGI_ACL_FILE_SIZE};
344 338
345 if (!(_ACL_ALLOC(acl))) 339 if (!(_ACL_ALLOC(acl)))
346 return -1; 340 return -1;
347 341
348 /* If the file has no ACL return -1. */ 342 /* If the file has no ACL return -1. */
349 rval = sizeof(xfs_acl_t); 343 rval = sizeof(xfs_acl_t);
350 if (xfs_attr_fetch(ip, SGI_ACL_FILE, SGI_ACL_FILE_SIZE, 344 if (xfs_attr_fetch(ip, &acl_name, (char *)acl, &rval,
351 (char *)acl, &rval, ATTR_ROOT | ATTR_KERNACCESS, cr)) { 345 ATTR_ROOT | ATTR_KERNACCESS)) {
352 _ACL_FREE(acl); 346 _ACL_FREE(acl);
353 return -1; 347 return -1;
354 } 348 }
@@ -373,23 +367,15 @@ xfs_acl_allow_set(
373 bhv_vnode_t *vp, 367 bhv_vnode_t *vp,
374 int kind) 368 int kind)
375{ 369{
376 xfs_inode_t *ip = xfs_vtoi(vp);
377 bhv_vattr_t va;
378 int error;
379
380 if (vp->i_flags & (S_IMMUTABLE|S_APPEND)) 370 if (vp->i_flags & (S_IMMUTABLE|S_APPEND))
381 return EPERM; 371 return EPERM;
382 if (kind == _ACL_TYPE_DEFAULT && !VN_ISDIR(vp)) 372 if (kind == _ACL_TYPE_DEFAULT && !S_ISDIR(vp->i_mode))
383 return ENOTDIR; 373 return ENOTDIR;
384 if (vp->i_sb->s_flags & MS_RDONLY) 374 if (vp->i_sb->s_flags & MS_RDONLY)
385 return EROFS; 375 return EROFS;
386 va.va_mask = XFS_AT_UID; 376 if (xfs_vtoi(vp)->i_d.di_uid != current->fsuid && !capable(CAP_FOWNER))
387 error = xfs_getattr(ip, &va, 0);
388 if (error)
389 return error;
390 if (va.va_uid != current->fsuid && !capable(CAP_FOWNER))
391 return EPERM; 377 return EPERM;
392 return error; 378 return 0;
393} 379}
394 380
395/* 381/*
@@ -594,7 +580,7 @@ xfs_acl_get_attr(
594 *error = xfs_attr_get(xfs_vtoi(vp), 580 *error = xfs_attr_get(xfs_vtoi(vp),
595 kind == _ACL_TYPE_ACCESS ? 581 kind == _ACL_TYPE_ACCESS ?
596 SGI_ACL_FILE : SGI_ACL_DEFAULT, 582 SGI_ACL_FILE : SGI_ACL_DEFAULT,
597 (char *)aclp, &len, flags, sys_cred); 583 (char *)aclp, &len, flags);
598 if (*error || (flags & ATTR_KERNOVAL)) 584 if (*error || (flags & ATTR_KERNOVAL))
599 return; 585 return;
600 xfs_acl_get_endian(aclp); 586 xfs_acl_get_endian(aclp);
@@ -643,7 +629,6 @@ xfs_acl_vtoacl(
643 xfs_acl_t *access_acl, 629 xfs_acl_t *access_acl,
644 xfs_acl_t *default_acl) 630 xfs_acl_t *default_acl)
645{ 631{
646 bhv_vattr_t va;
647 int error = 0; 632 int error = 0;
648 633
649 if (access_acl) { 634 if (access_acl) {
@@ -652,16 +637,10 @@ xfs_acl_vtoacl(
652 * be obtained for some reason, invalidate the access ACL. 637 * be obtained for some reason, invalidate the access ACL.
653 */ 638 */
654 xfs_acl_get_attr(vp, access_acl, _ACL_TYPE_ACCESS, 0, &error); 639 xfs_acl_get_attr(vp, access_acl, _ACL_TYPE_ACCESS, 0, &error);
655 if (!error) {
656 /* Got the ACL, need the mode... */
657 va.va_mask = XFS_AT_MODE;
658 error = xfs_getattr(xfs_vtoi(vp), &va, 0);
659 }
660
661 if (error) 640 if (error)
662 access_acl->acl_cnt = XFS_ACL_NOT_PRESENT; 641 access_acl->acl_cnt = XFS_ACL_NOT_PRESENT;
663 else /* We have a good ACL and the file mode, synchronize. */ 642 else /* We have a good ACL and the file mode, synchronize. */
664 xfs_acl_sync_mode(va.va_mode, access_acl); 643 xfs_acl_sync_mode(xfs_vtoi(vp)->i_d.di_mode, access_acl);
665 } 644 }
666 645
667 if (default_acl) { 646 if (default_acl) {
@@ -719,7 +698,7 @@ xfs_acl_inherit(
719 * If the new file is a directory, its default ACL is a copy of 698 * If the new file is a directory, its default ACL is a copy of
720 * the containing directory's default ACL. 699 * the containing directory's default ACL.
721 */ 700 */
722 if (VN_ISDIR(vp)) 701 if (S_ISDIR(vp->i_mode))
723 xfs_acl_set_attr(vp, pdaclp, _ACL_TYPE_DEFAULT, &error); 702 xfs_acl_set_attr(vp, pdaclp, _ACL_TYPE_DEFAULT, &error);
724 if (!error && !basicperms) 703 if (!error && !basicperms)
725 xfs_acl_set_attr(vp, cacl, _ACL_TYPE_ACCESS, &error); 704 xfs_acl_set_attr(vp, cacl, _ACL_TYPE_ACCESS, &error);
@@ -744,7 +723,7 @@ xfs_acl_setmode(
744 bhv_vattr_t va; 723 bhv_vattr_t va;
745 xfs_acl_entry_t *ap; 724 xfs_acl_entry_t *ap;
746 xfs_acl_entry_t *gap = NULL; 725 xfs_acl_entry_t *gap = NULL;
747 int i, error, nomask = 1; 726 int i, nomask = 1;
748 727
749 *basicperms = 1; 728 *basicperms = 1;
750 729
@@ -756,11 +735,7 @@ xfs_acl_setmode(
756 * mode. The m:: bits take precedence over the g:: bits. 735 * mode. The m:: bits take precedence over the g:: bits.
757 */ 736 */
758 va.va_mask = XFS_AT_MODE; 737 va.va_mask = XFS_AT_MODE;
759 error = xfs_getattr(xfs_vtoi(vp), &va, 0); 738 va.va_mode = xfs_vtoi(vp)->i_d.di_mode;
760 if (error)
761 return error;
762
763 va.va_mask = XFS_AT_MODE;
764 va.va_mode &= ~(S_IRWXU|S_IRWXG|S_IRWXO); 739 va.va_mode &= ~(S_IRWXU|S_IRWXG|S_IRWXO);
765 ap = acl->acl_entry; 740 ap = acl->acl_entry;
766 for (i = 0; i < acl->acl_cnt; ++i) { 741 for (i = 0; i < acl->acl_cnt; ++i) {
diff --git a/fs/xfs/xfs_attr.c b/fs/xfs/xfs_attr.c
index 36d781ee5fcc..df151a859186 100644
--- a/fs/xfs/xfs_attr.c
+++ b/fs/xfs/xfs_attr.c
@@ -101,14 +101,28 @@ STATIC int xfs_attr_rmtval_remove(xfs_da_args_t *args);
101ktrace_t *xfs_attr_trace_buf; 101ktrace_t *xfs_attr_trace_buf;
102#endif 102#endif
103 103
104STATIC int
105xfs_attr_name_to_xname(
106 struct xfs_name *xname,
107 const char *aname)
108{
109 if (!aname)
110 return EINVAL;
111 xname->name = aname;
112 xname->len = strlen(aname);
113 if (xname->len >= MAXNAMELEN)
114 return EFAULT; /* match IRIX behaviour */
115
116 return 0;
117}
104 118
105/*======================================================================== 119/*========================================================================
106 * Overall external interface routines. 120 * Overall external interface routines.
107 *========================================================================*/ 121 *========================================================================*/
108 122
109int 123int
110xfs_attr_fetch(xfs_inode_t *ip, const char *name, int namelen, 124xfs_attr_fetch(xfs_inode_t *ip, struct xfs_name *name,
111 char *value, int *valuelenp, int flags, struct cred *cred) 125 char *value, int *valuelenp, int flags)
112{ 126{
113 xfs_da_args_t args; 127 xfs_da_args_t args;
114 int error; 128 int error;
@@ -122,8 +136,8 @@ xfs_attr_fetch(xfs_inode_t *ip, const char *name, int namelen,
122 * Fill in the arg structure for this request. 136 * Fill in the arg structure for this request.
123 */ 137 */
124 memset((char *)&args, 0, sizeof(args)); 138 memset((char *)&args, 0, sizeof(args));
125 args.name = name; 139 args.name = name->name;
126 args.namelen = namelen; 140 args.namelen = name->len;
127 args.value = value; 141 args.value = value;
128 args.valuelen = *valuelenp; 142 args.valuelen = *valuelenp;
129 args.flags = flags; 143 args.flags = flags;
@@ -162,31 +176,29 @@ xfs_attr_get(
162 const char *name, 176 const char *name,
163 char *value, 177 char *value,
164 int *valuelenp, 178 int *valuelenp,
165 int flags, 179 int flags)
166 cred_t *cred)
167{ 180{
168 int error, namelen; 181 int error;
182 struct xfs_name xname;
169 183
170 XFS_STATS_INC(xs_attr_get); 184 XFS_STATS_INC(xs_attr_get);
171 185
172 if (!name)
173 return(EINVAL);
174 namelen = strlen(name);
175 if (namelen >= MAXNAMELEN)
176 return(EFAULT); /* match IRIX behaviour */
177
178 if (XFS_FORCED_SHUTDOWN(ip->i_mount)) 186 if (XFS_FORCED_SHUTDOWN(ip->i_mount))
179 return(EIO); 187 return(EIO);
180 188
189 error = xfs_attr_name_to_xname(&xname, name);
190 if (error)
191 return error;
192
181 xfs_ilock(ip, XFS_ILOCK_SHARED); 193 xfs_ilock(ip, XFS_ILOCK_SHARED);
182 error = xfs_attr_fetch(ip, name, namelen, value, valuelenp, flags, cred); 194 error = xfs_attr_fetch(ip, &xname, value, valuelenp, flags);
183 xfs_iunlock(ip, XFS_ILOCK_SHARED); 195 xfs_iunlock(ip, XFS_ILOCK_SHARED);
184 return(error); 196 return(error);
185} 197}
186 198
187int 199STATIC int
188xfs_attr_set_int(xfs_inode_t *dp, const char *name, int namelen, 200xfs_attr_set_int(xfs_inode_t *dp, struct xfs_name *name,
189 char *value, int valuelen, int flags) 201 char *value, int valuelen, int flags)
190{ 202{
191 xfs_da_args_t args; 203 xfs_da_args_t args;
192 xfs_fsblock_t firstblock; 204 xfs_fsblock_t firstblock;
@@ -209,7 +221,7 @@ xfs_attr_set_int(xfs_inode_t *dp, const char *name, int namelen,
209 */ 221 */
210 if (XFS_IFORK_Q(dp) == 0) { 222 if (XFS_IFORK_Q(dp) == 0) {
211 int sf_size = sizeof(xfs_attr_sf_hdr_t) + 223 int sf_size = sizeof(xfs_attr_sf_hdr_t) +
212 XFS_ATTR_SF_ENTSIZE_BYNAME(namelen, valuelen); 224 XFS_ATTR_SF_ENTSIZE_BYNAME(name->len, valuelen);
213 225
214 if ((error = xfs_bmap_add_attrfork(dp, sf_size, rsvd))) 226 if ((error = xfs_bmap_add_attrfork(dp, sf_size, rsvd)))
215 return(error); 227 return(error);
@@ -219,8 +231,8 @@ xfs_attr_set_int(xfs_inode_t *dp, const char *name, int namelen,
219 * Fill in the arg structure for this request. 231 * Fill in the arg structure for this request.
220 */ 232 */
221 memset((char *)&args, 0, sizeof(args)); 233 memset((char *)&args, 0, sizeof(args));
222 args.name = name; 234 args.name = name->name;
223 args.namelen = namelen; 235 args.namelen = name->len;
224 args.value = value; 236 args.value = value;
225 args.valuelen = valuelen; 237 args.valuelen = valuelen;
226 args.flags = flags; 238 args.flags = flags;
@@ -236,7 +248,7 @@ xfs_attr_set_int(xfs_inode_t *dp, const char *name, int namelen,
236 * Determine space new attribute will use, and if it would be 248 * Determine space new attribute will use, and if it would be
237 * "local" or "remote" (note: local != inline). 249 * "local" or "remote" (note: local != inline).
238 */ 250 */
239 size = xfs_attr_leaf_newentsize(namelen, valuelen, 251 size = xfs_attr_leaf_newentsize(name->len, valuelen,
240 mp->m_sb.sb_blocksize, &local); 252 mp->m_sb.sb_blocksize, &local);
241 253
242 nblks = XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK); 254 nblks = XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK);
@@ -429,26 +441,27 @@ xfs_attr_set(
429 int valuelen, 441 int valuelen,
430 int flags) 442 int flags)
431{ 443{
432 int namelen; 444 int error;
433 445 struct xfs_name xname;
434 namelen = strlen(name);
435 if (namelen >= MAXNAMELEN)
436 return EFAULT; /* match IRIX behaviour */
437 446
438 XFS_STATS_INC(xs_attr_set); 447 XFS_STATS_INC(xs_attr_set);
439 448
440 if (XFS_FORCED_SHUTDOWN(dp->i_mount)) 449 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
441 return (EIO); 450 return (EIO);
442 451
443 return xfs_attr_set_int(dp, name, namelen, value, valuelen, flags); 452 error = xfs_attr_name_to_xname(&xname, name);
453 if (error)
454 return error;
455
456 return xfs_attr_set_int(dp, &xname, value, valuelen, flags);
444} 457}
445 458
446/* 459/*
447 * Generic handler routine to remove a name from an attribute list. 460 * Generic handler routine to remove a name from an attribute list.
448 * Transitions attribute list from Btree to shortform as necessary. 461 * Transitions attribute list from Btree to shortform as necessary.
449 */ 462 */
450int 463STATIC int
451xfs_attr_remove_int(xfs_inode_t *dp, const char *name, int namelen, int flags) 464xfs_attr_remove_int(xfs_inode_t *dp, struct xfs_name *name, int flags)
452{ 465{
453 xfs_da_args_t args; 466 xfs_da_args_t args;
454 xfs_fsblock_t firstblock; 467 xfs_fsblock_t firstblock;
@@ -460,8 +473,8 @@ xfs_attr_remove_int(xfs_inode_t *dp, const char *name, int namelen, int flags)
460 * Fill in the arg structure for this request. 473 * Fill in the arg structure for this request.
461 */ 474 */
462 memset((char *)&args, 0, sizeof(args)); 475 memset((char *)&args, 0, sizeof(args));
463 args.name = name; 476 args.name = name->name;
464 args.namelen = namelen; 477 args.namelen = name->len;
465 args.flags = flags; 478 args.flags = flags;
466 args.hashval = xfs_da_hashname(args.name, args.namelen); 479 args.hashval = xfs_da_hashname(args.name, args.namelen);
467 args.dp = dp; 480 args.dp = dp;
@@ -575,17 +588,18 @@ xfs_attr_remove(
575 const char *name, 588 const char *name,
576 int flags) 589 int flags)
577{ 590{
578 int namelen; 591 int error;
579 592 struct xfs_name xname;
580 namelen = strlen(name);
581 if (namelen >= MAXNAMELEN)
582 return EFAULT; /* match IRIX behaviour */
583 593
584 XFS_STATS_INC(xs_attr_remove); 594 XFS_STATS_INC(xs_attr_remove);
585 595
586 if (XFS_FORCED_SHUTDOWN(dp->i_mount)) 596 if (XFS_FORCED_SHUTDOWN(dp->i_mount))
587 return (EIO); 597 return (EIO);
588 598
599 error = xfs_attr_name_to_xname(&xname, name);
600 if (error)
601 return error;
602
589 xfs_ilock(dp, XFS_ILOCK_SHARED); 603 xfs_ilock(dp, XFS_ILOCK_SHARED);
590 if (XFS_IFORK_Q(dp) == 0 || 604 if (XFS_IFORK_Q(dp) == 0 ||
591 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS && 605 (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
@@ -595,10 +609,10 @@ xfs_attr_remove(
595 } 609 }
596 xfs_iunlock(dp, XFS_ILOCK_SHARED); 610 xfs_iunlock(dp, XFS_ILOCK_SHARED);
597 611
598 return xfs_attr_remove_int(dp, name, namelen, flags); 612 return xfs_attr_remove_int(dp, &xname, flags);
599} 613}
600 614
601int /* error */ 615STATIC int
602xfs_attr_list_int(xfs_attr_list_context_t *context) 616xfs_attr_list_int(xfs_attr_list_context_t *context)
603{ 617{
604 int error; 618 int error;
@@ -2522,8 +2536,7 @@ attr_generic_get(
2522{ 2536{
2523 int error, asize = size; 2537 int error, asize = size;
2524 2538
2525 error = xfs_attr_get(xfs_vtoi(vp), name, data, 2539 error = xfs_attr_get(xfs_vtoi(vp), name, data, &asize, xflags);
2526 &asize, xflags, NULL);
2527 if (!error) 2540 if (!error)
2528 return asize; 2541 return asize;
2529 return -error; 2542 return -error;
diff --git a/fs/xfs/xfs_attr.h b/fs/xfs/xfs_attr.h
index 786eba3121c4..6cfc9384fe35 100644
--- a/fs/xfs/xfs_attr.h
+++ b/fs/xfs/xfs_attr.h
@@ -158,14 +158,10 @@ struct xfs_da_args;
158/* 158/*
159 * Overall external interface routines. 159 * Overall external interface routines.
160 */ 160 */
161int xfs_attr_set_int(struct xfs_inode *, const char *, int, char *, int, int);
162int xfs_attr_remove_int(struct xfs_inode *, const char *, int, int);
163int xfs_attr_list_int(struct xfs_attr_list_context *);
164int xfs_attr_inactive(struct xfs_inode *dp); 161int xfs_attr_inactive(struct xfs_inode *dp);
165 162
166int xfs_attr_shortform_getvalue(struct xfs_da_args *); 163int xfs_attr_shortform_getvalue(struct xfs_da_args *);
167int xfs_attr_fetch(struct xfs_inode *, const char *, int, 164int xfs_attr_fetch(struct xfs_inode *, struct xfs_name *, char *, int *, int);
168 char *, int *, int, struct cred *);
169int xfs_attr_rmtval_get(struct xfs_da_args *args); 165int xfs_attr_rmtval_get(struct xfs_da_args *args);
170 166
171#endif /* __XFS_ATTR_H__ */ 167#endif /* __XFS_ATTR_H__ */
diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
index eb198c01c35d..53c259f5a5af 100644
--- a/fs/xfs/xfs_bmap.c
+++ b/fs/xfs/xfs_bmap.c
@@ -4074,7 +4074,6 @@ xfs_bmap_add_attrfork(
4074error2: 4074error2:
4075 xfs_bmap_cancel(&flist); 4075 xfs_bmap_cancel(&flist);
4076error1: 4076error1:
4077 ASSERT(ismrlocked(&ip->i_lock,MR_UPDATE));
4078 xfs_iunlock(ip, XFS_ILOCK_EXCL); 4077 xfs_iunlock(ip, XFS_ILOCK_EXCL);
4079error0: 4078error0:
4080 xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT); 4079 xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES|XFS_TRANS_ABORT);
diff --git a/fs/xfs/xfs_dfrag.c b/fs/xfs/xfs_dfrag.c
index 3f53fad356a3..5f3647cb9885 100644
--- a/fs/xfs/xfs_dfrag.c
+++ b/fs/xfs/xfs_dfrag.c
@@ -162,7 +162,7 @@ xfs_swap_extents(
162 ips[1] = ip; 162 ips[1] = ip;
163 } 163 }
164 164
165 xfs_lock_inodes(ips, 2, 0, lock_flags); 165 xfs_lock_inodes(ips, 2, lock_flags);
166 locked = 1; 166 locked = 1;
167 167
168 /* Verify that both files have the same format */ 168 /* Verify that both files have the same format */
@@ -265,7 +265,7 @@ xfs_swap_extents(
265 locked = 0; 265 locked = 0;
266 goto error0; 266 goto error0;
267 } 267 }
268 xfs_lock_inodes(ips, 2, 0, XFS_ILOCK_EXCL); 268 xfs_lock_inodes(ips, 2, XFS_ILOCK_EXCL);
269 269
270 /* 270 /*
271 * Count the number of extended attribute blocks 271 * Count the number of extended attribute blocks
diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c
index d3a0f538d6a6..381ebda4f7bc 100644
--- a/fs/xfs/xfs_fsops.c
+++ b/fs/xfs/xfs_fsops.c
@@ -462,7 +462,7 @@ xfs_fs_counts(
462 xfs_mount_t *mp, 462 xfs_mount_t *mp,
463 xfs_fsop_counts_t *cnt) 463 xfs_fsop_counts_t *cnt)
464{ 464{
465 xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT); 465 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
466 spin_lock(&mp->m_sb_lock); 466 spin_lock(&mp->m_sb_lock);
467 cnt->freedata = mp->m_sb.sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp); 467 cnt->freedata = mp->m_sb.sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
468 cnt->freertx = mp->m_sb.sb_frextents; 468 cnt->freertx = mp->m_sb.sb_frextents;
@@ -524,7 +524,7 @@ xfs_reserve_blocks(
524 */ 524 */
525retry: 525retry:
526 spin_lock(&mp->m_sb_lock); 526 spin_lock(&mp->m_sb_lock);
527 xfs_icsb_sync_counters_flags(mp, XFS_ICSB_SB_LOCKED); 527 xfs_icsb_sync_counters_locked(mp, 0);
528 528
529 /* 529 /*
530 * If our previous reservation was larger than the current value, 530 * If our previous reservation was larger than the current value,
@@ -552,11 +552,8 @@ retry:
552 mp->m_resblks += free; 552 mp->m_resblks += free;
553 mp->m_resblks_avail += free; 553 mp->m_resblks_avail += free;
554 fdblks_delta = -free; 554 fdblks_delta = -free;
555 mp->m_sb.sb_fdblocks = XFS_ALLOC_SET_ASIDE(mp);
556 } else { 555 } else {
557 fdblks_delta = -delta; 556 fdblks_delta = -delta;
558 mp->m_sb.sb_fdblocks =
559 lcounter + XFS_ALLOC_SET_ASIDE(mp);
560 mp->m_resblks = request; 557 mp->m_resblks = request;
561 mp->m_resblks_avail += delta; 558 mp->m_resblks_avail += delta;
562 } 559 }
@@ -587,7 +584,6 @@ out:
587 if (error == ENOSPC) 584 if (error == ENOSPC)
588 goto retry; 585 goto retry;
589 } 586 }
590
591 return 0; 587 return 0;
592} 588}
593 589
diff --git a/fs/xfs/xfs_ialloc.c b/fs/xfs/xfs_ialloc.c
index a64dfbd565a5..aad8c5da38af 100644
--- a/fs/xfs/xfs_ialloc.c
+++ b/fs/xfs/xfs_ialloc.c
@@ -147,6 +147,7 @@ xfs_ialloc_ag_alloc(
147 int version; /* inode version number to use */ 147 int version; /* inode version number to use */
148 int isaligned = 0; /* inode allocation at stripe unit */ 148 int isaligned = 0; /* inode allocation at stripe unit */
149 /* boundary */ 149 /* boundary */
150 unsigned int gen;
150 151
151 args.tp = tp; 152 args.tp = tp;
152 args.mp = tp->t_mountp; 153 args.mp = tp->t_mountp;
@@ -290,6 +291,14 @@ xfs_ialloc_ag_alloc(
290 else 291 else
291 version = XFS_DINODE_VERSION_1; 292 version = XFS_DINODE_VERSION_1;
292 293
294 /*
295 * Seed the new inode cluster with a random generation number. This
296 * prevents short-term reuse of generation numbers if a chunk is
297 * freed and then immediately reallocated. We use random numbers
298 * rather than a linear progression to prevent the next generation
299 * number from being easily guessable.
300 */
301 gen = random32();
293 for (j = 0; j < nbufs; j++) { 302 for (j = 0; j < nbufs; j++) {
294 /* 303 /*
295 * Get the block. 304 * Get the block.
@@ -309,6 +318,7 @@ xfs_ialloc_ag_alloc(
309 free = XFS_MAKE_IPTR(args.mp, fbuf, i); 318 free = XFS_MAKE_IPTR(args.mp, fbuf, i);
310 free->di_core.di_magic = cpu_to_be16(XFS_DINODE_MAGIC); 319 free->di_core.di_magic = cpu_to_be16(XFS_DINODE_MAGIC);
311 free->di_core.di_version = version; 320 free->di_core.di_version = version;
321 free->di_core.di_gen = cpu_to_be32(gen);
312 free->di_next_unlinked = cpu_to_be32(NULLAGINO); 322 free->di_next_unlinked = cpu_to_be32(NULLAGINO);
313 xfs_ialloc_log_di(tp, fbuf, i, 323 xfs_ialloc_log_di(tp, fbuf, i,
314 XFS_DI_CORE_BITS | XFS_DI_NEXT_UNLINKED); 324 XFS_DI_CORE_BITS | XFS_DI_NEXT_UNLINKED);
diff --git a/fs/xfs/xfs_iget.c b/fs/xfs/xfs_iget.c
index e657c5128460..b07604b94d9f 100644
--- a/fs/xfs/xfs_iget.c
+++ b/fs/xfs/xfs_iget.c
@@ -593,8 +593,9 @@ xfs_iunlock_map_shared(
593 * XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL 593 * XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL
594 */ 594 */
595void 595void
596xfs_ilock(xfs_inode_t *ip, 596xfs_ilock(
597 uint lock_flags) 597 xfs_inode_t *ip,
598 uint lock_flags)
598{ 599{
599 /* 600 /*
600 * You can't set both SHARED and EXCL for the same lock, 601 * You can't set both SHARED and EXCL for the same lock,
@@ -607,16 +608,16 @@ xfs_ilock(xfs_inode_t *ip,
607 (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)); 608 (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL));
608 ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_LOCK_DEP_MASK)) == 0); 609 ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_LOCK_DEP_MASK)) == 0);
609 610
610 if (lock_flags & XFS_IOLOCK_EXCL) { 611 if (lock_flags & XFS_IOLOCK_EXCL)
611 mrupdate_nested(&ip->i_iolock, XFS_IOLOCK_DEP(lock_flags)); 612 mrupdate_nested(&ip->i_iolock, XFS_IOLOCK_DEP(lock_flags));
612 } else if (lock_flags & XFS_IOLOCK_SHARED) { 613 else if (lock_flags & XFS_IOLOCK_SHARED)
613 mraccess_nested(&ip->i_iolock, XFS_IOLOCK_DEP(lock_flags)); 614 mraccess_nested(&ip->i_iolock, XFS_IOLOCK_DEP(lock_flags));
614 } 615
615 if (lock_flags & XFS_ILOCK_EXCL) { 616 if (lock_flags & XFS_ILOCK_EXCL)
616 mrupdate_nested(&ip->i_lock, XFS_ILOCK_DEP(lock_flags)); 617 mrupdate_nested(&ip->i_lock, XFS_ILOCK_DEP(lock_flags));
617 } else if (lock_flags & XFS_ILOCK_SHARED) { 618 else if (lock_flags & XFS_ILOCK_SHARED)
618 mraccess_nested(&ip->i_lock, XFS_ILOCK_DEP(lock_flags)); 619 mraccess_nested(&ip->i_lock, XFS_ILOCK_DEP(lock_flags));
619 } 620
620 xfs_ilock_trace(ip, 1, lock_flags, (inst_t *)__return_address); 621 xfs_ilock_trace(ip, 1, lock_flags, (inst_t *)__return_address);
621} 622}
622 623
@@ -631,15 +632,12 @@ xfs_ilock(xfs_inode_t *ip,
631 * lock_flags -- this parameter indicates the inode's locks to be 632 * lock_flags -- this parameter indicates the inode's locks to be
632 * to be locked. See the comment for xfs_ilock() for a list 633 * to be locked. See the comment for xfs_ilock() for a list
633 * of valid values. 634 * of valid values.
634 *
635 */ 635 */
636int 636int
637xfs_ilock_nowait(xfs_inode_t *ip, 637xfs_ilock_nowait(
638 uint lock_flags) 638 xfs_inode_t *ip,
639 uint lock_flags)
639{ 640{
640 int iolocked;
641 int ilocked;
642
643 /* 641 /*
644 * You can't set both SHARED and EXCL for the same lock, 642 * You can't set both SHARED and EXCL for the same lock,
645 * and only XFS_IOLOCK_SHARED, XFS_IOLOCK_EXCL, XFS_ILOCK_SHARED, 643 * and only XFS_IOLOCK_SHARED, XFS_IOLOCK_EXCL, XFS_ILOCK_SHARED,
@@ -651,37 +649,30 @@ xfs_ilock_nowait(xfs_inode_t *ip,
651 (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)); 649 (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL));
652 ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_LOCK_DEP_MASK)) == 0); 650 ASSERT((lock_flags & ~(XFS_LOCK_MASK | XFS_LOCK_DEP_MASK)) == 0);
653 651
654 iolocked = 0;
655 if (lock_flags & XFS_IOLOCK_EXCL) { 652 if (lock_flags & XFS_IOLOCK_EXCL) {
656 iolocked = mrtryupdate(&ip->i_iolock); 653 if (!mrtryupdate(&ip->i_iolock))
657 if (!iolocked) { 654 goto out;
658 return 0;
659 }
660 } else if (lock_flags & XFS_IOLOCK_SHARED) { 655 } else if (lock_flags & XFS_IOLOCK_SHARED) {
661 iolocked = mrtryaccess(&ip->i_iolock); 656 if (!mrtryaccess(&ip->i_iolock))
662 if (!iolocked) { 657 goto out;
663 return 0;
664 }
665 } 658 }
666 if (lock_flags & XFS_ILOCK_EXCL) { 659 if (lock_flags & XFS_ILOCK_EXCL) {
667 ilocked = mrtryupdate(&ip->i_lock); 660 if (!mrtryupdate(&ip->i_lock))
668 if (!ilocked) { 661 goto out_undo_iolock;
669 if (iolocked) {
670 mrunlock(&ip->i_iolock);
671 }
672 return 0;
673 }
674 } else if (lock_flags & XFS_ILOCK_SHARED) { 662 } else if (lock_flags & XFS_ILOCK_SHARED) {
675 ilocked = mrtryaccess(&ip->i_lock); 663 if (!mrtryaccess(&ip->i_lock))
676 if (!ilocked) { 664 goto out_undo_iolock;
677 if (iolocked) {
678 mrunlock(&ip->i_iolock);
679 }
680 return 0;
681 }
682 } 665 }
683 xfs_ilock_trace(ip, 2, lock_flags, (inst_t *)__return_address); 666 xfs_ilock_trace(ip, 2, lock_flags, (inst_t *)__return_address);
684 return 1; 667 return 1;
668
669 out_undo_iolock:
670 if (lock_flags & XFS_IOLOCK_EXCL)
671 mrunlock_excl(&ip->i_iolock);
672 else if (lock_flags & XFS_IOLOCK_SHARED)
673 mrunlock_shared(&ip->i_iolock);
674 out:
675 return 0;
685} 676}
686 677
687/* 678/*
@@ -697,8 +688,9 @@ xfs_ilock_nowait(xfs_inode_t *ip,
697 * 688 *
698 */ 689 */
699void 690void
700xfs_iunlock(xfs_inode_t *ip, 691xfs_iunlock(
701 uint lock_flags) 692 xfs_inode_t *ip,
693 uint lock_flags)
702{ 694{
703 /* 695 /*
704 * You can't set both SHARED and EXCL for the same lock, 696 * You can't set both SHARED and EXCL for the same lock,
@@ -713,31 +705,25 @@ xfs_iunlock(xfs_inode_t *ip,
713 XFS_LOCK_DEP_MASK)) == 0); 705 XFS_LOCK_DEP_MASK)) == 0);
714 ASSERT(lock_flags != 0); 706 ASSERT(lock_flags != 0);
715 707
716 if (lock_flags & (XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL)) { 708 if (lock_flags & XFS_IOLOCK_EXCL)
717 ASSERT(!(lock_flags & XFS_IOLOCK_SHARED) || 709 mrunlock_excl(&ip->i_iolock);
718 (ismrlocked(&ip->i_iolock, MR_ACCESS))); 710 else if (lock_flags & XFS_IOLOCK_SHARED)
719 ASSERT(!(lock_flags & XFS_IOLOCK_EXCL) || 711 mrunlock_shared(&ip->i_iolock);
720 (ismrlocked(&ip->i_iolock, MR_UPDATE)));
721 mrunlock(&ip->i_iolock);
722 }
723 712
724 if (lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) { 713 if (lock_flags & XFS_ILOCK_EXCL)
725 ASSERT(!(lock_flags & XFS_ILOCK_SHARED) || 714 mrunlock_excl(&ip->i_lock);
726 (ismrlocked(&ip->i_lock, MR_ACCESS))); 715 else if (lock_flags & XFS_ILOCK_SHARED)
727 ASSERT(!(lock_flags & XFS_ILOCK_EXCL) || 716 mrunlock_shared(&ip->i_lock);
728 (ismrlocked(&ip->i_lock, MR_UPDATE)));
729 mrunlock(&ip->i_lock);
730 717
718 if ((lock_flags & (XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)) &&
719 !(lock_flags & XFS_IUNLOCK_NONOTIFY) && ip->i_itemp) {
731 /* 720 /*
732 * Let the AIL know that this item has been unlocked in case 721 * Let the AIL know that this item has been unlocked in case
733 * it is in the AIL and anyone is waiting on it. Don't do 722 * it is in the AIL and anyone is waiting on it. Don't do
734 * this if the caller has asked us not to. 723 * this if the caller has asked us not to.
735 */ 724 */
736 if (!(lock_flags & XFS_IUNLOCK_NONOTIFY) && 725 xfs_trans_unlocked_item(ip->i_mount,
737 ip->i_itemp != NULL) { 726 (xfs_log_item_t*)(ip->i_itemp));
738 xfs_trans_unlocked_item(ip->i_mount,
739 (xfs_log_item_t*)(ip->i_itemp));
740 }
741 } 727 }
742 xfs_ilock_trace(ip, 3, lock_flags, (inst_t *)__return_address); 728 xfs_ilock_trace(ip, 3, lock_flags, (inst_t *)__return_address);
743} 729}
@@ -747,21 +733,47 @@ xfs_iunlock(xfs_inode_t *ip,
747 * if it is being demoted. 733 * if it is being demoted.
748 */ 734 */
749void 735void
750xfs_ilock_demote(xfs_inode_t *ip, 736xfs_ilock_demote(
751 uint lock_flags) 737 xfs_inode_t *ip,
738 uint lock_flags)
752{ 739{
753 ASSERT(lock_flags & (XFS_IOLOCK_EXCL|XFS_ILOCK_EXCL)); 740 ASSERT(lock_flags & (XFS_IOLOCK_EXCL|XFS_ILOCK_EXCL));
754 ASSERT((lock_flags & ~(XFS_IOLOCK_EXCL|XFS_ILOCK_EXCL)) == 0); 741 ASSERT((lock_flags & ~(XFS_IOLOCK_EXCL|XFS_ILOCK_EXCL)) == 0);
755 742
756 if (lock_flags & XFS_ILOCK_EXCL) { 743 if (lock_flags & XFS_ILOCK_EXCL)
757 ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE));
758 mrdemote(&ip->i_lock); 744 mrdemote(&ip->i_lock);
759 } 745 if (lock_flags & XFS_IOLOCK_EXCL)
760 if (lock_flags & XFS_IOLOCK_EXCL) {
761 ASSERT(ismrlocked(&ip->i_iolock, MR_UPDATE));
762 mrdemote(&ip->i_iolock); 746 mrdemote(&ip->i_iolock);
747}
748
749#ifdef DEBUG
750/*
751 * Debug-only routine, without additional rw_semaphore APIs, we can
752 * now only answer requests regarding whether we hold the lock for write
753 * (reader state is outside our visibility, we only track writer state).
754 *
755 * Note: this means !xfs_isilocked would give false positives, so don't do that.
756 */
757int
758xfs_isilocked(
759 xfs_inode_t *ip,
760 uint lock_flags)
761{
762 if ((lock_flags & (XFS_ILOCK_EXCL|XFS_ILOCK_SHARED)) ==
763 XFS_ILOCK_EXCL) {
764 if (!ip->i_lock.mr_writer)
765 return 0;
763 } 766 }
767
768 if ((lock_flags & (XFS_IOLOCK_EXCL|XFS_IOLOCK_SHARED)) ==
769 XFS_IOLOCK_EXCL) {
770 if (!ip->i_iolock.mr_writer)
771 return 0;
772 }
773
774 return 1;
764} 775}
776#endif
765 777
766/* 778/*
767 * The following three routines simply manage the i_flock 779 * The following three routines simply manage the i_flock
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index ca12acb90394..cf0bb9c1d621 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -1291,7 +1291,7 @@ xfs_file_last_byte(
1291 xfs_fileoff_t size_last_block; 1291 xfs_fileoff_t size_last_block;
1292 int error; 1292 int error;
1293 1293
1294 ASSERT(ismrlocked(&(ip->i_iolock), MR_UPDATE | MR_ACCESS)); 1294 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL|XFS_IOLOCK_SHARED));
1295 1295
1296 mp = ip->i_mount; 1296 mp = ip->i_mount;
1297 /* 1297 /*
@@ -1402,7 +1402,7 @@ xfs_itruncate_start(
1402 bhv_vnode_t *vp; 1402 bhv_vnode_t *vp;
1403 int error = 0; 1403 int error = 0;
1404 1404
1405 ASSERT(ismrlocked(&ip->i_iolock, MR_UPDATE) != 0); 1405 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL));
1406 ASSERT((new_size == 0) || (new_size <= ip->i_size)); 1406 ASSERT((new_size == 0) || (new_size <= ip->i_size));
1407 ASSERT((flags == XFS_ITRUNC_DEFINITE) || 1407 ASSERT((flags == XFS_ITRUNC_DEFINITE) ||
1408 (flags == XFS_ITRUNC_MAYBE)); 1408 (flags == XFS_ITRUNC_MAYBE));
@@ -1528,8 +1528,7 @@ xfs_itruncate_finish(
1528 xfs_bmap_free_t free_list; 1528 xfs_bmap_free_t free_list;
1529 int error; 1529 int error;
1530 1530
1531 ASSERT(ismrlocked(&ip->i_iolock, MR_UPDATE) != 0); 1531 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_IOLOCK_EXCL));
1532 ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE) != 0);
1533 ASSERT((new_size == 0) || (new_size <= ip->i_size)); 1532 ASSERT((new_size == 0) || (new_size <= ip->i_size));
1534 ASSERT(*tp != NULL); 1533 ASSERT(*tp != NULL);
1535 ASSERT((*tp)->t_flags & XFS_TRANS_PERM_LOG_RES); 1534 ASSERT((*tp)->t_flags & XFS_TRANS_PERM_LOG_RES);
@@ -1780,8 +1779,7 @@ xfs_igrow_start(
1780 xfs_fsize_t new_size, 1779 xfs_fsize_t new_size,
1781 cred_t *credp) 1780 cred_t *credp)
1782{ 1781{
1783 ASSERT(ismrlocked(&(ip->i_lock), MR_UPDATE) != 0); 1782 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_IOLOCK_EXCL));
1784 ASSERT(ismrlocked(&(ip->i_iolock), MR_UPDATE) != 0);
1785 ASSERT(new_size > ip->i_size); 1783 ASSERT(new_size > ip->i_size);
1786 1784
1787 /* 1785 /*
@@ -1809,8 +1807,7 @@ xfs_igrow_finish(
1809 xfs_fsize_t new_size, 1807 xfs_fsize_t new_size,
1810 int change_flag) 1808 int change_flag)
1811{ 1809{
1812 ASSERT(ismrlocked(&(ip->i_lock), MR_UPDATE) != 0); 1810 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_IOLOCK_EXCL));
1813 ASSERT(ismrlocked(&(ip->i_iolock), MR_UPDATE) != 0);
1814 ASSERT(ip->i_transp == tp); 1811 ASSERT(ip->i_transp == tp);
1815 ASSERT(new_size > ip->i_size); 1812 ASSERT(new_size > ip->i_size);
1816 1813
@@ -2287,7 +2284,7 @@ xfs_ifree(
2287 xfs_dinode_t *dip; 2284 xfs_dinode_t *dip;
2288 xfs_buf_t *ibp; 2285 xfs_buf_t *ibp;
2289 2286
2290 ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE)); 2287 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
2291 ASSERT(ip->i_transp == tp); 2288 ASSERT(ip->i_transp == tp);
2292 ASSERT(ip->i_d.di_nlink == 0); 2289 ASSERT(ip->i_d.di_nlink == 0);
2293 ASSERT(ip->i_d.di_nextents == 0); 2290 ASSERT(ip->i_d.di_nextents == 0);
@@ -2746,7 +2743,7 @@ void
2746xfs_ipin( 2743xfs_ipin(
2747 xfs_inode_t *ip) 2744 xfs_inode_t *ip)
2748{ 2745{
2749 ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE)); 2746 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
2750 2747
2751 atomic_inc(&ip->i_pincount); 2748 atomic_inc(&ip->i_pincount);
2752} 2749}
@@ -2779,7 +2776,7 @@ __xfs_iunpin_wait(
2779{ 2776{
2780 xfs_inode_log_item_t *iip = ip->i_itemp; 2777 xfs_inode_log_item_t *iip = ip->i_itemp;
2781 2778
2782 ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE | MR_ACCESS)); 2779 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_ILOCK_SHARED));
2783 if (atomic_read(&ip->i_pincount) == 0) 2780 if (atomic_read(&ip->i_pincount) == 0)
2784 return; 2781 return;
2785 2782
@@ -2829,7 +2826,7 @@ xfs_iextents_copy(
2829 xfs_fsblock_t start_block; 2826 xfs_fsblock_t start_block;
2830 2827
2831 ifp = XFS_IFORK_PTR(ip, whichfork); 2828 ifp = XFS_IFORK_PTR(ip, whichfork);
2832 ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE|MR_ACCESS)); 2829 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_ILOCK_SHARED));
2833 ASSERT(ifp->if_bytes > 0); 2830 ASSERT(ifp->if_bytes > 0);
2834 2831
2835 nrecs = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t); 2832 nrecs = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t);
@@ -3132,7 +3129,7 @@ xfs_iflush(
3132 3129
3133 XFS_STATS_INC(xs_iflush_count); 3130 XFS_STATS_INC(xs_iflush_count);
3134 3131
3135 ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE|MR_ACCESS)); 3132 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_ILOCK_SHARED));
3136 ASSERT(issemalocked(&(ip->i_flock))); 3133 ASSERT(issemalocked(&(ip->i_flock)));
3137 ASSERT(ip->i_d.di_format != XFS_DINODE_FMT_BTREE || 3134 ASSERT(ip->i_d.di_format != XFS_DINODE_FMT_BTREE ||
3138 ip->i_d.di_nextents > ip->i_df.if_ext_max); 3135 ip->i_d.di_nextents > ip->i_df.if_ext_max);
@@ -3297,7 +3294,7 @@ xfs_iflush_int(
3297 int first; 3294 int first;
3298#endif 3295#endif
3299 3296
3300 ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE|MR_ACCESS)); 3297 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_ILOCK_SHARED));
3301 ASSERT(issemalocked(&(ip->i_flock))); 3298 ASSERT(issemalocked(&(ip->i_flock)));
3302 ASSERT(ip->i_d.di_format != XFS_DINODE_FMT_BTREE || 3299 ASSERT(ip->i_d.di_format != XFS_DINODE_FMT_BTREE ||
3303 ip->i_d.di_nextents > ip->i_df.if_ext_max); 3300 ip->i_d.di_nextents > ip->i_df.if_ext_max);
diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h
index 93c37697a72c..0a999fee4f03 100644
--- a/fs/xfs/xfs_inode.h
+++ b/fs/xfs/xfs_inode.h
@@ -386,20 +386,9 @@ xfs_iflags_test_and_clear(xfs_inode_t *ip, unsigned short flags)
386#define XFS_ILOCK_EXCL (1<<2) 386#define XFS_ILOCK_EXCL (1<<2)
387#define XFS_ILOCK_SHARED (1<<3) 387#define XFS_ILOCK_SHARED (1<<3)
388#define XFS_IUNLOCK_NONOTIFY (1<<4) 388#define XFS_IUNLOCK_NONOTIFY (1<<4)
389/* #define XFS_IOLOCK_NESTED (1<<5) */
390#define XFS_EXTENT_TOKEN_RD (1<<6)
391#define XFS_SIZE_TOKEN_RD (1<<7)
392#define XFS_EXTSIZE_RD (XFS_EXTENT_TOKEN_RD|XFS_SIZE_TOKEN_RD)
393#define XFS_WILLLEND (1<<8) /* Always acquire tokens for lending */
394#define XFS_EXTENT_TOKEN_WR (XFS_EXTENT_TOKEN_RD | XFS_WILLLEND)
395#define XFS_SIZE_TOKEN_WR (XFS_SIZE_TOKEN_RD | XFS_WILLLEND)
396#define XFS_EXTSIZE_WR (XFS_EXTSIZE_RD | XFS_WILLLEND)
397/* TODO:XFS_SIZE_TOKEN_WANT (1<<9) */
398 389
399#define XFS_LOCK_MASK (XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED \ 390#define XFS_LOCK_MASK (XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED \
400 | XFS_ILOCK_EXCL | XFS_ILOCK_SHARED \ 391 | XFS_ILOCK_EXCL | XFS_ILOCK_SHARED)
401 | XFS_EXTENT_TOKEN_RD | XFS_SIZE_TOKEN_RD \
402 | XFS_WILLLEND)
403 392
404/* 393/*
405 * Flags for lockdep annotations. 394 * Flags for lockdep annotations.
@@ -483,6 +472,7 @@ void xfs_ilock(xfs_inode_t *, uint);
483int xfs_ilock_nowait(xfs_inode_t *, uint); 472int xfs_ilock_nowait(xfs_inode_t *, uint);
484void xfs_iunlock(xfs_inode_t *, uint); 473void xfs_iunlock(xfs_inode_t *, uint);
485void xfs_ilock_demote(xfs_inode_t *, uint); 474void xfs_ilock_demote(xfs_inode_t *, uint);
475int xfs_isilocked(xfs_inode_t *, uint);
486void xfs_iflock(xfs_inode_t *); 476void xfs_iflock(xfs_inode_t *);
487int xfs_iflock_nowait(xfs_inode_t *); 477int xfs_iflock_nowait(xfs_inode_t *);
488uint xfs_ilock_map_shared(xfs_inode_t *); 478uint xfs_ilock_map_shared(xfs_inode_t *);
@@ -534,7 +524,7 @@ int xfs_iflush(xfs_inode_t *, uint);
534void xfs_iflush_all(struct xfs_mount *); 524void xfs_iflush_all(struct xfs_mount *);
535void xfs_ichgtime(xfs_inode_t *, int); 525void xfs_ichgtime(xfs_inode_t *, int);
536xfs_fsize_t xfs_file_last_byte(xfs_inode_t *); 526xfs_fsize_t xfs_file_last_byte(xfs_inode_t *);
537void xfs_lock_inodes(xfs_inode_t **, int, int, uint); 527void xfs_lock_inodes(xfs_inode_t **, int, uint);
538 528
539void xfs_synchronize_atime(xfs_inode_t *); 529void xfs_synchronize_atime(xfs_inode_t *);
540void xfs_mark_inode_dirty_sync(xfs_inode_t *); 530void xfs_mark_inode_dirty_sync(xfs_inode_t *);
diff --git a/fs/xfs/xfs_inode_item.c b/fs/xfs/xfs_inode_item.c
index 93b5db453ea2..167b33f15772 100644
--- a/fs/xfs/xfs_inode_item.c
+++ b/fs/xfs/xfs_inode_item.c
@@ -547,7 +547,7 @@ STATIC void
547xfs_inode_item_pin( 547xfs_inode_item_pin(
548 xfs_inode_log_item_t *iip) 548 xfs_inode_log_item_t *iip)
549{ 549{
550 ASSERT(ismrlocked(&(iip->ili_inode->i_lock), MR_UPDATE)); 550 ASSERT(xfs_isilocked(iip->ili_inode, XFS_ILOCK_EXCL));
551 xfs_ipin(iip->ili_inode); 551 xfs_ipin(iip->ili_inode);
552} 552}
553 553
@@ -664,13 +664,13 @@ xfs_inode_item_unlock(
664 664
665 ASSERT(iip != NULL); 665 ASSERT(iip != NULL);
666 ASSERT(iip->ili_inode->i_itemp != NULL); 666 ASSERT(iip->ili_inode->i_itemp != NULL);
667 ASSERT(ismrlocked(&(iip->ili_inode->i_lock), MR_UPDATE)); 667 ASSERT(xfs_isilocked(iip->ili_inode, XFS_ILOCK_EXCL));
668 ASSERT((!(iip->ili_inode->i_itemp->ili_flags & 668 ASSERT((!(iip->ili_inode->i_itemp->ili_flags &
669 XFS_ILI_IOLOCKED_EXCL)) || 669 XFS_ILI_IOLOCKED_EXCL)) ||
670 ismrlocked(&(iip->ili_inode->i_iolock), MR_UPDATE)); 670 xfs_isilocked(iip->ili_inode, XFS_IOLOCK_EXCL));
671 ASSERT((!(iip->ili_inode->i_itemp->ili_flags & 671 ASSERT((!(iip->ili_inode->i_itemp->ili_flags &
672 XFS_ILI_IOLOCKED_SHARED)) || 672 XFS_ILI_IOLOCKED_SHARED)) ||
673 ismrlocked(&(iip->ili_inode->i_iolock), MR_ACCESS)); 673 xfs_isilocked(iip->ili_inode, XFS_IOLOCK_SHARED));
674 /* 674 /*
675 * Clear the transaction pointer in the inode. 675 * Clear the transaction pointer in the inode.
676 */ 676 */
@@ -769,7 +769,7 @@ xfs_inode_item_pushbuf(
769 769
770 ip = iip->ili_inode; 770 ip = iip->ili_inode;
771 771
772 ASSERT(ismrlocked(&(ip->i_lock), MR_ACCESS)); 772 ASSERT(xfs_isilocked(ip, XFS_ILOCK_SHARED));
773 773
774 /* 774 /*
775 * The ili_pushbuf_flag keeps others from 775 * The ili_pushbuf_flag keeps others from
@@ -857,7 +857,7 @@ xfs_inode_item_push(
857 857
858 ip = iip->ili_inode; 858 ip = iip->ili_inode;
859 859
860 ASSERT(ismrlocked(&(ip->i_lock), MR_ACCESS)); 860 ASSERT(xfs_isilocked(ip, XFS_ILOCK_SHARED));
861 ASSERT(issemalocked(&(ip->i_flock))); 861 ASSERT(issemalocked(&(ip->i_flock)));
862 /* 862 /*
863 * Since we were able to lock the inode's flush lock and 863 * Since we were able to lock the inode's flush lock and
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index fb3cf1191419..7edcde691d1a 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -196,14 +196,14 @@ xfs_iomap(
196 break; 196 break;
197 case BMAPI_WRITE: 197 case BMAPI_WRITE:
198 xfs_iomap_enter_trace(XFS_IOMAP_WRITE_ENTER, ip, offset, count); 198 xfs_iomap_enter_trace(XFS_IOMAP_WRITE_ENTER, ip, offset, count);
199 lockmode = XFS_ILOCK_EXCL|XFS_EXTSIZE_WR; 199 lockmode = XFS_ILOCK_EXCL;
200 if (flags & BMAPI_IGNSTATE) 200 if (flags & BMAPI_IGNSTATE)
201 bmapi_flags |= XFS_BMAPI_IGSTATE|XFS_BMAPI_ENTIRE; 201 bmapi_flags |= XFS_BMAPI_IGSTATE|XFS_BMAPI_ENTIRE;
202 xfs_ilock(ip, lockmode); 202 xfs_ilock(ip, lockmode);
203 break; 203 break;
204 case BMAPI_ALLOCATE: 204 case BMAPI_ALLOCATE:
205 xfs_iomap_enter_trace(XFS_IOMAP_ALLOC_ENTER, ip, offset, count); 205 xfs_iomap_enter_trace(XFS_IOMAP_ALLOC_ENTER, ip, offset, count);
206 lockmode = XFS_ILOCK_SHARED|XFS_EXTSIZE_RD; 206 lockmode = XFS_ILOCK_SHARED;
207 bmapi_flags = XFS_BMAPI_ENTIRE; 207 bmapi_flags = XFS_BMAPI_ENTIRE;
208 208
209 /* Attempt non-blocking lock */ 209 /* Attempt non-blocking lock */
@@ -523,8 +523,7 @@ xfs_iomap_write_direct(
523 goto error_out; 523 goto error_out;
524 } 524 }
525 525
526 if (unlikely(!imap.br_startblock && 526 if (!(imap.br_startblock || XFS_IS_REALTIME_INODE(ip))) {
527 !(XFS_IS_REALTIME_INODE(ip)))) {
528 error = xfs_cmn_err_fsblock_zero(ip, &imap); 527 error = xfs_cmn_err_fsblock_zero(ip, &imap);
529 goto error_out; 528 goto error_out;
530 } 529 }
@@ -624,7 +623,7 @@ xfs_iomap_write_delay(
624 int prealloc, fsynced = 0; 623 int prealloc, fsynced = 0;
625 int error; 624 int error;
626 625
627 ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE) != 0); 626 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
628 627
629 /* 628 /*
630 * Make sure that the dquots are there. This doesn't hold 629 * Make sure that the dquots are there. This doesn't hold
@@ -686,8 +685,7 @@ retry:
686 goto retry; 685 goto retry;
687 } 686 }
688 687
689 if (unlikely(!imap[0].br_startblock && 688 if (!(imap[0].br_startblock || XFS_IS_REALTIME_INODE(ip)))
690 !(XFS_IS_REALTIME_INODE(ip))))
691 return xfs_cmn_err_fsblock_zero(ip, &imap[0]); 689 return xfs_cmn_err_fsblock_zero(ip, &imap[0]);
692 690
693 *ret_imap = imap[0]; 691 *ret_imap = imap[0];
@@ -838,9 +836,9 @@ xfs_iomap_write_allocate(
838 * See if we were able to allocate an extent that 836 * See if we were able to allocate an extent that
839 * covers at least part of the callers request 837 * covers at least part of the callers request
840 */ 838 */
841 if (unlikely(!imap.br_startblock && 839 if (!(imap.br_startblock || XFS_IS_REALTIME_INODE(ip)))
842 XFS_IS_REALTIME_INODE(ip)))
843 return xfs_cmn_err_fsblock_zero(ip, &imap); 840 return xfs_cmn_err_fsblock_zero(ip, &imap);
841
844 if ((offset_fsb >= imap.br_startoff) && 842 if ((offset_fsb >= imap.br_startoff) &&
845 (offset_fsb < (imap.br_startoff + 843 (offset_fsb < (imap.br_startoff +
846 imap.br_blockcount))) { 844 imap.br_blockcount))) {
@@ -934,8 +932,7 @@ xfs_iomap_write_unwritten(
934 if (error) 932 if (error)
935 return XFS_ERROR(error); 933 return XFS_ERROR(error);
936 934
937 if (unlikely(!imap.br_startblock && 935 if (!(imap.br_startblock || XFS_IS_REALTIME_INODE(ip)))
938 !(XFS_IS_REALTIME_INODE(ip))))
939 return xfs_cmn_err_fsblock_zero(ip, &imap); 936 return xfs_cmn_err_fsblock_zero(ip, &imap);
940 937
941 if ((numblks_fsb = imap.br_blockcount) == 0) { 938 if ((numblks_fsb = imap.br_blockcount) == 0) {
diff --git a/fs/xfs/xfs_itable.c b/fs/xfs/xfs_itable.c
index eb85bdedad0c..419de15aeb43 100644
--- a/fs/xfs/xfs_itable.c
+++ b/fs/xfs/xfs_itable.c
@@ -71,11 +71,6 @@ xfs_bulkstat_one_iget(
71 71
72 ASSERT(ip != NULL); 72 ASSERT(ip != NULL);
73 ASSERT(ip->i_blkno != (xfs_daddr_t)0); 73 ASSERT(ip->i_blkno != (xfs_daddr_t)0);
74 if (ip->i_d.di_mode == 0) {
75 *stat = BULKSTAT_RV_NOTHING;
76 error = XFS_ERROR(ENOENT);
77 goto out_iput;
78 }
79 74
80 vp = XFS_ITOV(ip); 75 vp = XFS_ITOV(ip);
81 dic = &ip->i_d; 76 dic = &ip->i_d;
@@ -124,7 +119,6 @@ xfs_bulkstat_one_iget(
124 break; 119 break;
125 } 120 }
126 121
127 out_iput:
128 xfs_iput(ip, XFS_ILOCK_SHARED); 122 xfs_iput(ip, XFS_ILOCK_SHARED);
129 return error; 123 return error;
130} 124}
diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
index 2fec452afbcc..da3988453b71 100644
--- a/fs/xfs/xfs_mount.c
+++ b/fs/xfs/xfs_mount.c
@@ -54,8 +54,9 @@ STATIC void xfs_unmountfs_wait(xfs_mount_t *);
54#ifdef HAVE_PERCPU_SB 54#ifdef HAVE_PERCPU_SB
55STATIC void xfs_icsb_destroy_counters(xfs_mount_t *); 55STATIC void xfs_icsb_destroy_counters(xfs_mount_t *);
56STATIC void xfs_icsb_balance_counter(xfs_mount_t *, xfs_sb_field_t, 56STATIC void xfs_icsb_balance_counter(xfs_mount_t *, xfs_sb_field_t,
57 int, int); 57 int);
58STATIC void xfs_icsb_sync_counters(xfs_mount_t *); 58STATIC void xfs_icsb_balance_counter_locked(xfs_mount_t *, xfs_sb_field_t,
59 int);
59STATIC int xfs_icsb_modify_counters(xfs_mount_t *, xfs_sb_field_t, 60STATIC int xfs_icsb_modify_counters(xfs_mount_t *, xfs_sb_field_t,
60 int64_t, int); 61 int64_t, int);
61STATIC void xfs_icsb_disable_counter(xfs_mount_t *, xfs_sb_field_t); 62STATIC void xfs_icsb_disable_counter(xfs_mount_t *, xfs_sb_field_t);
@@ -63,8 +64,8 @@ STATIC void xfs_icsb_disable_counter(xfs_mount_t *, xfs_sb_field_t);
63#else 64#else
64 65
65#define xfs_icsb_destroy_counters(mp) do { } while (0) 66#define xfs_icsb_destroy_counters(mp) do { } while (0)
66#define xfs_icsb_balance_counter(mp, a, b, c) do { } while (0) 67#define xfs_icsb_balance_counter(mp, a, b) do { } while (0)
67#define xfs_icsb_sync_counters(mp) do { } while (0) 68#define xfs_icsb_balance_counter_locked(mp, a, b) do { } while (0)
68#define xfs_icsb_modify_counters(mp, a, b, c) do { } while (0) 69#define xfs_icsb_modify_counters(mp, a, b, c) do { } while (0)
69 70
70#endif 71#endif
@@ -1400,7 +1401,7 @@ xfs_log_sbcount(
1400 if (!xfs_fs_writable(mp)) 1401 if (!xfs_fs_writable(mp))
1401 return 0; 1402 return 0;
1402 1403
1403 xfs_icsb_sync_counters(mp); 1404 xfs_icsb_sync_counters(mp, 0);
1404 1405
1405 /* 1406 /*
1406 * we don't need to do this if we are updating the superblock 1407 * we don't need to do this if we are updating the superblock
@@ -2026,9 +2027,9 @@ xfs_icsb_cpu_notify(
2026 case CPU_ONLINE: 2027 case CPU_ONLINE:
2027 case CPU_ONLINE_FROZEN: 2028 case CPU_ONLINE_FROZEN:
2028 xfs_icsb_lock(mp); 2029 xfs_icsb_lock(mp);
2029 xfs_icsb_balance_counter(mp, XFS_SBS_ICOUNT, 0, 0); 2030 xfs_icsb_balance_counter(mp, XFS_SBS_ICOUNT, 0);
2030 xfs_icsb_balance_counter(mp, XFS_SBS_IFREE, 0, 0); 2031 xfs_icsb_balance_counter(mp, XFS_SBS_IFREE, 0);
2031 xfs_icsb_balance_counter(mp, XFS_SBS_FDBLOCKS, 0, 0); 2032 xfs_icsb_balance_counter(mp, XFS_SBS_FDBLOCKS, 0);
2032 xfs_icsb_unlock(mp); 2033 xfs_icsb_unlock(mp);
2033 break; 2034 break;
2034 case CPU_DEAD: 2035 case CPU_DEAD:
@@ -2048,12 +2049,9 @@ xfs_icsb_cpu_notify(
2048 2049
2049 memset(cntp, 0, sizeof(xfs_icsb_cnts_t)); 2050 memset(cntp, 0, sizeof(xfs_icsb_cnts_t));
2050 2051
2051 xfs_icsb_balance_counter(mp, XFS_SBS_ICOUNT, 2052 xfs_icsb_balance_counter_locked(mp, XFS_SBS_ICOUNT, 0);
2052 XFS_ICSB_SB_LOCKED, 0); 2053 xfs_icsb_balance_counter_locked(mp, XFS_SBS_IFREE, 0);
2053 xfs_icsb_balance_counter(mp, XFS_SBS_IFREE, 2054 xfs_icsb_balance_counter_locked(mp, XFS_SBS_FDBLOCKS, 0);
2054 XFS_ICSB_SB_LOCKED, 0);
2055 xfs_icsb_balance_counter(mp, XFS_SBS_FDBLOCKS,
2056 XFS_ICSB_SB_LOCKED, 0);
2057 spin_unlock(&mp->m_sb_lock); 2055 spin_unlock(&mp->m_sb_lock);
2058 xfs_icsb_unlock(mp); 2056 xfs_icsb_unlock(mp);
2059 break; 2057 break;
@@ -2105,9 +2103,9 @@ xfs_icsb_reinit_counters(
2105 * initial balance kicks us off correctly 2103 * initial balance kicks us off correctly
2106 */ 2104 */
2107 mp->m_icsb_counters = -1; 2105 mp->m_icsb_counters = -1;
2108 xfs_icsb_balance_counter(mp, XFS_SBS_ICOUNT, 0, 0); 2106 xfs_icsb_balance_counter(mp, XFS_SBS_ICOUNT, 0);
2109 xfs_icsb_balance_counter(mp, XFS_SBS_IFREE, 0, 0); 2107 xfs_icsb_balance_counter(mp, XFS_SBS_IFREE, 0);
2110 xfs_icsb_balance_counter(mp, XFS_SBS_FDBLOCKS, 0, 0); 2108 xfs_icsb_balance_counter(mp, XFS_SBS_FDBLOCKS, 0);
2111 xfs_icsb_unlock(mp); 2109 xfs_icsb_unlock(mp);
2112} 2110}
2113 2111
@@ -2223,7 +2221,7 @@ xfs_icsb_disable_counter(
2223 if (!test_and_set_bit(field, &mp->m_icsb_counters)) { 2221 if (!test_and_set_bit(field, &mp->m_icsb_counters)) {
2224 /* drain back to superblock */ 2222 /* drain back to superblock */
2225 2223
2226 xfs_icsb_count(mp, &cnt, XFS_ICSB_SB_LOCKED|XFS_ICSB_LAZY_COUNT); 2224 xfs_icsb_count(mp, &cnt, XFS_ICSB_LAZY_COUNT);
2227 switch(field) { 2225 switch(field) {
2228 case XFS_SBS_ICOUNT: 2226 case XFS_SBS_ICOUNT:
2229 mp->m_sb.sb_icount = cnt.icsb_icount; 2227 mp->m_sb.sb_icount = cnt.icsb_icount;
@@ -2278,38 +2276,33 @@ xfs_icsb_enable_counter(
2278} 2276}
2279 2277
2280void 2278void
2281xfs_icsb_sync_counters_flags( 2279xfs_icsb_sync_counters_locked(
2282 xfs_mount_t *mp, 2280 xfs_mount_t *mp,
2283 int flags) 2281 int flags)
2284{ 2282{
2285 xfs_icsb_cnts_t cnt; 2283 xfs_icsb_cnts_t cnt;
2286 2284
2287 /* Pass 1: lock all counters */
2288 if ((flags & XFS_ICSB_SB_LOCKED) == 0)
2289 spin_lock(&mp->m_sb_lock);
2290
2291 xfs_icsb_count(mp, &cnt, flags); 2285 xfs_icsb_count(mp, &cnt, flags);
2292 2286
2293 /* Step 3: update mp->m_sb fields */
2294 if (!xfs_icsb_counter_disabled(mp, XFS_SBS_ICOUNT)) 2287 if (!xfs_icsb_counter_disabled(mp, XFS_SBS_ICOUNT))
2295 mp->m_sb.sb_icount = cnt.icsb_icount; 2288 mp->m_sb.sb_icount = cnt.icsb_icount;
2296 if (!xfs_icsb_counter_disabled(mp, XFS_SBS_IFREE)) 2289 if (!xfs_icsb_counter_disabled(mp, XFS_SBS_IFREE))
2297 mp->m_sb.sb_ifree = cnt.icsb_ifree; 2290 mp->m_sb.sb_ifree = cnt.icsb_ifree;
2298 if (!xfs_icsb_counter_disabled(mp, XFS_SBS_FDBLOCKS)) 2291 if (!xfs_icsb_counter_disabled(mp, XFS_SBS_FDBLOCKS))
2299 mp->m_sb.sb_fdblocks = cnt.icsb_fdblocks; 2292 mp->m_sb.sb_fdblocks = cnt.icsb_fdblocks;
2300
2301 if ((flags & XFS_ICSB_SB_LOCKED) == 0)
2302 spin_unlock(&mp->m_sb_lock);
2303} 2293}
2304 2294
2305/* 2295/*
2306 * Accurate update of per-cpu counters to incore superblock 2296 * Accurate update of per-cpu counters to incore superblock
2307 */ 2297 */
2308STATIC void 2298void
2309xfs_icsb_sync_counters( 2299xfs_icsb_sync_counters(
2310 xfs_mount_t *mp) 2300 xfs_mount_t *mp,
2301 int flags)
2311{ 2302{
2312 xfs_icsb_sync_counters_flags(mp, 0); 2303 spin_lock(&mp->m_sb_lock);
2304 xfs_icsb_sync_counters_locked(mp, flags);
2305 spin_unlock(&mp->m_sb_lock);
2313} 2306}
2314 2307
2315/* 2308/*
@@ -2332,19 +2325,15 @@ xfs_icsb_sync_counters(
2332#define XFS_ICSB_FDBLK_CNTR_REENABLE(mp) \ 2325#define XFS_ICSB_FDBLK_CNTR_REENABLE(mp) \
2333 (uint64_t)(512 + XFS_ALLOC_SET_ASIDE(mp)) 2326 (uint64_t)(512 + XFS_ALLOC_SET_ASIDE(mp))
2334STATIC void 2327STATIC void
2335xfs_icsb_balance_counter( 2328xfs_icsb_balance_counter_locked(
2336 xfs_mount_t *mp, 2329 xfs_mount_t *mp,
2337 xfs_sb_field_t field, 2330 xfs_sb_field_t field,
2338 int flags,
2339 int min_per_cpu) 2331 int min_per_cpu)
2340{ 2332{
2341 uint64_t count, resid; 2333 uint64_t count, resid;
2342 int weight = num_online_cpus(); 2334 int weight = num_online_cpus();
2343 uint64_t min = (uint64_t)min_per_cpu; 2335 uint64_t min = (uint64_t)min_per_cpu;
2344 2336
2345 if (!(flags & XFS_ICSB_SB_LOCKED))
2346 spin_lock(&mp->m_sb_lock);
2347
2348 /* disable counter and sync counter */ 2337 /* disable counter and sync counter */
2349 xfs_icsb_disable_counter(mp, field); 2338 xfs_icsb_disable_counter(mp, field);
2350 2339
@@ -2354,19 +2343,19 @@ xfs_icsb_balance_counter(
2354 count = mp->m_sb.sb_icount; 2343 count = mp->m_sb.sb_icount;
2355 resid = do_div(count, weight); 2344 resid = do_div(count, weight);
2356 if (count < max(min, XFS_ICSB_INO_CNTR_REENABLE)) 2345 if (count < max(min, XFS_ICSB_INO_CNTR_REENABLE))
2357 goto out; 2346 return;
2358 break; 2347 break;
2359 case XFS_SBS_IFREE: 2348 case XFS_SBS_IFREE:
2360 count = mp->m_sb.sb_ifree; 2349 count = mp->m_sb.sb_ifree;
2361 resid = do_div(count, weight); 2350 resid = do_div(count, weight);
2362 if (count < max(min, XFS_ICSB_INO_CNTR_REENABLE)) 2351 if (count < max(min, XFS_ICSB_INO_CNTR_REENABLE))
2363 goto out; 2352 return;
2364 break; 2353 break;
2365 case XFS_SBS_FDBLOCKS: 2354 case XFS_SBS_FDBLOCKS:
2366 count = mp->m_sb.sb_fdblocks; 2355 count = mp->m_sb.sb_fdblocks;
2367 resid = do_div(count, weight); 2356 resid = do_div(count, weight);
2368 if (count < max(min, XFS_ICSB_FDBLK_CNTR_REENABLE(mp))) 2357 if (count < max(min, XFS_ICSB_FDBLK_CNTR_REENABLE(mp)))
2369 goto out; 2358 return;
2370 break; 2359 break;
2371 default: 2360 default:
2372 BUG(); 2361 BUG();
@@ -2375,9 +2364,17 @@ xfs_icsb_balance_counter(
2375 } 2364 }
2376 2365
2377 xfs_icsb_enable_counter(mp, field, count, resid); 2366 xfs_icsb_enable_counter(mp, field, count, resid);
2378out: 2367}
2379 if (!(flags & XFS_ICSB_SB_LOCKED)) 2368
2380 spin_unlock(&mp->m_sb_lock); 2369STATIC void
2370xfs_icsb_balance_counter(
2371 xfs_mount_t *mp,
2372 xfs_sb_field_t fields,
2373 int min_per_cpu)
2374{
2375 spin_lock(&mp->m_sb_lock);
2376 xfs_icsb_balance_counter_locked(mp, fields, min_per_cpu);
2377 spin_unlock(&mp->m_sb_lock);
2381} 2378}
2382 2379
2383STATIC int 2380STATIC int
@@ -2484,7 +2481,7 @@ slow_path:
2484 * we are done. 2481 * we are done.
2485 */ 2482 */
2486 if (ret != ENOSPC) 2483 if (ret != ENOSPC)
2487 xfs_icsb_balance_counter(mp, field, 0, 0); 2484 xfs_icsb_balance_counter(mp, field, 0);
2488 xfs_icsb_unlock(mp); 2485 xfs_icsb_unlock(mp);
2489 return ret; 2486 return ret;
2490 2487
@@ -2508,7 +2505,7 @@ balance_counter:
2508 * will either succeed through the fast path or slow path without 2505 * will either succeed through the fast path or slow path without
2509 * another balance operation being required. 2506 * another balance operation being required.
2510 */ 2507 */
2511 xfs_icsb_balance_counter(mp, field, 0, delta); 2508 xfs_icsb_balance_counter(mp, field, delta);
2512 xfs_icsb_unlock(mp); 2509 xfs_icsb_unlock(mp);
2513 goto again; 2510 goto again;
2514} 2511}
diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h
index 1ed575110ff0..63e0693a358a 100644
--- a/fs/xfs/xfs_mount.h
+++ b/fs/xfs/xfs_mount.h
@@ -206,17 +206,18 @@ typedef struct xfs_icsb_cnts {
206 206
207#define XFS_ICSB_FLAG_LOCK (1 << 0) /* counter lock bit */ 207#define XFS_ICSB_FLAG_LOCK (1 << 0) /* counter lock bit */
208 208
209#define XFS_ICSB_SB_LOCKED (1 << 0) /* sb already locked */
210#define XFS_ICSB_LAZY_COUNT (1 << 1) /* accuracy not needed */ 209#define XFS_ICSB_LAZY_COUNT (1 << 1) /* accuracy not needed */
211 210
212extern int xfs_icsb_init_counters(struct xfs_mount *); 211extern int xfs_icsb_init_counters(struct xfs_mount *);
213extern void xfs_icsb_reinit_counters(struct xfs_mount *); 212extern void xfs_icsb_reinit_counters(struct xfs_mount *);
214extern void xfs_icsb_sync_counters_flags(struct xfs_mount *, int); 213extern void xfs_icsb_sync_counters(struct xfs_mount *, int);
214extern void xfs_icsb_sync_counters_locked(struct xfs_mount *, int);
215 215
216#else 216#else
217#define xfs_icsb_init_counters(mp) (0) 217#define xfs_icsb_init_counters(mp) (0)
218#define xfs_icsb_reinit_counters(mp) do { } while (0) 218#define xfs_icsb_reinit_counters(mp) do { } while (0)
219#define xfs_icsb_sync_counters_flags(mp, flags) do { } while (0) 219#define xfs_icsb_sync_counters(mp, flags) do { } while (0)
220#define xfs_icsb_sync_counters_locked(mp, flags) do { } while (0)
220#endif 221#endif
221 222
222typedef struct xfs_ail { 223typedef struct xfs_ail {
diff --git a/fs/xfs/xfs_rename.c b/fs/xfs/xfs_rename.c
index ee371890d85d..d8063e1ad298 100644
--- a/fs/xfs/xfs_rename.c
+++ b/fs/xfs/xfs_rename.c
@@ -55,85 +55,32 @@ xfs_rename_unlock4(
55 55
56 xfs_iunlock(i_tab[0], lock_mode); 56 xfs_iunlock(i_tab[0], lock_mode);
57 for (i = 1; i < 4; i++) { 57 for (i = 1; i < 4; i++) {
58 if (i_tab[i] == NULL) { 58 if (i_tab[i] == NULL)
59 break; 59 break;
60 } 60
61 /* 61 /*
62 * Watch out for duplicate entries in the table. 62 * Watch out for duplicate entries in the table.
63 */ 63 */
64 if (i_tab[i] != i_tab[i-1]) { 64 if (i_tab[i] != i_tab[i-1])
65 xfs_iunlock(i_tab[i], lock_mode); 65 xfs_iunlock(i_tab[i], lock_mode);
66 }
67 } 66 }
68} 67}
69 68
70#ifdef DEBUG
71int xfs_rename_skip, xfs_rename_nskip;
72#endif
73
74/* 69/*
75 * The following routine will acquire the locks required for a rename 70 * Enter all inodes for a rename transaction into a sorted array.
76 * operation. The code understands the semantics of renames and will
77 * validate that name1 exists under dp1 & that name2 may or may not
78 * exist under dp2.
79 *
80 * We are renaming dp1/name1 to dp2/name2.
81 *
82 * Return ENOENT if dp1 does not exist, other lookup errors, or 0 for success.
83 */ 71 */
84STATIC int 72STATIC void
85xfs_lock_for_rename( 73xfs_sort_for_rename(
86 xfs_inode_t *dp1, /* in: old (source) directory inode */ 74 xfs_inode_t *dp1, /* in: old (source) directory inode */
87 xfs_inode_t *dp2, /* in: new (target) directory inode */ 75 xfs_inode_t *dp2, /* in: new (target) directory inode */
88 xfs_inode_t *ip1, /* in: inode of old entry */ 76 xfs_inode_t *ip1, /* in: inode of old entry */
89 struct xfs_name *name2, /* in: new entry name */ 77 xfs_inode_t *ip2, /* in: inode of new entry, if it
90 xfs_inode_t **ipp2, /* out: inode of new entry, if it
91 already exists, NULL otherwise. */ 78 already exists, NULL otherwise. */
92 xfs_inode_t **i_tab,/* out: array of inode returned, sorted */ 79 xfs_inode_t **i_tab,/* out: array of inode returned, sorted */
93 int *num_inodes) /* out: number of inodes in array */ 80 int *num_inodes) /* out: number of inodes in array */
94{ 81{
95 xfs_inode_t *ip2 = NULL;
96 xfs_inode_t *temp; 82 xfs_inode_t *temp;
97 xfs_ino_t inum1, inum2;
98 int error;
99 int i, j; 83 int i, j;
100 uint lock_mode;
101 int diff_dirs = (dp1 != dp2);
102
103 /*
104 * First, find out the current inums of the entries so that we
105 * can determine the initial locking order. We'll have to
106 * sanity check stuff after all the locks have been acquired
107 * to see if we still have the right inodes, directories, etc.
108 */
109 lock_mode = xfs_ilock_map_shared(dp1);
110 IHOLD(ip1);
111 xfs_itrace_ref(ip1);
112
113 inum1 = ip1->i_ino;
114
115 /*
116 * Unlock dp1 and lock dp2 if they are different.
117 */
118 if (diff_dirs) {
119 xfs_iunlock_map_shared(dp1, lock_mode);
120 lock_mode = xfs_ilock_map_shared(dp2);
121 }
122
123 error = xfs_dir_lookup_int(dp2, lock_mode, name2, &inum2, &ip2);
124 if (error == ENOENT) { /* target does not need to exist. */
125 inum2 = 0;
126 } else if (error) {
127 /*
128 * If dp2 and dp1 are the same, the next line unlocks dp1.
129 * Got it?
130 */
131 xfs_iunlock_map_shared(dp2, lock_mode);
132 IRELE (ip1);
133 return error;
134 } else {
135 xfs_itrace_ref(ip2);
136 }
137 84
138 /* 85 /*
139 * i_tab contains a list of pointers to inodes. We initialize 86 * i_tab contains a list of pointers to inodes. We initialize
@@ -145,21 +92,20 @@ xfs_lock_for_rename(
145 i_tab[0] = dp1; 92 i_tab[0] = dp1;
146 i_tab[1] = dp2; 93 i_tab[1] = dp2;
147 i_tab[2] = ip1; 94 i_tab[2] = ip1;
148 if (inum2 == 0) { 95 if (ip2) {
149 *num_inodes = 3;
150 i_tab[3] = NULL;
151 } else {
152 *num_inodes = 4; 96 *num_inodes = 4;
153 i_tab[3] = ip2; 97 i_tab[3] = ip2;
98 } else {
99 *num_inodes = 3;
100 i_tab[3] = NULL;
154 } 101 }
155 *ipp2 = i_tab[3];
156 102
157 /* 103 /*
158 * Sort the elements via bubble sort. (Remember, there are at 104 * Sort the elements via bubble sort. (Remember, there are at
159 * most 4 elements to sort, so this is adequate.) 105 * most 4 elements to sort, so this is adequate.)
160 */ 106 */
161 for (i=0; i < *num_inodes; i++) { 107 for (i = 0; i < *num_inodes; i++) {
162 for (j=1; j < *num_inodes; j++) { 108 for (j = 1; j < *num_inodes; j++) {
163 if (i_tab[j]->i_ino < i_tab[j-1]->i_ino) { 109 if (i_tab[j]->i_ino < i_tab[j-1]->i_ino) {
164 temp = i_tab[j]; 110 temp = i_tab[j];
165 i_tab[j] = i_tab[j-1]; 111 i_tab[j] = i_tab[j-1];
@@ -167,30 +113,6 @@ xfs_lock_for_rename(
167 } 113 }
168 } 114 }
169 } 115 }
170
171 /*
172 * We have dp2 locked. If it isn't first, unlock it.
173 * If it is first, tell xfs_lock_inodes so it can skip it
174 * when locking. if dp1 == dp2, xfs_lock_inodes will skip both
175 * since they are equal. xfs_lock_inodes needs all these inodes
176 * so that it can unlock and retry if there might be a dead-lock
177 * potential with the log.
178 */
179
180 if (i_tab[0] == dp2 && lock_mode == XFS_ILOCK_SHARED) {
181#ifdef DEBUG
182 xfs_rename_skip++;
183#endif
184 xfs_lock_inodes(i_tab, *num_inodes, 1, XFS_ILOCK_SHARED);
185 } else {
186#ifdef DEBUG
187 xfs_rename_nskip++;
188#endif
189 xfs_iunlock_map_shared(dp2, lock_mode);
190 xfs_lock_inodes(i_tab, *num_inodes, 0, XFS_ILOCK_SHARED);
191 }
192
193 return 0;
194} 116}
195 117
196/* 118/*
@@ -202,10 +124,10 @@ xfs_rename(
202 struct xfs_name *src_name, 124 struct xfs_name *src_name,
203 xfs_inode_t *src_ip, 125 xfs_inode_t *src_ip,
204 xfs_inode_t *target_dp, 126 xfs_inode_t *target_dp,
205 struct xfs_name *target_name) 127 struct xfs_name *target_name,
128 xfs_inode_t *target_ip)
206{ 129{
207 xfs_trans_t *tp; 130 xfs_trans_t *tp = NULL;
208 xfs_inode_t *target_ip;
209 xfs_mount_t *mp = src_dp->i_mount; 131 xfs_mount_t *mp = src_dp->i_mount;
210 int new_parent; /* moving to a new dir */ 132 int new_parent; /* moving to a new dir */
211 int src_is_directory; /* src_name is a directory */ 133 int src_is_directory; /* src_name is a directory */
@@ -215,9 +137,7 @@ xfs_rename(
215 int cancel_flags; 137 int cancel_flags;
216 int committed; 138 int committed;
217 xfs_inode_t *inodes[4]; 139 xfs_inode_t *inodes[4];
218 int target_ip_dropped = 0; /* dropped target_ip link? */
219 int spaceres; 140 int spaceres;
220 int target_link_zero = 0;
221 int num_inodes; 141 int num_inodes;
222 142
223 xfs_itrace_entry(src_dp); 143 xfs_itrace_entry(src_dp);
@@ -230,64 +150,27 @@ xfs_rename(
230 target_dp, DM_RIGHT_NULL, 150 target_dp, DM_RIGHT_NULL,
231 src_name->name, target_name->name, 151 src_name->name, target_name->name,
232 0, 0, 0); 152 0, 0, 0);
233 if (error) { 153 if (error)
234 return error; 154 return error;
235 }
236 } 155 }
237 /* Return through std_return after this point. */ 156 /* Return through std_return after this point. */
238 157
239 /* 158 new_parent = (src_dp != target_dp);
240 * Lock all the participating inodes. Depending upon whether 159 src_is_directory = ((src_ip->i_d.di_mode & S_IFMT) == S_IFDIR);
241 * the target_name exists in the target directory, and
242 * whether the target directory is the same as the source
243 * directory, we can lock from 2 to 4 inodes.
244 * xfs_lock_for_rename() will return ENOENT if src_name
245 * does not exist in the source directory.
246 */
247 tp = NULL;
248 error = xfs_lock_for_rename(src_dp, target_dp, src_ip, target_name,
249 &target_ip, inodes, &num_inodes);
250 if (error) {
251 /*
252 * We have nothing locked, no inode references, and
253 * no transaction, so just get out.
254 */
255 goto std_return;
256 }
257
258 ASSERT(src_ip != NULL);
259 160
260 if ((src_ip->i_d.di_mode & S_IFMT) == S_IFDIR) { 161 if (src_is_directory) {
261 /* 162 /*
262 * Check for link count overflow on target_dp 163 * Check for link count overflow on target_dp
263 */ 164 */
264 if (target_ip == NULL && (src_dp != target_dp) && 165 if (target_ip == NULL && new_parent &&
265 target_dp->i_d.di_nlink >= XFS_MAXLINK) { 166 target_dp->i_d.di_nlink >= XFS_MAXLINK) {
266 error = XFS_ERROR(EMLINK); 167 error = XFS_ERROR(EMLINK);
267 xfs_rename_unlock4(inodes, XFS_ILOCK_SHARED); 168 goto std_return;
268 goto rele_return;
269 } 169 }
270 } 170 }
271 171
272 /* 172 xfs_sort_for_rename(src_dp, target_dp, src_ip, target_ip,
273 * If we are using project inheritance, we only allow renames 173 inodes, &num_inodes);
274 * into our tree when the project IDs are the same; else the
275 * tree quota mechanism would be circumvented.
276 */
277 if (unlikely((target_dp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
278 (target_dp->i_d.di_projid != src_ip->i_d.di_projid))) {
279 error = XFS_ERROR(EXDEV);
280 xfs_rename_unlock4(inodes, XFS_ILOCK_SHARED);
281 goto rele_return;
282 }
283
284 new_parent = (src_dp != target_dp);
285 src_is_directory = ((src_ip->i_d.di_mode & S_IFMT) == S_IFDIR);
286
287 /*
288 * Drop the locks on our inodes so that we can start the transaction.
289 */
290 xfs_rename_unlock4(inodes, XFS_ILOCK_SHARED);
291 174
292 XFS_BMAP_INIT(&free_list, &first_block); 175 XFS_BMAP_INIT(&free_list, &first_block);
293 tp = xfs_trans_alloc(mp, XFS_TRANS_RENAME); 176 tp = xfs_trans_alloc(mp, XFS_TRANS_RENAME);
@@ -302,7 +185,7 @@ xfs_rename(
302 } 185 }
303 if (error) { 186 if (error) {
304 xfs_trans_cancel(tp, 0); 187 xfs_trans_cancel(tp, 0);
305 goto rele_return; 188 goto std_return;
306 } 189 }
307 190
308 /* 191 /*
@@ -310,13 +193,29 @@ xfs_rename(
310 */ 193 */
311 if ((error = XFS_QM_DQVOPRENAME(mp, inodes))) { 194 if ((error = XFS_QM_DQVOPRENAME(mp, inodes))) {
312 xfs_trans_cancel(tp, cancel_flags); 195 xfs_trans_cancel(tp, cancel_flags);
313 goto rele_return; 196 goto std_return;
314 } 197 }
315 198
316 /* 199 /*
317 * Reacquire the inode locks we dropped above. 200 * Lock all the participating inodes. Depending upon whether
201 * the target_name exists in the target directory, and
202 * whether the target directory is the same as the source
203 * directory, we can lock from 2 to 4 inodes.
204 */
205 xfs_lock_inodes(inodes, num_inodes, XFS_ILOCK_EXCL);
206
207 /*
208 * If we are using project inheritance, we only allow renames
209 * into our tree when the project IDs are the same; else the
210 * tree quota mechanism would be circumvented.
318 */ 211 */
319 xfs_lock_inodes(inodes, num_inodes, 0, XFS_ILOCK_EXCL); 212 if (unlikely((target_dp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
213 (target_dp->i_d.di_projid != src_ip->i_d.di_projid))) {
214 error = XFS_ERROR(EXDEV);
215 xfs_rename_unlock4(inodes, XFS_ILOCK_SHARED);
216 xfs_trans_cancel(tp, cancel_flags);
217 goto std_return;
218 }
320 219
321 /* 220 /*
322 * Join all the inodes to the transaction. From this point on, 221 * Join all the inodes to the transaction. From this point on,
@@ -328,17 +227,17 @@ xfs_rename(
328 */ 227 */
329 IHOLD(src_dp); 228 IHOLD(src_dp);
330 xfs_trans_ijoin(tp, src_dp, XFS_ILOCK_EXCL); 229 xfs_trans_ijoin(tp, src_dp, XFS_ILOCK_EXCL);
230
331 if (new_parent) { 231 if (new_parent) {
332 IHOLD(target_dp); 232 IHOLD(target_dp);
333 xfs_trans_ijoin(tp, target_dp, XFS_ILOCK_EXCL); 233 xfs_trans_ijoin(tp, target_dp, XFS_ILOCK_EXCL);
334 } 234 }
335 if ((src_ip != src_dp) && (src_ip != target_dp)) { 235
336 xfs_trans_ijoin(tp, src_ip, XFS_ILOCK_EXCL); 236 IHOLD(src_ip);
337 } 237 xfs_trans_ijoin(tp, src_ip, XFS_ILOCK_EXCL);
338 if ((target_ip != NULL) && 238
339 (target_ip != src_ip) && 239 if (target_ip) {
340 (target_ip != src_dp) && 240 IHOLD(target_ip);
341 (target_ip != target_dp)) {
342 xfs_trans_ijoin(tp, target_ip, XFS_ILOCK_EXCL); 241 xfs_trans_ijoin(tp, target_ip, XFS_ILOCK_EXCL);
343 } 242 }
344 243
@@ -412,7 +311,6 @@ xfs_rename(
412 error = xfs_droplink(tp, target_ip); 311 error = xfs_droplink(tp, target_ip);
413 if (error) 312 if (error)
414 goto abort_return; 313 goto abort_return;
415 target_ip_dropped = 1;
416 314
417 if (src_is_directory) { 315 if (src_is_directory) {
418 /* 316 /*
@@ -422,10 +320,6 @@ xfs_rename(
422 if (error) 320 if (error)
423 goto abort_return; 321 goto abort_return;
424 } 322 }
425
426 /* Do this test while we still hold the locks */
427 target_link_zero = (target_ip)->i_d.di_nlink==0;
428
429 } /* target_ip != NULL */ 323 } /* target_ip != NULL */
430 324
431 /* 325 /*
@@ -492,15 +386,6 @@ xfs_rename(
492 } 386 }
493 387
494 /* 388 /*
495 * If there was a target inode, take an extra reference on
496 * it here so that it doesn't go to xfs_inactive() from
497 * within the commit.
498 */
499 if (target_ip != NULL) {
500 IHOLD(target_ip);
501 }
502
503 /*
504 * If this is a synchronous mount, make sure that the 389 * If this is a synchronous mount, make sure that the
505 * rename transaction goes to disk before returning to 390 * rename transaction goes to disk before returning to
506 * the user. 391 * the user.
@@ -509,30 +394,11 @@ xfs_rename(
509 xfs_trans_set_sync(tp); 394 xfs_trans_set_sync(tp);
510 } 395 }
511 396
512 /*
513 * Take refs. for vop_link_removed calls below. No need to worry
514 * about directory refs. because the caller holds them.
515 *
516 * Do holds before the xfs_bmap_finish since it might rele them down
517 * to zero.
518 */
519
520 if (target_ip_dropped)
521 IHOLD(target_ip);
522 IHOLD(src_ip);
523
524 error = xfs_bmap_finish(&tp, &free_list, &committed); 397 error = xfs_bmap_finish(&tp, &free_list, &committed);
525 if (error) { 398 if (error) {
526 xfs_bmap_cancel(&free_list); 399 xfs_bmap_cancel(&free_list);
527 xfs_trans_cancel(tp, (XFS_TRANS_RELEASE_LOG_RES | 400 xfs_trans_cancel(tp, (XFS_TRANS_RELEASE_LOG_RES |
528 XFS_TRANS_ABORT)); 401 XFS_TRANS_ABORT));
529 if (target_ip != NULL) {
530 IRELE(target_ip);
531 }
532 if (target_ip_dropped) {
533 IRELE(target_ip);
534 }
535 IRELE(src_ip);
536 goto std_return; 402 goto std_return;
537 } 403 }
538 404
@@ -541,15 +407,6 @@ xfs_rename(
541 * the vnode references. 407 * the vnode references.
542 */ 408 */
543 error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES); 409 error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
544 if (target_ip != NULL)
545 IRELE(target_ip);
546 /*
547 * Let interposed file systems know about removed links.
548 */
549 if (target_ip_dropped)
550 IRELE(target_ip);
551
552 IRELE(src_ip);
553 410
554 /* Fall through to std_return with error = 0 or errno from 411 /* Fall through to std_return with error = 0 or errno from
555 * xfs_trans_commit */ 412 * xfs_trans_commit */
@@ -571,11 +428,4 @@ std_return:
571 xfs_bmap_cancel(&free_list); 428 xfs_bmap_cancel(&free_list);
572 xfs_trans_cancel(tp, cancel_flags); 429 xfs_trans_cancel(tp, cancel_flags);
573 goto std_return; 430 goto std_return;
574
575 rele_return:
576 IRELE(src_ip);
577 if (target_ip != NULL) {
578 IRELE(target_ip);
579 }
580 goto std_return;
581} 431}
diff --git a/fs/xfs/xfs_trans_inode.c b/fs/xfs/xfs_trans_inode.c
index b8db1d5cde5a..4c70bf5e9985 100644
--- a/fs/xfs/xfs_trans_inode.c
+++ b/fs/xfs/xfs_trans_inode.c
@@ -111,13 +111,13 @@ xfs_trans_iget(
111 */ 111 */
112 ASSERT(ip->i_itemp != NULL); 112 ASSERT(ip->i_itemp != NULL);
113 ASSERT(lock_flags & XFS_ILOCK_EXCL); 113 ASSERT(lock_flags & XFS_ILOCK_EXCL);
114 ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE)); 114 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
115 ASSERT((!(lock_flags & XFS_IOLOCK_EXCL)) || 115 ASSERT((!(lock_flags & XFS_IOLOCK_EXCL)) ||
116 ismrlocked(&ip->i_iolock, MR_UPDATE)); 116 xfs_isilocked(ip, XFS_IOLOCK_EXCL));
117 ASSERT((!(lock_flags & XFS_IOLOCK_EXCL)) || 117 ASSERT((!(lock_flags & XFS_IOLOCK_EXCL)) ||
118 (ip->i_itemp->ili_flags & XFS_ILI_IOLOCKED_EXCL)); 118 (ip->i_itemp->ili_flags & XFS_ILI_IOLOCKED_EXCL));
119 ASSERT((!(lock_flags & XFS_IOLOCK_SHARED)) || 119 ASSERT((!(lock_flags & XFS_IOLOCK_SHARED)) ||
120 ismrlocked(&ip->i_iolock, (MR_UPDATE | MR_ACCESS))); 120 xfs_isilocked(ip, XFS_IOLOCK_EXCL|XFS_IOLOCK_SHARED));
121 ASSERT((!(lock_flags & XFS_IOLOCK_SHARED)) || 121 ASSERT((!(lock_flags & XFS_IOLOCK_SHARED)) ||
122 (ip->i_itemp->ili_flags & XFS_ILI_IOLOCKED_ANY)); 122 (ip->i_itemp->ili_flags & XFS_ILI_IOLOCKED_ANY));
123 123
@@ -185,7 +185,7 @@ xfs_trans_ijoin(
185 xfs_inode_log_item_t *iip; 185 xfs_inode_log_item_t *iip;
186 186
187 ASSERT(ip->i_transp == NULL); 187 ASSERT(ip->i_transp == NULL);
188 ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE)); 188 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
189 ASSERT(lock_flags & XFS_ILOCK_EXCL); 189 ASSERT(lock_flags & XFS_ILOCK_EXCL);
190 if (ip->i_itemp == NULL) 190 if (ip->i_itemp == NULL)
191 xfs_inode_item_init(ip, ip->i_mount); 191 xfs_inode_item_init(ip, ip->i_mount);
@@ -232,7 +232,7 @@ xfs_trans_ihold(
232{ 232{
233 ASSERT(ip->i_transp == tp); 233 ASSERT(ip->i_transp == tp);
234 ASSERT(ip->i_itemp != NULL); 234 ASSERT(ip->i_itemp != NULL);
235 ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE)); 235 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
236 236
237 ip->i_itemp->ili_flags |= XFS_ILI_HOLD; 237 ip->i_itemp->ili_flags |= XFS_ILI_HOLD;
238} 238}
@@ -257,7 +257,7 @@ xfs_trans_log_inode(
257 257
258 ASSERT(ip->i_transp == tp); 258 ASSERT(ip->i_transp == tp);
259 ASSERT(ip->i_itemp != NULL); 259 ASSERT(ip->i_itemp != NULL);
260 ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE)); 260 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
261 261
262 lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)(ip->i_itemp)); 262 lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)(ip->i_itemp));
263 ASSERT(lidp != NULL); 263 ASSERT(lidp != NULL);
diff --git a/fs/xfs/xfs_utils.c b/fs/xfs/xfs_utils.c
index 2b8dc7e40772..98e5f110ba5f 100644
--- a/fs/xfs/xfs_utils.c
+++ b/fs/xfs/xfs_utils.c
@@ -41,49 +41,6 @@
41#include "xfs_utils.h" 41#include "xfs_utils.h"
42 42
43 43
44int
45xfs_dir_lookup_int(
46 xfs_inode_t *dp,
47 uint lock_mode,
48 struct xfs_name *name,
49 xfs_ino_t *inum,
50 xfs_inode_t **ipp)
51{
52 int error;
53
54 xfs_itrace_entry(dp);
55
56 error = xfs_dir_lookup(NULL, dp, name, inum);
57 if (!error) {
58 /*
59 * Unlock the directory. We do this because we can't
60 * hold the directory lock while doing the vn_get()
61 * in xfs_iget(). Doing so could cause us to hold
62 * a lock while waiting for the inode to finish
63 * being inactive while it's waiting for a log
64 * reservation in the inactive routine.
65 */
66 xfs_iunlock(dp, lock_mode);
67 error = xfs_iget(dp->i_mount, NULL, *inum, 0, 0, ipp, 0);
68 xfs_ilock(dp, lock_mode);
69
70 if (error) {
71 *ipp = NULL;
72 } else if ((*ipp)->i_d.di_mode == 0) {
73 /*
74 * The inode has been freed. Something is
75 * wrong so just get out of here.
76 */
77 xfs_iunlock(dp, lock_mode);
78 xfs_iput_new(*ipp, 0);
79 *ipp = NULL;
80 xfs_ilock(dp, lock_mode);
81 error = XFS_ERROR(ENOENT);
82 }
83 }
84 return error;
85}
86
87/* 44/*
88 * Allocates a new inode from disk and return a pointer to the 45 * Allocates a new inode from disk and return a pointer to the
89 * incore copy. This routine will internally commit the current 46 * incore copy. This routine will internally commit the current
@@ -310,7 +267,7 @@ xfs_bump_ino_vers2(
310{ 267{
311 xfs_mount_t *mp; 268 xfs_mount_t *mp;
312 269
313 ASSERT(ismrlocked (&ip->i_lock, MR_UPDATE)); 270 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
314 ASSERT(ip->i_d.di_version == XFS_DINODE_VERSION_1); 271 ASSERT(ip->i_d.di_version == XFS_DINODE_VERSION_1);
315 272
316 ip->i_d.di_version = XFS_DINODE_VERSION_2; 273 ip->i_d.di_version = XFS_DINODE_VERSION_2;
diff --git a/fs/xfs/xfs_utils.h b/fs/xfs/xfs_utils.h
index 175b126d2cab..f316cb85d8e2 100644
--- a/fs/xfs/xfs_utils.h
+++ b/fs/xfs/xfs_utils.h
@@ -21,8 +21,6 @@
21#define IRELE(ip) VN_RELE(XFS_ITOV(ip)) 21#define IRELE(ip) VN_RELE(XFS_ITOV(ip))
22#define IHOLD(ip) VN_HOLD(XFS_ITOV(ip)) 22#define IHOLD(ip) VN_HOLD(XFS_ITOV(ip))
23 23
24extern int xfs_dir_lookup_int(xfs_inode_t *, uint, struct xfs_name *,
25 xfs_ino_t *, xfs_inode_t **);
26extern int xfs_truncate_file(xfs_mount_t *, xfs_inode_t *); 24extern int xfs_truncate_file(xfs_mount_t *, xfs_inode_t *);
27extern int xfs_dir_ialloc(xfs_trans_t **, xfs_inode_t *, mode_t, xfs_nlink_t, 25extern int xfs_dir_ialloc(xfs_trans_t **, xfs_inode_t *, mode_t, xfs_nlink_t,
28 xfs_dev_t, cred_t *, prid_t, int, 26 xfs_dev_t, cred_t *, prid_t, int,
diff --git a/fs/xfs/xfs_vfsops.c b/fs/xfs/xfs_vfsops.c
index fc48158fe479..30bacd8bb0e5 100644
--- a/fs/xfs/xfs_vfsops.c
+++ b/fs/xfs/xfs_vfsops.c
@@ -186,6 +186,7 @@ xfs_cleanup(void)
186 kmem_zone_destroy(xfs_efi_zone); 186 kmem_zone_destroy(xfs_efi_zone);
187 kmem_zone_destroy(xfs_ifork_zone); 187 kmem_zone_destroy(xfs_ifork_zone);
188 kmem_zone_destroy(xfs_ili_zone); 188 kmem_zone_destroy(xfs_ili_zone);
189 kmem_zone_destroy(xfs_log_ticket_zone);
189} 190}
190 191
191/* 192/*
diff --git a/fs/xfs/xfs_vnodeops.c b/fs/xfs/xfs_vnodeops.c
index 6650601c64f7..70702a60b4bb 100644
--- a/fs/xfs/xfs_vnodeops.c
+++ b/fs/xfs/xfs_vnodeops.c
@@ -76,132 +76,6 @@ xfs_open(
76} 76}
77 77
78/* 78/*
79 * xfs_getattr
80 */
81int
82xfs_getattr(
83 xfs_inode_t *ip,
84 bhv_vattr_t *vap,
85 int flags)
86{
87 bhv_vnode_t *vp = XFS_ITOV(ip);
88 xfs_mount_t *mp = ip->i_mount;
89
90 xfs_itrace_entry(ip);
91
92 if (XFS_FORCED_SHUTDOWN(mp))
93 return XFS_ERROR(EIO);
94
95 if (!(flags & ATTR_LAZY))
96 xfs_ilock(ip, XFS_ILOCK_SHARED);
97
98 vap->va_size = XFS_ISIZE(ip);
99 if (vap->va_mask == XFS_AT_SIZE)
100 goto all_done;
101
102 vap->va_nblocks =
103 XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
104 vap->va_nodeid = ip->i_ino;
105#if XFS_BIG_INUMS
106 vap->va_nodeid += mp->m_inoadd;
107#endif
108 vap->va_nlink = ip->i_d.di_nlink;
109
110 /*
111 * Quick exit for non-stat callers
112 */
113 if ((vap->va_mask &
114 ~(XFS_AT_SIZE|XFS_AT_FSID|XFS_AT_NODEID|
115 XFS_AT_NLINK|XFS_AT_BLKSIZE)) == 0)
116 goto all_done;
117
118 /*
119 * Copy from in-core inode.
120 */
121 vap->va_mode = ip->i_d.di_mode;
122 vap->va_uid = ip->i_d.di_uid;
123 vap->va_gid = ip->i_d.di_gid;
124 vap->va_projid = ip->i_d.di_projid;
125
126 /*
127 * Check vnode type block/char vs. everything else.
128 */
129 switch (ip->i_d.di_mode & S_IFMT) {
130 case S_IFBLK:
131 case S_IFCHR:
132 vap->va_rdev = ip->i_df.if_u2.if_rdev;
133 vap->va_blocksize = BLKDEV_IOSIZE;
134 break;
135 default:
136 vap->va_rdev = 0;
137
138 if (!(XFS_IS_REALTIME_INODE(ip))) {
139 vap->va_blocksize = xfs_preferred_iosize(mp);
140 } else {
141
142 /*
143 * If the file blocks are being allocated from a
144 * realtime partition, then return the inode's
145 * realtime extent size or the realtime volume's
146 * extent size.
147 */
148 vap->va_blocksize =
149 xfs_get_extsz_hint(ip) << mp->m_sb.sb_blocklog;
150 }
151 break;
152 }
153
154 vn_atime_to_timespec(vp, &vap->va_atime);
155 vap->va_mtime.tv_sec = ip->i_d.di_mtime.t_sec;
156 vap->va_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
157 vap->va_ctime.tv_sec = ip->i_d.di_ctime.t_sec;
158 vap->va_ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
159
160 /*
161 * Exit for stat callers. See if any of the rest of the fields
162 * to be filled in are needed.
163 */
164 if ((vap->va_mask &
165 (XFS_AT_XFLAGS|XFS_AT_EXTSIZE|XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|
166 XFS_AT_GENCOUNT|XFS_AT_VCODE)) == 0)
167 goto all_done;
168
169 /*
170 * Convert di_flags to xflags.
171 */
172 vap->va_xflags = xfs_ip2xflags(ip);
173
174 /*
175 * Exit for inode revalidate. See if any of the rest of
176 * the fields to be filled in are needed.
177 */
178 if ((vap->va_mask &
179 (XFS_AT_EXTSIZE|XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|
180 XFS_AT_GENCOUNT|XFS_AT_VCODE)) == 0)
181 goto all_done;
182
183 vap->va_extsize = ip->i_d.di_extsize << mp->m_sb.sb_blocklog;
184 vap->va_nextents =
185 (ip->i_df.if_flags & XFS_IFEXTENTS) ?
186 ip->i_df.if_bytes / sizeof(xfs_bmbt_rec_t) :
187 ip->i_d.di_nextents;
188 if (ip->i_afp)
189 vap->va_anextents =
190 (ip->i_afp->if_flags & XFS_IFEXTENTS) ?
191 ip->i_afp->if_bytes / sizeof(xfs_bmbt_rec_t) :
192 ip->i_d.di_anextents;
193 else
194 vap->va_anextents = 0;
195 vap->va_gen = ip->i_d.di_gen;
196
197 all_done:
198 if (!(flags & ATTR_LAZY))
199 xfs_iunlock(ip, XFS_ILOCK_SHARED);
200 return 0;
201}
202
203
204/*
205 * xfs_setattr 79 * xfs_setattr
206 */ 80 */
207int 81int
@@ -211,7 +85,6 @@ xfs_setattr(
211 int flags, 85 int flags,
212 cred_t *credp) 86 cred_t *credp)
213{ 87{
214 bhv_vnode_t *vp = XFS_ITOV(ip);
215 xfs_mount_t *mp = ip->i_mount; 88 xfs_mount_t *mp = ip->i_mount;
216 xfs_trans_t *tp; 89 xfs_trans_t *tp;
217 int mask; 90 int mask;
@@ -222,7 +95,6 @@ xfs_setattr(
222 gid_t gid=0, igid=0; 95 gid_t gid=0, igid=0;
223 int timeflags = 0; 96 int timeflags = 0;
224 xfs_prid_t projid=0, iprojid=0; 97 xfs_prid_t projid=0, iprojid=0;
225 int mandlock_before, mandlock_after;
226 struct xfs_dquot *udqp, *gdqp, *olddquot1, *olddquot2; 98 struct xfs_dquot *udqp, *gdqp, *olddquot1, *olddquot2;
227 int file_owner; 99 int file_owner;
228 int need_iolock = 1; 100 int need_iolock = 1;
@@ -383,7 +255,7 @@ xfs_setattr(
383 m |= S_ISGID; 255 m |= S_ISGID;
384#if 0 256#if 0
385 /* Linux allows this, Irix doesn't. */ 257 /* Linux allows this, Irix doesn't. */
386 if ((vap->va_mode & S_ISVTX) && !VN_ISDIR(vp)) 258 if ((vap->va_mode & S_ISVTX) && !S_ISDIR(ip->i_d.di_mode))
387 m |= S_ISVTX; 259 m |= S_ISVTX;
388#endif 260#endif
389 if (m && !capable(CAP_FSETID)) 261 if (m && !capable(CAP_FSETID))
@@ -461,10 +333,10 @@ xfs_setattr(
461 goto error_return; 333 goto error_return;
462 } 334 }
463 335
464 if (VN_ISDIR(vp)) { 336 if (S_ISDIR(ip->i_d.di_mode)) {
465 code = XFS_ERROR(EISDIR); 337 code = XFS_ERROR(EISDIR);
466 goto error_return; 338 goto error_return;
467 } else if (!VN_ISREG(vp)) { 339 } else if (!S_ISREG(ip->i_d.di_mode)) {
468 code = XFS_ERROR(EINVAL); 340 code = XFS_ERROR(EINVAL);
469 goto error_return; 341 goto error_return;
470 } 342 }
@@ -626,9 +498,6 @@ xfs_setattr(
626 xfs_trans_ihold(tp, ip); 498 xfs_trans_ihold(tp, ip);
627 } 499 }
628 500
629 /* determine whether mandatory locking mode changes */
630 mandlock_before = MANDLOCK(vp, ip->i_d.di_mode);
631
632 /* 501 /*
633 * Truncate file. Must have write permission and not be a directory. 502 * Truncate file. Must have write permission and not be a directory.
634 */ 503 */
@@ -858,13 +727,6 @@ xfs_setattr(
858 code = xfs_trans_commit(tp, commit_flags); 727 code = xfs_trans_commit(tp, commit_flags);
859 } 728 }
860 729
861 /*
862 * If the (regular) file's mandatory locking mode changed, then
863 * notify the vnode. We do this under the inode lock to prevent
864 * racing calls to vop_vnode_change.
865 */
866 mandlock_after = MANDLOCK(vp, ip->i_d.di_mode);
867
868 xfs_iunlock(ip, lock_flags); 730 xfs_iunlock(ip, lock_flags);
869 731
870 /* 732 /*
@@ -1443,7 +1305,7 @@ xfs_inactive_attrs(
1443 int error; 1305 int error;
1444 xfs_mount_t *mp; 1306 xfs_mount_t *mp;
1445 1307
1446 ASSERT(ismrlocked(&ip->i_iolock, MR_UPDATE)); 1308 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL));
1447 tp = *tpp; 1309 tp = *tpp;
1448 mp = ip->i_mount; 1310 mp = ip->i_mount;
1449 ASSERT(ip->i_d.di_forkoff != 0); 1311 ASSERT(ip->i_d.di_forkoff != 0);
@@ -1491,7 +1353,7 @@ xfs_release(
1491 xfs_mount_t *mp = ip->i_mount; 1353 xfs_mount_t *mp = ip->i_mount;
1492 int error; 1354 int error;
1493 1355
1494 if (!VN_ISREG(vp) || (ip->i_d.di_mode == 0)) 1356 if (!S_ISREG(ip->i_d.di_mode) || (ip->i_d.di_mode == 0))
1495 return 0; 1357 return 0;
1496 1358
1497 /* If this is a read-only mount, don't do this (would generate I/O) */ 1359 /* If this is a read-only mount, don't do this (would generate I/O) */
@@ -1774,8 +1636,7 @@ xfs_lookup(
1774 struct xfs_name *name, 1636 struct xfs_name *name,
1775 xfs_inode_t **ipp) 1637 xfs_inode_t **ipp)
1776{ 1638{
1777 xfs_inode_t *ip; 1639 xfs_ino_t inum;
1778 xfs_ino_t e_inum;
1779 int error; 1640 int error;
1780 uint lock_mode; 1641 uint lock_mode;
1781 1642
@@ -1785,12 +1646,21 @@ xfs_lookup(
1785 return XFS_ERROR(EIO); 1646 return XFS_ERROR(EIO);
1786 1647
1787 lock_mode = xfs_ilock_map_shared(dp); 1648 lock_mode = xfs_ilock_map_shared(dp);
1788 error = xfs_dir_lookup_int(dp, lock_mode, name, &e_inum, &ip); 1649 error = xfs_dir_lookup(NULL, dp, name, &inum);
1789 if (!error) {
1790 *ipp = ip;
1791 xfs_itrace_ref(ip);
1792 }
1793 xfs_iunlock_map_shared(dp, lock_mode); 1650 xfs_iunlock_map_shared(dp, lock_mode);
1651
1652 if (error)
1653 goto out;
1654
1655 error = xfs_iget(dp->i_mount, NULL, inum, 0, 0, ipp, 0);
1656 if (error)
1657 goto out;
1658
1659 xfs_itrace_ref(*ipp);
1660 return 0;
1661
1662 out:
1663 *ipp = NULL;
1794 return error; 1664 return error;
1795} 1665}
1796 1666
@@ -1906,7 +1776,7 @@ xfs_create(
1906 * It is locked (and joined to the transaction). 1776 * It is locked (and joined to the transaction).
1907 */ 1777 */
1908 1778
1909 ASSERT(ismrlocked (&ip->i_lock, MR_UPDATE)); 1779 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
1910 1780
1911 /* 1781 /*
1912 * Now we join the directory inode to the transaction. We do not do it 1782 * Now we join the directory inode to the transaction. We do not do it
@@ -2112,7 +1982,7 @@ again:
2112 1982
2113 ips[0] = ip; 1983 ips[0] = ip;
2114 ips[1] = dp; 1984 ips[1] = dp;
2115 xfs_lock_inodes(ips, 2, 0, XFS_ILOCK_EXCL); 1985 xfs_lock_inodes(ips, 2, XFS_ILOCK_EXCL);
2116 } 1986 }
2117 /* else e_inum == dp->i_ino */ 1987 /* else e_inum == dp->i_ino */
2118 /* This can happen if we're asked to lock /x/.. 1988 /* This can happen if we're asked to lock /x/..
@@ -2160,7 +2030,6 @@ void
2160xfs_lock_inodes( 2030xfs_lock_inodes(
2161 xfs_inode_t **ips, 2031 xfs_inode_t **ips,
2162 int inodes, 2032 int inodes,
2163 int first_locked,
2164 uint lock_mode) 2033 uint lock_mode)
2165{ 2034{
2166 int attempts = 0, i, j, try_lock; 2035 int attempts = 0, i, j, try_lock;
@@ -2168,13 +2037,8 @@ xfs_lock_inodes(
2168 2037
2169 ASSERT(ips && (inodes >= 2)); /* we need at least two */ 2038 ASSERT(ips && (inodes >= 2)); /* we need at least two */
2170 2039
2171 if (first_locked) { 2040 try_lock = 0;
2172 try_lock = 1; 2041 i = 0;
2173 i = 1;
2174 } else {
2175 try_lock = 0;
2176 i = 0;
2177 }
2178 2042
2179again: 2043again:
2180 for (; i < inodes; i++) { 2044 for (; i < inodes; i++) {
@@ -2298,29 +2162,14 @@ xfs_remove(
2298 return error; 2162 return error;
2299 } 2163 }
2300 2164
2301 /*
2302 * We need to get a reference to ip before we get our log
2303 * reservation. The reason for this is that we cannot call
2304 * xfs_iget for an inode for which we do not have a reference
2305 * once we've acquired a log reservation. This is because the
2306 * inode we are trying to get might be in xfs_inactive going
2307 * for a log reservation. Since we'll have to wait for the
2308 * inactive code to complete before returning from xfs_iget,
2309 * we need to make sure that we don't have log space reserved
2310 * when we call xfs_iget. Instead we get an unlocked reference
2311 * to the inode before getting our log reservation.
2312 */
2313 IHOLD(ip);
2314
2315 xfs_itrace_entry(ip); 2165 xfs_itrace_entry(ip);
2316 xfs_itrace_ref(ip); 2166 xfs_itrace_ref(ip);
2317 2167
2318 error = XFS_QM_DQATTACH(mp, dp, 0); 2168 error = XFS_QM_DQATTACH(mp, dp, 0);
2319 if (!error && dp != ip) 2169 if (!error)
2320 error = XFS_QM_DQATTACH(mp, ip, 0); 2170 error = XFS_QM_DQATTACH(mp, ip, 0);
2321 if (error) { 2171 if (error) {
2322 REMOVE_DEBUG_TRACE(__LINE__); 2172 REMOVE_DEBUG_TRACE(__LINE__);
2323 IRELE(ip);
2324 goto std_return; 2173 goto std_return;
2325 } 2174 }
2326 2175
@@ -2347,7 +2196,6 @@ xfs_remove(
2347 ASSERT(error != ENOSPC); 2196 ASSERT(error != ENOSPC);
2348 REMOVE_DEBUG_TRACE(__LINE__); 2197 REMOVE_DEBUG_TRACE(__LINE__);
2349 xfs_trans_cancel(tp, 0); 2198 xfs_trans_cancel(tp, 0);
2350 IRELE(ip);
2351 return error; 2199 return error;
2352 } 2200 }
2353 2201
@@ -2355,7 +2203,6 @@ xfs_remove(
2355 if (error) { 2203 if (error) {
2356 REMOVE_DEBUG_TRACE(__LINE__); 2204 REMOVE_DEBUG_TRACE(__LINE__);
2357 xfs_trans_cancel(tp, cancel_flags); 2205 xfs_trans_cancel(tp, cancel_flags);
2358 IRELE(ip);
2359 goto std_return; 2206 goto std_return;
2360 } 2207 }
2361 2208
@@ -2363,23 +2210,18 @@ xfs_remove(
2363 * At this point, we've gotten both the directory and the entry 2210 * At this point, we've gotten both the directory and the entry
2364 * inodes locked. 2211 * inodes locked.
2365 */ 2212 */
2213 IHOLD(ip);
2366 xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL); 2214 xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL);
2367 if (dp != ip) { 2215
2368 /* 2216 IHOLD(dp);
2369 * Increment vnode ref count only in this case since 2217 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
2370 * there's an extra vnode reference in the case where
2371 * dp == ip.
2372 */
2373 IHOLD(dp);
2374 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
2375 }
2376 2218
2377 /* 2219 /*
2378 * Entry must exist since we did a lookup in xfs_lock_dir_and_entry. 2220 * Entry must exist since we did a lookup in xfs_lock_dir_and_entry.
2379 */ 2221 */
2380 XFS_BMAP_INIT(&free_list, &first_block); 2222 XFS_BMAP_INIT(&free_list, &first_block);
2381 error = xfs_dir_removename(tp, dp, name, ip->i_ino, 2223 error = xfs_dir_removename(tp, dp, name, ip->i_ino,
2382 &first_block, &free_list, 0); 2224 &first_block, &free_list, resblks);
2383 if (error) { 2225 if (error) {
2384 ASSERT(error != ENOENT); 2226 ASSERT(error != ENOENT);
2385 REMOVE_DEBUG_TRACE(__LINE__); 2227 REMOVE_DEBUG_TRACE(__LINE__);
@@ -2402,12 +2244,6 @@ xfs_remove(
2402 link_zero = (ip)->i_d.di_nlink==0; 2244 link_zero = (ip)->i_d.di_nlink==0;
2403 2245
2404 /* 2246 /*
2405 * Take an extra ref on the inode so that it doesn't
2406 * go to xfs_inactive() from within the commit.
2407 */
2408 IHOLD(ip);
2409
2410 /*
2411 * If this is a synchronous mount, make sure that the 2247 * If this is a synchronous mount, make sure that the
2412 * remove transaction goes to disk before returning to 2248 * remove transaction goes to disk before returning to
2413 * the user. 2249 * the user.
@@ -2423,10 +2259,8 @@ xfs_remove(
2423 } 2259 }
2424 2260
2425 error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES); 2261 error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
2426 if (error) { 2262 if (error)
2427 IRELE(ip);
2428 goto std_return; 2263 goto std_return;
2429 }
2430 2264
2431 /* 2265 /*
2432 * If we are using filestreams, kill the stream association. 2266 * If we are using filestreams, kill the stream association.
@@ -2438,7 +2272,6 @@ xfs_remove(
2438 xfs_filestream_deassociate(ip); 2272 xfs_filestream_deassociate(ip);
2439 2273
2440 xfs_itrace_exit(ip); 2274 xfs_itrace_exit(ip);
2441 IRELE(ip);
2442 2275
2443/* Fall through to std_return with error = 0 */ 2276/* Fall through to std_return with error = 0 */
2444 std_return: 2277 std_return:
@@ -2467,8 +2300,6 @@ xfs_remove(
2467 cancel_flags |= XFS_TRANS_ABORT; 2300 cancel_flags |= XFS_TRANS_ABORT;
2468 xfs_trans_cancel(tp, cancel_flags); 2301 xfs_trans_cancel(tp, cancel_flags);
2469 2302
2470 IRELE(ip);
2471
2472 goto std_return; 2303 goto std_return;
2473} 2304}
2474 2305
@@ -2536,7 +2367,7 @@ xfs_link(
2536 ips[1] = sip; 2367 ips[1] = sip;
2537 } 2368 }
2538 2369
2539 xfs_lock_inodes(ips, 2, 0, XFS_ILOCK_EXCL); 2370 xfs_lock_inodes(ips, 2, XFS_ILOCK_EXCL);
2540 2371
2541 /* 2372 /*
2542 * Increment vnode ref counts since xfs_trans_commit & 2373 * Increment vnode ref counts since xfs_trans_commit &
@@ -2840,7 +2671,6 @@ xfs_rmdir(
2840 struct xfs_name *name, 2671 struct xfs_name *name,
2841 xfs_inode_t *cdp) 2672 xfs_inode_t *cdp)
2842{ 2673{
2843 bhv_vnode_t *dir_vp = XFS_ITOV(dp);
2844 xfs_mount_t *mp = dp->i_mount; 2674 xfs_mount_t *mp = dp->i_mount;
2845 xfs_trans_t *tp; 2675 xfs_trans_t *tp;
2846 int error; 2676 int error;
@@ -2866,27 +2696,12 @@ xfs_rmdir(
2866 } 2696 }
2867 2697
2868 /* 2698 /*
2869 * We need to get a reference to cdp before we get our log
2870 * reservation. The reason for this is that we cannot call
2871 * xfs_iget for an inode for which we do not have a reference
2872 * once we've acquired a log reservation. This is because the
2873 * inode we are trying to get might be in xfs_inactive going
2874 * for a log reservation. Since we'll have to wait for the
2875 * inactive code to complete before returning from xfs_iget,
2876 * we need to make sure that we don't have log space reserved
2877 * when we call xfs_iget. Instead we get an unlocked reference
2878 * to the inode before getting our log reservation.
2879 */
2880 IHOLD(cdp);
2881
2882 /*
2883 * Get the dquots for the inodes. 2699 * Get the dquots for the inodes.
2884 */ 2700 */
2885 error = XFS_QM_DQATTACH(mp, dp, 0); 2701 error = XFS_QM_DQATTACH(mp, dp, 0);
2886 if (!error && dp != cdp) 2702 if (!error)
2887 error = XFS_QM_DQATTACH(mp, cdp, 0); 2703 error = XFS_QM_DQATTACH(mp, cdp, 0);
2888 if (error) { 2704 if (error) {
2889 IRELE(cdp);
2890 REMOVE_DEBUG_TRACE(__LINE__); 2705 REMOVE_DEBUG_TRACE(__LINE__);
2891 goto std_return; 2706 goto std_return;
2892 } 2707 }
@@ -2913,7 +2728,6 @@ xfs_rmdir(
2913 if (error) { 2728 if (error) {
2914 ASSERT(error != ENOSPC); 2729 ASSERT(error != ENOSPC);
2915 cancel_flags = 0; 2730 cancel_flags = 0;
2916 IRELE(cdp);
2917 goto error_return; 2731 goto error_return;
2918 } 2732 }
2919 XFS_BMAP_INIT(&free_list, &first_block); 2733 XFS_BMAP_INIT(&free_list, &first_block);
@@ -2927,21 +2741,13 @@ xfs_rmdir(
2927 error = xfs_lock_dir_and_entry(dp, cdp); 2741 error = xfs_lock_dir_and_entry(dp, cdp);
2928 if (error) { 2742 if (error) {
2929 xfs_trans_cancel(tp, cancel_flags); 2743 xfs_trans_cancel(tp, cancel_flags);
2930 IRELE(cdp);
2931 goto std_return; 2744 goto std_return;
2932 } 2745 }
2933 2746
2747 IHOLD(dp);
2934 xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL); 2748 xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL);
2935 if (dp != cdp) {
2936 /*
2937 * Only increment the parent directory vnode count if
2938 * we didn't bump it in looking up cdp. The only time
2939 * we don't bump it is when we're looking up ".".
2940 */
2941 VN_HOLD(dir_vp);
2942 }
2943 2749
2944 xfs_itrace_ref(cdp); 2750 IHOLD(cdp);
2945 xfs_trans_ijoin(tp, cdp, XFS_ILOCK_EXCL); 2751 xfs_trans_ijoin(tp, cdp, XFS_ILOCK_EXCL);
2946 2752
2947 ASSERT(cdp->i_d.di_nlink >= 2); 2753 ASSERT(cdp->i_d.di_nlink >= 2);
@@ -2995,12 +2801,6 @@ xfs_rmdir(
2995 last_cdp_link = (cdp)->i_d.di_nlink==0; 2801 last_cdp_link = (cdp)->i_d.di_nlink==0;
2996 2802
2997 /* 2803 /*
2998 * Take an extra ref on the child vnode so that it
2999 * does not go to xfs_inactive() from within the commit.
3000 */
3001 IHOLD(cdp);
3002
3003 /*
3004 * If this is a synchronous mount, make sure that the 2804 * If this is a synchronous mount, make sure that the
3005 * rmdir transaction goes to disk before returning to 2805 * rmdir transaction goes to disk before returning to
3006 * the user. 2806 * the user.
@@ -3014,19 +2814,15 @@ xfs_rmdir(
3014 xfs_bmap_cancel(&free_list); 2814 xfs_bmap_cancel(&free_list);
3015 xfs_trans_cancel(tp, (XFS_TRANS_RELEASE_LOG_RES | 2815 xfs_trans_cancel(tp, (XFS_TRANS_RELEASE_LOG_RES |
3016 XFS_TRANS_ABORT)); 2816 XFS_TRANS_ABORT));
3017 IRELE(cdp);
3018 goto std_return; 2817 goto std_return;
3019 } 2818 }
3020 2819
3021 error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES); 2820 error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
3022 if (error) { 2821 if (error) {
3023 IRELE(cdp);
3024 goto std_return; 2822 goto std_return;
3025 } 2823 }
3026 2824
3027 2825
3028 IRELE(cdp);
3029
3030 /* Fall through to std_return with error = 0 or the errno 2826 /* Fall through to std_return with error = 0 or the errno
3031 * from xfs_trans_commit. */ 2827 * from xfs_trans_commit. */
3032 std_return: 2828 std_return:
diff --git a/fs/xfs/xfs_vnodeops.h b/fs/xfs/xfs_vnodeops.h
index 24c53923dc2c..8abe8f186e20 100644
--- a/fs/xfs/xfs_vnodeops.h
+++ b/fs/xfs/xfs_vnodeops.h
@@ -15,7 +15,6 @@ struct xfs_iomap;
15 15
16 16
17int xfs_open(struct xfs_inode *ip); 17int xfs_open(struct xfs_inode *ip);
18int xfs_getattr(struct xfs_inode *ip, struct bhv_vattr *vap, int flags);
19int xfs_setattr(struct xfs_inode *ip, struct bhv_vattr *vap, int flags, 18int xfs_setattr(struct xfs_inode *ip, struct bhv_vattr *vap, int flags,
20 struct cred *credp); 19 struct cred *credp);
21int xfs_readlink(struct xfs_inode *ip, char *link); 20int xfs_readlink(struct xfs_inode *ip, char *link);
@@ -48,9 +47,9 @@ int xfs_change_file_space(struct xfs_inode *ip, int cmd,
48 struct cred *credp, int attr_flags); 47 struct cred *credp, int attr_flags);
49int xfs_rename(struct xfs_inode *src_dp, struct xfs_name *src_name, 48int xfs_rename(struct xfs_inode *src_dp, struct xfs_name *src_name,
50 struct xfs_inode *src_ip, struct xfs_inode *target_dp, 49 struct xfs_inode *src_ip, struct xfs_inode *target_dp,
51 struct xfs_name *target_name); 50 struct xfs_name *target_name, struct xfs_inode *target_ip);
52int xfs_attr_get(struct xfs_inode *ip, const char *name, char *value, 51int xfs_attr_get(struct xfs_inode *ip, const char *name, char *value,
53 int *valuelenp, int flags, cred_t *cred); 52 int *valuelenp, int flags);
54int xfs_attr_set(struct xfs_inode *dp, const char *name, char *value, 53int xfs_attr_set(struct xfs_inode *dp, const char *name, char *value,
55 int valuelen, int flags); 54 int valuelen, int flags);
56int xfs_attr_remove(struct xfs_inode *dp, const char *name, int flags); 55int xfs_attr_remove(struct xfs_inode *dp, const char *name, int flags);
@@ -61,9 +60,6 @@ int xfs_ioctl(struct xfs_inode *ip, struct file *filp,
61ssize_t xfs_read(struct xfs_inode *ip, struct kiocb *iocb, 60ssize_t xfs_read(struct xfs_inode *ip, struct kiocb *iocb,
62 const struct iovec *iovp, unsigned int segs, 61 const struct iovec *iovp, unsigned int segs,
63 loff_t *offset, int ioflags); 62 loff_t *offset, int ioflags);
64ssize_t xfs_sendfile(struct xfs_inode *ip, struct file *filp,
65 loff_t *offset, int ioflags, size_t count,
66 read_actor_t actor, void *target);
67ssize_t xfs_splice_read(struct xfs_inode *ip, struct file *infilp, 63ssize_t xfs_splice_read(struct xfs_inode *ip, struct file *infilp,
68 loff_t *ppos, struct pipe_inode_info *pipe, size_t count, 64 loff_t *ppos, struct pipe_inode_info *pipe, size_t count,
69 int flags, int ioflags); 65 int flags, int ioflags);
diff --git a/include/acpi/acconfig.h b/include/acpi/acconfig.h
index 422f29c06c77..28fe8bae1037 100644
--- a/include/acpi/acconfig.h
+++ b/include/acpi/acconfig.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -63,7 +63,7 @@
63 63
64/* Current ACPICA subsystem version in YYYYMMDD format */ 64/* Current ACPICA subsystem version in YYYYMMDD format */
65 65
66#define ACPI_CA_VERSION 0x20070126 66#define ACPI_CA_VERSION 0x20080321
67 67
68/* 68/*
69 * OS name, used for the _OS object. The _OS object is essentially obsolete, 69 * OS name, used for the _OS object. The _OS object is essentially obsolete,
@@ -150,6 +150,17 @@
150#define ACPI_OBJ_NUM_OPERANDS 8 150#define ACPI_OBJ_NUM_OPERANDS 8
151#define ACPI_OBJ_MAX_OPERAND 7 151#define ACPI_OBJ_MAX_OPERAND 7
152 152
153/* Number of elements in the Result Stack frame, can be an arbitrary value */
154
155#define ACPI_RESULTS_FRAME_OBJ_NUM 8
156
157/*
158 * Maximal number of elements the Result Stack can contain,
159 * it may be an arbitray value not exceeding the types of
160 * result_size and result_count (now u8).
161 */
162#define ACPI_RESULTS_OBJ_NUM_MAX 255
163
153/* Names within the namespace are 4 bytes long */ 164/* Names within the namespace are 4 bytes long */
154 165
155#define ACPI_NAME_SIZE 4 166#define ACPI_NAME_SIZE 4
diff --git a/include/acpi/acdebug.h b/include/acpi/acdebug.h
index d626bb1d2973..c5a1b50d8d94 100644
--- a/include/acpi/acdebug.h
+++ b/include/acpi/acdebug.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/include/acpi/acdisasm.h b/include/acpi/acdisasm.h
index 389d772c7d5b..788f88782012 100644
--- a/include/acpi/acdisasm.h
+++ b/include/acpi/acdisasm.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -97,19 +97,23 @@ typedef const struct acpi_dmtable_info {
97#define ACPI_DMT_CHKSUM 20 97#define ACPI_DMT_CHKSUM 20
98#define ACPI_DMT_SPACEID 21 98#define ACPI_DMT_SPACEID 21
99#define ACPI_DMT_GAS 22 99#define ACPI_DMT_GAS 22
100#define ACPI_DMT_DMAR 23 100#define ACPI_DMT_ASF 23
101#define ACPI_DMT_MADT 24 101#define ACPI_DMT_DMAR 24
102#define ACPI_DMT_SRAT 25 102#define ACPI_DMT_HEST 25
103#define ACPI_DMT_EXIT 26 103#define ACPI_DMT_HESTNTFY 26
104#define ACPI_DMT_SIG 27 104#define ACPI_DMT_HESTNTYP 27
105#define ACPI_DMT_MADT 28
106#define ACPI_DMT_SRAT 29
107#define ACPI_DMT_EXIT 30
108#define ACPI_DMT_SIG 31
105 109
106typedef 110typedef
107void (*ACPI_TABLE_HANDLER) (struct acpi_table_header * table); 111void (*acpi_dmtable_handler) (struct acpi_table_header * table);
108 112
109struct acpi_dmtable_data { 113struct acpi_dmtable_data {
110 char *signature; 114 char *signature;
111 struct acpi_dmtable_info *table_info; 115 struct acpi_dmtable_info *table_info;
112 ACPI_TABLE_HANDLER table_handler; 116 acpi_dmtable_handler table_handler;
113 char *name; 117 char *name;
114}; 118};
115 119
@@ -149,6 +153,7 @@ extern struct acpi_dmtable_info acpi_dm_table_info_asf3[];
149extern struct acpi_dmtable_info acpi_dm_table_info_asf4[]; 153extern struct acpi_dmtable_info acpi_dm_table_info_asf4[];
150extern struct acpi_dmtable_info acpi_dm_table_info_asf_hdr[]; 154extern struct acpi_dmtable_info acpi_dm_table_info_asf_hdr[];
151extern struct acpi_dmtable_info acpi_dm_table_info_boot[]; 155extern struct acpi_dmtable_info acpi_dm_table_info_boot[];
156extern struct acpi_dmtable_info acpi_dm_table_info_bert[];
152extern struct acpi_dmtable_info acpi_dm_table_info_cpep[]; 157extern struct acpi_dmtable_info acpi_dm_table_info_cpep[];
153extern struct acpi_dmtable_info acpi_dm_table_info_cpep0[]; 158extern struct acpi_dmtable_info acpi_dm_table_info_cpep0[];
154extern struct acpi_dmtable_info acpi_dm_table_info_dbgp[]; 159extern struct acpi_dmtable_info acpi_dm_table_info_dbgp[];
@@ -158,11 +163,17 @@ extern struct acpi_dmtable_info acpi_dm_table_info_dmar_scope[];
158extern struct acpi_dmtable_info acpi_dm_table_info_dmar0[]; 163extern struct acpi_dmtable_info acpi_dm_table_info_dmar0[];
159extern struct acpi_dmtable_info acpi_dm_table_info_dmar1[]; 164extern struct acpi_dmtable_info acpi_dm_table_info_dmar1[];
160extern struct acpi_dmtable_info acpi_dm_table_info_ecdt[]; 165extern struct acpi_dmtable_info acpi_dm_table_info_ecdt[];
166extern struct acpi_dmtable_info acpi_dm_table_info_einj[];
167extern struct acpi_dmtable_info acpi_dm_table_info_einj0[];
168extern struct acpi_dmtable_info acpi_dm_table_info_erst[];
161extern struct acpi_dmtable_info acpi_dm_table_info_facs[]; 169extern struct acpi_dmtable_info acpi_dm_table_info_facs[];
162extern struct acpi_dmtable_info acpi_dm_table_info_fadt1[]; 170extern struct acpi_dmtable_info acpi_dm_table_info_fadt1[];
163extern struct acpi_dmtable_info acpi_dm_table_info_fadt2[]; 171extern struct acpi_dmtable_info acpi_dm_table_info_fadt2[];
164extern struct acpi_dmtable_info acpi_dm_table_info_gas[]; 172extern struct acpi_dmtable_info acpi_dm_table_info_gas[];
165extern struct acpi_dmtable_info acpi_dm_table_info_header[]; 173extern struct acpi_dmtable_info acpi_dm_table_info_header[];
174extern struct acpi_dmtable_info acpi_dm_table_info_hest[];
175extern struct acpi_dmtable_info acpi_dm_table_info_hest9[];
176extern struct acpi_dmtable_info acpi_dm_table_info_hest_notify[];
166extern struct acpi_dmtable_info acpi_dm_table_info_hpet[]; 177extern struct acpi_dmtable_info acpi_dm_table_info_hpet[];
167extern struct acpi_dmtable_info acpi_dm_table_info_madt[]; 178extern struct acpi_dmtable_info acpi_dm_table_info_madt[];
168extern struct acpi_dmtable_info acpi_dm_table_info_madt0[]; 179extern struct acpi_dmtable_info acpi_dm_table_info_madt0[];
@@ -180,6 +191,7 @@ extern struct acpi_dmtable_info acpi_dm_table_info_mcfg0[];
180extern struct acpi_dmtable_info acpi_dm_table_info_rsdp1[]; 191extern struct acpi_dmtable_info acpi_dm_table_info_rsdp1[];
181extern struct acpi_dmtable_info acpi_dm_table_info_rsdp2[]; 192extern struct acpi_dmtable_info acpi_dm_table_info_rsdp2[];
182extern struct acpi_dmtable_info acpi_dm_table_info_sbst[]; 193extern struct acpi_dmtable_info acpi_dm_table_info_sbst[];
194extern struct acpi_dmtable_info acpi_dm_table_info_slic[];
183extern struct acpi_dmtable_info acpi_dm_table_info_slit[]; 195extern struct acpi_dmtable_info acpi_dm_table_info_slit[];
184extern struct acpi_dmtable_info acpi_dm_table_info_spcr[]; 196extern struct acpi_dmtable_info acpi_dm_table_info_spcr[];
185extern struct acpi_dmtable_info acpi_dm_table_info_spmi[]; 197extern struct acpi_dmtable_info acpi_dm_table_info_spmi[];
@@ -194,7 +206,7 @@ extern struct acpi_dmtable_info acpi_dm_table_info_wdrt[];
194 */ 206 */
195void acpi_dm_dump_data_table(struct acpi_table_header *table); 207void acpi_dm_dump_data_table(struct acpi_table_header *table);
196 208
197void 209acpi_status
198acpi_dm_dump_table(u32 table_length, 210acpi_dm_dump_table(u32 table_length,
199 u32 table_offset, 211 u32 table_offset,
200 void *table, 212 void *table,
@@ -213,9 +225,13 @@ void acpi_dm_dump_cpep(struct acpi_table_header *table);
213 225
214void acpi_dm_dump_dmar(struct acpi_table_header *table); 226void acpi_dm_dump_dmar(struct acpi_table_header *table);
215 227
228void acpi_dm_dump_einj(struct acpi_table_header *table);
229
230void acpi_dm_dump_erst(struct acpi_table_header *table);
231
216void acpi_dm_dump_fadt(struct acpi_table_header *table); 232void acpi_dm_dump_fadt(struct acpi_table_header *table);
217 233
218void acpi_dm_dump_srat(struct acpi_table_header *table); 234void acpi_dm_dump_hest(struct acpi_table_header *table);
219 235
220void acpi_dm_dump_mcfg(struct acpi_table_header *table); 236void acpi_dm_dump_mcfg(struct acpi_table_header *table);
221 237
@@ -227,6 +243,8 @@ void acpi_dm_dump_rsdt(struct acpi_table_header *table);
227 243
228void acpi_dm_dump_slit(struct acpi_table_header *table); 244void acpi_dm_dump_slit(struct acpi_table_header *table);
229 245
246void acpi_dm_dump_srat(struct acpi_table_header *table);
247
230void acpi_dm_dump_xsdt(struct acpi_table_header *table); 248void acpi_dm_dump_xsdt(struct acpi_table_header *table);
231 249
232/* 250/*
diff --git a/include/acpi/acdispat.h b/include/acpi/acdispat.h
index 7f690bb0f02f..910f018d92c7 100644
--- a/include/acpi/acdispat.h
+++ b/include/acpi/acdispat.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -53,6 +53,9 @@
53acpi_status 53acpi_status
54acpi_ds_get_buffer_field_arguments(union acpi_operand_object *obj_desc); 54acpi_ds_get_buffer_field_arguments(union acpi_operand_object *obj_desc);
55 55
56acpi_status
57acpi_ds_get_bank_field_arguments(union acpi_operand_object *obj_desc);
58
56acpi_status acpi_ds_get_region_arguments(union acpi_operand_object *rgn_desc); 59acpi_status acpi_ds_get_region_arguments(union acpi_operand_object *rgn_desc);
57 60
58acpi_status acpi_ds_get_buffer_arguments(union acpi_operand_object *obj_desc); 61acpi_status acpi_ds_get_buffer_arguments(union acpi_operand_object *obj_desc);
@@ -68,10 +71,18 @@ acpi_ds_eval_region_operands(struct acpi_walk_state *walk_state,
68 union acpi_parse_object *op); 71 union acpi_parse_object *op);
69 72
70acpi_status 73acpi_status
74acpi_ds_eval_table_region_operands(struct acpi_walk_state *walk_state,
75 union acpi_parse_object *op);
76
77acpi_status
71acpi_ds_eval_data_object_operands(struct acpi_walk_state *walk_state, 78acpi_ds_eval_data_object_operands(struct acpi_walk_state *walk_state,
72 union acpi_parse_object *op, 79 union acpi_parse_object *op,
73 union acpi_operand_object *obj_desc); 80 union acpi_operand_object *obj_desc);
74 81
82acpi_status
83acpi_ds_eval_bank_field_operands(struct acpi_walk_state *walk_state,
84 union acpi_parse_object *op);
85
75acpi_status acpi_ds_initialize_region(acpi_handle obj_handle); 86acpi_status acpi_ds_initialize_region(acpi_handle obj_handle);
76 87
77/* 88/*
@@ -269,6 +280,8 @@ acpi_status acpi_ds_resolve_operands(struct acpi_walk_state *walk_state);
269 280
270void acpi_ds_clear_operands(struct acpi_walk_state *walk_state); 281void acpi_ds_clear_operands(struct acpi_walk_state *walk_state);
271 282
283acpi_status acpi_ds_evaluate_name_path(struct acpi_walk_state *walk_state);
284
272/* 285/*
273 * dswscope - Scope Stack manipulation 286 * dswscope - Scope Stack manipulation
274 */ 287 */
@@ -303,7 +316,7 @@ acpi_ds_init_aml_walk(struct acpi_walk_state *walk_state,
303 u32 aml_length, 316 u32 aml_length,
304 struct acpi_evaluate_info *info, u8 pass_number); 317 struct acpi_evaluate_info *info, u8 pass_number);
305 318
306acpi_status 319void
307acpi_ds_obj_stack_pop_and_delete(u32 pop_count, 320acpi_ds_obj_stack_pop_and_delete(u32 pop_count,
308 struct acpi_walk_state *walk_state); 321 struct acpi_walk_state *walk_state);
309 322
@@ -316,21 +329,11 @@ void
316acpi_ds_push_walk_state(struct acpi_walk_state *walk_state, 329acpi_ds_push_walk_state(struct acpi_walk_state *walk_state,
317 struct acpi_thread_state *thread); 330 struct acpi_thread_state *thread);
318 331
319acpi_status acpi_ds_result_stack_pop(struct acpi_walk_state *walk_state);
320
321acpi_status acpi_ds_result_stack_push(struct acpi_walk_state *walk_state);
322
323acpi_status acpi_ds_result_stack_clear(struct acpi_walk_state *walk_state); 332acpi_status acpi_ds_result_stack_clear(struct acpi_walk_state *walk_state);
324 333
325struct acpi_walk_state *acpi_ds_get_current_walk_state(struct acpi_thread_state 334struct acpi_walk_state *acpi_ds_get_current_walk_state(struct acpi_thread_state
326 *thread); 335 *thread);
327 336
328#ifdef ACPI_FUTURE_USAGE
329acpi_status
330acpi_ds_result_remove(union acpi_operand_object **object,
331 u32 index, struct acpi_walk_state *walk_state);
332#endif
333
334acpi_status 337acpi_status
335acpi_ds_result_pop(union acpi_operand_object **object, 338acpi_ds_result_pop(union acpi_operand_object **object,
336 struct acpi_walk_state *walk_state); 339 struct acpi_walk_state *walk_state);
@@ -339,8 +342,4 @@ acpi_status
339acpi_ds_result_push(union acpi_operand_object *object, 342acpi_ds_result_push(union acpi_operand_object *object,
340 struct acpi_walk_state *walk_state); 343 struct acpi_walk_state *walk_state);
341 344
342acpi_status
343acpi_ds_result_pop_from_bottom(union acpi_operand_object **object,
344 struct acpi_walk_state *walk_state);
345
346#endif /* _ACDISPAT_H_ */ 345#endif /* _ACDISPAT_H_ */
diff --git a/include/acpi/acevents.h b/include/acpi/acevents.h
index d23cdf326808..d5d099bf349c 100644
--- a/include/acpi/acevents.h
+++ b/include/acpi/acevents.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/include/acpi/acexcep.h b/include/acpi/acexcep.h
index b73f18a48785..1f591171bf31 100644
--- a/include/acpi/acexcep.h
+++ b/include/acpi/acexcep.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/include/acpi/acglobal.h b/include/acpi/acglobal.h
index 47a1fd8f2d8a..74ad971241db 100644
--- a/include/acpi/acglobal.h
+++ b/include/acpi/acglobal.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -170,10 +170,14 @@ ACPI_EXTERN u8 acpi_gbl_integer_nybble_width;
170ACPI_EXTERN struct acpi_mutex_info acpi_gbl_mutex_info[ACPI_NUM_MUTEX]; 170ACPI_EXTERN struct acpi_mutex_info acpi_gbl_mutex_info[ACPI_NUM_MUTEX];
171 171
172/* 172/*
173 * Global lock semaphore works in conjunction with the actual HW global lock 173 * Global lock mutex is an actual AML mutex object
174 * Global lock semaphore works in conjunction with the HW global lock
174 */ 175 */
175ACPI_EXTERN acpi_mutex acpi_gbl_global_lock_mutex; 176ACPI_EXTERN union acpi_operand_object *acpi_gbl_global_lock_mutex;
176ACPI_EXTERN acpi_semaphore acpi_gbl_global_lock_semaphore; 177ACPI_EXTERN acpi_semaphore acpi_gbl_global_lock_semaphore;
178ACPI_EXTERN u16 acpi_gbl_global_lock_handle;
179ACPI_EXTERN u8 acpi_gbl_global_lock_acquired;
180ACPI_EXTERN u8 acpi_gbl_global_lock_present;
177 181
178/* 182/*
179 * Spinlocks are used for interfaces that can be possibly called at 183 * Spinlocks are used for interfaces that can be possibly called at
@@ -213,27 +217,33 @@ ACPI_EXTERN struct acpi_object_notify_handler acpi_gbl_device_notify;
213ACPI_EXTERN struct acpi_object_notify_handler acpi_gbl_system_notify; 217ACPI_EXTERN struct acpi_object_notify_handler acpi_gbl_system_notify;
214ACPI_EXTERN acpi_exception_handler acpi_gbl_exception_handler; 218ACPI_EXTERN acpi_exception_handler acpi_gbl_exception_handler;
215ACPI_EXTERN acpi_init_handler acpi_gbl_init_handler; 219ACPI_EXTERN acpi_init_handler acpi_gbl_init_handler;
220ACPI_EXTERN acpi_tbl_handler acpi_gbl_table_handler;
221ACPI_EXTERN void *acpi_gbl_table_handler_context;
216ACPI_EXTERN struct acpi_walk_state *acpi_gbl_breakpoint_walk; 222ACPI_EXTERN struct acpi_walk_state *acpi_gbl_breakpoint_walk;
217 223
224/* Owner ID support */
225
226ACPI_EXTERN u32 acpi_gbl_owner_id_mask[ACPI_NUM_OWNERID_MASKS];
227ACPI_EXTERN u8 acpi_gbl_last_owner_id_index;
228ACPI_EXTERN u8 acpi_gbl_next_owner_id_offset;
229
218/* Misc */ 230/* Misc */
219 231
220ACPI_EXTERN u32 acpi_gbl_original_mode; 232ACPI_EXTERN u32 acpi_gbl_original_mode;
221ACPI_EXTERN u32 acpi_gbl_rsdp_original_location; 233ACPI_EXTERN u32 acpi_gbl_rsdp_original_location;
222ACPI_EXTERN u32 acpi_gbl_ns_lookup_count; 234ACPI_EXTERN u32 acpi_gbl_ns_lookup_count;
223ACPI_EXTERN u32 acpi_gbl_ps_find_count; 235ACPI_EXTERN u32 acpi_gbl_ps_find_count;
224ACPI_EXTERN u32 acpi_gbl_owner_id_mask[ACPI_NUM_OWNERID_MASKS];
225ACPI_EXTERN u16 acpi_gbl_pm1_enable_register_save; 236ACPI_EXTERN u16 acpi_gbl_pm1_enable_register_save;
226ACPI_EXTERN u16 acpi_gbl_global_lock_handle;
227ACPI_EXTERN u8 acpi_gbl_last_owner_id_index;
228ACPI_EXTERN u8 acpi_gbl_next_owner_id_offset;
229ACPI_EXTERN u8 acpi_gbl_debugger_configuration; 237ACPI_EXTERN u8 acpi_gbl_debugger_configuration;
230ACPI_EXTERN u8 acpi_gbl_global_lock_acquired;
231ACPI_EXTERN u8 acpi_gbl_step_to_next_call; 238ACPI_EXTERN u8 acpi_gbl_step_to_next_call;
232ACPI_EXTERN u8 acpi_gbl_acpi_hardware_present; 239ACPI_EXTERN u8 acpi_gbl_acpi_hardware_present;
233ACPI_EXTERN u8 acpi_gbl_global_lock_present;
234ACPI_EXTERN u8 acpi_gbl_events_initialized; 240ACPI_EXTERN u8 acpi_gbl_events_initialized;
235ACPI_EXTERN u8 acpi_gbl_system_awake_and_running; 241ACPI_EXTERN u8 acpi_gbl_system_awake_and_running;
236 242
243#ifndef DEFINE_ACPI_GLOBALS
244
245/* Other miscellaneous */
246
237extern u8 acpi_gbl_shutdown; 247extern u8 acpi_gbl_shutdown;
238extern u32 acpi_gbl_startup_flags; 248extern u32 acpi_gbl_startup_flags;
239extern const char *acpi_gbl_sleep_state_names[ACPI_S_STATE_COUNT]; 249extern const char *acpi_gbl_sleep_state_names[ACPI_S_STATE_COUNT];
@@ -241,6 +251,8 @@ extern const char *acpi_gbl_highest_dstate_names[4];
241extern const struct acpi_opcode_info acpi_gbl_aml_op_info[AML_NUM_OPCODES]; 251extern const struct acpi_opcode_info acpi_gbl_aml_op_info[AML_NUM_OPCODES];
242extern const char *acpi_gbl_region_types[ACPI_NUM_PREDEFINED_REGIONS]; 252extern const char *acpi_gbl_region_types[ACPI_NUM_PREDEFINED_REGIONS];
243 253
254#endif
255
244/* Exception codes */ 256/* Exception codes */
245 257
246extern char const *acpi_gbl_exception_names_env[]; 258extern char const *acpi_gbl_exception_names_env[];
@@ -255,8 +267,6 @@ extern char const *acpi_gbl_exception_names_ctrl[];
255 * 267 *
256 ****************************************************************************/ 268 ****************************************************************************/
257 269
258#define NUM_NS_TYPES ACPI_TYPE_INVALID+1
259
260#if !defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY) 270#if !defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY)
261#define NUM_PREDEFINED_NAMES 10 271#define NUM_PREDEFINED_NAMES 10
262#else 272#else
@@ -267,7 +277,7 @@ ACPI_EXTERN struct acpi_namespace_node acpi_gbl_root_node_struct;
267ACPI_EXTERN struct acpi_namespace_node *acpi_gbl_root_node; 277ACPI_EXTERN struct acpi_namespace_node *acpi_gbl_root_node;
268ACPI_EXTERN struct acpi_namespace_node *acpi_gbl_fadt_gpe_device; 278ACPI_EXTERN struct acpi_namespace_node *acpi_gbl_fadt_gpe_device;
269 279
270extern const u8 acpi_gbl_ns_properties[NUM_NS_TYPES]; 280extern const u8 acpi_gbl_ns_properties[ACPI_NUM_NS_TYPES];
271extern const struct acpi_predefined_names 281extern const struct acpi_predefined_names
272 acpi_gbl_pre_defined_names[NUM_PREDEFINED_NAMES]; 282 acpi_gbl_pre_defined_names[NUM_PREDEFINED_NAMES];
273 283
@@ -275,8 +285,8 @@ extern const struct acpi_predefined_names
275ACPI_EXTERN u32 acpi_gbl_current_node_count; 285ACPI_EXTERN u32 acpi_gbl_current_node_count;
276ACPI_EXTERN u32 acpi_gbl_current_node_size; 286ACPI_EXTERN u32 acpi_gbl_current_node_size;
277ACPI_EXTERN u32 acpi_gbl_max_concurrent_node_count; 287ACPI_EXTERN u32 acpi_gbl_max_concurrent_node_count;
278ACPI_EXTERN acpi_size acpi_gbl_entry_stack_pointer; 288ACPI_EXTERN acpi_size *acpi_gbl_entry_stack_pointer;
279ACPI_EXTERN acpi_size acpi_gbl_lowest_stack_pointer; 289ACPI_EXTERN acpi_size *acpi_gbl_lowest_stack_pointer;
280ACPI_EXTERN u32 acpi_gbl_deepest_nesting; 290ACPI_EXTERN u32 acpi_gbl_deepest_nesting;
281#endif 291#endif
282 292
diff --git a/include/acpi/achware.h b/include/acpi/achware.h
index 4053df943453..d4fb9bbc903c 100644
--- a/include/acpi/achware.h
+++ b/include/acpi/achware.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/include/acpi/acinterp.h b/include/acpi/acinterp.h
index ce7c9d653910..e249ce5d3300 100644
--- a/include/acpi/acinterp.h
+++ b/include/acpi/acinterp.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -215,8 +215,6 @@ acpi_ex_create_region(u8 * aml_start,
215 u32 aml_length, 215 u32 aml_length,
216 u8 region_space, struct acpi_walk_state *walk_state); 216 u8 region_space, struct acpi_walk_state *walk_state);
217 217
218acpi_status acpi_ex_create_table_region(struct acpi_walk_state *walk_state);
219
220acpi_status acpi_ex_create_event(struct acpi_walk_state *walk_state); 218acpi_status acpi_ex_create_event(struct acpi_walk_state *walk_state);
221 219
222acpi_status acpi_ex_create_alias(struct acpi_walk_state *walk_state); 220acpi_status acpi_ex_create_alias(struct acpi_walk_state *walk_state);
@@ -248,9 +246,16 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
248 struct acpi_walk_state *walk_state); 246 struct acpi_walk_state *walk_state);
249 247
250acpi_status 248acpi_status
249acpi_ex_acquire_mutex_object(u16 timeout,
250 union acpi_operand_object *obj_desc,
251 acpi_thread_id thread_id);
252
253acpi_status
251acpi_ex_release_mutex(union acpi_operand_object *obj_desc, 254acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
252 struct acpi_walk_state *walk_state); 255 struct acpi_walk_state *walk_state);
253 256
257acpi_status acpi_ex_release_mutex_object(union acpi_operand_object *obj_desc);
258
254void acpi_ex_release_all_mutexes(struct acpi_thread_state *thread); 259void acpi_ex_release_all_mutexes(struct acpi_thread_state *thread);
255 260
256void acpi_ex_unlink_mutex(union acpi_operand_object *obj_desc); 261void acpi_ex_unlink_mutex(union acpi_operand_object *obj_desc);
@@ -455,9 +460,9 @@ void acpi_ex_relinquish_interpreter(void);
455 460
456void acpi_ex_truncate_for32bit_table(union acpi_operand_object *obj_desc); 461void acpi_ex_truncate_for32bit_table(union acpi_operand_object *obj_desc);
457 462
458u8 acpi_ex_acquire_global_lock(u32 rule); 463void acpi_ex_acquire_global_lock(u32 rule);
459 464
460void acpi_ex_release_global_lock(u8 locked); 465void acpi_ex_release_global_lock(u32 rule);
461 466
462void acpi_ex_eisa_id_to_string(u32 numeric_id, char *out_string); 467void acpi_ex_eisa_id_to_string(u32 numeric_id, char *out_string);
463 468
diff --git a/include/acpi/aclocal.h b/include/acpi/aclocal.h
index 202cd4242ba1..c5cdc32ac2f8 100644
--- a/include/acpi/aclocal.h
+++ b/include/acpi/aclocal.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -522,9 +522,8 @@ struct acpi_thread_state {
522 * AML arguments 522 * AML arguments
523 */ 523 */
524struct acpi_result_values { 524struct acpi_result_values {
525 ACPI_STATE_COMMON u8 num_results; 525 ACPI_STATE_COMMON
526 u8 last_insert; 526 union acpi_operand_object *obj_desc[ACPI_RESULTS_FRAME_OBJ_NUM];
527 union acpi_operand_object *obj_desc[ACPI_OBJ_NUM_OPERANDS];
528}; 527};
529 528
530typedef 529typedef
@@ -604,6 +603,7 @@ union acpi_parse_value {
604 union acpi_parse_object *next; /* Next op */\ 603 union acpi_parse_object *next; /* Next op */\
605 struct acpi_namespace_node *node; /* For use by interpreter */\ 604 struct acpi_namespace_node *node; /* For use by interpreter */\
606 union acpi_parse_value value; /* Value or args associated with the opcode */\ 605 union acpi_parse_value value; /* Value or args associated with the opcode */\
606 u8 arg_list_length; /* Number of elements in the arg list */\
607 ACPI_DISASM_ONLY_MEMBERS (\ 607 ACPI_DISASM_ONLY_MEMBERS (\
608 u8 disasm_flags; /* Used during AML disassembly */\ 608 u8 disasm_flags; /* Used during AML disassembly */\
609 u8 disasm_opcode; /* Subtype used for disassembly */\ 609 u8 disasm_opcode; /* Subtype used for disassembly */\
@@ -696,6 +696,8 @@ struct acpi_parse_state {
696#define ACPI_PARSEOP_NAMED 0x02 696#define ACPI_PARSEOP_NAMED 0x02
697#define ACPI_PARSEOP_DEFERRED 0x04 697#define ACPI_PARSEOP_DEFERRED 0x04
698#define ACPI_PARSEOP_BYTELIST 0x08 698#define ACPI_PARSEOP_BYTELIST 0x08
699#define ACPI_PARSEOP_IN_STACK 0x10
700#define ACPI_PARSEOP_TARGET 0x20
699#define ACPI_PARSEOP_IN_CACHE 0x80 701#define ACPI_PARSEOP_IN_CACHE 0x80
700 702
701/* Parse object disasm_flags */ 703/* Parse object disasm_flags */
diff --git a/include/acpi/acmacros.h b/include/acpi/acmacros.h
index 99d171c87c84..fb41a3b802fc 100644
--- a/include/acpi/acmacros.h
+++ b/include/acpi/acmacros.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -61,30 +61,6 @@
61 61
62#define ACPI_ARRAY_LENGTH(x) (sizeof(x) / sizeof((x)[0])) 62#define ACPI_ARRAY_LENGTH(x) (sizeof(x) / sizeof((x)[0]))
63 63
64#ifdef ACPI_NO_INTEGER64_SUPPORT
65/*
66 * acpi_integer is 32-bits, no 64-bit support on this platform
67 */
68#define ACPI_LODWORD(l) ((u32)(l))
69#define ACPI_HIDWORD(l) ((u32)(0))
70
71#else
72
73/*
74 * Full 64-bit address/integer on both 32-bit and 64-bit platforms
75 */
76#define ACPI_LODWORD(l) ((u32)(u64)(l))
77#define ACPI_HIDWORD(l) ((u32)(((*(struct uint64_struct *)(void *)(&l))).hi))
78#endif
79
80/*
81 * printf() format helpers
82 */
83
84/* Split 64-bit integer into two 32-bit values. Use with %8.8_x%8.8_x */
85
86#define ACPI_FORMAT_UINT64(i) ACPI_HIDWORD(i),ACPI_LODWORD(i)
87
88/* 64/*
89 * Extract data using a pointer. Any more than a byte and we 65 * Extract data using a pointer. Any more than a byte and we
90 * get into potential aligment issues -- see the STORE macros below. 66 * get into potential aligment issues -- see the STORE macros below.
@@ -122,6 +98,31 @@
122#endif 98#endif
123 99
124/* 100/*
101 * Full 64-bit integer must be available on both 32-bit and 64-bit platforms
102 */
103struct acpi_integer_overlay {
104 u32 lo_dword;
105 u32 hi_dword;
106};
107
108#define ACPI_LODWORD(integer) (ACPI_CAST_PTR (struct acpi_integer_overlay, &integer)->lo_dword)
109#define ACPI_HIDWORD(integer) (ACPI_CAST_PTR (struct acpi_integer_overlay, &integer)->hi_dword)
110
111/*
112 * printf() format helpers
113 */
114
115/* Split 64-bit integer into two 32-bit values. Use with %8.8_x%8.8_x */
116
117#define ACPI_FORMAT_UINT64(i) ACPI_HIDWORD(i),ACPI_LODWORD(i)
118
119#if ACPI_MACHINE_WIDTH == 64
120#define ACPI_FORMAT_NATIVE_UINT(i) ACPI_FORMAT_UINT64(i)
121#else
122#define ACPI_FORMAT_NATIVE_UINT(i) 0, (i)
123#endif
124
125/*
125 * Macros for moving data around to/from buffers that are possibly unaligned. 126 * Macros for moving data around to/from buffers that are possibly unaligned.
126 * If the hardware supports the transfer of unaligned data, just do the store. 127 * If the hardware supports the transfer of unaligned data, just do the store.
127 * Otherwise, we have to move one byte at a time. 128 * Otherwise, we have to move one byte at a time.
@@ -137,29 +138,29 @@
137 138
138/* These macros reverse the bytes during the move, converting little-endian to big endian */ 139/* These macros reverse the bytes during the move, converting little-endian to big endian */
139 140
140 /* Big Endian <== Little Endian */ 141 /* Big Endian <== Little Endian */
141 /* Hi...Lo Lo...Hi */ 142 /* Hi...Lo Lo...Hi */
142/* 16-bit source, 16/32/64 destination */ 143/* 16-bit source, 16/32/64 destination */
143 144
144#define ACPI_MOVE_16_TO_16(d,s) {(( u8 *)(void *)(d))[0] = ((u8 *)(void *)(s))[1];\ 145#define ACPI_MOVE_16_TO_16(d,s) {(( u8 *)(void *)(d))[0] = ((u8 *)(void *)(s))[1];\
145 (( u8 *)(void *)(d))[1] = ((u8 *)(void *)(s))[0];} 146 (( u8 *)(void *)(d))[1] = ((u8 *)(void *)(s))[0];}
146 147
147#define ACPI_MOVE_16_TO_32(d,s) {(*(u32 *)(void *)(d))=0;\ 148#define ACPI_MOVE_16_TO_32(d,s) {(*(u32 *)(void *)(d))=0;\
148 ((u8 *)(void *)(d))[2] = ((u8 *)(void *)(s))[1];\ 149 ((u8 *)(void *)(d))[2] = ((u8 *)(void *)(s))[1];\
149 ((u8 *)(void *)(d))[3] = ((u8 *)(void *)(s))[0];} 150 ((u8 *)(void *)(d))[3] = ((u8 *)(void *)(s))[0];}
150 151
151#define ACPI_MOVE_16_TO_64(d,s) {(*(u64 *)(void *)(d))=0;\ 152#define ACPI_MOVE_16_TO_64(d,s) {(*(u64 *)(void *)(d))=0;\
152 ((u8 *)(void *)(d))[6] = ((u8 *)(void *)(s))[1];\ 153 ((u8 *)(void *)(d))[6] = ((u8 *)(void *)(s))[1];\
153 ((u8 *)(void *)(d))[7] = ((u8 *)(void *)(s))[0];} 154 ((u8 *)(void *)(d))[7] = ((u8 *)(void *)(s))[0];}
154 155
155/* 32-bit source, 16/32/64 destination */ 156/* 32-bit source, 16/32/64 destination */
156 157
157#define ACPI_MOVE_32_TO_16(d,s) ACPI_MOVE_16_TO_16(d,s) /* Truncate to 16 */ 158#define ACPI_MOVE_32_TO_16(d,s) ACPI_MOVE_16_TO_16(d,s) /* Truncate to 16 */
158 159
159#define ACPI_MOVE_32_TO_32(d,s) {(( u8 *)(void *)(d))[0] = ((u8 *)(void *)(s))[3];\ 160#define ACPI_MOVE_32_TO_32(d,s) {(( u8 *)(void *)(d))[0] = ((u8 *)(void *)(s))[3];\
160 (( u8 *)(void *)(d))[1] = ((u8 *)(void *)(s))[2];\ 161 (( u8 *)(void *)(d))[1] = ((u8 *)(void *)(s))[2];\
161 (( u8 *)(void *)(d))[2] = ((u8 *)(void *)(s))[1];\ 162 (( u8 *)(void *)(d))[2] = ((u8 *)(void *)(s))[1];\
162 (( u8 *)(void *)(d))[3] = ((u8 *)(void *)(s))[0];} 163 (( u8 *)(void *)(d))[3] = ((u8 *)(void *)(s))[0];}
163 164
164#define ACPI_MOVE_32_TO_64(d,s) {(*(u64 *)(void *)(d))=0;\ 165#define ACPI_MOVE_32_TO_64(d,s) {(*(u64 *)(void *)(d))=0;\
165 ((u8 *)(void *)(d))[4] = ((u8 *)(void *)(s))[3];\ 166 ((u8 *)(void *)(d))[4] = ((u8 *)(void *)(s))[3];\
diff --git a/include/acpi/acnames.h b/include/acpi/acnames.h
index 34bfae8a05f3..c1343a9265fa 100644
--- a/include/acpi/acnames.h
+++ b/include/acpi/acnames.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/include/acpi/acnamesp.h b/include/acpi/acnamesp.h
index 5ef38a6c8a61..713b30903fe5 100644
--- a/include/acpi/acnamesp.h
+++ b/include/acpi/acnamesp.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -113,7 +113,8 @@ acpi_ns_parse_table(acpi_native_uint table_index,
113 113
114acpi_status 114acpi_status
115acpi_ns_one_complete_parse(acpi_native_uint pass_number, 115acpi_ns_one_complete_parse(acpi_native_uint pass_number,
116 acpi_native_uint table_index); 116 acpi_native_uint table_index,
117 struct acpi_namespace_node *start_node);
117 118
118/* 119/*
119 * nsaccess - Top-level namespace access 120 * nsaccess - Top-level namespace access
diff --git a/include/acpi/acobject.h b/include/acpi/acobject.h
index 7e1211a8b8fa..e9657dac69b7 100644
--- a/include/acpi/acobject.h
+++ b/include/acpi/acobject.h
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -155,8 +155,9 @@ struct acpi_object_event {
155struct acpi_object_mutex { 155struct acpi_object_mutex {
156 ACPI_OBJECT_COMMON_HEADER u8 sync_level; /* 0-15, specified in Mutex() call */ 156 ACPI_OBJECT_COMMON_HEADER u8 sync_level; /* 0-15, specified in Mutex() call */
157 u16 acquisition_depth; /* Allow multiple Acquires, same thread */ 157 u16 acquisition_depth; /* Allow multiple Acquires, same thread */
158 struct acpi_thread_state *owner_thread; /* Current owner of the mutex */
159 acpi_mutex os_mutex; /* Actual OS synchronization object */ 158 acpi_mutex os_mutex; /* Actual OS synchronization object */
159 acpi_thread_id thread_id; /* Current owner of the mutex */
160 struct acpi_thread_state *owner_thread; /* Current owner of the mutex */
160 union acpi_operand_object *prev; /* Link for list of acquired mutexes */ 161 union acpi_operand_object *prev; /* Link for list of acquired mutexes */
161 union acpi_operand_object *next; /* Link for list of acquired mutexes */ 162 union acpi_operand_object *next; /* Link for list of acquired mutexes */
162 struct acpi_namespace_node *node; /* Containing namespace node */ 163 struct acpi_namespace_node *node; /* Containing namespace node */
diff --git a/include/acpi/acopcode.h b/include/acpi/acopcode.h
index e6f76a280a94..dfdf63327885 100644
--- a/include/acpi/acopcode.h
+++ b/include/acpi/acopcode.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -233,7 +233,7 @@
233#define ARGI_CREATE_WORD_FIELD_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_INTEGER, ARGI_REFERENCE) 233#define ARGI_CREATE_WORD_FIELD_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_INTEGER, ARGI_REFERENCE)
234#define ARGI_DATA_REGION_OP ARGI_LIST3 (ARGI_STRING, ARGI_STRING, ARGI_STRING) 234#define ARGI_DATA_REGION_OP ARGI_LIST3 (ARGI_STRING, ARGI_STRING, ARGI_STRING)
235#define ARGI_DEBUG_OP ARG_NONE 235#define ARGI_DEBUG_OP ARG_NONE
236#define ARGI_DECREMENT_OP ARGI_LIST1 (ARGI_INTEGER_REF) 236#define ARGI_DECREMENT_OP ARGI_LIST1 (ARGI_TARGETREF)
237#define ARGI_DEREF_OF_OP ARGI_LIST1 (ARGI_REF_OR_STRING) 237#define ARGI_DEREF_OF_OP ARGI_LIST1 (ARGI_REF_OR_STRING)
238#define ARGI_DEVICE_OP ARGI_INVALID_OPCODE 238#define ARGI_DEVICE_OP ARGI_INVALID_OPCODE
239#define ARGI_DIVIDE_OP ARGI_LIST4 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF, ARGI_TARGETREF) 239#define ARGI_DIVIDE_OP ARGI_LIST4 (ARGI_INTEGER, ARGI_INTEGER, ARGI_TARGETREF, ARGI_TARGETREF)
@@ -246,7 +246,7 @@
246#define ARGI_FIND_SET_RIGHT_BIT_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_TARGETREF) 246#define ARGI_FIND_SET_RIGHT_BIT_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_TARGETREF)
247#define ARGI_FROM_BCD_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_FIXED_TARGET) 247#define ARGI_FROM_BCD_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_FIXED_TARGET)
248#define ARGI_IF_OP ARGI_INVALID_OPCODE 248#define ARGI_IF_OP ARGI_INVALID_OPCODE
249#define ARGI_INCREMENT_OP ARGI_LIST1 (ARGI_INTEGER_REF) 249#define ARGI_INCREMENT_OP ARGI_LIST1 (ARGI_TARGETREF)
250#define ARGI_INDEX_FIELD_OP ARGI_INVALID_OPCODE 250#define ARGI_INDEX_FIELD_OP ARGI_INVALID_OPCODE
251#define ARGI_INDEX_OP ARGI_LIST3 (ARGI_COMPLEXOBJ, ARGI_INTEGER, ARGI_TARGETREF) 251#define ARGI_INDEX_OP ARGI_LIST3 (ARGI_COMPLEXOBJ, ARGI_INTEGER, ARGI_TARGETREF)
252#define ARGI_LAND_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_INTEGER) 252#define ARGI_LAND_OP ARGI_LIST2 (ARGI_INTEGER, ARGI_INTEGER)
diff --git a/include/acpi/acoutput.h b/include/acpi/acoutput.h
index c090a8b0bc99..e17873defcec 100644
--- a/include/acpi/acoutput.h
+++ b/include/acpi/acoutput.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/include/acpi/acparser.h b/include/acpi/acparser.h
index 85c358e21014..23ee0fbf5619 100644
--- a/include/acpi/acparser.h
+++ b/include/acpi/acparser.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -109,6 +109,8 @@ const struct acpi_opcode_info *acpi_ps_get_opcode_info(u16 opcode);
109 109
110char *acpi_ps_get_opcode_name(u16 opcode); 110char *acpi_ps_get_opcode_name(u16 opcode);
111 111
112u8 acpi_ps_get_argument_count(u32 op_type);
113
112/* 114/*
113 * psparse - top level parsing routines 115 * psparse - top level parsing routines
114 */ 116 */
diff --git a/include/acpi/acpi.h b/include/acpi/acpi.h
index 2e5f00d3ea0d..c515ef6cc89e 100644
--- a/include/acpi/acpi.h
+++ b/include/acpi/acpi.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/include/acpi/acpiosxf.h b/include/acpi/acpiosxf.h
index 4839f2af94c3..d4a560d2deb6 100644
--- a/include/acpi/acpiosxf.h
+++ b/include/acpi/acpiosxf.h
@@ -8,7 +8,7 @@
8 *****************************************************************************/ 8 *****************************************************************************/
9 9
10/* 10/*
11 * Copyright (C) 2000 - 2007, R. Byron Moore 11 * Copyright (C) 2000 - 2008, Intel Corp.
12 * All rights reserved. 12 * All rights reserved.
13 * 13 *
14 * Redistribution and use in source and binary forms, with or without 14 * Redistribution and use in source and binary forms, with or without
diff --git a/include/acpi/acpixf.h b/include/acpi/acpixf.h
index d970f7f99549..2c3806e6546f 100644
--- a/include/acpi/acpixf.h
+++ b/include/acpi/acpixf.h
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -119,6 +119,11 @@ acpi_status
119acpi_get_table_by_index(acpi_native_uint table_index, 119acpi_get_table_by_index(acpi_native_uint table_index,
120 struct acpi_table_header **out_table); 120 struct acpi_table_header **out_table);
121 121
122acpi_status
123acpi_install_table_handler(acpi_tbl_handler handler, void *context);
124
125acpi_status acpi_remove_table_handler(acpi_tbl_handler handler);
126
122/* 127/*
123 * Namespace and name interfaces 128 * Namespace and name interfaces
124 */ 129 */
diff --git a/include/acpi/acresrc.h b/include/acpi/acresrc.h
index 9486ab266a5e..eef5bd7a59fa 100644
--- a/include/acpi/acresrc.h
+++ b/include/acpi/acresrc.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -94,6 +94,7 @@ typedef const struct acpi_rsconvert_info {
94#define ACPI_RSC_BITMASK16 18 94#define ACPI_RSC_BITMASK16 18
95#define ACPI_RSC_EXIT_NE 19 95#define ACPI_RSC_EXIT_NE 19
96#define ACPI_RSC_EXIT_LE 20 96#define ACPI_RSC_EXIT_LE 20
97#define ACPI_RSC_EXIT_EQ 21
97 98
98/* Resource Conversion sub-opcodes */ 99/* Resource Conversion sub-opcodes */
99 100
diff --git a/include/acpi/acstruct.h b/include/acpi/acstruct.h
index 88482655407f..a907c67d651e 100644
--- a/include/acpi/acstruct.h
+++ b/include/acpi/acstruct.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -80,12 +80,15 @@ struct acpi_walk_state {
80 u16 opcode; /* Current AML opcode */ 80 u16 opcode; /* Current AML opcode */
81 u8 next_op_info; /* Info about next_op */ 81 u8 next_op_info; /* Info about next_op */
82 u8 num_operands; /* Stack pointer for Operands[] array */ 82 u8 num_operands; /* Stack pointer for Operands[] array */
83 u8 operand_index; /* Index into operand stack, to be used by acpi_ds_obj_stack_push */
83 acpi_owner_id owner_id; /* Owner of objects created during the walk */ 84 acpi_owner_id owner_id; /* Owner of objects created during the walk */
84 u8 last_predicate; /* Result of last predicate */ 85 u8 last_predicate; /* Result of last predicate */
85 u8 current_result; 86 u8 current_result;
86 u8 return_used; 87 u8 return_used;
87 u8 scope_depth; 88 u8 scope_depth;
88 u8 pass_number; /* Parse pass during table load */ 89 u8 pass_number; /* Parse pass during table load */
90 u8 result_size; /* Total elements for the result stack */
91 u8 result_count; /* Current number of occupied elements of result stack */
89 u32 aml_offset; 92 u32 aml_offset;
90 u32 arg_types; 93 u32 arg_types;
91 u32 method_breakpoint; /* For single stepping */ 94 u32 method_breakpoint; /* For single stepping */
diff --git a/include/acpi/actables.h b/include/acpi/actables.h
index 2b9f46f9da4d..4b36a55b0b3b 100644
--- a/include/acpi/actables.h
+++ b/include/acpi/actables.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/include/acpi/actbl.h b/include/acpi/actbl.h
index 955adfb8d64c..1ebbe883f786 100644
--- a/include/acpi/actbl.h
+++ b/include/acpi/actbl.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/include/acpi/actbl1.h b/include/acpi/actbl1.h
index a1b1b2ee3e51..9af239bd1153 100644
--- a/include/acpi/actbl1.h
+++ b/include/acpi/actbl1.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -58,20 +58,28 @@
58 * it more difficult to inadvertently type in the wrong signature. 58 * it more difficult to inadvertently type in the wrong signature.
59 */ 59 */
60#define ACPI_SIG_ASF "ASF!" /* Alert Standard Format table */ 60#define ACPI_SIG_ASF "ASF!" /* Alert Standard Format table */
61#define ACPI_SIG_BERT "BERT" /* Boot Error Record Table */
61#define ACPI_SIG_BOOT "BOOT" /* Simple Boot Flag Table */ 62#define ACPI_SIG_BOOT "BOOT" /* Simple Boot Flag Table */
62#define ACPI_SIG_CPEP "CPEP" /* Corrected Platform Error Polling table */ 63#define ACPI_SIG_CPEP "CPEP" /* Corrected Platform Error Polling table */
63#define ACPI_SIG_DBGP "DBGP" /* Debug Port table */ 64#define ACPI_SIG_DBGP "DBGP" /* Debug Port table */
64#define ACPI_SIG_DMAR "DMAR" /* DMA Remapping table */ 65#define ACPI_SIG_DMAR "DMAR" /* DMA Remapping table */
65#define ACPI_SIG_ECDT "ECDT" /* Embedded Controller Boot Resources Table */ 66#define ACPI_SIG_ECDT "ECDT" /* Embedded Controller Boot Resources Table */
67#define ACPI_SIG_EINJ "EINJ" /* Error Injection table */
68#define ACPI_SIG_ERST "ERST" /* Error Record Serialization Table */
69#define ACPI_SIG_HEST "HEST" /* Hardware Error Source Table */
66#define ACPI_SIG_HPET "HPET" /* High Precision Event Timer table */ 70#define ACPI_SIG_HPET "HPET" /* High Precision Event Timer table */
71#define ACPI_SIG_IBFT "IBFT" /* i_sCSI Boot Firmware Table */
67#define ACPI_SIG_MADT "APIC" /* Multiple APIC Description Table */ 72#define ACPI_SIG_MADT "APIC" /* Multiple APIC Description Table */
68#define ACPI_SIG_MCFG "MCFG" /* PCI Memory Mapped Configuration table */ 73#define ACPI_SIG_MCFG "MCFG" /* PCI Memory Mapped Configuration table */
69#define ACPI_SIG_SBST "SBST" /* Smart Battery Specification Table */ 74#define ACPI_SIG_SBST "SBST" /* Smart Battery Specification Table */
75#define ACPI_SIG_SLIC "SLIC" /* Software Licensing Description Table */
70#define ACPI_SIG_SLIT "SLIT" /* System Locality Distance Information Table */ 76#define ACPI_SIG_SLIT "SLIT" /* System Locality Distance Information Table */
71#define ACPI_SIG_SPCR "SPCR" /* Serial Port Console Redirection table */ 77#define ACPI_SIG_SPCR "SPCR" /* Serial Port Console Redirection table */
72#define ACPI_SIG_SPMI "SPMI" /* Server Platform Management Interface table */ 78#define ACPI_SIG_SPMI "SPMI" /* Server Platform Management Interface table */
73#define ACPI_SIG_SRAT "SRAT" /* System Resource Affinity Table */ 79#define ACPI_SIG_SRAT "SRAT" /* System Resource Affinity Table */
74#define ACPI_SIG_TCPA "TCPA" /* Trusted Computing Platform Alliance table */ 80#define ACPI_SIG_TCPA "TCPA" /* Trusted Computing Platform Alliance table */
81#define ACPI_SIG_UEFI "UEFI" /* Uefi Boot Optimization Table */
82#define ACPI_SIG_WDAT "WDAT" /* Watchdog Action Table */
75#define ACPI_SIG_WDRT "WDRT" /* Watchdog Resource Table */ 83#define ACPI_SIG_WDRT "WDRT" /* Watchdog Resource Table */
76 84
77/* 85/*
@@ -86,13 +94,25 @@
86 * portable, so do not use any other bitfield types. 94 * portable, so do not use any other bitfield types.
87 */ 95 */
88 96
89/* Common Sub-table header (used in MADT, SRAT, etc.) */ 97/* Common Subtable header (used in MADT, SRAT, etc.) */
90 98
91struct acpi_subtable_header { 99struct acpi_subtable_header {
92 u8 type; 100 u8 type;
93 u8 length; 101 u8 length;
94}; 102};
95 103
104/* Common Subtable header for WHEA tables (EINJ, ERST, WDAT) */
105
106struct acpi_whea_header {
107 u8 action;
108 u8 instruction;
109 u8 flags;
110 u8 reserved;
111 struct acpi_generic_address register_region;
112 u64 value; /* Value used with Read/Write register */
113 u64 mask; /* Bitmask required for this register instruction */
114};
115
96/******************************************************************************* 116/*******************************************************************************
97 * 117 *
98 * ASF - Alert Standard Format table (Signature "ASF!") 118 * ASF - Alert Standard Format table (Signature "ASF!")
@@ -204,6 +224,35 @@ struct acpi_asf_address {
204 224
205/******************************************************************************* 225/*******************************************************************************
206 * 226 *
227 * BERT - Boot Error Record Table
228 *
229 ******************************************************************************/
230
231struct acpi_table_bert {
232 struct acpi_table_header header; /* Common ACPI table header */
233 u32 region_length; /* Length of the boot error region */
234 u64 address; /* Physical addresss of the error region */
235};
236
237/* Boot Error Region */
238
239struct acpi_bert_region {
240 u32 block_status;
241 u32 raw_data_offset;
242 u32 raw_data_length;
243 u32 data_length;
244 u32 error_severity;
245};
246
247/* block_status Flags */
248
249#define ACPI_BERT_UNCORRECTABLE (1)
250#define ACPI_BERT_CORRECTABLE (2)
251#define ACPI_BERT_MULTIPLE_UNCORRECTABLE (4)
252#define ACPI_BERT_MULTIPLE_CORRECTABLE (8)
253
254/*******************************************************************************
255 *
207 * BOOT - Simple Boot Flag Table 256 * BOOT - Simple Boot Flag Table
208 * 257 *
209 ******************************************************************************/ 258 ******************************************************************************/
@@ -350,6 +399,352 @@ struct acpi_table_ecdt {
350 399
351/******************************************************************************* 400/*******************************************************************************
352 * 401 *
402 * EINJ - Error Injection Table
403 *
404 ******************************************************************************/
405
406struct acpi_table_einj {
407 struct acpi_table_header header; /* Common ACPI table header */
408 u32 header_length;
409 u32 reserved;
410 u32 entries;
411};
412
413/* EINJ Injection Instruction Entries (actions) */
414
415struct acpi_einj_entry {
416 struct acpi_whea_header whea_header; /* Common header for WHEA tables */
417};
418
419/* Values for Action field above */
420
421enum acpi_einj_actions {
422 ACPI_EINJ_BEGIN_OPERATION = 0,
423 ACPI_EINJ_GET_TRIGGER_TABLE = 1,
424 ACPI_EINJ_SET_ERROR_TYPE = 2,
425 ACPI_EINJ_GET_ERROR_TYPE = 3,
426 ACPI_EINJ_END_OPERATION = 4,
427 ACPI_EINJ_EXECUTE_OPERATION = 5,
428 ACPI_EINJ_CHECK_BUSY_STATUS = 6,
429 ACPI_EINJ_GET_COMMAND_STATUS = 7,
430 ACPI_EINJ_ACTION_RESERVED = 8, /* 8 and greater are reserved */
431 ACPI_EINJ_TRIGGER_ERROR = 0xFF /* Except for this value */
432};
433
434/* Values for Instruction field above */
435
436enum acpi_einj_instructions {
437 ACPI_EINJ_READ_REGISTER = 0,
438 ACPI_EINJ_READ_REGISTER_VALUE = 1,
439 ACPI_EINJ_WRITE_REGISTER = 2,
440 ACPI_EINJ_WRITE_REGISTER_VALUE = 3,
441 ACPI_EINJ_NOOP = 4,
442 ACPI_EINJ_INSTRUCTION_RESERVED = 5 /* 5 and greater are reserved */
443};
444
445/* EINJ Trigger Error Action Table */
446
447struct acpi_einj_trigger {
448 u32 header_size;
449 u32 revision;
450 u32 table_size;
451 u32 entry_count;
452};
453
454/*******************************************************************************
455 *
456 * ERST - Error Record Serialization Table
457 *
458 ******************************************************************************/
459
460struct acpi_table_erst {
461 struct acpi_table_header header; /* Common ACPI table header */
462 u32 header_length;
463 u32 reserved;
464 u32 entries;
465};
466
467/* ERST Serialization Entries (actions) */
468
469struct acpi_erst_entry {
470 struct acpi_whea_header whea_header; /* Common header for WHEA tables */
471};
472
473/* Values for Action field above */
474
475enum acpi_erst_actions {
476 ACPI_ERST_BEGIN_WRITE_OPERATION = 0,
477 ACPI_ERST_BEGIN_READ_OPERATION = 1,
478 ACPI_ERST_BETGIN_CLEAR_OPERATION = 2,
479 ACPI_ERST_END_OPERATION = 3,
480 ACPI_ERST_SET_RECORD_OFFSET = 4,
481 ACPI_ERST_EXECUTE_OPERATION = 5,
482 ACPI_ERST_CHECK_BUSY_STATUS = 6,
483 ACPI_ERST_GET_COMMAND_STATUS = 7,
484 ACPI_ERST_GET_RECORD_IDENTIFIER = 8,
485 ACPI_ERST_SET_RECORD_IDENTIFIER = 9,
486 ACPI_ERST_GET_RECORD_COUNT = 10,
487 ACPI_ERST_BEGIN_DUMMY_WRIITE = 11,
488 ACPI_ERST_NOT_USED = 12,
489 ACPI_ERST_GET_ERROR_RANGE = 13,
490 ACPI_ERST_GET_ERROR_LENGTH = 14,
491 ACPI_ERST_GET_ERROR_ATTRIBUTES = 15,
492 ACPI_ERST_ACTION_RESERVED = 16 /* 16 and greater are reserved */
493};
494
495/* Values for Instruction field above */
496
497enum acpi_erst_instructions {
498 ACPI_ERST_READ_REGISTER = 0,
499 ACPI_ERST_READ_REGISTER_VALUE = 1,
500 ACPI_ERST_WRITE_REGISTER = 2,
501 ACPI_ERST_WRITE_REGISTER_VALUE = 3,
502 ACPI_ERST_NOOP = 4,
503 ACPI_ERST_LOAD_VAR1 = 5,
504 ACPI_ERST_LOAD_VAR2 = 6,
505 ACPI_ERST_STORE_VAR1 = 7,
506 ACPI_ERST_ADD = 8,
507 ACPI_ERST_SUBTRACT = 9,
508 ACPI_ERST_ADD_VALUE = 10,
509 ACPI_ERST_SUBTRACT_VALUE = 11,
510 ACPI_ERST_STALL = 12,
511 ACPI_ERST_STALL_WHILE_TRUE = 13,
512 ACPI_ERST_SKIP_NEXT_IF_TRUE = 14,
513 ACPI_ERST_GOTO = 15,
514 ACPI_ERST_SET_SRC_ADDRESS_BASE = 16,
515 ACPI_ERST_SET_DST_ADDRESS_BASE = 17,
516 ACPI_ERST_MOVE_DATA = 18,
517 ACPI_ERST_INSTRUCTION_RESERVED = 19 /* 19 and greater are reserved */
518};
519
520/*******************************************************************************
521 *
522 * HEST - Hardware Error Source Table
523 *
524 ******************************************************************************/
525
526struct acpi_table_hest {
527 struct acpi_table_header header; /* Common ACPI table header */
528 u32 error_source_count;
529};
530
531/* HEST subtable header */
532
533struct acpi_hest_header {
534 u16 type;
535};
536
537/* Values for Type field above for subtables */
538
539enum acpi_hest_types {
540 ACPI_HEST_TYPE_XPF_MACHINE_CHECK = 0,
541 ACPI_HEST_TYPE_XPF_CORRECTED_MACHINE_CHECK = 1,
542 ACPI_HEST_TYPE_XPF_UNUSED = 2,
543 ACPI_HEST_TYPE_XPF_NON_MASKABLE_INTERRUPT = 3,
544 ACPI_HEST_TYPE_IPF_CORRECTED_MACHINE_CHECK = 4,
545 ACPI_HEST_TYPE_IPF_CORRECTED_PLATFORM_ERROR = 5,
546 ACPI_HEST_TYPE_AER_ROOT_PORT = 6,
547 ACPI_HEST_TYPE_AER_ENDPOINT = 7,
548 ACPI_HEST_TYPE_AER_BRIDGE = 8,
549 ACPI_HEST_TYPE_GENERIC_HARDWARE_ERROR_SOURCE = 9,
550 ACPI_HEST_TYPE_RESERVED = 10 /* 10 and greater are reserved */
551};
552
553/*
554 * HEST Sub-subtables
555 */
556
557/* XPF Machine Check Error Bank */
558
559struct acpi_hest_xpf_error_bank {
560 u8 bank_number;
561 u8 clear_status_on_init;
562 u8 status_format;
563 u8 config_write_enable;
564 u32 control_register;
565 u64 control_init_data;
566 u32 status_register;
567 u32 address_register;
568 u32 misc_register;
569};
570
571/* Generic Error Status */
572
573struct acpi_hest_generic_status {
574 u32 block_status;
575 u32 raw_data_offset;
576 u32 raw_data_length;
577 u32 data_length;
578 u32 error_severity;
579};
580
581/* Generic Error Data */
582
583struct acpi_hest_generic_data {
584 u8 section_type[16];
585 u32 error_severity;
586 u16 revision;
587 u8 validation_bits;
588 u8 flags;
589 u32 error_data_length;
590 u8 fru_id[16];
591 u8 fru_text[20];
592};
593
594/* Common HEST structure for PCI/AER types below (6,7,8) */
595
596struct acpi_hest_aer_common {
597 u16 source_id;
598 u16 config_write_enable;
599 u8 flags;
600 u8 enabled;
601 u32 records_to_pre_allocate;
602 u32 max_sections_per_record;
603 u32 bus;
604 u16 device;
605 u16 function;
606 u16 device_control;
607 u16 reserved;
608 u32 uncorrectable_error_mask;
609 u32 uncorrectable_error_severity;
610 u32 correctable_error_mask;
611 u32 advanced_error_cababilities;
612};
613
614/* Hardware Error Notification */
615
616struct acpi_hest_notify {
617 u8 type;
618 u8 length;
619 u16 config_write_enable;
620 u32 poll_interval;
621 u32 vector;
622 u32 polling_threshold_value;
623 u32 polling_threshold_window;
624 u32 error_threshold_value;
625 u32 error_threshold_window;
626};
627
628/* Values for Notify Type field above */
629
630enum acpi_hest_notify_types {
631 ACPI_HEST_NOTIFY_POLLED = 0,
632 ACPI_HEST_NOTIFY_EXTERNAL = 1,
633 ACPI_HEST_NOTIFY_LOCAL = 2,
634 ACPI_HEST_NOTIFY_SCI = 3,
635 ACPI_HEST_NOTIFY_NMI = 4,
636 ACPI_HEST_NOTIFY_RESERVED = 5 /* 5 and greater are reserved */
637};
638
639/*
640 * HEST subtables
641 *
642 * From WHEA Design Document, 16 May 2007.
643 * Note: There is no subtable type 2 in this version of the document,
644 * and there are two different subtable type 3s.
645 */
646
647 /* 0: XPF Machine Check Exception */
648
649struct acpi_hest_xpf_machine_check {
650 struct acpi_hest_header header;
651 u16 source_id;
652 u16 config_write_enable;
653 u8 flags;
654 u8 reserved1;
655 u32 records_to_pre_allocate;
656 u32 max_sections_per_record;
657 u64 global_capability_data;
658 u64 global_control_data;
659 u8 num_hardware_banks;
660 u8 reserved2[7];
661};
662
663/* 1: XPF Corrected Machine Check */
664
665struct acpi_table_hest_xpf_corrected {
666 struct acpi_hest_header header;
667 u16 source_id;
668 u16 config_write_enable;
669 u8 flags;
670 u8 enabled;
671 u32 records_to_pre_allocate;
672 u32 max_sections_per_record;
673 struct acpi_hest_notify notify;
674 u8 num_hardware_banks;
675 u8 reserved[3];
676};
677
678/* 3: XPF Non-Maskable Interrupt */
679
680struct acpi_hest_xpf_nmi {
681 struct acpi_hest_header header;
682 u16 source_id;
683 u32 reserved;
684 u32 records_to_pre_allocate;
685 u32 max_sections_per_record;
686 u32 max_raw_data_length;
687};
688
689/* 4: IPF Corrected Machine Check */
690
691struct acpi_hest_ipf_corrected {
692 struct acpi_hest_header header;
693 u8 enabled;
694 u8 reserved;
695};
696
697/* 5: IPF Corrected Platform Error */
698
699struct acpi_hest_ipf_corrected_platform {
700 struct acpi_hest_header header;
701 u8 enabled;
702 u8 reserved;
703};
704
705/* 6: PCI Express Root Port AER */
706
707struct acpi_hest_aer_root {
708 struct acpi_hest_header header;
709 struct acpi_hest_aer_common aer;
710 u32 root_error_command;
711};
712
713/* 7: PCI Express AER (AER Endpoint) */
714
715struct acpi_hest_aer {
716 struct acpi_hest_header header;
717 struct acpi_hest_aer_common aer;
718};
719
720/* 8: PCI Express/PCI-X Bridge AER */
721
722struct acpi_hest_aer_bridge {
723 struct acpi_hest_header header;
724 struct acpi_hest_aer_common aer;
725 u32 secondary_uncorrectable_error_mask;
726 u32 secondary_uncorrectable_error_severity;
727 u32 secondary_advanced_capabilities;
728};
729
730/* 9: Generic Hardware Error Source */
731
732struct acpi_hest_generic {
733 struct acpi_hest_header header;
734 u16 source_id;
735 u16 related_source_id;
736 u8 config_write_enable;
737 u8 enabled;
738 u32 records_to_pre_allocate;
739 u32 max_sections_per_record;
740 u32 max_raw_data_length;
741 struct acpi_generic_address error_status_address;
742 struct acpi_hest_notify notify;
743 u32 error_status_block_length;
744};
745
746/*******************************************************************************
747 *
353 * HPET - High Precision Event Timer table 748 * HPET - High Precision Event Timer table
354 * 749 *
355 ******************************************************************************/ 750 ******************************************************************************/
@@ -373,6 +768,96 @@ struct acpi_table_hpet {
373 768
374/******************************************************************************* 769/*******************************************************************************
375 * 770 *
771 * IBFT - Boot Firmware Table
772 *
773 ******************************************************************************/
774
775struct acpi_table_ibft {
776 struct acpi_table_header header; /* Common ACPI table header */
777 u8 reserved[12];
778};
779
780/* IBFT common subtable header */
781
782struct acpi_ibft_header {
783 u8 type;
784 u8 version;
785 u16 length;
786 u8 index;
787 u8 flags;
788};
789
790/* Values for Type field above */
791
792enum acpi_ibft_type {
793 ACPI_IBFT_TYPE_NOT_USED = 0,
794 ACPI_IBFT_TYPE_CONTROL = 1,
795 ACPI_IBFT_TYPE_INITIATOR = 2,
796 ACPI_IBFT_TYPE_NIC = 3,
797 ACPI_IBFT_TYPE_TARGET = 4,
798 ACPI_IBFT_TYPE_EXTENSIONS = 5,
799 ACPI_IBFT_TYPE_RESERVED = 6 /* 6 and greater are reserved */
800};
801
802/* IBFT subtables */
803
804struct acpi_ibft_control {
805 struct acpi_ibft_header header;
806 u16 extensions;
807 u16 initiator_offset;
808 u16 nic0_offset;
809 u16 target0_offset;
810 u16 nic1_offset;
811 u16 target1_offset;
812};
813
814struct acpi_ibft_initiator {
815 struct acpi_ibft_header header;
816 u8 sns_server[16];
817 u8 slp_server[16];
818 u8 primary_server[16];
819 u8 secondary_server[16];
820 u16 name_length;
821 u16 name_offset;
822};
823
824struct acpi_ibft_nic {
825 struct acpi_ibft_header header;
826 u8 ip_address[16];
827 u8 subnet_mask_prefix;
828 u8 origin;
829 u8 gateway[16];
830 u8 primary_dns[16];
831 u8 secondary_dns[16];
832 u8 dhcp[16];
833 u16 vlan;
834 u8 mac_address[6];
835 u16 pci_address;
836 u16 name_length;
837 u16 name_offset;
838};
839
840struct acpi_ibft_target {
841 struct acpi_ibft_header header;
842 u8 target_ip_address[16];
843 u16 target_ip_socket;
844 u8 target_boot_lun[8];
845 u8 chap_type;
846 u8 nic_association;
847 u16 target_name_length;
848 u16 target_name_offset;
849 u16 chap_name_length;
850 u16 chap_name_offset;
851 u16 chap_secret_length;
852 u16 chap_secret_offset;
853 u16 reverse_chap_name_length;
854 u16 reverse_chap_name_offset;
855 u16 reverse_chap_secret_length;
856 u16 reverse_chap_secret_offset;
857};
858
859/*******************************************************************************
860 *
376 * MADT - Multiple APIC Description Table 861 * MADT - Multiple APIC Description Table
377 * 862 *
378 ******************************************************************************/ 863 ******************************************************************************/
@@ -697,6 +1182,78 @@ struct acpi_table_tcpa {
697 1182
698/******************************************************************************* 1183/*******************************************************************************
699 * 1184 *
1185 * UEFI - UEFI Boot optimization Table
1186 *
1187 ******************************************************************************/
1188
1189struct acpi_table_uefi {
1190 struct acpi_table_header header; /* Common ACPI table header */
1191 u8 identifier[16]; /* UUID identifier */
1192 u16 data_offset; /* Offset of remaining data in table */
1193 u8 data;
1194};
1195
1196/*******************************************************************************
1197 *
1198 * WDAT - Watchdog Action Table
1199 *
1200 ******************************************************************************/
1201
1202struct acpi_table_wdat {
1203 struct acpi_table_header header; /* Common ACPI table header */
1204 u32 header_length; /* Watchdog Header Length */
1205 u16 pci_segment; /* PCI Segment number */
1206 u8 pci_bus; /* PCI Bus number */
1207 u8 pci_device; /* PCI Device number */
1208 u8 pci_function; /* PCI Function number */
1209 u8 reserved[3];
1210 u32 timer_period; /* Period of one timer count (msec) */
1211 u32 max_count; /* Maximum counter value supported */
1212 u32 min_count; /* Minimum counter value */
1213 u8 flags;
1214 u8 reserved2[3];
1215 u32 entries; /* Number of watchdog entries that follow */
1216};
1217
1218/* WDAT Instruction Entries (actions) */
1219
1220struct acpi_wdat_entry {
1221 struct acpi_whea_header whea_header; /* Common header for WHEA tables */
1222};
1223
1224/* Values for Action field above */
1225
1226enum acpi_wdat_actions {
1227 ACPI_WDAT_RESET = 1,
1228 ACPI_WDAT_GET_CURRENT_COUNTDOWN = 4,
1229 ACPI_WDAT_GET_COUNTDOWN = 5,
1230 ACPI_WDAT_SET_COUNTDOWN = 6,
1231 ACPI_WDAT_GET_RUNNING_STATE = 8,
1232 ACPI_WDAT_SET_RUNNING_STATE = 9,
1233 ACPI_WDAT_GET_STOPPED_STATE = 10,
1234 ACPI_WDAT_SET_STOPPED_STATE = 11,
1235 ACPI_WDAT_GET_REBOOT = 16,
1236 ACPI_WDAT_SET_REBOOT = 17,
1237 ACPI_WDAT_GET_SHUTDOWN = 18,
1238 ACPI_WDAT_SET_SHUTDOWN = 19,
1239 ACPI_WDAT_GET_STATUS = 32,
1240 ACPI_WDAT_SET_STATUS = 33,
1241 ACPI_WDAT_ACTION_RESERVED = 34 /* 34 and greater are reserved */
1242};
1243
1244/* Values for Instruction field above */
1245
1246enum acpi_wdat_instructions {
1247 ACPI_WDAT_READ_VALUE = 0,
1248 ACPI_WDAT_READ_COUNTDOWN = 1,
1249 ACPI_WDAT_WRITE_VALUE = 2,
1250 ACPI_WDAT_WRITE_COUNTDOWN = 3,
1251 ACPI_WDAT_INSTRUCTION_RESERVED = 4, /* 4 and greater are reserved */
1252 ACPI_WDAT_PRESERVE_REGISTER = 0x80 /* Except for this value */
1253};
1254
1255/*******************************************************************************
1256 *
700 * WDRT - Watchdog Resource Table 1257 * WDRT - Watchdog Resource Table
701 * 1258 *
702 ******************************************************************************/ 1259 ******************************************************************************/
diff --git a/include/acpi/actypes.h b/include/acpi/actypes.h
index e73a38939120..dfea2d440488 100644
--- a/include/acpi/actypes.h
+++ b/include/acpi/actypes.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -323,27 +323,11 @@ struct uint32_struct {
323#define acpi_semaphore void * 323#define acpi_semaphore void *
324 324
325/* 325/*
326 * Acpi integer width. In ACPI version 1, integers are 326 * Acpi integer width. In ACPI version 1, integers are 32 bits. In ACPI
327 * 32 bits. In ACPI version 2, integers are 64 bits. 327 * version 2, integers are 64 bits. Note that this pertains to the ACPI integer
328 * Note that this pertains to the ACPI integer type only, not 328 * type only, not other integers used in the implementation of the ACPI CA
329 * other integers used in the implementation of the ACPI CA
330 * subsystem. 329 * subsystem.
331 */ 330 */
332#ifdef ACPI_NO_INTEGER64_SUPPORT
333
334/* 32-bit integers only, no 64-bit support */
335
336typedef u32 acpi_integer;
337#define ACPI_INTEGER_MAX ACPI_UINT32_MAX
338#define ACPI_INTEGER_BIT_SIZE 32
339#define ACPI_MAX_DECIMAL_DIGITS 10 /* 2^32 = 4,294,967,296 */
340
341#define ACPI_USE_NATIVE_DIVIDE /* Use compiler native 32-bit divide */
342
343#else
344
345/* 64-bit integers */
346
347typedef unsigned long long acpi_integer; 331typedef unsigned long long acpi_integer;
348#define ACPI_INTEGER_MAX ACPI_UINT64_MAX 332#define ACPI_INTEGER_MAX ACPI_UINT64_MAX
349#define ACPI_INTEGER_BIT_SIZE 64 333#define ACPI_INTEGER_BIT_SIZE 64
@@ -352,7 +336,6 @@ typedef unsigned long long acpi_integer;
352#if ACPI_MACHINE_WIDTH == 64 336#if ACPI_MACHINE_WIDTH == 64
353#define ACPI_USE_NATIVE_DIVIDE /* Use compiler native 64-bit divide */ 337#define ACPI_USE_NATIVE_DIVIDE /* Use compiler native 64-bit divide */
354#endif 338#endif
355#endif
356 339
357#define ACPI_MAX64_DECIMAL_DIGITS 20 340#define ACPI_MAX64_DECIMAL_DIGITS 20
358#define ACPI_MAX32_DECIMAL_DIGITS 10 341#define ACPI_MAX32_DECIMAL_DIGITS 10
@@ -419,14 +402,20 @@ typedef unsigned long long acpi_integer;
419/* 402/*
420 * Standard notify values 403 * Standard notify values
421 */ 404 */
422#define ACPI_NOTIFY_BUS_CHECK (u8) 0 405#define ACPI_NOTIFY_BUS_CHECK (u8) 0x00
423#define ACPI_NOTIFY_DEVICE_CHECK (u8) 1 406#define ACPI_NOTIFY_DEVICE_CHECK (u8) 0x01
424#define ACPI_NOTIFY_DEVICE_WAKE (u8) 2 407#define ACPI_NOTIFY_DEVICE_WAKE (u8) 0x02
425#define ACPI_NOTIFY_EJECT_REQUEST (u8) 3 408#define ACPI_NOTIFY_EJECT_REQUEST (u8) 0x03
426#define ACPI_NOTIFY_DEVICE_CHECK_LIGHT (u8) 4 409#define ACPI_NOTIFY_DEVICE_CHECK_LIGHT (u8) 0x04
427#define ACPI_NOTIFY_FREQUENCY_MISMATCH (u8) 5 410#define ACPI_NOTIFY_FREQUENCY_MISMATCH (u8) 0x05
428#define ACPI_NOTIFY_BUS_MODE_MISMATCH (u8) 6 411#define ACPI_NOTIFY_BUS_MODE_MISMATCH (u8) 0x06
429#define ACPI_NOTIFY_POWER_FAULT (u8) 7 412#define ACPI_NOTIFY_POWER_FAULT (u8) 0x07
413#define ACPI_NOTIFY_CAPABILITIES_CHECK (u8) 0x08
414#define ACPI_NOTIFY_DEVICE_PLD_CHECK (u8) 0x09
415#define ACPI_NOTIFY_RESERVED (u8) 0x0A
416#define ACPI_NOTIFY_LOCALITY_UPDATE (u8) 0x0B
417
418#define ACPI_NOTIFY_MAX 0x0B
430 419
431/* 420/*
432 * Types associated with ACPI names and objects. The first group of 421 * Types associated with ACPI names and objects. The first group of
@@ -494,6 +483,8 @@ typedef u32 acpi_object_type;
494#define ACPI_TYPE_INVALID 0x1E 483#define ACPI_TYPE_INVALID 0x1E
495#define ACPI_TYPE_NOT_FOUND 0xFF 484#define ACPI_TYPE_NOT_FOUND 0xFF
496 485
486#define ACPI_NUM_NS_TYPES (ACPI_TYPE_INVALID + 1)
487
497/* 488/*
498 * All I/O 489 * All I/O
499 */ 490 */
@@ -599,7 +590,7 @@ typedef u32 acpi_event_status;
599 590
600#define ACPI_SYSTEM_NOTIFY 0x1 591#define ACPI_SYSTEM_NOTIFY 0x1
601#define ACPI_DEVICE_NOTIFY 0x2 592#define ACPI_DEVICE_NOTIFY 0x2
602#define ACPI_ALL_NOTIFY 0x3 593#define ACPI_ALL_NOTIFY (ACPI_SYSTEM_NOTIFY | ACPI_DEVICE_NOTIFY)
603#define ACPI_MAX_NOTIFY_HANDLER_TYPE 0x3 594#define ACPI_MAX_NOTIFY_HANDLER_TYPE 0x3
604 595
605#define ACPI_MAX_SYS_NOTIFY 0x7f 596#define ACPI_MAX_SYS_NOTIFY 0x7f
@@ -654,46 +645,51 @@ typedef u8 acpi_adr_space_type;
654/* 645/*
655 * External ACPI object definition 646 * External ACPI object definition
656 */ 647 */
648
649/*
650 * Note: Type == ACPI_TYPE_ANY (0) is used to indicate a NULL package element
651 * or an unresolved named reference.
652 */
657union acpi_object { 653union acpi_object {
658 acpi_object_type type; /* See definition of acpi_ns_type for values */ 654 acpi_object_type type; /* See definition of acpi_ns_type for values */
659 struct { 655 struct {
660 acpi_object_type type; 656 acpi_object_type type; /* ACPI_TYPE_INTEGER */
661 acpi_integer value; /* The actual number */ 657 acpi_integer value; /* The actual number */
662 } integer; 658 } integer;
663 659
664 struct { 660 struct {
665 acpi_object_type type; 661 acpi_object_type type; /* ACPI_TYPE_STRING */
666 u32 length; /* # of bytes in string, excluding trailing null */ 662 u32 length; /* # of bytes in string, excluding trailing null */
667 char *pointer; /* points to the string value */ 663 char *pointer; /* points to the string value */
668 } string; 664 } string;
669 665
670 struct { 666 struct {
671 acpi_object_type type; 667 acpi_object_type type; /* ACPI_TYPE_BUFFER */
672 u32 length; /* # of bytes in buffer */ 668 u32 length; /* # of bytes in buffer */
673 u8 *pointer; /* points to the buffer */ 669 u8 *pointer; /* points to the buffer */
674 } buffer; 670 } buffer;
675 671
676 struct { 672 struct {
677 acpi_object_type type; 673 acpi_object_type type; /* ACPI_TYPE_PACKAGE */
678 u32 fill1;
679 acpi_handle handle; /* object reference */
680 } reference;
681
682 struct {
683 acpi_object_type type;
684 u32 count; /* # of elements in package */ 674 u32 count; /* # of elements in package */
685 union acpi_object *elements; /* Pointer to an array of ACPI_OBJECTs */ 675 union acpi_object *elements; /* Pointer to an array of ACPI_OBJECTs */
686 } package; 676 } package;
687 677
688 struct { 678 struct {
689 acpi_object_type type; 679 acpi_object_type type; /* ACPI_TYPE_LOCAL_REFERENCE */
680 acpi_object_type actual_type; /* Type associated with the Handle */
681 acpi_handle handle; /* object reference */
682 } reference;
683
684 struct {
685 acpi_object_type type; /* ACPI_TYPE_PROCESSOR */
690 u32 proc_id; 686 u32 proc_id;
691 acpi_io_address pblk_address; 687 acpi_io_address pblk_address;
692 u32 pblk_length; 688 u32 pblk_length;
693 } processor; 689 } processor;
694 690
695 struct { 691 struct {
696 acpi_object_type type; 692 acpi_object_type type; /* ACPI_TYPE_POWER */
697 u32 system_level; 693 u32 system_level;
698 u32 resource_order; 694 u32 resource_order;
699 } power_resource; 695 } power_resource;
@@ -747,6 +743,12 @@ struct acpi_system_info {
747 u32 debug_layer; 743 u32 debug_layer;
748}; 744};
749 745
746/* Table Event Types */
747
748#define ACPI_TABLE_EVENT_LOAD 0x0
749#define ACPI_TABLE_EVENT_UNLOAD 0x1
750#define ACPI_NUM_TABLE_EVENTS 2
751
750/* 752/*
751 * Types specific to the OS service interfaces 753 * Types specific to the OS service interfaces
752 */ 754 */
@@ -776,6 +778,11 @@ acpi_status(*acpi_exception_handler) (acpi_status aml_status,
776 u16 opcode, 778 u16 opcode,
777 u32 aml_offset, void *context); 779 u32 aml_offset, void *context);
778 780
781/* Table Event handler (Load, load_table etc) and types */
782
783typedef
784acpi_status(*acpi_tbl_handler) (u32 event, void *table, void *context);
785
779/* Address Spaces (For Operation Regions) */ 786/* Address Spaces (For Operation Regions) */
780 787
781typedef 788typedef
@@ -990,6 +997,7 @@ struct acpi_vendor_uuid {
990 * Structures used to describe device resources 997 * Structures used to describe device resources
991 */ 998 */
992struct acpi_resource_irq { 999struct acpi_resource_irq {
1000 u8 descriptor_length;
993 u8 triggering; 1001 u8 triggering;
994 u8 polarity; 1002 u8 polarity;
995 u8 sharable; 1003 u8 sharable;
@@ -1006,6 +1014,7 @@ struct acpi_resource_dma {
1006}; 1014};
1007 1015
1008struct acpi_resource_start_dependent { 1016struct acpi_resource_start_dependent {
1017 u8 descriptor_length;
1009 u8 compatibility_priority; 1018 u8 compatibility_priority;
1010 u8 performance_robustness; 1019 u8 performance_robustness;
1011}; 1020};
diff --git a/include/acpi/acutils.h b/include/acpi/acutils.h
index a2918547c73f..b42cadf07302 100644
--- a/include/acpi/acutils.h
+++ b/include/acpi/acutils.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
@@ -116,6 +116,8 @@ void acpi_ut_init_globals(void);
116 116
117char *acpi_ut_get_mutex_name(u32 mutex_id); 117char *acpi_ut_get_mutex_name(u32 mutex_id);
118 118
119const char *acpi_ut_get_notify_name(u32 notify_value);
120
119#endif 121#endif
120 122
121char *acpi_ut_get_type_name(acpi_object_type type); 123char *acpi_ut_get_type_name(acpi_object_type type);
diff --git a/include/acpi/amlcode.h b/include/acpi/amlcode.h
index da53a4ef287a..ff851c5df698 100644
--- a/include/acpi/amlcode.h
+++ b/include/acpi/amlcode.h
@@ -7,7 +7,7 @@
7 *****************************************************************************/ 7 *****************************************************************************/
8 8
9/* 9/*
10 * Copyright (C) 2000 - 2007, R. Byron Moore 10 * Copyright (C) 2000 - 2008, Intel Corp.
11 * All rights reserved. 11 * All rights reserved.
12 * 12 *
13 * Redistribution and use in source and binary forms, with or without 13 * Redistribution and use in source and binary forms, with or without
diff --git a/include/acpi/amlresrc.h b/include/acpi/amlresrc.h
index f7d541239da4..7b070e42b7c5 100644
--- a/include/acpi/amlresrc.h
+++ b/include/acpi/amlresrc.h
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
diff --git a/include/acpi/platform/acenv.h b/include/acpi/platform/acenv.h
index c785485e62a6..fcd2572e428c 100644
--- a/include/acpi/platform/acenv.h
+++ b/include/acpi/platform/acenv.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/include/acpi/platform/acgcc.h b/include/acpi/platform/acgcc.h
index 3bb50494a38a..8996dba90cd9 100644
--- a/include/acpi/platform/acgcc.h
+++ b/include/acpi/platform/acgcc.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/include/acpi/platform/aclinux.h b/include/acpi/platform/aclinux.h
index 6ed15a0978eb..9af464598682 100644
--- a/include/acpi/platform/aclinux.h
+++ b/include/acpi/platform/aclinux.h
@@ -5,7 +5,7 @@
5 *****************************************************************************/ 5 *****************************************************************************/
6 6
7/* 7/*
8 * Copyright (C) 2000 - 2007, R. Byron Moore 8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
diff --git a/include/asm-alpha/types.h b/include/asm-alpha/types.h
index f5716139ec89..c1541353ccef 100644
--- a/include/asm-alpha/types.h
+++ b/include/asm-alpha/types.h
@@ -8,28 +8,12 @@
8 * not a major issue. However, for interoperability, libraries still 8 * not a major issue. However, for interoperability, libraries still
9 * need to be careful to avoid a name clashes. 9 * need to be careful to avoid a name clashes.
10 */ 10 */
11#include <asm-generic/int-l64.h>
11 12
12#ifndef __ASSEMBLY__ 13#ifndef __ASSEMBLY__
13 14
14typedef unsigned int umode_t; 15typedef unsigned int umode_t;
15 16
16/*
17 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
18 * header files exported to user space
19 */
20
21typedef __signed__ char __s8;
22typedef unsigned char __u8;
23
24typedef __signed__ short __s16;
25typedef unsigned short __u16;
26
27typedef __signed__ int __s32;
28typedef unsigned int __u32;
29
30typedef __signed__ long __s64;
31typedef unsigned long __u64;
32
33#endif /* __ASSEMBLY__ */ 17#endif /* __ASSEMBLY__ */
34 18
35/* 19/*
@@ -41,18 +25,6 @@ typedef unsigned long __u64;
41 25
42#ifndef __ASSEMBLY__ 26#ifndef __ASSEMBLY__
43 27
44typedef signed char s8;
45typedef unsigned char u8;
46
47typedef signed short s16;
48typedef unsigned short u16;
49
50typedef signed int s32;
51typedef unsigned int u32;
52
53typedef signed long s64;
54typedef unsigned long u64;
55
56typedef u64 dma_addr_t; 28typedef u64 dma_addr_t;
57typedef u64 dma64_addr_t; 29typedef u64 dma64_addr_t;
58 30
diff --git a/include/asm-arm/arch-pxa/pxa-regs.h b/include/asm-arm/arch-pxa/pxa-regs.h
index a322012f16ac..4b2ea1e95c57 100644
--- a/include/asm-arm/arch-pxa/pxa-regs.h
+++ b/include/asm-arm/arch-pxa/pxa-regs.h
@@ -1406,202 +1406,6 @@
1406#define OSCC_OON (1 << 1) /* 32.768kHz OON (write-once only bit) */ 1406#define OSCC_OON (1 << 1) /* 32.768kHz OON (write-once only bit) */
1407#define OSCC_OOK (1 << 0) /* 32.768kHz OOK (read-only bit) */ 1407#define OSCC_OOK (1 << 0) /* 32.768kHz OOK (read-only bit) */
1408 1408
1409
1410/*
1411 * LCD
1412 */
1413
1414#define LCCR0 __REG(0x44000000) /* LCD Controller Control Register 0 */
1415#define LCCR1 __REG(0x44000004) /* LCD Controller Control Register 1 */
1416#define LCCR2 __REG(0x44000008) /* LCD Controller Control Register 2 */
1417#define LCCR3 __REG(0x4400000C) /* LCD Controller Control Register 3 */
1418#define LCCR4 __REG(0x44000010) /* LCD Controller Control Register 3 */
1419#define DFBR0 __REG(0x44000020) /* DMA Channel 0 Frame Branch Register */
1420#define DFBR1 __REG(0x44000024) /* DMA Channel 1 Frame Branch Register */
1421#define LCSR __REG(0x44000038) /* LCD Controller Status Register */
1422#define LIIDR __REG(0x4400003C) /* LCD Controller Interrupt ID Register */
1423#define TMEDRGBR __REG(0x44000040) /* TMED RGB Seed Register */
1424#define TMEDCR __REG(0x44000044) /* TMED Control Register */
1425
1426#define LCCR3_1BPP (0 << 24)
1427#define LCCR3_2BPP (1 << 24)
1428#define LCCR3_4BPP (2 << 24)
1429#define LCCR3_8BPP (3 << 24)
1430#define LCCR3_16BPP (4 << 24)
1431
1432#define LCCR3_PDFOR_0 (0 << 30)
1433#define LCCR3_PDFOR_1 (1 << 30)
1434#define LCCR3_PDFOR_2 (2 << 30)
1435#define LCCR3_PDFOR_3 (3 << 30)
1436
1437#define LCCR4_PAL_FOR_0 (0 << 15)
1438#define LCCR4_PAL_FOR_1 (1 << 15)
1439#define LCCR4_PAL_FOR_2 (2 << 15)
1440#define LCCR4_PAL_FOR_MASK (3 << 15)
1441
1442#define FDADR0 __REG(0x44000200) /* DMA Channel 0 Frame Descriptor Address Register */
1443#define FSADR0 __REG(0x44000204) /* DMA Channel 0 Frame Source Address Register */
1444#define FIDR0 __REG(0x44000208) /* DMA Channel 0 Frame ID Register */
1445#define LDCMD0 __REG(0x4400020C) /* DMA Channel 0 Command Register */
1446#define FDADR1 __REG(0x44000210) /* DMA Channel 1 Frame Descriptor Address Register */
1447#define FSADR1 __REG(0x44000214) /* DMA Channel 1 Frame Source Address Register */
1448#define FIDR1 __REG(0x44000218) /* DMA Channel 1 Frame ID Register */
1449#define LDCMD1 __REG(0x4400021C) /* DMA Channel 1 Command Register */
1450
1451#define LCCR0_ENB (1 << 0) /* LCD Controller enable */
1452#define LCCR0_CMS (1 << 1) /* Color/Monochrome Display Select */
1453#define LCCR0_Color (LCCR0_CMS*0) /* Color display */
1454#define LCCR0_Mono (LCCR0_CMS*1) /* Monochrome display */
1455#define LCCR0_SDS (1 << 2) /* Single/Dual Panel Display */
1456 /* Select */
1457#define LCCR0_Sngl (LCCR0_SDS*0) /* Single panel display */
1458#define LCCR0_Dual (LCCR0_SDS*1) /* Dual panel display */
1459
1460#define LCCR0_LDM (1 << 3) /* LCD Disable Done Mask */
1461#define LCCR0_SFM (1 << 4) /* Start of frame mask */
1462#define LCCR0_IUM (1 << 5) /* Input FIFO underrun mask */
1463#define LCCR0_EFM (1 << 6) /* End of Frame mask */
1464#define LCCR0_PAS (1 << 7) /* Passive/Active display Select */
1465#define LCCR0_Pas (LCCR0_PAS*0) /* Passive display (STN) */
1466#define LCCR0_Act (LCCR0_PAS*1) /* Active display (TFT) */
1467#define LCCR0_DPD (1 << 9) /* Double Pixel Data (monochrome */
1468 /* display mode) */
1469#define LCCR0_4PixMono (LCCR0_DPD*0) /* 4-Pixel/clock Monochrome */
1470 /* display */
1471#define LCCR0_8PixMono (LCCR0_DPD*1) /* 8-Pixel/clock Monochrome */
1472 /* display */
1473#define LCCR0_DIS (1 << 10) /* LCD Disable */
1474#define LCCR0_QDM (1 << 11) /* LCD Quick Disable mask */
1475#define LCCR0_PDD (0xff << 12) /* Palette DMA request delay */
1476#define LCCR0_PDD_S 12
1477#define LCCR0_BM (1 << 20) /* Branch mask */
1478#define LCCR0_OUM (1 << 21) /* Output FIFO underrun mask */
1479#define LCCR0_LCDT (1 << 22) /* LCD panel type */
1480#define LCCR0_RDSTM (1 << 23) /* Read status interrupt mask */
1481#define LCCR0_CMDIM (1 << 24) /* Command interrupt mask */
1482#define LCCR0_OUC (1 << 25) /* Overlay Underlay control bit */
1483#define LCCR0_LDDALT (1 << 26) /* LDD alternate mapping control */
1484
1485#define LCCR1_PPL Fld (10, 0) /* Pixels Per Line - 1 */
1486#define LCCR1_DisWdth(Pixel) /* Display Width [1..800 pix.] */ \
1487 (((Pixel) - 1) << FShft (LCCR1_PPL))
1488
1489#define LCCR1_HSW Fld (6, 10) /* Horizontal Synchronization */
1490#define LCCR1_HorSnchWdth(Tpix) /* Horizontal Synchronization */ \
1491 /* pulse Width [1..64 Tpix] */ \
1492 (((Tpix) - 1) << FShft (LCCR1_HSW))
1493
1494#define LCCR1_ELW Fld (8, 16) /* End-of-Line pixel clock Wait */
1495 /* count - 1 [Tpix] */
1496#define LCCR1_EndLnDel(Tpix) /* End-of-Line Delay */ \
1497 /* [1..256 Tpix] */ \
1498 (((Tpix) - 1) << FShft (LCCR1_ELW))
1499
1500#define LCCR1_BLW Fld (8, 24) /* Beginning-of-Line pixel clock */
1501 /* Wait count - 1 [Tpix] */
1502#define LCCR1_BegLnDel(Tpix) /* Beginning-of-Line Delay */ \
1503 /* [1..256 Tpix] */ \
1504 (((Tpix) - 1) << FShft (LCCR1_BLW))
1505
1506
1507#define LCCR2_LPP Fld (10, 0) /* Line Per Panel - 1 */
1508#define LCCR2_DisHght(Line) /* Display Height [1..1024 lines] */ \
1509 (((Line) - 1) << FShft (LCCR2_LPP))
1510
1511#define LCCR2_VSW Fld (6, 10) /* Vertical Synchronization pulse */
1512 /* Width - 1 [Tln] (L_FCLK) */
1513#define LCCR2_VrtSnchWdth(Tln) /* Vertical Synchronization pulse */ \
1514 /* Width [1..64 Tln] */ \
1515 (((Tln) - 1) << FShft (LCCR2_VSW))
1516
1517#define LCCR2_EFW Fld (8, 16) /* End-of-Frame line clock Wait */
1518 /* count [Tln] */
1519#define LCCR2_EndFrmDel(Tln) /* End-of-Frame Delay */ \
1520 /* [0..255 Tln] */ \
1521 ((Tln) << FShft (LCCR2_EFW))
1522
1523#define LCCR2_BFW Fld (8, 24) /* Beginning-of-Frame line clock */
1524 /* Wait count [Tln] */
1525#define LCCR2_BegFrmDel(Tln) /* Beginning-of-Frame Delay */ \
1526 /* [0..255 Tln] */ \
1527 ((Tln) << FShft (LCCR2_BFW))
1528
1529#if 0
1530#define LCCR3_PCD (0xff) /* Pixel clock divisor */
1531#define LCCR3_ACB (0xff << 8) /* AC Bias pin frequency */
1532#define LCCR3_ACB_S 8
1533#endif
1534
1535#define LCCR3_API (0xf << 16) /* AC Bias pin trasitions per interrupt */
1536#define LCCR3_API_S 16
1537#define LCCR3_VSP (1 << 20) /* vertical sync polarity */
1538#define LCCR3_HSP (1 << 21) /* horizontal sync polarity */
1539#define LCCR3_PCP (1 << 22) /* Pixel Clock Polarity (L_PCLK) */
1540#define LCCR3_PixRsEdg (LCCR3_PCP*0) /* Pixel clock Rising-Edge */
1541#define LCCR3_PixFlEdg (LCCR3_PCP*1) /* Pixel clock Falling-Edge */
1542
1543#define LCCR3_OEP (1 << 23) /* Output Enable Polarity (L_BIAS, */
1544 /* active display mode) */
1545#define LCCR3_OutEnH (LCCR3_OEP*0) /* Output Enable active High */
1546#define LCCR3_OutEnL (LCCR3_OEP*1) /* Output Enable active Low */
1547
1548#if 0
1549#define LCCR3_BPP (7 << 24) /* bits per pixel */
1550#define LCCR3_BPP_S 24
1551#endif
1552#define LCCR3_DPC (1 << 27) /* double pixel clock mode */
1553
1554
1555#define LCCR3_PCD Fld (8, 0) /* Pixel Clock Divisor */
1556#define LCCR3_PixClkDiv(Div) /* Pixel Clock Divisor */ \
1557 (((Div) << FShft (LCCR3_PCD)))
1558
1559
1560#define LCCR3_BPP Fld (3, 24) /* Bit Per Pixel */
1561#define LCCR3_Bpp(Bpp) /* Bit Per Pixel */ \
1562 (((Bpp) << FShft (LCCR3_BPP)))
1563
1564#define LCCR3_ACB Fld (8, 8) /* AC Bias */
1565#define LCCR3_Acb(Acb) /* BAC Bias */ \
1566 (((Acb) << FShft (LCCR3_ACB)))
1567
1568#define LCCR3_HorSnchH (LCCR3_HSP*0) /* Horizontal Synchronization */
1569 /* pulse active High */
1570#define LCCR3_HorSnchL (LCCR3_HSP*1) /* Horizontal Synchronization */
1571
1572#define LCCR3_VrtSnchH (LCCR3_VSP*0) /* Vertical Synchronization pulse */
1573 /* active High */
1574#define LCCR3_VrtSnchL (LCCR3_VSP*1) /* Vertical Synchronization pulse */
1575 /* active Low */
1576
1577#define LCSR_LDD (1 << 0) /* LCD Disable Done */
1578#define LCSR_SOF (1 << 1) /* Start of frame */
1579#define LCSR_BER (1 << 2) /* Bus error */
1580#define LCSR_ABC (1 << 3) /* AC Bias count */
1581#define LCSR_IUL (1 << 4) /* input FIFO underrun Lower panel */
1582#define LCSR_IUU (1 << 5) /* input FIFO underrun Upper panel */
1583#define LCSR_OU (1 << 6) /* output FIFO underrun */
1584#define LCSR_QD (1 << 7) /* quick disable */
1585#define LCSR_EOF (1 << 8) /* end of frame */
1586#define LCSR_BS (1 << 9) /* branch status */
1587#define LCSR_SINT (1 << 10) /* subsequent interrupt */
1588
1589#define LDCMD_PAL (1 << 26) /* instructs DMA to load palette buffer */
1590
1591#define LCSR_LDD (1 << 0) /* LCD Disable Done */
1592#define LCSR_SOF (1 << 1) /* Start of frame */
1593#define LCSR_BER (1 << 2) /* Bus error */
1594#define LCSR_ABC (1 << 3) /* AC Bias count */
1595#define LCSR_IUL (1 << 4) /* input FIFO underrun Lower panel */
1596#define LCSR_IUU (1 << 5) /* input FIFO underrun Upper panel */
1597#define LCSR_OU (1 << 6) /* output FIFO underrun */
1598#define LCSR_QD (1 << 7) /* quick disable */
1599#define LCSR_EOF (1 << 8) /* end of frame */
1600#define LCSR_BS (1 << 9) /* branch status */
1601#define LCSR_SINT (1 << 10) /* subsequent interrupt */
1602
1603#define LDCMD_PAL (1 << 26) /* instructs DMA to load palette buffer */
1604
1605#ifdef CONFIG_PXA27x 1409#ifdef CONFIG_PXA27x
1606 1410
1607/* Camera Interface */ 1411/* Camera Interface */
diff --git a/include/asm-arm/arch-pxa/pxafb.h b/include/asm-arm/arch-pxa/pxafb.h
index ea2336aa70e4..bbd22396841a 100644
--- a/include/asm-arm/arch-pxa/pxafb.h
+++ b/include/asm-arm/arch-pxa/pxafb.h
@@ -13,6 +13,50 @@
13 */ 13 */
14 14
15#include <linux/fb.h> 15#include <linux/fb.h>
16#include <asm/arch/regs-lcd.h>
17
18/*
19 * Supported LCD connections
20 *
21 * bits 0 - 3: for LCD panel type:
22 *
23 * STN - for passive matrix
24 * DSTN - for dual scan passive matrix
25 * TFT - for active matrix
26 *
27 * bits 4 - 9 : for bus width
28 * bits 10-17 : for AC Bias Pin Frequency
29 * bit 18 : for output enable polarity
30 * bit 19 : for pixel clock edge
31 */
32#define LCD_CONN_TYPE(_x) ((_x) & 0x0f)
33#define LCD_CONN_WIDTH(_x) (((_x) >> 4) & 0x1f)
34
35#define LCD_TYPE_UNKNOWN 0
36#define LCD_TYPE_MONO_STN 1
37#define LCD_TYPE_MONO_DSTN 2
38#define LCD_TYPE_COLOR_STN 3
39#define LCD_TYPE_COLOR_DSTN 4
40#define LCD_TYPE_COLOR_TFT 5
41#define LCD_TYPE_SMART_PANEL 6
42#define LCD_TYPE_MAX 7
43
44#define LCD_MONO_STN_4BPP ((4 << 4) | LCD_TYPE_MONO_STN)
45#define LCD_MONO_STN_8BPP ((8 << 4) | LCD_TYPE_MONO_STN)
46#define LCD_MONO_DSTN_8BPP ((8 << 4) | LCD_TYPE_MONO_DSTN)
47#define LCD_COLOR_STN_8BPP ((8 << 4) | LCD_TYPE_COLOR_STN)
48#define LCD_COLOR_DSTN_16BPP ((16 << 4) | LCD_TYPE_COLOR_DSTN)
49#define LCD_COLOR_TFT_16BPP ((16 << 4) | LCD_TYPE_COLOR_TFT)
50#define LCD_COLOR_TFT_18BPP ((18 << 4) | LCD_TYPE_COLOR_TFT)
51#define LCD_SMART_PANEL_8BPP ((8 << 4) | LCD_TYPE_SMART_PANEL)
52#define LCD_SMART_PANEL_16BPP ((16 << 4) | LCD_TYPE_SMART_PANEL)
53#define LCD_SMART_PANEL_18BPP ((18 << 4) | LCD_TYPE_SMART_PANEL)
54
55#define LCD_AC_BIAS_FREQ(x) (((x) & 0xff) << 10)
56#define LCD_BIAS_ACTIVE_HIGH (0 << 17)
57#define LCD_BIAS_ACTIVE_LOW (1 << 17)
58#define LCD_PCLK_EDGE_RISE (0 << 18)
59#define LCD_PCLK_EDGE_FALL (1 << 18)
16 60
17/* 61/*
18 * This structure describes the machine which we are running on. 62 * This structure describes the machine which we are running on.
@@ -26,6 +70,10 @@ struct pxafb_mode_info {
26 u_short yres; 70 u_short yres;
27 71
28 u_char bpp; 72 u_char bpp;
73 u_int cmap_greyscale:1,
74 unused:31;
75
76 /* Parallel Mode Timing */
29 u_char hsync_len; 77 u_char hsync_len;
30 u_char left_margin; 78 u_char left_margin;
31 u_char right_margin; 79 u_char right_margin;
@@ -35,14 +83,28 @@ struct pxafb_mode_info {
35 u_char lower_margin; 83 u_char lower_margin;
36 u_char sync; 84 u_char sync;
37 85
38 u_int cmap_greyscale:1, 86 /* Smart Panel Mode Timing - see PXA27x DM 7.4.15.0.3 for details
39 unused:31; 87 * Note:
88 * 1. all parameters in nanosecond (ns)
89 * 2. a0cs{rd,wr}_set_hld are controlled by the same register bits
90 * in pxa27x and pxa3xx, initialize them to the same value or
91 * the larger one will be used
92 * 3. same to {rd,wr}_pulse_width
93 */
94 unsigned a0csrd_set_hld; /* A0 and CS Setup/Hold Time before/after L_FCLK_RD */
95 unsigned a0cswr_set_hld; /* A0 and CS Setup/Hold Time before/after L_PCLK_WR */
96 unsigned wr_pulse_width; /* L_PCLK_WR pulse width */
97 unsigned rd_pulse_width; /* L_FCLK_RD pulse width */
98 unsigned cmd_inh_time; /* Command Inhibit time between two writes */
99 unsigned op_hold_time; /* Output Hold time from L_FCLK_RD negation */
40}; 100};
41 101
42struct pxafb_mach_info { 102struct pxafb_mach_info {
43 struct pxafb_mode_info *modes; 103 struct pxafb_mode_info *modes;
44 unsigned int num_modes; 104 unsigned int num_modes;
45 105
106 unsigned int lcd_conn;
107
46 u_int fixed_modes:1, 108 u_int fixed_modes:1,
47 cmap_inverse:1, 109 cmap_inverse:1,
48 cmap_static:1, 110 cmap_static:1,
@@ -78,8 +140,11 @@ struct pxafb_mach_info {
78 u_int lccr4; 140 u_int lccr4;
79 void (*pxafb_backlight_power)(int); 141 void (*pxafb_backlight_power)(int);
80 void (*pxafb_lcd_power)(int, struct fb_var_screeninfo *); 142 void (*pxafb_lcd_power)(int, struct fb_var_screeninfo *);
81 143 void (*smart_update)(struct fb_info *);
82}; 144};
83void set_pxa_fb_info(struct pxafb_mach_info *hard_pxa_fb_info); 145void set_pxa_fb_info(struct pxafb_mach_info *hard_pxa_fb_info);
84void set_pxa_fb_parent(struct device *parent_dev); 146void set_pxa_fb_parent(struct device *parent_dev);
85unsigned long pxafb_get_hsync_time(struct device *dev); 147unsigned long pxafb_get_hsync_time(struct device *dev);
148
149extern int pxafb_smart_queue(struct fb_info *info, uint16_t *cmds, int);
150extern int pxafb_smart_flush(struct fb_info *info);
diff --git a/include/asm-arm/arch-pxa/regs-lcd.h b/include/asm-arm/arch-pxa/regs-lcd.h
new file mode 100644
index 000000000000..f762493f5141
--- /dev/null
+++ b/include/asm-arm/arch-pxa/regs-lcd.h
@@ -0,0 +1,171 @@
1#ifndef __ASM_ARCH_REGS_LCD_H
2#define __ASM_ARCH_REGS_LCD_H
3/*
4 * LCD Controller Registers and Bits Definitions
5 */
6#define LCCR0 (0x000) /* LCD Controller Control Register 0 */
7#define LCCR1 (0x004) /* LCD Controller Control Register 1 */
8#define LCCR2 (0x008) /* LCD Controller Control Register 2 */
9#define LCCR3 (0x00C) /* LCD Controller Control Register 3 */
10#define LCCR4 (0x010) /* LCD Controller Control Register 4 */
11#define LCCR5 (0x014) /* LCD Controller Control Register 5 */
12#define DFBR0 (0x020) /* DMA Channel 0 Frame Branch Register */
13#define DFBR1 (0x024) /* DMA Channel 1 Frame Branch Register */
14#define LCSR (0x038) /* LCD Controller Status Register */
15#define LIIDR (0x03C) /* LCD Controller Interrupt ID Register */
16#define TMEDRGBR (0x040) /* TMED RGB Seed Register */
17#define TMEDCR (0x044) /* TMED Control Register */
18
19#define CMDCR (0x100) /* Command Control Register */
20#define PRSR (0x104) /* Panel Read Status Register */
21
22#define LCCR3_1BPP (0 << 24)
23#define LCCR3_2BPP (1 << 24)
24#define LCCR3_4BPP (2 << 24)
25#define LCCR3_8BPP (3 << 24)
26#define LCCR3_16BPP (4 << 24)
27
28#define LCCR3_PDFOR_0 (0 << 30)
29#define LCCR3_PDFOR_1 (1 << 30)
30#define LCCR3_PDFOR_2 (2 << 30)
31#define LCCR3_PDFOR_3 (3 << 30)
32
33#define LCCR4_PAL_FOR_0 (0 << 15)
34#define LCCR4_PAL_FOR_1 (1 << 15)
35#define LCCR4_PAL_FOR_2 (2 << 15)
36#define LCCR4_PAL_FOR_MASK (3 << 15)
37
38#define FDADR0 (0x200) /* DMA Channel 0 Frame Descriptor Address Register */
39#define FSADR0 (0x204) /* DMA Channel 0 Frame Source Address Register */
40#define FIDR0 (0x208) /* DMA Channel 0 Frame ID Register */
41#define LDCMD0 (0x20C) /* DMA Channel 0 Command Register */
42#define FDADR1 (0x210) /* DMA Channel 1 Frame Descriptor Address Register */
43#define FSADR1 (0x214) /* DMA Channel 1 Frame Source Address Register */
44#define FIDR1 (0x218) /* DMA Channel 1 Frame ID Register */
45#define LDCMD1 (0x21C) /* DMA Channel 1 Command Register */
46#define FDADR6 (0x260) /* DMA Channel 6 Frame Descriptor Address Register */
47#define FSADR6 (0x264) /* DMA Channel 6 Frame Source Address Register */
48#define FIDR6 (0x268) /* DMA Channel 6 Frame ID Register */
49
50#define LCCR0_ENB (1 << 0) /* LCD Controller enable */
51#define LCCR0_CMS (1 << 1) /* Color/Monochrome Display Select */
52#define LCCR0_Color (LCCR0_CMS*0) /* Color display */
53#define LCCR0_Mono (LCCR0_CMS*1) /* Monochrome display */
54#define LCCR0_SDS (1 << 2) /* Single/Dual Panel Display Select */
55#define LCCR0_Sngl (LCCR0_SDS*0) /* Single panel display */
56#define LCCR0_Dual (LCCR0_SDS*1) /* Dual panel display */
57
58#define LCCR0_LDM (1 << 3) /* LCD Disable Done Mask */
59#define LCCR0_SFM (1 << 4) /* Start of frame mask */
60#define LCCR0_IUM (1 << 5) /* Input FIFO underrun mask */
61#define LCCR0_EFM (1 << 6) /* End of Frame mask */
62#define LCCR0_PAS (1 << 7) /* Passive/Active display Select */
63#define LCCR0_Pas (LCCR0_PAS*0) /* Passive display (STN) */
64#define LCCR0_Act (LCCR0_PAS*1) /* Active display (TFT) */
65#define LCCR0_DPD (1 << 9) /* Double Pixel Data (monochrome) */
66#define LCCR0_4PixMono (LCCR0_DPD*0) /* 4-Pixel/clock Monochrome display */
67#define LCCR0_8PixMono (LCCR0_DPD*1) /* 8-Pixel/clock Monochrome display */
68#define LCCR0_DIS (1 << 10) /* LCD Disable */
69#define LCCR0_QDM (1 << 11) /* LCD Quick Disable mask */
70#define LCCR0_PDD (0xff << 12) /* Palette DMA request delay */
71#define LCCR0_PDD_S 12
72#define LCCR0_BM (1 << 20) /* Branch mask */
73#define LCCR0_OUM (1 << 21) /* Output FIFO underrun mask */
74#define LCCR0_LCDT (1 << 22) /* LCD panel type */
75#define LCCR0_RDSTM (1 << 23) /* Read status interrupt mask */
76#define LCCR0_CMDIM (1 << 24) /* Command interrupt mask */
77#define LCCR0_OUC (1 << 25) /* Overlay Underlay control bit */
78#define LCCR0_LDDALT (1 << 26) /* LDD alternate mapping control */
79
80#define LCCR1_PPL Fld (10, 0) /* Pixels Per Line - 1 */
81#define LCCR1_DisWdth(Pixel) (((Pixel) - 1) << FShft (LCCR1_PPL))
82
83#define LCCR1_HSW Fld (6, 10) /* Horizontal Synchronization */
84#define LCCR1_HorSnchWdth(Tpix) (((Tpix) - 1) << FShft (LCCR1_HSW))
85
86#define LCCR1_ELW Fld (8, 16) /* End-of-Line pixel clock Wait - 1 */
87#define LCCR1_EndLnDel(Tpix) (((Tpix) - 1) << FShft (LCCR1_ELW))
88
89#define LCCR1_BLW Fld (8, 24) /* Beginning-of-Line pixel clock */
90#define LCCR1_BegLnDel(Tpix) (((Tpix) - 1) << FShft (LCCR1_BLW))
91
92#define LCCR2_LPP Fld (10, 0) /* Line Per Panel - 1 */
93#define LCCR2_DisHght(Line) (((Line) - 1) << FShft (LCCR2_LPP))
94
95#define LCCR2_VSW Fld (6, 10) /* Vertical Synchronization pulse - 1 */
96#define LCCR2_VrtSnchWdth(Tln) (((Tln) - 1) << FShft (LCCR2_VSW))
97
98#define LCCR2_EFW Fld (8, 16) /* End-of-Frame line clock Wait */
99#define LCCR2_EndFrmDel(Tln) ((Tln) << FShft (LCCR2_EFW))
100
101#define LCCR2_BFW Fld (8, 24) /* Beginning-of-Frame line clock */
102#define LCCR2_BegFrmDel(Tln) ((Tln) << FShft (LCCR2_BFW))
103
104#define LCCR3_API (0xf << 16) /* AC Bias pin trasitions per interrupt */
105#define LCCR3_API_S 16
106#define LCCR3_VSP (1 << 20) /* vertical sync polarity */
107#define LCCR3_HSP (1 << 21) /* horizontal sync polarity */
108#define LCCR3_PCP (1 << 22) /* Pixel Clock Polarity (L_PCLK) */
109#define LCCR3_PixRsEdg (LCCR3_PCP*0) /* Pixel clock Rising-Edge */
110#define LCCR3_PixFlEdg (LCCR3_PCP*1) /* Pixel clock Falling-Edge */
111
112#define LCCR3_OEP (1 << 23) /* Output Enable Polarity */
113#define LCCR3_OutEnH (LCCR3_OEP*0) /* Output Enable active High */
114#define LCCR3_OutEnL (LCCR3_OEP*1) /* Output Enable active Low */
115
116#define LCCR3_DPC (1 << 27) /* double pixel clock mode */
117#define LCCR3_PCD Fld (8, 0) /* Pixel Clock Divisor */
118#define LCCR3_PixClkDiv(Div) (((Div) << FShft (LCCR3_PCD)))
119
120#define LCCR3_BPP Fld (3, 24) /* Bit Per Pixel */
121#define LCCR3_Bpp(Bpp) (((Bpp) << FShft (LCCR3_BPP)))
122
123#define LCCR3_ACB Fld (8, 8) /* AC Bias */
124#define LCCR3_Acb(Acb) (((Acb) << FShft (LCCR3_ACB)))
125
126#define LCCR3_HorSnchH (LCCR3_HSP*0) /* HSP Active High */
127#define LCCR3_HorSnchL (LCCR3_HSP*1) /* HSP Active Low */
128
129#define LCCR3_VrtSnchH (LCCR3_VSP*0) /* VSP Active High */
130#define LCCR3_VrtSnchL (LCCR3_VSP*1) /* VSP Active Low */
131
132#define LCCR5_IUM(x) (1 << ((x) + 23)) /* input underrun mask */
133#define LCCR5_BSM(x) (1 << ((x) + 15)) /* branch mask */
134#define LCCR5_EOFM(x) (1 << ((x) + 7)) /* end of frame mask */
135#define LCCR5_SOFM(x) (1 << ((x) + 0)) /* start of frame mask */
136
137#define LCSR_LDD (1 << 0) /* LCD Disable Done */
138#define LCSR_SOF (1 << 1) /* Start of frame */
139#define LCSR_BER (1 << 2) /* Bus error */
140#define LCSR_ABC (1 << 3) /* AC Bias count */
141#define LCSR_IUL (1 << 4) /* input FIFO underrun Lower panel */
142#define LCSR_IUU (1 << 5) /* input FIFO underrun Upper panel */
143#define LCSR_OU (1 << 6) /* output FIFO underrun */
144#define LCSR_QD (1 << 7) /* quick disable */
145#define LCSR_EOF (1 << 8) /* end of frame */
146#define LCSR_BS (1 << 9) /* branch status */
147#define LCSR_SINT (1 << 10) /* subsequent interrupt */
148#define LCSR_RD_ST (1 << 11) /* read status */
149#define LCSR_CMD_INT (1 << 12) /* command interrupt */
150
151#define LDCMD_PAL (1 << 26) /* instructs DMA to load palette buffer */
152
153/* smartpanel related */
154#define PRSR_DATA(x) ((x) & 0xff) /* Panel Data */
155#define PRSR_A0 (1 << 8) /* Read Data Source */
156#define PRSR_ST_OK (1 << 9) /* Status OK */
157#define PRSR_CON_NT (1 << 10) /* Continue to Next Command */
158
159#define SMART_CMD_A0 (0x1 << 8)
160#define SMART_CMD_READ_STATUS_REG (0x0 << 9)
161#define SMART_CMD_READ_FRAME_BUFFER ((0x0 << 9) | SMART_CMD_A0)
162#define SMART_CMD_WRITE_COMMAND (0x1 << 9)
163#define SMART_CMD_WRITE_DATA ((0x1 << 9) | SMART_CMD_A0)
164#define SMART_CMD_WRITE_FRAME ((0x2 << 9) | SMART_CMD_A0)
165#define SMART_CMD_WAIT_FOR_VSYNC (0x3 << 9)
166#define SMART_CMD_NOOP (0x4 << 9)
167#define SMART_CMD_INTERRUPT (0x5 << 9)
168
169#define SMART_CMD(x) (SMART_CMD_WRITE_COMMAND | ((x) & 0xff))
170#define SMART_DAT(x) (SMART_CMD_WRITE_DATA | ((x) & 0xff))
171#endif /* __ASM_ARCH_REGS_LCD_H */
diff --git a/include/asm-arm/div64.h b/include/asm-arm/div64.h
index 0b5f881c3d85..5001390be958 100644
--- a/include/asm-arm/div64.h
+++ b/include/asm-arm/div64.h
@@ -224,6 +224,4 @@
224 224
225#endif 225#endif
226 226
227extern uint64_t div64_64(uint64_t dividend, uint64_t divisor);
228
229#endif 227#endif
diff --git a/include/asm-arm/types.h b/include/asm-arm/types.h
index 3141451a9bd6..345df01534a4 100644
--- a/include/asm-arm/types.h
+++ b/include/asm-arm/types.h
@@ -1,29 +1,12 @@
1#ifndef __ASM_ARM_TYPES_H 1#ifndef __ASM_ARM_TYPES_H
2#define __ASM_ARM_TYPES_H 2#define __ASM_ARM_TYPES_H
3 3
4#include <asm-generic/int-ll64.h>
5
4#ifndef __ASSEMBLY__ 6#ifndef __ASSEMBLY__
5 7
6typedef unsigned short umode_t; 8typedef unsigned short umode_t;
7 9
8/*
9 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
10 * header files exported to user space
11 */
12
13typedef __signed__ char __s8;
14typedef unsigned char __u8;
15
16typedef __signed__ short __s16;
17typedef unsigned short __u16;
18
19typedef __signed__ int __s32;
20typedef unsigned int __u32;
21
22#if defined(__GNUC__)
23__extension__ typedef __signed__ long long __s64;
24__extension__ typedef unsigned long long __u64;
25#endif
26
27#endif /* __ASSEMBLY__ */ 10#endif /* __ASSEMBLY__ */
28 11
29/* 12/*
@@ -35,18 +18,6 @@ __extension__ typedef unsigned long long __u64;
35 18
36#ifndef __ASSEMBLY__ 19#ifndef __ASSEMBLY__
37 20
38typedef signed char s8;
39typedef unsigned char u8;
40
41typedef signed short s16;
42typedef unsigned short u16;
43
44typedef signed int s32;
45typedef unsigned int u32;
46
47typedef signed long long s64;
48typedef unsigned long long u64;
49
50/* Dma addresses are 32-bits wide. */ 21/* Dma addresses are 32-bits wide. */
51 22
52typedef u32 dma_addr_t; 23typedef u32 dma_addr_t;
diff --git a/include/asm-avr32/types.h b/include/asm-avr32/types.h
index 8999a3819403..9cefda6f534a 100644
--- a/include/asm-avr32/types.h
+++ b/include/asm-avr32/types.h
@@ -8,28 +8,12 @@
8#ifndef __ASM_AVR32_TYPES_H 8#ifndef __ASM_AVR32_TYPES_H
9#define __ASM_AVR32_TYPES_H 9#define __ASM_AVR32_TYPES_H
10 10
11#include <asm-generic/int-ll64.h>
12
11#ifndef __ASSEMBLY__ 13#ifndef __ASSEMBLY__
12 14
13typedef unsigned short umode_t; 15typedef unsigned short umode_t;
14 16
15/*
16 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
17 * header files exported to user space
18 */
19typedef __signed__ char __s8;
20typedef unsigned char __u8;
21
22typedef __signed__ short __s16;
23typedef unsigned short __u16;
24
25typedef __signed__ int __s32;
26typedef unsigned int __u32;
27
28#if defined(__GNUC__)
29__extension__ typedef __signed__ long long __s64;
30__extension__ typedef unsigned long long __u64;
31#endif
32
33#endif /* __ASSEMBLY__ */ 17#endif /* __ASSEMBLY__ */
34 18
35/* 19/*
@@ -41,18 +25,6 @@ __extension__ typedef unsigned long long __u64;
41 25
42#ifndef __ASSEMBLY__ 26#ifndef __ASSEMBLY__
43 27
44typedef signed char s8;
45typedef unsigned char u8;
46
47typedef signed short s16;
48typedef unsigned short u16;
49
50typedef signed int s32;
51typedef unsigned int u32;
52
53typedef signed long long s64;
54typedef unsigned long long u64;
55
56/* Dma addresses are 32-bits wide. */ 28/* Dma addresses are 32-bits wide. */
57 29
58typedef u32 dma_addr_t; 30typedef u32 dma_addr_t;
diff --git a/include/asm-blackfin/types.h b/include/asm-blackfin/types.h
index 9785a6d531c6..8441cbc2bf9e 100644
--- a/include/asm-blackfin/types.h
+++ b/include/asm-blackfin/types.h
@@ -8,30 +8,12 @@
8 * not a major issue. However, for interoperability, libraries still 8 * not a major issue. However, for interoperability, libraries still
9 * need to be careful to avoid a name clashes. 9 * need to be careful to avoid a name clashes.
10 */ 10 */
11#include <asm-generic/int-ll64.h>
12
11#ifndef __ASSEMBLY__ 13#ifndef __ASSEMBLY__
12 14
13typedef unsigned short umode_t; 15typedef unsigned short umode_t;
14 16
15/*
16 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
17 * header files exported to user space
18 */
19
20typedef __signed__ char __s8;
21typedef unsigned char __u8;
22
23typedef __signed__ short __s16;
24typedef unsigned short __u16;
25
26typedef __signed__ int __s32;
27typedef unsigned int __u32;
28
29/* HK0617 -- Changes to unsigned long temporarily */
30#if defined(__GNUC__)
31__extension__ typedef __signed__ long long __s64;
32__extension__ typedef unsigned long long __u64;
33#endif
34
35#endif /* __ASSEMBLY__ */ 17#endif /* __ASSEMBLY__ */
36/* 18/*
37 * These aren't exported outside the kernel to avoid name space clashes 19 * These aren't exported outside the kernel to avoid name space clashes
@@ -42,18 +24,6 @@ __extension__ typedef unsigned long long __u64;
42 24
43#ifndef __ASSEMBLY__ 25#ifndef __ASSEMBLY__
44 26
45typedef signed char s8;
46typedef unsigned char u8;
47
48typedef signed short s16;
49typedef unsigned short u16;
50
51typedef signed int s32;
52typedef unsigned int u32;
53
54typedef signed long long s64;
55typedef unsigned long long u64;
56
57/* Dma addresses are 32-bits wide. */ 27/* Dma addresses are 32-bits wide. */
58 28
59typedef u32 dma_addr_t; 29typedef u32 dma_addr_t;
diff --git a/include/asm-cris/types.h b/include/asm-cris/types.h
index 5a21c42bc6c5..5790262cbe8a 100644
--- a/include/asm-cris/types.h
+++ b/include/asm-cris/types.h
@@ -1,29 +1,12 @@
1#ifndef _ETRAX_TYPES_H 1#ifndef _ETRAX_TYPES_H
2#define _ETRAX_TYPES_H 2#define _ETRAX_TYPES_H
3 3
4#include <asm-generic/int-ll64.h>
5
4#ifndef __ASSEMBLY__ 6#ifndef __ASSEMBLY__
5 7
6typedef unsigned short umode_t; 8typedef unsigned short umode_t;
7 9
8/*
9 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
10 * header files exported to user space
11 */
12
13typedef __signed__ char __s8;
14typedef unsigned char __u8;
15
16typedef __signed__ short __s16;
17typedef unsigned short __u16;
18
19typedef __signed__ int __s32;
20typedef unsigned int __u32;
21
22#if defined(__GNUC__)
23__extension__ typedef __signed__ long long __s64;
24__extension__ typedef unsigned long long __u64;
25#endif
26
27#endif /* __ASSEMBLY__ */ 10#endif /* __ASSEMBLY__ */
28 11
29/* 12/*
@@ -35,18 +18,6 @@ __extension__ typedef unsigned long long __u64;
35 18
36#ifndef __ASSEMBLY__ 19#ifndef __ASSEMBLY__
37 20
38typedef signed char s8;
39typedef unsigned char u8;
40
41typedef signed short s16;
42typedef unsigned short u16;
43
44typedef signed int s32;
45typedef unsigned int u32;
46
47typedef signed long long s64;
48typedef unsigned long long u64;
49
50/* Dma addresses are 32-bits wide, just like our other addresses. */ 21/* Dma addresses are 32-bits wide, just like our other addresses. */
51 22
52typedef u32 dma_addr_t; 23typedef u32 dma_addr_t;
diff --git a/include/asm-frv/types.h b/include/asm-frv/types.h
index 767e5ed71c4b..613bf1e962f0 100644
--- a/include/asm-frv/types.h
+++ b/include/asm-frv/types.h
@@ -12,29 +12,12 @@
12#ifndef _ASM_TYPES_H 12#ifndef _ASM_TYPES_H
13#define _ASM_TYPES_H 13#define _ASM_TYPES_H
14 14
15#include <asm-generic/int-ll64.h>
16
15#ifndef __ASSEMBLY__ 17#ifndef __ASSEMBLY__
16 18
17typedef unsigned short umode_t; 19typedef unsigned short umode_t;
18 20
19/*
20 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
21 * header files exported to user space
22 */
23
24typedef __signed__ char __s8;
25typedef unsigned char __u8;
26
27typedef __signed__ short __s16;
28typedef unsigned short __u16;
29
30typedef __signed__ int __s32;
31typedef unsigned int __u32;
32
33#if defined(__GNUC__)
34__extension__ typedef __signed__ long long __s64;
35__extension__ typedef unsigned long long __u64;
36#endif
37
38#endif /* __ASSEMBLY__ */ 21#endif /* __ASSEMBLY__ */
39 22
40/* 23/*
@@ -46,19 +29,6 @@ __extension__ typedef unsigned long long __u64;
46 29
47#ifndef __ASSEMBLY__ 30#ifndef __ASSEMBLY__
48 31
49
50typedef signed char s8;
51typedef unsigned char u8;
52
53typedef signed short s16;
54typedef unsigned short u16;
55
56typedef signed int s32;
57typedef unsigned int u32;
58
59typedef signed long long s64;
60typedef unsigned long long u64;
61
62/* Dma addresses are 32-bits wide. */ 32/* Dma addresses are 32-bits wide. */
63 33
64typedef u32 dma_addr_t; 34typedef u32 dma_addr_t;
diff --git a/include/asm-frv/unaligned.h b/include/asm-frv/unaligned.h
index 64ccc736f2d8..839a2fbffa0f 100644
--- a/include/asm-frv/unaligned.h
+++ b/include/asm-frv/unaligned.h
@@ -9,8 +9,8 @@
9 * 2 of the License, or (at your option) any later version. 9 * 2 of the License, or (at your option) any later version.
10 */ 10 */
11 11
12#ifndef _ASM_FRV_UNALIGNED_H 12#ifndef _ASM_UNALIGNED_H
13#define _ASM_FRV_UNALIGNED_H 13#define _ASM_UNALIGNED_H
14 14
15#include <linux/unaligned/le_byteshift.h> 15#include <linux/unaligned/le_byteshift.h>
16#include <linux/unaligned/be_byteshift.h> 16#include <linux/unaligned/be_byteshift.h>
@@ -19,4 +19,4 @@
19#define get_unaligned __get_unaligned_be 19#define get_unaligned __get_unaligned_be
20#define put_unaligned __put_unaligned_be 20#define put_unaligned __put_unaligned_be
21 21
22#endif /* _ASM_FRV_UNALIGNED_H */ 22#endif /* _ASM_UNALIGNED_H */
diff --git a/include/asm-generic/Kbuild b/include/asm-generic/Kbuild
index c18110ee30f1..4c9932a2503f 100644
--- a/include/asm-generic/Kbuild
+++ b/include/asm-generic/Kbuild
@@ -7,5 +7,7 @@ header-y += poll.h
7header-y += signal.h 7header-y += signal.h
8header-y += statfs.h 8header-y += statfs.h
9 9
10unifdef-y += int-l64.h
11unifdef-y += int-ll64.h
10unifdef-y += resource.h 12unifdef-y += resource.h
11unifdef-y += siginfo.h 13unifdef-y += siginfo.h
diff --git a/include/asm-generic/bitops.h b/include/asm-generic/bitops.h
index 15e6f253dda4..c9f369c4bd7e 100644
--- a/include/asm-generic/bitops.h
+++ b/include/asm-generic/bitops.h
@@ -17,8 +17,6 @@
17#include <asm-generic/bitops/fls64.h> 17#include <asm-generic/bitops/fls64.h>
18#include <asm-generic/bitops/find.h> 18#include <asm-generic/bitops/find.h>
19 19
20#ifdef __KERNEL__
21
22#ifndef _LINUX_BITOPS_H 20#ifndef _LINUX_BITOPS_H
23#error only <linux/bitops.h> can be included directly 21#error only <linux/bitops.h> can be included directly
24#endif 22#endif
@@ -32,6 +30,4 @@
32#include <asm-generic/bitops/ext2-atomic.h> 30#include <asm-generic/bitops/ext2-atomic.h>
33#include <asm-generic/bitops/minix.h> 31#include <asm-generic/bitops/minix.h>
34 32
35#endif /* __KERNEL__ */
36
37#endif /* _ASM_GENERIC_BITOPS_H */ 33#endif /* _ASM_GENERIC_BITOPS_H */
diff --git a/include/asm-generic/div64.h b/include/asm-generic/div64.h
index a4a49370793c..8f4e3193342e 100644
--- a/include/asm-generic/div64.h
+++ b/include/asm-generic/div64.h
@@ -30,11 +30,6 @@
30 __rem; \ 30 __rem; \
31 }) 31 })
32 32
33static inline uint64_t div64_64(uint64_t dividend, uint64_t divisor)
34{
35 return dividend / divisor;
36}
37
38#elif BITS_PER_LONG == 32 33#elif BITS_PER_LONG == 32
39 34
40extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor); 35extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor);
@@ -54,8 +49,6 @@ extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor);
54 __rem; \ 49 __rem; \
55 }) 50 })
56 51
57extern uint64_t div64_64(uint64_t dividend, uint64_t divisor);
58
59#else /* BITS_PER_LONG == ?? */ 52#else /* BITS_PER_LONG == ?? */
60 53
61# error do_div() does not yet support the C64 54# error do_div() does not yet support the C64
diff --git a/include/asm-generic/futex.h b/include/asm-generic/futex.h
index f422df0956a2..3c2344f48136 100644
--- a/include/asm-generic/futex.h
+++ b/include/asm-generic/futex.h
@@ -1,11 +1,9 @@
1#ifndef _ASM_GENERIC_FUTEX_H 1#ifndef _ASM_GENERIC_FUTEX_H
2#define _ASM_GENERIC_FUTEX_H 2#define _ASM_GENERIC_FUTEX_H
3 3
4#ifdef __KERNEL__
5
6#include <linux/futex.h> 4#include <linux/futex.h>
5#include <linux/uaccess.h>
7#include <asm/errno.h> 6#include <asm/errno.h>
8#include <asm/uaccess.h>
9 7
10static inline int 8static inline int
11futex_atomic_op_inuser (int encoded_op, int __user *uaddr) 9futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
@@ -56,4 +54,3 @@ futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
56} 54}
57 55
58#endif 56#endif
59#endif
diff --git a/include/asm-generic/int-l64.h b/include/asm-generic/int-l64.h
new file mode 100644
index 000000000000..2af9b75d77db
--- /dev/null
+++ b/include/asm-generic/int-l64.h
@@ -0,0 +1,71 @@
1/*
2 * asm-generic/int-l64.h
3 *
4 * Integer declarations for architectures which use "long"
5 * for 64-bit types.
6 */
7
8#ifndef _ASM_GENERIC_INT_L64_H
9#define _ASM_GENERIC_INT_L64_H
10
11#ifndef __ASSEMBLY__
12/*
13 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
14 * header files exported to user space
15 */
16
17typedef __signed__ char __s8;
18typedef unsigned char __u8;
19
20typedef __signed__ short __s16;
21typedef unsigned short __u16;
22
23typedef __signed__ int __s32;
24typedef unsigned int __u32;
25
26typedef __signed__ long __s64;
27typedef unsigned long __u64;
28
29#endif /* __ASSEMBLY__ */
30
31#ifdef __KERNEL__
32
33#ifndef __ASSEMBLY__
34
35typedef signed char s8;
36typedef unsigned char u8;
37
38typedef signed short s16;
39typedef unsigned short u16;
40
41typedef signed int s32;
42typedef unsigned int u32;
43
44typedef signed long s64;
45typedef unsigned long u64;
46
47#define S8_C(x) x
48#define U8_C(x) x ## U
49#define S16_C(x) x
50#define U16_C(x) x ## U
51#define S32_C(x) x
52#define U32_C(x) x ## U
53#define S64_C(x) x ## L
54#define U64_C(x) x ## UL
55
56#else /* __ASSEMBLY__ */
57
58#define S8_C(x) x
59#define U8_C(x) x
60#define S16_C(x) x
61#define U16_C(x) x
62#define S32_C(x) x
63#define U32_C(x) x
64#define S64_C(x) x
65#define U64_C(x) x
66
67#endif /* __ASSEMBLY__ */
68
69#endif /* __KERNEL__ */
70
71#endif /* _ASM_GENERIC_INT_L64_H */
diff --git a/include/asm-generic/int-ll64.h b/include/asm-generic/int-ll64.h
new file mode 100644
index 000000000000..260948905e4e
--- /dev/null
+++ b/include/asm-generic/int-ll64.h
@@ -0,0 +1,76 @@
1/*
2 * asm-generic/int-ll64.h
3 *
4 * Integer declarations for architectures which use "long long"
5 * for 64-bit types.
6 */
7
8#ifndef _ASM_GENERIC_INT_LL64_H
9#define _ASM_GENERIC_INT_LL64_H
10
11#ifndef __ASSEMBLY__
12/*
13 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
14 * header files exported to user space
15 */
16
17typedef __signed__ char __s8;
18typedef unsigned char __u8;
19
20typedef __signed__ short __s16;
21typedef unsigned short __u16;
22
23typedef __signed__ int __s32;
24typedef unsigned int __u32;
25
26#ifdef __GNUC__
27__extension__ typedef __signed__ long long __s64;
28__extension__ typedef unsigned long long __u64;
29#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
30typedef __signed__ long long __s64;
31typedef unsigned long long __u64;
32#endif
33
34#endif /* __ASSEMBLY__ */
35
36#ifdef __KERNEL__
37
38#ifndef __ASSEMBLY__
39
40typedef signed char s8;
41typedef unsigned char u8;
42
43typedef signed short s16;
44typedef unsigned short u16;
45
46typedef signed int s32;
47typedef unsigned int u32;
48
49typedef signed long long s64;
50typedef unsigned long long u64;
51
52#define S8_C(x) x
53#define U8_C(x) x ## U
54#define S16_C(x) x
55#define U16_C(x) x ## U
56#define S32_C(x) x
57#define U32_C(x) x ## U
58#define S64_C(x) x ## LL
59#define U64_C(x) x ## ULL
60
61#else /* __ASSEMBLY__ */
62
63#define S8_C(x) x
64#define U8_C(x) x
65#define S16_C(x) x
66#define U16_C(x) x
67#define S32_C(x) x
68#define U32_C(x) x
69#define S64_C(x) x
70#define U64_C(x) x
71
72#endif /* __ASSEMBLY__ */
73
74#endif /* __KERNEL__ */
75
76#endif /* _ASM_GENERIC_INT_LL64_H */
diff --git a/include/asm-generic/memory_model.h b/include/asm-generic/memory_model.h
index 52226e14bd7d..ae060c62aff1 100644
--- a/include/asm-generic/memory_model.h
+++ b/include/asm-generic/memory_model.h
@@ -1,7 +1,6 @@
1#ifndef __ASM_MEMORY_MODEL_H 1#ifndef __ASM_MEMORY_MODEL_H
2#define __ASM_MEMORY_MODEL_H 2#define __ASM_MEMORY_MODEL_H
3 3
4#ifdef __KERNEL__
5#ifndef __ASSEMBLY__ 4#ifndef __ASSEMBLY__
6 5
7#if defined(CONFIG_FLATMEM) 6#if defined(CONFIG_FLATMEM)
@@ -81,6 +80,5 @@ extern unsigned long page_to_pfn(struct page *page);
81#endif /* CONFIG_OUT_OF_LINE_PFN_TO_PAGE */ 80#endif /* CONFIG_OUT_OF_LINE_PFN_TO_PAGE */
82 81
83#endif /* __ASSEMBLY__ */ 82#endif /* __ASSEMBLY__ */
84#endif /* __KERNEL__ */
85 83
86#endif 84#endif
diff --git a/include/asm-generic/page.h b/include/asm-generic/page.h
index a96b5d986b6e..14db733b8e68 100644
--- a/include/asm-generic/page.h
+++ b/include/asm-generic/page.h
@@ -1,7 +1,6 @@
1#ifndef _ASM_GENERIC_PAGE_H 1#ifndef _ASM_GENERIC_PAGE_H
2#define _ASM_GENERIC_PAGE_H 2#define _ASM_GENERIC_PAGE_H
3 3
4#ifdef __KERNEL__
5#ifndef __ASSEMBLY__ 4#ifndef __ASSEMBLY__
6 5
7#include <linux/compiler.h> 6#include <linux/compiler.h>
@@ -21,6 +20,5 @@ static __inline__ __attribute_const__ int get_order(unsigned long size)
21} 20}
22 21
23#endif /* __ASSEMBLY__ */ 22#endif /* __ASSEMBLY__ */
24#endif /* __KERNEL__ */
25 23
26#endif /* _ASM_GENERIC_PAGE_H */ 24#endif /* _ASM_GENERIC_PAGE_H */
diff --git a/include/asm-generic/rtc.h b/include/asm-generic/rtc.h
index dd1bed860e64..be4af0029ac0 100644
--- a/include/asm-generic/rtc.h
+++ b/include/asm-generic/rtc.h
@@ -12,8 +12,6 @@
12#ifndef __ASM_RTC_H__ 12#ifndef __ASM_RTC_H__
13#define __ASM_RTC_H__ 13#define __ASM_RTC_H__
14 14
15#ifdef __KERNEL__
16
17#include <linux/mc146818rtc.h> 15#include <linux/mc146818rtc.h>
18#include <linux/rtc.h> 16#include <linux/rtc.h>
19#include <linux/bcd.h> 17#include <linux/bcd.h>
@@ -213,5 +211,4 @@ static inline int set_rtc_pll(struct rtc_pll_info *pll)
213 return -EINVAL; 211 return -EINVAL;
214} 212}
215 213
216#endif /* __KERNEL__ */
217#endif /* __ASM_RTC_H__ */ 214#endif /* __ASM_RTC_H__ */
diff --git a/include/asm-h8300/types.h b/include/asm-h8300/types.h
index 56566e2a09fd..12875190b156 100644
--- a/include/asm-h8300/types.h
+++ b/include/asm-h8300/types.h
@@ -1,6 +1,8 @@
1#ifndef _H8300_TYPES_H 1#ifndef _H8300_TYPES_H
2#define _H8300_TYPES_H 2#define _H8300_TYPES_H
3 3
4#include <asm-generic/int-ll64.h>
5
4#if !defined(__ASSEMBLY__) 6#if !defined(__ASSEMBLY__)
5 7
6/* 8/*
@@ -14,41 +16,10 @@
14typedef unsigned short umode_t; 16typedef unsigned short umode_t;
15 17
16/* 18/*
17 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
18 * header files exported to user space
19 */
20
21typedef __signed__ char __s8;
22typedef unsigned char __u8;
23
24typedef __signed__ short __s16;
25typedef unsigned short __u16;
26
27typedef __signed__ int __s32;
28typedef unsigned int __u32;
29
30#if defined(__GNUC__)
31__extension__ typedef __signed__ long long __s64;
32__extension__ typedef unsigned long long __u64;
33#endif
34
35/*
36 * These aren't exported outside the kernel to avoid name space clashes 19 * These aren't exported outside the kernel to avoid name space clashes
37 */ 20 */
38#ifdef __KERNEL__ 21#ifdef __KERNEL__
39 22
40typedef signed char s8;
41typedef unsigned char u8;
42
43typedef signed short s16;
44typedef unsigned short u16;
45
46typedef signed int s32;
47typedef unsigned int u32;
48
49typedef signed long long s64;
50typedef unsigned long long u64;
51
52#define BITS_PER_LONG 32 23#define BITS_PER_LONG 32
53 24
54/* Dma addresses are 32-bits wide. */ 25/* Dma addresses are 32-bits wide. */
diff --git a/include/asm-ia64/cpu.h b/include/asm-ia64/cpu.h
index e87fa3210a2b..fcca30b9f110 100644
--- a/include/asm-ia64/cpu.h
+++ b/include/asm-ia64/cpu.h
@@ -14,8 +14,8 @@ DECLARE_PER_CPU(struct ia64_cpu, cpu_devices);
14 14
15DECLARE_PER_CPU(int, cpu_state); 15DECLARE_PER_CPU(int, cpu_state);
16 16
17extern int arch_register_cpu(int num);
18#ifdef CONFIG_HOTPLUG_CPU 17#ifdef CONFIG_HOTPLUG_CPU
18extern int arch_register_cpu(int num);
19extern void arch_unregister_cpu(int); 19extern void arch_unregister_cpu(int);
20#endif 20#endif
21 21
diff --git a/include/asm-ia64/dmi.h b/include/asm-ia64/dmi.h
index f3efaa229525..00eb1b130b63 100644
--- a/include/asm-ia64/dmi.h
+++ b/include/asm-ia64/dmi.h
@@ -3,4 +3,9 @@
3 3
4#include <asm/io.h> 4#include <asm/io.h>
5 5
6/* Use normal IO mappings for DMI */
7#define dmi_ioremap ioremap
8#define dmi_iounmap(x,l) iounmap(x)
9#define dmi_alloc(l) kmalloc(l, GFP_ATOMIC)
10
6#endif 11#endif
diff --git a/include/asm-ia64/futex.h b/include/asm-ia64/futex.h
index 8a98a2654139..c7f0f062239c 100644
--- a/include/asm-ia64/futex.h
+++ b/include/asm-ia64/futex.h
@@ -2,9 +2,9 @@
2#define _ASM_FUTEX_H 2#define _ASM_FUTEX_H
3 3
4#include <linux/futex.h> 4#include <linux/futex.h>
5#include <linux/uaccess.h>
5#include <asm/errno.h> 6#include <asm/errno.h>
6#include <asm/system.h> 7#include <asm/system.h>
7#include <asm/uaccess.h>
8 8
9#define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \ 9#define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10do { \ 10do { \
diff --git a/include/asm-ia64/io.h b/include/asm-ia64/io.h
index 4ebed77aa472..260a85ac9d6a 100644
--- a/include/asm-ia64/io.h
+++ b/include/asm-ia64/io.h
@@ -423,11 +423,6 @@ extern void __iomem * ioremap(unsigned long offset, unsigned long size);
423extern void __iomem * ioremap_nocache (unsigned long offset, unsigned long size); 423extern void __iomem * ioremap_nocache (unsigned long offset, unsigned long size);
424extern void iounmap (volatile void __iomem *addr); 424extern void iounmap (volatile void __iomem *addr);
425 425
426/* Use normal IO mappings for DMI */
427#define dmi_ioremap ioremap
428#define dmi_iounmap(x,l) iounmap(x)
429#define dmi_alloc(l) kmalloc(l, GFP_ATOMIC)
430
431/* 426/*
432 * String version of IO memory access ops: 427 * String version of IO memory access ops:
433 */ 428 */
diff --git a/include/asm-ia64/thread_info.h b/include/asm-ia64/thread_info.h
index 6da8069a0f77..2422ac61658a 100644
--- a/include/asm-ia64/thread_info.h
+++ b/include/asm-ia64/thread_info.h
@@ -101,7 +101,6 @@ extern void tsk_clear_notify_resume(struct task_struct *tsk);
101#define TIF_SYSCALL_TRACE 2 /* syscall trace active */ 101#define TIF_SYSCALL_TRACE 2 /* syscall trace active */
102#define TIF_SYSCALL_AUDIT 3 /* syscall auditing active */ 102#define TIF_SYSCALL_AUDIT 3 /* syscall auditing active */
103#define TIF_SINGLESTEP 4 /* restore singlestep on return to user mode */ 103#define TIF_SINGLESTEP 4 /* restore singlestep on return to user mode */
104#define TIF_RESTORE_SIGMASK 5 /* restore signal mask in do_signal() */
105#define TIF_NOTIFY_RESUME 6 /* resumption notification requested */ 104#define TIF_NOTIFY_RESUME 6 /* resumption notification requested */
106#define TIF_POLLING_NRFLAG 16 /* true if poll_idle() is polling TIF_NEED_RESCHED */ 105#define TIF_POLLING_NRFLAG 16 /* true if poll_idle() is polling TIF_NEED_RESCHED */
107#define TIF_MEMDIE 17 106#define TIF_MEMDIE 17
@@ -114,7 +113,6 @@ extern void tsk_clear_notify_resume(struct task_struct *tsk);
114#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT) 113#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
115#define _TIF_SINGLESTEP (1 << TIF_SINGLESTEP) 114#define _TIF_SINGLESTEP (1 << TIF_SINGLESTEP)
116#define _TIF_SYSCALL_TRACEAUDIT (_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP) 115#define _TIF_SYSCALL_TRACEAUDIT (_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP)
117#define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
118#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME) 116#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
119#define _TIF_SIGPENDING (1 << TIF_SIGPENDING) 117#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
120#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED) 118#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
@@ -126,13 +124,23 @@ extern void tsk_clear_notify_resume(struct task_struct *tsk);
126 124
127/* "work to do on user-return" bits */ 125/* "work to do on user-return" bits */
128#define TIF_ALLWORK_MASK (_TIF_SIGPENDING|_TIF_NOTIFY_RESUME|_TIF_SYSCALL_AUDIT|\ 126#define TIF_ALLWORK_MASK (_TIF_SIGPENDING|_TIF_NOTIFY_RESUME|_TIF_SYSCALL_AUDIT|\
129 _TIF_NEED_RESCHED| _TIF_SYSCALL_TRACE|\ 127 _TIF_NEED_RESCHED|_TIF_SYSCALL_TRACE)
130 _TIF_RESTORE_SIGMASK)
131/* like TIF_ALLWORK_BITS but sans TIF_SYSCALL_TRACE or TIF_SYSCALL_AUDIT */ 128/* like TIF_ALLWORK_BITS but sans TIF_SYSCALL_TRACE or TIF_SYSCALL_AUDIT */
132#define TIF_WORK_MASK (TIF_ALLWORK_MASK&~(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT)) 129#define TIF_WORK_MASK (TIF_ALLWORK_MASK&~(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT))
133 130
134#define TS_POLLING 1 /* true if in idle loop and not sleeping */ 131#define TS_POLLING 1 /* true if in idle loop and not sleeping */
132#define TS_RESTORE_SIGMASK 2 /* restore signal mask in do_signal() */
135 133
136#define tsk_is_polling(t) (task_thread_info(t)->status & TS_POLLING) 134#define tsk_is_polling(t) (task_thread_info(t)->status & TS_POLLING)
137 135
136#ifndef __ASSEMBLY__
137#define HAVE_SET_RESTORE_SIGMASK 1
138static inline void set_restore_sigmask(void)
139{
140 struct thread_info *ti = current_thread_info();
141 ti->status |= TS_RESTORE_SIGMASK;
142 set_bit(TIF_SIGPENDING, &ti->flags);
143}
144#endif /* !__ASSEMBLY__ */
145
138#endif /* _ASM_IA64_THREAD_INFO_H */ 146#endif /* _ASM_IA64_THREAD_INFO_H */
diff --git a/include/asm-ia64/topology.h b/include/asm-ia64/topology.h
index f2f72ef2a897..32863b3bb1d3 100644
--- a/include/asm-ia64/topology.h
+++ b/include/asm-ia64/topology.h
@@ -116,6 +116,8 @@ void build_cpu_to_node_map(void);
116#define smt_capable() (smp_num_siblings > 1) 116#define smt_capable() (smp_num_siblings > 1)
117#endif 117#endif
118 118
119extern void arch_fix_phys_package_id(int num, u32 slot);
120
119#define pcibus_to_cpumask(bus) (pcibus_to_node(bus) == -1 ? \ 121#define pcibus_to_cpumask(bus) (pcibus_to_node(bus) == -1 ? \
120 CPU_MASK_ALL : \ 122 CPU_MASK_ALL : \
121 node_to_cpumask(pcibus_to_node(bus)) \ 123 node_to_cpumask(pcibus_to_node(bus)) \
diff --git a/include/asm-ia64/types.h b/include/asm-ia64/types.h
index 902850d12424..e36b3716e718 100644
--- a/include/asm-ia64/types.h
+++ b/include/asm-ia64/types.h
@@ -13,6 +13,8 @@
13 * David Mosberger-Tang <davidm@hpl.hp.com>, Hewlett-Packard Co 13 * David Mosberger-Tang <davidm@hpl.hp.com>, Hewlett-Packard Co
14 */ 14 */
15 15
16#include <asm-generic/int-l64.h>
17
16#ifdef __ASSEMBLY__ 18#ifdef __ASSEMBLY__
17# define __IA64_UL(x) (x) 19# define __IA64_UL(x) (x)
18# define __IA64_UL_CONST(x) x 20# define __IA64_UL_CONST(x) x
@@ -28,39 +30,10 @@
28typedef unsigned int umode_t; 30typedef unsigned int umode_t;
29 31
30/* 32/*
31 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
32 * header files exported to user space
33 */
34
35typedef __signed__ char __s8;
36typedef unsigned char __u8;
37
38typedef __signed__ short __s16;
39typedef unsigned short __u16;
40
41typedef __signed__ int __s32;
42typedef unsigned int __u32;
43
44typedef __signed__ long __s64;
45typedef unsigned long __u64;
46
47/*
48 * These aren't exported outside the kernel to avoid name space clashes 33 * These aren't exported outside the kernel to avoid name space clashes
49 */ 34 */
50# ifdef __KERNEL__ 35# ifdef __KERNEL__
51 36
52typedef __s8 s8;
53typedef __u8 u8;
54
55typedef __s16 s16;
56typedef __u16 u16;
57
58typedef __s32 s32;
59typedef __u32 u32;
60
61typedef __s64 s64;
62typedef __u64 u64;
63
64#define BITS_PER_LONG 64 37#define BITS_PER_LONG 64
65 38
66/* DMA addresses are 64-bits wide, in general. */ 39/* DMA addresses are 64-bits wide, in general. */
diff --git a/include/asm-ia64/uncached.h b/include/asm-ia64/uncached.h
index b82d923b73c1..13d7e65ca3cc 100644
--- a/include/asm-ia64/uncached.h
+++ b/include/asm-ia64/uncached.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2001-2005 Silicon Graphics, Inc. All rights reserved. 2 * Copyright (C) 2001-2008 Silicon Graphics, Inc. All rights reserved.
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify it 4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License 5 * under the terms of version 2 of the GNU General Public License
@@ -8,5 +8,5 @@
8 * Prototypes for the uncached page allocator 8 * Prototypes for the uncached page allocator
9 */ 9 */
10 10
11extern unsigned long uncached_alloc_page(int nid); 11extern unsigned long uncached_alloc_page(int starting_nid, int n_pages);
12extern void uncached_free_page(unsigned long); 12extern void uncached_free_page(unsigned long uc_addr, int n_pages);
diff --git a/include/asm-m32r/types.h b/include/asm-m32r/types.h
index b64c16639a7b..bc9f7fff0ac3 100644
--- a/include/asm-m32r/types.h
+++ b/include/asm-m32r/types.h
@@ -1,28 +1,12 @@
1#ifndef _ASM_M32R_TYPES_H 1#ifndef _ASM_M32R_TYPES_H
2#define _ASM_M32R_TYPES_H 2#define _ASM_M32R_TYPES_H
3 3
4#include <asm-generic/int-ll64.h>
5
4#ifndef __ASSEMBLY__ 6#ifndef __ASSEMBLY__
5 7
6typedef unsigned short umode_t; 8typedef unsigned short umode_t;
7 9
8/*
9 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
10 * header files exported to user space
11 */
12
13typedef __signed__ char __s8;
14typedef unsigned char __u8;
15
16typedef __signed__ short __s16;
17typedef unsigned short __u16;
18
19typedef __signed__ int __s32;
20typedef unsigned int __u32;
21
22#if defined(__GNUC__)
23__extension__ typedef __signed__ long long __s64;
24__extension__ typedef unsigned long long __u64;
25#endif
26#endif /* __ASSEMBLY__ */ 10#endif /* __ASSEMBLY__ */
27 11
28/* 12/*
@@ -34,18 +18,6 @@ __extension__ typedef unsigned long long __u64;
34 18
35#ifndef __ASSEMBLY__ 19#ifndef __ASSEMBLY__
36 20
37typedef signed char s8;
38typedef unsigned char u8;
39
40typedef signed short s16;
41typedef unsigned short u16;
42
43typedef signed int s32;
44typedef unsigned int u32;
45
46typedef signed long long s64;
47typedef unsigned long long u64;
48
49/* DMA addresses are 32-bits wide. */ 21/* DMA addresses are 32-bits wide. */
50 22
51typedef u32 dma_addr_t; 23typedef u32 dma_addr_t;
diff --git a/include/asm-m68k/div64.h b/include/asm-m68k/div64.h
index 33caad1628d4..8243c931b5c0 100644
--- a/include/asm-m68k/div64.h
+++ b/include/asm-m68k/div64.h
@@ -25,5 +25,4 @@
25 __rem; \ 25 __rem; \
26}) 26})
27 27
28extern uint64_t div64_64(uint64_t dividend, uint64_t divisor);
29#endif /* _M68K_DIV64_H */ 28#endif /* _M68K_DIV64_H */
diff --git a/include/asm-m68k/machw.h b/include/asm-m68k/machw.h
index d2e0e25d5c90..35624998291c 100644
--- a/include/asm-m68k/machw.h
+++ b/include/asm-m68k/machw.h
@@ -66,36 +66,6 @@ struct MAC_SCC
66# define mac_scc ((*(volatile struct SCC*)MAC_SCC_BAS)) 66# define mac_scc ((*(volatile struct SCC*)MAC_SCC_BAS))
67#endif 67#endif
68 68
69/* hardware stuff */
70
71#define MACHW_DECLARE(name) unsigned name : 1
72#define MACHW_SET(name) (mac_hw_present.name = 1)
73#define MACHW_PRESENT(name) (mac_hw_present.name)
74
75struct mac_hw_present {
76 /* video hardware */
77 /* sound hardware */
78 /* disk storage interfaces */
79 MACHW_DECLARE(MAC_SCSI_80); /* Directly mapped NCR5380 */
80 MACHW_DECLARE(MAC_SCSI_96); /* 53c9[46] */
81 MACHW_DECLARE(MAC_SCSI_96_2); /* 2nd 53c9[46] Q900 and Q950 */
82 MACHW_DECLARE(IDE); /* IDE Interface */
83 /* other I/O hardware */
84 MACHW_DECLARE(SCC); /* Serial Communications Contr. */
85 /* DMA */
86 MACHW_DECLARE(SCSI_DMA); /* DMA for the NCR5380 */
87 /* real time clocks */
88 MACHW_DECLARE(RTC_CLK); /* clock chip */
89 /* supporting hardware */
90 MACHW_DECLARE(VIA1); /* Versatile Interface Ad. 1 */
91 MACHW_DECLARE(VIA2); /* Versatile Interface Ad. 2 */
92 MACHW_DECLARE(RBV); /* Versatile Interface Ad. 2+ */
93 /* NUBUS */
94 MACHW_DECLARE(NUBUS); /* NUBUS */
95};
96
97extern struct mac_hw_present mac_hw_present;
98
99#endif /* __ASSEMBLY__ */ 69#endif /* __ASSEMBLY__ */
100 70
101#endif /* linux/machw.h */ 71#endif /* linux/machw.h */
diff --git a/include/asm-m68k/types.h b/include/asm-m68k/types.h
index c35c09d93b66..6441cb5f8e7c 100644
--- a/include/asm-m68k/types.h
+++ b/include/asm-m68k/types.h
@@ -8,30 +8,12 @@
8 * not a major issue. However, for interoperability, libraries still 8 * not a major issue. However, for interoperability, libraries still
9 * need to be careful to avoid a name clashes. 9 * need to be careful to avoid a name clashes.
10 */ 10 */
11#include <asm-generic/int-ll64.h>
11 12
12#ifndef __ASSEMBLY__ 13#ifndef __ASSEMBLY__
13 14
14typedef unsigned short umode_t; 15typedef unsigned short umode_t;
15 16
16/*
17 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
18 * header files exported to user space
19 */
20
21typedef __signed__ char __s8;
22typedef unsigned char __u8;
23
24typedef __signed__ short __s16;
25typedef unsigned short __u16;
26
27typedef __signed__ int __s32;
28typedef unsigned int __u32;
29
30#if defined(__GNUC__)
31__extension__ typedef __signed__ long long __s64;
32__extension__ typedef unsigned long long __u64;
33#endif
34
35#endif /* __ASSEMBLY__ */ 17#endif /* __ASSEMBLY__ */
36 18
37/* 19/*
@@ -43,18 +25,6 @@ __extension__ typedef unsigned long long __u64;
43 25
44#ifndef __ASSEMBLY__ 26#ifndef __ASSEMBLY__
45 27
46typedef signed char s8;
47typedef unsigned char u8;
48
49typedef signed short s16;
50typedef unsigned short u16;
51
52typedef signed int s32;
53typedef unsigned int u32;
54
55typedef signed long long s64;
56typedef unsigned long long u64;
57
58/* DMA addresses are always 32-bits wide */ 28/* DMA addresses are always 32-bits wide */
59 29
60typedef u32 dma_addr_t; 30typedef u32 dma_addr_t;
diff --git a/include/asm-m68knommu/dma.h b/include/asm-m68knommu/dma.h
index 3f20419c633a..939a02056217 100644
--- a/include/asm-m68knommu/dma.h
+++ b/include/asm-m68knommu/dma.h
@@ -35,7 +35,8 @@
35/* 35/*
36 * Set number of channels of DMA on ColdFire for different implementations. 36 * Set number of channels of DMA on ColdFire for different implementations.
37 */ 37 */
38#if defined(CONFIG_M5249) || defined(CONFIG_M5307) || defined(CONFIG_M5407) 38#if defined(CONFIG_M5249) || defined(CONFIG_M5307) || defined(CONFIG_M5407) || \
39 defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x)
39#define MAX_M68K_DMA_CHANNELS 4 40#define MAX_M68K_DMA_CHANNELS 4
40#elif defined(CONFIG_M5272) 41#elif defined(CONFIG_M5272)
41#define MAX_M68K_DMA_CHANNELS 1 42#define MAX_M68K_DMA_CHANNELS 1
diff --git a/include/asm-m68knommu/param.h b/include/asm-m68knommu/param.h
index 96c451018324..6044397adb64 100644
--- a/include/asm-m68knommu/param.h
+++ b/include/asm-m68knommu/param.h
@@ -1,13 +1,16 @@
1#ifndef _M68KNOMMU_PARAM_H 1#ifndef _M68KNOMMU_PARAM_H
2#define _M68KNOMMU_PARAM_H 2#define _M68KNOMMU_PARAM_H
3 3
4#define HZ CONFIG_HZ
5
6#ifdef __KERNEL__ 4#ifdef __KERNEL__
5#define HZ CONFIG_HZ
7#define USER_HZ HZ 6#define USER_HZ HZ
8#define CLOCKS_PER_SEC (USER_HZ) 7#define CLOCKS_PER_SEC (USER_HZ)
9#endif 8#endif
10 9
10#ifndef HZ
11#define HZ 100
12#endif
13
11#define EXEC_PAGESIZE 4096 14#define EXEC_PAGESIZE 4096
12 15
13#ifndef NOGROUP 16#ifndef NOGROUP
diff --git a/include/asm-mips/div64.h b/include/asm-mips/div64.h
index 716371bd0980..d1d699105c11 100644
--- a/include/asm-mips/div64.h
+++ b/include/asm-mips/div64.h
@@ -82,7 +82,6 @@
82 (n) = __quot; \ 82 (n) = __quot; \
83 __mod; }) 83 __mod; })
84 84
85extern uint64_t div64_64(uint64_t dividend, uint64_t divisor);
86#endif /* (_MIPS_SZLONG == 32) */ 85#endif /* (_MIPS_SZLONG == 32) */
87 86
88#if (_MIPS_SZLONG == 64) 87#if (_MIPS_SZLONG == 64)
@@ -106,11 +105,6 @@ extern uint64_t div64_64(uint64_t dividend, uint64_t divisor);
106 (n) = __quot; \ 105 (n) = __quot; \
107 __mod; }) 106 __mod; })
108 107
109static inline uint64_t div64_64(uint64_t dividend, uint64_t divisor)
110{
111 return dividend / divisor;
112}
113
114#endif /* (_MIPS_SZLONG == 64) */ 108#endif /* (_MIPS_SZLONG == 64) */
115 109
116#endif /* _ASM_DIV64_H */ 110#endif /* _ASM_DIV64_H */
diff --git a/include/asm-mips/futex.h b/include/asm-mips/futex.h
index 17f082cfea85..b9cce90346cf 100644
--- a/include/asm-mips/futex.h
+++ b/include/asm-mips/futex.h
@@ -11,9 +11,9 @@
11#ifdef __KERNEL__ 11#ifdef __KERNEL__
12 12
13#include <linux/futex.h> 13#include <linux/futex.h>
14#include <linux/uaccess.h>
14#include <asm/barrier.h> 15#include <asm/barrier.h>
15#include <asm/errno.h> 16#include <asm/errno.h>
16#include <asm/uaccess.h>
17#include <asm/war.h> 17#include <asm/war.h>
18 18
19#define __futex_atomic_op(insn, ret, oldval, uaddr, oparg) \ 19#define __futex_atomic_op(insn, ret, oldval, uaddr, oparg) \
diff --git a/include/asm-mips/types.h b/include/asm-mips/types.h
index 2dd147f519d1..bcbb8d675af5 100644
--- a/include/asm-mips/types.h
+++ b/include/asm-mips/types.h
@@ -9,37 +9,15 @@
9#ifndef _ASM_TYPES_H 9#ifndef _ASM_TYPES_H
10#define _ASM_TYPES_H 10#define _ASM_TYPES_H
11 11
12#ifndef __ASSEMBLY__ 12#if _MIPS_SZLONG == 64
13 13# include <asm-generic/int-l64.h>
14typedef unsigned short umode_t;
15
16/*
17 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
18 * header files exported to user space
19 */
20
21typedef __signed__ char __s8;
22typedef unsigned char __u8;
23
24typedef __signed__ short __s16;
25typedef unsigned short __u16;
26
27typedef __signed__ int __s32;
28typedef unsigned int __u32;
29
30#if (_MIPS_SZLONG == 64)
31
32typedef __signed__ long __s64;
33typedef unsigned long __u64;
34
35#else 14#else
36 15# include <asm-generic/int-ll64.h>
37#if defined(__GNUC__)
38__extension__ typedef __signed__ long long __s64;
39__extension__ typedef unsigned long long __u64;
40#endif 16#endif
41 17
42#endif 18#ifndef __ASSEMBLY__
19
20typedef unsigned short umode_t;
43 21
44#endif /* __ASSEMBLY__ */ 22#endif /* __ASSEMBLY__ */
45 23
@@ -52,30 +30,6 @@ __extension__ typedef unsigned long long __u64;
52 30
53#ifndef __ASSEMBLY__ 31#ifndef __ASSEMBLY__
54 32
55
56typedef __signed char s8;
57typedef unsigned char u8;
58
59typedef __signed short s16;
60typedef unsigned short u16;
61
62typedef __signed int s32;
63typedef unsigned int u32;
64
65#if (_MIPS_SZLONG == 64)
66
67typedef __signed__ long s64;
68typedef unsigned long u64;
69
70#else
71
72#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
73typedef __signed__ long long s64;
74typedef unsigned long long u64;
75#endif
76
77#endif
78
79#if (defined(CONFIG_HIGHMEM) && defined(CONFIG_64BIT_PHYS_ADDR)) \ 33#if (defined(CONFIG_HIGHMEM) && defined(CONFIG_64BIT_PHYS_ADDR)) \
80 || defined(CONFIG_64BIT) 34 || defined(CONFIG_64BIT)
81typedef u64 dma_addr_t; 35typedef u64 dma_addr_t;
diff --git a/include/asm-mn10300/div64.h b/include/asm-mn10300/div64.h
index bf9c515a998c..3a8329b3e869 100644
--- a/include/asm-mn10300/div64.h
+++ b/include/asm-mn10300/div64.h
@@ -97,7 +97,4 @@ signed __muldiv64s(signed val, signed mult, signed div)
97 return result; 97 return result;
98} 98}
99 99
100extern __attribute__((const))
101uint64_t div64_64(uint64_t dividend, uint64_t divisor);
102
103#endif /* _ASM_DIV64 */ 100#endif /* _ASM_DIV64 */
diff --git a/include/asm-mn10300/types.h b/include/asm-mn10300/types.h
index d40ea7628bfc..7b9f01042fd4 100644
--- a/include/asm-mn10300/types.h
+++ b/include/asm-mn10300/types.h
@@ -11,29 +11,12 @@
11#ifndef _ASM_TYPES_H 11#ifndef _ASM_TYPES_H
12#define _ASM_TYPES_H 12#define _ASM_TYPES_H
13 13
14#include <asm-generic/int-ll64.h>
15
14#ifndef __ASSEMBLY__ 16#ifndef __ASSEMBLY__
15 17
16typedef unsigned short umode_t; 18typedef unsigned short umode_t;
17 19
18/*
19 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
20 * header files exported to user space
21 */
22
23typedef __signed__ char __s8;
24typedef unsigned char __u8;
25
26typedef __signed__ short __s16;
27typedef unsigned short __u16;
28
29typedef __signed__ int __s32;
30typedef unsigned int __u32;
31
32#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
33typedef __signed__ long long __s64;
34typedef unsigned long long __u64;
35#endif
36
37#endif /* __ASSEMBLY__ */ 20#endif /* __ASSEMBLY__ */
38 21
39/* 22/*
@@ -45,18 +28,6 @@ typedef unsigned long long __u64;
45 28
46#ifndef __ASSEMBLY__ 29#ifndef __ASSEMBLY__
47 30
48typedef signed char s8;
49typedef unsigned char u8;
50
51typedef signed short s16;
52typedef unsigned short u16;
53
54typedef signed int s32;
55typedef unsigned int u32;
56
57typedef signed long long s64;
58typedef unsigned long long u64;
59
60/* Dma addresses are 32-bits wide. */ 31/* Dma addresses are 32-bits wide. */
61typedef u32 dma_addr_t; 32typedef u32 dma_addr_t;
62 33
diff --git a/include/asm-parisc/futex.h b/include/asm-parisc/futex.h
index fdc6d055ef7f..0c705c3a55ef 100644
--- a/include/asm-parisc/futex.h
+++ b/include/asm-parisc/futex.h
@@ -4,8 +4,8 @@
4#ifdef __KERNEL__ 4#ifdef __KERNEL__
5 5
6#include <linux/futex.h> 6#include <linux/futex.h>
7#include <linux/uaccess.h>
7#include <asm/errno.h> 8#include <asm/errno.h>
8#include <asm/uaccess.h>
9 9
10static inline int 10static inline int
11futex_atomic_op_inuser (int encoded_op, int __user *uaddr) 11futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
diff --git a/include/asm-parisc/types.h b/include/asm-parisc/types.h
index 56c84802da59..7f5a39bfb4ce 100644
--- a/include/asm-parisc/types.h
+++ b/include/asm-parisc/types.h
@@ -1,29 +1,12 @@
1#ifndef _PARISC_TYPES_H 1#ifndef _PARISC_TYPES_H
2#define _PARISC_TYPES_H 2#define _PARISC_TYPES_H
3 3
4#include <asm-generic/int-ll64.h>
5
4#ifndef __ASSEMBLY__ 6#ifndef __ASSEMBLY__
5 7
6typedef unsigned short umode_t; 8typedef unsigned short umode_t;
7 9
8/*
9 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
10 * header files exported to user space
11 */
12
13typedef __signed__ char __s8;
14typedef unsigned char __u8;
15
16typedef __signed__ short __s16;
17typedef unsigned short __u16;
18
19typedef __signed__ int __s32;
20typedef unsigned int __u32;
21
22#if defined(__GNUC__)
23__extension__ typedef __signed__ long long __s64;
24__extension__ typedef unsigned long long __u64;
25#endif
26
27#endif /* __ASSEMBLY__ */ 10#endif /* __ASSEMBLY__ */
28 11
29/* 12/*
@@ -41,18 +24,6 @@ __extension__ typedef unsigned long long __u64;
41 24
42#ifndef __ASSEMBLY__ 25#ifndef __ASSEMBLY__
43 26
44typedef signed char s8;
45typedef unsigned char u8;
46
47typedef signed short s16;
48typedef unsigned short u16;
49
50typedef signed int s32;
51typedef unsigned int u32;
52
53typedef signed long long s64;
54typedef unsigned long long u64;
55
56/* Dma addresses are 32-bits wide. */ 27/* Dma addresses are 32-bits wide. */
57 28
58typedef u32 dma_addr_t; 29typedef u32 dma_addr_t;
diff --git a/include/asm-powerpc/futex.h b/include/asm-powerpc/futex.h
index 3f3673fd3ff3..6d406c5c5de4 100644
--- a/include/asm-powerpc/futex.h
+++ b/include/asm-powerpc/futex.h
@@ -4,9 +4,9 @@
4#ifdef __KERNEL__ 4#ifdef __KERNEL__
5 5
6#include <linux/futex.h> 6#include <linux/futex.h>
7#include <linux/uaccess.h>
7#include <asm/errno.h> 8#include <asm/errno.h>
8#include <asm/synch.h> 9#include <asm/synch.h>
9#include <asm/uaccess.h>
10#include <asm/asm-compat.h> 10#include <asm/asm-compat.h>
11 11
12#define __futex_atomic_op(insn, ret, oldval, uaddr, oparg) \ 12#define __futex_atomic_op(insn, ret, oldval, uaddr, oparg) \
diff --git a/include/asm-powerpc/io.h b/include/asm-powerpc/io.h
index afae0697e8ce..e0062d73db1c 100644
--- a/include/asm-powerpc/io.h
+++ b/include/asm-powerpc/io.h
@@ -2,7 +2,7 @@
2#define _ASM_POWERPC_IO_H 2#define _ASM_POWERPC_IO_H
3#ifdef __KERNEL__ 3#ifdef __KERNEL__
4 4
5/* 5/*
6 * This program is free software; you can redistribute it and/or 6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License 7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 8 * as published by the Free Software Foundation; either version
@@ -18,6 +18,9 @@ extern int check_legacy_ioport(unsigned long base_port);
18#define _PNPWRP 0xa79 18#define _PNPWRP 0xa79
19#define PNPBIOS_BASE 0xf000 19#define PNPBIOS_BASE 0xf000
20 20
21#include <linux/device.h>
22#include <linux/io.h>
23
21#include <linux/compiler.h> 24#include <linux/compiler.h>
22#include <asm/page.h> 25#include <asm/page.h>
23#include <asm/byteorder.h> 26#include <asm/byteorder.h>
@@ -744,6 +747,9 @@ static inline void * bus_to_virt(unsigned long address)
744 747
745#define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set) 748#define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set)
746 749
750void __iomem *devm_ioremap_prot(struct device *dev, resource_size_t offset,
751 size_t size, unsigned long flags);
752
747#endif /* __KERNEL__ */ 753#endif /* __KERNEL__ */
748 754
749#endif /* _ASM_POWERPC_IO_H */ 755#endif /* _ASM_POWERPC_IO_H */
diff --git a/include/asm-powerpc/kvm_host.h b/include/asm-powerpc/kvm_host.h
index 04ffbb8e0a35..81a69d711017 100644
--- a/include/asm-powerpc/kvm_host.h
+++ b/include/asm-powerpc/kvm_host.h
@@ -59,6 +59,7 @@ struct kvm_vcpu_stat {
59 u32 emulated_inst_exits; 59 u32 emulated_inst_exits;
60 u32 dec_exits; 60 u32 dec_exits;
61 u32 ext_intr_exits; 61 u32 ext_intr_exits;
62 u32 halt_wakeup;
62}; 63};
63 64
64struct tlbe { 65struct tlbe {
diff --git a/include/asm-powerpc/kvm_ppc.h b/include/asm-powerpc/kvm_ppc.h
index 7ac820308a7e..b35a7e3ef978 100644
--- a/include/asm-powerpc/kvm_ppc.h
+++ b/include/asm-powerpc/kvm_ppc.h
@@ -77,12 +77,17 @@ static inline void kvmppc_clear_exception(struct kvm_vcpu *vcpu, int exception)
77 clear_bit(priority, &vcpu->arch.pending_exceptions); 77 clear_bit(priority, &vcpu->arch.pending_exceptions);
78} 78}
79 79
80/* Helper function for "full" MSR writes. No need to call this if only EE is
81 * changing. */
80static inline void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr) 82static inline void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr)
81{ 83{
82 if ((new_msr & MSR_PR) != (vcpu->arch.msr & MSR_PR)) 84 if ((new_msr & MSR_PR) != (vcpu->arch.msr & MSR_PR))
83 kvmppc_mmu_priv_switch(vcpu, new_msr & MSR_PR); 85 kvmppc_mmu_priv_switch(vcpu, new_msr & MSR_PR);
84 86
85 vcpu->arch.msr = new_msr; 87 vcpu->arch.msr = new_msr;
88
89 if (vcpu->arch.msr & MSR_WE)
90 kvm_vcpu_block(vcpu);
86} 91}
87 92
88#endif /* __POWERPC_KVM_PPC_H__ */ 93#endif /* __POWERPC_KVM_PPC_H__ */
diff --git a/include/asm-powerpc/ps3.h b/include/asm-powerpc/ps3.h
index 9e8ed6824e15..81ffe3b3c1ce 100644
--- a/include/asm-powerpc/ps3.h
+++ b/include/asm-powerpc/ps3.h
@@ -178,9 +178,6 @@ enum ps3_cpu_binding {
178 PS3_BINDING_CPU_1 = 1, 178 PS3_BINDING_CPU_1 = 1,
179}; 179};
180 180
181int ps3_virq_setup(enum ps3_cpu_binding cpu, unsigned long outlet,
182 unsigned int *virq);
183int ps3_virq_destroy(unsigned int virq);
184int ps3_irq_plug_setup(enum ps3_cpu_binding cpu, unsigned long outlet, 181int ps3_irq_plug_setup(enum ps3_cpu_binding cpu, unsigned long outlet,
185 unsigned int *virq); 182 unsigned int *virq);
186int ps3_irq_plug_destroy(unsigned int virq); 183int ps3_irq_plug_destroy(unsigned int virq);
diff --git a/include/asm-powerpc/syscalls.h b/include/asm-powerpc/syscalls.h
index b3ca41fc8bb1..2b8a458f990a 100644
--- a/include/asm-powerpc/syscalls.h
+++ b/include/asm-powerpc/syscalls.h
@@ -30,7 +30,7 @@ asmlinkage int sys_fork(unsigned long p1, unsigned long p2,
30asmlinkage int sys_vfork(unsigned long p1, unsigned long p2, 30asmlinkage int sys_vfork(unsigned long p1, unsigned long p2,
31 unsigned long p3, unsigned long p4, unsigned long p5, 31 unsigned long p3, unsigned long p4, unsigned long p5,
32 unsigned long p6, struct pt_regs *regs); 32 unsigned long p6, struct pt_regs *regs);
33asmlinkage int sys_pipe(int __user *fildes); 33asmlinkage long sys_pipe(int __user *fildes);
34asmlinkage long sys_rt_sigaction(int sig, 34asmlinkage long sys_rt_sigaction(int sig,
35 const struct sigaction __user *act, 35 const struct sigaction __user *act,
36 struct sigaction __user *oact, size_t sigsetsize); 36 struct sigaction __user *oact, size_t sigsetsize);
diff --git a/include/asm-powerpc/types.h b/include/asm-powerpc/types.h
index c243a6ac60e5..d3374bc865ba 100644
--- a/include/asm-powerpc/types.h
+++ b/include/asm-powerpc/types.h
@@ -1,6 +1,12 @@
1#ifndef _ASM_POWERPC_TYPES_H 1#ifndef _ASM_POWERPC_TYPES_H
2#define _ASM_POWERPC_TYPES_H 2#define _ASM_POWERPC_TYPES_H
3 3
4#ifdef __powerpc64__
5# include <asm-generic/int-l64.h>
6#else
7# include <asm-generic/int-ll64.h>
8#endif
9
4#ifndef __ASSEMBLY__ 10#ifndef __ASSEMBLY__
5 11
6/* 12/*
@@ -22,30 +28,6 @@ typedef unsigned int umode_t;
22typedef unsigned short umode_t; 28typedef unsigned short umode_t;
23#endif 29#endif
24 30
25/*
26 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
27 * header files exported to user space
28 */
29
30typedef __signed__ char __s8;
31typedef unsigned char __u8;
32
33typedef __signed__ short __s16;
34typedef unsigned short __u16;
35
36typedef __signed__ int __s32;
37typedef unsigned int __u32;
38
39#ifdef __powerpc64__
40typedef __signed__ long __s64;
41typedef unsigned long __u64;
42#else
43#if defined(__GNUC__)
44__extension__ typedef __signed__ long long __s64;
45__extension__ typedef unsigned long long __u64;
46#endif
47#endif /* __powerpc64__ */
48
49typedef struct { 31typedef struct {
50 __u32 u[4]; 32 __u32 u[4];
51} __attribute__((aligned(16))) __vector128; 33} __attribute__((aligned(16))) __vector128;
@@ -64,24 +46,6 @@ typedef struct {
64 46
65#ifndef __ASSEMBLY__ 47#ifndef __ASSEMBLY__
66 48
67
68typedef signed char s8;
69typedef unsigned char u8;
70
71typedef signed short s16;
72typedef unsigned short u16;
73
74typedef signed int s32;
75typedef unsigned int u32;
76
77#ifdef __powerpc64__
78typedef signed long s64;
79typedef unsigned long u64;
80#else
81typedef signed long long s64;
82typedef unsigned long long u64;
83#endif
84
85typedef __vector128 vector128; 49typedef __vector128 vector128;
86 50
87/* Physical address used by some IO functions */ 51/* Physical address used by some IO functions */
diff --git a/include/asm-s390/ccwgroup.h b/include/asm-s390/ccwgroup.h
index 289053ef5e60..a27f68985a79 100644
--- a/include/asm-s390/ccwgroup.h
+++ b/include/asm-s390/ccwgroup.h
@@ -57,10 +57,9 @@ struct ccwgroup_driver {
57 57
58extern int ccwgroup_driver_register (struct ccwgroup_driver *cdriver); 58extern int ccwgroup_driver_register (struct ccwgroup_driver *cdriver);
59extern void ccwgroup_driver_unregister (struct ccwgroup_driver *cdriver); 59extern void ccwgroup_driver_unregister (struct ccwgroup_driver *cdriver);
60extern int ccwgroup_create (struct device *root, 60int ccwgroup_create_from_string(struct device *root, unsigned int creator_id,
61 unsigned int creator_id, 61 struct ccw_driver *cdrv, int num_devices,
62 struct ccw_driver *gdrv, 62 const char *buf);
63 int argc, char *argv[]);
64 63
65extern int ccwgroup_probe_ccwdev(struct ccw_device *cdev); 64extern int ccwgroup_probe_ccwdev(struct ccw_device *cdev);
66extern void ccwgroup_remove_ccwdev(struct ccw_device *cdev); 65extern void ccwgroup_remove_ccwdev(struct ccw_device *cdev);
diff --git a/include/asm-s390/hugetlb.h b/include/asm-s390/hugetlb.h
new file mode 100644
index 000000000000..600a776f8f75
--- /dev/null
+++ b/include/asm-s390/hugetlb.h
@@ -0,0 +1,183 @@
1/*
2 * IBM System z Huge TLB Page Support for Kernel.
3 *
4 * Copyright IBM Corp. 2008
5 * Author(s): Gerald Schaefer <gerald.schaefer@de.ibm.com>
6 */
7
8#ifndef _ASM_S390_HUGETLB_H
9#define _ASM_S390_HUGETLB_H
10
11#include <asm/page.h>
12#include <asm/pgtable.h>
13
14
15#define is_hugepage_only_range(mm, addr, len) 0
16#define hugetlb_free_pgd_range free_pgd_range
17
18void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
19 pte_t *ptep, pte_t pte);
20
21/*
22 * If the arch doesn't supply something else, assume that hugepage
23 * size aligned regions are ok without further preparation.
24 */
25static inline int prepare_hugepage_range(unsigned long addr, unsigned long len)
26{
27 if (len & ~HPAGE_MASK)
28 return -EINVAL;
29 if (addr & ~HPAGE_MASK)
30 return -EINVAL;
31 return 0;
32}
33
34#define hugetlb_prefault_arch_hook(mm) do { } while (0)
35
36int arch_prepare_hugepage(struct page *page);
37void arch_release_hugepage(struct page *page);
38
39static inline pte_t pte_mkhuge(pte_t pte)
40{
41 /*
42 * PROT_NONE needs to be remapped from the pte type to the ste type.
43 * The HW invalid bit is also different for pte and ste. The pte
44 * invalid bit happens to be the same as the ste _SEGMENT_ENTRY_LARGE
45 * bit, so we don't have to clear it.
46 */
47 if (pte_val(pte) & _PAGE_INVALID) {
48 if (pte_val(pte) & _PAGE_SWT)
49 pte_val(pte) |= _HPAGE_TYPE_NONE;
50 pte_val(pte) |= _SEGMENT_ENTRY_INV;
51 }
52 /*
53 * Clear SW pte bits SWT and SWX, there are no SW bits in a segment
54 * table entry.
55 */
56 pte_val(pte) &= ~(_PAGE_SWT | _PAGE_SWX);
57 /*
58 * Also set the change-override bit because we don't need dirty bit
59 * tracking for hugetlbfs pages.
60 */
61 pte_val(pte) |= (_SEGMENT_ENTRY_LARGE | _SEGMENT_ENTRY_CO);
62 return pte;
63}
64
65static inline pte_t huge_pte_wrprotect(pte_t pte)
66{
67 pte_val(pte) |= _PAGE_RO;
68 return pte;
69}
70
71static inline int huge_pte_none(pte_t pte)
72{
73 return (pte_val(pte) & _SEGMENT_ENTRY_INV) &&
74 !(pte_val(pte) & _SEGMENT_ENTRY_RO);
75}
76
77static inline pte_t huge_ptep_get(pte_t *ptep)
78{
79 pte_t pte = *ptep;
80 unsigned long mask;
81
82 if (!MACHINE_HAS_HPAGE) {
83 ptep = (pte_t *) (pte_val(pte) & _SEGMENT_ENTRY_ORIGIN);
84 if (ptep) {
85 mask = pte_val(pte) &
86 (_SEGMENT_ENTRY_INV | _SEGMENT_ENTRY_RO);
87 pte = pte_mkhuge(*ptep);
88 pte_val(pte) |= mask;
89 }
90 }
91 return pte;
92}
93
94static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
95 unsigned long addr, pte_t *ptep)
96{
97 pte_t pte = huge_ptep_get(ptep);
98
99 pmd_clear((pmd_t *) ptep);
100 return pte;
101}
102
103static inline void __pmd_csp(pmd_t *pmdp)
104{
105 register unsigned long reg2 asm("2") = pmd_val(*pmdp);
106 register unsigned long reg3 asm("3") = pmd_val(*pmdp) |
107 _SEGMENT_ENTRY_INV;
108 register unsigned long reg4 asm("4") = ((unsigned long) pmdp) + 5;
109
110 asm volatile(
111 " csp %1,%3"
112 : "=m" (*pmdp)
113 : "d" (reg2), "d" (reg3), "d" (reg4), "m" (*pmdp) : "cc");
114 pmd_val(*pmdp) = _SEGMENT_ENTRY_INV | _SEGMENT_ENTRY;
115}
116
117static inline void __pmd_idte(unsigned long address, pmd_t *pmdp)
118{
119 unsigned long sto = (unsigned long) pmdp -
120 pmd_index(address) * sizeof(pmd_t);
121
122 if (!(pmd_val(*pmdp) & _SEGMENT_ENTRY_INV)) {
123 asm volatile(
124 " .insn rrf,0xb98e0000,%2,%3,0,0"
125 : "=m" (*pmdp)
126 : "m" (*pmdp), "a" (sto),
127 "a" ((address & HPAGE_MASK))
128 );
129 }
130 pmd_val(*pmdp) = _SEGMENT_ENTRY_INV | _SEGMENT_ENTRY;
131}
132
133static inline void huge_ptep_invalidate(struct mm_struct *mm,
134 unsigned long address, pte_t *ptep)
135{
136 pmd_t *pmdp = (pmd_t *) ptep;
137
138 if (!MACHINE_HAS_IDTE) {
139 __pmd_csp(pmdp);
140 if (mm->context.noexec) {
141 pmdp = get_shadow_table(pmdp);
142 __pmd_csp(pmdp);
143 }
144 return;
145 }
146
147 __pmd_idte(address, pmdp);
148 if (mm->context.noexec) {
149 pmdp = get_shadow_table(pmdp);
150 __pmd_idte(address, pmdp);
151 }
152 return;
153}
154
155#define huge_ptep_set_access_flags(__vma, __addr, __ptep, __entry, __dirty) \
156({ \
157 int __changed = !pte_same(huge_ptep_get(__ptep), __entry); \
158 if (__changed) { \
159 huge_ptep_invalidate((__vma)->vm_mm, __addr, __ptep); \
160 set_huge_pte_at((__vma)->vm_mm, __addr, __ptep, __entry); \
161 } \
162 __changed; \
163})
164
165#define huge_ptep_set_wrprotect(__mm, __addr, __ptep) \
166({ \
167 pte_t __pte = huge_ptep_get(__ptep); \
168 if (pte_write(__pte)) { \
169 if (atomic_read(&(__mm)->mm_users) > 1 || \
170 (__mm) != current->active_mm) \
171 huge_ptep_invalidate(__mm, __addr, __ptep); \
172 set_huge_pte_at(__mm, __addr, __ptep, \
173 huge_pte_wrprotect(__pte)); \
174 } \
175})
176
177static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,
178 unsigned long address, pte_t *ptep)
179{
180 huge_ptep_invalidate(vma->vm_mm, address, ptep);
181}
182
183#endif /* _ASM_S390_HUGETLB_H */
diff --git a/include/asm-s390/page.h b/include/asm-s390/page.h
index fe7f92b6ae6d..f0f4579eac13 100644
--- a/include/asm-s390/page.h
+++ b/include/asm-s390/page.h
@@ -19,17 +19,34 @@
19#define PAGE_DEFAULT_ACC 0 19#define PAGE_DEFAULT_ACC 0
20#define PAGE_DEFAULT_KEY (PAGE_DEFAULT_ACC << 4) 20#define PAGE_DEFAULT_KEY (PAGE_DEFAULT_ACC << 4)
21 21
22#define HPAGE_SHIFT 20
23#define HPAGE_SIZE (1UL << HPAGE_SHIFT)
24#define HPAGE_MASK (~(HPAGE_SIZE - 1))
25#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
26
27#define ARCH_HAS_SETCLEAR_HUGE_PTE
28#define ARCH_HAS_HUGE_PTE_TYPE
29#define ARCH_HAS_PREPARE_HUGEPAGE
30#define ARCH_HAS_HUGEPAGE_CLEAR_FLUSH
31
22#include <asm/setup.h> 32#include <asm/setup.h>
23#ifndef __ASSEMBLY__ 33#ifndef __ASSEMBLY__
24 34
25static inline void clear_page(void *page) 35static inline void clear_page(void *page)
26{ 36{
27 register unsigned long reg1 asm ("1") = 0; 37 if (MACHINE_HAS_PFMF) {
28 register void *reg2 asm ("2") = page; 38 asm volatile(
29 register unsigned long reg3 asm ("3") = 4096; 39 " .insn rre,0xb9af0000,%0,%1"
30 asm volatile( 40 : : "d" (0x10000), "a" (page) : "memory", "cc");
31 " mvcl 2,0" 41 } else {
32 : "+d" (reg2), "+d" (reg3) : "d" (reg1) : "memory", "cc"); 42 register unsigned long reg1 asm ("1") = 0;
43 register void *reg2 asm ("2") = page;
44 register unsigned long reg3 asm ("3") = 4096;
45 asm volatile(
46 " mvcl 2,0"
47 : "+d" (reg2), "+d" (reg3) : "d" (reg1)
48 : "memory", "cc");
49 }
33} 50}
34 51
35static inline void copy_page(void *to, void *from) 52static inline void copy_page(void *to, void *from)
@@ -108,26 +125,6 @@ page_get_storage_key(unsigned long addr)
108 return skey; 125 return skey;
109} 126}
110 127
111extern unsigned long max_pfn;
112
113static inline int pfn_valid(unsigned long pfn)
114{
115 unsigned long dummy;
116 int ccode;
117
118 if (pfn >= max_pfn)
119 return 0;
120
121 asm volatile(
122 " lra %0,0(%2)\n"
123 " ipm %1\n"
124 " srl %1,28\n"
125 : "=d" (dummy), "=d" (ccode)
126 : "a" (pfn << PAGE_SHIFT)
127 : "cc");
128 return !ccode;
129}
130
131#endif /* !__ASSEMBLY__ */ 128#endif /* !__ASSEMBLY__ */
132 129
133/* to align the pointer to the (next) page boundary */ 130/* to align the pointer to the (next) page boundary */
diff --git a/include/asm-s390/pgtable.h b/include/asm-s390/pgtable.h
index f8347ce9c5a1..c7f4f8e3e297 100644
--- a/include/asm-s390/pgtable.h
+++ b/include/asm-s390/pgtable.h
@@ -129,7 +129,7 @@ extern char empty_zero_page[PAGE_SIZE];
129#define VMEM_MAX_PAGES ((VMEM_MAP_END - VMALLOC_END) / sizeof(struct page)) 129#define VMEM_MAX_PAGES ((VMEM_MAP_END - VMALLOC_END) / sizeof(struct page))
130#define VMEM_MAX_PFN min(VMALLOC_START >> PAGE_SHIFT, VMEM_MAX_PAGES) 130#define VMEM_MAX_PFN min(VMALLOC_START >> PAGE_SHIFT, VMEM_MAX_PAGES)
131#define VMEM_MAX_PHYS ((VMEM_MAX_PFN << PAGE_SHIFT) & ~((16 << 20) - 1)) 131#define VMEM_MAX_PHYS ((VMEM_MAX_PFN << PAGE_SHIFT) & ~((16 << 20) - 1))
132#define VMEM_MAP ((struct page *) VMALLOC_END) 132#define vmemmap ((struct page *) VMALLOC_END)
133 133
134/* 134/*
135 * A 31 bit pagetable entry of S390 has following format: 135 * A 31 bit pagetable entry of S390 has following format:
@@ -234,6 +234,15 @@ extern char empty_zero_page[PAGE_SIZE];
234#define _PAGE_TYPE_EX_RW 0x002 234#define _PAGE_TYPE_EX_RW 0x002
235 235
236/* 236/*
237 * Only four types for huge pages, using the invalid bit and protection bit
238 * of a segment table entry.
239 */
240#define _HPAGE_TYPE_EMPTY 0x020 /* _SEGMENT_ENTRY_INV */
241#define _HPAGE_TYPE_NONE 0x220
242#define _HPAGE_TYPE_RO 0x200 /* _SEGMENT_ENTRY_RO */
243#define _HPAGE_TYPE_RW 0x000
244
245/*
237 * PTE type bits are rather complicated. handle_pte_fault uses pte_present, 246 * PTE type bits are rather complicated. handle_pte_fault uses pte_present,
238 * pte_none and pte_file to find out the pte type WITHOUT holding the page 247 * pte_none and pte_file to find out the pte type WITHOUT holding the page
239 * table lock. ptep_clear_flush on the other hand uses ptep_clear_flush to 248 * table lock. ptep_clear_flush on the other hand uses ptep_clear_flush to
@@ -325,6 +334,9 @@ extern char empty_zero_page[PAGE_SIZE];
325#define _SEGMENT_ENTRY (0) 334#define _SEGMENT_ENTRY (0)
326#define _SEGMENT_ENTRY_EMPTY (_SEGMENT_ENTRY_INV) 335#define _SEGMENT_ENTRY_EMPTY (_SEGMENT_ENTRY_INV)
327 336
337#define _SEGMENT_ENTRY_LARGE 0x400 /* STE-format control, large page */
338#define _SEGMENT_ENTRY_CO 0x100 /* change-recording override */
339
328#endif /* __s390x__ */ 340#endif /* __s390x__ */
329 341
330/* 342/*
@@ -1063,8 +1075,8 @@ static inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
1063 1075
1064#define kern_addr_valid(addr) (1) 1076#define kern_addr_valid(addr) (1)
1065 1077
1066extern int add_shared_memory(unsigned long start, unsigned long size); 1078extern int vmem_add_mapping(unsigned long start, unsigned long size);
1067extern int remove_shared_memory(unsigned long start, unsigned long size); 1079extern int vmem_remove_mapping(unsigned long start, unsigned long size);
1068extern int s390_enable_sie(void); 1080extern int s390_enable_sie(void);
1069 1081
1070/* 1082/*
@@ -1072,9 +1084,6 @@ extern int s390_enable_sie(void);
1072 */ 1084 */
1073#define pgtable_cache_init() do { } while (0) 1085#define pgtable_cache_init() do { } while (0)
1074 1086
1075#define __HAVE_ARCH_MEMMAP_INIT
1076extern void memmap_init(unsigned long, int, unsigned long, unsigned long);
1077
1078#include <asm-generic/pgtable.h> 1087#include <asm-generic/pgtable.h>
1079 1088
1080#endif /* _S390_PAGE_H */ 1089#endif /* _S390_PAGE_H */
diff --git a/include/asm-s390/processor.h b/include/asm-s390/processor.h
index 8eaf343a12a8..a00f79dd323b 100644
--- a/include/asm-s390/processor.h
+++ b/include/asm-s390/processor.h
@@ -172,16 +172,7 @@ extern unsigned long thread_saved_pc(struct task_struct *t);
172 */ 172 */
173extern void task_show_regs(struct seq_file *m, struct task_struct *task); 173extern void task_show_regs(struct seq_file *m, struct task_struct *task);
174 174
175extern void show_registers(struct pt_regs *regs);
176extern void show_code(struct pt_regs *regs); 175extern void show_code(struct pt_regs *regs);
177extern void show_trace(struct task_struct *task, unsigned long *sp);
178#ifdef CONFIG_64BIT
179extern void show_last_breaking_event(struct pt_regs *regs);
180#else
181static inline void show_last_breaking_event(struct pt_regs *regs)
182{
183}
184#endif
185 176
186unsigned long get_wchan(struct task_struct *p); 177unsigned long get_wchan(struct task_struct *p);
187#define task_pt_regs(tsk) ((struct pt_regs *) \ 178#define task_pt_regs(tsk) ((struct pt_regs *) \
diff --git a/include/asm-s390/ptrace.h b/include/asm-s390/ptrace.h
index 61f6952f2e35..441d7c260857 100644
--- a/include/asm-s390/ptrace.h
+++ b/include/asm-s390/ptrace.h
@@ -463,8 +463,6 @@ struct user_regs_struct
463}; 463};
464 464
465#ifdef __KERNEL__ 465#ifdef __KERNEL__
466#define __ARCH_SYS_PTRACE 1
467
468/* 466/*
469 * These are defined as per linux/ptrace.h, which see. 467 * These are defined as per linux/ptrace.h, which see.
470 */ 468 */
diff --git a/include/asm-s390/qdio.h b/include/asm-s390/qdio.h
index 4b8ff55f680e..11240342a0f4 100644
--- a/include/asm-s390/qdio.h
+++ b/include/asm-s390/qdio.h
@@ -127,6 +127,7 @@ extern int do_QDIO(struct ccw_device*, unsigned int flags,
127 unsigned int qidx,unsigned int count, 127 unsigned int qidx,unsigned int count,
128 struct qdio_buffer *buffers); 128 struct qdio_buffer *buffers);
129 129
130extern int qdio_get_ssqd_pct(struct ccw_device*);
130extern int qdio_synchronize(struct ccw_device*, unsigned int flags, 131extern int qdio_synchronize(struct ccw_device*, unsigned int flags,
131 unsigned int queue_number); 132 unsigned int queue_number);
132 133
diff --git a/include/asm-s390/setup.h b/include/asm-s390/setup.h
index aaf4b518b940..ba69674012a7 100644
--- a/include/asm-s390/setup.h
+++ b/include/asm-s390/setup.h
@@ -59,23 +59,42 @@ extern unsigned int s390_noexec;
59 */ 59 */
60extern unsigned long machine_flags; 60extern unsigned long machine_flags;
61 61
62#define MACHINE_IS_VM (machine_flags & 1) 62#define MACHINE_FLAG_VM (1UL << 0)
63#define MACHINE_IS_P390 (machine_flags & 4) 63#define MACHINE_FLAG_IEEE (1UL << 1)
64#define MACHINE_HAS_MVPG (machine_flags & 16) 64#define MACHINE_FLAG_P390 (1UL << 2)
65#define MACHINE_IS_KVM (machine_flags & 64) 65#define MACHINE_FLAG_CSP (1UL << 3)
66#define MACHINE_HAS_IDTE (machine_flags & 128) 66#define MACHINE_FLAG_MVPG (1UL << 4)
67#define MACHINE_HAS_DIAG9C (machine_flags & 256) 67#define MACHINE_FLAG_DIAG44 (1UL << 5)
68#define MACHINE_FLAG_IDTE (1UL << 6)
69#define MACHINE_FLAG_DIAG9C (1UL << 7)
70#define MACHINE_FLAG_MVCOS (1UL << 8)
71#define MACHINE_FLAG_KVM (1UL << 9)
72#define MACHINE_FLAG_HPAGE (1UL << 10)
73#define MACHINE_FLAG_PFMF (1UL << 11)
74
75#define MACHINE_IS_VM (machine_flags & MACHINE_FLAG_VM)
76#define MACHINE_IS_KVM (machine_flags & MACHINE_FLAG_KVM)
77#define MACHINE_IS_P390 (machine_flags & MACHINE_FLAG_P390)
78#define MACHINE_HAS_DIAG9C (machine_flags & MACHINE_FLAG_DIAG9C)
68 79
69#ifndef __s390x__ 80#ifndef __s390x__
70#define MACHINE_HAS_IEEE (machine_flags & 2) 81#define MACHINE_HAS_IEEE (machine_flags & MACHINE_FLAG_IEEE)
71#define MACHINE_HAS_CSP (machine_flags & 8) 82#define MACHINE_HAS_CSP (machine_flags & MACHINE_FLAG_CSP)
83#define MACHINE_HAS_IDTE (0)
72#define MACHINE_HAS_DIAG44 (1) 84#define MACHINE_HAS_DIAG44 (1)
85#define MACHINE_HAS_MVPG (machine_flags & MACHINE_FLAG_MVPG)
73#define MACHINE_HAS_MVCOS (0) 86#define MACHINE_HAS_MVCOS (0)
87#define MACHINE_HAS_HPAGE (0)
88#define MACHINE_HAS_PFMF (0)
74#else /* __s390x__ */ 89#else /* __s390x__ */
75#define MACHINE_HAS_IEEE (1) 90#define MACHINE_HAS_IEEE (1)
76#define MACHINE_HAS_CSP (1) 91#define MACHINE_HAS_CSP (1)
77#define MACHINE_HAS_DIAG44 (machine_flags & 32) 92#define MACHINE_HAS_IDTE (machine_flags & MACHINE_FLAG_IDTE)
78#define MACHINE_HAS_MVCOS (machine_flags & 512) 93#define MACHINE_HAS_DIAG44 (machine_flags & MACHINE_FLAG_DIAG44)
94#define MACHINE_HAS_MVPG (1)
95#define MACHINE_HAS_MVCOS (machine_flags & MACHINE_FLAG_MVCOS)
96#define MACHINE_HAS_HPAGE (machine_flags & MACHINE_FLAG_HPAGE)
97#define MACHINE_HAS_PFMF (machine_flags & MACHINE_FLAG_PFMF)
79#endif /* __s390x__ */ 98#endif /* __s390x__ */
80 99
81#define MACHINE_HAS_SCLP (!MACHINE_IS_P390) 100#define MACHINE_HAS_SCLP (!MACHINE_IS_P390)
diff --git a/include/asm-s390/smp.h b/include/asm-s390/smp.h
index 6f3821a6a902..ae89cf2478fc 100644
--- a/include/asm-s390/smp.h
+++ b/include/asm-s390/smp.h
@@ -19,6 +19,7 @@
19#include <asm/lowcore.h> 19#include <asm/lowcore.h>
20#include <asm/sigp.h> 20#include <asm/sigp.h>
21#include <asm/ptrace.h> 21#include <asm/ptrace.h>
22#include <asm/system.h>
22 23
23/* 24/*
24 s390 specific smp.c headers 25 s390 specific smp.c headers
@@ -53,10 +54,7 @@ extern void machine_power_off_smp(void);
53 54
54static inline __u16 hard_smp_processor_id(void) 55static inline __u16 hard_smp_processor_id(void)
55{ 56{
56 __u16 cpu_address; 57 return stap();
57
58 asm volatile("stap %0" : "=m" (cpu_address));
59 return cpu_address;
60} 58}
61 59
62/* 60/*
@@ -108,5 +106,11 @@ static inline void smp_send_stop(void)
108#define smp_cpu_not_running(cpu) 1 106#define smp_cpu_not_running(cpu) 1
109#endif 107#endif
110 108
109#ifdef CONFIG_HOTPLUG_CPU
110extern int smp_rescan_cpus(void);
111#else
112static inline int smp_rescan_cpus(void) { return 0; }
113#endif
114
111extern union save_area *zfcpdump_save_areas[NR_CPUS + 1]; 115extern union save_area *zfcpdump_save_areas[NR_CPUS + 1];
112#endif 116#endif
diff --git a/include/asm-s390/sparsemem.h b/include/asm-s390/sparsemem.h
new file mode 100644
index 000000000000..06dfdab6c0e8
--- /dev/null
+++ b/include/asm-s390/sparsemem.h
@@ -0,0 +1,18 @@
1#ifndef _ASM_S390_SPARSEMEM_H
2#define _ASM_S390_SPARSEMEM_H
3
4#define SECTION_SIZE_BITS 25
5
6#ifdef CONFIG_64BIT
7
8#define MAX_PHYSADDR_BITS 42
9#define MAX_PHYSMEM_BITS 42
10
11#else
12
13#define MAX_PHYSADDR_BITS 31
14#define MAX_PHYSMEM_BITS 31
15
16#endif /* CONFIG_64BIT */
17
18#endif /* _ASM_S390_SPARSEMEM_H */
diff --git a/include/asm-s390/sysinfo.h b/include/asm-s390/sysinfo.h
index abe10ae15e46..79d01343f8b0 100644
--- a/include/asm-s390/sysinfo.h
+++ b/include/asm-s390/sysinfo.h
@@ -11,6 +11,9 @@
11 * Christian Borntraeger <borntraeger@de.ibm.com> 11 * Christian Borntraeger <borntraeger@de.ibm.com>
12 */ 12 */
13 13
14#ifndef __ASM_S390_SYSINFO_H
15#define __ASM_S390_SYSINFO_H
16
14struct sysinfo_1_1_1 { 17struct sysinfo_1_1_1 {
15 char reserved_0[32]; 18 char reserved_0[32];
16 char manufacturer[16]; 19 char manufacturer[16];
@@ -114,3 +117,5 @@ static inline int stsi(void *sysinfo, int fc, int sel1, int sel2)
114 : "cc", "memory"); 117 : "cc", "memory");
115 return r0; 118 return r0;
116} 119}
120
121#endif /* __ASM_S390_SYSINFO_H */
diff --git a/include/asm-s390/system.h b/include/asm-s390/system.h
index 92098df4d6e3..c819ae25a842 100644
--- a/include/asm-s390/system.h
+++ b/include/asm-s390/system.h
@@ -16,6 +16,7 @@
16#include <asm/ptrace.h> 16#include <asm/ptrace.h>
17#include <asm/setup.h> 17#include <asm/setup.h>
18#include <asm/processor.h> 18#include <asm/processor.h>
19#include <asm/lowcore.h>
19 20
20#ifdef __KERNEL__ 21#ifdef __KERNEL__
21 22
@@ -422,6 +423,23 @@ extern void smp_ctl_clear_bit(int cr, int bit);
422 423
423#endif /* CONFIG_SMP */ 424#endif /* CONFIG_SMP */
424 425
426static inline unsigned int stfl(void)
427{
428 asm volatile(
429 " .insn s,0xb2b10000,0(0)\n" /* stfl */
430 "0:\n"
431 EX_TABLE(0b,0b));
432 return S390_lowcore.stfl_fac_list;
433}
434
435static inline unsigned short stap(void)
436{
437 unsigned short cpu_address;
438
439 asm volatile("stap %0" : "=m" (cpu_address));
440 return cpu_address;
441}
442
425extern void (*_machine_restart)(char *command); 443extern void (*_machine_restart)(char *command);
426extern void (*_machine_halt)(void); 444extern void (*_machine_halt)(void);
427extern void (*_machine_power_off)(void); 445extern void (*_machine_power_off)(void);
diff --git a/include/asm-s390/thread_info.h b/include/asm-s390/thread_info.h
index 0a518915bf90..99bbed99a3b2 100644
--- a/include/asm-s390/thread_info.h
+++ b/include/asm-s390/thread_info.h
@@ -89,7 +89,6 @@ static inline struct thread_info *current_thread_info(void)
89 * thread information flags bit numbers 89 * thread information flags bit numbers
90 */ 90 */
91#define TIF_SYSCALL_TRACE 0 /* syscall trace active */ 91#define TIF_SYSCALL_TRACE 0 /* syscall trace active */
92#define TIF_RESTORE_SIGMASK 1 /* restore signal mask in do_signal() */
93#define TIF_SIGPENDING 2 /* signal pending */ 92#define TIF_SIGPENDING 2 /* signal pending */
94#define TIF_NEED_RESCHED 3 /* rescheduling necessary */ 93#define TIF_NEED_RESCHED 3 /* rescheduling necessary */
95#define TIF_RESTART_SVC 4 /* restart svc with new svc number */ 94#define TIF_RESTART_SVC 4 /* restart svc with new svc number */
@@ -101,6 +100,7 @@ static inline struct thread_info *current_thread_info(void)
101 TIF_NEED_RESCHED */ 100 TIF_NEED_RESCHED */
102#define TIF_31BIT 18 /* 32bit process */ 101#define TIF_31BIT 18 /* 32bit process */
103#define TIF_MEMDIE 19 102#define TIF_MEMDIE 19
103#define TIF_RESTORE_SIGMASK 20 /* restore signal mask in do_signal() */
104 104
105#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE) 105#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
106#define _TIF_RESTORE_SIGMASK (1<<TIF_RESTORE_SIGMASK) 106#define _TIF_RESTORE_SIGMASK (1<<TIF_RESTORE_SIGMASK)
diff --git a/include/asm-s390/tlbflush.h b/include/asm-s390/tlbflush.h
index 9e57a93d7de1..d60394b9745e 100644
--- a/include/asm-s390/tlbflush.h
+++ b/include/asm-s390/tlbflush.h
@@ -2,6 +2,7 @@
2#define _S390_TLBFLUSH_H 2#define _S390_TLBFLUSH_H
3 3
4#include <linux/mm.h> 4#include <linux/mm.h>
5#include <linux/sched.h>
5#include <asm/processor.h> 6#include <asm/processor.h>
6#include <asm/pgalloc.h> 7#include <asm/pgalloc.h>
7 8
diff --git a/include/asm-s390/topology.h b/include/asm-s390/topology.h
index 8e97b06f298a..d96c91643458 100644
--- a/include/asm-s390/topology.h
+++ b/include/asm-s390/topology.h
@@ -7,6 +7,10 @@
7 7
8cpumask_t cpu_coregroup_map(unsigned int cpu); 8cpumask_t cpu_coregroup_map(unsigned int cpu);
9 9
10extern cpumask_t cpu_core_map[NR_CPUS];
11
12#define topology_core_siblings(cpu) (cpu_core_map[cpu])
13
10int topology_set_cpu_management(int fc); 14int topology_set_cpu_management(int fc);
11void topology_schedule_update(void); 15void topology_schedule_update(void);
12 16
diff --git a/include/asm-s390/types.h b/include/asm-s390/types.h
index 2c5879ae90ca..78dda038dd47 100644
--- a/include/asm-s390/types.h
+++ b/include/asm-s390/types.h
@@ -9,34 +9,16 @@
9#ifndef _S390_TYPES_H 9#ifndef _S390_TYPES_H
10#define _S390_TYPES_H 10#define _S390_TYPES_H
11 11
12#ifndef __s390x__
13# include <asm-generic/int-l64.h>
14#else
15# include <asm-generic/int-ll64.h>
16#endif
17
12#ifndef __ASSEMBLY__ 18#ifndef __ASSEMBLY__
13 19
14typedef unsigned short umode_t; 20typedef unsigned short umode_t;
15 21
16/*
17 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
18 * header files exported to user space
19 */
20
21typedef __signed__ char __s8;
22typedef unsigned char __u8;
23
24typedef __signed__ short __s16;
25typedef unsigned short __u16;
26
27typedef __signed__ int __s32;
28typedef unsigned int __u32;
29
30#ifndef __s390x__
31#if defined(__GNUC__)
32__extension__ typedef __signed__ long long __s64;
33__extension__ typedef unsigned long long __u64;
34#endif
35#else /* __s390x__ */
36typedef __signed__ long __s64;
37typedef unsigned long __u64;
38#endif
39
40/* A address type so that arithmetic can be done on it & it can be upgraded to 22/* A address type so that arithmetic can be done on it & it can be upgraded to
41 64 bit when necessary 23 64 bit when necessary
42*/ 24*/
@@ -58,24 +40,6 @@ typedef __signed__ long saddr_t;
58 40
59#ifndef __ASSEMBLY__ 41#ifndef __ASSEMBLY__
60 42
61
62typedef signed char s8;
63typedef unsigned char u8;
64
65typedef signed short s16;
66typedef unsigned short u16;
67
68typedef signed int s32;
69typedef unsigned int u32;
70
71#ifndef __s390x__
72typedef signed long long s64;
73typedef unsigned long long u64;
74#else /* __s390x__ */
75typedef signed long s64;
76typedef unsigned long u64;
77#endif /* __s390x__ */
78
79typedef u32 dma_addr_t; 43typedef u32 dma_addr_t;
80 44
81#ifndef __s390x__ 45#ifndef __s390x__
diff --git a/include/asm-sh/futex.h b/include/asm-sh/futex.h
index 74ed3681d33c..68256ec5fa35 100644
--- a/include/asm-sh/futex.h
+++ b/include/asm-sh/futex.h
@@ -4,8 +4,8 @@
4#ifdef __KERNEL__ 4#ifdef __KERNEL__
5 5
6#include <linux/futex.h> 6#include <linux/futex.h>
7#include <linux/uaccess.h>
7#include <asm/errno.h> 8#include <asm/errno.h>
8#include <asm/uaccess.h>
9 9
10/* XXX: UP variants, fix for SH-4A and SMP.. */ 10/* XXX: UP variants, fix for SH-4A and SMP.. */
11#include <asm/futex-irq.h> 11#include <asm/futex-irq.h>
diff --git a/include/asm-sh/types.h b/include/asm-sh/types.h
index a6e1d4126e67..beea4e6f8dfd 100644
--- a/include/asm-sh/types.h
+++ b/include/asm-sh/types.h
@@ -1,29 +1,12 @@
1#ifndef __ASM_SH_TYPES_H 1#ifndef __ASM_SH_TYPES_H
2#define __ASM_SH_TYPES_H 2#define __ASM_SH_TYPES_H
3 3
4#include <asm-generic/int-ll64.h>
5
4#ifndef __ASSEMBLY__ 6#ifndef __ASSEMBLY__
5 7
6typedef unsigned short umode_t; 8typedef unsigned short umode_t;
7 9
8/*
9 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
10 * header files exported to user space
11 */
12
13typedef __signed__ char __s8;
14typedef unsigned char __u8;
15
16typedef __signed__ short __s16;
17typedef unsigned short __u16;
18
19typedef __signed__ int __s32;
20typedef unsigned int __u32;
21
22#if defined(__GNUC__)
23__extension__ typedef __signed__ long long __s64;
24__extension__ typedef unsigned long long __u64;
25#endif
26
27#endif /* __ASSEMBLY__ */ 10#endif /* __ASSEMBLY__ */
28 11
29/* 12/*
@@ -35,19 +18,6 @@ __extension__ typedef unsigned long long __u64;
35 18
36#ifndef __ASSEMBLY__ 19#ifndef __ASSEMBLY__
37 20
38
39typedef __signed__ char s8;
40typedef unsigned char u8;
41
42typedef __signed__ short s16;
43typedef unsigned short u16;
44
45typedef __signed__ int s32;
46typedef unsigned int u32;
47
48typedef __signed__ long long s64;
49typedef unsigned long long u64;
50
51/* Dma addresses are 32-bits wide. */ 21/* Dma addresses are 32-bits wide. */
52 22
53typedef u32 dma_addr_t; 23typedef u32 dma_addr_t;
diff --git a/include/asm-sparc/head.h b/include/asm-sparc/head.h
index fcdba5116339..e6532c3e09c9 100644
--- a/include/asm-sparc/head.h
+++ b/include/asm-sparc/head.h
@@ -52,6 +52,17 @@
52 nop; \ 52 nop; \
53 nop; 53 nop;
54 54
55#ifdef CONFIG_KGDB
56#define KGDB_TRAP(num) \
57 b kgdb_trap_low; \
58 rd %psr,%l0; \
59 nop; \
60 nop;
61#else
62#define KGDB_TRAP(num) \
63 BAD_TRAP(num)
64#endif
65
55/* The Get Condition Codes software trap for userland. */ 66/* The Get Condition Codes software trap for userland. */
56#define GETCC_TRAP \ 67#define GETCC_TRAP \
57 b getcc_trap_handler; mov %psr, %l0; nop; nop; 68 b getcc_trap_handler; mov %psr, %l0; nop; nop;
diff --git a/include/asm-sparc/kgdb.h b/include/asm-sparc/kgdb.h
index d120adfb429f..b6ef301d05bf 100644
--- a/include/asm-sparc/kgdb.h
+++ b/include/asm-sparc/kgdb.h
@@ -1,94 +1,38 @@
1/* $Id: kgdb.h,v 1.8 1998/01/07 06:33:44 baccala Exp $
2 * kgdb.h: Defines and declarations for serial line source level
3 * remote debugging of the Linux kernel using gdb.
4 *
5 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
6 */
7#ifndef _SPARC_KGDB_H 1#ifndef _SPARC_KGDB_H
8#define _SPARC_KGDB_H 2#define _SPARC_KGDB_H
9 3
10#ifndef __ASSEMBLY__ 4#ifdef CONFIG_SPARC32
11/* To init the kgdb engine. */ 5#define BUFMAX 2048
12extern void set_debug_traps(void); 6#else
13 7#define BUFMAX 4096
14/* To enter the debugger explicitly. */ 8#endif
15extern void breakpoint(void); 9
16 10enum regnames {
17/* For convenience we define the format of a kgdb trap breakpoint 11 GDB_G0, GDB_G1, GDB_G2, GDB_G3, GDB_G4, GDB_G5, GDB_G6, GDB_G7,
18 * frame here also. 12 GDB_O0, GDB_O1, GDB_O2, GDB_O3, GDB_O4, GDB_O5, GDB_SP, GDB_O7,
19 */ 13 GDB_L0, GDB_L1, GDB_L2, GDB_L3, GDB_L4, GDB_L5, GDB_L6, GDB_L7,
20struct kgdb_frame { 14 GDB_I0, GDB_I1, GDB_I2, GDB_I3, GDB_I4, GDB_I5, GDB_FP, GDB_I7,
21 unsigned long globals[8]; 15 GDB_F0,
22 unsigned long outs[8]; 16 GDB_F31 = GDB_F0 + 31,
23 unsigned long locals[8]; 17#ifdef CONFIG_SPARC32
24 unsigned long ins[8]; 18 GDB_Y, GDB_PSR, GDB_WIM, GDB_TBR, GDB_PC, GDB_NPC,
25 unsigned long fpregs[32]; 19 GDB_FSR, GDB_CSR,
26 unsigned long y; 20#else
27 unsigned long psr; 21 GDB_F32 = GDB_F0 + 32,
28 unsigned long wim; 22 GDB_F62 = GDB_F32 + 15,
29 unsigned long tbr; 23 GDB_PC, GDB_NPC, GDB_STATE, GDB_FSR, GDB_FPRS, GDB_Y,
30 unsigned long pc; 24#endif
31 unsigned long npc;
32 unsigned long fpsr;
33 unsigned long cpsr;
34}; 25};
35#endif /* !(__ASSEMBLY__) */
36
37/* Macros for assembly usage of the kgdb breakpoint frame. */
38#define KGDB_G0 0x000
39#define KGDB_G1 0x004
40#define KGDB_G2 0x008
41#define KGDB_G4 0x010
42#define KGDB_G6 0x018
43#define KGDB_I0 0x020
44#define KGDB_I2 0x028
45#define KGDB_I4 0x030
46#define KGDB_I6 0x038
47#define KGDB_Y 0x100
48#define KGDB_PSR 0x104
49#define KGDB_WIM 0x108
50#define KGDB_TBR 0x10c
51#define KGDB_PC 0x110
52#define KGDB_NPC 0x114
53
54#define SAVE_KGDB_GLOBALS(reg) \
55 std %g0, [%reg + STACKFRAME_SZ + KGDB_G0]; \
56 std %g2, [%reg + STACKFRAME_SZ + KGDB_G2]; \
57 std %g4, [%reg + STACKFRAME_SZ + KGDB_G4]; \
58 std %g6, [%reg + STACKFRAME_SZ + KGDB_G6];
59
60#define SAVE_KGDB_INS(reg) \
61 std %i0, [%reg + STACKFRAME_SZ + KGDB_I0]; \
62 std %i2, [%reg + STACKFRAME_SZ + KGDB_I2]; \
63 std %i4, [%reg + STACKFRAME_SZ + KGDB_I4]; \
64 std %i6, [%reg + STACKFRAME_SZ + KGDB_I6];
65
66#define SAVE_KGDB_SREGS(reg, reg_y, reg_psr, reg_wim, reg_tbr, reg_pc, reg_npc) \
67 st %reg_y, [%reg + STACKFRAME_SZ + KGDB_Y]; \
68 st %reg_psr, [%reg + STACKFRAME_SZ + KGDB_PSR]; \
69 st %reg_wim, [%reg + STACKFRAME_SZ + KGDB_WIM]; \
70 st %reg_tbr, [%reg + STACKFRAME_SZ + KGDB_TBR]; \
71 st %reg_pc, [%reg + STACKFRAME_SZ + KGDB_PC]; \
72 st %reg_npc, [%reg + STACKFRAME_SZ + KGDB_NPC];
73 26
74#define LOAD_KGDB_GLOBALS(reg) \ 27#ifdef CONFIG_SPARC32
75 ld [%reg + STACKFRAME_SZ + KGDB_G1], %g1; \ 28#define NUMREGBYTES ((GDB_CSR + 1) * 4)
76 ldd [%reg + STACKFRAME_SZ + KGDB_G2], %g2; \ 29#else
77 ldd [%reg + STACKFRAME_SZ + KGDB_G4], %g4; \ 30#define NUMREGBYTES ((GDB_Y + 1) * 8)
78 ldd [%reg + STACKFRAME_SZ + KGDB_G6], %g6; 31#endif
79 32
80#define LOAD_KGDB_INS(reg) \ 33extern void arch_kgdb_breakpoint(void);
81 ldd [%reg + STACKFRAME_SZ + KGDB_I0], %i0; \
82 ldd [%reg + STACKFRAME_SZ + KGDB_I2], %i2; \
83 ldd [%reg + STACKFRAME_SZ + KGDB_I4], %i4; \
84 ldd [%reg + STACKFRAME_SZ + KGDB_I6], %i6;
85 34
86#define LOAD_KGDB_SREGS(reg, reg_y, reg_psr, reg_wim, reg_tbr, reg_pc, reg_npc) \ 35#define BREAK_INSTR_SIZE 4
87 ld [%reg + STACKFRAME_SZ + KGDB_Y], %reg_y; \ 36#define CACHE_FLUSH_IS_SAFE 1
88 ld [%reg + STACKFRAME_SZ + KGDB_PSR], %reg_psr; \
89 ld [%reg + STACKFRAME_SZ + KGDB_WIM], %reg_wim; \
90 ld [%reg + STACKFRAME_SZ + KGDB_TBR], %reg_tbr; \
91 ld [%reg + STACKFRAME_SZ + KGDB_PC], %reg_pc; \
92 ld [%reg + STACKFRAME_SZ + KGDB_NPC], %reg_npc;
93 37
94#endif /* !(_SPARC_KGDB_H) */ 38#endif /* _SPARC_KGDB_H */
diff --git a/include/asm-sparc/oplib.h b/include/asm-sparc/oplib.h
index 17ba82ee220a..7becc846544a 100644
--- a/include/asm-sparc/oplib.h
+++ b/include/asm-sparc/oplib.h
@@ -34,9 +34,6 @@ extern unsigned int prom_rev, prom_prev;
34 */ 34 */
35extern int prom_root_node; 35extern int prom_root_node;
36 36
37/* PROM stdin and stdout */
38extern int prom_stdin, prom_stdout;
39
40/* Pointer to prom structure containing the device tree traversal 37/* Pointer to prom structure containing the device tree traversal
41 * and usage utility functions. Only prom-lib should use these, 38 * and usage utility functions. Only prom-lib should use these,
42 * users use the interface defined by the library only! 39 * users use the interface defined by the library only!
@@ -84,20 +81,6 @@ extern int prom_devclose(int device_handle);
84extern void prom_seek(int device_handle, unsigned int seek_hival, 81extern void prom_seek(int device_handle, unsigned int seek_hival,
85 unsigned int seek_lowval); 82 unsigned int seek_lowval);
86 83
87/* Machine memory configuration routine. */
88
89/* This function returns a V0 format memory descriptor table, it has three
90 * entries. One for the total amount of physical ram on the machine, one
91 * for the amount of physical ram available, and one describing the virtual
92 * areas which are allocated by the prom. So, in a sense the physical
93 * available is a calculation of the total physical minus the physical mapped
94 * by the prom with virtual mappings.
95 *
96 * These lists are returned pre-sorted, this should make your life easier
97 * since the prom itself is way too lazy to do such nice things.
98 */
99extern struct linux_mem_v0 *prom_meminfo(void);
100
101/* Miscellaneous routines, don't really fit in any category per se. */ 84/* Miscellaneous routines, don't really fit in any category per se. */
102 85
103/* Reboot the machine with the command line passed. */ 86/* Reboot the machine with the command line passed. */
diff --git a/include/asm-sparc/page.h b/include/asm-sparc/page.h
index 39ccf2da297c..1625a8c3e0d2 100644
--- a/include/asm-sparc/page.h
+++ b/include/asm-sparc/page.h
@@ -38,12 +38,11 @@
38 38
39/* The following structure is used to hold the physical 39/* The following structure is used to hold the physical
40 * memory configuration of the machine. This is filled in 40 * memory configuration of the machine. This is filled in
41 * probe_memory() and is later used by mem_init() to set up 41 * prom_meminit() and is later used by mem_init() to set up
42 * mem_map[]. We statically allocate SPARC_PHYS_BANKS of 42 * mem_map[]. We statically allocate SPARC_PHYS_BANKS+1 of
43 * these structs, this is arbitrary. The entry after the 43 * these structs, this is arbitrary. The entry after the
44 * last valid one has num_bytes==0. 44 * last valid one has num_bytes==0.
45 */ 45 */
46
47struct sparc_phys_banks { 46struct sparc_phys_banks {
48 unsigned long base_addr; 47 unsigned long base_addr;
49 unsigned long num_bytes; 48 unsigned long num_bytes;
diff --git a/include/asm-sparc/smp.h b/include/asm-sparc/smp.h
index b3f492208fd2..e6d561599726 100644
--- a/include/asm-sparc/smp.h
+++ b/include/asm-sparc/smp.h
@@ -51,13 +51,11 @@ void smp_bogo(struct seq_file *);
51void smp_info(struct seq_file *); 51void smp_info(struct seq_file *);
52 52
53BTFIXUPDEF_CALL(void, smp_cross_call, smpfunc_t, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long) 53BTFIXUPDEF_CALL(void, smp_cross_call, smpfunc_t, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
54BTFIXUPDEF_CALL(void, smp_message_pass, int, int, unsigned long, int)
55BTFIXUPDEF_CALL(int, __hard_smp_processor_id, void) 54BTFIXUPDEF_CALL(int, __hard_smp_processor_id, void)
56BTFIXUPDEF_BLACKBOX(hard_smp_processor_id) 55BTFIXUPDEF_BLACKBOX(hard_smp_processor_id)
57BTFIXUPDEF_BLACKBOX(load_current) 56BTFIXUPDEF_BLACKBOX(load_current)
58 57
59#define smp_cross_call(func,arg1,arg2,arg3,arg4,arg5) BTFIXUP_CALL(smp_cross_call)(func,arg1,arg2,arg3,arg4,arg5) 58#define smp_cross_call(func,arg1,arg2,arg3,arg4,arg5) BTFIXUP_CALL(smp_cross_call)(func,arg1,arg2,arg3,arg4,arg5)
60#define smp_message_pass(target,msg,data,wait) BTFIXUP_CALL(smp_message_pass)(target,msg,data,wait)
61 59
62static inline void xc0(smpfunc_t func) { smp_cross_call(func, 0, 0, 0, 0, 0); } 60static inline void xc0(smpfunc_t func) { smp_cross_call(func, 0, 0, 0, 0, 0); }
63static inline void xc1(smpfunc_t func, unsigned long arg1) 61static inline void xc1(smpfunc_t func, unsigned long arg1)
diff --git a/include/asm-sparc/system.h b/include/asm-sparc/system.h
index 4e08210cd4c2..b4b024445fc9 100644
--- a/include/asm-sparc/system.h
+++ b/include/asm-sparc/system.h
@@ -94,6 +94,8 @@ extern void fpsave(unsigned long *fpregs, unsigned long *fsr,
94 } while(0) 94 } while(0)
95#endif 95#endif
96 96
97extern void flushw_all(void);
98
97/* 99/*
98 * Flush windows so that the VM switch which follows 100 * Flush windows so that the VM switch which follows
99 * would not pull the stack from under us. 101 * would not pull the stack from under us.
diff --git a/include/asm-sparc/types.h b/include/asm-sparc/types.h
index 42fc6ed98156..1b08ef860a66 100644
--- a/include/asm-sparc/types.h
+++ b/include/asm-sparc/types.h
@@ -3,34 +3,18 @@
3#define _SPARC_TYPES_H 3#define _SPARC_TYPES_H
4 4
5/* 5/*
6 * _xx is ok: it doesn't pollute the POSIX namespace. Use these in the
7 * header files exported to user space.
8 */
9
10/*
11 * This file is never included by application software unless 6 * This file is never included by application software unless
12 * explicitly requested (e.g., via linux/types.h) in which case the 7 * explicitly requested (e.g., via linux/types.h) in which case the
13 * application is Linux specific so (user-) name space pollution is 8 * application is Linux specific so (user-) name space pollution is
14 * not a major issue. However, for interoperability, libraries still 9 * not a major issue. However, for interoperability, libraries still
15 * need to be careful to avoid a name clashes. 10 * need to be careful to avoid a name clashes.
16 */ 11 */
12#include <asm-generic/int-ll64.h>
17 13
18#ifndef __ASSEMBLY__ 14#ifndef __ASSEMBLY__
19 15
20typedef unsigned short umode_t; 16typedef unsigned short umode_t;
21 17
22typedef __signed__ char __s8;
23typedef unsigned char __u8;
24
25typedef __signed__ short __s16;
26typedef unsigned short __u16;
27
28typedef __signed__ int __s32;
29typedef unsigned int __u32;
30
31typedef __signed__ long long __s64;
32typedef unsigned long long __u64;
33
34#endif /* __ASSEMBLY__ */ 18#endif /* __ASSEMBLY__ */
35 19
36#ifdef __KERNEL__ 20#ifdef __KERNEL__
@@ -39,18 +23,6 @@ typedef unsigned long long __u64;
39 23
40#ifndef __ASSEMBLY__ 24#ifndef __ASSEMBLY__
41 25
42typedef __signed__ char s8;
43typedef unsigned char u8;
44
45typedef __signed__ short s16;
46typedef unsigned short u16;
47
48typedef __signed__ int s32;
49typedef unsigned int u32;
50
51typedef __signed__ long long s64;
52typedef unsigned long long u64;
53
54typedef u32 dma_addr_t; 26typedef u32 dma_addr_t;
55typedef u32 dma64_addr_t; 27typedef u32 dma64_addr_t;
56 28
diff --git a/include/asm-sparc64/futex.h b/include/asm-sparc64/futex.h
index df1097d6ffbe..d8378935ae90 100644
--- a/include/asm-sparc64/futex.h
+++ b/include/asm-sparc64/futex.h
@@ -2,9 +2,9 @@
2#define _SPARC64_FUTEX_H 2#define _SPARC64_FUTEX_H
3 3
4#include <linux/futex.h> 4#include <linux/futex.h>
5#include <linux/uaccess.h>
5#include <asm/errno.h> 6#include <asm/errno.h>
6#include <asm/system.h> 7#include <asm/system.h>
7#include <asm/uaccess.h>
8 8
9#define __futex_cas_op(insn, ret, oldval, uaddr, oparg) \ 9#define __futex_cas_op(insn, ret, oldval, uaddr, oparg) \
10 __asm__ __volatile__( \ 10 __asm__ __volatile__( \
diff --git a/include/asm-sparc64/kgdb.h b/include/asm-sparc64/kgdb.h
new file mode 100644
index 000000000000..aa6532fd3a13
--- /dev/null
+++ b/include/asm-sparc64/kgdb.h
@@ -0,0 +1 @@
#include <asm-sparc/kgdb.h>
diff --git a/include/asm-sparc64/pil.h b/include/asm-sparc64/pil.h
index 72927749aebf..2f5d126f7163 100644
--- a/include/asm-sparc64/pil.h
+++ b/include/asm-sparc64/pil.h
@@ -19,11 +19,4 @@
19#define PIL_SMP_CTX_NEW_VERSION 4 19#define PIL_SMP_CTX_NEW_VERSION 4
20#define PIL_DEVICE_IRQ 5 20#define PIL_DEVICE_IRQ 5
21 21
22#ifndef __ASSEMBLY__
23#define PIL_RESERVED(PIL) ((PIL) == PIL_SMP_CALL_FUNC || \
24 (PIL) == PIL_SMP_RECEIVE_SIGNAL || \
25 (PIL) == PIL_SMP_CAPTURE || \
26 (PIL) == PIL_SMP_CTX_NEW_VERSION)
27#endif
28
29#endif /* !(_SPARC64_PIL_H) */ 22#endif /* !(_SPARC64_PIL_H) */
diff --git a/include/asm-sparc64/system.h b/include/asm-sparc64/system.h
index 53eae091a171..6897ac31be41 100644
--- a/include/asm-sparc64/system.h
+++ b/include/asm-sparc64/system.h
@@ -180,12 +180,13 @@ do { if (test_thread_flag(TIF_PERFCTR)) { \
180 "ldx [%%sp + 2047 + 0x70], %%i6\n\t" \ 180 "ldx [%%sp + 2047 + 0x70], %%i6\n\t" \
181 "ldx [%%sp + 2047 + 0x78], %%i7\n\t" \ 181 "ldx [%%sp + 2047 + 0x78], %%i7\n\t" \
182 "ldx [%%g6 + %9], %%g4\n\t" \ 182 "ldx [%%g6 + %9], %%g4\n\t" \
183 "brz,pt %%o7, 1f\n\t" \ 183 "brz,pt %%o7, switch_to_pc\n\t" \
184 " mov %%g7, %0\n\t" \ 184 " mov %%g7, %0\n\t" \
185 "sethi %%hi(ret_from_syscall), %%g1\n\t" \ 185 "sethi %%hi(ret_from_syscall), %%g1\n\t" \
186 "jmpl %%g1 + %%lo(ret_from_syscall), %%g0\n\t" \ 186 "jmpl %%g1 + %%lo(ret_from_syscall), %%g0\n\t" \
187 " nop\n\t" \ 187 " nop\n\t" \
188 "1:\n\t" \ 188 ".globl switch_to_pc\n\t" \
189 "switch_to_pc:\n\t" \
189 : "=&r" (last), "=r" (current), "=r" (current_thread_info_reg), \ 190 : "=&r" (last), "=r" (current), "=r" (current_thread_info_reg), \
190 "=r" (__local_per_cpu_offset) \ 191 "=r" (__local_per_cpu_offset) \
191 : "0" (task_thread_info(next)), \ 192 : "0" (task_thread_info(next)), \
diff --git a/include/asm-sparc64/ttable.h b/include/asm-sparc64/ttable.h
index d3cc4eff39a6..1b55538b944f 100644
--- a/include/asm-sparc64/ttable.h
+++ b/include/asm-sparc64/ttable.h
@@ -175,6 +175,12 @@
175#define KPROBES_TRAP(lvl) TRAP_ARG(bad_trap, lvl) 175#define KPROBES_TRAP(lvl) TRAP_ARG(bad_trap, lvl)
176#endif 176#endif
177 177
178#ifdef CONFIG_KGDB
179#define KGDB_TRAP(lvl) TRAP_IRQ(kgdb_trap, lvl)
180#else
181#define KGDB_TRAP(lvl) TRAP_ARG(bad_trap, lvl)
182#endif
183
178#define SUN4V_ITSB_MISS \ 184#define SUN4V_ITSB_MISS \
179 ldxa [%g0] ASI_SCRATCHPAD, %g2; \ 185 ldxa [%g0] ASI_SCRATCHPAD, %g2; \
180 ldx [%g2 + HV_FAULT_I_ADDR_OFFSET], %g4; \ 186 ldx [%g2 + HV_FAULT_I_ADDR_OFFSET], %g4; \
diff --git a/include/asm-sparc64/types.h b/include/asm-sparc64/types.h
index d0ee7f105838..5dbe04f4044a 100644
--- a/include/asm-sparc64/types.h
+++ b/include/asm-sparc64/types.h
@@ -9,28 +9,12 @@
9 * not a major issue. However, for interoperability, libraries still 9 * not a major issue. However, for interoperability, libraries still
10 * need to be careful to avoid a name clashes. 10 * need to be careful to avoid a name clashes.
11 */ 11 */
12#include <asm-generic/int-l64.h>
12 13
13#ifndef __ASSEMBLY__ 14#ifndef __ASSEMBLY__
14 15
15typedef unsigned short umode_t; 16typedef unsigned short umode_t;
16 17
17/*
18 * _xx is ok: it doesn't pollute the POSIX namespace. Use these in the
19 * header files exported to user space.
20 */
21
22typedef __signed__ char __s8;
23typedef unsigned char __u8;
24
25typedef __signed__ short __s16;
26typedef unsigned short __u16;
27
28typedef __signed__ int __s32;
29typedef unsigned int __u32;
30
31typedef __signed__ long __s64;
32typedef unsigned long __u64;
33
34#endif /* __ASSEMBLY__ */ 18#endif /* __ASSEMBLY__ */
35 19
36#ifdef __KERNEL__ 20#ifdef __KERNEL__
@@ -39,18 +23,6 @@ typedef unsigned long __u64;
39 23
40#ifndef __ASSEMBLY__ 24#ifndef __ASSEMBLY__
41 25
42typedef __signed__ char s8;
43typedef unsigned char u8;
44
45typedef __signed__ short s16;
46typedef unsigned short u16;
47
48typedef __signed__ int s32;
49typedef unsigned int u32;
50
51typedef __signed__ long s64;
52typedef unsigned long u64;
53
54/* Dma addresses come in generic and 64-bit flavours. */ 26/* Dma addresses come in generic and 64-bit flavours. */
55 27
56typedef u32 dma_addr_t; 28typedef u32 dma_addr_t;
diff --git a/include/asm-um/div64.h b/include/asm-um/div64.h
index 7b73b2cd5b34..1e17f7409cab 100644
--- a/include/asm-um/div64.h
+++ b/include/asm-um/div64.h
@@ -3,5 +3,4 @@
3 3
4#include "asm/arch/div64.h" 4#include "asm/arch/div64.h"
5 5
6extern uint64_t div64_64(uint64_t dividend, uint64_t divisor);
7#endif 6#endif
diff --git a/include/asm-v850/types.h b/include/asm-v850/types.h
index 284bda882112..89f735ee41dd 100644
--- a/include/asm-v850/types.h
+++ b/include/asm-v850/types.h
@@ -10,28 +10,10 @@
10 * not a major issue. However, for interoperability, libraries still 10 * not a major issue. However, for interoperability, libraries still
11 * need to be careful to avoid a name clashes. 11 * need to be careful to avoid a name clashes.
12 */ 12 */
13#include <asm-generic/int-ll64.h>
13 14
14typedef unsigned short umode_t; 15typedef unsigned short umode_t;
15 16
16/*
17 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
18 * header files exported to user space
19 */
20
21typedef __signed__ char __s8;
22typedef unsigned char __u8;
23
24typedef __signed__ short __s16;
25typedef unsigned short __u16;
26
27typedef __signed__ int __s32;
28typedef unsigned int __u32;
29
30#if defined(__GNUC__)
31__extension__ typedef __signed__ long long __s64;
32__extension__ typedef unsigned long long __u64;
33#endif
34
35#endif /* !__ASSEMBLY__ */ 17#endif /* !__ASSEMBLY__ */
36 18
37/* 19/*
@@ -43,18 +25,6 @@ __extension__ typedef unsigned long long __u64;
43 25
44#ifndef __ASSEMBLY__ 26#ifndef __ASSEMBLY__
45 27
46typedef signed char s8;
47typedef unsigned char u8;
48
49typedef signed short s16;
50typedef unsigned short u16;
51
52typedef signed int s32;
53typedef unsigned int u32;
54
55typedef signed long long s64;
56typedef unsigned long long u64;
57
58/* Dma addresses are 32-bits wide. */ 28/* Dma addresses are 32-bits wide. */
59 29
60typedef u32 dma_addr_t; 30typedef u32 dma_addr_t;
diff --git a/include/asm-x86/bootparam.h b/include/asm-x86/bootparam.h
index e8659909e5f6..f62f4733606b 100644
--- a/include/asm-x86/bootparam.h
+++ b/include/asm-x86/bootparam.h
@@ -14,10 +14,10 @@
14 14
15/* extensible setup data list node */ 15/* extensible setup data list node */
16struct setup_data { 16struct setup_data {
17 u64 next; 17 __u64 next;
18 u32 type; 18 __u32 type;
19 u32 len; 19 __u32 len;
20 u8 data[0]; 20 __u8 data[0];
21}; 21};
22 22
23struct setup_header { 23struct setup_header {
diff --git a/include/asm-x86/div64.h b/include/asm-x86/div64.h
index 0dbf8bf3ef0a..9a2d644c08ef 100644
--- a/include/asm-x86/div64.h
+++ b/include/asm-x86/div64.h
@@ -33,25 +33,25 @@
33 __mod; \ 33 __mod; \
34}) 34})
35 35
36/* 36static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
37 * (long)X = ((long long)divs) / (long)div
38 * (long)rem = ((long long)divs) % (long)div
39 *
40 * Warning, this will do an exception if X overflows.
41 */
42#define div_long_long_rem(a, b, c) div_ll_X_l_rem(a, b, c)
43
44static inline long div_ll_X_l_rem(long long divs, long div, long *rem)
45{ 37{
46 long dum2; 38 union {
47 asm("divl %2":"=a"(dum2), "=d"(*rem) 39 u64 v64;
48 : "rm"(div), "A"(divs)); 40 u32 v32[2];
49 41 } d = { dividend };
50 return dum2; 42 u32 upper;
51 43
44 upper = d.v32[1];
45 d.v32[1] = 0;
46 if (upper >= divisor) {
47 d.v32[1] = upper / divisor;
48 upper %= divisor;
49 }
50 asm ("divl %2" : "=a" (d.v32[0]), "=d" (*remainder) :
51 "rm" (divisor), "0" (d.v32[0]), "1" (upper));
52 return d.v64;
52} 53}
53 54#define div_u64_rem div_u64_rem
54extern uint64_t div64_64(uint64_t dividend, uint64_t divisor);
55 55
56#else 56#else
57# include <asm-generic/div64.h> 57# include <asm-generic/div64.h>
diff --git a/include/asm-x86/dmi.h b/include/asm-x86/dmi.h
index 1241e6ad1935..4edf7514a750 100644
--- a/include/asm-x86/dmi.h
+++ b/include/asm-x86/dmi.h
@@ -27,6 +27,7 @@ static inline void *dmi_alloc(unsigned len)
27 27
28#endif 28#endif
29 29
30/* Use early IO mappings for DMI because it's initialized early */
30#define dmi_ioremap early_ioremap 31#define dmi_ioremap early_ioremap
31#define dmi_iounmap early_iounmap 32#define dmi_iounmap early_iounmap
32 33
diff --git a/include/asm-x86/futex.h b/include/asm-x86/futex.h
index ac0fbf24d722..e7a76b37b333 100644
--- a/include/asm-x86/futex.h
+++ b/include/asm-x86/futex.h
@@ -4,12 +4,12 @@
4#ifdef __KERNEL__ 4#ifdef __KERNEL__
5 5
6#include <linux/futex.h> 6#include <linux/futex.h>
7#include <linux/uaccess.h>
7 8
8#include <asm/asm.h> 9#include <asm/asm.h>
9#include <asm/errno.h> 10#include <asm/errno.h>
10#include <asm/processor.h> 11#include <asm/processor.h>
11#include <asm/system.h> 12#include <asm/system.h>
12#include <asm/uaccess.h>
13 13
14#define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \ 14#define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
15 asm volatile("1:\t" insn "\n" \ 15 asm volatile("1:\t" insn "\n" \
diff --git a/include/asm-x86/io_32.h b/include/asm-x86/io_32.h
index 6e73467a4fb1..049e81e797a0 100644
--- a/include/asm-x86/io_32.h
+++ b/include/asm-x86/io_32.h
@@ -133,11 +133,6 @@ extern void *early_ioremap(unsigned long offset, unsigned long size);
133extern void early_iounmap(void *addr, unsigned long size); 133extern void early_iounmap(void *addr, unsigned long size);
134extern void __iomem *fix_ioremap(unsigned idx, unsigned long phys); 134extern void __iomem *fix_ioremap(unsigned idx, unsigned long phys);
135 135
136/* Use early IO mappings for DMI because it's initialized early */
137#define dmi_ioremap early_ioremap
138#define dmi_iounmap early_iounmap
139#define dmi_alloc alloc_bootmem
140
141/* 136/*
142 * ISA I/O bus memory addresses are 1:1 with the physical address. 137 * ISA I/O bus memory addresses are 1:1 with the physical address.
143 */ 138 */
diff --git a/include/asm-x86/kvm_host.h b/include/asm-x86/kvm_host.h
index 9d963cd6533c..1d8cd01fa514 100644
--- a/include/asm-x86/kvm_host.h
+++ b/include/asm-x86/kvm_host.h
@@ -314,6 +314,9 @@ struct kvm_arch{
314 struct page *apic_access_page; 314 struct page *apic_access_page;
315 315
316 gpa_t wall_clock; 316 gpa_t wall_clock;
317
318 struct page *ept_identity_pagetable;
319 bool ept_identity_pagetable_done;
317}; 320};
318 321
319struct kvm_vm_stat { 322struct kvm_vm_stat {
@@ -422,6 +425,7 @@ struct kvm_x86_ops {
422 struct kvm_run *run); 425 struct kvm_run *run);
423 426
424 int (*set_tss_addr)(struct kvm *kvm, unsigned int addr); 427 int (*set_tss_addr)(struct kvm *kvm, unsigned int addr);
428 int (*get_tdp_level)(void);
425}; 429};
426 430
427extern struct kvm_x86_ops *kvm_x86_ops; 431extern struct kvm_x86_ops *kvm_x86_ops;
@@ -433,6 +437,9 @@ void kvm_mmu_destroy(struct kvm_vcpu *vcpu);
433int kvm_mmu_create(struct kvm_vcpu *vcpu); 437int kvm_mmu_create(struct kvm_vcpu *vcpu);
434int kvm_mmu_setup(struct kvm_vcpu *vcpu); 438int kvm_mmu_setup(struct kvm_vcpu *vcpu);
435void kvm_mmu_set_nonpresent_ptes(u64 trap_pte, u64 notrap_pte); 439void kvm_mmu_set_nonpresent_ptes(u64 trap_pte, u64 notrap_pte);
440void kvm_mmu_set_base_ptes(u64 base_pte);
441void kvm_mmu_set_mask_ptes(u64 user_mask, u64 accessed_mask,
442 u64 dirty_mask, u64 nx_mask, u64 x_mask);
436 443
437int kvm_mmu_reset_context(struct kvm_vcpu *vcpu); 444int kvm_mmu_reset_context(struct kvm_vcpu *vcpu);
438void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot); 445void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot);
@@ -620,7 +627,7 @@ static inline void fx_restore(struct i387_fxsave_struct *image)
620 asm("fxrstor (%0)":: "r" (image)); 627 asm("fxrstor (%0)":: "r" (image));
621} 628}
622 629
623static inline void fpu_init(void) 630static inline void fx_finit(void)
624{ 631{
625 asm("finit"); 632 asm("finit");
626} 633}
@@ -644,6 +651,7 @@ static inline void kvm_inject_gp(struct kvm_vcpu *vcpu, u32 error_code)
644#define ASM_VMX_VMWRITE_RSP_RDX ".byte 0x0f, 0x79, 0xd4" 651#define ASM_VMX_VMWRITE_RSP_RDX ".byte 0x0f, 0x79, 0xd4"
645#define ASM_VMX_VMXOFF ".byte 0x0f, 0x01, 0xc4" 652#define ASM_VMX_VMXOFF ".byte 0x0f, 0x01, 0xc4"
646#define ASM_VMX_VMXON_RAX ".byte 0xf3, 0x0f, 0xc7, 0x30" 653#define ASM_VMX_VMXON_RAX ".byte 0xf3, 0x0f, 0xc7, 0x30"
654#define ASM_VMX_INVEPT ".byte 0x66, 0x0f, 0x38, 0x80, 0x08"
647#define ASM_VMX_INVVPID ".byte 0x66, 0x0f, 0x38, 0x81, 0x08" 655#define ASM_VMX_INVVPID ".byte 0x66, 0x0f, 0x38, 0x81, 0x08"
648 656
649#define MSR_IA32_TIME_STAMP_COUNTER 0x010 657#define MSR_IA32_TIME_STAMP_COUNTER 0x010
diff --git a/include/asm-x86/mach-default/mach_apic.h b/include/asm-x86/mach-default/mach_apic.h
index 0a6634f62abe..21003b56ae95 100644
--- a/include/asm-x86/mach-default/mach_apic.h
+++ b/include/asm-x86/mach-default/mach_apic.h
@@ -109,13 +109,8 @@ static inline int cpu_to_logical_apicid(int cpu)
109 109
110static inline int cpu_present_to_apicid(int mps_cpu) 110static inline int cpu_present_to_apicid(int mps_cpu)
111{ 111{
112#ifdef CONFIG_X86_64 112 if (mps_cpu < NR_CPUS && cpu_present(mps_cpu))
113 if (cpu_present(mps_cpu))
114 return (int)per_cpu(x86_bios_cpu_apicid, mps_cpu); 113 return (int)per_cpu(x86_bios_cpu_apicid, mps_cpu);
115#else
116 if (mps_cpu < get_physical_broadcast())
117 return mps_cpu;
118#endif
119 else 114 else
120 return BAD_APICID; 115 return BAD_APICID;
121} 116}
diff --git a/include/asm-x86/processor.h b/include/asm-x86/processor.h
index 2e7974ec77ec..559105220a47 100644
--- a/include/asm-x86/processor.h
+++ b/include/asm-x86/processor.h
@@ -3,9 +3,6 @@
3 3
4#include <asm/processor-flags.h> 4#include <asm/processor-flags.h>
5 5
6/* migration helper, for KVM - will be removed in 2.6.25: */
7#define Xgt_desc_struct desc_ptr
8
9/* Forward declaration, a strange C thing */ 6/* Forward declaration, a strange C thing */
10struct task_struct; 7struct task_struct;
11struct mm_struct; 8struct mm_struct;
diff --git a/include/asm-x86/proto.h b/include/asm-x86/proto.h
index 1e17bcce450e..6c8b41b03f6d 100644
--- a/include/asm-x86/proto.h
+++ b/include/asm-x86/proto.h
@@ -20,7 +20,11 @@ extern void syscall32_cpu_init(void);
20 20
21extern void check_efer(void); 21extern void check_efer(void);
22 22
23#ifdef CONFIG_X86_BIOS_REBOOT
23extern int reboot_force; 24extern int reboot_force;
25#else
26static const int reboot_force = 0;
27#endif
24 28
25long do_arch_prctl(struct task_struct *task, int code, unsigned long addr); 29long do_arch_prctl(struct task_struct *task, int code, unsigned long addr);
26 30
diff --git a/include/asm-x86/thread_info_32.h b/include/asm-x86/thread_info_32.h
index 531859962096..b6338829d1a8 100644
--- a/include/asm-x86/thread_info_32.h
+++ b/include/asm-x86/thread_info_32.h
@@ -131,7 +131,6 @@ static inline struct thread_info *current_thread_info(void)
131#define TIF_SYSCALL_EMU 5 /* syscall emulation active */ 131#define TIF_SYSCALL_EMU 5 /* syscall emulation active */
132#define TIF_SYSCALL_AUDIT 6 /* syscall auditing active */ 132#define TIF_SYSCALL_AUDIT 6 /* syscall auditing active */
133#define TIF_SECCOMP 7 /* secure computing */ 133#define TIF_SECCOMP 7 /* secure computing */
134#define TIF_RESTORE_SIGMASK 8 /* restore signal mask in do_signal() */
135#define TIF_HRTICK_RESCHED 9 /* reprogram hrtick timer */ 134#define TIF_HRTICK_RESCHED 9 /* reprogram hrtick timer */
136#define TIF_MEMDIE 16 135#define TIF_MEMDIE 16
137#define TIF_DEBUG 17 /* uses debug registers */ 136#define TIF_DEBUG 17 /* uses debug registers */
@@ -151,7 +150,6 @@ static inline struct thread_info *current_thread_info(void)
151#define _TIF_SYSCALL_EMU (1 << TIF_SYSCALL_EMU) 150#define _TIF_SYSCALL_EMU (1 << TIF_SYSCALL_EMU)
152#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT) 151#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
153#define _TIF_SECCOMP (1 << TIF_SECCOMP) 152#define _TIF_SECCOMP (1 << TIF_SECCOMP)
154#define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
155#define _TIF_HRTICK_RESCHED (1 << TIF_HRTICK_RESCHED) 153#define _TIF_HRTICK_RESCHED (1 << TIF_HRTICK_RESCHED)
156#define _TIF_DEBUG (1 << TIF_DEBUG) 154#define _TIF_DEBUG (1 << TIF_DEBUG)
157#define _TIF_IO_BITMAP (1 << TIF_IO_BITMAP) 155#define _TIF_IO_BITMAP (1 << TIF_IO_BITMAP)
@@ -188,9 +186,20 @@ static inline struct thread_info *current_thread_info(void)
188 this quantum (SMP) */ 186 this quantum (SMP) */
189#define TS_POLLING 0x0002 /* True if in idle loop 187#define TS_POLLING 0x0002 /* True if in idle loop
190 and not sleeping */ 188 and not sleeping */
189#define TS_RESTORE_SIGMASK 0x0004 /* restore signal mask in do_signal() */
191 190
192#define tsk_is_polling(t) (task_thread_info(t)->status & TS_POLLING) 191#define tsk_is_polling(t) (task_thread_info(t)->status & TS_POLLING)
193 192
193#ifndef __ASSEMBLY__
194#define HAVE_SET_RESTORE_SIGMASK 1
195static inline void set_restore_sigmask(void)
196{
197 struct thread_info *ti = current_thread_info();
198 ti->status |= TS_RESTORE_SIGMASK;
199 set_bit(TIF_SIGPENDING, &ti->flags);
200}
201#endif /* !__ASSEMBLY__ */
202
194#endif /* __KERNEL__ */ 203#endif /* __KERNEL__ */
195 204
196#endif /* _ASM_THREAD_INFO_H */ 205#endif /* _ASM_THREAD_INFO_H */
diff --git a/include/asm-x86/thread_info_64.h b/include/asm-x86/thread_info_64.h
index ed664e874dec..cb69f70abba1 100644
--- a/include/asm-x86/thread_info_64.h
+++ b/include/asm-x86/thread_info_64.h
@@ -109,7 +109,6 @@ static inline struct thread_info *stack_thread_info(void)
109#define TIF_IRET 5 /* force IRET */ 109#define TIF_IRET 5 /* force IRET */
110#define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */ 110#define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
111#define TIF_SECCOMP 8 /* secure computing */ 111#define TIF_SECCOMP 8 /* secure computing */
112#define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal */
113#define TIF_MCE_NOTIFY 10 /* notify userspace of an MCE */ 112#define TIF_MCE_NOTIFY 10 /* notify userspace of an MCE */
114#define TIF_HRTICK_RESCHED 11 /* reprogram hrtick timer */ 113#define TIF_HRTICK_RESCHED 11 /* reprogram hrtick timer */
115/* 16 free */ 114/* 16 free */
@@ -133,7 +132,6 @@ static inline struct thread_info *stack_thread_info(void)
133#define _TIF_IRET (1 << TIF_IRET) 132#define _TIF_IRET (1 << TIF_IRET)
134#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT) 133#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
135#define _TIF_SECCOMP (1 << TIF_SECCOMP) 134#define _TIF_SECCOMP (1 << TIF_SECCOMP)
136#define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
137#define _TIF_MCE_NOTIFY (1 << TIF_MCE_NOTIFY) 135#define _TIF_MCE_NOTIFY (1 << TIF_MCE_NOTIFY)
138#define _TIF_HRTICK_RESCHED (1 << TIF_HRTICK_RESCHED) 136#define _TIF_HRTICK_RESCHED (1 << TIF_HRTICK_RESCHED)
139#define _TIF_IA32 (1 << TIF_IA32) 137#define _TIF_IA32 (1 << TIF_IA32)
@@ -178,9 +176,20 @@ static inline struct thread_info *stack_thread_info(void)
178#define TS_COMPAT 0x0002 /* 32bit syscall active */ 176#define TS_COMPAT 0x0002 /* 32bit syscall active */
179#define TS_POLLING 0x0004 /* true if in idle loop 177#define TS_POLLING 0x0004 /* true if in idle loop
180 and not sleeping */ 178 and not sleeping */
179#define TS_RESTORE_SIGMASK 0x0008 /* restore signal mask in do_signal() */
181 180
182#define tsk_is_polling(t) (task_thread_info(t)->status & TS_POLLING) 181#define tsk_is_polling(t) (task_thread_info(t)->status & TS_POLLING)
183 182
183#ifndef __ASSEMBLY__
184#define HAVE_SET_RESTORE_SIGMASK 1
185static inline void set_restore_sigmask(void)
186{
187 struct thread_info *ti = current_thread_info();
188 ti->status |= TS_RESTORE_SIGMASK;
189 set_bit(TIF_SIGPENDING, &ti->flags);
190}
191#endif /* !__ASSEMBLY__ */
192
184#endif /* __KERNEL__ */ 193#endif /* __KERNEL__ */
185 194
186#endif /* _ASM_THREAD_INFO_H */ 195#endif /* _ASM_THREAD_INFO_H */
diff --git a/include/asm-x86/topology.h b/include/asm-x86/topology.h
index 0e6d6b03affe..4f35a0fb4f22 100644
--- a/include/asm-x86/topology.h
+++ b/include/asm-x86/topology.h
@@ -193,6 +193,10 @@ extern cpumask_t cpu_coregroup_map(int cpu);
193#define topology_thread_siblings(cpu) (per_cpu(cpu_sibling_map, cpu)) 193#define topology_thread_siblings(cpu) (per_cpu(cpu_sibling_map, cpu))
194#endif 194#endif
195 195
196static inline void arch_fix_phys_package_id(int num, u32 slot)
197{
198}
199
196struct pci_bus; 200struct pci_bus;
197void set_pci_bus_resources_arch_default(struct pci_bus *b); 201void set_pci_bus_resources_arch_default(struct pci_bus *b);
198 202
diff --git a/include/asm-x86/types.h b/include/asm-x86/types.h
index 63733f315688..1ac80cd9acf8 100644
--- a/include/asm-x86/types.h
+++ b/include/asm-x86/types.h
@@ -1,34 +1,12 @@
1#ifndef _ASM_X86_TYPES_H 1#ifndef _ASM_X86_TYPES_H
2#define _ASM_X86_TYPES_H 2#define _ASM_X86_TYPES_H
3 3
4#include <asm-generic/int-ll64.h>
5
4#ifndef __ASSEMBLY__ 6#ifndef __ASSEMBLY__
5 7
6typedef unsigned short umode_t; 8typedef unsigned short umode_t;
7 9
8/*
9 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
10 * header files exported to user space
11 */
12
13typedef __signed__ char __s8;
14typedef unsigned char __u8;
15
16typedef __signed__ short __s16;
17typedef unsigned short __u16;
18
19typedef __signed__ int __s32;
20typedef unsigned int __u32;
21
22#ifdef __i386__
23# ifdef __GNUC__
24__extension__ typedef __signed__ long long __s64;
25__extension__ typedef unsigned long long __u64;
26# endif
27#else
28typedef __signed__ long long __s64;
29typedef unsigned long long __u64;
30#endif
31
32#endif /* __ASSEMBLY__ */ 10#endif /* __ASSEMBLY__ */
33 11
34/* 12/*
@@ -44,18 +22,6 @@ typedef unsigned long long __u64;
44 22
45#ifndef __ASSEMBLY__ 23#ifndef __ASSEMBLY__
46 24
47typedef signed char s8;
48typedef unsigned char u8;
49
50typedef signed short s16;
51typedef unsigned short u16;
52
53typedef signed int s32;
54typedef unsigned int u32;
55
56typedef signed long long s64;
57typedef unsigned long long u64;
58
59typedef u64 dma64_addr_t; 25typedef u64 dma64_addr_t;
60#if defined(CONFIG_X86_64) || defined(CONFIG_HIGHMEM64G) 26#if defined(CONFIG_X86_64) || defined(CONFIG_HIGHMEM64G)
61/* DMA addresses come in 32-bit and 64-bit flavours. */ 27/* DMA addresses come in 32-bit and 64-bit flavours. */
diff --git a/include/asm-xtensa/types.h b/include/asm-xtensa/types.h
index b27d841a8eb7..c89569a8da0c 100644
--- a/include/asm-xtensa/types.h
+++ b/include/asm-xtensa/types.h
@@ -11,6 +11,7 @@
11#ifndef _XTENSA_TYPES_H 11#ifndef _XTENSA_TYPES_H
12#define _XTENSA_TYPES_H 12#define _XTENSA_TYPES_H
13 13
14#include <asm-generic/int-ll64.h>
14 15
15#ifdef __ASSEMBLY__ 16#ifdef __ASSEMBLY__
16# define __XTENSA_UL(x) (x) 17# define __XTENSA_UL(x) (x)
@@ -25,42 +26,10 @@
25typedef unsigned short umode_t; 26typedef unsigned short umode_t;
26 27
27/* 28/*
28 * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
29 * header files exported to user space
30 */
31
32typedef __signed__ char __s8;
33typedef unsigned char __u8;
34
35typedef __signed__ short __s16;
36typedef unsigned short __u16;
37
38typedef __signed__ int __s32;
39typedef unsigned int __u32;
40
41#if defined(__GNUC__)
42__extension__ typedef __signed__ long long __s64;
43__extension__ typedef unsigned long long __u64;
44#endif
45
46/*
47 * These aren't exported outside the kernel to avoid name space clashes 29 * These aren't exported outside the kernel to avoid name space clashes
48 */ 30 */
49#ifdef __KERNEL__ 31#ifdef __KERNEL__
50 32
51typedef __signed__ char s8;
52typedef unsigned char u8;
53
54typedef __signed__ short s16;
55typedef unsigned short u16;
56
57typedef __signed__ int s32;
58typedef unsigned int u32;
59
60typedef __signed__ long long s64;
61typedef unsigned long long u64;
62
63
64#define BITS_PER_LONG 32 33#define BITS_PER_LONG 32
65 34
66/* Dma addresses are 32-bits wide. */ 35/* Dma addresses are 32-bits wide. */
diff --git a/include/crypto/scatterwalk.h b/include/crypto/scatterwalk.h
index 224658b8d806..833d208c25d6 100644
--- a/include/crypto/scatterwalk.h
+++ b/include/crypto/scatterwalk.h
@@ -57,10 +57,14 @@ static inline void scatterwalk_sg_chain(struct scatterlist *sg1, int num,
57 struct scatterlist *sg2) 57 struct scatterlist *sg2)
58{ 58{
59 sg_set_page(&sg1[num - 1], (void *)sg2, 0, 0); 59 sg_set_page(&sg1[num - 1], (void *)sg2, 0, 0);
60 sg1[num - 1].page_link &= ~0x02;
60} 61}
61 62
62static inline struct scatterlist *scatterwalk_sg_next(struct scatterlist *sg) 63static inline struct scatterlist *scatterwalk_sg_next(struct scatterlist *sg)
63{ 64{
65 if (sg_is_last(sg))
66 return NULL;
67
64 return (++sg)->length ? sg : (void *)sg_page(sg); 68 return (++sg)->length ? sg : (void *)sg_page(sg);
65} 69}
66 70
diff --git a/include/linux/Kbuild b/include/linux/Kbuild
index 78fade0a1e35..b7d81b2a9041 100644
--- a/include/linux/Kbuild
+++ b/include/linux/Kbuild
@@ -346,6 +346,11 @@ unifdef-y += videodev.h
346unifdef-y += virtio_config.h 346unifdef-y += virtio_config.h
347unifdef-y += virtio_blk.h 347unifdef-y += virtio_blk.h
348unifdef-y += virtio_net.h 348unifdef-y += virtio_net.h
349unifdef-y += virtio_9p.h
350unifdef-y += virtio_balloon.h
351unifdef-y += virtio_console.h
352unifdef-y += virtio_pci.h
353unifdef-y += virtio_ring.h
349unifdef-y += vt.h 354unifdef-y += vt.h
350unifdef-y += wait.h 355unifdef-y += wait.h
351unifdef-y += wanrouter.h 356unifdef-y += wanrouter.h
diff --git a/include/linux/agp_backend.h b/include/linux/agp_backend.h
index 03e34547d489..661d90d6cf7c 100644
--- a/include/linux/agp_backend.h
+++ b/include/linux/agp_backend.h
@@ -30,8 +30,6 @@
30#ifndef _AGP_BACKEND_H 30#ifndef _AGP_BACKEND_H
31#define _AGP_BACKEND_H 1 31#define _AGP_BACKEND_H 1
32 32
33#ifdef __KERNEL__
34
35#ifndef TRUE 33#ifndef TRUE
36#define TRUE 1 34#define TRUE 1
37#endif 35#endif
@@ -111,5 +109,4 @@ extern struct agp_bridge_data *agp_backend_acquire(struct pci_dev *);
111extern void agp_backend_release(struct agp_bridge_data *); 109extern void agp_backend_release(struct agp_bridge_data *);
112extern void agp_flush_chipset(struct agp_bridge_data *); 110extern void agp_flush_chipset(struct agp_bridge_data *);
113 111
114#endif /* __KERNEL__ */
115#endif /* _AGP_BACKEND_H */ 112#endif /* _AGP_BACKEND_H */
diff --git a/include/linux/anon_inodes.h b/include/linux/anon_inodes.h
index b2e1ba325b9a..6129e58ca7c9 100644
--- a/include/linux/anon_inodes.h
+++ b/include/linux/anon_inodes.h
@@ -8,8 +8,7 @@
8#ifndef _LINUX_ANON_INODES_H 8#ifndef _LINUX_ANON_INODES_H
9#define _LINUX_ANON_INODES_H 9#define _LINUX_ANON_INODES_H
10 10
11int anon_inode_getfd(int *pfd, struct inode **pinode, struct file **pfile, 11int anon_inode_getfd(const char *name, const struct file_operations *fops,
12 const char *name, const struct file_operations *fops,
13 void *priv); 12 void *priv);
14 13
15#endif /* _LINUX_ANON_INODES_H */ 14#endif /* _LINUX_ANON_INODES_H */
diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h
index b66fa2bdfd9c..0a24d5550eb3 100644
--- a/include/linux/backing-dev.h
+++ b/include/linux/backing-dev.h
@@ -11,9 +11,13 @@
11#include <linux/percpu_counter.h> 11#include <linux/percpu_counter.h>
12#include <linux/log2.h> 12#include <linux/log2.h>
13#include <linux/proportions.h> 13#include <linux/proportions.h>
14#include <linux/kernel.h>
15#include <linux/fs.h>
14#include <asm/atomic.h> 16#include <asm/atomic.h>
15 17
16struct page; 18struct page;
19struct device;
20struct dentry;
17 21
18/* 22/*
19 * Bits in backing_dev_info.state 23 * Bits in backing_dev_info.state
@@ -48,11 +52,26 @@ struct backing_dev_info {
48 52
49 struct prop_local_percpu completions; 53 struct prop_local_percpu completions;
50 int dirty_exceeded; 54 int dirty_exceeded;
55
56 unsigned int min_ratio;
57 unsigned int max_ratio, max_prop_frac;
58
59 struct device *dev;
60
61#ifdef CONFIG_DEBUG_FS
62 struct dentry *debug_dir;
63 struct dentry *debug_stats;
64#endif
51}; 65};
52 66
53int bdi_init(struct backing_dev_info *bdi); 67int bdi_init(struct backing_dev_info *bdi);
54void bdi_destroy(struct backing_dev_info *bdi); 68void bdi_destroy(struct backing_dev_info *bdi);
55 69
70int bdi_register(struct backing_dev_info *bdi, struct device *parent,
71 const char *fmt, ...);
72int bdi_register_dev(struct backing_dev_info *bdi, dev_t dev);
73void bdi_unregister(struct backing_dev_info *bdi);
74
56static inline void __add_bdi_stat(struct backing_dev_info *bdi, 75static inline void __add_bdi_stat(struct backing_dev_info *bdi,
57 enum bdi_stat_item item, s64 amount) 76 enum bdi_stat_item item, s64 amount)
58{ 77{
@@ -116,6 +135,8 @@ static inline s64 bdi_stat_sum(struct backing_dev_info *bdi,
116 return sum; 135 return sum;
117} 136}
118 137
138extern void bdi_writeout_inc(struct backing_dev_info *bdi);
139
119/* 140/*
120 * maximal error of a stat counter. 141 * maximal error of a stat counter.
121 */ 142 */
@@ -128,24 +149,48 @@ static inline unsigned long bdi_stat_error(struct backing_dev_info *bdi)
128#endif 149#endif
129} 150}
130 151
152int bdi_set_min_ratio(struct backing_dev_info *bdi, unsigned int min_ratio);
153int bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned int max_ratio);
154
131/* 155/*
132 * Flags in backing_dev_info::capability 156 * Flags in backing_dev_info::capability
133 * - The first two flags control whether dirty pages will contribute to the 157 *
134 * VM's accounting and whether writepages() should be called for dirty pages 158 * The first three flags control whether dirty pages will contribute to the
135 * (something that would not, for example, be appropriate for ramfs) 159 * VM's accounting and whether writepages() should be called for dirty pages
136 * - These flags let !MMU mmap() govern direct device mapping vs immediate 160 * (something that would not, for example, be appropriate for ramfs)
137 * copying more easily for MAP_PRIVATE, especially for ROM filesystems 161 *
162 * WARNING: these flags are closely related and should not normally be
163 * used separately. The BDI_CAP_NO_ACCT_AND_WRITEBACK combines these
164 * three flags into a single convenience macro.
165 *
166 * BDI_CAP_NO_ACCT_DIRTY: Dirty pages shouldn't contribute to accounting
167 * BDI_CAP_NO_WRITEBACK: Don't write pages back
168 * BDI_CAP_NO_ACCT_WB: Don't automatically account writeback pages
169 *
170 * These flags let !MMU mmap() govern direct device mapping vs immediate
171 * copying more easily for MAP_PRIVATE, especially for ROM filesystems.
172 *
173 * BDI_CAP_MAP_COPY: Copy can be mapped (MAP_PRIVATE)
174 * BDI_CAP_MAP_DIRECT: Can be mapped directly (MAP_SHARED)
175 * BDI_CAP_READ_MAP: Can be mapped for reading
176 * BDI_CAP_WRITE_MAP: Can be mapped for writing
177 * BDI_CAP_EXEC_MAP: Can be mapped for execution
138 */ 178 */
139#define BDI_CAP_NO_ACCT_DIRTY 0x00000001 /* Dirty pages shouldn't contribute to accounting */ 179#define BDI_CAP_NO_ACCT_DIRTY 0x00000001
140#define BDI_CAP_NO_WRITEBACK 0x00000002 /* Don't write pages back */ 180#define BDI_CAP_NO_WRITEBACK 0x00000002
141#define BDI_CAP_MAP_COPY 0x00000004 /* Copy can be mapped (MAP_PRIVATE) */ 181#define BDI_CAP_MAP_COPY 0x00000004
142#define BDI_CAP_MAP_DIRECT 0x00000008 /* Can be mapped directly (MAP_SHARED) */ 182#define BDI_CAP_MAP_DIRECT 0x00000008
143#define BDI_CAP_READ_MAP 0x00000010 /* Can be mapped for reading */ 183#define BDI_CAP_READ_MAP 0x00000010
144#define BDI_CAP_WRITE_MAP 0x00000020 /* Can be mapped for writing */ 184#define BDI_CAP_WRITE_MAP 0x00000020
145#define BDI_CAP_EXEC_MAP 0x00000040 /* Can be mapped for execution */ 185#define BDI_CAP_EXEC_MAP 0x00000040
186#define BDI_CAP_NO_ACCT_WB 0x00000080
187
146#define BDI_CAP_VMFLAGS \ 188#define BDI_CAP_VMFLAGS \
147 (BDI_CAP_READ_MAP | BDI_CAP_WRITE_MAP | BDI_CAP_EXEC_MAP) 189 (BDI_CAP_READ_MAP | BDI_CAP_WRITE_MAP | BDI_CAP_EXEC_MAP)
148 190
191#define BDI_CAP_NO_ACCT_AND_WRITEBACK \
192 (BDI_CAP_NO_WRITEBACK | BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_ACCT_WB)
193
149#if defined(VM_MAYREAD) && \ 194#if defined(VM_MAYREAD) && \
150 (BDI_CAP_READ_MAP != VM_MAYREAD || \ 195 (BDI_CAP_READ_MAP != VM_MAYREAD || \
151 BDI_CAP_WRITE_MAP != VM_MAYWRITE || \ 196 BDI_CAP_WRITE_MAP != VM_MAYWRITE || \
@@ -185,17 +230,32 @@ void clear_bdi_congested(struct backing_dev_info *bdi, int rw);
185void set_bdi_congested(struct backing_dev_info *bdi, int rw); 230void set_bdi_congested(struct backing_dev_info *bdi, int rw);
186long congestion_wait(int rw, long timeout); 231long congestion_wait(int rw, long timeout);
187 232
188#define bdi_cap_writeback_dirty(bdi) \
189 (!((bdi)->capabilities & BDI_CAP_NO_WRITEBACK))
190 233
191#define bdi_cap_account_dirty(bdi) \ 234static inline bool bdi_cap_writeback_dirty(struct backing_dev_info *bdi)
192 (!((bdi)->capabilities & BDI_CAP_NO_ACCT_DIRTY)) 235{
236 return !(bdi->capabilities & BDI_CAP_NO_WRITEBACK);
237}
238
239static inline bool bdi_cap_account_dirty(struct backing_dev_info *bdi)
240{
241 return !(bdi->capabilities & BDI_CAP_NO_ACCT_DIRTY);
242}
193 243
194#define mapping_cap_writeback_dirty(mapping) \ 244static inline bool bdi_cap_account_writeback(struct backing_dev_info *bdi)
195 bdi_cap_writeback_dirty((mapping)->backing_dev_info) 245{
246 /* Paranoia: BDI_CAP_NO_WRITEBACK implies BDI_CAP_NO_ACCT_WB */
247 return !(bdi->capabilities & (BDI_CAP_NO_ACCT_WB |
248 BDI_CAP_NO_WRITEBACK));
249}
196 250
197#define mapping_cap_account_dirty(mapping) \ 251static inline bool mapping_cap_writeback_dirty(struct address_space *mapping)
198 bdi_cap_account_dirty((mapping)->backing_dev_info) 252{
253 return bdi_cap_writeback_dirty(mapping->backing_dev_info);
254}
199 255
256static inline bool mapping_cap_account_dirty(struct address_space *mapping)
257{
258 return bdi_cap_account_dirty(mapping->backing_dev_info);
259}
200 260
201#endif /* _LINUX_BACKING_DEV_H */ 261#endif /* _LINUX_BACKING_DEV_H */
diff --git a/include/linux/byteorder/Kbuild b/include/linux/byteorder/Kbuild
index 79bedddfd9ca..1133d5f9d818 100644
--- a/include/linux/byteorder/Kbuild
+++ b/include/linux/byteorder/Kbuild
@@ -1,5 +1,3 @@
1header-y += big_endian.h 1unifdef-y += big_endian.h
2header-y += little_endian.h 2unifdef-y += little_endian.h
3
4unifdef-y += generic.h
5unifdef-y += swab.h 3unifdef-y += swab.h
diff --git a/include/linux/byteorder/big_endian.h b/include/linux/byteorder/big_endian.h
index bef87891cb24..961ed4b48d8e 100644
--- a/include/linux/byteorder/big_endian.h
+++ b/include/linux/byteorder/big_endian.h
@@ -101,6 +101,8 @@ static inline __u16 __be16_to_cpup(const __be16 *p)
101#define __cpu_to_be16s(x) do {} while (0) 101#define __cpu_to_be16s(x) do {} while (0)
102#define __be16_to_cpus(x) do {} while (0) 102#define __be16_to_cpus(x) do {} while (0)
103 103
104#ifdef __KERNEL__
104#include <linux/byteorder/generic.h> 105#include <linux/byteorder/generic.h>
106#endif
105 107
106#endif /* _LINUX_BYTEORDER_BIG_ENDIAN_H */ 108#endif /* _LINUX_BYTEORDER_BIG_ENDIAN_H */
diff --git a/include/linux/byteorder/generic.h b/include/linux/byteorder/generic.h
index d3771551fdd9..0846e6b931ce 100644
--- a/include/linux/byteorder/generic.h
+++ b/include/linux/byteorder/generic.h
@@ -82,12 +82,6 @@
82 * 82 *
83 */ 83 */
84 84
85
86#if defined(__KERNEL__)
87/*
88 * inside the kernel, we can use nicknames;
89 * outside of it, we must avoid POSIX namespace pollution...
90 */
91#define cpu_to_le64 __cpu_to_le64 85#define cpu_to_le64 __cpu_to_le64
92#define le64_to_cpu __le64_to_cpu 86#define le64_to_cpu __le64_to_cpu
93#define cpu_to_le32 __cpu_to_le32 87#define cpu_to_le32 __cpu_to_le32
@@ -176,6 +170,4 @@ static inline void be64_add_cpu(__be64 *var, u64 val)
176 *var = cpu_to_be64(be64_to_cpu(*var) + val); 170 *var = cpu_to_be64(be64_to_cpu(*var) + val);
177} 171}
178 172
179#endif /* KERNEL */
180
181#endif /* _LINUX_BYTEORDER_GENERIC_H */ 173#endif /* _LINUX_BYTEORDER_GENERIC_H */
diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
index 86e62b750176..05dc7c35b3b2 100644
--- a/include/linux/byteorder/little_endian.h
+++ b/include/linux/byteorder/little_endian.h
@@ -101,6 +101,8 @@ static inline __u16 __be16_to_cpup(const __be16 *p)
101#define __cpu_to_be16s(x) __swab16s((x)) 101#define __cpu_to_be16s(x) __swab16s((x))
102#define __be16_to_cpus(x) __swab16s((x)) 102#define __be16_to_cpus(x) __swab16s((x))
103 103
104#ifdef __KERNEL__
104#include <linux/byteorder/generic.h> 105#include <linux/byteorder/generic.h>
106#endif
105 107
106#endif /* _LINUX_BYTEORDER_LITTLE_ENDIAN_H */ 108#endif /* _LINUX_BYTEORDER_LITTLE_ENDIAN_H */
diff --git a/include/linux/calc64.h b/include/linux/calc64.h
deleted file mode 100644
index ebf4b8f38d88..000000000000
--- a/include/linux/calc64.h
+++ /dev/null
@@ -1,49 +0,0 @@
1#ifndef _LINUX_CALC64_H
2#define _LINUX_CALC64_H
3
4#include <linux/types.h>
5#include <asm/div64.h>
6
7/*
8 * This is a generic macro which is used when the architecture
9 * specific div64.h does not provide a optimized one.
10 *
11 * The 64bit dividend is divided by the divisor (data type long), the
12 * result is returned and the remainder stored in the variable
13 * referenced by remainder (data type long *). In contrast to the
14 * do_div macro the dividend is kept intact.
15 */
16#ifndef div_long_long_rem
17#define div_long_long_rem(dividend, divisor, remainder) \
18 do_div_llr((dividend), divisor, remainder)
19
20static inline unsigned long do_div_llr(const long long dividend,
21 const long divisor, long *remainder)
22{
23 u64 result = dividend;
24
25 *(remainder) = do_div(result, divisor);
26 return (unsigned long) result;
27}
28#endif
29
30/*
31 * Sign aware variation of the above. On some architectures a
32 * negative dividend leads to an divide overflow exception, which
33 * is avoided by the sign check.
34 */
35static inline long div_long_long_rem_signed(const long long dividend,
36 const long divisor, long *remainder)
37{
38 long res;
39
40 if (unlikely(dividend < 0)) {
41 res = -div_long_long_rem(-dividend, divisor, remainder);
42 *remainder = -(*remainder);
43 } else
44 res = div_long_long_rem(dividend, divisor, remainder);
45
46 return res;
47}
48
49#endif
diff --git a/include/linux/cdev.h b/include/linux/cdev.h
index 1e29b13d0062..fb4591977b03 100644
--- a/include/linux/cdev.h
+++ b/include/linux/cdev.h
@@ -1,6 +1,5 @@
1#ifndef _LINUX_CDEV_H 1#ifndef _LINUX_CDEV_H
2#define _LINUX_CDEV_H 2#define _LINUX_CDEV_H
3#ifdef __KERNEL__
4 3
5#include <linux/kobject.h> 4#include <linux/kobject.h>
6#include <linux/kdev_t.h> 5#include <linux/kdev_t.h>
@@ -34,4 +33,3 @@ void cd_forget(struct inode *);
34extern struct backing_dev_info directly_mappable_cdev_bdi; 33extern struct backing_dev_info directly_mappable_cdev_bdi;
35 34
36#endif 35#endif
37#endif
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index 35094479ca55..55e434feec99 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -93,6 +93,8 @@ struct clocksource {
93#endif 93#endif
94}; 94};
95 95
96extern struct clocksource *clock; /* current clocksource */
97
96/* 98/*
97 * Clock source flags bits:: 99 * Clock source flags bits::
98 */ 100 */
diff --git a/include/linux/coda_fs_i.h b/include/linux/coda_fs_i.h
index 424fe9cf02c4..b3ef0c461578 100644
--- a/include/linux/coda_fs_i.h
+++ b/include/linux/coda_fs_i.h
@@ -8,7 +8,6 @@
8#ifndef _LINUX_CODA_FS_I 8#ifndef _LINUX_CODA_FS_I
9#define _LINUX_CODA_FS_I 9#define _LINUX_CODA_FS_I
10 10
11#ifdef __KERNEL__
12#include <linux/types.h> 11#include <linux/types.h>
13#include <linux/list.h> 12#include <linux/list.h>
14#include <linux/coda.h> 13#include <linux/coda.h>
@@ -52,4 +51,3 @@ struct inode *coda_fid_to_inode(struct CodaFid *fid, struct super_block *sb);
52void coda_replace_fid(struct inode *, struct CodaFid *, struct CodaFid *); 51void coda_replace_fid(struct inode *, struct CodaFid *, struct CodaFid *);
53 52
54#endif 53#endif
55#endif
diff --git a/include/linux/compat.h b/include/linux/compat.h
index 8fa7857e153b..cf8d11cad5ae 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -65,10 +65,11 @@ struct compat_timex {
65 compat_long_t calcnt; 65 compat_long_t calcnt;
66 compat_long_t errcnt; 66 compat_long_t errcnt;
67 compat_long_t stbcnt; 67 compat_long_t stbcnt;
68 compat_int_t tai;
68 69
69 compat_int_t :32; compat_int_t :32; compat_int_t :32; compat_int_t :32; 70 compat_int_t :32; compat_int_t :32; compat_int_t :32; compat_int_t :32;
70 compat_int_t :32; compat_int_t :32; compat_int_t :32; compat_int_t :32; 71 compat_int_t :32; compat_int_t :32; compat_int_t :32; compat_int_t :32;
71 compat_int_t :32; compat_int_t :32; compat_int_t :32; compat_int_t :32; 72 compat_int_t :32; compat_int_t :32; compat_int_t :32;
72}; 73};
73 74
74#define _COMPAT_NSIG_WORDS (_COMPAT_NSIG / _COMPAT_NSIG_BPW) 75#define _COMPAT_NSIG_WORDS (_COMPAT_NSIG / _COMPAT_NSIG_BPW)
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index b2fd7547b58d..5c8351b859f0 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -29,10 +29,11 @@
29 BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(typeof(a), typeof(&a[0]))) 29 BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(typeof(a), typeof(&a[0])))
30 30
31/* 31/*
32 * Force always-inline if the user requests it so via the .config: 32 * Force always-inline if the user requests it so via the .config,
33 * or if gcc is too old:
33 */ 34 */
34#if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \ 35#if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \
35 !defined(CONFIG_OPTIMIZE_INLINING) && (__GNUC__ >= 4) 36 !defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4)
36# define inline inline __attribute__((always_inline)) 37# define inline inline __attribute__((always_inline))
37# define __inline__ __inline__ __attribute__((always_inline)) 38# define __inline__ __inline__ __attribute__((always_inline))
38# define __inline __inline __attribute__((always_inline)) 39# define __inline __inline __attribute__((always_inline))
diff --git a/include/linux/concap.h b/include/linux/concap.h
index 27304651d700..977acb3d1fb2 100644
--- a/include/linux/concap.h
+++ b/include/linux/concap.h
@@ -8,7 +8,7 @@
8 8
9#ifndef _LINUX_CONCAP_H 9#ifndef _LINUX_CONCAP_H
10#define _LINUX_CONCAP_H 10#define _LINUX_CONCAP_H
11#ifdef __KERNEL__ 11
12#include <linux/skbuff.h> 12#include <linux/skbuff.h>
13#include <linux/netdevice.h> 13#include <linux/netdevice.h>
14 14
@@ -110,4 +110,3 @@ extern int concap_nop(struct concap_proto *cprot);
110 */ 110 */
111extern int concap_drop_skb(struct concap_proto *cprot, struct sk_buff *skb); 111extern int concap_drop_skb(struct concap_proto *cprot, struct sk_buff *skb);
112#endif 112#endif
113#endif
diff --git a/include/linux/configfs.h b/include/linux/configfs.h
index 4b287ad9371a..3ae65b1bf90f 100644
--- a/include/linux/configfs.h
+++ b/include/linux/configfs.h
@@ -35,8 +35,6 @@
35#ifndef _CONFIGFS_H_ 35#ifndef _CONFIGFS_H_
36#define _CONFIGFS_H_ 36#define _CONFIGFS_H_
37 37
38#ifdef __KERNEL__
39
40#include <linux/kernel.h> 38#include <linux/kernel.h>
41#include <linux/types.h> 39#include <linux/types.h>
42#include <linux/list.h> 40#include <linux/list.h>
@@ -194,6 +192,4 @@ void configfs_unregister_subsystem(struct configfs_subsystem *subsys);
194int configfs_depend_item(struct configfs_subsystem *subsys, struct config_item *target); 192int configfs_depend_item(struct configfs_subsystem *subsys, struct config_item *target);
195void configfs_undepend_item(struct configfs_subsystem *subsys, struct config_item *target); 193void configfs_undepend_item(struct configfs_subsystem *subsys, struct config_item *target);
196 194
197#endif /* __KERNEL__ */
198
199#endif /* _CONFIGFS_H_ */ 195#endif /* _CONFIGFS_H_ */
diff --git a/include/linux/console.h b/include/linux/console.h
index a5f88a6a259d..a4f27fbdf549 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -91,6 +91,7 @@ void give_up_console(const struct consw *sw);
91#define CON_ENABLED (4) 91#define CON_ENABLED (4)
92#define CON_BOOT (8) 92#define CON_BOOT (8)
93#define CON_ANYTIME (16) /* Safe to call when cpu is offline */ 93#define CON_ANYTIME (16) /* Safe to call when cpu is offline */
94#define CON_BRL (32) /* Used for a braille device */
94 95
95struct console { 96struct console {
96 char name[16]; 97 char name[16];
@@ -121,6 +122,9 @@ extern struct tty_driver *console_device(int *);
121extern void console_stop(struct console *); 122extern void console_stop(struct console *);
122extern void console_start(struct console *); 123extern void console_start(struct console *);
123extern int is_console_locked(void); 124extern int is_console_locked(void);
125extern int braille_register_console(struct console *, int index,
126 char *console_options, char *braille_options);
127extern int braille_unregister_console(struct console *);
124 128
125extern int console_suspend_enabled; 129extern int console_suspend_enabled;
126 130
diff --git a/include/linux/crc-ccitt.h b/include/linux/crc-ccitt.h
index 90037617da8f..f52696a1ff0d 100644
--- a/include/linux/crc-ccitt.h
+++ b/include/linux/crc-ccitt.h
@@ -1,6 +1,5 @@
1#ifndef _LINUX_CRC_CCITT_H 1#ifndef _LINUX_CRC_CCITT_H
2#define _LINUX_CRC_CCITT_H 2#define _LINUX_CRC_CCITT_H
3#ifdef __KERNEL__
4 3
5#include <linux/types.h> 4#include <linux/types.h>
6 5
@@ -13,5 +12,4 @@ static inline u16 crc_ccitt_byte(u16 crc, const u8 c)
13 return (crc >> 8) ^ crc_ccitt_table[(crc ^ c) & 0xff]; 12 return (crc >> 8) ^ crc_ccitt_table[(crc ^ c) & 0xff];
14} 13}
15 14
16#endif /* __KERNEL__ */
17#endif /* _LINUX_CRC_CCITT_H */ 15#endif /* _LINUX_CRC_CCITT_H */
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index cfb1627ac51c..2a6639407c80 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -1,8 +1,6 @@
1#ifndef __LINUX_DCACHE_H 1#ifndef __LINUX_DCACHE_H
2#define __LINUX_DCACHE_H 2#define __LINUX_DCACHE_H
3 3
4#ifdef __KERNEL__
5
6#include <asm/atomic.h> 4#include <asm/atomic.h>
7#include <linux/list.h> 5#include <linux/list.h>
8#include <linux/spinlock.h> 6#include <linux/spinlock.h>
@@ -365,6 +363,4 @@ extern struct dentry *lookup_create(struct nameidata *nd, int is_dir);
365 363
366extern int sysctl_vfs_cache_pressure; 364extern int sysctl_vfs_cache_pressure;
367 365
368#endif /* __KERNEL__ */
369
370#endif /* __LINUX_DCACHE_H */ 366#endif /* __LINUX_DCACHE_H */
diff --git a/include/linux/debugobjects.h b/include/linux/debugobjects.h
new file mode 100644
index 000000000000..8c243aaa86a7
--- /dev/null
+++ b/include/linux/debugobjects.h
@@ -0,0 +1,90 @@
1#ifndef _LINUX_DEBUGOBJECTS_H
2#define _LINUX_DEBUGOBJECTS_H
3
4#include <linux/list.h>
5#include <linux/spinlock.h>
6
7enum debug_obj_state {
8 ODEBUG_STATE_NONE,
9 ODEBUG_STATE_INIT,
10 ODEBUG_STATE_INACTIVE,
11 ODEBUG_STATE_ACTIVE,
12 ODEBUG_STATE_DESTROYED,
13 ODEBUG_STATE_NOTAVAILABLE,
14 ODEBUG_STATE_MAX,
15};
16
17struct debug_obj_descr;
18
19/**
20 * struct debug_obj - representaion of an tracked object
21 * @node: hlist node to link the object into the tracker list
22 * @state: tracked object state
23 * @object: pointer to the real object
24 * @descr: pointer to an object type specific debug description structure
25 */
26struct debug_obj {
27 struct hlist_node node;
28 enum debug_obj_state state;
29 void *object;
30 struct debug_obj_descr *descr;
31};
32
33/**
34 * struct debug_obj_descr - object type specific debug description structure
35 * @name: name of the object typee
36 * @fixup_init: fixup function, which is called when the init check
37 * fails
38 * @fixup_activate: fixup function, which is called when the activate check
39 * fails
40 * @fixup_destroy: fixup function, which is called when the destroy check
41 * fails
42 * @fixup_free: fixup function, which is called when the free check
43 * fails
44 */
45struct debug_obj_descr {
46 const char *name;
47
48 int (*fixup_init) (void *addr, enum debug_obj_state state);
49 int (*fixup_activate) (void *addr, enum debug_obj_state state);
50 int (*fixup_destroy) (void *addr, enum debug_obj_state state);
51 int (*fixup_free) (void *addr, enum debug_obj_state state);
52};
53
54#ifdef CONFIG_DEBUG_OBJECTS
55extern void debug_object_init (void *addr, struct debug_obj_descr *descr);
56extern void
57debug_object_init_on_stack(void *addr, struct debug_obj_descr *descr);
58extern void debug_object_activate (void *addr, struct debug_obj_descr *descr);
59extern void debug_object_deactivate(void *addr, struct debug_obj_descr *descr);
60extern void debug_object_destroy (void *addr, struct debug_obj_descr *descr);
61extern void debug_object_free (void *addr, struct debug_obj_descr *descr);
62
63extern void debug_objects_early_init(void);
64extern void debug_objects_mem_init(void);
65#else
66static inline void
67debug_object_init (void *addr, struct debug_obj_descr *descr) { }
68static inline void
69debug_object_init_on_stack(void *addr, struct debug_obj_descr *descr) { }
70static inline void
71debug_object_activate (void *addr, struct debug_obj_descr *descr) { }
72static inline void
73debug_object_deactivate(void *addr, struct debug_obj_descr *descr) { }
74static inline void
75debug_object_destroy (void *addr, struct debug_obj_descr *descr) { }
76static inline void
77debug_object_free (void *addr, struct debug_obj_descr *descr) { }
78
79static inline void debug_objects_early_init(void) { }
80static inline void debug_objects_mem_init(void) { }
81#endif
82
83#ifdef CONFIG_DEBUG_OBJECTS_FREE
84extern void debug_check_no_obj_freed(const void *address, unsigned long size);
85#else
86static inline void
87debug_check_no_obj_freed(const void *address, unsigned long size) { }
88#endif
89
90#endif
diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
index ad3b787479a4..0d8d419d191a 100644
--- a/include/linux/device-mapper.h
+++ b/include/linux/device-mapper.h
@@ -8,8 +8,6 @@
8#ifndef _LINUX_DEVICE_MAPPER_H 8#ifndef _LINUX_DEVICE_MAPPER_H
9#define _LINUX_DEVICE_MAPPER_H 9#define _LINUX_DEVICE_MAPPER_H
10 10
11#ifdef __KERNEL__
12
13#include <linux/bio.h> 11#include <linux/bio.h>
14 12
15struct dm_target; 13struct dm_target;
@@ -344,5 +342,4 @@ static inline unsigned long to_bytes(sector_t n)
344 return (n << SECTOR_SHIFT); 342 return (n << SECTOR_SHIFT);
345} 343}
346 344
347#endif /* __KERNEL__ */
348#endif /* _LINUX_DEVICE_MAPPER_H */ 345#endif /* _LINUX_DEVICE_MAPPER_H */
diff --git a/include/linux/device.h b/include/linux/device.h
index 1a060265acea..8c23e3dfe3ac 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -35,7 +35,6 @@ struct device;
35struct device_driver; 35struct device_driver;
36struct driver_private; 36struct driver_private;
37struct class; 37struct class;
38struct class_device;
39struct bus_type; 38struct bus_type;
40struct bus_type_private; 39struct bus_type_private;
41 40
@@ -190,13 +189,10 @@ struct class {
190 struct kset class_dirs; 189 struct kset class_dirs;
191 struct semaphore sem; /* locks children, devices, interfaces */ 190 struct semaphore sem; /* locks children, devices, interfaces */
192 struct class_attribute *class_attrs; 191 struct class_attribute *class_attrs;
193 struct class_device_attribute *class_dev_attrs;
194 struct device_attribute *dev_attrs; 192 struct device_attribute *dev_attrs;
195 193
196 int (*uevent)(struct class_device *dev, struct kobj_uevent_env *env);
197 int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env); 194 int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);
198 195
199 void (*release)(struct class_device *dev);
200 void (*class_release)(struct class *class); 196 void (*class_release)(struct class *class);
201 void (*dev_release)(struct device *dev); 197 void (*dev_release)(struct device *dev);
202 198
@@ -210,9 +206,6 @@ extern int class_for_each_device(struct class *class, void *data,
210 int (*fn)(struct device *dev, void *data)); 206 int (*fn)(struct device *dev, void *data));
211extern struct device *class_find_device(struct class *class, void *data, 207extern struct device *class_find_device(struct class *class, void *data,
212 int (*match)(struct device *, void *)); 208 int (*match)(struct device *, void *));
213extern struct class_device *class_find_child(struct class *class, void *data,
214 int (*match)(struct class_device *, void *));
215
216 209
217struct class_attribute { 210struct class_attribute {
218 struct attribute attr; 211 struct attribute attr;
@@ -228,92 +221,10 @@ extern int __must_check class_create_file(struct class *class,
228extern void class_remove_file(struct class *class, 221extern void class_remove_file(struct class *class,
229 const struct class_attribute *attr); 222 const struct class_attribute *attr);
230 223
231struct class_device_attribute {
232 struct attribute attr;
233 ssize_t (*show)(struct class_device *, char *buf);
234 ssize_t (*store)(struct class_device *, const char *buf, size_t count);
235};
236
237#define CLASS_DEVICE_ATTR(_name, _mode, _show, _store) \
238struct class_device_attribute class_device_attr_##_name = \
239 __ATTR(_name, _mode, _show, _store)
240
241extern int __must_check class_device_create_file(struct class_device *,
242 const struct class_device_attribute *);
243
244/**
245 * struct class_device - class devices
246 * @class: pointer to the parent class for this class device. This is required.
247 * @devt: for internal use by the driver core only.
248 * @node: for internal use by the driver core only.
249 * @kobj: for internal use by the driver core only.
250 * @groups: optional additional groups to be created
251 * @dev: if set, a symlink to the struct device is created in the sysfs
252 * directory for this struct class device.
253 * @class_data: pointer to whatever you want to store here for this struct
254 * class_device. Use class_get_devdata() and class_set_devdata() to get and
255 * set this pointer.
256 * @parent: pointer to a struct class_device that is the parent of this struct
257 * class_device. If NULL, this class_device will show up at the root of the
258 * struct class in sysfs (which is probably what you want to have happen.)
259 * @release: pointer to a release function for this struct class_device. If
260 * set, this will be called instead of the class specific release function.
261 * Only use this if you want to override the default release function, like
262 * when you are nesting class_device structures.
263 * @uevent: pointer to a uevent function for this struct class_device. If
264 * set, this will be called instead of the class specific uevent function.
265 * Only use this if you want to override the default uevent function, like
266 * when you are nesting class_device structures.
267 */
268struct class_device {
269 struct list_head node;
270
271 struct kobject kobj;
272 struct class *class;
273 dev_t devt;
274 struct device *dev;
275 void *class_data;
276 struct class_device *parent;
277 struct attribute_group **groups;
278
279 void (*release)(struct class_device *dev);
280 int (*uevent)(struct class_device *dev, struct kobj_uevent_env *env);
281 char class_id[BUS_ID_SIZE];
282};
283
284static inline void *class_get_devdata(struct class_device *dev)
285{
286 return dev->class_data;
287}
288
289static inline void class_set_devdata(struct class_device *dev, void *data)
290{
291 dev->class_data = data;
292}
293
294
295extern int __must_check class_device_register(struct class_device *);
296extern void class_device_unregister(struct class_device *);
297extern void class_device_initialize(struct class_device *);
298extern int __must_check class_device_add(struct class_device *);
299extern void class_device_del(struct class_device *);
300
301extern struct class_device *class_device_get(struct class_device *);
302extern void class_device_put(struct class_device *);
303
304extern void class_device_remove_file(struct class_device *,
305 const struct class_device_attribute *);
306extern int __must_check class_device_create_bin_file(struct class_device *,
307 struct bin_attribute *);
308extern void class_device_remove_bin_file(struct class_device *,
309 struct bin_attribute *);
310
311struct class_interface { 224struct class_interface {
312 struct list_head node; 225 struct list_head node;
313 struct class *class; 226 struct class *class;
314 227
315 int (*add) (struct class_device *, struct class_interface *);
316 void (*remove) (struct class_device *, struct class_interface *);
317 int (*add_dev) (struct device *, struct class_interface *); 228 int (*add_dev) (struct device *, struct class_interface *);
318 void (*remove_dev) (struct device *, struct class_interface *); 229 void (*remove_dev) (struct device *, struct class_interface *);
319}; 230};
@@ -323,13 +234,6 @@ extern void class_interface_unregister(struct class_interface *);
323 234
324extern struct class *class_create(struct module *owner, const char *name); 235extern struct class *class_create(struct module *owner, const char *name);
325extern void class_destroy(struct class *cls); 236extern void class_destroy(struct class *cls);
326extern struct class_device *class_device_create(struct class *cls,
327 struct class_device *parent,
328 dev_t devt,
329 struct device *device,
330 const char *fmt, ...)
331 __attribute__((format(printf, 5, 6)));
332extern void class_device_destroy(struct class *cls, dev_t devt);
333 237
334/* 238/*
335 * The type of device, "struct device" is embedded in. A class 239 * The type of device, "struct device" is embedded in. A class
@@ -465,7 +369,6 @@ struct device {
465 spinlock_t devres_lock; 369 spinlock_t devres_lock;
466 struct list_head devres_head; 370 struct list_head devres_head;
467 371
468 /* class_device migration path */
469 struct list_head node; 372 struct list_head node;
470 struct class *class; 373 struct class *class;
471 dev_t devt; /* dev_t, creates the sysfs "dev" */ 374 dev_t devt; /* dev_t, creates the sysfs "dev" */
@@ -477,6 +380,12 @@ struct device {
477/* Get the wakeup routines, which depend on struct device */ 380/* Get the wakeup routines, which depend on struct device */
478#include <linux/pm_wakeup.h> 381#include <linux/pm_wakeup.h>
479 382
383static inline const char *dev_name(struct device *dev)
384{
385 /* will be changed into kobject_name(&dev->kobj) in the near future */
386 return dev->bus_id;
387}
388
480#ifdef CONFIG_NUMA 389#ifdef CONFIG_NUMA
481static inline int dev_to_node(struct device *dev) 390static inline int dev_to_node(struct device *dev)
482{ 391{
@@ -575,7 +484,7 @@ extern void sysdev_shutdown(void);
575extern const char *dev_driver_string(struct device *dev); 484extern const char *dev_driver_string(struct device *dev);
576#define dev_printk(level, dev, format, arg...) \ 485#define dev_printk(level, dev, format, arg...) \
577 printk(level "%s %s: " format , dev_driver_string(dev) , \ 486 printk(level "%s %s: " format , dev_driver_string(dev) , \
578 (dev)->bus_id , ## arg) 487 dev_name(dev) , ## arg)
579 488
580#define dev_emerg(dev, format, arg...) \ 489#define dev_emerg(dev, format, arg...) \
581 dev_printk(KERN_EMERG , dev , format , ## arg) 490 dev_printk(KERN_EMERG , dev , format , ## arg)
diff --git a/include/linux/devpts_fs.h b/include/linux/devpts_fs.h
index b672ddc00735..154769cad3f3 100644
--- a/include/linux/devpts_fs.h
+++ b/include/linux/devpts_fs.h
@@ -17,6 +17,8 @@
17 17
18#ifdef CONFIG_UNIX98_PTYS 18#ifdef CONFIG_UNIX98_PTYS
19 19
20int devpts_new_index(void);
21void devpts_kill_index(int idx);
20int devpts_pty_new(struct tty_struct *tty); /* mknod in devpts */ 22int devpts_pty_new(struct tty_struct *tty); /* mknod in devpts */
21struct tty_struct *devpts_get_tty(int number); /* get tty structure */ 23struct tty_struct *devpts_get_tty(int number); /* get tty structure */
22void devpts_pty_kill(int number); /* unlink */ 24void devpts_pty_kill(int number); /* unlink */
@@ -24,6 +26,8 @@ void devpts_pty_kill(int number); /* unlink */
24#else 26#else
25 27
26/* Dummy stubs in the no-pty case */ 28/* Dummy stubs in the no-pty case */
29static inline int devpts_new_index(void) { return -EINVAL; }
30static inline void devpts_kill_index(int idx) { }
27static inline int devpts_pty_new(struct tty_struct *tty) { return -EINVAL; } 31static inline int devpts_pty_new(struct tty_struct *tty) { return -EINVAL; }
28static inline struct tty_struct *devpts_get_tty(int number) { return NULL; } 32static inline struct tty_struct *devpts_get_tty(int number) { return NULL; }
29static inline void devpts_pty_kill(int number) { } 33static inline void devpts_pty_kill(int number) { }
diff --git a/include/linux/eventfd.h b/include/linux/eventfd.h
index b489fc6d0b62..a701399b7fed 100644
--- a/include/linux/eventfd.h
+++ b/include/linux/eventfd.h
@@ -8,9 +8,6 @@
8#ifndef _LINUX_EVENTFD_H 8#ifndef _LINUX_EVENTFD_H
9#define _LINUX_EVENTFD_H 9#define _LINUX_EVENTFD_H
10 10
11
12#ifdef __KERNEL__
13
14#ifdef CONFIG_EVENTFD 11#ifdef CONFIG_EVENTFD
15 12
16struct file *eventfd_fget(int fd); 13struct file *eventfd_fget(int fd);
@@ -24,7 +21,5 @@ static inline int eventfd_signal(struct file *file, int n)
24 21
25#endif /* CONFIG_EVENTFD */ 22#endif /* CONFIG_EVENTFD */
26 23
27#endif /* __KERNEL__ */
28
29#endif /* _LINUX_EVENTFD_H */ 24#endif /* _LINUX_EVENTFD_H */
30 25
diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
new file mode 100644
index 000000000000..a118f3c0b240
--- /dev/null
+++ b/include/linux/fdtable.h
@@ -0,0 +1,99 @@
1/*
2 * descriptor table internals; you almost certainly want file.h instead.
3 */
4
5#ifndef __LINUX_FDTABLE_H
6#define __LINUX_FDTABLE_H
7
8#include <asm/atomic.h>
9#include <linux/posix_types.h>
10#include <linux/compiler.h>
11#include <linux/spinlock.h>
12#include <linux/rcupdate.h>
13#include <linux/types.h>
14
15/*
16 * The default fd array needs to be at least BITS_PER_LONG,
17 * as this is the granularity returned by copy_fdset().
18 */
19#define NR_OPEN_DEFAULT BITS_PER_LONG
20
21/*
22 * The embedded_fd_set is a small fd_set,
23 * suitable for most tasks (which open <= BITS_PER_LONG files)
24 */
25struct embedded_fd_set {
26 unsigned long fds_bits[1];
27};
28
29struct fdtable {
30 unsigned int max_fds;
31 struct file ** fd; /* current fd array */
32 fd_set *close_on_exec;
33 fd_set *open_fds;
34 struct rcu_head rcu;
35 struct fdtable *next;
36};
37
38/*
39 * Open file table structure
40 */
41struct files_struct {
42 /*
43 * read mostly part
44 */
45 atomic_t count;
46 struct fdtable *fdt;
47 struct fdtable fdtab;
48 /*
49 * written part on a separate cache line in SMP
50 */
51 spinlock_t file_lock ____cacheline_aligned_in_smp;
52 int next_fd;
53 struct embedded_fd_set close_on_exec_init;
54 struct embedded_fd_set open_fds_init;
55 struct file * fd_array[NR_OPEN_DEFAULT];
56};
57
58#define files_fdtable(files) (rcu_dereference((files)->fdt))
59
60extern struct kmem_cache *filp_cachep;
61
62struct file_operations;
63struct vfsmount;
64struct dentry;
65
66extern int expand_files(struct files_struct *, int nr);
67extern void free_fdtable_rcu(struct rcu_head *rcu);
68extern void __init files_defer_init(void);
69
70static inline void free_fdtable(struct fdtable *fdt)
71{
72 call_rcu(&fdt->rcu, free_fdtable_rcu);
73}
74
75static inline struct file * fcheck_files(struct files_struct *files, unsigned int fd)
76{
77 struct file * file = NULL;
78 struct fdtable *fdt = files_fdtable(files);
79
80 if (fd < fdt->max_fds)
81 file = rcu_dereference(fdt->fd[fd]);
82 return file;
83}
84
85/*
86 * Check whether the specified fd has an open file.
87 */
88#define fcheck(fd) fcheck_files(current->files, fd)
89
90struct task_struct;
91
92struct files_struct *get_files_struct(struct task_struct *);
93void put_files_struct(struct files_struct *fs);
94void reset_files_struct(struct files_struct *);
95int unshare_files(struct files_struct **);
96
97extern struct kmem_cache *files_cachep;
98
99#endif /* __LINUX_FDTABLE_H */
diff --git a/include/linux/file.h b/include/linux/file.h
index 69baf5a4f0a5..27c64bdc68c9 100644
--- a/include/linux/file.h
+++ b/include/linux/file.h
@@ -5,59 +5,11 @@
5#ifndef __LINUX_FILE_H 5#ifndef __LINUX_FILE_H
6#define __LINUX_FILE_H 6#define __LINUX_FILE_H
7 7
8#include <asm/atomic.h>
9#include <linux/posix_types.h>
10#include <linux/compiler.h> 8#include <linux/compiler.h>
11#include <linux/spinlock.h>
12#include <linux/rcupdate.h>
13#include <linux/types.h> 9#include <linux/types.h>
10#include <linux/posix_types.h>
14 11
15/* 12struct file;
16 * The default fd array needs to be at least BITS_PER_LONG,
17 * as this is the granularity returned by copy_fdset().
18 */
19#define NR_OPEN_DEFAULT BITS_PER_LONG
20
21/*
22 * The embedded_fd_set is a small fd_set,
23 * suitable for most tasks (which open <= BITS_PER_LONG files)
24 */
25struct embedded_fd_set {
26 unsigned long fds_bits[1];
27};
28
29struct fdtable {
30 unsigned int max_fds;
31 struct file ** fd; /* current fd array */
32 fd_set *close_on_exec;
33 fd_set *open_fds;
34 struct rcu_head rcu;
35 struct fdtable *next;
36};
37
38/*
39 * Open file table structure
40 */
41struct files_struct {
42 /*
43 * read mostly part
44 */
45 atomic_t count;
46 struct fdtable *fdt;
47 struct fdtable fdtab;
48 /*
49 * written part on a separate cache line in SMP
50 */
51 spinlock_t file_lock ____cacheline_aligned_in_smp;
52 int next_fd;
53 struct embedded_fd_set close_on_exec_init;
54 struct embedded_fd_set open_fds_init;
55 struct file * fd_array[NR_OPEN_DEFAULT];
56};
57
58#define files_fdtable(files) (rcu_dereference((files)->fdt))
59
60extern struct kmem_cache *filp_cachep;
61 13
62extern void __fput(struct file *); 14extern void __fput(struct file *);
63extern void fput(struct file *); 15extern void fput(struct file *);
@@ -85,41 +37,7 @@ extern void put_filp(struct file *);
85extern int get_unused_fd(void); 37extern int get_unused_fd(void);
86extern int get_unused_fd_flags(int flags); 38extern int get_unused_fd_flags(int flags);
87extern void put_unused_fd(unsigned int fd); 39extern void put_unused_fd(unsigned int fd);
88struct kmem_cache;
89
90extern int expand_files(struct files_struct *, int nr);
91extern void free_fdtable_rcu(struct rcu_head *rcu);
92extern void __init files_defer_init(void);
93
94static inline void free_fdtable(struct fdtable *fdt)
95{
96 call_rcu(&fdt->rcu, free_fdtable_rcu);
97}
98
99static inline struct file * fcheck_files(struct files_struct *files, unsigned int fd)
100{
101 struct file * file = NULL;
102 struct fdtable *fdt = files_fdtable(files);
103
104 if (fd < fdt->max_fds)
105 file = rcu_dereference(fdt->fd[fd]);
106 return file;
107}
108
109/*
110 * Check whether the specified fd has an open file.
111 */
112#define fcheck(fd) fcheck_files(current->files, fd)
113 40
114extern void fd_install(unsigned int fd, struct file *file); 41extern void fd_install(unsigned int fd, struct file *file);
115 42
116struct task_struct;
117
118struct files_struct *get_files_struct(struct task_struct *);
119void put_files_struct(struct files_struct *fs);
120void reset_files_struct(struct files_struct *);
121int unshare_files(struct files_struct **);
122
123extern struct kmem_cache *files_cachep;
124
125#endif /* __LINUX_FILE_H */ 43#endif /* __LINUX_FILE_H */
diff --git a/include/linux/fsl_devices.h b/include/linux/fsl_devices.h
index 2cad5c67397e..c415a496de3a 100644
--- a/include/linux/fsl_devices.h
+++ b/include/linux/fsl_devices.h
@@ -14,7 +14,6 @@
14 * option) any later version. 14 * option) any later version.
15 */ 15 */
16 16
17#ifdef __KERNEL__
18#ifndef _FSL_DEVICE_H_ 17#ifndef _FSL_DEVICE_H_
19#define _FSL_DEVICE_H_ 18#define _FSL_DEVICE_H_
20 19
@@ -127,4 +126,3 @@ struct mpc8xx_pcmcia_ops {
127}; 126};
128 127
129#endif /* _FSL_DEVICE_H_ */ 128#endif /* _FSL_DEVICE_H_ */
130#endif /* __KERNEL__ */
diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
index d4b7c4ac72e6..a89513188ce7 100644
--- a/include/linux/fsnotify.h
+++ b/include/linux/fsnotify.h
@@ -11,8 +11,6 @@
11 * (C) Copyright 2005 Robert Love 11 * (C) Copyright 2005 Robert Love
12 */ 12 */
13 13
14#ifdef __KERNEL__
15
16#include <linux/dnotify.h> 14#include <linux/dnotify.h>
17#include <linux/inotify.h> 15#include <linux/inotify.h>
18#include <linux/audit.h> 16#include <linux/audit.h>
@@ -296,6 +294,4 @@ static inline void fsnotify_oldname_free(const char *old_name)
296 294
297#endif /* ! CONFIG_INOTIFY */ 295#endif /* ! CONFIG_INOTIFY */
298 296
299#endif /* __KERNEL__ */
300
301#endif /* _LINUX_FS_NOTIFY_H */ 297#endif /* _LINUX_FS_NOTIFY_H */
diff --git a/include/linux/generic_serial.h b/include/linux/generic_serial.h
index 5412da28fa47..110833666e37 100644
--- a/include/linux/generic_serial.h
+++ b/include/linux/generic_serial.h
@@ -78,7 +78,7 @@ struct gs_port {
78#define GS_DEBUG_WRITE 0x00000040 78#define GS_DEBUG_WRITE 0x00000040
79 79
80#ifdef __KERNEL__ 80#ifdef __KERNEL__
81void gs_put_char(struct tty_struct *tty, unsigned char ch); 81int gs_put_char(struct tty_struct *tty, unsigned char ch);
82int gs_write(struct tty_struct *tty, 82int gs_write(struct tty_struct *tty,
83 const unsigned char *buf, int count); 83 const unsigned char *buf, int count);
84int gs_write_room(struct tty_struct *tty); 84int gs_write_room(struct tty_struct *tty);
diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
index 56f3236da829..6d93dce61cbb 100644
--- a/include/linux/hrtimer.h
+++ b/include/linux/hrtimer.h
@@ -266,6 +266,21 @@ extern ktime_t ktime_get_real(void);
266extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock, 266extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock,
267 enum hrtimer_mode mode); 267 enum hrtimer_mode mode);
268 268
269#ifdef CONFIG_DEBUG_OBJECTS_TIMERS
270extern void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t which_clock,
271 enum hrtimer_mode mode);
272
273extern void destroy_hrtimer_on_stack(struct hrtimer *timer);
274#else
275static inline void hrtimer_init_on_stack(struct hrtimer *timer,
276 clockid_t which_clock,
277 enum hrtimer_mode mode)
278{
279 hrtimer_init(timer, which_clock, mode);
280}
281static inline void destroy_hrtimer_on_stack(struct hrtimer *timer) { }
282#endif
283
269/* Basic timer operations: */ 284/* Basic timer operations: */
270extern int hrtimer_start(struct hrtimer *timer, ktime_t tim, 285extern int hrtimer_start(struct hrtimer *timer, ktime_t tim,
271 const enum hrtimer_mode mode); 286 const enum hrtimer_mode mode);
@@ -301,6 +316,15 @@ static inline int hrtimer_is_queued(struct hrtimer *timer)
301 (HRTIMER_STATE_ENQUEUED | HRTIMER_STATE_PENDING); 316 (HRTIMER_STATE_ENQUEUED | HRTIMER_STATE_PENDING);
302} 317}
303 318
319/*
320 * Helper function to check, whether the timer is running the callback
321 * function
322 */
323static inline int hrtimer_callback_running(struct hrtimer *timer)
324{
325 return timer->state & HRTIMER_STATE_CALLBACK;
326}
327
304/* Forward a hrtimer so it expires after now: */ 328/* Forward a hrtimer so it expires after now: */
305extern u64 329extern u64
306hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval); 330hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval);
diff --git a/include/linux/hw_random.h b/include/linux/hw_random.h
index 85d11916e9ea..7244456e7e65 100644
--- a/include/linux/hw_random.h
+++ b/include/linux/hw_random.h
@@ -11,7 +11,6 @@
11 11
12#ifndef LINUX_HWRANDOM_H_ 12#ifndef LINUX_HWRANDOM_H_
13#define LINUX_HWRANDOM_H_ 13#define LINUX_HWRANDOM_H_
14#ifdef __KERNEL__
15 14
16#include <linux/types.h> 15#include <linux/types.h>
17#include <linux/list.h> 16#include <linux/list.h>
@@ -46,5 +45,4 @@ extern int hwrng_register(struct hwrng *rng);
46/** Unregister a Hardware Random Number Generator driver. */ 45/** Unregister a Hardware Random Number Generator driver. */
47extern void hwrng_unregister(struct hwrng *rng); 46extern void hwrng_unregister(struct hwrng *rng);
48 47
49#endif /* __KERNEL__ */
50#endif /* LINUX_HWRANDOM_H_ */ 48#endif /* LINUX_HWRANDOM_H_ */
diff --git a/include/linux/i2o.h b/include/linux/i2o.h
index f65e58a1d925..7d51cbca49ab 100644
--- a/include/linux/i2o.h
+++ b/include/linux/i2o.h
@@ -18,8 +18,6 @@
18#ifndef _I2O_H 18#ifndef _I2O_H
19#define _I2O_H 19#define _I2O_H
20 20
21#ifdef __KERNEL__ /* This file to be included by kernel only */
22
23#include <linux/i2o-dev.h> 21#include <linux/i2o-dev.h>
24 22
25/* How many different OSM's are we allowing */ 23/* How many different OSM's are we allowing */
@@ -1255,5 +1253,4 @@ extern void i2o_dump_message(struct i2o_message *);
1255extern void i2o_dump_hrt(struct i2o_controller *c); 1253extern void i2o_dump_hrt(struct i2o_controller *c);
1256extern void i2o_debug_state(struct i2o_controller *c); 1254extern void i2o_debug_state(struct i2o_controller *c);
1257 1255
1258#endif /* __KERNEL__ */
1259#endif /* _I2O_H */ 1256#endif /* _I2O_H */
diff --git a/include/linux/ieee80211.h b/include/linux/ieee80211.h
index 529f301d9372..0b5e03eae6d2 100644
--- a/include/linux/ieee80211.h
+++ b/include/linux/ieee80211.h
@@ -113,7 +113,7 @@ struct ieee80211_hdr {
113struct ieee80211s_hdr { 113struct ieee80211s_hdr {
114 u8 flags; 114 u8 flags;
115 u8 ttl; 115 u8 ttl;
116 u8 seqnum[3]; 116 __le32 seqnum;
117 u8 eaddr1[6]; 117 u8 eaddr1[6];
118 u8 eaddr2[6]; 118 u8 eaddr2[6];
119 u8 eaddr3[6]; 119 u8 eaddr3[6];
diff --git a/include/linux/if_bridge.h b/include/linux/if_bridge.h
index 58e43e566457..950e13d09e06 100644
--- a/include/linux/if_bridge.h
+++ b/include/linux/if_bridge.h
@@ -97,7 +97,9 @@ struct __fdb_entry
97 __u8 port_no; 97 __u8 port_no;
98 __u8 is_local; 98 __u8 is_local;
99 __u32 ageing_timer_value; 99 __u32 ageing_timer_value;
100 __u32 unused; 100 __u8 port_hi;
101 __u8 pad0;
102 __u16 unused;
101}; 103};
102 104
103#ifdef __KERNEL__ 105#ifdef __KERNEL__
diff --git a/include/linux/if_macvlan.h b/include/linux/if_macvlan.h
index 0d9d7ea2c1cc..5f200bac3749 100644
--- a/include/linux/if_macvlan.h
+++ b/include/linux/if_macvlan.h
@@ -1,9 +1,6 @@
1#ifndef _LINUX_IF_MACVLAN_H 1#ifndef _LINUX_IF_MACVLAN_H
2#define _LINUX_IF_MACVLAN_H 2#define _LINUX_IF_MACVLAN_H
3 3
4#ifdef __KERNEL__
5
6extern struct sk_buff *(*macvlan_handle_frame_hook)(struct sk_buff *); 4extern struct sk_buff *(*macvlan_handle_frame_hook)(struct sk_buff *);
7 5
8#endif /* __KERNEL__ */
9#endif /* _LINUX_IF_MACVLAN_H */ 6#endif /* _LINUX_IF_MACVLAN_H */
diff --git a/include/linux/inet.h b/include/linux/inet.h
index 675a7dbe86f8..1354080cf8cf 100644
--- a/include/linux/inet.h
+++ b/include/linux/inet.h
@@ -42,11 +42,9 @@
42#ifndef _LINUX_INET_H 42#ifndef _LINUX_INET_H
43#define _LINUX_INET_H 43#define _LINUX_INET_H
44 44
45#ifdef __KERNEL__
46#include <linux/types.h> 45#include <linux/types.h>
47 46
48extern __be32 in_aton(const char *str); 47extern __be32 in_aton(const char *str);
49extern int in4_pton(const char *src, int srclen, u8 *dst, int delim, const char **end); 48extern int in4_pton(const char *src, int srclen, u8 *dst, int delim, const char **end);
50extern int in6_pton(const char *src, int srclen, u8 *dst, int delim, const char **end); 49extern int in6_pton(const char *src, int srclen, u8 *dst, int delim, const char **end);
51#endif
52#endif /* _LINUX_INET_H */ 50#endif /* _LINUX_INET_H */
diff --git a/include/linux/init_task.h b/include/linux/init_task.h
index bf6b8a61f8db..b24c2875aa05 100644
--- a/include/linux/init_task.h
+++ b/include/linux/init_task.h
@@ -1,7 +1,7 @@
1#ifndef _LINUX__INIT_TASK_H 1#ifndef _LINUX__INIT_TASK_H
2#define _LINUX__INIT_TASK_H 2#define _LINUX__INIT_TASK_H
3 3
4#include <linux/file.h> 4#include <linux/fdtable.h>
5#include <linux/rcupdate.h> 5#include <linux/rcupdate.h>
6#include <linux/irqflags.h> 6#include <linux/irqflags.h>
7#include <linux/utsname.h> 7#include <linux/utsname.h>
diff --git a/include/linux/io.h b/include/linux/io.h
index e3b2dda6c8eb..6c7f0ba0d5fa 100644
--- a/include/linux/io.h
+++ b/include/linux/io.h
@@ -58,12 +58,13 @@ static inline void devm_ioport_unmap(struct device *dev, void __iomem *addr)
58} 58}
59#endif 59#endif
60 60
61void __iomem * devm_ioremap(struct device *dev, unsigned long offset, 61void __iomem *devm_ioremap(struct device *dev, resource_size_t offset,
62 unsigned long size); 62 unsigned long size);
63void __iomem * devm_ioremap_nocache(struct device *dev, unsigned long offset, 63void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset,
64 unsigned long size); 64 unsigned long size);
65void devm_iounmap(struct device *dev, void __iomem *addr); 65void devm_iounmap(struct device *dev, void __iomem *addr);
66int check_signature(const volatile void __iomem *io_addr, 66int check_signature(const volatile void __iomem *io_addr,
67 const unsigned char *signature, int length); 67 const unsigned char *signature, int length);
68void devm_ioremap_release(struct device *dev, void *res);
68 69
69#endif /* _LINUX_IO_H */ 70#endif /* _LINUX_IO_H */
diff --git a/include/linux/irq.h b/include/linux/irq.h
index 1883a85625dd..552e0ec269c9 100644
--- a/include/linux/irq.h
+++ b/include/linux/irq.h
@@ -61,6 +61,7 @@ typedef void (*irq_flow_handler_t)(unsigned int irq,
61#define IRQ_WAKEUP 0x00100000 /* IRQ triggers system wakeup */ 61#define IRQ_WAKEUP 0x00100000 /* IRQ triggers system wakeup */
62#define IRQ_MOVE_PENDING 0x00200000 /* need to re-target IRQ destination */ 62#define IRQ_MOVE_PENDING 0x00200000 /* need to re-target IRQ destination */
63#define IRQ_NO_BALANCING 0x00400000 /* IRQ is excluded from balancing */ 63#define IRQ_NO_BALANCING 0x00400000 /* IRQ is excluded from balancing */
64#define IRQ_SPURIOUS_DISABLED 0x00800000 /* IRQ was disabled by the spurious trap */
64 65
65#ifdef CONFIG_IRQ_PER_CPU 66#ifdef CONFIG_IRQ_PER_CPU
66# define CHECK_IRQ_PER_CPU(var) ((var) & IRQ_PER_CPU) 67# define CHECK_IRQ_PER_CPU(var) ((var) & IRQ_PER_CPU)
diff --git a/include/linux/isapnp.h b/include/linux/isapnp.h
index 1e8728a9ee8a..cd5a269fdb5e 100644
--- a/include/linux/isapnp.h
+++ b/include/linux/isapnp.h
@@ -26,16 +26,6 @@
26#include <linux/pnp.h> 26#include <linux/pnp.h>
27 27
28/* 28/*
29 * Configuration registers (TODO: change by specification)
30 */
31
32#define ISAPNP_CFG_ACTIVATE 0x30 /* byte */
33#define ISAPNP_CFG_MEM 0x40 /* 4 * dword */
34#define ISAPNP_CFG_PORT 0x60 /* 8 * word */
35#define ISAPNP_CFG_IRQ 0x70 /* 2 * word */
36#define ISAPNP_CFG_DMA 0x74 /* 2 * byte */
37
38/*
39 * 29 *
40 */ 30 */
41 31
diff --git a/include/linux/isicom.h b/include/linux/isicom.h
index 8f4c71759d73..bbd42197298f 100644
--- a/include/linux/isicom.h
+++ b/include/linux/isicom.h
@@ -1,11 +1,6 @@
1#ifndef _LINUX_ISICOM_H 1#ifndef _LINUX_ISICOM_H
2#define _LINUX_ISICOM_H 2#define _LINUX_ISICOM_H
3 3
4/*#define ISICOM_DEBUG*/
5/*#define ISICOM_DEBUG_DTR_RTS*/
6
7#ifdef __KERNEL__
8
9#define YES 1 4#define YES 1
10#define NO 0 5#define NO 0
11 6
@@ -85,6 +80,4 @@
85 80
86#define ISI_TXOK 0x0001 81#define ISI_TXOK 0x0001
87 82
88#endif /* __KERNEL__ */
89
90#endif /* ISICOM_H */ 83#endif /* ISICOM_H */
diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
index 33ef710dac24..abb6ac639e8e 100644
--- a/include/linux/jiffies.h
+++ b/include/linux/jiffies.h
@@ -1,7 +1,7 @@
1#ifndef _LINUX_JIFFIES_H 1#ifndef _LINUX_JIFFIES_H
2#define _LINUX_JIFFIES_H 2#define _LINUX_JIFFIES_H
3 3
4#include <linux/calc64.h> 4#include <linux/math64.h>
5#include <linux/kernel.h> 5#include <linux/kernel.h>
6#include <linux/types.h> 6#include <linux/types.h>
7#include <linux/time.h> 7#include <linux/time.h>
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 53839ba265ec..4d46e299afb5 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -338,33 +338,90 @@ extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
338#endif /* __LITTLE_ENDIAN */ 338#endif /* __LITTLE_ENDIAN */
339 339
340/* 340/*
341 * min()/max() macros that also do 341 * min()/max()/clamp() macros that also do
342 * strict type-checking.. See the 342 * strict type-checking.. See the
343 * "unnecessary" pointer comparison. 343 * "unnecessary" pointer comparison.
344 */ 344 */
345#define min(x,y) ({ \ 345#define min(x, y) ({ \
346 typeof(x) _x = (x); \ 346 typeof(x) _min1 = (x); \
347 typeof(y) _y = (y); \ 347 typeof(y) _min2 = (y); \
348 (void) (&_x == &_y); \ 348 (void) (&_min1 == &_min2); \
349 _x < _y ? _x : _y; }) 349 _min1 < _min2 ? _min1 : _min2; })
350 350
351#define max(x,y) ({ \ 351#define max(x, y) ({ \
352 typeof(x) _x = (x); \ 352 typeof(x) _max1 = (x); \
353 typeof(y) _y = (y); \ 353 typeof(y) _max2 = (y); \
354 (void) (&_x == &_y); \ 354 (void) (&_max1 == &_max2); \
355 _x > _y ? _x : _y; }) 355 _max1 > _max2 ? _max1 : _max2; })
356
357/**
358 * clamp - return a value clamped to a given range with strict typechecking
359 * @val: current value
360 * @min: minimum allowable value
361 * @max: maximum allowable value
362 *
363 * This macro does strict typechecking of min/max to make sure they are of the
364 * same type as val. See the unnecessary pointer comparisons.
365 */
366#define clamp(val, min, max) ({ \
367 typeof(val) __val = (val); \
368 typeof(min) __min = (min); \
369 typeof(max) __max = (max); \
370 (void) (&__val == &__min); \
371 (void) (&__val == &__max); \
372 __val = __val < __min ? __min: __val; \
373 __val > __max ? __max: __val; })
356 374
357/* 375/*
358 * ..and if you can't take the strict 376 * ..and if you can't take the strict
359 * types, you can specify one yourself. 377 * types, you can specify one yourself.
360 * 378 *
361 * Or not use min/max at all, of course. 379 * Or not use min/max/clamp at all, of course.
380 */
381#define min_t(type, x, y) ({ \
382 type __min1 = (x); \
383 type __min2 = (y); \
384 __min1 < __min2 ? __min1: __min2; })
385
386#define max_t(type, x, y) ({ \
387 type __max1 = (x); \
388 type __max2 = (y); \
389 __max1 > __max2 ? __max1: __max2; })
390
391/**
392 * clamp_t - return a value clamped to a given range using a given type
393 * @type: the type of variable to use
394 * @val: current value
395 * @min: minimum allowable value
396 * @max: maximum allowable value
397 *
398 * This macro does no typechecking and uses temporary variables of type
399 * 'type' to make all the comparisons.
362 */ 400 */
363#define min_t(type,x,y) \ 401#define clamp_t(type, val, min, max) ({ \
364 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; }) 402 type __val = (val); \
365#define max_t(type,x,y) \ 403 type __min = (min); \
366 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; }) 404 type __max = (max); \
405 __val = __val < __min ? __min: __val; \
406 __val > __max ? __max: __val; })
367 407
408/**
409 * clamp_val - return a value clamped to a given range using val's type
410 * @val: current value
411 * @min: minimum allowable value
412 * @max: maximum allowable value
413 *
414 * This macro does no typechecking and uses temporary variables of whatever
415 * type the input argument 'val' is. This is useful when val is an unsigned
416 * type and min and max are literals that will otherwise be assigned a signed
417 * integer type.
418 */
419#define clamp_val(val, min, max) ({ \
420 typeof(val) __val = (val); \
421 typeof(val) __min = (min); \
422 typeof(val) __max = (max); \
423 __val = __val < __min ? __min: __val; \
424 __val > __max ? __max: __val; })
368 425
369/** 426/**
370 * container_of - cast a member of a structure out to the containing structure 427 * container_of - cast a member of a structure out to the containing structure
diff --git a/include/linux/kfifo.h b/include/linux/kfifo.h
index 404f4464cb1a..29f62e1733ff 100644
--- a/include/linux/kfifo.h
+++ b/include/linux/kfifo.h
@@ -21,8 +21,6 @@
21#ifndef _LINUX_KFIFO_H 21#ifndef _LINUX_KFIFO_H
22#define _LINUX_KFIFO_H 22#define _LINUX_KFIFO_H
23 23
24#ifdef __KERNEL__
25
26#include <linux/kernel.h> 24#include <linux/kernel.h>
27#include <linux/spinlock.h> 25#include <linux/spinlock.h>
28 26
@@ -151,7 +149,4 @@ static inline unsigned int kfifo_len(struct kfifo *fifo)
151 return ret; 149 return ret;
152} 150}
153 151
154#else
155#warning "don't include kernel headers in userspace"
156#endif /* __KERNEL__ */
157#endif 152#endif
diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
index 9757b1a6d9dc..6adcc297e354 100644
--- a/include/linux/kgdb.h
+++ b/include/linux/kgdb.h
@@ -261,10 +261,12 @@ struct kgdb_io {
261 261
262extern struct kgdb_arch arch_kgdb_ops; 262extern struct kgdb_arch arch_kgdb_ops;
263 263
264extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
265
264extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops); 266extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
265extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops); 267extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
266 268
267extern int kgdb_hex2long(char **ptr, long *long_val); 269extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
268extern int kgdb_mem2hex(char *mem, char *buf, int count); 270extern int kgdb_mem2hex(char *mem, char *buf, int count);
269extern int kgdb_hex2mem(char *buf, char *mem, int count); 271extern int kgdb_hex2mem(char *buf, char *mem, int count);
270 272
diff --git a/include/linux/klist.h b/include/linux/klist.h
index 74071254c9d3..06c338ef7f1b 100644
--- a/include/linux/klist.h
+++ b/include/linux/klist.h
@@ -25,37 +25,47 @@ struct klist {
25 void (*put)(struct klist_node *); 25 void (*put)(struct klist_node *);
26}; 26};
27 27
28#define KLIST_INIT(_name, _get, _put) \
29 { .k_lock = __SPIN_LOCK_UNLOCKED(_name.k_lock), \
30 .k_list = LIST_HEAD_INIT(_name.k_list), \
31 .get = _get, \
32 .put = _put, }
28 33
29extern void klist_init(struct klist * k, void (*get)(struct klist_node *), 34#define DEFINE_KLIST(_name, _get, _put) \
35 struct klist _name = KLIST_INIT(_name, _get, _put)
36
37extern void klist_init(struct klist *k, void (*get)(struct klist_node *),
30 void (*put)(struct klist_node *)); 38 void (*put)(struct klist_node *));
31 39
32struct klist_node { 40struct klist_node {
33 struct klist * n_klist; 41 struct klist *n_klist;
34 struct list_head n_node; 42 struct list_head n_node;
35 struct kref n_ref; 43 struct kref n_ref;
36 struct completion n_removed; 44 struct completion n_removed;
37}; 45};
38 46
39extern void klist_add_tail(struct klist_node * n, struct klist * k); 47extern void klist_add_tail(struct klist_node *n, struct klist *k);
40extern void klist_add_head(struct klist_node * n, struct klist * k); 48extern void klist_add_head(struct klist_node *n, struct klist *k);
49extern void klist_add_after(struct klist_node *n, struct klist_node *pos);
50extern void klist_add_before(struct klist_node *n, struct klist_node *pos);
41 51
42extern void klist_del(struct klist_node * n); 52extern void klist_del(struct klist_node *n);
43extern void klist_remove(struct klist_node * n); 53extern void klist_remove(struct klist_node *n);
44 54
45extern int klist_node_attached(struct klist_node * n); 55extern int klist_node_attached(struct klist_node *n);
46 56
47 57
48struct klist_iter { 58struct klist_iter {
49 struct klist * i_klist; 59 struct klist *i_klist;
50 struct list_head * i_head; 60 struct list_head *i_head;
51 struct klist_node * i_cur; 61 struct klist_node *i_cur;
52}; 62};
53 63
54 64
55extern void klist_iter_init(struct klist * k, struct klist_iter * i); 65extern void klist_iter_init(struct klist *k, struct klist_iter *i);
56extern void klist_iter_init_node(struct klist * k, struct klist_iter * i, 66extern void klist_iter_init_node(struct klist *k, struct klist_iter *i,
57 struct klist_node * n); 67 struct klist_node *n);
58extern void klist_iter_exit(struct klist_iter * i); 68extern void klist_iter_exit(struct klist_iter *i);
59extern struct klist_node * klist_next(struct klist_iter * i); 69extern struct klist_node *klist_next(struct klist_iter *i);
60 70
61#endif 71#endif
diff --git a/include/linux/kobj_map.h b/include/linux/kobj_map.h
index bafe178a381f..73717ed9ea79 100644
--- a/include/linux/kobj_map.h
+++ b/include/linux/kobj_map.h
@@ -1,5 +1,3 @@
1#ifdef __KERNEL__
2
3#include <linux/mutex.h> 1#include <linux/mutex.h>
4 2
5typedef struct kobject *kobj_probe_t(dev_t, int *, void *); 3typedef struct kobject *kobj_probe_t(dev_t, int *, void *);
@@ -10,5 +8,3 @@ int kobj_map(struct kobj_map *, dev_t, unsigned long, struct module *,
10void kobj_unmap(struct kobj_map *, dev_t, unsigned long); 8void kobj_unmap(struct kobj_map *, dev_t, unsigned long);
11struct kobject *kobj_lookup(struct kobj_map *, dev_t, int *); 9struct kobject *kobj_lookup(struct kobj_map *, dev_t, int *);
12struct kobj_map *kobj_map_init(kobj_probe_t *, struct mutex *); 10struct kobj_map *kobj_map_init(kobj_probe_t *, struct mutex *);
13
14#endif
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index caa3f411f15d..39e709f88aa0 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -16,8 +16,6 @@
16#ifndef _KOBJECT_H_ 16#ifndef _KOBJECT_H_
17#define _KOBJECT_H_ 17#define _KOBJECT_H_
18 18
19#ifdef __KERNEL__
20
21#include <linux/types.h> 19#include <linux/types.h>
22#include <linux/list.h> 20#include <linux/list.h>
23#include <linux/sysfs.h> 21#include <linux/sysfs.h>
@@ -224,5 +222,4 @@ static inline int kobject_action_type(const char *buf, size_t count,
224{ return -EINVAL; } 222{ return -EINVAL; }
225#endif 223#endif
226 224
227#endif /* __KERNEL__ */
228#endif /* _KOBJECT_H_ */ 225#endif /* _KOBJECT_H_ */
diff --git a/include/linux/kref.h b/include/linux/kref.h
index 5d185635786e..0cef6badd6fb 100644
--- a/include/linux/kref.h
+++ b/include/linux/kref.h
@@ -15,8 +15,6 @@
15#ifndef _KREF_H_ 15#ifndef _KREF_H_
16#define _KREF_H_ 16#define _KREF_H_
17 17
18#ifdef __KERNEL__
19
20#include <linux/types.h> 18#include <linux/types.h>
21#include <asm/atomic.h> 19#include <asm/atomic.h>
22 20
@@ -29,5 +27,4 @@ void kref_init(struct kref *kref);
29void kref_get(struct kref *kref); 27void kref_get(struct kref *kref);
30int kref_put(struct kref *kref, void (*release) (struct kref *kref)); 28int kref_put(struct kref *kref, void (*release) (struct kref *kref));
31 29
32#endif /* __KERNEL__ */
33#endif /* _KREF_H_ */ 30#endif /* _KREF_H_ */
diff --git a/include/linux/list.h b/include/linux/list.h
index 7627508f1b74..08cf4f651889 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -1,8 +1,6 @@
1#ifndef _LINUX_LIST_H 1#ifndef _LINUX_LIST_H
2#define _LINUX_LIST_H 2#define _LINUX_LIST_H
3 3
4#ifdef __KERNEL__
5
6#include <linux/stddef.h> 4#include <linux/stddef.h>
7#include <linux/poison.h> 5#include <linux/poison.h>
8#include <linux/prefetch.h> 6#include <linux/prefetch.h>
@@ -983,7 +981,4 @@ static inline void hlist_add_after_rcu(struct hlist_node *prev,
983 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ 981 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
984 pos = rcu_dereference(pos->next)) 982 pos = rcu_dereference(pos->next))
985 983
986#else
987#warning "don't include kernel headers in userspace"
988#endif /* __KERNEL__ */
989#endif 984#endif
diff --git a/include/linux/math64.h b/include/linux/math64.h
new file mode 100644
index 000000000000..c1a5f81501ff
--- /dev/null
+++ b/include/linux/math64.h
@@ -0,0 +1,84 @@
1#ifndef _LINUX_MATH64_H
2#define _LINUX_MATH64_H
3
4#include <linux/types.h>
5#include <asm/div64.h>
6
7#if BITS_PER_LONG == 64
8
9/**
10 * div_u64_rem - unsigned 64bit divide with 32bit divisor with remainder
11 *
12 * This is commonly provided by 32bit archs to provide an optimized 64bit
13 * divide.
14 */
15static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16{
17 *remainder = dividend % divisor;
18 return dividend / divisor;
19}
20
21/**
22 * div_s64_rem - signed 64bit divide with 32bit divisor with remainder
23 */
24static inline s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
25{
26 *remainder = dividend % divisor;
27 return dividend / divisor;
28}
29
30/**
31 * div64_u64 - unsigned 64bit divide with 64bit divisor
32 */
33static inline u64 div64_u64(u64 dividend, u64 divisor)
34{
35 return dividend / divisor;
36}
37
38#elif BITS_PER_LONG == 32
39
40#ifndef div_u64_rem
41static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
42{
43 *remainder = do_div(dividend, divisor);
44 return dividend;
45}
46#endif
47
48#ifndef div_s64_rem
49extern s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder);
50#endif
51
52#ifndef div64_u64
53extern u64 div64_u64(u64 dividend, u64 divisor);
54#endif
55
56#endif /* BITS_PER_LONG */
57
58/**
59 * div_u64 - unsigned 64bit divide with 32bit divisor
60 *
61 * This is the most common 64bit divide and should be used if possible,
62 * as many 32bit archs can optimize this variant better than a full 64bit
63 * divide.
64 */
65#ifndef div_u64
66static inline u64 div_u64(u64 dividend, u32 divisor)
67{
68 u32 remainder;
69 return div_u64_rem(dividend, divisor, &remainder);
70}
71#endif
72
73/**
74 * div_s64 - signed 64bit divide with 32bit divisor
75 */
76#ifndef div_s64
77static inline s64 div_s64(s64 dividend, s32 divisor)
78{
79 s32 remainder;
80 return div_s64_rem(dividend, divisor, &remainder);
81}
82#endif
83
84#endif /* _LINUX_MATH64_H */
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index aad98003176f..c463cd8a15a4 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -1,7 +1,6 @@
1#ifndef _LINUX_MMZONE_H 1#ifndef _LINUX_MMZONE_H
2#define _LINUX_MMZONE_H 2#define _LINUX_MMZONE_H
3 3
4#ifdef __KERNEL__
5#ifndef __ASSEMBLY__ 4#ifndef __ASSEMBLY__
6#ifndef __GENERATING_BOUNDS_H 5#ifndef __GENERATING_BOUNDS_H
7 6
@@ -97,6 +96,7 @@ enum zone_stat_item {
97 NR_UNSTABLE_NFS, /* NFS unstable pages */ 96 NR_UNSTABLE_NFS, /* NFS unstable pages */
98 NR_BOUNCE, 97 NR_BOUNCE,
99 NR_VMSCAN_WRITE, 98 NR_VMSCAN_WRITE,
99 NR_WRITEBACK_TEMP, /* Writeback using temporary buffers */
100#ifdef CONFIG_NUMA 100#ifdef CONFIG_NUMA
101 NUMA_HIT, /* allocated in intended node */ 101 NUMA_HIT, /* allocated in intended node */
102 NUMA_MISS, /* allocated in non intended node */ 102 NUMA_MISS, /* allocated in non intended node */
@@ -1004,5 +1004,4 @@ unsigned long __init node_memmap_size_bytes(int, unsigned long, unsigned long);
1004 1004
1005#endif /* !__GENERATING_BOUNDS.H */ 1005#endif /* !__GENERATING_BOUNDS.H */
1006#endif /* !__ASSEMBLY__ */ 1006#endif /* !__ASSEMBLY__ */
1007#endif /* __KERNEL__ */
1008#endif /* _LINUX_MMZONE_H */ 1007#endif /* _LINUX_MMZONE_H */
diff --git a/include/linux/module.h b/include/linux/module.h
index 819c4e889bf1..3e03b1acbc94 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -190,7 +190,7 @@ void *__symbol_get_gpl(const char *symbol);
190 extern typeof(sym) sym; \ 190 extern typeof(sym) sym; \
191 __CRC_SYMBOL(sym, sec) \ 191 __CRC_SYMBOL(sym, sec) \
192 static const char __kstrtab_##sym[] \ 192 static const char __kstrtab_##sym[] \
193 __attribute__((section("__ksymtab_strings"))) \ 193 __attribute__((section("__ksymtab_strings"), aligned(1))) \
194 = MODULE_SYMBOL_PREFIX #sym; \ 194 = MODULE_SYMBOL_PREFIX #sym; \
195 static const struct kernel_symbol __ksymtab_##sym \ 195 static const struct kernel_symbol __ksymtab_##sym \
196 __used \ 196 __used \
@@ -229,23 +229,6 @@ enum module_state
229 MODULE_STATE_GOING, 229 MODULE_STATE_GOING,
230}; 230};
231 231
232/* Similar stuff for section attributes. */
233struct module_sect_attr
234{
235 struct module_attribute mattr;
236 char *name;
237 unsigned long address;
238};
239
240struct module_sect_attrs
241{
242 struct attribute_group grp;
243 int nsections;
244 struct module_sect_attr attrs[0];
245};
246
247struct module_param_attrs;
248
249struct module 232struct module
250{ 233{
251 enum module_state state; 234 enum module_state state;
diff --git a/include/linux/mount.h b/include/linux/mount.h
index b4836d58f428..4374d1adeb4b 100644
--- a/include/linux/mount.h
+++ b/include/linux/mount.h
@@ -10,7 +10,6 @@
10 */ 10 */
11#ifndef _LINUX_MOUNT_H 11#ifndef _LINUX_MOUNT_H
12#define _LINUX_MOUNT_H 12#define _LINUX_MOUNT_H
13#ifdef __KERNEL__
14 13
15#include <linux/types.h> 14#include <linux/types.h>
16#include <linux/list.h> 15#include <linux/list.h>
@@ -114,5 +113,4 @@ extern void mark_mounts_for_expiry(struct list_head *mounts);
114extern spinlock_t vfsmount_lock; 113extern spinlock_t vfsmount_lock;
115extern dev_t name_to_dev_t(char *name); 114extern dev_t name_to_dev_t(char *name);
116 115
117#endif
118#endif /* _LINUX_MOUNT_H */ 116#endif /* _LINUX_MOUNT_H */
diff --git a/include/linux/mtd/jedec.h b/include/linux/mtd/jedec.h
deleted file mode 100644
index 9006feb218b9..000000000000
--- a/include/linux/mtd/jedec.h
+++ /dev/null
@@ -1,66 +0,0 @@
1
2/* JEDEC Flash Interface.
3 * This is an older type of interface for self programming flash. It is
4 * commonly use in older AMD chips and is obsolete compared with CFI.
5 * It is called JEDEC because the JEDEC association distributes the ID codes
6 * for the chips.
7 *
8 * See the AMD flash databook for information on how to operate the interface.
9 *
10 * $Id: jedec.h,v 1.4 2005/11/07 11:14:54 gleixner Exp $
11 */
12
13#ifndef __LINUX_MTD_JEDEC_H__
14#define __LINUX_MTD_JEDEC_H__
15
16#include <linux/types.h>
17
18#define MAX_JEDEC_CHIPS 16
19
20// Listing of all supported chips and their information
21struct JEDECTable
22{
23 __u16 jedec;
24 char *name;
25 unsigned long size;
26 unsigned long sectorsize;
27 __u32 capabilities;
28};
29
30// JEDEC being 0 is the end of the chip array
31struct jedec_flash_chip
32{
33 __u16 jedec;
34 unsigned long size;
35 unsigned long sectorsize;
36
37 // *(__u8*)(base + (adder << addrshift)) = data << datashift
38 // Address size = size << addrshift
39 unsigned long base; // Byte 0 of the flash, will be unaligned
40 unsigned int datashift; // Useful for 32bit/16bit accesses
41 unsigned int addrshift;
42 unsigned long offset; // linerized start. base==offset for unbanked, uninterleaved flash
43
44 __u32 capabilities;
45
46 // These markers are filled in by the flash_chip_scan function
47 unsigned long start;
48 unsigned long length;
49};
50
51struct jedec_private
52{
53 unsigned long size; // Total size of all the devices
54
55 /* Bank handling. If sum(bank_fill) == size then this is linear flash.
56 Otherwise the mapping has holes in it. bank_fill may be used to
57 find the holes, but in the common symetric case
58 bank_fill[0] == bank_fill[*], thus addresses may be computed
59 mathmatically. bank_fill must be powers of two */
60 unsigned is_banked;
61 unsigned long bank_fill[MAX_JEDEC_CHIPS];
62
63 struct jedec_flash_chip chips[MAX_JEDEC_CHIPS];
64};
65
66#endif
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 0a13bb35f044..245f9098e171 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -143,10 +143,12 @@ struct mtd_info {
143 int (*erase) (struct mtd_info *mtd, struct erase_info *instr); 143 int (*erase) (struct mtd_info *mtd, struct erase_info *instr);
144 144
145 /* This stuff for eXecute-In-Place */ 145 /* This stuff for eXecute-In-Place */
146 int (*point) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char **mtdbuf); 146 /* phys is optional and may be set to NULL */
147 int (*point) (struct mtd_info *mtd, loff_t from, size_t len,
148 size_t *retlen, void **virt, resource_size_t *phys);
147 149
148 /* We probably shouldn't allow XIP if the unpoint isn't a NULL */ 150 /* We probably shouldn't allow XIP if the unpoint isn't a NULL */
149 void (*unpoint) (struct mtd_info *mtd, u_char * addr, loff_t from, size_t len); 151 void (*unpoint) (struct mtd_info *mtd, loff_t from, size_t len);
150 152
151 153
152 int (*read) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); 154 int (*read) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
diff --git a/include/linux/mtd/pmc551.h b/include/linux/mtd/pmc551.h
index a7f6d20ad407..5cc070c24d88 100644
--- a/include/linux/mtd/pmc551.h
+++ b/include/linux/mtd/pmc551.h
@@ -36,8 +36,9 @@ struct mypriv {
36 * Function Prototypes 36 * Function Prototypes
37 */ 37 */
38static int pmc551_erase(struct mtd_info *, struct erase_info *); 38static int pmc551_erase(struct mtd_info *, struct erase_info *);
39static void pmc551_unpoint(struct mtd_info *, u_char *, loff_t, size_t); 39static void pmc551_unpoint(struct mtd_info *, loff_t, size_t);
40static int pmc551_point (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char **mtdbuf); 40static int pmc551_point(struct mtd_info *mtd, loff_t from, size_t len,
41 size_t *retlen, void **virt, resource_size_t *phys);
41static int pmc551_read(struct mtd_info *, loff_t, size_t, size_t *, u_char *); 42static int pmc551_read(struct mtd_info *, loff_t, size_t, size_t *, u_char *);
42static int pmc551_write(struct mtd_info *, loff_t, size_t, size_t *, const u_char *); 43static int pmc551_write(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
43 44
diff --git a/include/linux/ncp_fs_i.h b/include/linux/ncp_fs_i.h
index bdb4c8ae6924..4b0bec477846 100644
--- a/include/linux/ncp_fs_i.h
+++ b/include/linux/ncp_fs_i.h
@@ -8,8 +8,6 @@
8#ifndef _LINUX_NCP_FS_I 8#ifndef _LINUX_NCP_FS_I
9#define _LINUX_NCP_FS_I 9#define _LINUX_NCP_FS_I
10 10
11#ifdef __KERNEL__
12
13/* 11/*
14 * This is the ncpfs part of the inode structure. This must contain 12 * This is the ncpfs part of the inode structure. This must contain
15 * all the information we need to work with an inode after creation. 13 * all the information we need to work with an inode after creation.
@@ -28,6 +26,4 @@ struct ncp_inode_info {
28 struct inode vfs_inode; 26 struct inode vfs_inode;
29}; 27};
30 28
31#endif /* __KERNEL__ */
32
33#endif /* _LINUX_NCP_FS_I */ 29#endif /* _LINUX_NCP_FS_I */
diff --git a/include/linux/of_device.h b/include/linux/of_device.h
index 6dc11959770c..afe338217d91 100644
--- a/include/linux/of_device.h
+++ b/include/linux/of_device.h
@@ -1,6 +1,5 @@
1#ifndef _LINUX_OF_DEVICE_H 1#ifndef _LINUX_OF_DEVICE_H
2#define _LINUX_OF_DEVICE_H 2#define _LINUX_OF_DEVICE_H
3#ifdef __KERNEL__
4 3
5#include <linux/device.h> 4#include <linux/device.h>
6#include <linux/of.h> 5#include <linux/of.h>
@@ -25,5 +24,4 @@ static inline void of_device_free(struct of_device *dev)
25 of_release_dev(&dev->dev); 24 of_release_dev(&dev->dev);
26} 25}
27 26
28#endif /* __KERNEL__ */
29#endif /* _LINUX_OF_DEVICE_H */ 27#endif /* _LINUX_OF_DEVICE_H */
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 96acd0dae241..509159bcd4e7 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -44,6 +44,7 @@
44#include <linux/mod_devicetable.h> 44#include <linux/mod_devicetable.h>
45 45
46#include <linux/types.h> 46#include <linux/types.h>
47#include <linux/init.h>
47#include <linux/ioport.h> 48#include <linux/ioport.h>
48#include <linux/list.h> 49#include <linux/list.h>
49#include <linux/compiler.h> 50#include <linux/compiler.h>
@@ -474,7 +475,7 @@ extern struct pci_bus *pci_find_bus(int domain, int busnr);
474void pci_bus_add_devices(struct pci_bus *bus); 475void pci_bus_add_devices(struct pci_bus *bus);
475struct pci_bus *pci_scan_bus_parented(struct device *parent, int bus, 476struct pci_bus *pci_scan_bus_parented(struct device *parent, int bus,
476 struct pci_ops *ops, void *sysdata); 477 struct pci_ops *ops, void *sysdata);
477static inline struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops, 478static inline struct pci_bus * __devinit pci_scan_bus(int bus, struct pci_ops *ops,
478 void *sysdata) 479 void *sysdata)
479{ 480{
480 struct pci_bus *root_bus; 481 struct pci_bus *root_bus;
@@ -666,7 +667,7 @@ int pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,
666 667
667void pci_walk_bus(struct pci_bus *top, void (*cb)(struct pci_dev *, void *), 668void pci_walk_bus(struct pci_bus *top, void (*cb)(struct pci_dev *, void *),
668 void *userdata); 669 void *userdata);
669int pci_cfg_space_size_ext(struct pci_dev *dev, unsigned check_exp_pcix); 670int pci_cfg_space_size_ext(struct pci_dev *dev);
670int pci_cfg_space_size(struct pci_dev *dev); 671int pci_cfg_space_size(struct pci_dev *dev);
671unsigned char pci_bus_max_busnr(struct pci_bus *bus); 672unsigned char pci_bus_max_busnr(struct pci_bus *bus);
672 673
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index e5a53daf17f1..cf6dbd759395 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -1429,6 +1429,7 @@
1429#define PCI_DEVICE_ID_NEO_2DB9PRI 0x00C9 1429#define PCI_DEVICE_ID_NEO_2DB9PRI 0x00C9
1430#define PCI_DEVICE_ID_NEO_2RJ45 0x00CA 1430#define PCI_DEVICE_ID_NEO_2RJ45 0x00CA
1431#define PCI_DEVICE_ID_NEO_2RJ45PRI 0x00CB 1431#define PCI_DEVICE_ID_NEO_2RJ45PRI 0x00CB
1432#define PCIE_DEVICE_ID_NEO_4_IBM 0x00F4
1432 1433
1433#define PCI_VENDOR_ID_XIRCOM 0x115d 1434#define PCI_VENDOR_ID_XIRCOM 0x115d
1434#define PCI_DEVICE_ID_XIRCOM_RBM56G 0x0101 1435#define PCI_DEVICE_ID_XIRCOM_RBM56G 0x0101
diff --git a/include/linux/pda_power.h b/include/linux/pda_power.h
index 225beb136807..cb7d10f30763 100644
--- a/include/linux/pda_power.h
+++ b/include/linux/pda_power.h
@@ -16,10 +16,14 @@
16#define PDA_POWER_CHARGE_AC (1 << 0) 16#define PDA_POWER_CHARGE_AC (1 << 0)
17#define PDA_POWER_CHARGE_USB (1 << 1) 17#define PDA_POWER_CHARGE_USB (1 << 1)
18 18
19struct device;
20
19struct pda_power_pdata { 21struct pda_power_pdata {
22 int (*init)(struct device *dev);
20 int (*is_ac_online)(void); 23 int (*is_ac_online)(void);
21 int (*is_usb_online)(void); 24 int (*is_usb_online)(void);
22 void (*set_charge)(int flags); 25 void (*set_charge)(int flags);
26 void (*exit)(struct device *dev);
23 27
24 char **supplied_to; 28 char **supplied_to;
25 size_t num_supplicants; 29 size_t num_supplicants;
diff --git a/include/linux/pid.h b/include/linux/pid.h
index c7980810eb09..c21c7e8124a7 100644
--- a/include/linux/pid.h
+++ b/include/linux/pid.h
@@ -60,7 +60,7 @@ struct pid
60 /* lists of tasks that use this pid */ 60 /* lists of tasks that use this pid */
61 struct hlist_head tasks[PIDTYPE_MAX]; 61 struct hlist_head tasks[PIDTYPE_MAX];
62 struct rcu_head rcu; 62 struct rcu_head rcu;
63 int level; 63 unsigned int level;
64 struct upid numbers[1]; 64 struct upid numbers[1];
65}; 65};
66 66
@@ -89,9 +89,11 @@ extern struct pid *get_task_pid(struct task_struct *task, enum pid_type type);
89 * attach_pid() and detach_pid() must be called with the tasklist_lock 89 * attach_pid() and detach_pid() must be called with the tasklist_lock
90 * write-held. 90 * write-held.
91 */ 91 */
92extern int attach_pid(struct task_struct *task, enum pid_type type, 92extern void attach_pid(struct task_struct *task, enum pid_type type,
93 struct pid *pid); 93 struct pid *pid);
94extern void detach_pid(struct task_struct *task, enum pid_type); 94extern void detach_pid(struct task_struct *task, enum pid_type);
95extern void change_pid(struct task_struct *task, enum pid_type,
96 struct pid *pid);
95extern void transfer_pid(struct task_struct *old, struct task_struct *new, 97extern void transfer_pid(struct task_struct *old, struct task_struct *new,
96 enum pid_type); 98 enum pid_type);
97 99
diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
index fcd61fa2c833..caff5283d15c 100644
--- a/include/linux/pid_namespace.h
+++ b/include/linux/pid_namespace.h
@@ -20,7 +20,7 @@ struct pid_namespace {
20 int last_pid; 20 int last_pid;
21 struct task_struct *child_reaper; 21 struct task_struct *child_reaper;
22 struct kmem_cache *pid_cachep; 22 struct kmem_cache *pid_cachep;
23 int level; 23 unsigned int level;
24 struct pid_namespace *parent; 24 struct pid_namespace *parent;
25#ifdef CONFIG_PROC_FS 25#ifdef CONFIG_PROC_FS
26 struct vfsmount *proc_mnt; 26 struct vfsmount *proc_mnt;
diff --git a/include/linux/pm.h b/include/linux/pm.h
index 1de72cbbe0d1..39a7ee859b67 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -21,8 +21,6 @@
21#ifndef _LINUX_PM_H 21#ifndef _LINUX_PM_H
22#define _LINUX_PM_H 22#define _LINUX_PM_H
23 23
24#ifdef __KERNEL__
25
26#include <linux/list.h> 24#include <linux/list.h>
27#include <asm/atomic.h> 25#include <asm/atomic.h>
28#include <asm/errno.h> 26#include <asm/errno.h>
@@ -225,6 +223,4 @@ extern unsigned int pm_flags;
225#define PM_APM 1 223#define PM_APM 1
226#define PM_ACPI 2 224#define PM_ACPI 2
227 225
228#endif /* __KERNEL__ */
229
230#endif /* _LINUX_PM_H */ 226#endif /* _LINUX_PM_H */
diff --git a/include/linux/pnp.h b/include/linux/pnp.h
index b2f05c230f4b..63b128d512fb 100644
--- a/include/linux/pnp.h
+++ b/include/linux/pnp.h
@@ -6,66 +6,127 @@
6#ifndef _LINUX_PNP_H 6#ifndef _LINUX_PNP_H
7#define _LINUX_PNP_H 7#define _LINUX_PNP_H
8 8
9#ifdef __KERNEL__
10
11#include <linux/device.h> 9#include <linux/device.h>
12#include <linux/list.h> 10#include <linux/list.h>
13#include <linux/errno.h> 11#include <linux/errno.h>
14#include <linux/mod_devicetable.h> 12#include <linux/mod_devicetable.h>
15 13
16#define PNP_MAX_PORT 40
17#define PNP_MAX_MEM 24
18#define PNP_MAX_IRQ 2
19#define PNP_MAX_DMA 2
20#define PNP_NAME_LEN 50 14#define PNP_NAME_LEN 50
21 15
22struct pnp_protocol; 16struct pnp_protocol;
23struct pnp_dev; 17struct pnp_dev;
18struct pnp_resource_table;
24 19
25/* 20/*
26 * Resource Management 21 * Resource Management
27 */ 22 */
23struct resource *pnp_get_resource(struct pnp_dev *, unsigned int, unsigned int);
24
25static inline int pnp_resource_valid(struct resource *res)
26{
27 if (res && !(res->flags & IORESOURCE_UNSET))
28 return 1;
29 return 0;
30}
31
32static inline resource_size_t pnp_resource_len(struct resource *res)
33{
34 if (res->start == 0 && res->end == 0)
35 return 0;
36 return res->end - res->start + 1;
37}
38
39
40static inline resource_size_t pnp_port_start(struct pnp_dev *dev,
41 unsigned int bar)
42{
43 return pnp_get_resource(dev, IORESOURCE_IO, bar)->start;
44}
45
46static inline resource_size_t pnp_port_end(struct pnp_dev *dev,
47 unsigned int bar)
48{
49 return pnp_get_resource(dev, IORESOURCE_IO, bar)->end;
50}
51
52static inline unsigned long pnp_port_flags(struct pnp_dev *dev,
53 unsigned int bar)
54{
55 return pnp_get_resource(dev, IORESOURCE_IO, bar)->flags;
56}
57
58static inline int pnp_port_valid(struct pnp_dev *dev, unsigned int bar)
59{
60 return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_IO, bar));
61}
62
63static inline resource_size_t pnp_port_len(struct pnp_dev *dev,
64 unsigned int bar)
65{
66 return pnp_resource_len(pnp_get_resource(dev, IORESOURCE_IO, bar));
67}
68
69
70static inline resource_size_t pnp_mem_start(struct pnp_dev *dev,
71 unsigned int bar)
72{
73 return pnp_get_resource(dev, IORESOURCE_MEM, bar)->start;
74}
75
76static inline resource_size_t pnp_mem_end(struct pnp_dev *dev,
77 unsigned int bar)
78{
79 return pnp_get_resource(dev, IORESOURCE_MEM, bar)->end;
80}
81
82static inline unsigned long pnp_mem_flags(struct pnp_dev *dev, unsigned int bar)
83{
84 return pnp_get_resource(dev, IORESOURCE_MEM, bar)->flags;
85}
86
87static inline int pnp_mem_valid(struct pnp_dev *dev, unsigned int bar)
88{
89 return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_MEM, bar));
90}
91
92static inline resource_size_t pnp_mem_len(struct pnp_dev *dev,
93 unsigned int bar)
94{
95 return pnp_resource_len(pnp_get_resource(dev, IORESOURCE_MEM, bar));
96}
97
98
99static inline resource_size_t pnp_irq(struct pnp_dev *dev, unsigned int bar)
100{
101 return pnp_get_resource(dev, IORESOURCE_IRQ, bar)->start;
102}
103
104static inline unsigned long pnp_irq_flags(struct pnp_dev *dev, unsigned int bar)
105{
106 return pnp_get_resource(dev, IORESOURCE_IRQ, bar)->flags;
107}
108
109static inline int pnp_irq_valid(struct pnp_dev *dev, unsigned int bar)
110{
111 return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_IRQ, bar));
112}
113
114
115static inline resource_size_t pnp_dma(struct pnp_dev *dev, unsigned int bar)
116{
117 return pnp_get_resource(dev, IORESOURCE_DMA, bar)->start;
118}
119
120static inline unsigned long pnp_dma_flags(struct pnp_dev *dev, unsigned int bar)
121{
122 return pnp_get_resource(dev, IORESOURCE_DMA, bar)->flags;
123}
124
125static inline int pnp_dma_valid(struct pnp_dev *dev, unsigned int bar)
126{
127 return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_DMA, bar));
128}
28 129
29/* Use these instead of directly reading pnp_dev to get resource information */
30#define pnp_port_start(dev,bar) ((dev)->res.port_resource[(bar)].start)
31#define pnp_port_end(dev,bar) ((dev)->res.port_resource[(bar)].end)
32#define pnp_port_flags(dev,bar) ((dev)->res.port_resource[(bar)].flags)
33#define pnp_port_valid(dev,bar) \
34 ((pnp_port_flags((dev),(bar)) & (IORESOURCE_IO | IORESOURCE_UNSET)) \
35 == IORESOURCE_IO)
36#define pnp_port_len(dev,bar) \
37 ((pnp_port_start((dev),(bar)) == 0 && \
38 pnp_port_end((dev),(bar)) == \
39 pnp_port_start((dev),(bar))) ? 0 : \
40 \
41 (pnp_port_end((dev),(bar)) - \
42 pnp_port_start((dev),(bar)) + 1))
43
44#define pnp_mem_start(dev,bar) ((dev)->res.mem_resource[(bar)].start)
45#define pnp_mem_end(dev,bar) ((dev)->res.mem_resource[(bar)].end)
46#define pnp_mem_flags(dev,bar) ((dev)->res.mem_resource[(bar)].flags)
47#define pnp_mem_valid(dev,bar) \
48 ((pnp_mem_flags((dev),(bar)) & (IORESOURCE_MEM | IORESOURCE_UNSET)) \
49 == IORESOURCE_MEM)
50#define pnp_mem_len(dev,bar) \
51 ((pnp_mem_start((dev),(bar)) == 0 && \
52 pnp_mem_end((dev),(bar)) == \
53 pnp_mem_start((dev),(bar))) ? 0 : \
54 \
55 (pnp_mem_end((dev),(bar)) - \
56 pnp_mem_start((dev),(bar)) + 1))
57
58#define pnp_irq(dev,bar) ((dev)->res.irq_resource[(bar)].start)
59#define pnp_irq_flags(dev,bar) ((dev)->res.irq_resource[(bar)].flags)
60#define pnp_irq_valid(dev,bar) \
61 ((pnp_irq_flags((dev),(bar)) & (IORESOURCE_IRQ | IORESOURCE_UNSET)) \
62 == IORESOURCE_IRQ)
63
64#define pnp_dma(dev,bar) ((dev)->res.dma_resource[(bar)].start)
65#define pnp_dma_flags(dev,bar) ((dev)->res.dma_resource[(bar)].flags)
66#define pnp_dma_valid(dev,bar) \
67 ((pnp_dma_flags((dev),(bar)) & (IORESOURCE_DMA | IORESOURCE_UNSET)) \
68 == IORESOURCE_DMA)
69 130
70#define PNP_PORT_FLAG_16BITADDR (1<<0) 131#define PNP_PORT_FLAG_16BITADDR (1<<0)
71#define PNP_PORT_FLAG_FIXED (1<<1) 132#define PNP_PORT_FLAG_FIXED (1<<1)
@@ -118,13 +179,6 @@ struct pnp_option {
118 struct pnp_option *next; /* used to chain dependent resources */ 179 struct pnp_option *next; /* used to chain dependent resources */
119}; 180};
120 181
121struct pnp_resource_table {
122 struct resource port_resource[PNP_MAX_PORT];
123 struct resource mem_resource[PNP_MAX_MEM];
124 struct resource dma_resource[PNP_MAX_DMA];
125 struct resource irq_resource[PNP_MAX_IRQ];
126};
127
128/* 182/*
129 * Device Management 183 * Device Management
130 */ 184 */
@@ -194,10 +248,9 @@ struct pnp_dev {
194 int capabilities; 248 int capabilities;
195 struct pnp_option *independent; 249 struct pnp_option *independent;
196 struct pnp_option *dependent; 250 struct pnp_option *dependent;
197 struct pnp_resource_table res; 251 struct pnp_resource_table *res;
198 252
199 char name[PNP_NAME_LEN]; /* contains a human-readable name */ 253 char name[PNP_NAME_LEN]; /* contains a human-readable name */
200 unsigned short regs; /* ISAPnP: supported registers */
201 int flags; /* used by protocols */ 254 int flags; /* used by protocols */
202 struct proc_dir_entry *procent; /* device entry in /proc/bus/isapnp */ 255 struct proc_dir_entry *procent; /* device entry in /proc/bus/isapnp */
203 void *data; 256 void *data;
@@ -328,8 +381,8 @@ struct pnp_protocol {
328 char *name; 381 char *name;
329 382
330 /* resource control functions */ 383 /* resource control functions */
331 int (*get) (struct pnp_dev *dev, struct pnp_resource_table *res); 384 int (*get) (struct pnp_dev *dev);
332 int (*set) (struct pnp_dev *dev, struct pnp_resource_table *res); 385 int (*set) (struct pnp_dev *dev);
333 int (*disable) (struct pnp_dev *dev); 386 int (*disable) (struct pnp_dev *dev);
334 387
335 /* protocol specific suspend/resume */ 388 /* protocol specific suspend/resume */
@@ -358,20 +411,12 @@ extern struct bus_type pnp_bus_type;
358#if defined(CONFIG_PNP) 411#if defined(CONFIG_PNP)
359 412
360/* device management */ 413/* device management */
361int pnp_register_protocol(struct pnp_protocol *protocol);
362void pnp_unregister_protocol(struct pnp_protocol *protocol);
363int pnp_add_device(struct pnp_dev *dev);
364int pnp_device_attach(struct pnp_dev *pnp_dev); 414int pnp_device_attach(struct pnp_dev *pnp_dev);
365void pnp_device_detach(struct pnp_dev *pnp_dev); 415void pnp_device_detach(struct pnp_dev *pnp_dev);
366extern struct list_head pnp_global; 416extern struct list_head pnp_global;
367extern int pnp_platform_devices; 417extern int pnp_platform_devices;
368 418
369/* multidevice card support */ 419/* multidevice card support */
370int pnp_add_card(struct pnp_card *card);
371void pnp_remove_card(struct pnp_card *card);
372int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev);
373void pnp_remove_card_device(struct pnp_dev *dev);
374int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card);
375struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink, 420struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink,
376 const char *id, struct pnp_dev *from); 421 const char *id, struct pnp_dev *from);
377void pnp_release_card_device(struct pnp_dev *dev); 422void pnp_release_card_device(struct pnp_dev *dev);
@@ -380,77 +425,42 @@ void pnp_unregister_card_driver(struct pnp_card_driver *drv);
380extern struct list_head pnp_cards; 425extern struct list_head pnp_cards;
381 426
382/* resource management */ 427/* resource management */
383struct pnp_option *pnp_register_independent_option(struct pnp_dev *dev);
384struct pnp_option *pnp_register_dependent_option(struct pnp_dev *dev,
385 int priority);
386int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data);
387int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data);
388int pnp_register_port_resource(struct pnp_option *option,
389 struct pnp_port *data);
390int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data);
391void pnp_init_resource_table(struct pnp_resource_table *table);
392int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res,
393 int mode);
394int pnp_auto_config_dev(struct pnp_dev *dev); 428int pnp_auto_config_dev(struct pnp_dev *dev);
395int pnp_validate_config(struct pnp_dev *dev);
396int pnp_start_dev(struct pnp_dev *dev); 429int pnp_start_dev(struct pnp_dev *dev);
397int pnp_stop_dev(struct pnp_dev *dev); 430int pnp_stop_dev(struct pnp_dev *dev);
398int pnp_activate_dev(struct pnp_dev *dev); 431int pnp_activate_dev(struct pnp_dev *dev);
399int pnp_disable_dev(struct pnp_dev *dev); 432int pnp_disable_dev(struct pnp_dev *dev);
400void pnp_resource_change(struct resource *resource, resource_size_t start,
401 resource_size_t size);
402 433
403/* protocol helpers */ 434/* protocol helpers */
404int pnp_is_active(struct pnp_dev *dev); 435int pnp_is_active(struct pnp_dev *dev);
405int compare_pnp_id(struct pnp_id *pos, const char *id); 436int compare_pnp_id(struct pnp_id *pos, const char *id);
406int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev);
407int pnp_register_driver(struct pnp_driver *drv); 437int pnp_register_driver(struct pnp_driver *drv);
408void pnp_unregister_driver(struct pnp_driver *drv); 438void pnp_unregister_driver(struct pnp_driver *drv);
409 439
410#else 440#else
411 441
412/* device management */ 442/* device management */
413static inline int pnp_register_protocol(struct pnp_protocol *protocol) { return -ENODEV; }
414static inline void pnp_unregister_protocol(struct pnp_protocol *protocol) { }
415static inline int pnp_init_device(struct pnp_dev *dev) { return -ENODEV; }
416static inline int pnp_add_device(struct pnp_dev *dev) { return -ENODEV; }
417static inline int pnp_device_attach(struct pnp_dev *pnp_dev) { return -ENODEV; } 443static inline int pnp_device_attach(struct pnp_dev *pnp_dev) { return -ENODEV; }
418static inline void pnp_device_detach(struct pnp_dev *pnp_dev) { } 444static inline void pnp_device_detach(struct pnp_dev *pnp_dev) { }
419 445
420#define pnp_platform_devices 0 446#define pnp_platform_devices 0
421 447
422/* multidevice card support */ 448/* multidevice card support */
423static inline int pnp_add_card(struct pnp_card *card) { return -ENODEV; }
424static inline void pnp_remove_card(struct pnp_card *card) { }
425static inline int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev) { return -ENODEV; }
426static inline void pnp_remove_card_device(struct pnp_dev *dev) { }
427static inline int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card) { return -ENODEV; }
428static inline struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink, const char *id, struct pnp_dev *from) { return NULL; } 449static inline struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink, const char *id, struct pnp_dev *from) { return NULL; }
429static inline void pnp_release_card_device(struct pnp_dev *dev) { } 450static inline void pnp_release_card_device(struct pnp_dev *dev) { }
430static inline int pnp_register_card_driver(struct pnp_card_driver *drv) { return -ENODEV; } 451static inline int pnp_register_card_driver(struct pnp_card_driver *drv) { return -ENODEV; }
431static inline void pnp_unregister_card_driver(struct pnp_card_driver *drv) { } 452static inline void pnp_unregister_card_driver(struct pnp_card_driver *drv) { }
432 453
433/* resource management */ 454/* resource management */
434static inline struct pnp_option *pnp_register_independent_option(struct pnp_dev *dev) { return NULL; }
435static inline struct pnp_option *pnp_register_dependent_option(struct pnp_dev *dev, int priority) { return NULL; }
436static inline int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data) { return -ENODEV; }
437static inline int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data) { return -ENODEV; }
438static inline int pnp_register_port_resource(struct pnp_option *option, struct pnp_port *data) { return -ENODEV; }
439static inline int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data) { return -ENODEV; }
440static inline void pnp_init_resource_table(struct pnp_resource_table *table) { }
441static inline int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res, int mode) { return -ENODEV; }
442static inline int pnp_auto_config_dev(struct pnp_dev *dev) { return -ENODEV; } 455static inline int pnp_auto_config_dev(struct pnp_dev *dev) { return -ENODEV; }
443static inline int pnp_validate_config(struct pnp_dev *dev) { return -ENODEV; }
444static inline int pnp_start_dev(struct pnp_dev *dev) { return -ENODEV; } 456static inline int pnp_start_dev(struct pnp_dev *dev) { return -ENODEV; }
445static inline int pnp_stop_dev(struct pnp_dev *dev) { return -ENODEV; } 457static inline int pnp_stop_dev(struct pnp_dev *dev) { return -ENODEV; }
446static inline int pnp_activate_dev(struct pnp_dev *dev) { return -ENODEV; } 458static inline int pnp_activate_dev(struct pnp_dev *dev) { return -ENODEV; }
447static inline int pnp_disable_dev(struct pnp_dev *dev) { return -ENODEV; } 459static inline int pnp_disable_dev(struct pnp_dev *dev) { return -ENODEV; }
448static inline void pnp_resource_change(struct resource *resource, resource_size_t start, resource_size_t size) { }
449 460
450/* protocol helpers */ 461/* protocol helpers */
451static inline int pnp_is_active(struct pnp_dev *dev) { return 0; } 462static inline int pnp_is_active(struct pnp_dev *dev) { return 0; }
452static inline int compare_pnp_id(struct pnp_id *pos, const char *id) { return -ENODEV; } 463static inline int compare_pnp_id(struct pnp_id *pos, const char *id) { return -ENODEV; }
453static inline int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev) { return -ENODEV; }
454static inline int pnp_register_driver(struct pnp_driver *drv) { return -ENODEV; } 464static inline int pnp_register_driver(struct pnp_driver *drv) { return -ENODEV; }
455static inline void pnp_unregister_driver(struct pnp_driver *drv) { } 465static inline void pnp_unregister_driver(struct pnp_driver *drv) { }
456 466
@@ -466,6 +476,4 @@ static inline void pnp_unregister_driver(struct pnp_driver *drv) { }
466#define pnp_dbg(format, arg...) do {} while (0) 476#define pnp_dbg(format, arg...) do {} while (0)
467#endif 477#endif
468 478
469#endif /* __KERNEL__ */
470
471#endif /* _LINUX_PNP_H */ 479#endif /* _LINUX_PNP_H */
diff --git a/include/linux/pnpbios.h b/include/linux/pnpbios.h
deleted file mode 100644
index 329192adc9dd..000000000000
--- a/include/linux/pnpbios.h
+++ /dev/null
@@ -1,151 +0,0 @@
1/*
2 * Include file for the interface to a PnP BIOS
3 *
4 * Original BIOS code (C) 1998 Christian Schmidt (chr.schmidt@tu-bs.de)
5 * PnP handler parts (c) 1998 Tom Lees <tom@lpsg.demon.co.uk>
6 * Minor reorganizations by David Hinds <dahinds@users.sourceforge.net>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#ifndef _LINUX_PNPBIOS_H
24#define _LINUX_PNPBIOS_H
25
26#ifdef __KERNEL__
27
28#include <linux/types.h>
29#include <linux/pnp.h>
30
31/*
32 * Return codes
33 */
34#define PNP_SUCCESS 0x00
35#define PNP_NOT_SET_STATICALLY 0x7f
36#define PNP_UNKNOWN_FUNCTION 0x81
37#define PNP_FUNCTION_NOT_SUPPORTED 0x82
38#define PNP_INVALID_HANDLE 0x83
39#define PNP_BAD_PARAMETER 0x84
40#define PNP_SET_FAILED 0x85
41#define PNP_EVENTS_NOT_PENDING 0x86
42#define PNP_SYSTEM_NOT_DOCKED 0x87
43#define PNP_NO_ISA_PNP_CARDS 0x88
44#define PNP_UNABLE_TO_DETERMINE_DOCK_CAPABILITIES 0x89
45#define PNP_CONFIG_CHANGE_FAILED_NO_BATTERY 0x8a
46#define PNP_CONFIG_CHANGE_FAILED_RESOURCE_CONFLICT 0x8b
47#define PNP_BUFFER_TOO_SMALL 0x8c
48#define PNP_USE_ESCD_SUPPORT 0x8d
49#define PNP_MESSAGE_NOT_SUPPORTED 0x8e
50#define PNP_HARDWARE_ERROR 0x8f
51
52#define ESCD_SUCCESS 0x00
53#define ESCD_IO_ERROR_READING 0x55
54#define ESCD_INVALID 0x56
55#define ESCD_BUFFER_TOO_SMALL 0x59
56#define ESCD_NVRAM_TOO_SMALL 0x5a
57#define ESCD_FUNCTION_NOT_SUPPORTED 0x81
58
59/*
60 * Events that can be received by "get event"
61 */
62#define PNPEV_ABOUT_TO_CHANGE_CONFIG 0x0001
63#define PNPEV_DOCK_CHANGED 0x0002
64#define PNPEV_SYSTEM_DEVICE_CHANGED 0x0003
65#define PNPEV_CONFIG_CHANGED_FAILED 0x0004
66#define PNPEV_UNKNOWN_SYSTEM_EVENT 0xffff
67/* 0x8000 through 0xfffe are OEM defined */
68
69/*
70 * Messages that should be sent through "send message"
71 */
72#define PNPMSG_OK 0x00
73#define PNPMSG_ABORT 0x01
74#define PNPMSG_UNDOCK_DEFAULT_ACTION 0x40
75#define PNPMSG_POWER_OFF 0x41
76#define PNPMSG_PNP_OS_ACTIVE 0x42
77#define PNPMSG_PNP_OS_INACTIVE 0x43
78
79/*
80 * Plug and Play BIOS flags
81 */
82#define PNPBIOS_NO_DISABLE 0x0001
83#define PNPBIOS_NO_CONFIG 0x0002
84#define PNPBIOS_OUTPUT 0x0004
85#define PNPBIOS_INPUT 0x0008
86#define PNPBIOS_BOOTABLE 0x0010
87#define PNPBIOS_DOCK 0x0020
88#define PNPBIOS_REMOVABLE 0x0040
89#define pnpbios_is_static(x) (((x)->flags & 0x0100) == 0x0000)
90#define pnpbios_is_dynamic(x) ((x)->flags & 0x0080)
91
92/*
93 * Function Parameters
94 */
95#define PNPMODE_STATIC 1
96#define PNPMODE_DYNAMIC 0
97
98/* 0x8000 through 0xffff are OEM defined */
99
100#pragma pack(1)
101struct pnp_dev_node_info {
102 __u16 no_nodes;
103 __u16 max_node_size;
104};
105struct pnp_docking_station_info {
106 __u32 location_id;
107 __u32 serial;
108 __u16 capabilities;
109};
110struct pnp_isa_config_struc {
111 __u8 revision;
112 __u8 no_csns;
113 __u16 isa_rd_data_port;
114 __u16 reserved;
115};
116struct escd_info_struc {
117 __u16 min_escd_write_size;
118 __u16 escd_size;
119 __u32 nv_storage_base;
120};
121struct pnp_bios_node {
122 __u16 size;
123 __u8 handle;
124 __u32 eisa_id;
125 __u8 type_code[3];
126 __u16 flags;
127 __u8 data[0];
128};
129#pragma pack()
130
131#ifdef CONFIG_PNPBIOS
132
133/* non-exported */
134extern struct pnp_dev_node_info node_info;
135
136extern int pnp_bios_dev_node_info(struct pnp_dev_node_info *data);
137extern int pnp_bios_get_dev_node(u8 *nodenum, char config,
138 struct pnp_bios_node *data);
139extern int pnp_bios_set_dev_node(u8 nodenum, char config,
140 struct pnp_bios_node *data);
141extern int pnp_bios_get_stat_res(char *info);
142extern int pnp_bios_isapnp_config(struct pnp_isa_config_struc *data);
143extern int pnp_bios_escd_info(struct escd_info_struc *data);
144extern int pnp_bios_read_escd(char *data, u32 nvram_base);
145extern int pnp_bios_dock_station_info(struct pnp_docking_station_info *data);
146
147#endif /* CONFIG_PNPBIOS */
148
149#endif /* __KERNEL__ */
150
151#endif /* _LINUX_PNPBIOS_H */
diff --git a/include/linux/poison.h b/include/linux/poison.h
index a9c31be7052c..9f31683728fd 100644
--- a/include/linux/poison.h
+++ b/include/linux/poison.h
@@ -10,6 +10,13 @@
10#define LIST_POISON1 ((void *) 0x00100100) 10#define LIST_POISON1 ((void *) 0x00100100)
11#define LIST_POISON2 ((void *) 0x00200200) 11#define LIST_POISON2 ((void *) 0x00200200)
12 12
13/********** include/linux/timer.h **********/
14/*
15 * Magic number "tsta" to indicate a static timer initializer
16 * for the object debugging code.
17 */
18#define TIMER_ENTRY_STATIC ((void *) 0x74737461)
19
13/********** mm/slab.c **********/ 20/********** mm/slab.c **********/
14/* 21/*
15 * Magic nums for obj red zoning. 22 * Magic nums for obj red zoning.
diff --git a/include/linux/poll.h b/include/linux/poll.h
index 16d813b364ef..ef453828877a 100644
--- a/include/linux/poll.h
+++ b/include/linux/poll.h
@@ -117,6 +117,8 @@ void zero_fd_set(unsigned long nr, unsigned long *fdset)
117extern int do_select(int n, fd_set_bits *fds, s64 *timeout); 117extern int do_select(int n, fd_set_bits *fds, s64 *timeout);
118extern int do_sys_poll(struct pollfd __user * ufds, unsigned int nfds, 118extern int do_sys_poll(struct pollfd __user * ufds, unsigned int nfds,
119 s64 *timeout); 119 s64 *timeout);
120extern int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp,
121 fd_set __user *exp, s64 *timeout);
120 122
121#endif /* KERNEL */ 123#endif /* KERNEL */
122 124
diff --git a/include/linux/profile.h b/include/linux/profile.h
index ff576d1db67d..05c1cc736937 100644
--- a/include/linux/profile.h
+++ b/include/linux/profile.h
@@ -1,8 +1,6 @@
1#ifndef _LINUX_PROFILE_H 1#ifndef _LINUX_PROFILE_H
2#define _LINUX_PROFILE_H 2#define _LINUX_PROFILE_H
3 3
4#ifdef __KERNEL__
5
6#include <linux/kernel.h> 4#include <linux/kernel.h>
7#include <linux/init.h> 5#include <linux/init.h>
8#include <linux/cpumask.h> 6#include <linux/cpumask.h>
@@ -118,6 +116,4 @@ static inline void unregister_timer_hook(int (*hook)(struct pt_regs *))
118 116
119#endif /* CONFIG_PROFILING */ 117#endif /* CONFIG_PROFILING */
120 118
121#endif /* __KERNEL__ */
122
123#endif /* _LINUX_PROFILE_H */ 119#endif /* _LINUX_PROFILE_H */
diff --git a/include/linux/proportions.h b/include/linux/proportions.h
index 2c3b3cad92be..5afc1b23346d 100644
--- a/include/linux/proportions.h
+++ b/include/linux/proportions.h
@@ -78,6 +78,19 @@ void prop_inc_percpu(struct prop_descriptor *pd, struct prop_local_percpu *pl)
78} 78}
79 79
80/* 80/*
81 * Limit the time part in order to ensure there are some bits left for the
82 * cycle counter and fraction multiply.
83 */
84#define PROP_MAX_SHIFT (3*BITS_PER_LONG/4)
85
86#define PROP_FRAC_SHIFT (BITS_PER_LONG - PROP_MAX_SHIFT - 1)
87#define PROP_FRAC_BASE (1UL << PROP_FRAC_SHIFT)
88
89void __prop_inc_percpu_max(struct prop_descriptor *pd,
90 struct prop_local_percpu *pl, long frac);
91
92
93/*
81 * ----- SINGLE ------ 94 * ----- SINGLE ------
82 */ 95 */
83 96
diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
index ebe0c17039cf..f98501ba557e 100644
--- a/include/linux/ptrace.h
+++ b/include/linux/ptrace.h
@@ -98,6 +98,10 @@ extern void ptrace_untrace(struct task_struct *child);
98extern int ptrace_may_attach(struct task_struct *task); 98extern int ptrace_may_attach(struct task_struct *task);
99extern int __ptrace_may_attach(struct task_struct *task); 99extern int __ptrace_may_attach(struct task_struct *task);
100 100
101static inline int ptrace_reparented(struct task_struct *child)
102{
103 return child->real_parent != child->parent;
104}
101static inline void ptrace_link(struct task_struct *child, 105static inline void ptrace_link(struct task_struct *child,
102 struct task_struct *new_parent) 106 struct task_struct *new_parent)
103{ 107{
diff --git a/include/linux/quota.h b/include/linux/quota.h
index 52e49dce6584..dcddfb200947 100644
--- a/include/linux/quota.h
+++ b/include/linux/quota.h
@@ -347,6 +347,9 @@ struct quota_info {
347 ((type) == USRQUOTA ? (sb_dqopt(sb)->flags & DQUOT_USR_SUSPENDED) : \ 347 ((type) == USRQUOTA ? (sb_dqopt(sb)->flags & DQUOT_USR_SUSPENDED) : \
348 (sb_dqopt(sb)->flags & DQUOT_GRP_SUSPENDED)) 348 (sb_dqopt(sb)->flags & DQUOT_GRP_SUSPENDED))
349 349
350#define sb_any_quota_suspended(sb) (sb_has_quota_suspended(sb, USRQUOTA) | \
351 sb_has_quota_suspended(sb, GRPQUOTA))
352
350int register_quota_format(struct quota_format_type *fmt); 353int register_quota_format(struct quota_format_type *fmt);
351void unregister_quota_format(struct quota_format_type *fmt); 354void unregister_quota_format(struct quota_format_type *fmt);
352 355
diff --git a/include/linux/raid/md.h b/include/linux/raid/md.h
index 8ab630b67fcc..81a1a02d4566 100644
--- a/include/linux/raid/md.h
+++ b/include/linux/raid/md.h
@@ -94,6 +94,7 @@ extern int sync_page_io(struct block_device *bdev, sector_t sector, int size,
94extern void md_do_sync(mddev_t *mddev); 94extern void md_do_sync(mddev_t *mddev);
95extern void md_new_event(mddev_t *mddev); 95extern void md_new_event(mddev_t *mddev);
96extern void md_allow_write(mddev_t *mddev); 96extern void md_allow_write(mddev_t *mddev);
97extern void md_wait_for_blocked_rdev(mdk_rdev_t *rdev, mddev_t *mddev);
97 98
98#endif /* CONFIG_MD */ 99#endif /* CONFIG_MD */
99#endif 100#endif
diff --git a/include/linux/raid/md_k.h b/include/linux/raid/md_k.h
index 7bb6d1abf71e..812ffa590cff 100644
--- a/include/linux/raid/md_k.h
+++ b/include/linux/raid/md_k.h
@@ -84,6 +84,10 @@ struct mdk_rdev_s
84#define AllReserved 6 /* If whole device is reserved for 84#define AllReserved 6 /* If whole device is reserved for
85 * one array */ 85 * one array */
86#define AutoDetected 7 /* added by auto-detect */ 86#define AutoDetected 7 /* added by auto-detect */
87#define Blocked 8 /* An error occured on an externally
88 * managed array, don't allow writes
89 * until it is cleared */
90 wait_queue_head_t blocked_wait;
87 91
88 int desc_nr; /* descriptor index in the superblock */ 92 int desc_nr; /* descriptor index in the superblock */
89 int raid_disk; /* role of device in array */ 93 int raid_disk; /* role of device in array */
diff --git a/include/linux/rcuclassic.h b/include/linux/rcuclassic.h
index b3dccd68629e..b3aa05baab8a 100644
--- a/include/linux/rcuclassic.h
+++ b/include/linux/rcuclassic.h
@@ -33,8 +33,6 @@
33#ifndef __LINUX_RCUCLASSIC_H 33#ifndef __LINUX_RCUCLASSIC_H
34#define __LINUX_RCUCLASSIC_H 34#define __LINUX_RCUCLASSIC_H
35 35
36#ifdef __KERNEL__
37
38#include <linux/cache.h> 36#include <linux/cache.h>
39#include <linux/spinlock.h> 37#include <linux/spinlock.h>
40#include <linux/threads.h> 38#include <linux/threads.h>
@@ -163,5 +161,4 @@ extern long rcu_batches_completed_bh(void);
163#define rcu_enter_nohz() do { } while (0) 161#define rcu_enter_nohz() do { } while (0)
164#define rcu_exit_nohz() do { } while (0) 162#define rcu_exit_nohz() do { } while (0)
165 163
166#endif /* __KERNEL__ */
167#endif /* __LINUX_RCUCLASSIC_H */ 164#endif /* __LINUX_RCUCLASSIC_H */
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index 37a642c54871..8082d6587a0f 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -33,8 +33,6 @@
33#ifndef __LINUX_RCUPDATE_H 33#ifndef __LINUX_RCUPDATE_H
34#define __LINUX_RCUPDATE_H 34#define __LINUX_RCUPDATE_H
35 35
36#ifdef __KERNEL__
37
38#include <linux/cache.h> 36#include <linux/cache.h>
39#include <linux/spinlock.h> 37#include <linux/spinlock.h>
40#include <linux/threads.h> 38#include <linux/threads.h>
@@ -245,5 +243,4 @@ extern long rcu_batches_completed_bh(void);
245extern void rcu_init(void); 243extern void rcu_init(void);
246extern int rcu_needs_cpu(int cpu); 244extern int rcu_needs_cpu(int cpu);
247 245
248#endif /* __KERNEL__ */
249#endif /* __LINUX_RCUPDATE_H */ 246#endif /* __LINUX_RCUPDATE_H */
diff --git a/include/linux/rcupreempt.h b/include/linux/rcupreempt.h
index d038aa6e5ee1..8a05c7e20bc4 100644
--- a/include/linux/rcupreempt.h
+++ b/include/linux/rcupreempt.h
@@ -33,8 +33,6 @@
33#ifndef __LINUX_RCUPREEMPT_H 33#ifndef __LINUX_RCUPREEMPT_H
34#define __LINUX_RCUPREEMPT_H 34#define __LINUX_RCUPREEMPT_H
35 35
36#ifdef __KERNEL__
37
38#include <linux/cache.h> 36#include <linux/cache.h>
39#include <linux/spinlock.h> 37#include <linux/spinlock.h>
40#include <linux/threads.h> 38#include <linux/threads.h>
@@ -104,5 +102,4 @@ static inline void rcu_exit_nohz(void)
104#define rcu_exit_nohz() do { } while (0) 102#define rcu_exit_nohz() do { } while (0)
105#endif /* CONFIG_NO_HZ */ 103#endif /* CONFIG_NO_HZ */
106 104
107#endif /* __KERNEL__ */
108#endif /* __LINUX_RCUPREEMPT_H */ 105#endif /* __LINUX_RCUPREEMPT_H */
diff --git a/include/linux/rcupreempt_trace.h b/include/linux/rcupreempt_trace.h
index 21cd6b2a5c42..b99ae073192a 100644
--- a/include/linux/rcupreempt_trace.h
+++ b/include/linux/rcupreempt_trace.h
@@ -32,7 +32,6 @@
32#ifndef __LINUX_RCUPREEMPT_TRACE_H 32#ifndef __LINUX_RCUPREEMPT_TRACE_H
33#define __LINUX_RCUPREEMPT_TRACE_H 33#define __LINUX_RCUPREEMPT_TRACE_H
34 34
35#ifdef __KERNEL__
36#include <linux/types.h> 35#include <linux/types.h>
37#include <linux/kernel.h> 36#include <linux/kernel.h>
38 37
@@ -95,5 +94,4 @@ extern void rcupreempt_trace_done_remove(struct rcupreempt_trace *trace);
95extern void rcupreempt_trace_invoke(struct rcupreempt_trace *trace); 94extern void rcupreempt_trace_invoke(struct rcupreempt_trace *trace);
96extern void rcupreempt_trace_next_add(struct rcupreempt_trace *trace); 95extern void rcupreempt_trace_next_add(struct rcupreempt_trace *trace);
97 96
98#endif /* __KERNEL__ */
99#endif /* __LINUX_RCUPREEMPT_TRACE_H */ 97#endif /* __LINUX_RCUPREEMPT_TRACE_H */
diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
index db5ef9b83c3f..336ee43ed7d8 100644
--- a/include/linux/reiserfs_fs_sb.h
+++ b/include/linux/reiserfs_fs_sb.h
@@ -177,7 +177,6 @@ struct reiserfs_journal {
177 struct reiserfs_journal_cnode *j_last; /* newest journal block */ 177 struct reiserfs_journal_cnode *j_last; /* newest journal block */
178 struct reiserfs_journal_cnode *j_first; /* oldest journal block. start here for traverse */ 178 struct reiserfs_journal_cnode *j_first; /* oldest journal block. start here for traverse */
179 179
180 struct file *j_dev_file;
181 struct block_device *j_dev_bd; 180 struct block_device *j_dev_bd;
182 int j_1st_reserved_block; /* first block on s_dev of reserved area journal */ 181 int j_1st_reserved_block; /* first block on s_dev of reserved area journal */
183 182
diff --git a/include/linux/rio.h b/include/linux/rio.h
index cfb66bbc0f27..dc0c75556c63 100644
--- a/include/linux/rio.h
+++ b/include/linux/rio.h
@@ -14,8 +14,6 @@
14#ifndef LINUX_RIO_H 14#ifndef LINUX_RIO_H
15#define LINUX_RIO_H 15#define LINUX_RIO_H
16 16
17#ifdef __KERNEL__
18
19#include <linux/types.h> 17#include <linux/types.h>
20#include <linux/ioport.h> 18#include <linux/ioport.h>
21#include <linux/list.h> 19#include <linux/list.h>
@@ -163,6 +161,8 @@ enum rio_phy_type {
163 * @ops: configuration space functions 161 * @ops: configuration space functions
164 * @id: Port ID, unique among all ports 162 * @id: Port ID, unique among all ports
165 * @index: Port index, unique among all port interfaces of the same type 163 * @index: Port index, unique among all port interfaces of the same type
164 * @sys_size: RapidIO common transport system size
165 * @phy_type: RapidIO phy type
166 * @name: Port name string 166 * @name: Port name string
167 * @priv: Master port private data 167 * @priv: Master port private data
168 */ 168 */
@@ -331,5 +331,4 @@ extern void rio_close_inb_mbox(struct rio_mport *, int);
331extern int rio_open_outb_mbox(struct rio_mport *, void *, int, int); 331extern int rio_open_outb_mbox(struct rio_mport *, void *, int, int);
332extern void rio_close_outb_mbox(struct rio_mport *, int); 332extern void rio_close_outb_mbox(struct rio_mport *, int);
333 333
334#endif /* __KERNEL__ */
335#endif /* LINUX_RIO_H */ 334#endif /* LINUX_RIO_H */
diff --git a/include/linux/rio_drv.h b/include/linux/rio_drv.h
index 7adb2a1aac92..90987b7bcc1b 100644
--- a/include/linux/rio_drv.h
+++ b/include/linux/rio_drv.h
@@ -13,8 +13,6 @@
13#ifndef LINUX_RIO_DRV_H 13#ifndef LINUX_RIO_DRV_H
14#define LINUX_RIO_DRV_H 14#define LINUX_RIO_DRV_H
15 15
16#ifdef __KERNEL__
17
18#include <linux/types.h> 16#include <linux/types.h>
19#include <linux/ioport.h> 17#include <linux/ioport.h>
20#include <linux/list.h> 18#include <linux/list.h>
@@ -465,5 +463,4 @@ extern struct rio_dev *rio_get_device(u16 vid, u16 did, struct rio_dev *from);
465extern struct rio_dev *rio_get_asm(u16 vid, u16 did, u16 asm_vid, u16 asm_did, 463extern struct rio_dev *rio_get_asm(u16 vid, u16 did, u16 asm_vid, u16 asm_did,
466 struct rio_dev *from); 464 struct rio_dev *from);
467 465
468#endif /* __KERNEL__ */
469#endif /* LINUX_RIO_DRV_H */ 466#endif /* LINUX_RIO_DRV_H */
diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h
index 7b524b4109a0..efd348fe8ca7 100644
--- a/include/linux/rwsem.h
+++ b/include/linux/rwsem.h
@@ -9,8 +9,6 @@
9 9
10#include <linux/linkage.h> 10#include <linux/linkage.h>
11 11
12#ifdef __KERNEL__
13
14#include <linux/types.h> 12#include <linux/types.h>
15#include <linux/kernel.h> 13#include <linux/kernel.h>
16#include <asm/system.h> 14#include <asm/system.h>
@@ -90,5 +88,4 @@ extern void up_read_non_owner(struct rw_semaphore *sem);
90# define up_read_non_owner(sem) up_read(sem) 88# define up_read_non_owner(sem) up_read(sem)
91#endif 89#endif
92 90
93#endif /* __KERNEL__ */
94#endif /* _LINUX_RWSEM_H */ 91#endif /* _LINUX_RWSEM_H */
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 1d02babdb2c7..0c35b0343a76 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -158,6 +158,8 @@ print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
158} 158}
159#endif 159#endif
160 160
161extern unsigned long long time_sync_thresh;
162
161/* 163/*
162 * Task state bitmask. NOTE! These bits are also 164 * Task state bitmask. NOTE! These bits are also
163 * encoded in fs/proc/array.c: get_task_state(). 165 * encoded in fs/proc/array.c: get_task_state().
@@ -554,6 +556,14 @@ struct signal_struct {
554#define SIGNAL_STOP_DEQUEUED 0x00000002 /* stop signal dequeued */ 556#define SIGNAL_STOP_DEQUEUED 0x00000002 /* stop signal dequeued */
555#define SIGNAL_STOP_CONTINUED 0x00000004 /* SIGCONT since WCONTINUED reap */ 557#define SIGNAL_STOP_CONTINUED 0x00000004 /* SIGCONT since WCONTINUED reap */
556#define SIGNAL_GROUP_EXIT 0x00000008 /* group exit in progress */ 558#define SIGNAL_GROUP_EXIT 0x00000008 /* group exit in progress */
559/*
560 * Pending notifications to parent.
561 */
562#define SIGNAL_CLD_STOPPED 0x00000010
563#define SIGNAL_CLD_CONTINUED 0x00000020
564#define SIGNAL_CLD_MASK (SIGNAL_CLD_STOPPED|SIGNAL_CLD_CONTINUED)
565
566#define SIGNAL_UNKILLABLE 0x00000040 /* for init: ignore fatal signals */
557 567
558/* If true, all threads except ->group_exit_task have pending SIGKILL */ 568/* If true, all threads except ->group_exit_task have pending SIGKILL */
559static inline int signal_group_exit(const struct signal_struct *sig) 569static inline int signal_group_exit(const struct signal_struct *sig)
@@ -1167,7 +1177,7 @@ struct task_struct {
1167 struct sighand_struct *sighand; 1177 struct sighand_struct *sighand;
1168 1178
1169 sigset_t blocked, real_blocked; 1179 sigset_t blocked, real_blocked;
1170 sigset_t saved_sigmask; /* To be restored with TIF_RESTORE_SIGMASK */ 1180 sigset_t saved_sigmask; /* restored if set_restore_sigmask() was used */
1171 struct sigpending pending; 1181 struct sigpending pending;
1172 1182
1173 unsigned long sas_ss_sp; 1183 unsigned long sas_ss_sp;
@@ -1543,6 +1553,35 @@ static inline int set_cpus_allowed(struct task_struct *p, cpumask_t new_mask)
1543 1553
1544extern unsigned long long sched_clock(void); 1554extern unsigned long long sched_clock(void);
1545 1555
1556#ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
1557static inline void sched_clock_init(void)
1558{
1559}
1560
1561static inline u64 sched_clock_cpu(int cpu)
1562{
1563 return sched_clock();
1564}
1565
1566static inline void sched_clock_tick(void)
1567{
1568}
1569
1570static inline void sched_clock_idle_sleep_event(void)
1571{
1572}
1573
1574static inline void sched_clock_idle_wakeup_event(u64 delta_ns)
1575{
1576}
1577#else
1578extern void sched_clock_init(void);
1579extern u64 sched_clock_cpu(int cpu);
1580extern void sched_clock_tick(void);
1581extern void sched_clock_idle_sleep_event(void);
1582extern void sched_clock_idle_wakeup_event(u64 delta_ns);
1583#endif
1584
1546/* 1585/*
1547 * For kernel-internal use: high-speed (but slightly incorrect) per-cpu 1586 * For kernel-internal use: high-speed (but slightly incorrect) per-cpu
1548 * clock constructed from sched_clock(): 1587 * clock constructed from sched_clock():
@@ -1669,7 +1708,10 @@ extern struct pid_namespace init_pid_ns;
1669extern struct task_struct *find_task_by_pid_type_ns(int type, int pid, 1708extern struct task_struct *find_task_by_pid_type_ns(int type, int pid,
1670 struct pid_namespace *ns); 1709 struct pid_namespace *ns);
1671 1710
1672extern struct task_struct *find_task_by_pid(pid_t nr); 1711static inline struct task_struct *__deprecated find_task_by_pid(pid_t nr)
1712{
1713 return find_task_by_pid_type_ns(PIDTYPE_PID, nr, &init_pid_ns);
1714}
1673extern struct task_struct *find_task_by_vpid(pid_t nr); 1715extern struct task_struct *find_task_by_vpid(pid_t nr);
1674extern struct task_struct *find_task_by_pid_ns(pid_t nr, 1716extern struct task_struct *find_task_by_pid_ns(pid_t nr,
1675 struct pid_namespace *ns); 1717 struct pid_namespace *ns);
@@ -1745,8 +1787,7 @@ extern void zap_other_threads(struct task_struct *p);
1745extern int kill_proc(pid_t, int, int); 1787extern int kill_proc(pid_t, int, int);
1746extern struct sigqueue *sigqueue_alloc(void); 1788extern struct sigqueue *sigqueue_alloc(void);
1747extern void sigqueue_free(struct sigqueue *); 1789extern void sigqueue_free(struct sigqueue *);
1748extern int send_sigqueue(int, struct sigqueue *, struct task_struct *); 1790extern int send_sigqueue(struct sigqueue *, struct task_struct *, int group);
1749extern int send_group_sigqueue(int, struct sigqueue *, struct task_struct *);
1750extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *); 1791extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *);
1751extern int do_sigaltstack(const stack_t __user *, stack_t __user *, unsigned long); 1792extern int do_sigaltstack(const stack_t __user *, stack_t __user *, unsigned long);
1752 1793
@@ -1967,6 +2008,11 @@ static inline void clear_tsk_need_resched(struct task_struct *tsk)
1967 clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED); 2008 clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
1968} 2009}
1969 2010
2011static inline int test_tsk_need_resched(struct task_struct *tsk)
2012{
2013 return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED));
2014}
2015
1970static inline int signal_pending(struct task_struct *p) 2016static inline int signal_pending(struct task_struct *p)
1971{ 2017{
1972 return unlikely(test_tsk_thread_flag(p,TIF_SIGPENDING)); 2018 return unlikely(test_tsk_thread_flag(p,TIF_SIGPENDING));
@@ -1981,7 +2027,7 @@ static inline int fatal_signal_pending(struct task_struct *p)
1981 2027
1982static inline int need_resched(void) 2028static inline int need_resched(void)
1983{ 2029{
1984 return unlikely(test_thread_flag(TIF_NEED_RESCHED)); 2030 return unlikely(test_tsk_need_resched(current));
1985} 2031}
1986 2032
1987/* 2033/*
diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index 5b5369c3c209..a66304a09955 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -1,6 +1,5 @@
1#ifndef _LINUX_SEQ_FILE_H 1#ifndef _LINUX_SEQ_FILE_H
2#define _LINUX_SEQ_FILE_H 2#define _LINUX_SEQ_FILE_H
3#ifdef __KERNEL__
4 3
5#include <linux/types.h> 4#include <linux/types.h>
6#include <linux/string.h> 5#include <linux/string.h>
@@ -69,4 +68,3 @@ extern struct list_head *seq_list_next(void *v, struct list_head *head,
69 loff_t *ppos); 68 loff_t *ppos);
70 69
71#endif 70#endif
72#endif
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index 7cb094a82456..d32123ae08ad 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -149,13 +149,15 @@
149/* Freescale ColdFire */ 149/* Freescale ColdFire */
150#define PORT_MCF 78 150#define PORT_MCF 78
151 151
152#define PORT_SC26XX 79 152/* Blackfin SPORT */
153 153#define PORT_BFIN_SPORT 79
154 154
155/* MN10300 on-chip UART numbers */ 155/* MN10300 on-chip UART numbers */
156#define PORT_MN10300 80 156#define PORT_MN10300 80
157#define PORT_MN10300_CTS 81 157#define PORT_MN10300_CTS 81
158 158
159#define PORT_SC26XX 82
160
159#ifdef __KERNEL__ 161#ifdef __KERNEL__
160 162
161#include <linux/compiler.h> 163#include <linux/compiler.h>
diff --git a/include/linux/signal.h b/include/linux/signal.h
index 42d2e0a948f4..84f997f8aa53 100644
--- a/include/linux/signal.h
+++ b/include/linux/signal.h
@@ -362,8 +362,6 @@ int unhandled_signal(struct task_struct *tsk, int sig);
362#define sig_kernel_stop(sig) \ 362#define sig_kernel_stop(sig) \
363 (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_STOP_MASK)) 363 (((sig) < SIGRTMIN) && siginmask(sig, SIG_KERNEL_STOP_MASK))
364 364
365#define sig_needs_tasklist(sig) ((sig) == SIGCONT)
366
367#define sig_user_defined(t, signr) \ 365#define sig_user_defined(t, signr) \
368 (((t)->sighand->action[(signr)-1].sa.sa_handler != SIG_DFL) && \ 366 (((t)->sighand->action[(signr)-1].sa.sa_handler != SIG_DFL) && \
369 ((t)->sighand->action[(signr)-1].sa.sa_handler != SIG_IGN)) 367 ((t)->sighand->action[(signr)-1].sa.sa_handler != SIG_IGN))
diff --git a/include/linux/slab.h b/include/linux/slab.h
index f62caaad94e0..805ed4b92f9a 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -9,8 +9,6 @@
9#ifndef _LINUX_SLAB_H 9#ifndef _LINUX_SLAB_H
10#define _LINUX_SLAB_H 10#define _LINUX_SLAB_H
11 11
12#ifdef __KERNEL__
13
14#include <linux/gfp.h> 12#include <linux/gfp.h>
15#include <linux/types.h> 13#include <linux/types.h>
16 14
@@ -29,6 +27,13 @@
29#define SLAB_MEM_SPREAD 0x00100000UL /* Spread some memory over cpuset */ 27#define SLAB_MEM_SPREAD 0x00100000UL /* Spread some memory over cpuset */
30#define SLAB_TRACE 0x00200000UL /* Trace allocations and frees */ 28#define SLAB_TRACE 0x00200000UL /* Trace allocations and frees */
31 29
30/* Flag to prevent checks on free */
31#ifdef CONFIG_DEBUG_OBJECTS
32# define SLAB_DEBUG_OBJECTS 0x00400000UL
33#else
34# define SLAB_DEBUG_OBJECTS 0x00000000UL
35#endif
36
32/* The following flags affect the page allocator grouping pages by mobility */ 37/* The following flags affect the page allocator grouping pages by mobility */
33#define SLAB_RECLAIM_ACCOUNT 0x00020000UL /* Objects are reclaimable */ 38#define SLAB_RECLAIM_ACCOUNT 0x00020000UL /* Objects are reclaimable */
34#define SLAB_TEMPORARY SLAB_RECLAIM_ACCOUNT /* Objects are short-lived */ 39#define SLAB_TEMPORARY SLAB_RECLAIM_ACCOUNT /* Objects are short-lived */
@@ -276,5 +281,4 @@ extern const struct seq_operations slabinfo_op;
276ssize_t slabinfo_write(struct file *, const char __user *, size_t, loff_t *); 281ssize_t slabinfo_write(struct file *, const char __user *, size_t, loff_t *);
277#endif 282#endif
278 283
279#endif /* __KERNEL__ */
280#endif /* _LINUX_SLAB_H */ 284#endif /* _LINUX_SLAB_H */
diff --git a/include/linux/smb_fs_i.h b/include/linux/smb_fs_i.h
index 8516954a5141..8ccf4eca2c3d 100644
--- a/include/linux/smb_fs_i.h
+++ b/include/linux/smb_fs_i.h
@@ -9,7 +9,6 @@
9#ifndef _LINUX_SMB_FS_I 9#ifndef _LINUX_SMB_FS_I
10#define _LINUX_SMB_FS_I 10#define _LINUX_SMB_FS_I
11 11
12#ifdef __KERNEL__
13#include <linux/types.h> 12#include <linux/types.h>
14#include <linux/fs.h> 13#include <linux/fs.h>
15 14
@@ -36,4 +35,3 @@ struct smb_inode_info {
36}; 35};
37 36
38#endif 37#endif
39#endif
diff --git a/include/linux/smb_fs_sb.h b/include/linux/smb_fs_sb.h
index 3aa97aa4277f..8a060a7040d8 100644
--- a/include/linux/smb_fs_sb.h
+++ b/include/linux/smb_fs_sb.h
@@ -9,8 +9,6 @@
9#ifndef _SMB_FS_SB 9#ifndef _SMB_FS_SB
10#define _SMB_FS_SB 10#define _SMB_FS_SB
11 11
12#ifdef __KERNEL__
13
14#include <linux/types.h> 12#include <linux/types.h>
15#include <linux/smb.h> 13#include <linux/smb.h>
16 14
@@ -96,6 +94,4 @@ smb_unlock_server(struct smb_sb_info *server)
96 up(&(server->sem)); 94 up(&(server->sem));
97} 95}
98 96
99#endif /* __KERNEL__ */
100
101#endif 97#endif
diff --git a/include/linux/string.h b/include/linux/string.h
index c5d3fcad7b57..efdc44593b52 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -109,5 +109,7 @@ extern void *kmemdup(const void *src, size_t len, gfp_t gfp);
109extern char **argv_split(gfp_t gfp, const char *str, int *argcp); 109extern char **argv_split(gfp_t gfp, const char *str, int *argcp);
110extern void argv_free(char **argv); 110extern void argv_free(char **argv);
111 111
112extern bool sysfs_streq(const char *s1, const char *s2);
113
112#endif 114#endif
113#endif /* _LINUX_STRING_H_ */ 115#endif /* _LINUX_STRING_H_ */
diff --git a/include/linux/svga.h b/include/linux/svga.h
index 13ad0b82ac28..c59a51a2b0e7 100644
--- a/include/linux/svga.h
+++ b/include/linux/svga.h
@@ -1,8 +1,6 @@
1#ifndef _LINUX_SVGA_H 1#ifndef _LINUX_SVGA_H
2#define _LINUX_SVGA_H 2#define _LINUX_SVGA_H
3 3
4#ifdef __KERNEL__
5
6#include <linux/pci.h> 4#include <linux/pci.h>
7#include <video/vga.h> 5#include <video/vga.h>
8 6
@@ -122,6 +120,5 @@ void svga_set_timings(const struct svga_timing_regs *tm, struct fb_var_screeninf
122 120
123int svga_match_format(const struct svga_fb_format *frm, struct fb_var_screeninfo *var, struct fb_fix_screeninfo *fix); 121int svga_match_format(const struct svga_fb_format *frm, struct fb_var_screeninfo *var, struct fb_fix_screeninfo *fix);
124 122
125#endif /* __KERNEL__ */
126#endif /* _LINUX_SVGA_H */ 123#endif /* _LINUX_SVGA_H */
127 124
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index add3c5a40827..7858eac40aa7 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -190,6 +190,12 @@ static inline int sysfs_create_group(struct kobject *kobj,
190 return 0; 190 return 0;
191} 191}
192 192
193static inline int sysfs_update_group(struct kobject *kobj,
194 const struct attribute_group *grp)
195{
196 return 0;
197}
198
193static inline void sysfs_remove_group(struct kobject *kobj, 199static inline void sysfs_remove_group(struct kobject *kobj,
194 const struct attribute_group *grp) 200 const struct attribute_group *grp)
195{ 201{
diff --git a/include/linux/textsearch.h b/include/linux/textsearch.h
index 004808a6df1d..6f371f24160b 100644
--- a/include/linux/textsearch.h
+++ b/include/linux/textsearch.h
@@ -1,8 +1,6 @@
1#ifndef __LINUX_TEXTSEARCH_H 1#ifndef __LINUX_TEXTSEARCH_H
2#define __LINUX_TEXTSEARCH_H 2#define __LINUX_TEXTSEARCH_H
3 3
4#ifdef __KERNEL__
5
6#include <linux/types.h> 4#include <linux/types.h>
7#include <linux/list.h> 5#include <linux/list.h>
8#include <linux/kernel.h> 6#include <linux/kernel.h>
@@ -177,6 +175,4 @@ static inline void *ts_config_priv(struct ts_config *conf)
177 return ((u8 *) conf + TS_PRIV_ALIGN(sizeof(struct ts_config))); 175 return ((u8 *) conf + TS_PRIV_ALIGN(sizeof(struct ts_config)));
178} 176}
179 177
180#endif /* __KERNEL__ */
181
182#endif 178#endif
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 90c1c191ea69..06d3e6eb9ca8 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -41,6 +41,7 @@ struct thermal_zone_device_ops {
41 int (*set_mode) (struct thermal_zone_device *, const char *); 41 int (*set_mode) (struct thermal_zone_device *, const char *);
42 int (*get_trip_type) (struct thermal_zone_device *, int, char *); 42 int (*get_trip_type) (struct thermal_zone_device *, int, char *);
43 int (*get_trip_temp) (struct thermal_zone_device *, int, char *); 43 int (*get_trip_temp) (struct thermal_zone_device *, int, char *);
44 int (*get_crit_temp) (struct thermal_zone_device *, unsigned long *);
44}; 45};
45 46
46struct thermal_cooling_device_ops { 47struct thermal_cooling_device_ops {
@@ -65,6 +66,23 @@ struct thermal_cooling_device {
65 ((long)t-2732+5)/10 : ((long)t-2732-5)/10) 66 ((long)t-2732+5)/10 : ((long)t-2732-5)/10)
66#define CELSIUS_TO_KELVIN(t) ((t)*10+2732) 67#define CELSIUS_TO_KELVIN(t) ((t)*10+2732)
67 68
69#if defined(CONFIG_HWMON) || \
70 (defined(CONFIG_HWMON_MODULE) && defined(CONFIG_THERMAL_MODULE))
71/* thermal zone devices with the same type share one hwmon device */
72struct thermal_hwmon_device {
73 char type[THERMAL_NAME_LENGTH];
74 struct device *device;
75 int count;
76 struct list_head tz_list;
77 struct list_head node;
78};
79
80struct thermal_hwmon_attr {
81 struct device_attribute attr;
82 char name[16];
83};
84#endif
85
68struct thermal_zone_device { 86struct thermal_zone_device {
69 int id; 87 int id;
70 char type[THERMAL_NAME_LENGTH]; 88 char type[THERMAL_NAME_LENGTH];
@@ -76,6 +94,13 @@ struct thermal_zone_device {
76 struct idr idr; 94 struct idr idr;
77 struct mutex lock; /* protect cooling devices list */ 95 struct mutex lock; /* protect cooling devices list */
78 struct list_head node; 96 struct list_head node;
97#if defined(CONFIG_HWMON) || \
98 (defined(CONFIG_HWMON_MODULE) && defined(CONFIG_THERMAL_MODULE))
99 struct list_head hwmon_node;
100 struct thermal_hwmon_device *hwmon;
101 struct thermal_hwmon_attr temp_input; /* hwmon sys attr */
102 struct thermal_hwmon_attr temp_crit; /* hwmon sys attr */
103#endif
79}; 104};
80 105
81struct thermal_zone_device *thermal_zone_device_register(char *, int, void *, 106struct thermal_zone_device *thermal_zone_device_register(char *, int, void *,
@@ -88,24 +113,10 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
88 struct thermal_cooling_device *); 113 struct thermal_cooling_device *);
89int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int, 114int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int,
90 struct thermal_cooling_device *); 115 struct thermal_cooling_device *);
91
92#ifdef CONFIG_THERMAL
93struct thermal_cooling_device *thermal_cooling_device_register(char *, void *, 116struct thermal_cooling_device *thermal_cooling_device_register(char *, void *,
94 struct 117 struct
95 thermal_cooling_device_ops 118 thermal_cooling_device_ops
96 *); 119 *);
97void thermal_cooling_device_unregister(struct thermal_cooling_device *); 120void thermal_cooling_device_unregister(struct thermal_cooling_device *);
98#else
99static inline struct thermal_cooling_device
100*thermal_cooling_device_register(char *c, void *v,
101 struct thermal_cooling_device_ops *t)
102{
103 return NULL;
104}
105static inline
106 void thermal_cooling_device_unregister(struct thermal_cooling_device *t)
107{
108};
109#endif
110 121
111#endif /* __THERMAL_H__ */ 122#endif /* __THERMAL_H__ */
diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index accd7bad35b0..38a56477f27a 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -92,6 +92,31 @@ static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
92#define set_need_resched() set_thread_flag(TIF_NEED_RESCHED) 92#define set_need_resched() set_thread_flag(TIF_NEED_RESCHED)
93#define clear_need_resched() clear_thread_flag(TIF_NEED_RESCHED) 93#define clear_need_resched() clear_thread_flag(TIF_NEED_RESCHED)
94 94
95#endif 95#if defined TIF_RESTORE_SIGMASK && !defined HAVE_SET_RESTORE_SIGMASK
96/*
97 * An arch can define its own version of set_restore_sigmask() to get the
98 * job done however works, with or without TIF_RESTORE_SIGMASK.
99 */
100#define HAVE_SET_RESTORE_SIGMASK 1
101
102/**
103 * set_restore_sigmask() - make sure saved_sigmask processing gets done
104 *
105 * This sets TIF_RESTORE_SIGMASK and ensures that the arch signal code
106 * will run before returning to user mode, to process the flag. For
107 * all callers, TIF_SIGPENDING is already set or it's no harm to set
108 * it. TIF_RESTORE_SIGMASK need not be in the set of bits that the
109 * arch code will notice on return to user mode, in case those bits
110 * are scarce. We set TIF_SIGPENDING here to ensure that the arch
111 * signal code always gets run when TIF_RESTORE_SIGMASK is set.
112 */
113static inline void set_restore_sigmask(void)
114{
115 set_thread_flag(TIF_RESTORE_SIGMASK);
116 set_thread_flag(TIF_SIGPENDING);
117}
118#endif /* TIF_RESTORE_SIGMASK && !HAVE_SET_RESTORE_SIGMASK */
119
120#endif /* __KERNEL__ */
96 121
97#endif /* _LINUX_THREAD_INFO_H */ 122#endif /* _LINUX_THREAD_INFO_H */
diff --git a/include/linux/timer.h b/include/linux/timer.h
index 979fefdeb862..d4ba79248a27 100644
--- a/include/linux/timer.h
+++ b/include/linux/timer.h
@@ -4,6 +4,7 @@
4#include <linux/list.h> 4#include <linux/list.h>
5#include <linux/ktime.h> 5#include <linux/ktime.h>
6#include <linux/stddef.h> 6#include <linux/stddef.h>
7#include <linux/debugobjects.h>
7 8
8struct tvec_base; 9struct tvec_base;
9 10
@@ -25,6 +26,7 @@ struct timer_list {
25extern struct tvec_base boot_tvec_bases; 26extern struct tvec_base boot_tvec_bases;
26 27
27#define TIMER_INITIALIZER(_function, _expires, _data) { \ 28#define TIMER_INITIALIZER(_function, _expires, _data) { \
29 .entry = { .prev = TIMER_ENTRY_STATIC }, \
28 .function = (_function), \ 30 .function = (_function), \
29 .expires = (_expires), \ 31 .expires = (_expires), \
30 .data = (_data), \ 32 .data = (_data), \
@@ -38,6 +40,17 @@ extern struct tvec_base boot_tvec_bases;
38void init_timer(struct timer_list *timer); 40void init_timer(struct timer_list *timer);
39void init_timer_deferrable(struct timer_list *timer); 41void init_timer_deferrable(struct timer_list *timer);
40 42
43#ifdef CONFIG_DEBUG_OBJECTS_TIMERS
44extern void init_timer_on_stack(struct timer_list *timer);
45extern void destroy_timer_on_stack(struct timer_list *timer);
46#else
47static inline void destroy_timer_on_stack(struct timer_list *timer) { }
48static inline void init_timer_on_stack(struct timer_list *timer)
49{
50 init_timer(timer);
51}
52#endif
53
41static inline void setup_timer(struct timer_list * timer, 54static inline void setup_timer(struct timer_list * timer,
42 void (*function)(unsigned long), 55 void (*function)(unsigned long),
43 unsigned long data) 56 unsigned long data)
@@ -47,6 +60,15 @@ static inline void setup_timer(struct timer_list * timer,
47 init_timer(timer); 60 init_timer(timer);
48} 61}
49 62
63static inline void setup_timer_on_stack(struct timer_list *timer,
64 void (*function)(unsigned long),
65 unsigned long data)
66{
67 timer->function = function;
68 timer->data = data;
69 init_timer_on_stack(timer);
70}
71
50/** 72/**
51 * timer_pending - is a timer pending? 73 * timer_pending - is a timer pending?
52 * @timer: the timer in question 74 * @timer: the timer in question
@@ -164,5 +186,4 @@ unsigned long __round_jiffies_relative(unsigned long j, int cpu);
164unsigned long round_jiffies(unsigned long j); 186unsigned long round_jiffies(unsigned long j);
165unsigned long round_jiffies_relative(unsigned long j); 187unsigned long round_jiffies_relative(unsigned long j);
166 188
167
168#endif 189#endif
diff --git a/include/linux/timex.h b/include/linux/timex.h
index 8ea3e71ba7fa..fc6035d29d56 100644
--- a/include/linux/timex.h
+++ b/include/linux/timex.h
@@ -58,6 +58,8 @@
58 58
59#include <asm/param.h> 59#include <asm/param.h>
60 60
61#define NTP_API 4 /* NTP API version */
62
61/* 63/*
62 * SHIFT_KG and SHIFT_KF establish the damping of the PLL and are chosen 64 * SHIFT_KG and SHIFT_KF establish the damping of the PLL and are chosen
63 * for a slightly underdamped convergence characteristic. SHIFT_KH 65 * for a slightly underdamped convergence characteristic. SHIFT_KH
@@ -74,24 +76,22 @@
74#define MAXTC 10 /* maximum time constant (shift) */ 76#define MAXTC 10 /* maximum time constant (shift) */
75 77
76/* 78/*
77 * The SHIFT_UPDATE define establishes the decimal point of the
78 * time_offset variable which represents the current offset with
79 * respect to standard time.
80 *
81 * SHIFT_USEC defines the scaling (shift) of the time_freq and 79 * SHIFT_USEC defines the scaling (shift) of the time_freq and
82 * time_tolerance variables, which represent the current frequency 80 * time_tolerance variables, which represent the current frequency
83 * offset and maximum frequency tolerance. 81 * offset and maximum frequency tolerance.
84 */ 82 */
85#define SHIFT_UPDATE (SHIFT_HZ + 1) /* time offset scale (shift) */
86#define SHIFT_USEC 16 /* frequency offset scale (shift) */ 83#define SHIFT_USEC 16 /* frequency offset scale (shift) */
87#define SHIFT_NSEC 12 /* kernel frequency offset scale */ 84#define PPM_SCALE (NSEC_PER_USEC << (NTP_SCALE_SHIFT - SHIFT_USEC))
88 85#define PPM_SCALE_INV_SHIFT 20
89#define MAXPHASE 512000L /* max phase error (us) */ 86#define PPM_SCALE_INV ((1ll << (PPM_SCALE_INV_SHIFT + NTP_SCALE_SHIFT)) / \
90#define MAXFREQ (512L << SHIFT_USEC) /* max frequency error (ppm) */ 87 PPM_SCALE + 1)
91#define MAXFREQ_NSEC (512000L << SHIFT_NSEC) /* max frequency error (ppb) */ 88
89#define MAXPHASE 500000000l /* max phase error (ns) */
90#define MAXFREQ 500000 /* max frequency error (ns/s) */
91#define MAXFREQ_SCALED ((s64)MAXFREQ << NTP_SCALE_SHIFT)
92#define MINSEC 256 /* min interval between updates (s) */ 92#define MINSEC 256 /* min interval between updates (s) */
93#define MAXSEC 2048 /* max interval between updates (s) */ 93#define MAXSEC 2048 /* max interval between updates (s) */
94#define NTP_PHASE_LIMIT (MAXPHASE << 5) /* beyond max. dispersion */ 94#define NTP_PHASE_LIMIT ((MAXPHASE / NSEC_PER_USEC) << 5) /* beyond max. dispersion */
95 95
96/* 96/*
97 * syscall interface - used (mainly by NTP daemon) 97 * syscall interface - used (mainly by NTP daemon)
@@ -121,9 +121,11 @@ struct timex {
121 long errcnt; /* calibration errors (ro) */ 121 long errcnt; /* calibration errors (ro) */
122 long stbcnt; /* stability limit exceeded (ro) */ 122 long stbcnt; /* stability limit exceeded (ro) */
123 123
124 int tai; /* TAI offset (ro) */
125
124 int :32; int :32; int :32; int :32; 126 int :32; int :32; int :32; int :32;
125 int :32; int :32; int :32; int :32; 127 int :32; int :32; int :32; int :32;
126 int :32; int :32; int :32; int :32; 128 int :32; int :32; int :32;
127}; 129};
128 130
129/* 131/*
@@ -135,6 +137,9 @@ struct timex {
135#define ADJ_ESTERROR 0x0008 /* estimated time error */ 137#define ADJ_ESTERROR 0x0008 /* estimated time error */
136#define ADJ_STATUS 0x0010 /* clock status */ 138#define ADJ_STATUS 0x0010 /* clock status */
137#define ADJ_TIMECONST 0x0020 /* pll time constant */ 139#define ADJ_TIMECONST 0x0020 /* pll time constant */
140#define ADJ_TAI 0x0080 /* set TAI offset */
141#define ADJ_MICRO 0x1000 /* select microsecond resolution */
142#define ADJ_NANO 0x2000 /* select nanosecond resolution */
138#define ADJ_TICK 0x4000 /* tick value */ 143#define ADJ_TICK 0x4000 /* tick value */
139#define ADJ_OFFSET_SINGLESHOT 0x8001 /* old-fashioned adjtime */ 144#define ADJ_OFFSET_SINGLESHOT 0x8001 /* old-fashioned adjtime */
140#define ADJ_OFFSET_SS_READ 0xa001 /* read-only adjtime */ 145#define ADJ_OFFSET_SS_READ 0xa001 /* read-only adjtime */
@@ -146,8 +151,6 @@ struct timex {
146#define MOD_ESTERROR ADJ_ESTERROR 151#define MOD_ESTERROR ADJ_ESTERROR
147#define MOD_STATUS ADJ_STATUS 152#define MOD_STATUS ADJ_STATUS
148#define MOD_TIMECONST ADJ_TIMECONST 153#define MOD_TIMECONST ADJ_TIMECONST
149#define MOD_CLKB ADJ_TICK
150#define MOD_CLKA ADJ_OFFSET_SINGLESHOT /* 0x8000 in original */
151 154
152 155
153/* 156/*
@@ -169,9 +172,13 @@ struct timex {
169#define STA_PPSERROR 0x0800 /* PPS signal calibration error (ro) */ 172#define STA_PPSERROR 0x0800 /* PPS signal calibration error (ro) */
170 173
171#define STA_CLOCKERR 0x1000 /* clock hardware fault (ro) */ 174#define STA_CLOCKERR 0x1000 /* clock hardware fault (ro) */
175#define STA_NANO 0x2000 /* resolution (0 = us, 1 = ns) (ro) */
176#define STA_MODE 0x4000 /* mode (0 = PLL, 1 = FLL) (ro) */
177#define STA_CLK 0x8000 /* clock source (0 = A, 1 = B) (ro) */
172 178
179/* read-only bits */
173#define STA_RONLY (STA_PPSSIGNAL | STA_PPSJITTER | STA_PPSWANDER | \ 180#define STA_RONLY (STA_PPSSIGNAL | STA_PPSJITTER | STA_PPSWANDER | \
174 STA_PPSERROR | STA_CLOCKERR) /* read-only bits */ 181 STA_PPSERROR | STA_CLOCKERR | STA_NANO | STA_MODE | STA_CLK)
175 182
176/* 183/*
177 * Clock states (time_state) 184 * Clock states (time_state)
@@ -203,10 +210,9 @@ extern int time_status; /* clock synchronization status bits */
203extern long time_maxerror; /* maximum error */ 210extern long time_maxerror; /* maximum error */
204extern long time_esterror; /* estimated error */ 211extern long time_esterror; /* estimated error */
205 212
206extern long time_freq; /* frequency offset (scaled ppm) */
207
208extern long time_adjust; /* The amount of adjtime left */ 213extern long time_adjust; /* The amount of adjtime left */
209 214
215extern void ntp_init(void);
210extern void ntp_clear(void); 216extern void ntp_clear(void);
211 217
212/** 218/**
@@ -225,7 +231,7 @@ static inline int ntp_synced(void)
225 __x < 0 ? -(-__x >> __s) : __x >> __s; \ 231 __x < 0 ? -(-__x >> __s) : __x >> __s; \
226}) 232})
227 233
228#define TICK_LENGTH_SHIFT 32 234#define NTP_SCALE_SHIFT 32
229 235
230#ifdef CONFIG_NO_HZ 236#ifdef CONFIG_NO_HZ
231#define NTP_INTERVAL_FREQ (2) 237#define NTP_INTERVAL_FREQ (2)
@@ -234,8 +240,8 @@ static inline int ntp_synced(void)
234#endif 240#endif
235#define NTP_INTERVAL_LENGTH (NSEC_PER_SEC/NTP_INTERVAL_FREQ) 241#define NTP_INTERVAL_LENGTH (NSEC_PER_SEC/NTP_INTERVAL_FREQ)
236 242
237/* Returns how long ticks are at present, in ns / 2^(SHIFT_SCALE-10). */ 243/* Returns how long ticks are at present, in ns / 2^NTP_SCALE_SHIFT. */
238extern u64 current_tick_length(void); 244extern u64 tick_length;
239 245
240extern void second_overflow(void); 246extern void second_overflow(void);
241extern void update_ntp_one_tick(void); 247extern void update_ntp_one_tick(void);
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 265831ccaa88..7f7121f9c968 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -177,27 +177,33 @@ struct signal_struct;
177 * size each time the window is created or resized anyway. 177 * size each time the window is created or resized anyway.
178 * - TYT, 9/14/92 178 * - TYT, 9/14/92
179 */ 179 */
180
181struct tty_operations;
182
180struct tty_struct { 183struct tty_struct {
181 int magic; 184 int magic;
182 struct tty_driver *driver; 185 struct tty_driver *driver;
186 const struct tty_operations *ops;
183 int index; 187 int index;
184 struct tty_ldisc ldisc; 188 struct tty_ldisc ldisc;
185 struct mutex termios_mutex; 189 struct mutex termios_mutex;
190 spinlock_t ctrl_lock;
191 /* Termios values are protected by the termios mutex */
186 struct ktermios *termios, *termios_locked; 192 struct ktermios *termios, *termios_locked;
187 char name[64]; 193 char name[64];
188 struct pid *pgrp; 194 struct pid *pgrp; /* Protected by ctrl lock */
189 struct pid *session; 195 struct pid *session;
190 unsigned long flags; 196 unsigned long flags;
191 int count; 197 int count;
192 struct winsize winsize; 198 struct winsize winsize; /* termios mutex */
193 unsigned char stopped:1, hw_stopped:1, flow_stopped:1, packet:1; 199 unsigned char stopped:1, hw_stopped:1, flow_stopped:1, packet:1;
194 unsigned char low_latency:1, warned:1; 200 unsigned char low_latency:1, warned:1;
195 unsigned char ctrl_status; 201 unsigned char ctrl_status; /* ctrl_lock */
196 unsigned int receive_room; /* Bytes free for queue */ 202 unsigned int receive_room; /* Bytes free for queue */
197 203
198 struct tty_struct *link; 204 struct tty_struct *link;
199 struct fasync_struct *fasync; 205 struct fasync_struct *fasync;
200 struct tty_bufhead buf; 206 struct tty_bufhead buf; /* Locked internally */
201 int alt_speed; /* For magic substitution of 38400 bps */ 207 int alt_speed; /* For magic substitution of 38400 bps */
202 wait_queue_head_t write_wait; 208 wait_queue_head_t write_wait;
203 wait_queue_head_t read_wait; 209 wait_queue_head_t read_wait;
@@ -211,6 +217,7 @@ struct tty_struct {
211 /* 217 /*
212 * The following is data for the N_TTY line discipline. For 218 * The following is data for the N_TTY line discipline. For
213 * historical reasons, this is included in the tty structure. 219 * historical reasons, this is included in the tty structure.
220 * Mostly locked by the BKL.
214 */ 221 */
215 unsigned int column; 222 unsigned int column;
216 unsigned char lnext:1, erasing:1, raw:1, real_raw:1, icanon:1; 223 unsigned char lnext:1, erasing:1, raw:1, real_raw:1, icanon:1;
@@ -292,8 +299,15 @@ extern void tty_unregister_device(struct tty_driver *driver, unsigned index);
292extern int tty_read_raw_data(struct tty_struct *tty, unsigned char *bufp, 299extern int tty_read_raw_data(struct tty_struct *tty, unsigned char *bufp,
293 int buflen); 300 int buflen);
294extern void tty_write_message(struct tty_struct *tty, char *msg); 301extern void tty_write_message(struct tty_struct *tty, char *msg);
302extern int tty_put_char(struct tty_struct *tty, unsigned char c);
303extern int tty_chars_in_buffer(struct tty_struct *tty);
304extern int tty_write_room(struct tty_struct *tty);
305extern void tty_driver_flush_buffer(struct tty_struct *tty);
306extern void tty_throttle(struct tty_struct *tty);
307extern void tty_unthrottle(struct tty_struct *tty);
295 308
296extern int is_current_pgrp_orphaned(void); 309extern int is_current_pgrp_orphaned(void);
310extern struct pid *tty_get_pgrp(struct tty_struct *tty);
297extern int is_ignored(int sig); 311extern int is_ignored(int sig);
298extern int tty_signal(int sig, struct tty_struct *tty); 312extern int tty_signal(int sig, struct tty_struct *tty);
299extern void tty_hangup(struct tty_struct * tty); 313extern void tty_hangup(struct tty_struct * tty);
@@ -323,8 +337,7 @@ extern void tty_ldisc_put(int);
323extern void tty_wakeup(struct tty_struct *tty); 337extern void tty_wakeup(struct tty_struct *tty);
324extern void tty_ldisc_flush(struct tty_struct *tty); 338extern void tty_ldisc_flush(struct tty_struct *tty);
325 339
326extern int tty_ioctl(struct inode *inode, struct file *file, unsigned int cmd, 340extern long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
327 unsigned long arg);
328extern int tty_mode_ioctl(struct tty_struct *tty, struct file *file, 341extern int tty_mode_ioctl(struct tty_struct *tty, struct file *file,
329 unsigned int cmd, unsigned long arg); 342 unsigned int cmd, unsigned long arg);
330extern int tty_perform_flush(struct tty_struct *tty, unsigned long arg); 343extern int tty_perform_flush(struct tty_struct *tty, unsigned long arg);
diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
index 21f69aca4505..59f1c0bd8f9c 100644
--- a/include/linux/tty_driver.h
+++ b/include/linux/tty_driver.h
@@ -12,11 +12,15 @@
12 * This routine is called when a particular tty device is opened. 12 * This routine is called when a particular tty device is opened.
13 * This routine is mandatory; if this routine is not filled in, 13 * This routine is mandatory; if this routine is not filled in,
14 * the attempted open will fail with ENODEV. 14 * the attempted open will fail with ENODEV.
15 *
16 * Required method.
15 * 17 *
16 * void (*close)(struct tty_struct * tty, struct file * filp); 18 * void (*close)(struct tty_struct * tty, struct file * filp);
17 * 19 *
18 * This routine is called when a particular tty device is closed. 20 * This routine is called when a particular tty device is closed.
19 * 21 *
22 * Required method.
23 *
20 * int (*write)(struct tty_struct * tty, 24 * int (*write)(struct tty_struct * tty,
21 * const unsigned char *buf, int count); 25 * const unsigned char *buf, int count);
22 * 26 *
@@ -26,7 +30,9 @@
26 * number of characters actually accepted for writing. This 30 * number of characters actually accepted for writing. This
27 * routine is mandatory. 31 * routine is mandatory.
28 * 32 *
29 * void (*put_char)(struct tty_struct *tty, unsigned char ch); 33 * Optional: Required for writable devices.
34 *
35 * int (*put_char)(struct tty_struct *tty, unsigned char ch);
30 * 36 *
31 * This routine is called by the kernel to write a single 37 * This routine is called by the kernel to write a single
32 * character to the tty device. If the kernel uses this routine, 38 * character to the tty device. If the kernel uses this routine,
@@ -34,10 +40,18 @@
34 * done stuffing characters into the driver. If there is no room 40 * done stuffing characters into the driver. If there is no room
35 * in the queue, the character is ignored. 41 * in the queue, the character is ignored.
36 * 42 *
43 * Optional: Kernel will use the write method if not provided.
44 *
45 * Note: Do not call this function directly, call tty_put_char
46 *
37 * void (*flush_chars)(struct tty_struct *tty); 47 * void (*flush_chars)(struct tty_struct *tty);
38 * 48 *
39 * This routine is called by the kernel after it has written a 49 * This routine is called by the kernel after it has written a
40 * series of characters to the tty device using put_char(). 50 * series of characters to the tty device using put_char().
51 *
52 * Optional:
53 *
54 * Note: Do not call this function directly, call tty_driver_flush_chars
41 * 55 *
42 * int (*write_room)(struct tty_struct *tty); 56 * int (*write_room)(struct tty_struct *tty);
43 * 57 *
@@ -45,6 +59,10 @@
45 * will accept for queuing to be written. This number is subject 59 * will accept for queuing to be written. This number is subject
46 * to change as output buffers get emptied, or if the output flow 60 * to change as output buffers get emptied, or if the output flow
47 * control is acted. 61 * control is acted.
62 *
63 * Required if write method is provided else not needed.
64 *
65 * Note: Do not call this function directly, call tty_write_room
48 * 66 *
49 * int (*ioctl)(struct tty_struct *tty, struct file * file, 67 * int (*ioctl)(struct tty_struct *tty, struct file * file,
50 * unsigned int cmd, unsigned long arg); 68 * unsigned int cmd, unsigned long arg);
@@ -53,28 +71,37 @@
53 * device-specific ioctl's. If the ioctl number passed in cmd 71 * device-specific ioctl's. If the ioctl number passed in cmd
54 * is not recognized by the driver, it should return ENOIOCTLCMD. 72 * is not recognized by the driver, it should return ENOIOCTLCMD.
55 * 73 *
74 * Optional
75 *
56 * long (*compat_ioctl)(struct tty_struct *tty, struct file * file, 76 * long (*compat_ioctl)(struct tty_struct *tty, struct file * file,
57 * unsigned int cmd, unsigned long arg); 77 * unsigned int cmd, unsigned long arg);
58 * 78 *
59 * implement ioctl processing for 32 bit process on 64 bit system 79 * implement ioctl processing for 32 bit process on 64 bit system
80 *
81 * Optional
60 * 82 *
61 * void (*set_termios)(struct tty_struct *tty, struct ktermios * old); 83 * void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
62 * 84 *
63 * This routine allows the tty driver to be notified when 85 * This routine allows the tty driver to be notified when
64 * device's termios settings have changed. Note that a 86 * device's termios settings have changed.
65 * well-designed tty driver should be prepared to accept the case 87 *
66 * where old == NULL, and try to do something rational. 88 * Optional: Called under the termios lock
89 *
67 * 90 *
68 * void (*set_ldisc)(struct tty_struct *tty); 91 * void (*set_ldisc)(struct tty_struct *tty);
69 * 92 *
70 * This routine allows the tty driver to be notified when the 93 * This routine allows the tty driver to be notified when the
71 * device's termios settings have changed. 94 * device's termios settings have changed.
95 *
96 * Optional: Called under BKL (currently)
72 * 97 *
73 * void (*throttle)(struct tty_struct * tty); 98 * void (*throttle)(struct tty_struct * tty);
74 * 99 *
75 * This routine notifies the tty driver that input buffers for 100 * This routine notifies the tty driver that input buffers for
76 * the line discipline are close to full, and it should somehow 101 * the line discipline are close to full, and it should somehow
77 * signal that no more characters should be sent to the tty. 102 * signal that no more characters should be sent to the tty.
103 *
104 * Optional: Always invoke via tty_throttle();
78 * 105 *
79 * void (*unthrottle)(struct tty_struct * tty); 106 * void (*unthrottle)(struct tty_struct * tty);
80 * 107 *
@@ -82,21 +109,33 @@
82 * that characters can now be sent to the tty without fear of 109 * that characters can now be sent to the tty without fear of
83 * overrunning the input buffers of the line disciplines. 110 * overrunning the input buffers of the line disciplines.
84 * 111 *
112 * Optional: Always invoke via tty_unthrottle();
113 *
85 * void (*stop)(struct tty_struct *tty); 114 * void (*stop)(struct tty_struct *tty);
86 * 115 *
87 * This routine notifies the tty driver that it should stop 116 * This routine notifies the tty driver that it should stop
88 * outputting characters to the tty device. 117 * outputting characters to the tty device.
118 *
119 * Optional:
120 *
121 * Note: Call stop_tty not this method.
89 * 122 *
90 * void (*start)(struct tty_struct *tty); 123 * void (*start)(struct tty_struct *tty);
91 * 124 *
92 * This routine notifies the tty driver that it resume sending 125 * This routine notifies the tty driver that it resume sending
93 * characters to the tty device. 126 * characters to the tty device.
127 *
128 * Optional:
129 *
130 * Note: Call start_tty not this method.
94 * 131 *
95 * void (*hangup)(struct tty_struct *tty); 132 * void (*hangup)(struct tty_struct *tty);
96 * 133 *
97 * This routine notifies the tty driver that it should hangup the 134 * This routine notifies the tty driver that it should hangup the
98 * tty device. 135 * tty device.
99 * 136 *
137 * Required:
138 *
100 * void (*break_ctl)(struct tty_stuct *tty, int state); 139 * void (*break_ctl)(struct tty_stuct *tty, int state);
101 * 140 *
102 * This optional routine requests the tty driver to turn on or 141 * This optional routine requests the tty driver to turn on or
@@ -106,18 +145,26 @@
106 * 145 *
107 * If this routine is implemented, the high-level tty driver will 146 * If this routine is implemented, the high-level tty driver will
108 * handle the following ioctls: TCSBRK, TCSBRKP, TIOCSBRK, 147 * handle the following ioctls: TCSBRK, TCSBRKP, TIOCSBRK,
109 * TIOCCBRK. Otherwise, these ioctls will be passed down to the 148 * TIOCCBRK.
110 * driver to handle. 149 *
150 * Optional: Required for TCSBRK/BRKP/etc handling.
111 * 151 *
112 * void (*wait_until_sent)(struct tty_struct *tty, int timeout); 152 * void (*wait_until_sent)(struct tty_struct *tty, int timeout);
113 * 153 *
114 * This routine waits until the device has written out all of the 154 * This routine waits until the device has written out all of the
115 * characters in its transmitter FIFO. 155 * characters in its transmitter FIFO.
116 * 156 *
157 * Optional: If not provided the device is assumed to have no FIFO
158 *
159 * Note: Usually correct to call tty_wait_until_sent
160 *
117 * void (*send_xchar)(struct tty_struct *tty, char ch); 161 * void (*send_xchar)(struct tty_struct *tty, char ch);
118 * 162 *
119 * This routine is used to send a high-priority XON/XOFF 163 * This routine is used to send a high-priority XON/XOFF
120 * character to the device. 164 * character to the device.
165 *
166 * Optional: If not provided then the write method is called under
167 * the atomic write lock to keep it serialized with the ldisc.
121 */ 168 */
122 169
123#include <linux/fs.h> 170#include <linux/fs.h>
@@ -132,7 +179,7 @@ struct tty_operations {
132 void (*close)(struct tty_struct * tty, struct file * filp); 179 void (*close)(struct tty_struct * tty, struct file * filp);
133 int (*write)(struct tty_struct * tty, 180 int (*write)(struct tty_struct * tty,
134 const unsigned char *buf, int count); 181 const unsigned char *buf, int count);
135 void (*put_char)(struct tty_struct *tty, unsigned char ch); 182 int (*put_char)(struct tty_struct *tty, unsigned char ch);
136 void (*flush_chars)(struct tty_struct *tty); 183 void (*flush_chars)(struct tty_struct *tty);
137 int (*write_room)(struct tty_struct *tty); 184 int (*write_room)(struct tty_struct *tty);
138 int (*chars_in_buffer)(struct tty_struct *tty); 185 int (*chars_in_buffer)(struct tty_struct *tty);
@@ -153,8 +200,6 @@ struct tty_operations {
153 void (*send_xchar)(struct tty_struct *tty, char ch); 200 void (*send_xchar)(struct tty_struct *tty, char ch);
154 int (*read_proc)(char *page, char **start, off_t off, 201 int (*read_proc)(char *page, char **start, off_t off,
155 int count, int *eof, void *data); 202 int count, int *eof, void *data);
156 int (*write_proc)(struct file *file, const char __user *buffer,
157 unsigned long count, void *data);
158 int (*tiocmget)(struct tty_struct *tty, struct file *file); 203 int (*tiocmget)(struct tty_struct *tty, struct file *file);
159 int (*tiocmset)(struct tty_struct *tty, struct file *file, 204 int (*tiocmset)(struct tty_struct *tty, struct file *file,
160 unsigned int set, unsigned int clear); 205 unsigned int set, unsigned int clear);
@@ -190,48 +235,13 @@ struct tty_driver {
190 struct tty_struct **ttys; 235 struct tty_struct **ttys;
191 struct ktermios **termios; 236 struct ktermios **termios;
192 struct ktermios **termios_locked; 237 struct ktermios **termios_locked;
193 void *driver_state; /* only used for the PTY driver */ 238 void *driver_state;
194 239
195 /* 240 /*
196 * Interface routines from the upper tty layer to the tty 241 * Driver methods
197 * driver. Will be replaced with struct tty_operations.
198 */ 242 */
199 int (*open)(struct tty_struct * tty, struct file * filp);
200 void (*close)(struct tty_struct * tty, struct file * filp);
201 int (*write)(struct tty_struct * tty,
202 const unsigned char *buf, int count);
203 void (*put_char)(struct tty_struct *tty, unsigned char ch);
204 void (*flush_chars)(struct tty_struct *tty);
205 int (*write_room)(struct tty_struct *tty);
206 int (*chars_in_buffer)(struct tty_struct *tty);
207 int (*ioctl)(struct tty_struct *tty, struct file * file,
208 unsigned int cmd, unsigned long arg);
209 long (*compat_ioctl)(struct tty_struct *tty, struct file * file,
210 unsigned int cmd, unsigned long arg);
211 void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
212 void (*throttle)(struct tty_struct * tty);
213 void (*unthrottle)(struct tty_struct * tty);
214 void (*stop)(struct tty_struct *tty);
215 void (*start)(struct tty_struct *tty);
216 void (*hangup)(struct tty_struct *tty);
217 void (*break_ctl)(struct tty_struct *tty, int state);
218 void (*flush_buffer)(struct tty_struct *tty);
219 void (*set_ldisc)(struct tty_struct *tty);
220 void (*wait_until_sent)(struct tty_struct *tty, int timeout);
221 void (*send_xchar)(struct tty_struct *tty, char ch);
222 int (*read_proc)(char *page, char **start, off_t off,
223 int count, int *eof, void *data);
224 int (*write_proc)(struct file *file, const char __user *buffer,
225 unsigned long count, void *data);
226 int (*tiocmget)(struct tty_struct *tty, struct file *file);
227 int (*tiocmset)(struct tty_struct *tty, struct file *file,
228 unsigned int set, unsigned int clear);
229#ifdef CONFIG_CONSOLE_POLL
230 int (*poll_init)(struct tty_driver *driver, int line, char *options);
231 int (*poll_get_char)(struct tty_driver *driver, int line);
232 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
233#endif
234 243
244 const struct tty_operations *ops;
235 struct list_head tty_drivers; 245 struct list_head tty_drivers;
236}; 246};
237 247
diff --git a/include/linux/usb/c67x00.h b/include/linux/usb/c67x00.h
new file mode 100644
index 000000000000..83c6b45470ca
--- /dev/null
+++ b/include/linux/usb/c67x00.h
@@ -0,0 +1,48 @@
1/*
2 * usb_c67x00.h: platform definitions for the Cypress C67X00 USB chip
3 *
4 * Copyright (C) 2006-2008 Barco N.V.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 * MA 02110-1301 USA.
20 */
21
22#ifndef _LINUX_USB_C67X00_H
23#define _LINUX_USB_C67X00_H
24
25/* SIE configuration */
26#define C67X00_SIE_UNUSED 0
27#define C67X00_SIE_HOST 1
28#define C67X00_SIE_PERIPHERAL_A 2 /* peripheral on A port */
29#define C67X00_SIE_PERIPHERAL_B 3 /* peripheral on B port */
30
31#define c67x00_sie_config(config, n) (((config)>>(4*(n)))&0x3)
32
33#define C67X00_SIE1_UNUSED (C67X00_SIE_UNUSED << 0)
34#define C67X00_SIE1_HOST (C67X00_SIE_HOST << 0)
35#define C67X00_SIE1_PERIPHERAL_A (C67X00_SIE_PERIPHERAL_A << 0)
36#define C67X00_SIE1_PERIPHERAL_B (C67X00_SIE_PERIPHERAL_B << 0)
37
38#define C67X00_SIE2_UNUSED (C67X00_SIE_UNUSED << 4)
39#define C67X00_SIE2_HOST (C67X00_SIE_HOST << 4)
40#define C67X00_SIE2_PERIPHERAL_A (C67X00_SIE_PERIPHERAL_A << 4)
41#define C67X00_SIE2_PERIPHERAL_B (C67X00_SIE_PERIPHERAL_B << 4)
42
43struct c67x00_platform_data {
44 int sie_config; /* SIEs config (C67X00_SIEx_*) */
45 unsigned long hpi_regstep; /* Step between HPI registers */
46};
47
48#endif /* _LINUX_USB_C67X00_H */
diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h
index 7e0d3084f76c..73a2f4eb1f7a 100644
--- a/include/linux/usb/ch9.h
+++ b/include/linux/usb/ch9.h
@@ -455,7 +455,7 @@ struct usb_encryption_descriptor {
455 455
456/*-------------------------------------------------------------------------*/ 456/*-------------------------------------------------------------------------*/
457 457
458/* USB_DT_BOS: group of wireless capabilities */ 458/* USB_DT_BOS: group of device-level capabilities */
459struct usb_bos_descriptor { 459struct usb_bos_descriptor {
460 __u8 bLength; 460 __u8 bLength;
461 __u8 bDescriptorType; 461 __u8 bDescriptorType;
@@ -501,6 +501,16 @@ struct usb_wireless_cap_descriptor { /* Ultra Wide Band */
501 __u8 bReserved; 501 __u8 bReserved;
502} __attribute__((packed)); 502} __attribute__((packed));
503 503
504#define USB_CAP_TYPE_EXT 2
505
506struct usb_ext_cap_descriptor { /* Link Power Management */
507 __u8 bLength;
508 __u8 bDescriptorType;
509 __u8 bDevCapabilityType;
510 __u8 bmAttributes;
511#define USB_LPM_SUPPORT (1 << 1) /* supports LPM */
512} __attribute__((packed));
513
504/*-------------------------------------------------------------------------*/ 514/*-------------------------------------------------------------------------*/
505 515
506/* USB_DT_WIRELESS_ENDPOINT_COMP: companion descriptor associated with 516/* USB_DT_WIRELESS_ENDPOINT_COMP: companion descriptor associated with
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index d8128f7102c9..cf468fbdbf8e 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -114,6 +114,8 @@ struct usb_ep_ops {
114 int (*dequeue) (struct usb_ep *ep, struct usb_request *req); 114 int (*dequeue) (struct usb_ep *ep, struct usb_request *req);
115 115
116 int (*set_halt) (struct usb_ep *ep, int value); 116 int (*set_halt) (struct usb_ep *ep, int value);
117 int (*set_wedge) (struct usb_ep *ep);
118
117 int (*fifo_status) (struct usb_ep *ep); 119 int (*fifo_status) (struct usb_ep *ep);
118 void (*fifo_flush) (struct usb_ep *ep); 120 void (*fifo_flush) (struct usb_ep *ep);
119}; 121};
@@ -349,6 +351,25 @@ static inline int usb_ep_clear_halt(struct usb_ep *ep)
349} 351}
350 352
351/** 353/**
354 * usb_ep_set_wedge - sets the halt feature and ignores clear requests
355 * @ep: the endpoint being wedged
356 *
357 * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
358 * requests. If the gadget driver clears the halt status, it will
359 * automatically unwedge the endpoint.
360 *
361 * Returns zero on success, else negative errno.
362 */
363static inline int
364usb_ep_set_wedge(struct usb_ep *ep)
365{
366 if (ep->ops->set_wedge)
367 return ep->ops->set_wedge(ep);
368 else
369 return ep->ops->set_halt(ep, 1);
370}
371
372/**
352 * usb_ep_fifo_status - returns number of bytes in fifo, or error 373 * usb_ep_fifo_status - returns number of bytes in fifo, or error
353 * @ep: the endpoint whose fifo status is being checked. 374 * @ep: the endpoint whose fifo status is being checked.
354 * 375 *
diff --git a/include/linux/virtio.h b/include/linux/virtio.h
index e7d10845b3c1..06005fa9e982 100644
--- a/include/linux/virtio.h
+++ b/include/linux/virtio.h
@@ -76,6 +76,7 @@ struct virtqueue_ops {
76 * @dev: underlying device. 76 * @dev: underlying device.
77 * @id: the device type identification (used to match it with a driver). 77 * @id: the device type identification (used to match it with a driver).
78 * @config: the configuration ops for this device. 78 * @config: the configuration ops for this device.
79 * @features: the features supported by both driver and device.
79 * @priv: private pointer for the driver's use. 80 * @priv: private pointer for the driver's use.
80 */ 81 */
81struct virtio_device 82struct virtio_device
@@ -84,6 +85,8 @@ struct virtio_device
84 struct device dev; 85 struct device dev;
85 struct virtio_device_id id; 86 struct virtio_device_id id;
86 struct virtio_config_ops *config; 87 struct virtio_config_ops *config;
88 /* Note that this is a Linux set_bit-style bitmap. */
89 unsigned long features[1];
87 void *priv; 90 void *priv;
88}; 91};
89 92
@@ -94,6 +97,8 @@ void unregister_virtio_device(struct virtio_device *dev);
94 * virtio_driver - operations for a virtio I/O driver 97 * virtio_driver - operations for a virtio I/O driver
95 * @driver: underlying device driver (populate name and owner). 98 * @driver: underlying device driver (populate name and owner).
96 * @id_table: the ids serviced by this driver. 99 * @id_table: the ids serviced by this driver.
100 * @feature_table: an array of feature numbers supported by this device.
101 * @feature_table_size: number of entries in the feature table array.
97 * @probe: the function to call when a device is found. Returns a token for 102 * @probe: the function to call when a device is found. Returns a token for
98 * remove, or PTR_ERR(). 103 * remove, or PTR_ERR().
99 * @remove: the function when a device is removed. 104 * @remove: the function when a device is removed.
@@ -103,6 +108,8 @@ void unregister_virtio_device(struct virtio_device *dev);
103struct virtio_driver { 108struct virtio_driver {
104 struct device_driver driver; 109 struct device_driver driver;
105 const struct virtio_device_id *id_table; 110 const struct virtio_device_id *id_table;
111 const unsigned int *feature_table;
112 unsigned int feature_table_size;
106 int (*probe)(struct virtio_device *dev); 113 int (*probe)(struct virtio_device *dev);
107 void (*remove)(struct virtio_device *dev); 114 void (*remove)(struct virtio_device *dev);
108 void (*config_changed)(struct virtio_device *dev); 115 void (*config_changed)(struct virtio_device *dev);
diff --git a/include/linux/virtio_blk.h b/include/linux/virtio_blk.h
index bca0b10d7947..d4695a3356d0 100644
--- a/include/linux/virtio_blk.h
+++ b/include/linux/virtio_blk.h
@@ -9,6 +9,7 @@
9#define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */ 9#define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */
10#define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */ 10#define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */
11#define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */ 11#define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */
12#define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */
12 13
13struct virtio_blk_config 14struct virtio_blk_config
14{ 15{
@@ -18,6 +19,12 @@ struct virtio_blk_config
18 __le32 size_max; 19 __le32 size_max;
19 /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */ 20 /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */
20 __le32 seg_max; 21 __le32 seg_max;
22 /* geometry the device (if VIRTIO_BLK_F_GEOMETRY) */
23 struct virtio_blk_geometry {
24 __le16 cylinders;
25 __u8 heads;
26 __u8 sectors;
27 } geometry;
21} __attribute__((packed)); 28} __attribute__((packed));
22 29
23/* These two define direction. */ 30/* These two define direction. */
@@ -41,13 +48,8 @@ struct virtio_blk_outhdr
41 __u64 sector; 48 __u64 sector;
42}; 49};
43 50
51/* And this is the final byte of the write scatter-gather list. */
44#define VIRTIO_BLK_S_OK 0 52#define VIRTIO_BLK_S_OK 0
45#define VIRTIO_BLK_S_IOERR 1 53#define VIRTIO_BLK_S_IOERR 1
46#define VIRTIO_BLK_S_UNSUPP 2 54#define VIRTIO_BLK_S_UNSUPP 2
47
48/* This is the first element of the write scatter-gather list */
49struct virtio_blk_inhdr
50{
51 unsigned char status;
52};
53#endif /* _LINUX_VIRTIO_BLK_H */ 55#endif /* _LINUX_VIRTIO_BLK_H */
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index d581b2914b34..50db245c81ad 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -16,27 +16,20 @@
16#define VIRTIO_CONFIG_S_FAILED 0x80 16#define VIRTIO_CONFIG_S_FAILED 0x80
17 17
18#ifdef __KERNEL__ 18#ifdef __KERNEL__
19struct virtio_device; 19#include <linux/virtio.h>
20 20
21/** 21/**
22 * virtio_config_ops - operations for configuring a virtio device 22 * virtio_config_ops - operations for configuring a virtio device
23 * @feature: search for a feature in this config
24 * vdev: the virtio_device
25 * bit: the feature bit
26 * Returns true if the feature is supported. Acknowledges the feature
27 * so the host can see it.
28 * @get: read the value of a configuration field 23 * @get: read the value of a configuration field
29 * vdev: the virtio_device 24 * vdev: the virtio_device
30 * offset: the offset of the configuration field 25 * offset: the offset of the configuration field
31 * buf: the buffer to write the field value into. 26 * buf: the buffer to write the field value into.
32 * len: the length of the buffer 27 * len: the length of the buffer
33 * Note that contents are conventionally little-endian.
34 * @set: write the value of a configuration field 28 * @set: write the value of a configuration field
35 * vdev: the virtio_device 29 * vdev: the virtio_device
36 * offset: the offset of the configuration field 30 * offset: the offset of the configuration field
37 * buf: the buffer to read the field value from. 31 * buf: the buffer to read the field value from.
38 * len: the length of the buffer 32 * len: the length of the buffer
39 * Note that contents are conventionally little-endian.
40 * @get_status: read the status byte 33 * @get_status: read the status byte
41 * vdev: the virtio_device 34 * vdev: the virtio_device
42 * Returns the status byte 35 * Returns the status byte
@@ -52,10 +45,15 @@ struct virtio_device;
52 * callback: the virqtueue callback 45 * callback: the virqtueue callback
53 * Returns the new virtqueue or ERR_PTR() (eg. -ENOENT). 46 * Returns the new virtqueue or ERR_PTR() (eg. -ENOENT).
54 * @del_vq: free a virtqueue found by find_vq(). 47 * @del_vq: free a virtqueue found by find_vq().
48 * @get_features: get the array of feature bits for this device.
49 * vdev: the virtio_device
50 * Returns the first 32 feature bits (all we currently need).
51 * @set_features: confirm what device features we'll be using.
52 * vdev: the virtio_device
53 * feature: the first 32 feature bits
55 */ 54 */
56struct virtio_config_ops 55struct virtio_config_ops
57{ 56{
58 bool (*feature)(struct virtio_device *vdev, unsigned bit);
59 void (*get)(struct virtio_device *vdev, unsigned offset, 57 void (*get)(struct virtio_device *vdev, unsigned offset,
60 void *buf, unsigned len); 58 void *buf, unsigned len);
61 void (*set)(struct virtio_device *vdev, unsigned offset, 59 void (*set)(struct virtio_device *vdev, unsigned offset,
@@ -67,43 +65,52 @@ struct virtio_config_ops
67 unsigned index, 65 unsigned index,
68 void (*callback)(struct virtqueue *)); 66 void (*callback)(struct virtqueue *));
69 void (*del_vq)(struct virtqueue *vq); 67 void (*del_vq)(struct virtqueue *vq);
68 u32 (*get_features)(struct virtio_device *vdev);
69 void (*set_features)(struct virtio_device *vdev, u32 features);
70}; 70};
71 71
72/* If driver didn't advertise the feature, it will never appear. */
73void virtio_check_driver_offered_feature(const struct virtio_device *vdev,
74 unsigned int fbit);
75
72/** 76/**
73 * virtio_config_val - look for a feature and get a single virtio config. 77 * virtio_has_feature - helper to determine if this device has this feature.
74 * @vdev: the virtio device 78 * @vdev: the device
75 * @fbit: the feature bit 79 * @fbit: the feature bit
76 * @offset: the type to search for. 80 */
77 * @val: a pointer to the value to fill in. 81static inline bool virtio_has_feature(const struct virtio_device *vdev,
78 * 82 unsigned int fbit)
79 * The return value is -ENOENT if the feature doesn't exist. Otherwise 83{
80 * the value is endian-corrected and returned in v. */ 84 /* Did you forget to fix assumptions on max features? */
81#define virtio_config_val(vdev, fbit, offset, v) ({ \ 85 if (__builtin_constant_p(fbit))
82 int _err; \ 86 BUILD_BUG_ON(fbit >= 32);
83 if ((vdev)->config->feature((vdev), (fbit))) { \ 87
84 __virtio_config_val((vdev), (offset), (v)); \ 88 virtio_check_driver_offered_feature(vdev, fbit);
85 _err = 0; \ 89 return test_bit(fbit, vdev->features);
86 } else \ 90}
87 _err = -ENOENT; \
88 _err; \
89})
90 91
91/** 92/**
92 * __virtio_config_val - get a single virtio config without feature check. 93 * virtio_config_val - look for a feature and get a virtio config entry.
93 * @vdev: the virtio device 94 * @vdev: the virtio device
95 * @fbit: the feature bit
94 * @offset: the type to search for. 96 * @offset: the type to search for.
95 * @val: a pointer to the value to fill in. 97 * @val: a pointer to the value to fill in.
96 * 98 *
97 * The value is endian-corrected and returned in v. */ 99 * The return value is -ENOENT if the feature doesn't exist. Otherwise
98#define __virtio_config_val(vdev, offset, v) do { \ 100 * the config value is copied into whatever is pointed to by v. */
99 BUILD_BUG_ON(sizeof(*(v)) != 1 && sizeof(*(v)) != 2 \ 101#define virtio_config_val(vdev, fbit, offset, v) \
100 && sizeof(*(v)) != 4 && sizeof(*(v)) != 8); \ 102 virtio_config_buf((vdev), (fbit), (offset), (v), sizeof(v))
101 (vdev)->config->get((vdev), (offset), (v), sizeof(*(v))); \ 103
102 switch (sizeof(*(v))) { \ 104static inline int virtio_config_buf(struct virtio_device *vdev,
103 case 2: le16_to_cpus((__u16 *) v); break; \ 105 unsigned int fbit,
104 case 4: le32_to_cpus((__u32 *) v); break; \ 106 unsigned int offset,
105 case 8: le64_to_cpus((__u64 *) v); break; \ 107 void *buf, unsigned len)
106 } \ 108{
107} while(0) 109 if (!virtio_has_feature(vdev, fbit))
110 return -ENOENT;
111
112 vdev->config->get(vdev, offset, buf, len);
113 return 0;
114}
108#endif /* __KERNEL__ */ 115#endif /* __KERNEL__ */
109#endif /* _LINUX_VIRTIO_CONFIG_H */ 116#endif /* _LINUX_VIRTIO_CONFIG_H */
diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
index 1ea3351df609..9405aa6cdf26 100644
--- a/include/linux/virtio_net.h
+++ b/include/linux/virtio_net.h
@@ -6,9 +6,18 @@
6#define VIRTIO_ID_NET 1 6#define VIRTIO_ID_NET 1
7 7
8/* The feature bitmap for virtio net */ 8/* The feature bitmap for virtio net */
9#define VIRTIO_NET_F_CSUM 0 /* Can handle pkts w/ partial csum */ 9#define VIRTIO_NET_F_CSUM 0 /* Host handles pkts w/ partial csum */
10#define VIRTIO_NET_F_GUEST_CSUM 1 /* Guest handles pkts w/ partial csum */
10#define VIRTIO_NET_F_MAC 5 /* Host has given MAC address. */ 11#define VIRTIO_NET_F_MAC 5 /* Host has given MAC address. */
11#define VIRTIO_NET_F_GSO 6 /* Can handle pkts w/ any GSO type */ 12#define VIRTIO_NET_F_GSO 6 /* Host handles pkts w/ any GSO type */
13#define VIRTIO_NET_F_GUEST_TSO4 7 /* Guest can handle TSOv4 in. */
14#define VIRTIO_NET_F_GUEST_TSO6 8 /* Guest can handle TSOv6 in. */
15#define VIRTIO_NET_F_GUEST_ECN 9 /* Guest can handle TSO[6] w/ ECN in. */
16#define VIRTIO_NET_F_GUEST_UFO 10 /* Guest can handle UFO in. */
17#define VIRTIO_NET_F_HOST_TSO4 11 /* Host can handle TSOv4 in. */
18#define VIRTIO_NET_F_HOST_TSO6 12 /* Host can handle TSOv6 in. */
19#define VIRTIO_NET_F_HOST_ECN 13 /* Host can handle TSO[6] w/ ECN in. */
20#define VIRTIO_NET_F_HOST_UFO 14 /* Host can handle UFO in. */
12 21
13struct virtio_net_config 22struct virtio_net_config
14{ 23{
diff --git a/include/linux/wireless.h b/include/linux/wireless.h
index 2864b1699ecc..0a9b5b41ed67 100644
--- a/include/linux/wireless.h
+++ b/include/linux/wireless.h
@@ -69,14 +69,9 @@
69 69
70/***************************** INCLUDES *****************************/ 70/***************************** INCLUDES *****************************/
71 71
72/* This header is used in user-space, therefore need to be sanitised 72#include <linux/types.h> /* for __u* and __s* typedefs */
73 * for that purpose. Those includes are usually not compatible with glibc.
74 * To know which includes to use in user-space, check iwlib.h. */
75#ifdef __KERNEL__
76#include <linux/types.h> /* for "caddr_t" et al */
77#include <linux/socket.h> /* for "struct sockaddr" et al */ 73#include <linux/socket.h> /* for "struct sockaddr" et al */
78#include <linux/if.h> /* for IFNAMSIZ and co... */ 74#include <linux/if.h> /* for IFNAMSIZ and co... */
79#endif /* __KERNEL__ */
80 75
81/***************************** VERSION *****************************/ 76/***************************** VERSION *****************************/
82/* 77/*
diff --git a/include/linux/writeback.h b/include/linux/writeback.h
index b7b3362f7717..f462439cc288 100644
--- a/include/linux/writeback.h
+++ b/include/linux/writeback.h
@@ -114,6 +114,9 @@ struct file;
114int dirty_writeback_centisecs_handler(struct ctl_table *, int, struct file *, 114int dirty_writeback_centisecs_handler(struct ctl_table *, int, struct file *,
115 void __user *, size_t *, loff_t *); 115 void __user *, size_t *, loff_t *);
116 116
117void get_dirty_limits(long *pbackground, long *pdirty, long *pbdi_dirty,
118 struct backing_dev_info *bdi);
119
117void page_writeback_init(void); 120void page_writeback_init(void);
118void balance_dirty_pages_ratelimited_nr(struct address_space *mapping, 121void balance_dirty_pages_ratelimited_nr(struct address_space *mapping,
119 unsigned long nr_pages_dirtied); 122 unsigned long nr_pages_dirtied);
diff --git a/include/net/compat.h b/include/net/compat.h
index 05fa5d0254ab..164cb682e220 100644
--- a/include/net/compat.h
+++ b/include/net/compat.h
@@ -42,5 +42,8 @@ extern int cmsghdr_from_user_compat_to_kern(struct msghdr *, struct sock *, unsi
42 42
43extern int compat_mc_setsockopt(struct sock *, int, int, char __user *, int, 43extern int compat_mc_setsockopt(struct sock *, int, int, char __user *, int,
44 int (*)(struct sock *, int, int, char __user *, int)); 44 int (*)(struct sock *, int, int, char __user *, int));
45extern int compat_mc_getsockopt(struct sock *, int, int, char __user *,
46 int __user *, int (*)(struct sock *, int, int, char __user *,
47 int __user *));
45 48
46#endif /* NET_COMPAT_H */ 49#endif /* NET_COMPAT_H */
diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
index 56f3c94ae620..9a51ebad3f1f 100644
--- a/include/net/ip_vs.h
+++ b/include/net/ip_vs.h
@@ -405,7 +405,8 @@ struct sk_buff;
405struct ip_vs_protocol { 405struct ip_vs_protocol {
406 struct ip_vs_protocol *next; 406 struct ip_vs_protocol *next;
407 char *name; 407 char *name;
408 __u16 protocol; 408 u16 protocol;
409 u16 num_states;
409 int dont_defrag; 410 int dont_defrag;
410 atomic_t appcnt; /* counter of proto app incs */ 411 atomic_t appcnt; /* counter of proto app incs */
411 int *timeout_table; /* protocol timeout table */ 412 int *timeout_table; /* protocol timeout table */
diff --git a/include/net/netfilter/nf_conntrack_tuple.h b/include/net/netfilter/nf_conntrack_tuple.h
index 1bb7087833d3..a6874ba22d54 100644
--- a/include/net/netfilter/nf_conntrack_tuple.h
+++ b/include/net/netfilter/nf_conntrack_tuple.h
@@ -107,16 +107,6 @@ struct nf_conntrack_tuple_mask
107 } src; 107 } src;
108}; 108};
109 109
110/* This is optimized opposed to a memset of the whole structure. Everything we
111 * really care about is the source/destination unions */
112#define NF_CT_TUPLE_U_BLANK(tuple) \
113 do { \
114 (tuple)->src.u.all = 0; \
115 (tuple)->dst.u.all = 0; \
116 memset(&(tuple)->src.u3, 0, sizeof((tuple)->src.u3)); \
117 memset(&(tuple)->dst.u3, 0, sizeof((tuple)->dst.u3)); \
118 } while (0)
119
120#ifdef __KERNEL__ 110#ifdef __KERNEL__
121 111
122static inline void nf_ct_dump_tuple_ip(const struct nf_conntrack_tuple *t) 112static inline void nf_ct_dump_tuple_ip(const struct nf_conntrack_tuple *t)
diff --git a/include/net/route.h b/include/net/route.h
index c6338802e8f1..fc836ff824cc 100644
--- a/include/net/route.h
+++ b/include/net/route.h
@@ -116,7 +116,7 @@ extern int __ip_route_output_key(struct net *, struct rtable **, const struct f
116extern int ip_route_output_key(struct net *, struct rtable **, struct flowi *flp); 116extern int ip_route_output_key(struct net *, struct rtable **, struct flowi *flp);
117extern int ip_route_output_flow(struct net *, struct rtable **rp, struct flowi *flp, struct sock *sk, int flags); 117extern int ip_route_output_flow(struct net *, struct rtable **rp, struct flowi *flp, struct sock *sk, int flags);
118extern int ip_route_input(struct sk_buff*, __be32 dst, __be32 src, u8 tos, struct net_device *devin); 118extern int ip_route_input(struct sk_buff*, __be32 dst, __be32 src, u8 tos, struct net_device *devin);
119extern unsigned short ip_rt_frag_needed(struct net *net, struct iphdr *iph, unsigned short new_mtu); 119extern unsigned short ip_rt_frag_needed(struct net *net, struct iphdr *iph, unsigned short new_mtu, struct net_device *dev);
120extern void ip_rt_send_redirect(struct sk_buff *skb); 120extern void ip_rt_send_redirect(struct sk_buff *skb);
121 121
122extern unsigned inet_addr_type(struct net *net, __be32 addr); 122extern unsigned inet_addr_type(struct net *net, __be32 addr);
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
index 1f74bcd603fe..32742c4563de 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -30,13 +30,6 @@
30#endif 30#endif
31 31
32/* 32/*
33 * SCSI command lengths
34 */
35
36extern const unsigned char scsi_command_size[8];
37#define COMMAND_SIZE(opcode) scsi_command_size[((opcode) >> 5) & 7]
38
39/*
40 * Special value for scanning to specify scanning or rescanning of all 33 * Special value for scanning to specify scanning or rescanning of all
41 * possible channels, (target) ids, or luns on a given shost. 34 * possible channels, (target) ids, or luns on a given shost.
42 */ 35 */
@@ -109,6 +102,7 @@ extern const unsigned char scsi_command_size[8];
109#define MODE_SENSE_10 0x5a 102#define MODE_SENSE_10 0x5a
110#define PERSISTENT_RESERVE_IN 0x5e 103#define PERSISTENT_RESERVE_IN 0x5e
111#define PERSISTENT_RESERVE_OUT 0x5f 104#define PERSISTENT_RESERVE_OUT 0x5f
105#define VARIABLE_LENGTH_CMD 0x7f
112#define REPORT_LUNS 0xa0 106#define REPORT_LUNS 0xa0
113#define MAINTENANCE_IN 0xa3 107#define MAINTENANCE_IN 0xa3
114#define MOVE_MEDIUM 0xa5 108#define MOVE_MEDIUM 0xa5
@@ -136,6 +130,38 @@ extern const unsigned char scsi_command_size[8];
136#define ATA_12 0xa1 /* 12-byte pass-thru */ 130#define ATA_12 0xa1 /* 12-byte pass-thru */
137 131
138/* 132/*
133 * SCSI command lengths
134 */
135
136#define SCSI_MAX_VARLEN_CDB_SIZE 260
137
138/* defined in T10 SCSI Primary Commands-2 (SPC2) */
139struct scsi_varlen_cdb_hdr {
140 u8 opcode; /* opcode always == VARIABLE_LENGTH_CMD */
141 u8 control;
142 u8 misc[5];
143 u8 additional_cdb_length; /* total cdb length - 8 */
144 __be16 service_action;
145 /* service specific data follows */
146};
147
148static inline unsigned
149scsi_varlen_cdb_length(const void *hdr)
150{
151 return ((struct scsi_varlen_cdb_hdr *)hdr)->additional_cdb_length + 8;
152}
153
154extern const unsigned char scsi_command_size_tbl[8];
155#define COMMAND_SIZE(opcode) scsi_command_size_tbl[((opcode) >> 5) & 7]
156
157static inline unsigned
158scsi_command_size(const unsigned char *cmnd)
159{
160 return (cmnd[0] == VARIABLE_LENGTH_CMD) ?
161 scsi_varlen_cdb_length(cmnd) : COMMAND_SIZE(cmnd[0]);
162}
163
164/*
139 * SCSI Architecture Model (SAM) Status codes. Taken from SAM-3 draft 165 * SCSI Architecture Model (SAM) Status codes. Taken from SAM-3 draft
140 * T10/1561-D Revision 4 Draft dated 7th November 2002. 166 * T10/1561-D Revision 4 Draft dated 7th November 2002.
141 */ 167 */
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index 8d20e60a94b7..3e46dfae8194 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -7,10 +7,28 @@
7#include <linux/types.h> 7#include <linux/types.h>
8#include <linux/timer.h> 8#include <linux/timer.h>
9#include <linux/scatterlist.h> 9#include <linux/scatterlist.h>
10#include <linux/blkdev.h>
10 11
11struct Scsi_Host; 12struct Scsi_Host;
12struct scsi_device; 13struct scsi_device;
13 14
15/*
16 * MAX_COMMAND_SIZE is:
17 * The longest fixed-length SCSI CDB as per the SCSI standard.
18 * fixed-length means: commands that their size can be determined
19 * by their opcode and the CDB does not carry a length specifier, (unlike
20 * the VARIABLE_LENGTH_CMD(0x7f) command). This is actually not exactly
21 * true and the SCSI standard also defines extended commands and
22 * vendor specific commands that can be bigger than 16 bytes. The kernel
23 * will support these using the same infrastructure used for VARLEN CDB's.
24 * So in effect MAX_COMMAND_SIZE means the maximum size command scsi-ml
25 * supports without specifying a cmd_len by ULD's
26 */
27#define MAX_COMMAND_SIZE 16
28#if (MAX_COMMAND_SIZE > BLK_MAX_CDB)
29# error MAX_COMMAND_SIZE can not be bigger than BLK_MAX_CDB
30#endif
31
14struct scsi_data_buffer { 32struct scsi_data_buffer {
15 struct sg_table table; 33 struct sg_table table;
16 unsigned length; 34 unsigned length;
@@ -60,12 +78,11 @@ struct scsi_cmnd {
60 int allowed; 78 int allowed;
61 int timeout_per_command; 79 int timeout_per_command;
62 80
63 unsigned char cmd_len; 81 unsigned short cmd_len;
64 enum dma_data_direction sc_data_direction; 82 enum dma_data_direction sc_data_direction;
65 83
66 /* These elements define the operation we are about to perform */ 84 /* These elements define the operation we are about to perform */
67#define MAX_COMMAND_SIZE 16 85 unsigned char *cmnd;
68 unsigned char cmnd[MAX_COMMAND_SIZE];
69 86
70 struct timer_list eh_timeout; /* Used to time out the command. */ 87 struct timer_list eh_timeout; /* Used to time out the command. */
71 88
diff --git a/include/scsi/scsi_eh.h b/include/scsi/scsi_eh.h
index d3a133b4a072..2a9add21267d 100644
--- a/include/scsi/scsi_eh.h
+++ b/include/scsi/scsi_eh.h
@@ -75,11 +75,11 @@ struct scsi_eh_save {
75 int result; 75 int result;
76 enum dma_data_direction data_direction; 76 enum dma_data_direction data_direction;
77 unsigned char cmd_len; 77 unsigned char cmd_len;
78 unsigned char cmnd[MAX_COMMAND_SIZE]; 78 unsigned char *cmnd;
79 struct scsi_data_buffer sdb; 79 struct scsi_data_buffer sdb;
80 struct request *next_rq; 80 struct request *next_rq;
81
82 /* new command support */ 81 /* new command support */
82 unsigned char eh_cmnd[BLK_MAX_CDB];
83 struct scatterlist sense_sgl; 83 struct scatterlist sense_sgl;
84}; 84};
85 85
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
index d967d6dc7a28..1834fdfe82a7 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -573,13 +573,11 @@ struct Scsi_Host {
573 /* 573 /*
574 * The maximum length of SCSI commands that this host can accept. 574 * The maximum length of SCSI commands that this host can accept.
575 * Probably 12 for most host adapters, but could be 16 for others. 575 * Probably 12 for most host adapters, but could be 16 for others.
576 * or 260 if the driver supports variable length cdbs.
576 * For drivers that don't set this field, a value of 12 is 577 * For drivers that don't set this field, a value of 12 is
577 * assumed. I am leaving this as a number rather than a bit 578 * assumed.
578 * because you never know what subsequent SCSI standards might do
579 * (i.e. could there be a 20 byte or a 24-byte command a few years
580 * down the road?).
581 */ 579 */
582 unsigned char max_cmd_len; 580 unsigned short max_cmd_len;
583 581
584 int this_id; 582 int this_id;
585 int can_queue; 583 int can_queue;
diff --git a/init/Kconfig b/init/Kconfig
index 3e7b257fc05f..4c33316743f5 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -316,9 +316,16 @@ config CPUSETS
316 316
317 Say N if unsure. 317 Say N if unsure.
318 318
319#
320# Architectures with an unreliable sched_clock() should select this:
321#
322config HAVE_UNSTABLE_SCHED_CLOCK
323 bool
324
319config GROUP_SCHED 325config GROUP_SCHED
320 bool "Group CPU scheduler" 326 bool "Group CPU scheduler"
321 default y 327 depends on EXPERIMENTAL
328 default n
322 help 329 help
323 This feature lets CPU scheduler recognize task groups and control CPU 330 This feature lets CPU scheduler recognize task groups and control CPU
324 bandwidth allocation to such task groups. 331 bandwidth allocation to such task groups.
@@ -326,7 +333,7 @@ config GROUP_SCHED
326config FAIR_GROUP_SCHED 333config FAIR_GROUP_SCHED
327 bool "Group scheduling for SCHED_OTHER" 334 bool "Group scheduling for SCHED_OTHER"
328 depends on GROUP_SCHED 335 depends on GROUP_SCHED
329 default y 336 default GROUP_SCHED
330 337
331config RT_GROUP_SCHED 338config RT_GROUP_SCHED
332 bool "Group scheduling for SCHED_RR/FIFO" 339 bool "Group scheduling for SCHED_RR/FIFO"
@@ -720,7 +727,7 @@ config VM_EVENT_COUNTERS
720config SLUB_DEBUG 727config SLUB_DEBUG
721 default y 728 default y
722 bool "Enable SLUB debugging support" if EMBEDDED 729 bool "Enable SLUB debugging support" if EMBEDDED
723 depends on SLUB 730 depends on SLUB && SYSFS
724 help 731 help
725 SLUB has extensive debug support features. Disabling these can 732 SLUB has extensive debug support features. Disabling these can
726 result in significant savings in code size. This also disables 733 result in significant savings in code size. This also disables
@@ -825,6 +832,15 @@ menuconfig MODULES
825 832
826 If unsure, say Y. 833 If unsure, say Y.
827 834
835config MODULE_FORCE_LOAD
836 bool "Forced module loading"
837 depends on MODULES
838 default n
839 help
840 This option allows loading of modules even if that would set the
841 'F' (forced) taint, due to lack of version info. Which is
842 usually a really bad idea.
843
828config MODULE_UNLOAD 844config MODULE_UNLOAD
829 bool "Module unloading" 845 bool "Module unloading"
830 depends on MODULES 846 depends on MODULES
diff --git a/init/main.c b/init/main.c
index 624266b524d4..ddada7acf363 100644
--- a/init/main.c
+++ b/init/main.c
@@ -52,6 +52,7 @@
52#include <linux/unwind.h> 52#include <linux/unwind.h>
53#include <linux/buffer_head.h> 53#include <linux/buffer_head.h>
54#include <linux/debug_locks.h> 54#include <linux/debug_locks.h>
55#include <linux/debugobjects.h>
55#include <linux/lockdep.h> 56#include <linux/lockdep.h>
56#include <linux/pid_namespace.h> 57#include <linux/pid_namespace.h>
57#include <linux/device.h> 58#include <linux/device.h>
@@ -459,7 +460,7 @@ static void noinline __init_refok rest_init(void)
459 kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND); 460 kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND);
460 numa_default_policy(); 461 numa_default_policy();
461 pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES); 462 pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);
462 kthreadd_task = find_task_by_pid(pid); 463 kthreadd_task = find_task_by_pid_ns(pid, &init_pid_ns);
463 unlock_kernel(); 464 unlock_kernel();
464 465
465 /* 466 /*
@@ -543,6 +544,7 @@ asmlinkage void __init start_kernel(void)
543 */ 544 */
544 unwind_init(); 545 unwind_init();
545 lockdep_init(); 546 lockdep_init();
547 debug_objects_early_init();
546 cgroup_init_early(); 548 cgroup_init_early();
547 549
548 local_irq_disable(); 550 local_irq_disable();
@@ -600,6 +602,7 @@ asmlinkage void __init start_kernel(void)
600 softirq_init(); 602 softirq_init();
601 timekeeping_init(); 603 timekeeping_init();
602 time_init(); 604 time_init();
605 sched_clock_init();
603 profile_init(); 606 profile_init();
604 if (!irqs_disabled()) 607 if (!irqs_disabled())
605 printk("start_kernel(): bug: interrupts were enabled early\n"); 608 printk("start_kernel(): bug: interrupts were enabled early\n");
@@ -638,6 +641,7 @@ asmlinkage void __init start_kernel(void)
638 enable_debug_pagealloc(); 641 enable_debug_pagealloc();
639 cpu_hotplug_init(); 642 cpu_hotplug_init();
640 kmem_cache_init(); 643 kmem_cache_init();
644 debug_objects_mem_init();
641 idr_init_cache(); 645 idr_init_cache();
642 setup_per_cpu_pageset(); 646 setup_per_cpu_pageset();
643 numa_policy_init(); 647 numa_policy_init();
@@ -802,6 +806,8 @@ static int noinline init_post(void)
802 (void) sys_dup(0); 806 (void) sys_dup(0);
803 (void) sys_dup(0); 807 (void) sys_dup(0);
804 808
809 current->signal->flags |= SIGNAL_UNKILLABLE;
810
805 if (ramdisk_execute_command) { 811 if (ramdisk_execute_command) {
806 run_init_process(ramdisk_execute_command); 812 run_init_process(ramdisk_execute_command);
807 printk(KERN_WARNING "Failed to execute %s\n", 813 printk(KERN_WARNING "Failed to execute %s\n",
diff --git a/ipc/mqueue.c b/ipc/mqueue.c
index 94fd3b08fb77..b3b69fd51330 100644
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -673,7 +673,7 @@ asmlinkage long sys_mq_open(const char __user *u_name, int oflag, mode_t mode,
673 if (IS_ERR(name = getname(u_name))) 673 if (IS_ERR(name = getname(u_name)))
674 return PTR_ERR(name); 674 return PTR_ERR(name);
675 675
676 fd = get_unused_fd(); 676 fd = get_unused_fd_flags(O_CLOEXEC);
677 if (fd < 0) 677 if (fd < 0)
678 goto out_putname; 678 goto out_putname;
679 679
@@ -709,7 +709,6 @@ asmlinkage long sys_mq_open(const char __user *u_name, int oflag, mode_t mode,
709 goto out_putfd; 709 goto out_putfd;
710 } 710 }
711 711
712 set_close_on_exec(fd, 1);
713 fd_install(fd, filp); 712 fd_install(fd, filp);
714 goto out_upsem; 713 goto out_upsem;
715 714
diff --git a/kernel/Makefile b/kernel/Makefile
index 188c43223f52..1c9938addb9d 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -9,7 +9,7 @@ obj-y = sched.o fork.o exec_domain.o panic.o printk.o profile.o \
9 rcupdate.o extable.o params.o posix-timers.o \ 9 rcupdate.o extable.o params.o posix-timers.o \
10 kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \ 10 kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
11 hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \ 11 hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \
12 notifier.o ksysfs.o pm_qos_params.o 12 notifier.o ksysfs.o pm_qos_params.o sched_clock.o
13 13
14obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o 14obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
15obj-$(CONFIG_STACKTRACE) += stacktrace.o 15obj-$(CONFIG_STACKTRACE) += stacktrace.o
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index b9d467d83fc1..fbc6fc8949b4 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -575,7 +575,7 @@ static struct inode_operations cgroup_dir_inode_operations;
575static struct file_operations proc_cgroupstats_operations; 575static struct file_operations proc_cgroupstats_operations;
576 576
577static struct backing_dev_info cgroup_backing_dev_info = { 577static struct backing_dev_info cgroup_backing_dev_info = {
578 .capabilities = BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_WRITEBACK, 578 .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK,
579}; 579};
580 580
581static struct inode *cgroup_new_inode(mode_t mode, struct super_block *sb) 581static struct inode *cgroup_new_inode(mode_t mode, struct super_block *sb)
diff --git a/kernel/compat.c b/kernel/compat.c
index e1ef04870c2a..32c254a8ab9a 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -898,7 +898,7 @@ asmlinkage long compat_sys_rt_sigsuspend(compat_sigset_t __user *unewset, compat
898 898
899 current->state = TASK_INTERRUPTIBLE; 899 current->state = TASK_INTERRUPTIBLE;
900 schedule(); 900 schedule();
901 set_thread_flag(TIF_RESTORE_SIGMASK); 901 set_restore_sigmask();
902 return -ERESTARTNOHAND; 902 return -ERESTARTNOHAND;
903} 903}
904#endif /* __ARCH_WANT_COMPAT_SYS_RT_SIGSUSPEND */ 904#endif /* __ARCH_WANT_COMPAT_SYS_RT_SIGSUSPEND */
@@ -955,7 +955,8 @@ asmlinkage long compat_sys_adjtimex(struct compat_timex __user *utp)
955 __put_user(txc.jitcnt, &utp->jitcnt) || 955 __put_user(txc.jitcnt, &utp->jitcnt) ||
956 __put_user(txc.calcnt, &utp->calcnt) || 956 __put_user(txc.calcnt, &utp->calcnt) ||
957 __put_user(txc.errcnt, &utp->errcnt) || 957 __put_user(txc.errcnt, &utp->errcnt) ||
958 __put_user(txc.stbcnt, &utp->stbcnt)) 958 __put_user(txc.stbcnt, &utp->stbcnt) ||
959 __put_user(txc.tai, &utp->tai))
959 ret = -EFAULT; 960 ret = -EFAULT;
960 961
961 return ret; 962 return ret;
@@ -1080,4 +1081,3 @@ compat_sys_sysinfo(struct compat_sysinfo __user *info)
1080 1081
1081 return 0; 1082 return 0;
1082} 1083}
1083
diff --git a/kernel/cpu.c b/kernel/cpu.c
index a98f6ab16ecd..c77bc3a1c722 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -215,7 +215,7 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
215 __raw_notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED | mod, 215 __raw_notifier_call_chain(&cpu_chain, CPU_DOWN_FAILED | mod,
216 hcpu, nr_calls, NULL); 216 hcpu, nr_calls, NULL);
217 printk("%s: attempt to take down CPU %u failed\n", 217 printk("%s: attempt to take down CPU %u failed\n",
218 __FUNCTION__, cpu); 218 __func__, cpu);
219 err = -EINVAL; 219 err = -EINVAL;
220 goto out_release; 220 goto out_release;
221 } 221 }
@@ -295,7 +295,7 @@ static int __cpuinit _cpu_up(unsigned int cpu, int tasks_frozen)
295 if (ret == NOTIFY_BAD) { 295 if (ret == NOTIFY_BAD) {
296 nr_calls--; 296 nr_calls--;
297 printk("%s: attempt to bring up CPU %u failed\n", 297 printk("%s: attempt to bring up CPU %u failed\n",
298 __FUNCTION__, cpu); 298 __func__, cpu);
299 ret = -EINVAL; 299 ret = -EINVAL;
300 goto out_notify; 300 goto out_notify;
301 } 301 }
diff --git a/kernel/exit.c b/kernel/exit.c
index ae0f2c4e452b..1510f78a0ffa 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -19,6 +19,7 @@
19#include <linux/acct.h> 19#include <linux/acct.h>
20#include <linux/tsacct_kern.h> 20#include <linux/tsacct_kern.h>
21#include <linux/file.h> 21#include <linux/file.h>
22#include <linux/fdtable.h>
22#include <linux/binfmts.h> 23#include <linux/binfmts.h>
23#include <linux/nsproxy.h> 24#include <linux/nsproxy.h>
24#include <linux/pid_namespace.h> 25#include <linux/pid_namespace.h>
@@ -52,6 +53,11 @@
52 53
53static void exit_mm(struct task_struct * tsk); 54static void exit_mm(struct task_struct * tsk);
54 55
56static inline int task_detached(struct task_struct *p)
57{
58 return p->exit_signal == -1;
59}
60
55static void __unhash_process(struct task_struct *p) 61static void __unhash_process(struct task_struct *p)
56{ 62{
57 nr_threads--; 63 nr_threads--;
@@ -160,7 +166,7 @@ repeat:
160 zap_leader = 0; 166 zap_leader = 0;
161 leader = p->group_leader; 167 leader = p->group_leader;
162 if (leader != p && thread_group_empty(leader) && leader->exit_state == EXIT_ZOMBIE) { 168 if (leader != p && thread_group_empty(leader) && leader->exit_state == EXIT_ZOMBIE) {
163 BUG_ON(leader->exit_signal == -1); 169 BUG_ON(task_detached(leader));
164 do_notify_parent(leader, leader->exit_signal); 170 do_notify_parent(leader, leader->exit_signal);
165 /* 171 /*
166 * If we were the last child thread and the leader has 172 * If we were the last child thread and the leader has
@@ -170,7 +176,7 @@ repeat:
170 * do_notify_parent() will have marked it self-reaping in 176 * do_notify_parent() will have marked it self-reaping in
171 * that case. 177 * that case.
172 */ 178 */
173 zap_leader = (leader->exit_signal == -1); 179 zap_leader = task_detached(leader);
174 } 180 }
175 181
176 write_unlock_irq(&tasklist_lock); 182 write_unlock_irq(&tasklist_lock);
@@ -329,13 +335,11 @@ void __set_special_pids(struct pid *pid)
329 pid_t nr = pid_nr(pid); 335 pid_t nr = pid_nr(pid);
330 336
331 if (task_session(curr) != pid) { 337 if (task_session(curr) != pid) {
332 detach_pid(curr, PIDTYPE_SID); 338 change_pid(curr, PIDTYPE_SID, pid);
333 attach_pid(curr, PIDTYPE_SID, pid);
334 set_task_session(curr, nr); 339 set_task_session(curr, nr);
335 } 340 }
336 if (task_pgrp(curr) != pid) { 341 if (task_pgrp(curr) != pid) {
337 detach_pid(curr, PIDTYPE_PGID); 342 change_pid(curr, PIDTYPE_PGID, pid);
338 attach_pid(curr, PIDTYPE_PGID, pid);
339 set_task_pgrp(curr, nr); 343 set_task_pgrp(curr, nr);
340 } 344 }
341} 345}
@@ -693,7 +697,7 @@ reparent_thread(struct task_struct *p, struct task_struct *father, int traced)
693 if (unlikely(traced)) { 697 if (unlikely(traced)) {
694 /* Preserve ptrace links if someone else is tracing this child. */ 698 /* Preserve ptrace links if someone else is tracing this child. */
695 list_del_init(&p->ptrace_list); 699 list_del_init(&p->ptrace_list);
696 if (p->parent != p->real_parent) 700 if (ptrace_reparented(p))
697 list_add(&p->ptrace_list, &p->real_parent->ptrace_children); 701 list_add(&p->ptrace_list, &p->real_parent->ptrace_children);
698 } else { 702 } else {
699 /* If this child is being traced, then we're the one tracing it 703 /* If this child is being traced, then we're the one tracing it
@@ -717,18 +721,18 @@ reparent_thread(struct task_struct *p, struct task_struct *father, int traced)
717 /* If this is a threaded reparent there is no need to 721 /* If this is a threaded reparent there is no need to
718 * notify anyone anything has happened. 722 * notify anyone anything has happened.
719 */ 723 */
720 if (p->real_parent->group_leader == father->group_leader) 724 if (same_thread_group(p->real_parent, father))
721 return; 725 return;
722 726
723 /* We don't want people slaying init. */ 727 /* We don't want people slaying init. */
724 if (p->exit_signal != -1) 728 if (!task_detached(p))
725 p->exit_signal = SIGCHLD; 729 p->exit_signal = SIGCHLD;
726 730
727 /* If we'd notified the old parent about this child's death, 731 /* If we'd notified the old parent about this child's death,
728 * also notify the new parent. 732 * also notify the new parent.
729 */ 733 */
730 if (!traced && p->exit_state == EXIT_ZOMBIE && 734 if (!traced && p->exit_state == EXIT_ZOMBIE &&
731 p->exit_signal != -1 && thread_group_empty(p)) 735 !task_detached(p) && thread_group_empty(p))
732 do_notify_parent(p, p->exit_signal); 736 do_notify_parent(p, p->exit_signal);
733 737
734 kill_orphaned_pgrp(p, father); 738 kill_orphaned_pgrp(p, father);
@@ -781,18 +785,18 @@ static void forget_original_parent(struct task_struct *father)
781 } else { 785 } else {
782 /* reparent ptraced task to its real parent */ 786 /* reparent ptraced task to its real parent */
783 __ptrace_unlink (p); 787 __ptrace_unlink (p);
784 if (p->exit_state == EXIT_ZOMBIE && p->exit_signal != -1 && 788 if (p->exit_state == EXIT_ZOMBIE && !task_detached(p) &&
785 thread_group_empty(p)) 789 thread_group_empty(p))
786 do_notify_parent(p, p->exit_signal); 790 do_notify_parent(p, p->exit_signal);
787 } 791 }
788 792
789 /* 793 /*
790 * if the ptraced child is a zombie with exit_signal == -1 794 * if the ptraced child is a detached zombie we must collect
791 * we must collect it before we exit, or it will remain 795 * it before we exit, or it will remain zombie forever since
792 * zombie forever since we prevented it from self-reap itself 796 * we prevented it from self-reap itself while it was being
793 * while it was being traced by us, to be able to see it in wait4. 797 * traced by us, to be able to see it in wait4.
794 */ 798 */
795 if (unlikely(ptrace && p->exit_state == EXIT_ZOMBIE && p->exit_signal == -1)) 799 if (unlikely(ptrace && p->exit_state == EXIT_ZOMBIE && task_detached(p)))
796 list_add(&p->ptrace_list, &ptrace_dead); 800 list_add(&p->ptrace_list, &ptrace_dead);
797 } 801 }
798 802
@@ -849,29 +853,30 @@ static void exit_notify(struct task_struct *tsk, int group_dead)
849 * we have changed execution domain as these two values started 853 * we have changed execution domain as these two values started
850 * the same after a fork. 854 * the same after a fork.
851 */ 855 */
852 if (tsk->exit_signal != SIGCHLD && tsk->exit_signal != -1 && 856 if (tsk->exit_signal != SIGCHLD && !task_detached(tsk) &&
853 (tsk->parent_exec_id != tsk->real_parent->self_exec_id || 857 (tsk->parent_exec_id != tsk->real_parent->self_exec_id ||
854 tsk->self_exec_id != tsk->parent_exec_id) 858 tsk->self_exec_id != tsk->parent_exec_id) &&
855 && !capable(CAP_KILL)) 859 !capable(CAP_KILL))
856 tsk->exit_signal = SIGCHLD; 860 tsk->exit_signal = SIGCHLD;
857 861
858
859 /* If something other than our normal parent is ptracing us, then 862 /* If something other than our normal parent is ptracing us, then
860 * send it a SIGCHLD instead of honoring exit_signal. exit_signal 863 * send it a SIGCHLD instead of honoring exit_signal. exit_signal
861 * only has special meaning to our real parent. 864 * only has special meaning to our real parent.
862 */ 865 */
863 if (tsk->exit_signal != -1 && thread_group_empty(tsk)) { 866 if (!task_detached(tsk) && thread_group_empty(tsk)) {
864 int signal = tsk->parent == tsk->real_parent ? tsk->exit_signal : SIGCHLD; 867 int signal = ptrace_reparented(tsk) ?
868 SIGCHLD : tsk->exit_signal;
865 do_notify_parent(tsk, signal); 869 do_notify_parent(tsk, signal);
866 } else if (tsk->ptrace) { 870 } else if (tsk->ptrace) {
867 do_notify_parent(tsk, SIGCHLD); 871 do_notify_parent(tsk, SIGCHLD);
868 } 872 }
869 873
870 state = EXIT_ZOMBIE; 874 state = EXIT_ZOMBIE;
871 if (tsk->exit_signal == -1 && likely(!tsk->ptrace)) 875 if (task_detached(tsk) && likely(!tsk->ptrace))
872 state = EXIT_DEAD; 876 state = EXIT_DEAD;
873 tsk->exit_state = state; 877 tsk->exit_state = state;
874 878
879 /* mt-exec, de_thread() is waiting for us */
875 if (thread_group_leader(tsk) && 880 if (thread_group_leader(tsk) &&
876 tsk->signal->notify_count < 0 && 881 tsk->signal->notify_count < 0 &&
877 tsk->signal->group_exit_task) 882 tsk->signal->group_exit_task)
@@ -1115,12 +1120,13 @@ asmlinkage long sys_exit(int error_code)
1115NORET_TYPE void 1120NORET_TYPE void
1116do_group_exit(int exit_code) 1121do_group_exit(int exit_code)
1117{ 1122{
1123 struct signal_struct *sig = current->signal;
1124
1118 BUG_ON(exit_code & 0x80); /* core dumps don't get here */ 1125 BUG_ON(exit_code & 0x80); /* core dumps don't get here */
1119 1126
1120 if (current->signal->flags & SIGNAL_GROUP_EXIT) 1127 if (signal_group_exit(sig))
1121 exit_code = current->signal->group_exit_code; 1128 exit_code = sig->group_exit_code;
1122 else if (!thread_group_empty(current)) { 1129 else if (!thread_group_empty(current)) {
1123 struct signal_struct *const sig = current->signal;
1124 struct sighand_struct *const sighand = current->sighand; 1130 struct sighand_struct *const sighand = current->sighand;
1125 spin_lock_irq(&sighand->siglock); 1131 spin_lock_irq(&sighand->siglock);
1126 if (signal_group_exit(sig)) 1132 if (signal_group_exit(sig))
@@ -1172,7 +1178,7 @@ static int eligible_child(enum pid_type type, struct pid *pid, int options,
1172 * Do not consider detached threads that are 1178 * Do not consider detached threads that are
1173 * not ptraced: 1179 * not ptraced:
1174 */ 1180 */
1175 if (p->exit_signal == -1 && !p->ptrace) 1181 if (task_detached(p) && !p->ptrace)
1176 return 0; 1182 return 0;
1177 1183
1178 /* Wait for all children (clone and not) if __WALL is set; 1184 /* Wait for all children (clone and not) if __WALL is set;
@@ -1262,8 +1268,7 @@ static int wait_task_zombie(struct task_struct *p, int noreap,
1262 return 0; 1268 return 0;
1263 } 1269 }
1264 1270
1265 /* traced means p->ptrace, but not vice versa */ 1271 traced = ptrace_reparented(p);
1266 traced = (p->real_parent != p->parent);
1267 1272
1268 if (likely(!traced)) { 1273 if (likely(!traced)) {
1269 struct signal_struct *psig; 1274 struct signal_struct *psig;
@@ -1364,9 +1369,9 @@ static int wait_task_zombie(struct task_struct *p, int noreap,
1364 * If it's still not detached after that, don't release 1369 * If it's still not detached after that, don't release
1365 * it now. 1370 * it now.
1366 */ 1371 */
1367 if (p->exit_signal != -1) { 1372 if (!task_detached(p)) {
1368 do_notify_parent(p, p->exit_signal); 1373 do_notify_parent(p, p->exit_signal);
1369 if (p->exit_signal != -1) { 1374 if (!task_detached(p)) {
1370 p->exit_state = EXIT_ZOMBIE; 1375 p->exit_state = EXIT_ZOMBIE;
1371 p = NULL; 1376 p = NULL;
1372 } 1377 }
diff --git a/kernel/fork.c b/kernel/fork.c
index 068ffe007529..933e60ebccae 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -22,6 +22,7 @@
22#include <linux/mempolicy.h> 22#include <linux/mempolicy.h>
23#include <linux/sem.h> 23#include <linux/sem.h>
24#include <linux/file.h> 24#include <linux/file.h>
25#include <linux/fdtable.h>
25#include <linux/key.h> 26#include <linux/key.h>
26#include <linux/binfmts.h> 27#include <linux/binfmts.h>
27#include <linux/mman.h> 28#include <linux/mman.h>
@@ -892,7 +893,7 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk)
892 sig->group_exit_code = 0; 893 sig->group_exit_code = 0;
893 sig->group_exit_task = NULL; 894 sig->group_exit_task = NULL;
894 sig->group_stop_count = 0; 895 sig->group_stop_count = 0;
895 sig->curr_target = NULL; 896 sig->curr_target = tsk;
896 init_sigpending(&sig->shared_pending); 897 init_sigpending(&sig->shared_pending);
897 INIT_LIST_HEAD(&sig->posix_timers); 898 INIT_LIST_HEAD(&sig->posix_timers);
898 899
diff --git a/kernel/futex.c b/kernel/futex.c
index e43945e995f5..449def8074fe 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -104,10 +104,6 @@ struct futex_q {
104 /* Key which the futex is hashed on: */ 104 /* Key which the futex is hashed on: */
105 union futex_key key; 105 union futex_key key;
106 106
107 /* For fd, sigio sent using these: */
108 int fd;
109 struct file *filp;
110
111 /* Optional priority inheritance state: */ 107 /* Optional priority inheritance state: */
112 struct futex_pi_state *pi_state; 108 struct futex_pi_state *pi_state;
113 struct task_struct *task; 109 struct task_struct *task;
@@ -126,9 +122,6 @@ struct futex_hash_bucket {
126 122
127static struct futex_hash_bucket futex_queues[1<<FUTEX_HASHBITS]; 123static struct futex_hash_bucket futex_queues[1<<FUTEX_HASHBITS];
128 124
129/* Futex-fs vfsmount entry: */
130static struct vfsmount *futex_mnt;
131
132/* 125/*
133 * Take mm->mmap_sem, when futex is shared 126 * Take mm->mmap_sem, when futex is shared
134 */ 127 */
@@ -610,8 +603,6 @@ lookup_pi_state(u32 uval, struct futex_hash_bucket *hb,
610static void wake_futex(struct futex_q *q) 603static void wake_futex(struct futex_q *q)
611{ 604{
612 plist_del(&q->list, &q->list.plist); 605 plist_del(&q->list, &q->list.plist);
613 if (q->filp)
614 send_sigio(&q->filp->f_owner, q->fd, POLL_IN);
615 /* 606 /*
616 * The lock in wake_up_all() is a crucial memory barrier after the 607 * The lock in wake_up_all() is a crucial memory barrier after the
617 * plist_del() and also before assigning to q->lock_ptr. 608 * plist_del() and also before assigning to q->lock_ptr.
@@ -988,14 +979,10 @@ out:
988} 979}
989 980
990/* The key must be already stored in q->key. */ 981/* The key must be already stored in q->key. */
991static inline struct futex_hash_bucket * 982static inline struct futex_hash_bucket *queue_lock(struct futex_q *q)
992queue_lock(struct futex_q *q, int fd, struct file *filp)
993{ 983{
994 struct futex_hash_bucket *hb; 984 struct futex_hash_bucket *hb;
995 985
996 q->fd = fd;
997 q->filp = filp;
998
999 init_waitqueue_head(&q->waiters); 986 init_waitqueue_head(&q->waiters);
1000 987
1001 get_futex_key_refs(&q->key); 988 get_futex_key_refs(&q->key);
@@ -1006,7 +993,7 @@ queue_lock(struct futex_q *q, int fd, struct file *filp)
1006 return hb; 993 return hb;
1007} 994}
1008 995
1009static inline void __queue_me(struct futex_q *q, struct futex_hash_bucket *hb) 996static inline void queue_me(struct futex_q *q, struct futex_hash_bucket *hb)
1010{ 997{
1011 int prio; 998 int prio;
1012 999
@@ -1041,15 +1028,6 @@ queue_unlock(struct futex_q *q, struct futex_hash_bucket *hb)
1041 * exactly once. They are called with the hashed spinlock held. 1028 * exactly once. They are called with the hashed spinlock held.
1042 */ 1029 */
1043 1030
1044/* The key must be already stored in q->key. */
1045static void queue_me(struct futex_q *q, int fd, struct file *filp)
1046{
1047 struct futex_hash_bucket *hb;
1048
1049 hb = queue_lock(q, fd, filp);
1050 __queue_me(q, hb);
1051}
1052
1053/* Return 1 if we were still queued (ie. 0 means we were woken) */ 1031/* Return 1 if we were still queued (ie. 0 means we were woken) */
1054static int unqueue_me(struct futex_q *q) 1032static int unqueue_me(struct futex_q *q)
1055{ 1033{
@@ -1194,7 +1172,7 @@ static int futex_wait(u32 __user *uaddr, struct rw_semaphore *fshared,
1194 if (unlikely(ret != 0)) 1172 if (unlikely(ret != 0))
1195 goto out_release_sem; 1173 goto out_release_sem;
1196 1174
1197 hb = queue_lock(&q, -1, NULL); 1175 hb = queue_lock(&q);
1198 1176
1199 /* 1177 /*
1200 * Access the page AFTER the futex is queued. 1178 * Access the page AFTER the futex is queued.
@@ -1238,7 +1216,7 @@ static int futex_wait(u32 __user *uaddr, struct rw_semaphore *fshared,
1238 goto out_unlock_release_sem; 1216 goto out_unlock_release_sem;
1239 1217
1240 /* Only actually queue if *uaddr contained val. */ 1218 /* Only actually queue if *uaddr contained val. */
1241 __queue_me(&q, hb); 1219 queue_me(&q, hb);
1242 1220
1243 /* 1221 /*
1244 * Now the futex is queued and we have checked the data, we 1222 * Now the futex is queued and we have checked the data, we
@@ -1266,11 +1244,13 @@ static int futex_wait(u32 __user *uaddr, struct rw_semaphore *fshared,
1266 if (!abs_time) 1244 if (!abs_time)
1267 schedule(); 1245 schedule();
1268 else { 1246 else {
1269 hrtimer_init(&t.timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); 1247 hrtimer_init_on_stack(&t.timer, CLOCK_MONOTONIC,
1248 HRTIMER_MODE_ABS);
1270 hrtimer_init_sleeper(&t, current); 1249 hrtimer_init_sleeper(&t, current);
1271 t.timer.expires = *abs_time; 1250 t.timer.expires = *abs_time;
1272 1251
1273 hrtimer_start(&t.timer, t.timer.expires, HRTIMER_MODE_ABS); 1252 hrtimer_start(&t.timer, t.timer.expires,
1253 HRTIMER_MODE_ABS);
1274 if (!hrtimer_active(&t.timer)) 1254 if (!hrtimer_active(&t.timer))
1275 t.task = NULL; 1255 t.task = NULL;
1276 1256
@@ -1286,6 +1266,8 @@ static int futex_wait(u32 __user *uaddr, struct rw_semaphore *fshared,
1286 1266
1287 /* Flag if a timeout occured */ 1267 /* Flag if a timeout occured */
1288 rem = (t.task == NULL); 1268 rem = (t.task == NULL);
1269
1270 destroy_hrtimer_on_stack(&t.timer);
1289 } 1271 }
1290 } 1272 }
1291 __set_current_state(TASK_RUNNING); 1273 __set_current_state(TASK_RUNNING);
@@ -1367,7 +1349,8 @@ static int futex_lock_pi(u32 __user *uaddr, struct rw_semaphore *fshared,
1367 1349
1368 if (time) { 1350 if (time) {
1369 to = &timeout; 1351 to = &timeout;
1370 hrtimer_init(&to->timer, CLOCK_REALTIME, HRTIMER_MODE_ABS); 1352 hrtimer_init_on_stack(&to->timer, CLOCK_REALTIME,
1353 HRTIMER_MODE_ABS);
1371 hrtimer_init_sleeper(to, current); 1354 hrtimer_init_sleeper(to, current);
1372 to->timer.expires = *time; 1355 to->timer.expires = *time;
1373 } 1356 }
@@ -1381,7 +1364,7 @@ static int futex_lock_pi(u32 __user *uaddr, struct rw_semaphore *fshared,
1381 goto out_release_sem; 1364 goto out_release_sem;
1382 1365
1383 retry_unlocked: 1366 retry_unlocked:
1384 hb = queue_lock(&q, -1, NULL); 1367 hb = queue_lock(&q);
1385 1368
1386 retry_locked: 1369 retry_locked:
1387 ret = lock_taken = 0; 1370 ret = lock_taken = 0;
@@ -1494,7 +1477,7 @@ static int futex_lock_pi(u32 __user *uaddr, struct rw_semaphore *fshared,
1494 /* 1477 /*
1495 * Only actually queue now that the atomic ops are done: 1478 * Only actually queue now that the atomic ops are done:
1496 */ 1479 */
1497 __queue_me(&q, hb); 1480 queue_me(&q, hb);
1498 1481
1499 /* 1482 /*
1500 * Now the futex is queued and we have checked the data, we 1483 * Now the futex is queued and we have checked the data, we
@@ -1581,6 +1564,8 @@ static int futex_lock_pi(u32 __user *uaddr, struct rw_semaphore *fshared,
1581 unqueue_me_pi(&q); 1564 unqueue_me_pi(&q);
1582 futex_unlock_mm(fshared); 1565 futex_unlock_mm(fshared);
1583 1566
1567 if (to)
1568 destroy_hrtimer_on_stack(&to->timer);
1584 return ret != -EINTR ? ret : -ERESTARTNOINTR; 1569 return ret != -EINTR ? ret : -ERESTARTNOINTR;
1585 1570
1586 out_unlock_release_sem: 1571 out_unlock_release_sem:
@@ -1588,6 +1573,8 @@ static int futex_lock_pi(u32 __user *uaddr, struct rw_semaphore *fshared,
1588 1573
1589 out_release_sem: 1574 out_release_sem:
1590 futex_unlock_mm(fshared); 1575 futex_unlock_mm(fshared);
1576 if (to)
1577 destroy_hrtimer_on_stack(&to->timer);
1591 return ret; 1578 return ret;
1592 1579
1593 uaddr_faulted: 1580 uaddr_faulted:
@@ -1615,6 +1602,8 @@ static int futex_lock_pi(u32 __user *uaddr, struct rw_semaphore *fshared,
1615 if (!ret && (uval != -EFAULT)) 1602 if (!ret && (uval != -EFAULT))
1616 goto retry; 1603 goto retry;
1617 1604
1605 if (to)
1606 destroy_hrtimer_on_stack(&to->timer);
1618 return ret; 1607 return ret;
1619} 1608}
1620 1609
@@ -1735,121 +1724,6 @@ pi_faulted:
1735 return ret; 1724 return ret;
1736} 1725}
1737 1726
1738static int futex_close(struct inode *inode, struct file *filp)
1739{
1740 struct futex_q *q = filp->private_data;
1741
1742 unqueue_me(q);
1743 kfree(q);
1744
1745 return 0;
1746}
1747
1748/* This is one-shot: once it's gone off you need a new fd */
1749static unsigned int futex_poll(struct file *filp,
1750 struct poll_table_struct *wait)
1751{
1752 struct futex_q *q = filp->private_data;
1753 int ret = 0;
1754
1755 poll_wait(filp, &q->waiters, wait);
1756
1757 /*
1758 * plist_node_empty() is safe here without any lock.
1759 * q->lock_ptr != 0 is not safe, because of ordering against wakeup.
1760 */
1761 if (plist_node_empty(&q->list))
1762 ret = POLLIN | POLLRDNORM;
1763
1764 return ret;
1765}
1766
1767static const struct file_operations futex_fops = {
1768 .release = futex_close,
1769 .poll = futex_poll,
1770};
1771
1772/*
1773 * Signal allows caller to avoid the race which would occur if they
1774 * set the sigio stuff up afterwards.
1775 */
1776static int futex_fd(u32 __user *uaddr, int signal)
1777{
1778 struct futex_q *q;
1779 struct file *filp;
1780 int ret, err;
1781 struct rw_semaphore *fshared;
1782 static unsigned long printk_interval;
1783
1784 if (printk_timed_ratelimit(&printk_interval, 60 * 60 * 1000)) {
1785 printk(KERN_WARNING "Process `%s' used FUTEX_FD, which "
1786 "will be removed from the kernel in June 2007\n",
1787 current->comm);
1788 }
1789
1790 ret = -EINVAL;
1791 if (!valid_signal(signal))
1792 goto out;
1793
1794 ret = get_unused_fd();
1795 if (ret < 0)
1796 goto out;
1797 filp = get_empty_filp();
1798 if (!filp) {
1799 put_unused_fd(ret);
1800 ret = -ENFILE;
1801 goto out;
1802 }
1803 filp->f_op = &futex_fops;
1804 filp->f_path.mnt = mntget(futex_mnt);
1805 filp->f_path.dentry = dget(futex_mnt->mnt_root);
1806 filp->f_mapping = filp->f_path.dentry->d_inode->i_mapping;
1807
1808 if (signal) {
1809 err = __f_setown(filp, task_pid(current), PIDTYPE_PID, 1);
1810 if (err < 0) {
1811 goto error;
1812 }
1813 filp->f_owner.signum = signal;
1814 }
1815
1816 q = kmalloc(sizeof(*q), GFP_KERNEL);
1817 if (!q) {
1818 err = -ENOMEM;
1819 goto error;
1820 }
1821 q->pi_state = NULL;
1822
1823 fshared = &current->mm->mmap_sem;
1824 down_read(fshared);
1825 err = get_futex_key(uaddr, fshared, &q->key);
1826
1827 if (unlikely(err != 0)) {
1828 up_read(fshared);
1829 kfree(q);
1830 goto error;
1831 }
1832
1833 /*
1834 * queue_me() must be called before releasing mmap_sem, because
1835 * key->shared.inode needs to be referenced while holding it.
1836 */
1837 filp->private_data = q;
1838
1839 queue_me(q, ret, filp);
1840 up_read(fshared);
1841
1842 /* Now we map fd to filp, so userspace can access it */
1843 fd_install(ret, filp);
1844out:
1845 return ret;
1846error:
1847 put_unused_fd(ret);
1848 put_filp(filp);
1849 ret = err;
1850 goto out;
1851}
1852
1853/* 1727/*
1854 * Support for robust futexes: the kernel cleans up held futexes at 1728 * Support for robust futexes: the kernel cleans up held futexes at
1855 * thread exit time. 1729 * thread exit time.
@@ -2081,10 +1955,6 @@ long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
2081 case FUTEX_WAKE_BITSET: 1955 case FUTEX_WAKE_BITSET:
2082 ret = futex_wake(uaddr, fshared, val, val3); 1956 ret = futex_wake(uaddr, fshared, val, val3);
2083 break; 1957 break;
2084 case FUTEX_FD:
2085 /* non-zero val means F_SETOWN(getpid()) & F_SETSIG(val) */
2086 ret = futex_fd(uaddr, val);
2087 break;
2088 case FUTEX_REQUEUE: 1958 case FUTEX_REQUEUE:
2089 ret = futex_requeue(uaddr, fshared, uaddr2, val, val2, NULL); 1959 ret = futex_requeue(uaddr, fshared, uaddr2, val, val2, NULL);
2090 break; 1960 break;
@@ -2145,19 +2015,6 @@ asmlinkage long sys_futex(u32 __user *uaddr, int op, u32 val,
2145 return do_futex(uaddr, op, val, tp, uaddr2, val2, val3); 2015 return do_futex(uaddr, op, val, tp, uaddr2, val2, val3);
2146} 2016}
2147 2017
2148static int futexfs_get_sb(struct file_system_type *fs_type,
2149 int flags, const char *dev_name, void *data,
2150 struct vfsmount *mnt)
2151{
2152 return get_sb_pseudo(fs_type, "futex", NULL, FUTEXFS_SUPER_MAGIC, mnt);
2153}
2154
2155static struct file_system_type futex_fs_type = {
2156 .name = "futexfs",
2157 .get_sb = futexfs_get_sb,
2158 .kill_sb = kill_anon_super,
2159};
2160
2161static int __init futex_init(void) 2018static int __init futex_init(void)
2162{ 2019{
2163 u32 curval; 2020 u32 curval;
@@ -2182,16 +2039,6 @@ static int __init futex_init(void)
2182 spin_lock_init(&futex_queues[i].lock); 2039 spin_lock_init(&futex_queues[i].lock);
2183 } 2040 }
2184 2041
2185 i = register_filesystem(&futex_fs_type);
2186 if (i)
2187 return i;
2188
2189 futex_mnt = kern_mount(&futex_fs_type);
2190 if (IS_ERR(futex_mnt)) {
2191 unregister_filesystem(&futex_fs_type);
2192 return PTR_ERR(futex_mnt);
2193 }
2194
2195 return 0; 2042 return 0;
2196} 2043}
2197__initcall(futex_init); 2044__initcall(futex_init);
diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
index dea4c9124ac8..421be5fe5cc7 100644
--- a/kernel/hrtimer.c
+++ b/kernel/hrtimer.c
@@ -43,6 +43,7 @@
43#include <linux/tick.h> 43#include <linux/tick.h>
44#include <linux/seq_file.h> 44#include <linux/seq_file.h>
45#include <linux/err.h> 45#include <linux/err.h>
46#include <linux/debugobjects.h>
46 47
47#include <asm/uaccess.h> 48#include <asm/uaccess.h>
48 49
@@ -153,15 +154,6 @@ static void hrtimer_get_softirq_time(struct hrtimer_cpu_base *base)
153} 154}
154 155
155/* 156/*
156 * Helper function to check, whether the timer is running the callback
157 * function
158 */
159static inline int hrtimer_callback_running(struct hrtimer *timer)
160{
161 return timer->state & HRTIMER_STATE_CALLBACK;
162}
163
164/*
165 * Functions and macros which are different for UP/SMP systems are kept in a 157 * Functions and macros which are different for UP/SMP systems are kept in a
166 * single place 158 * single place
167 */ 159 */
@@ -342,6 +334,115 @@ ktime_t ktime_add_safe(const ktime_t lhs, const ktime_t rhs)
342 return res; 334 return res;
343} 335}
344 336
337#ifdef CONFIG_DEBUG_OBJECTS_TIMERS
338
339static struct debug_obj_descr hrtimer_debug_descr;
340
341/*
342 * fixup_init is called when:
343 * - an active object is initialized
344 */
345static int hrtimer_fixup_init(void *addr, enum debug_obj_state state)
346{
347 struct hrtimer *timer = addr;
348
349 switch (state) {
350 case ODEBUG_STATE_ACTIVE:
351 hrtimer_cancel(timer);
352 debug_object_init(timer, &hrtimer_debug_descr);
353 return 1;
354 default:
355 return 0;
356 }
357}
358
359/*
360 * fixup_activate is called when:
361 * - an active object is activated
362 * - an unknown object is activated (might be a statically initialized object)
363 */
364static int hrtimer_fixup_activate(void *addr, enum debug_obj_state state)
365{
366 switch (state) {
367
368 case ODEBUG_STATE_NOTAVAILABLE:
369 WARN_ON_ONCE(1);
370 return 0;
371
372 case ODEBUG_STATE_ACTIVE:
373 WARN_ON(1);
374
375 default:
376 return 0;
377 }
378}
379
380/*
381 * fixup_free is called when:
382 * - an active object is freed
383 */
384static int hrtimer_fixup_free(void *addr, enum debug_obj_state state)
385{
386 struct hrtimer *timer = addr;
387
388 switch (state) {
389 case ODEBUG_STATE_ACTIVE:
390 hrtimer_cancel(timer);
391 debug_object_free(timer, &hrtimer_debug_descr);
392 return 1;
393 default:
394 return 0;
395 }
396}
397
398static struct debug_obj_descr hrtimer_debug_descr = {
399 .name = "hrtimer",
400 .fixup_init = hrtimer_fixup_init,
401 .fixup_activate = hrtimer_fixup_activate,
402 .fixup_free = hrtimer_fixup_free,
403};
404
405static inline void debug_hrtimer_init(struct hrtimer *timer)
406{
407 debug_object_init(timer, &hrtimer_debug_descr);
408}
409
410static inline void debug_hrtimer_activate(struct hrtimer *timer)
411{
412 debug_object_activate(timer, &hrtimer_debug_descr);
413}
414
415static inline void debug_hrtimer_deactivate(struct hrtimer *timer)
416{
417 debug_object_deactivate(timer, &hrtimer_debug_descr);
418}
419
420static inline void debug_hrtimer_free(struct hrtimer *timer)
421{
422 debug_object_free(timer, &hrtimer_debug_descr);
423}
424
425static void __hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
426 enum hrtimer_mode mode);
427
428void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t clock_id,
429 enum hrtimer_mode mode)
430{
431 debug_object_init_on_stack(timer, &hrtimer_debug_descr);
432 __hrtimer_init(timer, clock_id, mode);
433}
434
435void destroy_hrtimer_on_stack(struct hrtimer *timer)
436{
437 debug_object_free(timer, &hrtimer_debug_descr);
438}
439
440#else
441static inline void debug_hrtimer_init(struct hrtimer *timer) { }
442static inline void debug_hrtimer_activate(struct hrtimer *timer) { }
443static inline void debug_hrtimer_deactivate(struct hrtimer *timer) { }
444#endif
445
345/* 446/*
346 * Check, whether the timer is on the callback pending list 447 * Check, whether the timer is on the callback pending list
347 */ 448 */
@@ -567,6 +668,7 @@ static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer,
567 /* Timer is expired, act upon the callback mode */ 668 /* Timer is expired, act upon the callback mode */
568 switch(timer->cb_mode) { 669 switch(timer->cb_mode) {
569 case HRTIMER_CB_IRQSAFE_NO_RESTART: 670 case HRTIMER_CB_IRQSAFE_NO_RESTART:
671 debug_hrtimer_deactivate(timer);
570 /* 672 /*
571 * We can call the callback from here. No restart 673 * We can call the callback from here. No restart
572 * happens, so no danger of recursion 674 * happens, so no danger of recursion
@@ -581,6 +683,7 @@ static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer,
581 * the tick timer in the softirq ! The calling site 683 * the tick timer in the softirq ! The calling site
582 * takes care of this. 684 * takes care of this.
583 */ 685 */
686 debug_hrtimer_deactivate(timer);
584 return 1; 687 return 1;
585 case HRTIMER_CB_IRQSAFE: 688 case HRTIMER_CB_IRQSAFE:
586 case HRTIMER_CB_SOFTIRQ: 689 case HRTIMER_CB_SOFTIRQ:
@@ -735,6 +838,8 @@ static void enqueue_hrtimer(struct hrtimer *timer,
735 struct hrtimer *entry; 838 struct hrtimer *entry;
736 int leftmost = 1; 839 int leftmost = 1;
737 840
841 debug_hrtimer_activate(timer);
842
738 /* 843 /*
739 * Find the right place in the rbtree: 844 * Find the right place in the rbtree:
740 */ 845 */
@@ -831,6 +936,7 @@ remove_hrtimer(struct hrtimer *timer, struct hrtimer_clock_base *base)
831 * reprogramming happens in the interrupt handler. This is a 936 * reprogramming happens in the interrupt handler. This is a
832 * rare case and less expensive than a smp call. 937 * rare case and less expensive than a smp call.
833 */ 938 */
939 debug_hrtimer_deactivate(timer);
834 timer_stats_hrtimer_clear_start_info(timer); 940 timer_stats_hrtimer_clear_start_info(timer);
835 reprogram = base->cpu_base == &__get_cpu_var(hrtimer_bases); 941 reprogram = base->cpu_base == &__get_cpu_var(hrtimer_bases);
836 __remove_hrtimer(timer, base, HRTIMER_STATE_INACTIVE, 942 __remove_hrtimer(timer, base, HRTIMER_STATE_INACTIVE,
@@ -878,6 +984,7 @@ hrtimer_start(struct hrtimer *timer, ktime_t tim, const enum hrtimer_mode mode)
878 tim = ktime_add_safe(tim, base->resolution); 984 tim = ktime_add_safe(tim, base->resolution);
879#endif 985#endif
880 } 986 }
987
881 timer->expires = tim; 988 timer->expires = tim;
882 989
883 timer_stats_hrtimer_set_start_info(timer); 990 timer_stats_hrtimer_set_start_info(timer);
@@ -1011,14 +1118,8 @@ ktime_t hrtimer_get_next_event(void)
1011} 1118}
1012#endif 1119#endif
1013 1120
1014/** 1121static void __hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
1015 * hrtimer_init - initialize a timer to the given clock 1122 enum hrtimer_mode mode)
1016 * @timer: the timer to be initialized
1017 * @clock_id: the clock to be used
1018 * @mode: timer mode abs/rel
1019 */
1020void hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
1021 enum hrtimer_mode mode)
1022{ 1123{
1023 struct hrtimer_cpu_base *cpu_base; 1124 struct hrtimer_cpu_base *cpu_base;
1024 1125
@@ -1039,6 +1140,19 @@ void hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
1039 memset(timer->start_comm, 0, TASK_COMM_LEN); 1140 memset(timer->start_comm, 0, TASK_COMM_LEN);
1040#endif 1141#endif
1041} 1142}
1143
1144/**
1145 * hrtimer_init - initialize a timer to the given clock
1146 * @timer: the timer to be initialized
1147 * @clock_id: the clock to be used
1148 * @mode: timer mode abs/rel
1149 */
1150void hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
1151 enum hrtimer_mode mode)
1152{
1153 debug_hrtimer_init(timer);
1154 __hrtimer_init(timer, clock_id, mode);
1155}
1042EXPORT_SYMBOL_GPL(hrtimer_init); 1156EXPORT_SYMBOL_GPL(hrtimer_init);
1043 1157
1044/** 1158/**
@@ -1072,6 +1186,7 @@ static void run_hrtimer_pending(struct hrtimer_cpu_base *cpu_base)
1072 timer = list_entry(cpu_base->cb_pending.next, 1186 timer = list_entry(cpu_base->cb_pending.next,
1073 struct hrtimer, cb_entry); 1187 struct hrtimer, cb_entry);
1074 1188
1189 debug_hrtimer_deactivate(timer);
1075 timer_stats_account_hrtimer(timer); 1190 timer_stats_account_hrtimer(timer);
1076 1191
1077 fn = timer->function; 1192 fn = timer->function;
@@ -1120,6 +1235,7 @@ static void __run_hrtimer(struct hrtimer *timer)
1120 enum hrtimer_restart (*fn)(struct hrtimer *); 1235 enum hrtimer_restart (*fn)(struct hrtimer *);
1121 int restart; 1236 int restart;
1122 1237
1238 debug_hrtimer_deactivate(timer);
1123 __remove_hrtimer(timer, base, HRTIMER_STATE_CALLBACK, 0); 1239 __remove_hrtimer(timer, base, HRTIMER_STATE_CALLBACK, 0);
1124 timer_stats_account_hrtimer(timer); 1240 timer_stats_account_hrtimer(timer);
1125 1241
@@ -1378,22 +1494,27 @@ long __sched hrtimer_nanosleep_restart(struct restart_block *restart)
1378{ 1494{
1379 struct hrtimer_sleeper t; 1495 struct hrtimer_sleeper t;
1380 struct timespec __user *rmtp; 1496 struct timespec __user *rmtp;
1497 int ret = 0;
1381 1498
1382 hrtimer_init(&t.timer, restart->nanosleep.index, HRTIMER_MODE_ABS); 1499 hrtimer_init_on_stack(&t.timer, restart->nanosleep.index,
1500 HRTIMER_MODE_ABS);
1383 t.timer.expires.tv64 = restart->nanosleep.expires; 1501 t.timer.expires.tv64 = restart->nanosleep.expires;
1384 1502
1385 if (do_nanosleep(&t, HRTIMER_MODE_ABS)) 1503 if (do_nanosleep(&t, HRTIMER_MODE_ABS))
1386 return 0; 1504 goto out;
1387 1505
1388 rmtp = restart->nanosleep.rmtp; 1506 rmtp = restart->nanosleep.rmtp;
1389 if (rmtp) { 1507 if (rmtp) {
1390 int ret = update_rmtp(&t.timer, rmtp); 1508 ret = update_rmtp(&t.timer, rmtp);
1391 if (ret <= 0) 1509 if (ret <= 0)
1392 return ret; 1510 goto out;
1393 } 1511 }
1394 1512
1395 /* The other values in restart are already filled in */ 1513 /* The other values in restart are already filled in */
1396 return -ERESTART_RESTARTBLOCK; 1514 ret = -ERESTART_RESTARTBLOCK;
1515out:
1516 destroy_hrtimer_on_stack(&t.timer);
1517 return ret;
1397} 1518}
1398 1519
1399long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp, 1520long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
@@ -1401,20 +1522,23 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
1401{ 1522{
1402 struct restart_block *restart; 1523 struct restart_block *restart;
1403 struct hrtimer_sleeper t; 1524 struct hrtimer_sleeper t;
1525 int ret = 0;
1404 1526
1405 hrtimer_init(&t.timer, clockid, mode); 1527 hrtimer_init_on_stack(&t.timer, clockid, mode);
1406 t.timer.expires = timespec_to_ktime(*rqtp); 1528 t.timer.expires = timespec_to_ktime(*rqtp);
1407 if (do_nanosleep(&t, mode)) 1529 if (do_nanosleep(&t, mode))
1408 return 0; 1530 goto out;
1409 1531
1410 /* Absolute timers do not update the rmtp value and restart: */ 1532 /* Absolute timers do not update the rmtp value and restart: */
1411 if (mode == HRTIMER_MODE_ABS) 1533 if (mode == HRTIMER_MODE_ABS) {
1412 return -ERESTARTNOHAND; 1534 ret = -ERESTARTNOHAND;
1535 goto out;
1536 }
1413 1537
1414 if (rmtp) { 1538 if (rmtp) {
1415 int ret = update_rmtp(&t.timer, rmtp); 1539 ret = update_rmtp(&t.timer, rmtp);
1416 if (ret <= 0) 1540 if (ret <= 0)
1417 return ret; 1541 goto out;
1418 } 1542 }
1419 1543
1420 restart = &current_thread_info()->restart_block; 1544 restart = &current_thread_info()->restart_block;
@@ -1423,7 +1547,10 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
1423 restart->nanosleep.rmtp = rmtp; 1547 restart->nanosleep.rmtp = rmtp;
1424 restart->nanosleep.expires = t.timer.expires.tv64; 1548 restart->nanosleep.expires = t.timer.expires.tv64;
1425 1549
1426 return -ERESTART_RESTARTBLOCK; 1550 ret = -ERESTART_RESTARTBLOCK;
1551out:
1552 destroy_hrtimer_on_stack(&t.timer);
1553 return ret;
1427} 1554}
1428 1555
1429asmlinkage long 1556asmlinkage long
@@ -1468,6 +1595,7 @@ static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base,
1468 while ((node = rb_first(&old_base->active))) { 1595 while ((node = rb_first(&old_base->active))) {
1469 timer = rb_entry(node, struct hrtimer, node); 1596 timer = rb_entry(node, struct hrtimer, node);
1470 BUG_ON(hrtimer_callback_running(timer)); 1597 BUG_ON(hrtimer_callback_running(timer));
1598 debug_hrtimer_deactivate(timer);
1471 __remove_hrtimer(timer, old_base, HRTIMER_STATE_INACTIVE, 0); 1599 __remove_hrtimer(timer, old_base, HRTIMER_STATE_INACTIVE, 0);
1472 timer->base = new_base; 1600 timer->base = new_base;
1473 /* 1601 /*
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 46e4ad1723f0..46d6611a33bb 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -150,6 +150,26 @@ void disable_irq(unsigned int irq)
150} 150}
151EXPORT_SYMBOL(disable_irq); 151EXPORT_SYMBOL(disable_irq);
152 152
153static void __enable_irq(struct irq_desc *desc, unsigned int irq)
154{
155 switch (desc->depth) {
156 case 0:
157 printk(KERN_WARNING "Unbalanced enable for IRQ %d\n", irq);
158 WARN_ON(1);
159 break;
160 case 1: {
161 unsigned int status = desc->status & ~IRQ_DISABLED;
162
163 /* Prevent probing on this irq: */
164 desc->status = status | IRQ_NOPROBE;
165 check_irq_resend(desc, irq);
166 /* fall-through */
167 }
168 default:
169 desc->depth--;
170 }
171}
172
153/** 173/**
154 * enable_irq - enable handling of an irq 174 * enable_irq - enable handling of an irq
155 * @irq: Interrupt to enable 175 * @irq: Interrupt to enable
@@ -169,22 +189,7 @@ void enable_irq(unsigned int irq)
169 return; 189 return;
170 190
171 spin_lock_irqsave(&desc->lock, flags); 191 spin_lock_irqsave(&desc->lock, flags);
172 switch (desc->depth) { 192 __enable_irq(desc, irq);
173 case 0:
174 printk(KERN_WARNING "Unbalanced enable for IRQ %d\n", irq);
175 WARN_ON(1);
176 break;
177 case 1: {
178 unsigned int status = desc->status & ~IRQ_DISABLED;
179
180 /* Prevent probing on this irq: */
181 desc->status = status | IRQ_NOPROBE;
182 check_irq_resend(desc, irq);
183 /* fall-through */
184 }
185 default:
186 desc->depth--;
187 }
188 spin_unlock_irqrestore(&desc->lock, flags); 193 spin_unlock_irqrestore(&desc->lock, flags);
189} 194}
190EXPORT_SYMBOL(enable_irq); 195EXPORT_SYMBOL(enable_irq);
@@ -365,7 +370,7 @@ int setup_irq(unsigned int irq, struct irqaction *new)
365 compat_irq_chip_set_default_handler(desc); 370 compat_irq_chip_set_default_handler(desc);
366 371
367 desc->status &= ~(IRQ_AUTODETECT | IRQ_WAITING | 372 desc->status &= ~(IRQ_AUTODETECT | IRQ_WAITING |
368 IRQ_INPROGRESS); 373 IRQ_INPROGRESS | IRQ_SPURIOUS_DISABLED);
369 374
370 if (!(desc->status & IRQ_NOAUTOEN)) { 375 if (!(desc->status & IRQ_NOAUTOEN)) {
371 desc->depth = 0; 376 desc->depth = 0;
@@ -381,6 +386,16 @@ int setup_irq(unsigned int irq, struct irqaction *new)
381 /* Reset broken irq detection when installing new handler */ 386 /* Reset broken irq detection when installing new handler */
382 desc->irq_count = 0; 387 desc->irq_count = 0;
383 desc->irqs_unhandled = 0; 388 desc->irqs_unhandled = 0;
389
390 /*
391 * Check whether we disabled the irq via the spurious handler
392 * before. Reenable it and give it another chance.
393 */
394 if (shared && (desc->status & IRQ_SPURIOUS_DISABLED)) {
395 desc->status &= ~IRQ_SPURIOUS_DISABLED;
396 __enable_irq(desc, irq);
397 }
398
384 spin_unlock_irqrestore(&desc->lock, flags); 399 spin_unlock_irqrestore(&desc->lock, flags);
385 400
386 new->irq = irq; 401 new->irq = irq;
diff --git a/kernel/irq/spurious.c b/kernel/irq/spurious.c
index 088dabbf2d6a..c66d3f10e853 100644
--- a/kernel/irq/spurious.c
+++ b/kernel/irq/spurious.c
@@ -209,8 +209,8 @@ void note_interrupt(unsigned int irq, struct irq_desc *desc,
209 * Now kill the IRQ 209 * Now kill the IRQ
210 */ 210 */
211 printk(KERN_EMERG "Disabling IRQ #%d\n", irq); 211 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
212 desc->status |= IRQ_DISABLED; 212 desc->status |= IRQ_DISABLED | IRQ_SPURIOUS_DISABLED;
213 desc->depth = 1; 213 desc->depth++;
214 desc->chip->disable(irq); 214 desc->chip->disable(irq);
215 } 215 }
216 desc->irqs_unhandled = 0; 216 desc->irqs_unhandled = 0;
diff --git a/kernel/kexec.c b/kernel/kexec.c
index cb85c79989b4..1c5fcacbcf33 100644
--- a/kernel/kexec.c
+++ b/kernel/kexec.c
@@ -1217,7 +1217,7 @@ static int __init parse_crashkernel_mem(char *cmdline,
1217 } 1217 }
1218 1218
1219 /* match ? */ 1219 /* match ? */
1220 if (system_ram >= start && system_ram <= end) { 1220 if (system_ram >= start && system_ram < end) {
1221 *crash_size = size; 1221 *crash_size = size;
1222 break; 1222 break;
1223 } 1223 }
diff --git a/kernel/kgdb.c b/kernel/kgdb.c
index 1bd0ec1c80b2..39e31a036f5b 100644
--- a/kernel/kgdb.c
+++ b/kernel/kgdb.c
@@ -61,7 +61,7 @@ struct kgdb_state {
61 int err_code; 61 int err_code;
62 int cpu; 62 int cpu;
63 int pass_exception; 63 int pass_exception;
64 long threadid; 64 unsigned long threadid;
65 long kgdb_usethreadid; 65 long kgdb_usethreadid;
66 struct pt_regs *linux_regs; 66 struct pt_regs *linux_regs;
67}; 67};
@@ -146,7 +146,7 @@ atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
146 * the other CPUs might interfere with your debugging context, so 146 * the other CPUs might interfere with your debugging context, so
147 * use this with care: 147 * use this with care:
148 */ 148 */
149int kgdb_do_roundup = 1; 149static int kgdb_do_roundup = 1;
150 150
151static int __init opt_nokgdbroundup(char *str) 151static int __init opt_nokgdbroundup(char *str)
152{ 152{
@@ -438,7 +438,7 @@ int kgdb_hex2mem(char *buf, char *mem, int count)
438 * While we find nice hex chars, build a long_val. 438 * While we find nice hex chars, build a long_val.
439 * Return number of chars processed. 439 * Return number of chars processed.
440 */ 440 */
441int kgdb_hex2long(char **ptr, long *long_val) 441int kgdb_hex2long(char **ptr, unsigned long *long_val)
442{ 442{
443 int hex_val; 443 int hex_val;
444 int num = 0; 444 int num = 0;
@@ -709,7 +709,7 @@ int kgdb_isremovedbreak(unsigned long addr)
709 return 0; 709 return 0;
710} 710}
711 711
712int remove_all_break(void) 712static int remove_all_break(void)
713{ 713{
714 unsigned long addr; 714 unsigned long addr;
715 int error; 715 int error;
diff --git a/kernel/kmod.c b/kernel/kmod.c
index e2764047ec03..8df97d3dfda8 100644
--- a/kernel/kmod.c
+++ b/kernel/kmod.c
@@ -27,6 +27,7 @@
27#include <linux/mnt_namespace.h> 27#include <linux/mnt_namespace.h>
28#include <linux/completion.h> 28#include <linux/completion.h>
29#include <linux/file.h> 29#include <linux/file.h>
30#include <linux/fdtable.h>
30#include <linux/workqueue.h> 31#include <linux/workqueue.h>
31#include <linux/security.h> 32#include <linux/security.h>
32#include <linux/mount.h> 33#include <linux/mount.h>
diff --git a/kernel/kthread.c b/kernel/kthread.c
index ac72eea48339..bd1b9ea024e1 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -98,7 +98,7 @@ static void create_kthread(struct kthread_create_info *create)
98 struct sched_param param = { .sched_priority = 0 }; 98 struct sched_param param = { .sched_priority = 0 };
99 wait_for_completion(&create->started); 99 wait_for_completion(&create->started);
100 read_lock(&tasklist_lock); 100 read_lock(&tasklist_lock);
101 create->result = find_task_by_pid(pid); 101 create->result = find_task_by_pid_ns(pid, &init_pid_ns);
102 read_unlock(&tasklist_lock); 102 read_unlock(&tasklist_lock);
103 /* 103 /*
104 * root may have changed our (kthreadd's) priority or CPU mask. 104 * root may have changed our (kthreadd's) priority or CPU mask.
diff --git a/kernel/marker.c b/kernel/marker.c
index 139260e5460c..b5a9fe1d50d5 100644
--- a/kernel/marker.c
+++ b/kernel/marker.c
@@ -29,7 +29,7 @@ extern struct marker __start___markers[];
29extern struct marker __stop___markers[]; 29extern struct marker __stop___markers[];
30 30
31/* Set to 1 to enable marker debug output */ 31/* Set to 1 to enable marker debug output */
32const int marker_debug; 32static const int marker_debug;
33 33
34/* 34/*
35 * markers_mutex nests inside module_mutex. Markers mutex protects the builtin 35 * markers_mutex nests inside module_mutex. Markers mutex protects the builtin
diff --git a/kernel/module.c b/kernel/module.c
index 8d6cccc6c3cf..8e4528c9909f 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -164,131 +164,140 @@ static const struct kernel_symbol *lookup_symbol(const char *name,
164 return NULL; 164 return NULL;
165} 165}
166 166
167static void printk_unused_warning(const char *name) 167static bool always_ok(bool gplok, bool warn, const char *name)
168{ 168{
169 printk(KERN_WARNING "Symbol %s is marked as UNUSED, " 169 return true;
170 "however this module is using it.\n", name);
171 printk(KERN_WARNING "This symbol will go away in the future.\n");
172 printk(KERN_WARNING "Please evalute if this is the right api to use, "
173 "and if it really is, submit a report the linux kernel "
174 "mailinglist together with submitting your code for "
175 "inclusion.\n");
176} 170}
177 171
178/* Find a symbol, return value, crc and module which owns it */ 172static bool printk_unused_warning(bool gplok, bool warn, const char *name)
179static unsigned long __find_symbol(const char *name,
180 struct module **owner,
181 const unsigned long **crc,
182 int gplok)
183{ 173{
184 struct module *mod; 174 if (warn) {
185 const struct kernel_symbol *ks; 175 printk(KERN_WARNING "Symbol %s is marked as UNUSED, "
186 176 "however this module is using it.\n", name);
187 /* Core kernel first. */ 177 printk(KERN_WARNING
188 *owner = NULL; 178 "This symbol will go away in the future.\n");
189 ks = lookup_symbol(name, __start___ksymtab, __stop___ksymtab); 179 printk(KERN_WARNING
190 if (ks) { 180 "Please evalute if this is the right api to use and if "
191 *crc = symversion(__start___kcrctab, (ks - __start___ksymtab)); 181 "it really is, submit a report the linux kernel "
192 return ks->value; 182 "mailinglist together with submitting your code for "
193 } 183 "inclusion.\n");
194 if (gplok) {
195 ks = lookup_symbol(name, __start___ksymtab_gpl,
196 __stop___ksymtab_gpl);
197 if (ks) {
198 *crc = symversion(__start___kcrctab_gpl,
199 (ks - __start___ksymtab_gpl));
200 return ks->value;
201 }
202 } 184 }
203 ks = lookup_symbol(name, __start___ksymtab_gpl_future, 185 return true;
204 __stop___ksymtab_gpl_future); 186}
205 if (ks) { 187
206 if (!gplok) { 188static bool gpl_only_unused_warning(bool gplok, bool warn, const char *name)
207 printk(KERN_WARNING "Symbol %s is being used " 189{
208 "by a non-GPL module, which will not " 190 if (!gplok)
209 "be allowed in the future\n", name); 191 return false;
210 printk(KERN_WARNING "Please see the file " 192 return printk_unused_warning(gplok, warn, name);
211 "Documentation/feature-removal-schedule.txt " 193}
212 "in the kernel source tree for more " 194
213 "details.\n"); 195static bool gpl_only(bool gplok, bool warn, const char *name)
214 } 196{
215 *crc = symversion(__start___kcrctab_gpl_future, 197 return gplok;
216 (ks - __start___ksymtab_gpl_future)); 198}
217 return ks->value; 199
200static bool warn_if_not_gpl(bool gplok, bool warn, const char *name)
201{
202 if (!gplok && warn) {
203 printk(KERN_WARNING "Symbol %s is being used "
204 "by a non-GPL module, which will not "
205 "be allowed in the future\n", name);
206 printk(KERN_WARNING "Please see the file "
207 "Documentation/feature-removal-schedule.txt "
208 "in the kernel source tree for more details.\n");
218 } 209 }
210 return true;
211}
219 212
220 ks = lookup_symbol(name, __start___ksymtab_unused, 213struct symsearch {
221 __stop___ksymtab_unused); 214 const struct kernel_symbol *start, *stop;
222 if (ks) { 215 const unsigned long *crcs;
223 printk_unused_warning(name); 216 bool (*check)(bool gplok, bool warn, const char *name);
224 *crc = symversion(__start___kcrctab_unused, 217};
225 (ks - __start___ksymtab_unused)); 218
226 return ks->value; 219/* Look through this array of symbol tables for a symbol match which
220 * passes the check function. */
221static const struct kernel_symbol *search_symarrays(const struct symsearch *arr,
222 unsigned int num,
223 const char *name,
224 bool gplok,
225 bool warn,
226 const unsigned long **crc)
227{
228 unsigned int i;
229 const struct kernel_symbol *ks;
230
231 for (i = 0; i < num; i++) {
232 ks = lookup_symbol(name, arr[i].start, arr[i].stop);
233 if (!ks || !arr[i].check(gplok, warn, name))
234 continue;
235
236 if (crc)
237 *crc = symversion(arr[i].crcs, ks - arr[i].start);
238 return ks;
227 } 239 }
240 return NULL;
241}
228 242
229 if (gplok) 243/* Find a symbol, return value, (optional) crc and (optional) module
230 ks = lookup_symbol(name, __start___ksymtab_unused_gpl, 244 * which owns it */
231 __stop___ksymtab_unused_gpl); 245static unsigned long find_symbol(const char *name,
246 struct module **owner,
247 const unsigned long **crc,
248 bool gplok,
249 bool warn)
250{
251 struct module *mod;
252 const struct kernel_symbol *ks;
253 const struct symsearch arr[] = {
254 { __start___ksymtab, __stop___ksymtab, __start___kcrctab,
255 always_ok },
256 { __start___ksymtab_gpl, __stop___ksymtab_gpl,
257 __start___kcrctab_gpl, gpl_only },
258 { __start___ksymtab_gpl_future, __stop___ksymtab_gpl_future,
259 __start___kcrctab_gpl_future, warn_if_not_gpl },
260 { __start___ksymtab_unused, __stop___ksymtab_unused,
261 __start___kcrctab_unused, printk_unused_warning },
262 { __start___ksymtab_unused_gpl, __stop___ksymtab_unused_gpl,
263 __start___kcrctab_unused_gpl, gpl_only_unused_warning },
264 };
265
266 /* Core kernel first. */
267 ks = search_symarrays(arr, ARRAY_SIZE(arr), name, gplok, warn, crc);
232 if (ks) { 268 if (ks) {
233 printk_unused_warning(name); 269 if (owner)
234 *crc = symversion(__start___kcrctab_unused_gpl, 270 *owner = NULL;
235 (ks - __start___ksymtab_unused_gpl));
236 return ks->value; 271 return ks->value;
237 } 272 }
238 273
239 /* Now try modules. */ 274 /* Now try modules. */
240 list_for_each_entry(mod, &modules, list) { 275 list_for_each_entry(mod, &modules, list) {
241 *owner = mod; 276 struct symsearch arr[] = {
242 ks = lookup_symbol(name, mod->syms, mod->syms + mod->num_syms); 277 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
278 always_ok },
279 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
280 mod->gpl_crcs, gpl_only },
281 { mod->gpl_future_syms,
282 mod->gpl_future_syms + mod->num_gpl_future_syms,
283 mod->gpl_future_crcs, warn_if_not_gpl },
284 { mod->unused_syms,
285 mod->unused_syms + mod->num_unused_syms,
286 mod->unused_crcs, printk_unused_warning },
287 { mod->unused_gpl_syms,
288 mod->unused_gpl_syms + mod->num_unused_gpl_syms,
289 mod->unused_gpl_crcs, gpl_only_unused_warning },
290 };
291
292 ks = search_symarrays(arr, ARRAY_SIZE(arr),
293 name, gplok, warn, crc);
243 if (ks) { 294 if (ks) {
244 *crc = symversion(mod->crcs, (ks - mod->syms)); 295 if (owner)
245 return ks->value; 296 *owner = mod;
246 }
247
248 if (gplok) {
249 ks = lookup_symbol(name, mod->gpl_syms,
250 mod->gpl_syms + mod->num_gpl_syms);
251 if (ks) {
252 *crc = symversion(mod->gpl_crcs,
253 (ks - mod->gpl_syms));
254 return ks->value;
255 }
256 }
257 ks = lookup_symbol(name, mod->unused_syms, mod->unused_syms + mod->num_unused_syms);
258 if (ks) {
259 printk_unused_warning(name);
260 *crc = symversion(mod->unused_crcs, (ks - mod->unused_syms));
261 return ks->value;
262 }
263
264 if (gplok) {
265 ks = lookup_symbol(name, mod->unused_gpl_syms,
266 mod->unused_gpl_syms + mod->num_unused_gpl_syms);
267 if (ks) {
268 printk_unused_warning(name);
269 *crc = symversion(mod->unused_gpl_crcs,
270 (ks - mod->unused_gpl_syms));
271 return ks->value;
272 }
273 }
274 ks = lookup_symbol(name, mod->gpl_future_syms,
275 (mod->gpl_future_syms +
276 mod->num_gpl_future_syms));
277 if (ks) {
278 if (!gplok) {
279 printk(KERN_WARNING "Symbol %s is being used "
280 "by a non-GPL module, which will not "
281 "be allowed in the future\n", name);
282 printk(KERN_WARNING "Please see the file "
283 "Documentation/feature-removal-schedule.txt "
284 "in the kernel source tree for more "
285 "details.\n");
286 }
287 *crc = symversion(mod->gpl_future_crcs,
288 (ks - mod->gpl_future_syms));
289 return ks->value; 297 return ks->value;
290 } 298 }
291 } 299 }
300
292 DEBUGP("Failed to find symbol %s\n", name); 301 DEBUGP("Failed to find symbol %s\n", name);
293 return -ENOENT; 302 return -ENOENT;
294} 303}
@@ -736,12 +745,13 @@ sys_delete_module(const char __user *name_user, unsigned int flags)
736 if (!forced && module_refcount(mod) != 0) 745 if (!forced && module_refcount(mod) != 0)
737 wait_for_zero_refcount(mod); 746 wait_for_zero_refcount(mod);
738 747
748 mutex_unlock(&module_mutex);
739 /* Final destruction now noone is using it. */ 749 /* Final destruction now noone is using it. */
740 if (mod->exit != NULL) { 750 if (mod->exit != NULL)
741 mutex_unlock(&module_mutex);
742 mod->exit(); 751 mod->exit();
743 mutex_lock(&module_mutex); 752 blocking_notifier_call_chain(&module_notify_list,
744 } 753 MODULE_STATE_GOING, mod);
754 mutex_lock(&module_mutex);
745 /* Store the name of the last unloaded module for diagnostic purposes */ 755 /* Store the name of the last unloaded module for diagnostic purposes */
746 strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module)); 756 strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module));
747 free_module(mod); 757 free_module(mod);
@@ -777,10 +787,9 @@ static void print_unload_info(struct seq_file *m, struct module *mod)
777void __symbol_put(const char *symbol) 787void __symbol_put(const char *symbol)
778{ 788{
779 struct module *owner; 789 struct module *owner;
780 const unsigned long *crc;
781 790
782 preempt_disable(); 791 preempt_disable();
783 if (IS_ERR_VALUE(__find_symbol(symbol, &owner, &crc, 1))) 792 if (IS_ERR_VALUE(find_symbol(symbol, &owner, NULL, true, false)))
784 BUG(); 793 BUG();
785 module_put(owner); 794 module_put(owner);
786 preempt_enable(); 795 preempt_enable();
@@ -881,6 +890,19 @@ static struct module_attribute *modinfo_attrs[] = {
881 890
882static const char vermagic[] = VERMAGIC_STRING; 891static const char vermagic[] = VERMAGIC_STRING;
883 892
893static int try_to_force_load(struct module *mod, const char *symname)
894{
895#ifdef CONFIG_MODULE_FORCE_LOAD
896 if (!(tainted & TAINT_FORCED_MODULE))
897 printk("%s: no version for \"%s\" found: kernel tainted.\n",
898 mod->name, symname);
899 add_taint_module(mod, TAINT_FORCED_MODULE);
900 return 0;
901#else
902 return -ENOEXEC;
903#endif
904}
905
884#ifdef CONFIG_MODVERSIONS 906#ifdef CONFIG_MODVERSIONS
885static int check_version(Elf_Shdr *sechdrs, 907static int check_version(Elf_Shdr *sechdrs,
886 unsigned int versindex, 908 unsigned int versindex,
@@ -905,18 +927,18 @@ static int check_version(Elf_Shdr *sechdrs,
905 927
906 if (versions[i].crc == *crc) 928 if (versions[i].crc == *crc)
907 return 1; 929 return 1;
908 printk("%s: disagrees about version of symbol %s\n",
909 mod->name, symname);
910 DEBUGP("Found checksum %lX vs module %lX\n", 930 DEBUGP("Found checksum %lX vs module %lX\n",
911 *crc, versions[i].crc); 931 *crc, versions[i].crc);
912 return 0; 932 goto bad_version;
913 } 933 }
914 /* Not in module's version table. OK, but that taints the kernel. */ 934
915 if (!(tainted & TAINT_FORCED_MODULE)) 935 if (!try_to_force_load(mod, symname))
916 printk("%s: no version for \"%s\" found: kernel tainted.\n", 936 return 1;
917 mod->name, symname); 937
918 add_taint_module(mod, TAINT_FORCED_MODULE); 938bad_version:
919 return 1; 939 printk("%s: disagrees about version of symbol %s\n",
940 mod->name, symname);
941 return 0;
920} 942}
921 943
922static inline int check_modstruct_version(Elf_Shdr *sechdrs, 944static inline int check_modstruct_version(Elf_Shdr *sechdrs,
@@ -924,13 +946,10 @@ static inline int check_modstruct_version(Elf_Shdr *sechdrs,
924 struct module *mod) 946 struct module *mod)
925{ 947{
926 const unsigned long *crc; 948 const unsigned long *crc;
927 struct module *owner;
928 949
929 if (IS_ERR_VALUE(__find_symbol("struct_module", 950 if (IS_ERR_VALUE(find_symbol("struct_module", NULL, &crc, true, false)))
930 &owner, &crc, 1)))
931 BUG(); 951 BUG();
932 return check_version(sechdrs, versindex, "struct_module", mod, 952 return check_version(sechdrs, versindex, "struct_module", mod, crc);
933 crc);
934} 953}
935 954
936/* First part is kernel version, which we ignore. */ 955/* First part is kernel version, which we ignore. */
@@ -974,8 +993,8 @@ static unsigned long resolve_symbol(Elf_Shdr *sechdrs,
974 unsigned long ret; 993 unsigned long ret;
975 const unsigned long *crc; 994 const unsigned long *crc;
976 995
977 ret = __find_symbol(name, &owner, &crc, 996 ret = find_symbol(name, &owner, &crc,
978 !(mod->taints & TAINT_PROPRIETARY_MODULE)); 997 !(mod->taints & TAINT_PROPRIETARY_MODULE), true);
979 if (!IS_ERR_VALUE(ret)) { 998 if (!IS_ERR_VALUE(ret)) {
980 /* use_module can fail due to OOM, 999 /* use_module can fail due to OOM,
981 or module initialization or unloading */ 1000 or module initialization or unloading */
@@ -991,6 +1010,20 @@ static unsigned long resolve_symbol(Elf_Shdr *sechdrs,
991 * J. Corbet <corbet@lwn.net> 1010 * J. Corbet <corbet@lwn.net>
992 */ 1011 */
993#if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS) 1012#if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS)
1013struct module_sect_attr
1014{
1015 struct module_attribute mattr;
1016 char *name;
1017 unsigned long address;
1018};
1019
1020struct module_sect_attrs
1021{
1022 struct attribute_group grp;
1023 unsigned int nsections;
1024 struct module_sect_attr attrs[0];
1025};
1026
994static ssize_t module_sect_show(struct module_attribute *mattr, 1027static ssize_t module_sect_show(struct module_attribute *mattr,
995 struct module *mod, char *buf) 1028 struct module *mod, char *buf)
996{ 1029{
@@ -1001,7 +1034,7 @@ static ssize_t module_sect_show(struct module_attribute *mattr,
1001 1034
1002static void free_sect_attrs(struct module_sect_attrs *sect_attrs) 1035static void free_sect_attrs(struct module_sect_attrs *sect_attrs)
1003{ 1036{
1004 int section; 1037 unsigned int section;
1005 1038
1006 for (section = 0; section < sect_attrs->nsections; section++) 1039 for (section = 0; section < sect_attrs->nsections; section++)
1007 kfree(sect_attrs->attrs[section].name); 1040 kfree(sect_attrs->attrs[section].name);
@@ -1362,10 +1395,9 @@ void *__symbol_get(const char *symbol)
1362{ 1395{
1363 struct module *owner; 1396 struct module *owner;
1364 unsigned long value; 1397 unsigned long value;
1365 const unsigned long *crc;
1366 1398
1367 preempt_disable(); 1399 preempt_disable();
1368 value = __find_symbol(symbol, &owner, &crc, 1); 1400 value = find_symbol(symbol, &owner, NULL, true, true);
1369 if (IS_ERR_VALUE(value)) 1401 if (IS_ERR_VALUE(value))
1370 value = 0; 1402 value = 0;
1371 else if (strong_try_module_get(owner)) 1403 else if (strong_try_module_get(owner))
@@ -1382,33 +1414,33 @@ EXPORT_SYMBOL_GPL(__symbol_get);
1382 */ 1414 */
1383static int verify_export_symbols(struct module *mod) 1415static int verify_export_symbols(struct module *mod)
1384{ 1416{
1385 const char *name = NULL; 1417 unsigned int i;
1386 unsigned long i, ret = 0;
1387 struct module *owner; 1418 struct module *owner;
1388 const unsigned long *crc; 1419 const struct kernel_symbol *s;
1389 1420 struct {
1390 for (i = 0; i < mod->num_syms; i++) 1421 const struct kernel_symbol *sym;
1391 if (!IS_ERR_VALUE(__find_symbol(mod->syms[i].name, 1422 unsigned int num;
1392 &owner, &crc, 1))) { 1423 } arr[] = {
1393 name = mod->syms[i].name; 1424 { mod->syms, mod->num_syms },
1394 ret = -ENOEXEC; 1425 { mod->gpl_syms, mod->num_gpl_syms },
1395 goto dup; 1426 { mod->gpl_future_syms, mod->num_gpl_future_syms },
1396 } 1427 { mod->unused_syms, mod->num_unused_syms },
1428 { mod->unused_gpl_syms, mod->num_unused_gpl_syms },
1429 };
1397 1430
1398 for (i = 0; i < mod->num_gpl_syms; i++) 1431 for (i = 0; i < ARRAY_SIZE(arr); i++) {
1399 if (!IS_ERR_VALUE(__find_symbol(mod->gpl_syms[i].name, 1432 for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) {
1400 &owner, &crc, 1))) { 1433 if (!IS_ERR_VALUE(find_symbol(s->name, &owner,
1401 name = mod->gpl_syms[i].name; 1434 NULL, true, false))) {
1402 ret = -ENOEXEC; 1435 printk(KERN_ERR
1403 goto dup; 1436 "%s: exports duplicate symbol %s"
1437 " (owned by %s)\n",
1438 mod->name, s->name, module_name(owner));
1439 return -ENOEXEC;
1440 }
1404 } 1441 }
1405 1442 }
1406dup: 1443 return 0;
1407 if (ret)
1408 printk(KERN_ERR "%s: exports duplicate symbol %s (owned by %s)\n",
1409 mod->name, name, module_name(owner));
1410
1411 return ret;
1412} 1444}
1413 1445
1414/* Change all symbols so that st_value encodes the pointer directly. */ 1446/* Change all symbols so that st_value encodes the pointer directly. */
@@ -1814,8 +1846,9 @@ static struct module *load_module(void __user *umod,
1814 unwindex = find_sec(hdr, sechdrs, secstrings, ARCH_UNWIND_SECTION_NAME); 1846 unwindex = find_sec(hdr, sechdrs, secstrings, ARCH_UNWIND_SECTION_NAME);
1815#endif 1847#endif
1816 1848
1817 /* Don't keep modinfo section */ 1849 /* Don't keep modinfo and version sections. */
1818 sechdrs[infoindex].sh_flags &= ~(unsigned long)SHF_ALLOC; 1850 sechdrs[infoindex].sh_flags &= ~(unsigned long)SHF_ALLOC;
1851 sechdrs[versindex].sh_flags &= ~(unsigned long)SHF_ALLOC;
1819#ifdef CONFIG_KALLSYMS 1852#ifdef CONFIG_KALLSYMS
1820 /* Keep symbol and string tables for decoding later. */ 1853 /* Keep symbol and string tables for decoding later. */
1821 sechdrs[symindex].sh_flags |= SHF_ALLOC; 1854 sechdrs[symindex].sh_flags |= SHF_ALLOC;
@@ -1833,9 +1866,9 @@ static struct module *load_module(void __user *umod,
1833 modmagic = get_modinfo(sechdrs, infoindex, "vermagic"); 1866 modmagic = get_modinfo(sechdrs, infoindex, "vermagic");
1834 /* This is allowed: modprobe --force will invalidate it. */ 1867 /* This is allowed: modprobe --force will invalidate it. */
1835 if (!modmagic) { 1868 if (!modmagic) {
1836 add_taint_module(mod, TAINT_FORCED_MODULE); 1869 err = try_to_force_load(mod, "magic");
1837 printk(KERN_WARNING "%s: no version magic, tainting kernel.\n", 1870 if (err)
1838 mod->name); 1871 goto free_hdr;
1839 } else if (!same_magic(modmagic, vermagic)) { 1872 } else if (!same_magic(modmagic, vermagic)) {
1840 printk(KERN_ERR "%s: version magic '%s' should be '%s'\n", 1873 printk(KERN_ERR "%s: version magic '%s' should be '%s'\n",
1841 mod->name, modmagic, vermagic); 1874 mod->name, modmagic, vermagic);
@@ -1977,7 +2010,8 @@ static struct module *load_module(void __user *umod,
1977 mod->unused_crcs = (void *)sechdrs[unusedcrcindex].sh_addr; 2010 mod->unused_crcs = (void *)sechdrs[unusedcrcindex].sh_addr;
1978 mod->unused_gpl_syms = (void *)sechdrs[unusedgplindex].sh_addr; 2011 mod->unused_gpl_syms = (void *)sechdrs[unusedgplindex].sh_addr;
1979 if (unusedgplcrcindex) 2012 if (unusedgplcrcindex)
1980 mod->unused_crcs = (void *)sechdrs[unusedgplcrcindex].sh_addr; 2013 mod->unused_gpl_crcs
2014 = (void *)sechdrs[unusedgplcrcindex].sh_addr;
1981 2015
1982#ifdef CONFIG_MODVERSIONS 2016#ifdef CONFIG_MODVERSIONS
1983 if ((mod->num_syms && !crcindex) || 2017 if ((mod->num_syms && !crcindex) ||
@@ -1985,9 +2019,10 @@ static struct module *load_module(void __user *umod,
1985 (mod->num_gpl_future_syms && !gplfuturecrcindex) || 2019 (mod->num_gpl_future_syms && !gplfuturecrcindex) ||
1986 (mod->num_unused_syms && !unusedcrcindex) || 2020 (mod->num_unused_syms && !unusedcrcindex) ||
1987 (mod->num_unused_gpl_syms && !unusedgplcrcindex)) { 2021 (mod->num_unused_gpl_syms && !unusedgplcrcindex)) {
1988 printk(KERN_WARNING "%s: No versions for exported symbols." 2022 printk(KERN_WARNING "%s: No versions for exported symbols.\n", mod->name);
1989 " Tainting kernel.\n", mod->name); 2023 err = try_to_force_load(mod, "nocrc");
1990 add_taint_module(mod, TAINT_FORCED_MODULE); 2024 if (err)
2025 goto cleanup;
1991 } 2026 }
1992#endif 2027#endif
1993 markersindex = find_sec(hdr, sechdrs, secstrings, "__markers"); 2028 markersindex = find_sec(hdr, sechdrs, secstrings, "__markers");
@@ -2171,6 +2206,8 @@ sys_init_module(void __user *umod,
2171 mod->state = MODULE_STATE_GOING; 2206 mod->state = MODULE_STATE_GOING;
2172 synchronize_sched(); 2207 synchronize_sched();
2173 module_put(mod); 2208 module_put(mod);
2209 blocking_notifier_call_chain(&module_notify_list,
2210 MODULE_STATE_GOING, mod);
2174 mutex_lock(&module_mutex); 2211 mutex_lock(&module_mutex);
2175 free_module(mod); 2212 free_module(mod);
2176 mutex_unlock(&module_mutex); 2213 mutex_unlock(&module_mutex);
diff --git a/kernel/pid.c b/kernel/pid.c
index 477691576b33..20d59fa2d493 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -111,10 +111,11 @@ EXPORT_SYMBOL(is_container_init);
111 111
112static __cacheline_aligned_in_smp DEFINE_SPINLOCK(pidmap_lock); 112static __cacheline_aligned_in_smp DEFINE_SPINLOCK(pidmap_lock);
113 113
114static void free_pidmap(struct pid_namespace *pid_ns, int pid) 114static void free_pidmap(struct upid *upid)
115{ 115{
116 struct pidmap *map = pid_ns->pidmap + pid / BITS_PER_PAGE; 116 int nr = upid->nr;
117 int offset = pid & BITS_PER_PAGE_MASK; 117 struct pidmap *map = upid->ns->pidmap + nr / BITS_PER_PAGE;
118 int offset = nr & BITS_PER_PAGE_MASK;
118 119
119 clear_bit(offset, map->page); 120 clear_bit(offset, map->page);
120 atomic_inc(&map->nr_free); 121 atomic_inc(&map->nr_free);
@@ -232,7 +233,7 @@ void free_pid(struct pid *pid)
232 spin_unlock_irqrestore(&pidmap_lock, flags); 233 spin_unlock_irqrestore(&pidmap_lock, flags);
233 234
234 for (i = 0; i <= pid->level; i++) 235 for (i = 0; i <= pid->level; i++)
235 free_pidmap(pid->numbers[i].ns, pid->numbers[i].nr); 236 free_pidmap(pid->numbers + i);
236 237
237 call_rcu(&pid->rcu, delayed_put_pid); 238 call_rcu(&pid->rcu, delayed_put_pid);
238} 239}
@@ -278,8 +279,8 @@ out:
278 return pid; 279 return pid;
279 280
280out_free: 281out_free:
281 for (i++; i <= ns->level; i++) 282 while (++i <= ns->level)
282 free_pidmap(pid->numbers[i].ns, pid->numbers[i].nr); 283 free_pidmap(pid->numbers + i);
283 284
284 kmem_cache_free(ns->pid_cachep, pid); 285 kmem_cache_free(ns->pid_cachep, pid);
285 pid = NULL; 286 pid = NULL;
@@ -316,7 +317,7 @@ EXPORT_SYMBOL_GPL(find_pid);
316/* 317/*
317 * attach_pid() must be called with the tasklist_lock write-held. 318 * attach_pid() must be called with the tasklist_lock write-held.
318 */ 319 */
319int attach_pid(struct task_struct *task, enum pid_type type, 320void attach_pid(struct task_struct *task, enum pid_type type,
320 struct pid *pid) 321 struct pid *pid)
321{ 322{
322 struct pid_link *link; 323 struct pid_link *link;
@@ -324,11 +325,10 @@ int attach_pid(struct task_struct *task, enum pid_type type,
324 link = &task->pids[type]; 325 link = &task->pids[type];
325 link->pid = pid; 326 link->pid = pid;
326 hlist_add_head_rcu(&link->node, &pid->tasks[type]); 327 hlist_add_head_rcu(&link->node, &pid->tasks[type]);
327
328 return 0;
329} 328}
330 329
331void detach_pid(struct task_struct *task, enum pid_type type) 330static void __change_pid(struct task_struct *task, enum pid_type type,
331 struct pid *new)
332{ 332{
333 struct pid_link *link; 333 struct pid_link *link;
334 struct pid *pid; 334 struct pid *pid;
@@ -338,7 +338,7 @@ void detach_pid(struct task_struct *task, enum pid_type type)
338 pid = link->pid; 338 pid = link->pid;
339 339
340 hlist_del_rcu(&link->node); 340 hlist_del_rcu(&link->node);
341 link->pid = NULL; 341 link->pid = new;
342 342
343 for (tmp = PIDTYPE_MAX; --tmp >= 0; ) 343 for (tmp = PIDTYPE_MAX; --tmp >= 0; )
344 if (!hlist_empty(&pid->tasks[tmp])) 344 if (!hlist_empty(&pid->tasks[tmp]))
@@ -347,13 +347,24 @@ void detach_pid(struct task_struct *task, enum pid_type type)
347 free_pid(pid); 347 free_pid(pid);
348} 348}
349 349
350void detach_pid(struct task_struct *task, enum pid_type type)
351{
352 __change_pid(task, type, NULL);
353}
354
355void change_pid(struct task_struct *task, enum pid_type type,
356 struct pid *pid)
357{
358 __change_pid(task, type, pid);
359 attach_pid(task, type, pid);
360}
361
350/* transfer_pid is an optimization of attach_pid(new), detach_pid(old) */ 362/* transfer_pid is an optimization of attach_pid(new), detach_pid(old) */
351void transfer_pid(struct task_struct *old, struct task_struct *new, 363void transfer_pid(struct task_struct *old, struct task_struct *new,
352 enum pid_type type) 364 enum pid_type type)
353{ 365{
354 new->pids[type].pid = old->pids[type].pid; 366 new->pids[type].pid = old->pids[type].pid;
355 hlist_replace_rcu(&old->pids[type].node, &new->pids[type].node); 367 hlist_replace_rcu(&old->pids[type].node, &new->pids[type].node);
356 old->pids[type].pid = NULL;
357} 368}
358 369
359struct task_struct *pid_task(struct pid *pid, enum pid_type type) 370struct task_struct *pid_task(struct pid *pid, enum pid_type type)
@@ -380,12 +391,6 @@ struct task_struct *find_task_by_pid_type_ns(int type, int nr,
380 391
381EXPORT_SYMBOL(find_task_by_pid_type_ns); 392EXPORT_SYMBOL(find_task_by_pid_type_ns);
382 393
383struct task_struct *find_task_by_pid(pid_t nr)
384{
385 return find_task_by_pid_type_ns(PIDTYPE_PID, nr, &init_pid_ns);
386}
387EXPORT_SYMBOL(find_task_by_pid);
388
389struct task_struct *find_task_by_vpid(pid_t vnr) 394struct task_struct *find_task_by_vpid(pid_t vnr)
390{ 395{
391 return find_task_by_pid_type_ns(PIDTYPE_PID, vnr, 396 return find_task_by_pid_type_ns(PIDTYPE_PID, vnr,
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
index 5ca37fa50beb..98702b4b8851 100644
--- a/kernel/pid_namespace.c
+++ b/kernel/pid_namespace.c
@@ -66,7 +66,7 @@ err_alloc:
66 return NULL; 66 return NULL;
67} 67}
68 68
69static struct pid_namespace *create_pid_namespace(int level) 69static struct pid_namespace *create_pid_namespace(unsigned int level)
70{ 70{
71 struct pid_namespace *ns; 71 struct pid_namespace *ns;
72 int i; 72 int i;
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
index ae5c6c147c4b..f1525ad06cb3 100644
--- a/kernel/posix-cpu-timers.c
+++ b/kernel/posix-cpu-timers.c
@@ -4,8 +4,9 @@
4 4
5#include <linux/sched.h> 5#include <linux/sched.h>
6#include <linux/posix-timers.h> 6#include <linux/posix-timers.h>
7#include <asm/uaccess.h>
8#include <linux/errno.h> 7#include <linux/errno.h>
8#include <linux/math64.h>
9#include <asm/uaccess.h>
9 10
10static int check_clock(const clockid_t which_clock) 11static int check_clock(const clockid_t which_clock)
11{ 12{
@@ -47,12 +48,10 @@ static void sample_to_timespec(const clockid_t which_clock,
47 union cpu_time_count cpu, 48 union cpu_time_count cpu,
48 struct timespec *tp) 49 struct timespec *tp)
49{ 50{
50 if (CPUCLOCK_WHICH(which_clock) == CPUCLOCK_SCHED) { 51 if (CPUCLOCK_WHICH(which_clock) == CPUCLOCK_SCHED)
51 tp->tv_sec = div_long_long_rem(cpu.sched, 52 *tp = ns_to_timespec(cpu.sched);
52 NSEC_PER_SEC, &tp->tv_nsec); 53 else
53 } else {
54 cputime_to_timespec(cpu.cpu, tp); 54 cputime_to_timespec(cpu.cpu, tp);
55 }
56} 55}
57 56
58static inline int cpu_time_before(const clockid_t which_clock, 57static inline int cpu_time_before(const clockid_t which_clock,
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index 8476956ffd92..dbd8398ddb0b 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -310,8 +310,7 @@ int posix_timer_event(struct k_itimer *timr,int si_private)
310 310
311 if (timr->it_sigev_notify & SIGEV_THREAD_ID) { 311 if (timr->it_sigev_notify & SIGEV_THREAD_ID) {
312 struct task_struct *leader; 312 struct task_struct *leader;
313 int ret = send_sigqueue(timr->it_sigev_signo, timr->sigq, 313 int ret = send_sigqueue(timr->sigq, timr->it_process, 0);
314 timr->it_process);
315 314
316 if (likely(ret >= 0)) 315 if (likely(ret >= 0))
317 return ret; 316 return ret;
@@ -322,8 +321,7 @@ int posix_timer_event(struct k_itimer *timr,int si_private)
322 timr->it_process = leader; 321 timr->it_process = leader;
323 } 322 }
324 323
325 return send_group_sigqueue(timr->it_sigev_signo, timr->sigq, 324 return send_sigqueue(timr->sigq, timr->it_process, 1);
326 timr->it_process);
327} 325}
328EXPORT_SYMBOL_GPL(posix_timer_event); 326EXPORT_SYMBOL_GPL(posix_timer_event);
329 327
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index 6233f3b4ae66..b45da40e8d25 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig
@@ -19,16 +19,6 @@ config PM
19 will issue the hlt instruction if nothing is to be done, thereby 19 will issue the hlt instruction if nothing is to be done, thereby
20 sending the processor to sleep and saving power. 20 sending the processor to sleep and saving power.
21 21
22config PM_LEGACY
23 bool "Legacy Power Management API (DEPRECATED)"
24 depends on PM
25 default n
26 ---help---
27 Support for pm_register() and friends. This old API is obsoleted
28 by the driver model.
29
30 If unsure, say N.
31
32config PM_DEBUG 22config PM_DEBUG
33 bool "Power Management Debug Support" 23 bool "Power Management Debug Support"
34 depends on PM 24 depends on PM
diff --git a/kernel/power/Makefile b/kernel/power/Makefile
index f7dfff28ecdb..597823b5b700 100644
--- a/kernel/power/Makefile
+++ b/kernel/power/Makefile
@@ -4,7 +4,6 @@ EXTRA_CFLAGS += -DDEBUG
4endif 4endif
5 5
6obj-y := main.o 6obj-y := main.o
7obj-$(CONFIG_PM_LEGACY) += pm.o
8obj-$(CONFIG_PM_SLEEP) += process.o console.o 7obj-$(CONFIG_PM_SLEEP) += process.o console.o
9obj-$(CONFIG_HIBERNATION) += swsusp.o disk.o snapshot.o swap.o user.o 8obj-$(CONFIG_HIBERNATION) += swsusp.o disk.o snapshot.o swap.o user.o
10 9
diff --git a/kernel/power/pm.c b/kernel/power/pm.c
deleted file mode 100644
index 60c73fa670d5..000000000000
--- a/kernel/power/pm.c
+++ /dev/null
@@ -1,205 +0,0 @@
1/*
2 * pm.c - Power management interface
3 *
4 * Copyright (C) 2000 Andrew Henroid
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20#include <linux/init.h>
21#include <linux/module.h>
22#include <linux/spinlock.h>
23#include <linux/mm.h>
24#include <linux/slab.h>
25#include <linux/pm.h>
26#include <linux/pm_legacy.h>
27#include <linux/interrupt.h>
28#include <linux/mutex.h>
29
30/*
31 * Locking notes:
32 * pm_devs_lock can be a semaphore providing pm ops are not called
33 * from an interrupt handler (already a bad idea so no change here). Each
34 * change must be protected so that an unlink of an entry doesn't clash
35 * with a pm send - which is permitted to sleep in the current architecture
36 *
37 * Module unloads clashing with pm events now work out safely, the module
38 * unload path will block until the event has been sent. It may well block
39 * until a resume but that will be fine.
40 */
41
42static DEFINE_MUTEX(pm_devs_lock);
43static LIST_HEAD(pm_devs);
44
45/**
46 * pm_register - register a device with power management
47 * @type: device type
48 * @id: device ID
49 * @callback: callback function
50 *
51 * Add a device to the list of devices that wish to be notified about
52 * power management events. A &pm_dev structure is returned on success,
53 * on failure the return is %NULL.
54 *
55 * The callback function will be called in process context and
56 * it may sleep.
57 */
58
59struct pm_dev *pm_register(pm_dev_t type,
60 unsigned long id,
61 pm_callback callback)
62{
63 struct pm_dev *dev = kzalloc(sizeof(struct pm_dev), GFP_KERNEL);
64 if (dev) {
65 dev->type = type;
66 dev->id = id;
67 dev->callback = callback;
68
69 mutex_lock(&pm_devs_lock);
70 list_add(&dev->entry, &pm_devs);
71 mutex_unlock(&pm_devs_lock);
72 }
73 return dev;
74}
75
76/**
77 * pm_send - send request to a single device
78 * @dev: device to send to
79 * @rqst: power management request
80 * @data: data for the callback
81 *
82 * Issue a power management request to a given device. The
83 * %PM_SUSPEND and %PM_RESUME events are handled specially. The
84 * data field must hold the intended next state. No call is made
85 * if the state matches.
86 *
87 * BUGS: what stops two power management requests occurring in parallel
88 * and conflicting.
89 *
90 * WARNING: Calling pm_send directly is not generally recommended, in
91 * particular there is no locking against the pm_dev going away. The
92 * caller must maintain all needed locking or have 'inside knowledge'
93 * on the safety. Also remember that this function is not locked against
94 * pm_unregister. This means that you must handle SMP races on callback
95 * execution and unload yourself.
96 */
97
98static int pm_send(struct pm_dev *dev, pm_request_t rqst, void *data)
99{
100 int status = 0;
101 unsigned long prev_state, next_state;
102
103 if (in_interrupt())
104 BUG();
105
106 switch (rqst) {
107 case PM_SUSPEND:
108 case PM_RESUME:
109 prev_state = dev->state;
110 next_state = (unsigned long) data;
111 if (prev_state != next_state) {
112 if (dev->callback)
113 status = (*dev->callback)(dev, rqst, data);
114 if (!status) {
115 dev->state = next_state;
116 dev->prev_state = prev_state;
117 }
118 }
119 else {
120 dev->prev_state = prev_state;
121 }
122 break;
123 default:
124 if (dev->callback)
125 status = (*dev->callback)(dev, rqst, data);
126 break;
127 }
128 return status;
129}
130
131/*
132 * Undo incomplete request
133 */
134static void pm_undo_all(struct pm_dev *last)
135{
136 struct list_head *entry = last->entry.prev;
137 while (entry != &pm_devs) {
138 struct pm_dev *dev = list_entry(entry, struct pm_dev, entry);
139 if (dev->state != dev->prev_state) {
140 /* previous state was zero (running) resume or
141 * previous state was non-zero (suspended) suspend
142 */
143 pm_request_t undo = (dev->prev_state
144 ? PM_SUSPEND:PM_RESUME);
145 pm_send(dev, undo, (void*) dev->prev_state);
146 }
147 entry = entry->prev;
148 }
149}
150
151/**
152 * pm_send_all - send request to all managed devices
153 * @rqst: power management request
154 * @data: data for the callback
155 *
156 * Issue a power management request to a all devices. The
157 * %PM_SUSPEND events are handled specially. Any device is
158 * permitted to fail a suspend by returning a non zero (error)
159 * value from its callback function. If any device vetoes a
160 * suspend request then all other devices that have suspended
161 * during the processing of this request are restored to their
162 * previous state.
163 *
164 * WARNING: This function takes the pm_devs_lock. The lock is not dropped until
165 * the callbacks have completed. This prevents races against pm locking
166 * functions, races against module unload pm_unregister code. It does
167 * mean however that you must not issue pm_ functions within the callback
168 * or you will deadlock and users will hate you.
169 *
170 * Zero is returned on success. If a suspend fails then the status
171 * from the device that vetoes the suspend is returned.
172 *
173 * BUGS: what stops two power management requests occurring in parallel
174 * and conflicting.
175 */
176
177int pm_send_all(pm_request_t rqst, void *data)
178{
179 struct list_head *entry;
180
181 mutex_lock(&pm_devs_lock);
182 entry = pm_devs.next;
183 while (entry != &pm_devs) {
184 struct pm_dev *dev = list_entry(entry, struct pm_dev, entry);
185 if (dev->callback) {
186 int status = pm_send(dev, rqst, data);
187 if (status) {
188 /* return devices to previous state on
189 * failed suspend request
190 */
191 if (rqst == PM_SUSPEND)
192 pm_undo_all(dev);
193 mutex_unlock(&pm_devs_lock);
194 return status;
195 }
196 }
197 entry = entry->next;
198 }
199 mutex_unlock(&pm_devs_lock);
200 return 0;
201}
202
203EXPORT_SYMBOL(pm_register);
204EXPORT_SYMBOL(pm_send_all);
205
diff --git a/kernel/printk.c b/kernel/printk.c
index d3f9c0f788bf..8fb01c32aa3b 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -111,6 +111,9 @@ struct console_cmdline
111 char name[8]; /* Name of the driver */ 111 char name[8]; /* Name of the driver */
112 int index; /* Minor dev. to use */ 112 int index; /* Minor dev. to use */
113 char *options; /* Options for the driver */ 113 char *options; /* Options for the driver */
114#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
115 char *brl_options; /* Options for braille driver */
116#endif
114}; 117};
115 118
116#define MAX_CMDLINECONSOLES 8 119#define MAX_CMDLINECONSOLES 8
@@ -808,15 +811,60 @@ static void call_console_drivers(unsigned start, unsigned end)
808 811
809#endif 812#endif
810 813
814static int __add_preferred_console(char *name, int idx, char *options,
815 char *brl_options)
816{
817 struct console_cmdline *c;
818 int i;
819
820 /*
821 * See if this tty is not yet registered, and
822 * if we have a slot free.
823 */
824 for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0]; i++)
825 if (strcmp(console_cmdline[i].name, name) == 0 &&
826 console_cmdline[i].index == idx) {
827 if (!brl_options)
828 selected_console = i;
829 return 0;
830 }
831 if (i == MAX_CMDLINECONSOLES)
832 return -E2BIG;
833 if (!brl_options)
834 selected_console = i;
835 c = &console_cmdline[i];
836 strlcpy(c->name, name, sizeof(c->name));
837 c->options = options;
838#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
839 c->brl_options = brl_options;
840#endif
841 c->index = idx;
842 return 0;
843}
811/* 844/*
812 * Set up a list of consoles. Called from init/main.c 845 * Set up a list of consoles. Called from init/main.c
813 */ 846 */
814static int __init console_setup(char *str) 847static int __init console_setup(char *str)
815{ 848{
816 char buf[sizeof(console_cmdline[0].name) + 4]; /* 4 for index */ 849 char buf[sizeof(console_cmdline[0].name) + 4]; /* 4 for index */
817 char *s, *options; 850 char *s, *options, *brl_options = NULL;
818 int idx; 851 int idx;
819 852
853#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
854 if (!memcmp(str, "brl,", 4)) {
855 brl_options = "";
856 str += 4;
857 } else if (!memcmp(str, "brl=", 4)) {
858 brl_options = str + 4;
859 str = strchr(brl_options, ',');
860 if (!str) {
861 printk(KERN_ERR "need port name after brl=\n");
862 return 1;
863 }
864 *(str++) = 0;
865 }
866#endif
867
820 /* 868 /*
821 * Decode str into name, index, options. 869 * Decode str into name, index, options.
822 */ 870 */
@@ -841,7 +889,7 @@ static int __init console_setup(char *str)
841 idx = simple_strtoul(s, NULL, 10); 889 idx = simple_strtoul(s, NULL, 10);
842 *s = 0; 890 *s = 0;
843 891
844 add_preferred_console(buf, idx, options); 892 __add_preferred_console(buf, idx, options, brl_options);
845 return 1; 893 return 1;
846} 894}
847__setup("console=", console_setup); 895__setup("console=", console_setup);
@@ -861,28 +909,7 @@ __setup("console=", console_setup);
861 */ 909 */
862int add_preferred_console(char *name, int idx, char *options) 910int add_preferred_console(char *name, int idx, char *options)
863{ 911{
864 struct console_cmdline *c; 912 return __add_preferred_console(name, idx, options, NULL);
865 int i;
866
867 /*
868 * See if this tty is not yet registered, and
869 * if we have a slot free.
870 */
871 for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0]; i++)
872 if (strcmp(console_cmdline[i].name, name) == 0 &&
873 console_cmdline[i].index == idx) {
874 selected_console = i;
875 return 0;
876 }
877 if (i == MAX_CMDLINECONSOLES)
878 return -E2BIG;
879 selected_console = i;
880 c = &console_cmdline[i];
881 memcpy(c->name, name, sizeof(c->name));
882 c->name[sizeof(c->name) - 1] = 0;
883 c->options = options;
884 c->index = idx;
885 return 0;
886} 913}
887 914
888int update_console_cmdline(char *name, int idx, char *name_new, int idx_new, char *options) 915int update_console_cmdline(char *name, int idx, char *name_new, int idx_new, char *options)
@@ -894,7 +921,7 @@ int update_console_cmdline(char *name, int idx, char *name_new, int idx_new, cha
894 if (strcmp(console_cmdline[i].name, name) == 0 && 921 if (strcmp(console_cmdline[i].name, name) == 0 &&
895 console_cmdline[i].index == idx) { 922 console_cmdline[i].index == idx) {
896 c = &console_cmdline[i]; 923 c = &console_cmdline[i];
897 memcpy(c->name, name_new, sizeof(c->name)); 924 strlcpy(c->name, name_new, sizeof(c->name));
898 c->name[sizeof(c->name) - 1] = 0; 925 c->name[sizeof(c->name) - 1] = 0;
899 c->options = options; 926 c->options = options;
900 c->index = idx_new; 927 c->index = idx_new;
@@ -1163,6 +1190,16 @@ void register_console(struct console *console)
1163 continue; 1190 continue;
1164 if (console->index < 0) 1191 if (console->index < 0)
1165 console->index = console_cmdline[i].index; 1192 console->index = console_cmdline[i].index;
1193#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
1194 if (console_cmdline[i].brl_options) {
1195 console->flags |= CON_BRL;
1196 braille_register_console(console,
1197 console_cmdline[i].index,
1198 console_cmdline[i].options,
1199 console_cmdline[i].brl_options);
1200 return;
1201 }
1202#endif
1166 if (console->setup && 1203 if (console->setup &&
1167 console->setup(console, console_cmdline[i].options) != 0) 1204 console->setup(console, console_cmdline[i].options) != 0)
1168 break; 1205 break;
@@ -1221,6 +1258,11 @@ int unregister_console(struct console *console)
1221 struct console *a, *b; 1258 struct console *a, *b;
1222 int res = 1; 1259 int res = 1;
1223 1260
1261#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
1262 if (console->flags & CON_BRL)
1263 return braille_unregister_console(console);
1264#endif
1265
1224 acquire_console_sem(); 1266 acquire_console_sem();
1225 if (console_drivers == console) { 1267 if (console_drivers == console) {
1226 console_drivers=console->next; 1268 console_drivers=console->next;
@@ -1272,8 +1314,8 @@ late_initcall(disable_boot_consoles);
1272 */ 1314 */
1273void tty_write_message(struct tty_struct *tty, char *msg) 1315void tty_write_message(struct tty_struct *tty, char *msg)
1274{ 1316{
1275 if (tty && tty->driver->write) 1317 if (tty && tty->ops->write)
1276 tty->driver->write(tty, msg, strlen(msg)); 1318 tty->ops->write(tty, msg, strlen(msg));
1277 return; 1319 return;
1278} 1320}
1279 1321
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index dac4b4e57293..6c19e94fd0a5 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -73,7 +73,7 @@ void __ptrace_unlink(struct task_struct *child)
73 BUG_ON(!child->ptrace); 73 BUG_ON(!child->ptrace);
74 74
75 child->ptrace = 0; 75 child->ptrace = 0;
76 if (!list_empty(&child->ptrace_list)) { 76 if (ptrace_reparented(child)) {
77 list_del_init(&child->ptrace_list); 77 list_del_init(&child->ptrace_list);
78 remove_parent(child); 78 remove_parent(child);
79 child->parent = child->real_parent; 79 child->parent = child->real_parent;
@@ -168,8 +168,6 @@ int ptrace_attach(struct task_struct *task)
168 audit_ptrace(task); 168 audit_ptrace(task);
169 169
170 retval = -EPERM; 170 retval = -EPERM;
171 if (task->pid <= 1)
172 goto out;
173 if (same_thread_group(task, current)) 171 if (same_thread_group(task, current))
174 goto out; 172 goto out;
175 173
@@ -208,8 +206,7 @@ repeat:
208 206
209 __ptrace_link(task, current); 207 __ptrace_link(task, current);
210 208
211 force_sig_specific(SIGSTOP, task); 209 send_sig_info(SIGSTOP, SEND_SIG_FORCED, task);
212
213bad: 210bad:
214 write_unlock_irqrestore(&tasklist_lock, flags); 211 write_unlock_irqrestore(&tasklist_lock, flags);
215 task_unlock(task); 212 task_unlock(task);
@@ -522,12 +519,6 @@ struct task_struct *ptrace_get_task_struct(pid_t pid)
522{ 519{
523 struct task_struct *child; 520 struct task_struct *child;
524 521
525 /*
526 * Tracing init is not allowed.
527 */
528 if (pid == 1)
529 return ERR_PTR(-EPERM);
530
531 read_lock(&tasklist_lock); 522 read_lock(&tasklist_lock);
532 child = find_task_by_vpid(pid); 523 child = find_task_by_vpid(pid);
533 if (child) 524 if (child)
@@ -543,7 +534,6 @@ struct task_struct *ptrace_get_task_struct(pid_t pid)
543#define arch_ptrace_attach(child) do { } while (0) 534#define arch_ptrace_attach(child) do { } while (0)
544#endif 535#endif
545 536
546#ifndef __ARCH_SYS_PTRACE
547asmlinkage long sys_ptrace(long request, long pid, long addr, long data) 537asmlinkage long sys_ptrace(long request, long pid, long addr, long data)
548{ 538{
549 struct task_struct *child; 539 struct task_struct *child;
@@ -591,7 +581,6 @@ asmlinkage long sys_ptrace(long request, long pid, long addr, long data)
591 unlock_kernel(); 581 unlock_kernel();
592 return ret; 582 return ret;
593} 583}
594#endif /* __ARCH_SYS_PTRACE */
595 584
596int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data) 585int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data)
597{ 586{
diff --git a/kernel/sched.c b/kernel/sched.c
index e2f7f5acc807..58fb8af15776 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -75,16 +75,6 @@
75#include <asm/irq_regs.h> 75#include <asm/irq_regs.h>
76 76
77/* 77/*
78 * Scheduler clock - returns current time in nanosec units.
79 * This is default implementation.
80 * Architectures and sub-architectures can override this.
81 */
82unsigned long long __attribute__((weak)) sched_clock(void)
83{
84 return (unsigned long long)jiffies * (NSEC_PER_SEC / HZ);
85}
86
87/*
88 * Convert user-nice values [ -20 ... 0 ... 19 ] 78 * Convert user-nice values [ -20 ... 0 ... 19 ]
89 * to static priority [ MAX_RT_PRIO..MAX_PRIO-1 ], 79 * to static priority [ MAX_RT_PRIO..MAX_PRIO-1 ],
90 * and back. 80 * and back.
@@ -242,6 +232,12 @@ static void destroy_rt_bandwidth(struct rt_bandwidth *rt_b)
242} 232}
243#endif 233#endif
244 234
235/*
236 * sched_domains_mutex serializes calls to arch_init_sched_domains,
237 * detach_destroy_domains and partition_sched_domains.
238 */
239static DEFINE_MUTEX(sched_domains_mutex);
240
245#ifdef CONFIG_GROUP_SCHED 241#ifdef CONFIG_GROUP_SCHED
246 242
247#include <linux/cgroup.h> 243#include <linux/cgroup.h>
@@ -308,9 +304,6 @@ static DEFINE_PER_CPU(struct rt_rq, init_rt_rq) ____cacheline_aligned_in_smp;
308 */ 304 */
309static DEFINE_SPINLOCK(task_group_lock); 305static DEFINE_SPINLOCK(task_group_lock);
310 306
311/* doms_cur_mutex serializes access to doms_cur[] array */
312static DEFINE_MUTEX(doms_cur_mutex);
313
314#ifdef CONFIG_FAIR_GROUP_SCHED 307#ifdef CONFIG_FAIR_GROUP_SCHED
315#ifdef CONFIG_USER_SCHED 308#ifdef CONFIG_USER_SCHED
316# define INIT_TASK_GROUP_LOAD (2*NICE_0_LOAD) 309# define INIT_TASK_GROUP_LOAD (2*NICE_0_LOAD)
@@ -318,7 +311,13 @@ static DEFINE_MUTEX(doms_cur_mutex);
318# define INIT_TASK_GROUP_LOAD NICE_0_LOAD 311# define INIT_TASK_GROUP_LOAD NICE_0_LOAD
319#endif 312#endif
320 313
314/*
315 * A weight of 0, 1 or ULONG_MAX can cause arithmetics problems.
316 * (The default weight is 1024 - so there's no practical
317 * limitation from this.)
318 */
321#define MIN_SHARES 2 319#define MIN_SHARES 2
320#define MAX_SHARES (ULONG_MAX - 1)
322 321
323static int init_task_group_load = INIT_TASK_GROUP_LOAD; 322static int init_task_group_load = INIT_TASK_GROUP_LOAD;
324#endif 323#endif
@@ -358,21 +357,9 @@ static inline void set_task_rq(struct task_struct *p, unsigned int cpu)
358#endif 357#endif
359} 358}
360 359
361static inline void lock_doms_cur(void)
362{
363 mutex_lock(&doms_cur_mutex);
364}
365
366static inline void unlock_doms_cur(void)
367{
368 mutex_unlock(&doms_cur_mutex);
369}
370
371#else 360#else
372 361
373static inline void set_task_rq(struct task_struct *p, unsigned int cpu) { } 362static inline void set_task_rq(struct task_struct *p, unsigned int cpu) { }
374static inline void lock_doms_cur(void) { }
375static inline void unlock_doms_cur(void) { }
376 363
377#endif /* CONFIG_GROUP_SCHED */ 364#endif /* CONFIG_GROUP_SCHED */
378 365
@@ -560,13 +547,7 @@ struct rq {
560 unsigned long next_balance; 547 unsigned long next_balance;
561 struct mm_struct *prev_mm; 548 struct mm_struct *prev_mm;
562 549
563 u64 clock, prev_clock_raw; 550 u64 clock;
564 s64 clock_max_delta;
565
566 unsigned int clock_warps, clock_overflows, clock_underflows;
567 u64 idle_clock;
568 unsigned int clock_deep_idle_events;
569 u64 tick_timestamp;
570 551
571 atomic_t nr_iowait; 552 atomic_t nr_iowait;
572 553
@@ -631,82 +612,6 @@ static inline int cpu_of(struct rq *rq)
631#endif 612#endif
632} 613}
633 614
634#ifdef CONFIG_NO_HZ
635static inline bool nohz_on(int cpu)
636{
637 return tick_get_tick_sched(cpu)->nohz_mode != NOHZ_MODE_INACTIVE;
638}
639
640static inline u64 max_skipped_ticks(struct rq *rq)
641{
642 return nohz_on(cpu_of(rq)) ? jiffies - rq->last_tick_seen + 2 : 1;
643}
644
645static inline void update_last_tick_seen(struct rq *rq)
646{
647 rq->last_tick_seen = jiffies;
648}
649#else
650static inline u64 max_skipped_ticks(struct rq *rq)
651{
652 return 1;
653}
654
655static inline void update_last_tick_seen(struct rq *rq)
656{
657}
658#endif
659
660/*
661 * Update the per-runqueue clock, as finegrained as the platform can give
662 * us, but without assuming monotonicity, etc.:
663 */
664static void __update_rq_clock(struct rq *rq)
665{
666 u64 prev_raw = rq->prev_clock_raw;
667 u64 now = sched_clock();
668 s64 delta = now - prev_raw;
669 u64 clock = rq->clock;
670
671#ifdef CONFIG_SCHED_DEBUG
672 WARN_ON_ONCE(cpu_of(rq) != smp_processor_id());
673#endif
674 /*
675 * Protect against sched_clock() occasionally going backwards:
676 */
677 if (unlikely(delta < 0)) {
678 clock++;
679 rq->clock_warps++;
680 } else {
681 /*
682 * Catch too large forward jumps too:
683 */
684 u64 max_jump = max_skipped_ticks(rq) * TICK_NSEC;
685 u64 max_time = rq->tick_timestamp + max_jump;
686
687 if (unlikely(clock + delta > max_time)) {
688 if (clock < max_time)
689 clock = max_time;
690 else
691 clock++;
692 rq->clock_overflows++;
693 } else {
694 if (unlikely(delta > rq->clock_max_delta))
695 rq->clock_max_delta = delta;
696 clock += delta;
697 }
698 }
699
700 rq->prev_clock_raw = now;
701 rq->clock = clock;
702}
703
704static void update_rq_clock(struct rq *rq)
705{
706 if (likely(smp_processor_id() == cpu_of(rq)))
707 __update_rq_clock(rq);
708}
709
710/* 615/*
711 * The domain tree (rq->sd) is protected by RCU's quiescent state transition. 616 * The domain tree (rq->sd) is protected by RCU's quiescent state transition.
712 * See detach_destroy_domains: synchronize_sched for details. 617 * See detach_destroy_domains: synchronize_sched for details.
@@ -722,6 +627,11 @@ static void update_rq_clock(struct rq *rq)
722#define task_rq(p) cpu_rq(task_cpu(p)) 627#define task_rq(p) cpu_rq(task_cpu(p))
723#define cpu_curr(cpu) (cpu_rq(cpu)->curr) 628#define cpu_curr(cpu) (cpu_rq(cpu)->curr)
724 629
630static inline void update_rq_clock(struct rq *rq)
631{
632 rq->clock = sched_clock_cpu(cpu_of(rq));
633}
634
725/* 635/*
726 * Tunables that become constants when CONFIG_SCHED_DEBUG is off: 636 * Tunables that become constants when CONFIG_SCHED_DEBUG is off:
727 */ 637 */
@@ -757,14 +667,14 @@ const_debug unsigned int sysctl_sched_features =
757#define SCHED_FEAT(name, enabled) \ 667#define SCHED_FEAT(name, enabled) \
758 #name , 668 #name ,
759 669
760__read_mostly char *sched_feat_names[] = { 670static __read_mostly char *sched_feat_names[] = {
761#include "sched_features.h" 671#include "sched_features.h"
762 NULL 672 NULL
763}; 673};
764 674
765#undef SCHED_FEAT 675#undef SCHED_FEAT
766 676
767int sched_feat_open(struct inode *inode, struct file *filp) 677static int sched_feat_open(struct inode *inode, struct file *filp)
768{ 678{
769 filp->private_data = inode->i_private; 679 filp->private_data = inode->i_private;
770 return 0; 680 return 0;
@@ -899,7 +809,7 @@ static inline u64 global_rt_runtime(void)
899 return (u64)sysctl_sched_rt_runtime * NSEC_PER_USEC; 809 return (u64)sysctl_sched_rt_runtime * NSEC_PER_USEC;
900} 810}
901 811
902static const unsigned long long time_sync_thresh = 100000; 812unsigned long long time_sync_thresh = 100000;
903 813
904static DEFINE_PER_CPU(unsigned long long, time_offset); 814static DEFINE_PER_CPU(unsigned long long, time_offset);
905static DEFINE_PER_CPU(unsigned long long, prev_cpu_time); 815static DEFINE_PER_CPU(unsigned long long, prev_cpu_time);
@@ -913,11 +823,14 @@ static DEFINE_PER_CPU(unsigned long long, prev_cpu_time);
913static DEFINE_SPINLOCK(time_sync_lock); 823static DEFINE_SPINLOCK(time_sync_lock);
914static unsigned long long prev_global_time; 824static unsigned long long prev_global_time;
915 825
916static unsigned long long __sync_cpu_clock(cycles_t time, int cpu) 826static unsigned long long __sync_cpu_clock(unsigned long long time, int cpu)
917{ 827{
918 unsigned long flags; 828 /*
919 829 * We want this inlined, to not get tracer function calls
920 spin_lock_irqsave(&time_sync_lock, flags); 830 * in this critical section:
831 */
832 spin_acquire(&time_sync_lock.dep_map, 0, 0, _THIS_IP_);
833 __raw_spin_lock(&time_sync_lock.raw_lock);
921 834
922 if (time < prev_global_time) { 835 if (time < prev_global_time) {
923 per_cpu(time_offset, cpu) += prev_global_time - time; 836 per_cpu(time_offset, cpu) += prev_global_time - time;
@@ -926,7 +839,8 @@ static unsigned long long __sync_cpu_clock(cycles_t time, int cpu)
926 prev_global_time = time; 839 prev_global_time = time;
927 } 840 }
928 841
929 spin_unlock_irqrestore(&time_sync_lock, flags); 842 __raw_spin_unlock(&time_sync_lock.raw_lock);
843 spin_release(&time_sync_lock.dep_map, 1, _THIS_IP_);
930 844
931 return time; 845 return time;
932} 846}
@@ -934,8 +848,6 @@ static unsigned long long __sync_cpu_clock(cycles_t time, int cpu)
934static unsigned long long __cpu_clock(int cpu) 848static unsigned long long __cpu_clock(int cpu)
935{ 849{
936 unsigned long long now; 850 unsigned long long now;
937 unsigned long flags;
938 struct rq *rq;
939 851
940 /* 852 /*
941 * Only call sched_clock() if the scheduler has already been 853 * Only call sched_clock() if the scheduler has already been
@@ -944,11 +856,7 @@ static unsigned long long __cpu_clock(int cpu)
944 if (unlikely(!scheduler_running)) 856 if (unlikely(!scheduler_running))
945 return 0; 857 return 0;
946 858
947 local_irq_save(flags); 859 now = sched_clock_cpu(cpu);
948 rq = cpu_rq(cpu);
949 update_rq_clock(rq);
950 now = rq->clock;
951 local_irq_restore(flags);
952 860
953 return now; 861 return now;
954} 862}
@@ -960,13 +868,18 @@ static unsigned long long __cpu_clock(int cpu)
960unsigned long long cpu_clock(int cpu) 868unsigned long long cpu_clock(int cpu)
961{ 869{
962 unsigned long long prev_cpu_time, time, delta_time; 870 unsigned long long prev_cpu_time, time, delta_time;
871 unsigned long flags;
963 872
873 local_irq_save(flags);
964 prev_cpu_time = per_cpu(prev_cpu_time, cpu); 874 prev_cpu_time = per_cpu(prev_cpu_time, cpu);
965 time = __cpu_clock(cpu) + per_cpu(time_offset, cpu); 875 time = __cpu_clock(cpu) + per_cpu(time_offset, cpu);
966 delta_time = time-prev_cpu_time; 876 delta_time = time-prev_cpu_time;
967 877
968 if (unlikely(delta_time > time_sync_thresh)) 878 if (unlikely(delta_time > time_sync_thresh)) {
969 time = __sync_cpu_clock(time, cpu); 879 time = __sync_cpu_clock(time, cpu);
880 per_cpu(prev_cpu_time, cpu) = time;
881 }
882 local_irq_restore(flags);
970 883
971 return time; 884 return time;
972} 885}
@@ -1117,43 +1030,6 @@ static struct rq *this_rq_lock(void)
1117 return rq; 1030 return rq;
1118} 1031}
1119 1032
1120/*
1121 * We are going deep-idle (irqs are disabled):
1122 */
1123void sched_clock_idle_sleep_event(void)
1124{
1125 struct rq *rq = cpu_rq(smp_processor_id());
1126
1127 spin_lock(&rq->lock);
1128 __update_rq_clock(rq);
1129 spin_unlock(&rq->lock);
1130 rq->clock_deep_idle_events++;
1131}
1132EXPORT_SYMBOL_GPL(sched_clock_idle_sleep_event);
1133
1134/*
1135 * We just idled delta nanoseconds (called with irqs disabled):
1136 */
1137void sched_clock_idle_wakeup_event(u64 delta_ns)
1138{
1139 struct rq *rq = cpu_rq(smp_processor_id());
1140 u64 now = sched_clock();
1141
1142 rq->idle_clock += delta_ns;
1143 /*
1144 * Override the previous timestamp and ignore all
1145 * sched_clock() deltas that occured while we idled,
1146 * and use the PM-provided delta_ns to advance the
1147 * rq clock:
1148 */
1149 spin_lock(&rq->lock);
1150 rq->prev_clock_raw = now;
1151 rq->clock += delta_ns;
1152 spin_unlock(&rq->lock);
1153 touch_softlockup_watchdog();
1154}
1155EXPORT_SYMBOL_GPL(sched_clock_idle_wakeup_event);
1156
1157static void __resched_task(struct task_struct *p, int tif_bit); 1033static void __resched_task(struct task_struct *p, int tif_bit);
1158 1034
1159static inline void resched_task(struct task_struct *p) 1035static inline void resched_task(struct task_struct *p)
@@ -1189,6 +1065,7 @@ static inline void resched_rq(struct rq *rq)
1189enum { 1065enum {
1190 HRTICK_SET, /* re-programm hrtick_timer */ 1066 HRTICK_SET, /* re-programm hrtick_timer */
1191 HRTICK_RESET, /* not a new slice */ 1067 HRTICK_RESET, /* not a new slice */
1068 HRTICK_BLOCK, /* stop hrtick operations */
1192}; 1069};
1193 1070
1194/* 1071/*
@@ -1200,6 +1077,8 @@ static inline int hrtick_enabled(struct rq *rq)
1200{ 1077{
1201 if (!sched_feat(HRTICK)) 1078 if (!sched_feat(HRTICK))
1202 return 0; 1079 return 0;
1080 if (unlikely(test_bit(HRTICK_BLOCK, &rq->hrtick_flags)))
1081 return 0;
1203 return hrtimer_is_hres_active(&rq->hrtick_timer); 1082 return hrtimer_is_hres_active(&rq->hrtick_timer);
1204} 1083}
1205 1084
@@ -1275,14 +1154,70 @@ static enum hrtimer_restart hrtick(struct hrtimer *timer)
1275 WARN_ON_ONCE(cpu_of(rq) != smp_processor_id()); 1154 WARN_ON_ONCE(cpu_of(rq) != smp_processor_id());
1276 1155
1277 spin_lock(&rq->lock); 1156 spin_lock(&rq->lock);
1278 __update_rq_clock(rq); 1157 update_rq_clock(rq);
1279 rq->curr->sched_class->task_tick(rq, rq->curr, 1); 1158 rq->curr->sched_class->task_tick(rq, rq->curr, 1);
1280 spin_unlock(&rq->lock); 1159 spin_unlock(&rq->lock);
1281 1160
1282 return HRTIMER_NORESTART; 1161 return HRTIMER_NORESTART;
1283} 1162}
1284 1163
1285static inline void init_rq_hrtick(struct rq *rq) 1164static void hotplug_hrtick_disable(int cpu)
1165{
1166 struct rq *rq = cpu_rq(cpu);
1167 unsigned long flags;
1168
1169 spin_lock_irqsave(&rq->lock, flags);
1170 rq->hrtick_flags = 0;
1171 __set_bit(HRTICK_BLOCK, &rq->hrtick_flags);
1172 spin_unlock_irqrestore(&rq->lock, flags);
1173
1174 hrtick_clear(rq);
1175}
1176
1177static void hotplug_hrtick_enable(int cpu)
1178{
1179 struct rq *rq = cpu_rq(cpu);
1180 unsigned long flags;
1181
1182 spin_lock_irqsave(&rq->lock, flags);
1183 __clear_bit(HRTICK_BLOCK, &rq->hrtick_flags);
1184 spin_unlock_irqrestore(&rq->lock, flags);
1185}
1186
1187static int
1188hotplug_hrtick(struct notifier_block *nfb, unsigned long action, void *hcpu)
1189{
1190 int cpu = (int)(long)hcpu;
1191
1192 switch (action) {
1193 case CPU_UP_CANCELED:
1194 case CPU_UP_CANCELED_FROZEN:
1195 case CPU_DOWN_PREPARE:
1196 case CPU_DOWN_PREPARE_FROZEN:
1197 case CPU_DEAD:
1198 case CPU_DEAD_FROZEN:
1199 hotplug_hrtick_disable(cpu);
1200 return NOTIFY_OK;
1201
1202 case CPU_UP_PREPARE:
1203 case CPU_UP_PREPARE_FROZEN:
1204 case CPU_DOWN_FAILED:
1205 case CPU_DOWN_FAILED_FROZEN:
1206 case CPU_ONLINE:
1207 case CPU_ONLINE_FROZEN:
1208 hotplug_hrtick_enable(cpu);
1209 return NOTIFY_OK;
1210 }
1211
1212 return NOTIFY_DONE;
1213}
1214
1215static void init_hrtick(void)
1216{
1217 hotcpu_notifier(hotplug_hrtick, 0);
1218}
1219
1220static void init_rq_hrtick(struct rq *rq)
1286{ 1221{
1287 rq->hrtick_flags = 0; 1222 rq->hrtick_flags = 0;
1288 hrtimer_init(&rq->hrtick_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); 1223 hrtimer_init(&rq->hrtick_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
@@ -1319,6 +1254,10 @@ static inline void init_rq_hrtick(struct rq *rq)
1319void hrtick_resched(void) 1254void hrtick_resched(void)
1320{ 1255{
1321} 1256}
1257
1258static inline void init_hrtick(void)
1259{
1260}
1322#endif 1261#endif
1323 1262
1324/* 1263/*
@@ -1438,8 +1377,8 @@ calc_delta_mine(unsigned long delta_exec, unsigned long weight,
1438{ 1377{
1439 u64 tmp; 1378 u64 tmp;
1440 1379
1441 if (unlikely(!lw->inv_weight)) 1380 if (!lw->inv_weight)
1442 lw->inv_weight = (WMULT_CONST-lw->weight/2) / (lw->weight+1); 1381 lw->inv_weight = 1 + (WMULT_CONST-lw->weight/2)/(lw->weight+1);
1443 1382
1444 tmp = (u64)delta_exec * weight; 1383 tmp = (u64)delta_exec * weight;
1445 /* 1384 /*
@@ -1748,6 +1687,8 @@ __update_group_shares_cpu(struct task_group *tg, struct sched_domain *sd,
1748 1687
1749 if (shares < MIN_SHARES) 1688 if (shares < MIN_SHARES)
1750 shares = MIN_SHARES; 1689 shares = MIN_SHARES;
1690 else if (shares > MAX_SHARES)
1691 shares = MAX_SHARES;
1751 1692
1752 __set_se_shares(tg->se[tcpu], shares); 1693 __set_se_shares(tg->se[tcpu], shares);
1753} 1694}
@@ -4339,8 +4280,10 @@ void account_system_time(struct task_struct *p, int hardirq_offset,
4339 struct rq *rq = this_rq(); 4280 struct rq *rq = this_rq();
4340 cputime64_t tmp; 4281 cputime64_t tmp;
4341 4282
4342 if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) 4283 if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
4343 return account_guest_time(p, cputime); 4284 account_guest_time(p, cputime);
4285 return;
4286 }
4344 4287
4345 p->stime = cputime_add(p->stime, cputime); 4288 p->stime = cputime_add(p->stime, cputime);
4346 4289
@@ -4404,19 +4347,11 @@ void scheduler_tick(void)
4404 int cpu = smp_processor_id(); 4347 int cpu = smp_processor_id();
4405 struct rq *rq = cpu_rq(cpu); 4348 struct rq *rq = cpu_rq(cpu);
4406 struct task_struct *curr = rq->curr; 4349 struct task_struct *curr = rq->curr;
4407 u64 next_tick = rq->tick_timestamp + TICK_NSEC; 4350
4351 sched_clock_tick();
4408 4352
4409 spin_lock(&rq->lock); 4353 spin_lock(&rq->lock);
4410 __update_rq_clock(rq); 4354 update_rq_clock(rq);
4411 /*
4412 * Let rq->clock advance by at least TICK_NSEC:
4413 */
4414 if (unlikely(rq->clock < next_tick)) {
4415 rq->clock = next_tick;
4416 rq->clock_underflows++;
4417 }
4418 rq->tick_timestamp = rq->clock;
4419 update_last_tick_seen(rq);
4420 update_cpu_load(rq); 4355 update_cpu_load(rq);
4421 curr->sched_class->task_tick(rq, curr, 0); 4356 curr->sched_class->task_tick(rq, curr, 0);
4422 spin_unlock(&rq->lock); 4357 spin_unlock(&rq->lock);
@@ -4570,7 +4505,7 @@ need_resched_nonpreemptible:
4570 * Do the rq-clock update outside the rq lock: 4505 * Do the rq-clock update outside the rq lock:
4571 */ 4506 */
4572 local_irq_disable(); 4507 local_irq_disable();
4573 __update_rq_clock(rq); 4508 update_rq_clock(rq);
4574 spin_lock(&rq->lock); 4509 spin_lock(&rq->lock);
4575 clear_tsk_need_resched(prev); 4510 clear_tsk_need_resched(prev);
4576 4511
@@ -4595,9 +4530,9 @@ need_resched_nonpreemptible:
4595 prev->sched_class->put_prev_task(rq, prev); 4530 prev->sched_class->put_prev_task(rq, prev);
4596 next = pick_next_task(rq, prev); 4531 next = pick_next_task(rq, prev);
4597 4532
4598 sched_info_switch(prev, next);
4599
4600 if (likely(prev != next)) { 4533 if (likely(prev != next)) {
4534 sched_info_switch(prev, next);
4535
4601 rq->nr_switches++; 4536 rq->nr_switches++;
4602 rq->curr = next; 4537 rq->curr = next;
4603 ++*switch_count; 4538 ++*switch_count;
@@ -7755,7 +7690,7 @@ void partition_sched_domains(int ndoms_new, cpumask_t *doms_new,
7755{ 7690{
7756 int i, j; 7691 int i, j;
7757 7692
7758 lock_doms_cur(); 7693 mutex_lock(&sched_domains_mutex);
7759 7694
7760 /* always unregister in case we don't destroy any domains */ 7695 /* always unregister in case we don't destroy any domains */
7761 unregister_sched_domain_sysctl(); 7696 unregister_sched_domain_sysctl();
@@ -7804,7 +7739,7 @@ match2:
7804 7739
7805 register_sched_domain_sysctl(); 7740 register_sched_domain_sysctl();
7806 7741
7807 unlock_doms_cur(); 7742 mutex_unlock(&sched_domains_mutex);
7808} 7743}
7809 7744
7810#if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT) 7745#if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT)
@@ -7813,8 +7748,10 @@ int arch_reinit_sched_domains(void)
7813 int err; 7748 int err;
7814 7749
7815 get_online_cpus(); 7750 get_online_cpus();
7751 mutex_lock(&sched_domains_mutex);
7816 detach_destroy_domains(&cpu_online_map); 7752 detach_destroy_domains(&cpu_online_map);
7817 err = arch_init_sched_domains(&cpu_online_map); 7753 err = arch_init_sched_domains(&cpu_online_map);
7754 mutex_unlock(&sched_domains_mutex);
7818 put_online_cpus(); 7755 put_online_cpus();
7819 7756
7820 return err; 7757 return err;
@@ -7932,13 +7869,16 @@ void __init sched_init_smp(void)
7932 BUG_ON(sched_group_nodes_bycpu == NULL); 7869 BUG_ON(sched_group_nodes_bycpu == NULL);
7933#endif 7870#endif
7934 get_online_cpus(); 7871 get_online_cpus();
7872 mutex_lock(&sched_domains_mutex);
7935 arch_init_sched_domains(&cpu_online_map); 7873 arch_init_sched_domains(&cpu_online_map);
7936 cpus_andnot(non_isolated_cpus, cpu_possible_map, cpu_isolated_map); 7874 cpus_andnot(non_isolated_cpus, cpu_possible_map, cpu_isolated_map);
7937 if (cpus_empty(non_isolated_cpus)) 7875 if (cpus_empty(non_isolated_cpus))
7938 cpu_set(smp_processor_id(), non_isolated_cpus); 7876 cpu_set(smp_processor_id(), non_isolated_cpus);
7877 mutex_unlock(&sched_domains_mutex);
7939 put_online_cpus(); 7878 put_online_cpus();
7940 /* XXX: Theoretical race here - CPU may be hotplugged now */ 7879 /* XXX: Theoretical race here - CPU may be hotplugged now */
7941 hotcpu_notifier(update_sched_domains, 0); 7880 hotcpu_notifier(update_sched_domains, 0);
7881 init_hrtick();
7942 7882
7943 /* Move init over to a non-isolated CPU */ 7883 /* Move init over to a non-isolated CPU */
7944 if (set_cpus_allowed_ptr(current, &non_isolated_cpus) < 0) 7884 if (set_cpus_allowed_ptr(current, &non_isolated_cpus) < 0)
@@ -8025,7 +7965,7 @@ static void init_tg_cfs_entry(struct task_group *tg, struct cfs_rq *cfs_rq,
8025 7965
8026 se->my_q = cfs_rq; 7966 se->my_q = cfs_rq;
8027 se->load.weight = tg->shares; 7967 se->load.weight = tg->shares;
8028 se->load.inv_weight = div64_64(1ULL<<32, se->load.weight); 7968 se->load.inv_weight = 0;
8029 se->parent = parent; 7969 se->parent = parent;
8030} 7970}
8031#endif 7971#endif
@@ -8149,8 +8089,6 @@ void __init sched_init(void)
8149 spin_lock_init(&rq->lock); 8089 spin_lock_init(&rq->lock);
8150 lockdep_set_class(&rq->lock, &rq->rq_lock_key); 8090 lockdep_set_class(&rq->lock, &rq->rq_lock_key);
8151 rq->nr_running = 0; 8091 rq->nr_running = 0;
8152 rq->clock = 1;
8153 update_last_tick_seen(rq);
8154 init_cfs_rq(&rq->cfs, rq); 8092 init_cfs_rq(&rq->cfs, rq);
8155 init_rt_rq(&rq->rt, rq); 8093 init_rt_rq(&rq->rt, rq);
8156#ifdef CONFIG_FAIR_GROUP_SCHED 8094#ifdef CONFIG_FAIR_GROUP_SCHED
@@ -8294,6 +8232,7 @@ EXPORT_SYMBOL(__might_sleep);
8294static void normalize_task(struct rq *rq, struct task_struct *p) 8232static void normalize_task(struct rq *rq, struct task_struct *p)
8295{ 8233{
8296 int on_rq; 8234 int on_rq;
8235
8297 update_rq_clock(rq); 8236 update_rq_clock(rq);
8298 on_rq = p->se.on_rq; 8237 on_rq = p->se.on_rq;
8299 if (on_rq) 8238 if (on_rq)
@@ -8325,7 +8264,6 @@ void normalize_rt_tasks(void)
8325 p->se.sleep_start = 0; 8264 p->se.sleep_start = 0;
8326 p->se.block_start = 0; 8265 p->se.block_start = 0;
8327#endif 8266#endif
8328 task_rq(p)->clock = 0;
8329 8267
8330 if (!rt_task(p)) { 8268 if (!rt_task(p)) {
8331 /* 8269 /*
@@ -8692,7 +8630,7 @@ static void __set_se_shares(struct sched_entity *se, unsigned long shares)
8692 dequeue_entity(cfs_rq, se, 0); 8630 dequeue_entity(cfs_rq, se, 0);
8693 8631
8694 se->load.weight = shares; 8632 se->load.weight = shares;
8695 se->load.inv_weight = div64_64((1ULL<<32), shares); 8633 se->load.inv_weight = 0;
8696 8634
8697 if (on_rq) 8635 if (on_rq)
8698 enqueue_entity(cfs_rq, se, 0); 8636 enqueue_entity(cfs_rq, se, 0);
@@ -8722,13 +8660,10 @@ int sched_group_set_shares(struct task_group *tg, unsigned long shares)
8722 if (!tg->se[0]) 8660 if (!tg->se[0])
8723 return -EINVAL; 8661 return -EINVAL;
8724 8662
8725 /*
8726 * A weight of 0 or 1 can cause arithmetics problems.
8727 * (The default weight is 1024 - so there's no practical
8728 * limitation from this.)
8729 */
8730 if (shares < MIN_SHARES) 8663 if (shares < MIN_SHARES)
8731 shares = MIN_SHARES; 8664 shares = MIN_SHARES;
8665 else if (shares > MAX_SHARES)
8666 shares = MAX_SHARES;
8732 8667
8733 mutex_lock(&shares_mutex); 8668 mutex_lock(&shares_mutex);
8734 if (tg->shares == shares) 8669 if (tg->shares == shares)
@@ -8753,7 +8688,7 @@ int sched_group_set_shares(struct task_group *tg, unsigned long shares)
8753 * force a rebalance 8688 * force a rebalance
8754 */ 8689 */
8755 cfs_rq_set_shares(tg->cfs_rq[i], 0); 8690 cfs_rq_set_shares(tg->cfs_rq[i], 0);
8756 set_se_shares(tg->se[i], shares/nr_cpu_ids); 8691 set_se_shares(tg->se[i], shares);
8757 } 8692 }
8758 8693
8759 /* 8694 /*
@@ -8787,7 +8722,7 @@ static unsigned long to_ratio(u64 period, u64 runtime)
8787 if (runtime == RUNTIME_INF) 8722 if (runtime == RUNTIME_INF)
8788 return 1ULL << 16; 8723 return 1ULL << 16;
8789 8724
8790 return div64_64(runtime << 16, period); 8725 return div64_u64(runtime << 16, period);
8791} 8726}
8792 8727
8793#ifdef CONFIG_CGROUP_SCHED 8728#ifdef CONFIG_CGROUP_SCHED
diff --git a/kernel/sched_clock.c b/kernel/sched_clock.c
new file mode 100644
index 000000000000..9c597e37f7de
--- /dev/null
+++ b/kernel/sched_clock.c
@@ -0,0 +1,236 @@
1/*
2 * sched_clock for unstable cpu clocks
3 *
4 * Copyright (C) 2008 Red Hat, Inc., Peter Zijlstra <pzijlstr@redhat.com>
5 *
6 * Based on code by:
7 * Ingo Molnar <mingo@redhat.com>
8 * Guillaume Chazarain <guichaz@gmail.com>
9 *
10 * Create a semi stable clock from a mixture of other events, including:
11 * - gtod
12 * - jiffies
13 * - sched_clock()
14 * - explicit idle events
15 *
16 * We use gtod as base and the unstable clock deltas. The deltas are filtered,
17 * making it monotonic and keeping it within an expected window. This window
18 * is set up using jiffies.
19 *
20 * Furthermore, explicit sleep and wakeup hooks allow us to account for time
21 * that is otherwise invisible (TSC gets stopped).
22 *
23 * The clock: sched_clock_cpu() is monotonic per cpu, and should be somewhat
24 * consistent between cpus (never more than 1 jiffies difference).
25 */
26#include <linux/sched.h>
27#include <linux/percpu.h>
28#include <linux/spinlock.h>
29#include <linux/ktime.h>
30#include <linux/module.h>
31
32
33#ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
34
35struct sched_clock_data {
36 /*
37 * Raw spinlock - this is a special case: this might be called
38 * from within instrumentation code so we dont want to do any
39 * instrumentation ourselves.
40 */
41 raw_spinlock_t lock;
42
43 unsigned long prev_jiffies;
44 u64 prev_raw;
45 u64 tick_raw;
46 u64 tick_gtod;
47 u64 clock;
48};
49
50static DEFINE_PER_CPU_SHARED_ALIGNED(struct sched_clock_data, sched_clock_data);
51
52static inline struct sched_clock_data *this_scd(void)
53{
54 return &__get_cpu_var(sched_clock_data);
55}
56
57static inline struct sched_clock_data *cpu_sdc(int cpu)
58{
59 return &per_cpu(sched_clock_data, cpu);
60}
61
62void sched_clock_init(void)
63{
64 u64 ktime_now = ktime_to_ns(ktime_get());
65 u64 now = 0;
66 int cpu;
67
68 for_each_possible_cpu(cpu) {
69 struct sched_clock_data *scd = cpu_sdc(cpu);
70
71 scd->lock = (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
72 scd->prev_jiffies = jiffies;
73 scd->prev_raw = now;
74 scd->tick_raw = now;
75 scd->tick_gtod = ktime_now;
76 scd->clock = ktime_now;
77 }
78}
79
80/*
81 * update the percpu scd from the raw @now value
82 *
83 * - filter out backward motion
84 * - use jiffies to generate a min,max window to clip the raw values
85 */
86static void __update_sched_clock(struct sched_clock_data *scd, u64 now)
87{
88 unsigned long now_jiffies = jiffies;
89 long delta_jiffies = now_jiffies - scd->prev_jiffies;
90 u64 clock = scd->clock;
91 u64 min_clock, max_clock;
92 s64 delta = now - scd->prev_raw;
93
94 WARN_ON_ONCE(!irqs_disabled());
95 min_clock = scd->tick_gtod + delta_jiffies * TICK_NSEC;
96
97 if (unlikely(delta < 0)) {
98 clock++;
99 goto out;
100 }
101
102 max_clock = min_clock + TICK_NSEC;
103
104 if (unlikely(clock + delta > max_clock)) {
105 if (clock < max_clock)
106 clock = max_clock;
107 else
108 clock++;
109 } else {
110 clock += delta;
111 }
112
113 out:
114 if (unlikely(clock < min_clock))
115 clock = min_clock;
116
117 scd->prev_raw = now;
118 scd->prev_jiffies = now_jiffies;
119 scd->clock = clock;
120}
121
122static void lock_double_clock(struct sched_clock_data *data1,
123 struct sched_clock_data *data2)
124{
125 if (data1 < data2) {
126 __raw_spin_lock(&data1->lock);
127 __raw_spin_lock(&data2->lock);
128 } else {
129 __raw_spin_lock(&data2->lock);
130 __raw_spin_lock(&data1->lock);
131 }
132}
133
134u64 sched_clock_cpu(int cpu)
135{
136 struct sched_clock_data *scd = cpu_sdc(cpu);
137 u64 now, clock;
138
139 WARN_ON_ONCE(!irqs_disabled());
140 now = sched_clock();
141
142 if (cpu != raw_smp_processor_id()) {
143 /*
144 * in order to update a remote cpu's clock based on our
145 * unstable raw time rebase it against:
146 * tick_raw (offset between raw counters)
147 * tick_gotd (tick offset between cpus)
148 */
149 struct sched_clock_data *my_scd = this_scd();
150
151 lock_double_clock(scd, my_scd);
152
153 now -= my_scd->tick_raw;
154 now += scd->tick_raw;
155
156 now -= my_scd->tick_gtod;
157 now += scd->tick_gtod;
158
159 __raw_spin_unlock(&my_scd->lock);
160 } else {
161 __raw_spin_lock(&scd->lock);
162 }
163
164 __update_sched_clock(scd, now);
165 clock = scd->clock;
166
167 __raw_spin_unlock(&scd->lock);
168
169 return clock;
170}
171
172void sched_clock_tick(void)
173{
174 struct sched_clock_data *scd = this_scd();
175 u64 now, now_gtod;
176
177 WARN_ON_ONCE(!irqs_disabled());
178
179 now = sched_clock();
180 now_gtod = ktime_to_ns(ktime_get());
181
182 __raw_spin_lock(&scd->lock);
183 __update_sched_clock(scd, now);
184 /*
185 * update tick_gtod after __update_sched_clock() because that will
186 * already observe 1 new jiffy; adding a new tick_gtod to that would
187 * increase the clock 2 jiffies.
188 */
189 scd->tick_raw = now;
190 scd->tick_gtod = now_gtod;
191 __raw_spin_unlock(&scd->lock);
192}
193
194/*
195 * We are going deep-idle (irqs are disabled):
196 */
197void sched_clock_idle_sleep_event(void)
198{
199 sched_clock_cpu(smp_processor_id());
200}
201EXPORT_SYMBOL_GPL(sched_clock_idle_sleep_event);
202
203/*
204 * We just idled delta nanoseconds (called with irqs disabled):
205 */
206void sched_clock_idle_wakeup_event(u64 delta_ns)
207{
208 struct sched_clock_data *scd = this_scd();
209 u64 now = sched_clock();
210
211 /*
212 * Override the previous timestamp and ignore all
213 * sched_clock() deltas that occured while we idled,
214 * and use the PM-provided delta_ns to advance the
215 * rq clock:
216 */
217 __raw_spin_lock(&scd->lock);
218 scd->prev_raw = now;
219 scd->clock += delta_ns;
220 __raw_spin_unlock(&scd->lock);
221
222 touch_softlockup_watchdog();
223}
224EXPORT_SYMBOL_GPL(sched_clock_idle_wakeup_event);
225
226#endif
227
228/*
229 * Scheduler clock - returns current time in nanosec units.
230 * This is default implementation.
231 * Architectures and sub-architectures can override this.
232 */
233unsigned long long __attribute__((weak)) sched_clock(void)
234{
235 return (unsigned long long)jiffies * (NSEC_PER_SEC / HZ);
236}
diff --git a/kernel/sched_debug.c b/kernel/sched_debug.c
index 8a9498e7c831..5f06118fbc31 100644
--- a/kernel/sched_debug.c
+++ b/kernel/sched_debug.c
@@ -204,13 +204,6 @@ static void print_cpu(struct seq_file *m, int cpu)
204 PN(next_balance); 204 PN(next_balance);
205 P(curr->pid); 205 P(curr->pid);
206 PN(clock); 206 PN(clock);
207 PN(idle_clock);
208 PN(prev_clock_raw);
209 P(clock_warps);
210 P(clock_overflows);
211 P(clock_underflows);
212 P(clock_deep_idle_events);
213 PN(clock_max_delta);
214 P(cpu_load[0]); 207 P(cpu_load[0]);
215 P(cpu_load[1]); 208 P(cpu_load[1]);
216 P(cpu_load[2]); 209 P(cpu_load[2]);
@@ -357,8 +350,8 @@ void proc_sched_show_task(struct task_struct *p, struct seq_file *m)
357 350
358 avg_per_cpu = p->se.sum_exec_runtime; 351 avg_per_cpu = p->se.sum_exec_runtime;
359 if (p->se.nr_migrations) { 352 if (p->se.nr_migrations) {
360 avg_per_cpu = div64_64(avg_per_cpu, 353 avg_per_cpu = div64_u64(avg_per_cpu,
361 p->se.nr_migrations); 354 p->se.nr_migrations);
362 } else { 355 } else {
363 avg_per_cpu = -1LL; 356 avg_per_cpu = -1LL;
364 } 357 }
diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
index 89fa32b4edf2..c863663d204d 100644
--- a/kernel/sched_fair.c
+++ b/kernel/sched_fair.c
@@ -682,6 +682,7 @@ enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int wakeup)
682 * Update run-time statistics of the 'current'. 682 * Update run-time statistics of the 'current'.
683 */ 683 */
684 update_curr(cfs_rq); 684 update_curr(cfs_rq);
685 account_entity_enqueue(cfs_rq, se);
685 686
686 if (wakeup) { 687 if (wakeup) {
687 place_entity(cfs_rq, se, 0); 688 place_entity(cfs_rq, se, 0);
@@ -692,7 +693,6 @@ enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int wakeup)
692 check_spread(cfs_rq, se); 693 check_spread(cfs_rq, se);
693 if (se != cfs_rq->curr) 694 if (se != cfs_rq->curr)
694 __enqueue_entity(cfs_rq, se); 695 __enqueue_entity(cfs_rq, se);
695 account_entity_enqueue(cfs_rq, se);
696} 696}
697 697
698static void update_avg(u64 *avg, u64 sample) 698static void update_avg(u64 *avg, u64 sample)
@@ -841,8 +841,10 @@ entity_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr, int queued)
841 * queued ticks are scheduled to match the slice, so don't bother 841 * queued ticks are scheduled to match the slice, so don't bother
842 * validating it and just reschedule. 842 * validating it and just reschedule.
843 */ 843 */
844 if (queued) 844 if (queued) {
845 return resched_task(rq_of(cfs_rq)->curr); 845 resched_task(rq_of(cfs_rq)->curr);
846 return;
847 }
846 /* 848 /*
847 * don't let the period tick interfere with the hrtick preemption 849 * don't let the period tick interfere with the hrtick preemption
848 */ 850 */
@@ -957,7 +959,7 @@ static void yield_task_fair(struct rq *rq)
957 return; 959 return;
958 960
959 if (likely(!sysctl_sched_compat_yield) && curr->policy != SCHED_BATCH) { 961 if (likely(!sysctl_sched_compat_yield) && curr->policy != SCHED_BATCH) {
960 __update_rq_clock(rq); 962 update_rq_clock(rq);
961 /* 963 /*
962 * Update run-time statistics of the 'current'. 964 * Update run-time statistics of the 'current'.
963 */ 965 */
@@ -1007,7 +1009,7 @@ static int wake_idle(int cpu, struct task_struct *p)
1007 * sibling runqueue info. This will avoid the checks and cache miss 1009 * sibling runqueue info. This will avoid the checks and cache miss
1008 * penalities associated with that. 1010 * penalities associated with that.
1009 */ 1011 */
1010 if (idle_cpu(cpu) || cpu_rq(cpu)->nr_running > 1) 1012 if (idle_cpu(cpu) || cpu_rq(cpu)->cfs.nr_running > 1)
1011 return cpu; 1013 return cpu;
1012 1014
1013 for_each_domain(cpu, sd) { 1015 for_each_domain(cpu, sd) {
@@ -1611,30 +1613,6 @@ static const struct sched_class fair_sched_class = {
1611}; 1613};
1612 1614
1613#ifdef CONFIG_SCHED_DEBUG 1615#ifdef CONFIG_SCHED_DEBUG
1614static void
1615print_cfs_rq_tasks(struct seq_file *m, struct cfs_rq *cfs_rq, int depth)
1616{
1617 struct sched_entity *se;
1618
1619 if (!cfs_rq)
1620 return;
1621
1622 list_for_each_entry_rcu(se, &cfs_rq->tasks, group_node) {
1623 int i;
1624
1625 for (i = depth; i; i--)
1626 seq_puts(m, " ");
1627
1628 seq_printf(m, "%lu %s %lu\n",
1629 se->load.weight,
1630 entity_is_task(se) ? "T" : "G",
1631 calc_delta_weight(SCHED_LOAD_SCALE, se)
1632 );
1633 if (!entity_is_task(se))
1634 print_cfs_rq_tasks(m, group_cfs_rq(se), depth + 1);
1635 }
1636}
1637
1638static void print_cfs_stats(struct seq_file *m, int cpu) 1616static void print_cfs_stats(struct seq_file *m, int cpu)
1639{ 1617{
1640 struct cfs_rq *cfs_rq; 1618 struct cfs_rq *cfs_rq;
@@ -1642,9 +1620,6 @@ static void print_cfs_stats(struct seq_file *m, int cpu)
1642 rcu_read_lock(); 1620 rcu_read_lock();
1643 for_each_leaf_cfs_rq(cpu_rq(cpu), cfs_rq) 1621 for_each_leaf_cfs_rq(cpu_rq(cpu), cfs_rq)
1644 print_cfs_rq(m, cpu, cfs_rq); 1622 print_cfs_rq(m, cpu, cfs_rq);
1645
1646 seq_printf(m, "\nWeight tree:\n");
1647 print_cfs_rq_tasks(m, &cpu_rq(cpu)->cfs, 1);
1648 rcu_read_unlock(); 1623 rcu_read_unlock();
1649} 1624}
1650#endif 1625#endif
diff --git a/kernel/sched_idletask.c b/kernel/sched_idletask.c
index 2bcafa375633..3a4f92dbbe66 100644
--- a/kernel/sched_idletask.c
+++ b/kernel/sched_idletask.c
@@ -99,7 +99,7 @@ static void prio_changed_idle(struct rq *rq, struct task_struct *p,
99/* 99/*
100 * Simple, special scheduling class for the per-CPU idle tasks: 100 * Simple, special scheduling class for the per-CPU idle tasks:
101 */ 101 */
102const struct sched_class idle_sched_class = { 102static const struct sched_class idle_sched_class = {
103 /* .next is NULL */ 103 /* .next is NULL */
104 /* no enqueue/yield_task for idle tasks */ 104 /* no enqueue/yield_task for idle tasks */
105 105
diff --git a/kernel/sched_rt.c b/kernel/sched_rt.c
index c2730a5a4f05..060e87b0cb1c 100644
--- a/kernel/sched_rt.c
+++ b/kernel/sched_rt.c
@@ -1098,11 +1098,14 @@ static void post_schedule_rt(struct rq *rq)
1098 } 1098 }
1099} 1099}
1100 1100
1101 1101/*
1102 * If we are not running and we are not going to reschedule soon, we should
1103 * try to push tasks away now
1104 */
1102static void task_wake_up_rt(struct rq *rq, struct task_struct *p) 1105static void task_wake_up_rt(struct rq *rq, struct task_struct *p)
1103{ 1106{
1104 if (!task_running(rq, p) && 1107 if (!task_running(rq, p) &&
1105 (p->prio >= rq->rt.highest_prio) && 1108 !test_tsk_need_resched(rq->curr) &&
1106 rq->rt.overloaded) 1109 rq->rt.overloaded)
1107 push_rt_tasks(rq); 1110 push_rt_tasks(rq);
1108} 1111}
@@ -1309,7 +1312,7 @@ static void set_curr_task_rt(struct rq *rq)
1309 p->se.exec_start = rq->clock; 1312 p->se.exec_start = rq->clock;
1310} 1313}
1311 1314
1312const struct sched_class rt_sched_class = { 1315static const struct sched_class rt_sched_class = {
1313 .next = &fair_sched_class, 1316 .next = &fair_sched_class,
1314 .enqueue_task = enqueue_task_rt, 1317 .enqueue_task = enqueue_task_rt,
1315 .dequeue_task = dequeue_task_rt, 1318 .dequeue_task = dequeue_task_rt,
diff --git a/kernel/signal.c b/kernel/signal.c
index 64ad0ed15992..72bb4f51f963 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -39,11 +39,19 @@
39 39
40static struct kmem_cache *sigqueue_cachep; 40static struct kmem_cache *sigqueue_cachep;
41 41
42static int __sig_ignored(struct task_struct *t, int sig)
43{
44 void __user *handler;
45
46 /* Is it explicitly or implicitly ignored? */
47
48 handler = t->sighand->action[sig - 1].sa.sa_handler;
49 return handler == SIG_IGN ||
50 (handler == SIG_DFL && sig_kernel_ignore(sig));
51}
42 52
43static int sig_ignored(struct task_struct *t, int sig) 53static int sig_ignored(struct task_struct *t, int sig)
44{ 54{
45 void __user * handler;
46
47 /* 55 /*
48 * Tracers always want to know about signals.. 56 * Tracers always want to know about signals..
49 */ 57 */
@@ -58,10 +66,7 @@ static int sig_ignored(struct task_struct *t, int sig)
58 if (sigismember(&t->blocked, sig) || sigismember(&t->real_blocked, sig)) 66 if (sigismember(&t->blocked, sig) || sigismember(&t->real_blocked, sig))
59 return 0; 67 return 0;
60 68
61 /* Is it explicitly or implicitly ignored? */ 69 return __sig_ignored(t, sig);
62 handler = t->sighand->action[sig-1].sa.sa_handler;
63 return handler == SIG_IGN ||
64 (handler == SIG_DFL && sig_kernel_ignore(sig));
65} 70}
66 71
67/* 72/*
@@ -372,7 +377,7 @@ static int __dequeue_signal(struct sigpending *pending, sigset_t *mask,
372 */ 377 */
373int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info) 378int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info)
374{ 379{
375 int signr = 0; 380 int signr;
376 381
377 /* We only dequeue private signals from ourselves, we don't let 382 /* We only dequeue private signals from ourselves, we don't let
378 * signalfd steal them 383 * signalfd steal them
@@ -405,8 +410,12 @@ int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info)
405 } 410 }
406 } 411 }
407 } 412 }
413
408 recalc_sigpending(); 414 recalc_sigpending();
409 if (signr && unlikely(sig_kernel_stop(signr))) { 415 if (!signr)
416 return 0;
417
418 if (unlikely(sig_kernel_stop(signr))) {
410 /* 419 /*
411 * Set a marker that we have dequeued a stop signal. Our 420 * Set a marker that we have dequeued a stop signal. Our
412 * caller might release the siglock and then the pending 421 * caller might release the siglock and then the pending
@@ -422,9 +431,7 @@ int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info)
422 if (!(tsk->signal->flags & SIGNAL_GROUP_EXIT)) 431 if (!(tsk->signal->flags & SIGNAL_GROUP_EXIT))
423 tsk->signal->flags |= SIGNAL_STOP_DEQUEUED; 432 tsk->signal->flags |= SIGNAL_STOP_DEQUEUED;
424 } 433 }
425 if (signr && 434 if ((info->si_code & __SI_MASK) == __SI_TIMER && info->si_sys_private) {
426 ((info->si_code & __SI_MASK) == __SI_TIMER) &&
427 info->si_sys_private) {
428 /* 435 /*
429 * Release the siglock to ensure proper locking order 436 * Release the siglock to ensure proper locking order
430 * of timer locks outside of siglocks. Note, we leave 437 * of timer locks outside of siglocks. Note, we leave
@@ -526,21 +533,34 @@ static int rm_from_queue(unsigned long mask, struct sigpending *s)
526static int check_kill_permission(int sig, struct siginfo *info, 533static int check_kill_permission(int sig, struct siginfo *info,
527 struct task_struct *t) 534 struct task_struct *t)
528{ 535{
529 int error = -EINVAL; 536 struct pid *sid;
537 int error;
538
530 if (!valid_signal(sig)) 539 if (!valid_signal(sig))
531 return error; 540 return -EINVAL;
532 541
533 if (info == SEND_SIG_NOINFO || (!is_si_special(info) && SI_FROMUSER(info))) { 542 if (info != SEND_SIG_NOINFO && (is_si_special(info) || SI_FROMKERNEL(info)))
534 error = audit_signal_info(sig, t); /* Let audit system see the signal */ 543 return 0;
535 if (error) 544
536 return error; 545 error = audit_signal_info(sig, t); /* Let audit system see the signal */
537 error = -EPERM; 546 if (error)
538 if (((sig != SIGCONT) ||
539 (task_session_nr(current) != task_session_nr(t)))
540 && (current->euid ^ t->suid) && (current->euid ^ t->uid)
541 && (current->uid ^ t->suid) && (current->uid ^ t->uid)
542 && !capable(CAP_KILL))
543 return error; 547 return error;
548
549 if ((current->euid ^ t->suid) && (current->euid ^ t->uid) &&
550 (current->uid ^ t->suid) && (current->uid ^ t->uid) &&
551 !capable(CAP_KILL)) {
552 switch (sig) {
553 case SIGCONT:
554 sid = task_session(t);
555 /*
556 * We don't return the error if sid == NULL. The
557 * task was unhashed, the caller must notice this.
558 */
559 if (!sid || sid == task_session(current))
560 break;
561 default:
562 return -EPERM;
563 }
544 } 564 }
545 565
546 return security_task_kill(t, info, sig, 0); 566 return security_task_kill(t, info, sig, 0);
@@ -550,62 +570,44 @@ static int check_kill_permission(int sig, struct siginfo *info,
550static void do_notify_parent_cldstop(struct task_struct *tsk, int why); 570static void do_notify_parent_cldstop(struct task_struct *tsk, int why);
551 571
552/* 572/*
553 * Handle magic process-wide effects of stop/continue signals. 573 * Handle magic process-wide effects of stop/continue signals. Unlike
554 * Unlike the signal actions, these happen immediately at signal-generation 574 * the signal actions, these happen immediately at signal-generation
555 * time regardless of blocking, ignoring, or handling. This does the 575 * time regardless of blocking, ignoring, or handling. This does the
556 * actual continuing for SIGCONT, but not the actual stopping for stop 576 * actual continuing for SIGCONT, but not the actual stopping for stop
557 * signals. The process stop is done as a signal action for SIG_DFL. 577 * signals. The process stop is done as a signal action for SIG_DFL.
578 *
579 * Returns true if the signal should be actually delivered, otherwise
580 * it should be dropped.
558 */ 581 */
559static void handle_stop_signal(int sig, struct task_struct *p) 582static int prepare_signal(int sig, struct task_struct *p)
560{ 583{
584 struct signal_struct *signal = p->signal;
561 struct task_struct *t; 585 struct task_struct *t;
562 586
563 if (p->signal->flags & SIGNAL_GROUP_EXIT) 587 if (unlikely(signal->flags & SIGNAL_GROUP_EXIT)) {
564 /* 588 /*
565 * The process is in the middle of dying already. 589 * The process is in the middle of dying, nothing to do.
566 */ 590 */
567 return; 591 } else if (sig_kernel_stop(sig)) {
568
569 if (sig_kernel_stop(sig)) {
570 /* 592 /*
571 * This is a stop signal. Remove SIGCONT from all queues. 593 * This is a stop signal. Remove SIGCONT from all queues.
572 */ 594 */
573 rm_from_queue(sigmask(SIGCONT), &p->signal->shared_pending); 595 rm_from_queue(sigmask(SIGCONT), &signal->shared_pending);
574 t = p; 596 t = p;
575 do { 597 do {
576 rm_from_queue(sigmask(SIGCONT), &t->pending); 598 rm_from_queue(sigmask(SIGCONT), &t->pending);
577 t = next_thread(t); 599 } while_each_thread(p, t);
578 } while (t != p);
579 } else if (sig == SIGCONT) { 600 } else if (sig == SIGCONT) {
601 unsigned int why;
580 /* 602 /*
581 * Remove all stop signals from all queues, 603 * Remove all stop signals from all queues,
582 * and wake all threads. 604 * and wake all threads.
583 */ 605 */
584 if (unlikely(p->signal->group_stop_count > 0)) { 606 rm_from_queue(SIG_KERNEL_STOP_MASK, &signal->shared_pending);
585 /*
586 * There was a group stop in progress. We'll
587 * pretend it finished before we got here. We are
588 * obliged to report it to the parent: if the
589 * SIGSTOP happened "after" this SIGCONT, then it
590 * would have cleared this pending SIGCONT. If it
591 * happened "before" this SIGCONT, then the parent
592 * got the SIGCHLD about the stop finishing before
593 * the continue happened. We do the notification
594 * now, and it's as if the stop had finished and
595 * the SIGCHLD was pending on entry to this kill.
596 */
597 p->signal->group_stop_count = 0;
598 p->signal->flags = SIGNAL_STOP_CONTINUED;
599 spin_unlock(&p->sighand->siglock);
600 do_notify_parent_cldstop(p, CLD_STOPPED);
601 spin_lock(&p->sighand->siglock);
602 }
603 rm_from_queue(SIG_KERNEL_STOP_MASK, &p->signal->shared_pending);
604 t = p; 607 t = p;
605 do { 608 do {
606 unsigned int state; 609 unsigned int state;
607 rm_from_queue(SIG_KERNEL_STOP_MASK, &t->pending); 610 rm_from_queue(SIG_KERNEL_STOP_MASK, &t->pending);
608
609 /* 611 /*
610 * If there is a handler for SIGCONT, we must make 612 * If there is a handler for SIGCONT, we must make
611 * sure that no thread returns to user mode before 613 * sure that no thread returns to user mode before
@@ -615,7 +617,7 @@ static void handle_stop_signal(int sig, struct task_struct *p)
615 * running the handler. With the TIF_SIGPENDING 617 * running the handler. With the TIF_SIGPENDING
616 * flag set, the thread will pause and acquire the 618 * flag set, the thread will pause and acquire the
617 * siglock that we hold now and until we've queued 619 * siglock that we hold now and until we've queued
618 * the pending signal. 620 * the pending signal.
619 * 621 *
620 * Wake up the stopped thread _after_ setting 622 * Wake up the stopped thread _after_ setting
621 * TIF_SIGPENDING 623 * TIF_SIGPENDING
@@ -626,49 +628,163 @@ static void handle_stop_signal(int sig, struct task_struct *p)
626 state |= TASK_INTERRUPTIBLE; 628 state |= TASK_INTERRUPTIBLE;
627 } 629 }
628 wake_up_state(t, state); 630 wake_up_state(t, state);
631 } while_each_thread(p, t);
629 632
630 t = next_thread(t); 633 /*
631 } while (t != p); 634 * Notify the parent with CLD_CONTINUED if we were stopped.
635 *
636 * If we were in the middle of a group stop, we pretend it
637 * was already finished, and then continued. Since SIGCHLD
638 * doesn't queue we report only CLD_STOPPED, as if the next
639 * CLD_CONTINUED was dropped.
640 */
641 why = 0;
642 if (signal->flags & SIGNAL_STOP_STOPPED)
643 why |= SIGNAL_CLD_CONTINUED;
644 else if (signal->group_stop_count)
645 why |= SIGNAL_CLD_STOPPED;
632 646
633 if (p->signal->flags & SIGNAL_STOP_STOPPED) { 647 if (why) {
634 /* 648 /*
635 * We were in fact stopped, and are now continued. 649 * The first thread which returns from finish_stop()
636 * Notify the parent with CLD_CONTINUED. 650 * will take ->siglock, notice SIGNAL_CLD_MASK, and
651 * notify its parent. See get_signal_to_deliver().
637 */ 652 */
638 p->signal->flags = SIGNAL_STOP_CONTINUED; 653 signal->flags = why | SIGNAL_STOP_CONTINUED;
639 p->signal->group_exit_code = 0; 654 signal->group_stop_count = 0;
640 spin_unlock(&p->sighand->siglock); 655 signal->group_exit_code = 0;
641 do_notify_parent_cldstop(p, CLD_CONTINUED);
642 spin_lock(&p->sighand->siglock);
643 } else { 656 } else {
644 /* 657 /*
645 * We are not stopped, but there could be a stop 658 * We are not stopped, but there could be a stop
646 * signal in the middle of being processed after 659 * signal in the middle of being processed after
647 * being removed from the queue. Clear that too. 660 * being removed from the queue. Clear that too.
648 */ 661 */
649 p->signal->flags = 0; 662 signal->flags &= ~SIGNAL_STOP_DEQUEUED;
650 } 663 }
651 } else if (sig == SIGKILL) { 664 }
665
666 return !sig_ignored(p, sig);
667}
668
669/*
670 * Test if P wants to take SIG. After we've checked all threads with this,
671 * it's equivalent to finding no threads not blocking SIG. Any threads not
672 * blocking SIG were ruled out because they are not running and already
673 * have pending signals. Such threads will dequeue from the shared queue
674 * as soon as they're available, so putting the signal on the shared queue
675 * will be equivalent to sending it to one such thread.
676 */
677static inline int wants_signal(int sig, struct task_struct *p)
678{
679 if (sigismember(&p->blocked, sig))
680 return 0;
681 if (p->flags & PF_EXITING)
682 return 0;
683 if (sig == SIGKILL)
684 return 1;
685 if (task_is_stopped_or_traced(p))
686 return 0;
687 return task_curr(p) || !signal_pending(p);
688}
689
690static void complete_signal(int sig, struct task_struct *p, int group)
691{
692 struct signal_struct *signal = p->signal;
693 struct task_struct *t;
694
695 /*
696 * Now find a thread we can wake up to take the signal off the queue.
697 *
698 * If the main thread wants the signal, it gets first crack.
699 * Probably the least surprising to the average bear.
700 */
701 if (wants_signal(sig, p))
702 t = p;
703 else if (!group || thread_group_empty(p))
704 /*
705 * There is just one thread and it does not need to be woken.
706 * It will dequeue unblocked signals before it runs again.
707 */
708 return;
709 else {
652 /* 710 /*
653 * Make sure that any pending stop signal already dequeued 711 * Otherwise try to find a suitable thread.
654 * is undone by the wakeup for SIGKILL.
655 */ 712 */
656 p->signal->flags = 0; 713 t = signal->curr_target;
714 while (!wants_signal(sig, t)) {
715 t = next_thread(t);
716 if (t == signal->curr_target)
717 /*
718 * No thread needs to be woken.
719 * Any eligible threads will see
720 * the signal in the queue soon.
721 */
722 return;
723 }
724 signal->curr_target = t;
657 } 725 }
726
727 /*
728 * Found a killable thread. If the signal will be fatal,
729 * then start taking the whole group down immediately.
730 */
731 if (sig_fatal(p, sig) &&
732 !(signal->flags & (SIGNAL_UNKILLABLE | SIGNAL_GROUP_EXIT)) &&
733 !sigismember(&t->real_blocked, sig) &&
734 (sig == SIGKILL || !(t->ptrace & PT_PTRACED))) {
735 /*
736 * This signal will be fatal to the whole group.
737 */
738 if (!sig_kernel_coredump(sig)) {
739 /*
740 * Start a group exit and wake everybody up.
741 * This way we don't have other threads
742 * running and doing things after a slower
743 * thread has the fatal signal pending.
744 */
745 signal->flags = SIGNAL_GROUP_EXIT;
746 signal->group_exit_code = sig;
747 signal->group_stop_count = 0;
748 t = p;
749 do {
750 sigaddset(&t->pending.signal, SIGKILL);
751 signal_wake_up(t, 1);
752 } while_each_thread(p, t);
753 return;
754 }
755 }
756
757 /*
758 * The signal is already in the shared-pending queue.
759 * Tell the chosen thread to wake up and dequeue it.
760 */
761 signal_wake_up(t, sig == SIGKILL);
762 return;
763}
764
765static inline int legacy_queue(struct sigpending *signals, int sig)
766{
767 return (sig < SIGRTMIN) && sigismember(&signals->signal, sig);
658} 768}
659 769
660static int send_signal(int sig, struct siginfo *info, struct task_struct *t, 770static int send_signal(int sig, struct siginfo *info, struct task_struct *t,
661 struct sigpending *signals) 771 int group)
662{ 772{
663 struct sigqueue * q = NULL; 773 struct sigpending *pending;
664 int ret = 0; 774 struct sigqueue *q;
775
776 assert_spin_locked(&t->sighand->siglock);
777 if (!prepare_signal(sig, t))
778 return 0;
665 779
780 pending = group ? &t->signal->shared_pending : &t->pending;
666 /* 781 /*
667 * Deliver the signal to listening signalfds. This must be called 782 * Short-circuit ignored signals and support queuing
668 * with the sighand lock held. 783 * exactly one non-rt signal, so that we can get more
784 * detailed information about the cause of the signal.
669 */ 785 */
670 signalfd_notify(t, sig); 786 if (legacy_queue(pending, sig))
671 787 return 0;
672 /* 788 /*
673 * fast-pathed signals for kernel-internal things like SIGSTOP 789 * fast-pathed signals for kernel-internal things like SIGSTOP
674 * or SIGKILL. 790 * or SIGKILL.
@@ -688,7 +804,7 @@ static int send_signal(int sig, struct siginfo *info, struct task_struct *t,
688 (is_si_special(info) || 804 (is_si_special(info) ||
689 info->si_code >= 0))); 805 info->si_code >= 0)));
690 if (q) { 806 if (q) {
691 list_add_tail(&q->list, &signals->list); 807 list_add_tail(&q->list, &pending->list);
692 switch ((unsigned long) info) { 808 switch ((unsigned long) info) {
693 case (unsigned long) SEND_SIG_NOINFO: 809 case (unsigned long) SEND_SIG_NOINFO:
694 q->info.si_signo = sig; 810 q->info.si_signo = sig;
@@ -718,13 +834,12 @@ static int send_signal(int sig, struct siginfo *info, struct task_struct *t,
718 } 834 }
719 835
720out_set: 836out_set:
721 sigaddset(&signals->signal, sig); 837 signalfd_notify(t, sig);
722 return ret; 838 sigaddset(&pending->signal, sig);
839 complete_signal(sig, t, group);
840 return 0;
723} 841}
724 842
725#define LEGACY_QUEUE(sigptr, sig) \
726 (((sig) < SIGRTMIN) && sigismember(&(sigptr)->signal, (sig)))
727
728int print_fatal_signals; 843int print_fatal_signals;
729 844
730static void print_fatal_signal(struct pt_regs *regs, int signr) 845static void print_fatal_signal(struct pt_regs *regs, int signr)
@@ -757,29 +872,16 @@ static int __init setup_print_fatal_signals(char *str)
757 872
758__setup("print-fatal-signals=", setup_print_fatal_signals); 873__setup("print-fatal-signals=", setup_print_fatal_signals);
759 874
875int
876__group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
877{
878 return send_signal(sig, info, p, 1);
879}
880
760static int 881static int
761specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t) 882specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
762{ 883{
763 int ret = 0; 884 return send_signal(sig, info, t, 0);
764
765 BUG_ON(!irqs_disabled());
766 assert_spin_locked(&t->sighand->siglock);
767
768 /* Short-circuit ignored signals. */
769 if (sig_ignored(t, sig))
770 goto out;
771
772 /* Support queueing exactly one non-rt signal, so that we
773 can get more detailed information about the cause of
774 the signal. */
775 if (LEGACY_QUEUE(&t->pending, sig))
776 goto out;
777
778 ret = send_signal(sig, info, t, &t->pending);
779 if (!ret && !sigismember(&t->blocked, sig))
780 signal_wake_up(t, sig == SIGKILL);
781out:
782 return ret;
783} 885}
784 886
785/* 887/*
@@ -790,7 +892,8 @@ out:
790 * since we do not want to have a signal handler that was blocked 892 * since we do not want to have a signal handler that was blocked
791 * be invoked when user space had explicitly blocked it. 893 * be invoked when user space had explicitly blocked it.
792 * 894 *
793 * We don't want to have recursive SIGSEGV's etc, for example. 895 * We don't want to have recursive SIGSEGV's etc, for example,
896 * that is why we also clear SIGNAL_UNKILLABLE.
794 */ 897 */
795int 898int
796force_sig_info(int sig, struct siginfo *info, struct task_struct *t) 899force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
@@ -810,6 +913,8 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
810 recalc_sigpending_and_wake(t); 913 recalc_sigpending_and_wake(t);
811 } 914 }
812 } 915 }
916 if (action->sa.sa_handler == SIG_DFL)
917 t->signal->flags &= ~SIGNAL_UNKILLABLE;
813 ret = specific_send_sig_info(sig, info, t); 918 ret = specific_send_sig_info(sig, info, t);
814 spin_unlock_irqrestore(&t->sighand->siglock, flags); 919 spin_unlock_irqrestore(&t->sighand->siglock, flags);
815 920
@@ -823,134 +928,6 @@ force_sig_specific(int sig, struct task_struct *t)
823} 928}
824 929
825/* 930/*
826 * Test if P wants to take SIG. After we've checked all threads with this,
827 * it's equivalent to finding no threads not blocking SIG. Any threads not
828 * blocking SIG were ruled out because they are not running and already
829 * have pending signals. Such threads will dequeue from the shared queue
830 * as soon as they're available, so putting the signal on the shared queue
831 * will be equivalent to sending it to one such thread.
832 */
833static inline int wants_signal(int sig, struct task_struct *p)
834{
835 if (sigismember(&p->blocked, sig))
836 return 0;
837 if (p->flags & PF_EXITING)
838 return 0;
839 if (sig == SIGKILL)
840 return 1;
841 if (task_is_stopped_or_traced(p))
842 return 0;
843 return task_curr(p) || !signal_pending(p);
844}
845
846static void
847__group_complete_signal(int sig, struct task_struct *p)
848{
849 struct task_struct *t;
850
851 /*
852 * Now find a thread we can wake up to take the signal off the queue.
853 *
854 * If the main thread wants the signal, it gets first crack.
855 * Probably the least surprising to the average bear.
856 */
857 if (wants_signal(sig, p))
858 t = p;
859 else if (thread_group_empty(p))
860 /*
861 * There is just one thread and it does not need to be woken.
862 * It will dequeue unblocked signals before it runs again.
863 */
864 return;
865 else {
866 /*
867 * Otherwise try to find a suitable thread.
868 */
869 t = p->signal->curr_target;
870 if (t == NULL)
871 /* restart balancing at this thread */
872 t = p->signal->curr_target = p;
873
874 while (!wants_signal(sig, t)) {
875 t = next_thread(t);
876 if (t == p->signal->curr_target)
877 /*
878 * No thread needs to be woken.
879 * Any eligible threads will see
880 * the signal in the queue soon.
881 */
882 return;
883 }
884 p->signal->curr_target = t;
885 }
886
887 /*
888 * Found a killable thread. If the signal will be fatal,
889 * then start taking the whole group down immediately.
890 */
891 if (sig_fatal(p, sig) && !(p->signal->flags & SIGNAL_GROUP_EXIT) &&
892 !sigismember(&t->real_blocked, sig) &&
893 (sig == SIGKILL || !(t->ptrace & PT_PTRACED))) {
894 /*
895 * This signal will be fatal to the whole group.
896 */
897 if (!sig_kernel_coredump(sig)) {
898 /*
899 * Start a group exit and wake everybody up.
900 * This way we don't have other threads
901 * running and doing things after a slower
902 * thread has the fatal signal pending.
903 */
904 p->signal->flags = SIGNAL_GROUP_EXIT;
905 p->signal->group_exit_code = sig;
906 p->signal->group_stop_count = 0;
907 t = p;
908 do {
909 sigaddset(&t->pending.signal, SIGKILL);
910 signal_wake_up(t, 1);
911 } while_each_thread(p, t);
912 return;
913 }
914 }
915
916 /*
917 * The signal is already in the shared-pending queue.
918 * Tell the chosen thread to wake up and dequeue it.
919 */
920 signal_wake_up(t, sig == SIGKILL);
921 return;
922}
923
924int
925__group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
926{
927 int ret = 0;
928
929 assert_spin_locked(&p->sighand->siglock);
930 handle_stop_signal(sig, p);
931
932 /* Short-circuit ignored signals. */
933 if (sig_ignored(p, sig))
934 return ret;
935
936 if (LEGACY_QUEUE(&p->signal->shared_pending, sig))
937 /* This is a non-RT signal and we already have one queued. */
938 return ret;
939
940 /*
941 * Put this signal on the shared-pending queue, or fail with EAGAIN.
942 * We always use the shared queue for process-wide signals,
943 * to avoid several races.
944 */
945 ret = send_signal(sig, info, p, &p->signal->shared_pending);
946 if (unlikely(ret))
947 return ret;
948
949 __group_complete_signal(sig, p);
950 return 0;
951}
952
953/*
954 * Nuke all other threads in the group. 931 * Nuke all other threads in the group.
955 */ 932 */
956void zap_other_threads(struct task_struct *p) 933void zap_other_threads(struct task_struct *p)
@@ -978,13 +955,11 @@ int __fatal_signal_pending(struct task_struct *tsk)
978} 955}
979EXPORT_SYMBOL(__fatal_signal_pending); 956EXPORT_SYMBOL(__fatal_signal_pending);
980 957
981/*
982 * Must be called under rcu_read_lock() or with tasklist_lock read-held.
983 */
984struct sighand_struct *lock_task_sighand(struct task_struct *tsk, unsigned long *flags) 958struct sighand_struct *lock_task_sighand(struct task_struct *tsk, unsigned long *flags)
985{ 959{
986 struct sighand_struct *sighand; 960 struct sighand_struct *sighand;
987 961
962 rcu_read_lock();
988 for (;;) { 963 for (;;) {
989 sighand = rcu_dereference(tsk->sighand); 964 sighand = rcu_dereference(tsk->sighand);
990 if (unlikely(sighand == NULL)) 965 if (unlikely(sighand == NULL))
@@ -995,6 +970,7 @@ struct sighand_struct *lock_task_sighand(struct task_struct *tsk, unsigned long
995 break; 970 break;
996 spin_unlock_irqrestore(&sighand->siglock, *flags); 971 spin_unlock_irqrestore(&sighand->siglock, *flags);
997 } 972 }
973 rcu_read_unlock();
998 974
999 return sighand; 975 return sighand;
1000} 976}
@@ -1043,9 +1019,6 @@ int kill_pid_info(int sig, struct siginfo *info, struct pid *pid)
1043 struct task_struct *p; 1019 struct task_struct *p;
1044 1020
1045 rcu_read_lock(); 1021 rcu_read_lock();
1046 if (unlikely(sig_needs_tasklist(sig)))
1047 read_lock(&tasklist_lock);
1048
1049retry: 1022retry:
1050 p = pid_task(pid, PIDTYPE_PID); 1023 p = pid_task(pid, PIDTYPE_PID);
1051 if (p) { 1024 if (p) {
@@ -1059,10 +1032,8 @@ retry:
1059 */ 1032 */
1060 goto retry; 1033 goto retry;
1061 } 1034 }
1062
1063 if (unlikely(sig_needs_tasklist(sig)))
1064 read_unlock(&tasklist_lock);
1065 rcu_read_unlock(); 1035 rcu_read_unlock();
1036
1066 return error; 1037 return error;
1067} 1038}
1068 1039
@@ -1159,8 +1130,7 @@ static int kill_something_info(int sig, struct siginfo *info, int pid)
1159 */ 1130 */
1160 1131
1161/* 1132/*
1162 * These two are the most common entry points. They send a signal 1133 * The caller must ensure the task can't exit.
1163 * just to the specific thread.
1164 */ 1134 */
1165int 1135int
1166send_sig_info(int sig, struct siginfo *info, struct task_struct *p) 1136send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
@@ -1175,17 +1145,9 @@ send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
1175 if (!valid_signal(sig)) 1145 if (!valid_signal(sig))
1176 return -EINVAL; 1146 return -EINVAL;
1177 1147
1178 /*
1179 * We need the tasklist lock even for the specific
1180 * thread case (when we don't need to follow the group
1181 * lists) in order to avoid races with "p->sighand"
1182 * going away or changing from under us.
1183 */
1184 read_lock(&tasklist_lock);
1185 spin_lock_irqsave(&p->sighand->siglock, flags); 1148 spin_lock_irqsave(&p->sighand->siglock, flags);
1186 ret = specific_send_sig_info(sig, info, p); 1149 ret = specific_send_sig_info(sig, info, p);
1187 spin_unlock_irqrestore(&p->sighand->siglock, flags); 1150 spin_unlock_irqrestore(&p->sighand->siglock, flags);
1188 read_unlock(&tasklist_lock);
1189 return ret; 1151 return ret;
1190} 1152}
1191 1153
@@ -1291,28 +1253,24 @@ void sigqueue_free(struct sigqueue *q)
1291 __sigqueue_free(q); 1253 __sigqueue_free(q);
1292} 1254}
1293 1255
1294int send_sigqueue(int sig, struct sigqueue *q, struct task_struct *p) 1256int send_sigqueue(struct sigqueue *q, struct task_struct *t, int group)
1295{ 1257{
1258 int sig = q->info.si_signo;
1259 struct sigpending *pending;
1296 unsigned long flags; 1260 unsigned long flags;
1297 int ret = 0; 1261 int ret;
1298 1262
1299 BUG_ON(!(q->flags & SIGQUEUE_PREALLOC)); 1263 BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
1300 1264
1301 /* 1265 ret = -1;
1302 * The rcu based delayed sighand destroy makes it possible to 1266 if (!likely(lock_task_sighand(t, &flags)))
1303 * run this without tasklist lock held. The task struct itself 1267 goto ret;
1304 * cannot go away as create_timer did get_task_struct().
1305 *
1306 * We return -1, when the task is marked exiting, so
1307 * posix_timer_event can redirect it to the group leader
1308 */
1309 rcu_read_lock();
1310 1268
1311 if (!likely(lock_task_sighand(p, &flags))) { 1269 ret = 1; /* the signal is ignored */
1312 ret = -1; 1270 if (!prepare_signal(sig, t))
1313 goto out_err; 1271 goto out;
1314 }
1315 1272
1273 ret = 0;
1316 if (unlikely(!list_empty(&q->list))) { 1274 if (unlikely(!list_empty(&q->list))) {
1317 /* 1275 /*
1318 * If an SI_TIMER entry is already queue just increment 1276 * If an SI_TIMER entry is already queue just increment
@@ -1322,77 +1280,15 @@ int send_sigqueue(int sig, struct sigqueue *q, struct task_struct *p)
1322 q->info.si_overrun++; 1280 q->info.si_overrun++;
1323 goto out; 1281 goto out;
1324 } 1282 }
1325 /* Short-circuit ignored signals. */
1326 if (sig_ignored(p, sig)) {
1327 ret = 1;
1328 goto out;
1329 }
1330 /*
1331 * Deliver the signal to listening signalfds. This must be called
1332 * with the sighand lock held.
1333 */
1334 signalfd_notify(p, sig);
1335
1336 list_add_tail(&q->list, &p->pending.list);
1337 sigaddset(&p->pending.signal, sig);
1338 if (!sigismember(&p->blocked, sig))
1339 signal_wake_up(p, sig == SIGKILL);
1340
1341out:
1342 unlock_task_sighand(p, &flags);
1343out_err:
1344 rcu_read_unlock();
1345
1346 return ret;
1347}
1348
1349int
1350send_group_sigqueue(int sig, struct sigqueue *q, struct task_struct *p)
1351{
1352 unsigned long flags;
1353 int ret = 0;
1354
1355 BUG_ON(!(q->flags & SIGQUEUE_PREALLOC));
1356
1357 read_lock(&tasklist_lock);
1358 /* Since it_lock is held, p->sighand cannot be NULL. */
1359 spin_lock_irqsave(&p->sighand->siglock, flags);
1360 handle_stop_signal(sig, p);
1361
1362 /* Short-circuit ignored signals. */
1363 if (sig_ignored(p, sig)) {
1364 ret = 1;
1365 goto out;
1366 }
1367 1283
1368 if (unlikely(!list_empty(&q->list))) { 1284 signalfd_notify(t, sig);
1369 /* 1285 pending = group ? &t->signal->shared_pending : &t->pending;
1370 * If an SI_TIMER entry is already queue just increment 1286 list_add_tail(&q->list, &pending->list);
1371 * the overrun count. Other uses should not try to 1287 sigaddset(&pending->signal, sig);
1372 * send the signal multiple times. 1288 complete_signal(sig, t, group);
1373 */
1374 BUG_ON(q->info.si_code != SI_TIMER);
1375 q->info.si_overrun++;
1376 goto out;
1377 }
1378 /*
1379 * Deliver the signal to listening signalfds. This must be called
1380 * with the sighand lock held.
1381 */
1382 signalfd_notify(p, sig);
1383
1384 /*
1385 * Put this signal on the shared-pending queue.
1386 * We always use the shared queue for process-wide signals,
1387 * to avoid several races.
1388 */
1389 list_add_tail(&q->list, &p->signal->shared_pending.list);
1390 sigaddset(&p->signal->shared_pending.signal, sig);
1391
1392 __group_complete_signal(sig, p);
1393out: 1289out:
1394 spin_unlock_irqrestore(&p->sighand->siglock, flags); 1290 unlock_task_sighand(t, &flags);
1395 read_unlock(&tasklist_lock); 1291ret:
1396 return ret; 1292 return ret;
1397} 1293}
1398 1294
@@ -1723,8 +1619,9 @@ static int do_signal_stop(int signr)
1723 } else { 1619 } else {
1724 struct task_struct *t; 1620 struct task_struct *t;
1725 1621
1726 if (!likely(sig->flags & SIGNAL_STOP_DEQUEUED) || 1622 if (unlikely((sig->flags & (SIGNAL_STOP_DEQUEUED | SIGNAL_UNKILLABLE))
1727 unlikely(sig->group_exit_task)) 1623 != SIGNAL_STOP_DEQUEUED) ||
1624 unlikely(signal_group_exit(sig)))
1728 return 0; 1625 return 0;
1729 /* 1626 /*
1730 * There is no group stop already in progress. 1627 * There is no group stop already in progress.
@@ -1799,8 +1696,9 @@ static int ptrace_signal(int signr, siginfo_t *info,
1799int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, 1696int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka,
1800 struct pt_regs *regs, void *cookie) 1697 struct pt_regs *regs, void *cookie)
1801{ 1698{
1802 sigset_t *mask = &current->blocked; 1699 struct sighand_struct *sighand = current->sighand;
1803 int signr = 0; 1700 struct signal_struct *signal = current->signal;
1701 int signr;
1804 1702
1805relock: 1703relock:
1806 /* 1704 /*
@@ -1811,16 +1709,32 @@ relock:
1811 */ 1709 */
1812 try_to_freeze(); 1710 try_to_freeze();
1813 1711
1814 spin_lock_irq(&current->sighand->siglock); 1712 spin_lock_irq(&sighand->siglock);
1713 /*
1714 * Every stopped thread goes here after wakeup. Check to see if
1715 * we should notify the parent, prepare_signal(SIGCONT) encodes
1716 * the CLD_ si_code into SIGNAL_CLD_MASK bits.
1717 */
1718 if (unlikely(signal->flags & SIGNAL_CLD_MASK)) {
1719 int why = (signal->flags & SIGNAL_STOP_CONTINUED)
1720 ? CLD_CONTINUED : CLD_STOPPED;
1721 signal->flags &= ~SIGNAL_CLD_MASK;
1722 spin_unlock_irq(&sighand->siglock);
1723
1724 read_lock(&tasklist_lock);
1725 do_notify_parent_cldstop(current->group_leader, why);
1726 read_unlock(&tasklist_lock);
1727 goto relock;
1728 }
1729
1815 for (;;) { 1730 for (;;) {
1816 struct k_sigaction *ka; 1731 struct k_sigaction *ka;
1817 1732
1818 if (unlikely(current->signal->group_stop_count > 0) && 1733 if (unlikely(signal->group_stop_count > 0) &&
1819 do_signal_stop(0)) 1734 do_signal_stop(0))
1820 goto relock; 1735 goto relock;
1821 1736
1822 signr = dequeue_signal(current, mask, info); 1737 signr = dequeue_signal(current, &current->blocked, info);
1823
1824 if (!signr) 1738 if (!signr)
1825 break; /* will return 0 */ 1739 break; /* will return 0 */
1826 1740
@@ -1830,7 +1744,7 @@ relock:
1830 continue; 1744 continue;
1831 } 1745 }
1832 1746
1833 ka = &current->sighand->action[signr-1]; 1747 ka = &sighand->action[signr-1];
1834 if (ka->sa.sa_handler == SIG_IGN) /* Do nothing. */ 1748 if (ka->sa.sa_handler == SIG_IGN) /* Do nothing. */
1835 continue; 1749 continue;
1836 if (ka->sa.sa_handler != SIG_DFL) { 1750 if (ka->sa.sa_handler != SIG_DFL) {
@@ -1852,7 +1766,8 @@ relock:
1852 /* 1766 /*
1853 * Global init gets no signals it doesn't want. 1767 * Global init gets no signals it doesn't want.
1854 */ 1768 */
1855 if (is_global_init(current)) 1769 if (unlikely(signal->flags & SIGNAL_UNKILLABLE) &&
1770 !signal_group_exit(signal))
1856 continue; 1771 continue;
1857 1772
1858 if (sig_kernel_stop(signr)) { 1773 if (sig_kernel_stop(signr)) {
@@ -1867,14 +1782,14 @@ relock:
1867 * We need to check for that and bail out if necessary. 1782 * We need to check for that and bail out if necessary.
1868 */ 1783 */
1869 if (signr != SIGSTOP) { 1784 if (signr != SIGSTOP) {
1870 spin_unlock_irq(&current->sighand->siglock); 1785 spin_unlock_irq(&sighand->siglock);
1871 1786
1872 /* signals can be posted during this window */ 1787 /* signals can be posted during this window */
1873 1788
1874 if (is_current_pgrp_orphaned()) 1789 if (is_current_pgrp_orphaned())
1875 goto relock; 1790 goto relock;
1876 1791
1877 spin_lock_irq(&current->sighand->siglock); 1792 spin_lock_irq(&sighand->siglock);
1878 } 1793 }
1879 1794
1880 if (likely(do_signal_stop(signr))) { 1795 if (likely(do_signal_stop(signr))) {
@@ -1889,15 +1804,16 @@ relock:
1889 continue; 1804 continue;
1890 } 1805 }
1891 1806
1892 spin_unlock_irq(&current->sighand->siglock); 1807 spin_unlock_irq(&sighand->siglock);
1893 1808
1894 /* 1809 /*
1895 * Anything else is fatal, maybe with a core dump. 1810 * Anything else is fatal, maybe with a core dump.
1896 */ 1811 */
1897 current->flags |= PF_SIGNALED; 1812 current->flags |= PF_SIGNALED;
1898 if ((signr != SIGKILL) && print_fatal_signals) 1813
1899 print_fatal_signal(regs, signr);
1900 if (sig_kernel_coredump(signr)) { 1814 if (sig_kernel_coredump(signr)) {
1815 if (print_fatal_signals)
1816 print_fatal_signal(regs, signr);
1901 /* 1817 /*
1902 * If it was able to dump core, this kills all 1818 * If it was able to dump core, this kills all
1903 * other threads in the group and synchronizes with 1819 * other threads in the group and synchronizes with
@@ -1915,7 +1831,7 @@ relock:
1915 do_group_exit(signr); 1831 do_group_exit(signr);
1916 /* NOTREACHED */ 1832 /* NOTREACHED */
1917 } 1833 }
1918 spin_unlock_irq(&current->sighand->siglock); 1834 spin_unlock_irq(&sighand->siglock);
1919 return signr; 1835 return signr;
1920} 1836}
1921 1837
@@ -2259,6 +2175,7 @@ static int do_tkill(int tgid, int pid, int sig)
2259 int error; 2175 int error;
2260 struct siginfo info; 2176 struct siginfo info;
2261 struct task_struct *p; 2177 struct task_struct *p;
2178 unsigned long flags;
2262 2179
2263 error = -ESRCH; 2180 error = -ESRCH;
2264 info.si_signo = sig; 2181 info.si_signo = sig;
@@ -2267,22 +2184,24 @@ static int do_tkill(int tgid, int pid, int sig)
2267 info.si_pid = task_tgid_vnr(current); 2184 info.si_pid = task_tgid_vnr(current);
2268 info.si_uid = current->uid; 2185 info.si_uid = current->uid;
2269 2186
2270 read_lock(&tasklist_lock); 2187 rcu_read_lock();
2271 p = find_task_by_vpid(pid); 2188 p = find_task_by_vpid(pid);
2272 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) { 2189 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
2273 error = check_kill_permission(sig, &info, p); 2190 error = check_kill_permission(sig, &info, p);
2274 /* 2191 /*
2275 * The null signal is a permissions and process existence 2192 * The null signal is a permissions and process existence
2276 * probe. No signal is actually delivered. 2193 * probe. No signal is actually delivered.
2194 *
2195 * If lock_task_sighand() fails we pretend the task dies
2196 * after receiving the signal. The window is tiny, and the
2197 * signal is private anyway.
2277 */ 2198 */
2278 if (!error && sig && p->sighand) { 2199 if (!error && sig && lock_task_sighand(p, &flags)) {
2279 spin_lock_irq(&p->sighand->siglock);
2280 handle_stop_signal(sig, p);
2281 error = specific_send_sig_info(sig, &info, p); 2200 error = specific_send_sig_info(sig, &info, p);
2282 spin_unlock_irq(&p->sighand->siglock); 2201 unlock_task_sighand(p, &flags);
2283 } 2202 }
2284 } 2203 }
2285 read_unlock(&tasklist_lock); 2204 rcu_read_unlock();
2286 2205
2287 return error; 2206 return error;
2288} 2207}
@@ -2339,13 +2258,14 @@ sys_rt_sigqueueinfo(int pid, int sig, siginfo_t __user *uinfo)
2339 2258
2340int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact) 2259int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact)
2341{ 2260{
2261 struct task_struct *t = current;
2342 struct k_sigaction *k; 2262 struct k_sigaction *k;
2343 sigset_t mask; 2263 sigset_t mask;
2344 2264
2345 if (!valid_signal(sig) || sig < 1 || (act && sig_kernel_only(sig))) 2265 if (!valid_signal(sig) || sig < 1 || (act && sig_kernel_only(sig)))
2346 return -EINVAL; 2266 return -EINVAL;
2347 2267
2348 k = &current->sighand->action[sig-1]; 2268 k = &t->sighand->action[sig-1];
2349 2269
2350 spin_lock_irq(&current->sighand->siglock); 2270 spin_lock_irq(&current->sighand->siglock);
2351 if (oact) 2271 if (oact)
@@ -2366,9 +2286,7 @@ int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact)
2366 * (for example, SIGCHLD), shall cause the pending signal to 2286 * (for example, SIGCHLD), shall cause the pending signal to
2367 * be discarded, whether or not it is blocked" 2287 * be discarded, whether or not it is blocked"
2368 */ 2288 */
2369 if (act->sa.sa_handler == SIG_IGN || 2289 if (__sig_ignored(t, sig)) {
2370 (act->sa.sa_handler == SIG_DFL && sig_kernel_ignore(sig))) {
2371 struct task_struct *t = current;
2372 sigemptyset(&mask); 2290 sigemptyset(&mask);
2373 sigaddset(&mask, sig); 2291 sigaddset(&mask, sig);
2374 rm_from_queue_full(&mask, &t->signal->shared_pending); 2292 rm_from_queue_full(&mask, &t->signal->shared_pending);
@@ -2623,7 +2541,7 @@ asmlinkage long sys_rt_sigsuspend(sigset_t __user *unewset, size_t sigsetsize)
2623 2541
2624 current->state = TASK_INTERRUPTIBLE; 2542 current->state = TASK_INTERRUPTIBLE;
2625 schedule(); 2543 schedule();
2626 set_thread_flag(TIF_RESTORE_SIGMASK); 2544 set_restore_sigmask();
2627 return -ERESTARTNOHAND; 2545 return -ERESTARTNOHAND;
2628} 2546}
2629#endif /* __ARCH_WANT_SYS_RT_SIGSUSPEND */ 2547#endif /* __ARCH_WANT_SYS_RT_SIGSUSPEND */
diff --git a/kernel/softirq.c b/kernel/softirq.c
index 3c44956ee7e2..36e061740047 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -589,16 +589,20 @@ static void takeover_tasklets(unsigned int cpu)
589 local_irq_disable(); 589 local_irq_disable();
590 590
591 /* Find end, append list for that CPU. */ 591 /* Find end, append list for that CPU. */
592 *__get_cpu_var(tasklet_vec).tail = per_cpu(tasklet_vec, cpu).head; 592 if (&per_cpu(tasklet_vec, cpu).head != per_cpu(tasklet_vec, cpu).tail) {
593 __get_cpu_var(tasklet_vec).tail = per_cpu(tasklet_vec, cpu).tail; 593 *(__get_cpu_var(tasklet_vec).tail) = per_cpu(tasklet_vec, cpu).head;
594 per_cpu(tasklet_vec, cpu).head = NULL; 594 __get_cpu_var(tasklet_vec).tail = per_cpu(tasklet_vec, cpu).tail;
595 per_cpu(tasklet_vec, cpu).tail = &per_cpu(tasklet_vec, cpu).head; 595 per_cpu(tasklet_vec, cpu).head = NULL;
596 per_cpu(tasklet_vec, cpu).tail = &per_cpu(tasklet_vec, cpu).head;
597 }
596 raise_softirq_irqoff(TASKLET_SOFTIRQ); 598 raise_softirq_irqoff(TASKLET_SOFTIRQ);
597 599
598 *__get_cpu_var(tasklet_hi_vec).tail = per_cpu(tasklet_hi_vec, cpu).head; 600 if (&per_cpu(tasklet_hi_vec, cpu).head != per_cpu(tasklet_hi_vec, cpu).tail) {
599 __get_cpu_var(tasklet_hi_vec).tail = per_cpu(tasklet_hi_vec, cpu).tail; 601 *__get_cpu_var(tasklet_hi_vec).tail = per_cpu(tasklet_hi_vec, cpu).head;
600 per_cpu(tasklet_hi_vec, cpu).head = NULL; 602 __get_cpu_var(tasklet_hi_vec).tail = per_cpu(tasklet_hi_vec, cpu).tail;
601 per_cpu(tasklet_hi_vec, cpu).tail = &per_cpu(tasklet_hi_vec, cpu).head; 603 per_cpu(tasklet_hi_vec, cpu).head = NULL;
604 per_cpu(tasklet_hi_vec, cpu).tail = &per_cpu(tasklet_hi_vec, cpu).head;
605 }
602 raise_softirq_irqoff(HI_SOFTIRQ); 606 raise_softirq_irqoff(HI_SOFTIRQ);
603 607
604 local_irq_enable(); 608 local_irq_enable();
diff --git a/kernel/sys.c b/kernel/sys.c
index e423d0d9e6ff..895d2d4c9493 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -978,8 +978,7 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
978 goto out; 978 goto out;
979 979
980 if (task_pgrp(p) != pgrp) { 980 if (task_pgrp(p) != pgrp) {
981 detach_pid(p, PIDTYPE_PGID); 981 change_pid(p, PIDTYPE_PGID, pgrp);
982 attach_pid(p, PIDTYPE_PGID, pgrp);
983 set_task_pgrp(p, pid_nr(pgrp)); 982 set_task_pgrp(p, pid_nr(pgrp));
984 } 983 }
985 984
@@ -992,54 +991,67 @@ out:
992 991
993asmlinkage long sys_getpgid(pid_t pid) 992asmlinkage long sys_getpgid(pid_t pid)
994{ 993{
994 struct task_struct *p;
995 struct pid *grp;
996 int retval;
997
998 rcu_read_lock();
995 if (!pid) 999 if (!pid)
996 return task_pgrp_vnr(current); 1000 grp = task_pgrp(current);
997 else { 1001 else {
998 int retval;
999 struct task_struct *p;
1000
1001 read_lock(&tasklist_lock);
1002 p = find_task_by_vpid(pid);
1003 retval = -ESRCH; 1002 retval = -ESRCH;
1004 if (p) { 1003 p = find_task_by_vpid(pid);
1005 retval = security_task_getpgid(p); 1004 if (!p)
1006 if (!retval) 1005 goto out;
1007 retval = task_pgrp_vnr(p); 1006 grp = task_pgrp(p);
1008 } 1007 if (!grp)
1009 read_unlock(&tasklist_lock); 1008 goto out;
1010 return retval; 1009
1010 retval = security_task_getpgid(p);
1011 if (retval)
1012 goto out;
1011 } 1013 }
1014 retval = pid_vnr(grp);
1015out:
1016 rcu_read_unlock();
1017 return retval;
1012} 1018}
1013 1019
1014#ifdef __ARCH_WANT_SYS_GETPGRP 1020#ifdef __ARCH_WANT_SYS_GETPGRP
1015 1021
1016asmlinkage long sys_getpgrp(void) 1022asmlinkage long sys_getpgrp(void)
1017{ 1023{
1018 /* SMP - assuming writes are word atomic this is fine */ 1024 return sys_getpgid(0);
1019 return task_pgrp_vnr(current);
1020} 1025}
1021 1026
1022#endif 1027#endif
1023 1028
1024asmlinkage long sys_getsid(pid_t pid) 1029asmlinkage long sys_getsid(pid_t pid)
1025{ 1030{
1031 struct task_struct *p;
1032 struct pid *sid;
1033 int retval;
1034
1035 rcu_read_lock();
1026 if (!pid) 1036 if (!pid)
1027 return task_session_vnr(current); 1037 sid = task_session(current);
1028 else { 1038 else {
1029 int retval;
1030 struct task_struct *p;
1031
1032 rcu_read_lock();
1033 p = find_task_by_vpid(pid);
1034 retval = -ESRCH; 1039 retval = -ESRCH;
1035 if (p) { 1040 p = find_task_by_vpid(pid);
1036 retval = security_task_getsid(p); 1041 if (!p)
1037 if (!retval) 1042 goto out;
1038 retval = task_session_vnr(p); 1043 sid = task_session(p);
1039 } 1044 if (!sid)
1040 rcu_read_unlock(); 1045 goto out;
1041 return retval; 1046
1047 retval = security_task_getsid(p);
1048 if (retval)
1049 goto out;
1042 } 1050 }
1051 retval = pid_vnr(sid);
1052out:
1053 rcu_read_unlock();
1054 return retval;
1043} 1055}
1044 1056
1045asmlinkage long sys_setsid(void) 1057asmlinkage long sys_setsid(void)
@@ -1572,11 +1584,8 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r)
1572 goto out; 1584 goto out;
1573 } 1585 }
1574 1586
1575 rcu_read_lock(); 1587 if (!lock_task_sighand(p, &flags))
1576 if (!lock_task_sighand(p, &flags)) {
1577 rcu_read_unlock();
1578 return; 1588 return;
1579 }
1580 1589
1581 switch (who) { 1590 switch (who) {
1582 case RUSAGE_BOTH: 1591 case RUSAGE_BOTH:
@@ -1612,9 +1621,7 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r)
1612 default: 1621 default:
1613 BUG(); 1622 BUG();
1614 } 1623 }
1615
1616 unlock_task_sighand(p, &flags); 1624 unlock_task_sighand(p, &flags);
1617 rcu_read_unlock();
1618 1625
1619out: 1626out:
1620 cputime_to_timeval(utime, &r->ru_utime); 1627 cputime_to_timeval(utime, &r->ru_utime);
diff --git a/kernel/taskstats.c b/kernel/taskstats.c
index 07e86a828073..4a23517169a6 100644
--- a/kernel/taskstats.c
+++ b/kernel/taskstats.c
@@ -183,7 +183,7 @@ static int fill_pid(pid_t pid, struct task_struct *tsk,
183 183
184 if (!tsk) { 184 if (!tsk) {
185 rcu_read_lock(); 185 rcu_read_lock();
186 tsk = find_task_by_pid(pid); 186 tsk = find_task_by_vpid(pid);
187 if (tsk) 187 if (tsk)
188 get_task_struct(tsk); 188 get_task_struct(tsk);
189 rcu_read_unlock(); 189 rcu_read_unlock();
@@ -230,7 +230,7 @@ static int fill_tgid(pid_t tgid, struct task_struct *first,
230 */ 230 */
231 rcu_read_lock(); 231 rcu_read_lock();
232 if (!first) 232 if (!first)
233 first = find_task_by_pid(tgid); 233 first = find_task_by_vpid(tgid);
234 234
235 if (!first || !lock_task_sighand(first, &flags)) 235 if (!first || !lock_task_sighand(first, &flags))
236 goto out; 236 goto out;
@@ -547,7 +547,7 @@ void taskstats_exit(struct task_struct *tsk, int group_dead)
547 if (!stats) 547 if (!stats)
548 goto err; 548 goto err;
549 549
550 rc = fill_pid(tsk->pid, tsk, stats); 550 rc = fill_pid(-1, tsk, stats);
551 if (rc < 0) 551 if (rc < 0)
552 goto err; 552 goto err;
553 553
diff --git a/kernel/time.c b/kernel/time.c
index 86729042e4cd..6a08660b4fac 100644
--- a/kernel/time.c
+++ b/kernel/time.c
@@ -36,6 +36,7 @@
36#include <linux/security.h> 36#include <linux/security.h>
37#include <linux/fs.h> 37#include <linux/fs.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/math64.h>
39 40
40#include <asm/uaccess.h> 41#include <asm/uaccess.h>
41#include <asm/unistd.h> 42#include <asm/unistd.h>
@@ -245,7 +246,7 @@ unsigned int inline jiffies_to_msecs(const unsigned long j)
245 return (j + (HZ / MSEC_PER_SEC) - 1)/(HZ / MSEC_PER_SEC); 246 return (j + (HZ / MSEC_PER_SEC) - 1)/(HZ / MSEC_PER_SEC);
246#else 247#else
247# if BITS_PER_LONG == 32 248# if BITS_PER_LONG == 32
248 return ((u64)HZ_TO_MSEC_MUL32 * j) >> HZ_TO_MSEC_SHR32; 249 return (HZ_TO_MSEC_MUL32 * j) >> HZ_TO_MSEC_SHR32;
249# else 250# else
250 return (j * HZ_TO_MSEC_NUM) / HZ_TO_MSEC_DEN; 251 return (j * HZ_TO_MSEC_NUM) / HZ_TO_MSEC_DEN;
251# endif 252# endif
@@ -261,7 +262,7 @@ unsigned int inline jiffies_to_usecs(const unsigned long j)
261 return (j + (HZ / USEC_PER_SEC) - 1)/(HZ / USEC_PER_SEC); 262 return (j + (HZ / USEC_PER_SEC) - 1)/(HZ / USEC_PER_SEC);
262#else 263#else
263# if BITS_PER_LONG == 32 264# if BITS_PER_LONG == 32
264 return ((u64)HZ_TO_USEC_MUL32 * j) >> HZ_TO_USEC_SHR32; 265 return (HZ_TO_USEC_MUL32 * j) >> HZ_TO_USEC_SHR32;
265# else 266# else
266 return (j * HZ_TO_USEC_NUM) / HZ_TO_USEC_DEN; 267 return (j * HZ_TO_USEC_NUM) / HZ_TO_USEC_DEN;
267# endif 268# endif
@@ -391,13 +392,17 @@ EXPORT_SYMBOL(set_normalized_timespec);
391struct timespec ns_to_timespec(const s64 nsec) 392struct timespec ns_to_timespec(const s64 nsec)
392{ 393{
393 struct timespec ts; 394 struct timespec ts;
395 s32 rem;
394 396
395 if (!nsec) 397 if (!nsec)
396 return (struct timespec) {0, 0}; 398 return (struct timespec) {0, 0};
397 399
398 ts.tv_sec = div_long_long_rem_signed(nsec, NSEC_PER_SEC, &ts.tv_nsec); 400 ts.tv_sec = div_s64_rem(nsec, NSEC_PER_SEC, &rem);
399 if (unlikely(nsec < 0)) 401 if (unlikely(rem < 0)) {
400 set_normalized_timespec(&ts, ts.tv_sec, ts.tv_nsec); 402 ts.tv_sec--;
403 rem += NSEC_PER_SEC;
404 }
405 ts.tv_nsec = rem;
401 406
402 return ts; 407 return ts;
403} 408}
@@ -471,7 +476,7 @@ unsigned long msecs_to_jiffies(const unsigned int m)
471 if (HZ > MSEC_PER_SEC && m > jiffies_to_msecs(MAX_JIFFY_OFFSET)) 476 if (HZ > MSEC_PER_SEC && m > jiffies_to_msecs(MAX_JIFFY_OFFSET))
472 return MAX_JIFFY_OFFSET; 477 return MAX_JIFFY_OFFSET;
473 478
474 return ((u64)MSEC_TO_HZ_MUL32 * m + MSEC_TO_HZ_ADJ32) 479 return (MSEC_TO_HZ_MUL32 * m + MSEC_TO_HZ_ADJ32)
475 >> MSEC_TO_HZ_SHR32; 480 >> MSEC_TO_HZ_SHR32;
476#endif 481#endif
477} 482}
@@ -486,7 +491,7 @@ unsigned long usecs_to_jiffies(const unsigned int u)
486#elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC) 491#elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC)
487 return u * (HZ / USEC_PER_SEC); 492 return u * (HZ / USEC_PER_SEC);
488#else 493#else
489 return ((u64)USEC_TO_HZ_MUL32 * u + USEC_TO_HZ_ADJ32) 494 return (USEC_TO_HZ_MUL32 * u + USEC_TO_HZ_ADJ32)
490 >> USEC_TO_HZ_SHR32; 495 >> USEC_TO_HZ_SHR32;
491#endif 496#endif
492} 497}
@@ -527,8 +532,10 @@ jiffies_to_timespec(const unsigned long jiffies, struct timespec *value)
527 * Convert jiffies to nanoseconds and separate with 532 * Convert jiffies to nanoseconds and separate with
528 * one divide. 533 * one divide.
529 */ 534 */
530 u64 nsec = (u64)jiffies * TICK_NSEC; 535 u32 rem;
531 value->tv_sec = div_long_long_rem(nsec, NSEC_PER_SEC, &value->tv_nsec); 536 value->tv_sec = div_u64_rem((u64)jiffies * TICK_NSEC,
537 NSEC_PER_SEC, &rem);
538 value->tv_nsec = rem;
532} 539}
533EXPORT_SYMBOL(jiffies_to_timespec); 540EXPORT_SYMBOL(jiffies_to_timespec);
534 541
@@ -566,12 +573,11 @@ void jiffies_to_timeval(const unsigned long jiffies, struct timeval *value)
566 * Convert jiffies to nanoseconds and separate with 573 * Convert jiffies to nanoseconds and separate with
567 * one divide. 574 * one divide.
568 */ 575 */
569 u64 nsec = (u64)jiffies * TICK_NSEC; 576 u32 rem;
570 long tv_usec;
571 577
572 value->tv_sec = div_long_long_rem(nsec, NSEC_PER_SEC, &tv_usec); 578 value->tv_sec = div_u64_rem((u64)jiffies * TICK_NSEC,
573 tv_usec /= NSEC_PER_USEC; 579 NSEC_PER_SEC, &rem);
574 value->tv_usec = tv_usec; 580 value->tv_usec = rem / NSEC_PER_USEC;
575} 581}
576EXPORT_SYMBOL(jiffies_to_timeval); 582EXPORT_SYMBOL(jiffies_to_timeval);
577 583
@@ -587,9 +593,7 @@ clock_t jiffies_to_clock_t(long x)
587 return x / (HZ / USER_HZ); 593 return x / (HZ / USER_HZ);
588# endif 594# endif
589#else 595#else
590 u64 tmp = (u64)x * TICK_NSEC; 596 return div_u64((u64)x * TICK_NSEC, NSEC_PER_SEC / USER_HZ);
591 do_div(tmp, (NSEC_PER_SEC / USER_HZ));
592 return (long)tmp;
593#endif 597#endif
594} 598}
595EXPORT_SYMBOL(jiffies_to_clock_t); 599EXPORT_SYMBOL(jiffies_to_clock_t);
@@ -601,16 +605,12 @@ unsigned long clock_t_to_jiffies(unsigned long x)
601 return ~0UL; 605 return ~0UL;
602 return x * (HZ / USER_HZ); 606 return x * (HZ / USER_HZ);
603#else 607#else
604 u64 jif;
605
606 /* Don't worry about loss of precision here .. */ 608 /* Don't worry about loss of precision here .. */
607 if (x >= ~0UL / HZ * USER_HZ) 609 if (x >= ~0UL / HZ * USER_HZ)
608 return ~0UL; 610 return ~0UL;
609 611
610 /* .. but do try to contain it here */ 612 /* .. but do try to contain it here */
611 jif = x * (u64) HZ; 613 return div_u64((u64)x * HZ, USER_HZ);
612 do_div(jif, USER_HZ);
613 return jif;
614#endif 614#endif
615} 615}
616EXPORT_SYMBOL(clock_t_to_jiffies); 616EXPORT_SYMBOL(clock_t_to_jiffies);
@@ -619,10 +619,9 @@ u64 jiffies_64_to_clock_t(u64 x)
619{ 619{
620#if (TICK_NSEC % (NSEC_PER_SEC / USER_HZ)) == 0 620#if (TICK_NSEC % (NSEC_PER_SEC / USER_HZ)) == 0
621# if HZ < USER_HZ 621# if HZ < USER_HZ
622 x *= USER_HZ; 622 x = div_u64(x * USER_HZ, HZ);
623 do_div(x, HZ);
624# elif HZ > USER_HZ 623# elif HZ > USER_HZ
625 do_div(x, HZ / USER_HZ); 624 x = div_u64(x, HZ / USER_HZ);
626# else 625# else
627 /* Nothing to do */ 626 /* Nothing to do */
628# endif 627# endif
@@ -632,8 +631,7 @@ u64 jiffies_64_to_clock_t(u64 x)
632 * but even this doesn't overflow in hundreds of years 631 * but even this doesn't overflow in hundreds of years
633 * in 64 bits, so.. 632 * in 64 bits, so..
634 */ 633 */
635 x *= TICK_NSEC; 634 x = div_u64(x * TICK_NSEC, (NSEC_PER_SEC / USER_HZ));
636 do_div(x, (NSEC_PER_SEC / USER_HZ));
637#endif 635#endif
638 return x; 636 return x;
639} 637}
@@ -642,21 +640,17 @@ EXPORT_SYMBOL(jiffies_64_to_clock_t);
642u64 nsec_to_clock_t(u64 x) 640u64 nsec_to_clock_t(u64 x)
643{ 641{
644#if (NSEC_PER_SEC % USER_HZ) == 0 642#if (NSEC_PER_SEC % USER_HZ) == 0
645 do_div(x, (NSEC_PER_SEC / USER_HZ)); 643 return div_u64(x, NSEC_PER_SEC / USER_HZ);
646#elif (USER_HZ % 512) == 0 644#elif (USER_HZ % 512) == 0
647 x *= USER_HZ/512; 645 return div_u64(x * USER_HZ / 512, NSEC_PER_SEC / 512);
648 do_div(x, (NSEC_PER_SEC / 512));
649#else 646#else
650 /* 647 /*
651 * max relative error 5.7e-8 (1.8s per year) for USER_HZ <= 1024, 648 * max relative error 5.7e-8 (1.8s per year) for USER_HZ <= 1024,
652 * overflow after 64.99 years. 649 * overflow after 64.99 years.
653 * exact for HZ=60, 72, 90, 120, 144, 180, 300, 600, 900, ... 650 * exact for HZ=60, 72, 90, 120, 144, 180, 300, 600, 900, ...
654 */ 651 */
655 x *= 9; 652 return div_u64(x * 9, (9ull * NSEC_PER_SEC + (USER_HZ / 2)) / USER_HZ);
656 do_div(x, (unsigned long)((9ull * NSEC_PER_SEC + (USER_HZ/2)) /
657 USER_HZ));
658#endif 653#endif
659 return x;
660} 654}
661 655
662#if (BITS_PER_LONG < 64) 656#if (BITS_PER_LONG < 64)
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index 73961f35fdc8..dadde5361f32 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -471,10 +471,10 @@ sysfs_show_available_clocksources(struct sys_device *dev, char *buf)
471/* 471/*
472 * Sysfs setup bits: 472 * Sysfs setup bits:
473 */ 473 */
474static SYSDEV_ATTR(current_clocksource, 0600, sysfs_show_current_clocksources, 474static SYSDEV_ATTR(current_clocksource, 0644, sysfs_show_current_clocksources,
475 sysfs_override_clocksource); 475 sysfs_override_clocksource);
476 476
477static SYSDEV_ATTR(available_clocksource, 0600, 477static SYSDEV_ATTR(available_clocksource, 0444,
478 sysfs_show_available_clocksources, NULL); 478 sysfs_show_available_clocksources, NULL);
479 479
480static struct sysdev_class clocksource_sysclass = { 480static struct sysdev_class clocksource_sysclass = {
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 5fd9b9469770..5125ddd8196b 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -15,7 +15,8 @@
15#include <linux/jiffies.h> 15#include <linux/jiffies.h>
16#include <linux/hrtimer.h> 16#include <linux/hrtimer.h>
17#include <linux/capability.h> 17#include <linux/capability.h>
18#include <asm/div64.h> 18#include <linux/math64.h>
19#include <linux/clocksource.h>
19#include <asm/timex.h> 20#include <asm/timex.h>
20 21
21/* 22/*
@@ -23,11 +24,14 @@
23 */ 24 */
24unsigned long tick_usec = TICK_USEC; /* USER_HZ period (usec) */ 25unsigned long tick_usec = TICK_USEC; /* USER_HZ period (usec) */
25unsigned long tick_nsec; /* ACTHZ period (nsec) */ 26unsigned long tick_nsec; /* ACTHZ period (nsec) */
26static u64 tick_length, tick_length_base; 27u64 tick_length;
28static u64 tick_length_base;
29
30static struct hrtimer leap_timer;
27 31
28#define MAX_TICKADJ 500 /* microsecs */ 32#define MAX_TICKADJ 500 /* microsecs */
29#define MAX_TICKADJ_SCALED (((u64)(MAX_TICKADJ * NSEC_PER_USEC) << \ 33#define MAX_TICKADJ_SCALED (((u64)(MAX_TICKADJ * NSEC_PER_USEC) << \
30 TICK_LENGTH_SHIFT) / NTP_INTERVAL_FREQ) 34 NTP_SCALE_SHIFT) / NTP_INTERVAL_FREQ)
31 35
32/* 36/*
33 * phase-lock loop variables 37 * phase-lock loop variables
@@ -35,11 +39,12 @@ static u64 tick_length, tick_length_base;
35/* TIME_ERROR prevents overwriting the CMOS clock */ 39/* TIME_ERROR prevents overwriting the CMOS clock */
36static int time_state = TIME_OK; /* clock synchronization status */ 40static int time_state = TIME_OK; /* clock synchronization status */
37int time_status = STA_UNSYNC; /* clock status bits */ 41int time_status = STA_UNSYNC; /* clock status bits */
38static s64 time_offset; /* time adjustment (ns) */ 42static long time_tai; /* TAI offset (s) */
43static s64 time_offset; /* time adjustment (ns) */
39static long time_constant = 2; /* pll time constant */ 44static long time_constant = 2; /* pll time constant */
40long time_maxerror = NTP_PHASE_LIMIT; /* maximum error (us) */ 45long time_maxerror = NTP_PHASE_LIMIT; /* maximum error (us) */
41long time_esterror = NTP_PHASE_LIMIT; /* estimated error (us) */ 46long time_esterror = NTP_PHASE_LIMIT; /* estimated error (us) */
42long time_freq; /* frequency offset (scaled ppm)*/ 47static s64 time_freq; /* frequency offset (scaled ns/s)*/
43static long time_reftime; /* time at last adjustment (s) */ 48static long time_reftime; /* time at last adjustment (s) */
44long time_adjust; 49long time_adjust;
45static long ntp_tick_adj; 50static long ntp_tick_adj;
@@ -47,16 +52,56 @@ static long ntp_tick_adj;
47static void ntp_update_frequency(void) 52static void ntp_update_frequency(void)
48{ 53{
49 u64 second_length = (u64)(tick_usec * NSEC_PER_USEC * USER_HZ) 54 u64 second_length = (u64)(tick_usec * NSEC_PER_USEC * USER_HZ)
50 << TICK_LENGTH_SHIFT; 55 << NTP_SCALE_SHIFT;
51 second_length += (s64)ntp_tick_adj << TICK_LENGTH_SHIFT; 56 second_length += (s64)ntp_tick_adj << NTP_SCALE_SHIFT;
52 second_length += (s64)time_freq << (TICK_LENGTH_SHIFT - SHIFT_NSEC); 57 second_length += time_freq;
53 58
54 tick_length_base = second_length; 59 tick_length_base = second_length;
55 60
56 do_div(second_length, HZ); 61 tick_nsec = div_u64(second_length, HZ) >> NTP_SCALE_SHIFT;
57 tick_nsec = second_length >> TICK_LENGTH_SHIFT; 62 tick_length_base = div_u64(tick_length_base, NTP_INTERVAL_FREQ);
63}
64
65static void ntp_update_offset(long offset)
66{
67 long mtemp;
68 s64 freq_adj;
69
70 if (!(time_status & STA_PLL))
71 return;
58 72
59 do_div(tick_length_base, NTP_INTERVAL_FREQ); 73 if (!(time_status & STA_NANO))
74 offset *= NSEC_PER_USEC;
75
76 /*
77 * Scale the phase adjustment and
78 * clamp to the operating range.
79 */
80 offset = min(offset, MAXPHASE);
81 offset = max(offset, -MAXPHASE);
82
83 /*
84 * Select how the frequency is to be controlled
85 * and in which mode (PLL or FLL).
86 */
87 if (time_status & STA_FREQHOLD || time_reftime == 0)
88 time_reftime = xtime.tv_sec;
89 mtemp = xtime.tv_sec - time_reftime;
90 time_reftime = xtime.tv_sec;
91
92 freq_adj = (s64)offset * mtemp;
93 freq_adj <<= NTP_SCALE_SHIFT - 2 * (SHIFT_PLL + 2 + time_constant);
94 time_status &= ~STA_MODE;
95 if (mtemp >= MINSEC && (time_status & STA_FLL || mtemp > MAXSEC)) {
96 freq_adj += div_s64((s64)offset << (NTP_SCALE_SHIFT - SHIFT_FLL),
97 mtemp);
98 time_status |= STA_MODE;
99 }
100 freq_adj += time_freq;
101 freq_adj = min(freq_adj, MAXFREQ_SCALED);
102 time_freq = max(freq_adj, -MAXFREQ_SCALED);
103
104 time_offset = div_s64((s64)offset << NTP_SCALE_SHIFT, NTP_INTERVAL_FREQ);
60} 105}
61 106
62/** 107/**
@@ -78,62 +123,70 @@ void ntp_clear(void)
78} 123}
79 124
80/* 125/*
81 * this routine handles the overflow of the microsecond field 126 * Leap second processing. If in leap-insert state at the end of the
82 * 127 * day, the system clock is set back one second; if in leap-delete
83 * The tricky bits of code to handle the accurate clock support 128 * state, the system clock is set ahead one second.
84 * were provided by Dave Mills (Mills@UDEL.EDU) of NTP fame.
85 * They were originally developed for SUN and DEC kernels.
86 * All the kudos should go to Dave for this stuff.
87 */ 129 */
88void second_overflow(void) 130static enum hrtimer_restart ntp_leap_second(struct hrtimer *timer)
89{ 131{
90 long time_adj; 132 enum hrtimer_restart res = HRTIMER_NORESTART;
91 133
92 /* Bump the maxerror field */ 134 write_seqlock_irq(&xtime_lock);
93 time_maxerror += MAXFREQ >> SHIFT_USEC;
94 if (time_maxerror > NTP_PHASE_LIMIT) {
95 time_maxerror = NTP_PHASE_LIMIT;
96 time_status |= STA_UNSYNC;
97 }
98 135
99 /*
100 * Leap second processing. If in leap-insert state at the end of the
101 * day, the system clock is set back one second; if in leap-delete
102 * state, the system clock is set ahead one second. The microtime()
103 * routine or external clock driver will insure that reported time is
104 * always monotonic. The ugly divides should be replaced.
105 */
106 switch (time_state) { 136 switch (time_state) {
107 case TIME_OK: 137 case TIME_OK:
108 if (time_status & STA_INS)
109 time_state = TIME_INS;
110 else if (time_status & STA_DEL)
111 time_state = TIME_DEL;
112 break; 138 break;
113 case TIME_INS: 139 case TIME_INS:
114 if (xtime.tv_sec % 86400 == 0) { 140 xtime.tv_sec--;
115 xtime.tv_sec--; 141 wall_to_monotonic.tv_sec++;
116 wall_to_monotonic.tv_sec++; 142 time_state = TIME_OOP;
117 time_state = TIME_OOP; 143 printk(KERN_NOTICE "Clock: "
118 printk(KERN_NOTICE "Clock: inserting leap second " 144 "inserting leap second 23:59:60 UTC\n");
119 "23:59:60 UTC\n"); 145 leap_timer.expires = ktime_add_ns(leap_timer.expires,
120 } 146 NSEC_PER_SEC);
147 res = HRTIMER_RESTART;
121 break; 148 break;
122 case TIME_DEL: 149 case TIME_DEL:
123 if ((xtime.tv_sec + 1) % 86400 == 0) { 150 xtime.tv_sec++;
124 xtime.tv_sec++; 151 time_tai--;
125 wall_to_monotonic.tv_sec--; 152 wall_to_monotonic.tv_sec--;
126 time_state = TIME_WAIT; 153 time_state = TIME_WAIT;
127 printk(KERN_NOTICE "Clock: deleting leap second " 154 printk(KERN_NOTICE "Clock: "
128 "23:59:59 UTC\n"); 155 "deleting leap second 23:59:59 UTC\n");
129 }
130 break; 156 break;
131 case TIME_OOP: 157 case TIME_OOP:
158 time_tai++;
132 time_state = TIME_WAIT; 159 time_state = TIME_WAIT;
133 break; 160 /* fall through */
134 case TIME_WAIT: 161 case TIME_WAIT:
135 if (!(time_status & (STA_INS | STA_DEL))) 162 if (!(time_status & (STA_INS | STA_DEL)))
136 time_state = TIME_OK; 163 time_state = TIME_OK;
164 break;
165 }
166 update_vsyscall(&xtime, clock);
167
168 write_sequnlock_irq(&xtime_lock);
169
170 return res;
171}
172
173/*
174 * this routine handles the overflow of the microsecond field
175 *
176 * The tricky bits of code to handle the accurate clock support
177 * were provided by Dave Mills (Mills@UDEL.EDU) of NTP fame.
178 * They were originally developed for SUN and DEC kernels.
179 * All the kudos should go to Dave for this stuff.
180 */
181void second_overflow(void)
182{
183 s64 time_adj;
184
185 /* Bump the maxerror field */
186 time_maxerror += MAXFREQ / NSEC_PER_USEC;
187 if (time_maxerror > NTP_PHASE_LIMIT) {
188 time_maxerror = NTP_PHASE_LIMIT;
189 time_status |= STA_UNSYNC;
137 } 190 }
138 191
139 /* 192 /*
@@ -143,7 +196,7 @@ void second_overflow(void)
143 tick_length = tick_length_base; 196 tick_length = tick_length_base;
144 time_adj = shift_right(time_offset, SHIFT_PLL + time_constant); 197 time_adj = shift_right(time_offset, SHIFT_PLL + time_constant);
145 time_offset -= time_adj; 198 time_offset -= time_adj;
146 tick_length += (s64)time_adj << (TICK_LENGTH_SHIFT - SHIFT_UPDATE); 199 tick_length += time_adj;
147 200
148 if (unlikely(time_adjust)) { 201 if (unlikely(time_adjust)) {
149 if (time_adjust > MAX_TICKADJ) { 202 if (time_adjust > MAX_TICKADJ) {
@@ -154,25 +207,12 @@ void second_overflow(void)
154 tick_length -= MAX_TICKADJ_SCALED; 207 tick_length -= MAX_TICKADJ_SCALED;
155 } else { 208 } else {
156 tick_length += (s64)(time_adjust * NSEC_PER_USEC / 209 tick_length += (s64)(time_adjust * NSEC_PER_USEC /
157 NTP_INTERVAL_FREQ) << TICK_LENGTH_SHIFT; 210 NTP_INTERVAL_FREQ) << NTP_SCALE_SHIFT;
158 time_adjust = 0; 211 time_adjust = 0;
159 } 212 }
160 } 213 }
161} 214}
162 215
163/*
164 * Return how long ticks are at the moment, that is, how much time
165 * update_wall_time_one_tick will add to xtime next time we call it
166 * (assuming no calls to do_adjtimex in the meantime).
167 * The return value is in fixed-point nanoseconds shifted by the
168 * specified number of bits to the right of the binary point.
169 * This function has no side-effects.
170 */
171u64 current_tick_length(void)
172{
173 return tick_length;
174}
175
176#ifdef CONFIG_GENERIC_CMOS_UPDATE 216#ifdef CONFIG_GENERIC_CMOS_UPDATE
177 217
178/* Disable the cmos update - used by virtualization and embedded */ 218/* Disable the cmos update - used by virtualization and embedded */
@@ -236,8 +276,8 @@ static inline void notify_cmos_timer(void) { }
236 */ 276 */
237int do_adjtimex(struct timex *txc) 277int do_adjtimex(struct timex *txc)
238{ 278{
239 long mtemp, save_adjust, rem; 279 struct timespec ts;
240 s64 freq_adj, temp64; 280 long save_adjust, sec;
241 int result; 281 int result;
242 282
243 /* In order to modify anything, you gotta be super-user! */ 283 /* In order to modify anything, you gotta be super-user! */
@@ -247,147 +287,132 @@ int do_adjtimex(struct timex *txc)
247 /* Now we validate the data before disabling interrupts */ 287 /* Now we validate the data before disabling interrupts */
248 288
249 if ((txc->modes & ADJ_OFFSET_SINGLESHOT) == ADJ_OFFSET_SINGLESHOT) { 289 if ((txc->modes & ADJ_OFFSET_SINGLESHOT) == ADJ_OFFSET_SINGLESHOT) {
250 /* singleshot must not be used with any other mode bits */ 290 /* singleshot must not be used with any other mode bits */
251 if (txc->modes != ADJ_OFFSET_SINGLESHOT && 291 if (txc->modes & ~ADJ_OFFSET_SS_READ)
252 txc->modes != ADJ_OFFSET_SS_READ)
253 return -EINVAL; 292 return -EINVAL;
254 } 293 }
255 294
256 if (txc->modes != ADJ_OFFSET_SINGLESHOT && (txc->modes & ADJ_OFFSET))
257 /* adjustment Offset limited to +- .512 seconds */
258 if (txc->offset <= - MAXPHASE || txc->offset >= MAXPHASE )
259 return -EINVAL;
260
261 /* if the quartz is off by more than 10% something is VERY wrong ! */ 295 /* if the quartz is off by more than 10% something is VERY wrong ! */
262 if (txc->modes & ADJ_TICK) 296 if (txc->modes & ADJ_TICK)
263 if (txc->tick < 900000/USER_HZ || 297 if (txc->tick < 900000/USER_HZ ||
264 txc->tick > 1100000/USER_HZ) 298 txc->tick > 1100000/USER_HZ)
265 return -EINVAL; 299 return -EINVAL;
266 300
301 if (time_state != TIME_OK && txc->modes & ADJ_STATUS)
302 hrtimer_cancel(&leap_timer);
303 getnstimeofday(&ts);
304
267 write_seqlock_irq(&xtime_lock); 305 write_seqlock_irq(&xtime_lock);
268 result = time_state; /* mostly `TIME_OK' */
269 306
270 /* Save for later - semantics of adjtime is to return old value */ 307 /* Save for later - semantics of adjtime is to return old value */
271 save_adjust = time_adjust; 308 save_adjust = time_adjust;
272 309
273#if 0 /* STA_CLOCKERR is never set yet */
274 time_status &= ~STA_CLOCKERR; /* reset STA_CLOCKERR */
275#endif
276 /* If there are input parameters, then process them */ 310 /* If there are input parameters, then process them */
277 if (txc->modes) 311 if (txc->modes) {
278 { 312 if (txc->modes & ADJ_STATUS) {
279 if (txc->modes & ADJ_STATUS) /* only set allowed bits */ 313 if ((time_status & STA_PLL) &&
280 time_status = (txc->status & ~STA_RONLY) | 314 !(txc->status & STA_PLL)) {
281 (time_status & STA_RONLY); 315 time_state = TIME_OK;
282 316 time_status = STA_UNSYNC;
283 if (txc->modes & ADJ_FREQUENCY) { /* p. 22 */ 317 }
284 if (txc->freq > MAXFREQ || txc->freq < -MAXFREQ) { 318 /* only set allowed bits */
285 result = -EINVAL; 319 time_status &= STA_RONLY;
286 goto leave; 320 time_status |= txc->status & ~STA_RONLY;
287 } 321
288 time_freq = ((s64)txc->freq * NSEC_PER_USEC) 322 switch (time_state) {
289 >> (SHIFT_USEC - SHIFT_NSEC); 323 case TIME_OK:
290 } 324 start_timer:
291 325 sec = ts.tv_sec;
292 if (txc->modes & ADJ_MAXERROR) { 326 if (time_status & STA_INS) {
293 if (txc->maxerror < 0 || txc->maxerror >= NTP_PHASE_LIMIT) { 327 time_state = TIME_INS;
294 result = -EINVAL; 328 sec += 86400 - sec % 86400;
295 goto leave; 329 hrtimer_start(&leap_timer, ktime_set(sec, 0), HRTIMER_MODE_ABS);
330 } else if (time_status & STA_DEL) {
331 time_state = TIME_DEL;
332 sec += 86400 - (sec + 1) % 86400;
333 hrtimer_start(&leap_timer, ktime_set(sec, 0), HRTIMER_MODE_ABS);
334 }
335 break;
336 case TIME_INS:
337 case TIME_DEL:
338 time_state = TIME_OK;
339 goto start_timer;
340 break;
341 case TIME_WAIT:
342 if (!(time_status & (STA_INS | STA_DEL)))
343 time_state = TIME_OK;
344 break;
345 case TIME_OOP:
346 hrtimer_restart(&leap_timer);
347 break;
348 }
296 } 349 }
297 time_maxerror = txc->maxerror;
298 }
299 350
300 if (txc->modes & ADJ_ESTERROR) { 351 if (txc->modes & ADJ_NANO)
301 if (txc->esterror < 0 || txc->esterror >= NTP_PHASE_LIMIT) { 352 time_status |= STA_NANO;
302 result = -EINVAL; 353 if (txc->modes & ADJ_MICRO)
303 goto leave; 354 time_status &= ~STA_NANO;
355
356 if (txc->modes & ADJ_FREQUENCY) {
357 time_freq = (s64)txc->freq * PPM_SCALE;
358 time_freq = min(time_freq, MAXFREQ_SCALED);
359 time_freq = max(time_freq, -MAXFREQ_SCALED);
304 } 360 }
305 time_esterror = txc->esterror;
306 }
307 361
308 if (txc->modes & ADJ_TIMECONST) { /* p. 24 */ 362 if (txc->modes & ADJ_MAXERROR)
309 if (txc->constant < 0) { /* NTP v4 uses values > 6 */ 363 time_maxerror = txc->maxerror;
310 result = -EINVAL; 364 if (txc->modes & ADJ_ESTERROR)
311 goto leave; 365 time_esterror = txc->esterror;
366
367 if (txc->modes & ADJ_TIMECONST) {
368 time_constant = txc->constant;
369 if (!(time_status & STA_NANO))
370 time_constant += 4;
371 time_constant = min(time_constant, (long)MAXTC);
372 time_constant = max(time_constant, 0l);
312 } 373 }
313 time_constant = min(txc->constant + 4, (long)MAXTC);
314 }
315 374
316 if (txc->modes & ADJ_OFFSET) { /* values checked earlier */ 375 if (txc->modes & ADJ_TAI && txc->constant > 0)
317 if (txc->modes == ADJ_OFFSET_SINGLESHOT) { 376 time_tai = txc->constant;
318 /* adjtime() is independent from ntp_adjtime() */ 377
319 time_adjust = txc->offset; 378 if (txc->modes & ADJ_OFFSET) {
379 if (txc->modes == ADJ_OFFSET_SINGLESHOT)
380 /* adjtime() is independent from ntp_adjtime() */
381 time_adjust = txc->offset;
382 else
383 ntp_update_offset(txc->offset);
320 } 384 }
321 else if (time_status & STA_PLL) { 385 if (txc->modes & ADJ_TICK)
322 time_offset = txc->offset * NSEC_PER_USEC; 386 tick_usec = txc->tick;
323 387
324 /* 388 if (txc->modes & (ADJ_TICK|ADJ_FREQUENCY|ADJ_OFFSET))
325 * Scale the phase adjustment and 389 ntp_update_frequency();
326 * clamp to the operating range. 390 }
327 */ 391
328 time_offset = min(time_offset, (s64)MAXPHASE * NSEC_PER_USEC); 392 result = time_state; /* mostly `TIME_OK' */
329 time_offset = max(time_offset, (s64)-MAXPHASE * NSEC_PER_USEC); 393 if (time_status & (STA_UNSYNC|STA_CLOCKERR))
330
331 /*
332 * Select whether the frequency is to be controlled
333 * and in which mode (PLL or FLL). Clamp to the operating
334 * range. Ugly multiply/divide should be replaced someday.
335 */
336
337 if (time_status & STA_FREQHOLD || time_reftime == 0)
338 time_reftime = xtime.tv_sec;
339 mtemp = xtime.tv_sec - time_reftime;
340 time_reftime = xtime.tv_sec;
341
342 freq_adj = time_offset * mtemp;
343 freq_adj = shift_right(freq_adj, time_constant * 2 +
344 (SHIFT_PLL + 2) * 2 - SHIFT_NSEC);
345 if (mtemp >= MINSEC && (time_status & STA_FLL || mtemp > MAXSEC)) {
346 u64 utemp64;
347 temp64 = time_offset << (SHIFT_NSEC - SHIFT_FLL);
348 if (time_offset < 0) {
349 utemp64 = -temp64;
350 do_div(utemp64, mtemp);
351 freq_adj -= utemp64;
352 } else {
353 utemp64 = temp64;
354 do_div(utemp64, mtemp);
355 freq_adj += utemp64;
356 }
357 }
358 freq_adj += time_freq;
359 freq_adj = min(freq_adj, (s64)MAXFREQ_NSEC);
360 time_freq = max(freq_adj, (s64)-MAXFREQ_NSEC);
361 time_offset = div_long_long_rem_signed(time_offset,
362 NTP_INTERVAL_FREQ,
363 &rem);
364 time_offset <<= SHIFT_UPDATE;
365 } /* STA_PLL */
366 } /* txc->modes & ADJ_OFFSET */
367 if (txc->modes & ADJ_TICK)
368 tick_usec = txc->tick;
369
370 if (txc->modes & (ADJ_TICK|ADJ_FREQUENCY|ADJ_OFFSET))
371 ntp_update_frequency();
372 } /* txc->modes */
373leave: if ((time_status & (STA_UNSYNC|STA_CLOCKERR)) != 0)
374 result = TIME_ERROR; 394 result = TIME_ERROR;
375 395
376 if ((txc->modes == ADJ_OFFSET_SINGLESHOT) || 396 if ((txc->modes == ADJ_OFFSET_SINGLESHOT) ||
377 (txc->modes == ADJ_OFFSET_SS_READ)) 397 (txc->modes == ADJ_OFFSET_SS_READ))
378 txc->offset = save_adjust; 398 txc->offset = save_adjust;
379 else 399 else {
380 txc->offset = ((long)shift_right(time_offset, SHIFT_UPDATE)) * 400 txc->offset = shift_right(time_offset * NTP_INTERVAL_FREQ,
381 NTP_INTERVAL_FREQ / 1000; 401 NTP_SCALE_SHIFT);
382 txc->freq = (time_freq / NSEC_PER_USEC) << 402 if (!(time_status & STA_NANO))
383 (SHIFT_USEC - SHIFT_NSEC); 403 txc->offset /= NSEC_PER_USEC;
404 }
405 txc->freq = shift_right((s32)(time_freq >> PPM_SCALE_INV_SHIFT) *
406 (s64)PPM_SCALE_INV,
407 NTP_SCALE_SHIFT);
384 txc->maxerror = time_maxerror; 408 txc->maxerror = time_maxerror;
385 txc->esterror = time_esterror; 409 txc->esterror = time_esterror;
386 txc->status = time_status; 410 txc->status = time_status;
387 txc->constant = time_constant; 411 txc->constant = time_constant;
388 txc->precision = 1; 412 txc->precision = 1;
389 txc->tolerance = MAXFREQ; 413 txc->tolerance = MAXFREQ_SCALED / PPM_SCALE;
390 txc->tick = tick_usec; 414 txc->tick = tick_usec;
415 txc->tai = time_tai;
391 416
392 /* PPS is not implemented, so these are zero */ 417 /* PPS is not implemented, so these are zero */
393 txc->ppsfreq = 0; 418 txc->ppsfreq = 0;
@@ -399,9 +424,15 @@ leave: if ((time_status & (STA_UNSYNC|STA_CLOCKERR)) != 0)
399 txc->errcnt = 0; 424 txc->errcnt = 0;
400 txc->stbcnt = 0; 425 txc->stbcnt = 0;
401 write_sequnlock_irq(&xtime_lock); 426 write_sequnlock_irq(&xtime_lock);
402 do_gettimeofday(&txc->time); 427
428 txc->time.tv_sec = ts.tv_sec;
429 txc->time.tv_usec = ts.tv_nsec;
430 if (!(time_status & STA_NANO))
431 txc->time.tv_usec /= NSEC_PER_USEC;
432
403 notify_cmos_timer(); 433 notify_cmos_timer();
404 return(result); 434
435 return result;
405} 436}
406 437
407static int __init ntp_tick_adj_setup(char *str) 438static int __init ntp_tick_adj_setup(char *str)
@@ -411,3 +442,10 @@ static int __init ntp_tick_adj_setup(char *str)
411} 442}
412 443
413__setup("ntp_tick_adj=", ntp_tick_adj_setup); 444__setup("ntp_tick_adj=", ntp_tick_adj_setup);
445
446void __init ntp_init(void)
447{
448 ntp_clear();
449 hrtimer_init(&leap_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS);
450 leap_timer.function = ntp_leap_second;
451}
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 2d6087c7cf98..e91c29f961c9 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -53,7 +53,7 @@ void update_xtime_cache(u64 nsec)
53 timespec_add_ns(&xtime_cache, nsec); 53 timespec_add_ns(&xtime_cache, nsec);
54} 54}
55 55
56static struct clocksource *clock; /* pointer to current clocksource */ 56struct clocksource *clock;
57 57
58 58
59#ifdef CONFIG_GENERIC_TIME 59#ifdef CONFIG_GENERIC_TIME
@@ -246,7 +246,7 @@ void __init timekeeping_init(void)
246 246
247 write_seqlock_irqsave(&xtime_lock, flags); 247 write_seqlock_irqsave(&xtime_lock, flags);
248 248
249 ntp_clear(); 249 ntp_init();
250 250
251 clock = clocksource_get_next(); 251 clock = clocksource_get_next();
252 clocksource_calculate_interval(clock, NTP_INTERVAL_LENGTH); 252 clocksource_calculate_interval(clock, NTP_INTERVAL_LENGTH);
@@ -371,7 +371,7 @@ static __always_inline int clocksource_bigadjust(s64 error, s64 *interval,
371 * here. This is tuned so that an error of about 1 msec is adjusted 371 * here. This is tuned so that an error of about 1 msec is adjusted
372 * within about 1 sec (or 2^20 nsec in 2^SHIFT_HZ ticks). 372 * within about 1 sec (or 2^20 nsec in 2^SHIFT_HZ ticks).
373 */ 373 */
374 error2 = clock->error >> (TICK_LENGTH_SHIFT + 22 - 2 * SHIFT_HZ); 374 error2 = clock->error >> (NTP_SCALE_SHIFT + 22 - 2 * SHIFT_HZ);
375 error2 = abs(error2); 375 error2 = abs(error2);
376 for (look_ahead = 0; error2 > 0; look_ahead++) 376 for (look_ahead = 0; error2 > 0; look_ahead++)
377 error2 >>= 2; 377 error2 >>= 2;
@@ -380,8 +380,7 @@ static __always_inline int clocksource_bigadjust(s64 error, s64 *interval,
380 * Now calculate the error in (1 << look_ahead) ticks, but first 380 * Now calculate the error in (1 << look_ahead) ticks, but first
381 * remove the single look ahead already included in the error. 381 * remove the single look ahead already included in the error.
382 */ 382 */
383 tick_error = current_tick_length() >> 383 tick_error = tick_length >> (NTP_SCALE_SHIFT - clock->shift + 1);
384 (TICK_LENGTH_SHIFT - clock->shift + 1);
385 tick_error -= clock->xtime_interval >> 1; 384 tick_error -= clock->xtime_interval >> 1;
386 error = ((error - tick_error) >> look_ahead) + tick_error; 385 error = ((error - tick_error) >> look_ahead) + tick_error;
387 386
@@ -412,7 +411,7 @@ static void clocksource_adjust(s64 offset)
412 s64 error, interval = clock->cycle_interval; 411 s64 error, interval = clock->cycle_interval;
413 int adj; 412 int adj;
414 413
415 error = clock->error >> (TICK_LENGTH_SHIFT - clock->shift - 1); 414 error = clock->error >> (NTP_SCALE_SHIFT - clock->shift - 1);
416 if (error > interval) { 415 if (error > interval) {
417 error >>= 2; 416 error >>= 2;
418 if (likely(error <= interval)) 417 if (likely(error <= interval))
@@ -434,7 +433,7 @@ static void clocksource_adjust(s64 offset)
434 clock->xtime_interval += interval; 433 clock->xtime_interval += interval;
435 clock->xtime_nsec -= offset; 434 clock->xtime_nsec -= offset;
436 clock->error -= (interval - offset) << 435 clock->error -= (interval - offset) <<
437 (TICK_LENGTH_SHIFT - clock->shift); 436 (NTP_SCALE_SHIFT - clock->shift);
438} 437}
439 438
440/** 439/**
@@ -473,8 +472,8 @@ void update_wall_time(void)
473 } 472 }
474 473
475 /* accumulate error between NTP and clock interval */ 474 /* accumulate error between NTP and clock interval */
476 clock->error += current_tick_length(); 475 clock->error += tick_length;
477 clock->error -= clock->xtime_interval << (TICK_LENGTH_SHIFT - clock->shift); 476 clock->error -= clock->xtime_interval << (NTP_SCALE_SHIFT - clock->shift);
478 } 477 }
479 478
480 /* correct the clock when NTP error is too big */ 479 /* correct the clock when NTP error is too big */
diff --git a/kernel/timeconst.pl b/kernel/timeconst.pl
index 41468035473c..eb51d76e058a 100644
--- a/kernel/timeconst.pl
+++ b/kernel/timeconst.pl
@@ -1,7 +1,7 @@
1#!/usr/bin/perl 1#!/usr/bin/perl
2# ----------------------------------------------------------------------- 2# -----------------------------------------------------------------------
3# 3#
4# Copyright 2007 rPath, Inc. - All Rights Reserved 4# Copyright 2007-2008 rPath, Inc. - All Rights Reserved
5# 5#
6# This file is part of the Linux kernel, and is made available under 6# This file is part of the Linux kernel, and is made available under
7# the terms of the GNU General Public License version 2 or (at your 7# the terms of the GNU General Public License version 2 or (at your
@@ -20,198 +20,138 @@
20%canned_values = ( 20%canned_values = (
21 24 => [ 21 24 => [
22 '0xa6aaaaab','0x2aaaaaa',26, 22 '0xa6aaaaab','0x2aaaaaa',26,
23 '0xa6aaaaaaaaaaaaab','0x2aaaaaaaaaaaaaa',58,
24 125,3, 23 125,3,
25 '0xc49ba5e4','0x1fbe76c8b4',37, 24 '0xc49ba5e4','0x1fbe76c8b4',37,
26 '0xc49ba5e353f7ceda','0x1fbe76c8b439581062',69,
27 3,125, 25 3,125,
28 '0xa2c2aaab','0xaaaa',16, 26 '0xa2c2aaab','0xaaaa',16,
29 '0xa2c2aaaaaaaaaaab','0xaaaaaaaaaaaa',48,
30 125000,3, 27 125000,3,
31 '0xc9539b89','0x7fffbce4217d',47, 28 '0xc9539b89','0x7fffbce4217d',47,
32 '0xc9539b8887229e91','0x7fffbce4217d2849cb25',79,
33 3,125000, 29 3,125000,
34 ], 32 => [ 30 ], 32 => [
35 '0xfa000000','0x6000000',27, 31 '0xfa000000','0x6000000',27,
36 '0xfa00000000000000','0x600000000000000',59,
37 125,4, 32 125,4,
38 '0x83126e98','0xfdf3b645a',36, 33 '0x83126e98','0xfdf3b645a',36,
39 '0x83126e978d4fdf3c','0xfdf3b645a1cac0831',68,
40 4,125, 34 4,125,
41 '0xf4240000','0x0',17, 35 '0xf4240000','0x0',17,
42 '0xf424000000000000','0x0',49,
43 31250,1, 36 31250,1,
44 '0x8637bd06','0x3fff79c842fa',46, 37 '0x8637bd06','0x3fff79c842fa',46,
45 '0x8637bd05af6c69b6','0x3fff79c842fa5093964a',78,
46 1,31250, 38 1,31250,
47 ], 48 => [ 39 ], 48 => [
48 '0xa6aaaaab','0x6aaaaaa',27, 40 '0xa6aaaaab','0x6aaaaaa',27,
49 '0xa6aaaaaaaaaaaaab','0x6aaaaaaaaaaaaaa',59,
50 125,6, 41 125,6,
51 '0xc49ba5e4','0xfdf3b645a',36, 42 '0xc49ba5e4','0xfdf3b645a',36,
52 '0xc49ba5e353f7ceda','0xfdf3b645a1cac0831',68,
53 6,125, 43 6,125,
54 '0xa2c2aaab','0x15555',17, 44 '0xa2c2aaab','0x15555',17,
55 '0xa2c2aaaaaaaaaaab','0x1555555555555',49,
56 62500,3, 45 62500,3,
57 '0xc9539b89','0x3fffbce4217d',46, 46 '0xc9539b89','0x3fffbce4217d',46,
58 '0xc9539b8887229e91','0x3fffbce4217d2849cb25',78,
59 3,62500, 47 3,62500,
60 ], 64 => [ 48 ], 64 => [
61 '0xfa000000','0xe000000',28, 49 '0xfa000000','0xe000000',28,
62 '0xfa00000000000000','0xe00000000000000',60,
63 125,8, 50 125,8,
64 '0x83126e98','0x7ef9db22d',35, 51 '0x83126e98','0x7ef9db22d',35,
65 '0x83126e978d4fdf3c','0x7ef9db22d0e560418',67,
66 8,125, 52 8,125,
67 '0xf4240000','0x0',18, 53 '0xf4240000','0x0',18,
68 '0xf424000000000000','0x0',50,
69 15625,1, 54 15625,1,
70 '0x8637bd06','0x1fff79c842fa',45, 55 '0x8637bd06','0x1fff79c842fa',45,
71 '0x8637bd05af6c69b6','0x1fff79c842fa5093964a',77,
72 1,15625, 56 1,15625,
73 ], 100 => [ 57 ], 100 => [
74 '0xa0000000','0x0',28, 58 '0xa0000000','0x0',28,
75 '0xa000000000000000','0x0',60,
76 10,1, 59 10,1,
77 '0xcccccccd','0x733333333',35, 60 '0xcccccccd','0x733333333',35,
78 '0xcccccccccccccccd','0x73333333333333333',67,
79 1,10, 61 1,10,
80 '0x9c400000','0x0',18, 62 '0x9c400000','0x0',18,
81 '0x9c40000000000000','0x0',50,
82 10000,1, 63 10000,1,
83 '0xd1b71759','0x1fff2e48e8a7',45, 64 '0xd1b71759','0x1fff2e48e8a7',45,
84 '0xd1b71758e219652c','0x1fff2e48e8a71de69ad4',77,
85 1,10000, 65 1,10000,
86 ], 122 => [ 66 ], 122 => [
87 '0x8325c53f','0xfbcda3a',28, 67 '0x8325c53f','0xfbcda3a',28,
88 '0x8325c53ef368eb05','0xfbcda3ac10c9714',60,
89 500,61, 68 500,61,
90 '0xf9db22d1','0x7fbe76c8b',35, 69 '0xf9db22d1','0x7fbe76c8b',35,
91 '0xf9db22d0e560418a','0x7fbe76c8b43958106',67,
92 61,500, 70 61,500,
93 '0x8012e2a0','0x3ef36',18, 71 '0x8012e2a0','0x3ef36',18,
94 '0x8012e29f79b47583','0x3ef368eb04325',50,
95 500000,61, 72 500000,61,
96 '0xffda4053','0x1ffffbce4217',45, 73 '0xffda4053','0x1ffffbce4217',45,
97 '0xffda4052d666a983','0x1ffffbce4217d2849cb2',77,
98 61,500000, 74 61,500000,
99 ], 128 => [ 75 ], 128 => [
100 '0xfa000000','0x1e000000',29, 76 '0xfa000000','0x1e000000',29,
101 '0xfa00000000000000','0x1e00000000000000',61,
102 125,16, 77 125,16,
103 '0x83126e98','0x3f7ced916',34, 78 '0x83126e98','0x3f7ced916',34,
104 '0x83126e978d4fdf3c','0x3f7ced916872b020c',66,
105 16,125, 79 16,125,
106 '0xf4240000','0x40000',19, 80 '0xf4240000','0x40000',19,
107 '0xf424000000000000','0x4000000000000',51,
108 15625,2, 81 15625,2,
109 '0x8637bd06','0xfffbce4217d',44, 82 '0x8637bd06','0xfffbce4217d',44,
110 '0x8637bd05af6c69b6','0xfffbce4217d2849cb25',76,
111 2,15625, 83 2,15625,
112 ], 200 => [ 84 ], 200 => [
113 '0xa0000000','0x0',29, 85 '0xa0000000','0x0',29,
114 '0xa000000000000000','0x0',61,
115 5,1, 86 5,1,
116 '0xcccccccd','0x333333333',34, 87 '0xcccccccd','0x333333333',34,
117 '0xcccccccccccccccd','0x33333333333333333',66,
118 1,5, 88 1,5,
119 '0x9c400000','0x0',19, 89 '0x9c400000','0x0',19,
120 '0x9c40000000000000','0x0',51,
121 5000,1, 90 5000,1,
122 '0xd1b71759','0xfff2e48e8a7',44, 91 '0xd1b71759','0xfff2e48e8a7',44,
123 '0xd1b71758e219652c','0xfff2e48e8a71de69ad4',76,
124 1,5000, 92 1,5000,
125 ], 250 => [ 93 ], 250 => [
126 '0x80000000','0x0',29, 94 '0x80000000','0x0',29,
127 '0x8000000000000000','0x0',61,
128 4,1, 95 4,1,
129 '0x80000000','0x180000000',33, 96 '0x80000000','0x180000000',33,
130 '0x8000000000000000','0x18000000000000000',65,
131 1,4, 97 1,4,
132 '0xfa000000','0x0',20, 98 '0xfa000000','0x0',20,
133 '0xfa00000000000000','0x0',52,
134 4000,1, 99 4000,1,
135 '0x83126e98','0x7ff7ced9168',43, 100 '0x83126e98','0x7ff7ced9168',43,
136 '0x83126e978d4fdf3c','0x7ff7ced916872b020c4',75,
137 1,4000, 101 1,4000,
138 ], 256 => [ 102 ], 256 => [
139 '0xfa000000','0x3e000000',30, 103 '0xfa000000','0x3e000000',30,
140 '0xfa00000000000000','0x3e00000000000000',62,
141 125,32, 104 125,32,
142 '0x83126e98','0x1fbe76c8b',33, 105 '0x83126e98','0x1fbe76c8b',33,
143 '0x83126e978d4fdf3c','0x1fbe76c8b43958106',65,
144 32,125, 106 32,125,
145 '0xf4240000','0xc0000',20, 107 '0xf4240000','0xc0000',20,
146 '0xf424000000000000','0xc000000000000',52,
147 15625,4, 108 15625,4,
148 '0x8637bd06','0x7ffde7210be',43, 109 '0x8637bd06','0x7ffde7210be',43,
149 '0x8637bd05af6c69b6','0x7ffde7210be9424e592',75,
150 4,15625, 110 4,15625,
151 ], 300 => [ 111 ], 300 => [
152 '0xd5555556','0x2aaaaaaa',30, 112 '0xd5555556','0x2aaaaaaa',30,
153 '0xd555555555555556','0x2aaaaaaaaaaaaaaa',62,
154 10,3, 113 10,3,
155 '0x9999999a','0x1cccccccc',33, 114 '0x9999999a','0x1cccccccc',33,
156 '0x999999999999999a','0x1cccccccccccccccc',65,
157 3,10, 115 3,10,
158 '0xd0555556','0xaaaaa',20, 116 '0xd0555556','0xaaaaa',20,
159 '0xd055555555555556','0xaaaaaaaaaaaaa',52,
160 10000,3, 117 10000,3,
161 '0x9d495183','0x7ffcb923a29',43, 118 '0x9d495183','0x7ffcb923a29',43,
162 '0x9d495182a9930be1','0x7ffcb923a29c779a6b5',75,
163 3,10000, 119 3,10000,
164 ], 512 => [ 120 ], 512 => [
165 '0xfa000000','0x7e000000',31, 121 '0xfa000000','0x7e000000',31,
166 '0xfa00000000000000','0x7e00000000000000',63,
167 125,64, 122 125,64,
168 '0x83126e98','0xfdf3b645',32, 123 '0x83126e98','0xfdf3b645',32,
169 '0x83126e978d4fdf3c','0xfdf3b645a1cac083',64,
170 64,125, 124 64,125,
171 '0xf4240000','0x1c0000',21, 125 '0xf4240000','0x1c0000',21,
172 '0xf424000000000000','0x1c000000000000',53,
173 15625,8, 126 15625,8,
174 '0x8637bd06','0x3ffef39085f',42, 127 '0x8637bd06','0x3ffef39085f',42,
175 '0x8637bd05af6c69b6','0x3ffef39085f4a1272c9',74,
176 8,15625, 128 8,15625,
177 ], 1000 => [ 129 ], 1000 => [
178 '0x80000000','0x0',31, 130 '0x80000000','0x0',31,
179 '0x8000000000000000','0x0',63,
180 1,1, 131 1,1,
181 '0x80000000','0x0',31, 132 '0x80000000','0x0',31,
182 '0x8000000000000000','0x0',63,
183 1,1, 133 1,1,
184 '0xfa000000','0x0',22, 134 '0xfa000000','0x0',22,
185 '0xfa00000000000000','0x0',54,
186 1000,1, 135 1000,1,
187 '0x83126e98','0x1ff7ced9168',41, 136 '0x83126e98','0x1ff7ced9168',41,
188 '0x83126e978d4fdf3c','0x1ff7ced916872b020c4',73,
189 1,1000, 137 1,1000,
190 ], 1024 => [ 138 ], 1024 => [
191 '0xfa000000','0xfe000000',32, 139 '0xfa000000','0xfe000000',32,
192 '0xfa00000000000000','0xfe00000000000000',64,
193 125,128, 140 125,128,
194 '0x83126e98','0x7ef9db22',31, 141 '0x83126e98','0x7ef9db22',31,
195 '0x83126e978d4fdf3c','0x7ef9db22d0e56041',63,
196 128,125, 142 128,125,
197 '0xf4240000','0x3c0000',22, 143 '0xf4240000','0x3c0000',22,
198 '0xf424000000000000','0x3c000000000000',54,
199 15625,16, 144 15625,16,
200 '0x8637bd06','0x1fff79c842f',41, 145 '0x8637bd06','0x1fff79c842f',41,
201 '0x8637bd05af6c69b6','0x1fff79c842fa5093964',73,
202 16,15625, 146 16,15625,
203 ], 1200 => [ 147 ], 1200 => [
204 '0xd5555556','0xd5555555',32, 148 '0xd5555556','0xd5555555',32,
205 '0xd555555555555556','0xd555555555555555',64,
206 5,6, 149 5,6,
207 '0x9999999a','0x66666666',31, 150 '0x9999999a','0x66666666',31,
208 '0x999999999999999a','0x6666666666666666',63,
209 6,5, 151 6,5,
210 '0xd0555556','0x2aaaaa',22, 152 '0xd0555556','0x2aaaaa',22,
211 '0xd055555555555556','0x2aaaaaaaaaaaaa',54,
212 2500,3, 153 2500,3,
213 '0x9d495183','0x1ffcb923a29',41, 154 '0x9d495183','0x1ffcb923a29',41,
214 '0x9d495182a9930be1','0x1ffcb923a29c779a6b5',73,
215 3,2500, 155 3,2500,
216 ] 156 ]
217); 157);
@@ -264,6 +204,15 @@ sub fmuls($$$) {
264 return 0; 204 return 0;
265} 205}
266 206
207# Generate a hex value if the result fits in 64 bits;
208# otherwise skip.
209sub bignum_hex($) {
210 my($x) = @_;
211 my $s = $x->as_hex();
212
213 return (length($s) > 18) ? undef : $s;
214}
215
267# Provides mul, adj, and shr factors for a specific 216# Provides mul, adj, and shr factors for a specific
268# (bit, time, hz) combination 217# (bit, time, hz) combination
269sub muladj($$$) { 218sub muladj($$$) {
@@ -271,7 +220,7 @@ sub muladj($$$) {
271 my $s = fmuls($b, $t, $hz); 220 my $s = fmuls($b, $t, $hz);
272 my $m = fmul($s, $t, $hz); 221 my $m = fmul($s, $t, $hz);
273 my $a = fadj($s, $t, $hz); 222 my $a = fadj($s, $t, $hz);
274 return ($m->as_hex(), $a->as_hex(), $s); 223 return (bignum_hex($m), bignum_hex($a), $s);
275} 224}
276 225
277# Provides numerator, denominator values 226# Provides numerator, denominator values
@@ -288,12 +237,10 @@ sub conversions($$) {
288 237
289 # HZ_TO_xx 238 # HZ_TO_xx
290 push(@val, muladj(32, $t, $hz)); 239 push(@val, muladj(32, $t, $hz));
291 push(@val, muladj(64, $t, $hz));
292 push(@val, numden($t, $hz)); 240 push(@val, numden($t, $hz));
293 241
294 # xx_TO_HZ 242 # xx_TO_HZ
295 push(@val, muladj(32, $hz, $t)); 243 push(@val, muladj(32, $hz, $t));
296 push(@val, muladj(64, $hz, $t));
297 push(@val, numden($hz, $t)); 244 push(@val, numden($hz, $t));
298 245
299 return @val; 246 return @val;
@@ -318,6 +265,19 @@ sub compute_values($) {
318 return @val; 265 return @val;
319} 266}
320 267
268sub outputval($$)
269{
270 my($name, $val) = @_;
271 my $csuf;
272
273 if (defined($val)) {
274 if ($name !~ /SHR/) {
275 $val = "U64_C($val)";
276 }
277 printf "#define %-23s %s\n", $name.$csuf, $val.$csuf;
278 }
279}
280
321sub output($@) 281sub output($@)
322{ 282{
323 my($hz, @val) = @_; 283 my($hz, @val) = @_;
@@ -331,6 +291,7 @@ sub output($@)
331 print "\n"; 291 print "\n";
332 292
333 print "#include <linux/param.h>\n"; 293 print "#include <linux/param.h>\n";
294 print "#include <linux/types.h>\n";
334 295
335 print "\n"; 296 print "\n";
336 print "#if HZ != $hz\n"; 297 print "#if HZ != $hz\n";
@@ -340,15 +301,13 @@ sub output($@)
340 301
341 foreach $pfx ('HZ_TO_MSEC','MSEC_TO_HZ', 302 foreach $pfx ('HZ_TO_MSEC','MSEC_TO_HZ',
342 'HZ_TO_USEC','USEC_TO_HZ') { 303 'HZ_TO_USEC','USEC_TO_HZ') {
343 foreach $bit (32, 64) { 304 foreach $bit (32) {
344 foreach $suf ('MUL', 'ADJ', 'SHR') { 305 foreach $suf ('MUL', 'ADJ', 'SHR') {
345 printf "#define %-23s %s\n", 306 outputval("${pfx}_$suf$bit", shift(@val));
346 "${pfx}_$suf$bit", shift(@val);
347 } 307 }
348 } 308 }
349 foreach $suf ('NUM', 'DEN') { 309 foreach $suf ('NUM', 'DEN') {
350 printf "#define %-23s %s\n", 310 outputval("${pfx}_$suf", shift(@val));
351 "${pfx}_$suf", shift(@val);
352 } 311 }
353 } 312 }
354 313
@@ -356,6 +315,23 @@ sub output($@)
356 print "#endif /* KERNEL_TIMECONST_H */\n"; 315 print "#endif /* KERNEL_TIMECONST_H */\n";
357} 316}
358 317
318# Pretty-print Perl values
319sub perlvals(@) {
320 my $v;
321 my @l = ();
322
323 foreach $v (@_) {
324 if (!defined($v)) {
325 push(@l, 'undef');
326 } elsif ($v =~ /^0x/) {
327 push(@l, "\'".$v."\'");
328 } else {
329 push(@l, $v.'');
330 }
331 }
332 return join(',', @l);
333}
334
359($hz) = @ARGV; 335($hz) = @ARGV;
360 336
361# Use this to generate the %canned_values structure 337# Use this to generate the %canned_values structure
@@ -373,15 +349,15 @@ if ($hz eq '--can') {
373 print "$pf$hz => [\n"; 349 print "$pf$hz => [\n";
374 while (scalar(@values)) { 350 while (scalar(@values)) {
375 my $bit; 351 my $bit;
376 foreach $bit (32, 64) { 352 foreach $bit (32) {
377 my $m = shift(@values); 353 my $m = shift(@values);
378 my $a = shift(@values); 354 my $a = shift(@values);
379 my $s = shift(@values); 355 my $s = shift(@values);
380 print "\t\t\'",$m,"\',\'",$a,"\',",$s,",\n"; 356 print "\t\t", perlvals($m,$a,$s), ",\n";
381 } 357 }
382 my $n = shift(@values); 358 my $n = shift(@values);
383 my $d = shift(@values); 359 my $d = shift(@values);
384 print "\t\t",$n,',',$d,",\n"; 360 print "\t\t", perlvals($n,$d), ",\n";
385 } 361 }
386 print "\t]"; 362 print "\t]";
387 $pf = ', '; 363 $pf = ', ';
diff --git a/kernel/timer.c b/kernel/timer.c
index f3d35d4ea42e..ceacc6626572 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -320,14 +320,130 @@ static void timer_stats_account_timer(struct timer_list *timer)
320static void timer_stats_account_timer(struct timer_list *timer) {} 320static void timer_stats_account_timer(struct timer_list *timer) {}
321#endif 321#endif
322 322
323/** 323#ifdef CONFIG_DEBUG_OBJECTS_TIMERS
324 * init_timer - initialize a timer. 324
325 * @timer: the timer to be initialized 325static struct debug_obj_descr timer_debug_descr;
326 * 326
327 * init_timer() must be done to a timer prior calling *any* of the 327/*
328 * other timer functions. 328 * fixup_init is called when:
329 * - an active object is initialized
329 */ 330 */
330void init_timer(struct timer_list *timer) 331static int timer_fixup_init(void *addr, enum debug_obj_state state)
332{
333 struct timer_list *timer = addr;
334
335 switch (state) {
336 case ODEBUG_STATE_ACTIVE:
337 del_timer_sync(timer);
338 debug_object_init(timer, &timer_debug_descr);
339 return 1;
340 default:
341 return 0;
342 }
343}
344
345/*
346 * fixup_activate is called when:
347 * - an active object is activated
348 * - an unknown object is activated (might be a statically initialized object)
349 */
350static int timer_fixup_activate(void *addr, enum debug_obj_state state)
351{
352 struct timer_list *timer = addr;
353
354 switch (state) {
355
356 case ODEBUG_STATE_NOTAVAILABLE:
357 /*
358 * This is not really a fixup. The timer was
359 * statically initialized. We just make sure that it
360 * is tracked in the object tracker.
361 */
362 if (timer->entry.next == NULL &&
363 timer->entry.prev == TIMER_ENTRY_STATIC) {
364 debug_object_init(timer, &timer_debug_descr);
365 debug_object_activate(timer, &timer_debug_descr);
366 return 0;
367 } else {
368 WARN_ON_ONCE(1);
369 }
370 return 0;
371
372 case ODEBUG_STATE_ACTIVE:
373 WARN_ON(1);
374
375 default:
376 return 0;
377 }
378}
379
380/*
381 * fixup_free is called when:
382 * - an active object is freed
383 */
384static int timer_fixup_free(void *addr, enum debug_obj_state state)
385{
386 struct timer_list *timer = addr;
387
388 switch (state) {
389 case ODEBUG_STATE_ACTIVE:
390 del_timer_sync(timer);
391 debug_object_free(timer, &timer_debug_descr);
392 return 1;
393 default:
394 return 0;
395 }
396}
397
398static struct debug_obj_descr timer_debug_descr = {
399 .name = "timer_list",
400 .fixup_init = timer_fixup_init,
401 .fixup_activate = timer_fixup_activate,
402 .fixup_free = timer_fixup_free,
403};
404
405static inline void debug_timer_init(struct timer_list *timer)
406{
407 debug_object_init(timer, &timer_debug_descr);
408}
409
410static inline void debug_timer_activate(struct timer_list *timer)
411{
412 debug_object_activate(timer, &timer_debug_descr);
413}
414
415static inline void debug_timer_deactivate(struct timer_list *timer)
416{
417 debug_object_deactivate(timer, &timer_debug_descr);
418}
419
420static inline void debug_timer_free(struct timer_list *timer)
421{
422 debug_object_free(timer, &timer_debug_descr);
423}
424
425static void __init_timer(struct timer_list *timer);
426
427void init_timer_on_stack(struct timer_list *timer)
428{
429 debug_object_init_on_stack(timer, &timer_debug_descr);
430 __init_timer(timer);
431}
432EXPORT_SYMBOL_GPL(init_timer_on_stack);
433
434void destroy_timer_on_stack(struct timer_list *timer)
435{
436 debug_object_free(timer, &timer_debug_descr);
437}
438EXPORT_SYMBOL_GPL(destroy_timer_on_stack);
439
440#else
441static inline void debug_timer_init(struct timer_list *timer) { }
442static inline void debug_timer_activate(struct timer_list *timer) { }
443static inline void debug_timer_deactivate(struct timer_list *timer) { }
444#endif
445
446static void __init_timer(struct timer_list *timer)
331{ 447{
332 timer->entry.next = NULL; 448 timer->entry.next = NULL;
333 timer->base = __raw_get_cpu_var(tvec_bases); 449 timer->base = __raw_get_cpu_var(tvec_bases);
@@ -337,6 +453,19 @@ void init_timer(struct timer_list *timer)
337 memset(timer->start_comm, 0, TASK_COMM_LEN); 453 memset(timer->start_comm, 0, TASK_COMM_LEN);
338#endif 454#endif
339} 455}
456
457/**
458 * init_timer - initialize a timer.
459 * @timer: the timer to be initialized
460 *
461 * init_timer() must be done to a timer prior calling *any* of the
462 * other timer functions.
463 */
464void init_timer(struct timer_list *timer)
465{
466 debug_timer_init(timer);
467 __init_timer(timer);
468}
340EXPORT_SYMBOL(init_timer); 469EXPORT_SYMBOL(init_timer);
341 470
342void init_timer_deferrable(struct timer_list *timer) 471void init_timer_deferrable(struct timer_list *timer)
@@ -351,6 +480,8 @@ static inline void detach_timer(struct timer_list *timer,
351{ 480{
352 struct list_head *entry = &timer->entry; 481 struct list_head *entry = &timer->entry;
353 482
483 debug_timer_deactivate(timer);
484
354 __list_del(entry->prev, entry->next); 485 __list_del(entry->prev, entry->next);
355 if (clear_pending) 486 if (clear_pending)
356 entry->next = NULL; 487 entry->next = NULL;
@@ -405,6 +536,8 @@ int __mod_timer(struct timer_list *timer, unsigned long expires)
405 ret = 1; 536 ret = 1;
406 } 537 }
407 538
539 debug_timer_activate(timer);
540
408 new_base = __get_cpu_var(tvec_bases); 541 new_base = __get_cpu_var(tvec_bases);
409 542
410 if (base != new_base) { 543 if (base != new_base) {
@@ -450,6 +583,7 @@ void add_timer_on(struct timer_list *timer, int cpu)
450 BUG_ON(timer_pending(timer) || !timer->function); 583 BUG_ON(timer_pending(timer) || !timer->function);
451 spin_lock_irqsave(&base->lock, flags); 584 spin_lock_irqsave(&base->lock, flags);
452 timer_set_base(timer, base); 585 timer_set_base(timer, base);
586 debug_timer_activate(timer);
453 internal_add_timer(base, timer); 587 internal_add_timer(base, timer);
454 /* 588 /*
455 * Check whether the other CPU is idle and needs to be 589 * Check whether the other CPU is idle and needs to be
@@ -1086,11 +1220,14 @@ signed long __sched schedule_timeout(signed long timeout)
1086 1220
1087 expire = timeout + jiffies; 1221 expire = timeout + jiffies;
1088 1222
1089 setup_timer(&timer, process_timeout, (unsigned long)current); 1223 setup_timer_on_stack(&timer, process_timeout, (unsigned long)current);
1090 __mod_timer(&timer, expire); 1224 __mod_timer(&timer, expire);
1091 schedule(); 1225 schedule();
1092 del_singleshot_timer_sync(&timer); 1226 del_singleshot_timer_sync(&timer);
1093 1227
1228 /* Remove the timer from the object tracker */
1229 destroy_timer_on_stack(&timer);
1230
1094 timeout = expire - jiffies; 1231 timeout = expire - jiffies;
1095 1232
1096 out: 1233 out:
diff --git a/kernel/user.c b/kernel/user.c
index aefbbfa3159f..865ecf57a096 100644
--- a/kernel/user.c
+++ b/kernel/user.c
@@ -384,7 +384,7 @@ void free_uid(struct user_struct *up)
384 local_irq_restore(flags); 384 local_irq_restore(flags);
385} 385}
386 386
387struct user_struct * alloc_uid(struct user_namespace *ns, uid_t uid) 387struct user_struct *alloc_uid(struct user_namespace *ns, uid_t uid)
388{ 388{
389 struct hlist_head *hashent = uidhashentry(ns, uid); 389 struct hlist_head *hashent = uidhashentry(ns, uid);
390 struct user_struct *up, *new; 390 struct user_struct *up, *new;
@@ -399,26 +399,12 @@ struct user_struct * alloc_uid(struct user_namespace *ns, uid_t uid)
399 spin_unlock_irq(&uidhash_lock); 399 spin_unlock_irq(&uidhash_lock);
400 400
401 if (!up) { 401 if (!up) {
402 new = kmem_cache_alloc(uid_cachep, GFP_KERNEL); 402 new = kmem_cache_zalloc(uid_cachep, GFP_KERNEL);
403 if (!new) 403 if (!new)
404 goto out_unlock; 404 goto out_unlock;
405 405
406 new->uid = uid; 406 new->uid = uid;
407 atomic_set(&new->__count, 1); 407 atomic_set(&new->__count, 1);
408 atomic_set(&new->processes, 0);
409 atomic_set(&new->files, 0);
410 atomic_set(&new->sigpending, 0);
411#ifdef CONFIG_INOTIFY_USER
412 atomic_set(&new->inotify_watches, 0);
413 atomic_set(&new->inotify_devs, 0);
414#endif
415#ifdef CONFIG_POSIX_MQUEUE
416 new->mq_bytes = 0;
417#endif
418 new->locked_shm = 0;
419#ifdef CONFIG_KEYS
420 new->uid_keyring = new->session_keyring = NULL;
421#endif
422 408
423 if (sched_create_user(new) < 0) 409 if (sched_create_user(new) < 0)
424 goto out_free_user; 410 goto out_free_user;
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 7db251a959c5..29fc39f1029c 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -195,7 +195,6 @@ static void delayed_work_timer_fn(unsigned long __data)
195int queue_delayed_work(struct workqueue_struct *wq, 195int queue_delayed_work(struct workqueue_struct *wq,
196 struct delayed_work *dwork, unsigned long delay) 196 struct delayed_work *dwork, unsigned long delay)
197{ 197{
198 timer_stats_timer_set_start_info(&dwork->timer);
199 if (delay == 0) 198 if (delay == 0)
200 return queue_work(wq, &dwork->work); 199 return queue_work(wq, &dwork->work);
201 200
@@ -219,11 +218,12 @@ int queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
219 struct timer_list *timer = &dwork->timer; 218 struct timer_list *timer = &dwork->timer;
220 struct work_struct *work = &dwork->work; 219 struct work_struct *work = &dwork->work;
221 220
222 timer_stats_timer_set_start_info(&dwork->timer);
223 if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) { 221 if (!test_and_set_bit(WORK_STRUCT_PENDING, work_data_bits(work))) {
224 BUG_ON(timer_pending(timer)); 222 BUG_ON(timer_pending(timer));
225 BUG_ON(!list_empty(&work->entry)); 223 BUG_ON(!list_empty(&work->entry));
226 224
225 timer_stats_timer_set_start_info(&dwork->timer);
226
227 /* This stores cwq for the moment, for the timer_fn */ 227 /* This stores cwq for the moment, for the timer_fn */
228 set_wq_data(work, wq_per_cpu(wq, raw_smp_processor_id())); 228 set_wq_data(work, wq_per_cpu(wq, raw_smp_processor_id()));
229 timer->expires = jiffies + delay; 229 timer->expires = jiffies + delay;
@@ -247,7 +247,7 @@ static void run_workqueue(struct cpu_workqueue_struct *cwq)
247 if (cwq->run_depth > 3) { 247 if (cwq->run_depth > 3) {
248 /* morton gets to eat his hat */ 248 /* morton gets to eat his hat */
249 printk("%s: recursion depth exceeded: %d\n", 249 printk("%s: recursion depth exceeded: %d\n",
250 __FUNCTION__, cwq->run_depth); 250 __func__, cwq->run_depth);
251 dump_stack(); 251 dump_stack();
252 } 252 }
253 while (!list_empty(&cwq->worklist)) { 253 while (!list_empty(&cwq->worklist)) {
@@ -564,7 +564,6 @@ EXPORT_SYMBOL(schedule_work);
564int schedule_delayed_work(struct delayed_work *dwork, 564int schedule_delayed_work(struct delayed_work *dwork,
565 unsigned long delay) 565 unsigned long delay)
566{ 566{
567 timer_stats_timer_set_start_info(&dwork->timer);
568 return queue_delayed_work(keventd_wq, dwork, delay); 567 return queue_delayed_work(keventd_wq, dwork, delay);
569} 568}
570EXPORT_SYMBOL(schedule_delayed_work); 569EXPORT_SYMBOL(schedule_delayed_work);
@@ -581,7 +580,6 @@ EXPORT_SYMBOL(schedule_delayed_work);
581int schedule_delayed_work_on(int cpu, 580int schedule_delayed_work_on(int cpu,
582 struct delayed_work *dwork, unsigned long delay) 581 struct delayed_work *dwork, unsigned long delay)
583{ 582{
584 timer_stats_timer_set_start_info(&dwork->timer);
585 return queue_delayed_work_on(cpu, keventd_wq, dwork, delay); 583 return queue_delayed_work_on(cpu, keventd_wq, dwork, delay);
586} 584}
587EXPORT_SYMBOL(schedule_delayed_work_on); 585EXPORT_SYMBOL(schedule_delayed_work_on);
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 754cc0027f2a..d2099f41aa1e 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -194,6 +194,37 @@ config TIMER_STATS
194 (it defaults to deactivated on bootup and will only be activated 194 (it defaults to deactivated on bootup and will only be activated
195 if some application like powertop activates it explicitly). 195 if some application like powertop activates it explicitly).
196 196
197config DEBUG_OBJECTS
198 bool "Debug object operations"
199 depends on DEBUG_KERNEL
200 help
201 If you say Y here, additional code will be inserted into the
202 kernel to track the life time of various objects and validate
203 the operations on those objects.
204
205config DEBUG_OBJECTS_SELFTEST
206 bool "Debug objects selftest"
207 depends on DEBUG_OBJECTS
208 help
209 This enables the selftest of the object debug code.
210
211config DEBUG_OBJECTS_FREE
212 bool "Debug objects in freed memory"
213 depends on DEBUG_OBJECTS
214 help
215 This enables checks whether a k/v free operation frees an area
216 which contains an object which has not been deactivated
217 properly. This can make kmalloc/kfree-intensive workloads
218 much slower.
219
220config DEBUG_OBJECTS_TIMERS
221 bool "Debug timer objects"
222 depends on DEBUG_OBJECTS
223 help
224 If you say Y here, additional code will be inserted into the
225 timer routines to track the life time of timer objects and
226 validate the timer operations.
227
197config DEBUG_SLAB 228config DEBUG_SLAB
198 bool "Debug slab memory allocations" 229 bool "Debug slab memory allocations"
199 depends on DEBUG_KERNEL && SLAB 230 depends on DEBUG_KERNEL && SLAB
diff --git a/lib/Kconfig.kgdb b/lib/Kconfig.kgdb
index f2e01ac5ab09..a5d4b1dac2a5 100644
--- a/lib/Kconfig.kgdb
+++ b/lib/Kconfig.kgdb
@@ -1,4 +1,10 @@
1 1
2config HAVE_ARCH_KGDB_SHADOW_INFO
3 bool
4
5config HAVE_ARCH_KGDB
6 bool
7
2menuconfig KGDB 8menuconfig KGDB
3 bool "KGDB: kernel debugging with remote gdb" 9 bool "KGDB: kernel debugging with remote gdb"
4 select FRAME_POINTER 10 select FRAME_POINTER
@@ -10,15 +16,10 @@ menuconfig KGDB
10 at http://kgdb.sourceforge.net as well as in DocBook form 16 at http://kgdb.sourceforge.net as well as in DocBook form
11 in Documentation/DocBook/. If unsure, say N. 17 in Documentation/DocBook/. If unsure, say N.
12 18
13config HAVE_ARCH_KGDB_SHADOW_INFO 19if KGDB
14 bool
15
16config HAVE_ARCH_KGDB
17 bool
18 20
19config KGDB_SERIAL_CONSOLE 21config KGDB_SERIAL_CONSOLE
20 tristate "KGDB: use kgdb over the serial console" 22 tristate "KGDB: use kgdb over the serial console"
21 depends on KGDB
22 select CONSOLE_POLL 23 select CONSOLE_POLL
23 select MAGIC_SYSRQ 24 select MAGIC_SYSRQ
24 default y 25 default y
@@ -28,7 +29,6 @@ config KGDB_SERIAL_CONSOLE
28 29
29config KGDB_TESTS 30config KGDB_TESTS
30 bool "KGDB: internal test suite" 31 bool "KGDB: internal test suite"
31 depends on KGDB
32 default n 32 default n
33 help 33 help
34 This is a kgdb I/O module specifically designed to test 34 This is a kgdb I/O module specifically designed to test
@@ -56,3 +56,5 @@ config KGDB_TESTS_BOOT_STRING
56 boot. See the drivers/misc/kgdbts.c for detailed 56 boot. See the drivers/misc/kgdbts.c for detailed
57 information about other strings you could use beyond the 57 information about other strings you could use beyond the
58 default of V1F100. 58 default of V1F100.
59
60endif # KGDB
diff --git a/lib/Makefile b/lib/Makefile
index 0ae4eb047aac..74b0cfb1fcc3 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -36,6 +36,7 @@ obj-$(CONFIG_LOCK_KERNEL) += kernel_lock.o
36obj-$(CONFIG_PLIST) += plist.o 36obj-$(CONFIG_PLIST) += plist.o
37obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o 37obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
38obj-$(CONFIG_DEBUG_LIST) += list_debug.o 38obj-$(CONFIG_DEBUG_LIST) += list_debug.o
39obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
39 40
40ifneq ($(CONFIG_HAVE_DEC_LOCK),y) 41ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
41 lib-y += dec_and_lock.o 42 lib-y += dec_and_lock.o
diff --git a/lib/debugobjects.c b/lib/debugobjects.c
new file mode 100644
index 000000000000..a76a5e122ae1
--- /dev/null
+++ b/lib/debugobjects.c
@@ -0,0 +1,890 @@
1/*
2 * Generic infrastructure for lifetime debugging of objects.
3 *
4 * Started by Thomas Gleixner
5 *
6 * Copyright (C) 2008, Thomas Gleixner <tglx@linutronix.de>
7 *
8 * For licencing details see kernel-base/COPYING
9 */
10#include <linux/debugobjects.h>
11#include <linux/interrupt.h>
12#include <linux/seq_file.h>
13#include <linux/debugfs.h>
14#include <linux/hash.h>
15
16#define ODEBUG_HASH_BITS 14
17#define ODEBUG_HASH_SIZE (1 << ODEBUG_HASH_BITS)
18
19#define ODEBUG_POOL_SIZE 512
20#define ODEBUG_POOL_MIN_LEVEL 256
21
22#define ODEBUG_CHUNK_SHIFT PAGE_SHIFT
23#define ODEBUG_CHUNK_SIZE (1 << ODEBUG_CHUNK_SHIFT)
24#define ODEBUG_CHUNK_MASK (~(ODEBUG_CHUNK_SIZE - 1))
25
26struct debug_bucket {
27 struct hlist_head list;
28 spinlock_t lock;
29};
30
31static struct debug_bucket obj_hash[ODEBUG_HASH_SIZE];
32
33static struct debug_obj obj_static_pool[ODEBUG_POOL_SIZE];
34
35static DEFINE_SPINLOCK(pool_lock);
36
37static HLIST_HEAD(obj_pool);
38
39static int obj_pool_min_free = ODEBUG_POOL_SIZE;
40static int obj_pool_free = ODEBUG_POOL_SIZE;
41static int obj_pool_used;
42static int obj_pool_max_used;
43static struct kmem_cache *obj_cache;
44
45static int debug_objects_maxchain __read_mostly;
46static int debug_objects_fixups __read_mostly;
47static int debug_objects_warnings __read_mostly;
48static int debug_objects_enabled __read_mostly;
49static struct debug_obj_descr *descr_test __read_mostly;
50
51static int __init enable_object_debug(char *str)
52{
53 debug_objects_enabled = 1;
54 return 0;
55}
56early_param("debug_objects", enable_object_debug);
57
58static const char *obj_states[ODEBUG_STATE_MAX] = {
59 [ODEBUG_STATE_NONE] = "none",
60 [ODEBUG_STATE_INIT] = "initialized",
61 [ODEBUG_STATE_INACTIVE] = "inactive",
62 [ODEBUG_STATE_ACTIVE] = "active",
63 [ODEBUG_STATE_DESTROYED] = "destroyed",
64 [ODEBUG_STATE_NOTAVAILABLE] = "not available",
65};
66
67static int fill_pool(void)
68{
69 gfp_t gfp = GFP_ATOMIC | __GFP_NORETRY | __GFP_NOWARN;
70 struct debug_obj *new;
71
72 if (likely(obj_pool_free >= ODEBUG_POOL_MIN_LEVEL))
73 return obj_pool_free;
74
75 if (unlikely(!obj_cache))
76 return obj_pool_free;
77
78 while (obj_pool_free < ODEBUG_POOL_MIN_LEVEL) {
79
80 new = kmem_cache_zalloc(obj_cache, gfp);
81 if (!new)
82 return obj_pool_free;
83
84 spin_lock(&pool_lock);
85 hlist_add_head(&new->node, &obj_pool);
86 obj_pool_free++;
87 spin_unlock(&pool_lock);
88 }
89 return obj_pool_free;
90}
91
92/*
93 * Lookup an object in the hash bucket.
94 */
95static struct debug_obj *lookup_object(void *addr, struct debug_bucket *b)
96{
97 struct hlist_node *node;
98 struct debug_obj *obj;
99 int cnt = 0;
100
101 hlist_for_each_entry(obj, node, &b->list, node) {
102 cnt++;
103 if (obj->object == addr)
104 return obj;
105 }
106 if (cnt > debug_objects_maxchain)
107 debug_objects_maxchain = cnt;
108
109 return NULL;
110}
111
112/*
113 * Allocate a new object. If the pool is empty and no refill possible,
114 * switch off the debugger.
115 */
116static struct debug_obj *
117alloc_object(void *addr, struct debug_bucket *b, struct debug_obj_descr *descr)
118{
119 struct debug_obj *obj = NULL;
120 int retry = 0;
121
122repeat:
123 spin_lock(&pool_lock);
124 if (obj_pool.first) {
125 obj = hlist_entry(obj_pool.first, typeof(*obj), node);
126
127 obj->object = addr;
128 obj->descr = descr;
129 obj->state = ODEBUG_STATE_NONE;
130 hlist_del(&obj->node);
131
132 hlist_add_head(&obj->node, &b->list);
133
134 obj_pool_used++;
135 if (obj_pool_used > obj_pool_max_used)
136 obj_pool_max_used = obj_pool_used;
137
138 obj_pool_free--;
139 if (obj_pool_free < obj_pool_min_free)
140 obj_pool_min_free = obj_pool_free;
141 }
142 spin_unlock(&pool_lock);
143
144 if (fill_pool() && !obj && !retry++)
145 goto repeat;
146
147 return obj;
148}
149
150/*
151 * Put the object back into the pool or give it back to kmem_cache:
152 */
153static void free_object(struct debug_obj *obj)
154{
155 unsigned long idx = (unsigned long)(obj - obj_static_pool);
156
157 if (obj_pool_free < ODEBUG_POOL_SIZE || idx < ODEBUG_POOL_SIZE) {
158 spin_lock(&pool_lock);
159 hlist_add_head(&obj->node, &obj_pool);
160 obj_pool_free++;
161 obj_pool_used--;
162 spin_unlock(&pool_lock);
163 } else {
164 spin_lock(&pool_lock);
165 obj_pool_used--;
166 spin_unlock(&pool_lock);
167 kmem_cache_free(obj_cache, obj);
168 }
169}
170
171/*
172 * We run out of memory. That means we probably have tons of objects
173 * allocated.
174 */
175static void debug_objects_oom(void)
176{
177 struct debug_bucket *db = obj_hash;
178 struct hlist_node *node, *tmp;
179 struct debug_obj *obj;
180 unsigned long flags;
181 int i;
182
183 printk(KERN_WARNING "ODEBUG: Out of memory. ODEBUG disabled\n");
184
185 for (i = 0; i < ODEBUG_HASH_SIZE; i++, db++) {
186 spin_lock_irqsave(&db->lock, flags);
187 hlist_for_each_entry_safe(obj, node, tmp, &db->list, node) {
188 hlist_del(&obj->node);
189 free_object(obj);
190 }
191 spin_unlock_irqrestore(&db->lock, flags);
192 }
193}
194
195/*
196 * We use the pfn of the address for the hash. That way we can check
197 * for freed objects simply by checking the affected bucket.
198 */
199static struct debug_bucket *get_bucket(unsigned long addr)
200{
201 unsigned long hash;
202
203 hash = hash_long((addr >> ODEBUG_CHUNK_SHIFT), ODEBUG_HASH_BITS);
204 return &obj_hash[hash];
205}
206
207static void debug_print_object(struct debug_obj *obj, char *msg)
208{
209 static int limit;
210
211 if (limit < 5 && obj->descr != descr_test) {
212 limit++;
213 printk(KERN_ERR "ODEBUG: %s %s object type: %s\n", msg,
214 obj_states[obj->state], obj->descr->name);
215 WARN_ON(1);
216 }
217 debug_objects_warnings++;
218}
219
220/*
221 * Try to repair the damage, so we have a better chance to get useful
222 * debug output.
223 */
224static void
225debug_object_fixup(int (*fixup)(void *addr, enum debug_obj_state state),
226 void * addr, enum debug_obj_state state)
227{
228 if (fixup)
229 debug_objects_fixups += fixup(addr, state);
230}
231
232static void debug_object_is_on_stack(void *addr, int onstack)
233{
234 void *stack = current->stack;
235 int is_on_stack;
236 static int limit;
237
238 if (limit > 4)
239 return;
240
241 is_on_stack = (addr >= stack && addr < (stack + THREAD_SIZE));
242
243 if (is_on_stack == onstack)
244 return;
245
246 limit++;
247 if (is_on_stack)
248 printk(KERN_WARNING
249 "ODEBUG: object is on stack, but not annotated\n");
250 else
251 printk(KERN_WARNING
252 "ODEBUG: object is not on stack, but annotated\n");
253 WARN_ON(1);
254}
255
256static void
257__debug_object_init(void *addr, struct debug_obj_descr *descr, int onstack)
258{
259 enum debug_obj_state state;
260 struct debug_bucket *db;
261 struct debug_obj *obj;
262 unsigned long flags;
263
264 db = get_bucket((unsigned long) addr);
265
266 spin_lock_irqsave(&db->lock, flags);
267
268 obj = lookup_object(addr, db);
269 if (!obj) {
270 obj = alloc_object(addr, db, descr);
271 if (!obj) {
272 debug_objects_enabled = 0;
273 spin_unlock_irqrestore(&db->lock, flags);
274 debug_objects_oom();
275 return;
276 }
277 debug_object_is_on_stack(addr, onstack);
278 }
279
280 switch (obj->state) {
281 case ODEBUG_STATE_NONE:
282 case ODEBUG_STATE_INIT:
283 case ODEBUG_STATE_INACTIVE:
284 obj->state = ODEBUG_STATE_INIT;
285 break;
286
287 case ODEBUG_STATE_ACTIVE:
288 debug_print_object(obj, "init");
289 state = obj->state;
290 spin_unlock_irqrestore(&db->lock, flags);
291 debug_object_fixup(descr->fixup_init, addr, state);
292 return;
293
294 case ODEBUG_STATE_DESTROYED:
295 debug_print_object(obj, "init");
296 break;
297 default:
298 break;
299 }
300
301 spin_unlock_irqrestore(&db->lock, flags);
302}
303
304/**
305 * debug_object_init - debug checks when an object is initialized
306 * @addr: address of the object
307 * @descr: pointer to an object specific debug description structure
308 */
309void debug_object_init(void *addr, struct debug_obj_descr *descr)
310{
311 if (!debug_objects_enabled)
312 return;
313
314 __debug_object_init(addr, descr, 0);
315}
316
317/**
318 * debug_object_init_on_stack - debug checks when an object on stack is
319 * initialized
320 * @addr: address of the object
321 * @descr: pointer to an object specific debug description structure
322 */
323void debug_object_init_on_stack(void *addr, struct debug_obj_descr *descr)
324{
325 if (!debug_objects_enabled)
326 return;
327
328 __debug_object_init(addr, descr, 1);
329}
330
331/**
332 * debug_object_activate - debug checks when an object is activated
333 * @addr: address of the object
334 * @descr: pointer to an object specific debug description structure
335 */
336void debug_object_activate(void *addr, struct debug_obj_descr *descr)
337{
338 enum debug_obj_state state;
339 struct debug_bucket *db;
340 struct debug_obj *obj;
341 unsigned long flags;
342
343 if (!debug_objects_enabled)
344 return;
345
346 db = get_bucket((unsigned long) addr);
347
348 spin_lock_irqsave(&db->lock, flags);
349
350 obj = lookup_object(addr, db);
351 if (obj) {
352 switch (obj->state) {
353 case ODEBUG_STATE_INIT:
354 case ODEBUG_STATE_INACTIVE:
355 obj->state = ODEBUG_STATE_ACTIVE;
356 break;
357
358 case ODEBUG_STATE_ACTIVE:
359 debug_print_object(obj, "activate");
360 state = obj->state;
361 spin_unlock_irqrestore(&db->lock, flags);
362 debug_object_fixup(descr->fixup_activate, addr, state);
363 return;
364
365 case ODEBUG_STATE_DESTROYED:
366 debug_print_object(obj, "activate");
367 break;
368 default:
369 break;
370 }
371 spin_unlock_irqrestore(&db->lock, flags);
372 return;
373 }
374
375 spin_unlock_irqrestore(&db->lock, flags);
376 /*
377 * This happens when a static object is activated. We
378 * let the type specific code decide whether this is
379 * true or not.
380 */
381 debug_object_fixup(descr->fixup_activate, addr,
382 ODEBUG_STATE_NOTAVAILABLE);
383}
384
385/**
386 * debug_object_deactivate - debug checks when an object is deactivated
387 * @addr: address of the object
388 * @descr: pointer to an object specific debug description structure
389 */
390void debug_object_deactivate(void *addr, struct debug_obj_descr *descr)
391{
392 struct debug_bucket *db;
393 struct debug_obj *obj;
394 unsigned long flags;
395
396 if (!debug_objects_enabled)
397 return;
398
399 db = get_bucket((unsigned long) addr);
400
401 spin_lock_irqsave(&db->lock, flags);
402
403 obj = lookup_object(addr, db);
404 if (obj) {
405 switch (obj->state) {
406 case ODEBUG_STATE_INIT:
407 case ODEBUG_STATE_INACTIVE:
408 case ODEBUG_STATE_ACTIVE:
409 obj->state = ODEBUG_STATE_INACTIVE;
410 break;
411
412 case ODEBUG_STATE_DESTROYED:
413 debug_print_object(obj, "deactivate");
414 break;
415 default:
416 break;
417 }
418 } else {
419 struct debug_obj o = { .object = addr,
420 .state = ODEBUG_STATE_NOTAVAILABLE,
421 .descr = descr };
422
423 debug_print_object(&o, "deactivate");
424 }
425
426 spin_unlock_irqrestore(&db->lock, flags);
427}
428
429/**
430 * debug_object_destroy - debug checks when an object is destroyed
431 * @addr: address of the object
432 * @descr: pointer to an object specific debug description structure
433 */
434void debug_object_destroy(void *addr, struct debug_obj_descr *descr)
435{
436 enum debug_obj_state state;
437 struct debug_bucket *db;
438 struct debug_obj *obj;
439 unsigned long flags;
440
441 if (!debug_objects_enabled)
442 return;
443
444 db = get_bucket((unsigned long) addr);
445
446 spin_lock_irqsave(&db->lock, flags);
447
448 obj = lookup_object(addr, db);
449 if (!obj)
450 goto out_unlock;
451
452 switch (obj->state) {
453 case ODEBUG_STATE_NONE:
454 case ODEBUG_STATE_INIT:
455 case ODEBUG_STATE_INACTIVE:
456 obj->state = ODEBUG_STATE_DESTROYED;
457 break;
458 case ODEBUG_STATE_ACTIVE:
459 debug_print_object(obj, "destroy");
460 state = obj->state;
461 spin_unlock_irqrestore(&db->lock, flags);
462 debug_object_fixup(descr->fixup_destroy, addr, state);
463 return;
464
465 case ODEBUG_STATE_DESTROYED:
466 debug_print_object(obj, "destroy");
467 break;
468 default:
469 break;
470 }
471out_unlock:
472 spin_unlock_irqrestore(&db->lock, flags);
473}
474
475/**
476 * debug_object_free - debug checks when an object is freed
477 * @addr: address of the object
478 * @descr: pointer to an object specific debug description structure
479 */
480void debug_object_free(void *addr, struct debug_obj_descr *descr)
481{
482 enum debug_obj_state state;
483 struct debug_bucket *db;
484 struct debug_obj *obj;
485 unsigned long flags;
486
487 if (!debug_objects_enabled)
488 return;
489
490 db = get_bucket((unsigned long) addr);
491
492 spin_lock_irqsave(&db->lock, flags);
493
494 obj = lookup_object(addr, db);
495 if (!obj)
496 goto out_unlock;
497
498 switch (obj->state) {
499 case ODEBUG_STATE_ACTIVE:
500 debug_print_object(obj, "free");
501 state = obj->state;
502 spin_unlock_irqrestore(&db->lock, flags);
503 debug_object_fixup(descr->fixup_free, addr, state);
504 return;
505 default:
506 hlist_del(&obj->node);
507 free_object(obj);
508 break;
509 }
510out_unlock:
511 spin_unlock_irqrestore(&db->lock, flags);
512}
513
514#ifdef CONFIG_DEBUG_OBJECTS_FREE
515static void __debug_check_no_obj_freed(const void *address, unsigned long size)
516{
517 unsigned long flags, oaddr, saddr, eaddr, paddr, chunks;
518 struct hlist_node *node, *tmp;
519 struct debug_obj_descr *descr;
520 enum debug_obj_state state;
521 struct debug_bucket *db;
522 struct debug_obj *obj;
523 int cnt;
524
525 saddr = (unsigned long) address;
526 eaddr = saddr + size;
527 paddr = saddr & ODEBUG_CHUNK_MASK;
528 chunks = ((eaddr - paddr) + (ODEBUG_CHUNK_SIZE - 1));
529 chunks >>= ODEBUG_CHUNK_SHIFT;
530
531 for (;chunks > 0; chunks--, paddr += ODEBUG_CHUNK_SIZE) {
532 db = get_bucket(paddr);
533
534repeat:
535 cnt = 0;
536 spin_lock_irqsave(&db->lock, flags);
537 hlist_for_each_entry_safe(obj, node, tmp, &db->list, node) {
538 cnt++;
539 oaddr = (unsigned long) obj->object;
540 if (oaddr < saddr || oaddr >= eaddr)
541 continue;
542
543 switch (obj->state) {
544 case ODEBUG_STATE_ACTIVE:
545 debug_print_object(obj, "free");
546 descr = obj->descr;
547 state = obj->state;
548 spin_unlock_irqrestore(&db->lock, flags);
549 debug_object_fixup(descr->fixup_free,
550 (void *) oaddr, state);
551 goto repeat;
552 default:
553 hlist_del(&obj->node);
554 free_object(obj);
555 break;
556 }
557 }
558 spin_unlock_irqrestore(&db->lock, flags);
559 if (cnt > debug_objects_maxchain)
560 debug_objects_maxchain = cnt;
561 }
562}
563
564void debug_check_no_obj_freed(const void *address, unsigned long size)
565{
566 if (debug_objects_enabled)
567 __debug_check_no_obj_freed(address, size);
568}
569#endif
570
571#ifdef CONFIG_DEBUG_FS
572
573static int debug_stats_show(struct seq_file *m, void *v)
574{
575 seq_printf(m, "max_chain :%d\n", debug_objects_maxchain);
576 seq_printf(m, "warnings :%d\n", debug_objects_warnings);
577 seq_printf(m, "fixups :%d\n", debug_objects_fixups);
578 seq_printf(m, "pool_free :%d\n", obj_pool_free);
579 seq_printf(m, "pool_min_free :%d\n", obj_pool_min_free);
580 seq_printf(m, "pool_used :%d\n", obj_pool_used);
581 seq_printf(m, "pool_max_used :%d\n", obj_pool_max_used);
582 return 0;
583}
584
585static int debug_stats_open(struct inode *inode, struct file *filp)
586{
587 return single_open(filp, debug_stats_show, NULL);
588}
589
590static const struct file_operations debug_stats_fops = {
591 .open = debug_stats_open,
592 .read = seq_read,
593 .llseek = seq_lseek,
594 .release = single_release,
595};
596
597static int __init debug_objects_init_debugfs(void)
598{
599 struct dentry *dbgdir, *dbgstats;
600
601 if (!debug_objects_enabled)
602 return 0;
603
604 dbgdir = debugfs_create_dir("debug_objects", NULL);
605 if (!dbgdir)
606 return -ENOMEM;
607
608 dbgstats = debugfs_create_file("stats", 0444, dbgdir, NULL,
609 &debug_stats_fops);
610 if (!dbgstats)
611 goto err;
612
613 return 0;
614
615err:
616 debugfs_remove(dbgdir);
617
618 return -ENOMEM;
619}
620__initcall(debug_objects_init_debugfs);
621
622#else
623static inline void debug_objects_init_debugfs(void) { }
624#endif
625
626#ifdef CONFIG_DEBUG_OBJECTS_SELFTEST
627
628/* Random data structure for the self test */
629struct self_test {
630 unsigned long dummy1[6];
631 int static_init;
632 unsigned long dummy2[3];
633};
634
635static __initdata struct debug_obj_descr descr_type_test;
636
637/*
638 * fixup_init is called when:
639 * - an active object is initialized
640 */
641static int __init fixup_init(void *addr, enum debug_obj_state state)
642{
643 struct self_test *obj = addr;
644
645 switch (state) {
646 case ODEBUG_STATE_ACTIVE:
647 debug_object_deactivate(obj, &descr_type_test);
648 debug_object_init(obj, &descr_type_test);
649 return 1;
650 default:
651 return 0;
652 }
653}
654
655/*
656 * fixup_activate is called when:
657 * - an active object is activated
658 * - an unknown object is activated (might be a statically initialized object)
659 */
660static int __init fixup_activate(void *addr, enum debug_obj_state state)
661{
662 struct self_test *obj = addr;
663
664 switch (state) {
665 case ODEBUG_STATE_NOTAVAILABLE:
666 if (obj->static_init == 1) {
667 debug_object_init(obj, &descr_type_test);
668 debug_object_activate(obj, &descr_type_test);
669 /*
670 * Real code should return 0 here ! This is
671 * not a fixup of some bad behaviour. We
672 * merily call the debug_init function to keep
673 * track of the object.
674 */
675 return 1;
676 } else {
677 /* Real code needs to emit a warning here */
678 }
679 return 0;
680
681 case ODEBUG_STATE_ACTIVE:
682 debug_object_deactivate(obj, &descr_type_test);
683 debug_object_activate(obj, &descr_type_test);
684 return 1;
685
686 default:
687 return 0;
688 }
689}
690
691/*
692 * fixup_destroy is called when:
693 * - an active object is destroyed
694 */
695static int __init fixup_destroy(void *addr, enum debug_obj_state state)
696{
697 struct self_test *obj = addr;
698
699 switch (state) {
700 case ODEBUG_STATE_ACTIVE:
701 debug_object_deactivate(obj, &descr_type_test);
702 debug_object_destroy(obj, &descr_type_test);
703 return 1;
704 default:
705 return 0;
706 }
707}
708
709/*
710 * fixup_free is called when:
711 * - an active object is freed
712 */
713static int __init fixup_free(void *addr, enum debug_obj_state state)
714{
715 struct self_test *obj = addr;
716
717 switch (state) {
718 case ODEBUG_STATE_ACTIVE:
719 debug_object_deactivate(obj, &descr_type_test);
720 debug_object_free(obj, &descr_type_test);
721 return 1;
722 default:
723 return 0;
724 }
725}
726
727static int
728check_results(void *addr, enum debug_obj_state state, int fixups, int warnings)
729{
730 struct debug_bucket *db;
731 struct debug_obj *obj;
732 unsigned long flags;
733 int res = -EINVAL;
734
735 db = get_bucket((unsigned long) addr);
736
737 spin_lock_irqsave(&db->lock, flags);
738
739 obj = lookup_object(addr, db);
740 if (!obj && state != ODEBUG_STATE_NONE) {
741 printk(KERN_ERR "ODEBUG: selftest object not found\n");
742 WARN_ON(1);
743 goto out;
744 }
745 if (obj && obj->state != state) {
746 printk(KERN_ERR "ODEBUG: selftest wrong state: %d != %d\n",
747 obj->state, state);
748 WARN_ON(1);
749 goto out;
750 }
751 if (fixups != debug_objects_fixups) {
752 printk(KERN_ERR "ODEBUG: selftest fixups failed %d != %d\n",
753 fixups, debug_objects_fixups);
754 WARN_ON(1);
755 goto out;
756 }
757 if (warnings != debug_objects_warnings) {
758 printk(KERN_ERR "ODEBUG: selftest warnings failed %d != %d\n",
759 warnings, debug_objects_warnings);
760 WARN_ON(1);
761 goto out;
762 }
763 res = 0;
764out:
765 spin_unlock_irqrestore(&db->lock, flags);
766 if (res)
767 debug_objects_enabled = 0;
768 return res;
769}
770
771static __initdata struct debug_obj_descr descr_type_test = {
772 .name = "selftest",
773 .fixup_init = fixup_init,
774 .fixup_activate = fixup_activate,
775 .fixup_destroy = fixup_destroy,
776 .fixup_free = fixup_free,
777};
778
779static __initdata struct self_test obj = { .static_init = 0 };
780
781static void __init debug_objects_selftest(void)
782{
783 int fixups, oldfixups, warnings, oldwarnings;
784 unsigned long flags;
785
786 local_irq_save(flags);
787
788 fixups = oldfixups = debug_objects_fixups;
789 warnings = oldwarnings = debug_objects_warnings;
790 descr_test = &descr_type_test;
791
792 debug_object_init(&obj, &descr_type_test);
793 if (check_results(&obj, ODEBUG_STATE_INIT, fixups, warnings))
794 goto out;
795 debug_object_activate(&obj, &descr_type_test);
796 if (check_results(&obj, ODEBUG_STATE_ACTIVE, fixups, warnings))
797 goto out;
798 debug_object_activate(&obj, &descr_type_test);
799 if (check_results(&obj, ODEBUG_STATE_ACTIVE, ++fixups, ++warnings))
800 goto out;
801 debug_object_deactivate(&obj, &descr_type_test);
802 if (check_results(&obj, ODEBUG_STATE_INACTIVE, fixups, warnings))
803 goto out;
804 debug_object_destroy(&obj, &descr_type_test);
805 if (check_results(&obj, ODEBUG_STATE_DESTROYED, fixups, warnings))
806 goto out;
807 debug_object_init(&obj, &descr_type_test);
808 if (check_results(&obj, ODEBUG_STATE_DESTROYED, fixups, ++warnings))
809 goto out;
810 debug_object_activate(&obj, &descr_type_test);
811 if (check_results(&obj, ODEBUG_STATE_DESTROYED, fixups, ++warnings))
812 goto out;
813 debug_object_deactivate(&obj, &descr_type_test);
814 if (check_results(&obj, ODEBUG_STATE_DESTROYED, fixups, ++warnings))
815 goto out;
816 debug_object_free(&obj, &descr_type_test);
817 if (check_results(&obj, ODEBUG_STATE_NONE, fixups, warnings))
818 goto out;
819
820 obj.static_init = 1;
821 debug_object_activate(&obj, &descr_type_test);
822 if (check_results(&obj, ODEBUG_STATE_ACTIVE, ++fixups, warnings))
823 goto out;
824 debug_object_init(&obj, &descr_type_test);
825 if (check_results(&obj, ODEBUG_STATE_INIT, ++fixups, ++warnings))
826 goto out;
827 debug_object_free(&obj, &descr_type_test);
828 if (check_results(&obj, ODEBUG_STATE_NONE, fixups, warnings))
829 goto out;
830
831#ifdef CONFIG_DEBUG_OBJECTS_FREE
832 debug_object_init(&obj, &descr_type_test);
833 if (check_results(&obj, ODEBUG_STATE_INIT, fixups, warnings))
834 goto out;
835 debug_object_activate(&obj, &descr_type_test);
836 if (check_results(&obj, ODEBUG_STATE_ACTIVE, fixups, warnings))
837 goto out;
838 __debug_check_no_obj_freed(&obj, sizeof(obj));
839 if (check_results(&obj, ODEBUG_STATE_NONE, ++fixups, ++warnings))
840 goto out;
841#endif
842 printk(KERN_INFO "ODEBUG: selftest passed\n");
843
844out:
845 debug_objects_fixups = oldfixups;
846 debug_objects_warnings = oldwarnings;
847 descr_test = NULL;
848
849 local_irq_restore(flags);
850}
851#else
852static inline void debug_objects_selftest(void) { }
853#endif
854
855/*
856 * Called during early boot to initialize the hash buckets and link
857 * the static object pool objects into the poll list. After this call
858 * the object tracker is fully operational.
859 */
860void __init debug_objects_early_init(void)
861{
862 int i;
863
864 for (i = 0; i < ODEBUG_HASH_SIZE; i++)
865 spin_lock_init(&obj_hash[i].lock);
866
867 for (i = 0; i < ODEBUG_POOL_SIZE; i++)
868 hlist_add_head(&obj_static_pool[i].node, &obj_pool);
869}
870
871/*
872 * Called after the kmem_caches are functional to setup a dedicated
873 * cache pool, which has the SLAB_DEBUG_OBJECTS flag set. This flag
874 * prevents that the debug code is called on kmem_cache_free() for the
875 * debug tracker objects to avoid recursive calls.
876 */
877void __init debug_objects_mem_init(void)
878{
879 if (!debug_objects_enabled)
880 return;
881
882 obj_cache = kmem_cache_create("debug_objects_cache",
883 sizeof (struct debug_obj), 0,
884 SLAB_DEBUG_OBJECTS, NULL);
885
886 if (!obj_cache)
887 debug_objects_enabled = 0;
888 else
889 debug_objects_selftest();
890}
diff --git a/lib/devres.c b/lib/devres.c
index edc27a5d1b73..72c8909006da 100644
--- a/lib/devres.c
+++ b/lib/devres.c
@@ -2,7 +2,7 @@
2#include <linux/io.h> 2#include <linux/io.h>
3#include <linux/module.h> 3#include <linux/module.h>
4 4
5static void devm_ioremap_release(struct device *dev, void *res) 5void devm_ioremap_release(struct device *dev, void *res)
6{ 6{
7 iounmap(*(void __iomem **)res); 7 iounmap(*(void __iomem **)res);
8} 8}
@@ -20,7 +20,7 @@ static int devm_ioremap_match(struct device *dev, void *res, void *match_data)
20 * 20 *
21 * Managed ioremap(). Map is automatically unmapped on driver detach. 21 * Managed ioremap(). Map is automatically unmapped on driver detach.
22 */ 22 */
23void __iomem *devm_ioremap(struct device *dev, unsigned long offset, 23void __iomem *devm_ioremap(struct device *dev, resource_size_t offset,
24 unsigned long size) 24 unsigned long size)
25{ 25{
26 void __iomem **ptr, *addr; 26 void __iomem **ptr, *addr;
@@ -49,7 +49,7 @@ EXPORT_SYMBOL(devm_ioremap);
49 * Managed ioremap_nocache(). Map is automatically unmapped on driver 49 * Managed ioremap_nocache(). Map is automatically unmapped on driver
50 * detach. 50 * detach.
51 */ 51 */
52void __iomem *devm_ioremap_nocache(struct device *dev, unsigned long offset, 52void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset,
53 unsigned long size) 53 unsigned long size)
54{ 54{
55 void __iomem **ptr, *addr; 55 void __iomem **ptr, *addr;
diff --git a/lib/div64.c b/lib/div64.c
index b71cf93c529a..bb5bd0c0f030 100644
--- a/lib/div64.c
+++ b/lib/div64.c
@@ -16,9 +16,8 @@
16 * assembly versions such as arch/ppc/lib/div64.S and arch/sh/lib/div64.S. 16 * assembly versions such as arch/ppc/lib/div64.S and arch/sh/lib/div64.S.
17 */ 17 */
18 18
19#include <linux/types.h>
20#include <linux/module.h> 19#include <linux/module.h>
21#include <asm/div64.h> 20#include <linux/math64.h>
22 21
23/* Not needed on 64bit architectures */ 22/* Not needed on 64bit architectures */
24#if BITS_PER_LONG == 32 23#if BITS_PER_LONG == 32
@@ -58,10 +57,31 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
58 57
59EXPORT_SYMBOL(__div64_32); 58EXPORT_SYMBOL(__div64_32);
60 59
60#ifndef div_s64_rem
61s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
62{
63 u64 quotient;
64
65 if (dividend < 0) {
66 quotient = div_u64_rem(-dividend, abs(divisor), (u32 *)remainder);
67 *remainder = -*remainder;
68 if (divisor > 0)
69 quotient = -quotient;
70 } else {
71 quotient = div_u64_rem(dividend, abs(divisor), (u32 *)remainder);
72 if (divisor < 0)
73 quotient = -quotient;
74 }
75 return quotient;
76}
77EXPORT_SYMBOL(div_s64_rem);
78#endif
79
61/* 64bit divisor, dividend and result. dynamic precision */ 80/* 64bit divisor, dividend and result. dynamic precision */
62uint64_t div64_64(uint64_t dividend, uint64_t divisor) 81#ifndef div64_u64
82u64 div64_u64(u64 dividend, u64 divisor)
63{ 83{
64 uint32_t high, d; 84 u32 high, d;
65 85
66 high = divisor >> 32; 86 high = divisor >> 32;
67 if (high) { 87 if (high) {
@@ -72,10 +92,9 @@ uint64_t div64_64(uint64_t dividend, uint64_t divisor)
72 } else 92 } else
73 d = divisor; 93 d = divisor;
74 94
75 do_div(dividend, d); 95 return div_u64(dividend, d);
76
77 return dividend;
78} 96}
79EXPORT_SYMBOL(div64_64); 97EXPORT_SYMBOL(div64_u64);
98#endif
80 99
81#endif /* BITS_PER_LONG == 32 */ 100#endif /* BITS_PER_LONG == 32 */
diff --git a/lib/idr.c b/lib/idr.c
index 8368c81fcb7d..7a02e173f027 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -385,8 +385,8 @@ void idr_remove(struct idr *idp, int id)
385 while (idp->id_free_cnt >= IDR_FREE_MAX) { 385 while (idp->id_free_cnt >= IDR_FREE_MAX) {
386 p = alloc_layer(idp); 386 p = alloc_layer(idp);
387 kmem_cache_free(idr_layer_cache, p); 387 kmem_cache_free(idr_layer_cache, p);
388 return;
389 } 388 }
389 return;
390} 390}
391EXPORT_SYMBOL(idr_remove); 391EXPORT_SYMBOL(idr_remove);
392 392
diff --git a/lib/klist.c b/lib/klist.c
index 120bd175aa78..cca37f96faa2 100644
--- a/lib/klist.c
+++ b/lib/klist.c
@@ -1,38 +1,37 @@
1/* 1/*
2 * klist.c - Routines for manipulating klists. 2 * klist.c - Routines for manipulating klists.
3 * 3 *
4 * Copyright (C) 2005 Patrick Mochel
4 * 5 *
5 * This klist interface provides a couple of structures that wrap around 6 * This file is released under the GPL v2.
6 * struct list_head to provide explicit list "head" (struct klist) and
7 * list "node" (struct klist_node) objects. For struct klist, a spinlock
8 * is included that protects access to the actual list itself. struct
9 * klist_node provides a pointer to the klist that owns it and a kref
10 * reference count that indicates the number of current users of that node
11 * in the list.
12 * 7 *
13 * The entire point is to provide an interface for iterating over a list 8 * This klist interface provides a couple of structures that wrap around
14 * that is safe and allows for modification of the list during the 9 * struct list_head to provide explicit list "head" (struct klist) and list
15 * iteration (e.g. insertion and removal), including modification of the 10 * "node" (struct klist_node) objects. For struct klist, a spinlock is
16 * current node on the list. 11 * included that protects access to the actual list itself. struct
12 * klist_node provides a pointer to the klist that owns it and a kref
13 * reference count that indicates the number of current users of that node
14 * in the list.
17 * 15 *
18 * It works using a 3rd object type - struct klist_iter - that is declared 16 * The entire point is to provide an interface for iterating over a list
19 * and initialized before an iteration. klist_next() is used to acquire the 17 * that is safe and allows for modification of the list during the
20 * next element in the list. It returns NULL if there are no more items. 18 * iteration (e.g. insertion and removal), including modification of the
21 * Internally, that routine takes the klist's lock, decrements the reference 19 * current node on the list.
22 * count of the previous klist_node and increments the count of the next
23 * klist_node. It then drops the lock and returns.
24 * 20 *
25 * There are primitives for adding and removing nodes to/from a klist. 21 * It works using a 3rd object type - struct klist_iter - that is declared
26 * When deleting, klist_del() will simply decrement the reference count. 22 * and initialized before an iteration. klist_next() is used to acquire the
27 * Only when the count goes to 0 is the node removed from the list. 23 * next element in the list. It returns NULL if there are no more items.
28 * klist_remove() will try to delete the node from the list and block 24 * Internally, that routine takes the klist's lock, decrements the
29 * until it is actually removed. This is useful for objects (like devices) 25 * reference count of the previous klist_node and increments the count of
30 * that have been removed from the system and must be freed (but must wait 26 * the next klist_node. It then drops the lock and returns.
31 * until all accessors have finished).
32 * 27 *
33 * Copyright (C) 2005 Patrick Mochel 28 * There are primitives for adding and removing nodes to/from a klist.
34 * 29 * When deleting, klist_del() will simply decrement the reference count.
35 * This file is released under the GPL v2. 30 * Only when the count goes to 0 is the node removed from the list.
31 * klist_remove() will try to delete the node from the list and block until
32 * it is actually removed. This is useful for objects (like devices) that
33 * have been removed from the system and must be freed (but must wait until
34 * all accessors have finished).
36 */ 35 */
37 36
38#include <linux/klist.h> 37#include <linux/klist.h>
@@ -40,10 +39,10 @@
40 39
41 40
42/** 41/**
43 * klist_init - Initialize a klist structure. 42 * klist_init - Initialize a klist structure.
44 * @k: The klist we're initializing. 43 * @k: The klist we're initializing.
45 * @get: The get function for the embedding object (NULL if none) 44 * @get: The get function for the embedding object (NULL if none)
46 * @put: The put function for the embedding object (NULL if none) 45 * @put: The put function for the embedding object (NULL if none)
47 * 46 *
48 * Initialises the klist structure. If the klist_node structures are 47 * Initialises the klist structure. If the klist_node structures are
49 * going to be embedded in refcounted objects (necessary for safe 48 * going to be embedded in refcounted objects (necessary for safe
@@ -51,8 +50,7 @@
51 * functions that take and release references on the embedding 50 * functions that take and release references on the embedding
52 * objects. 51 * objects.
53 */ 52 */
54 53void klist_init(struct klist *k, void (*get)(struct klist_node *),
55void klist_init(struct klist * k, void (*get)(struct klist_node *),
56 void (*put)(struct klist_node *)) 54 void (*put)(struct klist_node *))
57{ 55{
58 INIT_LIST_HEAD(&k->k_list); 56 INIT_LIST_HEAD(&k->k_list);
@@ -60,26 +58,23 @@ void klist_init(struct klist * k, void (*get)(struct klist_node *),
60 k->get = get; 58 k->get = get;
61 k->put = put; 59 k->put = put;
62} 60}
63
64EXPORT_SYMBOL_GPL(klist_init); 61EXPORT_SYMBOL_GPL(klist_init);
65 62
66 63static void add_head(struct klist *k, struct klist_node *n)
67static void add_head(struct klist * k, struct klist_node * n)
68{ 64{
69 spin_lock(&k->k_lock); 65 spin_lock(&k->k_lock);
70 list_add(&n->n_node, &k->k_list); 66 list_add(&n->n_node, &k->k_list);
71 spin_unlock(&k->k_lock); 67 spin_unlock(&k->k_lock);
72} 68}
73 69
74static void add_tail(struct klist * k, struct klist_node * n) 70static void add_tail(struct klist *k, struct klist_node *n)
75{ 71{
76 spin_lock(&k->k_lock); 72 spin_lock(&k->k_lock);
77 list_add_tail(&n->n_node, &k->k_list); 73 list_add_tail(&n->n_node, &k->k_list);
78 spin_unlock(&k->k_lock); 74 spin_unlock(&k->k_lock);
79} 75}
80 76
81 77static void klist_node_init(struct klist *k, struct klist_node *n)
82static void klist_node_init(struct klist * k, struct klist_node * n)
83{ 78{
84 INIT_LIST_HEAD(&n->n_node); 79 INIT_LIST_HEAD(&n->n_node);
85 init_completion(&n->n_removed); 80 init_completion(&n->n_removed);
@@ -89,60 +84,83 @@ static void klist_node_init(struct klist * k, struct klist_node * n)
89 k->get(n); 84 k->get(n);
90} 85}
91 86
92
93/** 87/**
94 * klist_add_head - Initialize a klist_node and add it to front. 88 * klist_add_head - Initialize a klist_node and add it to front.
95 * @n: node we're adding. 89 * @n: node we're adding.
96 * @k: klist it's going on. 90 * @k: klist it's going on.
97 */ 91 */
98 92void klist_add_head(struct klist_node *n, struct klist *k)
99void klist_add_head(struct klist_node * n, struct klist * k)
100{ 93{
101 klist_node_init(k, n); 94 klist_node_init(k, n);
102 add_head(k, n); 95 add_head(k, n);
103} 96}
104
105EXPORT_SYMBOL_GPL(klist_add_head); 97EXPORT_SYMBOL_GPL(klist_add_head);
106 98
107
108/** 99/**
109 * klist_add_tail - Initialize a klist_node and add it to back. 100 * klist_add_tail - Initialize a klist_node and add it to back.
110 * @n: node we're adding. 101 * @n: node we're adding.
111 * @k: klist it's going on. 102 * @k: klist it's going on.
112 */ 103 */
113 104void klist_add_tail(struct klist_node *n, struct klist *k)
114void klist_add_tail(struct klist_node * n, struct klist * k)
115{ 105{
116 klist_node_init(k, n); 106 klist_node_init(k, n);
117 add_tail(k, n); 107 add_tail(k, n);
118} 108}
119
120EXPORT_SYMBOL_GPL(klist_add_tail); 109EXPORT_SYMBOL_GPL(klist_add_tail);
121 110
111/**
112 * klist_add_after - Init a klist_node and add it after an existing node
113 * @n: node we're adding.
114 * @pos: node to put @n after
115 */
116void klist_add_after(struct klist_node *n, struct klist_node *pos)
117{
118 struct klist *k = pos->n_klist;
119
120 klist_node_init(k, n);
121 spin_lock(&k->k_lock);
122 list_add(&n->n_node, &pos->n_node);
123 spin_unlock(&k->k_lock);
124}
125EXPORT_SYMBOL_GPL(klist_add_after);
126
127/**
128 * klist_add_before - Init a klist_node and add it before an existing node
129 * @n: node we're adding.
130 * @pos: node to put @n after
131 */
132void klist_add_before(struct klist_node *n, struct klist_node *pos)
133{
134 struct klist *k = pos->n_klist;
135
136 klist_node_init(k, n);
137 spin_lock(&k->k_lock);
138 list_add_tail(&n->n_node, &pos->n_node);
139 spin_unlock(&k->k_lock);
140}
141EXPORT_SYMBOL_GPL(klist_add_before);
122 142
123static void klist_release(struct kref * kref) 143static void klist_release(struct kref *kref)
124{ 144{
125 struct klist_node * n = container_of(kref, struct klist_node, n_ref); 145 struct klist_node *n = container_of(kref, struct klist_node, n_ref);
126 146
127 list_del(&n->n_node); 147 list_del(&n->n_node);
128 complete(&n->n_removed); 148 complete(&n->n_removed);
129 n->n_klist = NULL; 149 n->n_klist = NULL;
130} 150}
131 151
132static int klist_dec_and_del(struct klist_node * n) 152static int klist_dec_and_del(struct klist_node *n)
133{ 153{
134 return kref_put(&n->n_ref, klist_release); 154 return kref_put(&n->n_ref, klist_release);
135} 155}
136 156
137
138/** 157/**
139 * klist_del - Decrement the reference count of node and try to remove. 158 * klist_del - Decrement the reference count of node and try to remove.
140 * @n: node we're deleting. 159 * @n: node we're deleting.
141 */ 160 */
142 161void klist_del(struct klist_node *n)
143void klist_del(struct klist_node * n)
144{ 162{
145 struct klist * k = n->n_klist; 163 struct klist *k = n->n_klist;
146 void (*put)(struct klist_node *) = k->put; 164 void (*put)(struct klist_node *) = k->put;
147 165
148 spin_lock(&k->k_lock); 166 spin_lock(&k->k_lock);
@@ -152,48 +170,40 @@ void klist_del(struct klist_node * n)
152 if (put) 170 if (put)
153 put(n); 171 put(n);
154} 172}
155
156EXPORT_SYMBOL_GPL(klist_del); 173EXPORT_SYMBOL_GPL(klist_del);
157 174
158
159/** 175/**
160 * klist_remove - Decrement the refcount of node and wait for it to go away. 176 * klist_remove - Decrement the refcount of node and wait for it to go away.
161 * @n: node we're removing. 177 * @n: node we're removing.
162 */ 178 */
163 179void klist_remove(struct klist_node *n)
164void klist_remove(struct klist_node * n)
165{ 180{
166 klist_del(n); 181 klist_del(n);
167 wait_for_completion(&n->n_removed); 182 wait_for_completion(&n->n_removed);
168} 183}
169
170EXPORT_SYMBOL_GPL(klist_remove); 184EXPORT_SYMBOL_GPL(klist_remove);
171 185
172
173/** 186/**
174 * klist_node_attached - Say whether a node is bound to a list or not. 187 * klist_node_attached - Say whether a node is bound to a list or not.
175 * @n: Node that we're testing. 188 * @n: Node that we're testing.
176 */ 189 */
177 190int klist_node_attached(struct klist_node *n)
178int klist_node_attached(struct klist_node * n)
179{ 191{
180 return (n->n_klist != NULL); 192 return (n->n_klist != NULL);
181} 193}
182
183EXPORT_SYMBOL_GPL(klist_node_attached); 194EXPORT_SYMBOL_GPL(klist_node_attached);
184 195
185
186/** 196/**
187 * klist_iter_init_node - Initialize a klist_iter structure. 197 * klist_iter_init_node - Initialize a klist_iter structure.
188 * @k: klist we're iterating. 198 * @k: klist we're iterating.
189 * @i: klist_iter we're filling. 199 * @i: klist_iter we're filling.
190 * @n: node to start with. 200 * @n: node to start with.
191 * 201 *
192 * Similar to klist_iter_init(), but starts the action off with @n, 202 * Similar to klist_iter_init(), but starts the action off with @n,
193 * instead of with the list head. 203 * instead of with the list head.
194 */ 204 */
195 205void klist_iter_init_node(struct klist *k, struct klist_iter *i,
196void klist_iter_init_node(struct klist * k, struct klist_iter * i, struct klist_node * n) 206 struct klist_node *n)
197{ 207{
198 i->i_klist = k; 208 i->i_klist = k;
199 i->i_head = &k->k_list; 209 i->i_head = &k->k_list;
@@ -201,66 +211,56 @@ void klist_iter_init_node(struct klist * k, struct klist_iter * i, struct klist_
201 if (n) 211 if (n)
202 kref_get(&n->n_ref); 212 kref_get(&n->n_ref);
203} 213}
204
205EXPORT_SYMBOL_GPL(klist_iter_init_node); 214EXPORT_SYMBOL_GPL(klist_iter_init_node);
206 215
207
208/** 216/**
209 * klist_iter_init - Iniitalize a klist_iter structure. 217 * klist_iter_init - Iniitalize a klist_iter structure.
210 * @k: klist we're iterating. 218 * @k: klist we're iterating.
211 * @i: klist_iter structure we're filling. 219 * @i: klist_iter structure we're filling.
212 * 220 *
213 * Similar to klist_iter_init_node(), but start with the list head. 221 * Similar to klist_iter_init_node(), but start with the list head.
214 */ 222 */
215 223void klist_iter_init(struct klist *k, struct klist_iter *i)
216void klist_iter_init(struct klist * k, struct klist_iter * i)
217{ 224{
218 klist_iter_init_node(k, i, NULL); 225 klist_iter_init_node(k, i, NULL);
219} 226}
220
221EXPORT_SYMBOL_GPL(klist_iter_init); 227EXPORT_SYMBOL_GPL(klist_iter_init);
222 228
223
224/** 229/**
225 * klist_iter_exit - Finish a list iteration. 230 * klist_iter_exit - Finish a list iteration.
226 * @i: Iterator structure. 231 * @i: Iterator structure.
227 * 232 *
228 * Must be called when done iterating over list, as it decrements the 233 * Must be called when done iterating over list, as it decrements the
229 * refcount of the current node. Necessary in case iteration exited before 234 * refcount of the current node. Necessary in case iteration exited before
230 * the end of the list was reached, and always good form. 235 * the end of the list was reached, and always good form.
231 */ 236 */
232 237void klist_iter_exit(struct klist_iter *i)
233void klist_iter_exit(struct klist_iter * i)
234{ 238{
235 if (i->i_cur) { 239 if (i->i_cur) {
236 klist_del(i->i_cur); 240 klist_del(i->i_cur);
237 i->i_cur = NULL; 241 i->i_cur = NULL;
238 } 242 }
239} 243}
240
241EXPORT_SYMBOL_GPL(klist_iter_exit); 244EXPORT_SYMBOL_GPL(klist_iter_exit);
242 245
243 246static struct klist_node *to_klist_node(struct list_head *n)
244static struct klist_node * to_klist_node(struct list_head * n)
245{ 247{
246 return container_of(n, struct klist_node, n_node); 248 return container_of(n, struct klist_node, n_node);
247} 249}
248 250
249
250/** 251/**
251 * klist_next - Ante up next node in list. 252 * klist_next - Ante up next node in list.
252 * @i: Iterator structure. 253 * @i: Iterator structure.
253 * 254 *
254 * First grab list lock. Decrement the reference count of the previous 255 * First grab list lock. Decrement the reference count of the previous
255 * node, if there was one. Grab the next node, increment its reference 256 * node, if there was one. Grab the next node, increment its reference
256 * count, drop the lock, and return that next node. 257 * count, drop the lock, and return that next node.
257 */ 258 */
258 259struct klist_node *klist_next(struct klist_iter *i)
259struct klist_node * klist_next(struct klist_iter * i)
260{ 260{
261 struct list_head * next; 261 struct list_head *next;
262 struct klist_node * lnode = i->i_cur; 262 struct klist_node *lnode = i->i_cur;
263 struct klist_node * knode = NULL; 263 struct klist_node *knode = NULL;
264 void (*put)(struct klist_node *) = i->i_klist->put; 264 void (*put)(struct klist_node *) = i->i_klist->put;
265 265
266 spin_lock(&i->i_klist->k_lock); 266 spin_lock(&i->i_klist->k_lock);
@@ -281,7 +281,4 @@ struct klist_node * klist_next(struct klist_iter * i)
281 put(lnode); 281 put(lnode);
282 return knode; 282 return knode;
283} 283}
284
285EXPORT_SYMBOL_GPL(klist_next); 284EXPORT_SYMBOL_GPL(klist_next);
286
287
diff --git a/lib/kobject.c b/lib/kobject.c
index 2c6490370922..718e5101c263 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -90,7 +90,7 @@ static void fill_kobj_path(struct kobject *kobj, char *path, int length)
90 } 90 }
91 91
92 pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobject_name(kobj), 92 pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobject_name(kobj),
93 kobj, __FUNCTION__, path); 93 kobj, __func__, path);
94} 94}
95 95
96/** 96/**
@@ -181,7 +181,7 @@ static int kobject_add_internal(struct kobject *kobj)
181 } 181 }
182 182
183 pr_debug("kobject: '%s' (%p): %s: parent: '%s', set: '%s'\n", 183 pr_debug("kobject: '%s' (%p): %s: parent: '%s', set: '%s'\n",
184 kobject_name(kobj), kobj, __FUNCTION__, 184 kobject_name(kobj), kobj, __func__,
185 parent ? kobject_name(parent) : "<NULL>", 185 parent ? kobject_name(parent) : "<NULL>",
186 kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>"); 186 kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>");
187 187
@@ -196,10 +196,10 @@ static int kobject_add_internal(struct kobject *kobj)
196 printk(KERN_ERR "%s failed for %s with " 196 printk(KERN_ERR "%s failed for %s with "
197 "-EEXIST, don't try to register things with " 197 "-EEXIST, don't try to register things with "
198 "the same name in the same directory.\n", 198 "the same name in the same directory.\n",
199 __FUNCTION__, kobject_name(kobj)); 199 __func__, kobject_name(kobj));
200 else 200 else
201 printk(KERN_ERR "%s failed for %s (%d)\n", 201 printk(KERN_ERR "%s failed for %s (%d)\n",
202 __FUNCTION__, kobject_name(kobj), error); 202 __func__, kobject_name(kobj), error);
203 dump_stack(); 203 dump_stack();
204 } else 204 } else
205 kobj->state_in_sysfs = 1; 205 kobj->state_in_sysfs = 1;
@@ -216,21 +216,12 @@ static int kobject_add_internal(struct kobject *kobj)
216static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, 216static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
217 va_list vargs) 217 va_list vargs)
218{ 218{
219 va_list aq;
220 char *name;
221
222 va_copy(aq, vargs);
223 name = kvasprintf(GFP_KERNEL, fmt, vargs);
224 va_end(aq);
225
226 if (!name)
227 return -ENOMEM;
228
229 /* Free the old name, if necessary. */ 219 /* Free the old name, if necessary. */
230 kfree(kobj->name); 220 kfree(kobj->name);
231 221
232 /* Now, set the new name */ 222 kobj->name = kvasprintf(GFP_KERNEL, fmt, vargs);
233 kobj->name = name; 223 if (!kobj->name)
224 return -ENOMEM;
234 225
235 return 0; 226 return 0;
236} 227}
@@ -246,12 +237,12 @@ static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
246 */ 237 */
247int kobject_set_name(struct kobject *kobj, const char *fmt, ...) 238int kobject_set_name(struct kobject *kobj, const char *fmt, ...)
248{ 239{
249 va_list args; 240 va_list vargs;
250 int retval; 241 int retval;
251 242
252 va_start(args, fmt); 243 va_start(vargs, fmt);
253 retval = kobject_set_name_vargs(kobj, fmt, args); 244 retval = kobject_set_name_vargs(kobj, fmt, vargs);
254 va_end(args); 245 va_end(vargs);
255 246
256 return retval; 247 return retval;
257} 248}
@@ -301,12 +292,9 @@ EXPORT_SYMBOL(kobject_init);
301static int kobject_add_varg(struct kobject *kobj, struct kobject *parent, 292static int kobject_add_varg(struct kobject *kobj, struct kobject *parent,
302 const char *fmt, va_list vargs) 293 const char *fmt, va_list vargs)
303{ 294{
304 va_list aq;
305 int retval; 295 int retval;
306 296
307 va_copy(aq, vargs); 297 retval = kobject_set_name_vargs(kobj, fmt, vargs);
308 retval = kobject_set_name_vargs(kobj, fmt, aq);
309 va_end(aq);
310 if (retval) { 298 if (retval) {
311 printk(KERN_ERR "kobject: can not set name properly!\n"); 299 printk(KERN_ERR "kobject: can not set name properly!\n");
312 return retval; 300 return retval;
@@ -540,7 +528,7 @@ static void kobject_cleanup(struct kobject *kobj)
540 const char *name = kobj->name; 528 const char *name = kobj->name;
541 529
542 pr_debug("kobject: '%s' (%p): %s\n", 530 pr_debug("kobject: '%s' (%p): %s\n",
543 kobject_name(kobj), kobj, __FUNCTION__); 531 kobject_name(kobj), kobj, __func__);
544 532
545 if (t && !t->release) 533 if (t && !t->release)
546 pr_debug("kobject: '%s' (%p): does not have a release() " 534 pr_debug("kobject: '%s' (%p): does not have a release() "
@@ -600,7 +588,7 @@ void kobject_put(struct kobject *kobj)
600 588
601static void dynamic_kobj_release(struct kobject *kobj) 589static void dynamic_kobj_release(struct kobject *kobj)
602{ 590{
603 pr_debug("kobject: (%p): %s\n", kobj, __FUNCTION__); 591 pr_debug("kobject: (%p): %s\n", kobj, __func__);
604 kfree(kobj); 592 kfree(kobj);
605} 593}
606 594
@@ -657,7 +645,7 @@ struct kobject *kobject_create_and_add(const char *name, struct kobject *parent)
657 retval = kobject_add(kobj, parent, "%s", name); 645 retval = kobject_add(kobj, parent, "%s", name);
658 if (retval) { 646 if (retval) {
659 printk(KERN_WARNING "%s: kobject_add error: %d\n", 647 printk(KERN_WARNING "%s: kobject_add error: %d\n",
660 __FUNCTION__, retval); 648 __func__, retval);
661 kobject_put(kobj); 649 kobject_put(kobj);
662 kobj = NULL; 650 kobj = NULL;
663 } 651 }
@@ -765,7 +753,7 @@ static void kset_release(struct kobject *kobj)
765{ 753{
766 struct kset *kset = container_of(kobj, struct kset, kobj); 754 struct kset *kset = container_of(kobj, struct kset, kobj);
767 pr_debug("kobject: '%s' (%p): %s\n", 755 pr_debug("kobject: '%s' (%p): %s\n",
768 kobject_name(kobj), kobj, __FUNCTION__); 756 kobject_name(kobj), kobj, __func__);
769 kfree(kset); 757 kfree(kset);
770} 758}
771 759
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index 9fb6b86cf6b1..2fa545a63160 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -101,7 +101,7 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
101 int retval = 0; 101 int retval = 0;
102 102
103 pr_debug("kobject: '%s' (%p): %s\n", 103 pr_debug("kobject: '%s' (%p): %s\n",
104 kobject_name(kobj), kobj, __FUNCTION__); 104 kobject_name(kobj), kobj, __func__);
105 105
106 /* search the kset we belong to */ 106 /* search the kset we belong to */
107 top_kobj = kobj; 107 top_kobj = kobj;
@@ -111,7 +111,7 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
111 if (!top_kobj->kset) { 111 if (!top_kobj->kset) {
112 pr_debug("kobject: '%s' (%p): %s: attempted to send uevent " 112 pr_debug("kobject: '%s' (%p): %s: attempted to send uevent "
113 "without kset!\n", kobject_name(kobj), kobj, 113 "without kset!\n", kobject_name(kobj), kobj,
114 __FUNCTION__); 114 __func__);
115 return -EINVAL; 115 return -EINVAL;
116 } 116 }
117 117
@@ -123,7 +123,7 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
123 if (!uevent_ops->filter(kset, kobj)) { 123 if (!uevent_ops->filter(kset, kobj)) {
124 pr_debug("kobject: '%s' (%p): %s: filter function " 124 pr_debug("kobject: '%s' (%p): %s: filter function "
125 "caused the event to drop!\n", 125 "caused the event to drop!\n",
126 kobject_name(kobj), kobj, __FUNCTION__); 126 kobject_name(kobj), kobj, __func__);
127 return 0; 127 return 0;
128 } 128 }
129 129
@@ -135,7 +135,7 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
135 if (!subsystem) { 135 if (!subsystem) {
136 pr_debug("kobject: '%s' (%p): %s: unset subsystem caused the " 136 pr_debug("kobject: '%s' (%p): %s: unset subsystem caused the "
137 "event to drop!\n", kobject_name(kobj), kobj, 137 "event to drop!\n", kobject_name(kobj), kobj,
138 __FUNCTION__); 138 __func__);
139 return 0; 139 return 0;
140 } 140 }
141 141
@@ -177,7 +177,7 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
177 if (retval) { 177 if (retval) {
178 pr_debug("kobject: '%s' (%p): %s: uevent() returned " 178 pr_debug("kobject: '%s' (%p): %s: uevent() returned "
179 "%d\n", kobject_name(kobj), kobj, 179 "%d\n", kobject_name(kobj), kobj,
180 __FUNCTION__, retval); 180 __func__, retval);
181 goto exit; 181 goto exit;
182 } 182 }
183 } 183 }
diff --git a/lib/percpu_counter.c b/lib/percpu_counter.c
index 393a0e915c23..119174494cb5 100644
--- a/lib/percpu_counter.c
+++ b/lib/percpu_counter.c
@@ -102,6 +102,7 @@ void percpu_counter_destroy(struct percpu_counter *fbc)
102 return; 102 return;
103 103
104 free_percpu(fbc->counters); 104 free_percpu(fbc->counters);
105 fbc->counters = NULL;
105#ifdef CONFIG_HOTPLUG_CPU 106#ifdef CONFIG_HOTPLUG_CPU
106 mutex_lock(&percpu_counters_lock); 107 mutex_lock(&percpu_counters_lock);
107 list_del(&fbc->list); 108 list_del(&fbc->list);
diff --git a/lib/proportions.c b/lib/proportions.c
index 9508d9a7af3e..4f387a643d72 100644
--- a/lib/proportions.c
+++ b/lib/proportions.c
@@ -73,12 +73,6 @@
73#include <linux/proportions.h> 73#include <linux/proportions.h>
74#include <linux/rcupdate.h> 74#include <linux/rcupdate.h>
75 75
76/*
77 * Limit the time part in order to ensure there are some bits left for the
78 * cycle counter.
79 */
80#define PROP_MAX_SHIFT (3*BITS_PER_LONG/4)
81
82int prop_descriptor_init(struct prop_descriptor *pd, int shift) 76int prop_descriptor_init(struct prop_descriptor *pd, int shift)
83{ 77{
84 int err; 78 int err;
@@ -268,6 +262,38 @@ void __prop_inc_percpu(struct prop_descriptor *pd, struct prop_local_percpu *pl)
268} 262}
269 263
270/* 264/*
265 * identical to __prop_inc_percpu, except that it limits this pl's fraction to
266 * @frac/PROP_FRAC_BASE by ignoring events when this limit has been exceeded.
267 */
268void __prop_inc_percpu_max(struct prop_descriptor *pd,
269 struct prop_local_percpu *pl, long frac)
270{
271 struct prop_global *pg = prop_get_global(pd);
272
273 prop_norm_percpu(pg, pl);
274
275 if (unlikely(frac != PROP_FRAC_BASE)) {
276 unsigned long period_2 = 1UL << (pg->shift - 1);
277 unsigned long counter_mask = period_2 - 1;
278 unsigned long global_count;
279 long numerator, denominator;
280
281 numerator = percpu_counter_read_positive(&pl->events);
282 global_count = percpu_counter_read(&pg->events);
283 denominator = period_2 + (global_count & counter_mask);
284
285 if (numerator > ((denominator * frac) >> PROP_FRAC_SHIFT))
286 goto out_put;
287 }
288
289 percpu_counter_add(&pl->events, 1);
290 percpu_counter_add(&pg->events, 1);
291
292out_put:
293 prop_put_global(pd, pg);
294}
295
296/*
271 * Obtain a fraction of this proportion 297 * Obtain a fraction of this proportion
272 * 298 *
273 * p_{j} = x_{j} / (period/2 + t % period/2) 299 * p_{j} = x_{j} / (period/2 + t % period/2)
diff --git a/lib/string.c b/lib/string.c
index 5efafed3d6b6..b19b87af65a3 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -493,6 +493,33 @@ char *strsep(char **s, const char *ct)
493EXPORT_SYMBOL(strsep); 493EXPORT_SYMBOL(strsep);
494#endif 494#endif
495 495
496/**
497 * sysfs_streq - return true if strings are equal, modulo trailing newline
498 * @s1: one string
499 * @s2: another string
500 *
501 * This routine returns true iff two strings are equal, treating both
502 * NUL and newline-then-NUL as equivalent string terminations. It's
503 * geared for use with sysfs input strings, which generally terminate
504 * with newlines but are compared against values without newlines.
505 */
506bool sysfs_streq(const char *s1, const char *s2)
507{
508 while (*s1 && *s1 == *s2) {
509 s1++;
510 s2++;
511 }
512
513 if (*s1 == *s2)
514 return true;
515 if (!*s1 && *s2 == '\n' && !s2[1])
516 return true;
517 if (*s1 == '\n' && !s1[1] && !*s2)
518 return true;
519 return false;
520}
521EXPORT_SYMBOL(sysfs_streq);
522
496#ifndef __HAVE_ARCH_MEMSET 523#ifndef __HAVE_ARCH_MEMSET
497/** 524/**
498 * memset - Fill a region of memory with the given value 525 * memset - Fill a region of memory with the given value
diff --git a/mm/backing-dev.c b/mm/backing-dev.c
index e8644b1e5527..7c4f9e097095 100644
--- a/mm/backing-dev.c
+++ b/mm/backing-dev.c
@@ -4,12 +4,229 @@
4#include <linux/fs.h> 4#include <linux/fs.h>
5#include <linux/sched.h> 5#include <linux/sched.h>
6#include <linux/module.h> 6#include <linux/module.h>
7#include <linux/writeback.h>
8#include <linux/device.h>
9
10
11static struct class *bdi_class;
12
13#ifdef CONFIG_DEBUG_FS
14#include <linux/debugfs.h>
15#include <linux/seq_file.h>
16
17static struct dentry *bdi_debug_root;
18
19static void bdi_debug_init(void)
20{
21 bdi_debug_root = debugfs_create_dir("bdi", NULL);
22}
23
24static int bdi_debug_stats_show(struct seq_file *m, void *v)
25{
26 struct backing_dev_info *bdi = m->private;
27 long background_thresh;
28 long dirty_thresh;
29 long bdi_thresh;
30
31 get_dirty_limits(&background_thresh, &dirty_thresh, &bdi_thresh, bdi);
32
33#define K(x) ((x) << (PAGE_SHIFT - 10))
34 seq_printf(m,
35 "BdiWriteback: %8lu kB\n"
36 "BdiReclaimable: %8lu kB\n"
37 "BdiDirtyThresh: %8lu kB\n"
38 "DirtyThresh: %8lu kB\n"
39 "BackgroundThresh: %8lu kB\n",
40 (unsigned long) K(bdi_stat(bdi, BDI_WRITEBACK)),
41 (unsigned long) K(bdi_stat(bdi, BDI_RECLAIMABLE)),
42 K(bdi_thresh),
43 K(dirty_thresh),
44 K(background_thresh));
45#undef K
46
47 return 0;
48}
49
50static int bdi_debug_stats_open(struct inode *inode, struct file *file)
51{
52 return single_open(file, bdi_debug_stats_show, inode->i_private);
53}
54
55static const struct file_operations bdi_debug_stats_fops = {
56 .open = bdi_debug_stats_open,
57 .read = seq_read,
58 .llseek = seq_lseek,
59 .release = single_release,
60};
61
62static void bdi_debug_register(struct backing_dev_info *bdi, const char *name)
63{
64 bdi->debug_dir = debugfs_create_dir(name, bdi_debug_root);
65 bdi->debug_stats = debugfs_create_file("stats", 0444, bdi->debug_dir,
66 bdi, &bdi_debug_stats_fops);
67}
68
69static void bdi_debug_unregister(struct backing_dev_info *bdi)
70{
71 debugfs_remove(bdi->debug_stats);
72 debugfs_remove(bdi->debug_dir);
73}
74#else
75static inline void bdi_debug_init(void)
76{
77}
78static inline void bdi_debug_register(struct backing_dev_info *bdi,
79 const char *name)
80{
81}
82static inline void bdi_debug_unregister(struct backing_dev_info *bdi)
83{
84}
85#endif
86
87static ssize_t read_ahead_kb_store(struct device *dev,
88 struct device_attribute *attr,
89 const char *buf, size_t count)
90{
91 struct backing_dev_info *bdi = dev_get_drvdata(dev);
92 char *end;
93 unsigned long read_ahead_kb;
94 ssize_t ret = -EINVAL;
95
96 read_ahead_kb = simple_strtoul(buf, &end, 10);
97 if (*buf && (end[0] == '\0' || (end[0] == '\n' && end[1] == '\0'))) {
98 bdi->ra_pages = read_ahead_kb >> (PAGE_SHIFT - 10);
99 ret = count;
100 }
101 return ret;
102}
103
104#define K(pages) ((pages) << (PAGE_SHIFT - 10))
105
106#define BDI_SHOW(name, expr) \
107static ssize_t name##_show(struct device *dev, \
108 struct device_attribute *attr, char *page) \
109{ \
110 struct backing_dev_info *bdi = dev_get_drvdata(dev); \
111 \
112 return snprintf(page, PAGE_SIZE-1, "%lld\n", (long long)expr); \
113}
114
115BDI_SHOW(read_ahead_kb, K(bdi->ra_pages))
116
117static ssize_t min_ratio_store(struct device *dev,
118 struct device_attribute *attr, const char *buf, size_t count)
119{
120 struct backing_dev_info *bdi = dev_get_drvdata(dev);
121 char *end;
122 unsigned int ratio;
123 ssize_t ret = -EINVAL;
124
125 ratio = simple_strtoul(buf, &end, 10);
126 if (*buf && (end[0] == '\0' || (end[0] == '\n' && end[1] == '\0'))) {
127 ret = bdi_set_min_ratio(bdi, ratio);
128 if (!ret)
129 ret = count;
130 }
131 return ret;
132}
133BDI_SHOW(min_ratio, bdi->min_ratio)
134
135static ssize_t max_ratio_store(struct device *dev,
136 struct device_attribute *attr, const char *buf, size_t count)
137{
138 struct backing_dev_info *bdi = dev_get_drvdata(dev);
139 char *end;
140 unsigned int ratio;
141 ssize_t ret = -EINVAL;
142
143 ratio = simple_strtoul(buf, &end, 10);
144 if (*buf && (end[0] == '\0' || (end[0] == '\n' && end[1] == '\0'))) {
145 ret = bdi_set_max_ratio(bdi, ratio);
146 if (!ret)
147 ret = count;
148 }
149 return ret;
150}
151BDI_SHOW(max_ratio, bdi->max_ratio)
152
153#define __ATTR_RW(attr) __ATTR(attr, 0644, attr##_show, attr##_store)
154
155static struct device_attribute bdi_dev_attrs[] = {
156 __ATTR_RW(read_ahead_kb),
157 __ATTR_RW(min_ratio),
158 __ATTR_RW(max_ratio),
159 __ATTR_NULL,
160};
161
162static __init int bdi_class_init(void)
163{
164 bdi_class = class_create(THIS_MODULE, "bdi");
165 bdi_class->dev_attrs = bdi_dev_attrs;
166 bdi_debug_init();
167 return 0;
168}
169
170postcore_initcall(bdi_class_init);
171
172int bdi_register(struct backing_dev_info *bdi, struct device *parent,
173 const char *fmt, ...)
174{
175 char *name;
176 va_list args;
177 int ret = 0;
178 struct device *dev;
179
180 va_start(args, fmt);
181 name = kvasprintf(GFP_KERNEL, fmt, args);
182 va_end(args);
183
184 if (!name)
185 return -ENOMEM;
186
187 dev = device_create(bdi_class, parent, MKDEV(0, 0), name);
188 if (IS_ERR(dev)) {
189 ret = PTR_ERR(dev);
190 goto exit;
191 }
192
193 bdi->dev = dev;
194 dev_set_drvdata(bdi->dev, bdi);
195 bdi_debug_register(bdi, name);
196
197exit:
198 kfree(name);
199 return ret;
200}
201EXPORT_SYMBOL(bdi_register);
202
203int bdi_register_dev(struct backing_dev_info *bdi, dev_t dev)
204{
205 return bdi_register(bdi, NULL, "%u:%u", MAJOR(dev), MINOR(dev));
206}
207EXPORT_SYMBOL(bdi_register_dev);
208
209void bdi_unregister(struct backing_dev_info *bdi)
210{
211 if (bdi->dev) {
212 bdi_debug_unregister(bdi);
213 device_unregister(bdi->dev);
214 bdi->dev = NULL;
215 }
216}
217EXPORT_SYMBOL(bdi_unregister);
7 218
8int bdi_init(struct backing_dev_info *bdi) 219int bdi_init(struct backing_dev_info *bdi)
9{ 220{
10 int i; 221 int i;
11 int err; 222 int err;
12 223
224 bdi->dev = NULL;
225
226 bdi->min_ratio = 0;
227 bdi->max_ratio = 100;
228 bdi->max_prop_frac = PROP_FRAC_BASE;
229
13 for (i = 0; i < NR_BDI_STAT_ITEMS; i++) { 230 for (i = 0; i < NR_BDI_STAT_ITEMS; i++) {
14 err = percpu_counter_init_irq(&bdi->bdi_stat[i], 0); 231 err = percpu_counter_init_irq(&bdi->bdi_stat[i], 0);
15 if (err) 232 if (err)
@@ -33,6 +250,8 @@ void bdi_destroy(struct backing_dev_info *bdi)
33{ 250{
34 int i; 251 int i;
35 252
253 bdi_unregister(bdi);
254
36 for (i = 0; i < NR_BDI_STAT_ITEMS; i++) 255 for (i = 0; i < NR_BDI_STAT_ITEMS; i++)
37 percpu_counter_destroy(&bdi->bdi_stat[i]); 256 percpu_counter_destroy(&bdi->bdi_stat[i]);
38 257
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 33add96cd5fb..e46451e1d9b7 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -48,6 +48,8 @@ enum mem_cgroup_stat_index {
48 */ 48 */
49 MEM_CGROUP_STAT_CACHE, /* # of pages charged as cache */ 49 MEM_CGROUP_STAT_CACHE, /* # of pages charged as cache */
50 MEM_CGROUP_STAT_RSS, /* # of pages charged as rss */ 50 MEM_CGROUP_STAT_RSS, /* # of pages charged as rss */
51 MEM_CGROUP_STAT_PGPGIN_COUNT, /* # of pages paged in */
52 MEM_CGROUP_STAT_PGPGOUT_COUNT, /* # of pages paged out */
51 53
52 MEM_CGROUP_STAT_NSTATS, 54 MEM_CGROUP_STAT_NSTATS,
53}; 55};
@@ -199,6 +201,13 @@ static void mem_cgroup_charge_statistics(struct mem_cgroup *mem, int flags,
199 __mem_cgroup_stat_add_safe(stat, MEM_CGROUP_STAT_CACHE, val); 201 __mem_cgroup_stat_add_safe(stat, MEM_CGROUP_STAT_CACHE, val);
200 else 202 else
201 __mem_cgroup_stat_add_safe(stat, MEM_CGROUP_STAT_RSS, val); 203 __mem_cgroup_stat_add_safe(stat, MEM_CGROUP_STAT_RSS, val);
204
205 if (charge)
206 __mem_cgroup_stat_add_safe(stat,
207 MEM_CGROUP_STAT_PGPGIN_COUNT, 1);
208 else
209 __mem_cgroup_stat_add_safe(stat,
210 MEM_CGROUP_STAT_PGPGOUT_COUNT, 1);
202} 211}
203 212
204static struct mem_cgroup_per_zone * 213static struct mem_cgroup_per_zone *
@@ -884,6 +893,8 @@ static const struct mem_cgroup_stat_desc {
884} mem_cgroup_stat_desc[] = { 893} mem_cgroup_stat_desc[] = {
885 [MEM_CGROUP_STAT_CACHE] = { "cache", PAGE_SIZE, }, 894 [MEM_CGROUP_STAT_CACHE] = { "cache", PAGE_SIZE, },
886 [MEM_CGROUP_STAT_RSS] = { "rss", PAGE_SIZE, }, 895 [MEM_CGROUP_STAT_RSS] = { "rss", PAGE_SIZE, },
896 [MEM_CGROUP_STAT_PGPGIN_COUNT] = {"pgpgin", 1, },
897 [MEM_CGROUP_STAT_PGPGOUT_COUNT] = {"pgpgout", 1, },
887}; 898};
888 899
889static int mem_control_stat_show(struct cgroup *cont, struct cftype *cft, 900static int mem_control_stat_show(struct cgroup *cont, struct cftype *cft,
diff --git a/mm/migrate.c b/mm/migrate.c
index 4e0eccca5e26..449d77d409f5 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -383,7 +383,14 @@ static void migrate_page_copy(struct page *newpage, struct page *page)
383 383
384 if (PageDirty(page)) { 384 if (PageDirty(page)) {
385 clear_page_dirty_for_io(page); 385 clear_page_dirty_for_io(page);
386 set_page_dirty(newpage); 386 /*
387 * Want to mark the page and the radix tree as dirty, and
388 * redo the accounting that clear_page_dirty_for_io undid,
389 * but we can't use set_page_dirty because that function
390 * is actually a signal that all of the page has become dirty.
391 * Wheras only part of our page may be dirty.
392 */
393 __set_page_dirty_nobuffers(newpage);
387 } 394 }
388 395
389#ifdef CONFIG_SWAP 396#ifdef CONFIG_SWAP
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 5e00f1772c20..789b6adbef37 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -164,9 +164,20 @@ int dirty_ratio_handler(struct ctl_table *table, int write,
164 */ 164 */
165static inline void __bdi_writeout_inc(struct backing_dev_info *bdi) 165static inline void __bdi_writeout_inc(struct backing_dev_info *bdi)
166{ 166{
167 __prop_inc_percpu(&vm_completions, &bdi->completions); 167 __prop_inc_percpu_max(&vm_completions, &bdi->completions,
168 bdi->max_prop_frac);
168} 169}
169 170
171void bdi_writeout_inc(struct backing_dev_info *bdi)
172{
173 unsigned long flags;
174
175 local_irq_save(flags);
176 __bdi_writeout_inc(bdi);
177 local_irq_restore(flags);
178}
179EXPORT_SYMBOL_GPL(bdi_writeout_inc);
180
170static inline void task_dirty_inc(struct task_struct *tsk) 181static inline void task_dirty_inc(struct task_struct *tsk)
171{ 182{
172 prop_inc_single(&vm_dirties, &tsk->dirties); 183 prop_inc_single(&vm_dirties, &tsk->dirties);
@@ -200,7 +211,8 @@ clip_bdi_dirty_limit(struct backing_dev_info *bdi, long dirty, long *pbdi_dirty)
200 avail_dirty = dirty - 211 avail_dirty = dirty -
201 (global_page_state(NR_FILE_DIRTY) + 212 (global_page_state(NR_FILE_DIRTY) +
202 global_page_state(NR_WRITEBACK) + 213 global_page_state(NR_WRITEBACK) +
203 global_page_state(NR_UNSTABLE_NFS)); 214 global_page_state(NR_UNSTABLE_NFS) +
215 global_page_state(NR_WRITEBACK_TEMP));
204 216
205 if (avail_dirty < 0) 217 if (avail_dirty < 0)
206 avail_dirty = 0; 218 avail_dirty = 0;
@@ -243,6 +255,55 @@ static void task_dirty_limit(struct task_struct *tsk, long *pdirty)
243} 255}
244 256
245/* 257/*
258 *
259 */
260static DEFINE_SPINLOCK(bdi_lock);
261static unsigned int bdi_min_ratio;
262
263int bdi_set_min_ratio(struct backing_dev_info *bdi, unsigned int min_ratio)
264{
265 int ret = 0;
266 unsigned long flags;
267
268 spin_lock_irqsave(&bdi_lock, flags);
269 if (min_ratio > bdi->max_ratio) {
270 ret = -EINVAL;
271 } else {
272 min_ratio -= bdi->min_ratio;
273 if (bdi_min_ratio + min_ratio < 100) {
274 bdi_min_ratio += min_ratio;
275 bdi->min_ratio += min_ratio;
276 } else {
277 ret = -EINVAL;
278 }
279 }
280 spin_unlock_irqrestore(&bdi_lock, flags);
281
282 return ret;
283}
284
285int bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned max_ratio)
286{
287 unsigned long flags;
288 int ret = 0;
289
290 if (max_ratio > 100)
291 return -EINVAL;
292
293 spin_lock_irqsave(&bdi_lock, flags);
294 if (bdi->min_ratio > max_ratio) {
295 ret = -EINVAL;
296 } else {
297 bdi->max_ratio = max_ratio;
298 bdi->max_prop_frac = (PROP_FRAC_BASE * max_ratio) / 100;
299 }
300 spin_unlock_irqrestore(&bdi_lock, flags);
301
302 return ret;
303}
304EXPORT_SYMBOL(bdi_set_max_ratio);
305
306/*
246 * Work out the current dirty-memory clamping and background writeout 307 * Work out the current dirty-memory clamping and background writeout
247 * thresholds. 308 * thresholds.
248 * 309 *
@@ -300,7 +361,7 @@ static unsigned long determine_dirtyable_memory(void)
300 return x + 1; /* Ensure that we never return 0 */ 361 return x + 1; /* Ensure that we never return 0 */
301} 362}
302 363
303static void 364void
304get_dirty_limits(long *pbackground, long *pdirty, long *pbdi_dirty, 365get_dirty_limits(long *pbackground, long *pdirty, long *pbdi_dirty,
305 struct backing_dev_info *bdi) 366 struct backing_dev_info *bdi)
306{ 367{
@@ -330,7 +391,7 @@ get_dirty_limits(long *pbackground, long *pdirty, long *pbdi_dirty,
330 *pdirty = dirty; 391 *pdirty = dirty;
331 392
332 if (bdi) { 393 if (bdi) {
333 u64 bdi_dirty = dirty; 394 u64 bdi_dirty;
334 long numerator, denominator; 395 long numerator, denominator;
335 396
336 /* 397 /*
@@ -338,8 +399,12 @@ get_dirty_limits(long *pbackground, long *pdirty, long *pbdi_dirty,
338 */ 399 */
339 bdi_writeout_fraction(bdi, &numerator, &denominator); 400 bdi_writeout_fraction(bdi, &numerator, &denominator);
340 401
402 bdi_dirty = (dirty * (100 - bdi_min_ratio)) / 100;
341 bdi_dirty *= numerator; 403 bdi_dirty *= numerator;
342 do_div(bdi_dirty, denominator); 404 do_div(bdi_dirty, denominator);
405 bdi_dirty += (dirty * bdi->min_ratio) / 100;
406 if (bdi_dirty > (dirty * bdi->max_ratio) / 100)
407 bdi_dirty = dirty * bdi->max_ratio / 100;
343 408
344 *pbdi_dirty = bdi_dirty; 409 *pbdi_dirty = bdi_dirty;
345 clip_bdi_dirty_limit(bdi, dirty, pbdi_dirty); 410 clip_bdi_dirty_limit(bdi, dirty, pbdi_dirty);
@@ -1192,7 +1257,7 @@ int test_clear_page_writeback(struct page *page)
1192 radix_tree_tag_clear(&mapping->page_tree, 1257 radix_tree_tag_clear(&mapping->page_tree,
1193 page_index(page), 1258 page_index(page),
1194 PAGECACHE_TAG_WRITEBACK); 1259 PAGECACHE_TAG_WRITEBACK);
1195 if (bdi_cap_writeback_dirty(bdi)) { 1260 if (bdi_cap_account_writeback(bdi)) {
1196 __dec_bdi_stat(bdi, BDI_WRITEBACK); 1261 __dec_bdi_stat(bdi, BDI_WRITEBACK);
1197 __bdi_writeout_inc(bdi); 1262 __bdi_writeout_inc(bdi);
1198 } 1263 }
@@ -1221,7 +1286,7 @@ int test_set_page_writeback(struct page *page)
1221 radix_tree_tag_set(&mapping->page_tree, 1286 radix_tree_tag_set(&mapping->page_tree,
1222 page_index(page), 1287 page_index(page),
1223 PAGECACHE_TAG_WRITEBACK); 1288 PAGECACHE_TAG_WRITEBACK);
1224 if (bdi_cap_writeback_dirty(bdi)) 1289 if (bdi_cap_account_writeback(bdi))
1225 __inc_bdi_stat(bdi, BDI_WRITEBACK); 1290 __inc_bdi_stat(bdi, BDI_WRITEBACK);
1226 } 1291 }
1227 if (!PageDirty(page)) 1292 if (!PageDirty(page))
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 0a502e99ee22..bdd5c432c426 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -45,6 +45,7 @@
45#include <linux/fault-inject.h> 45#include <linux/fault-inject.h>
46#include <linux/page-isolation.h> 46#include <linux/page-isolation.h>
47#include <linux/memcontrol.h> 47#include <linux/memcontrol.h>
48#include <linux/debugobjects.h>
48 49
49#include <asm/tlbflush.h> 50#include <asm/tlbflush.h>
50#include <asm/div64.h> 51#include <asm/div64.h>
@@ -532,8 +533,11 @@ static void __free_pages_ok(struct page *page, unsigned int order)
532 if (reserved) 533 if (reserved)
533 return; 534 return;
534 535
535 if (!PageHighMem(page)) 536 if (!PageHighMem(page)) {
536 debug_check_no_locks_freed(page_address(page),PAGE_SIZE<<order); 537 debug_check_no_locks_freed(page_address(page),PAGE_SIZE<<order);
538 debug_check_no_obj_freed(page_address(page),
539 PAGE_SIZE << order);
540 }
537 arch_free_page(page, order); 541 arch_free_page(page, order);
538 kernel_map_pages(page, 1 << order, 0); 542 kernel_map_pages(page, 1 << order, 0);
539 543
@@ -995,8 +999,10 @@ static void free_hot_cold_page(struct page *page, int cold)
995 if (free_pages_check(page)) 999 if (free_pages_check(page))
996 return; 1000 return;
997 1001
998 if (!PageHighMem(page)) 1002 if (!PageHighMem(page)) {
999 debug_check_no_locks_freed(page_address(page), PAGE_SIZE); 1003 debug_check_no_locks_freed(page_address(page), PAGE_SIZE);
1004 debug_check_no_obj_freed(page_address(page), PAGE_SIZE);
1005 }
1000 arch_free_page(page, 0); 1006 arch_free_page(page, 0);
1001 kernel_map_pages(page, 1, 0); 1007 kernel_map_pages(page, 1, 0);
1002 1008
diff --git a/mm/readahead.c b/mm/readahead.c
index 8762e8988972..d8723a5f6496 100644
--- a/mm/readahead.c
+++ b/mm/readahead.c
@@ -235,7 +235,13 @@ unsigned long max_sane_readahead(unsigned long nr)
235 235
236static int __init readahead_init(void) 236static int __init readahead_init(void)
237{ 237{
238 return bdi_init(&default_backing_dev_info); 238 int err;
239
240 err = bdi_init(&default_backing_dev_info);
241 if (!err)
242 bdi_register(&default_backing_dev_info, NULL, "default");
243
244 return err;
239} 245}
240subsys_initcall(readahead_init); 246subsys_initcall(readahead_init);
241 247
diff --git a/mm/shmem.c b/mm/shmem.c
index e6d9298aa22a..e2a6ae1a44e9 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -201,7 +201,7 @@ static struct vm_operations_struct shmem_vm_ops;
201 201
202static struct backing_dev_info shmem_backing_dev_info __read_mostly = { 202static struct backing_dev_info shmem_backing_dev_info __read_mostly = {
203 .ra_pages = 0, /* No readahead */ 203 .ra_pages = 0, /* No readahead */
204 .capabilities = BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_WRITEBACK, 204 .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK,
205 .unplug_io_fn = default_unplug_io_fn, 205 .unplug_io_fn = default_unplug_io_fn,
206}; 206};
207 207
diff --git a/mm/slab.c b/mm/slab.c
index 39d20f8a0791..06236e4ddc1b 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -110,6 +110,7 @@
110#include <linux/fault-inject.h> 110#include <linux/fault-inject.h>
111#include <linux/rtmutex.h> 111#include <linux/rtmutex.h>
112#include <linux/reciprocal_div.h> 112#include <linux/reciprocal_div.h>
113#include <linux/debugobjects.h>
113 114
114#include <asm/cacheflush.h> 115#include <asm/cacheflush.h>
115#include <asm/tlbflush.h> 116#include <asm/tlbflush.h>
@@ -174,12 +175,14 @@
174 SLAB_CACHE_DMA | \ 175 SLAB_CACHE_DMA | \
175 SLAB_STORE_USER | \ 176 SLAB_STORE_USER | \
176 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \ 177 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
177 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD) 178 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
179 SLAB_DEBUG_OBJECTS)
178#else 180#else
179# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \ 181# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
180 SLAB_CACHE_DMA | \ 182 SLAB_CACHE_DMA | \
181 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \ 183 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
182 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD) 184 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
185 SLAB_DEBUG_OBJECTS)
183#endif 186#endif
184 187
185/* 188/*
@@ -858,7 +861,7 @@ static void cache_estimate(unsigned long gfporder, size_t buffer_size,
858 *left_over = slab_size - nr_objs*buffer_size - mgmt_size; 861 *left_over = slab_size - nr_objs*buffer_size - mgmt_size;
859} 862}
860 863
861#define slab_error(cachep, msg) __slab_error(__FUNCTION__, cachep, msg) 864#define slab_error(cachep, msg) __slab_error(__func__, cachep, msg)
862 865
863static void __slab_error(const char *function, struct kmem_cache *cachep, 866static void __slab_error(const char *function, struct kmem_cache *cachep,
864 char *msg) 867 char *msg)
@@ -2153,7 +2156,7 @@ kmem_cache_create (const char *name, size_t size, size_t align,
2153 */ 2156 */
2154 if (!name || in_interrupt() || (size < BYTES_PER_WORD) || 2157 if (!name || in_interrupt() || (size < BYTES_PER_WORD) ||
2155 size > KMALLOC_MAX_SIZE) { 2158 size > KMALLOC_MAX_SIZE) {
2156 printk(KERN_ERR "%s: Early error in slab %s\n", __FUNCTION__, 2159 printk(KERN_ERR "%s: Early error in slab %s\n", __func__,
2157 name); 2160 name);
2158 BUG(); 2161 BUG();
2159 } 2162 }
@@ -3760,6 +3763,8 @@ void kmem_cache_free(struct kmem_cache *cachep, void *objp)
3760 3763
3761 local_irq_save(flags); 3764 local_irq_save(flags);
3762 debug_check_no_locks_freed(objp, obj_size(cachep)); 3765 debug_check_no_locks_freed(objp, obj_size(cachep));
3766 if (!(cachep->flags & SLAB_DEBUG_OBJECTS))
3767 debug_check_no_obj_freed(objp, obj_size(cachep));
3763 __cache_free(cachep, objp); 3768 __cache_free(cachep, objp);
3764 local_irq_restore(flags); 3769 local_irq_restore(flags);
3765} 3770}
@@ -3785,6 +3790,7 @@ void kfree(const void *objp)
3785 kfree_debugcheck(objp); 3790 kfree_debugcheck(objp);
3786 c = virt_to_cache(objp); 3791 c = virt_to_cache(objp);
3787 debug_check_no_locks_freed(objp, obj_size(c)); 3792 debug_check_no_locks_freed(objp, obj_size(c));
3793 debug_check_no_obj_freed(objp, obj_size(c));
3788 __cache_free(c, (void *)objp); 3794 __cache_free(c, (void *)objp);
3789 local_irq_restore(flags); 3795 local_irq_restore(flags);
3790} 3796}
diff --git a/mm/slub.c b/mm/slub.c
index b145e798bf3d..d379b782fc83 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -19,8 +19,10 @@
19#include <linux/cpuset.h> 19#include <linux/cpuset.h>
20#include <linux/mempolicy.h> 20#include <linux/mempolicy.h>
21#include <linux/ctype.h> 21#include <linux/ctype.h>
22#include <linux/debugobjects.h>
22#include <linux/kallsyms.h> 23#include <linux/kallsyms.h>
23#include <linux/memory.h> 24#include <linux/memory.h>
25#include <linux/math64.h>
24 26
25/* 27/*
26 * Lock order: 28 * Lock order:
@@ -215,7 +217,7 @@ struct track {
215 217
216enum track_item { TRACK_ALLOC, TRACK_FREE }; 218enum track_item { TRACK_ALLOC, TRACK_FREE };
217 219
218#if defined(CONFIG_SYSFS) && defined(CONFIG_SLUB_DEBUG) 220#ifdef CONFIG_SLUB_DEBUG
219static int sysfs_slab_add(struct kmem_cache *); 221static int sysfs_slab_add(struct kmem_cache *);
220static int sysfs_slab_alias(struct kmem_cache *, const char *); 222static int sysfs_slab_alias(struct kmem_cache *, const char *);
221static void sysfs_slab_remove(struct kmem_cache *); 223static void sysfs_slab_remove(struct kmem_cache *);
@@ -812,7 +814,8 @@ static int on_freelist(struct kmem_cache *s, struct page *page, void *search)
812 return search == NULL; 814 return search == NULL;
813} 815}
814 816
815static void trace(struct kmem_cache *s, struct page *page, void *object, int alloc) 817static void trace(struct kmem_cache *s, struct page *page, void *object,
818 int alloc)
816{ 819{
817 if (s->flags & SLAB_TRACE) { 820 if (s->flags & SLAB_TRACE) {
818 printk(KERN_INFO "TRACE %s %s 0x%p inuse=%d fp=0x%p\n", 821 printk(KERN_INFO "TRACE %s %s 0x%p inuse=%d fp=0x%p\n",
@@ -1265,8 +1268,7 @@ static void add_partial(struct kmem_cache_node *n,
1265 spin_unlock(&n->list_lock); 1268 spin_unlock(&n->list_lock);
1266} 1269}
1267 1270
1268static void remove_partial(struct kmem_cache *s, 1271static void remove_partial(struct kmem_cache *s, struct page *page)
1269 struct page *page)
1270{ 1272{
1271 struct kmem_cache_node *n = get_node(s, page_to_nid(page)); 1273 struct kmem_cache_node *n = get_node(s, page_to_nid(page));
1272 1274
@@ -1281,7 +1283,8 @@ static void remove_partial(struct kmem_cache *s,
1281 * 1283 *
1282 * Must hold list_lock. 1284 * Must hold list_lock.
1283 */ 1285 */
1284static inline int lock_and_freeze_slab(struct kmem_cache_node *n, struct page *page) 1286static inline int lock_and_freeze_slab(struct kmem_cache_node *n,
1287 struct page *page)
1285{ 1288{
1286 if (slab_trylock(page)) { 1289 if (slab_trylock(page)) {
1287 list_del(&page->lru); 1290 list_del(&page->lru);
@@ -1418,8 +1421,8 @@ static void unfreeze_slab(struct kmem_cache *s, struct page *page, int tail)
1418 * so that the others get filled first. That way the 1421 * so that the others get filled first. That way the
1419 * size of the partial list stays small. 1422 * size of the partial list stays small.
1420 * 1423 *
1421 * kmem_cache_shrink can reclaim any empty slabs from the 1424 * kmem_cache_shrink can reclaim any empty slabs from
1422 * partial list. 1425 * the partial list.
1423 */ 1426 */
1424 add_partial(n, page, 1); 1427 add_partial(n, page, 1);
1425 slab_unlock(page); 1428 slab_unlock(page);
@@ -1747,6 +1750,8 @@ static __always_inline void slab_free(struct kmem_cache *s,
1747 local_irq_save(flags); 1750 local_irq_save(flags);
1748 c = get_cpu_slab(s, smp_processor_id()); 1751 c = get_cpu_slab(s, smp_processor_id());
1749 debug_check_no_locks_freed(object, c->objsize); 1752 debug_check_no_locks_freed(object, c->objsize);
1753 if (!(s->flags & SLAB_DEBUG_OBJECTS))
1754 debug_check_no_obj_freed(object, s->objsize);
1750 if (likely(page == c->page && c->node >= 0)) { 1755 if (likely(page == c->page && c->node >= 0)) {
1751 object[c->offset] = c->freelist; 1756 object[c->offset] = c->freelist;
1752 c->freelist = object; 1757 c->freelist = object;
@@ -2905,7 +2910,7 @@ static int slab_mem_going_online_callback(void *arg)
2905 return 0; 2910 return 0;
2906 2911
2907 /* 2912 /*
2908 * We are bringing a node online. No memory is availabe yet. We must 2913 * We are bringing a node online. No memory is available yet. We must
2909 * allocate a kmem_cache_node structure in order to bring the node 2914 * allocate a kmem_cache_node structure in order to bring the node
2910 * online. 2915 * online.
2911 */ 2916 */
@@ -3242,7 +3247,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
3242 return slab_alloc(s, gfpflags, node, caller); 3247 return slab_alloc(s, gfpflags, node, caller);
3243} 3248}
3244 3249
3245#if (defined(CONFIG_SYSFS) && defined(CONFIG_SLUB_DEBUG)) || defined(CONFIG_SLABINFO) 3250#ifdef CONFIG_SLUB_DEBUG
3246static unsigned long count_partial(struct kmem_cache_node *n, 3251static unsigned long count_partial(struct kmem_cache_node *n,
3247 int (*get_count)(struct page *)) 3252 int (*get_count)(struct page *))
3248{ 3253{
@@ -3271,9 +3276,7 @@ static int count_free(struct page *page)
3271{ 3276{
3272 return page->objects - page->inuse; 3277 return page->objects - page->inuse;
3273} 3278}
3274#endif
3275 3279
3276#if defined(CONFIG_SYSFS) && defined(CONFIG_SLUB_DEBUG)
3277static int validate_slab(struct kmem_cache *s, struct page *page, 3280static int validate_slab(struct kmem_cache *s, struct page *page,
3278 unsigned long *map) 3281 unsigned long *map)
3279{ 3282{
@@ -3618,12 +3621,10 @@ static int list_locations(struct kmem_cache *s, char *buf,
3618 len += sprintf(buf + len, "<not-available>"); 3621 len += sprintf(buf + len, "<not-available>");
3619 3622
3620 if (l->sum_time != l->min_time) { 3623 if (l->sum_time != l->min_time) {
3621 unsigned long remainder;
3622
3623 len += sprintf(buf + len, " age=%ld/%ld/%ld", 3624 len += sprintf(buf + len, " age=%ld/%ld/%ld",
3624 l->min_time, 3625 l->min_time,
3625 div_long_long_rem(l->sum_time, l->count, &remainder), 3626 (long)div_u64(l->sum_time, l->count),
3626 l->max_time); 3627 l->max_time);
3627 } else 3628 } else
3628 len += sprintf(buf + len, " age=%ld", 3629 len += sprintf(buf + len, " age=%ld",
3629 l->min_time); 3630 l->min_time);
@@ -3810,7 +3811,12 @@ SLAB_ATTR_RO(objs_per_slab);
3810static ssize_t order_store(struct kmem_cache *s, 3811static ssize_t order_store(struct kmem_cache *s,
3811 const char *buf, size_t length) 3812 const char *buf, size_t length)
3812{ 3813{
3813 int order = simple_strtoul(buf, NULL, 10); 3814 unsigned long order;
3815 int err;
3816
3817 err = strict_strtoul(buf, 10, &order);
3818 if (err)
3819 return err;
3814 3820
3815 if (order > slub_max_order || order < slub_min_order) 3821 if (order > slub_max_order || order < slub_min_order)
3816 return -EINVAL; 3822 return -EINVAL;
@@ -4063,10 +4069,16 @@ static ssize_t remote_node_defrag_ratio_show(struct kmem_cache *s, char *buf)
4063static ssize_t remote_node_defrag_ratio_store(struct kmem_cache *s, 4069static ssize_t remote_node_defrag_ratio_store(struct kmem_cache *s,
4064 const char *buf, size_t length) 4070 const char *buf, size_t length)
4065{ 4071{
4066 int n = simple_strtoul(buf, NULL, 10); 4072 unsigned long ratio;
4073 int err;
4074
4075 err = strict_strtoul(buf, 10, &ratio);
4076 if (err)
4077 return err;
4078
4079 if (ratio < 100)
4080 s->remote_node_defrag_ratio = ratio * 10;
4067 4081
4068 if (n < 100)
4069 s->remote_node_defrag_ratio = n * 10;
4070 return length; 4082 return length;
4071} 4083}
4072SLAB_ATTR(remote_node_defrag_ratio); 4084SLAB_ATTR(remote_node_defrag_ratio);
@@ -4423,8 +4435,8 @@ __initcall(slab_sysfs_init);
4423 */ 4435 */
4424#ifdef CONFIG_SLABINFO 4436#ifdef CONFIG_SLABINFO
4425 4437
4426ssize_t slabinfo_write(struct file *file, const char __user * buffer, 4438ssize_t slabinfo_write(struct file *file, const char __user *buffer,
4427 size_t count, loff_t *ppos) 4439 size_t count, loff_t *ppos)
4428{ 4440{
4429 return -EINVAL; 4441 return -EINVAL;
4430} 4442}
diff --git a/mm/sparse.c b/mm/sparse.c
index dff71f173ae9..36511c7b5e2c 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -250,29 +250,18 @@ static unsigned long *__kmalloc_section_usemap(void)
250 250
251static unsigned long *__init sparse_early_usemap_alloc(unsigned long pnum) 251static unsigned long *__init sparse_early_usemap_alloc(unsigned long pnum)
252{ 252{
253 unsigned long *usemap, section_nr; 253 unsigned long *usemap;
254 struct mem_section *ms = __nr_to_section(pnum); 254 struct mem_section *ms = __nr_to_section(pnum);
255 int nid = sparse_early_nid(ms); 255 int nid = sparse_early_nid(ms);
256 struct pglist_data *pgdat = NODE_DATA(nid);
257 256
258 /* 257 usemap = alloc_bootmem_node(NODE_DATA(nid), usemap_size());
259 * Usemap's page can't be freed until freeing other sections
260 * which use it. And, Pgdat has same feature.
261 * If section A has pgdat and section B has usemap for other
262 * sections (includes section A), both sections can't be removed,
263 * because there is the dependency each other.
264 * To solve above issue, this collects all usemap on the same section
265 * which has pgdat.
266 */
267 section_nr = pfn_to_section_nr(__pa(pgdat) >> PAGE_SHIFT);
268 usemap = alloc_bootmem_section(usemap_size(), section_nr);
269 if (usemap) 258 if (usemap)
270 return usemap; 259 return usemap;
271 260
272 /* Stupid: suppress gcc warning for SPARSEMEM && !NUMA */ 261 /* Stupid: suppress gcc warning for SPARSEMEM && !NUMA */
273 nid = 0; 262 nid = 0;
274 263
275 printk(KERN_WARNING "%s: allocation failed\n", __FUNCTION__); 264 printk(KERN_WARNING "%s: allocation failed\n", __func__);
276 return NULL; 265 return NULL;
277} 266}
278 267
@@ -302,7 +291,7 @@ struct page __init *sparse_early_mem_map_alloc(unsigned long pnum)
302 return map; 291 return map;
303 292
304 printk(KERN_ERR "%s: sparsemem memory map backing failed " 293 printk(KERN_ERR "%s: sparsemem memory map backing failed "
305 "some memory will not be available.\n", __FUNCTION__); 294 "some memory will not be available.\n", __func__);
306 ms->section_mem_map = 0; 295 ms->section_mem_map = 0;
307 return NULL; 296 return NULL;
308} 297}
diff --git a/mm/swap_state.c b/mm/swap_state.c
index 50757ee3f9f3..d8aadaf2a0ba 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -33,7 +33,7 @@ static const struct address_space_operations swap_aops = {
33}; 33};
34 34
35static struct backing_dev_info swap_backing_dev_info = { 35static struct backing_dev_info swap_backing_dev_info = {
36 .capabilities = BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_WRITEBACK, 36 .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK,
37 .unplug_io_fn = swap_unplug_io_fn, 37 .unplug_io_fn = swap_unplug_io_fn,
38}; 38};
39 39
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index e33e0ae69ad1..6e45b0f3d125 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -15,6 +15,7 @@
15#include <linux/spinlock.h> 15#include <linux/spinlock.h>
16#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/seq_file.h> 17#include <linux/seq_file.h>
18#include <linux/debugobjects.h>
18#include <linux/vmalloc.h> 19#include <linux/vmalloc.h>
19#include <linux/kallsyms.h> 20#include <linux/kallsyms.h>
20 21
@@ -394,6 +395,7 @@ static void __vunmap(const void *addr, int deallocate_pages)
394 } 395 }
395 396
396 debug_check_no_locks_freed(addr, area->size); 397 debug_check_no_locks_freed(addr, area->size);
398 debug_check_no_obj_freed(addr, area->size);
397 399
398 if (deallocate_pages) { 400 if (deallocate_pages) {
399 int i; 401 int i;
@@ -545,6 +547,7 @@ void *__vmalloc_area(struct vm_struct *area, gfp_t gfp_mask, pgprot_t prot)
545 * @gfp_mask: flags for the page level allocator 547 * @gfp_mask: flags for the page level allocator
546 * @prot: protection mask for the allocated pages 548 * @prot: protection mask for the allocated pages
547 * @node: node to use for allocation or -1 549 * @node: node to use for allocation or -1
550 * @caller: caller's return address
548 * 551 *
549 * Allocate enough pages to cover @size from the page level 552 * Allocate enough pages to cover @size from the page level
550 * allocator with @gfp_mask flags. Map them into contiguous 553 * allocator with @gfp_mask flags. Map them into contiguous
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 12e8627c9747..9a29901ad3b3 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -191,7 +191,7 @@ unsigned long shrink_slab(unsigned long scanned, gfp_t gfp_mask,
191 shrinker->nr += delta; 191 shrinker->nr += delta;
192 if (shrinker->nr < 0) { 192 if (shrinker->nr < 0) {
193 printk(KERN_ERR "%s: nr=%ld\n", 193 printk(KERN_ERR "%s: nr=%ld\n",
194 __FUNCTION__, shrinker->nr); 194 __func__, shrinker->nr);
195 shrinker->nr = max_pass; 195 shrinker->nr = max_pass;
196 } 196 }
197 197
@@ -339,7 +339,7 @@ static pageout_t pageout(struct page *page, struct address_space *mapping,
339 if (PagePrivate(page)) { 339 if (PagePrivate(page)) {
340 if (try_to_free_buffers(page)) { 340 if (try_to_free_buffers(page)) {
341 ClearPageDirty(page); 341 ClearPageDirty(page);
342 printk("%s: orphaned page\n", __FUNCTION__); 342 printk("%s: orphaned page\n", __func__);
343 return PAGE_CLEAN; 343 return PAGE_CLEAN;
344 } 344 }
345 } 345 }
diff --git a/mm/vmstat.c b/mm/vmstat.c
index ec6035eda933..1a32130b958c 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -548,6 +548,10 @@ static int pagetypeinfo_show(struct seq_file *m, void *arg)
548{ 548{
549 pg_data_t *pgdat = (pg_data_t *)arg; 549 pg_data_t *pgdat = (pg_data_t *)arg;
550 550
551 /* check memoryless node */
552 if (!node_state(pgdat->node_id, N_HIGH_MEMORY))
553 return 0;
554
551 seq_printf(m, "Page block order: %d\n", pageblock_order); 555 seq_printf(m, "Page block order: %d\n", pageblock_order);
552 seq_printf(m, "Pages per block: %lu\n", pageblock_nr_pages); 556 seq_printf(m, "Pages per block: %lu\n", pageblock_nr_pages);
553 seq_putc(m, '\n'); 557 seq_putc(m, '\n');
@@ -608,6 +612,7 @@ static const char * const vmstat_text[] = {
608 "nr_unstable", 612 "nr_unstable",
609 "nr_bounce", 613 "nr_bounce",
610 "nr_vmscan_write", 614 "nr_vmscan_write",
615 "nr_writeback_temp",
611 616
612#ifdef CONFIG_NUMA 617#ifdef CONFIG_NUMA
613 "numa_hit", 618 "numa_hit",
diff --git a/net/8021q/vlanproc.c b/net/8021q/vlanproc.c
index daad0064e2c2..08b54b593d56 100644
--- a/net/8021q/vlanproc.c
+++ b/net/8021q/vlanproc.c
@@ -176,12 +176,11 @@ int vlan_proc_add_dev(struct net_device *vlandev)
176 struct vlan_dev_info *dev_info = vlan_dev_info(vlandev); 176 struct vlan_dev_info *dev_info = vlan_dev_info(vlandev);
177 struct vlan_net *vn = net_generic(dev_net(vlandev), vlan_net_id); 177 struct vlan_net *vn = net_generic(dev_net(vlandev), vlan_net_id);
178 178
179 dev_info->dent = proc_create(vlandev->name, S_IFREG|S_IRUSR|S_IWUSR, 179 dev_info->dent =
180 vn->proc_vlan_dir, &vlandev_fops); 180 proc_create_data(vlandev->name, S_IFREG|S_IRUSR|S_IWUSR,
181 vn->proc_vlan_dir, &vlandev_fops, vlandev);
181 if (!dev_info->dent) 182 if (!dev_info->dent)
182 return -ENOBUFS; 183 return -ENOBUFS;
183
184 dev_info->dent->data = vlandev;
185 return 0; 184 return 0;
186} 185}
187 186
diff --git a/net/atm/proc.c b/net/atm/proc.c
index 5c9f3d148135..49487b313f22 100644
--- a/net/atm/proc.c
+++ b/net/atm/proc.c
@@ -417,12 +417,10 @@ int atm_proc_dev_register(struct atm_dev *dev)
417 goto err_out; 417 goto err_out;
418 sprintf(dev->proc_name,"%s:%d",dev->type, dev->number); 418 sprintf(dev->proc_name,"%s:%d",dev->type, dev->number);
419 419
420 dev->proc_entry = proc_create(dev->proc_name, 0, atm_proc_root, 420 dev->proc_entry = proc_create_data(dev->proc_name, 0, atm_proc_root,
421 &proc_atm_dev_ops); 421 &proc_atm_dev_ops, dev);
422 if (!dev->proc_entry) 422 if (!dev->proc_entry)
423 goto err_free_name; 423 goto err_free_name;
424 dev->proc_entry->data = dev;
425 dev->proc_entry->owner = THIS_MODULE;
426 return 0; 424 return 0;
427err_free_name: 425err_free_name:
428 kfree(dev->proc_name); 426 kfree(dev->proc_name);
diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
index 347e935faaf0..f85d94643aaf 100644
--- a/net/bluetooth/bnep/core.c
+++ b/net/bluetooth/bnep/core.c
@@ -135,7 +135,7 @@ static int bnep_ctrl_set_netfilter(struct bnep_session *s, __be16 *data, int len
135 if (len < 2) 135 if (len < 2)
136 return -EILSEQ; 136 return -EILSEQ;
137 137
138 n = ntohs(get_unaligned(data)); 138 n = get_unaligned_be16(data);
139 data++; len -= 2; 139 data++; len -= 2;
140 140
141 if (len < n) 141 if (len < n)
@@ -150,8 +150,8 @@ static int bnep_ctrl_set_netfilter(struct bnep_session *s, __be16 *data, int len
150 int i; 150 int i;
151 151
152 for (i = 0; i < n; i++) { 152 for (i = 0; i < n; i++) {
153 f[i].start = ntohs(get_unaligned(data++)); 153 f[i].start = get_unaligned_be16(data++);
154 f[i].end = ntohs(get_unaligned(data++)); 154 f[i].end = get_unaligned_be16(data++);
155 155
156 BT_DBG("proto filter start %d end %d", 156 BT_DBG("proto filter start %d end %d",
157 f[i].start, f[i].end); 157 f[i].start, f[i].end);
@@ -180,7 +180,7 @@ static int bnep_ctrl_set_mcfilter(struct bnep_session *s, u8 *data, int len)
180 if (len < 2) 180 if (len < 2)
181 return -EILSEQ; 181 return -EILSEQ;
182 182
183 n = ntohs(get_unaligned((__be16 *) data)); 183 n = get_unaligned_be16(data);
184 data += 2; len -= 2; 184 data += 2; len -= 2;
185 185
186 if (len < n) 186 if (len < n)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 46df2e403df8..6aef8f24e581 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -129,8 +129,7 @@ static void hci_cc_write_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
129 129
130 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); 130 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
131 if (conn) { 131 if (conn) {
132 __le16 policy = get_unaligned((__le16 *) (sent + 2)); 132 conn->link_policy = get_unaligned_le16(sent + 2);
133 conn->link_policy = __le16_to_cpu(policy);
134 } 133 }
135 134
136 hci_dev_unlock(hdev); 135 hci_dev_unlock(hdev);
@@ -313,7 +312,7 @@ static void hci_cc_write_voice_setting(struct hci_dev *hdev, struct sk_buff *skb
313 return; 312 return;
314 313
315 if (!status) { 314 if (!status) {
316 __u16 setting = __le16_to_cpu(get_unaligned((__le16 *) sent)); 315 __u16 setting = get_unaligned_le16(sent);
317 316
318 if (hdev->voice_setting != setting) { 317 if (hdev->voice_setting != setting) {
319 hdev->voice_setting = setting; 318 hdev->voice_setting = setting;
@@ -1152,8 +1151,8 @@ static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *s
1152 struct hci_conn *conn; 1151 struct hci_conn *conn;
1153 __u16 handle, count; 1152 __u16 handle, count;
1154 1153
1155 handle = __le16_to_cpu(get_unaligned(ptr++)); 1154 handle = get_unaligned_le16(ptr++);
1156 count = __le16_to_cpu(get_unaligned(ptr++)); 1155 count = get_unaligned_le16(ptr++);
1157 1156
1158 conn = hci_conn_hash_lookup_handle(hdev, handle); 1157 conn = hci_conn_hash_lookup_handle(hdev, handle);
1159 if (conn) { 1158 if (conn) {
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 1d36c093523b..747fabd735d2 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -440,7 +440,7 @@ static int hci_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
440 skb->dev = (void *) hdev; 440 skb->dev = (void *) hdev;
441 441
442 if (bt_cb(skb)->pkt_type == HCI_COMMAND_PKT) { 442 if (bt_cb(skb)->pkt_type == HCI_COMMAND_PKT) {
443 u16 opcode = __le16_to_cpu(get_unaligned((__le16 *) skb->data)); 443 u16 opcode = get_unaligned_le16(skb->data);
444 u16 ogf = hci_opcode_ogf(opcode); 444 u16 ogf = hci_opcode_ogf(opcode);
445 u16 ocf = hci_opcode_ocf(opcode); 445 u16 ocf = hci_opcode_ocf(opcode);
446 446
diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
index a4849f2c1d81..6e180d255505 100644
--- a/net/bluetooth/l2cap.c
+++ b/net/bluetooth/l2cap.c
@@ -1827,7 +1827,7 @@ static inline int l2cap_information_rsp(struct l2cap_conn *conn, struct l2cap_cm
1827 del_timer(&conn->info_timer); 1827 del_timer(&conn->info_timer);
1828 1828
1829 if (type == L2CAP_IT_FEAT_MASK) 1829 if (type == L2CAP_IT_FEAT_MASK)
1830 conn->feat_mask = __le32_to_cpu(get_unaligned((__le32 *) rsp->data)); 1830 conn->feat_mask = get_unaligned_le32(rsp->data);
1831 1831
1832 l2cap_conn_start(conn); 1832 l2cap_conn_start(conn);
1833 1833
diff --git a/net/bridge/br.c b/net/bridge/br.c
index a90182873120..8f3c58e5f7a5 100644
--- a/net/bridge/br.c
+++ b/net/bridge/br.c
@@ -76,7 +76,6 @@ static void __exit br_deinit(void)
76 rcu_assign_pointer(br_stp_sap->rcv_func, NULL); 76 rcu_assign_pointer(br_stp_sap->rcv_func, NULL);
77 77
78 br_netlink_fini(); 78 br_netlink_fini();
79 br_netfilter_fini();
80 unregister_netdevice_notifier(&br_device_notifier); 79 unregister_netdevice_notifier(&br_device_notifier);
81 brioctl_set(NULL); 80 brioctl_set(NULL);
82 81
@@ -84,6 +83,7 @@ static void __exit br_deinit(void)
84 83
85 synchronize_net(); 84 synchronize_net();
86 85
86 br_netfilter_fini();
87 llc_sap_put(br_stp_sap); 87 llc_sap_put(br_stp_sap);
88 br_fdb_get_hook = NULL; 88 br_fdb_get_hook = NULL;
89 br_fdb_put_hook = NULL; 89 br_fdb_put_hook = NULL;
diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
index 9326c377822e..72c5976a5ce3 100644
--- a/net/bridge/br_fdb.c
+++ b/net/bridge/br_fdb.c
@@ -285,7 +285,11 @@ int br_fdb_fillbuf(struct net_bridge *br, void *buf,
285 285
286 /* convert from internal format to API */ 286 /* convert from internal format to API */
287 memcpy(fe->mac_addr, f->addr.addr, ETH_ALEN); 287 memcpy(fe->mac_addr, f->addr.addr, ETH_ALEN);
288
289 /* due to ABI compat need to split into hi/lo */
288 fe->port_no = f->dst->port_no; 290 fe->port_no = f->dst->port_no;
291 fe->port_hi = f->dst->port_no >> 8;
292
289 fe->is_local = f->is_local; 293 fe->is_local = f->is_local;
290 if (!f->is_static) 294 if (!f->is_static)
291 fe->ageing_timer_value = jiffies_to_clock_t(jiffies - f->ageing_timer); 295 fe->ageing_timer_value = jiffies_to_clock_t(jiffies - f->ageing_timer);
diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
index 298e0f463c56..77a981a1ee52 100644
--- a/net/bridge/br_if.c
+++ b/net/bridge/br_if.c
@@ -411,9 +411,12 @@ err2:
411 br_fdb_delete_by_port(br, p, 1); 411 br_fdb_delete_by_port(br, p, 1);
412err1: 412err1:
413 kobject_del(&p->kobj); 413 kobject_del(&p->kobj);
414 return err; 414 goto put_back;
415err0: 415err0:
416 kobject_put(&p->kobj); 416 kobject_put(&p->kobj);
417
418put_back:
419 dev_put(dev);
417 return err; 420 return err;
418} 421}
419 422
diff --git a/net/bridge/br_stp_bpdu.c b/net/bridge/br_stp_bpdu.c
index 8deab645ef75..ddeb6e5d45d6 100644
--- a/net/bridge/br_stp_bpdu.c
+++ b/net/bridge/br_stp_bpdu.c
@@ -58,12 +58,12 @@ static inline void br_set_ticks(unsigned char *dest, int j)
58{ 58{
59 unsigned long ticks = (STP_HZ * j)/ HZ; 59 unsigned long ticks = (STP_HZ * j)/ HZ;
60 60
61 put_unaligned(htons(ticks), (__be16 *)dest); 61 put_unaligned_be16(ticks, dest);
62} 62}
63 63
64static inline int br_get_ticks(const unsigned char *src) 64static inline int br_get_ticks(const unsigned char *src)
65{ 65{
66 unsigned long ticks = ntohs(get_unaligned((__be16 *)src)); 66 unsigned long ticks = get_unaligned_be16(src);
67 67
68 return DIV_ROUND_UP(ticks * HZ, STP_HZ); 68 return DIV_ROUND_UP(ticks * HZ, STP_HZ);
69} 69}
diff --git a/net/can/bcm.c b/net/can/bcm.c
index 74fd2d33aff4..d9a3a9d13bed 100644
--- a/net/can/bcm.c
+++ b/net/can/bcm.c
@@ -412,12 +412,6 @@ static void bcm_rx_changed(struct bcm_op *op, struct can_frame *data)
412 bcm_send_to_user(op, &head, data, 1); 412 bcm_send_to_user(op, &head, data, 1);
413} 413}
414 414
415/* TODO: move to linux/hrtimer.h */
416static inline int hrtimer_callback_running(struct hrtimer *timer)
417{
418 return timer->state & HRTIMER_STATE_CALLBACK;
419}
420
421/* 415/*
422 * bcm_rx_update_and_send - process a detected relevant receive content change 416 * bcm_rx_update_and_send - process a detected relevant receive content change
423 * 1. update the last received data 417 * 1. update the last received data
diff --git a/net/compat.c b/net/compat.c
index 01bf95d0832e..c823f6f290cb 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -548,6 +548,9 @@ struct compat_group_filter {
548 __attribute__ ((aligned(4))); 548 __attribute__ ((aligned(4)));
549} __attribute__ ((packed)); 549} __attribute__ ((packed));
550 550
551#define __COMPAT_GF0_SIZE (sizeof(struct compat_group_filter) - \
552 sizeof(struct __kernel_sockaddr_storage))
553
551 554
552int compat_mc_setsockopt(struct sock *sock, int level, int optname, 555int compat_mc_setsockopt(struct sock *sock, int level, int optname,
553 char __user *optval, int optlen, 556 char __user *optval, int optlen,
@@ -582,7 +585,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
582 case MCAST_UNBLOCK_SOURCE: 585 case MCAST_UNBLOCK_SOURCE:
583 { 586 {
584 struct compat_group_source_req __user *gsr32 = (void *)optval; 587 struct compat_group_source_req __user *gsr32 = (void *)optval;
585 struct group_source_req *kgsr = compat_alloc_user_space( 588 struct group_source_req __user *kgsr = compat_alloc_user_space(
586 sizeof(struct group_source_req)); 589 sizeof(struct group_source_req));
587 u32 interface; 590 u32 interface;
588 591
@@ -603,10 +606,10 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
603 case MCAST_MSFILTER: 606 case MCAST_MSFILTER:
604 { 607 {
605 struct compat_group_filter __user *gf32 = (void *)optval; 608 struct compat_group_filter __user *gf32 = (void *)optval;
606 struct group_filter *kgf; 609 struct group_filter __user *kgf;
607 u32 interface, fmode, numsrc; 610 u32 interface, fmode, numsrc;
608 611
609 if (!access_ok(VERIFY_READ, gf32, sizeof(*gf32)) || 612 if (!access_ok(VERIFY_READ, gf32, __COMPAT_GF0_SIZE) ||
610 __get_user(interface, &gf32->gf_interface) || 613 __get_user(interface, &gf32->gf_interface) ||
611 __get_user(fmode, &gf32->gf_fmode) || 614 __get_user(fmode, &gf32->gf_fmode) ||
612 __get_user(numsrc, &gf32->gf_numsrc)) 615 __get_user(numsrc, &gf32->gf_numsrc))
@@ -622,7 +625,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
622 __put_user(numsrc, &kgf->gf_numsrc) || 625 __put_user(numsrc, &kgf->gf_numsrc) ||
623 copy_in_user(&kgf->gf_group, &gf32->gf_group, 626 copy_in_user(&kgf->gf_group, &gf32->gf_group,
624 sizeof(kgf->gf_group)) || 627 sizeof(kgf->gf_group)) ||
625 (numsrc && copy_in_user(&kgf->gf_slist, &gf32->gf_slist, 628 (numsrc && copy_in_user(kgf->gf_slist, gf32->gf_slist,
626 numsrc * sizeof(kgf->gf_slist[0])))) 629 numsrc * sizeof(kgf->gf_slist[0]))))
627 return -EFAULT; 630 return -EFAULT;
628 koptval = (char __user *)kgf; 631 koptval = (char __user *)kgf;
@@ -637,6 +640,85 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
637 640
638EXPORT_SYMBOL(compat_mc_setsockopt); 641EXPORT_SYMBOL(compat_mc_setsockopt);
639 642
643int compat_mc_getsockopt(struct sock *sock, int level, int optname,
644 char __user *optval, int __user *optlen,
645 int (*getsockopt)(struct sock *,int,int,char __user *,int __user *))
646{
647 struct compat_group_filter __user *gf32 = (void *)optval;
648 struct group_filter __user *kgf;
649 int __user *koptlen;
650 u32 interface, fmode, numsrc;
651 int klen, ulen, err;
652
653 if (optname != MCAST_MSFILTER)
654 return getsockopt(sock, level, optname, optval, optlen);
655
656 koptlen = compat_alloc_user_space(sizeof(*koptlen));
657 if (!access_ok(VERIFY_READ, optlen, sizeof(*optlen)) ||
658 __get_user(ulen, optlen))
659 return -EFAULT;
660
661 /* adjust len for pad */
662 klen = ulen + sizeof(*kgf) - sizeof(*gf32);
663
664 if (klen < GROUP_FILTER_SIZE(0))
665 return -EINVAL;
666
667 if (!access_ok(VERIFY_WRITE, koptlen, sizeof(*koptlen)) ||
668 __put_user(klen, koptlen))
669 return -EFAULT;
670
671 /* have to allow space for previous compat_alloc_user_space, too */
672 kgf = compat_alloc_user_space(klen+sizeof(*optlen));
673
674 if (!access_ok(VERIFY_READ, gf32, __COMPAT_GF0_SIZE) ||
675 __get_user(interface, &gf32->gf_interface) ||
676 __get_user(fmode, &gf32->gf_fmode) ||
677 __get_user(numsrc, &gf32->gf_numsrc) ||
678 __put_user(interface, &kgf->gf_interface) ||
679 __put_user(fmode, &kgf->gf_fmode) ||
680 __put_user(numsrc, &kgf->gf_numsrc) ||
681 copy_in_user(&kgf->gf_group,&gf32->gf_group,sizeof(kgf->gf_group)))
682 return -EFAULT;
683
684 err = getsockopt(sock, level, optname, (char __user *)kgf, koptlen);
685 if (err)
686 return err;
687
688 if (!access_ok(VERIFY_READ, koptlen, sizeof(*koptlen)) ||
689 __get_user(klen, koptlen))
690 return -EFAULT;
691
692 ulen = klen - (sizeof(*kgf)-sizeof(*gf32));
693
694 if (!access_ok(VERIFY_WRITE, optlen, sizeof(*optlen)) ||
695 __put_user(ulen, optlen))
696 return -EFAULT;
697
698 if (!access_ok(VERIFY_READ, kgf, klen) ||
699 !access_ok(VERIFY_WRITE, gf32, ulen) ||
700 __get_user(interface, &kgf->gf_interface) ||
701 __get_user(fmode, &kgf->gf_fmode) ||
702 __get_user(numsrc, &kgf->gf_numsrc) ||
703 __put_user(interface, &gf32->gf_interface) ||
704 __put_user(fmode, &gf32->gf_fmode) ||
705 __put_user(numsrc, &gf32->gf_numsrc))
706 return -EFAULT;
707 if (numsrc) {
708 int copylen;
709
710 klen -= GROUP_FILTER_SIZE(0);
711 copylen = numsrc * sizeof(gf32->gf_slist[0]);
712 if (copylen > klen)
713 copylen = klen;
714 if (copy_in_user(gf32->gf_slist, kgf->gf_slist, copylen))
715 return -EFAULT;
716 }
717 return err;
718}
719
720EXPORT_SYMBOL(compat_mc_getsockopt);
721
640 722
641/* Argument list sizes for compat_sys_socketcall */ 723/* Argument list sizes for compat_sys_socketcall */
642#define AL(x) ((x) * sizeof(u32)) 724#define AL(x) ((x) * sizeof(u32))
diff --git a/net/core/dev.c b/net/core/dev.c
index ed49da592051..d334446a8eaf 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -162,7 +162,7 @@ struct net_dma {
162 struct dma_client client; 162 struct dma_client client;
163 spinlock_t lock; 163 spinlock_t lock;
164 cpumask_t channel_mask; 164 cpumask_t channel_mask;
165 struct dma_chan *channels[NR_CPUS]; 165 struct dma_chan **channels;
166}; 166};
167 167
168static enum dma_state_client 168static enum dma_state_client
@@ -2444,7 +2444,7 @@ static struct netif_rx_stats *softnet_get_online(loff_t *pos)
2444{ 2444{
2445 struct netif_rx_stats *rc = NULL; 2445 struct netif_rx_stats *rc = NULL;
2446 2446
2447 while (*pos < NR_CPUS) 2447 while (*pos < nr_cpu_ids)
2448 if (cpu_online(*pos)) { 2448 if (cpu_online(*pos)) {
2449 rc = &per_cpu(netdev_rx_stat, *pos); 2449 rc = &per_cpu(netdev_rx_stat, *pos);
2450 break; 2450 break;
@@ -3776,6 +3776,7 @@ int register_netdevice(struct net_device *dev)
3776 } 3776 }
3777 } 3777 }
3778 3778
3779 netdev_initialize_kobject(dev);
3779 ret = netdev_register_kobject(dev); 3780 ret = netdev_register_kobject(dev);
3780 if (ret) 3781 if (ret)
3781 goto err_uninit; 3782 goto err_uninit;
@@ -4208,7 +4209,8 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char
4208 } 4209 }
4209 4210
4210 /* Fixup kobjects */ 4211 /* Fixup kobjects */
4211 err = device_rename(&dev->dev, dev->name); 4212 netdev_unregister_kobject(dev);
4213 err = netdev_register_kobject(dev);
4212 WARN_ON(err); 4214 WARN_ON(err);
4213 4215
4214 /* Add the device back in the hashes */ 4216 /* Add the device back in the hashes */
@@ -4324,7 +4326,7 @@ netdev_dma_event(struct dma_client *client, struct dma_chan *chan,
4324 spin_lock(&net_dma->lock); 4326 spin_lock(&net_dma->lock);
4325 switch (state) { 4327 switch (state) {
4326 case DMA_RESOURCE_AVAILABLE: 4328 case DMA_RESOURCE_AVAILABLE:
4327 for (i = 0; i < NR_CPUS; i++) 4329 for (i = 0; i < nr_cpu_ids; i++)
4328 if (net_dma->channels[i] == chan) { 4330 if (net_dma->channels[i] == chan) {
4329 found = 1; 4331 found = 1;
4330 break; 4332 break;
@@ -4339,7 +4341,7 @@ netdev_dma_event(struct dma_client *client, struct dma_chan *chan,
4339 } 4341 }
4340 break; 4342 break;
4341 case DMA_RESOURCE_REMOVED: 4343 case DMA_RESOURCE_REMOVED:
4342 for (i = 0; i < NR_CPUS; i++) 4344 for (i = 0; i < nr_cpu_ids; i++)
4343 if (net_dma->channels[i] == chan) { 4345 if (net_dma->channels[i] == chan) {
4344 found = 1; 4346 found = 1;
4345 pos = i; 4347 pos = i;
@@ -4366,6 +4368,13 @@ netdev_dma_event(struct dma_client *client, struct dma_chan *chan,
4366 */ 4368 */
4367static int __init netdev_dma_register(void) 4369static int __init netdev_dma_register(void)
4368{ 4370{
4371 net_dma.channels = kzalloc(nr_cpu_ids * sizeof(struct net_dma),
4372 GFP_KERNEL);
4373 if (unlikely(!net_dma.channels)) {
4374 printk(KERN_NOTICE
4375 "netdev_dma: no memory for net_dma.channels\n");
4376 return -ENOMEM;
4377 }
4369 spin_lock_init(&net_dma.lock); 4378 spin_lock_init(&net_dma.lock);
4370 dma_cap_set(DMA_MEMCPY, net_dma.client.cap_mask); 4379 dma_cap_set(DMA_MEMCPY, net_dma.client.cap_mask);
4371 dma_async_client_register(&net_dma.client); 4380 dma_async_client_register(&net_dma.client);
diff --git a/net/core/filter.c b/net/core/filter.c
index f5f3cf603064..4f8369729a4e 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -213,7 +213,7 @@ unsigned int sk_run_filter(struct sk_buff *skb, struct sock_filter *filter, int
213load_w: 213load_w:
214 ptr = load_pointer(skb, k, 4, &tmp); 214 ptr = load_pointer(skb, k, 4, &tmp);
215 if (ptr != NULL) { 215 if (ptr != NULL) {
216 A = ntohl(get_unaligned((__be32 *)ptr)); 216 A = get_unaligned_be32(ptr);
217 continue; 217 continue;
218 } 218 }
219 break; 219 break;
@@ -222,7 +222,7 @@ load_w:
222load_h: 222load_h:
223 ptr = load_pointer(skb, k, 2, &tmp); 223 ptr = load_pointer(skb, k, 2, &tmp);
224 if (ptr != NULL) { 224 if (ptr != NULL) {
225 A = ntohs(get_unaligned((__be16 *)ptr)); 225 A = get_unaligned_be16(ptr);
226 continue; 226 continue;
227 } 227 }
228 break; 228 break;
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 75075c303c44..5d9d7130bd6e 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -1430,11 +1430,10 @@ void neigh_table_init_no_netlink(struct neigh_table *tbl)
1430 panic("cannot create neighbour cache statistics"); 1430 panic("cannot create neighbour cache statistics");
1431 1431
1432#ifdef CONFIG_PROC_FS 1432#ifdef CONFIG_PROC_FS
1433 tbl->pde = proc_create(tbl->id, 0, init_net.proc_net_stat, 1433 tbl->pde = proc_create_data(tbl->id, 0, init_net.proc_net_stat,
1434 &neigh_stat_seq_fops); 1434 &neigh_stat_seq_fops, tbl);
1435 if (!tbl->pde) 1435 if (!tbl->pde)
1436 panic("cannot create neighbour proc dir entry"); 1436 panic("cannot create neighbour proc dir entry");
1437 tbl->pde->data = tbl;
1438#endif 1437#endif
1439 1438
1440 tbl->hash_mask = 1; 1439 tbl->hash_mask = 1;
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 4e7b847347f7..90e2177af081 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -449,7 +449,6 @@ int netdev_register_kobject(struct net_device *net)
449 struct device *dev = &(net->dev); 449 struct device *dev = &(net->dev);
450 struct attribute_group **groups = net->sysfs_groups; 450 struct attribute_group **groups = net->sysfs_groups;
451 451
452 device_initialize(dev);
453 dev->class = &net_class; 452 dev->class = &net_class;
454 dev->platform_data = net; 453 dev->platform_data = net;
455 dev->groups = groups; 454 dev->groups = groups;
@@ -470,6 +469,12 @@ int netdev_register_kobject(struct net_device *net)
470 return device_add(dev); 469 return device_add(dev);
471} 470}
472 471
472void netdev_initialize_kobject(struct net_device *net)
473{
474 struct device *device = &(net->dev);
475 device_initialize(device);
476}
477
473int netdev_kobject_init(void) 478int netdev_kobject_init(void)
474{ 479{
475 return class_register(&net_class); 480 return class_register(&net_class);
diff --git a/net/core/net-sysfs.h b/net/core/net-sysfs.h
index f5f108db3924..14e7524260b3 100644
--- a/net/core/net-sysfs.h
+++ b/net/core/net-sysfs.h
@@ -4,5 +4,5 @@
4int netdev_kobject_init(void); 4int netdev_kobject_init(void);
5int netdev_register_kobject(struct net_device *); 5int netdev_register_kobject(struct net_device *);
6void netdev_unregister_kobject(struct net_device *); 6void netdev_unregister_kobject(struct net_device *);
7 7void netdev_initialize_kobject(struct net_device *);
8#endif 8#endif
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index a803b442234c..8dca21110493 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -3570,15 +3570,14 @@ static int pktgen_add_device(struct pktgen_thread *t, const char *ifname)
3570 if (err) 3570 if (err)
3571 goto out1; 3571 goto out1;
3572 3572
3573 pkt_dev->entry = proc_create(ifname, 0600, 3573 pkt_dev->entry = proc_create_data(ifname, 0600, pg_proc_dir,
3574 pg_proc_dir, &pktgen_if_fops); 3574 &pktgen_if_fops, pkt_dev);
3575 if (!pkt_dev->entry) { 3575 if (!pkt_dev->entry) {
3576 printk(KERN_ERR "pktgen: cannot create %s/%s procfs entry.\n", 3576 printk(KERN_ERR "pktgen: cannot create %s/%s procfs entry.\n",
3577 PG_PROC_DIR, ifname); 3577 PG_PROC_DIR, ifname);
3578 err = -EINVAL; 3578 err = -EINVAL;
3579 goto out2; 3579 goto out2;
3580 } 3580 }
3581 pkt_dev->entry->data = pkt_dev;
3582#ifdef CONFIG_XFRM 3581#ifdef CONFIG_XFRM
3583 pkt_dev->ipsmode = XFRM_MODE_TRANSPORT; 3582 pkt_dev->ipsmode = XFRM_MODE_TRANSPORT;
3584 pkt_dev->ipsproto = IPPROTO_ESP; 3583 pkt_dev->ipsproto = IPPROTO_ESP;
@@ -3628,7 +3627,8 @@ static int __init pktgen_create_thread(int cpu)
3628 kthread_bind(p, cpu); 3627 kthread_bind(p, cpu);
3629 t->tsk = p; 3628 t->tsk = p;
3630 3629
3631 pe = proc_create(t->tsk->comm, 0600, pg_proc_dir, &pktgen_thread_fops); 3630 pe = proc_create_data(t->tsk->comm, 0600, pg_proc_dir,
3631 &pktgen_thread_fops, t);
3632 if (!pe) { 3632 if (!pe) {
3633 printk(KERN_ERR "pktgen: cannot create %s/%s procfs entry.\n", 3633 printk(KERN_ERR "pktgen: cannot create %s/%s procfs entry.\n",
3634 PG_PROC_DIR, t->tsk->comm); 3634 PG_PROC_DIR, t->tsk->comm);
@@ -3638,8 +3638,6 @@ static int __init pktgen_create_thread(int cpu)
3638 return -EINVAL; 3638 return -EINVAL;
3639 } 3639 }
3640 3640
3641 pe->data = t;
3642
3643 wake_up_process(p); 3641 wake_up_process(p);
3644 3642
3645 return 0; 3643 return 0;
@@ -3716,8 +3714,6 @@ static int __init pg_init(void)
3716 return -EINVAL; 3714 return -EINVAL;
3717 } 3715 }
3718 3716
3719 pe->data = NULL;
3720
3721 /* Register us to receive netdevice events */ 3717 /* Register us to receive netdevice events */
3722 register_netdevice_notifier(&pktgen_notifier_block); 3718 register_netdevice_notifier(&pktgen_notifier_block);
3723 3719
diff --git a/net/core/sock.c b/net/core/sock.c
index 5dbb81bc9673..fa76f04fa9c6 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -228,11 +228,12 @@ static int sock_set_timeout(long *timeo_p, char __user *optval, int optlen)
228 static int warned __read_mostly; 228 static int warned __read_mostly;
229 229
230 *timeo_p = 0; 230 *timeo_p = 0;
231 if (warned < 10 && net_ratelimit()) 231 if (warned < 10 && net_ratelimit()) {
232 warned++; 232 warned++;
233 printk(KERN_INFO "sock_set_timeout: `%s' (pid %d) " 233 printk(KERN_INFO "sock_set_timeout: `%s' (pid %d) "
234 "tries to set negative timeout\n", 234 "tries to set negative timeout\n",
235 current->comm, task_pid_nr(current)); 235 current->comm, task_pid_nr(current));
236 }
236 return 0; 237 return 0;
237 } 238 }
238 *timeo_p = MAX_SCHEDULE_TIMEOUT; 239 *timeo_p = MAX_SCHEDULE_TIMEOUT;
diff --git a/net/dccp/ccids/ccid2.c b/net/dccp/ccids/ccid2.c
index b5b52ebb2693..8e9580874216 100644
--- a/net/dccp/ccids/ccid2.c
+++ b/net/dccp/ccids/ccid2.c
@@ -716,7 +716,7 @@ static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk)
716 * packets for new connections, following the rules from [RFC3390]". 716 * packets for new connections, following the rules from [RFC3390]".
717 * We need to convert the bytes of RFC3390 into the packets of RFC 4341. 717 * We need to convert the bytes of RFC3390 into the packets of RFC 4341.
718 */ 718 */
719 hctx->ccid2hctx_cwnd = min(4U, max(2U, 4380U / dp->dccps_mss_cache)); 719 hctx->ccid2hctx_cwnd = clamp(4380U / dp->dccps_mss_cache, 2U, 4U);
720 720
721 /* Make sure that Ack Ratio is enabled and within bounds. */ 721 /* Make sure that Ack Ratio is enabled and within bounds. */
722 max_ratio = DIV_ROUND_UP(hctx->ccid2hctx_cwnd, 2); 722 max_ratio = DIV_ROUND_UP(hctx->ccid2hctx_cwnd, 2);
diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c
index e76f460af0ea..cd61dea2eea1 100644
--- a/net/dccp/ccids/ccid3.c
+++ b/net/dccp/ccids/ccid3.c
@@ -88,8 +88,8 @@ static void ccid3_hc_tx_set_state(struct sock *sk,
88static inline u64 rfc3390_initial_rate(struct sock *sk) 88static inline u64 rfc3390_initial_rate(struct sock *sk)
89{ 89{
90 const struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 90 const struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
91 const __u32 w_init = min_t(__u32, 4 * hctx->ccid3hctx_s, 91 const __u32 w_init = clamp_t(__u32, 4380U,
92 max_t(__u32, 2 * hctx->ccid3hctx_s, 4380)); 92 2 * hctx->ccid3hctx_s, 4 * hctx->ccid3hctx_s);
93 93
94 return scaled_div(w_init << 6, hctx->ccid3hctx_rtt); 94 return scaled_div(w_init << 6, hctx->ccid3hctx_rtt);
95} 95}
diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c
index 4637ded3dba8..05afb576d935 100644
--- a/net/ipv4/cipso_ipv4.c
+++ b/net/ipv4/cipso_ipv4.c
@@ -983,7 +983,7 @@ static int cipso_v4_map_cat_enum_valid(const struct cipso_v4_doi *doi_def,
983 return -EFAULT; 983 return -EFAULT;
984 984
985 for (iter = 0; iter < enumcat_len; iter += 2) { 985 for (iter = 0; iter < enumcat_len; iter += 2) {
986 cat = ntohs(get_unaligned((__be16 *)&enumcat[iter])); 986 cat = get_unaligned_be16(&enumcat[iter]);
987 if (cat <= cat_prev) 987 if (cat <= cat_prev)
988 return -EFAULT; 988 return -EFAULT;
989 cat_prev = cat; 989 cat_prev = cat;
@@ -1052,7 +1052,7 @@ static int cipso_v4_map_cat_enum_ntoh(const struct cipso_v4_doi *doi_def,
1052 1052
1053 for (iter = 0; iter < net_cat_len; iter += 2) { 1053 for (iter = 0; iter < net_cat_len; iter += 2) {
1054 ret_val = netlbl_secattr_catmap_setbit(secattr->attr.mls.cat, 1054 ret_val = netlbl_secattr_catmap_setbit(secattr->attr.mls.cat,
1055 ntohs(get_unaligned((__be16 *)&net_cat[iter])), 1055 get_unaligned_be16(&net_cat[iter]),
1056 GFP_ATOMIC); 1056 GFP_ATOMIC);
1057 if (ret_val != 0) 1057 if (ret_val != 0)
1058 return ret_val; 1058 return ret_val;
@@ -1086,10 +1086,9 @@ static int cipso_v4_map_cat_rng_valid(const struct cipso_v4_doi *doi_def,
1086 return -EFAULT; 1086 return -EFAULT;
1087 1087
1088 for (iter = 0; iter < rngcat_len; iter += 4) { 1088 for (iter = 0; iter < rngcat_len; iter += 4) {
1089 cat_high = ntohs(get_unaligned((__be16 *)&rngcat[iter])); 1089 cat_high = get_unaligned_be16(&rngcat[iter]);
1090 if ((iter + 4) <= rngcat_len) 1090 if ((iter + 4) <= rngcat_len)
1091 cat_low = ntohs( 1091 cat_low = get_unaligned_be16(&rngcat[iter + 2]);
1092 get_unaligned((__be16 *)&rngcat[iter + 2]));
1093 else 1092 else
1094 cat_low = 0; 1093 cat_low = 0;
1095 1094
@@ -1188,10 +1187,9 @@ static int cipso_v4_map_cat_rng_ntoh(const struct cipso_v4_doi *doi_def,
1188 u16 cat_high; 1187 u16 cat_high;
1189 1188
1190 for (net_iter = 0; net_iter < net_cat_len; net_iter += 4) { 1189 for (net_iter = 0; net_iter < net_cat_len; net_iter += 4) {
1191 cat_high = ntohs(get_unaligned((__be16 *)&net_cat[net_iter])); 1190 cat_high = get_unaligned_be16(&net_cat[net_iter]);
1192 if ((net_iter + 4) <= net_cat_len) 1191 if ((net_iter + 4) <= net_cat_len)
1193 cat_low = ntohs( 1192 cat_low = get_unaligned_be16(&net_cat[net_iter + 2]);
1194 get_unaligned((__be16 *)&net_cat[net_iter + 2]));
1195 else 1193 else
1196 cat_low = 0; 1194 cat_low = 0;
1197 1195
@@ -1562,7 +1560,7 @@ int cipso_v4_validate(unsigned char **option)
1562 } 1560 }
1563 1561
1564 rcu_read_lock(); 1562 rcu_read_lock();
1565 doi_def = cipso_v4_doi_search(ntohl(get_unaligned((__be32 *)&opt[2]))); 1563 doi_def = cipso_v4_doi_search(get_unaligned_be32(&opt[2]));
1566 if (doi_def == NULL) { 1564 if (doi_def == NULL) {
1567 err_offset = 2; 1565 err_offset = 2;
1568 goto validate_return_locked; 1566 goto validate_return_locked;
@@ -1843,7 +1841,7 @@ static int cipso_v4_getattr(const unsigned char *cipso,
1843 if (cipso_v4_cache_check(cipso, cipso[1], secattr) == 0) 1841 if (cipso_v4_cache_check(cipso, cipso[1], secattr) == 0)
1844 return 0; 1842 return 0;
1845 1843
1846 doi = ntohl(get_unaligned((__be32 *)&cipso[2])); 1844 doi = get_unaligned_be32(&cipso[2]);
1847 rcu_read_lock(); 1845 rcu_read_lock();
1848 doi_def = cipso_v4_doi_search(doi); 1846 doi_def = cipso_v4_doi_search(doi);
1849 if (doi_def == NULL) 1847 if (doi_def == NULL)
diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
index c67d00e8c600..87397351ddac 100644
--- a/net/ipv4/icmp.c
+++ b/net/ipv4/icmp.c
@@ -691,7 +691,8 @@ static void icmp_unreach(struct sk_buff *skb)
691 NIPQUAD(iph->daddr)); 691 NIPQUAD(iph->daddr));
692 } else { 692 } else {
693 info = ip_rt_frag_needed(net, iph, 693 info = ip_rt_frag_needed(net, iph,
694 ntohs(icmph->un.frag.mtu)); 694 ntohs(icmph->un.frag.mtu),
695 skb->dev);
695 if (!info) 696 if (!info)
696 goto out; 697 goto out;
697 } 698 }
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 08349267ceb4..e527628f56cf 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -753,23 +753,15 @@ static inline int ip_ufo_append_data(struct sock *sk,
753 skb->ip_summed = CHECKSUM_PARTIAL; 753 skb->ip_summed = CHECKSUM_PARTIAL;
754 skb->csum = 0; 754 skb->csum = 0;
755 sk->sk_sndmsg_off = 0; 755 sk->sk_sndmsg_off = 0;
756 }
757 756
758 err = skb_append_datato_frags(sk,skb, getfrag, from, 757 /* specify the length of each IP datagram fragment */
759 (length - transhdrlen));
760 if (!err) {
761 /* specify the length of each IP datagram fragment*/
762 skb_shinfo(skb)->gso_size = mtu - fragheaderlen; 758 skb_shinfo(skb)->gso_size = mtu - fragheaderlen;
763 skb_shinfo(skb)->gso_type = SKB_GSO_UDP; 759 skb_shinfo(skb)->gso_type = SKB_GSO_UDP;
764 __skb_queue_tail(&sk->sk_write_queue, skb); 760 __skb_queue_tail(&sk->sk_write_queue, skb);
765
766 return 0;
767 } 761 }
768 /* There is not enough support do UFO , 762
769 * so follow normal path 763 return skb_append_datato_frags(sk, skb, getfrag, from,
770 */ 764 (length - transhdrlen));
771 kfree_skb(skb);
772 return err;
773} 765}
774 766
775/* 767/*
@@ -863,9 +855,9 @@ int ip_append_data(struct sock *sk,
863 csummode = CHECKSUM_PARTIAL; 855 csummode = CHECKSUM_PARTIAL;
864 856
865 inet->cork.length += length; 857 inet->cork.length += length;
866 if (((length > mtu) && (sk->sk_protocol == IPPROTO_UDP)) && 858 if (((length> mtu) || !skb_queue_empty(&sk->sk_write_queue)) &&
867 (rt->u.dst.dev->features & NETIF_F_UFO)) { 859 (sk->sk_protocol == IPPROTO_UDP) &&
868 860 (rt->u.dst.dev->features & NETIF_F_UFO)) {
869 err = ip_ufo_append_data(sk, getfrag, from, length, hh_len, 861 err = ip_ufo_append_data(sk, getfrag, from, length, hh_len,
870 fragheaderlen, transhdrlen, mtu, 862 fragheaderlen, transhdrlen, mtu,
871 flags); 863 flags);
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index 4d8d95404f45..e0514e82308e 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -1186,7 +1186,14 @@ int ip_getsockopt(struct sock *sk, int level,
1186int compat_ip_getsockopt(struct sock *sk, int level, int optname, 1186int compat_ip_getsockopt(struct sock *sk, int level, int optname,
1187 char __user *optval, int __user *optlen) 1187 char __user *optval, int __user *optlen)
1188{ 1188{
1189 int err = do_ip_getsockopt(sk, level, optname, optval, optlen); 1189 int err;
1190
1191 if (optname == MCAST_MSFILTER)
1192 return compat_mc_getsockopt(sk, level, optname, optval, optlen,
1193 ip_getsockopt);
1194
1195 err = do_ip_getsockopt(sk, level, optname, optval, optlen);
1196
1190#ifdef CONFIG_NETFILTER 1197#ifdef CONFIG_NETFILTER
1191 /* we need to exclude all possible ENOPROTOOPTs except default case */ 1198 /* we need to exclude all possible ENOPROTOOPTs except default case */
1192 if (err == -ENOPROTOOPT && optname != IP_PKTOPTIONS && 1199 if (err == -ENOPROTOOPT && optname != IP_PKTOPTIONS &&
diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
index 0f42d1c1f690..89dee4346f60 100644
--- a/net/ipv4/ipconfig.c
+++ b/net/ipv4/ipconfig.c
@@ -412,12 +412,12 @@ static struct packet_type rarp_packet_type __initdata = {
412 .func = ic_rarp_recv, 412 .func = ic_rarp_recv,
413}; 413};
414 414
415static inline void ic_rarp_init(void) 415static inline void __init ic_rarp_init(void)
416{ 416{
417 dev_add_pack(&rarp_packet_type); 417 dev_add_pack(&rarp_packet_type);
418} 418}
419 419
420static inline void ic_rarp_cleanup(void) 420static inline void __init ic_rarp_cleanup(void)
421{ 421{
422 dev_remove_pack(&rarp_packet_type); 422 dev_remove_pack(&rarp_packet_type);
423} 423}
@@ -682,7 +682,7 @@ static void __init ic_bootp_init_ext(u8 *e)
682/* 682/*
683 * Initialize the DHCP/BOOTP mechanism. 683 * Initialize the DHCP/BOOTP mechanism.
684 */ 684 */
685static inline void ic_bootp_init(void) 685static inline void __init ic_bootp_init(void)
686{ 686{
687 int i; 687 int i;
688 688
@@ -696,7 +696,7 @@ static inline void ic_bootp_init(void)
696/* 696/*
697 * DHCP/BOOTP cleanup. 697 * DHCP/BOOTP cleanup.
698 */ 698 */
699static inline void ic_bootp_cleanup(void) 699static inline void __init ic_bootp_cleanup(void)
700{ 700{
701 dev_remove_pack(&bootp_packet_type); 701 dev_remove_pack(&bootp_packet_type);
702} 702}
diff --git a/net/ipv4/ipvs/ip_vs_proto.c b/net/ipv4/ipvs/ip_vs_proto.c
index dde28a250d92..4b1c16cbb16b 100644
--- a/net/ipv4/ipvs/ip_vs_proto.c
+++ b/net/ipv4/ipvs/ip_vs_proto.c
@@ -148,7 +148,7 @@ const char * ip_vs_state_name(__u16 proto, int state)
148 struct ip_vs_protocol *pp = ip_vs_proto_get(proto); 148 struct ip_vs_protocol *pp = ip_vs_proto_get(proto);
149 149
150 if (pp == NULL || pp->state_name == NULL) 150 if (pp == NULL || pp->state_name == NULL)
151 return "ERR!"; 151 return (IPPROTO_IP == proto) ? "NONE" : "ERR!";
152 return pp->state_name(state); 152 return pp->state_name(state);
153} 153}
154 154
diff --git a/net/ipv4/ipvs/ip_vs_proto_ah.c b/net/ipv4/ipvs/ip_vs_proto_ah.c
index a842676e1c69..4bf835e1d86d 100644
--- a/net/ipv4/ipvs/ip_vs_proto_ah.c
+++ b/net/ipv4/ipvs/ip_vs_proto_ah.c
@@ -160,6 +160,7 @@ static void ah_exit(struct ip_vs_protocol *pp)
160struct ip_vs_protocol ip_vs_protocol_ah = { 160struct ip_vs_protocol ip_vs_protocol_ah = {
161 .name = "AH", 161 .name = "AH",
162 .protocol = IPPROTO_AH, 162 .protocol = IPPROTO_AH,
163 .num_states = 1,
163 .dont_defrag = 1, 164 .dont_defrag = 1,
164 .init = ah_init, 165 .init = ah_init,
165 .exit = ah_exit, 166 .exit = ah_exit,
diff --git a/net/ipv4/ipvs/ip_vs_proto_esp.c b/net/ipv4/ipvs/ip_vs_proto_esp.c
index aef0d3ee8e44..db6a6b7b1a0b 100644
--- a/net/ipv4/ipvs/ip_vs_proto_esp.c
+++ b/net/ipv4/ipvs/ip_vs_proto_esp.c
@@ -159,6 +159,7 @@ static void esp_exit(struct ip_vs_protocol *pp)
159struct ip_vs_protocol ip_vs_protocol_esp = { 159struct ip_vs_protocol ip_vs_protocol_esp = {
160 .name = "ESP", 160 .name = "ESP",
161 .protocol = IPPROTO_ESP, 161 .protocol = IPPROTO_ESP,
162 .num_states = 1,
162 .dont_defrag = 1, 163 .dont_defrag = 1,
163 .init = esp_init, 164 .init = esp_init,
164 .exit = esp_exit, 165 .exit = esp_exit,
diff --git a/net/ipv4/ipvs/ip_vs_proto_tcp.c b/net/ipv4/ipvs/ip_vs_proto_tcp.c
index 620e40ff79a9..b83dc14b0a4d 100644
--- a/net/ipv4/ipvs/ip_vs_proto_tcp.c
+++ b/net/ipv4/ipvs/ip_vs_proto_tcp.c
@@ -594,6 +594,7 @@ static void ip_vs_tcp_exit(struct ip_vs_protocol *pp)
594struct ip_vs_protocol ip_vs_protocol_tcp = { 594struct ip_vs_protocol ip_vs_protocol_tcp = {
595 .name = "TCP", 595 .name = "TCP",
596 .protocol = IPPROTO_TCP, 596 .protocol = IPPROTO_TCP,
597 .num_states = IP_VS_TCP_S_LAST,
597 .dont_defrag = 0, 598 .dont_defrag = 0,
598 .appcnt = ATOMIC_INIT(0), 599 .appcnt = ATOMIC_INIT(0),
599 .init = ip_vs_tcp_init, 600 .init = ip_vs_tcp_init,
diff --git a/net/ipv4/ipvs/ip_vs_proto_udp.c b/net/ipv4/ipvs/ip_vs_proto_udp.c
index 1caa2908373f..75771cb3cd6f 100644
--- a/net/ipv4/ipvs/ip_vs_proto_udp.c
+++ b/net/ipv4/ipvs/ip_vs_proto_udp.c
@@ -409,6 +409,7 @@ static void udp_exit(struct ip_vs_protocol *pp)
409struct ip_vs_protocol ip_vs_protocol_udp = { 409struct ip_vs_protocol ip_vs_protocol_udp = {
410 .name = "UDP", 410 .name = "UDP",
411 .protocol = IPPROTO_UDP, 411 .protocol = IPPROTO_UDP,
412 .num_states = IP_VS_UDP_S_LAST,
412 .dont_defrag = 0, 413 .dont_defrag = 0,
413 .init = udp_init, 414 .init = udp_init,
414 .exit = udp_exit, 415 .exit = udp_exit,
diff --git a/net/ipv4/ipvs/ip_vs_sync.c b/net/ipv4/ipvs/ip_vs_sync.c
index 69c56663cc9a..eff54efe0351 100644
--- a/net/ipv4/ipvs/ip_vs_sync.c
+++ b/net/ipv4/ipvs/ip_vs_sync.c
@@ -288,11 +288,16 @@ static void ip_vs_process_message(const char *buffer, const size_t buflen)
288 char *p; 288 char *p;
289 int i; 289 int i;
290 290
291 if (buflen < sizeof(struct ip_vs_sync_mesg)) {
292 IP_VS_ERR_RL("sync message header too short\n");
293 return;
294 }
295
291 /* Convert size back to host byte order */ 296 /* Convert size back to host byte order */
292 m->size = ntohs(m->size); 297 m->size = ntohs(m->size);
293 298
294 if (buflen != m->size) { 299 if (buflen != m->size) {
295 IP_VS_ERR("bogus message\n"); 300 IP_VS_ERR_RL("bogus sync message size\n");
296 return; 301 return;
297 } 302 }
298 303
@@ -307,9 +312,48 @@ static void ip_vs_process_message(const char *buffer, const size_t buflen)
307 for (i=0; i<m->nr_conns; i++) { 312 for (i=0; i<m->nr_conns; i++) {
308 unsigned flags, state; 313 unsigned flags, state;
309 314
310 s = (struct ip_vs_sync_conn *)p; 315 if (p + SIMPLE_CONN_SIZE > buffer+buflen) {
316 IP_VS_ERR_RL("bogus conn in sync message\n");
317 return;
318 }
319 s = (struct ip_vs_sync_conn *) p;
311 flags = ntohs(s->flags) | IP_VS_CONN_F_SYNC; 320 flags = ntohs(s->flags) | IP_VS_CONN_F_SYNC;
321 flags &= ~IP_VS_CONN_F_HASHED;
322 if (flags & IP_VS_CONN_F_SEQ_MASK) {
323 opt = (struct ip_vs_sync_conn_options *)&s[1];
324 p += FULL_CONN_SIZE;
325 if (p > buffer+buflen) {
326 IP_VS_ERR_RL("bogus conn options in sync message\n");
327 return;
328 }
329 } else {
330 opt = NULL;
331 p += SIMPLE_CONN_SIZE;
332 }
333
312 state = ntohs(s->state); 334 state = ntohs(s->state);
335 if (!(flags & IP_VS_CONN_F_TEMPLATE)) {
336 pp = ip_vs_proto_get(s->protocol);
337 if (!pp) {
338 IP_VS_ERR_RL("Unsupported protocol %u in sync msg\n",
339 s->protocol);
340 continue;
341 }
342 if (state >= pp->num_states) {
343 IP_VS_DBG(2, "Invalid %s state %u in sync msg\n",
344 pp->name, state);
345 continue;
346 }
347 } else {
348 /* protocol in templates is not used for state/timeout */
349 pp = NULL;
350 if (state > 0) {
351 IP_VS_DBG(2, "Invalid template state %u in sync msg\n",
352 state);
353 state = 0;
354 }
355 }
356
313 if (!(flags & IP_VS_CONN_F_TEMPLATE)) 357 if (!(flags & IP_VS_CONN_F_TEMPLATE))
314 cp = ip_vs_conn_in_get(s->protocol, 358 cp = ip_vs_conn_in_get(s->protocol,
315 s->caddr, s->cport, 359 s->caddr, s->cport,
@@ -345,14 +389,9 @@ static void ip_vs_process_message(const char *buffer, const size_t buflen)
345 IP_VS_ERR("ip_vs_conn_new failed\n"); 389 IP_VS_ERR("ip_vs_conn_new failed\n");
346 return; 390 return;
347 } 391 }
348 cp->state = state;
349 } else if (!cp->dest) { 392 } else if (!cp->dest) {
350 dest = ip_vs_try_bind_dest(cp); 393 dest = ip_vs_try_bind_dest(cp);
351 if (!dest) { 394 if (dest)
352 /* it is an unbound entry created by
353 * synchronization */
354 cp->flags = flags | IP_VS_CONN_F_HASHED;
355 } else
356 atomic_dec(&dest->refcnt); 395 atomic_dec(&dest->refcnt);
357 } else if ((cp->dest) && (cp->protocol == IPPROTO_TCP) && 396 } else if ((cp->dest) && (cp->protocol == IPPROTO_TCP) &&
358 (cp->state != state)) { 397 (cp->state != state)) {
@@ -371,23 +410,22 @@ static void ip_vs_process_message(const char *buffer, const size_t buflen)
371 } 410 }
372 } 411 }
373 412
374 if (flags & IP_VS_CONN_F_SEQ_MASK) { 413 if (opt)
375 opt = (struct ip_vs_sync_conn_options *)&s[1];
376 memcpy(&cp->in_seq, opt, sizeof(*opt)); 414 memcpy(&cp->in_seq, opt, sizeof(*opt));
377 p += FULL_CONN_SIZE;
378 } else
379 p += SIMPLE_CONN_SIZE;
380
381 atomic_set(&cp->in_pkts, sysctl_ip_vs_sync_threshold[0]); 415 atomic_set(&cp->in_pkts, sysctl_ip_vs_sync_threshold[0]);
382 cp->state = state; 416 cp->state = state;
383 pp = ip_vs_proto_get(s->protocol); 417 cp->old_state = cp->state;
384 cp->timeout = pp->timeout_table[cp->state]; 418 /*
419 * We can not recover the right timeout for templates
420 * in all cases, we can not find the right fwmark
421 * virtual service. If needed, we can do it for
422 * non-fwmark persistent services.
423 */
424 if (!(flags & IP_VS_CONN_F_TEMPLATE) && pp->timeout_table)
425 cp->timeout = pp->timeout_table[state];
426 else
427 cp->timeout = (3*60*HZ);
385 ip_vs_conn_put(cp); 428 ip_vs_conn_put(cp);
386
387 if (p > buffer+buflen) {
388 IP_VS_ERR("bogus message\n");
389 return;
390 }
391 } 429 }
392} 430}
393 431
diff --git a/net/ipv4/netfilter/ip_queue.c b/net/ipv4/netfilter/ip_queue.c
index 719be29f7506..26a37cedcf2e 100644
--- a/net/ipv4/netfilter/ip_queue.c
+++ b/net/ipv4/netfilter/ip_queue.c
@@ -296,9 +296,8 @@ ipq_mangle_ipv4(ipq_verdict_msg_t *v, struct nf_queue_entry *e)
296 if (v->data_len > 0xFFFF) 296 if (v->data_len > 0xFFFF)
297 return -EINVAL; 297 return -EINVAL;
298 if (diff > skb_tailroom(e->skb)) { 298 if (diff > skb_tailroom(e->skb)) {
299 nskb = skb_copy_expand(e->skb, 0, 299 nskb = skb_copy_expand(e->skb, skb_headroom(e->skb),
300 diff - skb_tailroom(e->skb), 300 diff, GFP_ATOMIC);
301 GFP_ATOMIC);
302 if (!nskb) { 301 if (!nskb) {
303 printk(KERN_WARNING "ip_queue: error " 302 printk(KERN_WARNING "ip_queue: error "
304 "in mangle, dropping packet\n"); 303 "in mangle, dropping packet\n");
diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
index 22d8e7cd9197..1819ad7ab910 100644
--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
@@ -169,14 +169,14 @@ clusterip_config_init(const struct ipt_clusterip_tgt_info *i, __be32 ip,
169 169
170 /* create proc dir entry */ 170 /* create proc dir entry */
171 sprintf(buffer, "%u.%u.%u.%u", NIPQUAD(ip)); 171 sprintf(buffer, "%u.%u.%u.%u", NIPQUAD(ip));
172 c->pde = proc_create(buffer, S_IWUSR|S_IRUSR, 172 c->pde = proc_create_data(buffer, S_IWUSR|S_IRUSR,
173 clusterip_procdir, &clusterip_proc_fops); 173 clusterip_procdir,
174 &clusterip_proc_fops, c);
174 if (!c->pde) { 175 if (!c->pde) {
175 kfree(c); 176 kfree(c);
176 return NULL; 177 return NULL;
177 } 178 }
178 } 179 }
179 c->pde->data = c;
180#endif 180#endif
181 181
182 write_lock_bh(&clusterip_lock); 182 write_lock_bh(&clusterip_lock);
diff --git a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
index cacb9cb27dab..5a955c440364 100644
--- a/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
+++ b/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
@@ -303,7 +303,7 @@ getorigdst(struct sock *sk, int optval, void __user *user, int *len)
303 const struct nf_conntrack_tuple_hash *h; 303 const struct nf_conntrack_tuple_hash *h;
304 struct nf_conntrack_tuple tuple; 304 struct nf_conntrack_tuple tuple;
305 305
306 NF_CT_TUPLE_U_BLANK(&tuple); 306 memset(&tuple, 0, sizeof(tuple));
307 tuple.src.u3.ip = inet->rcv_saddr; 307 tuple.src.u3.ip = inet->rcv_saddr;
308 tuple.src.u.tcp.port = inet->sport; 308 tuple.src.u.tcp.port = inet->sport;
309 tuple.dst.u3.ip = inet->daddr; 309 tuple.dst.u3.ip = inet->daddr;
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index ce25a13f3430..5e3685c5c407 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1430,11 +1430,13 @@ static inline unsigned short guess_mtu(unsigned short old_mtu)
1430} 1430}
1431 1431
1432unsigned short ip_rt_frag_needed(struct net *net, struct iphdr *iph, 1432unsigned short ip_rt_frag_needed(struct net *net, struct iphdr *iph,
1433 unsigned short new_mtu) 1433 unsigned short new_mtu,
1434 struct net_device *dev)
1434{ 1435{
1435 int i; 1436 int i, k;
1436 unsigned short old_mtu = ntohs(iph->tot_len); 1437 unsigned short old_mtu = ntohs(iph->tot_len);
1437 struct rtable *rth; 1438 struct rtable *rth;
1439 int ikeys[2] = { dev->ifindex, 0 };
1438 __be32 skeys[2] = { iph->saddr, 0, }; 1440 __be32 skeys[2] = { iph->saddr, 0, };
1439 __be32 daddr = iph->daddr; 1441 __be32 daddr = iph->daddr;
1440 unsigned short est_mtu = 0; 1442 unsigned short est_mtu = 0;
@@ -1442,22 +1444,26 @@ unsigned short ip_rt_frag_needed(struct net *net, struct iphdr *iph,
1442 if (ipv4_config.no_pmtu_disc) 1444 if (ipv4_config.no_pmtu_disc)
1443 return 0; 1445 return 0;
1444 1446
1445 for (i = 0; i < 2; i++) { 1447 for (k = 0; k < 2; k++) {
1446 unsigned hash = rt_hash(daddr, skeys[i], 0); 1448 for (i = 0; i < 2; i++) {
1449 unsigned hash = rt_hash(daddr, skeys[i], ikeys[k]);
1447 1450
1448 rcu_read_lock(); 1451 rcu_read_lock();
1449 for (rth = rcu_dereference(rt_hash_table[hash].chain); rth; 1452 for (rth = rcu_dereference(rt_hash_table[hash].chain); rth;
1450 rth = rcu_dereference(rth->u.dst.rt_next)) { 1453 rth = rcu_dereference(rth->u.dst.rt_next)) {
1451 if (rth->fl.fl4_dst == daddr &&
1452 rth->fl.fl4_src == skeys[i] &&
1453 rth->rt_dst == daddr &&
1454 rth->rt_src == iph->saddr &&
1455 rth->fl.iif == 0 &&
1456 !(dst_metric_locked(&rth->u.dst, RTAX_MTU)) &&
1457 net_eq(dev_net(rth->u.dst.dev), net) &&
1458 rth->rt_genid == atomic_read(&rt_genid)) {
1459 unsigned short mtu = new_mtu; 1454 unsigned short mtu = new_mtu;
1460 1455
1456 if (rth->fl.fl4_dst != daddr ||
1457 rth->fl.fl4_src != skeys[i] ||
1458 rth->rt_dst != daddr ||
1459 rth->rt_src != iph->saddr ||
1460 rth->fl.oif != ikeys[k] ||
1461 rth->fl.iif != 0 ||
1462 dst_metric_locked(&rth->u.dst, RTAX_MTU) ||
1463 !net_eq(dev_net(rth->u.dst.dev), net) ||
1464 rth->rt_genid != atomic_read(&rt_genid))
1465 continue;
1466
1461 if (new_mtu < 68 || new_mtu >= old_mtu) { 1467 if (new_mtu < 68 || new_mtu >= old_mtu) {
1462 1468
1463 /* BSD 4.2 compatibility hack :-( */ 1469 /* BSD 4.2 compatibility hack :-( */
@@ -1483,8 +1489,8 @@ unsigned short ip_rt_frag_needed(struct net *net, struct iphdr *iph,
1483 est_mtu = mtu; 1489 est_mtu = mtu;
1484 } 1490 }
1485 } 1491 }
1492 rcu_read_unlock();
1486 } 1493 }
1487 rcu_read_unlock();
1488 } 1494 }
1489 return est_mtu ? : new_mtu; 1495 return est_mtu ? : new_mtu;
1490} 1496}
diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c
index 3a6be23d222f..6a250828b767 100644
--- a/net/ipv4/tcp_cong.c
+++ b/net/ipv4/tcp_cong.c
@@ -285,14 +285,12 @@ int tcp_is_cwnd_limited(const struct sock *sk, u32 in_flight)
285 if (in_flight >= tp->snd_cwnd) 285 if (in_flight >= tp->snd_cwnd)
286 return 1; 286 return 1;
287 287
288 if (!sk_can_gso(sk))
289 return 0;
290
291 left = tp->snd_cwnd - in_flight; 288 left = tp->snd_cwnd - in_flight;
292 if (sysctl_tcp_tso_win_divisor) 289 if (sk_can_gso(sk) &&
293 return left * sysctl_tcp_tso_win_divisor < tp->snd_cwnd; 290 left * sysctl_tcp_tso_win_divisor < tp->snd_cwnd &&
294 else 291 left * tp->mss_cache < sk->sk_gso_max_size)
295 return left <= tcp_max_burst(tp); 292 return 1;
293 return left <= tcp_max_burst(tp);
296} 294}
297EXPORT_SYMBOL_GPL(tcp_is_cwnd_limited); 295EXPORT_SYMBOL_GPL(tcp_is_cwnd_limited);
298 296
diff --git a/net/ipv4/tcp_cubic.c b/net/ipv4/tcp_cubic.c
index eb5b9854c8c7..4a1221e5e8ee 100644
--- a/net/ipv4/tcp_cubic.c
+++ b/net/ipv4/tcp_cubic.c
@@ -15,8 +15,8 @@
15 15
16#include <linux/mm.h> 16#include <linux/mm.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/math64.h>
18#include <net/tcp.h> 19#include <net/tcp.h>
19#include <asm/div64.h>
20 20
21#define BICTCP_BETA_SCALE 1024 /* Scale factor beta calculation 21#define BICTCP_BETA_SCALE 1024 /* Scale factor beta calculation
22 * max_cwnd = snd_cwnd * beta 22 * max_cwnd = snd_cwnd * beta
@@ -128,7 +128,7 @@ static u32 cubic_root(u64 a)
128 * x = ( 2 * x + a / x ) / 3 128 * x = ( 2 * x + a / x ) / 3
129 * k+1 k k 129 * k+1 k k
130 */ 130 */
131 x = (2 * x + (u32)div64_64(a, (u64)x * (u64)(x - 1))); 131 x = (2 * x + (u32)div64_u64(a, (u64)x * (u64)(x - 1)));
132 x = ((x * 341) >> 10); 132 x = ((x * 341) >> 10);
133 return x; 133 return x;
134} 134}
diff --git a/net/ipv4/tcp_hybla.c b/net/ipv4/tcp_hybla.c
index 44618b675916..bfcbd148a89d 100644
--- a/net/ipv4/tcp_hybla.c
+++ b/net/ipv4/tcp_hybla.c
@@ -101,8 +101,10 @@ static void hybla_cong_avoid(struct sock *sk, u32 ack, u32 in_flight)
101 if (!tcp_is_cwnd_limited(sk, in_flight)) 101 if (!tcp_is_cwnd_limited(sk, in_flight))
102 return; 102 return;
103 103
104 if (!ca->hybla_en) 104 if (!ca->hybla_en) {
105 return tcp_reno_cong_avoid(sk, ack, in_flight); 105 tcp_reno_cong_avoid(sk, ack, in_flight);
106 return;
107 }
106 108
107 if (ca->rho == 0) 109 if (ca->rho == 0)
108 hybla_recalc_param(sk); 110 hybla_recalc_param(sk);
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 0298f80681f2..eda4f4a233f3 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -1172,8 +1172,8 @@ static int tcp_check_dsack(struct tcp_sock *tp, struct sk_buff *ack_skb,
1172 struct tcp_sack_block_wire *sp, int num_sacks, 1172 struct tcp_sack_block_wire *sp, int num_sacks,
1173 u32 prior_snd_una) 1173 u32 prior_snd_una)
1174{ 1174{
1175 u32 start_seq_0 = ntohl(get_unaligned(&sp[0].start_seq)); 1175 u32 start_seq_0 = get_unaligned_be32(&sp[0].start_seq);
1176 u32 end_seq_0 = ntohl(get_unaligned(&sp[0].end_seq)); 1176 u32 end_seq_0 = get_unaligned_be32(&sp[0].end_seq);
1177 int dup_sack = 0; 1177 int dup_sack = 0;
1178 1178
1179 if (before(start_seq_0, TCP_SKB_CB(ack_skb)->ack_seq)) { 1179 if (before(start_seq_0, TCP_SKB_CB(ack_skb)->ack_seq)) {
@@ -1181,8 +1181,8 @@ static int tcp_check_dsack(struct tcp_sock *tp, struct sk_buff *ack_skb,
1181 tcp_dsack_seen(tp); 1181 tcp_dsack_seen(tp);
1182 NET_INC_STATS_BH(LINUX_MIB_TCPDSACKRECV); 1182 NET_INC_STATS_BH(LINUX_MIB_TCPDSACKRECV);
1183 } else if (num_sacks > 1) { 1183 } else if (num_sacks > 1) {
1184 u32 end_seq_1 = ntohl(get_unaligned(&sp[1].end_seq)); 1184 u32 end_seq_1 = get_unaligned_be32(&sp[1].end_seq);
1185 u32 start_seq_1 = ntohl(get_unaligned(&sp[1].start_seq)); 1185 u32 start_seq_1 = get_unaligned_be32(&sp[1].start_seq);
1186 1186
1187 if (!after(end_seq_0, end_seq_1) && 1187 if (!after(end_seq_0, end_seq_1) &&
1188 !before(start_seq_0, start_seq_1)) { 1188 !before(start_seq_0, start_seq_1)) {
@@ -1453,8 +1453,8 @@ tcp_sacktag_write_queue(struct sock *sk, struct sk_buff *ack_skb,
1453 for (i = 0; i < num_sacks; i++) { 1453 for (i = 0; i < num_sacks; i++) {
1454 int dup_sack = !i && found_dup_sack; 1454 int dup_sack = !i && found_dup_sack;
1455 1455
1456 sp[used_sacks].start_seq = ntohl(get_unaligned(&sp_wire[i].start_seq)); 1456 sp[used_sacks].start_seq = get_unaligned_be32(&sp_wire[i].start_seq);
1457 sp[used_sacks].end_seq = ntohl(get_unaligned(&sp_wire[i].end_seq)); 1457 sp[used_sacks].end_seq = get_unaligned_be32(&sp_wire[i].end_seq);
1458 1458
1459 if (!tcp_is_sackblock_valid(tp, dup_sack, 1459 if (!tcp_is_sackblock_valid(tp, dup_sack,
1460 sp[used_sacks].start_seq, 1460 sp[used_sacks].start_seq,
@@ -3340,7 +3340,7 @@ void tcp_parse_options(struct sk_buff *skb, struct tcp_options_received *opt_rx,
3340 switch (opcode) { 3340 switch (opcode) {
3341 case TCPOPT_MSS: 3341 case TCPOPT_MSS:
3342 if (opsize == TCPOLEN_MSS && th->syn && !estab) { 3342 if (opsize == TCPOLEN_MSS && th->syn && !estab) {
3343 u16 in_mss = ntohs(get_unaligned((__be16 *)ptr)); 3343 u16 in_mss = get_unaligned_be16(ptr);
3344 if (in_mss) { 3344 if (in_mss) {
3345 if (opt_rx->user_mss && 3345 if (opt_rx->user_mss &&
3346 opt_rx->user_mss < in_mss) 3346 opt_rx->user_mss < in_mss)
@@ -3369,8 +3369,8 @@ void tcp_parse_options(struct sk_buff *skb, struct tcp_options_received *opt_rx,
3369 ((estab && opt_rx->tstamp_ok) || 3369 ((estab && opt_rx->tstamp_ok) ||
3370 (!estab && sysctl_tcp_timestamps))) { 3370 (!estab && sysctl_tcp_timestamps))) {
3371 opt_rx->saw_tstamp = 1; 3371 opt_rx->saw_tstamp = 1;
3372 opt_rx->rcv_tsval = ntohl(get_unaligned((__be32 *)ptr)); 3372 opt_rx->rcv_tsval = get_unaligned_be32(ptr);
3373 opt_rx->rcv_tsecr = ntohl(get_unaligned((__be32 *)(ptr+4))); 3373 opt_rx->rcv_tsecr = get_unaligned_be32(ptr + 4);
3374 } 3374 }
3375 break; 3375 break;
3376 case TCPOPT_SACK_PERM: 3376 case TCPOPT_SACK_PERM:
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 0e9bc120707d..cd601a866c2f 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -2214,9 +2214,6 @@ static int tcp_seq_open(struct inode *inode, struct file *file)
2214 struct tcp_iter_state *s; 2214 struct tcp_iter_state *s;
2215 int err; 2215 int err;
2216 2216
2217 if (unlikely(afinfo == NULL))
2218 return -EINVAL;
2219
2220 err = seq_open_net(inode, file, &afinfo->seq_ops, 2217 err = seq_open_net(inode, file, &afinfo->seq_ops,
2221 sizeof(struct tcp_iter_state)); 2218 sizeof(struct tcp_iter_state));
2222 if (err < 0) 2219 if (err < 0)
@@ -2241,10 +2238,9 @@ int tcp_proc_register(struct net *net, struct tcp_seq_afinfo *afinfo)
2241 afinfo->seq_ops.next = tcp_seq_next; 2238 afinfo->seq_ops.next = tcp_seq_next;
2242 afinfo->seq_ops.stop = tcp_seq_stop; 2239 afinfo->seq_ops.stop = tcp_seq_stop;
2243 2240
2244 p = proc_net_fops_create(net, afinfo->name, S_IRUGO, &afinfo->seq_fops); 2241 p = proc_create_data(afinfo->name, S_IRUGO, net->proc_net,
2245 if (p) 2242 &afinfo->seq_fops, afinfo);
2246 p->data = afinfo; 2243 if (!p)
2247 else
2248 rc = -ENOMEM; 2244 rc = -ENOMEM;
2249 return rc; 2245 return rc;
2250} 2246}
diff --git a/net/ipv4/tcp_vegas.c b/net/ipv4/tcp_vegas.c
index be24d6ee34bd..14504dada116 100644
--- a/net/ipv4/tcp_vegas.c
+++ b/net/ipv4/tcp_vegas.c
@@ -167,8 +167,10 @@ static void tcp_vegas_cong_avoid(struct sock *sk, u32 ack, u32 in_flight)
167 struct tcp_sock *tp = tcp_sk(sk); 167 struct tcp_sock *tp = tcp_sk(sk);
168 struct vegas *vegas = inet_csk_ca(sk); 168 struct vegas *vegas = inet_csk_ca(sk);
169 169
170 if (!vegas->doing_vegas_now) 170 if (!vegas->doing_vegas_now) {
171 return tcp_reno_cong_avoid(sk, ack, in_flight); 171 tcp_reno_cong_avoid(sk, ack, in_flight);
172 return;
173 }
172 174
173 /* The key players are v_beg_snd_una and v_beg_snd_nxt. 175 /* The key players are v_beg_snd_una and v_beg_snd_nxt.
174 * 176 *
@@ -229,7 +231,8 @@ static void tcp_vegas_cong_avoid(struct sock *sk, u32 ack, u32 in_flight)
229 */ 231 */
230 tcp_reno_cong_avoid(sk, ack, in_flight); 232 tcp_reno_cong_avoid(sk, ack, in_flight);
231 } else { 233 } else {
232 u32 rtt, target_cwnd, diff; 234 u32 rtt, diff;
235 u64 target_cwnd;
233 236
234 /* We have enough RTT samples, so, using the Vegas 237 /* We have enough RTT samples, so, using the Vegas
235 * algorithm, we determine if we should increase or 238 * algorithm, we determine if we should increase or
@@ -252,8 +255,9 @@ static void tcp_vegas_cong_avoid(struct sock *sk, u32 ack, u32 in_flight)
252 * We keep it as a fixed point number with 255 * We keep it as a fixed point number with
253 * V_PARAM_SHIFT bits to the right of the binary point. 256 * V_PARAM_SHIFT bits to the right of the binary point.
254 */ 257 */
255 target_cwnd = ((old_wnd * vegas->baseRTT) 258 target_cwnd = ((u64)old_wnd * vegas->baseRTT);
256 << V_PARAM_SHIFT) / rtt; 259 target_cwnd <<= V_PARAM_SHIFT;
260 do_div(target_cwnd, rtt);
257 261
258 /* Calculate the difference between the window we had, 262 /* Calculate the difference between the window we had,
259 * and the window we would like to have. This quantity 263 * and the window we would like to have. This quantity
@@ -279,7 +283,7 @@ static void tcp_vegas_cong_avoid(struct sock *sk, u32 ack, u32 in_flight)
279 * utilization. 283 * utilization.
280 */ 284 */
281 tp->snd_cwnd = min(tp->snd_cwnd, 285 tp->snd_cwnd = min(tp->snd_cwnd,
282 (target_cwnd >> 286 ((u32)target_cwnd >>
283 V_PARAM_SHIFT)+1); 287 V_PARAM_SHIFT)+1);
284 288
285 } else if (tp->snd_cwnd <= tp->snd_ssthresh) { 289 } else if (tp->snd_cwnd <= tp->snd_ssthresh) {
diff --git a/net/ipv4/tcp_veno.c b/net/ipv4/tcp_veno.c
index d16689e98516..d08b2e855c22 100644
--- a/net/ipv4/tcp_veno.c
+++ b/net/ipv4/tcp_veno.c
@@ -119,8 +119,10 @@ static void tcp_veno_cong_avoid(struct sock *sk, u32 ack, u32 in_flight)
119 struct tcp_sock *tp = tcp_sk(sk); 119 struct tcp_sock *tp = tcp_sk(sk);
120 struct veno *veno = inet_csk_ca(sk); 120 struct veno *veno = inet_csk_ca(sk);
121 121
122 if (!veno->doing_veno_now) 122 if (!veno->doing_veno_now) {
123 return tcp_reno_cong_avoid(sk, ack, in_flight); 123 tcp_reno_cong_avoid(sk, ack, in_flight);
124 return;
125 }
124 126
125 /* limited by applications */ 127 /* limited by applications */
126 if (!tcp_is_cwnd_limited(sk, in_flight)) 128 if (!tcp_is_cwnd_limited(sk, in_flight))
@@ -133,7 +135,8 @@ static void tcp_veno_cong_avoid(struct sock *sk, u32 ack, u32 in_flight)
133 */ 135 */
134 tcp_reno_cong_avoid(sk, ack, in_flight); 136 tcp_reno_cong_avoid(sk, ack, in_flight);
135 } else { 137 } else {
136 u32 rtt, target_cwnd; 138 u64 target_cwnd;
139 u32 rtt;
137 140
138 /* We have enough rtt samples, so, using the Veno 141 /* We have enough rtt samples, so, using the Veno
139 * algorithm, we determine the state of the network. 142 * algorithm, we determine the state of the network.
@@ -141,8 +144,9 @@ static void tcp_veno_cong_avoid(struct sock *sk, u32 ack, u32 in_flight)
141 144
142 rtt = veno->minrtt; 145 rtt = veno->minrtt;
143 146
144 target_cwnd = ((tp->snd_cwnd * veno->basertt) 147 target_cwnd = (tp->snd_cwnd * veno->basertt);
145 << V_PARAM_SHIFT) / rtt; 148 target_cwnd <<= V_PARAM_SHIFT;
149 do_div(target_cwnd, rtt);
146 150
147 veno->diff = (tp->snd_cwnd << V_PARAM_SHIFT) - target_cwnd; 151 veno->diff = (tp->snd_cwnd << V_PARAM_SHIFT) - target_cwnd;
148 152
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 1f535e315188..db1cb7c96d63 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -1605,10 +1605,9 @@ int udp_proc_register(struct net *net, struct udp_seq_afinfo *afinfo)
1605 afinfo->seq_ops.next = udp_seq_next; 1605 afinfo->seq_ops.next = udp_seq_next;
1606 afinfo->seq_ops.stop = udp_seq_stop; 1606 afinfo->seq_ops.stop = udp_seq_stop;
1607 1607
1608 p = proc_net_fops_create(net, afinfo->name, S_IRUGO, &afinfo->seq_fops); 1608 p = proc_create_data(afinfo->name, S_IRUGO, net->proc_net,
1609 if (p) 1609 &afinfo->seq_fops, afinfo);
1610 p->data = afinfo; 1610 if (!p)
1611 else
1612 rc = -ENOMEM; 1611 rc = -ENOMEM;
1613 return rc; 1612 return rc;
1614} 1613}
diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
index db6fdc1498aa..56d55fecf8ec 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -1127,6 +1127,10 @@ int compat_ipv6_getsockopt(struct sock *sk, int level, int optname,
1127 if (level != SOL_IPV6) 1127 if (level != SOL_IPV6)
1128 return -ENOPROTOOPT; 1128 return -ENOPROTOOPT;
1129 1129
1130 if (optname == MCAST_MSFILTER)
1131 return compat_mc_getsockopt(sk, level, optname, optval, optlen,
1132 ipv6_getsockopt);
1133
1130 err = do_ipv6_getsockopt(sk, level, optname, optval, optlen); 1134 err = do_ipv6_getsockopt(sk, level, optname, optval, optlen);
1131#ifdef CONFIG_NETFILTER 1135#ifdef CONFIG_NETFILTER
1132 /* we need to exclude all possible ENOPROTOOPTs except default case */ 1136 /* we need to exclude all possible ENOPROTOOPTs except default case */
diff --git a/net/ipv6/netfilter/ip6_queue.c b/net/ipv6/netfilter/ip6_queue.c
index 92a36c9e5402..2eff3ae8977d 100644
--- a/net/ipv6/netfilter/ip6_queue.c
+++ b/net/ipv6/netfilter/ip6_queue.c
@@ -298,9 +298,8 @@ ipq_mangle_ipv6(ipq_verdict_msg_t *v, struct nf_queue_entry *e)
298 if (v->data_len > 0xFFFF) 298 if (v->data_len > 0xFFFF)
299 return -EINVAL; 299 return -EINVAL;
300 if (diff > skb_tailroom(e->skb)) { 300 if (diff > skb_tailroom(e->skb)) {
301 nskb = skb_copy_expand(e->skb, 0, 301 nskb = skb_copy_expand(e->skb, skb_headroom(e->skb),
302 diff - skb_tailroom(e->skb), 302 diff, GFP_ATOMIC);
303 GFP_ATOMIC);
304 if (!nskb) { 303 if (!nskb) {
305 printk(KERN_WARNING "ip6_queue: OOM " 304 printk(KERN_WARNING "ip6_queue: OOM "
306 "in mangle, dropping packet\n"); 305 "in mangle, dropping packet\n");
diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
index ca8b82f96fe5..df0736a4cafa 100644
--- a/net/ipv6/proc.c
+++ b/net/ipv6/proc.c
@@ -247,13 +247,11 @@ int snmp6_register_dev(struct inet6_dev *idev)
247 if (!proc_net_devsnmp6) 247 if (!proc_net_devsnmp6)
248 return -ENOENT; 248 return -ENOENT;
249 249
250 p = proc_create(idev->dev->name, S_IRUGO, 250 p = proc_create_data(idev->dev->name, S_IRUGO,
251 proc_net_devsnmp6, &snmp6_seq_fops); 251 proc_net_devsnmp6, &snmp6_seq_fops, idev);
252 if (!p) 252 if (!p)
253 return -ENOMEM; 253 return -ENOMEM;
254 254
255 p->data = idev;
256
257 idev->stats.proc_dir_entry = p; 255 idev->stats.proc_dir_entry = p;
258 return 0; 256 return 0;
259} 257}
diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
index 7b247e3a16fe..798cabc7535b 100644
--- a/net/ipv6/reassembly.c
+++ b/net/ipv6/reassembly.c
@@ -197,6 +197,7 @@ static void ip6_frag_expire(unsigned long data)
197{ 197{
198 struct frag_queue *fq; 198 struct frag_queue *fq;
199 struct net_device *dev = NULL; 199 struct net_device *dev = NULL;
200 struct net *net;
200 201
201 fq = container_of((struct inet_frag_queue *)data, struct frag_queue, q); 202 fq = container_of((struct inet_frag_queue *)data, struct frag_queue, q);
202 203
@@ -207,7 +208,8 @@ static void ip6_frag_expire(unsigned long data)
207 208
208 fq_kill(fq); 209 fq_kill(fq);
209 210
210 dev = dev_get_by_index(&init_net, fq->iif); 211 net = container_of(fq->q.net, struct net, ipv6.frags);
212 dev = dev_get_by_index(net, fq->iif);
211 if (!dev) 213 if (!dev)
212 goto out; 214 goto out;
213 215
diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
index d2620410cb0a..76c3057d0179 100644
--- a/net/irda/ircomm/ircomm_tty.c
+++ b/net/irda/ircomm/ircomm_tty.c
@@ -555,10 +555,8 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
555 555
556 ircomm_tty_shutdown(self); 556 ircomm_tty_shutdown(self);
557 557
558 if (tty->driver->flush_buffer) 558 tty_driver_flush_buffer(tty);
559 tty->driver->flush_buffer(tty); 559 tty_ldisc_flush(tty);
560 if (tty->ldisc.flush_buffer)
561 tty->ldisc.flush_buffer(tty);
562 560
563 tty->closing = 0; 561 tty->closing = 0;
564 self->tty = NULL; 562 self->tty = NULL;
diff --git a/net/irda/iriap.c b/net/irda/iriap.c
index 9e15c82960fe..4a105dc32dcd 100644
--- a/net/irda/iriap.c
+++ b/net/irda/iriap.c
@@ -451,12 +451,14 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
451 n = 2; 451 n = 2;
452 452
453 /* Get length, MSB first */ 453 /* Get length, MSB first */
454 len = be16_to_cpu(get_unaligned((__be16 *)(fp+n))); n += 2; 454 len = get_unaligned_be16(fp + n);
455 n += 2;
455 456
456 IRDA_DEBUG(4, "%s(), len=%d\n", __func__, len); 457 IRDA_DEBUG(4, "%s(), len=%d\n", __func__, len);
457 458
458 /* Get object ID, MSB first */ 459 /* Get object ID, MSB first */
459 obj_id = be16_to_cpu(get_unaligned((__be16 *)(fp+n))); n += 2; 460 obj_id = get_unaligned_be16(fp + n);
461 n += 2;
460 462
461 type = fp[n++]; 463 type = fp[n++];
462 IRDA_DEBUG(4, "%s(), Value type = %d\n", __func__, type); 464 IRDA_DEBUG(4, "%s(), Value type = %d\n", __func__, type);
@@ -506,7 +508,7 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
506 value = irias_new_string_value(fp+n); 508 value = irias_new_string_value(fp+n);
507 break; 509 break;
508 case IAS_OCT_SEQ: 510 case IAS_OCT_SEQ:
509 value_len = be16_to_cpu(get_unaligned((__be16 *)(fp+n))); 511 value_len = get_unaligned_be16(fp + n);
510 n += 2; 512 n += 2;
511 513
512 /* Will truncate to IAS_MAX_OCTET_STRING bytes */ 514 /* Will truncate to IAS_MAX_OCTET_STRING bytes */
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 8e53ce7ed444..c7314bf4bec2 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -354,7 +354,7 @@ struct ieee80211_if_sta {
354 int preq_queue_len; 354 int preq_queue_len;
355 struct mesh_stats mshstats; 355 struct mesh_stats mshstats;
356 struct mesh_config mshcfg; 356 struct mesh_config mshcfg;
357 u8 mesh_seqnum[3]; 357 u32 mesh_seqnum;
358 bool accepting_plinks; 358 bool accepting_plinks;
359#endif 359#endif
360 u16 aid; 360 u16 aid;
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index e9a978979d38..9ad4e3631b6b 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -255,22 +255,8 @@ static int ieee80211_open(struct net_device *dev)
255 255
256 switch (sdata->vif.type) { 256 switch (sdata->vif.type) {
257 case IEEE80211_IF_TYPE_WDS: 257 case IEEE80211_IF_TYPE_WDS:
258 if (is_zero_ether_addr(sdata->u.wds.remote_addr)) 258 if (!is_valid_ether_addr(sdata->u.wds.remote_addr))
259 return -ENOLINK; 259 return -ENOLINK;
260
261 /* Create STA entry for the WDS peer */
262 sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
263 GFP_KERNEL);
264 if (!sta)
265 return -ENOMEM;
266
267 sta->flags |= WLAN_STA_AUTHORIZED;
268
269 res = sta_info_insert(sta);
270 if (res) {
271 /* STA has been freed */
272 return res;
273 }
274 break; 260 break;
275 case IEEE80211_IF_TYPE_VLAN: 261 case IEEE80211_IF_TYPE_VLAN:
276 if (!sdata->u.vlan.ap) 262 if (!sdata->u.vlan.ap)
@@ -337,10 +323,8 @@ static int ieee80211_open(struct net_device *dev)
337 conf.type = sdata->vif.type; 323 conf.type = sdata->vif.type;
338 conf.mac_addr = dev->dev_addr; 324 conf.mac_addr = dev->dev_addr;
339 res = local->ops->add_interface(local_to_hw(local), &conf); 325 res = local->ops->add_interface(local_to_hw(local), &conf);
340 if (res && !local->open_count && local->ops->stop)
341 local->ops->stop(local_to_hw(local));
342 if (res) 326 if (res)
343 return res; 327 goto err_stop;
344 328
345 ieee80211_if_config(dev); 329 ieee80211_if_config(dev);
346 ieee80211_reset_erp_info(dev); 330 ieee80211_reset_erp_info(dev);
@@ -353,9 +337,29 @@ static int ieee80211_open(struct net_device *dev)
353 netif_carrier_on(dev); 337 netif_carrier_on(dev);
354 } 338 }
355 339
340 if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
341 /* Create STA entry for the WDS peer */
342 sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
343 GFP_KERNEL);
344 if (!sta) {
345 res = -ENOMEM;
346 goto err_del_interface;
347 }
348
349 sta->flags |= WLAN_STA_AUTHORIZED;
350
351 res = sta_info_insert(sta);
352 if (res) {
353 /* STA has been freed */
354 goto err_del_interface;
355 }
356 }
357
356 if (local->open_count == 0) { 358 if (local->open_count == 0) {
357 res = dev_open(local->mdev); 359 res = dev_open(local->mdev);
358 WARN_ON(res); 360 WARN_ON(res);
361 if (res)
362 goto err_del_interface;
359 tasklet_enable(&local->tx_pending_tasklet); 363 tasklet_enable(&local->tx_pending_tasklet);
360 tasklet_enable(&local->tasklet); 364 tasklet_enable(&local->tasklet);
361 } 365 }
@@ -390,6 +394,12 @@ static int ieee80211_open(struct net_device *dev)
390 netif_start_queue(dev); 394 netif_start_queue(dev);
391 395
392 return 0; 396 return 0;
397 err_del_interface:
398 local->ops->remove_interface(local_to_hw(local), &conf);
399 err_stop:
400 if (!local->open_count && local->ops->stop)
401 local->ops->stop(local_to_hw(local));
402 return res;
393} 403}
394 404
395static int ieee80211_stop(struct net_device *dev) 405static int ieee80211_stop(struct net_device *dev)
@@ -975,6 +985,7 @@ static int __ieee80211_if_config(struct net_device *dev,
975 conf.ssid_len = sdata->u.sta.ssid_len; 985 conf.ssid_len = sdata->u.sta.ssid_len;
976 } else if (ieee80211_vif_is_mesh(&sdata->vif)) { 986 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
977 conf.beacon = beacon; 987 conf.beacon = beacon;
988 conf.beacon_control = control;
978 ieee80211_start_mesh(dev); 989 ieee80211_start_mesh(dev);
979 } else if (sdata->vif.type == IEEE80211_IF_TYPE_AP) { 990 } else if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
980 conf.ssid = sdata->u.ap.ssid; 991 conf.ssid = sdata->u.ap.ssid;
diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index 594a3356a508..f76bc26ae4d2 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -8,6 +8,7 @@
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10 10
11#include <asm/unaligned.h>
11#include "ieee80211_i.h" 12#include "ieee80211_i.h"
12#include "mesh.h" 13#include "mesh.h"
13 14
@@ -167,8 +168,8 @@ int mesh_rmc_check(u8 *sa, struct ieee80211s_hdr *mesh_hdr,
167 struct rmc_entry *p, *n; 168 struct rmc_entry *p, *n;
168 169
169 /* Don't care about endianness since only match matters */ 170 /* Don't care about endianness since only match matters */
170 memcpy(&seqnum, mesh_hdr->seqnum, sizeof(mesh_hdr->seqnum)); 171 memcpy(&seqnum, &mesh_hdr->seqnum, sizeof(mesh_hdr->seqnum));
171 idx = mesh_hdr->seqnum[0] & rmc->idx_mask; 172 idx = le32_to_cpu(mesh_hdr->seqnum) & rmc->idx_mask;
172 list_for_each_entry_safe(p, n, &rmc->bucket[idx].list, list) { 173 list_for_each_entry_safe(p, n, &rmc->bucket[idx].list, list) {
173 ++entries; 174 ++entries;
174 if (time_after(jiffies, p->exp_time) || 175 if (time_after(jiffies, p->exp_time) ||
@@ -393,16 +394,8 @@ int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr,
393{ 394{
394 meshhdr->flags = 0; 395 meshhdr->flags = 0;
395 meshhdr->ttl = sdata->u.sta.mshcfg.dot11MeshTTL; 396 meshhdr->ttl = sdata->u.sta.mshcfg.dot11MeshTTL;
396 397 put_unaligned(cpu_to_le32(sdata->u.sta.mesh_seqnum), &meshhdr->seqnum);
397 meshhdr->seqnum[0] = sdata->u.sta.mesh_seqnum[0]++; 398 sdata->u.sta.mesh_seqnum++;
398 meshhdr->seqnum[1] = sdata->u.sta.mesh_seqnum[1];
399 meshhdr->seqnum[2] = sdata->u.sta.mesh_seqnum[2];
400
401 if (sdata->u.sta.mesh_seqnum[0] == 0) {
402 sdata->u.sta.mesh_seqnum[1]++;
403 if (sdata->u.sta.mesh_seqnum[1] == 0)
404 sdata->u.sta.mesh_seqnum[2]++;
405 }
406 399
407 return 5; 400 return 5;
408} 401}
diff --git a/net/mac80211/mesh.h b/net/mac80211/mesh.h
index 9ee3affab346..2e161f6d8288 100644
--- a/net/mac80211/mesh.h
+++ b/net/mac80211/mesh.h
@@ -140,7 +140,7 @@ struct rmc_entry {
140 140
141struct mesh_rmc { 141struct mesh_rmc {
142 struct rmc_entry bucket[RMC_BUCKETS]; 142 struct rmc_entry bucket[RMC_BUCKETS];
143 u8 idx_mask; 143 u32 idx_mask;
144}; 144};
145 145
146 146
diff --git a/net/mac80211/tkip.c b/net/mac80211/tkip.c
index dddbfd60f351..09093da24af6 100644
--- a/net/mac80211/tkip.c
+++ b/net/mac80211/tkip.c
@@ -230,10 +230,8 @@ void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf,
230 230
231 iv16 = data[hdr_len] << 8; 231 iv16 = data[hdr_len] << 8;
232 iv16 += data[hdr_len + 2]; 232 iv16 += data[hdr_len + 2];
233 iv32 = data[hdr_len + 4] + 233 iv32 = data[hdr_len + 4] | (data[hdr_len + 5] << 8) |
234 (data[hdr_len + 5] >> 8) + 234 (data[hdr_len + 6] << 16) | (data[hdr_len + 7] << 24);
235 (data[hdr_len + 6] >> 16) +
236 (data[hdr_len + 7] >> 24);
237 235
238#ifdef CONFIG_TKIP_DEBUG 236#ifdef CONFIG_TKIP_DEBUG
239 printk(KERN_DEBUG "TKIP encrypt: iv16 = 0x%04x, iv32 = 0x%08x\n", 237 printk(KERN_DEBUG "TKIP encrypt: iv16 = 0x%04x, iv32 = 0x%08x\n",
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 4eac65c74ed0..c4b1799da5d7 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -104,7 +104,7 @@ nf_ct_get_tuple(const struct sk_buff *skb,
104 const struct nf_conntrack_l3proto *l3proto, 104 const struct nf_conntrack_l3proto *l3proto,
105 const struct nf_conntrack_l4proto *l4proto) 105 const struct nf_conntrack_l4proto *l4proto)
106{ 106{
107 NF_CT_TUPLE_U_BLANK(tuple); 107 memset(tuple, 0, sizeof(*tuple));
108 108
109 tuple->src.l3num = l3num; 109 tuple->src.l3num = l3num;
110 if (l3proto->pkt_to_tuple(skb, nhoff, tuple) == 0) 110 if (l3proto->pkt_to_tuple(skb, nhoff, tuple) == 0)
@@ -151,7 +151,7 @@ nf_ct_invert_tuple(struct nf_conntrack_tuple *inverse,
151 const struct nf_conntrack_l3proto *l3proto, 151 const struct nf_conntrack_l3proto *l3proto,
152 const struct nf_conntrack_l4proto *l4proto) 152 const struct nf_conntrack_l4proto *l4proto)
153{ 153{
154 NF_CT_TUPLE_U_BLANK(inverse); 154 memset(inverse, 0, sizeof(*inverse));
155 155
156 inverse->src.l3num = orig->src.l3num; 156 inverse->src.l3num = orig->src.l3num;
157 if (l3proto->invert_tuple(inverse, orig) == 0) 157 if (l3proto->invert_tuple(inverse, orig) == 0)
diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
index b59871f6bdda..46ea542d0df9 100644
--- a/net/netfilter/nf_conntrack_standalone.c
+++ b/net/netfilter/nf_conntrack_standalone.c
@@ -296,11 +296,11 @@ static int nf_conntrack_standalone_init_proc(void)
296 pde = proc_net_fops_create(&init_net, "nf_conntrack", 0440, &ct_file_ops); 296 pde = proc_net_fops_create(&init_net, "nf_conntrack", 0440, &ct_file_ops);
297 if (!pde) 297 if (!pde)
298 goto out_nf_conntrack; 298 goto out_nf_conntrack;
299 pde = create_proc_entry("nf_conntrack", S_IRUGO, init_net.proc_net_stat); 299
300 pde = proc_create("nf_conntrack", S_IRUGO, init_net.proc_net_stat,
301 &ct_cpu_seq_fops);
300 if (!pde) 302 if (!pde)
301 goto out_stat_nf_conntrack; 303 goto out_stat_nf_conntrack;
302 pde->proc_fops = &ct_cpu_seq_fops;
303 pde->owner = THIS_MODULE;
304 return 0; 304 return 0;
305 305
306out_stat_nf_conntrack: 306out_stat_nf_conntrack:
diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c
index 2c9fe5c12894..3447025ce068 100644
--- a/net/netfilter/nfnetlink_queue.c
+++ b/net/netfilter/nfnetlink_queue.c
@@ -454,9 +454,8 @@ nfqnl_mangle(void *data, int data_len, struct nf_queue_entry *e)
454 if (data_len > 0xFFFF) 454 if (data_len > 0xFFFF)
455 return -EINVAL; 455 return -EINVAL;
456 if (diff > skb_tailroom(e->skb)) { 456 if (diff > skb_tailroom(e->skb)) {
457 nskb = skb_copy_expand(e->skb, 0, 457 nskb = skb_copy_expand(e->skb, skb_headroom(e->skb),
458 diff - skb_tailroom(e->skb), 458 diff, GFP_ATOMIC);
459 GFP_ATOMIC);
460 if (!nskb) { 459 if (!nskb) {
461 printk(KERN_WARNING "nf_queue: OOM " 460 printk(KERN_WARNING "nf_queue: OOM "
462 "in mangle, dropping packet\n"); 461 "in mangle, dropping packet\n");
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index f52f7f810ac4..5d75cd86ebb3 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -787,7 +787,7 @@ static const struct file_operations xt_table_ops = {
787 .open = xt_table_open, 787 .open = xt_table_open,
788 .read = seq_read, 788 .read = seq_read,
789 .llseek = seq_lseek, 789 .llseek = seq_lseek,
790 .release = seq_release, 790 .release = seq_release_net,
791}; 791};
792 792
793static void *xt_match_seq_start(struct seq_file *seq, loff_t *pos) 793static void *xt_match_seq_start(struct seq_file *seq, loff_t *pos)
@@ -936,25 +936,24 @@ int xt_proto_init(struct net *net, int af)
936#ifdef CONFIG_PROC_FS 936#ifdef CONFIG_PROC_FS
937 strlcpy(buf, xt_prefix[af], sizeof(buf)); 937 strlcpy(buf, xt_prefix[af], sizeof(buf));
938 strlcat(buf, FORMAT_TABLES, sizeof(buf)); 938 strlcat(buf, FORMAT_TABLES, sizeof(buf));
939 proc = proc_net_fops_create(net, buf, 0440, &xt_table_ops); 939 proc = proc_create_data(buf, 0440, net->proc_net, &xt_table_ops,
940 (void *)(unsigned long)af);
940 if (!proc) 941 if (!proc)
941 goto out; 942 goto out;
942 proc->data = (void *)(unsigned long)af;
943
944 943
945 strlcpy(buf, xt_prefix[af], sizeof(buf)); 944 strlcpy(buf, xt_prefix[af], sizeof(buf));
946 strlcat(buf, FORMAT_MATCHES, sizeof(buf)); 945 strlcat(buf, FORMAT_MATCHES, sizeof(buf));
947 proc = proc_net_fops_create(net, buf, 0440, &xt_match_ops); 946 proc = proc_create_data(buf, 0440, net->proc_net, &xt_match_ops,
947 (void *)(unsigned long)af);
948 if (!proc) 948 if (!proc)
949 goto out_remove_tables; 949 goto out_remove_tables;
950 proc->data = (void *)(unsigned long)af;
951 950
952 strlcpy(buf, xt_prefix[af], sizeof(buf)); 951 strlcpy(buf, xt_prefix[af], sizeof(buf));
953 strlcat(buf, FORMAT_TARGETS, sizeof(buf)); 952 strlcat(buf, FORMAT_TARGETS, sizeof(buf));
954 proc = proc_net_fops_create(net, buf, 0440, &xt_target_ops); 953 proc = proc_create_data(buf, 0440, net->proc_net, &xt_target_ops,
954 (void *)(unsigned long)af);
955 if (!proc) 955 if (!proc)
956 goto out_remove_matches; 956 goto out_remove_matches;
957 proc->data = (void *)(unsigned long)af;
958#endif 957#endif
959 958
960 return 0; 959 return 0;
diff --git a/net/netfilter/xt_TCPOPTSTRIP.c b/net/netfilter/xt_TCPOPTSTRIP.c
index 3b2aa56833b9..9685b6fcbc81 100644
--- a/net/netfilter/xt_TCPOPTSTRIP.c
+++ b/net/netfilter/xt_TCPOPTSTRIP.c
@@ -90,7 +90,7 @@ tcpoptstrip_tg6(struct sk_buff *skb, const struct net_device *in,
90 const struct xt_target *target, const void *targinfo) 90 const struct xt_target *target, const void *targinfo)
91{ 91{
92 struct ipv6hdr *ipv6h = ipv6_hdr(skb); 92 struct ipv6hdr *ipv6h = ipv6_hdr(skb);
93 unsigned int tcphoff; 93 int tcphoff;
94 u_int8_t nexthdr; 94 u_int8_t nexthdr;
95 95
96 nexthdr = ipv6h->nexthdr; 96 nexthdr = ipv6h->nexthdr;
diff --git a/net/netfilter/xt_connbytes.c b/net/netfilter/xt_connbytes.c
index b15e7e2fa143..d7e8983cd37f 100644
--- a/net/netfilter/xt_connbytes.c
+++ b/net/netfilter/xt_connbytes.c
@@ -4,12 +4,11 @@
4#include <linux/module.h> 4#include <linux/module.h>
5#include <linux/bitops.h> 5#include <linux/bitops.h>
6#include <linux/skbuff.h> 6#include <linux/skbuff.h>
7#include <linux/math64.h>
7#include <linux/netfilter/x_tables.h> 8#include <linux/netfilter/x_tables.h>
8#include <linux/netfilter/xt_connbytes.h> 9#include <linux/netfilter/xt_connbytes.h>
9#include <net/netfilter/nf_conntrack.h> 10#include <net/netfilter/nf_conntrack.h>
10 11
11#include <asm/div64.h>
12
13MODULE_LICENSE("GPL"); 12MODULE_LICENSE("GPL");
14MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>"); 13MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
15MODULE_DESCRIPTION("Xtables: Number of packets/bytes per connection matching"); 14MODULE_DESCRIPTION("Xtables: Number of packets/bytes per connection matching");
@@ -82,7 +81,7 @@ connbytes_mt(const struct sk_buff *skb, const struct net_device *in,
82 break; 81 break;
83 } 82 }
84 if (pkts != 0) 83 if (pkts != 0)
85 what = div64_64(bytes, pkts); 84 what = div64_u64(bytes, pkts);
86 break; 85 break;
87 } 86 }
88 87
diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
index 40d344b21453..6809af542a2c 100644
--- a/net/netfilter/xt_hashlimit.c
+++ b/net/netfilter/xt_hashlimit.c
@@ -237,15 +237,15 @@ static int htable_create_v0(struct xt_hashlimit_info *minfo, int family)
237 hinfo->family = family; 237 hinfo->family = family;
238 hinfo->rnd_initialized = 0; 238 hinfo->rnd_initialized = 0;
239 spin_lock_init(&hinfo->lock); 239 spin_lock_init(&hinfo->lock);
240 hinfo->pde = proc_create(minfo->name, 0, 240 hinfo->pde =
241 proc_create_data(minfo->name, 0,
241 family == AF_INET ? hashlimit_procdir4 : 242 family == AF_INET ? hashlimit_procdir4 :
242 hashlimit_procdir6, 243 hashlimit_procdir6,
243 &dl_file_ops); 244 &dl_file_ops, hinfo);
244 if (!hinfo->pde) { 245 if (!hinfo->pde) {
245 vfree(hinfo); 246 vfree(hinfo);
246 return -1; 247 return -1;
247 } 248 }
248 hinfo->pde->data = hinfo;
249 249
250 setup_timer(&hinfo->timer, htable_gc, (unsigned long )hinfo); 250 setup_timer(&hinfo->timer, htable_gc, (unsigned long )hinfo);
251 hinfo->timer.expires = jiffies + msecs_to_jiffies(hinfo->cfg.gc_interval); 251 hinfo->timer.expires = jiffies + msecs_to_jiffies(hinfo->cfg.gc_interval);
@@ -301,15 +301,15 @@ static int htable_create(struct xt_hashlimit_mtinfo1 *minfo,
301 hinfo->rnd_initialized = 0; 301 hinfo->rnd_initialized = 0;
302 spin_lock_init(&hinfo->lock); 302 spin_lock_init(&hinfo->lock);
303 303
304 hinfo->pde = proc_create(minfo->name, 0, 304 hinfo->pde =
305 proc_create_data(minfo->name, 0,
305 family == AF_INET ? hashlimit_procdir4 : 306 family == AF_INET ? hashlimit_procdir4 :
306 hashlimit_procdir6, 307 hashlimit_procdir6,
307 &dl_file_ops); 308 &dl_file_ops, hinfo);
308 if (hinfo->pde == NULL) { 309 if (hinfo->pde == NULL) {
309 vfree(hinfo); 310 vfree(hinfo);
310 return -1; 311 return -1;
311 } 312 }
312 hinfo->pde->data = hinfo;
313 313
314 setup_timer(&hinfo->timer, htable_gc, (unsigned long)hinfo); 314 setup_timer(&hinfo->timer, htable_gc, (unsigned long)hinfo);
315 hinfo->timer.expires = jiffies + msecs_to_jiffies(hinfo->cfg.gc_interval); 315 hinfo->timer.expires = jiffies + msecs_to_jiffies(hinfo->cfg.gc_interval);
diff --git a/net/rose/rose_route.c b/net/rose/rose_route.c
index 5053a53ba24f..bd593871c81e 100644
--- a/net/rose/rose_route.c
+++ b/net/rose/rose_route.c
@@ -1066,12 +1066,12 @@ out:
1066#ifdef CONFIG_PROC_FS 1066#ifdef CONFIG_PROC_FS
1067 1067
1068static void *rose_node_start(struct seq_file *seq, loff_t *pos) 1068static void *rose_node_start(struct seq_file *seq, loff_t *pos)
1069 __acquires(rose_neigh_list_lock) 1069 __acquires(rose_node_list_lock)
1070{ 1070{
1071 struct rose_node *rose_node; 1071 struct rose_node *rose_node;
1072 int i = 1; 1072 int i = 1;
1073 1073
1074 spin_lock_bh(&rose_neigh_list_lock); 1074 spin_lock_bh(&rose_node_list_lock);
1075 if (*pos == 0) 1075 if (*pos == 0)
1076 return SEQ_START_TOKEN; 1076 return SEQ_START_TOKEN;
1077 1077
@@ -1090,9 +1090,9 @@ static void *rose_node_next(struct seq_file *seq, void *v, loff_t *pos)
1090} 1090}
1091 1091
1092static void rose_node_stop(struct seq_file *seq, void *v) 1092static void rose_node_stop(struct seq_file *seq, void *v)
1093 __releases(rose_neigh_list_lock) 1093 __releases(rose_node_list_lock)
1094{ 1094{
1095 spin_unlock_bh(&rose_neigh_list_lock); 1095 spin_unlock_bh(&rose_node_list_lock);
1096} 1096}
1097 1097
1098static int rose_node_show(struct seq_file *seq, void *v) 1098static int rose_node_show(struct seq_file *seq, void *v)
diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
index bb282a6a19f0..64069c8769a5 100644
--- a/net/rxrpc/ar-transport.c
+++ b/net/rxrpc/ar-transport.c
@@ -184,12 +184,13 @@ void rxrpc_put_transport(struct rxrpc_transport *trans)
184 ASSERTCMP(atomic_read(&trans->usage), >, 0); 184 ASSERTCMP(atomic_read(&trans->usage), >, 0);
185 185
186 trans->put_time = get_seconds(); 186 trans->put_time = get_seconds();
187 if (unlikely(atomic_dec_and_test(&trans->usage))) 187 if (unlikely(atomic_dec_and_test(&trans->usage))) {
188 _debug("zombie"); 188 _debug("zombie");
189 /* let the reaper determine the timeout to avoid a race with 189 /* let the reaper determine the timeout to avoid a race with
190 * overextending the timeout if the reaper is running at the 190 * overextending the timeout if the reaper is running at the
191 * same time */ 191 * same time */
192 rxrpc_queue_delayed_work(&rxrpc_transport_reap, 0); 192 rxrpc_queue_delayed_work(&rxrpc_transport_reap, 0);
193 }
193 _leave(""); 194 _leave("");
194} 195}
195 196
diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
index b741618e4d54..d355e5e47fe3 100644
--- a/net/sched/sch_generic.c
+++ b/net/sched/sch_generic.c
@@ -219,6 +219,7 @@ static void dev_watchdog(unsigned long arg)
219 printk(KERN_INFO "NETDEV WATCHDOG: %s: transmit timed out\n", 219 printk(KERN_INFO "NETDEV WATCHDOG: %s: transmit timed out\n",
220 dev->name); 220 dev->name);
221 dev->tx_timeout(dev); 221 dev->tx_timeout(dev);
222 WARN_ON_ONCE(1);
222 } 223 }
223 if (!mod_timer(&dev->watchdog_timer, round_jiffies(jiffies + dev->watchdog_timeo))) 224 if (!mod_timer(&dev->watchdog_timer, round_jiffies(jiffies + dev->watchdog_timeo)))
224 dev_hold(dev); 225 dev_hold(dev);
diff --git a/net/sched/sch_sfq.c b/net/sched/sch_sfq.c
index a20e2ef7704b..f0463d757a98 100644
--- a/net/sched/sch_sfq.c
+++ b/net/sched/sch_sfq.c
@@ -521,7 +521,8 @@ static void sfq_destroy(struct Qdisc *sch)
521 struct sfq_sched_data *q = qdisc_priv(sch); 521 struct sfq_sched_data *q = qdisc_priv(sch);
522 522
523 tcf_destroy_chain(q->filter_list); 523 tcf_destroy_chain(q->filter_list);
524 del_timer(&q->perturb_timer); 524 q->perturb_period = 0;
525 del_timer_sync(&q->perturb_timer);
525} 526}
526 527
527static int sfq_dump(struct Qdisc *sch, struct sk_buff *skb) 528static int sfq_dump(struct Qdisc *sch, struct sk_buff *skb)
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index d75530ff2a6d..c9966713282a 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -316,31 +316,28 @@ static int create_cache_proc_entries(struct cache_detail *cd)
316 cd->proc_ent->owner = cd->owner; 316 cd->proc_ent->owner = cd->owner;
317 cd->channel_ent = cd->content_ent = NULL; 317 cd->channel_ent = cd->content_ent = NULL;
318 318
319 p = proc_create("flush", S_IFREG|S_IRUSR|S_IWUSR, 319 p = proc_create_data("flush", S_IFREG|S_IRUSR|S_IWUSR,
320 cd->proc_ent, &cache_flush_operations); 320 cd->proc_ent, &cache_flush_operations, cd);
321 cd->flush_ent = p; 321 cd->flush_ent = p;
322 if (p == NULL) 322 if (p == NULL)
323 goto out_nomem; 323 goto out_nomem;
324 p->owner = cd->owner; 324 p->owner = cd->owner;
325 p->data = cd;
326 325
327 if (cd->cache_request || cd->cache_parse) { 326 if (cd->cache_request || cd->cache_parse) {
328 p = proc_create("channel", S_IFREG|S_IRUSR|S_IWUSR, 327 p = proc_create_data("channel", S_IFREG|S_IRUSR|S_IWUSR,
329 cd->proc_ent, &cache_file_operations); 328 cd->proc_ent, &cache_file_operations, cd);
330 cd->channel_ent = p; 329 cd->channel_ent = p;
331 if (p == NULL) 330 if (p == NULL)
332 goto out_nomem; 331 goto out_nomem;
333 p->owner = cd->owner; 332 p->owner = cd->owner;
334 p->data = cd;
335 } 333 }
336 if (cd->cache_show) { 334 if (cd->cache_show) {
337 p = proc_create("content", S_IFREG|S_IRUSR|S_IWUSR, 335 p = proc_create_data("content", S_IFREG|S_IRUSR|S_IWUSR,
338 cd->proc_ent, &content_file_operations); 336 cd->proc_ent, &content_file_operations, cd);
339 cd->content_ent = p; 337 cd->content_ent = p;
340 if (p == NULL) 338 if (p == NULL)
341 goto out_nomem; 339 goto out_nomem;
342 p->owner = cd->owner; 340 p->owner = cd->owner;
343 p->data = cd;
344 } 341 }
345 return 0; 342 return 0;
346out_nomem: 343out_nomem:
diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
index c6061a4346c8..50b049c6598a 100644
--- a/net/sunrpc/stats.c
+++ b/net/sunrpc/stats.c
@@ -224,16 +224,10 @@ EXPORT_SYMBOL_GPL(rpc_print_iostats);
224static inline struct proc_dir_entry * 224static inline struct proc_dir_entry *
225do_register(const char *name, void *data, const struct file_operations *fops) 225do_register(const char *name, void *data, const struct file_operations *fops)
226{ 226{
227 struct proc_dir_entry *ent;
228
229 rpc_proc_init(); 227 rpc_proc_init();
230 dprintk("RPC: registering /proc/net/rpc/%s\n", name); 228 dprintk("RPC: registering /proc/net/rpc/%s\n", name);
231 229
232 ent = proc_create(name, 0, proc_net_rpc, fops); 230 return proc_create_data(name, 0, proc_net_rpc, fops, data);
233 if (ent) {
234 ent->data = data;
235 }
236 return ent;
237} 231}
238 232
239struct proc_dir_entry * 233struct proc_dir_entry *
diff --git a/net/sysctl_net.c b/net/sysctl_net.c
index 665e856675a4..b4f0525f91af 100644
--- a/net/sysctl_net.c
+++ b/net/sysctl_net.c
@@ -82,6 +82,6 @@ EXPORT_SYMBOL_GPL(register_net_sysctl_table);
82 82
83void unregister_net_sysctl_table(struct ctl_table_header *header) 83void unregister_net_sysctl_table(struct ctl_table_header *header)
84{ 84{
85 return unregister_sysctl_table(header); 85 unregister_sysctl_table(header);
86} 86}
87EXPORT_SYMBOL_GPL(unregister_net_sysctl_table); 87EXPORT_SYMBOL_GPL(unregister_net_sysctl_table);
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index c912137f80e2..5d20a2e24cd1 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -7,12 +7,6 @@
7 * 7 *
8 * Usage: nm -n vmlinux | scripts/kallsyms [--all-symbols] > symbols.S 8 * Usage: nm -n vmlinux | scripts/kallsyms [--all-symbols] > symbols.S
9 * 9 *
10 * ChangeLog:
11 *
12 * (25/Aug/2004) Paulo Marques <pmarques@grupopie.com>
13 * Changed the compression method from stem compression to "table lookup"
14 * compression
15 *
16 * Table compression uses all the unused char codes on the symbols and 10 * Table compression uses all the unused char codes on the symbols and
17 * maps these to the most used substrings (tokens). For instance, it might 11 * maps these to the most used substrings (tokens). For instance, it might
18 * map char code 0xF7 to represent "write_" and then in every symbol where 12 * map char code 0xF7 to represent "write_" and then in every symbol where
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index 4bc68f20a73c..96521cb087ec 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -11,9 +11,9 @@
11#ifndef KBUILD_NO_NLS 11#ifndef KBUILD_NO_NLS
12# include <libintl.h> 12# include <libintl.h>
13#else 13#else
14# define gettext(Msgid) ((const char *) (Msgid)) 14static inline const char *gettext(const char *txt) { return txt; }
15# define textdomain(Domainname) ((const char *) (Domainname)) 15static inline void textdomain(const char *domainname) {}
16# define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname)) 16static inline void bindtextdomain(const char *name, const char *dir) {}
17#endif 17#endif
18 18
19#ifdef __cplusplus 19#ifdef __cplusplus
diff --git a/scripts/kconfig/lxdialog/check-lxdialog.sh b/scripts/kconfig/lxdialog/check-lxdialog.sh
index 62e1e02126e6..5552154cbedb 100644
--- a/scripts/kconfig/lxdialog/check-lxdialog.sh
+++ b/scripts/kconfig/lxdialog/check-lxdialog.sh
@@ -36,8 +36,10 @@ trap "rm -f $tmp" 0 1 2 3 15
36 36
37# Check if we can link to ncurses 37# Check if we can link to ncurses
38check() { 38check() {
39 echo -e " #include CURSES_LOC \n main() {}" | 39 $cc -xc - -o $tmp 2>/dev/null <<'EOF'
40 $cc -xc - -o $tmp 2> /dev/null 40#include CURSES_LOC
41main() {}
42EOF
41 if [ $? != 0 ]; then 43 if [ $? != 0 ]; then
42 echo " *** Unable to find the ncurses libraries or the" 1>&2 44 echo " *** Unable to find the ncurses libraries or the" 1>&2
43 echo " *** required header files." 1>&2 45 echo " *** required header files." 1>&2
diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
index 734cf4f3131e..6841e95c0989 100644
--- a/scripts/kconfig/mconf.c
+++ b/scripts/kconfig/mconf.c
@@ -773,7 +773,7 @@ static void conf_string(struct menu *menu)
773 773
774 while (1) { 774 while (1) {
775 int res; 775 int res;
776 char *heading; 776 const char *heading;
777 777
778 switch (sym_get_type(menu->sym)) { 778 switch (sym_get_type(menu->sym)) {
779 case S_INT: 779 case S_INT:
@@ -925,3 +925,4 @@ int main(int ac, char **av)
925 925
926 return 0; 926 return 0;
927} 927}
928
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index e04c4218cb52..cea4a790e1e9 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -51,6 +51,15 @@ do { \
51 sprintf(str + strlen(str), "*"); \ 51 sprintf(str + strlen(str), "*"); \
52} while(0) 52} while(0)
53 53
54/* Always end in a wildcard, for future extension */
55static inline void add_wildcard(char *str)
56{
57 int len = strlen(str);
58
59 if (str[len - 1] != '*')
60 strcat(str + len, "*");
61}
62
54unsigned int cross_build = 0; 63unsigned int cross_build = 0;
55/** 64/**
56 * Check that sizeof(device_id type) are consistent with size of section 65 * Check that sizeof(device_id type) are consistent with size of section
@@ -133,9 +142,7 @@ static void do_usb_entry(struct usb_device_id *id,
133 id->match_flags&USB_DEVICE_ID_MATCH_INT_PROTOCOL, 142 id->match_flags&USB_DEVICE_ID_MATCH_INT_PROTOCOL,
134 id->bInterfaceProtocol); 143 id->bInterfaceProtocol);
135 144
136 /* Always end in a wildcard, for future extension */ 145 add_wildcard(alias);
137 if (alias[strlen(alias)-1] != '*')
138 strcat(alias, "*");
139 buf_printf(&mod->dev_table_buf, 146 buf_printf(&mod->dev_table_buf,
140 "MODULE_ALIAS(\"%s\");\n", alias); 147 "MODULE_ALIAS(\"%s\");\n", alias);
141} 148}
@@ -219,6 +226,7 @@ static int do_ieee1394_entry(const char *filename,
219 ADD(alias, "ver", id->match_flags & IEEE1394_MATCH_VERSION, 226 ADD(alias, "ver", id->match_flags & IEEE1394_MATCH_VERSION,
220 id->version); 227 id->version);
221 228
229 add_wildcard(alias);
222 return 1; 230 return 1;
223} 231}
224 232
@@ -261,6 +269,7 @@ static int do_pci_entry(const char *filename,
261 ADD(alias, "bc", baseclass_mask == 0xFF, baseclass); 269 ADD(alias, "bc", baseclass_mask == 0xFF, baseclass);
262 ADD(alias, "sc", subclass_mask == 0xFF, subclass); 270 ADD(alias, "sc", subclass_mask == 0xFF, subclass);
263 ADD(alias, "i", interface_mask == 0xFF, interface); 271 ADD(alias, "i", interface_mask == 0xFF, interface);
272 add_wildcard(alias);
264 return 1; 273 return 1;
265} 274}
266 275
@@ -283,6 +292,7 @@ static int do_ccw_entry(const char *filename,
283 id->dev_type); 292 id->dev_type);
284 ADD(alias, "dm", id->match_flags&CCW_DEVICE_ID_MATCH_DEVICE_MODEL, 293 ADD(alias, "dm", id->match_flags&CCW_DEVICE_ID_MATCH_DEVICE_MODEL,
285 id->dev_model); 294 id->dev_model);
295 add_wildcard(alias);
286 return 1; 296 return 1;
287} 297}
288 298
@@ -290,7 +300,7 @@ static int do_ccw_entry(const char *filename,
290static int do_ap_entry(const char *filename, 300static int do_ap_entry(const char *filename,
291 struct ap_device_id *id, char *alias) 301 struct ap_device_id *id, char *alias)
292{ 302{
293 sprintf(alias, "ap:t%02X", id->dev_type); 303 sprintf(alias, "ap:t%02X*", id->dev_type);
294 return 1; 304 return 1;
295} 305}
296 306
@@ -309,6 +319,7 @@ static int do_serio_entry(const char *filename,
309 ADD(alias, "id", id->id != SERIO_ANY, id->id); 319 ADD(alias, "id", id->id != SERIO_ANY, id->id);
310 ADD(alias, "ex", id->extra != SERIO_ANY, id->extra); 320 ADD(alias, "ex", id->extra != SERIO_ANY, id->extra);
311 321
322 add_wildcard(alias);
312 return 1; 323 return 1;
313} 324}
314 325
@@ -316,7 +327,7 @@ static int do_serio_entry(const char *filename,
316static int do_acpi_entry(const char *filename, 327static int do_acpi_entry(const char *filename,
317 struct acpi_device_id *id, char *alias) 328 struct acpi_device_id *id, char *alias)
318{ 329{
319 sprintf(alias, "acpi*:%s:", id->id); 330 sprintf(alias, "acpi*:%s:*", id->id);
320 return 1; 331 return 1;
321} 332}
322 333
@@ -324,7 +335,7 @@ static int do_acpi_entry(const char *filename,
324static int do_pnp_entry(const char *filename, 335static int do_pnp_entry(const char *filename,
325 struct pnp_device_id *id, char *alias) 336 struct pnp_device_id *id, char *alias)
326{ 337{
327 sprintf(alias, "pnp:d%s", id->id); 338 sprintf(alias, "pnp:d%s*", id->id);
328 return 1; 339 return 1;
329} 340}
330 341
@@ -409,6 +420,7 @@ static int do_pcmcia_entry(const char *filename,
409 ADD(alias, "pc", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID3, id->prod_id_hash[2]); 420 ADD(alias, "pc", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID3, id->prod_id_hash[2]);
410 ADD(alias, "pd", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID4, id->prod_id_hash[3]); 421 ADD(alias, "pd", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID4, id->prod_id_hash[3]);
411 422
423 add_wildcard(alias);
412 return 1; 424 return 1;
413} 425}
414 426
@@ -432,6 +444,7 @@ static int do_of_entry (const char *filename, struct of_device_id *of, char *ali
432 if (isspace (*tmp)) 444 if (isspace (*tmp))
433 *tmp = '_'; 445 *tmp = '_';
434 446
447 add_wildcard(alias);
435 return 1; 448 return 1;
436} 449}
437 450
@@ -448,6 +461,7 @@ static int do_vio_entry(const char *filename, struct vio_device_id *vio,
448 if (isspace (*tmp)) 461 if (isspace (*tmp))
449 *tmp = '_'; 462 *tmp = '_';
450 463
464 add_wildcard(alias);
451 return 1; 465 return 1;
452} 466}
453 467
@@ -511,6 +525,8 @@ static int do_eisa_entry(const char *filename, struct eisa_device_id *eisa,
511{ 525{
512 if (eisa->sig[0]) 526 if (eisa->sig[0])
513 sprintf(alias, EISA_DEVICE_MODALIAS_FMT "*", eisa->sig); 527 sprintf(alias, EISA_DEVICE_MODALIAS_FMT "*", eisa->sig);
528 else
529 strcat(alias, "*");
514 return 1; 530 return 1;
515} 531}
516 532
@@ -529,6 +545,7 @@ static int do_parisc_entry(const char *filename, struct parisc_device_id *id,
529 ADD(alias, "rev", id->hversion_rev != PA_HVERSION_REV_ANY_ID, id->hversion_rev); 545 ADD(alias, "rev", id->hversion_rev != PA_HVERSION_REV_ANY_ID, id->hversion_rev);
530 ADD(alias, "sv", id->sversion != PA_SVERSION_ANY_ID, id->sversion); 546 ADD(alias, "sv", id->sversion != PA_SVERSION_ANY_ID, id->sversion);
531 547
548 add_wildcard(alias);
532 return 1; 549 return 1;
533} 550}
534 551
@@ -544,6 +561,7 @@ static int do_sdio_entry(const char *filename,
544 ADD(alias, "c", id->class != (__u8)SDIO_ANY_ID, id->class); 561 ADD(alias, "c", id->class != (__u8)SDIO_ANY_ID, id->class);
545 ADD(alias, "v", id->vendor != (__u16)SDIO_ANY_ID, id->vendor); 562 ADD(alias, "v", id->vendor != (__u16)SDIO_ANY_ID, id->vendor);
546 ADD(alias, "d", id->device != (__u16)SDIO_ANY_ID, id->device); 563 ADD(alias, "d", id->device != (__u16)SDIO_ANY_ID, id->device);
564 add_wildcard(alias);
547 return 1; 565 return 1;
548} 566}
549 567
@@ -559,6 +577,7 @@ static int do_ssb_entry(const char *filename,
559 ADD(alias, "v", id->vendor != SSB_ANY_VENDOR, id->vendor); 577 ADD(alias, "v", id->vendor != SSB_ANY_VENDOR, id->vendor);
560 ADD(alias, "id", id->coreid != SSB_ANY_ID, id->coreid); 578 ADD(alias, "id", id->coreid != SSB_ANY_ID, id->coreid);
561 ADD(alias, "rev", id->revision != SSB_ANY_REV, id->revision); 579 ADD(alias, "rev", id->revision != SSB_ANY_REV, id->revision);
580 add_wildcard(alias);
562 return 1; 581 return 1;
563} 582}
564 583
@@ -573,6 +592,7 @@ static int do_virtio_entry(const char *filename, struct virtio_device_id *id,
573 ADD(alias, "d", 1, id->device); 592 ADD(alias, "d", 1, id->device);
574 ADD(alias, "v", id->vendor != VIRTIO_DEV_ANY_ID, id->vendor); 593 ADD(alias, "v", id->vendor != VIRTIO_DEV_ANY_ID, id->vendor);
575 594
595 add_wildcard(alias);
576 return 1; 596 return 1;
577} 597}
578 598
@@ -612,9 +632,6 @@ static void do_table(void *symval, unsigned long size,
612 632
613 for (i = 0; i < size; i += id_size) { 633 for (i = 0; i < size; i += id_size) {
614 if (do_entry(mod->name, symval+i, alias)) { 634 if (do_entry(mod->name, symval+i, alias)) {
615 /* Always end in a wildcard, for future extension */
616 if (alias[strlen(alias)-1] != '*')
617 strcat(alias, "*");
618 buf_printf(&mod->dev_table_buf, 635 buf_printf(&mod->dev_table_buf,
619 "MODULE_ALIAS(\"%s\");\n", alias); 636 "MODULE_ALIAS(\"%s\");\n", alias);
620 } 637 }
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 85a220465a8f..1c864c0efe2b 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -39,6 +39,7 @@
39#include <linux/spinlock.h> 39#include <linux/spinlock.h>
40#include <linux/syscalls.h> 40#include <linux/syscalls.h>
41#include <linux/file.h> 41#include <linux/file.h>
42#include <linux/fdtable.h>
42#include <linux/namei.h> 43#include <linux/namei.h>
43#include <linux/mount.h> 44#include <linux/mount.h>
44#include <linux/ext2_fs.h> 45#include <linux/ext2_fs.h>
@@ -3286,9 +3287,6 @@ static int selinux_task_kill(struct task_struct *p, struct siginfo *info,
3286 if (rc) 3287 if (rc)
3287 return rc; 3288 return rc;
3288 3289
3289 if (info != SEND_SIG_NOINFO && (is_si_special(info) || SI_FROMKERNEL(info)))
3290 return 0;
3291
3292 if (!sig) 3290 if (!sig)
3293 perm = PROCESS__SIGNULL; /* null signal; existence test */ 3291 perm = PROCESS__SIGNULL; /* null signal; existence test */
3294 else 3292 else
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 92baee53a7dc..b5c8f9237008 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -26,6 +26,7 @@
26#include <linux/pipe_fs_i.h> 26#include <linux/pipe_fs_i.h>
27#include <net/netlabel.h> 27#include <net/netlabel.h>
28#include <net/cipso_ipv4.h> 28#include <net/cipso_ipv4.h>
29#include <linux/audit.h>
29 30
30#include "smack.h" 31#include "smack.h"
31 32
@@ -752,6 +753,18 @@ static int smack_inode_listsecurity(struct inode *inode, char *buffer,
752 return -EINVAL; 753 return -EINVAL;
753} 754}
754 755
756/**
757 * smack_inode_getsecid - Extract inode's security id
758 * @inode: inode to extract the info from
759 * @secid: where result will be saved
760 */
761static void smack_inode_getsecid(const struct inode *inode, u32 *secid)
762{
763 struct inode_smack *isp = inode->i_security;
764
765 *secid = smack_to_secid(isp->smk_inode);
766}
767
755/* 768/*
756 * File Hooks 769 * File Hooks
757 */ 770 */
@@ -1118,15 +1131,6 @@ static int smack_task_kill(struct task_struct *p, struct siginfo *info,
1118 int sig, u32 secid) 1131 int sig, u32 secid)
1119{ 1132{
1120 /* 1133 /*
1121 * Special cases where signals really ought to go through
1122 * in spite of policy. Stephen Smalley suggests it may
1123 * make sense to change the caller so that it doesn't
1124 * bother with the LSM hook in these cases.
1125 */
1126 if (info != SEND_SIG_NOINFO &&
1127 (is_si_special(info) || SI_FROMKERNEL(info)))
1128 return 0;
1129 /*
1130 * Sending a signal requires that the sender 1134 * Sending a signal requires that the sender
1131 * can write the receiver. 1135 * can write the receiver.
1132 */ 1136 */
@@ -1805,6 +1809,18 @@ static int smack_ipc_permission(struct kern_ipc_perm *ipp, short flag)
1805 return smk_curacc(isp, may); 1809 return smk_curacc(isp, may);
1806} 1810}
1807 1811
1812/**
1813 * smack_ipc_getsecid - Extract smack security id
1814 * @ipcp: the object permissions
1815 * @secid: where result will be saved
1816 */
1817static void smack_ipc_getsecid(struct kern_ipc_perm *ipp, u32 *secid)
1818{
1819 char *smack = ipp->security;
1820
1821 *secid = smack_to_secid(smack);
1822}
1823
1808/* module stacking operations */ 1824/* module stacking operations */
1809 1825
1810/** 1826/**
@@ -2382,6 +2398,124 @@ static int smack_key_permission(key_ref_t key_ref,
2382#endif /* CONFIG_KEYS */ 2398#endif /* CONFIG_KEYS */
2383 2399
2384/* 2400/*
2401 * Smack Audit hooks
2402 *
2403 * Audit requires a unique representation of each Smack specific
2404 * rule. This unique representation is used to distinguish the
2405 * object to be audited from remaining kernel objects and also
2406 * works as a glue between the audit hooks.
2407 *
2408 * Since repository entries are added but never deleted, we'll use
2409 * the smack_known label address related to the given audit rule as
2410 * the needed unique representation. This also better fits the smack
2411 * model where nearly everything is a label.
2412 */
2413#ifdef CONFIG_AUDIT
2414
2415/**
2416 * smack_audit_rule_init - Initialize a smack audit rule
2417 * @field: audit rule fields given from user-space (audit.h)
2418 * @op: required testing operator (=, !=, >, <, ...)
2419 * @rulestr: smack label to be audited
2420 * @vrule: pointer to save our own audit rule representation
2421 *
2422 * Prepare to audit cases where (@field @op @rulestr) is true.
2423 * The label to be audited is created if necessay.
2424 */
2425static int smack_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule)
2426{
2427 char **rule = (char **)vrule;
2428 *rule = NULL;
2429
2430 if (field != AUDIT_SUBJ_USER && field != AUDIT_OBJ_USER)
2431 return -EINVAL;
2432
2433 if (op != AUDIT_EQUAL && op != AUDIT_NOT_EQUAL)
2434 return -EINVAL;
2435
2436 *rule = smk_import(rulestr, 0);
2437
2438 return 0;
2439}
2440
2441/**
2442 * smack_audit_rule_known - Distinguish Smack audit rules
2443 * @krule: rule of interest, in Audit kernel representation format
2444 *
2445 * This is used to filter Smack rules from remaining Audit ones.
2446 * If it's proved that this rule belongs to us, the
2447 * audit_rule_match hook will be called to do the final judgement.
2448 */
2449static int smack_audit_rule_known(struct audit_krule *krule)
2450{
2451 struct audit_field *f;
2452 int i;
2453
2454 for (i = 0; i < krule->field_count; i++) {
2455 f = &krule->fields[i];
2456
2457 if (f->type == AUDIT_SUBJ_USER || f->type == AUDIT_OBJ_USER)
2458 return 1;
2459 }
2460
2461 return 0;
2462}
2463
2464/**
2465 * smack_audit_rule_match - Audit given object ?
2466 * @secid: security id for identifying the object to test
2467 * @field: audit rule flags given from user-space
2468 * @op: required testing operator
2469 * @vrule: smack internal rule presentation
2470 * @actx: audit context associated with the check
2471 *
2472 * The core Audit hook. It's used to take the decision of
2473 * whether to audit or not to audit a given object.
2474 */
2475static int smack_audit_rule_match(u32 secid, u32 field, u32 op, void *vrule,
2476 struct audit_context *actx)
2477{
2478 char *smack;
2479 char *rule = vrule;
2480
2481 if (!rule) {
2482 audit_log(actx, GFP_KERNEL, AUDIT_SELINUX_ERR,
2483 "Smack: missing rule\n");
2484 return -ENOENT;
2485 }
2486
2487 if (field != AUDIT_SUBJ_USER && field != AUDIT_OBJ_USER)
2488 return 0;
2489
2490 smack = smack_from_secid(secid);
2491
2492 /*
2493 * No need to do string comparisons. If a match occurs,
2494 * both pointers will point to the same smack_known
2495 * label.
2496 */
2497 if (op == AUDIT_EQUAL)
2498 return (rule == smack);
2499 if (op == AUDIT_NOT_EQUAL)
2500 return (rule != smack);
2501
2502 return 0;
2503}
2504
2505/**
2506 * smack_audit_rule_free - free smack rule representation
2507 * @vrule: rule to be freed.
2508 *
2509 * No memory was allocated.
2510 */
2511static void smack_audit_rule_free(void *vrule)
2512{
2513 /* No-op */
2514}
2515
2516#endif /* CONFIG_AUDIT */
2517
2518/*
2385 * smack_secid_to_secctx - return the smack label for a secid 2519 * smack_secid_to_secctx - return the smack label for a secid
2386 * @secid: incoming integer 2520 * @secid: incoming integer
2387 * @secdata: destination 2521 * @secdata: destination
@@ -2467,6 +2601,7 @@ struct security_operations smack_ops = {
2467 .inode_getsecurity = smack_inode_getsecurity, 2601 .inode_getsecurity = smack_inode_getsecurity,
2468 .inode_setsecurity = smack_inode_setsecurity, 2602 .inode_setsecurity = smack_inode_setsecurity,
2469 .inode_listsecurity = smack_inode_listsecurity, 2603 .inode_listsecurity = smack_inode_listsecurity,
2604 .inode_getsecid = smack_inode_getsecid,
2470 2605
2471 .file_permission = smack_file_permission, 2606 .file_permission = smack_file_permission,
2472 .file_alloc_security = smack_file_alloc_security, 2607 .file_alloc_security = smack_file_alloc_security,
@@ -2498,6 +2633,7 @@ struct security_operations smack_ops = {
2498 .task_prctl = cap_task_prctl, 2633 .task_prctl = cap_task_prctl,
2499 2634
2500 .ipc_permission = smack_ipc_permission, 2635 .ipc_permission = smack_ipc_permission,
2636 .ipc_getsecid = smack_ipc_getsecid,
2501 2637
2502 .msg_msg_alloc_security = smack_msg_msg_alloc_security, 2638 .msg_msg_alloc_security = smack_msg_msg_alloc_security,
2503 .msg_msg_free_security = smack_msg_msg_free_security, 2639 .msg_msg_free_security = smack_msg_msg_free_security,
@@ -2542,12 +2678,22 @@ struct security_operations smack_ops = {
2542 .sk_free_security = smack_sk_free_security, 2678 .sk_free_security = smack_sk_free_security,
2543 .sock_graft = smack_sock_graft, 2679 .sock_graft = smack_sock_graft,
2544 .inet_conn_request = smack_inet_conn_request, 2680 .inet_conn_request = smack_inet_conn_request,
2681
2545 /* key management security hooks */ 2682 /* key management security hooks */
2546#ifdef CONFIG_KEYS 2683#ifdef CONFIG_KEYS
2547 .key_alloc = smack_key_alloc, 2684 .key_alloc = smack_key_alloc,
2548 .key_free = smack_key_free, 2685 .key_free = smack_key_free,
2549 .key_permission = smack_key_permission, 2686 .key_permission = smack_key_permission,
2550#endif /* CONFIG_KEYS */ 2687#endif /* CONFIG_KEYS */
2688
2689 /* Audit hooks */
2690#ifdef CONFIG_AUDIT
2691 .audit_rule_init = smack_audit_rule_init,
2692 .audit_rule_known = smack_audit_rule_known,
2693 .audit_rule_match = smack_audit_rule_match,
2694 .audit_rule_free = smack_audit_rule_free,
2695#endif /* CONFIG_AUDIT */
2696
2551 .secid_to_secctx = smack_secid_to_secctx, 2697 .secid_to_secctx = smack_secid_to_secctx,
2552 .secctx_to_secid = smack_secctx_to_secid, 2698 .secctx_to_secid = smack_secctx_to_secid,
2553 .release_secctx = smack_release_secctx, 2699 .release_secctx = smack_release_secctx,
diff --git a/sound/drivers/pcsp/pcsp.c b/sound/drivers/pcsp/pcsp.c
index 59203511e77d..54a1f9036c66 100644
--- a/sound/drivers/pcsp/pcsp.c
+++ b/sound/drivers/pcsp/pcsp.c
@@ -194,6 +194,7 @@ static void pcsp_stop_beep(struct snd_pcsp *chip)
194 spin_unlock_irq(&chip->substream_lock); 194 spin_unlock_irq(&chip->substream_lock);
195} 195}
196 196
197#ifdef CONFIG_PM
197static int pcsp_suspend(struct platform_device *dev, pm_message_t state) 198static int pcsp_suspend(struct platform_device *dev, pm_message_t state)
198{ 199{
199 struct snd_pcsp *chip = platform_get_drvdata(dev); 200 struct snd_pcsp *chip = platform_get_drvdata(dev);
@@ -201,6 +202,9 @@ static int pcsp_suspend(struct platform_device *dev, pm_message_t state)
201 snd_pcm_suspend_all(chip->pcm); 202 snd_pcm_suspend_all(chip->pcm);
202 return 0; 203 return 0;
203} 204}
205#else
206#define pcsp_suspend NULL
207#endif /* CONFIG_PM */
204 208
205static void pcsp_shutdown(struct platform_device *dev) 209static void pcsp_shutdown(struct platform_device *dev)
206{ 210{
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index 581debf37dcb..7e4742109572 100644
--- a/sound/pci/Kconfig
+++ b/sound/pci/Kconfig
@@ -515,19 +515,16 @@ config SND_FM801
515config SND_FM801_TEA575X_BOOL 515config SND_FM801_TEA575X_BOOL
516 bool "ForteMedia FM801 + TEA5757 tuner" 516 bool "ForteMedia FM801 + TEA5757 tuner"
517 depends on SND_FM801 517 depends on SND_FM801
518 depends on VIDEO_V4L1=y || VIDEO_V4L1=SND_FM801
518 help 519 help
519 Say Y here to include support for soundcards based on the ForteMedia 520 Say Y here to include support for soundcards based on the ForteMedia
520 FM801 chip with a TEA5757 tuner connected to GPIO1-3 pins (Media 521 FM801 chip with a TEA5757 tuner connected to GPIO1-3 pins (Media
521 Forte SF256-PCS-02) into the snd-fm801 driver. 522 Forte SF256-PCS-02) into the snd-fm801 driver.
522 523
523 This will enable support for the old V4L1 API.
524
525config SND_FM801_TEA575X 524config SND_FM801_TEA575X
526 tristate 525 tristate
527 depends on SND_FM801_TEA575X_BOOL 526 depends on SND_FM801_TEA575X_BOOL
528 default SND_FM801 527 default SND_FM801
529 select VIDEO_V4L1
530 select VIDEO_DEV
531 528
532config SND_HDA_INTEL 529config SND_HDA_INTEL
533 tristate "Intel HD Audio" 530 tristate "Intel HD Audio"
diff --git a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c
index 39198e505b12..2da89810ca10 100644
--- a/sound/pci/ac97/ac97_patch.c
+++ b/sound/pci/ac97/ac97_patch.c
@@ -3446,6 +3446,7 @@ static const struct snd_kcontrol_new snd_ac97_controls_vt1617a[] = {
3446int patch_vt1617a(struct snd_ac97 * ac97) 3446int patch_vt1617a(struct snd_ac97 * ac97)
3447{ 3447{
3448 int err = 0; 3448 int err = 0;
3449 int val;
3449 3450
3450 /* we choose to not fail out at this point, but we tell the 3451 /* we choose to not fail out at this point, but we tell the
3451 caller when we return */ 3452 caller when we return */
@@ -3456,7 +3457,13 @@ int patch_vt1617a(struct snd_ac97 * ac97)
3456 /* bring analog power consumption to normal by turning off the 3457 /* bring analog power consumption to normal by turning off the
3457 * headphone amplifier, like WinXP driver for EPIA SP 3458 * headphone amplifier, like WinXP driver for EPIA SP
3458 */ 3459 */
3459 snd_ac97_write_cache(ac97, 0x5c, 0x20); 3460 /* We need to check the bit before writing it.
3461 * On some (many?) hardwares, setting bit actually clears it!
3462 */
3463 val = snd_ac97_read(ac97, 0x5c);
3464 if (!(val & 0x20))
3465 snd_ac97_write_cache(ac97, 0x5c, 0x20);
3466
3460 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ 3467 ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */
3461 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000; 3468 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000;
3462 ac97->build_ops = &patch_vt1616_ops; 3469 ac97->build_ops = &patch_vt1616_ops;
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index d9783a4263e0..6d4df45e81e0 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -11902,7 +11902,10 @@ static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
11902 hda_nid_t nid, 11902 hda_nid_t nid,
11903 int pin_type, int dac_idx) 11903 int pin_type, int dac_idx)
11904{ 11904{
11905 alc_set_pin_output(codec, nid, pin_type); 11905 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
11906 pin_type);
11907 snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11908 AMP_OUT_UNMUTE);
11906} 11909}
11907 11910
11908static void alc861_auto_init_multi_out(struct hda_codec *codec) 11911static void alc861_auto_init_multi_out(struct hda_codec *codec)
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index b3a15d616873..393f7fd2b1be 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -4289,6 +4289,8 @@ struct hda_codec_preset snd_hda_preset_sigmatel[] = {
4289 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x }, 4289 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
4290 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x }, 4290 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
4291 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x }, 4291 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
4292 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
4293 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
4292 /* The following does not take into account .id=0x83847661 when subsys = 4294 /* The following does not take into account .id=0x83847661 when subsys =
4293 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are 4295 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
4294 * currently not fully supported. 4296 * currently not fully supported.
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c
index 76a5c7b05dfb..fb41826c4c4c 100644
--- a/sound/soc/codecs/wm8753.c
+++ b/sound/soc/codecs/wm8753.c
@@ -150,7 +150,7 @@ static int wm8753_write(struct snd_soc_codec *codec, unsigned int reg,
150 data[0] = (reg << 1) | ((value >> 8) & 0x0001); 150 data[0] = (reg << 1) | ((value >> 8) & 0x0001);
151 data[1] = value & 0x00ff; 151 data[1] = value & 0x00ff;
152 152
153 wm8753_write_reg_cache (codec, reg, value); 153 wm8753_write_reg_cache(codec, reg, value);
154 if (codec->hw_write(codec->control_data, data, 2) == 2) 154 if (codec->hw_write(codec->control_data, data, 2) == 2)
155 return 0; 155 return 0;
156 else 156 else
@@ -249,7 +249,7 @@ static int wm8753_set_dai(struct snd_kcontrol *kcontrol,
249 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 249 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
250 int mode = wm8753_read_reg_cache(codec, WM8753_IOCTL); 250 int mode = wm8753_read_reg_cache(codec, WM8753_IOCTL);
251 251
252 if (((mode &0xc) >> 2) == ucontrol->value.integer.value[0]) 252 if (((mode & 0xc) >> 2) == ucontrol->value.integer.value[0])
253 return 0; 253 return 0;
254 254
255 mode &= 0xfff3; 255 mode &= 0xfff3;
@@ -342,7 +342,8 @@ static int wm8753_add_controls(struct snd_soc_codec *codec)
342 342
343 for (i = 0; i < ARRAY_SIZE(wm8753_snd_controls); i++) { 343 for (i = 0; i < ARRAY_SIZE(wm8753_snd_controls); i++) {
344 err = snd_ctl_add(codec->card, 344 err = snd_ctl_add(codec->card,
345 snd_soc_cnew(&wm8753_snd_controls[i],codec, NULL)); 345 snd_soc_cnew(&wm8753_snd_controls[i],
346 codec, NULL));
346 if (err < 0) 347 if (err < 0)
347 return err; 348 return err;
348 } 349 }
@@ -722,7 +723,7 @@ static void pll_factors(struct _pll_div *pll_div, unsigned int target,
722 723
723 if ((Ndiv < 6) || (Ndiv > 12)) 724 if ((Ndiv < 6) || (Ndiv > 12))
724 printk(KERN_WARNING 725 printk(KERN_WARNING
725 "WM8753 N value outwith recommended range! N = %d\n",Ndiv); 726 "wm8753: unsupported N = %d\n", Ndiv);
726 727
727 pll_div->n = Ndiv; 728 pll_div->n = Ndiv;
728 Nmod = target % source; 729 Nmod = target % source;
@@ -1300,8 +1301,9 @@ static int wm8753_dapm_event(struct snd_soc_codec *codec, int event)
1300} 1301}
1301 1302
1302#define WM8753_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ 1303#define WM8753_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
1303 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \ 1304 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
1304 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000) 1305 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
1306 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
1305 1307
1306#define WM8753_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 1308#define WM8753_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
1307 SNDRV_PCM_FMTBIT_S24_LE) 1309 SNDRV_PCM_FMTBIT_S24_LE)
@@ -1507,9 +1509,9 @@ static int wm8753_suspend(struct platform_device *pdev, pm_message_t state)
1507 struct snd_soc_codec *codec = socdev->codec; 1509 struct snd_soc_codec *codec = socdev->codec;
1508 1510
1509 /* we only need to suspend if we are a valid card */ 1511 /* we only need to suspend if we are a valid card */
1510 if(!codec->card) 1512 if (!codec->card)
1511 return 0; 1513 return 0;
1512 1514
1513 wm8753_dapm_event(codec, SNDRV_CTL_POWER_D3cold); 1515 wm8753_dapm_event(codec, SNDRV_CTL_POWER_D3cold);
1514 return 0; 1516 return 0;
1515} 1517}
@@ -1523,7 +1525,7 @@ static int wm8753_resume(struct platform_device *pdev)
1523 u16 *cache = codec->reg_cache; 1525 u16 *cache = codec->reg_cache;
1524 1526
1525 /* we only need to resume if we are a valid card */ 1527 /* we only need to resume if we are a valid card */
1526 if(!codec->card) 1528 if (!codec->card)
1527 return 0; 1529 return 0;
1528 1530
1529 /* Sync reg_cache with the hardware */ 1531 /* Sync reg_cache with the hardware */
@@ -1613,9 +1615,10 @@ static int wm8753_init(struct snd_soc_device *socdev)
1613 wm8753_add_widgets(codec); 1615 wm8753_add_widgets(codec);
1614 ret = snd_soc_register_card(socdev); 1616 ret = snd_soc_register_card(socdev);
1615 if (ret < 0) { 1617 if (ret < 0) {
1616 printk(KERN_ERR "wm8753: failed to register card\n"); 1618 printk(KERN_ERR "wm8753: failed to register card\n");
1617 goto card_err; 1619 goto card_err;
1618 } 1620 }
1621
1619 return ret; 1622 return ret;
1620 1623
1621card_err: 1624card_err:
@@ -1630,7 +1633,7 @@ pcm_err:
1630 around */ 1633 around */
1631static struct snd_soc_device *wm8753_socdev; 1634static struct snd_soc_device *wm8753_socdev;
1632 1635
1633#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 1636#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1634 1637
1635/* 1638/*
1636 * WM8753 2 wire address is determined by GPIO5 1639 * WM8753 2 wire address is determined by GPIO5
@@ -1661,7 +1664,7 @@ static int wm8753_codec_probe(struct i2c_adapter *adap, int addr, int kind)
1661 client_template.addr = addr; 1664 client_template.addr = addr;
1662 1665
1663 i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL); 1666 i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL);
1664 if (i2c == NULL){ 1667 if (!i2c) {
1665 kfree(codec); 1668 kfree(codec);
1666 return -ENOMEM; 1669 return -ENOMEM;
1667 } 1670 }
@@ -1749,7 +1752,7 @@ static int wm8753_probe(struct platform_device *pdev)
1749 wm8753_socdev = socdev; 1752 wm8753_socdev = socdev;
1750 INIT_DELAYED_WORK(&codec->delayed_work, wm8753_work); 1753 INIT_DELAYED_WORK(&codec->delayed_work, wm8753_work);
1751 1754
1752#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 1755#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1753 if (setup->i2c_address) { 1756 if (setup->i2c_address) {
1754 normal_i2c[0] = setup->i2c_address; 1757 normal_i2c[0] = setup->i2c_address;
1755 codec->hw_write = (hw_write_t)i2c_master_send; 1758 codec->hw_write = (hw_write_t)i2c_master_send;
@@ -1793,7 +1796,7 @@ static int wm8753_remove(struct platform_device *pdev)
1793 run_delayed_work(&codec->delayed_work); 1796 run_delayed_work(&codec->delayed_work);
1794 snd_soc_free_pcms(socdev); 1797 snd_soc_free_pcms(socdev);
1795 snd_soc_dapm_free(socdev); 1798 snd_soc_dapm_free(socdev);
1796#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 1799#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1797 i2c_del_driver(&wm8753_i2c_driver); 1800 i2c_del_driver(&wm8753_i2c_driver);
1798#endif 1801#endif
1799 kfree(codec->private_data); 1802 kfree(codec->private_data);
@@ -1808,7 +1811,6 @@ struct snd_soc_codec_device soc_codec_dev_wm8753 = {
1808 .suspend = wm8753_suspend, 1811 .suspend = wm8753_suspend,
1809 .resume = wm8753_resume, 1812 .resume = wm8753_resume,
1810}; 1813};
1811
1812EXPORT_SYMBOL_GPL(soc_codec_dev_wm8753); 1814EXPORT_SYMBOL_GPL(soc_codec_dev_wm8753);
1813 1815
1814MODULE_DESCRIPTION("ASoC WM8753 driver"); 1816MODULE_DESCRIPTION("ASoC WM8753 driver");
diff --git a/sound/soc/s3c24xx/ln2440sbc_alc650.c b/sound/soc/s3c24xx/ln2440sbc_alc650.c
index 9ed8f2e8da10..4eab2c19c454 100644
--- a/sound/soc/s3c24xx/ln2440sbc_alc650.c
+++ b/sound/soc/s3c24xx/ln2440sbc_alc650.c
@@ -1,10 +1,10 @@
1/* 1/*
2 * SoC audio for ln2440sbc 2 * SoC audio for ln2440sbc
3 * 3 *
4 * Copyright 2007 KonekTel, a.s. 4 * Copyright 2007 KonekTel, a.s.
5 * Author: Ivan Kuten 5 * Author: Ivan Kuten
6 * ivan.kuten@promwad.com 6 * ivan.kuten@promwad.com
7 * 7 *
8 * Heavily based on smdk2443_wm9710.c 8 * Heavily based on smdk2443_wm9710.c
9 * Copyright 2007 Wolfson Microelectronics PLC. 9 * Copyright 2007 Wolfson Microelectronics PLC.
10 * Author: Graeme Gregory 10 * Author: Graeme Gregory
diff --git a/sound/soc/s3c24xx/neo1973_wm8753.c b/sound/soc/s3c24xx/neo1973_wm8753.c
index 962cc20b1af5..0e9d1c5f2484 100644
--- a/sound/soc/s3c24xx/neo1973_wm8753.c
+++ b/sound/soc/s3c24xx/neo1973_wm8753.c
@@ -33,7 +33,7 @@
33#include <asm/arch/regs-gpio.h> 33#include <asm/arch/regs-gpio.h>
34#include <asm/hardware.h> 34#include <asm/hardware.h>
35#include <asm/arch/audio.h> 35#include <asm/arch/audio.h>
36#include <asm/io.h> 36#include <linux/io.h>
37#include <asm/arch/spi-gpio.h> 37#include <asm/arch/spi-gpio.h>
38 38
39#include <asm/plat-s3c24xx/regs-iis.h> 39#include <asm/plat-s3c24xx/regs-iis.h>
@@ -122,7 +122,7 @@ static int neo1973_hifi_hw_params(struct snd_pcm_substream *substream,
122 122
123 /* set MCLK division for sample rate */ 123 /* set MCLK division for sample rate */
124 ret = cpu_dai->dai_ops.set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK, 124 ret = cpu_dai->dai_ops.set_clkdiv(cpu_dai, S3C24XX_DIV_MCLK,
125 S3C2410_IISMOD_32FS ); 125 S3C2410_IISMOD_32FS);
126 if (ret < 0) 126 if (ret < 0)
127 return ret; 127 return ret;
128 128
@@ -133,7 +133,7 @@ static int neo1973_hifi_hw_params(struct snd_pcm_substream *substream,
133 133
134 /* set prescaler division for sample rate */ 134 /* set prescaler division for sample rate */
135 ret = cpu_dai->dai_ops.set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER, 135 ret = cpu_dai->dai_ops.set_clkdiv(cpu_dai, S3C24XX_DIV_PRESCALER,
136 S3C24XX_PRESCALE(4,4)); 136 S3C24XX_PRESCALE(4, 4));
137 if (ret < 0) 137 if (ret < 0)
138 return ret; 138 return ret;
139 139
@@ -222,7 +222,7 @@ static struct snd_soc_ops neo1973_voice_ops = {
222 .hw_free = neo1973_voice_hw_free, 222 .hw_free = neo1973_voice_hw_free,
223}; 223};
224 224
225static int neo1973_scenario = 0; 225static int neo1973_scenario;
226 226
227static int neo1973_get_scenario(struct snd_kcontrol *kcontrol, 227static int neo1973_get_scenario(struct snd_kcontrol *kcontrol,
228 struct snd_ctl_elem_value *ucontrol) 228 struct snd_ctl_elem_value *ucontrol)
@@ -233,7 +233,7 @@ static int neo1973_get_scenario(struct snd_kcontrol *kcontrol,
233 233
234static int set_scenario_endpoints(struct snd_soc_codec *codec, int scenario) 234static int set_scenario_endpoints(struct snd_soc_codec *codec, int scenario)
235{ 235{
236 switch(neo1973_scenario) { 236 switch (neo1973_scenario) {
237 case NEO_AUDIO_OFF: 237 case NEO_AUDIO_OFF:
238 snd_soc_dapm_set_endpoint(codec, "Audio Out", 0); 238 snd_soc_dapm_set_endpoint(codec, "Audio Out", 0);
239 snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0); 239 snd_soc_dapm_set_endpoint(codec, "GSM Line Out", 0);
@@ -334,7 +334,7 @@ static void lm4857_write_regs(void)
334static int lm4857_get_reg(struct snd_kcontrol *kcontrol, 334static int lm4857_get_reg(struct snd_kcontrol *kcontrol,
335 struct snd_ctl_elem_value *ucontrol) 335 struct snd_ctl_elem_value *ucontrol)
336{ 336{
337 int reg=kcontrol->private_value & 0xFF; 337 int reg = kcontrol->private_value & 0xFF;
338 int shift = (kcontrol->private_value >> 8) & 0x0F; 338 int shift = (kcontrol->private_value >> 8) & 0x0F;
339 int mask = (kcontrol->private_value >> 16) & 0xFF; 339 int mask = (kcontrol->private_value >> 16) & 0xFF;
340 340
@@ -349,11 +349,11 @@ static int lm4857_set_reg(struct snd_kcontrol *kcontrol,
349 int shift = (kcontrol->private_value >> 8) & 0x0F; 349 int shift = (kcontrol->private_value >> 8) & 0x0F;
350 int mask = (kcontrol->private_value >> 16) & 0xFF; 350 int mask = (kcontrol->private_value >> 16) & 0xFF;
351 351
352 if (((lm4857_regs[reg] >> shift ) & mask) == 352 if (((lm4857_regs[reg] >> shift) & mask) ==
353 ucontrol->value.integer.value[0]) 353 ucontrol->value.integer.value[0])
354 return 0; 354 return 0;
355 355
356 lm4857_regs[reg] &= ~ (mask << shift); 356 lm4857_regs[reg] &= ~(mask << shift);
357 lm4857_regs[reg] |= ucontrol->value.integer.value[0] << shift; 357 lm4857_regs[reg] |= ucontrol->value.integer.value[0] << shift;
358 lm4857_write_regs(); 358 lm4857_write_regs();
359 return 1; 359 return 1;
@@ -398,7 +398,7 @@ static const struct snd_soc_dapm_widget wm8753_dapm_widgets[] = {
398 398
399 399
400/* example machine audio_mapnections */ 400/* example machine audio_mapnections */
401static const char* audio_map[][3] = { 401static const char *audio_map[][3] = {
402 402
403 /* Connections to the lm4857 amp */ 403 /* Connections to the lm4857 amp */
404 {"Audio Out", NULL, "LOUT1"}, 404 {"Audio Out", NULL, "LOUT1"},
@@ -450,7 +450,7 @@ static const char *neo_scenarios[] = {
450}; 450};
451 451
452static const struct soc_enum neo_scenario_enum[] = { 452static const struct soc_enum neo_scenario_enum[] = {
453 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(neo_scenarios),neo_scenarios), 453 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(neo_scenarios), neo_scenarios),
454}; 454};
455 455
456static const struct snd_kcontrol_new wm8753_neo1973_controls[] = { 456static const struct snd_kcontrol_new wm8753_neo1973_controls[] = {
@@ -521,8 +521,8 @@ static int neo1973_wm8753_init(struct snd_soc_codec *codec)
521/* 521/*
522 * BT Codec DAI 522 * BT Codec DAI
523 */ 523 */
524static struct snd_soc_cpu_dai bt_dai = 524static struct snd_soc_cpu_dai bt_dai = {
525{ .name = "Bluetooth", 525 .name = "Bluetooth",
526 .id = 0, 526 .id = 0,
527 .type = SND_SOC_DAI_PCM, 527 .type = SND_SOC_DAI_PCM,
528 .playback = { 528 .playback = {
@@ -616,6 +616,35 @@ static int lm4857_i2c_attach(struct i2c_adapter *adap)
616 return i2c_probe(adap, &addr_data, lm4857_amp_probe); 616 return i2c_probe(adap, &addr_data, lm4857_amp_probe);
617} 617}
618 618
619static u8 lm4857_state;
620
621static int lm4857_suspend(struct i2c_client *dev, pm_message_t state)
622{
623 dev_dbg(&dev->dev, "lm4857_suspend\n");
624 lm4857_state = lm4857_regs[LM4857_CTRL] & 0xf;
625 if (lm4857_state) {
626 lm4857_regs[LM4857_CTRL] &= 0xf0;
627 lm4857_write_regs();
628 }
629 return 0;
630}
631
632static int lm4857_resume(struct i2c_client *dev)
633{
634 if (lm4857_state) {
635 lm4857_regs[LM4857_CTRL] |= (lm4857_state & 0x0f);
636 lm4857_write_regs();
637 }
638 return 0;
639}
640
641static void lm4857_shutdown(struct i2c_client *dev)
642{
643 dev_dbg(&dev->dev, "lm4857_shutdown\n");
644 lm4857_regs[LM4857_CTRL] &= 0xf0;
645 lm4857_write_regs();
646}
647
619/* corgi i2c codec control layer */ 648/* corgi i2c codec control layer */
620static struct i2c_driver lm4857_i2c_driver = { 649static struct i2c_driver lm4857_i2c_driver = {
621 .driver = { 650 .driver = {
@@ -623,6 +652,9 @@ static struct i2c_driver lm4857_i2c_driver = {
623 .owner = THIS_MODULE, 652 .owner = THIS_MODULE,
624 }, 653 },
625 .id = I2C_DRIVERID_LM4857, 654 .id = I2C_DRIVERID_LM4857,
655 .suspend = lm4857_suspend,
656 .resume = lm4857_resume,
657 .shutdown = lm4857_shutdown,
626 .attach_adapter = lm4857_i2c_attach, 658 .attach_adapter = lm4857_i2c_attach,
627 .detach_client = lm4857_i2c_detach, 659 .detach_client = lm4857_i2c_detach,
628 .command = NULL, 660 .command = NULL,
@@ -667,6 +699,6 @@ module_init(neo1973_init);
667module_exit(neo1973_exit); 699module_exit(neo1973_exit);
668 700
669/* Module information */ 701/* Module information */
670MODULE_AUTHOR("Graeme Gregory, graeme.gregory@wolfsonmicro.com, www.wolfsonmicro.com"); 702MODULE_AUTHOR("Graeme Gregory, graeme@openmoko.org, www.openmoko.org");
671MODULE_DESCRIPTION("ALSA SoC WM8753 Neo1973"); 703MODULE_DESCRIPTION("ALSA SoC WM8753 Neo1973");
672MODULE_LICENSE("GPL"); 704MODULE_LICENSE("GPL");
diff --git a/sound/soc/s3c24xx/s3c2443-ac97.c b/sound/soc/s3c24xx/s3c2443-ac97.c
index 1c1ddbf7f3c0..e81d9a6c83da 100644
--- a/sound/soc/s3c24xx/s3c2443-ac97.c
+++ b/sound/soc/s3c24xx/s3c2443-ac97.c
@@ -19,6 +19,7 @@
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/io.h>
22#include <linux/wait.h> 23#include <linux/wait.h>
23#include <linux/delay.h> 24#include <linux/delay.h>
24#include <linux/clk.h> 25#include <linux/clk.h>
@@ -30,7 +31,6 @@
30#include <sound/soc.h> 31#include <sound/soc.h>
31 32
32#include <asm/hardware.h> 33#include <asm/hardware.h>
33#include <asm/io.h>
34#include <asm/plat-s3c/regs-ac97.h> 34#include <asm/plat-s3c/regs-ac97.h>
35#include <asm/arch/regs-gpio.h> 35#include <asm/arch/regs-gpio.h>
36#include <asm/arch/regs-clock.h> 36#include <asm/arch/regs-clock.h>
@@ -47,7 +47,7 @@ struct s3c24xx_ac97_info {
47}; 47};
48static struct s3c24xx_ac97_info s3c24xx_ac97; 48static struct s3c24xx_ac97_info s3c24xx_ac97;
49 49
50DECLARE_COMPLETION(ac97_completion); 50static DECLARE_COMPLETION(ac97_completion);
51static u32 codec_ready; 51static u32 codec_ready;
52static DECLARE_MUTEX(ac97_mutex); 52static DECLARE_MUTEX(ac97_mutex);
53 53
@@ -290,7 +290,7 @@ static int s3c2443_ac97_trigger(struct snd_pcm_substream *substream, int cmd)
290 u32 ac_glbctrl; 290 u32 ac_glbctrl;
291 291
292 ac_glbctrl = readl(s3c24xx_ac97.regs + S3C_AC97_GLBCTRL); 292 ac_glbctrl = readl(s3c24xx_ac97.regs + S3C_AC97_GLBCTRL);
293 switch(cmd) { 293 switch (cmd) {
294 case SNDRV_PCM_TRIGGER_START: 294 case SNDRV_PCM_TRIGGER_START:
295 case SNDRV_PCM_TRIGGER_RESUME: 295 case SNDRV_PCM_TRIGGER_RESUME:
296 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 296 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
@@ -333,7 +333,7 @@ static int s3c2443_ac97_mic_trigger(struct snd_pcm_substream *substream,
333 u32 ac_glbctrl; 333 u32 ac_glbctrl;
334 334
335 ac_glbctrl = readl(s3c24xx_ac97.regs + S3C_AC97_GLBCTRL); 335 ac_glbctrl = readl(s3c24xx_ac97.regs + S3C_AC97_GLBCTRL);
336 switch(cmd) { 336 switch (cmd) {
337 case SNDRV_PCM_TRIGGER_START: 337 case SNDRV_PCM_TRIGGER_START:
338 case SNDRV_PCM_TRIGGER_RESUME: 338 case SNDRV_PCM_TRIGGER_RESUME:
339 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 339 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
@@ -391,7 +391,6 @@ struct snd_soc_cpu_dai s3c2443_ac97_dai[] = {
391 .trigger = s3c2443_ac97_mic_trigger,}, 391 .trigger = s3c2443_ac97_mic_trigger,},
392}, 392},
393}; 393};
394
395EXPORT_SYMBOL_GPL(s3c2443_ac97_dai); 394EXPORT_SYMBOL_GPL(s3c2443_ac97_dai);
396EXPORT_SYMBOL_GPL(soc_ac97_ops); 395EXPORT_SYMBOL_GPL(soc_ac97_ops);
397 396
diff --git a/sound/soc/s3c24xx/s3c24xx-i2s.c b/sound/soc/s3c24xx/s3c24xx-i2s.c
index 4ebcd6a8bf28..1ed6afd45459 100644
--- a/sound/soc/s3c24xx/s3c24xx-i2s.c
+++ b/sound/soc/s3c24xx/s3c24xx-i2s.c
@@ -224,6 +224,7 @@ static int s3c24xx_i2s_set_fmt(struct snd_soc_cpu_dai *cpu_dai,
224 iismod |= S3C2410_IISMOD_SLAVE; 224 iismod |= S3C2410_IISMOD_SLAVE;
225 break; 225 break;
226 case SND_SOC_DAIFMT_CBS_CFS: 226 case SND_SOC_DAIFMT_CBS_CFS:
227 iismod &= ~S3C2410_IISMOD_SLAVE;
227 break; 228 break;
228 default: 229 default:
229 return -EINVAL; 230 return -EINVAL;
@@ -234,6 +235,7 @@ static int s3c24xx_i2s_set_fmt(struct snd_soc_cpu_dai *cpu_dai,
234 iismod |= S3C2410_IISMOD_MSB; 235 iismod |= S3C2410_IISMOD_MSB;
235 break; 236 break;
236 case SND_SOC_DAIFMT_I2S: 237 case SND_SOC_DAIFMT_I2S:
238 iismod &= ~S3C2410_IISMOD_MSB;
237 break; 239 break;
238 default: 240 default:
239 return -EINVAL; 241 return -EINVAL;
diff --git a/sound/soc/s3c24xx/s3c24xx-pcm.c b/sound/soc/s3c24xx/s3c24xx-pcm.c
index 49580fb481d5..7806ae614617 100644
--- a/sound/soc/s3c24xx/s3c24xx-pcm.c
+++ b/sound/soc/s3c24xx/s3c24xx-pcm.c
@@ -20,6 +20,7 @@
20 20
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/io.h>
23#include <linux/platform_device.h> 24#include <linux/platform_device.h>
24#include <linux/slab.h> 25#include <linux/slab.h>
25#include <linux/dma-mapping.h> 26#include <linux/dma-mapping.h>
@@ -30,7 +31,6 @@
30#include <sound/soc.h> 31#include <sound/soc.h>
31 32
32#include <asm/dma.h> 33#include <asm/dma.h>
33#include <asm/io.h>
34#include <asm/hardware.h> 34#include <asm/hardware.h>
35#include <asm/arch/dma.h> 35#include <asm/arch/dma.h>
36#include <asm/arch/audio.h> 36#include <asm/arch/audio.h>
@@ -93,7 +93,7 @@ static void s3c24xx_pcm_enqueue(struct snd_pcm_substream *substream)
93 while (prtd->dma_loaded < prtd->dma_limit) { 93 while (prtd->dma_loaded < prtd->dma_limit) {
94 unsigned long len = prtd->dma_period; 94 unsigned long len = prtd->dma_period;
95 95
96 DBG("dma_loaded: %d\n",prtd->dma_loaded); 96 DBG("dma_loaded: %d\n", prtd->dma_loaded);
97 97
98 if ((pos + len) > prtd->dma_end) { 98 if ((pos + len) > prtd->dma_end) {
99 len = prtd->dma_end - pos; 99 len = prtd->dma_end - pos;
@@ -101,7 +101,7 @@ static void s3c24xx_pcm_enqueue(struct snd_pcm_substream *substream)
101 __func__, len); 101 __func__, len);
102 } 102 }
103 103
104 ret = s3c2410_dma_enqueue(prtd->params->channel, 104 ret = s3c2410_dma_enqueue(prtd->params->channel,
105 substream, pos, len); 105 substream, pos, len);
106 106
107 if (ret == 0) { 107 if (ret == 0) {
@@ -129,7 +129,7 @@ static void s3c24xx_audio_buffdone(struct s3c2410_dma_chan *channel,
129 return; 129 return;
130 130
131 prtd = substream->runtime->private_data; 131 prtd = substream->runtime->private_data;
132 132
133 if (substream) 133 if (substream)
134 snd_pcm_period_elapsed(substream); 134 snd_pcm_period_elapsed(substream);
135 135
@@ -150,7 +150,7 @@ static int s3c24xx_pcm_hw_params(struct snd_pcm_substream *substream,
150 struct snd_soc_pcm_runtime *rtd = substream->private_data; 150 struct snd_soc_pcm_runtime *rtd = substream->private_data;
151 struct s3c24xx_pcm_dma_params *dma = rtd->dai->cpu_dai->dma_data; 151 struct s3c24xx_pcm_dma_params *dma = rtd->dai->cpu_dai->dma_data;
152 unsigned long totbytes = params_buffer_bytes(params); 152 unsigned long totbytes = params_buffer_bytes(params);
153 int ret=0; 153 int ret = 0;
154 154
155 DBG("Entered %s\n", __func__); 155 DBG("Entered %s\n", __func__);
156 156
@@ -171,7 +171,7 @@ static int s3c24xx_pcm_hw_params(struct snd_pcm_substream *substream,
171 ret = s3c2410_dma_request(prtd->params->channel, 171 ret = s3c2410_dma_request(prtd->params->channel,
172 prtd->params->client, NULL); 172 prtd->params->client, NULL);
173 173
174 if (ret) { 174 if (ret < 0) {
175 DBG(KERN_ERR "failed to get dma channel\n"); 175 DBG(KERN_ERR "failed to get dma channel\n");
176 return ret; 176 return ret;
177 } 177 }
@@ -223,7 +223,7 @@ static int s3c24xx_pcm_prepare(struct snd_pcm_substream *substream)
223 /* return if this is a bufferless transfer e.g. 223 /* return if this is a bufferless transfer e.g.
224 * codec <--> BT codec or GSM modem -- lg FIXME */ 224 * codec <--> BT codec or GSM modem -- lg FIXME */
225 if (!prtd->params) 225 if (!prtd->params)
226 return 0; 226 return 0;
227 227
228 /* channel needs configuring for mem=>device, increment memory addr, 228 /* channel needs configuring for mem=>device, increment memory addr,
229 * sync to pclk, half-word transfers to the IIS-FIFO. */ 229 * sync to pclk, half-word transfers to the IIS-FIFO. */
@@ -293,8 +293,8 @@ static int s3c24xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
293 return ret; 293 return ret;
294} 294}
295 295
296static snd_pcm_uframes_t 296static snd_pcm_uframes_t
297 s3c24xx_pcm_pointer(struct snd_pcm_substream *substream) 297s3c24xx_pcm_pointer(struct snd_pcm_substream *substream)
298{ 298{
299 struct snd_pcm_runtime *runtime = substream->runtime; 299 struct snd_pcm_runtime *runtime = substream->runtime;
300 struct s3c24xx_runtime_data *prtd = runtime->private_data; 300 struct s3c24xx_runtime_data *prtd = runtime->private_data;
@@ -313,7 +313,7 @@ static snd_pcm_uframes_t
313 313
314 spin_unlock(&prtd->lock); 314 spin_unlock(&prtd->lock);
315 315
316 DBG("Pointer %x %x\n",src,dst); 316 DBG("Pointer %x %x\n", src, dst);
317 317
318 /* we seem to be getting the odd error from the pcm library due 318 /* we seem to be getting the odd error from the pcm library due
319 * to out-of-bounds pointers. this is maybe due to the dma engine 319 * to out-of-bounds pointers. this is maybe due to the dma engine
@@ -355,11 +355,11 @@ static int s3c24xx_pcm_close(struct snd_pcm_substream *substream)
355 355
356 DBG("Entered %s\n", __func__); 356 DBG("Entered %s\n", __func__);
357 357
358 if (prtd) 358 if (!prtd)
359 kfree(prtd);
360 else
361 DBG("s3c24xx_pcm_close called with prtd == NULL\n"); 359 DBG("s3c24xx_pcm_close called with prtd == NULL\n");
362 360
361 kfree(prtd);
362
363 return 0; 363 return 0;
364} 364}
365 365
@@ -371,9 +371,9 @@ static int s3c24xx_pcm_mmap(struct snd_pcm_substream *substream,
371 DBG("Entered %s\n", __func__); 371 DBG("Entered %s\n", __func__);
372 372
373 return dma_mmap_writecombine(substream->pcm->card->dev, vma, 373 return dma_mmap_writecombine(substream->pcm->card->dev, vma,
374 runtime->dma_area, 374 runtime->dma_area,
375 runtime->dma_addr, 375 runtime->dma_addr,
376 runtime->dma_bytes); 376 runtime->dma_bytes);
377} 377}
378 378
379static struct snd_pcm_ops s3c24xx_pcm_ops = { 379static struct snd_pcm_ops s3c24xx_pcm_ops = {
@@ -432,7 +432,7 @@ static void s3c24xx_pcm_free_dma_buffers(struct snd_pcm *pcm)
432 432
433static u64 s3c24xx_pcm_dmamask = DMA_32BIT_MASK; 433static u64 s3c24xx_pcm_dmamask = DMA_32BIT_MASK;
434 434
435static int s3c24xx_pcm_new(struct snd_card *card, 435static int s3c24xx_pcm_new(struct snd_card *card,
436 struct snd_soc_codec_dai *dai, struct snd_pcm *pcm) 436 struct snd_soc_codec_dai *dai, struct snd_pcm *pcm)
437{ 437{
438 int ret = 0; 438 int ret = 0;
@@ -467,7 +467,6 @@ struct snd_soc_platform s3c24xx_soc_platform = {
467 .pcm_new = s3c24xx_pcm_new, 467 .pcm_new = s3c24xx_pcm_new,
468 .pcm_free = s3c24xx_pcm_free_dma_buffers, 468 .pcm_free = s3c24xx_pcm_free_dma_buffers,
469}; 469};
470
471EXPORT_SYMBOL_GPL(s3c24xx_soc_platform); 470EXPORT_SYMBOL_GPL(s3c24xx_soc_platform);
472 471
473MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>"); 472MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index c82cf15730a1..f7ba099049ea 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -522,6 +522,7 @@ unsigned long gfn_to_hva(struct kvm *kvm, gfn_t gfn)
522 return bad_hva(); 522 return bad_hva();
523 return (slot->userspace_addr + (gfn - slot->base_gfn) * PAGE_SIZE); 523 return (slot->userspace_addr + (gfn - slot->base_gfn) * PAGE_SIZE);
524} 524}
525EXPORT_SYMBOL_GPL(gfn_to_hva);
525 526
526/* 527/*
527 * Requires current->mm->mmap_sem to be held 528 * Requires current->mm->mmap_sem to be held
@@ -834,16 +835,9 @@ static const struct file_operations kvm_vcpu_fops = {
834 */ 835 */
835static int create_vcpu_fd(struct kvm_vcpu *vcpu) 836static int create_vcpu_fd(struct kvm_vcpu *vcpu)
836{ 837{
837 int fd, r; 838 int fd = anon_inode_getfd("kvm-vcpu", &kvm_vcpu_fops, vcpu);
838 struct inode *inode; 839 if (fd < 0)
839 struct file *file;
840
841 r = anon_inode_getfd(&fd, &inode, &file,
842 "kvm-vcpu", &kvm_vcpu_fops, vcpu);
843 if (r) {
844 kvm_put_kvm(vcpu->kvm); 840 kvm_put_kvm(vcpu->kvm);
845 return r;
846 }
847 return fd; 841 return fd;
848} 842}
849 843
@@ -1168,19 +1162,15 @@ static const struct file_operations kvm_vm_fops = {
1168 1162
1169static int kvm_dev_ioctl_create_vm(void) 1163static int kvm_dev_ioctl_create_vm(void)
1170{ 1164{
1171 int fd, r; 1165 int fd;
1172 struct inode *inode;
1173 struct file *file;
1174 struct kvm *kvm; 1166 struct kvm *kvm;
1175 1167
1176 kvm = kvm_create_vm(); 1168 kvm = kvm_create_vm();
1177 if (IS_ERR(kvm)) 1169 if (IS_ERR(kvm))
1178 return PTR_ERR(kvm); 1170 return PTR_ERR(kvm);
1179 r = anon_inode_getfd(&fd, &inode, &file, "kvm-vm", &kvm_vm_fops, kvm); 1171 fd = anon_inode_getfd("kvm-vm", &kvm_vm_fops, kvm);
1180 if (r) { 1172 if (fd < 0)
1181 kvm_put_kvm(kvm); 1173 kvm_put_kvm(kvm);
1182 return r;
1183 }
1184 1174
1185 return fd; 1175 return fd;
1186} 1176}